diff --git a/TombEngine/Game/spotcam.cpp b/TombEngine/Game/spotcam.cpp index 96e6b8b612..9d5b5d1019 100644 --- a/TombEngine/Game/spotcam.cpp +++ b/TombEngine/Game/spotcam.cpp @@ -50,9 +50,9 @@ int LastSpotCamSequence; int LaraHealth; int LaraAir; int CurrentSpotcamSequence; -SPOTCAM SpotCam[MAX_SPOTCAMS]; -int SpotCamRemap[MAX_SPOTCAMS]; -int CameraCnt[MAX_SPOTCAMS]; +std::vector SpotCam; +std::vector SpotCamRemap; +std::vector CameraCnt; int NumberSpotcams; bool CheckTrigger = false; @@ -67,9 +67,9 @@ void ClearSpotCamSequences() SpotcamDontDrawLara = false; SpotcamOverlay = false; - - for (int i = 0; i < MAX_SPOTCAMS; i++) - SpotCam[i] = {}; + SpotCam.clear(); + SpotCamRemap.clear(); + CameraCnt.clear(); } void InitializeSpotCamSequences(bool startFirstSequence) @@ -848,7 +848,7 @@ Pose GetCameraTransform(int sequence, float alpha, bool loop) alpha = std::clamp(alpha, 0.0f, 1.0f); - if (sequence < 0 || sequence >= MAX_SPOTCAMS) + if (sequence < 0 || sequence >= SPOTCAM_MAX_SEQUENCE_ID) { TENLog("Wrong flyby sequence number provided for getting camera coordinates.", LogLevel::Warning); return Pose::Zero; diff --git a/TombEngine/Game/spotcam.h b/TombEngine/Game/spotcam.h index 07917c26d5..1f406884e0 100644 --- a/TombEngine/Game/spotcam.h +++ b/TombEngine/Game/spotcam.h @@ -1,8 +1,9 @@ #pragma once #include "Math/Math.h" #include "Specific/clock.h" +#include -constexpr auto MAX_SPOTCAMS = 256; +constexpr auto SPOTCAM_MAX_SEQUENCE_ID = 256; // Max value for unsigned char sequence field constexpr auto SPOTCAM_CINEMATIC_BARS_HEIGHT = 1.0f / 16; constexpr auto SPOTCAM_CINEMATIC_BARS_SPEED = 1.0f / FPS; @@ -47,9 +48,9 @@ enum SPOTCAM_FLAGS SCF_CAMERA_ONE_SHOT = (1 << 15), }; -extern SPOTCAM SpotCam[MAX_SPOTCAMS]; -extern int SpotCamRemap[MAX_SPOTCAMS]; -extern int CameraCnt[MAX_SPOTCAMS]; +extern std::vector SpotCam; +extern std::vector SpotCamRemap; +extern std::vector CameraCnt; extern int LastSpotCamSequence; extern int NumberSpotcams; extern bool UseSpotCam; diff --git a/TombEngine/Specific/level.cpp b/TombEngine/Specific/level.cpp index 835836fcb3..76ae5999f4 100644 --- a/TombEngine/Specific/level.cpp +++ b/TombEngine/Specific/level.cpp @@ -605,9 +605,17 @@ void LoadCameras() NumberSpotcams = ReadCount(); + // SpotCamRemap and CameraCnt are indexed by sequence number (unsigned char 0-255) + // Always initialize them to handle GetCameraTransform calls even when NumberSpotcams == 0 + SpotCamRemap.assign(SPOTCAM_MAX_SEQUENCE_ID, 0); + CameraCnt.assign(SPOTCAM_MAX_SEQUENCE_ID, 0); + // TODO: Read properly! if (NumberSpotcams != 0) - ReadBytes(SpotCam, NumberSpotcams * sizeof(SPOTCAM)); + { + SpotCam.resize(NumberSpotcams); + ReadBytes(SpotCam.data(), NumberSpotcams * sizeof(SPOTCAM)); + } int sinkCount = ReadCount(); TENLog("Sink count: " + std::to_string(sinkCount), LogLevel::Info);