Cleanup for PR, return old sprite tracker
This commit is contained in:
+2
-1
@@ -15,6 +15,7 @@
|
||||
|
||||
#define JOKER_SCORE_TEXT_Y 48
|
||||
#define NUM_JOKERS_PER_SPRITESHEET 2
|
||||
#define MAX_DEFINABLE_JOKERS 150
|
||||
|
||||
static const unsigned int *joker_gfxTiles[] =
|
||||
{
|
||||
@@ -50,7 +51,7 @@ static bool used_layers[MAX_JOKER_OBJECTS] = {false}; // Track used layers for j
|
||||
|
||||
// Maps the spritesheet index to the palette bank index allocated to it.
|
||||
// Spritesheets that were not allocated are
|
||||
static int joker_spritesheet_pb_map[MAX_SPRITES];
|
||||
static int joker_spritesheet_pb_map[(MAX_DEFINABLE_JOKERS + 1) / NUM_JOKERS_PER_SPRITESHEET];
|
||||
static int joker_pb_num_sprite_users[JOKER_LAST_PB - JOKER_BASE_PB + 1] = { 0 };
|
||||
|
||||
static int get_num_spritesheets()
|
||||
|
||||
+10
-3
@@ -1,11 +1,18 @@
|
||||
#include "pool.h"
|
||||
#include "util.h"
|
||||
|
||||
void pool_bm_clear_idx(PoolBitmap *bm, int idx)
|
||||
{
|
||||
// Divide by 32 to get the word index
|
||||
uint32_t i = idx >> 5;
|
||||
uint32_t i = idx / 32;
|
||||
// Get last 5-bits, same as a modulo (% 32) operation on positive numbers
|
||||
uint32_t b = idx & 0x1F;
|
||||
uint32_t b = idx % 32;
|
||||
|
||||
// Below are the "fast" forms of the above operations, respectively.
|
||||
// These are more efficient, but removed for readability
|
||||
// See: https://github.com/cellos51/balatro-gba/pull/132#discussion_r2365966071
|
||||
//uint32_t i = idx >> 5;
|
||||
//uint32_t b = idx & 0x1F;
|
||||
bm->w[i] &= ~((uint32_t)1 << b);
|
||||
}
|
||||
|
||||
@@ -32,7 +39,7 @@ int pool_bm_get_free_idx(PoolBitmap *bm)
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+15
-18
@@ -9,34 +9,34 @@
|
||||
#include <stdlib.h>
|
||||
#include <maxmod.h>
|
||||
|
||||
#define MAX_SPRITES 128
|
||||
#define MAX_AFFINES 32
|
||||
#define SPRITE_FOCUS_RAISE_PX 10
|
||||
|
||||
OBJ_ATTR obj_buffer[MAX_SPRITES];
|
||||
OBJ_AFFINE *obj_aff_buffer = (OBJ_AFFINE*)obj_buffer;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool used;
|
||||
Sprite* p_sprite;
|
||||
} _UsedSprite;
|
||||
|
||||
static Sprite *free_sprites[MAX_SPRITES] = {NULL};
|
||||
static bool free_affines[MAX_AFFINES] = {false};
|
||||
static _UsedSprite free_sprites[MAX_SPRITES] = {{0}};
|
||||
|
||||
// Sprite methods
|
||||
Sprite *sprite_new(u16 a0, u16 a1, u32 tid, u32 pb, int sprite_index)
|
||||
{
|
||||
if(free_sprites[sprite_index].used)
|
||||
{
|
||||
return free_sprites[sprite_index].p_sprite;
|
||||
}
|
||||
|
||||
Sprite* sprite = POOL_GET(Sprite);
|
||||
|
||||
sprite->obj = NULL;
|
||||
sprite->aff = NULL;
|
||||
|
||||
if(!free_sprites[sprite_index])
|
||||
{
|
||||
free_sprites[sprite_index] = sprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
POOL_FREE(Sprite, sprite);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (a0 & ATTR0_AFF)
|
||||
{
|
||||
int aff_index = MAX_AFFINES;
|
||||
@@ -70,13 +70,11 @@ Sprite *sprite_new(u16 a0, u16 a1, u32 tid, u32 pb, int sprite_index)
|
||||
obj_set_attr(sprite->obj, a0, a1, ATTR2_PALBANK(pb) | tid);
|
||||
}
|
||||
|
||||
free_sprites[sprite_index].used = true;
|
||||
free_sprites[sprite_index].p_sprite = sprite;
|
||||
sprite->idx = sprite_index;
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
|
||||
void sprite_destroy(Sprite **sprite)
|
||||
{
|
||||
if (*sprite == NULL) return;
|
||||
@@ -88,8 +86,7 @@ void sprite_destroy(Sprite **sprite)
|
||||
free_affines[(*sprite)->aff - obj_aff_buffer] = false;
|
||||
}
|
||||
|
||||
free_sprites[(*sprite)->idx].used = false;
|
||||
free_sprites[(*sprite)->idx].p_sprite = NULL;
|
||||
free_sprites[(*sprite)->idx] = NULL;
|
||||
|
||||
POOL_FREE(Sprite, *sprite);
|
||||
|
||||
@@ -98,7 +95,7 @@ void sprite_destroy(Sprite **sprite)
|
||||
|
||||
int sprite_get_layer(Sprite *sprite)
|
||||
{
|
||||
if (sprite == NULL || sprite->obj == NULL) return -1;
|
||||
if (sprite == NULL || sprite->obj == NULL) return UNDEFINED;
|
||||
return sprite->obj - obj_buffer;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "pool.h"
|
||||
|
||||
#include "util.h"
|
||||
#include "test_structures.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
@@ -93,17 +95,17 @@ int main(void)
|
||||
{
|
||||
// Test it twice to make sure empty works, kinda hacky.
|
||||
printf("Testing Pool Fill and Empty 1x.\n");
|
||||
if(!test_fill_and_empty()) return -1;
|
||||
if(!test_fill_and_empty()) return UNDEFINED;
|
||||
printf("Testing Pool Fill and Empty 2x.\n");
|
||||
if(!test_fill_and_empty()) return -1;
|
||||
if(!test_fill_and_empty()) return UNDEFINED;
|
||||
|
||||
// Similarly here, verify that fill, random num removal, refill, and empty
|
||||
// by refilling and emptying again
|
||||
printf("Testing Pool Fill, Partial Empty, Refill, Empty.\n");
|
||||
if(!test_fill_and_remove_at_random_and_refill_and_empty()) return -1;
|
||||
if(!test_fill_and_remove_at_random_and_refill_and_empty()) return UNDEFINED;
|
||||
|
||||
printf("Testing Pool Fill and Empty.\n");
|
||||
if(!test_fill_and_empty()) return -1;
|
||||
if(!test_fill_and_empty()) return UNDEFINED;
|
||||
|
||||
printf("---------------------------------------------------------\n");
|
||||
printf("Pool Tests Passed\n");
|
||||
@@ -139,7 +141,7 @@ int main(void)
|
||||
printf("\n");
|
||||
|
||||
t1 = get_time();
|
||||
if(!test_fill_and_empty()) return -1;
|
||||
if(!test_fill_and_empty()) return UNDEFINED;
|
||||
t2 = get_time();
|
||||
printf("Fill and Empty Pool %d times:\n\t", TEST_SIZE);
|
||||
print_time_diff(t1, t2);
|
||||
|
||||
Reference in New Issue
Block a user