diff options
Diffstat (limited to 'world.hpp')
-rw-r--r-- | world.hpp | 38 |
1 files changed, 30 insertions, 8 deletions
@@ -12,19 +12,35 @@ using Component_Mask = uint64_t; using Entity_Id = uint32_t; #define max_entities 1024 -#define pool_cap 128 +#define slinky_size 128 #define max_components 64 +#define max_slinkies (max_entities / slinky_size) + +struct Slinky { + Entity_Id* entities; + void* data; + int count; + + 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 { + struct Mapping { + int slinky; + int mapping; + }; + Component_Mask mask; - Pool* next; - void* data; - Entity_Id entities[pool_cap]; - int mapping[max_entities]; + Slinky slinkies[max_slinkies]; + Mapping mapping[max_entities]; int offsets[max_components]; - int size, count; + int size, count, slinky_count; void init(Arena* a, Component_Mask m); + Slinky& get_slinky(Arena* a); void* add(Arena* a, Entity_Id eid); void* get(Entity_Id eid, int cid); void* get(Entity_Id eid); @@ -126,8 +142,11 @@ struct World { template <typename C> C& get() { Pool* p = v->pools[ind]; + Slinky& s = p->slinkies[ptr / slinky_size]; + int si = &s - p->slinkies; + int off = ptr - (si * slinky_size); return *(C*)( - (char*)p->data + ptr * p->size + + (char*)s.data + off * p->size + p->offsets[v->w->get_component_id<C>()] ); } @@ -138,7 +157,10 @@ struct World { Entity_Id entity() { Pool* p = v->pools[ind]; - return p->entities[ptr]; + Slinky& s = p->slinkies[ptr / slinky_size]; + int si = &s - p->slinkies; + int off = ptr - (si * slinky_size); + return s.entities[off]; } }; |