aboutsummaryrefslogtreecommitdiff
path: root/src/entity_list.odin
diff options
context:
space:
mode:
Diffstat (limited to 'src/entity_list.odin')
-rw-r--r--src/entity_list.odin25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/entity_list.odin b/src/entity_list.odin
index 3ee553e..d5cdb50 100644
--- a/src/entity_list.odin
+++ b/src/entity_list.odin
@@ -1,7 +1,5 @@
package demonchime
-import "core:math"
-
Entity_Handle :: struct {
idx: u32,
uses: u32,
@@ -24,8 +22,7 @@ make_entity :: proc(list: ^Entity_List($T), ent: T) -> (Entity_Handle, ^T) {
handle = pop(&list.holes)
handle.uses += 1
} else {
- // because index 0 in a handle is considered a null handle
- resize(&list.items, math.max(2, len(list.items) + 1))
+ resize(&list.items, len(list.items) + 1)
handle.idx = u32(len(list.items) - 1)
handle.uses = 1
}
@@ -35,21 +32,18 @@ make_entity :: proc(list: ^Entity_List($T), ent: T) -> (Entity_Handle, ^T) {
return handle, &list.items[handle.idx]
}
-delete_entity :: proc(list: ^Entity_List($T), handle: Entity_Handle) {
- if handle.idx <= 0 || int(handle.idx) >= len(list.items) {
- return
- }
- if list.items[handle.idx].handle != handle {
+delete_entity :: proc(list: ^Entity_List($T), h: Entity_Handle) {
+ if int(h.idx) >= len(list.items) ||
+ list.items[h.idx].handle != h {
return
}
- append(&list.holes, handle)
- list.items[handle.idx] = {}
+ append(&list.holes, h)
+ list.items[h.idx] = {}
}
get_entity :: proc(list: Entity_List($T), h: Entity_Handle) -> ^T {
- if h.idx < 1 ||
- h.idx >= u32(len(list.items)) ||
+ if h.idx >= u32(len(list.items)) ||
list.items[h.idx].handle != h {
return nil
}
@@ -57,8 +51,7 @@ get_entity :: proc(list: Entity_List($T), h: Entity_Handle) -> ^T {
}
active_entity_count :: proc(list: Entity_List($T)) -> int {
- // - 1 because there's an empty slot at the beginning
- return len(list.items) - len(list.holes) - 1
+ return len(list.items) - len(list.holes)
}
Entity_List_Iter :: struct($T: typeid) {
@@ -72,7 +65,7 @@ iter_entity_list :: proc(list: Entity_List($T)) -> Entity_List_Iter(T) {
entity_list_iter :: proc(it: ^Entity_List_Iter($T)) -> (^T, bool) {
for it.idx < len(it.list.items) {
- if it.list.items[it.idx].handle.idx > 0 {
+ if it.list.items[it.idx].handle.uses > 0 {
entity := &it.list.items[it.idx]
it.idx += 1
return entity, true