From 261be8d702cdfb78bf213b6e43efdf9278e7b61d Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 4 May 2023 22:33:52 +1000 Subject: [PATCH] Improve roomproplist code --- src/game/prop.c | 21 +++++++++++---------- src/game/varsreset.c | 5 ----- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/game/prop.c b/src/game/prop.c index 6ad564bfc..471d86b93 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -2786,24 +2786,25 @@ bool propTryAddToChunk(s16 propnum, s32 chunkindex) s32 roomAllocatePropListChunk(s32 room, s32 prevchunkindex) { - s32 i; - s32 j; + u32 i; + + static u32 nextindex = 0; for (i = 0; i < 256; i++) { - if (g_RoomPropListChunks[i].count == 0) { - for (j = 0; j < ARRAYCOUNT(g_RoomPropListChunks[i].propnums); j++) { - g_RoomPropListChunks[i].propnums[j] = -1; - } + s32 index = (nextindex + i) % 256; - g_RoomPropListChunks[i].next = -1; + if (g_RoomPropListChunks[index].count == 0) { + g_RoomPropListChunks[index].next = -1; if (prevchunkindex >= 0) { - g_RoomPropListChunks[prevchunkindex].next = i; + g_RoomPropListChunks[prevchunkindex].next = index; } else { - g_RoomPropListChunkIndexes[room] = i; + g_RoomPropListChunkIndexes[room] = index; } - return i; + nextindex = (index + 1) % 256; + + return index; } } diff --git a/src/game/varsreset.c b/src/game/varsreset.c index ce0c4de85..609a8b234 100644 --- a/src/game/varsreset.c +++ b/src/game/varsreset.c @@ -61,7 +61,6 @@ void varsReset(void) void varsResetRoomProps(void) { s32 i; - s32 j; g_RoomPropListChunkIndexes = mempAlloc(ALIGN16(g_Vars.roomcount * sizeof(s16)), MEMPOOL_STAGE); g_RoomPropListChunks = mempAlloc(256 * sizeof(struct roomproplistchunk), MEMPOOL_STAGE); @@ -73,9 +72,5 @@ void varsResetRoomProps(void) for (i = 0; i < 256; i++) { g_RoomPropListChunks[i].count = 0; g_RoomPropListChunks[i].next = -1; - - for (j = 0; j < ARRAYCOUNT(g_RoomPropListChunks[i].propnums); j++) { - g_RoomPropListChunks[i].propnums[j] = -1; - } } }