From bfe2e2557b870dd703a8e830467e243953e532bd Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 31 Jan 2024 18:14:01 +0300 Subject: [PATCH] minor refactor --- src/{definitions.cpp => core_defs.cpp} | 89 ++++++++++++-------------- src/core_defs.h | 8 ++- src/definitions.h | 13 ---- src/engine.cpp | 4 +- src/voxel_engine.cpp | 4 +- 5 files changed, 53 insertions(+), 65 deletions(-) rename src/{definitions.cpp => core_defs.cpp} (87%) delete mode 100644 src/definitions.h diff --git a/src/definitions.cpp b/src/core_defs.cpp similarity index 87% rename from src/definitions.cpp rename to src/core_defs.cpp index a9243ee4..da3136ba 100644 --- a/src/definitions.cpp +++ b/src/core_defs.cpp @@ -1,48 +1,43 @@ -#include "definitions.h" - -#include - -#include "items/ItemDef.h" -#include "content/Content.h" -#include "window/Window.h" -#include "window/Events.h" -#include "window/input.h" -#include "voxels/Block.h" - -using glm::vec3; - -// All in-game definitions (blocks, items, etc..) -void setup_definitions(ContentBuilder* builder) { // Strange function, need to REDO ? - Block* block = new Block("core:air", "air"); - block->replaceable = true; - block->drawGroup = 1; - block->lightPassing = true; - block->skyLightPassing = true; - block->obstacle = false; - block->selectable = false; - block->model = BlockModel::none; - block->pickingItem = "core:empty"; - builder->add(block); - - ItemDef* item = builder->createItem("core:empty"); - item->iconType = item_icon_type::none; -} - -void setup_bindings() { - Events::bind(BIND_MOVE_FORWARD, inputtype::keyboard, keycode::W); - 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); - Events::bind(BIND_MOVE_JUMP, inputtype::keyboard, keycode::SPACE); - Events::bind(BIND_MOVE_SPRINT, inputtype::keyboard, keycode::LEFT_CONTROL); - Events::bind(BIND_MOVE_CROUCH, inputtype::keyboard, keycode::LEFT_SHIFT); - Events::bind(BIND_MOVE_CHEAT, inputtype::keyboard, keycode::R); - Events::bind(BIND_CAM_ZOOM, inputtype::keyboard, keycode::C); - Events::bind(BIND_CAM_MODE, inputtype::keyboard, keycode::F4); - Events::bind(BIND_PLAYER_NOCLIP, inputtype::keyboard, keycode::N); - 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); +#include "core_defs.h" + +#include "items/ItemDef.h" +#include "content/Content.h" +#include "window/Window.h" +#include "window/Events.h" +#include "window/input.h" +#include "voxels/Block.h" + +// All in-game definitions (blocks, items, etc..) +void corecontent::setup(ContentBuilder* builder) { + Block* block = builder->createBlock("core:air"); + block->replaceable = true; + block->drawGroup = 1; + block->lightPassing = true; + block->skyLightPassing = true; + block->obstacle = false; + block->selectable = false; + block->model = BlockModel::none; + block->pickingItem = "core:empty"; + + ItemDef* item = builder->createItem("core:empty"); + item->iconType = item_icon_type::none; +} + +void corecontent::setup_bindings() { + Events::bind(BIND_MOVE_FORWARD, inputtype::keyboard, keycode::W); + 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); + Events::bind(BIND_MOVE_JUMP, inputtype::keyboard, keycode::SPACE); + Events::bind(BIND_MOVE_SPRINT, inputtype::keyboard, keycode::LEFT_CONTROL); + Events::bind(BIND_MOVE_CROUCH, inputtype::keyboard, keycode::LEFT_SHIFT); + Events::bind(BIND_MOVE_CHEAT, inputtype::keyboard, keycode::R); + Events::bind(BIND_CAM_ZOOM, inputtype::keyboard, keycode::C); + Events::bind(BIND_CAM_MODE, inputtype::keyboard, keycode::F4); + Events::bind(BIND_PLAYER_NOCLIP, inputtype::keyboard, keycode::N); + 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); } \ No newline at end of file diff --git a/src/core_defs.h b/src/core_defs.h index 5cdfbf2b..a813c133 100644 --- a/src/core_defs.h +++ b/src/core_defs.h @@ -3,7 +3,6 @@ #include - const std::string TEXTURE_NOTFOUND = "notfound"; /* 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_HUD_INVENTORY = "hud.inventory"; +class ContentBuilder; + +namespace corecontent { + extern void setup_bindings(); + extern void setup(ContentBuilder* builder); +} + #endif // SRC_CORE_DEFS_H_ \ No newline at end of file diff --git a/src/definitions.h b/src/definitions.h deleted file mode 100644 index 31dc982c..00000000 --- a/src/definitions.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DECLARATIONS_H -#define DECLARATIONS_H - -#include -#include "core_defs.h" - -class ContentBuilder; - -extern void setup_bindings(); -extern void setup_definitions(ContentBuilder* builder); - -#endif // DECLARATIONS_H - diff --git a/src/engine.cpp b/src/engine.cpp index a387cdb2..b6e568d2 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -37,7 +37,7 @@ #include "frontend/locale/langs.h" #include "logic/scripting/scripting.h" -#include "definitions.h" +#include "core_defs.h" namespace fs = std::filesystem; @@ -148,7 +148,7 @@ inline const std::string checkPacks(const std::unordered_set& packs void Engine::loadContent() { auto resdir = paths->getResources(); ContentBuilder contentBuilder; - setup_definitions(&contentBuilder); + corecontent::setup(&contentBuilder); paths->setContentPacks(&contentPacks); std::vector resRoots; diff --git a/src/voxel_engine.cpp b/src/voxel_engine.cpp index a1a3bd11..ec9e470c 100644 --- a/src/voxel_engine.cpp +++ b/src/voxel_engine.cpp @@ -5,7 +5,7 @@ #include #include -#include "definitions.h" +#include "core_defs.h" #include "engine.h" #include "util/platform.h" #include "coders/toml.h" @@ -38,7 +38,7 @@ int main(int argc, char** argv) { toml::Reader reader(wrapper.get(), settings_file.string(), text); reader.read(); } - setup_bindings(); + corecontent::setup_bindings(); Engine engine(settings, &paths); if (fs::is_regular_file(controls_file)) { std::cout << "-- loading controls" << std::endl;