Skip to content

Commit

Permalink
level: read objects and statics in TRX
Browse files Browse the repository at this point in the history
This moves reading all three object types fully to TRX.
  • Loading branch information
lahm86 committed Feb 2, 2025
1 parent edaa676 commit 48d0c3c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 60 deletions.
21 changes: 18 additions & 3 deletions src/libtrx/game/level/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,11 @@ void Level_LoadAnimFrames(LEVEL_INFO *const info)
Memory_FreePointer(&info->anims.frames);
}

void Level_ReadObjects(const int32_t num_objects, VFILE *const file)
void Level_ReadObjects(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
const int32_t num_objects = VFile_ReadS32(file);
LOG_INFO("objects: %d", num_objects);
for (int32_t i = 0; i < num_objects; i++) {
const GAME_OBJECT_ID object_id = VFile_ReadS32(file);
if (object_id < 0 || object_id >= O_NUMBER_OF) {
Expand All @@ -461,10 +464,15 @@ void Level_ReadObjects(const int32_t num_objects, VFILE *const file)
object->anim_idx = VFile_ReadS16(file);
object->loaded = true;
}

Benchmark_End(benchmark, nullptr);
}

void Level_ReadStaticObjects(const int32_t num_objects, VFILE *const file)
void Level_ReadStaticObjects(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
const int32_t num_objects = VFile_ReadS32(file);
LOG_INFO("static objects: %d", num_objects);
for (int32_t i = 0; i < num_objects; i++) {
const int32_t static_id = VFile_ReadS32(file);
if (static_id < 0 || static_id >= MAX_STATIC_OBJECTS) {
Expand All @@ -485,6 +493,8 @@ void Level_ReadStaticObjects(const int32_t num_objects, VFILE *const file)
static_obj->collidable = (flags & 1) == 0;
static_obj->visible = (flags & 2) != 0;
}

Benchmark_End(benchmark, nullptr);
}

void Level_ReadObjectTextures(
Expand Down Expand Up @@ -519,8 +529,11 @@ void Level_ReadSpriteTextures(
}
}

void Level_ReadSpriteSequences(const int32_t num_sequences, VFILE *const file)
void Level_ReadSpriteSequences(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
const int32_t num_sequences = VFile_ReadS32(file);
LOG_DEBUG("sprite sequences: %d", num_sequences);
for (int32_t i = 0; i < num_sequences; i++) {
const int32_t object_id = VFile_ReadS32(file);
const int16_t num_meshes = VFile_ReadS16(file);
Expand All @@ -541,6 +554,8 @@ void Level_ReadSpriteSequences(const int32_t num_sequences, VFILE *const file)
Shell_ExitSystemFmt("Invalid sprite slot (%d)", object_id);
}
}

Benchmark_End(benchmark, nullptr);
}

void Level_ReadAnimatedTextureRanges(
Expand Down
6 changes: 3 additions & 3 deletions src/libtrx/include/libtrx/game/level/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ 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_ReadObjects(VFILE *file);
void Level_ReadStaticObjects(VFILE *file);
void Level_ReadObjectTextures(
int32_t base_idx, int16_t base_page_idx, int32_t num_textures, VFILE *file);
void Level_ReadSpriteTextures(
int32_t base_idx, int16_t base_page_idx, int32_t num_textures, VFILE *file);
void Level_ReadSpriteSequences(int32_t num_sequences, VFILE *file);
void Level_ReadSpriteSequences(VFILE *file);
void Level_ReadAnimatedTextureRanges(int32_t num_ranges, VFILE *file);
void Level_ReadLightMap(VFILE *file);
void Level_ReadCinematicFrames(VFILE *file);
Expand Down
30 changes: 3 additions & 27 deletions src/tr1/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ static void M_LoadAnimRanges(VFILE *file);
static void M_LoadAnimCommands(VFILE *file);
static void M_LoadAnimBones(VFILE *file);
static void M_LoadAnimFrames(VFILE *file);
static void M_LoadObjects(VFILE *file);
static void M_LoadStaticObjects(VFILE *file);
static void M_LoadTextures(VFILE *file);
static void M_LoadSprites(VFILE *file);
static void M_LoadSoundEffects(VFILE *file);
Expand Down Expand Up @@ -225,10 +223,11 @@ static void M_LoadFromFile(const GF_LEVEL *const level)
M_LoadAnimCommands(file);
M_LoadAnimBones(file);
M_LoadAnimFrames(file);
M_LoadObjects(file);
M_LoadStaticObjects(file);
Level_ReadObjects(file);
Level_ReadStaticObjects(file);
M_LoadTextures(file);
M_LoadSprites(file);
Level_ReadSpriteSequences(file);

if (layout == LEVEL_LAYOUT_TR1_DEMO_PC) {
Level_ReadPalettes(&m_LevelInfo, file);
Expand Down Expand Up @@ -479,24 +478,6 @@ static void M_LoadAnimFrames(VFILE *file)
Benchmark_End(benchmark, nullptr);
}

static void M_LoadObjects(VFILE *file)
{
BENCHMARK *const benchmark = Benchmark_Start();
const int32_t num_objects = VFile_ReadS32(file);
LOG_INFO("%d objects", num_objects);
Level_ReadObjects(num_objects, file);
Benchmark_End(benchmark, nullptr);
}

static void M_LoadStaticObjects(VFILE *file)
{
BENCHMARK *const benchmark = Benchmark_Start();
const int32_t num_static_objects = VFile_ReadS32(file);
LOG_INFO("%d static objects", num_static_objects);
Level_ReadStaticObjects(num_static_objects, file);
Benchmark_End(benchmark, nullptr);
}

static void M_LoadTextures(VFILE *file)
{
BENCHMARK *const benchmark = Benchmark_Start();
Expand All @@ -518,11 +499,6 @@ static void M_LoadSprites(VFILE *file)
Output_InitialiseSpriteTextures(
num_textures + m_InjectionInfo->sprite_info_count);
Level_ReadSpriteTextures(0, 0, num_textures, file);

const int32_t num_sequences = VFile_ReadS32(file);
LOG_DEBUG("sprite sequences: %d", num_sequences);
Level_ReadSpriteSequences(num_sequences, file);

Benchmark_End(benchmark, nullptr);
}

Expand Down
30 changes: 3 additions & 27 deletions src/tr2/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ static void M_LoadAnimRanges(VFILE *file);
static void M_LoadAnimCommands(VFILE *file);
static void M_LoadAnimBones(VFILE *file);
static void M_LoadAnimFrames(VFILE *file);
static void M_LoadObjects(VFILE *file);
static void M_LoadStaticObjects(VFILE *file);
static void M_LoadTextures(VFILE *file);
static void M_LoadSprites(VFILE *file);
static void M_LoadItems(VFILE *file);
Expand Down Expand Up @@ -256,24 +254,6 @@ static void M_LoadAnimFrames(VFILE *const file)
Benchmark_End(benchmark, nullptr);
}

static void M_LoadObjects(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
const int32_t num_objects = VFile_ReadS32(file);
LOG_INFO("objects: %d", num_objects);
Level_ReadObjects(num_objects, file);
Benchmark_End(benchmark, nullptr);
}

static void M_LoadStaticObjects(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
const int32_t num_static_objects = VFile_ReadS32(file);
LOG_INFO("static objects: %d", num_static_objects);
Level_ReadStaticObjects(num_static_objects, file);
Benchmark_End(benchmark, nullptr);
}

static void M_LoadTextures(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
Expand All @@ -291,11 +271,6 @@ static void M_LoadSprites(VFILE *const file)
LOG_DEBUG("sprite textures: %d", num_textures);
Output_InitialiseSpriteTextures(num_textures);
Level_ReadSpriteTextures(0, 0, num_textures, file);

const int32_t num_sequences = VFile_ReadS32(file);
LOG_DEBUG("sprite sequences: %d", num_sequences);
Level_ReadSpriteSequences(num_sequences, file);

Benchmark_End(benchmark, nullptr);
}

Expand Down Expand Up @@ -563,13 +538,14 @@ static void M_LoadFromFile(const GF_LEVEL *const level)
M_LoadAnimBones(file);
M_LoadAnimFrames(file);

M_LoadObjects(file);
Level_ReadObjects(file);
Object_SetupAllObjects();

M_LoadStaticObjects(file);
Level_ReadStaticObjects(file);
M_LoadTextures(file);

M_LoadSprites(file);
Level_ReadSpriteSequences(file);
Level_ReadCamerasAndSinks(file);
M_LoadSoundEffects(file);
M_LoadBoxes(file);
Expand Down

0 comments on commit 48d0c3c

Please sign in to comment.