Skip to content

Commit 9904e75

Browse files
authored
level: structure animated textures (LostArtefacts#1303)
This is an internal change to place animated textures into structures for improved readability.
1 parent c39be6f commit 9904e75

File tree

5 files changed

+42
-22
lines changed

5 files changed

+42
-22
lines changed

src/game/level.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -720,14 +720,33 @@ static bool Level_LoadBoxes(MYFILE *fp)
720720

721721
static bool Level_LoadAnimatedTextures(MYFILE *fp)
722722
{
723+
int16_t num_ranges;
723724
File_Read(&m_LevelInfo.anim_texture_range_count, sizeof(int32_t), 1, fp);
724-
LOG_INFO("%d animated textures", m_LevelInfo.anim_texture_range_count);
725+
File_Read(&num_ranges, sizeof(int16_t), 1, fp);
726+
LOG_INFO("%d animated texture ranges", num_ranges);
727+
if (!num_ranges) {
728+
g_AnimTextureRanges = NULL;
729+
return true;
730+
}
731+
725732
g_AnimTextureRanges = GameBuf_Alloc(
726-
sizeof(int16_t) * m_LevelInfo.anim_texture_range_count,
727-
GBUF_ANIMATING_TEXTURE_RANGES);
728-
File_Read(
729-
g_AnimTextureRanges, sizeof(int16_t),
730-
m_LevelInfo.anim_texture_range_count, fp);
733+
sizeof(TEXTURE_RANGE) * num_ranges, GBUF_ANIMATING_TEXTURE_RANGES);
734+
for (int32_t i = 0; i < num_ranges; i++) {
735+
TEXTURE_RANGE *range = &g_AnimTextureRanges[i];
736+
range->next_range =
737+
i == num_ranges - 1 ? NULL : &g_AnimTextureRanges[i + 1];
738+
739+
// Level data is tied to the original logic in Output_AnimateTextures
740+
// and hence stores one less than the actual count here.
741+
File_Read(&range->num_textures, sizeof(int16_t), 1, fp);
742+
range->num_textures++;
743+
744+
range->textures = GameBuf_Alloc(
745+
sizeof(int16_t) * range->num_textures,
746+
GBUF_ANIMATING_TEXTURE_RANGES);
747+
File_Read(range->textures, sizeof(int16_t), range->num_textures, fp);
748+
}
749+
731750
return true;
732751
}
733752

src/game/output.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -928,21 +928,16 @@ void Output_AnimateTextures(void)
928928
return;
929929
}
930930

931-
if (g_AnimTextureRanges) {
932-
const int16_t *ptr = g_AnimTextureRanges;
933-
int16_t i = *ptr++;
934-
while (i > 0) {
935-
int16_t j = *ptr++;
936-
const PHD_TEXTURE temp = g_PhdTextureInfo[*ptr];
937-
while (j > 0) {
938-
g_PhdTextureInfo[ptr[0]] = g_PhdTextureInfo[ptr[1]];
939-
j--;
940-
ptr++;
941-
}
942-
g_PhdTextureInfo[*ptr] = temp;
943-
i--;
944-
ptr++;
931+
const TEXTURE_RANGE *range = g_AnimTextureRanges;
932+
while (range) {
933+
int32_t i = 0;
934+
const PHD_TEXTURE temp = g_PhdTextureInfo[range->textures[i]];
935+
for (; i < range->num_textures - 1; i++) {
936+
g_PhdTextureInfo[range->textures[i]] =
937+
g_PhdTextureInfo[range->textures[i + 1]];
945938
}
939+
g_PhdTextureInfo[range->textures[i]] = temp;
940+
range = range->next_range;
946941
}
947942

948943
for (int32_t i = 0; i < STATIC_NUMBER_OF; i++) {

src/global/types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,12 @@ typedef struct PHD_SPRITE {
11421142
int16_t y2;
11431143
} PHD_SPRITE;
11441144

1145+
typedef struct TEXTURE_RANGE {
1146+
int16_t num_textures;
1147+
int16_t *textures;
1148+
struct TEXTURE_RANGE *next_range;
1149+
} TEXTURE_RANGE;
1150+
11451151
typedef struct DOOR_INFO {
11461152
int16_t room_num;
11471153
struct {

src/global/vars.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int16_t *g_FlyZone[2] = { NULL };
7979
ANIM_STRUCT *g_Anims = NULL;
8080
ANIM_CHANGE_STRUCT *g_AnimChanges = NULL;
8181
ANIM_RANGE_STRUCT *g_AnimRanges = NULL;
82-
int16_t *g_AnimTextureRanges = NULL;
82+
TEXTURE_RANGE *g_AnimTextureRanges = NULL;
8383
int16_t *g_AnimCommands = NULL;
8484
int32_t *g_AnimBones = NULL;
8585
FRAME_INFO *g_AnimFrames = NULL;

src/global/vars.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extern int16_t *g_FlyZone[2];
6767
extern ANIM_STRUCT *g_Anims;
6868
extern ANIM_CHANGE_STRUCT *g_AnimChanges;
6969
extern ANIM_RANGE_STRUCT *g_AnimRanges;
70-
extern int16_t *g_AnimTextureRanges;
70+
extern TEXTURE_RANGE *g_AnimTextureRanges;
7171
extern int16_t *g_AnimCommands;
7272
extern int32_t *g_AnimBones;
7373
extern FRAME_INFO *g_AnimFrames;

0 commit comments

Comments
 (0)