Skip to content

Commit

Permalink
output: move animated textures to module scope
Browse files Browse the repository at this point in the history
This removes the global animated texture array and replaces with an
accessor.
  • Loading branch information
lahm86 committed Jan 28, 2025
1 parent 19c66ba commit 40729e6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/libtrx/game/level/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ void Level_ReadAnimatedTextureRanges(
const int32_t num_ranges, VFILE *const file)
{
for (int32_t i = 0; i < num_ranges; i++) {
ANIMATED_TEXTURE_RANGE *const range = &g_AnimTextureRanges[i];
ANIMATED_TEXTURE_RANGE *const range = Output_GetAnimatedTextureRange(i);
range->next_range =
i == num_ranges - 1 ? NULL : &g_AnimTextureRanges[i + 1];
i == num_ranges - 1 ? NULL : Output_GetAnimatedTextureRange(i + 1);

// Level data is tied to the original logic in Output_AnimateTextures
// and hence stores one less than the actual count here.
Expand Down
10 changes: 8 additions & 2 deletions src/libtrx/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef struct {
int32_t shade;
} COMMON_LIGHT;

static ANIMATED_TEXTURE_RANGE *m_AnimTextureRanges = NULL;
static int32_t m_DynamicLightCount = 0;
static LIGHT m_DynamicLights[MAX_DYNAMIC_LIGHTS] = {};

Expand Down Expand Up @@ -105,16 +106,21 @@ static int32_t M_CalculateDynamicLight(

void Output_InitialiseAnimatedTextures(const int32_t num_ranges)
{
g_AnimTextureRanges = num_ranges == 0
m_AnimTextureRanges = num_ranges == 0
? NULL
: GameBuf_Alloc(
sizeof(ANIMATED_TEXTURE_RANGE) * num_ranges,
GBUF_ANIMATED_TEXTURE_RANGES);
}

ANIMATED_TEXTURE_RANGE *Output_GetAnimatedTextureRange(const int32_t range_idx)
{
return &m_AnimTextureRanges[range_idx];
}

void Output_CycleAnimatedTextures(void)
{
const ANIMATED_TEXTURE_RANGE *range = g_AnimTextureRanges;
const ANIMATED_TEXTURE_RANGE *range = m_AnimTextureRanges;
for (; range != NULL; range = range->next_range) {
int32_t i = 0;
const OBJECT_TEXTURE temp = g_ObjectTextures[range->textures[i]];
Expand Down
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern int32_t Output_GetRoomLightShade(ROOM_LIGHT_MODE mode);
extern void Output_LightRoomVertices(const ROOM *room);

void Output_InitialiseAnimatedTextures(int32_t num_ranges);
ANIMATED_TEXTURE_RANGE *Output_GetAnimatedTextureRange(int32_t range_idx);
void Output_CycleAnimatedTextures(void);

void Output_CalculateLight(XYZ_32 pos, int16_t room_num);
Expand Down
1 change: 0 additions & 1 deletion src/libtrx/include/libtrx/game/output/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
// TODO: change to output.c module scope
extern OBJECT_TEXTURE g_ObjectTextures[MAX_OBJECT_TEXTURES];
extern SPRITE_TEXTURE g_SpriteTextures[MAX_SPRITE_TEXTURES];
extern ANIMATED_TEXTURE_RANGE *g_AnimTextureRanges;
1 change: 0 additions & 1 deletion src/tr1/global/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ uint16_t *g_Overlap = NULL;
int16_t *g_GroundZone[2] = { NULL };
int16_t *g_GroundZone2[2] = { NULL };
int16_t *g_FlyZone[2] = { NULL };
ANIMATED_TEXTURE_RANGE *g_AnimTextureRanges = NULL;
int16_t g_NumCineFrames = 0;
int16_t g_CineFrame = -1;
CINE_CAMERA *g_CineCamera = NULL;
Expand Down
1 change: 0 additions & 1 deletion src/tr2/global/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ int32_t g_TexturePageCount;
int32_t g_ObjectTextureCount;
uint8_t g_LabTextureUVFlag[MAX_OBJECT_TEXTURES];
int32_t g_NumCameras;
ANIMATED_TEXTURE_RANGE *g_AnimTextureRanges = NULL;
uint32_t *g_DemoData = NULL;
char g_LevelFileName[256];
uint16_t g_MusicTrackFlags[64];
Expand Down

0 comments on commit 40729e6

Please sign in to comment.