diff options
| author | iamcheeseman <[hidden email]> | 2026-01-15 12:13:41 -0500 |
|---|---|---|
| committer | iamcheeseman <[hidden email]> | 2026-01-15 12:13:41 -0500 |
| commit | 1ebeadbad7f7ee757096320d9c5daf3b55373f6a (patch) | |
| tree | ffa9ce9d9df6f93970c488441f0a74c8bfcc9022 /src/entity_list.odin | |
| parent | d6f276be6bc1214c88cfc5346ceb7a5bea610638 (diff) | |
Bullets! And buncha physics fixes! And more!
Diffstat (limited to 'src/entity_list.odin')
| -rw-r--r-- | src/entity_list.odin | 25 |
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 |
