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

output: move texture pages and palettes to TRX #2415

Merged
merged 11 commits into from
Jan 31, 2025

Conversation

lahm86
Copy link
Collaborator

@lahm86 lahm86 commented Jan 30, 2025

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
  • I have added a readme entry about my new feature or OG bug fix, or it is a different change

Description

This moves texture pages and palettes fully to TRX, and gets TR1 and TR2 both loading and handling the data in similar ways. Globals are removed and common accessors are available accordingly instead.

I've adjusted TR1 to initially skip textures pages when reading the level, delaying it until after the palette has been read; this means we can create the 32-bit pages on read rather than having the logic fragmented between the original read and later just before moving on to injections. TR2 is similar here, we interpret the ARGB1555 on read into 32-bit. So overall, TR2 is in a place ready to support texture injections, and the reading logic/flow is very similar for both.

I also moved g_NamedColors into TR2's output module as it's only referenced there. I'm wondering if we can eventually replace this with direct RGB values, but that's a separate task I'd say.

This adds common texture page storage in TRX.
This removes the global texture pages in TR1 and uses the common
storage in TRX instead.
This removes the global texture pages in TR2 and uses the common
storage in TRX instead.
@lahm86 lahm86 added Internal The invisible stuff TR2 TR1 labels Jan 30, 2025
@lahm86 lahm86 self-assigned this Jan 30, 2025
@lahm86 lahm86 requested review from a team as code owners January 30, 2025 21:05
@lahm86 lahm86 requested review from rr-, walkawayy and aredfan and removed request for a team January 30, 2025 21:06
Copy link

github-actions bot commented Jan 30, 2025

}

int16_t Output_FindColor8(
const int32_t red, const int32_t green, const int32_t blue)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could pass RGB_888 here?

{
int32_t best_idx = 0;
int32_t best_diff = INT32_MAX;
for (int32_t i = 0; i < m_PaletteSize; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can start at index 1, since we assume best_idx to be 0.
Do we care to return -1 if there is no palette?

output->g = 0;
output->b = 0;
output->a = 0;
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this check necessary considering we hardcode the index 0 to hold zeroes in M_LoadPalette?

for (int32_t i = 0; i < palette_size; i++) {
m_LevelInfo.palette.data_32[i].r = palette_16[i].r;
m_LevelInfo.palette.data_32[i].g = palette_16[i].g;
m_LevelInfo.palette.data_32[i].b = palette_16[i].b;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I might be mistaken but I think we already have most of this functionality in TRX.

VFile_Read(file, input, texture_size_16_bit);
RGBA_8888 *output = m_LevelInfo.textures.pages_32;
for (int32_t i = 0; i < num_pages * TEXTURE_PAGE_SIZE; i++) {
*output++ = Render_ARGB1555To8888(*input++);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this part could be put into TRX too already at this stage?

This delays reading and preparing the texture pages in TR1 until the
palette is loaded to avoid disjointed setup of LEVEL_INFO, and to bring
the logic more close to TR2.
This adds common palette storage in TRX.
This migrates TR1 to use the TRX palette API.
This migrates TR2 to use the TRX palette API.
@lahm86
Copy link
Collaborator Author

lahm86 commented Jan 31, 2025

@rr- all addressed, thank you. I had somehow overlooked shifting the actual palette/texture reading to TRX; there is a temporary workaround of passing the injection texture page count here for TR1, but that will be eliminated further down the line with the injection refactor.
@aredfan could be worth another quick check as a few things have been shifted about. Thanks!

@lahm86 lahm86 requested review from aredfan and rr- January 31, 2025 11:58
@aredfan
Copy link
Collaborator

aredfan commented Jan 31, 2025

@lahm86 I found a small issue with the draw distance fog colour.

20250131_130420_The_Dragons_Lair

This moves the named colors array into TR2's output module, the only
place it is referenced. Perhaps this can be further refactored at a
later date to pass RGB values rather than palette indices.
This moves the final texture and palette setup after level/injection
loading to TRX.
This makes the palette and texture page readers for both games common
in TRX.
@lahm86
Copy link
Collaborator Author

lahm86 commented Jan 31, 2025

@lahm86 I found a small issue with the draw distance fog colour.

20250131_130420_The_Dragons_Lair

Thanks, fixed.

Copy link
Collaborator

@rr- rr- left a comment

Choose a reason for hiding this comment

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

Apologies for recommending a faulty optimization for the palettes. LGTM.

@lahm86
Copy link
Collaborator Author

lahm86 commented Jan 31, 2025

Apologies for recommending a faulty optimization for the palettes. LGTM.

Not a problem, it seemed logical to me too.

@lahm86 lahm86 merged commit 01ef336 into LostArtefacts:develop Jan 31, 2025
8 checks passed
@lahm86 lahm86 deleted the common-tex-pages branch January 31, 2025 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internal The invisible stuff TR1 TR2
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants