From 45d54c38f74d3b8c681e73957e4fe4dfe1523792 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sat, 16 Mar 2024 16:26:33 +0100 Subject: [PATCH] Use bitarray_t for used_spr --- src/deh_lua.c | 4 ++-- src/deh_soc.c | 4 ++-- src/deh_tables.c | 2 +- src/deh_tables.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/deh_lua.c b/src/deh_lua.c index 0effe4fa7..3176f5d69 100644 --- a/src/deh_lua.c +++ b/src/deh_lua.c @@ -66,12 +66,12 @@ static inline int lib_freeslot(lua_State *L) for (j = SPR_FIRSTFREESLOT; j <= SPR_LASTFREESLOT; j++) { - if (used_spr[(j-SPR_FIRSTFREESLOT)/8] & (1<<(j%8))) + if (in_bit_array(used_spr, j - SPR_FIRSTFREESLOT)) continue; // Already allocated, next. // Found a free slot! CONS_Printf("Sprite SPR_%s allocated.\n",word); strcpy(sprnames[j], word); - used_spr[(j-SPR_FIRSTFREESLOT)/8] |= 1<<(j%8); // Okay, this sprite slot has been named now. + set_bit_array(used_spr, j - SPR_FIRSTFREESLOT); // Okay, this sprite slot has been named now. // Lua needs to update the value in _G if it exists LUA_UpdateSprName(word, j); lua_pushinteger(L, j); diff --git a/src/deh_soc.c b/src/deh_soc.c index fe43cd283..5e068313d 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -445,11 +445,11 @@ void readfreeslots(MYFILE *f) for (i = SPR_FIRSTFREESLOT; i <= SPR_LASTFREESLOT; i++) { - if (used_spr[(i-SPR_FIRSTFREESLOT)/8] & (1<<(i%8))) + if (in_bit_array(used_spr, i - SPR_FIRSTFREESLOT)) continue; // Already allocated, next. // Found a free slot! strcpy(sprnames[i], word); - used_spr[(i-SPR_FIRSTFREESLOT)/8] |= 1<<(i%8); // Okay, this sprite slot has been named now. + set_bit_array(used_spr, i - SPR_FIRSTFREESLOT); // Okay, this sprite slot has been named now. // Lua needs to update the value in _G if it exists LUA_UpdateSprName(word, i); break; diff --git a/src/deh_tables.c b/src/deh_tables.c index ed401d68a..c7c7c6040 100644 --- a/src/deh_tables.c +++ b/src/deh_tables.c @@ -31,7 +31,7 @@ char *FREE_STATES[NUMSTATEFREESLOTS]; char *FREE_MOBJS[NUMMOBJFREESLOTS]; char *FREE_SKINCOLORS[NUMCOLORFREESLOTS]; -UINT8 used_spr[(NUMSPRITEFREESLOTS / 8) + 1]; // Bitwise flag for sprite freeslot in use! I would use ceil() here if I could, but it only saves 1 byte of memory anyway. +bitarray_t used_spr[BIT_ARRAY_SIZE(NUMSPRITEFREESLOTS)]; // Sprite freeslots in use const char NIGHTSGRADE_LIST[] = { 'F', // GRADE_F diff --git a/src/deh_tables.h b/src/deh_tables.h index b71a2a23b..b6986adff 100644 --- a/src/deh_tables.h +++ b/src/deh_tables.h @@ -23,7 +23,7 @@ extern char *FREE_STATES[NUMSTATEFREESLOTS]; extern char *FREE_MOBJS[NUMMOBJFREESLOTS]; extern char *FREE_SKINCOLORS[NUMCOLORFREESLOTS]; -extern UINT8 used_spr[(NUMSPRITEFREESLOTS / 8) + 1]; // Bitwise flag for sprite freeslot in use! I would use ceil() here if I could, but it only saves 1 byte of memory anyway. +extern bitarray_t used_spr[BIT_ARRAY_SIZE(NUMSPRITEFREESLOTS)]; // Sprite freeslots in use #define initfreeslots() {\ memset(FREE_STATES, 0, sizeof(FREE_STATES));\