Skip to content

Commit

Permalink
output: use accessor for object texture count
Browse files Browse the repository at this point in the history
This replaces g_ObjectTextureCount with static storage in the common
output module, and introduces an accessor. TR1 will also set this value
although it remains unused.
  • Loading branch information
lahm86 committed Jan 28, 2025
1 parent 3f54f34 commit 6a6878e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/libtrx/game/level/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ void Level_ReadObjectTextures(
texture->uv[j].v = VFile_ReadU16(file);
}
}

Output_SetObjectTextureCount(base_idx + num_textures);
}

void Level_ReadSpriteTextures(
Expand Down
11 changes: 11 additions & 0 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 int32_t m_ObjectTextureCount = 0;
static OBJECT_TEXTURE m_ObjectTextures[MAX_OBJECT_TEXTURES] = {};
static SPRITE_TEXTURE m_SpriteTextures[MAX_SPRITE_TEXTURES] = {};
static ANIMATED_TEXTURE_RANGE *m_AnimTextureRanges = NULL;
Expand Down Expand Up @@ -120,6 +121,16 @@ ANIMATED_TEXTURE_RANGE *Output_GetAnimatedTextureRange(const int32_t range_idx)
return &m_AnimTextureRanges[range_idx];
}

void Output_SetObjectTextureCount(const int32_t num_textures)
{
m_ObjectTextureCount = num_textures;
}

int32_t Output_GetObjectTextureCount(void)
{
return m_ObjectTextureCount;
}

OBJECT_TEXTURE *Output_GetObjectTexture(const int32_t texture_idx)
{
return &m_ObjectTextures[texture_idx];
Expand Down
2 changes: 2 additions & 0 deletions src/libtrx/include/libtrx/game/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ 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_SetObjectTextureCount(int32_t num_textures);
int32_t Output_GetObjectTextureCount(void);
OBJECT_TEXTURE *Output_GetObjectTexture(int32_t texture_idx);
SPRITE_TEXTURE *Output_GetSpriteTexture(int32_t texture_idx);
void Output_CycleAnimatedTextures(void);
Expand Down
3 changes: 1 addition & 2 deletions src/tr2/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ static void M_LoadTextures(VFILE *const file)
Level_ReadObjectTextures(0, 0, num_textures, file);

// TODO: handle this post-injection/packing
g_ObjectTextureCount = num_textures;
for (int32_t i = 0; i < num_textures; i++) {
OBJECT_TEXTURE *const texture = Output_GetObjectTexture(i);
uint16_t *const uv = &texture->uv[0].u;
Expand Down Expand Up @@ -856,5 +855,5 @@ void Level_Unload(void)
strcpy(g_LevelFileName, "");
memset(g_TexturePageBuffer8, 0, sizeof(uint8_t *) * MAX_TEXTURE_PAGES);
memset(g_TexturePageBuffer16, 0, sizeof(uint16_t *) * MAX_TEXTURE_PAGES);
g_ObjectTextureCount = 0;
Output_SetObjectTextureCount(0);
}
5 changes: 3 additions & 2 deletions src/tr2/game/render/priv.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ int32_t Render_GetUVAdjustment(void)

void Render_AdjustTextureUVs(const bool reset_uv_add)
{
if (g_ObjectTextureCount <= 0) {
const int32_t num_textures = Output_GetObjectTextureCount();
if (num_textures <= 0) {
return;
}

const int32_t offset = Render_GetUVAdjustment();
for (int32_t i = 0; i < g_ObjectTextureCount; i++) {
for (int32_t i = 0; i < num_textures; i++) {
OBJECT_TEXTURE *const texture = Output_GetObjectTexture(i);
TEXTURE_UV *const uv = texture->uv;
const TEXTURE_UV *const uv_backup = texture->uv_backup;
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 @@ -112,7 +112,6 @@ int32_t g_FlipMaps[MAX_FLIP_MAPS];
bool g_CameraUnderwater;
int32_t g_BoxCount;
int32_t g_TexturePageCount;
int32_t g_ObjectTextureCount;
uint8_t g_LabTextureUVFlag[MAX_OBJECT_TEXTURES];
int32_t g_NumCameras;
uint32_t *g_DemoData = NULL;
Expand Down
1 change: 0 additions & 1 deletion src/tr2/global/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ extern int32_t g_FlipMaps[MAX_FLIP_MAPS];
extern bool g_CameraUnderwater;
extern int32_t g_BoxCount;
extern int32_t g_TexturePageCount;
extern int32_t g_ObjectTextureCount;
extern uint8_t g_LabTextureUVFlag[MAX_OBJECT_TEXTURES];
extern int32_t g_NumCameras;
extern uint32_t *g_DemoData;
Expand Down

0 comments on commit 6a6878e

Please sign in to comment.