Skip to content

Commit

Permalink
room: refactor floor data
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 committed Aug 2, 2024
1 parent 0e27908 commit f04578e
Show file tree
Hide file tree
Showing 24 changed files with 450 additions and 503 deletions.
27 changes: 9 additions & 18 deletions src/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,20 +781,14 @@ void Camera_UpdateCutscene(void)
Viewport_SetFOV(ref->fov);
}

void Camera_RefreshFromTrigger(int16_t type, int16_t *data)
void Camera_RefreshFromTrigger(const TRIGGER *const trigger)
{
int16_t trigger;
int16_t target_ok = 2;
do {
trigger = *data++;
int16_t value = trigger & VALUE_BITS;

switch (TRIG_BITS(trigger)) {
case TO_CAMERA:
trigger = *data++;

if (value == g_Camera.last) {
g_Camera.number = value;
for (int32_t i = 0; i < trigger->command_count; i++) {
TRIGGER_CMD *cmd = &trigger->commands[i];
if (cmd->type == TO_CAMERA) {
if (cmd->parameter == g_Camera.last) {
g_Camera.number = cmd->parameter;

if (g_Camera.timer < 0 || g_Camera.type == CAM_LOOK
|| g_Camera.type == CAM_COMBAT) {
Expand All @@ -807,15 +801,12 @@ void Camera_RefreshFromTrigger(int16_t type, int16_t *data)
} else {
target_ok = 0;
}
break;

case TO_TARGET:
} else if (cmd->type == TO_TARGET) {
if (g_Camera.type != CAM_LOOK && g_Camera.type != CAM_COMBAT) {
g_Camera.item = &g_Items[value];
g_Camera.item = &g_Items[cmd->parameter];
}
break;
}
} while (!(trigger & END_BIT));
}

if (g_Camera.item != NULL) {
if (!target_ok
Expand Down
2 changes: 1 addition & 1 deletion src/game/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ void Camera_Fixed(void);
void Camera_Update(void);
void Camera_UpdateCutscene(void);
void Camera_OffsetReset(void);
void Camera_RefreshFromTrigger(int16_t type, int16_t *data);
void Camera_RefreshFromTrigger(const TRIGGER *const trigger);
void Camera_MoveManual(void);
void Camera_Apply(void);
3 changes: 2 additions & 1 deletion src/game/carrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ static void Carrier_AnimateDrop(CARRIED_ITEM *item)
pickup->pos.y += pickup->fall_speed;
pickup->rot.y += in_water ? DROP_SLOW_TURN : DROP_FAST_TURN;

if (floor->pit_room != NO_ROOM && pickup->pos.y > (floor->floor << 8)) {
if (floor->pit_room != NO_ROOM
&& pickup->pos.y > (floor->floor.clicks << 8)) {
room_num = floor->pit_room;
}
}
Expand Down
20 changes: 13 additions & 7 deletions src/game/collide.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void Collide_GetCollisionInfo(
coll->mid_floor = height;
coll->mid_ceiling = ceiling;
coll->mid_type = g_HeightType;
coll->trigger = g_TriggerIndex;

int16_t tilt = Room_GetTiltType(floor, x, g_LaraItem->pos.y, z);
coll->tilt_z = tilt >> 8;
Expand Down Expand Up @@ -111,6 +110,9 @@ void Collide_GetCollisionInfo(
ceiling -= y;
}

const FLOOR_INFO *absolute_floor =
Room_GetFloor(x, MAX_HEIGHT, z, &room_num);

coll->front_floor = height;
coll->front_ceiling = ceiling;
coll->front_type = g_HeightType;
Expand All @@ -122,8 +124,8 @@ void Collide_GetCollisionInfo(
&& coll->front_floor > 0) {
coll->front_floor = 512;
} else if (
coll->lava_is_pit && coll->front_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->lava_is_pit && coll->front_floor > 0
&& absolute_floor->death_tile) {
coll->front_floor = 512;
}

Expand All @@ -140,6 +142,8 @@ void Collide_GetCollisionInfo(
ceiling -= y;
}

absolute_floor = Room_GetFloor(x, MAX_HEIGHT, z, &room_num);

coll->left_floor = height;
coll->left_ceiling = ceiling;
coll->left_type = g_HeightType;
Expand All @@ -151,8 +155,8 @@ void Collide_GetCollisionInfo(
&& coll->left_floor > 0) {
coll->left_floor = 512;
} else if (
coll->lava_is_pit && coll->left_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->lava_is_pit && coll->left_floor > 0
&& absolute_floor->death_tile) {
coll->left_floor = 512;
}

Expand All @@ -169,6 +173,8 @@ void Collide_GetCollisionInfo(
ceiling -= y;
}

absolute_floor = Room_GetFloor(x, MAX_HEIGHT, z, &room_num);

coll->right_floor = height;
coll->right_ceiling = ceiling;
coll->right_type = g_HeightType;
Expand All @@ -180,8 +186,8 @@ void Collide_GetCollisionInfo(
&& coll->right_floor > 0) {
coll->right_floor = 512;
} else if (
coll->lava_is_pit && coll->right_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->lava_is_pit && coll->right_floor > 0
&& absolute_floor->death_tile) {
coll->right_floor = 512;
}

Expand Down
31 changes: 16 additions & 15 deletions src/game/inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ static void Inject_TextureOverwrites(

static void Inject_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info);
static void Inject_TriggerParameterChange(
INJECTION *injection, FLOOR_INFO *floor);
static void Inject_SetMusicOneShot(FLOOR_INFO *floor);
INJECTION *injection, FLOOR_INFO *floor, LEVEL_INFO *level_info);
static void Inject_SetMusicOneShot(FLOOR_INFO *floor, LEVEL_INFO *level_info);
static void Inject_InsertFloorData(
INJECTION *injection, FLOOR_INFO *floor, LEVEL_INFO *level_info);
static void Inject_RoomShift(INJECTION *injection, int16_t room_num);
Expand Down Expand Up @@ -1157,10 +1157,10 @@ static void Inject_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info)
File_Read(&edit_type, sizeof(int32_t), 1, fp);
switch (edit_type) {
case FET_TRIGGER_PARAM:
Inject_TriggerParameterChange(injection, floor);
Inject_TriggerParameterChange(injection, floor, level_info);
break;
case FET_MUSIC_ONESHOT:
Inject_SetMusicOneShot(floor);
Inject_SetMusicOneShot(floor, level_info);
break;
case FET_FD_INSERT:
Inject_InsertFloorData(injection, floor, level_info);
Expand All @@ -1180,7 +1180,7 @@ static void Inject_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info)
}

static void Inject_TriggerParameterChange(
INJECTION *injection, FLOOR_INFO *floor)
INJECTION *injection, FLOOR_INFO *floor, LEVEL_INFO *level_info)
{
MYFILE *fp = injection->fp;

Expand All @@ -1204,7 +1204,7 @@ static void Inject_TriggerParameterChange(
}

while (1) {
uint16_t data = g_FloorData[fd_index++];
uint16_t data = level_info->raw_floor_data[fd_index++];
switch (data & DATA_TYPE) {
case FT_DOOR:
case FT_ROOF:
Expand All @@ -1225,7 +1225,7 @@ static void Inject_TriggerParameterChange(
}

while (1) {
int16_t *command = &g_FloorData[fd_index++];
int16_t *command = &level_info->raw_floor_data[fd_index++];

if (TRIG_BITS(*command) == cmd_type) {
int16_t param = *command & VALUE_BITS;
Expand Down Expand Up @@ -1254,7 +1254,7 @@ static void Inject_TriggerParameterChange(
}
}

static void Inject_SetMusicOneShot(FLOOR_INFO *floor)
static void Inject_SetMusicOneShot(FLOOR_INFO *floor, LEVEL_INFO *level_info)
{
if (!floor) {
return;
Expand All @@ -1266,7 +1266,7 @@ static void Inject_SetMusicOneShot(FLOOR_INFO *floor)
}

while (1) {
uint16_t data = g_FloorData[fd_index++];
uint16_t data = level_info->raw_floor_data[fd_index++];
switch (data & DATA_TYPE) {
case FT_DOOR:
case FT_ROOF:
Expand All @@ -1279,15 +1279,15 @@ static void Inject_SetMusicOneShot(FLOOR_INFO *floor)

case FT_TRIGGER: {
uint16_t trig_type = TRIG_TYPE(data);
int16_t *flags = &g_FloorData[fd_index++];
int16_t *flags = &level_info->raw_floor_data[fd_index++];

if (trig_type == TT_SWITCH || trig_type == TT_KEY
|| trig_type == TT_PICKUP) {
fd_index++; // skip entity reference
}

while (1) {
int16_t *command = &g_FloorData[fd_index++];
int16_t *command = &level_info->raw_floor_data[fd_index++];
if (TRIG_BITS(*command) == TO_CD) {
*flags |= IF_ONESHOT;
return;
Expand Down Expand Up @@ -1328,7 +1328,7 @@ static void Inject_InsertFloorData(

floor->index = level_info->floor_data_size;
for (int i = 0; i < data_length; i++) {
g_FloorData[level_info->floor_data_size + i] = data[i];
level_info->raw_floor_data[level_info->floor_data_size + i] = data[i];
}

level_info->floor_data_size += data_length;
Expand Down Expand Up @@ -1373,12 +1373,13 @@ static void Inject_RoomShift(INJECTION *injection, int16_t room_num)
const int8_t wall_height = NO_HEIGHT / STEP_L;
for (int i = 0; i < room->x_size * room->y_size; i++) {
FLOOR_INFO *floor = &room->floor[i];
if (floor->floor == wall_height || floor->ceiling == wall_height) {
if (floor->floor.clicks == wall_height
|| floor->ceiling.clicks == wall_height) {
continue;
}

floor->floor += click_shift;
floor->ceiling += click_shift;
floor->floor.clicks += click_shift;
floor->ceiling.clicks += click_shift;
}

// Update vertex Y values to match; x and z are room-relative.
Expand Down
2 changes: 1 addition & 1 deletion src/game/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void Item_Initialise(int16_t item_num)
int32_t x_floor = (item->pos.z - r->z) >> WALL_SHIFT;
int32_t y_floor = (item->pos.x - r->x) >> WALL_SHIFT;
FLOOR_INFO *floor = &r->floor[x_floor + y_floor * r->x_size];
item->floor = floor->floor << 8;
item->floor = floor->floor.clicks << 8;

if (g_GameInfo.bonus_flag & GBF_NGPLUS) {
item->hit_points *= 2;
Expand Down
9 changes: 3 additions & 6 deletions src/game/lara/lara_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ void Lara_HandleAboveWater(ITEM_INFO *item, COLL_INFO *coll)
coll->old.y = item->pos.y;
coll->old.z = item->pos.z;
coll->radius = LARA_RAD;
coll->trigger = NULL;

coll->lava_is_pit = 0;
coll->slopes_are_walls = 0;
Expand Down Expand Up @@ -240,7 +239,7 @@ void Lara_HandleAboveWater(ITEM_INFO *item, COLL_INFO *coll)
g_LaraCollisionRoutines[item->current_anim_state](item, coll);
Item_UpdateRoom(item, -LARA_HEIGHT / 2);
Gun_Control();
Room_TestTriggers(coll->trigger, false);
Room_TestTriggers(item);
}

void Lara_HandleSurface(ITEM_INFO *item, COLL_INFO *coll)
Expand All @@ -254,7 +253,6 @@ void Lara_HandleSurface(ITEM_INFO *item, COLL_INFO *coll)
coll->old.y = item->pos.y;
coll->old.z = item->pos.z;
coll->radius = SURF_RADIUS;
coll->trigger = NULL;
coll->slopes_are_walls = 0;
coll->slopes_are_pits = 0;
coll->lava_is_pit = 0;
Expand Down Expand Up @@ -307,7 +305,7 @@ void Lara_HandleSurface(ITEM_INFO *item, COLL_INFO *coll)
g_LaraCollisionRoutines[item->current_anim_state](item, coll);
Item_UpdateRoom(item, 100);
Gun_Control();
Room_TestTriggers(coll->trigger, false);
Room_TestTriggers(item);
}

void Lara_HandleUnderwater(ITEM_INFO *item, COLL_INFO *coll)
Expand All @@ -319,7 +317,6 @@ void Lara_HandleUnderwater(ITEM_INFO *item, COLL_INFO *coll)
coll->old.y = item->pos.y;
coll->old.z = item->pos.z;
coll->radius = UW_RADIUS;
coll->trigger = NULL;
coll->slopes_are_walls = 0;
coll->slopes_are_pits = 0;
coll->lava_is_pit = 0;
Expand Down Expand Up @@ -397,5 +394,5 @@ void Lara_HandleUnderwater(ITEM_INFO *item, COLL_INFO *coll)
g_LaraCollisionRoutines[item->current_anim_state](item, coll);
Item_UpdateRoom(item, 0);
Gun_Control();
Room_TestTriggers(coll->trigger, false);
Room_TestTriggers(item);
}
2 changes: 1 addition & 1 deletion src/game/lara/lara_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ bool Lara_LandedBad(ITEM_INFO *item, COLL_INFO *coll)

item->floor = height;
item->pos.y = height;
Room_TestTriggers(g_TriggerIndex, false);
Room_TestTriggers(item);
item->pos.y = oy;

int landspeed = item->fall_speed - DAMAGE_START;
Expand Down
17 changes: 11 additions & 6 deletions src/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ static bool Level_LoadRooms(MYFILE *fp)
File_Read(&floor->index, sizeof(uint16_t), 1, fp);
File_Read(&floor->box, sizeof(int16_t), 1, fp);
File_Read(&floor->pit_room, sizeof(uint8_t), 1, fp);
File_Read(&floor->floor, sizeof(int8_t), 1, fp);
File_Read(&floor->floor.clicks, sizeof(int8_t), 1, fp);
File_Read(&floor->sky_room, sizeof(uint8_t), 1, fp);
File_Read(&floor->ceiling, sizeof(int8_t), 1, fp);
File_Read(&floor->ceiling.clicks, sizeof(int8_t), 1, fp);
}

// Room lights
Expand Down Expand Up @@ -277,11 +277,12 @@ static bool Level_LoadRooms(MYFILE *fp)
}

File_Read(&m_LevelInfo.floor_data_size, sizeof(uint32_t), 1, fp);
g_FloorData = GameBuf_Alloc(
m_LevelInfo.raw_floor_data = Memory_Alloc(
sizeof(uint16_t)
* (m_LevelInfo.floor_data_size + m_InjectionInfo->floor_data_size),
GBUF_FLOOR_DATA);
File_Read(g_FloorData, sizeof(uint16_t), m_LevelInfo.floor_data_size, fp);
* (m_LevelInfo.floor_data_size + m_InjectionInfo->floor_data_size));
File_Read(
m_LevelInfo.raw_floor_data, sizeof(uint16_t),
m_LevelInfo.floor_data_size, fp);

return true;
}
Expand Down Expand Up @@ -877,6 +878,10 @@ static void Level_CompleteSetup(int32_t level_num)
{
Inject_AllInjections(&m_LevelInfo);

// Expand raw FD into sectors
Room_ParseFloorData(m_LevelInfo.raw_floor_data);
Memory_FreePointer(&m_LevelInfo.raw_floor_data);

// Must be called post-injection to allow for floor data changes.
Stats_ObserveRoomsLoad();

Expand Down
6 changes: 2 additions & 4 deletions src/game/objects/creatures/bacon_lara.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,11 @@ void BaconLara_Control(int16_t item_num)
int32_t h = Room_GetHeight(floor, x, y, z);
item->floor = h;

Room_TestTriggers(g_TriggerIndex, true);
Room_TestTriggers(item);
if (item->pos.y >= h) {
item->floor = h;
item->pos.y = h;
floor = Room_GetFloor(x, h, z, &room_num);
Room_GetHeight(floor, x, h, z);
Room_TestTriggers(g_TriggerIndex, true);
Room_TestTriggers(item);
item->gravity_status = 0;
item->fall_speed = 0;
item->goal_anim_state = LS_DEATH;
Expand Down
5 changes: 1 addition & 4 deletions src/game/objects/creatures/torso.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ void Torso_Control(int16_t item_num)
if (item->status == IS_DEACTIVATED) {
Sound_Effect(SFX_ATLANTEAN_DEATH, &item->pos, SPM_NORMAL);
Effect_ExplodingDeath(item_num, -1, TORSO_PART_DAMAGE);
FLOOR_INFO *floor = Room_GetFloor(
item->pos.x, item->pos.y, item->pos.z, &item->room_number);
Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z);
Room_TestTriggers(g_TriggerIndex, true);
Room_TestTriggers(item);

Item_Kill(item_num);
item->status = IS_DEACTIVATED;
Expand Down
6 changes: 4 additions & 2 deletions src/game/objects/general/door.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ static void Door_Shut(DOORPOS_DATA *const d)

floor->index = 0;
floor->box = NO_BOX;
floor->floor = NO_HEIGHT / STEP_L;
floor->ceiling = NO_HEIGHT / STEP_L;
floor->floor.clicks = NO_HEIGHT / STEP_L;
floor->ceiling.clicks = NO_HEIGHT / STEP_L;
floor->sky_room = NO_ROOM;
floor->pit_room = NO_ROOM;
floor->door_room = NO_ROOM;
floor->trigger = NULL;

const int16_t box_num = d->block;
if (box_num != NO_BOX) {
Expand Down
Loading

0 comments on commit f04578e

Please sign in to comment.