Skip to content

Commit

Permalink
room_draw: include camera target room (LostArtefacts#1327)
Browse files Browse the repository at this point in the history
This is a workaround for flickers in 60 FPS to ensure that the camera's
target room is included in drawing checks. It does not solve every
issue, but the majority.

Part of LostArtefacts#1295.
  • Loading branch information
lahm86 authored Apr 21, 2024
1 parent dcac730 commit 829cb01
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- fixed console not retaining changed user settings across game relaunches (#1318)
- fixed passport inventory item not being animated in 60 FPS (#1314)
- fixed compass needle being too fast in 60 FPS (#1316, regression from 4.0)
- fixed black screen flickers that can occur in 60 FPS (#1295)

## [4.0.3](https://github.com/LostArtefacts/TR1X/compare/4.0.2...4.0.3) - 2024-04-14
- fixed flickering sprite pickups (#1298)
Expand Down
3 changes: 2 additions & 1 deletion src/game/game/game_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ void Game_DrawScene(bool draw_overlay)
Camera_Apply();

if (g_Objects[O_LARA].loaded) {
Room_DrawAllRooms(g_Camera.interp.room_num);
Room_DrawAllRooms(
g_Camera.interp.room_num, g_Camera.target.room_number);
if (draw_overlay) {
Overlay_DrawGameInfo();
} else {
Expand Down
45 changes: 27 additions & 18 deletions src/game/room_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static int32_t m_RoomNumStack[MAX_ROOMS_TO_DRAW] = { 0 };
static int32_t m_RoomNumStackIdx = 0;

static void Room_PrintDrawStack(void);
static void Room_PrepareToDraw(int16_t room_num);

static void Room_PrintDrawStack(void)
{
Expand Down Expand Up @@ -184,28 +185,49 @@ void Room_GetBounds(int16_t room_num)
m_RoomNumStackIdx--;
}

void Room_DrawAllRooms(int16_t room_num)
void Room_DrawAllRooms(int16_t base_room, int16_t target_room)
{
g_PhdLeft = Viewport_GetMinX();
g_PhdTop = Viewport_GetMinY();
g_PhdRight = Viewport_GetMaxX();
g_PhdBottom = Viewport_GetMaxY();

g_RoomsToDrawCount = 0;

Room_PrepareToDraw(base_room);
Room_PrepareToDraw(target_room);

for (int i = 0; i < g_RoomsToDrawCount; i++) {
Room_DrawSingleRoom(g_RoomsToDraw[i]);
}

if (g_Objects[O_LARA].loaded) {
if (g_RoomInfo[g_LaraItem->room_number].flags & RF_UNDERWATER) {
Output_SetupBelowWater(g_Camera.underwater);
} else {
Output_SetupAboveWater(g_Camera.underwater);
}
Lara_Draw(g_LaraItem);
}
}

static void Room_PrepareToDraw(int16_t room_num)
{
ROOM_INFO *r = &g_RoomInfo[room_num];
if (r->bound_active) {
return;
}

r->left = g_PhdLeft;
r->top = g_PhdTop;
r->right = g_PhdRight;
r->bottom = g_PhdBottom;
r->bound_active = 1;

g_RoomsToDrawCount = 0;
if (g_RoomsToDrawCount + 1 < MAX_ROOMS_TO_DRAW) {
g_RoomsToDraw[g_RoomsToDrawCount++] = room_num;
}

bool camera_underwater =
g_RoomInfo[g_Camera.pos.room_number].flags & RF_UNDERWATER;

Matrix_Push();
Matrix_TranslateAbs(r->x, r->y, r->z);
if (r->doors) {
Expand All @@ -217,19 +239,6 @@ void Room_DrawAllRooms(int16_t room_num)
}
}
Matrix_Pop();

for (int i = 0; i < g_RoomsToDrawCount; i++) {
Room_DrawSingleRoom(g_RoomsToDraw[i]);
}

if (g_Objects[O_LARA].loaded) {
if (g_RoomInfo[g_LaraItem->room_number].flags & RF_UNDERWATER) {
Output_SetupBelowWater(camera_underwater);
} else {
Output_SetupAboveWater(camera_underwater);
}
Lara_Draw(g_LaraItem);
}
}

void Room_DrawSingleRoom(int16_t room_num)
Expand Down
2 changes: 1 addition & 1 deletion src/game/room_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

bool Room_SetBounds(int16_t *objptr, int16_t room_num, ROOM_INFO *parent);
void Room_GetBounds(int16_t room_num);
void Room_DrawAllRooms(int16_t room_num);
void Room_DrawAllRooms(int16_t base_room, int16_t target_room);
void Room_DrawSingleRoom(int16_t room_num);

0 comments on commit 829cb01

Please sign in to comment.