Skip to content

Commit

Permalink
output: add reflections
Browse files Browse the repository at this point in the history
Resolves #154.
  • Loading branch information
rr- committed Sep 11, 2024
1 parent c4de1a2 commit 606af16
Show file tree
Hide file tree
Showing 22 changed files with 428 additions and 70 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Unreleased](https://github.com/LostArtefacts/TR1X/compare/stable...develop) - ××××-××-××
- added `/exit` command (#1462)
- added reflections for save crystals and Midas Hand special animation (#154)
- fixed `/play`, `/load`, `/demo` and similar commands not working in stats, credits, cinematics and fmvs (#1477)
- fixed console commands being able to interfere with demos, cutscenes and the title screen (#1489, regression from 3.0)
- fixed reopening the compass not resetting its needle (#1472, regression from 4.0)
Expand Down
1 change: 1 addition & 0 deletions data/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@
"DETAIL_FPS": "FPS",
"DETAIL_PERSPECTIVE": "Perspective",
"DETAIL_PRETTY_PIXELS": "Pretty pixels",
"DETAIL_REFLECTIONS": "Reflections",
"DETAIL_BILINEAR": "Bilinear",
"DETAIL_TEXTURE_FILTER": "Texture filter",
"DETAIL_FBO_FILTER": "FBO filter",
Expand Down
1 change: 1 addition & 0 deletions data/ship/cfg/TR1X_gameflow_demo_pc.json5
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"DETAIL_FPS": "FPS",
"DETAIL_PERSPECTIVE": "Perspective",
"DETAIL_PRETTY_PIXELS": "Pretty pixels",
"DETAIL_REFLECTIONS": "Reflections",
"DETAIL_BILINEAR": "Bilinear",
"DETAIL_TEXTURE_FILTER": "Texture filter",
"DETAIL_FBO_FILTER": "FBO filter",
Expand Down
1 change: 1 addition & 0 deletions data/ship/cfg/TR1X_gameflow_ub.json5
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"DETAIL_FPS": "FPS",
"DETAIL_PERSPECTIVE": "Perspective",
"DETAIL_PRETTY_PIXELS": "Pretty pixels",
"DETAIL_REFLECTIONS": "Reflections",
"DETAIL_BILINEAR": "Bilinear",
"DETAIL_TEXTURE_FILTER": "Texture filter",
"DETAIL_FBO_FILTER": "FBO filter",
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ typedef struct {
float anisotropy_filter;
int32_t turbo_speed;
bool pretty_pixels;
bool enable_reflections;
} rendering;

struct {
Expand Down
1 change: 1 addition & 0 deletions src/config_map.def
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ CFG_DOUBLE(g_Config, rendering.wireframe_width, 2.5)
CFG_BOOL(g_Config, rendering.enable_perspective_filter, true)
CFG_BOOL(g_Config, rendering.enable_vsync, true)
CFG_BOOL(g_Config, rendering.pretty_pixels, true)
CFG_BOOL(g_Config, rendering.enable_reflections, true)
CFG_INT32(g_Config, music_volume, 8)
CFG_INT32(g_Config, sound_volume, 8)
CFG_INT32(g_Config, input.layout, 0)
Expand Down
16 changes: 13 additions & 3 deletions src/game/game/game_draw.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "game/game.h"

#include "config.h"
#include "game/camera.h"
#include "game/interpolation.h"
#include "game/lara/lara_draw.h"
#include "game/lara/lara_hair.h"
#include "game/output.h"
#include "game/overlay.h"
Expand All @@ -20,11 +22,19 @@ void Game_DrawScene(bool draw_overlay)

if (g_Objects[O_LARA].loaded) {
Room_DrawAllRooms(g_Camera.interp.room_num, g_Camera.target.room_num);
if (draw_overlay) {
Overlay_DrawGameInfo();

if (g_Config.rendering.enable_reflections) {
Output_FillEnvironmentMap();
}

if (g_RoomInfo[g_LaraItem->room_num].flags & RF_UNDERWATER) {
Output_SetupBelowWater(g_Camera.underwater);
} else {
Overlay_HideGameInfo();
Output_SetupAboveWater(g_Camera.underwater);
}

Lara_Draw(g_LaraItem);

} else {
// cinematic scene
for (int i = 0; i < g_RoomsToDrawCount; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/game/game_string.def
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ GS_DEFINE(DETAIL_LEVEL_LOW, "Low")
GS_DEFINE(DETAIL_FPS, "FPS")
GS_DEFINE(DETAIL_PERSPECTIVE, "Perspective")
GS_DEFINE(DETAIL_PRETTY_PIXELS, "Pretty pixels")
GS_DEFINE(DETAIL_REFLECTIONS, "Reflections")
GS_DEFINE(DETAIL_BILINEAR, "Bilinear")
GS_DEFINE(DETAIL_TEXTURE_FILTER, "Texture filter")
GS_DEFINE(DETAIL_FBO_FILTER, "FBO filter")
Expand Down
4 changes: 4 additions & 0 deletions src/game/lara/lara_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "game/items.h"
#include "game/lara.h"
#include "game/lara/lara_look.h"
#include "game/objects/common.h"
#include "game/objects/effects/twinkle.h"
#include "game/room.h"
#include "game/sound.h"
Expand Down Expand Up @@ -678,6 +679,8 @@ void Lara_State_DieMidas(ITEM_INFO *item, COLL_INFO *coll)
coll->enable_spaz = 0;
coll->enable_baddie_push = 0;

Object_SetReflective(O_LARA_EXTRA, true);

int frm = item->frame_num - g_Anims[item->anim_num].frame_base;
switch (frm) {
case 5:
Expand Down Expand Up @@ -745,6 +748,7 @@ void Lara_State_DieMidas(ITEM_INFO *item, COLL_INFO *coll)
break;

case 225:
Object_SetReflective(O_HAIR, true);
g_Lara.mesh_effects |= (1 << LM_HEAD);
Lara_SwapSingleMesh(LM_HEAD, O_LARA_EXTRA);
break;
Expand Down
62 changes: 62 additions & 0 deletions src/game/objects/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,65 @@ void Object_DrawUnclippedItem(ITEM_INFO *item)
g_PhdRight = right;
g_PhdBottom = bottom;
}

void Object_SetMeshReflective(
const GAME_OBJECT_ID object_id, const int32_t mesh_idx, const bool enabled)
{
const OBJECT_INFO *const object = &g_Objects[object_id];
if (!object->loaded) {
return;
}
int16_t *obj_ptr = g_Meshes[object->mesh_index + mesh_idx];

TOGGLE_REFLECTION_ENABLED(obj_ptr[0], enabled);

obj_ptr += 5;
int32_t vertex_count = *obj_ptr++;
obj_ptr += vertex_count * 3;
vertex_count = *obj_ptr++;
if (vertex_count > 0) {
obj_ptr += vertex_count * 3;
} else {
obj_ptr += vertex_count;
}

// textured quads
int32_t num = *obj_ptr++;
for (int32_t i = 0; i < num; i++) {
// skip vertices
obj_ptr += 4;
TOGGLE_REFLECTION_ENABLED(*obj_ptr++, enabled);
}

// textured triangles
num = *obj_ptr++;
for (int32_t i = 0; i < num; i++) {
// skip vertices
obj_ptr += 3;
TOGGLE_REFLECTION_ENABLED(*obj_ptr++, enabled);
}

// color quads
num = *obj_ptr++;
for (int32_t i = 0; i < num; i++) {
// skip vertices
obj_ptr += 4;
TOGGLE_REFLECTION_ENABLED(*obj_ptr++, enabled);
}

// color triangles
num = *obj_ptr++;
for (int32_t i = 0; i < num; i++) {
// skip vertices
obj_ptr += 3;
TOGGLE_REFLECTION_ENABLED(*obj_ptr++, enabled);
}
}

void Object_SetReflective(const GAME_OBJECT_ID object_id, const bool enabled)
{
const OBJECT_INFO *const object = &g_Objects[object_id];
for (int32_t i = 0; i < object->nmeshes; i++) {
Object_SetMeshReflective(object_id, i, enabled);
}
}
3 changes: 3 additions & 0 deletions src/game/objects/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ void Object_DrawSpriteItem(ITEM_INFO *item);
void Object_DrawPickupItem(ITEM_INFO *item);
void Object_DrawAnimatingItem(ITEM_INFO *item);
void Object_DrawUnclippedItem(ITEM_INFO *item);
void Object_SetMeshReflective(
GAME_OBJECT_ID object_id, int32_t mesh_idx, bool enabled);
void Object_SetReflective(GAME_OBJECT_ID object_id, bool enabled);
1 change: 1 addition & 0 deletions src/game/objects/general/save_crystal.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void SaveCrystal_Setup(OBJECT_INFO *obj)
obj->save_flags = 1;
}
obj->bounds = SaveCrystal_Bounds;
Object_SetReflective(O_SAVEGAME_ITEM, true);
}

void SaveCrystal_Initialise(int16_t item_num)
Expand Down
28 changes: 27 additions & 1 deletion src/game/option/option_graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ typedef enum GRAPHICS_OPTION_NAME {
OPTION_RESOLUTION,
OPTION_PERSPECTIVE,
OPTION_PRETTY_PIXELS,
OPTION_REFLECTIONS,
OPTION_NUMBER_OF,
OPTION_MIN = OPTION_FPS,
OPTION_MAX = OPTION_PRETTY_PIXELS,
OPTION_MAX = OPTION_REFLECTIONS,
} GRAPHICS_OPTION_NAME;

typedef struct GRAPHICS_OPTION_ROW {
Expand Down Expand Up @@ -85,6 +86,7 @@ static const GRAPHICS_OPTION_ROW m_GfxOptionRows[] = {
{ OPTION_RESOLUTION, GS_DETAIL_RESOLUTION, GS_DETAIL_RESOLUTION_FMT },
{ OPTION_PERSPECTIVE, GS_DETAIL_PERSPECTIVE, GS_MISC_ON },
{ OPTION_PRETTY_PIXELS, GS_DETAIL_PRETTY_PIXELS, GS_MISC_ON },
{ OPTION_REFLECTIONS, GS_DETAIL_REFLECTIONS, GS_MISC_ON },
// end
{ OPTION_NUMBER_OF, 0, 0 },
};
Expand Down Expand Up @@ -302,6 +304,10 @@ static void Option_Graphics_UpdateArrows(
m_HideArrowLeft = !g_Config.rendering.pretty_pixels;
m_HideArrowRight = g_Config.rendering.pretty_pixels;
break;
case OPTION_REFLECTIONS:
m_HideArrowLeft = !g_Config.rendering.enable_reflections;
m_HideArrowRight = g_Config.rendering.enable_reflections;
break;

case OPTION_NUMBER_OF:
default:
Expand Down Expand Up @@ -447,6 +453,12 @@ static void Option_Graphics_ChangeTextOption(
break;
}

case OPTION_REFLECTIONS: {
bool is_enabled = g_Config.rendering.enable_reflections;
Text_ChangeText(value_text, is_enabled ? GS(MISC_ON) : GS(MISC_OFF));
break;
}

case OPTION_NUMBER_OF:
default:
break;
Expand Down Expand Up @@ -557,6 +569,13 @@ void Option_Graphics(INVENTORY_ITEM *inv_item)
}
break;

case OPTION_REFLECTIONS:
if (!g_Config.rendering.enable_reflections) {
g_Config.rendering.enable_reflections = true;
reset = OPTION_REFLECTIONS;
}
break;

case OPTION_NUMBER_OF:
default:
break;
Expand Down Expand Up @@ -644,6 +663,13 @@ void Option_Graphics(INVENTORY_ITEM *inv_item)
}
break;

case OPTION_REFLECTIONS:
if (g_Config.rendering.enable_reflections) {
g_Config.rendering.enable_reflections = false;
reset = OPTION_REFLECTIONS;
}
break;

case OPTION_NUMBER_OF:
default:
break;
Expand Down
Loading

0 comments on commit 606af16

Please sign in to comment.