diff --git a/source/graphics/CinemaManager.cpp b/source/graphics/CinemaManager.cpp index 417c4adf31..fe7e37d8c9 100644 --- a/source/graphics/CinemaManager.cpp +++ b/source/graphics/CinemaManager.cpp @@ -20,7 +20,6 @@ #include "CinemaManager.h" #include "graphics/Color.h" -#include "graphics/GameView.h" #include "graphics/Terrain.h" #include "maths/FixedVector3D.h" #include "maths/NUSpline.h" @@ -40,7 +39,7 @@ #include #include -void CCinemaManager::Update(const float deltaRealTime) +void CCinemaManager::Update(const float deltaRealTime, CCamera& camera) { CmpPtr cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); if (!cmpCinemaManager) @@ -53,7 +52,7 @@ void CCinemaManager::Update(const float deltaRealTime) g_RenderingOptions.SetSmoothLOS(false); m_SmoothLosOverridden = true; } - cmpCinemaManager->UpdateActivePath(deltaRealTime, g_Game->GetView()->GetCamera()); + cmpCinemaManager->UpdateActivePath(deltaRealTime, camera); return; } diff --git a/source/graphics/CinemaManager.h b/source/graphics/CinemaManager.h index d9f7347b1a..dee5f8187d 100644 --- a/source/graphics/CinemaManager.h +++ b/source/graphics/CinemaManager.h @@ -18,6 +18,7 @@ #ifndef INCLUDED_CINEMAMANAGER #define INCLUDED_CINEMAMANAGER +class CCamera; class RNSpline; namespace Renderer::Backend { class IDeviceCommandContext; } @@ -40,8 +41,9 @@ public: /** * Updates CCinemManager and current path * @param deltaRealTime Elapsed real time since the last frame. + * @param camera To which camera apply the current path is playing. */ - void Update(const float deltaRealTime); + void Update(const float deltaRealTime, CCamera& camera); bool GetPathsDrawing() const; void SetPathsDrawing(const bool drawPath); diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index c1a0f8d327..381ffaf72b 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -191,9 +191,9 @@ CObjectManager& CGameView::GetObjectManager() return m->ObjectManager; } -CCamera* CGameView::GetCamera() +CCamera& CGameView::GetCamera() { - return &m->ViewCamera; + return m->ViewCamera; } CCinemaManager* CGameView::GetCinema() @@ -304,7 +304,7 @@ void CGameView::Update(const float deltaRealTime) { m->MiniMapTexture.Update(deltaRealTime); - m->CinemaManager.Update(deltaRealTime); + m->CinemaManager.Update(deltaRealTime, m->ViewCamera); if (m->CinemaManager.IsPlaying()) return; // If camera movement is being handled by the touch-input system, diff --git a/source/graphics/GameView.h b/source/graphics/GameView.h index 8376fe1793..a54d374850 100644 --- a/source/graphics/GameView.h +++ b/source/graphics/GameView.h @@ -78,7 +78,7 @@ public: #undef DECLARE_BOOLEAN_SETTING - CCamera* GetCamera(); + CCamera& GetCamera(); CCinemaManager* GetCinema(); CObjectManager& GetObjectManager(); diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index 53027b393a..005b4fa01f 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -388,7 +388,7 @@ int CMapReader::ApplyData() if (pGameView && cmpPlayerManager) { // Default to global camera (with constraints) - pGameView->ResetCameraTarget(pGameView->GetCamera()->GetFocus()); + pGameView->ResetCameraTarget(pGameView->GetCamera().GetFocus()); // TODO: Starting rotation? CmpPtr cmpPlayer(*pSimContext, cmpPlayerManager->GetPlayerByID(m_PlayerID)); @@ -867,10 +867,10 @@ void CXMLReader::ReadCamera(XMBElement parent) if (m_MapReader.pGameView) { - m_MapReader.pGameView->GetCamera()->m_Orientation.SetXRotation(declination); - m_MapReader.pGameView->GetCamera()->m_Orientation.RotateY(rotation); - m_MapReader.pGameView->GetCamera()->m_Orientation.Translate(translation); - m_MapReader.pGameView->GetCamera()->UpdateFrustum(); + m_MapReader.pGameView->GetCamera().m_Orientation.SetXRotation(declination); + m_MapReader.pGameView->GetCamera().m_Orientation.RotateY(rotation); + m_MapReader.pGameView->GetCamera().m_Orientation.Translate(translation); + m_MapReader.pGameView->GetCamera().UpdateFrustum(); } } @@ -1631,10 +1631,10 @@ int CMapReader::ParseCamera() if (pGameView) { - pGameView->GetCamera()->m_Orientation.SetXRotation(declination); - pGameView->GetCamera()->m_Orientation.RotateY(rotation); - pGameView->GetCamera()->m_Orientation.Translate(translation); - pGameView->GetCamera()->UpdateFrustum(); + pGameView->GetCamera().m_Orientation.SetXRotation(declination); + pGameView->GetCamera().m_Orientation.RotateY(rotation); + pGameView->GetCamera().m_Orientation.Translate(translation); + pGameView->GetCamera().UpdateFrustum(); } return 0; diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index 7afd5ae786..bbc4744bad 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -76,7 +76,7 @@ CMapWriter::CMapWriter() /////////////////////////////////////////////////////////////////////////////////////////////////// // SaveMap: try to save the current map to the given file void CMapWriter::SaveMap(const VfsPath& pathname, CTerrain* pTerrain, WaterManager* pWaterMan, - SkyManager* pSkyMan, CLightEnv* pLightEnv, CCamera* pCamera, CCinemaManager*, + SkyManager* pSkyMan, CLightEnv* pLightEnv, const CCamera& camera, CCinemaManager*, CPostprocManager* pPostproc, CSimulation2* pSimulation2) { CFilePacker packer(FILE_VERSION, "PSMP"); @@ -96,7 +96,7 @@ void CMapWriter::SaveMap(const VfsPath& pathname, CTerrain* pTerrain, WaterManag } VfsPath pathnameXML = pathname.ChangeExtension(L".xml"); - WriteXML(pathnameXML, pWaterMan, pSkyMan, pLightEnv, pCamera, pPostproc, pSimulation2); + WriteXML(pathnameXML, pWaterMan, pSkyMan, pLightEnv, camera, pPostproc, pSimulation2); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -204,7 +204,7 @@ void CMapWriter::PackTerrain(CFilePacker& packer, CTerrain* pTerrain) void CMapWriter::WriteXML(const VfsPath& filename, WaterManager* pWaterMan, SkyManager* pSkyMan, - CLightEnv* pLightEnv, CCamera* pCamera, + CLightEnv* pLightEnv, const CCamera& camera, CPostprocManager* pPostproc, CSimulation2* pSimulation2) { @@ -299,13 +299,13 @@ void CMapWriter::WriteXML(const VfsPath& filename, XMLWriter_Element cameraTag(xmlMapFile, "Camera"); { XMLWriter_Element positionTag(xmlMapFile, "Position"); - CVector3D pos = pCamera->GetOrientation().GetTranslation(); + const CVector3D pos{camera.GetOrientation().GetTranslation()}; positionTag.Attribute("x", pos.X); positionTag.Attribute("y", pos.Y); positionTag.Attribute("z", pos.Z); } - CVector3D in = pCamera->GetOrientation().GetIn(); + const CVector3D in{camera.GetOrientation().GetIn()}; // Convert to spherical coordinates float rotation = atan2(in.X, in.Z); float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - std::numbers::pi_v / 2.f; diff --git a/source/graphics/MapWriter.h b/source/graphics/MapWriter.h index 2b17040f87..2f748eb02e 100644 --- a/source/graphics/MapWriter.h +++ b/source/graphics/MapWriter.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -42,7 +42,7 @@ public: // SaveMap: try to save the current map to the given file void SaveMap(const VfsPath& pathname, CTerrain* pTerr, WaterManager* pWaterMan, SkyManager* pSkyMan, - CLightEnv* pLightEnv, CCamera* pCamera, + CLightEnv* pLightEnv, const CCamera& camera, CCinemaManager* pCinema, CPostprocManager* pPostproc, CSimulation2* pSimulation2); @@ -59,7 +59,7 @@ private: // WriteXML: output some other data (entities, etc) in XML format void WriteXML(const VfsPath& pathname, WaterManager* pWaterMan, - SkyManager* pSkyMan, CLightEnv* pLightEnv, CCamera* pCamera, + SkyManager* pSkyMan, CLightEnv* pLightEnv, const CCamera& camera, CPostprocManager* pPostproc, CSimulation2* pSimulation2); }; diff --git a/source/graphics/scripting/JSInterface_GameView.cpp b/source/graphics/scripting/JSInterface_GameView.cpp index c2c8232535..3afcc76f79 100644 --- a/source/graphics/scripting/JSInterface_GameView.cpp +++ b/source/graphics/scripting/JSInterface_GameView.cpp @@ -196,7 +196,7 @@ entity_id_t GetFollowedEntity() CFixedVector3D GetTerrainAtScreenPoint(int x, int y) { - CVector3D pos = g_Game->GetView()->GetCamera()->GetWorldCoordinates(x, y, true); + CVector3D pos = g_Game->GetView()->GetCamera().GetWorldCoordinates(x, y, true); return CFixedVector3D(fixed::FromFloat(pos.X), fixed::FromFloat(pos.Y), fixed::FromFloat(pos.Z)); } diff --git a/source/gui/ObjectTypes/CMiniMap.cpp b/source/gui/ObjectTypes/CMiniMap.cpp index 141998ed37..4808fada5f 100644 --- a/source/gui/ObjectTypes/CMiniMap.cpp +++ b/source/gui/ObjectTypes/CMiniMap.cpp @@ -238,7 +238,7 @@ void CMiniMap::SetCameraPositionFromMousePosition() float CMiniMap::GetAngle() const { - CVector3D cameraIn = g_Game->GetView()->GetCamera()->GetOrientation().GetIn(); + CVector3D cameraIn = g_Game->GetView()->GetCamera().GetOrientation().GetIn(); return -atan2(cameraIn.X, cameraIn.Z); } @@ -288,12 +288,12 @@ void CMiniMap::DrawViewRect(CCanvas2D& canvas) const // Use the water height as a fixed base height, which should be the lowest we can go const float sampleHeight = g_Renderer.GetSceneRenderer().GetWaterManager().m_WaterHeight; - const CCamera* camera = g_Game->GetView()->GetCamera(); + const CCamera& camera{g_Game->GetView()->GetCamera()}; const std::array hitPoints = { - camera->GetWorldCoordinates(0, g_Renderer.GetHeight(), sampleHeight), - camera->GetWorldCoordinates(g_Renderer.GetWidth(), g_Renderer.GetHeight(), sampleHeight), - camera->GetWorldCoordinates(g_Renderer.GetWidth(), 0, sampleHeight), - camera->GetWorldCoordinates(0, 0, sampleHeight) + camera.GetWorldCoordinates(0, g_Renderer.GetHeight(), sampleHeight), + camera.GetWorldCoordinates(g_Renderer.GetWidth(), g_Renderer.GetHeight(), sampleHeight), + camera.GetWorldCoordinates(g_Renderer.GetWidth(), 0, sampleHeight), + camera.GetWorldCoordinates(0, 0, sampleHeight) }; std::vector worldSpaceLines; diff --git a/source/ps/TouchInput.cpp b/source/ps/TouchInput.cpp index 77982c62ee..bc3f656d99 100644 --- a/source/ps/TouchInput.cpp +++ b/source/ps/TouchInput.cpp @@ -133,7 +133,7 @@ void CTouchInput::OnFingerMotion(int id, int x, int y) { m_State = STATE_PANNING; - const CCamera& camera = *(g_Game->GetView()->GetCamera()); + const CCamera& camera{g_Game->GetView()->GetCamera()}; m_PanFocus = camera.GetWorldCoordinates(m_FirstTouchPos.X, m_FirstTouchPos.Y, true); m_PanDist = (m_PanFocus - camera.GetOrientation().GetTranslation()).Y; } @@ -141,7 +141,7 @@ void CTouchInput::OnFingerMotion(int id, int x, int y) if (m_State == STATE_PANNING && id == 0) { - CCamera& camera = *(g_Game->GetView()->GetCamera()); + CCamera& camera{g_Game->GetView()->GetCamera()}; auto [origin, dir] = camera.BuildCameraRay(x, y); dir *= m_PanDist / dir.Y; camera.GetOrientation().Translate(m_PanFocus - dir - origin); @@ -154,7 +154,7 @@ void CTouchInput::OnFingerMotion(int id, int x, int y) float newDist = (m_Pos[id] - m_Pos[1 - id]).Length(); float zoomDist = (newDist - oldDist) * -0.005f * m_PanDist; - CCamera& camera = *(g_Game->GetView()->GetCamera()); + CCamera& camera{g_Game->GetView()->GetCamera()}; CVector3D dir{camera.BuildCameraRay(m_Pos[0].X, m_Pos[0].Y).direction}; dir *= zoomDist; camera.GetOrientation().Translate(dir); diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index 9598fb5f78..a2ef5a89b2 100644 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -1380,7 +1380,7 @@ void CPatchRData::RenderSides( void CPatchRData::RenderPriorities(CTextRenderer& textRenderer) { CTerrain* terrain = m_Patch->m_Parent; - const CCamera& camera = *(g_Game->GetView()->GetCamera()); + const CCamera& camera{g_Game->GetView()->GetCamera()}; for (ssize_t j = 0; j < PATCH_SIZE; ++j) { diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index cafd37e0ce..7c6478d165 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -863,7 +863,7 @@ void CRenderer::RenderBigScreenShot(const bool needsPresent) return; } - CCamera oldCamera = *g_Game->GetView()->GetCamera(); + const CCamera oldCamera{g_Game->GetView()->GetCamera()}; // Resize various things so that the sizes and aspect ratios are correct { @@ -887,7 +887,7 @@ void CRenderer::RenderBigScreenShot(const bool needsPresent) oldCamera.GetFOV(), aspectRatio, oldCamera.GetNearPlane(), oldCamera.GetFarPlane(), tiles, tileX, tileY); } - g_Game->GetView()->GetCamera()->SetProjection(projection); + g_Game->GetView()->GetCamera().SetProjection(projection); Renderer::Backend::ISwapChain* swapChain{g_VideoMode.GetOrCreateSwapChain()}; if (!swapChain || !swapChain->IsValid()) @@ -919,7 +919,7 @@ void CRenderer::RenderBigScreenShot(const bool needsPresent) g_Renderer.Resize(g_xres, g_yres); SViewPort vp = { 0, 0, g_xres, g_yres }; g_Game->GetView()->SetViewport(vp); - g_Game->GetView()->GetCamera()->SetProjectionFromCamera(oldCamera); + g_Game->GetView()->GetCamera().SetProjectionFromCamera(oldCamera); } if (tex_write(&t, filename) == INFO::OK) diff --git a/source/simulation2/components/CCmpCinemaManager.cpp b/source/simulation2/components/CCmpCinemaManager.cpp index 7acc5c0134..b2e38ca23f 100644 --- a/source/simulation2/components/CCmpCinemaManager.cpp +++ b/source/simulation2/components/CCmpCinemaManager.cpp @@ -258,7 +258,7 @@ public: return m_IsPlayingPathQueue; } - void UpdateActivePath(const float deltaRealTime, CCamera* camera) override + void UpdateActivePath(const float deltaRealTime, CCamera& camera) override { if (m_IsPlayingPathQueue) { diff --git a/source/simulation2/components/ICmpCinemaManager.h b/source/simulation2/components/ICmpCinemaManager.h index ff0adb71fb..63f1ad8a70 100644 --- a/source/simulation2/components/ICmpCinemaManager.h +++ b/source/simulation2/components/ICmpCinemaManager.h @@ -97,7 +97,7 @@ public: * Send an update to the path currently playing for it to determine the new camera position. * Called every frame. */ - virtual void UpdateActivePath(const float deltaRealTime, CCamera* camera) = 0; + virtual void UpdateActivePath(const float deltaRealTime, CCamera& camera) = 0; /** * Get the name of the path currently playing, if any. diff --git a/source/simulation2/helpers/CinemaPath.cpp b/source/simulation2/helpers/CinemaPath.cpp index cd01c7e90c..eef82250c6 100644 --- a/source/simulation2/helpers/CinemaPath.cpp +++ b/source/simulation2/helpers/CinemaPath.cpp @@ -113,7 +113,7 @@ void CCinemaPath::SetTimescale(fixed scale) m_Timescale = scale; } -void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera) const +void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera& camera) const { t = (this->*DistModePtr)(t); @@ -122,9 +122,9 @@ void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRota if (m_LookAtTarget) { if (m_TimeElapsed <= m_TargetSpline.MaxDistance.ToFloat()) - camera->LookAt(pos, m_TargetSpline.GetPosition(m_TimeElapsed / m_TargetSpline.MaxDistance.ToFloat()), CVector3D(0, 1, 0)); + camera.LookAt(pos, m_TargetSpline.GetPosition(m_TimeElapsed / m_TargetSpline.MaxDistance.ToFloat()), CVector3D(0, 1, 0)); else - camera->LookAt(pos, m_TargetSpline.GetAllNodes().back().Position, CVector3D(0, 1, 0)); + camera.LookAt(pos, m_TargetSpline.GetAllNodes().back().Position, CVector3D(0, 1, 0)); } else { @@ -134,11 +134,11 @@ void CCinemaPath::MoveToPointAt(float t, float nodet, const CVector3D& startRota end.FromEulerAngles(DEGTORAD(nodeRotation.X), DEGTORAD(nodeRotation.Y), DEGTORAD(nodeRotation.Z)); start.Slerp(start, end, nodet); - camera->m_Orientation.SetIdentity(); - camera->m_Orientation.Rotate(start); - camera->m_Orientation.Translate(pos); + camera.m_Orientation.SetIdentity(); + camera.m_Orientation.Rotate(start); + camera.m_Orientation.Translate(pos); } - camera->UpdateFrustum(); + camera.UpdateFrustum(); } // Distortion mode functions @@ -236,7 +236,7 @@ bool CCinemaPath::Validate() return false; } -bool CCinemaPath::Play(const float deltaRealTime, CCamera* camera) +bool CCinemaPath::Play(const float deltaRealTime, CCamera& camera) { m_TimeElapsed += m_Timescale.ToFloat() * deltaRealTime; if (!Validate()) diff --git a/source/simulation2/helpers/CinemaPath.h b/source/simulation2/helpers/CinemaPath.h index 576c68d28c..c1d6be49af 100644 --- a/source/simulation2/helpers/CinemaPath.h +++ b/source/simulation2/helpers/CinemaPath.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -62,7 +62,7 @@ public: CCinemaPath(const CCinemaData& data, const TNSpline& spline, const TNSpline& targetSpline); // Sets camera position to calculated point on spline - void MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera* camera) const; + void MoveToPointAt(float t, float nodet, const CVector3D& startRotation, CCamera& camera) const; // Distortion mode functions-change how ratio is passed to distortion style functions float EaseIn(float t) const; @@ -108,7 +108,7 @@ public: * @param deltaRealTime Elapsed real time since the last frame. * @param camera An affected camera */ - bool Play(const float deltaRealTime, CCamera* camera); + bool Play(const float deltaRealTime, CCamera& camera); /** * Validate the path diff --git a/source/simulation2/scripting/JSInterface_Simulation.cpp b/source/simulation2/scripting/JSInterface_Simulation.cpp index dac73f3e73..62a1c45071 100644 --- a/source/simulation2/scripting/JSInterface_Simulation.cpp +++ b/source/simulation2/scripting/JSInterface_Simulation.cpp @@ -108,22 +108,22 @@ void DumpSimState() entity_id_t PickEntityAtPoint(int x, int y) { - return EntitySelection::PickEntityAtPoint(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x, y, g_Game->GetViewedPlayerID(), false); + return EntitySelection::PickEntityAtPoint(*g_Game->GetSimulation2(), g_Game->GetView()->GetCamera(), x, y, g_Game->GetViewedPlayerID(), false); } std::vector PickPlayerEntitiesInRect(int x0, int y0, int x1, int y1, int player) { - return EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x0, y0, x1, y1, player, false); + return EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), g_Game->GetView()->GetCamera(), x0, y0, x1, y1, player, false); } std::vector PickPlayerEntitiesOnScreen(int player) { - return EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), 0, 0, g_xres, g_yres, player, false); + return EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), g_Game->GetView()->GetCamera(), 0, 0, g_xres, g_yres, player, false); } std::vector PickNonGaiaEntitiesOnScreen() { - return EntitySelection::PickNonGaiaEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), 0, 0, g_xres, g_yres, false); + return EntitySelection::PickNonGaiaEntitiesInRect(*g_Game->GetSimulation2(), g_Game->GetView()->GetCamera(), 0, 0, g_xres, g_yres, false); } std::vector GetEntitiesWithStaticObstructionOnScreen() @@ -136,7 +136,7 @@ std::vector GetEntitiesWithStaticObstructionOnScreen() return cmpObstruction->GetObstructionType() == ICmpObstruction::STATIC; } }; - return EntitySelection::GetEntitiesWithComponentInRect(*g_Game->GetSimulation2(), IID_Obstruction, *g_Game->GetView()->GetCamera(), 0, 0, g_xres, g_yres); + return EntitySelection::GetEntitiesWithComponentInRect(*g_Game->GetSimulation2(), IID_Obstruction, g_Game->GetView()->GetCamera(), 0, 0, g_xres, g_yres); } JS::Value GetEdgesOfStaticObstructionsOnScreenNearTo(const Script::Interface& scriptInterface, entity_pos_t x, entity_pos_t z) @@ -209,7 +209,7 @@ JS::Value GetEdgesOfStaticObstructionsOnScreenNearTo(const Script::Interface& sc std::vector PickSimilarPlayerEntities(const std::string& templateName, bool includeOffScreen, bool matchRank, bool allowFoundations) { - return EntitySelection::PickSimilarEntities(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), templateName, g_Game->GetViewedPlayerID(), includeOffScreen, matchRank, false, allowFoundations); + return EntitySelection::PickSimilarEntities(*g_Game->GetSimulation2(), g_Game->GetView()->GetCamera(), templateName, g_Game->GetViewedPlayerID(), includeOffScreen, matchRank, false, allowFoundations); } JS::Value GetAIs(const Script::Interface& scriptInterface) diff --git a/source/soundmanager/scripting/SoundGroup.cpp b/source/soundmanager/scripting/SoundGroup.cpp index 1ea41ed470..3a853f405d 100644 --- a/source/soundmanager/scripting/SoundGroup.cpp +++ b/source/soundmanager/scripting/SoundGroup.cpp @@ -150,13 +150,13 @@ float CSoundGroup::RadiansOffCenter([[maybe_unused]] const CVector3D& position, #if !CONFIG2_AUDIO return 0.f; #else - const int screenWidth = g_Game->GetView()->GetCamera()->GetViewPort().m_Width; - const int screenHeight = g_Game->GetView()->GetCamera()->GetViewPort().m_Height; + const int screenWidth = g_Game->GetView()->GetCamera().GetViewPort().m_Width; + const int screenHeight = g_Game->GetView()->GetCamera().GetViewPort().m_Height; const float xBufferSize = screenWidth * 0.1f; const float yBufferSize = 15.f; const float radianCap = m_MaxStereoAngle; - const CVector2D screenPos{g_Game->GetView()->GetCamera()->GetScreenCoordinates(position)}; + const CVector2D screenPos{g_Game->GetView()->GetCamera().GetScreenCoordinates(position)}; onScreen = true; float answer = 0.f; @@ -225,7 +225,7 @@ void CSoundGroup::UploadPropertiesAndPlay([[maybe_unused]] size_t index, if (!TestFlag(eOmnipresent)) { - CVector3D origin = g_Game->GetView()->GetCamera()->GetOrientation().GetTranslation(); + CVector3D origin = g_Game->GetView()->GetCamera().GetOrientation().GetTranslation(); float itemDist = (position - origin).Length(); if (TestFlag(eDistanceless)) diff --git a/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp index 3900fcb342..e6f3095ca1 100644 --- a/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp @@ -49,7 +49,7 @@ MESSAGEHANDLER(CameraReset) if (!g_Game || g_Game->GetView()->GetCinema()->IsPlaying()) return; - CVector3D focus = g_Game->GetView()->GetCamera()->GetFocus(); + CVector3D focus = g_Game->GetView()->GetCamera().GetFocus(); CVector3D target; if (!g_Game->GetWorld()->GetTerrain().IsOnMap(focus.X, focus.Z)) @@ -95,7 +95,7 @@ MESSAGEHANDLER(Scroll) static CVector3D targetPos; static float targetDistance = 0.f; - CMatrix3D& camera = g_Game->GetView()->GetCamera()->m_Orientation; + CMatrix3D& camera = g_Game->GetView()->GetCamera().m_Orientation; static CVector3D lastCameraPos = camera.GetTranslation(); @@ -124,10 +124,10 @@ MESSAGEHANDLER(Scroll) { float x, y; msg->pos->GetScreenSpace(x, y); - auto [origin, dir] = g_Game->GetView()->GetCamera()->BuildCameraRay((int)x, (int)y); + auto [origin, dir] = g_Game->GetView()->GetCamera().BuildCameraRay((int)x, (int)y); dir *= targetDistance; camera.Translate(targetPos - dir - origin); - g_Game->GetView()->GetCamera()->UpdateFrustum(); + g_Game->GetView()->GetCamera().UpdateFrustum(); } else { @@ -152,7 +152,7 @@ MESSAGEHANDLER(RotateAround) static CVector3D focusPos; static float lastX = 0.f, lastY = 0.f; - CMatrix3D& camera = g_Game->GetView()->GetCamera()->m_Orientation; + CMatrix3D& camera = g_Game->GetView()->GetCamera().m_Orientation; if (msg->type == eRotateAroundType::FROM) { @@ -186,7 +186,7 @@ MESSAGEHANDLER(RotateAround) camera._21 = 0.f; // (_21 = Y component returned by GetLeft()) camera.Translate(focusPos + offset); - g_Game->GetView()->GetCamera()->UpdateFrustum(); + g_Game->GetView()->GetCamera().UpdateFrustum(); lastX = x; lastY = y; @@ -232,14 +232,14 @@ QUERYHANDLER(GetView) if (!g_Game) return; - CVector3D focus = g_Game->GetView()->GetCamera()->GetFocus(); + CVector3D focus = g_Game->GetView()->GetCamera().GetFocus(); sCameraInfo info; info.pX = focus.X; info.pY = focus.Y; info.pZ = focus.Z; - CQuaternion quatRot = g_Game->GetView()->GetCamera()->GetOrientation().GetRotation(); + CQuaternion quatRot = g_Game->GetView()->GetCamera().GetOrientation().GetRotation(); quatRot.Normalize(); CVector3D rotation = quatRot.ToEulerAngles(); @@ -256,7 +256,7 @@ MESSAGEHANDLER(SetView) return; CGameView* view = g_Game->GetView(); - view->ResetCameraTarget(view->GetCamera()->GetFocus()); + view->ResetCameraTarget(view->GetCamera().GetFocus()); sCameraInfo cam = msg->info; diff --git a/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp b/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp index b5a03689f5..dfa3cfbc3a 100644 --- a/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp +++ b/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp @@ -162,7 +162,7 @@ void SetCurrentPaths(const std::vector& atlasPaths) QUERYHANDLER(GetCameraInfo) { sCameraInfo info; - const CMatrix3D& cameraOrientation = g_Game->GetView()->GetCamera()->GetOrientation(); + const CMatrix3D& cameraOrientation = g_Game->GetView()->GetCamera().GetOrientation(); CQuaternion quatRot = cameraOrientation.GetRotation(); quatRot.Normalize(); @@ -214,14 +214,14 @@ BEGIN_COMMAND(AddCinemaPath) pathData.m_Mode = L"ease_inout"; pathData.m_Style = L"default"; - CVector3D focus = g_Game->GetView()->GetCamera()->GetFocus(); + CVector3D focus = g_Game->GetView()->GetCamera().GetFocus(); CFixedVector3D target( fixed::FromFloat(focus.X), fixed::FromFloat(focus.Y), fixed::FromFloat(focus.Z) ); - CVector3D camera = g_Game->GetView()->GetCamera()->GetOrientation().GetTranslation(); + CVector3D camera = g_Game->GetView()->GetCamera().GetOrientation().GetTranslation(); CFixedVector3D position( fixed::FromFloat(camera.X), fixed::FromFloat(camera.Y), @@ -310,8 +310,8 @@ static CVector3D GetNearestPointToScreenCoords(const CVector3D& base, const CVec float delta = (upper - lower) / 3.0; float middle1 = lower + delta, middle2 = lower + 2.0f * delta; CVector3D p1 = base + dir * middle1, p2 = base + dir * middle2; - const CVector2D s1{g_Game->GetView()->GetCamera()->GetScreenCoordinates(p1)}; - const CVector2D s2{g_Game->GetView()->GetCamera()->GetScreenCoordinates(p2)}; + const CVector2D s1{g_Game->GetView()->GetCamera().GetScreenCoordinates(p1)}; + const CVector2D s2{g_Game->GetView()->GetCamera().GetScreenCoordinates(p2)}; if ((s1 - screen).Length() < (s2 - screen).Length()) upper = middle2; else @@ -351,7 +351,7 @@ BEGIN_COMMAND(AddPathNode) TNSpline targetSpline = path.GetTargetSpline(); TNSpline& spline = msg->node->targetNode ? targetSpline : positionSpline; - CVector3D focus = g_Game->GetView()->GetCamera()->GetFocus(); + CVector3D focus = g_Game->GetView()->GetCamera().GetFocus(); CFixedVector3D target( fixed::FromFloat(focus.X), fixed::FromFloat(focus.Y), @@ -479,7 +479,7 @@ static bool isPathNodePicked(const TNSpline& spline, const CVector2D& cursor, At data.Position.Y.ToFloat(), data.Position.Z.ToFloat() ); - const CVector2D screenPos{g_Game->GetView()->GetCamera()->GetScreenCoordinates(position)}; + const CVector2D screenPos{g_Game->GetView()->GetCamera().GetScreenCoordinates(position)}; if ((screenPos - cursor).Length() < MINIMAL_SCREEN_DISTANCE) { node.index = i; @@ -524,7 +524,7 @@ QUERYHANDLER(PickPathNode) static bool isAxisPicked(const CVector3D& base, const CVector3D& direction, float length, const CVector2D& cursor) { CVector3D position = GetNearestPointToScreenCoords(base, direction, cursor, 0, length); - const CVector2D screenPos{g_Game->GetView()->GetCamera()->GetScreenCoordinates(position)}; + const CVector2D screenPos{g_Game->GetView()->GetCamera().GetScreenCoordinates(position)}; return (cursor - screenPos).Length() < MINIMAL_SCREEN_DISTANCE; } @@ -537,7 +537,7 @@ QUERYHANDLER(PickAxis) const TNSpline& spline = msg->node->targetNode ? path.GetTargetSpline() : path; CFixedVector3D pos = spline.GetAllNodes()[index].Position; CVector3D position(pos.X.ToFloat(), pos.Y.ToFloat(), pos.Z.ToFloat()); - CVector3D camera = g_Game->GetView()->GetCamera()->GetOrientation().GetTranslation(); + CVector3D camera = g_Game->GetView()->GetCamera().GetOrientation().GetTranslation(); float scale = (position - camera).Length() / 10.0; CVector2D cursor; diff --git a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp index 008b213efe..e31d56c664 100644 --- a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -667,7 +667,7 @@ QUERYHANDLER(PickObject) // Normally this function would be called with a player ID to check LOS, // but in Atlas the entire map is revealed, so just pass INVALID_PLAYER - entity_id_t ent = EntitySelection::PickEntityAtPoint(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x, y, INVALID_PLAYER, msg->selectActors);; + entity_id_t ent = EntitySelection::PickEntityAtPoint(*g_Game->GetSimulation2(), g_Game->GetView()->GetCamera(), x, y, INVALID_PLAYER, msg->selectActors);; if (ent == INVALID_ENTITY) msg->id = INVALID_ENTITY; @@ -687,7 +687,7 @@ QUERYHANDLER(PickObject) CFixedVector3D fixed = cmpPosition->GetPosition(); CVector3D centre = CVector3D(fixed.X.ToFloat(), fixed.Y.ToFloat(), fixed.Z.ToFloat()); - const CVector2D screenPos{g_Game->GetView()->GetCamera()->GetScreenCoordinates(centre)}; + const CVector2D screenPos{g_Game->GetView()->GetCamera().GetScreenCoordinates(centre)}; msg->offsetx = static_cast(screenPos.X - x); msg->offsety = static_cast(screenPos.Y - y); @@ -703,7 +703,7 @@ QUERYHANDLER(PickObjectsInRect) msg->end->GetScreenSpace(x1, y1); // Since owner selections are meaningless in Atlas, use INVALID_PLAYER - msg->ids = EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x0, y0, x1, y1, INVALID_PLAYER, msg->selectActors); + msg->ids = EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), g_Game->GetView()->GetCamera(), x0, y0, x1, y1, INVALID_PLAYER, msg->selectActors); } @@ -721,7 +721,7 @@ QUERYHANDLER(PickSimilarObjects) if (cmpOwnership) owner = cmpOwnership->GetOwner(); - msg->ids = EntitySelection::PickSimilarEntities(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), templateName, owner, false, true, true, false); + msg->ids = EntitySelection::PickSimilarEntities(*g_Game->GetSimulation2(), g_Game->GetView()->GetCamera(), templateName, owner, false, true, true, false); } MESSAGEHANDLER(ResetSelectionColor) diff --git a/source/tools/atlas/GameInterface/InputProcessor.cpp b/source/tools/atlas/GameInterface/InputProcessor.cpp index 5fa7a61586..e0867f9558 100644 --- a/source/tools/atlas/GameInterface/InputProcessor.cpp +++ b/source/tools/atlas/GameInterface/InputProcessor.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -52,11 +52,11 @@ bool InputProcessor::ProcessInput(GameLoopState* state) if (! g_Game) return false; - CCamera* camera = g_Game->GetView()->GetCamera(); + CCamera& camera{g_Game->GetView()->GetCamera()}; - CVector3D leftwards = camera->m_Orientation.GetLeft(); + CVector3D leftwards = camera.m_Orientation.GetLeft(); - CVector3D inwards = camera->m_Orientation.GetIn(); + CVector3D inwards = camera.m_Orientation.GetIn(); // Calculate a vector pointing forwards, parallel to the ground CVector3D forwards = inwards; @@ -72,44 +72,44 @@ bool InputProcessor::ProcessInput(GameLoopState* state) if (state->input.scrollSpeed[0] != 0.0f) { - camera->m_Orientation.Translate(forwards * (input.scrollSpeed[0] * state->realFrameLength)); + camera.m_Orientation.Translate(forwards * (input.scrollSpeed[0] * state->realFrameLength)); moved = true; } if (state->input.scrollSpeed[1] != 0.0f) { - camera->m_Orientation.Translate(forwards * (-input.scrollSpeed[1] * state->realFrameLength)); + camera.m_Orientation.Translate(forwards * (-input.scrollSpeed[1] * state->realFrameLength)); moved = true; } if (state->input.scrollSpeed[2] != 0.0f) { - camera->m_Orientation.Translate(leftwards * (input.scrollSpeed[2] * state->realFrameLength)); + camera.m_Orientation.Translate(leftwards * (input.scrollSpeed[2] * state->realFrameLength)); moved = true; } if (state->input.scrollSpeed[3] != 0.0f) { - camera->m_Orientation.Translate(leftwards * (-input.scrollSpeed[3] * state->realFrameLength)); + camera.m_Orientation.Translate(leftwards * (-input.scrollSpeed[3] * state->realFrameLength)); moved = true; } if (state->input.scrollSpeed[4] != 0.0f) { - Rotate(*camera, input.scrollSpeed[4] * state->realFrameLength * g_ViewRotateScale); + Rotate(camera, input.scrollSpeed[4] * state->realFrameLength * g_ViewRotateScale); moved = true; } if (state->input.scrollSpeed[5] != 0.0f) { - Rotate(*camera, -input.scrollSpeed[5] * state->realFrameLength * g_ViewRotateScale); + Rotate(camera, -input.scrollSpeed[5] * state->realFrameLength * g_ViewRotateScale); moved = true; } if (state->input.zoomDelta != 0.0f) { float zoom_proportion = powf(g_ViewZoomSmoothness, state->realFrameLength); - camera->m_Orientation.Translate(inwards * (input.zoomDelta * (1.0f - zoom_proportion))); + camera.m_Orientation.Translate(inwards * (input.zoomDelta * (1.0f - zoom_proportion))); input.zoomDelta *= zoom_proportion; if (fabsf(input.zoomDelta) < 0.1f) @@ -119,7 +119,7 @@ bool InputProcessor::ProcessInput(GameLoopState* state) } if (moved) - camera->UpdateFrustum(); + camera.UpdateFrustum(); return moved; } diff --git a/source/tools/atlas/GameInterface/Misc.cpp b/source/tools/atlas/GameInterface/Misc.cpp index 480030340f..95ebf74506 100644 --- a/source/tools/atlas/GameInterface/Misc.cpp +++ b/source/tools/atlas/GameInterface/Misc.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -36,7 +36,7 @@ CVector3D AtlasMessage::Position::GetWorldSpace(bool floating) const break; case 1: - return g_Game->GetView()->GetCamera()->GetWorldCoordinates(type1.x, type1.y, floating); + return g_Game->GetView()->GetCamera().GetWorldCoordinates(type1.x, type1.y, floating); break; case 2: @@ -55,7 +55,7 @@ CVector3D AtlasMessage::Position::GetWorldSpace(float h, bool floating) const switch (type) { case 1: - return g_Game->GetView()->GetCamera()->GetWorldCoordinates(type1.x, type1.y, h); + return g_Game->GetView()->GetCamera().GetWorldCoordinates(type1.x, type1.y, h); default: return GetWorldSpace(floating); @@ -80,7 +80,7 @@ void AtlasMessage::Position::GetScreenSpace(float& x, float& y) const { case 0: { - const CVector2D screenPos{g_Game->GetView()->GetCamera()->GetScreenCoordinates( + const CVector2D screenPos{g_Game->GetView()->GetCamera().GetScreenCoordinates( CVector3D{type0.x, type0.y, type0.x})}; x = screenPos.X; y = screenPos.Y; diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index 7001dae442..d7b7e4f103 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -229,7 +229,7 @@ void AtlasViewGame::Update(float realFrameLength) // Cinematic motion should be independent of simulation update, so we can // preview the cinematics by themselves - g_Game->GetView()->GetCinema()->Update(realFrameLength); + g_Game->GetView()->GetCinema()->Update(realFrameLength, g_Game->GetView()->GetCamera()); } void AtlasViewGame::Render() @@ -241,7 +241,7 @@ void AtlasViewGame::Render() SViewPort vp = { 0, 0, g_xres, g_yres }; CCamera& camera = GetCamera(); camera.SetViewPort(vp); - camera.SetProjectionFromCamera(*g_Game->GetView()->GetCamera()); + camera.SetProjectionFromCamera(g_Game->GetView()->GetCamera()); camera.UpdateFrustum(); g_Renderer.RenderFrame(false); @@ -337,7 +337,7 @@ void AtlasViewGame::SetParam(const std::wstring& name, const std::wstring& value CCamera& AtlasViewGame::GetCamera() { - return *g_Game->GetView()->GetCamera(); + return g_Game->GetView()->GetCamera(); } bool AtlasViewGame::GetSmoothFramerate() const