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
|
target_link_libraries(factory-hole-tests PRIVATE
|
||||||
|
factory-hole-core
|
||||||
doctest::doctest_with_main
|
doctest::doctest_with_main
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "Util/Span.h"
|
||||||
#include "flecs.h"
|
#include "flecs.h"
|
||||||
|
|
||||||
#include "ItemConfig.hpp"
|
#include "ItemConfig.hpp"
|
||||||
@@ -12,7 +13,10 @@
|
|||||||
class WorldConfig
|
class WorldConfig
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void RegisterItem(const std::string& name);
|
uint16_t RegisterItem(const std::string& name);
|
||||||
|
|
||||||
|
public:
|
||||||
|
tcb::span<const ItemConfig> GetItems() const { return Items; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<ItemConfig> Items{};
|
std::vector<ItemConfig> Items{};
|
||||||
|
|||||||
@@ -19,15 +19,7 @@ struct InventoryT
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
InventoryT() = default;
|
InventoryT() = default;
|
||||||
InventoryT(const Vector<Ref<ItemConfig>>& items)
|
InventoryT(size_t itemAmount) { Slots = { static_cast<int>(items.size()), InventoryMeta{} }; }
|
||||||
{
|
|
||||||
Slots = { static_cast<int>(items.size()), InventoryMeta{} };
|
|
||||||
|
|
||||||
for (int i{}; i < items.size(); ++i)
|
|
||||||
{
|
|
||||||
DEV_ASSERT(items[i]->Item.ItemID != Item::null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IntegralType GetItemsAmount(uint16_t id) const { Assert(id); return Slots[id]; }
|
IntegralType GetItemsAmount(uint16_t id) const { Assert(id); return Slots[id]; }
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "flecs.h"
|
#include "flecs.h"
|
||||||
|
|
||||||
#include "Tick.hpp"
|
#include "Tick.hpp"
|
||||||
|
#include "Inventory.hpp"
|
||||||
|
|
||||||
struct ResourceInfo
|
struct ResourceInfo
|
||||||
{
|
{
|
||||||
@@ -25,7 +26,6 @@ struct ResourceTick : public TickAccumulator
|
|||||||
struct Renewing
|
struct Renewing
|
||||||
{};
|
{};
|
||||||
|
|
||||||
|
|
||||||
inline void Flecs_Resource(flecs::world& world)
|
inline void Flecs_Resource(flecs::world& world)
|
||||||
{
|
{
|
||||||
world.component<ResourceInfo>()
|
world.component<ResourceInfo>()
|
||||||
@@ -43,8 +43,23 @@ inline void Flecs_Resource(flecs::world& world)
|
|||||||
world.component<Renewing>()
|
world.component<Renewing>()
|
||||||
.add<Freezes, ResourceTick>();
|
.add<Freezes, ResourceTick>();
|
||||||
|
|
||||||
world.system<ResourceInfo>()
|
world.system<ResourceInfo, ResourceTick>()
|
||||||
.without<ResourceHealth>()
|
.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);
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,15 @@ class WorldInstance
|
|||||||
public:
|
public:
|
||||||
WorldInstance() = default;
|
WorldInstance() = default;
|
||||||
WorldInstance(const WorldConfig& worldConfig);
|
WorldInstance(const WorldConfig& worldConfig);
|
||||||
|
|
||||||
|
~WorldInstance() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void ProcessFrame();
|
||||||
|
|
||||||
|
public:
|
||||||
|
flecs::world& GetEcsWorld() { return EcsWorld; }
|
||||||
|
const flecs::world& GetEcsWorld() const { return EcsWorld; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void RegisterTypes(flecs::world& world);
|
static void RegisterTypes(flecs::world& world);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "cassert"
|
#include "cassert"
|
||||||
|
#include <atomic>
|
||||||
#include "Util/Span.h"
|
#include "Util/Span.h"
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
#include "Components/Configs/WorldConfig.hpp"
|
#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{};
|
ItemConfig cfg{};
|
||||||
cfg.Name = name;
|
cfg.Name = name;
|
||||||
Items.push_back(std::move(cfg));
|
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);
|
RegisterTypes(EcsWorld);
|
||||||
|
|
||||||
|
WorldInventory newInventory = WorldInventory{worldConfig.GetItems().size()};
|
||||||
|
|
||||||
EcsWorld.set<WorldConfig>(worldConfig);
|
EcsWorld.set<WorldConfig>(worldConfig);
|
||||||
|
EcsWorld.set<WorldInventory>(newInventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldInstance::RegisterTypes(flecs::world &world)
|
void WorldInstance::RegisterTypes(flecs::world &world)
|
||||||
@@ -20,3 +23,8 @@ void WorldInstance::RegisterTypes(flecs::world &world)
|
|||||||
Flecs_Tick(world);
|
Flecs_Tick(world);
|
||||||
Flecs_Resource(world);
|
Flecs_Resource(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldInstance::ProcessFrame()
|
||||||
|
{
|
||||||
|
EcsWorld.progress();
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ int main()
|
|||||||
config.RegisterItem("Stick");
|
config.RegisterItem("Stick");
|
||||||
config.RegisterItem("Copper Ore");
|
config.RegisterItem("Copper Ore");
|
||||||
|
|
||||||
|
|
||||||
WorldInstance worldInstance{ config };
|
WorldInstance worldInstance{ config };
|
||||||
|
|
||||||
|
worldInstance.ProcessFrame();
|
||||||
|
|
||||||
std::cout << "test\n";
|
std::cout << "test\n";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user