From 8e013c4171e2d1d9a03d76b57ed095bd4e8bb56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Thu, 29 Sep 2022 16:05:07 +0200 Subject: [PATCH] make prefabs folder --- code/foundation/CMakeLists.txt | 9 +++++---- code/foundation/src/debug/debug_ui.c | 2 +- code/foundation/src/ents/device.c | 6 +++--- code/foundation/src/ents/entity.c | 16 ++++++++-------- code/foundation/src/ents/entity_spawnlist.c | 4 ++-- .../src/ents/{ => prefabs}/furnace.c | 5 +---- .../src/ents/{ => prefabs}/furnace.h | 0 .../foundation/src/ents/{ => prefabs}/player.c | 18 +++++++----------- .../foundation/src/ents/{ => prefabs}/player.h | 0 .../src/ents/{ => prefabs}/storage.c | 8 +++----- .../src/ents/{ => prefabs}/storage.h | 0 .../src/ents/{ => prefabs}/vehicle.c | 4 ++-- .../src/ents/{ => prefabs}/vehicle.h | 0 code/foundation/src/gen/asset_setup.h | 3 +++ code/foundation/src/net/network_enet.c | 2 +- code/foundation/src/packets/pkt_00_init.c | 2 +- .../foundation/src/packets/pkt_switch_viewer.c | 2 +- code/games/minimal/src/worldgen.c | 2 +- code/games/sandbox/src/worldgen.c | 2 +- 19 files changed, 40 insertions(+), 45 deletions(-) rename code/foundation/src/ents/{ => prefabs}/furnace.c (81%) rename code/foundation/src/ents/{ => prefabs}/furnace.h (100%) rename code/foundation/src/ents/{ => prefabs}/player.c (76%) rename code/foundation/src/ents/{ => prefabs}/player.h (100%) rename code/foundation/src/ents/{ => prefabs}/storage.c (73%) rename code/foundation/src/ents/{ => prefabs}/storage.h (100%) rename code/foundation/src/ents/{ => prefabs}/vehicle.c (90%) rename code/foundation/src/ents/{ => prefabs}/vehicle.h (100%) diff --git a/code/foundation/CMakeLists.txt b/code/foundation/CMakeLists.txt index 65d9b13..36a82f4 100644 --- a/code/foundation/CMakeLists.txt +++ b/code/foundation/CMakeLists.txt @@ -10,11 +10,12 @@ add_library(eco2d-foundation STATIC src/ents/items.c src/ents/entity.c - src/ents/player.c - src/ents/vehicle.c - src/ents/storage.c src/ents/device.c - src/ents/furnace.c + + src/ents/prefabs/player.c + src/ents/prefabs/vehicle.c + src/ents/prefabs/storage.c + src/ents/prefabs/furnace.c src/pkt/packet.c diff --git a/code/foundation/src/debug/debug_ui.c b/code/foundation/src/debug/debug_ui.c index c66056c..e2d17e8 100644 --- a/code/foundation/src/debug/debug_ui.c +++ b/code/foundation/src/debug/debug_ui.c @@ -1,7 +1,7 @@ #include "debug/debug_ui.h" #include "debug/debug_draw.h" #include "raylib.h" -#include "ents/vehicle.h" +#include "ents/prefabs/vehicle.h" #include "core/camera.h" #include "world/world.h" #include "core/game.h" diff --git a/code/foundation/src/ents/device.c b/code/foundation/src/ents/device.c index 9928494..7660875 100644 --- a/code/foundation/src/ents/device.c +++ b/code/foundation/src/ents/device.c @@ -5,12 +5,12 @@ #include "ecs/components.h" -uint64_t device_spawn(asset_id id) { +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; } diff --git a/code/foundation/src/ents/entity.c b/code/foundation/src/ents/entity.c index 81985db..5bb140c 100644 --- a/code/foundation/src/ents/entity.c +++ b/code/foundation/src/ents/entity.c @@ -13,10 +13,10 @@ uint64_t entity_spawn(uint16_t class_id) { ecs_entity_t e = ecs_new(world_ecs(), 0); - + ecs_set(world_ecs(), e, Classify, { .id = class_id }); entity_wake(e); - + if (class_id != EKIND_SERVER) { ecs_set(world_ecs(), e, Velocity, {0}); Position *pos = ecs_get_mut(world_ecs(), e, Position); @@ -28,12 +28,12 @@ uint64_t entity_spawn(uint16_t class_id) { pos->x=350.0f; pos->y=88.0f; #endif - + librg_entity_track(world_tracker(), e); librg_entity_chunk_set(world_tracker(), e, librg_chunk_from_realpos(world_tracker(), pos->x, pos->y, 0)); librg_entity_owner_set(world_tracker(), e, (int64_t)e); } - + return (uint64_t)e; } @@ -81,12 +81,12 @@ void entity_update_action_timers() { ecs_streaminfo = ecs_query_new(world_ecs(), "components.StreamInfo"); last_update_time = get_cached_time(); } - + ecs_iter_t it = ecs_query_iter(world_ecs(), ecs_streaminfo); - + while (ecs_query_next(&it)) { StreamInfo *si = ecs_field(&it, StreamInfo, 1); - + for (int32_t i = 0; i < it.count; i++) { if (si[i].last_update < get_cached_time()) { si[i].last_update = get_cached_time() + si[i].tick_delay; @@ -94,7 +94,7 @@ void entity_update_action_timers() { } } } - + last_update_time = get_cached_time(); } diff --git a/code/foundation/src/ents/entity_spawnlist.c b/code/foundation/src/ents/entity_spawnlist.c index 806681f..fb31050 100644 --- a/code/foundation/src/ents/entity_spawnlist.c +++ b/code/foundation/src/ents/entity_spawnlist.c @@ -1,6 +1,6 @@ // NOTE(zaklaus): access to spawners -#include "ents/storage.h" -#include "ents/furnace.h" +#include "ents/prefabs/storage.h" +#include "ents/prefabs/furnace.h" static struct { asset_id id; diff --git a/code/foundation/src/ents/furnace.c b/code/foundation/src/ents/prefabs/furnace.c similarity index 81% rename from code/foundation/src/ents/furnace.c rename to code/foundation/src/ents/prefabs/furnace.c index c79ccb7..33e5809 100644 --- a/code/foundation/src/ents/furnace.c +++ b/code/foundation/src/ents/prefabs/furnace.c @@ -1,8 +1,5 @@ -#include "ents/furnace.h" +#include "furnace.h" #include "ents/device.h" -#include "ents/entity.h" -#include "world/entity_view.h" -#include "world/world.h" #include "ecs/components.h" diff --git a/code/foundation/src/ents/furnace.h b/code/foundation/src/ents/prefabs/furnace.h similarity index 100% rename from code/foundation/src/ents/furnace.h rename to code/foundation/src/ents/prefabs/furnace.h diff --git a/code/foundation/src/ents/player.c b/code/foundation/src/ents/prefabs/player.c similarity index 76% rename from code/foundation/src/ents/player.c rename to code/foundation/src/ents/prefabs/player.c index 4693e8a..0ca94e0 100644 --- a/code/foundation/src/ents/player.c +++ b/code/foundation/src/ents/prefabs/player.c @@ -1,31 +1,27 @@ -#include "ents/player.h" -#include "ents/entity.h" +#include "player.h" #include "world/entity_view.h" -#include "flecs/flecs.h" -#include "librg.h" + #include "world/world.h" #include "ecs/components.h" -#include "ecs/systems.h" -#include "zpl.h" #define PLAYER_MAX_HP 100.0f -uint64_t player_spawn(char *name) { +uint64_t player_spawn(char *name) { ecs_entity_t e = entity_spawn(EKIND_PLAYER); - + if (!name) { name = zpl_bprintf("player_%d", e); } - + ecs_set_name(world_ecs(), e, name); ecs_set(world_ecs(), e, ClientInfo, {0}); ecs_set(world_ecs(), e, Input, {0}); ecs_set(world_ecs(), e, Inventory, {0}); ecs_set(world_ecs(), e, Health, {.hp = PLAYER_MAX_HP, .max_hp = PLAYER_MAX_HP}); - + librg_entity_owner_set(world_tracker(), e, (int64_t)e); - + return (uint64_t)e; } diff --git a/code/foundation/src/ents/player.h b/code/foundation/src/ents/prefabs/player.h similarity index 100% rename from code/foundation/src/ents/player.h rename to code/foundation/src/ents/prefabs/player.h diff --git a/code/foundation/src/ents/storage.c b/code/foundation/src/ents/prefabs/storage.c similarity index 73% rename from code/foundation/src/ents/storage.c rename to code/foundation/src/ents/prefabs/storage.c index ff2acaf..b625a2e 100644 --- a/code/foundation/src/ents/storage.c +++ b/code/foundation/src/ents/prefabs/storage.c @@ -1,14 +1,12 @@ -#include "ents/storage.h" +#include "storage.h" #include "ents/device.h" -#include "ents/entity.h" -#include "world/entity_view.h" #include "world/world.h" #include "ecs/components.h" -uint64_t storage_spawn(void) { +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; diff --git a/code/foundation/src/ents/storage.h b/code/foundation/src/ents/prefabs/storage.h similarity index 100% rename from code/foundation/src/ents/storage.h rename to code/foundation/src/ents/prefabs/storage.h diff --git a/code/foundation/src/ents/vehicle.c b/code/foundation/src/ents/prefabs/vehicle.c similarity index 90% rename from code/foundation/src/ents/vehicle.c rename to code/foundation/src/ents/prefabs/vehicle.c index fe13677..0711c27 100644 --- a/code/foundation/src/ents/vehicle.c +++ b/code/foundation/src/ents/prefabs/vehicle.c @@ -1,5 +1,5 @@ -#include "ents/vehicle.h" -#include "ents/entity.h" +#include "vehicle.h" + #include "world/entity_view.h" #include "world/world.h" diff --git a/code/foundation/src/ents/vehicle.h b/code/foundation/src/ents/prefabs/vehicle.h similarity index 100% rename from code/foundation/src/ents/vehicle.h rename to code/foundation/src/ents/prefabs/vehicle.h diff --git a/code/foundation/src/gen/asset_setup.h b/code/foundation/src/gen/asset_setup.h index 0fea9a9..23d8c25 100644 --- a/code/foundation/src/gen/asset_setup.h +++ b/code/foundation/src/gen/asset_setup.h @@ -21,3 +21,6 @@ // NOTE(zaklaus): Register an item #include "items_list.c" +// NOTE(zaklaus): Register a spawnable entity +#include "ents/entity_spawnlist.c" + diff --git a/code/foundation/src/net/network_enet.c b/code/foundation/src/net/network_enet.c index 19926cd..cc2c503 100644 --- a/code/foundation/src/net/network_enet.c +++ b/code/foundation/src/net/network_enet.c @@ -16,7 +16,7 @@ #include "packets/pkt_00_init.h" #include "world/world.h" #include "core/game.h" -#include "ents/player.h" +#include "ents/prefabs/player.h" #include "ecs/components.h" diff --git a/code/foundation/src/packets/pkt_00_init.c b/code/foundation/src/packets/pkt_00_init.c index e7a9417..350b9e9 100644 --- a/code/foundation/src/packets/pkt_00_init.c +++ b/code/foundation/src/packets/pkt_00_init.c @@ -6,7 +6,7 @@ #include "net/network.h" #include "world/entity_view.h" #include "core/camera.h" -#include "ents/player.h" +#include "ents/prefabs/player.h" #include "ents/entity.h" #include "ecs/components.h" diff --git a/code/foundation/src/packets/pkt_switch_viewer.c b/code/foundation/src/packets/pkt_switch_viewer.c index 346bb28..13625bf 100644 --- a/code/foundation/src/packets/pkt_switch_viewer.c +++ b/code/foundation/src/packets/pkt_switch_viewer.c @@ -5,7 +5,7 @@ #include "net/network.h" #include "world/entity_view.h" #include "core/camera.h" -#include "ents/player.h" +#include "ents/prefabs/player.h" #include "ecs/components.h" #include "ecs/systems.h" diff --git a/code/games/minimal/src/worldgen.c b/code/games/minimal/src/worldgen.c index 802b914..465a694 100644 --- a/code/games/minimal/src/worldgen.c +++ b/code/games/minimal/src/worldgen.c @@ -9,7 +9,7 @@ #include "ecs/components.h" #include "ents/entity.h" -#include "ents/vehicle.h" +#include "ents/prefabs/vehicle.h" #include "ents/items.h" #include "world/blocks_info.h" diff --git a/code/games/sandbox/src/worldgen.c b/code/games/sandbox/src/worldgen.c index 4b94bbd..5d34873 100644 --- a/code/games/sandbox/src/worldgen.c +++ b/code/games/sandbox/src/worldgen.c @@ -9,7 +9,7 @@ #include "ecs/components.h" #include "ents/entity.h" -#include "ents/vehicle.h" +#include "ents/prefabs/vehicle.h" #include "ents/items.h" #include "world/blocks_info.h"