From 9a241dbc80810d427d8611f13aa51cd00f46eaf3 Mon Sep 17 00:00:00 2001 From: Lwmte <3331699+Lwmte@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:15:26 +0100 Subject: [PATCH 1/8] Fix issues with timer --- Scripts/Engine/Timer.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Engine/Timer.lua b/Scripts/Engine/Timer.lua index 59ce2f3a3..a47bdc0f7 100644 --- a/Scripts/Engine/Timer.lua +++ b/Scripts/Engine/Timer.lua @@ -202,7 +202,7 @@ Timer = { str:SetColor(pausedColor) end - TEN.Strings.ShowString(str, 1) + TEN.Strings.ShowString(str, 1, false) end end From b582601abf47c5f176e6ce105d1b129713c573d1 Mon Sep 17 00:00:00 2001 From: Lwmte <3331699+Lwmte@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:40:34 +0100 Subject: [PATCH 2/8] Fixed original issue with weapon hotkeys available in binoculars or lasersight mode --- CHANGELOG.md | 1 + TombEngine/Game/Lara/lara_helpers.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cea2b24c..eba972ea7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ TombEngine releases are located in this repository (alongside with Tomb Editor): * Fixed Lara's Home entry not working. * Fixed exploding TR3 bosses. * Fixed original issue with deactivation of Dart Emitter. +* Fixed original issue with weapon hotkeys available in binoculars or lasersight mode. * Fixed Lens Flare object not functioning properly. * Fixed lens flares not being occluded by static meshes and moveables. * Fixed spotlight shadows. diff --git a/TombEngine/Game/Lara/lara_helpers.cpp b/TombEngine/Game/Lara/lara_helpers.cpp index 48fee7e30..35bc49722 100644 --- a/TombEngine/Game/Lara/lara_helpers.cpp +++ b/TombEngine/Game/Lara/lara_helpers.cpp @@ -342,6 +342,10 @@ void HandlePlayerQuickActions(ItemInfo& item) g_Gui.UseItem(item, GAME_OBJECT_ID::ID_BIGMEDI_ITEM); } + // Don't process weapon hotkeys in optics mode. + if (player.Control.Look.IsUsingBinoculars) + return; + // Handle weapon scroll request. if (IsClicked(In::PreviousWeapon) || IsClicked(In::NextWeapon)) { From 5df743ac9b68e14bba27871afe52b9eae0060898 Mon Sep 17 00:00:00 2001 From: Lwmte <3331699+Lwmte@users.noreply.github.com> Date: Mon, 9 Dec 2024 01:36:50 +0100 Subject: [PATCH 3/8] Allow camera bounce during flybys --- CHANGELOG.md | 1 + TombEngine/Game/camera.cpp | 71 ++++++++++++++++++------------------- TombEngine/Game/camera.h | 1 + TombEngine/Game/spotcam.cpp | 1 + 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eba972ea7..1945c1d6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ TombEngine releases are located in this repository (alongside with Tomb Editor): ### New Features * Added fast savegame reloading. * Added ricochet sounds and make the effect more prominent. +* Allow camera bounce during flybys. * Allow to run the engine without title level. * Allow more than 1024 objects in a level. * Allow more than 1000 static mesh slots in a level. diff --git a/TombEngine/Game/camera.cpp b/TombEngine/Game/camera.cpp index 1a79ecfc8..f1007e352 100644 --- a/TombEngine/Game/camera.cpp +++ b/TombEngine/Game/camera.cpp @@ -215,6 +215,38 @@ inline void RumbleFromBounce() Rumble(std::clamp((float)abs(Camera.bounce) / 70.0f, 0.0f, 0.8f), 0.2f); } +void CalculateBounce(bool binocularMode) +{ + if (Camera.bounce == 0) + return; + + if (Camera.bounce <= 0) + { + if (binocularMode) + { + Camera.target.x += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); + Camera.target.y += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); + Camera.target.z += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); + } + else + { + int bounce = -Camera.bounce; + int bounce2 = bounce / 2; + Camera.target.x += GetRandomControl() % bounce - bounce2; + Camera.target.y += GetRandomControl() % bounce - bounce2; + Camera.target.z += GetRandomControl() % bounce - bounce2; + } + + Camera.bounce += 5; + RumbleFromBounce(); + } + else + { + Camera.pos.y += Camera.bounce; + Camera.target.y += Camera.bounce; + Camera.bounce = 0; + } +} void InitializeCamera() { @@ -313,25 +345,7 @@ void MoveCamera(GameVector* ideal, int speed) Camera.pos.z += (ideal->z - Camera.pos.z) / speed; Camera.pos.RoomNumber = ideal->RoomNumber; - if (Camera.bounce) - { - if (Camera.bounce <= 0) - { - int bounce = -Camera.bounce; - int bounce2 = bounce / 2; - Camera.target.x += GetRandomControl() % bounce - bounce2; - Camera.target.y += GetRandomControl() % bounce - bounce2; - Camera.target.z += GetRandomControl() % bounce - bounce2; - Camera.bounce += 5; - RumbleFromBounce(); - } - else - { - Camera.pos.y += Camera.bounce; - Camera.target.y += Camera.bounce; - Camera.bounce = 0; - } - } + CalculateBounce(false); int y = Camera.pos.y; if (TestEnvironment(ENV_FLAG_SWAMP, Camera.pos.RoomNumber)) @@ -1000,23 +1014,8 @@ void BinocularCamera(ItemInfo* item) Camera.target.RoomNumber = item->RoomNumber; } - if (Camera.bounce && - Camera.type == Camera.oldType) - { - if (Camera.bounce <= 0) - { - Camera.target.x += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); - Camera.target.y += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); - Camera.target.z += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); - Camera.bounce += 5; - RumbleFromBounce(); - } - else - { - Camera.bounce = 0; - Camera.target.y += Camera.bounce; - } - } + if (Camera.type == Camera.oldType) + CalculateBounce(true); Camera.target.RoomNumber = GetPointCollision(Camera.pos.ToVector3i(), Camera.target.RoomNumber).GetRoomNumber(); LookAt(&Camera, 0); diff --git a/TombEngine/Game/camera.h b/TombEngine/Game/camera.h index 6a6939c94..f92703ec7 100644 --- a/TombEngine/Game/camera.h +++ b/TombEngine/Game/camera.h @@ -99,6 +99,7 @@ void BounceCamera(ItemInfo* item, short bounce, short maxDistance); void BinocularCamera(ItemInfo* item); void ConfirmCameraTargetPos(); void CalculateCamera(const CollisionInfo& coll); +void CalculateBounce(bool binocularMode); void RumbleScreen(); bool TestBoundsCollideCamera(const GameBoundingBox& bounds, const Pose& pose, short radius); void ItemPushCamera(GameBoundingBox* bounds, Pose* pos, short radius); diff --git a/TombEngine/Game/spotcam.cpp b/TombEngine/Game/spotcam.cpp index e39ba51a0..2d2b3bc54 100644 --- a/TombEngine/Game/spotcam.cpp +++ b/TombEngine/Game/spotcam.cpp @@ -494,6 +494,7 @@ void CalculateSpotCameras() Camera.target.x = ctx; Camera.target.y = cty; Camera.target.z = ctz; + CalculateBounce(false); } int outsideRoom = IsRoomOutside(cpx, cpy, cpz); From 8da4d36b54005ecbe7f53be0b5cc53f9519db368 Mon Sep 17 00:00:00 2001 From: Lwmte <3331699+Lwmte@users.noreply.github.com> Date: Mon, 9 Dec 2024 01:37:06 +0100 Subject: [PATCH 4/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1945c1d6b..aa07bf0f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,7 @@ TombEngine releases are located in this repository (alongside with Tomb Editor): ### New Features * Added fast savegame reloading. * Added ricochet sounds and make the effect more prominent. -* Allow camera bounce during flybys. +* Allow camera shake during flybys. * Allow to run the engine without title level. * Allow more than 1024 objects in a level. * Allow more than 1000 static mesh slots in a level. From a71cf7bced6bab5a517c9fc63e343b44d7488102 Mon Sep 17 00:00:00 2001 From: Lwmte <3331699+Lwmte@users.noreply.github.com> Date: Mon, 9 Dec 2024 02:46:26 +0100 Subject: [PATCH 5/8] Prevent loading of incorrect savegames --- TombEngine/Game/control/control.cpp | 8 +++++++- TombEngine/Game/savegame.cpp | 23 +++++++++++++++-------- TombEngine/Game/savegame.h | 1 + 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/TombEngine/Game/control/control.cpp b/TombEngine/Game/control/control.cpp index 548df849c..0941e0682 100644 --- a/TombEngine/Game/control/control.cpp +++ b/TombEngine/Game/control/control.cpp @@ -594,8 +594,14 @@ void InitializeOrLoadGame(bool loadGame) g_Gui.SetEnterInventory(NO_VALUE); // Restore game? - if (loadGame && SaveGame::Load(g_GameFlow->SelectedSaveGame)) + if (loadGame) { + if (!SaveGame::Load(g_GameFlow->SelectedSaveGame)) + { + NextLevel = g_GameFlow->GetNumLevels(); + return; + } + InitializeGame = false; g_GameFlow->SelectedSaveGame = 0; diff --git a/TombEngine/Game/savegame.cpp b/TombEngine/Game/savegame.cpp index 968867ccd..5105b1d26 100644 --- a/TombEngine/Game/savegame.cpp +++ b/TombEngine/Game/savegame.cpp @@ -206,6 +206,19 @@ bool SaveGame::DoesSaveGameExist(int slot, bool silent) return true; } +bool SaveGame::IsSaveGameValid(int slot) +{ + SaveGameHeader header; + if (!LoadHeader(slot, &header)) + return false; + + // Hash mismatch between savegame and level file means that level version has changed. + if (header.LevelHash != LastLevelHash) + return false; + + return true; +} + bool SaveGame::IsLoadGamePossible() { for (int i = 0; i < SAVEGAME_MAX; i++) @@ -1614,15 +1627,9 @@ bool SaveGame::Save(int slot) bool SaveGame::Load(int slot) { - if (!IsSaveGameSlotValid(slot)) + if (!IsSaveGameValid(slot)) { - TENLog("Savegame slot " + std::to_string(slot) + " is invalid, load is impossible.", LogLevel::Error); - return false; - } - - if (!DoesSaveGameExist(slot)) - { - TENLog("Savegame in slot " + std::to_string(slot) + " does not exist.", LogLevel::Error); + TENLog("Loading from savegame in slot " + std::to_string(slot) + " is impossible, data is incorrect or missing.", LogLevel::Error); return false; } diff --git a/TombEngine/Game/savegame.h b/TombEngine/Game/savegame.h index 3b09ac92d..067391a93 100644 --- a/TombEngine/Game/savegame.h +++ b/TombEngine/Game/savegame.h @@ -66,6 +66,7 @@ public: static bool DoesSaveGameExist(int slot, bool silent = false); static bool IsLoadGamePossible(); + static bool IsSaveGameValid(int slot); static void SaveHub(int index); static void LoadHub(int index); From 45f515c44493194b6a2e14c79b1aede13d4ca7ad Mon Sep 17 00:00:00 2001 From: Lwmte <3331699+Lwmte@users.noreply.github.com> Date: Mon, 9 Dec 2024 02:59:39 +0100 Subject: [PATCH 6/8] Update savegame.cpp --- TombEngine/Game/savegame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TombEngine/Game/savegame.cpp b/TombEngine/Game/savegame.cpp index 5105b1d26..fe1962878 100644 --- a/TombEngine/Game/savegame.cpp +++ b/TombEngine/Game/savegame.cpp @@ -1629,7 +1629,7 @@ bool SaveGame::Load(int slot) { if (!IsSaveGameValid(slot)) { - TENLog("Loading from savegame in slot " + std::to_string(slot) + " is impossible, data is incorrect or missing.", LogLevel::Error); + TENLog("Loading from savegame in slot " + std::to_string(slot) + " is impossible, data is missing or level has changed.", LogLevel::Error); return false; } From 8d20d6f1cadefa075925545a602e502f16d5d86a Mon Sep 17 00:00:00 2001 From: Lwmte <3331699+Lwmte@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:40:57 +0100 Subject: [PATCH 7/8] Less frequent updates to CalculateBounce --- TombEngine/Game/camera.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/TombEngine/Game/camera.cpp b/TombEngine/Game/camera.cpp index f1007e352..2e8274e37 100644 --- a/TombEngine/Game/camera.cpp +++ b/TombEngine/Game/camera.cpp @@ -222,19 +222,22 @@ void CalculateBounce(bool binocularMode) if (Camera.bounce <= 0) { - if (binocularMode) + if (GlobalCounter & 3) { - Camera.target.x += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); - Camera.target.y += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); - Camera.target.z += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); - } - else - { - int bounce = -Camera.bounce; - int bounce2 = bounce / 2; - Camera.target.x += GetRandomControl() % bounce - bounce2; - Camera.target.y += GetRandomControl() % bounce - bounce2; - Camera.target.z += GetRandomControl() % bounce - bounce2; + if (binocularMode) + { + Camera.target.x += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); + Camera.target.y += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); + Camera.target.z += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); + } + else + { + int bounce = -Camera.bounce; + int bounce2 = bounce / 2; + Camera.target.x += GetRandomControl() % bounce - bounce2; + Camera.target.y += GetRandomControl() % bounce - bounce2; + Camera.target.z += GetRandomControl() % bounce - bounce2; + } } Camera.bounce += 5; From 0a2d82ab11ec58a406e40b8dd5b5684f091a54af Mon Sep 17 00:00:00 2001 From: Lwmte <3331699+Lwmte@users.noreply.github.com> Date: Tue, 10 Dec 2024 03:01:23 +0100 Subject: [PATCH 8/8] Revert "Less frequent updates to CalculateBounce" This reverts commit 8d20d6f1cadefa075925545a602e502f16d5d86a. --- TombEngine/Game/camera.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/TombEngine/Game/camera.cpp b/TombEngine/Game/camera.cpp index 2e8274e37..f1007e352 100644 --- a/TombEngine/Game/camera.cpp +++ b/TombEngine/Game/camera.cpp @@ -222,22 +222,19 @@ void CalculateBounce(bool binocularMode) if (Camera.bounce <= 0) { - if (GlobalCounter & 3) + if (binocularMode) { - if (binocularMode) - { - Camera.target.x += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); - Camera.target.y += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); - Camera.target.z += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); - } - else - { - int bounce = -Camera.bounce; - int bounce2 = bounce / 2; - Camera.target.x += GetRandomControl() % bounce - bounce2; - Camera.target.y += GetRandomControl() % bounce - bounce2; - Camera.target.z += GetRandomControl() % bounce - bounce2; - } + Camera.target.x += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); + Camera.target.y += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); + Camera.target.z += (CLICK(0.25f) / 4) * (GetRandomControl() % (-Camera.bounce) - (-Camera.bounce / 2)); + } + else + { + int bounce = -Camera.bounce; + int bounce2 = bounce / 2; + Camera.target.x += GetRandomControl() % bounce - bounce2; + Camera.target.y += GetRandomControl() % bounce - bounce2; + Camera.target.z += GetRandomControl() % bounce - bounce2; } Camera.bounce += 5;