Skip to content

Commit

Permalink
output: add skybox support
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 committed Jun 14, 2024
1 parent 28dd411 commit 63cfde8
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
2 changes: 2 additions & 0 deletions data/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"type": "normal",
"music": 57,
"injections": [
"data/injections/skybox.bin",
"data/injections/valley_itemrots.bin",
"data/injections/valley_textures.bin",
],
Expand Down Expand Up @@ -183,6 +184,7 @@
"data/injections/colosseum_fd.bin",
"data/injections/colosseum_itemrots.bin",
"data/injections/colosseum_textures.bin",
"data/injections/skybox.bin",
],
"sequence": [
{"type": "loading_screen", "picture_path": "data/images/greece.webp", "display_time": 5},
Expand Down
Binary file added data/ship/data/injections/skybox.bin
Binary file not shown.
39 changes: 39 additions & 0 deletions src/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static const int16_t *Output_DrawObjectGT4(
const int16_t *obj_ptr, int32_t number);
static const int16_t *Output_DrawRoomSprites(
const int16_t *obj_ptr, int32_t vertex_count);
static const int16_t *Output_CalculateSkyboxLight(const int16_t *obj_ptr);
static const int16_t *Output_CalcObjectVertices(const int16_t *obj_ptr);
static const int16_t *Output_CalcVerticeLight(const int16_t *obj_ptr);
static const int16_t *Output_CalcRoomVertices(const int16_t *obj_ptr);
Expand Down Expand Up @@ -236,6 +237,23 @@ static const int16_t *Output_CalcObjectVertices(const int16_t *obj_ptr)
return total_clip == 0 ? obj_ptr : NULL;
}

static const int16_t *Output_CalculateSkyboxLight(const int16_t *obj_ptr)
{
int32_t vertex_count = *obj_ptr++;
if (vertex_count > 0) {
obj_ptr += 3 * vertex_count;
} else {
vertex_count = -vertex_count;
obj_ptr += vertex_count;
}

for (int i = 0; i < vertex_count; i++) {
m_VBuf[i].g = 0xFFF;
}

return obj_ptr;
}

static const int16_t *Output_CalcVerticeLight(const int16_t *obj_ptr)
{
int32_t vertex_count = *obj_ptr++;
Expand Down Expand Up @@ -535,6 +553,27 @@ void Output_CalculateObjectLighting(
Output_CalculateLight(offset.x, offset.y, offset.z, item->room_number);
}

void Output_DrawSkybox(const int16_t *obj_ptr)
{
g_PhdLeft = Viewport_GetMinX();
g_PhdTop = Viewport_GetMinY();
g_PhdRight = Viewport_GetMaxX();
g_PhdBottom = Viewport_GetMaxY();

obj_ptr = Output_CalcObjectVertices(obj_ptr + 4);
if (obj_ptr) {
S_Output_DisableDepthTest();

obj_ptr = Output_CalculateSkyboxLight(obj_ptr);
obj_ptr = Output_DrawObjectGT4(obj_ptr + 1, *obj_ptr);
obj_ptr = Output_DrawObjectGT3(obj_ptr + 1, *obj_ptr);
obj_ptr = Output_DrawObjectG4(obj_ptr + 1, *obj_ptr);
obj_ptr = Output_DrawObjectG3(obj_ptr + 1, *obj_ptr);

S_Output_EnableDepthTest();
}
}

void Output_DrawPolygons(const int16_t *obj_ptr, int clip)
{
obj_ptr += 4;
Expand Down
2 changes: 2 additions & 0 deletions src/game/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ void Output_CalculateStaticLight(int16_t adder);
void Output_CalculateObjectLighting(
const ITEM_INFO *item, const BOUNDS_16 *bounds);

void Output_DrawSkybox(const int16_t *obj_ptr);

void Output_DrawPolygons(const int16_t *obj_ptr, int clip);
void Output_DrawPolygons_I(const int16_t *obj_ptr, int32_t clip);

Expand Down
13 changes: 13 additions & 0 deletions src/game/room_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ void Room_DrawAllRooms(int16_t base_room, int16_t target_room)
Room_PrepareToDraw(base_room);
Room_PrepareToDraw(target_room);

if (g_Objects[O_SKYBOX].loaded) {
Output_SetupAboveWater(g_Camera.underwater);
Matrix_Push();
g_MatrixPtr->_03 = g_MatrixPtr->_13 = g_MatrixPtr->_23 = 0;

FRAME_INFO *frame = g_Anims[g_Objects[O_SKYBOX].anim_index].frame_ptr;
int32_t *packed_rotation = frame->mesh_rots;
Matrix_RotYXZpack(packed_rotation[0]);
Output_DrawSkybox(g_Meshes[g_Objects[O_SKYBOX].mesh_index]);

Matrix_Pop();
}

for (int i = 0; i < g_RoomsToDrawCount; i++) {
Room_DrawSingleRoom(g_RoomsToDraw[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/global/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ typedef enum GAME_OBJECT_ID {
O_BIG_POD = 181,
O_BOAT = 182,
O_EARTHQUAKE = 183,
O_TEMP5 = 184,
O_SKYBOX = 184,
O_TEMP6 = 185,
O_TEMP7 = 186,
O_TEMP8 = 187,
Expand Down

0 comments on commit 63cfde8

Please sign in to comment.