From 0edb71385fa74fcb5af4c30e57517cd217ad4a52 Mon Sep 17 00:00:00 2001 From: szdytom Date: Tue, 5 Aug 2025 16:09:37 +0800 Subject: [PATCH] feat: implement TickSystem for managing world ticks and initialize World constructor Signed-off-by: szdytom --- core/include/istd_core/world.h | 4 ++++ core/src/world.cpp | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 core/src/world.cpp diff --git a/core/include/istd_core/world.h b/core/include/istd_core/world.h index 3ace3d4..857b93e 100644 --- a/core/include/istd_core/world.h +++ b/core/include/istd_core/world.h @@ -2,17 +2,21 @@ #define ISTD_CORE_WORLD_H #include "istd_core/room.h" +#include "tilemap/generation.h" #include "tilemap/tilemap.h" #include namespace istd { struct World { + std::uint32_t tick; TileMap tilemap; std::vector> rooms; entt::registry registry; World(std::uint8_t size); + + void generateTilemap(const GenerationConfig &config); }; } // namespace istd diff --git a/core/src/world.cpp b/core/src/world.cpp new file mode 100644 index 0000000..3875f56 --- /dev/null +++ b/core/src/world.cpp @@ -0,0 +1,39 @@ +#include "istd_core/world.h" +#include "istd_core/system.h" +#include "tilemap/generation.h" + +namespace istd { + +namespace { + +struct TickSystem : public System { + void tick(World &world) const noexcept override { + world.tick += 1; + } + + std::string_view name() const noexcept override { + return "Tick System"; + } +}; + +static const TickSystem tick_system; +static const SystemRegistry::Registar tick_registrar( + System::Precedence::Highest, &tick_system +); + +} // namespace + +World::World(std::uint8_t size) + : tick(0), tilemap(size), rooms(size, std::vector(size, {0, 0})) { + for (std::uint8_t x = 0; x < size; ++x) { + for (std::uint8_t y = 0; y < size; ++y) { + rooms[x][y] = {x, y}; + } + } +} + +void World::generateTilemap(const GenerationConfig &config) { + map_generate(tilemap, config); +} + +} // namespace istd