Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectTypes/CMiniMap.cpp
Show All 20 Lines | |||||
#include "graphics/GameView.h" | #include "graphics/GameView.h" | ||||
#include "graphics/LOSTexture.h" | #include "graphics/LOSTexture.h" | ||||
#include "graphics/MiniPatch.h" | #include "graphics/MiniPatch.h" | ||||
#include "graphics/Terrain.h" | #include "graphics/Terrain.h" | ||||
#include "graphics/TerrainTextureEntry.h" | #include "graphics/TerrainTextureEntry.h" | ||||
#include "graphics/TerrainTextureManager.h" | #include "graphics/TerrainTextureManager.h" | ||||
#include "graphics/TerritoryTexture.h" | #include "graphics/TerritoryTexture.h" | ||||
#include "graphics/WaterManager.h" | |||||
#include "gui/CGUI.h" | #include "gui/CGUI.h" | ||||
#include "gui/GUIManager.h" | #include "gui/GUIManager.h" | ||||
#include "gui/GUIMatrix.h" | #include "gui/GUIMatrix.h" | ||||
#include "lib/bits.h" | #include "lib/bits.h" | ||||
#include "lib/external_libraries/libsdl.h" | #include "lib/external_libraries/libsdl.h" | ||||
#include "lib/ogl.h" | #include "lib/ogl.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "ps/ConfigDB.h" | #include "ps/ConfigDB.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/GameSetup/Config.h" | #include "ps/GameSetup/Config.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/RenderingOptions.h" | #include "renderer/RenderingOptions.h" | ||||
#include "renderer/WaterManager.h" | |||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/components/ICmpMinimap.h" | #include "simulation2/components/ICmpMinimap.h" | ||||
#include "simulation2/components/ICmpRangeManager.h" | #include "simulation2/components/ICmpRangeManager.h" | ||||
#include "simulation2/helpers/Los.h" | #include "simulation2/helpers/Los.h" | ||||
#include "simulation2/system/ParamNode.h" | #include "simulation2/system/ParamNode.h" | ||||
#include <cmath> | #include <cmath> | ||||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
// This sets up and draws the rectangle on the minimap | // This sets up and draws the rectangle on the minimap | ||||
// which represents the view of the camera in the world. | // which represents the view of the camera in the world. | ||||
void CMiniMap::DrawViewRect(CMatrix3D transform) const | void CMiniMap::DrawViewRect(CMatrix3D transform) const | ||||
{ | { | ||||
// Compute the camera frustum intersected with a fixed-height plane. | // Compute the camera frustum intersected with a fixed-height plane. | ||||
// Use the water height as a fixed base height, which should be the lowest we can go | // Use the water height as a fixed base height, which should be the lowest we can go | ||||
float h = g_Renderer.GetWaterManager()->m_WaterHeight; | float h = g_Game->GetView()->GetWaterManager().GetWaterHeight(); | ||||
const float width = m_CachedActualSize.GetWidth(); | const float width = m_CachedActualSize.GetWidth(); | ||||
const float height = m_CachedActualSize.GetHeight(); | const float height = m_CachedActualSize.GetHeight(); | ||||
const float invTileMapSize = 1.0f / float(TERRAIN_TILE_SIZE * m_MapSize); | const float invTileMapSize = 1.0f / float(TERRAIN_TILE_SIZE * m_MapSize); | ||||
CVector3D hitPt[4]; | CVector3D hitPt[4]; | ||||
hitPt[0] = m_Camera->GetWorldCoordinates(0, g_Renderer.GetHeight(), h); | hitPt[0] = m_Camera->GetWorldCoordinates(0, g_Renderer.GetHeight(), h); | ||||
hitPt[1] = m_Camera->GetWorldCoordinates(g_Renderer.GetWidth(), g_Renderer.GetHeight(), h); | hitPt[1] = m_Camera->GetWorldCoordinates(g_Renderer.GetWidth(), g_Renderer.GetHeight(), h); | ||||
hitPt[2] = m_Camera->GetWorldCoordinates(g_Renderer.GetWidth(), 0, h); | hitPt[2] = m_Camera->GetWorldCoordinates(g_Renderer.GetWidth(), 0, h); | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | void CMiniMap::Draw() | ||||
// we can get away with infrequent updates; this is slow) | // we can get away with infrequent updates; this is slow) | ||||
// TODO: Update all but camera at same speed as simulation | // TODO: Update all but camera at same speed as simulation | ||||
static double last_time; | static double last_time; | ||||
const double cur_time = timer_Time(); | const double cur_time = timer_Time(); | ||||
const bool doUpdate = cur_time - last_time > 0.5; | const bool doUpdate = cur_time - last_time > 0.5; | ||||
if (doUpdate) | if (doUpdate) | ||||
{ | { | ||||
last_time = cur_time; | last_time = cur_time; | ||||
if (m_TerrainDirty || m_WaterHeight != g_Renderer.GetWaterManager()->m_WaterHeight) | if (m_TerrainDirty || m_WaterHeight != g_Game->GetView()->GetWaterManager().GetWaterHeight()) | ||||
RebuildTerrainTexture(); | RebuildTerrainTexture(); | ||||
} | } | ||||
const float x = m_CachedActualSize.left, y = m_CachedActualSize.bottom; | const float x = m_CachedActualSize.left, y = m_CachedActualSize.bottom; | ||||
const float x2 = m_CachedActualSize.right, y2 = m_CachedActualSize.top; | const float x2 = m_CachedActualSize.right, y2 = m_CachedActualSize.top; | ||||
const float z = GetBufferedZ(); | const float z = GetBufferedZ(); | ||||
const float texCoordMax = (float)(m_MapSize - 1) / (float)m_TextureSize; | const float texCoordMax = (float)(m_MapSize - 1) / (float)m_TextureSize; | ||||
const float angle = GetAngle(); | const float angle = GetAngle(); | ||||
▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | |||||
void CMiniMap::RebuildTerrainTexture() | void CMiniMap::RebuildTerrainTexture() | ||||
{ | { | ||||
u32 x = 0; | u32 x = 0; | ||||
u32 y = 0; | u32 y = 0; | ||||
u32 w = m_MapSize - 1; | u32 w = m_MapSize - 1; | ||||
u32 h = m_MapSize - 1; | u32 h = m_MapSize - 1; | ||||
m_WaterHeight = g_Renderer.GetWaterManager()->m_WaterHeight; | m_WaterHeight = g_Game->GetView()->GetWaterManager().GetWaterHeight(); | ||||
m_TerrainDirty = false; | m_TerrainDirty = false; | ||||
for (u32 j = 0; j < h; ++j) | for (u32 j = 0; j < h; ++j) | ||||
{ | { | ||||
u32* dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x; | u32* dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x; | ||||
for (u32 i = 0; i < w; ++i) | for (u32 i = 0; i < w; ++i) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator