Index: ps/trunk/source/graphics/Camera.cpp =================================================================== --- ps/trunk/source/graphics/Camera.cpp +++ ps/trunk/source/graphics/Camera.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -277,7 +277,7 @@ // Clamp the water intersection to within the map's bounds, so that // we'll always return a valid position on the map - ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); + const ssize_t mapSize = g_Game->GetWorld()->GetTerrain().GetVerticesPerSide(); if (gotWater) { waterPoint.X = Clamp(waterPoint.X, 0.f, (mapSize - 1) * TERRAIN_TILE_SIZE); @@ -355,7 +355,7 @@ // Clamp the water intersection to within the map's bounds, so that // we'll always return a valid position on the map - ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); + const ssize_t mapSize = g_Game->GetWorld()->GetTerrain().GetVerticesPerSide(); if (gotWater) { waterPoint.X = Clamp(waterPoint.X, 0.f, (mapSize - 1) * TERRAIN_TILE_SIZE); Index: ps/trunk/source/graphics/CameraController.cpp =================================================================== --- ps/trunk/source/graphics/CameraController.cpp +++ ps/trunk/source/graphics/CameraController.cpp @@ -1,19 +1,19 @@ -/* Copyright (C) 2022 Wildfire Games. -* This file is part of 0 A.D. -* -* 0 A.D. is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 2 of the License, or -* (at your option) any later version. -* -* 0 A.D. is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with 0 A.D. If not, see . -*/ +/* Copyright (C) 2023 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ #include "precompiled.h" @@ -293,7 +293,7 @@ CCamera targetCam = m_Camera; SetupCameraMatrixSmoothRot(&targetCam.m_Orientation); - CTerrain* pTerrain = g_Game->GetWorld()->GetTerrain(); + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); CVector3D pivot = GetSmoothPivot(targetCam); CVector3D delta = targetCam.GetOrientation().GetTranslation() - pivot; @@ -304,7 +304,7 @@ if (cmpRangeManager && cmpRangeManager->GetLosCircular()) { // Clamp to a circular region around the center of the map - float r = pTerrain->GetMaxX() / 2; + const float r = terrain.GetMaxX() / 2.f; CVector3D center(r, desiredPivot.Y, r); float dist = (desiredPivot - center).Length(); if (dist > r - CAMERA_EDGE_MARGIN) @@ -313,8 +313,10 @@ else { // Clamp to the square edges of the map - desiredPivot.X = Clamp(desiredPivot.X, pTerrain->GetMinX() + CAMERA_EDGE_MARGIN, pTerrain->GetMaxX() - CAMERA_EDGE_MARGIN); - desiredPivot.Z = Clamp(desiredPivot.Z, pTerrain->GetMinZ() + CAMERA_EDGE_MARGIN, pTerrain->GetMaxZ() - CAMERA_EDGE_MARGIN); + desiredPivot.X = Clamp(desiredPivot.X, terrain.GetMinX() + CAMERA_EDGE_MARGIN, + terrain.GetMaxX() - CAMERA_EDGE_MARGIN); + desiredPivot.Z = Clamp(desiredPivot.Z, terrain.GetMinZ() + CAMERA_EDGE_MARGIN, + terrain.GetMaxZ() - CAMERA_EDGE_MARGIN); } // Update the position so that pivot is within the margin @@ -580,12 +582,12 @@ const CVector3D pivotPoint = position + forwards * m_Zoom.GetSmoothedValue(); const float ground = std::max( - g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(nearPoint.X, nearPoint.Z), + g_Game->GetWorld()->GetTerrain().GetExactGroundLevel(nearPoint.X, nearPoint.Z), g_Renderer.GetSceneRenderer().GetWaterManager().m_WaterHeight); // filter ground levels for smooth camera movement - const float filtered_near_ground = g_Game->GetWorld()->GetTerrain()->GetFilteredGroundLevel(nearPoint.X, nearPoint.Z, near_radius); - const float filtered_pivot_ground = g_Game->GetWorld()->GetTerrain()->GetFilteredGroundLevel(pivotPoint.X, pivotPoint.Z, pivot_radius); + const float filtered_near_ground = g_Game->GetWorld()->GetTerrain().GetFilteredGroundLevel(nearPoint.X, nearPoint.Z, near_radius); + const float filtered_pivot_ground = g_Game->GetWorld()->GetTerrain().GetFilteredGroundLevel(pivotPoint.X, pivotPoint.Z, pivot_radius); // filtered maximum visible ground level in view const float filtered_ground = std::max( Index: ps/trunk/source/graphics/CinemaManager.cpp =================================================================== --- ps/trunk/source/graphics/CinemaManager.cpp +++ ps/trunk/source/graphics/CinemaManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -103,13 +103,13 @@ g_Renderer.GetDebugRenderer().DrawLine(line, splineColor, 0.2f, false); // Height indicator - if (g_Game && g_Game->GetWorld() && g_Game->GetWorld()->GetTerrain()) + if (g_Game && g_Game->GetWorld()) { for (int i = 0; i <= smoothness; ++i) { const float time = start * i / spline.MaxDistance.ToFloat(); const CVector3D tmp = spline.GetPosition(time); - const float groundY = g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(tmp.X, tmp.Z); + const float groundY = g_Game->GetWorld()->GetTerrain().GetExactGroundLevel(tmp.X, tmp.Z); g_Renderer.GetDebugRenderer().DrawLine(tmp, CVector3D(tmp.X, groundY, tmp.Z), splineColor, 0.1f, false); } } Index: ps/trunk/source/graphics/GameView.cpp =================================================================== --- ps/trunk/source/graphics/GameView.cpp +++ ps/trunk/source/graphics/GameView.cpp @@ -259,16 +259,16 @@ { PROFILE3("submit terrain"); - CTerrain* pTerrain = m->Game->GetWorld()->GetTerrain(); + const CTerrain& terrain = m->Game->GetWorld()->GetTerrain(); float waterHeight = g_Renderer.GetSceneRenderer().GetWaterManager().m_WaterHeight + 0.001f; - const ssize_t patchesPerSide = pTerrain->GetPatchesPerSide(); + const ssize_t patchesPerSide = terrain.GetPatchesPerSide(); // find out which patches will be drawn for (ssize_t j=0; jGetPatch(i,j); // can't fail + CPatch* const patch = terrain.GetPatch(i,j); // can't fail // If the patch is underwater, calculate a bounding box that also contains the water plane CBoundingBoxAligned bounds = patch->GetWorldBounds(); Index: ps/trunk/source/graphics/HFTracer.h =================================================================== --- ps/trunk/source/graphics/HFTracer.h +++ ps/trunk/source/graphics/HFTracer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -32,7 +32,7 @@ { public: // constructor; setup data - CHFTracer(CTerrain *pTerrain); + CHFTracer(CTerrain& terrain); // intersect ray with this heightfield; return true if intersection // occurs (and fill in grid coordinates and point of intersection), or false otherwise @@ -60,7 +60,7 @@ bool CellIntersect(int cx, int cz, const CVector3D& origin, const CVector3D& dir, float& dist) const; // The terrain we're operating on - CTerrain *m_pTerrain; + CTerrain& m_Terrain; // the heightfield were tracing const u16* m_Heightfield; // size of the heightfield Index: ps/trunk/source/graphics/HFTracer.cpp =================================================================== --- ps/trunk/source/graphics/HFTracer.cpp +++ ps/trunk/source/graphics/HFTracer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -41,10 +41,10 @@ /////////////////////////////////////////////////////////////////////////////// // CHFTracer constructor -CHFTracer::CHFTracer(CTerrain *pTerrain): - m_pTerrain(pTerrain), - m_Heightfield(m_pTerrain->GetHeightMap()), - m_MapSize(m_pTerrain->GetVerticesPerSide()), +CHFTracer::CHFTracer(CTerrain& terrain): + m_Terrain(terrain), + m_Heightfield(m_Terrain.GetHeightMap()), + m_MapSize(m_Terrain.GetVerticesPerSide()), m_CellSize((float)TERRAIN_TILE_SIZE), m_HeightScale(HEIGHT_SCALE) { @@ -109,10 +109,10 @@ // get vertices for this cell CVector3D vpos[4]; - m_pTerrain->CalcPosition(cx,cz,vpos[0]); - m_pTerrain->CalcPosition(cx+1,cz,vpos[1]); - m_pTerrain->CalcPosition(cx+1,cz+1,vpos[2]); - m_pTerrain->CalcPosition(cx,cz+1,vpos[3]); + m_Terrain.CalcPosition(cx,cz,vpos[0]); + m_Terrain.CalcPosition(cx+1,cz,vpos[1]); + m_Terrain.CalcPosition(cx+1,cz+1,vpos[2]); + m_Terrain.CalcPosition(cx,cz+1,vpos[3]); dist=1.0e30f; if (RayTriIntersect(vpos[0],vpos[1],vpos[2],origin,dir,dist)) { Index: ps/trunk/source/graphics/MiniMapTexture.h =================================================================== --- ps/trunk/source/graphics/MiniMapTexture.h +++ ps/trunk/source/graphics/MiniMapTexture.h @@ -78,11 +78,11 @@ private: void CreateTextures( Renderer::Backend::IDeviceCommandContext* deviceCommandContext, - const CTerrain* terrain); + const CTerrain& terrain); void DestroyTextures(); void RebuildTerrainTexture( Renderer::Backend::IDeviceCommandContext* deviceCommandContext, - const CTerrain* terrain); + const CTerrain& terrain); void RenderFinalTexture( Renderer::Backend::IDeviceCommandContext* deviceCommandContext, CLOSTexture& losTexture, CTerritoryTexture& territoryTexture); Index: ps/trunk/source/graphics/MiniMapTexture.cpp =================================================================== --- ps/trunk/source/graphics/MiniMapTexture.cpp +++ ps/trunk/source/graphics/MiniMapTexture.cpp @@ -356,10 +356,7 @@ Renderer::Backend::IDeviceCommandContext* deviceCommandContext, CLOSTexture& losTexture, CTerritoryTexture& territoryTexture) { - const CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); - if (!terrain) - return; - + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); if (!m_TerrainTexture) CreateTextures(deviceCommandContext, terrain); @@ -370,11 +367,11 @@ } void CMiniMapTexture::CreateTextures( - Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTerrain* terrain) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTerrain& terrain) { DestroyTextures(); - m_MapSize = terrain->GetVerticesPerSide(); + m_MapSize = terrain.GetVerticesPerSide(); const size_t textureSize = round_up_to_pow2(static_cast(m_MapSize)); const Renderer::Backend::Sampler::Desc defaultSamplerDesc = @@ -428,7 +425,7 @@ void CMiniMapTexture::RebuildTerrainTexture( Renderer::Backend::IDeviceCommandContext* deviceCommandContext, - const CTerrain* terrain) + const CTerrain& terrain) { const u32 x = 0; const u32 y = 0; @@ -443,10 +440,11 @@ u32* dataPtr = m_TerrainData.get() + ((y + j) * width) + x; for (u32 i = 0; i < width; ++i) { - const float avgHeight = ( terrain->GetVertexGroundLevel((int)i, (int)j) - + terrain->GetVertexGroundLevel((int)i+1, (int)j) - + terrain->GetVertexGroundLevel((int)i, (int)j+1) - + terrain->GetVertexGroundLevel((int)i+1, (int)j+1) + const float avgHeight = ( + terrain.GetVertexGroundLevel(static_cast(i), static_cast(j)) + + terrain.GetVertexGroundLevel(static_cast(i+1), static_cast(j)) + + terrain.GetVertexGroundLevel(static_cast(i), static_cast(j+1)) + + terrain.GetVertexGroundLevel(static_cast(i+1), static_cast(j+1)) ) / 4.0f; if (avgHeight < m_WaterHeight && avgHeight > m_WaterHeight - m_ShallowPassageHeight) @@ -461,12 +459,13 @@ } else { - int hmap = ((int)terrain->GetHeightMap()[(y + j) * m_MapSize + x + i]) >> 8; + const int hmap = + static_cast(terrain.GetHeightMap()[(y + j) * m_MapSize + x + i]) >> 8; int val = (hmap / 3) + 170; u32 color = 0xFFFFFFFF; - CMiniPatch* mp = terrain->GetTile(x + i, y + j); + CMiniPatch* const mp = terrain.GetTile(x + i, y + j); if (mp) { CTerrainTextureEntry* tex = mp->GetTextureEntry(); Index: ps/trunk/source/graphics/scripting/JSInterface_GameView.cpp =================================================================== --- ps/trunk/source/graphics/scripting/JSInterface_GameView.cpp +++ ps/trunk/source/graphics/scripting/JSInterface_GameView.cpp @@ -118,15 +118,15 @@ */ void CameraMoveTo(entity_pos_t x, entity_pos_t z) { - if (!g_Game || !g_Game->GetWorld() || !g_Game->GetView() || !g_Game->GetWorld()->GetTerrain()) + if (!g_Game || !g_Game->GetWorld() || !g_Game->GetView()) return; - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); CVector3D target; target.X = x.ToFloat(); target.Z = z.ToFloat(); - target.Y = terrain->GetExactGroundLevel(target.X, target.Z); + target.Y = terrain.GetExactGroundLevel(target.X, target.Z); g_Game->GetView()->MoveCameraTarget(target); } Index: ps/trunk/source/gui/ObjectTypes/CMiniMap.cpp =================================================================== --- ps/trunk/source/gui/ObjectTypes/CMiniMap.cpp +++ ps/trunk/source/gui/ObjectTypes/CMiniMap.cpp @@ -211,11 +211,11 @@ void CMiniMap::SetCameraPositionFromMousePosition() { - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); CVector3D target; GetMouseWorldCoordinates(target.X, target.Z); - target.Y = terrain->GetExactGroundLevel(target.X, target.Z); + target.Y = terrain.GetExactGroundLevel(target.X, target.Z); g_Game->GetView()->MoveCameraTarget(target); } @@ -354,8 +354,8 @@ ENSURE(cmpRangeManager); // Set our globals in case they hadn't been set before - const CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); - m_MapSize = terrain->GetVerticesPerSide(); + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); + m_MapSize = terrain.GetVerticesPerSide(); m_MapScale = (cmpRangeManager->GetLosCircular() ? 1.f : 1.414f); // Draw the main textured quad Index: ps/trunk/source/ps/Game.cpp =================================================================== --- ps/trunk/source/ps/Game.cpp +++ ps/trunk/source/ps/Game.cpp @@ -69,7 +69,7 @@ **/ CGame::CGame(bool replayLog): m_World(new CWorld(this)), - m_Simulation2(new CSimulation2(&m_World->GetUnitManager(), g_ScriptContext, m_World->GetTerrain())), + m_Simulation2(new CSimulation2(&m_World->GetUnitManager(), g_ScriptContext, &m_World->GetTerrain())), // TODO: we need to remove that global dependency. Maybe the game view // should be created outside only if needed. m_GameView(CRenderer::IsInitialised() ? new CGameView(g_VideoMode.GetBackendDevice(), this) : nullptr), Index: ps/trunk/source/ps/World.h =================================================================== --- ps/trunk/source/ps/World.h +++ ps/trunk/source/ps/World.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -84,20 +84,24 @@ int DeleteMapReader(); /** - * Get the pointer to the terrain object. + * Get a reference to the terrain object. * - * @return CTerrain * the value of m_Terrain. + * @return CTerrain& dereferenced m_Terrain. **/ - inline CTerrain *GetTerrain() - { return m_Terrain; } + CTerrain& GetTerrain() + { + return *m_Terrain; + } /** * Get a reference to the unit manager object. * - * @return CUnitManager & dereferenced m_UnitManager. + * @return CUnitManager& dereferenced m_UnitManager. **/ - inline CUnitManager &GetUnitManager() - { return *m_UnitManager; } + CUnitManager& GetUnitManager() + { + return *m_UnitManager; + } }; // rationale: see definition. Index: ps/trunk/source/ps/scripting/JSInterface_Game.cpp =================================================================== --- ps/trunk/source/ps/scripting/JSInterface_Game.cpp +++ ps/trunk/source/ps/scripting/JSInterface_Game.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -171,7 +171,7 @@ void DumpTerrainMipmap() { VfsPath filename(L"screenshots/terrainmipmap.png"); - g_Game->GetWorld()->GetTerrain()->GetHeightMipmap().DumpToDisk(filename); + g_Game->GetWorld()->GetTerrain().GetHeightMipmap().DumpToDisk(filename); OsPath realPath; g_VFS->GetRealPath(filename, realPath); LOGMESSAGERENDER("Terrain mipmap written to '%s'", realPath.string8()); Index: ps/trunk/source/renderer/TerrainOverlay.cpp =================================================================== --- ps/trunk/source/renderer/TerrainOverlay.cpp +++ ps/trunk/source/renderer/TerrainOverlay.cpp @@ -335,10 +335,10 @@ void TerrainTextureOverlay::RenderAfterWater( Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) { - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); - ssize_t w = (ssize_t)(terrain->GetTilesPerSide() * m_TexelsPerTile); - ssize_t h = (ssize_t)(terrain->GetTilesPerSide() * m_TexelsPerTile); + const ssize_t w = static_cast(terrain.GetTilesPerSide() * m_TexelsPerTile); + const ssize_t h = static_cast(terrain.GetTilesPerSide() * m_TexelsPerTile); const uint32_t requiredWidth = round_up_to_pow2(w); const uint32_t requiredHeight = round_up_to_pow2(h); Index: ps/trunk/source/renderer/WaterManager.cpp =================================================================== --- ps/trunk/source/renderer/WaterManager.cpp +++ ps/trunk/source/renderer/WaterManager.cpp @@ -469,8 +469,8 @@ // Calculate our binary heightmap from the terrain heightmap. void WaterManager::RecomputeDistanceHeightmap() { - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); - if (!terrain || !terrain->GetHeightMap()) + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); + if (!terrain.GetHeightMap()) return; size_t SideSize = m_MapSize; @@ -487,7 +487,7 @@ // Create a manhattan-distance heightmap. // This could be refined to only be done near the coast itself, but it's probably not necessary. - u16* heightmap = terrain->GetHeightMap(); + const u16* const heightmap = terrain.GetHeightMap(); ComputeDirection(m_DistanceHeightmap.get(), heightmap, m_WaterHeight, SideSize, maxLevel); ComputeDirection(m_DistanceHeightmap.get(), heightmap, m_WaterHeight, SideSize, maxLevel); @@ -499,8 +499,8 @@ if (m_MapSize == 0) return; - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); - if (!terrain || !terrain->GetHeightMap()) + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); + if (!terrain.GetHeightMap()) return; m_ShoreWaves.clear(); @@ -702,15 +702,19 @@ break; } - if (terrain->GetExactGroundLevel(pos.X+perp.X*1.5f, pos.Y+perp.Y*1.5f) > m_WaterHeight) + if (terrain.GetExactGroundLevel(pos.X+perp.X*1.5f, pos.Y+perp.Y*1.5f) + > m_WaterHeight) sign = -1; - avgDepth += terrain->GetExactGroundLevel(pos.X+sign*perp.X*20.0f, pos.Y+sign*perp.Y*20.0f) - m_WaterHeight; + avgDepth += terrain.GetExactGroundLevel(pos.X+sign*perp.X*20.0f, + pos.Y+sign*perp.Y*20.0f) - m_WaterHeight; float localOutmost = -2.0f; while (localOutmost < 0.0f) { - float depth = terrain->GetExactGroundLevel(pos.X+sign*perp.X*localOutmost, pos.Y+sign*perp.Y*localOutmost) - m_WaterHeight; + const float depth = terrain.GetExactGroundLevel( + pos.X+sign*perp.X*localOutmost, + pos.Y+sign*perp.Y*localOutmost) - m_WaterHeight; if (depth < 0.0f || depth > 0.6f) localOutmost += 0.2f; else @@ -811,27 +815,31 @@ for (size_t t = 0; t < 9; ++t) { - float terrHeight = 0.05f + terrain->GetExactGroundLevel(pos.X+sign*perp.X*(perpT1[t]+outmost), + const float terrHeight = 0.05f + terrain.GetExactGroundLevel( + pos.X+sign*perp.X*(perpT1[t]+outmost), pos.Y+sign*perp.Y*(perpT1[t]+outmost)); point[t].m_BasePosition = CVector3D(pos.X+sign*perp.X*(perpT1[t]+outmost), baseHeight + heightT1[t]*sideNess + std::max(m_WaterHeight,terrHeight), pos.Y+sign*perp.Y*(perpT1[t]+outmost)); } for (size_t t = 0; t < 9; ++t) { - float terrHeight = 0.05f + terrain->GetExactGroundLevel(pos.X+sign*perp.X*(perpT2[t]+outmost), + const float terrHeight = 0.05f + terrain.GetExactGroundLevel( + pos.X+sign*perp.X*(perpT2[t]+outmost), pos.Y+sign*perp.Y*(perpT2[t]+outmost)); point[t].m_ApexPosition = CVector3D(pos.X+sign*perp.X*(perpT2[t]+outmost), baseHeight + heightT1[t]*sideNess + std::max(m_WaterHeight,terrHeight), pos.Y+sign*perp.Y*(perpT2[t]+outmost)); } for (size_t t = 0; t < 9; ++t) { - float terrHeight = 0.05f + terrain->GetExactGroundLevel(pos.X+sign*perp.X*(perpT3[t]+outmost*sideNess), + const float terrHeight = 0.05f + terrain.GetExactGroundLevel( + pos.X+sign*perp.X*(perpT3[t]+outmost*sideNess), pos.Y+sign*perp.Y*(perpT3[t]+outmost*sideNess)); point[t].m_SplashPosition = CVector3D(pos.X+sign*perp.X*(perpT3[t]+outmost*sideNess), baseHeight + heightT2[t]*sideNess + std::max(m_WaterHeight,terrHeight), pos.Y+sign*perp.Y*(perpT3[t]+outmost*sideNess)); } for (size_t t = 0; t < 9; ++t) { - float terrHeight = 0.05f + terrain->GetExactGroundLevel(pos.X+sign*perp.X*(perpT4[t]+outmost), + const float terrHeight = 0.05f + terrain.GetExactGroundLevel( + pos.X+sign*perp.X*(perpT4[t]+outmost), pos.Y+sign*perp.Y*(perpT4[t]+outmost)); point[t].m_RetreatPosition = CVector3D(pos.X+sign*perp.X*(perpT4[t]+outmost), baseHeight + heightT3[t]*sideNess + std::max(m_WaterHeight,terrHeight), pos.Y+sign*perp.Y*(perpT4[t]+outmost)); @@ -970,8 +978,8 @@ if (!m_WindStrength) m_WindStrength = std::make_unique(m_MapSize * m_MapSize); - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); - if (!terrain || !terrain->GetHeightMap()) + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); + if (!terrain.GetHeightMap()) return; CVector2D windDir = CVector2D(cos(m_WindAngle), sin(m_WindAngle)); @@ -1042,7 +1050,7 @@ { // Starting velocity is 1.0 unless in shallow water. m_WindStrength[point.Y * m_MapSize + point.X] = 1.f; - float depth = m_WaterHeight - terrain->GetVertexGroundLevel(point.X, point.Y); + const float depth = m_WaterHeight - terrain.GetVertexGroundLevel(point.X, point.Y); if (depth > 0.f && depth < 2.f) m_WindStrength[point.Y * m_MapSize + point.X] = depth / 2.f; point.windStrength = m_WindStrength[point.Y * m_MapSize + point.X]; @@ -1056,8 +1064,9 @@ // Adjust speed based on height difference, a positive height difference slowly increases speed (simulate venturi effect) // and a lower height reduces speed (wind protection from hills/...) - float heightDiff = std::max(m_WaterHeight, terrain->GetVertexGroundLevel(point.X + movement[step].first, point.Y + movement[step].second)) - - std::max(m_WaterHeight, terrain->GetVertexGroundLevel(point.X, point.Y)); + const float heightDiff = std::max(m_WaterHeight, terrain.GetVertexGroundLevel( + point.X + movement[step].first, point.Y + movement[step].second)) - + std::max(m_WaterHeight, terrain.GetVertexGroundLevel(point.X, point.Y)); if (heightDiff > 0.f) point.windStrength = std::min(2.f, point.windStrength + std::min(4.f, heightDiff) / 40.f); else Index: ps/trunk/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp +++ ps/trunk/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -44,12 +44,12 @@ CVector3D focus = g_Game->GetView()->GetCamera()->GetFocus(); CVector3D target; - if (!g_Game->GetWorld()->GetTerrain()->IsOnMap(focus.X, focus.Z)) + if (!g_Game->GetWorld()->GetTerrain().IsOnMap(focus.X, focus.Z)) { target = CVector3D( - g_Game->GetWorld()->GetTerrain()->GetMaxX()/2.f, + g_Game->GetWorld()->GetTerrain().GetMaxX()/2.f, focus.Y, - g_Game->GetWorld()->GetTerrain()->GetMaxZ()/2.f); + g_Game->GetWorld()->GetTerrain().GetMaxZ()/2.f); } else { Index: ps/trunk/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp +++ ps/trunk/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp @@ -41,8 +41,8 @@ public: void Init() { - m_Heightmap = g_Game->GetWorld()->GetTerrain()->GetHeightMap(); - m_VertsPerSide = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); + m_Heightmap = g_Game->GetWorld()->GetTerrain().GetHeightMap(); + m_VertsPerSide = g_Game->GetWorld()->GetTerrain().GetVerticesPerSide(); } void RaiseVertex(ssize_t x, ssize_t y, int amount) @@ -111,7 +111,7 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); + g_Game->GetWorld()->GetTerrain().MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); g_Game->GetWorld()->GetUnitManager().MakeTerrainDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) @@ -194,7 +194,7 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); + g_Game->GetWorld()->GetTerrain().MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); g_Game->GetWorld()->GetUnitManager().MakeTerrainDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) @@ -307,7 +307,7 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); + g_Game->GetWorld()->GetTerrain().MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); g_Game->GetWorld()->GetUnitManager().MakeTerrainDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) @@ -382,7 +382,7 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); + g_Game->GetWorld()->GetTerrain().MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); g_Game->GetWorld()->GetUnitManager().MakeTerrainDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) Index: ps/trunk/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ ps/trunk/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -202,14 +202,14 @@ // resize terrain to heightmap size // Notice that the number of tiles/pixels per side of the heightmap image is // one less than the number of vertices per side of the heightmap. - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); const ssize_t newSize = (sqrt(heightmap_source.size()) - 1) / PATCH_SIZE; - const ssize_t offset = (newSize - terrain->GetPatchesPerSide()) / 2; - terrain->ResizeAndOffset(newSize, offset, offset); + const ssize_t offset = (newSize - terrain.GetPatchesPerSide()) / 2; + terrain.ResizeAndOffset(newSize, offset, offset); // copy heightmap data into map - u16* heightmap = g_Game->GetWorld()->GetTerrain()->GetHeightMap(); - ENSURE(heightmap_source.size() == (std::size_t) SQR(g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide())); + u16* const heightmap = g_Game->GetWorld()->GetTerrain().GetHeightMap(); + ENSURE(heightmap_source.size() == (std::size_t) SQR(g_Game->GetWorld()->GetTerrain().GetVerticesPerSide())); std::copy(heightmap_source.begin(), heightmap_source.end(), heightmap); // update simulation @@ -225,7 +225,7 @@ CMapWriter writer; VfsPath pathname = VfsPath(*msg->filename).ChangeExtension(L".pmp"); writer.SaveMap(pathname, - g_Game->GetWorld()->GetTerrain(), + &g_Game->GetWorld()->GetTerrain(), &g_Renderer.GetSceneRenderer().GetWaterManager(), &g_Renderer.GetSceneRenderer().GetSkyManager(), &g_LightEnv, g_Game->GetView()->GetCamera(), g_Game->GetView()->GetCinema(), &g_Renderer.GetPostprocManager(), @@ -287,8 +287,8 @@ { // TODO: remove the code duplication of the rasterization algorithm, using // CMinimap version. - const CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); - const ssize_t dimension = terrain->GetVerticesPerSide() - 1; + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); + const ssize_t dimension = terrain.GetVerticesPerSide() - 1; const ssize_t bpp = 24; const ssize_t imageDataSize = dimension * dimension * (bpp / 8); @@ -306,10 +306,10 @@ ssize_t position = 3 * (h - j - 1) * dimension; for (ssize_t i = 0; i < w; ++i) { - float avgHeight = (terrain->GetVertexGroundLevel(i, j) - + terrain->GetVertexGroundLevel(i + 1, j) - + terrain->GetVertexGroundLevel(i, j + 1) - + terrain->GetVertexGroundLevel(i + 1, j + 1) + const float avgHeight = (terrain.GetVertexGroundLevel(i, j) + + terrain.GetVertexGroundLevel(i + 1, j) + + terrain.GetVertexGroundLevel(i, j + 1) + + terrain.GetVertexGroundLevel(i + 1, j + 1) ) / 4.0f; if (avgHeight < waterHeight && avgHeight > waterHeight - shallowPassageHeight) @@ -329,10 +329,10 @@ else { u32 color = std::numeric_limits::max(); - u32 hmap = static_cast(terrain->GetHeightMap()[j * dimension + i]) >> 8; + const u32 hmap = static_cast(terrain.GetHeightMap()[j * dimension + i]) >> 8; float scale = hmap / 3.0f + 170.0f / 255.0f; - CMiniPatch* mp = terrain->GetTile(i, j); + CMiniPatch* const mp = terrain.GetTile(i, j); if (mp) { CTerrainTextureEntry* tex = mp->GetTextureEntry(); @@ -359,7 +359,7 @@ QUERYHANDLER(GetCurrentMapSize) { - msg->size = g_Game->GetWorld()->GetTerrain()->GetTilesPerSide(); + msg->size = g_Game->GetWorld()->GetTerrain().GetTilesPerSide(); } BEGIN_COMMAND(ResizeMap) @@ -420,8 +420,8 @@ void ResizeTerrain(ssize_t patches, int offsetX, int offsetY) { - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); - terrain->ResizeAndOffset(patches, -offsetX, -offsetY); + CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); + terrain.ResizeAndOffset(patches, -offsetX, -offsetY); } void DeleteObjects(const std::vector& deletedObjects) Index: ps/trunk/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ ps/trunk/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -381,7 +381,7 @@ // Use 'Clamp' with a value slightly less than the width, so that converting // to integer (rounding towards zero) will put it on the tile inside the edge // instead of just outside - float mapWidth = (g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()-1)*TERRAIN_TILE_SIZE; + const float mapWidth = (g_Game->GetWorld()->GetTerrain().GetVerticesPerSide()-1)*TERRAIN_TILE_SIZE; float delta = 1e-6f; // fraction of map width - must be > FLT_EPSILON float xOnMap = Clamp(vec.X, 0.f, mapWidth * (1.f - delta)); @@ -392,7 +392,7 @@ { vec.X = xOnMap; vec.Z = zOnMap; - vec.Y = g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(xOnMap, zOnMap); + vec.Y = g_Game->GetWorld()->GetTerrain().GetExactGroundLevel(xOnMap, zOnMap); } return vec; Index: ps/trunk/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp +++ ps/trunk/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp @@ -205,8 +205,8 @@ g_CurrentBrush.m_Centre = msg->pos->GetWorldSpace(); g_CurrentBrush.GetCentre(x, y); - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); - CMiniPatch* tile = terrain->GetTile(x, y); + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); + CMiniPatch* const tile = terrain.GetTile(x, y); if (tile) { CTerrainTextureEntry* tex = tile->GetTextureEntry(); @@ -244,8 +244,8 @@ public: void Init() { - m_Terrain = g_Game->GetWorld()->GetTerrain(); - m_VertsPerSide = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); + m_Terrain = &g_Game->GetWorld()->GetTerrain(); + m_VertsPerSide = m_Terrain->GetVerticesPerSide(); } void UpdatePriority(ssize_t x, ssize_t y, CTerrainTextureEntry* tex, ssize_t priorityScale, ssize_t& priority) @@ -325,7 +325,8 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES); + g_Game->GetWorld()->GetTerrain().MakeDirty(m_i0, m_j0, m_i1, m_j1, + RENDERDATA_UPDATE_INDICES); } void Do() @@ -411,7 +412,8 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES); + g_Game->GetWorld()->GetTerrain().MakeDirty(m_i0, m_j0, m_i1, m_j1, + RENDERDATA_UPDATE_INDICES); } void Do() @@ -487,7 +489,8 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES); + g_Game->GetWorld()->GetTerrain().MakeDirty(m_i0, m_j0, m_i1, m_j1, + RENDERDATA_UPDATE_INDICES); } void Do()