Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tr2/room: refactor floor data handling #1896

Merged

Conversation

lahm86
Copy link
Collaborator

@lahm86 lahm86 commented Nov 13, 2024

Resolves #1883.

Checklist

  • I have read the coding conventions
  • I have added a changelog entry about what my pull request accomplishes, or it is an internal change

Description

This follows a similar approach as we did for TR1 in #941. Best viewed commit-by-commit to see the iterative changes.

As well as the main FD overhaul, there were a few snagging points that have been addressed here.

  • Item_Initialise was previously called during M_LoadItems in level.c but this had to be shifted because there are floor data dependencies there. We now take a similar approach to TR1, so load the level data, then perform a "CompleteSetup"; this can be expanded later for things like injection processing.
  • With the above, @aredfan found that if you start a level then go back to the title screen, it can crash. g_LevelItemCount wasn't being set to 0 here - not an issue originally because Item_Initialise (where the crash would occur) would have been skipped in that case.
  • While the triggers that are meant to activate after pulling the dagger from the dragon are heavy, the call to test triggers came from Lara's extra anim routine. As we now pass the item, which determines the heavy state, this had to be amended to locate the dragon bones item and to pass that. The dragon control has already ended by the time the extra anim completes so we couldn't add the call anywhere there, and running it too early meant issues like the camera still being in cinematic mode while looking at the doors opening.

The dragon may need some extra checks based on where it lands e.g. if partially in the wall. I may change this to behave like the Torso in TR1, where it checks a range of surrounding sectors.

For testing, attached is a level with various trigger types, basic geometry, ladders, and death tiles. I didn't include a dragon for testing, that can be done in OG easily enough. For ceiling geometry, it's best to fly against it and hold down to see that Lara follows the structure properly.

WALL.zip

There is a lot of scope now for sharing FD handling with TR1, but that can be tackled in the future. I may follow this up with some minor changes, like moving all FD macros to libtrx and renaming some enums, but I didn't want to touch TR1 at all in this PR.

@lahm86 lahm86 added Internal The invisible stuff Enhancement Improvement of an existing feature TR2 labels Nov 13, 2024
@lahm86 lahm86 self-assigned this Nov 13, 2024
@lahm86 lahm86 force-pushed the issue-1883-refactor-tr2-floor-data branch from 244613a to f7d8927 Compare November 13, 2024 22:23
Copy link

github-actions bot commented Nov 13, 2024

@aredfan
Copy link
Collaborator

aredfan commented Nov 14, 2024

An issue I found that is currently confined to this PR - the /title command closes the game prematurely.

@lahm86
Copy link
Collaborator Author

lahm86 commented Nov 14, 2024

An issue I found that is currently confined to this PR - the /title command closes the game prematurely.

Thanks, now addressed. The global item count wasn't being set to 0 for the title level. It wasn't an issue before because we were skipping Item_Initialise in that case, but that call now happens after everything else has loaded. So it was trying to load based on the count of whichever level you were on previously.

This prepares for additional loading activities we will need to
perform, such as FD parsing. This is akin to TR1.
This creates a shell floor data master parser to (later) allow setting
all relevant properties for sectors once, thus reducing FD iteration
and complexity throughout the codebase.
This creates a tilt property for each sector, which is populated via
floor data parsing. Calls related to GetHeight for floor and ceiling
have been updated to use this property.
This creates a wall portal room property for each sector, which is
initialised to NO_ROOM and populated via floor data parsing.
Room_GetDoor is now redundant.
This also moves sky and pit portals, together with wall, into a struct
in the sector for readability.
Adds functions to get absolute pit and sky sectors, given another
sector and X/Z values, to eliminate repeated looping logic where
feasible.
Adds a death property to SECTOR. This contains a temporary check in
Room_TestTriggers until we can later eliminate g_TriggerIndex.
Adds a more explicit ladder property and makes the ladder test less
cryptic as a result.
@lahm86 lahm86 force-pushed the issue-1883-refactor-tr2-floor-data branch from ad3b40b to 7b5e265 Compare November 15, 2024 09:21
@lahm86 lahm86 marked this pull request as ready for review November 15, 2024 09:23
@lahm86 lahm86 requested review from a team as code owners November 15, 2024 09:23
@lahm86 lahm86 requested review from rr-, walkawayy and aredfan and removed request for a team November 15, 2024 09:23
TT_COMBAT = 7,
TT_DUMMY = 8,
TT_ANTITRIGGER = 9,
} TRIGGER_TYPE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this file is autogenerated, we also need to mark these types as // decompiled in progress.txt, otherwise just tr2-auto will bring them back here.

Triggers are also now directly in sectors, and their list of commands.
Most duplicated FD iterations are now removed. All callers to
Room_TestTriggers updated, and an additional change was needed when
Lara pulls the dagger from the dragon (as she is not heavy).
TR1 and TR2 are now equivalent, bar the ladder property for TR2.
g_FloorData is now redundant, but retained as legacy until decomp
completed.
@lahm86 lahm86 force-pushed the issue-1883-refactor-tr2-floor-data branch from 7b5e265 to 60d20a3 Compare November 15, 2024 11:03
@lahm86 lahm86 merged commit f4162df into LostArtefacts:develop Nov 15, 2024
6 checks passed
@lahm86 lahm86 deleted the issue-1883-refactor-tr2-floor-data branch November 15, 2024 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Improvement of an existing feature Internal The invisible stuff TR2
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Refactor FD data
3 participants