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 <glm/glm.hpp>
#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);
}

View File

@ -3,7 +3,6 @@
#include <string>
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_

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 "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<std::string>& packs
void Engine::loadContent() {
auto resdir = paths->getResources();
ContentBuilder contentBuilder;
setup_definitions(&contentBuilder);
corecontent::setup(&contentBuilder);
paths->setContentPacks(&contentPacks);
std::vector<fs::path> resRoots;

View File

@ -5,7 +5,7 @@
#include <filesystem>
#include <stdexcept>
#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;