From 22e754cd75df176d7175b303eb3816686795cd4f Mon Sep 17 00:00:00 2001 From: Connor Date: Sun, 15 Feb 2026 18:42:47 +0900 Subject: [PATCH] 2/15/2026 --- CLAUDE.md | 9 +++++++++ CMakeLists.txt | 1 + include/Components/Configs/WorldConfig.hpp | 6 +++++- include/Components/Inventory.hpp | 10 +--------- include/Components/Resource.hpp | 21 ++++++++++++++++++--- include/Core/WorldInstance.h | 9 +++++++++ include/Util/SharedBuffer.h | 1 + src/Components/Config/WorldConfig.cpp | 8 +++++--- src/Core/WorldInstance.cpp | 8 ++++++++ src/main.cpp | 2 +- 10 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..1b7233e --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,9 @@ +# CLAUDE.md + +## Dependencies + +### Flecs (ECS Framework) +Documentation is located at `build/flecs-src/docs/`. If the docs are not available, run CMake to fetch and build dependencies: +``` +cmake -B build +``` diff --git a/CMakeLists.txt b/CMakeLists.txt index ba01e11..0fb0acf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,7 @@ target_include_directories(factory-hole-tests PRIVATE ) target_link_libraries(factory-hole-tests PRIVATE + factory-hole-core doctest::doctest_with_main ) diff --git a/include/Components/Configs/WorldConfig.hpp b/include/Components/Configs/WorldConfig.hpp index 886c326..56ed50c 100644 --- a/include/Components/Configs/WorldConfig.hpp +++ b/include/Components/Configs/WorldConfig.hpp @@ -3,6 +3,7 @@ #include #include +#include "Util/Span.h" #include "flecs.h" #include "ItemConfig.hpp" @@ -12,7 +13,10 @@ class WorldConfig { public: - void RegisterItem(const std::string& name); + uint16_t RegisterItem(const std::string& name); + +public: + tcb::span GetItems() const { return Items; } private: std::vector Items{}; diff --git a/include/Components/Inventory.hpp b/include/Components/Inventory.hpp index f4b6168..7f69409 100644 --- a/include/Components/Inventory.hpp +++ b/include/Components/Inventory.hpp @@ -19,15 +19,7 @@ struct InventoryT public: InventoryT() = default; - InventoryT(const Vector>& items) - { - Slots = { static_cast(items.size()), InventoryMeta{} }; - - for (int i{}; i < items.size(); ++i) - { - DEV_ASSERT(items[i]->Item.ItemID != Item::null); - } - } + InventoryT(size_t itemAmount) { Slots = { static_cast(items.size()), InventoryMeta{} }; } public: IntegralType GetItemsAmount(uint16_t id) const { Assert(id); return Slots[id]; } diff --git a/include/Components/Resource.hpp b/include/Components/Resource.hpp index 4e44605..f8d50be 100644 --- a/include/Components/Resource.hpp +++ b/include/Components/Resource.hpp @@ -5,6 +5,7 @@ #include "flecs.h" #include "Tick.hpp" +#include "Inventory.hpp" struct ResourceInfo { @@ -25,7 +26,6 @@ struct ResourceTick : public TickAccumulator struct Renewing {}; - inline void Flecs_Resource(flecs::world& world) { world.component() @@ -43,8 +43,23 @@ inline void Flecs_Resource(flecs::world& world) world.component() .add(); - world.system() + world.system() .without() - .each([](ResourceInfo) {}); + .with() + .each([](ResourceInfo info, ResourceTick tick, WorldInventory& worldInventory) { + if (tick.Finished()) worldInventory.AddItems(info.ResourceID, 1); + }); +} + +inline void Resource_Ore_Helper(const flecs::entity& entity, uint16_t resourceID, uint16_t gatherTicks) +{ + ResourceInfo info{}; + info.ResourceID = resourceID; + + ResourceTick tick{}; + tick.MaxTick = gatherTicks; + + entity.add(info); + entity.add(tick); } \ No newline at end of file diff --git a/include/Core/WorldInstance.h b/include/Core/WorldInstance.h index 9ea1ffb..ee8e15f 100644 --- a/include/Core/WorldInstance.h +++ b/include/Core/WorldInstance.h @@ -10,6 +10,15 @@ class WorldInstance public: WorldInstance() = default; WorldInstance(const WorldConfig& worldConfig); + + ~WorldInstance() = default; + +public: + void ProcessFrame(); + +public: + flecs::world& GetEcsWorld() { return EcsWorld; } + const flecs::world& GetEcsWorld() const { return EcsWorld; } private: static void RegisterTypes(flecs::world& world); diff --git a/include/Util/SharedBuffer.h b/include/Util/SharedBuffer.h index 093ad2b..323b72d 100644 --- a/include/Util/SharedBuffer.h +++ b/include/Util/SharedBuffer.h @@ -2,6 +2,7 @@ #include "stdint.h" #include "cassert" +#include #include "Util/Span.h" template diff --git a/src/Components/Config/WorldConfig.cpp b/src/Components/Config/WorldConfig.cpp index 8ccbaa9..480e770 100644 --- a/src/Components/Config/WorldConfig.cpp +++ b/src/Components/Config/WorldConfig.cpp @@ -1,13 +1,15 @@ #include "Components/Configs/WorldConfig.hpp" -void WorldConfig::RegisterItem(const std::string& name) +uint16_t WorldConfig::RegisterItem(const std::string& name) { - for (const auto& item : Items) + for (uint16_t i = 0; i < Items.size(); ++i) { - if (item.Name == name) return; + if (Items[i].Name == name) return i; } ItemConfig cfg{}; cfg.Name = name; Items.push_back(std::move(cfg)); + + return static_cast(Items.size() - 1); } \ No newline at end of file diff --git a/src/Core/WorldInstance.cpp b/src/Core/WorldInstance.cpp index 4425881..af02717 100644 --- a/src/Core/WorldInstance.cpp +++ b/src/Core/WorldInstance.cpp @@ -9,7 +9,10 @@ WorldInstance::WorldInstance(const WorldConfig& worldConfig) { RegisterTypes(EcsWorld); + WorldInventory newInventory = WorldInventory{worldConfig.GetItems().size()}; + EcsWorld.set(worldConfig); + EcsWorld.set(newInventory); } void WorldInstance::RegisterTypes(flecs::world &world) @@ -20,3 +23,8 @@ void WorldInstance::RegisterTypes(flecs::world &world) Flecs_Tick(world); Flecs_Resource(world); } + +void WorldInstance::ProcessFrame() +{ + EcsWorld.progress(); +} diff --git a/src/main.cpp b/src/main.cpp index 9ce7fb1..2d6206a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,9 +14,9 @@ int main() config.RegisterItem("Stick"); config.RegisterItem("Copper Ore"); - WorldInstance worldInstance{ config }; + worldInstance.ProcessFrame(); std::cout << "test\n";