2/15/2026
This commit is contained in:
9
CLAUDE.md
Normal file
9
CLAUDE.md
Normal file
@@ -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
|
||||
```
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#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<const ItemConfig> GetItems() const { return Items; }
|
||||
|
||||
private:
|
||||
std::vector<ItemConfig> Items{};
|
||||
|
||||
@@ -19,15 +19,7 @@ struct InventoryT
|
||||
|
||||
public:
|
||||
InventoryT() = default;
|
||||
InventoryT(const Vector<Ref<ItemConfig>>& items)
|
||||
{
|
||||
Slots = { static_cast<int>(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<int>(items.size()), InventoryMeta{} }; }
|
||||
|
||||
public:
|
||||
IntegralType GetItemsAmount(uint16_t id) const { Assert(id); return Slots[id]; }
|
||||
|
||||
@@ -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<ResourceInfo>()
|
||||
@@ -43,8 +43,23 @@ inline void Flecs_Resource(flecs::world& world)
|
||||
world.component<Renewing>()
|
||||
.add<Freezes, ResourceTick>();
|
||||
|
||||
world.system<ResourceInfo>()
|
||||
world.system<ResourceInfo, ResourceTick>()
|
||||
.without<ResourceHealth>()
|
||||
.each([](ResourceInfo) {});
|
||||
.with<WorldInventory>()
|
||||
.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<ResourceInfo>(info);
|
||||
entity.add<ResourceTick>(tick);
|
||||
}
|
||||
@@ -11,6 +11,15 @@ 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);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "stdint.h"
|
||||
#include "cassert"
|
||||
#include <atomic>
|
||||
#include "Util/Span.h"
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -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<uint16_t>(Items.size() - 1);
|
||||
}
|
||||
@@ -9,7 +9,10 @@ WorldInstance::WorldInstance(const WorldConfig& worldConfig)
|
||||
{
|
||||
RegisterTypes(EcsWorld);
|
||||
|
||||
WorldInventory newInventory = WorldInventory{worldConfig.GetItems().size()};
|
||||
|
||||
EcsWorld.set<WorldConfig>(worldConfig);
|
||||
EcsWorld.set<WorldInventory>(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();
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ int main()
|
||||
config.RegisterItem("Stick");
|
||||
config.RegisterItem("Copper Ore");
|
||||
|
||||
|
||||
WorldInstance worldInstance{ config };
|
||||
|
||||
worldInstance.ProcessFrame();
|
||||
|
||||
std::cout << "test\n";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user