device code

isolation_bkp/dynres
Dominik Madarász 2022-09-15 22:50:48 +02:00
parent 04e257ec61
commit da8030bab8
9 changed files with 96 additions and 74 deletions

View File

@ -19,6 +19,7 @@ add_executable(eco2d
src/player.c src/player.c
src/vehicle.c src/vehicle.c
src/storage.c src/storage.c
src/device.c
src/signal_handling.c src/signal_handling.c
src/profiler.c src/profiler.c
src/debug_ui.c src/debug_ui.c

View File

@ -0,0 +1,19 @@
#include "device.h"
#include "entity.h"
#include "entity_view.h"
#include "world/world.h"
#include "modules/components.h"
uint64_t device_spawn(asset_id id) {
ecs_entity_t e = entity_spawn(EKIND_DEVICE);
Device *dev = ecs_get_mut(world_ecs(), e, Device);
dev->asset = id;
return (uint64_t)e;
}
void device_despawn(uint64_t ent_id) {
entity_despawn(ent_id);
}

View File

@ -0,0 +1,6 @@
#pragma once
#include "system.h"
#include "assets.h"
uint64_t device_spawn(asset_id id);
void device_despawn(uint64_t ent_id);

View File

@ -8,6 +8,9 @@
#include "modules/systems.h" #include "modules/systems.h"
#include "zpl.h" #include "zpl.h"
// NOTE(zaklaus): bring in entity spawnlist
#include "entity_spawnlist.c"
uint64_t entity_spawn(uint16_t class_id) { uint64_t entity_spawn(uint16_t class_id) {
ecs_entity_t e = ecs_new(world_ecs(), 0); ecs_entity_t e = ecs_new(world_ecs(), 0);
@ -33,6 +36,16 @@ uint64_t entity_spawn(uint16_t class_id) {
return (uint64_t)e; return (uint64_t)e;
} }
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_batch_despawn(uint64_t *ids, size_t num_ids) { void entity_batch_despawn(uint64_t *ids, size_t num_ids) {
for (size_t i = 0; i < num_ids; i++ ) { for (size_t i = 0; i < num_ids; i++ ) {
librg_entity_untrack(world_tracker(), ids[i]); librg_entity_untrack(world_tracker(), ids[i]);
@ -45,20 +58,6 @@ void entity_despawn(uint64_t ent_id) {
ecs_delete(world_ecs(), 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) { void entity_set_position(uint64_t ent_id, float x, float y) {
Position *p = ecs_get_mut(world_ecs(), ent_id, Position); Position *p = ecs_get_mut(world_ecs(), ent_id, Position);
p->x = x; p->x = x;

View File

@ -4,11 +4,11 @@
#define ENTITY_ACTION_VELOCITY_THRESHOLD 0.05f #define ENTITY_ACTION_VELOCITY_THRESHOLD 0.05f
uint64_t entity_spawn(uint16_t class_id /* 0 = no streaming */); uint64_t entity_spawn(uint16_t class_id /* 0 = no streaming */);
uint64_t entity_spawn_id(uint16_t id);
void entity_batch_despawn(uint64_t *ids, size_t num_ids); void entity_batch_despawn(uint64_t *ids, size_t num_ids);
void entity_despawn(uint64_t ent_id); void entity_despawn(uint64_t ent_id);
void entity_set_position(uint64_t ent_id, float x, float y); 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 // NOTE(zaklaus): action-based entity stream throttling
void entity_wake(uint64_t ent_id); void entity_wake(uint64_t ent_id);

View File

@ -1,7 +1,7 @@
// NOTE(zaklaus): access to spawners // NOTE(zaklaus): access to spawners
#include "storage.h" #include "storage.h"
struct { static struct {
asset_id id; asset_id id;
uint64_t (*proc)(); uint64_t (*proc)();
} entity_spawnlist[] = { } entity_spawnlist[] = {

View File

@ -1,61 +1,9 @@
#include "items.h" #include "items.h"
#include "entity_view.h" #include "entity_view.h"
#include "items_list_helpers.h"
#define ITEM_HOLD(asset, qty)\
{\
.kind = asset,\
.usage = UKIND_HOLD,\
.max_quantity = qty,\
}
#define ITEM_BLOCK(asset, qty, build_asset)\
{\
.kind = asset,\
.usage = UKIND_PLACE,\
.max_quantity = qty,\
.place = {\
.kind = build_asset,\
}\
}
#define ITEM_BLOCK_DIR(asset, qty, build_asset)\
{\
.kind = asset,\
.usage = UKIND_PLACE,\
.max_quantity = qty,\
.place = {\
.kind = build_asset,\
.directional = true,\
}\
}
#define ITEM_PROXY(asset, proxy_id)\
{\
.kind = asset,\
.usage = UKIND_PROXY,\
.proxy = {\
.id = proxy_id,\
}\
}
#define ITEM_ENT(asset, qty, eid)\
{\
.kind = asset,\
.usage = UKIND_PLACE_ITEM,\
.max_quantity = qty,\
.place_item = {\
.id = eid\
}\
}
#define ITEM_SELF(asset, qty) ITEM_BLOCK(asset, qty, asset)
#define ITEM_SELF_DIR(asset, qty) ITEM_BLOCK_DIR(asset, qty, asset)
static item_desc items[] = { static item_desc items[] = {
{ { .kind = 0, .max_quantity = 0, },
.kind = 0,
.max_quantity = 0,
},
ITEM_BLOCK(ASSET_DEMO_ICEMAKER, 64, ASSET_WATER), ITEM_BLOCK(ASSET_DEMO_ICEMAKER, 64, ASSET_WATER),
ITEM_SELF(ASSET_FENCE, 64), ITEM_SELF(ASSET_FENCE, 64),
ITEM_SELF(ASSET_WOOD, 64), ITEM_SELF(ASSET_WOOD, 64),

View File

@ -0,0 +1,51 @@
#pragma once
#define ITEM_HOLD(asset, qty)\
{\
.kind = asset,\
.usage = UKIND_HOLD,\
.max_quantity = qty,\
}
#define ITEM_BLOCK(asset, qty, build_asset)\
{\
.kind = asset,\
.usage = UKIND_PLACE,\
.max_quantity = qty,\
.place = {\
.kind = build_asset,\
}\
}
#define ITEM_BLOCK_DIR(asset, qty, build_asset)\
{\
.kind = asset,\
.usage = UKIND_PLACE,\
.max_quantity = qty,\
.place = {\
.kind = build_asset,\
.directional = true,\
}\
}
#define ITEM_PROXY(asset, proxy_id)\
{\
.kind = asset,\
.usage = UKIND_PROXY,\
.proxy = {\
.id = proxy_id,\
}\
}
#define ITEM_ENT(asset, qty, eid)\
{\
.kind = asset,\
.usage = UKIND_PLACE_ITEM,\
.max_quantity = qty,\
.place_item = {\
.id = eid\
}\
}
#define ITEM_SELF(asset, qty) ITEM_BLOCK(asset, qty, asset)
#define ITEM_SELF_DIR(asset, qty) ITEM_BLOCK_DIR(asset, qty, asset)

View File

@ -1,4 +1,5 @@
#include "storage.h" #include "storage.h"
#include "device.h"
#include "entity.h" #include "entity.h"
#include "entity_view.h" #include "entity_view.h"
#include "world/world.h" #include "world/world.h"
@ -6,10 +7,7 @@
#include "modules/components.h" #include "modules/components.h"
uint64_t storage_spawn(void) { uint64_t storage_spawn(void) {
ecs_entity_t e = entity_spawn(EKIND_DEVICE); ecs_entity_t e = device_spawn(ASSET_CHEST);
Device *dev = ecs_get_mut(world_ecs(), e, Device);
dev->asset = ASSET_CHEST;
ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer);
*storage = (ItemContainer){0}; *storage = (ItemContainer){0};