Skip to content

Commit cbfd30d

Browse files
committed
level: load anim frames in TRX
This introduces LEVEL_INFO in TR2's level module, and makes a common function for loading the frames post-reading.
1 parent ced8852 commit cbfd30d

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

src/libtrx/game/level/common.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,15 @@ void Level_ReadAnimBones(
326326
}
327327
}
328328

329+
void Level_LoadAnimFrames(LEVEL_INFO *const info)
330+
{
331+
const int32_t frame_count =
332+
Anim_GetTotalFrameCount(info->anims.frame_count);
333+
Anim_InitialiseFrames(frame_count);
334+
Anim_LoadFrames(info->anims.frames, info->anims.frame_count);
335+
Memory_FreePointer(&info->anims.frames);
336+
}
337+
329338
void Level_ReadObjects(const int32_t num_objects, VFILE *const file)
330339
{
331340
for (int32_t i = 0; i < num_objects; i++) {

src/libtrx/include/libtrx/game/level/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "../../virtual_file.h"
4+
#include "./types.h"
45

56
#define ANIM_BONE_SIZE 4
67

@@ -15,6 +16,7 @@ void Level_InitialiseAnimCommands(int32_t num_cmds);
1516
void Level_ReadAnimCommands(int32_t base_idx, int32_t num_cmds, VFILE *file);
1617
void Level_LoadAnimCommands(void);
1718
void Level_ReadAnimBones(int32_t base_idx, int32_t num_bones, VFILE *file);
19+
void Level_LoadAnimFrames(LEVEL_INFO *info);
1820
void Level_ReadObjects(int32_t num_objects, VFILE *file);
1921
void Level_ReadStaticObjects(int32_t num_objects, VFILE *file);
2022
void Level_ReadObjectTextures(

src/tr1/game/level.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,7 @@ static void M_CompleteSetup(const GAME_FLOW_LEVEL *const level)
817817

818818
Inject_AllInjections(&m_LevelInfo);
819819

820-
const int32_t frame_count =
821-
Anim_GetTotalFrameCount(m_LevelInfo.anims.frame_count);
822-
Anim_InitialiseFrames(frame_count);
823-
Anim_LoadFrames(m_LevelInfo.anims.frames, m_LevelInfo.anims.frame_count);
824-
Memory_FreePointer(&m_LevelInfo.anims.frames);
825-
820+
Level_LoadAnimFrames(&m_LevelInfo);
826821
Level_LoadAnimCommands();
827822

828823
M_MarkWaterEdgeVertices();

src/tr2/game/level.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
#include <libtrx/memory.h>
3333
#include <libtrx/virtual_file.h>
3434

35-
static int16_t *m_AnimFrameData = NULL;
36-
static int32_t m_AnimFrameDataLength = 0;
35+
static LEVEL_INFO m_LevelInfo = {};
3736

3837
static void M_LoadFromFile(const GAME_FLOW_LEVEL *level);
3938
static void M_LoadRooms(VFILE *file);
@@ -281,10 +280,12 @@ static void M_LoadAnimBones(VFILE *const file)
281280
static void M_LoadAnimFrames(VFILE *const file)
282281
{
283282
BENCHMARK *const benchmark = Benchmark_Start();
284-
m_AnimFrameDataLength = VFile_ReadS32(file);
285-
LOG_INFO("anim frame data size: %d", m_AnimFrameDataLength);
286-
m_AnimFrameData = Memory_Alloc(sizeof(int16_t) * m_AnimFrameDataLength);
287-
VFile_Read(file, m_AnimFrameData, sizeof(int16_t) * m_AnimFrameDataLength);
283+
const int32_t raw_data_count = VFile_ReadS32(file);
284+
m_LevelInfo.anims.frame_count = raw_data_count;
285+
LOG_INFO("anim frame data size: %d", raw_data_count);
286+
m_LevelInfo.anims.frames = Memory_Alloc(sizeof(int16_t) * raw_data_count);
287+
VFile_Read(
288+
file, m_LevelInfo.anims.frames, sizeof(int16_t) * raw_data_count);
288289
Benchmark_End(benchmark, NULL);
289290
}
290291

@@ -724,11 +725,7 @@ static void M_CompleteSetup(void)
724725

725726
Inject_AllInjections();
726727

727-
const int32_t frame_count = Anim_GetTotalFrameCount(m_AnimFrameDataLength);
728-
Anim_InitialiseFrames(frame_count);
729-
Anim_LoadFrames(m_AnimFrameData, m_AnimFrameDataLength);
730-
Memory_FreePointer(&m_AnimFrameData);
731-
728+
Level_LoadAnimFrames(&m_LevelInfo);
732729
Level_LoadAnimCommands();
733730

734731
// Must be called after Setup_AllObjects using the cached item

0 commit comments

Comments
 (0)