minor refactor

This commit is contained in:
MihailRis 2024-01-31 18:14:01 +03:00
parent ded80e0d4b
commit bfe2e2557b
5 changed files with 53 additions and 65 deletions

View File

@ -1,48 +1,43 @@
#include "definitions.h" #include "core_defs.h"
#include <glm/glm.hpp> #include "items/ItemDef.h"
#include "content/Content.h"
#include "items/ItemDef.h" #include "window/Window.h"
#include "content/Content.h" #include "window/Events.h"
#include "window/Window.h" #include "window/input.h"
#include "window/Events.h" #include "voxels/Block.h"
#include "window/input.h"
#include "voxels/Block.h" // All in-game definitions (blocks, items, etc..)
void corecontent::setup(ContentBuilder* builder) {
using glm::vec3; Block* block = builder->createBlock("core:air");
block->replaceable = true;
// All in-game definitions (blocks, items, etc..) block->drawGroup = 1;
void setup_definitions(ContentBuilder* builder) { // Strange function, need to REDO ? block->lightPassing = true;
Block* block = new Block("core:air", "air"); block->skyLightPassing = true;
block->replaceable = true; block->obstacle = false;
block->drawGroup = 1; block->selectable = false;
block->lightPassing = true; block->model = BlockModel::none;
block->skyLightPassing = true; block->pickingItem = "core:empty";
block->obstacle = false;
block->selectable = false; ItemDef* item = builder->createItem("core:empty");
block->model = BlockModel::none; item->iconType = item_icon_type::none;
block->pickingItem = "core:empty"; }
builder->add(block);
void corecontent::setup_bindings() {
ItemDef* item = builder->createItem("core:empty"); Events::bind(BIND_MOVE_FORWARD, inputtype::keyboard, keycode::W);
item->iconType = item_icon_type::none; Events::bind(BIND_MOVE_BACK, inputtype::keyboard, keycode::S);
} Events::bind(BIND_MOVE_RIGHT, inputtype::keyboard, keycode::D);
Events::bind(BIND_MOVE_LEFT, inputtype::keyboard, keycode::A);
void setup_bindings() { Events::bind(BIND_MOVE_JUMP, inputtype::keyboard, keycode::SPACE);
Events::bind(BIND_MOVE_FORWARD, inputtype::keyboard, keycode::W); Events::bind(BIND_MOVE_SPRINT, inputtype::keyboard, keycode::LEFT_CONTROL);
Events::bind(BIND_MOVE_BACK, inputtype::keyboard, keycode::S); Events::bind(BIND_MOVE_CROUCH, inputtype::keyboard, keycode::LEFT_SHIFT);
Events::bind(BIND_MOVE_RIGHT, inputtype::keyboard, keycode::D); Events::bind(BIND_MOVE_CHEAT, inputtype::keyboard, keycode::R);
Events::bind(BIND_MOVE_LEFT, inputtype::keyboard, keycode::A); Events::bind(BIND_CAM_ZOOM, inputtype::keyboard, keycode::C);
Events::bind(BIND_MOVE_JUMP, inputtype::keyboard, keycode::SPACE); Events::bind(BIND_CAM_MODE, inputtype::keyboard, keycode::F4);
Events::bind(BIND_MOVE_SPRINT, inputtype::keyboard, keycode::LEFT_CONTROL); Events::bind(BIND_PLAYER_NOCLIP, inputtype::keyboard, keycode::N);
Events::bind(BIND_MOVE_CROUCH, inputtype::keyboard, keycode::LEFT_SHIFT); Events::bind(BIND_PLAYER_FLIGHT, inputtype::keyboard, keycode::F);
Events::bind(BIND_MOVE_CHEAT, inputtype::keyboard, keycode::R); Events::bind(BIND_PLAYER_ATTACK, inputtype::mouse, mousecode::BUTTON_1);
Events::bind(BIND_CAM_ZOOM, inputtype::keyboard, keycode::C); Events::bind(BIND_PLAYER_BUILD, inputtype::mouse, mousecode::BUTTON_2);
Events::bind(BIND_CAM_MODE, inputtype::keyboard, keycode::F4); Events::bind(BIND_PLAYER_PICK, inputtype::mouse, mousecode::BUTTON_3);
Events::bind(BIND_PLAYER_NOCLIP, inputtype::keyboard, keycode::N); Events::bind(BIND_HUD_INVENTORY, inputtype::keyboard, keycode::TAB);
Events::bind(BIND_PLAYER_FLIGHT, inputtype::keyboard, keycode::F);
Events::bind(BIND_PLAYER_ATTACK, inputtype::mouse, mousecode::BUTTON_1);
Events::bind(BIND_PLAYER_BUILD, inputtype::mouse, mousecode::BUTTON_2);
Events::bind(BIND_PLAYER_PICK, inputtype::mouse, mousecode::BUTTON_3);
Events::bind(BIND_HUD_INVENTORY, inputtype::keyboard, keycode::TAB);
} }

