summaryrefslogtreecommitdiff
path: root/world.hpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-05-01 20:45:12 +1000
committerquou <quou@disroot.org>2025-05-01 21:09:54 +1000
commit26aebfdb92eb6780b1eb7195670b042b97948b0f (patch)
tree0b5eeb5f123fbf8b93c21c7d55add8a7e77bca34 /world.hpp
parentdf03ffea8d23b319c29c0c937e70d5afb15e76e2 (diff)
fixing bugs in the entity systemHEADmaster
Diffstat (limited to 'world.hpp')
-rw-r--r--world.hpp17
1 files changed, 12 insertions, 5 deletions
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 <stdint.h>
#include <new>
+#include <tuple>
#include <utility>
-
+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];
}
};