diff --git a/code/foundation/CMakeLists.txt b/code/foundation/CMakeLists.txt index 4e00983..88b3d4d 100644 --- a/code/foundation/CMakeLists.txt +++ b/code/foundation/CMakeLists.txt @@ -18,13 +18,6 @@ add_library(eco2d-foundation STATIC src/models/prefabs/player.c src/models/prefabs/vehicle.c - src/models/prefabs/storage.c - src/models/prefabs/furnace.c - src/models/prefabs/blueprint.c - src/models/prefabs/splitter.c - src/models/prefabs/craftbench.c - src/models/prefabs/assembler.c - src/models/prefabs/creature.c src/pkt/packet.c diff --git a/code/foundation/src/lists/entity_spawnlist.c b/code/foundation/src/lists/entity_spawnlist.c index de3dd89..8515139 100644 --- a/code/foundation/src/lists/entity_spawnlist.c +++ b/code/foundation/src/lists/entity_spawnlist.c @@ -1,12 +1,5 @@ // NOTE(zaklaus): access to spawners -#include "models/prefabs/storage.h" -#include "models/prefabs/furnace.h" -#include "models/prefabs/blueprint.h" -#include "models/prefabs/craftbench.h" -#include "models/prefabs/splitter.h" -#include "models/prefabs/assembler.h" -#include "models/prefabs/creature.h" - +#include "models/prefabs/prefabs_list.c" static struct { asset_id id; uint64_t (*proc)(); diff --git a/code/foundation/src/lists/prefabs_list.c b/code/foundation/src/lists/prefabs_list.c new file mode 100644 index 0000000..e69de29 diff --git a/code/foundation/src/models/prefabs/assembler.c b/code/foundation/src/models/prefabs/assembler.c deleted file mode 100644 index c91de86..0000000 --- a/code/foundation/src/models/prefabs/assembler.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "assembler.h" -#include "models/device.h" -#include "world/world.h" - -#include "models/entity.h" -#include "models/components.h" - -uint64_t assembler_spawn(void) { - ecs_entity_t e = device_spawn(ASSET_ASSEMBLER); - - ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); - *storage = (ItemContainer){0}; - - Producer *producer = ecs_get_mut(world_ecs(), e, Producer); - *producer = (Producer){0}; - producer->energy_level = 69.0f; - producer->pending_task = PRODUCER_CRAFT_AUTO; - producer->push_filter = PRODUCER_PUSH_PRODUCT; - producer->target_item = ASSET_INVALID; - - ecs_set(world_ecs(), e, ItemRouter, {.push_qty = 1, .counter = 0}); - return (uint64_t)e; -} - -void assembler_despawn(uint64_t ent_id) { - entity_despawn(ent_id); -} diff --git a/code/foundation/src/models/prefabs/assembler.h b/code/foundation/src/models/prefabs/assembler.h deleted file mode 100644 index 0ab04fe..0000000 --- a/code/foundation/src/models/prefabs/assembler.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "platform/system.h" - -uint64_t assembler_spawn(void); -void assembler_despawn(uint64_t id); diff --git a/code/foundation/src/models/prefabs/blueprint.c b/code/foundation/src/models/prefabs/blueprint.c deleted file mode 100644 index 29d24f0..0000000 --- a/code/foundation/src/models/prefabs/blueprint.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "vehicle.h" - -#include "world/entity_view.h" -#include "world/world.h" - -#include "models/device.h" -#include "models/entity.h" -#include "models/items.h" -#include "models/components.h" - -uint64_t blueprint_spawn(uint8_t w, uint8_t h, const asset_id *plan) { - ZPL_ASSERT((w*h) < 256); - ecs_entity_t e = device_spawn(ASSET_BLUEPRINT); - - Blueprint *blueprint = ecs_get_mut(world_ecs(), e, Blueprint); - blueprint->w = w; - blueprint->h = h; - zpl_memcopy(blueprint->plan, plan, w*h*sizeof(asset_id)); - - return (uint64_t)e; -} - -uint64_t blueprint_spawn_udata(void* udata) { - item_desc *it = (item_desc*)udata; - return blueprint_spawn(it->blueprint.w, it->blueprint.h, it->blueprint.plan); -} - -void blueprint_despawn(uint64_t id) { - entity_despawn(id); -} diff --git a/code/foundation/src/models/prefabs/blueprint.h b/code/foundation/src/models/prefabs/blueprint.h deleted file mode 100644 index 38180d2..0000000 --- a/code/foundation/src/models/prefabs/blueprint.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "platform/system.h" - -uint64_t blueprint_spawn(uint8_t w, uint8_t h, const uint16_t *plan); -uint64_t blueprint_spawn_udata(void* udata); -void blueprint_despawn(uint64_t id); - - diff --git a/code/foundation/src/models/prefabs/craftbench.c b/code/foundation/src/models/prefabs/craftbench.c deleted file mode 100644 index 704adc8..0000000 --- a/code/foundation/src/models/prefabs/craftbench.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "craftbench.h" -#include "models/device.h" -#include "world/world.h" - -#include "models/entity.h" -#include "models/components.h" - -uint64_t craftbench_spawn(void) { - ecs_entity_t e = device_spawn(ASSET_CRAFTBENCH); - - ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); - *storage = (ItemContainer){0}; - - Producer *producer = ecs_get_mut(world_ecs(), e, Producer); - *producer = (Producer){0}; - producer->energy_level = 69.0f; - producer->pending_task = PRODUCER_CRAFT_WAITING; - producer->push_filter = PRODUCER_PUSH_NONE; - return (uint64_t)e; -} - -void craftbench_despawn(uint64_t ent_id) { - entity_despawn(ent_id); -} diff --git a/code/foundation/src/models/prefabs/craftbench.h b/code/foundation/src/models/prefabs/craftbench.h deleted file mode 100644 index a9a7491..0000000 --- a/code/foundation/src/models/prefabs/craftbench.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "platform/system.h" - -uint64_t craftbench_spawn(void); -void craftbench_despawn(uint64_t id); - diff --git a/code/foundation/src/models/prefabs/creature.c b/code/foundation/src/models/prefabs/creature.c deleted file mode 100644 index 196116b..0000000 --- a/code/foundation/src/models/prefabs/creature.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "creature.h" -#include "world/world.h" - -#include "models/entity.h" -#include "world/entity_view.h" -#include "models/components.h" - -uint64_t creature_spawn(void) { - ecs_entity_t e = entity_spawn(EKIND_DEMO_NPC); - - Creature *c = ecs_get_mut_ex(world_ecs(), e, Creature); - c->hunger_satisfied = 0; - c->mating_satisfied = rand() % 1800; - c->life_remaining = 500 + rand() % 5200; - - return (uint64_t)e; -} - -void creature_despawn(uint64_t ent_id) { - entity_despawn(ent_id); -} diff --git a/code/foundation/src/models/prefabs/creature.h b/code/foundation/src/models/prefabs/creature.h deleted file mode 100644 index fb28c15..0000000 --- a/code/foundation/src/models/prefabs/creature.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "platform/system.h" - -uint64_t creature_spawn(void); -void creature_despawn(uint64_t id); diff --git a/code/foundation/src/models/prefabs/furnace.c b/code/foundation/src/models/prefabs/furnace.c deleted file mode 100644 index f520b1a..0000000 --- a/code/foundation/src/models/prefabs/furnace.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "furnace.h" -#include "models/device.h" -#include "world/world.h" - -#include "models/entity.h" -#include "models/components.h" - -uint64_t furnace_spawn(void) { - ecs_entity_t e = device_spawn(ASSET_FURNACE); - - ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); - *storage = (ItemContainer){0}; - - Producer *producer = ecs_get_mut(world_ecs(), e, Producer); - *producer = (Producer){0}; - producer->energy_level = 69.0f; - producer->pending_task = PRODUCER_CRAFT_AUTO; - producer->push_filter = PRODUCER_PUSH_ANY; - - ecs_set(world_ecs(), e, ItemRouter, {.push_qty = 1, .counter = 0}); - return (uint64_t)e; -} - -void furnace_despawn(uint64_t ent_id) { - entity_despawn(ent_id); -} diff --git a/code/foundation/src/models/prefabs/furnace.h b/code/foundation/src/models/prefabs/furnace.h deleted file mode 100644 index 5a91baf..0000000 --- a/code/foundation/src/models/prefabs/furnace.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "platform/system.h" - -uint64_t furnace_spawn(void); -void furnace_despawn(uint64_t id); - diff --git a/code/foundation/src/models/prefabs/prefabs_list.c b/code/foundation/src/models/prefabs/prefabs_list.c new file mode 100644 index 0000000..c757478 --- /dev/null +++ b/code/foundation/src/models/prefabs/prefabs_list.c @@ -0,0 +1,119 @@ +#include "models/device.h" +#include "models/assets.h" +#include "world/world.h" +#include "models/components.h" +#include "world/entity_view.h" +#include "world/world.h" +#include "models/device.h" +#include "models/entity.h" +#include "models/items.h" +#include "models/components.h" + +//------------------------------------------------------------------------ + +uint64_t assembler_spawn(void) { + ecs_entity_t e = device_spawn(ASSET_ASSEMBLER); + + ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); + *storage = (ItemContainer){0}; + + Producer *producer = ecs_get_mut(world_ecs(), e, Producer); + *producer = (Producer){0}; + producer->energy_level = 69.0f; + producer->pending_task = PRODUCER_CRAFT_AUTO; + producer->push_filter = PRODUCER_PUSH_PRODUCT; + producer->target_item = ASSET_INVALID; + + ecs_set(world_ecs(), e, ItemRouter, {.push_qty = 1, .counter = 0}); + return (uint64_t)e; +} + +//------------------------------------------------------------------------ + +uint64_t blueprint_spawn(uint8_t w, uint8_t h, const asset_id *plan) { + ZPL_ASSERT((w*h) < 256); + ecs_entity_t e = device_spawn(ASSET_BLUEPRINT); + + Blueprint *blueprint = ecs_get_mut(world_ecs(), e, Blueprint); + blueprint->w = w; + blueprint->h = h; + zpl_memcopy(blueprint->plan, plan, w*h*sizeof(asset_id)); + + return (uint64_t)e; +} + +uint64_t blueprint_spawn_udata(void* udata) { + item_desc *it = (item_desc*)udata; + return blueprint_spawn(it->blueprint.w, it->blueprint.h, it->blueprint.plan); +} + +//------------------------------------------------------------------------ + +uint64_t craftbench_spawn(void) { + ecs_entity_t e = device_spawn(ASSET_CRAFTBENCH); + + ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); + *storage = (ItemContainer){0}; + + Producer *producer = ecs_get_mut(world_ecs(), e, Producer); + *producer = (Producer){0}; + producer->energy_level = 69.0f; + producer->pending_task = PRODUCER_CRAFT_WAITING; + producer->push_filter = PRODUCER_PUSH_NONE; + return (uint64_t)e; +} + +//------------------------------------------------------------------------ + +uint64_t creature_spawn(void) { + ecs_entity_t e = entity_spawn(EKIND_DEMO_NPC); + + Creature *c = ecs_get_mut_ex(world_ecs(), e, Creature); + c->hunger_satisfied = 0; + c->mating_satisfied = rand() % 1800; + c->life_remaining = 500 + rand() % 5200; + + return (uint64_t)e; +} + +//------------------------------------------------------------------------ + +uint64_t furnace_spawn(void) { + ecs_entity_t e = device_spawn(ASSET_FURNACE); + + ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); + *storage = (ItemContainer){0}; + + Producer *producer = ecs_get_mut(world_ecs(), e, Producer); + *producer = (Producer){0}; + producer->energy_level = 69.0f; + producer->pending_task = PRODUCER_CRAFT_AUTO; + producer->push_filter = PRODUCER_PUSH_ANY; + + ecs_set(world_ecs(), e, ItemRouter, {.push_qty = 1, .counter = 0}); + return (uint64_t)e; +} + +//------------------------------------------------------------------------ + +uint64_t splitter_spawn(void) { + ecs_entity_t e = device_spawn(ASSET_SPLITTER); + + ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); + *storage = (ItemContainer){0}; + + ecs_set(world_ecs(), e, ItemRouter, {.push_qty = 1, .counter = 0}); + return (uint64_t)e; +} + +//------------------------------------------------------------------------ + +uint64_t storage_spawn(void) { + ecs_entity_t e = device_spawn(ASSET_CHEST); + + ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); + *storage = (ItemContainer){0}; + return (uint64_t)e; +} + +//------------------------------------------------------------------------ \ No newline at end of file diff --git a/code/foundation/src/models/prefabs/splitter.c b/code/foundation/src/models/prefabs/splitter.c deleted file mode 100644 index 51ad3c2..0000000 --- a/code/foundation/src/models/prefabs/splitter.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "splitter.h" -#include "models/device.h" -#include "world/world.h" - -#include "models/entity.h" -#include "models/components.h" - -uint64_t splitter_spawn(void) { - ecs_entity_t e = device_spawn(ASSET_SPLITTER); - - ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); - *storage = (ItemContainer){0}; - - ecs_set(world_ecs(), e, ItemRouter, {.push_qty = 1, .counter = 0}); - return (uint64_t)e; -} - -void splitter_despawn(uint64_t ent_id) { - entity_despawn(ent_id); -} diff --git a/code/foundation/src/models/prefabs/splitter.h b/code/foundation/src/models/prefabs/splitter.h deleted file mode 100644 index b25eea0..0000000 --- a/code/foundation/src/models/prefabs/splitter.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "platform/system.h" - -uint64_t splitter_spawn(void); -void splitter_despawn(uint64_t id); - diff --git a/code/foundation/src/models/prefabs/storage.c b/code/foundation/src/models/prefabs/storage.c deleted file mode 100644 index a220bba..0000000 --- a/code/foundation/src/models/prefabs/storage.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "storage.h" -#include "models/device.h" -#include "world/world.h" - -#include "models/entity.h" -#include "models/components.h" - -uint64_t storage_spawn(void) { - ecs_entity_t e = device_spawn(ASSET_CHEST); - - ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); - *storage = (ItemContainer){0}; - return (uint64_t)e; -} - -void storage_despawn(uint64_t ent_id) { - entity_despawn(ent_id); -} diff --git a/code/foundation/src/models/prefabs/storage.h b/code/foundation/src/models/prefabs/storage.h deleted file mode 100644 index 734b14c..0000000 --- a/code/foundation/src/models/prefabs/storage.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "platform/system.h" - -uint64_t storage_spawn(void); -void storage_despawn(uint64_t id); -