View File

@ -3,7 +3,6 @@
#include <string> #include <string>
const std::string TEXTURE_NOTFOUND = "notfound"; const std::string TEXTURE_NOTFOUND = "notfound";
/* bindings used in engine code */ /* bindings used in engine code */
@ -24,4 +23,11 @@ const std::string BIND_PLAYER_BUILD = "player.build";
const std::string BIND_PLAYER_PICK = "player.pick"; const std::string BIND_PLAYER_PICK = "player.pick";
const std::string BIND_HUD_INVENTORY = "hud.inventory"; const std::string BIND_HUD_INVENTORY = "hud.inventory";
class ContentBuilder;
namespace corecontent {
extern void setup_bindings();
extern void setup(ContentBuilder* builder);
}
#endif // SRC_CORE_DEFS_H_ #endif // SRC_CORE_DEFS_H_

View File

@ -1,13 +0,0 @@
#ifndef DECLARATIONS_H
#define DECLARATIONS_H
#include <iostream>
#include "core_defs.h"
class ContentBuilder;
extern void setup_bindings();
extern void setup_definitions(ContentBuilder* builder);
#endif // DECLARATIONS_H

View File

@ -37,7 +37,7 @@
#include "frontend/locale/langs.h" #include "frontend/locale/langs.h"
#include "logic/scripting/scripting.h" #include "logic/scripting/scripting.h"
#include "definitions.h" #include "core_defs.h"
namespace fs = std::filesystem; namespace fs = std::filesystem;
@ -148,7 +148,7 @@ inline const std::string checkPacks(const std::unordered_set<std::string>& packs
void Engine::loadContent() { void Engine::loadContent() {
auto resdir = paths->getResources(); auto resdir = paths->getResources();
ContentBuilder contentBuilder; ContentBuilder contentBuilder;
setup_definitions(&contentBuilder); corecontent::setup(&contentBuilder);
paths->setContentPacks(&contentPacks); paths->setContentPacks(&contentPacks);
std::vector<fs::path> resRoots; std::vector<fs::path> resRoots;

View File

@ -5,7 +5,7 @@
#include <filesystem> #include <filesystem>
#include <stdexcept> #include <stdexcept>
#include "definitions.h" #include "core_defs.h"
#include "engine.h" #include "engine.h"
#include "util/platform.h" #include "util/platform.h"
#include "coders/toml.h" #include "coders/toml.h"
@ -38,7 +38,7 @@ int main(int argc, char** argv) {
toml::Reader reader(wrapper.get(), settings_file.string(), text); toml::Reader reader(wrapper.get(), settings_file.string(), text);
reader.read(); reader.read();
} }
setup_bindings(); corecontent::setup_bindings();
Engine engine(settings, &paths); Engine engine(settings, &paths);
if (fs::is_regular_file(controls_file)) { if (fs::is_regular_file(controls_file)) {
std::cout << "-- loading controls" << std::endl; std::cout << "-- loading controls" << std::endl;