diff --git a/src/files/settings_io.cpp b/src/files/settings_io.cpp index 2a67fb34..1c488a82 100644 --- a/src/files/settings_io.cpp +++ b/src/files/settings_io.cpp @@ -12,79 +12,79 @@ #include "../data/dynamic.h" toml::Wrapper* create_wrapper(EngineSettings& settings) { - std::unique_ptr wrapper (new toml::Wrapper()); - toml::Section& display = wrapper->add("display"); - display.add("fullscreen", &settings.display.fullscreen); - display.add("width", &settings.display.width); - display.add("height", &settings.display.height); - display.add("samples", &settings.display.samples); - display.add("swap-interval", &settings.display.swapInterval); + std::unique_ptr wrapper (new toml::Wrapper()); + toml::Section& display = wrapper->add("display"); + display.add("fullscreen", &settings.display.fullscreen); + display.add("width", &settings.display.width); + display.add("height", &settings.display.height); + display.add("samples", &settings.display.samples); + display.add("swap-interval", &settings.display.swapInterval); - toml::Section& chunks = wrapper->add("chunks"); - chunks.add("load-distance", &settings.chunks.loadDistance); - chunks.add("load-speed", &settings.chunks.loadSpeed); - chunks.add("padding", &settings.chunks.padding); - - toml::Section& camera = wrapper->add("camera"); - camera.add("fov-effects", &settings.camera.fovEvents); - camera.add("fov", &settings.camera.fov); - camera.add("shaking", &settings.camera.shaking); - camera.add("sensitivity", &settings.camera.sensitivity); + toml::Section& chunks = wrapper->add("chunks"); + chunks.add("load-distance", &settings.chunks.loadDistance); + chunks.add("load-speed", &settings.chunks.loadSpeed); + chunks.add("padding", &settings.chunks.padding); + + toml::Section& camera = wrapper->add("camera"); + camera.add("fov-effects", &settings.camera.fovEvents); + camera.add("fov", &settings.camera.fov); + camera.add("shaking", &settings.camera.shaking); + camera.add("sensitivity", &settings.camera.sensitivity); - toml::Section& graphics = wrapper->add("graphics"); + toml::Section& graphics = wrapper->add("graphics"); graphics.add("gamma", &settings.graphics.gamma); - graphics.add("fog-curve", &settings.graphics.fogCurve); - graphics.add("backlight", &settings.graphics.backlight); - graphics.add("frustum-culling", &settings.graphics.frustumCulling); - graphics.add("skybox-resolution", &settings.graphics.skyboxResolution); + graphics.add("fog-curve", &settings.graphics.fogCurve); + graphics.add("backlight", &settings.graphics.backlight); + graphics.add("frustum-culling", &settings.graphics.frustumCulling); + graphics.add("skybox-resolution", &settings.graphics.skyboxResolution); - toml::Section& debug = wrapper->add("debug"); - debug.add("generator-test-mode", &settings.debug.generatorTestMode); - debug.add("show-chunk-borders", &settings.debug.showChunkBorders); - debug.add("do-write-lights", &settings.debug.doWriteLights); + toml::Section& debug = wrapper->add("debug"); + debug.add("generator-test-mode", &settings.debug.generatorTestMode); + debug.add("show-chunk-borders", &settings.debug.showChunkBorders); + debug.add("do-write-lights", &settings.debug.doWriteLights); toml::Section& ui = wrapper->add("ui"); ui.add("language", &settings.ui.language); - return wrapper.release(); + return wrapper.release(); } std::string write_controls() { - dynamic::Map obj; - for (auto& entry : Events::bindings) { - const auto& binding = entry.second; + dynamic::Map obj; + for (auto& entry : Events::bindings) { + const auto& binding = entry.second; auto& jentry = obj.putMap(entry.first); - switch (binding.type) { - case inputtype::keyboard: jentry.put("type", "keyboard"); break; - case inputtype::mouse: jentry.put("type", "mouse"); break; - default: throw std::runtime_error("unsupported control type"); - } - jentry.put("code", binding.code); - } - return json::stringify(&obj, true, " "); + switch (binding.type) { + case inputtype::keyboard: jentry.put("type", "keyboard"); break; + case inputtype::mouse: jentry.put("type", "mouse"); break; + default: throw std::runtime_error("unsupported control type"); + } + jentry.put("code", binding.code); + } + return json::stringify(&obj, true, " "); } void load_controls(std::string filename, std::string source) { auto obj = json::parse(filename, source); - for (auto& entry : Events::bindings) { - auto& binding = entry.second; + for (auto& entry : Events::bindings) { + auto& binding = entry.second; - auto jentry = obj->map(entry.first); - if (jentry == nullptr) - continue; - inputtype type; - std::string typestr; - jentry->str("type", typestr); + auto jentry = obj->map(entry.first); + if (jentry == nullptr) + continue; + inputtype type; + std::string typestr; + jentry->str("type", typestr); - if (typestr == "keyboard") { - type = inputtype::keyboard; - } else if (typestr == "mouse") { - type = inputtype::mouse; - } else { - std::cerr << "unknown input type '" << typestr << "'" << std::endl; - continue; - } - binding.type = type; - jentry->num("code", binding.code); - } + if (typestr == "keyboard") { + type = inputtype::keyboard; + } else if (typestr == "mouse") { + type = inputtype::mouse; + } else { + std::cerr << "unknown input type '" << typestr << "'" << std::endl; + continue; + } + binding.type = type; + jentry->num("code", binding.code); + } } diff --git a/src/frontend/InventoryView.cpp b/src/frontend/InventoryView.cpp index 332cab33..0ca2b752 100644 --- a/src/frontend/InventoryView.cpp +++ b/src/frontend/InventoryView.cpp @@ -34,35 +34,25 @@ SlotLayout::SlotLayout( slotcallback updateFunc, slotcallback shareFunc, slotcallback rightClick -) - : index(index), - position(position), - background(background), - itemSource(itemSource), - updateFunc(updateFunc), - shareFunc(shareFunc), - rightClick(rightClick) {} +) : index(index), + position(position), + background(background), + itemSource(itemSource), + updateFunc(updateFunc), + shareFunc(shareFunc), + rightClick(rightClick) {} InventoryBuilder::InventoryBuilder() { view = std::make_shared(); } -/** Add slots grid to inventory view - * @param cols grid columns - * @param count total number of grid slots - * @param pos position of the first slot of the grid - * @param padding additional space around the grid - * @param addpanel automatically create panel behind the grid - * with size including padding - * @param slotLayout slot settings (index and position are ignored) - */ void InventoryBuilder::addGrid( int cols, int count, glm::vec2 pos, int padding, bool addpanel, - SlotLayout slotLayout) -{ + SlotLayout slotLayout +) { const int slotSize = InventoryView::SLOT_SIZE; const int interval = InventoryView::SLOT_INTERVAL; @@ -88,8 +78,9 @@ void InventoryBuilder::addGrid( for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { - if (row * cols + col >= count) + if (row * cols + col >= count) { break; + } glm::vec2 position ( col * (slotSize + interval) + padding, row * (slotSize + interval) + padding @@ -122,14 +113,13 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) { if (bound == nullptr) return; + const int slotSize = InventoryView::SLOT_SIZE; + ItemStack& stack = *bound; - - glm::vec2 pos = calcPos(); - - int slotSize = InventoryView::SLOT_SIZE; - glm::vec4 tint(1.0f); + glm::vec2 pos = calcPos(); glm::vec4 color = getColor(); + if (hover || highlighted) { tint *= 1.333f; color = glm::vec4(1, 1, 1, 0.2f); diff --git a/src/frontend/InventoryView.h b/src/frontend/InventoryView.h index 81e8a4e8..e7a49af1 100644 --- a/src/frontend/InventoryView.h +++ b/src/frontend/InventoryView.h @@ -48,13 +48,15 @@ struct SlotLayout { slotcallback rightClick; int padding = 0; - SlotLayout(int index, - glm::vec2 position, - bool background, - bool itemSource, - slotcallback updateFunc, - slotcallback shareFunc, - slotcallback rightClick); + SlotLayout( + int index, + glm::vec2 position, + bool background, + bool itemSource, + slotcallback updateFunc, + slotcallback shareFunc, + slotcallback rightClick + ); }; class SlotView : public gui::UINode { @@ -135,6 +137,14 @@ class InventoryBuilder { public: InventoryBuilder(); + /// @brief Add slots grid to inventory view + /// @param cols grid columns + /// @param count total number of grid slots + /// @param pos position of the first slot of the grid + /// @param padding additional space around the grid + /// @param addpanel automatically create panel behind the grid + /// with size including padding + /// @param slotLayout slot settings (index and position are ignored) void addGrid( int cols, int count, glm::vec2 pos, diff --git a/src/settings.h b/src/settings.h index 2aa00615..ad57b0ee 100644 --- a/src/settings.h +++ b/src/settings.h @@ -7,59 +7,59 @@ #include "typedefs.h" struct DisplaySettings { - /* Is window in full screen mode */ - bool fullscreen = false; - /* Window width (pixels) */ - int width = 1280; - /* Window height (pixels) */ - int height = 720; - /* Anti-aliasing samples */ - int samples = 0; - /* GLFW swap interval value, 0 - unlimited fps, 1 - vsync*/ - int swapInterval = 1; - /* Window title */ - std::string title = "VoxelEngine-Cpp v" + - std::to_string(ENGINE_VERSION_MAJOR) + "." + - std::to_string(ENGINE_VERSION_MINOR); + /// @brief Is window in full screen mode + bool fullscreen = false; + /// @brief Window width (pixels) + int width = 1280; + /// @brief Window height (pixels) + int height = 720; + /// @brief Anti-aliasing samples + int samples = 0; + /// @brief GLFW swap interval value, 0 - unlimited fps, 1 - vsync + int swapInterval = 1; + /// @brief Window title */ + std::string title = "VoxelEngine-Cpp v" + + std::to_string(ENGINE_VERSION_MAJOR) + "." + + std::to_string(ENGINE_VERSION_MINOR); }; struct ChunksSettings { - /* Max milliseconds that engine uses for chunks loading only */ - uint loadSpeed = 4; - /* Radius of chunks loading zone (chunk is unit) */ - uint loadDistance = 22; - /* Buffer zone where chunks are not unloading (chunk is unit)*/ - uint padding = 2; + /// @brief Max milliseconds that engine uses for chunks loading only + uint loadSpeed = 4; + /// @brief Radius of chunks loading zone (chunk is unit) + uint loadDistance = 22; + /// @brief Buffer zone where chunks are not unloading (chunk is unit) + uint padding = 2; }; struct CameraSettings { - /* Camera dynamic field of view effects */ + /// @brief Camera dynamic field of view effects bool fovEvents = true; - /* Camera movement shake */ + /// @brief Camera movement shake bool shaking = true; - /* Camera field of view */ - float fov = 90.0f; - /* Camera sensitivity */ - float sensitivity = 2.0f; + /// @brief Camera field of view + float fov = 90.0f; + /// @brief Camera sensitivity + float sensitivity = 2.0f; }; struct GraphicsSettings { - /* Fog opacity is calculated as `pow(depth*k, fogCurve)` where k depends on chunksLoadDistance. - Use values in range [1.0 - 2.0] where 1.0 is linear, 2.0 is quadratic */ - float fogCurve = 1.6f; + /// @brief Fog opacity is calculated as `pow(depth*k, fogCurve)` where k depends on chunksLoadDistance. + /// Use values in range [1.0 - 2.0] where 1.0 is linear, 2.0 is quadratic + float fogCurve = 1.6f; float gamma = 1.0f; - /* Enable blocks backlight to prevent complete darkness */ - bool backlight = true; - /* Enable chunks frustum culling */ - bool frustumCulling = true; - int skyboxResolution = 64 + 32; + /// @brief Enable blocks backlight to prevent complete darkness + bool backlight = true; + /// @brief Enable chunks frustum culling */ + bool frustumCulling = true; + int skyboxResolution = 64 + 32; }; struct DebugSettings { - /* Turns off chunks saving/loading */ - bool generatorTestMode = false; - bool showChunkBorders = false; - bool doWriteLights = true; + /// @brief Turns off chunks saving/loading + bool generatorTestMode = false; + bool showChunkBorders = false; + bool doWriteLights = true; }; struct UiSettings { @@ -68,10 +68,10 @@ struct UiSettings { struct EngineSettings { DisplaySettings display; - ChunksSettings chunks; - CameraSettings camera; - GraphicsSettings graphics; - DebugSettings debug; + ChunksSettings chunks; + CameraSettings camera; + GraphicsSettings graphics; + DebugSettings debug; UiSettings ui; }; diff --git a/src/voxels/ChunksStorage.cpp b/src/voxels/ChunksStorage.cpp index 4d97de42..6d751369 100644 --- a/src/voxels/ChunksStorage.cpp +++ b/src/voxels/ChunksStorage.cpp @@ -75,7 +75,7 @@ std::shared_ptr ChunksStorage::create(int x, int z) { return chunk; } -// some magic code +// reduce nesting on next modification void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const { const Content* content = level->content; auto indices = content->getIndices();