Skip to content

Commit

Permalink
output: rename depthQ and gouraud
Browse files Browse the repository at this point in the history
This renames depthQ to light_map and gouraud to shade_map;
  • Loading branch information
lahm86 committed Feb 1, 2025
1 parent b7f8b35 commit 6071e38
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 42 deletions.
14 changes: 7 additions & 7 deletions src/libtrx/game/level/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,20 +562,20 @@ void Level_ReadAnimatedTextureRanges(
}
}

void Level_ReadDepthQ(VFILE *const file)
void Level_ReadLightMap(VFILE *const file)
{
BENCHMARK *const benchmark = Benchmark_Start();
for (int32_t i = 0; i < 32; i++) {
DEPTHQ_ENTRY *const depth = Output_GetDepthQ(i);
VFile_Read(file, depth->index, sizeof(uint8_t) * 256);
depth->index[0] = 0;
LIGHT_MAP *const light_map = Output_GetLightMap(i);
VFile_Read(file, light_map->index, sizeof(uint8_t) * 256);
light_map->index[0] = 0;
}

for (int32_t i = 0; i < 32; i++) {
const DEPTHQ_ENTRY *const depth = Output_GetDepthQ(i);
const LIGHT_MAP *const light_map = Output_GetLightMap(i);
for (int32_t j = 0; j < 256; j++) {
GOURAUD_ENTRY *const gouraud = Output_GetGouraud(j);
gouraud->index[i] = depth->index[j];
SHADE_MAP *const shade_map = Output_GetShadeMap(j);
shade_map->index[i] = light_map->index[j];
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/libtrx/game/output/textures.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ static int32_t m_PaletteSize = 0;
static RGB_888 *m_Palette8 = nullptr;
static RGB_888 *m_Palette16 = nullptr;

static DEPTHQ_ENTRY m_DepthQTable[32];
static GOURAUD_ENTRY m_GouraudTable[256];
static LIGHT_MAP m_LightMap[32];
static SHADE_MAP m_ShadeMap[256];

static int32_t m_ObjectTextureCount = 0;
static OBJECT_TEXTURE *m_ObjectTextures = nullptr;
Expand Down Expand Up @@ -127,14 +127,14 @@ RGB_888 Output_GetPaletteColor16(const uint16_t idx)
return m_Palette16[idx];
}

DEPTHQ_ENTRY *Output_GetDepthQ(const uint8_t idx)
LIGHT_MAP *Output_GetLightMap(const uint8_t idx)
{
return &m_DepthQTable[idx];
return &m_LightMap[idx];
}

GOURAUD_ENTRY *Output_GetGouraud(const uint8_t idx)
SHADE_MAP *Output_GetShadeMap(const uint8_t idx)
{
return &m_GouraudTable[idx];
return &m_ShadeMap[idx];
}

int32_t Output_GetObjectTextureCount(void)
Expand Down
2 changes: 1 addition & 1 deletion src/libtrx/include/libtrx/game/level/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ 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_ReadAnimatedTextureRanges(int32_t num_ranges, VFILE *file);
void Level_ReadDepthQ(VFILE *file);
void Level_ReadLightMap(VFILE *file);
void Level_LoadTexturePages(LEVEL_INFO *info);
void Level_LoadPalettes(LEVEL_INFO *info);
4 changes: 2 additions & 2 deletions src/libtrx/include/libtrx/game/output/textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ RGBA_8888 *Output_GetTexturePage32(int32_t page_idx);
int32_t Output_GetPaletteSize(void);
RGB_888 Output_GetPaletteColor8(uint16_t idx);
RGB_888 Output_GetPaletteColor16(uint16_t idx);
DEPTHQ_ENTRY *Output_GetDepthQ(uint8_t idx);
GOURAUD_ENTRY *Output_GetGouraud(uint8_t idx);
LIGHT_MAP *Output_GetLightMap(uint8_t idx);
SHADE_MAP *Output_GetShadeMap(uint8_t idx);
int32_t Output_GetObjectTextureCount(void);
OBJECT_TEXTURE *Output_GetObjectTexture(int32_t texture_idx);
SPRITE_TEXTURE *Output_GetSpriteTexture(int32_t texture_idx);
Expand Down
4 changes: 2 additions & 2 deletions src/libtrx/include/libtrx/game/output/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ typedef struct {

typedef struct {
uint8_t index[256];
} DEPTHQ_ENTRY;
} LIGHT_MAP;

typedef struct {
uint8_t index[32];
} GOURAUD_ENTRY;
} SHADE_MAP;
2 changes: 1 addition & 1 deletion src/tr1/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static void M_LoadFromFile(const GF_LEVEL *const level)
M_LoadAnimatedTextures(file);
M_LoadItems(file);
Stats_ObserveItemsLoad();
Level_ReadDepthQ(file);
Level_ReadLightMap(file);

if (layout != LEVEL_LAYOUT_TR1_DEMO_PC) {
Level_ReadPalettes(&m_LevelInfo, file);
Expand Down
2 changes: 1 addition & 1 deletion src/tr2/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ static void M_LoadFromFile(const GF_LEVEL *const level)
M_LoadAnimatedTextures(file);
M_LoadItems(file);

Level_ReadDepthQ(file);
Level_ReadLightMap(file);
M_LoadCinematic(file);
M_LoadDemo(file);
M_LoadSamples(file);
Expand Down
46 changes: 24 additions & 22 deletions src/tr2/game/render/swr.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static void M_TransA(
const int32_t alpha_stride = alpha_surface->desc.pitch;
PIX_FMT *target_ptr = target_surface->buffer + y1 * target_stride;
ALPHA_FMT *alpha_ptr = alpha_surface->buffer + y1 * alpha_stride;
const DEPTHQ_ENTRY *qt = Output_GetDepthQ(depth);
const LIGHT_MAP *const map = Output_GetLightMap(depth);

while (y_size > 0) {
const int32_t x = xbuf->x1 / PHD_ONE;
Expand All @@ -258,7 +258,7 @@ static void M_TransA(
PIX_FMT *target_line_ptr = target_ptr + x;
ALPHA_FMT *alpha_line_ptr = alpha_ptr + x;
while (x_size > 0) {
*target_line_ptr = MAKE_PAL_IDX(qt->index[*target_line_ptr]);
*target_line_ptr = MAKE_PAL_IDX(map->index[*target_line_ptr]);
target_line_ptr++;
*alpha_line_ptr++ = 255;
x_size--;
Expand Down Expand Up @@ -286,7 +286,7 @@ static void M_GourA(
const int32_t alpha_stride = alpha_surface->desc.pitch;
PIX_FMT *target_ptr = target_surface->buffer + y1 * target_stride;
ALPHA_FMT *alpha_ptr = alpha_surface->buffer + y1 * alpha_stride;
const GOURAUD_ENTRY *gt = Output_GetGouraud(color_idx);
const SHADE_MAP *const map = Output_GetShadeMap(color_idx);

while (y_size > 0) {
const int32_t x = xbuf->x1 / PHD_ONE;
Expand All @@ -301,7 +301,7 @@ static void M_GourA(
PIX_FMT *target_line_ptr = target_ptr + x;
ALPHA_FMT *alpha_line_ptr = alpha_ptr + x;
while (x_size > 0) {
*target_line_ptr++ = MAKE_PAL_IDX(gt->index[MAKE_Q_ID(g)]);
*target_line_ptr++ = MAKE_PAL_IDX(map->index[MAKE_Q_ID(g)]);
*alpha_line_ptr++ = 255;
g += g_add;
x_size--;
Expand Down Expand Up @@ -348,8 +348,8 @@ static void M_GTMapA(
ALPHA_FMT *alpha_line_ptr = alpha_ptr + x;
while (x_size > 0) {
uint8_t color_idx = tex_page[MAKE_TEX_ID(v, u)];
*target_line_ptr++ =
MAKE_PAL_IDX(Output_GetDepthQ(MAKE_Q_ID(g))->index[color_idx]);
*target_line_ptr++ = MAKE_PAL_IDX(
Output_GetLightMap(MAKE_Q_ID(g))->index[color_idx]);
*alpha_line_ptr++ = 255;
g += g_add;
u += u_add;
Expand Down Expand Up @@ -400,7 +400,7 @@ static void M_WGTMapA(
const uint8_t color_idx = tex_page[MAKE_TEX_ID(v, u)];
if (color_idx != 0) {
*target_line_ptr = MAKE_PAL_IDX(
Output_GetDepthQ(MAKE_Q_ID(g))->index[color_idx]);
Output_GetLightMap(MAKE_Q_ID(g))->index[color_idx]);
*alpha_line_ptr = 255;
}
target_line_ptr++;
Expand Down Expand Up @@ -479,7 +479,7 @@ static void M_GTMapPersp32FP(
while (batch_counter--) {
const uint8_t color_idx = tex_page[MAKE_TEX_ID(v0, u0)];
const uint8_t color =
Output_GetDepthQ(MAKE_Q_ID(g))->index[color_idx];
Output_GetLightMap(MAKE_Q_ID(g))->index[color_idx];
*target_line_ptr++ = MAKE_PAL_IDX(color);
*target_line_ptr++ = MAKE_PAL_IDX(color);
*alpha_line_ptr++ = 255;
Expand All @@ -493,7 +493,7 @@ static void M_GTMapPersp32FP(
while (batch_counter--) {
const uint8_t color_idx = tex_page[MAKE_TEX_ID(v0, u0)];
const uint8_t color =
Output_GetDepthQ(MAKE_Q_ID(g))->index[color_idx];
Output_GetLightMap(MAKE_Q_ID(g))->index[color_idx];
*target_line_ptr++ = MAKE_PAL_IDX(color);
*alpha_line_ptr++ = 255;
g += g_add;
Expand Down Expand Up @@ -522,7 +522,7 @@ static void M_GTMapPersp32FP(
while (batch_counter--) {
const uint8_t color_idx = tex_page[MAKE_TEX_ID(v0, u0)];
const uint8_t color =
Output_GetDepthQ(MAKE_Q_ID(g))->index[color_idx];
Output_GetLightMap(MAKE_Q_ID(g))->index[color_idx];
*target_line_ptr++ = MAKE_PAL_IDX(color);
*target_line_ptr++ = MAKE_PAL_IDX(color);
*alpha_line_ptr++ = 255;
Expand All @@ -536,7 +536,7 @@ static void M_GTMapPersp32FP(
while (batch_counter--) {
const uint8_t color_idx = tex_page[MAKE_TEX_ID(v0, u0)];
const uint8_t color =
Output_GetDepthQ(MAKE_Q_ID(g))->index[color_idx];
Output_GetLightMap(MAKE_Q_ID(g))->index[color_idx];
*target_line_ptr++ = MAKE_PAL_IDX(color);
*alpha_line_ptr++ = 255;
g += g_add;
Expand All @@ -549,7 +549,7 @@ static void M_GTMapPersp32FP(
if (x_size == 1) {
const uint8_t color_idx = tex_page[MAKE_TEX_ID(v0, u0)];
const uint8_t color =
Output_GetDepthQ(MAKE_Q_ID(g))->index[color_idx];
Output_GetLightMap(MAKE_Q_ID(g))->index[color_idx];
*target_line_ptr = MAKE_PAL_IDX(color);
*alpha_line_ptr = 255;
}
Expand Down Expand Up @@ -622,8 +622,9 @@ static void M_WGTMapPersp32FP(
while (batch_counter--) {
const uint8_t color_idx = tex_page[MAKE_TEX_ID(v0, u0)];
if (color_idx != 0) {
const uint8_t color = Output_GetDepthQ(MAKE_Q_ID(g))
->index[color_idx];
const uint8_t color =
Output_GetLightMap(MAKE_Q_ID(g))
->index[color_idx];
target_line_ptr[0] = MAKE_PAL_IDX(color);
target_line_ptr[1] = MAKE_PAL_IDX(color);
alpha_line_ptr[0] = 255;
Expand All @@ -640,8 +641,9 @@ static void M_WGTMapPersp32FP(
while (batch_counter--) {
const uint8_t color_idx = tex_page[MAKE_TEX_ID(v0, u0)];
if (color_idx != 0) {
const uint8_t color = Output_GetDepthQ(MAKE_Q_ID(g))
->index[color_idx];
const uint8_t color =
Output_GetLightMap(MAKE_Q_ID(g))
->index[color_idx];
*target_line_ptr = MAKE_PAL_IDX(color);
*alpha_line_ptr = 255;
}
Expand Down Expand Up @@ -674,7 +676,7 @@ static void M_WGTMapPersp32FP(
const uint8_t color_idx = tex_page[MAKE_TEX_ID(v0, u0)];
if (color_idx != 0) {
const uint8_t color =
Output_GetDepthQ(MAKE_Q_ID(g))->index[color_idx];
Output_GetLightMap(MAKE_Q_ID(g))->index[color_idx];
target_line_ptr[0] = MAKE_PAL_IDX(color);
target_line_ptr[1] = MAKE_PAL_IDX(color);
alpha_line_ptr[0] = 255;
Expand All @@ -692,7 +694,7 @@ static void M_WGTMapPersp32FP(
const uint8_t color_idx = tex_page[MAKE_TEX_ID(v0, u0)];
if (color_idx != 0) {
const uint8_t color =
Output_GetDepthQ(MAKE_Q_ID(g))->index[color_idx];
Output_GetLightMap(MAKE_Q_ID(g))->index[color_idx];
*target_line_ptr = MAKE_PAL_IDX(color);
*alpha_line_ptr = 255;
}
Expand All @@ -709,7 +711,7 @@ static void M_WGTMapPersp32FP(
const uint8_t color_idx = tex_page[MAKE_TEX_ID(v0, u0)];
if (color_idx != 0) {
const uint8_t color =
Output_GetDepthQ(MAKE_Q_ID(g))->index[color_idx];
Output_GetLightMap(MAKE_Q_ID(g))->index[color_idx];
*target_line_ptr = MAKE_PAL_IDX(color);
*alpha_line_ptr = 255;
}
Expand Down Expand Up @@ -1242,7 +1244,7 @@ static void M_DrawScaledSpriteC(
return;
}

const DEPTHQ_ENTRY *const depth = Output_GetDepthQ(shade >> 8);
const LIGHT_MAP *const map = Output_GetLightMap(shade >> 8);
const SPRITE_TEXTURE *const sprite = Output_GetSpriteTexture(sprite_idx);

int32_t u_base = 0x4000;
Expand Down Expand Up @@ -1271,15 +1273,15 @@ static void M_DrawScaledSpriteC(
ALPHA_FMT *alpha_ptr = &alpha_surface->buffer[y0 * target_stride + x0];
const int32_t dst_add = target_stride - width;

const bool is_depth_q = depth != Output_GetDepthQ(16);
const bool use_light_map = map != Output_GetLightMap(16);

for (int32_t i = 0; i < height; i++) {
int32_t u = u_base;
const uint8_t *const src = &src_base[(v_base >> 16) << 8];
for (int32_t j = 0; j < width; j++) {
const uint8_t pix = src[u >> 16];
if (pix != 0) {
*target_ptr = is_depth_q ? depth->index[pix] : pix;
*target_ptr = use_light_map ? map->index[pix] : pix;
*alpha_ptr = 255;
}
u += u_add;
Expand Down

0 comments on commit 6071e38

Please sign in to comment.