Skip to content

Commit

Permalink
level: load anim frames in TRX
Browse files Browse the repository at this point in the history
This introduces LEVEL_INFO in TR2's level module, and makes a common
function for loading the frames post-reading.
  • Loading branch information
lahm86 committed Jan 29, 2025
1 parent fa8e61d commit b0c418a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
9 changes: 9 additions & 0 deletions src/libtrx/game/level/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ void Level_ReadAnimBones(
}
}

void Level_LoadAnimFrames(LEVEL_INFO *const info)
{
const int32_t frame_count =
Anim_GetTotalFrameCount(info->anims.frame_count);
Anim_InitialiseFrames(frame_count);
Anim_LoadFrames(info->anims.frames, info->anims.frame_count);
Memory_FreePointer(&info->anims.frames);
}

void Level_ReadObjects(const int32_t num_objects, VFILE *const file)
{
for (int32_t i = 0; i < num_objects; i++) {
Expand Down
2 changes: 2 additions & 0 deletions src/libtrx/include/libtrx/game/level/common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "../../virtual_file.h"
#include "./types.h"

#define ANIM_BONE_SIZE 4

Expand All @@ -15,6 +16,7 @@ void Level_InitialiseAnimCommands(int32_t num_cmds);
void Level_ReadAnimCommands(int32_t base_idx, int32_t num_cmds, VFILE *file);
void Level_LoadAnimCommands(void);
void Level_ReadAnimBones(int32_t base_idx, int32_t num_bones, VFILE *file);
void Level_LoadAnimFrames(LEVEL_INFO *info);
void Level_ReadObjects(int32_t num_objects, VFILE *file);
void Level_ReadStaticObjects(int32_t num_objects, VFILE *file);
void Level_ReadObjectTextures(
Expand Down
7 changes: 1 addition & 6 deletions src/tr1/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,12 +817,7 @@ static void M_CompleteSetup(const GAME_FLOW_LEVEL *const level)

Inject_AllInjections(&m_LevelInfo);

const int32_t frame_count =
Anim_GetTotalFrameCount(m_LevelInfo.anims.frame_count);
Anim_InitialiseFrames(frame_count);
Anim_LoadFrames(m_LevelInfo.anims.frames, m_LevelInfo.anims.frame_count);
Memory_FreePointer(&m_LevelInfo.anims.frames);

Level_LoadAnimFrames(&m_LevelInfo);
Level_LoadAnimCommands();

M_MarkWaterEdgeVertices();
Expand Down
19 changes: 8 additions & 11 deletions src/tr2/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
#include <libtrx/memory.h>
#include <libtrx/virtual_file.h>

static int16_t *m_AnimFrameData = NULL;
static int32_t m_AnimFrameDataLength = 0;
static LEVEL_INFO m_LevelInfo = {};

static void M_LoadFromFile(const GAME_FLOW_LEVEL *level);
static void M_LoadRooms(VFILE *file);
Expand Down Expand Up @@ -281,10 +280,12 @@ static void M_LoadAnimBones(VFILE *const file)
static void M_LoadAnimFrames(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
m_AnimFrameDataLength = VFile_ReadS32(file);
LOG_INFO("anim frame data size: %d", m_AnimFrameDataLength);
m_AnimFrameData = Memory_Alloc(sizeof(int16_t) * m_AnimFrameDataLength);
VFile_Read(file, m_AnimFrameData, sizeof(int16_t) * m_AnimFrameDataLength);
const int32_t raw_data_count = VFile_ReadS32(file);
m_LevelInfo.anims.frame_count = raw_data_count;
LOG_INFO("anim frame data size: %d", raw_data_count);
m_LevelInfo.anims.frames = Memory_Alloc(sizeof(int16_t) * raw_data_count);
VFile_Read(
file, m_LevelInfo.anims.frames, sizeof(int16_t) * raw_data_count);
Benchmark_End(benchmark, NULL);
}

Expand Down Expand Up @@ -724,11 +725,7 @@ static void M_CompleteSetup(void)

Inject_AllInjections();

const int32_t frame_count = Anim_GetTotalFrameCount(m_AnimFrameDataLength);
Anim_InitialiseFrames(frame_count);
Anim_LoadFrames(m_AnimFrameData, m_AnimFrameDataLength);
Memory_FreePointer(&m_AnimFrameData);

Level_LoadAnimFrames(&m_LevelInfo);
Level_LoadAnimCommands();

// Must be called after Setup_AllObjects using the cached item
Expand Down

0 comments on commit b0c418a

Please sign in to comment.