Added WorldEdit step buttons.

This commit is contained in:
2025-02-19 03:34:20 -06:00
parent 6ba265e9e2
commit d82c821e6f
6 changed files with 58 additions and 18 deletions

View File

@@ -16,8 +16,8 @@
#include <JUI/Widgets/Checkbox.hpp> #include <JUI/Widgets/Checkbox.hpp>
#include <JUI/Widgets/ListLayout.hpp> #include <JUI/Widgets/ListLayout.hpp>
namespace CaveGame::Client namespace CaveGame::Client {
{
using namespace JUI; using namespace JUI;
class TileTool : public JUI::Window class TileTool : public JUI::Window
@@ -26,11 +26,9 @@ namespace CaveGame::Client
Event<float> BrushSizeChanged; Event<float> BrushSizeChanged;
Event<float> BrushPercentChanged; Event<float> BrushPercentChanged;
Event<bool> TileSimulationDisabledChanged; Event<bool> TileSimulationDisabledChanged;
Event<int> TileSimulationStep;
void SetBrushSize(float size); void SetBrushSize(float size);
explicit TileTool(Widget* parent); explicit TileTool(Widget* parent);
void Enable(bool value); void Enable(bool value);
bool IsEnabled() const { return enabled; } bool IsEnabled() const { return enabled; }
@@ -40,6 +38,8 @@ namespace CaveGame::Client
Slider* brush_size_slider; Slider* brush_size_slider;
Slider* brush_percent_slider; Slider* brush_percent_slider;
TextRect* tool_size_label; TextRect* tool_size_label;
TextButton* step_btn;
TextButton* step2_btn;
bool enabled = false; bool enabled = false;
bool tile_sim_disabled; bool tile_sim_disabled;
private: private:

View File

@@ -67,14 +67,40 @@ CaveGame::Client::TileTool::TileTool(JUI::Widget *parent) : JUI::Window(parent)
brush_percent_slider->CurrentValue(1.f); brush_percent_slider->CurrentValue(1.f);
auto* tile_sim_checkbox = new Checkbox(right_row_layout); auto* tile_sim_checkbox = new Checkbox(right_row_layout);
tile_sim_checkbox->Size({row_height, row_height, 0, 0}); 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; tile_sim_disabled = !tile_sim_disabled;
TileSimulationDisabledChanged.Invoke(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) { void CaveGame::Client::TileTool::SetBrushSize(float size) {

View File

@@ -121,6 +121,11 @@ namespace CaveGame::ClientApp
// TODO: Check that current ctx is game context // TODO: Check that current ctx is game context
game_ctx->world->SetTileSimulationEnabled(!value); 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() void CaveGameWindow::create_window_widgets()

View File

@@ -36,7 +36,7 @@ namespace CaveGame::Core {
public: public:
Event<> OnNextDay; Event<> OnNextDay;
Event<> OnAutosave; Event<> OnAutosave;
constexpr static float TileTiccRate = 48.f; // Ticcs per second.
constexpr static uint RandomTileTickCoefficient = 100; constexpr static uint RandomTileTickCoefficient = 100;
constexpr static float PeriodicAutosaveIntervalSeconds = 30.f; constexpr static float PeriodicAutosaveIntervalSeconds = 30.f;
World() = default; World() = default;
@@ -119,6 +119,8 @@ namespace CaveGame::Core {
void DoForcedTileTick(const Vector2i& coords, Chunk* chunk); void DoForcedTileTick(const Vector2i& coords, Chunk* chunk);
void DoTileTiccs(float elapsed);
virtual void Update(float elapsed); virtual void Update(float elapsed);
virtual void RefreshAll(); virtual void RefreshAll();
@@ -157,6 +159,9 @@ namespace CaveGame::Core {
void RequestChunk(const Vector2i& cell); void RequestChunk(const Vector2i& cell);
void DropChunk(const Vector2i& cell); void DropChunk(const Vector2i& cell);
void SetTileTiccRate(float ticcrate);
float GetTileTiccRate() const { return TileTiccRate; }
protected: protected:
void SaveChunkToFile(const Vector2i &cell, Chunk* chunk); void SaveChunkToFile(const Vector2i &cell, Chunk* chunk);
bool ValidCoords(const Vector2i &cell) const; bool ValidCoords(const Vector2i &cell) const;
@@ -177,6 +182,7 @@ namespace CaveGame::Core {
ConcurrentQueue<Core::Chunk*> ServedChunks; ConcurrentQueue<Core::Chunk*> ServedChunks;
float tile_ticc_counter; float tile_ticc_counter;
float TileTiccRate = 48.f; // Ticcs per second.
private: private:

View File

@@ -10,6 +10,17 @@
namespace CaveGame::Core 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) { void CaveGame::Core::World::Update(float elapsed) {
for (const auto& [coords, chunk] : loaded_chunks) { for (const auto& [coords, chunk] : loaded_chunks) {
@@ -38,14 +49,7 @@ namespace CaveGame::Core
if (tile_ticc_counter > 1.f / TileTiccRate) { if (tile_ticc_counter > 1.f / TileTiccRate) {
tile_ticc_counter -= 1.f / TileTiccRate; tile_ticc_counter -= 1.f / TileTiccRate;
for (const auto& [coords, chunk] : loaded_chunks) { DoTileTiccs(elapsed);
// TODO: Allow separate toggling of the two tile update types.
DoRandomTileTick(coords, chunk);
DoForcedTileTick(coords, chunk);
}
} }
} }

View File

@@ -1,8 +1,7 @@
#include <Server/GameServer.hpp> #include <Server/GameServer.hpp>
namespace CaveGame::Server namespace CaveGame::Server {
{