introduce entity spawndefs
parent
e84de812a0
commit
04e257ec61
|
@ -45,6 +45,20 @@ void entity_despawn(uint64_t ent_id) {
|
|||
ecs_delete(world_ecs(), ent_id);
|
||||
}
|
||||
|
||||
// NOTE(zaklaus): bring in entity spawnlist
|
||||
#include "entity_spawnlist.c"
|
||||
|
||||
uint64_t entity_spawn_id(uint16_t id){
|
||||
for (size_t i = 0; i < MAX_ENTITY_SPAWNDEFS; ++i){
|
||||
if (entity_spawnlist[i].id == id){
|
||||
ZPL_ASSERT(entity_spawnlist[i].proc);
|
||||
return entity_spawnlist[i].proc();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void entity_set_position(uint64_t ent_id, float x, float y) {
|
||||
Position *p = ecs_get_mut(world_ecs(), ent_id, Position);
|
||||
p->x = x;
|
||||
|
|
|
@ -8,6 +8,8 @@ void entity_batch_despawn(uint64_t *ids, size_t num_ids);
|
|||
void entity_despawn(uint64_t ent_id);
|
||||
void entity_set_position(uint64_t ent_id, float x, float y);
|
||||
|
||||
uint64_t entity_spawn_id(uint16_t id);
|
||||
|
||||
// NOTE(zaklaus): action-based entity stream throttling
|
||||
void entity_wake(uint64_t ent_id);
|
||||
void entity_update_action_timers();
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
// NOTE(zaklaus): access to spawners
|
||||
#include "storage.h"
|
||||
|
||||
struct {
|
||||
asset_id id;
|
||||
uint64_t (*proc)();
|
||||
} entity_spawnlist[] = {
|
||||
{ .id = ASSET_CHEST, .proc = storage_spawn }
|
||||
};
|
||||
|
||||
#define MAX_ENTITY_SPAWNDEFS ((sizeof(entity_spawnlist))/(sizeof(entity_spawnlist[0])))
|
|
@ -67,6 +67,11 @@ void buildmode_draw(void) {
|
|||
qty = item->quantity;
|
||||
}
|
||||
|
||||
world_block_lookup l = world_block_from_realpos((float)cam.x, (float)cam.y);
|
||||
if (build_is_deletion_mode && !l.is_outer){
|
||||
goto build_skip_placements;
|
||||
}
|
||||
|
||||
if (build_is_in_draw_mode) {
|
||||
for (size_t i = 0; i < BUILD_MAX_PLACEMENTS; i++) {
|
||||
item_placement *it = &build_placements[i];
|
||||
|
@ -96,9 +101,11 @@ void buildmode_draw(void) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (!is_outside_range)
|
||||
renderer_draw_single((float)cam.x, (float)cam.y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(build_is_deletion_mode ? RED : WHITE, 0.2f));
|
||||
|
||||
build_skip_placements:
|
||||
build_num_placements = zpl_min(build_num_placements, qty);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ void item_use(ecs_world_t *ecs, ItemDrop *it, Position p, uint64_t udata) {
|
|||
return;
|
||||
}
|
||||
|
||||
ecs_entity_t e = desc->place_item.spawn_proc();
|
||||
ecs_entity_t e = entity_spawn_id(desc->place_item.id);
|
||||
ZPL_ASSERT(world_entity_valid(e));
|
||||
Position *pos = ecs_get_mut(ecs, e, Position);
|
||||
pos->x = p.x;
|
||||
|
|
|
@ -34,7 +34,7 @@ typedef struct {
|
|||
} proxy;
|
||||
|
||||
struct {
|
||||
uint64_t (*spawn_proc)();
|
||||
asset_id id;
|
||||
} place_item;
|
||||
};
|
||||
} item_desc;
|
||||
|
|
|
@ -38,22 +38,19 @@
|
|||
}\
|
||||
}
|
||||
|
||||
#define ITEM_ENT(asset, qty, proc)\
|
||||
#define ITEM_ENT(asset, qty, eid)\
|
||||
{\
|
||||
.kind = asset,\
|
||||
.usage = UKIND_PLACE_ITEM,\
|
||||
.max_quantity = qty,\
|
||||
.place_item = {\
|
||||
.spawn_proc = proc\
|
||||
.id = eid\
|
||||
}\
|
||||
}
|
||||
|
||||
#define ITEM_SELF(asset, qty) ITEM_BLOCK(asset, qty, asset)
|
||||
#define ITEM_SELF_DIR(asset, qty) ITEM_BLOCK_DIR(asset, qty, asset)
|
||||
|
||||
// NOTE(zaklaus): access to spawners
|
||||
#include "storage.h"
|
||||
|
||||
static item_desc items[] = {
|
||||
{
|
||||
.kind = 0,
|
||||
|
@ -70,5 +67,5 @@ static item_desc items[] = {
|
|||
ITEM_PROXY(ASSET_BELT_UP, ASSET_BELT),
|
||||
ITEM_PROXY(ASSET_BELT_DOWN, ASSET_BELT),
|
||||
|
||||
ITEM_ENT(ASSET_CHEST, 32, storage_spawn),
|
||||
ITEM_ENT(ASSET_CHEST, 32, ASSET_CHEST),
|
||||
};
|
||||
|
|
|
@ -157,11 +157,13 @@ int32_t tracker_write_update(librg_world *w, librg_event *e) {
|
|||
}
|
||||
|
||||
// NOTE(zaklaus): action-based updates
|
||||
#if ECO2D_STREAM_ACTIONFILTER
|
||||
{
|
||||
if (view.kind != EKIND_CHUNK && !entity_can_stream(entity_id)) {
|
||||
return LIBRG_WRITE_REJECT;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return (int32_t)entity_view_pack_struct(buffer, actual_length, view);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue