simplify prefabs
parent
1c68c73028
commit
36a4a010c8
|
@ -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
|
||||
|
||||
|
|
|
@ -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)();
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "platform/system.h"
|
||||
|
||||
uint64_t assembler_spawn(void);
|
||||
void assembler_despawn(uint64_t id);
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "platform/system.h"
|
||||
|
||||
uint64_t craftbench_spawn(void);
|
||||
void craftbench_despawn(uint64_t id);
|
||||
|
|
@ -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);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "platform/system.h"
|
||||
|
||||
uint64_t creature_spawn(void);
|
||||
void creature_despawn(uint64_t id);
|
|
@ -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);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "platform/system.h"
|
||||
|
||||
uint64_t furnace_spawn(void);
|
||||
void furnace_despawn(uint64_t id);
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
|
@ -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);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "platform/system.h"
|
||||
|
||||
uint64_t splitter_spawn(void);
|
||||
void splitter_despawn(uint64_t id);
|
||||
|
|
@ -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);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "platform/system.h"
|
||||
|
||||
uint64_t storage_spawn(void);
|
||||
void storage_despawn(uint64_t id);
|
||||
|
Loading…
Reference in New Issue