Skip to content

Commit

Permalink
level: load objects and items in TRX
Browse files Browse the repository at this point in the history
This moves the object setup and item initialisation calls to TRX in a
common routine.
  • Loading branch information
lahm86 committed Feb 7, 2025
1 parent a0cf0f6 commit e696c2c
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 40 deletions.
14 changes: 14 additions & 0 deletions src/libtrx/game/level/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "game/game_buf.h"
#include "game/inject.h"
#include "game/objects/common.h"
#include "game/objects/setup.h"
#include "game/output.h"
#include "game/rooms.h"
#include "game/shell.h"
Expand Down Expand Up @@ -822,3 +823,16 @@ void Level_LoadPalettes(LEVEL_INFO *const info)
Memory_FreePointer(&info->palette.data_24);
Memory_FreePointer(&info->palette.data_32);
}

void Level_LoadObjectsAndItems(void)
{
// Object and item setup/initialisation must take place after injections
// have been processed. We also need to use a cached item count as
// individual initialisations may increment the total item count.
Object_SetupAllObjects();

const int32_t item_count = Item_GetLevelCount();
for (int32_t i = 0; i < item_count; i++) {
Item_Initialise(i);
}
}
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/items/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void Item_SetPrevActive(int16_t item_num);
int32_t Item_GetDistance(const ITEM *item, const XYZ_32 *target);
void Item_TakeDamage(ITEM *item, int16_t damage, bool hit_status);

void Item_Initialise(int16_t item_num);
int16_t Item_Create(void);
int16_t Item_CreateLevelItem(void);
void Item_Kill(int16_t item_num);
Expand Down
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/level/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ void Level_ReadItems(VFILE *file);

void Level_LoadTexturePages(LEVEL_INFO *info);
void Level_LoadPalettes(LEVEL_INFO *info);
void Level_LoadObjectsAndItems(void);
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#pragma once

#include "global/types.h"

void Object_SetupAllObjects(void);
1 change: 0 additions & 1 deletion src/tr1/game/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <stdint.h>

void Item_Control(void);
void Item_Initialise(int16_t item_num);
void Item_UpdateRoom(ITEM *item, int32_t height);
int16_t Item_GetHeight(ITEM *item);
int16_t Item_GetWaterHeight(ITEM *item);
Expand Down
11 changes: 1 addition & 10 deletions src/tr1/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "game/music.h"
#include "game/objects/creatures/mutant.h"
#include "game/objects/creatures/pierre.h"
#include "game/objects/setup.h"
#include "game/output.h"
#include "game/overlay.h"
#include "game/random.h"
Expand Down Expand Up @@ -535,15 +534,7 @@ static void M_CompleteSetup(const GF_LEVEL *const level)
// Must be called post-injection to allow for floor data changes.
Stats_ObserveRoomsLoad();

// Must be called after all animations, meshes etc are initialised.
Object_SetupAllObjects();

// Must be called after Setup_AllObjects using the cached item count, as
// individual setups may increment the level item count.
const int32_t item_count = Item_GetLevelCount();
for (int32_t i = 0; i < item_count; i++) {
Item_Initialise(i);
}
Level_LoadObjectsAndItems();

Lara_State_Initialise();

Expand Down
2 changes: 0 additions & 2 deletions src/tr1/game/objects/setup.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "game/objects/setup.h"

#include "game/lara/common.h"
#include "game/lara/hair.h"
#include "game/objects/common.h"
Expand Down
1 change: 0 additions & 1 deletion src/tr2/game/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "global/types.h"

void Item_Control(void);
void Item_Initialise(int16_t item_num);
void Item_ClearKilled(void);
void Item_ShiftCol(ITEM *item, COLL_INFO *coll);
void Item_UpdateRoom(ITEM *item, int32_t height);
Expand Down
11 changes: 1 addition & 10 deletions src/tr2/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "game/lara/control.h"
#include "game/lot.h"
#include "game/music.h"
#include "game/objects/setup.h"
#include "game/output.h"
#include "game/overlay.h"
#include "game/random.h"
Expand Down Expand Up @@ -382,8 +381,6 @@ static void M_LoadFromFile(const GF_LEVEL *const level)
M_LoadAnimFrames(file);

Level_ReadObjects(file);
Object_SetupAllObjects();

Level_ReadStaticObjects(file);
M_LoadTextures(file);

Expand Down Expand Up @@ -412,13 +409,7 @@ static void M_CompleteSetup(void)

Level_LoadAnimFrames(&m_LevelInfo);
Level_LoadAnimCommands();

// Must be called after Setup_AllObjects using the cached item count, as
// individual setups may increment the level item count.
const int32_t item_count = Item_GetLevelCount();
for (int32_t i = 0; i < item_count; i++) {
Item_Initialise(i);
}
Level_LoadObjectsAndItems();

Level_LoadTexturePages(&m_LevelInfo);
Level_LoadPalettes(&m_LevelInfo);
Expand Down
17 changes: 9 additions & 8 deletions src/tr2/game/objects/setup.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "game/objects/setup.h"

#include "game/lara/control.h"
#include "game/lara/hair.h"
#include "game/objects/common.h"
Expand Down Expand Up @@ -121,6 +119,9 @@

static void M_SetupLara(void);
static void M_SetupLaraExtra(void);
static void M_SetupBaddyObjects(void);
static void M_SetupTrapObjects(void);
static void M_SetupGeneralObjects(void);

static void M_SetupLara(void)
{
Expand All @@ -143,7 +144,7 @@ static void M_SetupLaraExtra(void)
obj->control = Lara_ControlExtra;
}

void Object_SetupBaddyObjects(void)
static void M_SetupBaddyObjects(void)
{
M_SetupLara();
M_SetupLaraExtra();
Expand Down Expand Up @@ -188,7 +189,7 @@ void Object_SetupBaddyObjects(void)
Winston_Setup();
}

void Object_SetupTrapObjects(void)
static void M_SetupTrapObjects(void)
{
Blade_Setup();
DartEmitter_Setup();
Expand Down Expand Up @@ -223,7 +224,7 @@ void Object_SetupTrapObjects(void)
TeethTrap_Setup();
}

void Object_SetupGeneralObjects(void)
static void M_SetupGeneralObjects(void)
{
Boat_Setup();
SkidooArmed_Setup();
Expand Down Expand Up @@ -396,9 +397,9 @@ void Object_SetupAllObjects(void)
obj->intelligent = 0;
}

Object_SetupBaddyObjects();
Object_SetupTrapObjects();
Object_SetupGeneralObjects();
M_SetupBaddyObjects();
M_SetupTrapObjects();
M_SetupGeneralObjects();

Lara_Hair_Initialise();
}
6 changes: 0 additions & 6 deletions src/tr2/game/objects/setup.h

This file was deleted.

0 comments on commit e696c2c

Please sign in to comment.