Skip to content

Commit

Permalink
level: structure animated textures
Browse files Browse the repository at this point in the history
This is an internal change to place animated textures into structures
for improved readability.
  • Loading branch information
lahm86 committed Apr 14, 2024
1 parent 0ca1f4b commit 4b0c3b3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
31 changes: 25 additions & 6 deletions src/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,14 +720,33 @@ static bool Level_LoadBoxes(MYFILE *fp)

static bool Level_LoadAnimatedTextures(MYFILE *fp)
{
int16_t num_ranges;
File_Read(&m_LevelInfo.anim_texture_range_count, sizeof(int32_t), 1, fp);
LOG_INFO("%d animated textures", m_LevelInfo.anim_texture_range_count);
File_Read(&num_ranges, sizeof(int16_t), 1, fp);
LOG_INFO("%d animated texture ranges", num_ranges);
if (!num_ranges) {
g_AnimTextureRanges = NULL;
return true;
}

g_AnimTextureRanges = GameBuf_Alloc(
sizeof(int16_t) * m_LevelInfo.anim_texture_range_count,
GBUF_ANIMATING_TEXTURE_RANGES);
File_Read(
g_AnimTextureRanges, sizeof(int16_t),
m_LevelInfo.anim_texture_range_count, fp);
sizeof(TEXTURE_RANGE) * num_ranges, GBUF_ANIMATING_TEXTURE_RANGES);
for (int32_t i = 0; i < num_ranges; i++) {
TEXTURE_RANGE *range = &g_AnimTextureRanges[i];
range->next_range =
i == num_ranges - 1 ? NULL : &g_AnimTextureRanges[i + 1];

// Level data is tied to the original logic in Output_AnimateTextures
// and hence stores one less than the actual count here.
File_Read(&range->num_textures, sizeof(int16_t), 1, fp);
range->num_textures++;

range->textures = GameBuf_Alloc(
sizeof(int16_t) * range->num_textures,
GBUF_ANIMATING_TEXTURE_RANGES);
File_Read(range->textures, sizeof(int16_t), range->num_textures, fp);
}

return true;
}

Expand Down
23 changes: 9 additions & 14 deletions src/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,21 +928,16 @@ void Output_AnimateTextures(void)
return;
}

if (g_AnimTextureRanges) {
const int16_t *ptr = g_AnimTextureRanges;
int16_t i = *ptr++;
while (i > 0) {
int16_t j = *ptr++;
const PHD_TEXTURE temp = g_PhdTextureInfo[*ptr];
while (j > 0) {
g_PhdTextureInfo[ptr[0]] = g_PhdTextureInfo[ptr[1]];
j--;
ptr++;
}
g_PhdTextureInfo[*ptr] = temp;
i--;
ptr++;
const TEXTURE_RANGE *range = g_AnimTextureRanges;
while (range) {
int32_t i = 0;
const PHD_TEXTURE temp = g_PhdTextureInfo[range->textures[i]];
for (; i < range->num_textures - 1; i++) {
g_PhdTextureInfo[range->textures[i]] =
g_PhdTextureInfo[range->textures[i + 1]];
}
g_PhdTextureInfo[range->textures[i]] = temp;
range = range->next_range;
}

for (int32_t i = 0; i < STATIC_NUMBER_OF; i++) {
Expand Down
6 changes: 6 additions & 0 deletions src/global/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,12 @@ typedef struct PHD_SPRITE {
int16_t y2;
} PHD_SPRITE;

typedef struct TEXTURE_RANGE {
int16_t num_textures;
int16_t *textures;
struct TEXTURE_RANGE *next_range;
} TEXTURE_RANGE;

typedef struct DOOR_INFO {
int16_t room_num;
struct {
Expand Down
2 changes: 1 addition & 1 deletion src/global/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int16_t *g_FlyZone[2] = { NULL };
ANIM_STRUCT *g_Anims = NULL;
ANIM_CHANGE_STRUCT *g_AnimChanges = NULL;
ANIM_RANGE_STRUCT *g_AnimRanges = NULL;
int16_t *g_AnimTextureRanges = NULL;
TEXTURE_RANGE *g_AnimTextureRanges = NULL;
int16_t *g_AnimCommands = NULL;
int32_t *g_AnimBones = NULL;
FRAME_INFO *g_AnimFrames = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/global/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extern int16_t *g_FlyZone[2];
extern ANIM_STRUCT *g_Anims;
extern ANIM_CHANGE_STRUCT *g_AnimChanges;
extern ANIM_RANGE_STRUCT *g_AnimRanges;
extern int16_t *g_AnimTextureRanges;
extern TEXTURE_RANGE *g_AnimTextureRanges;
extern int16_t *g_AnimCommands;
extern int32_t *g_AnimBones;
extern FRAME_INFO *g_AnimFrames;
Expand Down

0 comments on commit 4b0c3b3

Please sign in to comment.