From 26aebfdb92eb6780b1eb7195670b042b97948b0f Mon Sep 17 00:00:00 2001 From: quou Date: Thu, 1 May 2025 20:45:12 +1000 Subject: fixing bugs in the entity system --- world.hpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'world.hpp') diff --git a/world.hpp b/world.hpp index f486ba1..c944b12 100644 --- a/world.hpp +++ b/world.hpp @@ -3,16 +3,20 @@ struct Arena; +#include "entity.hpp" + #include #include +#include #include - +extern "C" { +#include "plat.h" +} using Component_Mask = uint64_t; -using Entity_Id = uint32_t; #define max_entities 1024 -#define slinky_size 128 +#define slinky_size 1 #define max_components 64 #define max_slinkies (max_entities / slinky_size) @@ -36,7 +40,6 @@ struct Slinky { void init(Arena* a, int size); void* add(Entity_Id eid, int size, int& mapping); void* get(Entity_Id eid, int mapping, int size); - void remove(Entity_Id eid, int mapping, int size); }; struct Pool { @@ -71,8 +74,9 @@ struct World { uint8_t versions[max_entities]; Entity_Id entities[max_entities]; Entity_Id freelist[max_entities]; + Entity_Id dq[max_entities]; Arena* arena; - int count, free_count; + int count, dq_count, free_count; void init(Arena* a); uint64_t hash_mask(Component_Mask m); @@ -122,6 +126,8 @@ struct World { void* get(Entity_Id eid, int cid); void remove(Entity_Id eid, int cid); void destroy(Entity_Id e); + void qdestroy(Entity_Id e); + void update(); struct View { World* w; @@ -172,6 +178,7 @@ struct World { Slinky& s = p->slinkies[ptr >> slinky_size_bit]; int si = &s - p->slinkies; int off = ptr - (si << slinky_size_bit); + assert(s.entities[off]); return s.entities[off]; } }; -- cgit v1.2.3-54-g00ecf