Use bitarray_t for used_spr

This commit is contained in:
LJ Sonic 2024-03-16 16:26:33 +01:00
parent b3844a9ca5
commit 45d54c38f7
4 changed files with 6 additions and 6 deletions

View file

@ -66,12 +66,12 @@ static inline int lib_freeslot(lua_State *L)
for (j = SPR_FIRSTFREESLOT; j <= SPR_LASTFREESLOT; j++) 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. continue; // Already allocated, next.
// Found a free slot! // Found a free slot!
CONS_Printf("Sprite SPR_%s allocated.\n",word); CONS_Printf("Sprite SPR_%s allocated.\n",word);
strcpy(sprnames[j], 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 needs to update the value in _G if it exists
LUA_UpdateSprName(word, j); LUA_UpdateSprName(word, j);
lua_pushinteger(L, j); lua_pushinteger(L, j);

View file

@ -445,11 +445,11 @@ void readfreeslots(MYFILE *f)
for (i = SPR_FIRSTFREESLOT; i <= SPR_LASTFREESLOT; i++) 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. continue; // Already allocated, next.
// Found a free slot! // Found a free slot!
strcpy(sprnames[i], word); 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 needs to update the value in _G if it exists
LUA_UpdateSprName(word, i); LUA_UpdateSprName(word, i);
break; break;

View file

@ -31,7 +31,7 @@
char *FREE_STATES[NUMSTATEFREESLOTS]; char *FREE_STATES[NUMSTATEFREESLOTS];
char *FREE_MOBJS[NUMMOBJFREESLOTS]; char *FREE_MOBJS[NUMMOBJFREESLOTS];
char *FREE_SKINCOLORS[NUMCOLORFREESLOTS]; 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[] = { const char NIGHTSGRADE_LIST[] = {
'F', // GRADE_F 'F', // GRADE_F

View file

@ -23,7 +23,7 @@
extern char *FREE_STATES[NUMSTATEFREESLOTS]; extern char *FREE_STATES[NUMSTATEFREESLOTS];
extern char *FREE_MOBJS[NUMMOBJFREESLOTS]; extern char *FREE_MOBJS[NUMMOBJFREESLOTS];
extern char *FREE_SKINCOLORS[NUMCOLORFREESLOTS]; 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() {\ #define initfreeslots() {\
memset(FREE_STATES, 0, sizeof(FREE_STATES));\ memset(FREE_STATES, 0, sizeof(FREE_STATES));\