From d82c821e6f9307bb07bb1301c6b58416daab93b7 Mon Sep 17 00:00:00 2001 From: josh Date: Wed, 19 Feb 2025 03:34:20 -0600 Subject: [PATCH] Added WorldEdit step buttons. --- Client/include/Client/TileTool.hpp | 10 ++++---- Client/src/Client/TileTool.cpp | 30 ++++++++++++++++++++-- ClientApp/src/ClientApp/CaveGameWindow.cpp | 5 ++++ Core/include/Core/World.hpp | 8 +++++- Core/src/Core/World.cpp | 20 +++++++++------ Server/src/Server/GameServer.cpp | 3 +-- 6 files changed, 58 insertions(+), 18 deletions(-) diff --git a/Client/include/Client/TileTool.hpp b/Client/include/Client/TileTool.hpp index 845b28d..f9db601 100644 --- a/Client/include/Client/TileTool.hpp +++ b/Client/include/Client/TileTool.hpp @@ -16,8 +16,8 @@ #include #include -namespace CaveGame::Client -{ +namespace CaveGame::Client { + using namespace JUI; class TileTool : public JUI::Window @@ -26,11 +26,9 @@ namespace CaveGame::Client Event BrushSizeChanged; Event BrushPercentChanged; Event TileSimulationDisabledChanged; - + Event TileSimulationStep; void SetBrushSize(float size); - - explicit TileTool(Widget* parent); void Enable(bool value); bool IsEnabled() const { return enabled; } @@ -40,6 +38,8 @@ namespace CaveGame::Client Slider* brush_size_slider; Slider* brush_percent_slider; TextRect* tool_size_label; + TextButton* step_btn; + TextButton* step2_btn; bool enabled = false; bool tile_sim_disabled; private: diff --git a/Client/src/Client/TileTool.cpp b/Client/src/Client/TileTool.cpp index 7cf5163..e66dfc9 100644 --- a/Client/src/Client/TileTool.cpp +++ b/Client/src/Client/TileTool.cpp @@ -67,14 +67,40 @@ CaveGame::Client::TileTool::TileTool(JUI::Widget *parent) : JUI::Window(parent) brush_percent_slider->CurrentValue(1.f); + auto* tile_sim_checkbox = new Checkbox(right_row_layout); tile_sim_checkbox->Size({row_height, row_height, 0, 0}); - tile_sim_checkbox->OnReleaseEvent += [this] (Vector2 _, JUI::MouseButton _2, bool _3) { + tile_sim_checkbox->OnReleaseEvent += [&, this] (Vector2 _, JUI::MouseButton _2, bool _3) { tile_sim_disabled = !tile_sim_disabled; - TileSimulationDisabledChanged.Invoke(tile_sim_disabled); + step_btn->SetEnabled(tile_sim_disabled); + step2_btn->SetEnabled(tile_sim_disabled); }; + + + step_btn = new TextButton(left_row_layout); + step_btn->Size({100_percent, UDim(row_height, 0)}); + step_btn->SetContent("Step"); + step_btn->BGColor(Colors::LightGray); + step_btn->BaseBGColor(Colors::LightGray); + step_btn->Disable(); + step_btn->OnClickEvent += [&, this] (auto a, auto b) { + TileSimulationStep.Invoke(1); + }; + + step2_btn = new TextButton(right_row_layout); + step2_btn->Size({100_percent, UDim(row_height, 0)}); + step2_btn->SetContent("Step 10"); + step2_btn->BGColor(Colors::LightGray); + step2_btn->BaseBGColor(Colors::LightGray); + step2_btn->Disable(); + step2_btn->OnClickEvent += [&, this] (auto a, auto b) { + TileSimulationStep.Invoke(10); + }; + + + //auto* } void CaveGame::Client::TileTool::SetBrushSize(float size) { diff --git a/ClientApp/src/ClientApp/CaveGameWindow.cpp b/ClientApp/src/ClientApp/CaveGameWindow.cpp index 78a8b11..e3ec07f 100644 --- a/ClientApp/src/ClientApp/CaveGameWindow.cpp +++ b/ClientApp/src/ClientApp/CaveGameWindow.cpp @@ -121,6 +121,11 @@ namespace CaveGame::ClientApp // TODO: Check that current ctx is game context game_ctx->world->SetTileSimulationEnabled(!value); }; + tile_tool->TileSimulationStep += [this] (int steps) { + for (int i = 0; i < steps; i++) { + game_ctx->world->DoTileTiccs(0.f); + } + }; } void CaveGameWindow::create_window_widgets() diff --git a/Core/include/Core/World.hpp b/Core/include/Core/World.hpp index d7534a2..b60830e 100644 --- a/Core/include/Core/World.hpp +++ b/Core/include/Core/World.hpp @@ -36,7 +36,7 @@ namespace CaveGame::Core { public: Event<> OnNextDay; Event<> OnAutosave; - constexpr static float TileTiccRate = 48.f; // Ticcs per second. + constexpr static uint RandomTileTickCoefficient = 100; constexpr static float PeriodicAutosaveIntervalSeconds = 30.f; World() = default; @@ -119,6 +119,8 @@ namespace CaveGame::Core { void DoForcedTileTick(const Vector2i& coords, Chunk* chunk); + void DoTileTiccs(float elapsed); + virtual void Update(float elapsed); virtual void RefreshAll(); @@ -157,6 +159,9 @@ namespace CaveGame::Core { void RequestChunk(const Vector2i& cell); void DropChunk(const Vector2i& cell); + void SetTileTiccRate(float ticcrate); + float GetTileTiccRate() const { return TileTiccRate; } + protected: void SaveChunkToFile(const Vector2i &cell, Chunk* chunk); bool ValidCoords(const Vector2i &cell) const; @@ -177,6 +182,7 @@ namespace CaveGame::Core { ConcurrentQueue ServedChunks; float tile_ticc_counter; + float TileTiccRate = 48.f; // Ticcs per second. private: diff --git a/Core/src/Core/World.cpp b/Core/src/Core/World.cpp index feef5ed..560854c 100644 --- a/Core/src/Core/World.cpp +++ b/Core/src/Core/World.cpp @@ -10,6 +10,17 @@ namespace CaveGame::Core { + + void World::DoTileTiccs(float elapsed) { + for (const auto& [coords, chunk] : loaded_chunks) { + + // TODO: Allow separate toggling of the two tile update types. + + DoRandomTileTick(coords, chunk); + DoForcedTileTick(coords, chunk); + } + } + void CaveGame::Core::World::Update(float elapsed) { for (const auto& [coords, chunk] : loaded_chunks) { @@ -38,14 +49,7 @@ namespace CaveGame::Core if (tile_ticc_counter > 1.f / TileTiccRate) { tile_ticc_counter -= 1.f / TileTiccRate; - for (const auto& [coords, chunk] : loaded_chunks) { - - // TODO: Allow separate toggling of the two tile update types. - - DoRandomTileTick(coords, chunk); - DoForcedTileTick(coords, chunk); - - } + DoTileTiccs(elapsed); } } diff --git a/Server/src/Server/GameServer.cpp b/Server/src/Server/GameServer.cpp index 84a9fc9..57268a9 100644 --- a/Server/src/Server/GameServer.cpp +++ b/Server/src/Server/GameServer.cpp @@ -1,8 +1,7 @@ #include -namespace CaveGame::Server -{ +namespace CaveGame::Server {