2019-07-22 21:35:14 +02:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2004-10-08 03:10:14 +02:00
|
|
|
#include "precompiled.h"
|
2004-11-07 22:30:47 +01:00
|
|
|
|
2005-08-01 01:54:19 +02:00
|
|
|
#include <math.h>
|
2006-06-09 18:44:16 +02:00
|
|
|
|
2006-12-15 17:09:30 +01:00
|
|
|
#include "MiniMap.h"
|
|
|
|
|
2006-06-09 18:44:16 +02:00
|
|
|
#include "graphics/GameView.h"
|
2011-02-03 02:12:24 +01:00
|
|
|
#include "graphics/LOSTexture.h"
|
2006-06-09 18:44:16 +02:00
|
|
|
#include "graphics/MiniPatch.h"
|
|
|
|
#include "graphics/Terrain.h"
|
2010-09-04 23:26:52 +02:00
|
|
|
#include "graphics/TerrainTextureEntry.h"
|
|
|
|
#include "graphics/TerrainTextureManager.h"
|
2011-07-20 21:48:06 +02:00
|
|
|
#include "graphics/TerritoryTexture.h"
|
2019-09-18 22:51:45 +02:00
|
|
|
#include "gui/CGUI.h"
|
2014-01-04 11:14:53 +01:00
|
|
|
#include "gui/GUIManager.h"
|
2019-08-04 05:52:00 +02:00
|
|
|
#include "gui/GUIMatrix.h"
|
2007-05-09 23:01:11 +02:00
|
|
|
#include "lib/bits.h"
|
2015-08-21 19:08:41 +02:00
|
|
|
#include "lib/external_libraries/libsdl.h"
|
|
|
|
#include "lib/ogl.h"
|
2007-01-21 04:33:52 +01:00
|
|
|
#include "lib/timer.h"
|
2013-10-06 06:49:38 +02:00
|
|
|
#include "ps/ConfigDB.h"
|
2016-01-13 01:20:22 +01:00
|
|
|
#include "ps/Filesystem.h"
|
2006-06-09 18:44:16 +02:00
|
|
|
#include "ps/Game.h"
|
2016-08-02 18:58:30 +02:00
|
|
|
#include "ps/GameSetup/Config.h"
|
2006-06-09 18:44:16 +02:00
|
|
|
#include "ps/Profile.h"
|
2007-01-13 23:44:42 +01:00
|
|
|
#include "ps/World.h"
|
2015-06-07 23:56:52 +02:00
|
|
|
#include "ps/XML/Xeromyces.h"
|
2006-06-09 18:44:16 +02:00
|
|
|
#include "renderer/Renderer.h"
|
2019-08-04 10:28:30 +02:00
|
|
|
#include "renderer/RenderingOptions.h"
|
2006-06-09 18:44:16 +02:00
|
|
|
#include "renderer/WaterManager.h"
|
2010-09-11 21:49:21 +02:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2010-04-23 20:36:48 +02:00
|
|
|
#include "simulation2/Simulation2.h"
|
|
|
|
#include "simulation2/components/ICmpMinimap.h"
|
2012-08-04 20:52:02 +02:00
|
|
|
#include "simulation2/system/ParamNode.h"
|
2005-10-20 17:27:39 +02:00
|
|
|
|
2018-05-08 11:24:16 +02:00
|
|
|
extern bool g_GameRestarted;
|
2005-10-19 05:02:51 +02:00
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
// Set max drawn entities to UINT16_MAX for now, which is more than enough
|
|
|
|
// TODO: we should be cleverer about drawing them to reduce clutter
|
|
|
|
const u16 MAX_ENTITIES_DRAWN = 65535;
|
|
|
|
|
2005-10-09 05:43:03 +02:00
|
|
|
static unsigned int ScaleColor(unsigned int color, float x)
|
2004-10-08 03:10:14 +02:00
|
|
|
{
|
2008-06-26 01:01:13 +02:00
|
|
|
unsigned int r = unsigned(float(color & 0xff) * x);
|
|
|
|
unsigned int g = unsigned(float((color>>8) & 0xff) * x);
|
|
|
|
unsigned int b = unsigned(float((color>>16) & 0xff) * x);
|
2013-11-12 02:11:08 +01:00
|
|
|
return (0xff000000 | b | g<<8 | r<<16);
|
2004-10-08 03:10:14 +02:00
|
|
|
}
|
|
|
|
|
2019-08-21 12:12:33 +02:00
|
|
|
CMiniMap::CMiniMap(CGUI& pGUI) :
|
2019-08-01 22:20:24 +02:00
|
|
|
IGUIObject(pGUI),
|
2013-06-06 02:10:58 +02:00
|
|
|
m_TerrainTexture(0), m_TerrainData(0), m_MapSize(0), m_Terrain(0), m_TerrainDirty(true), m_MapScale(1.f),
|
2013-10-06 06:49:38 +02:00
|
|
|
m_EntitiesDrawn(0), m_IndexArray(GL_STATIC_DRAW), m_VertexArray(GL_DYNAMIC_DRAW),
|
2017-04-17 00:13:32 +02:00
|
|
|
m_NextBlinkTime(0.0), m_PingDuration(25.0), m_BlinkState(false), m_WaterHeight(0.0)
|
2004-10-08 03:10:14 +02:00
|
|
|
{
|
2019-08-04 04:20:08 +02:00
|
|
|
AddSetting<CStrW>("tooltip");
|
|
|
|
AddSetting<CStr>("tooltip_style");
|
2006-01-21 12:07:25 +01:00
|
|
|
m_Clicking = false;
|
2012-05-04 19:44:28 +02:00
|
|
|
m_MouseHovering = false;
|
2014-07-14 19:15:22 +02:00
|
|
|
|
2015-06-07 23:56:52 +02:00
|
|
|
// Register Relax NG validator
|
|
|
|
CXeromyces::AddValidator(g_VFS, "pathfinder", "simulation/data/pathfinder.rng");
|
|
|
|
|
2012-08-04 20:52:02 +02:00
|
|
|
// Get the maximum height for unit passage in water.
|
|
|
|
CParamNode externalParamNode;
|
2015-06-07 23:56:52 +02:00
|
|
|
CParamNode::LoadXML(externalParamNode, L"simulation/data/pathfinder.xml", "pathfinder");
|
2012-08-04 20:52:02 +02:00
|
|
|
const CParamNode pathingSettings = externalParamNode.GetChild("Pathfinder").GetChild("PassabilityClasses");
|
|
|
|
if (pathingSettings.GetChild("default").IsOk() && pathingSettings.GetChild("default").GetChild("MaxWaterDepth").IsOk())
|
|
|
|
m_ShallowPassageHeight = pathingSettings.GetChild("default").GetChild("MaxWaterDepth").ToFloat();
|
|
|
|
else
|
|
|
|
m_ShallowPassageHeight = 0.0f;
|
2014-07-14 19:15:22 +02:00
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
m_AttributePos.type = GL_FLOAT;
|
|
|
|
m_AttributePos.elems = 2;
|
|
|
|
m_VertexArray.AddAttribute(&m_AttributePos);
|
2015-08-21 19:08:41 +02:00
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
m_AttributeColor.type = GL_UNSIGNED_BYTE;
|
|
|
|
m_AttributeColor.elems = 4;
|
|
|
|
m_VertexArray.AddAttribute(&m_AttributeColor);
|
2015-08-21 19:08:41 +02:00
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
m_VertexArray.SetNumVertices(MAX_ENTITIES_DRAWN);
|
|
|
|
m_VertexArray.Layout();
|
|
|
|
|
|
|
|
m_IndexArray.SetNumVertices(MAX_ENTITIES_DRAWN);
|
|
|
|
m_IndexArray.Layout();
|
|
|
|
VertexArrayIterator<u16> index = m_IndexArray.GetIterator();
|
|
|
|
for (u16 i = 0; i < MAX_ENTITIES_DRAWN; ++i)
|
|
|
|
*index++ = i;
|
|
|
|
m_IndexArray.Upload();
|
|
|
|
m_IndexArray.FreeBackingStore();
|
2014-07-14 19:15:22 +02:00
|
|
|
|
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
VertexArrayIterator<float[2]> attrPos = m_AttributePos.GetIterator<float[2]>();
|
|
|
|
VertexArrayIterator<u8[4]> attrColor = m_AttributeColor.GetIterator<u8[4]>();
|
2015-08-21 19:08:41 +02:00
|
|
|
for (u16 i = 0; i < MAX_ENTITIES_DRAWN; ++i)
|
2013-06-06 02:10:58 +02:00
|
|
|
{
|
|
|
|
(*attrColor)[0] = 0;
|
|
|
|
(*attrColor)[1] = 0;
|
|
|
|
(*attrColor)[2] = 0;
|
|
|
|
(*attrColor)[3] = 0;
|
|
|
|
++attrColor;
|
|
|
|
|
|
|
|
(*attrPos)[0] = -10000.0f;
|
|
|
|
(*attrPos)[1] = -10000.0f;
|
2014-07-14 19:15:22 +02:00
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
++attrPos;
|
2014-07-14 19:15:22 +02:00
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
}
|
|
|
|
m_VertexArray.Upload();
|
2013-10-06 06:49:38 +02:00
|
|
|
|
|
|
|
double blinkDuration = 1.0;
|
|
|
|
|
|
|
|
// Tests won't have config initialised
|
|
|
|
if (CConfigDB::IsInitialised())
|
|
|
|
{
|
2014-11-18 00:29:49 +01:00
|
|
|
CFG_GET_VAL("gui.session.minimap.pingduration", m_PingDuration);
|
|
|
|
CFG_GET_VAL("gui.session.minimap.blinkduration", blinkDuration);
|
2013-10-06 06:49:38 +02:00
|
|
|
}
|
|
|
|
m_HalfBlinkDuration = blinkDuration/2;
|
2004-10-08 03:10:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CMiniMap::~CMiniMap()
|
|
|
|
{
|
2005-05-13 03:15:53 +02:00
|
|
|
Destroy();
|
2004-10-08 03:10:14 +02:00
|
|
|
}
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
void CMiniMap::HandleMessage(SGUIMessage& Message)
|
2005-10-19 19:16:34 +02:00
|
|
|
{
|
2015-08-21 19:08:41 +02:00
|
|
|
switch (Message.type)
|
2005-10-19 19:16:34 +02:00
|
|
|
{
|
2005-10-20 17:27:39 +02:00
|
|
|
case GUIM_MOUSE_PRESS_LEFT:
|
2015-08-21 19:08:41 +02:00
|
|
|
if (m_MouseHovering)
|
2005-10-19 19:16:34 +02:00
|
|
|
{
|
2015-08-21 19:08:41 +02:00
|
|
|
SetCameraPos();
|
|
|
|
m_Clicking = true;
|
2005-10-19 19:16:34 +02:00
|
|
|
}
|
2015-08-21 19:08:41 +02:00
|
|
|
break;
|
2006-01-21 12:07:25 +01:00
|
|
|
case GUIM_MOUSE_RELEASE_LEFT:
|
2015-08-21 19:08:41 +02:00
|
|
|
if (m_MouseHovering && m_Clicking)
|
|
|
|
SetCameraPos();
|
|
|
|
m_Clicking = false;
|
|
|
|
break;
|
2008-07-29 08:56:38 +02:00
|
|
|
case GUIM_MOUSE_DBLCLICK_LEFT:
|
2015-08-21 19:08:41 +02:00
|
|
|
if (m_MouseHovering && m_Clicking)
|
|
|
|
SetCameraPos();
|
|
|
|
m_Clicking = false;
|
|
|
|
break;
|
2006-01-21 12:07:25 +01:00
|
|
|
case GUIM_MOUSE_ENTER:
|
2015-08-21 19:08:41 +02:00
|
|
|
m_MouseHovering = true;
|
|
|
|
break;
|
2006-01-21 12:07:25 +01:00
|
|
|
case GUIM_MOUSE_LEAVE:
|
2015-08-21 19:08:41 +02:00
|
|
|
m_Clicking = false;
|
|
|
|
m_MouseHovering = false;
|
|
|
|
break;
|
2006-01-21 12:07:25 +01:00
|
|
|
case GUIM_MOUSE_RELEASE_RIGHT:
|
2015-08-21 19:08:41 +02:00
|
|
|
CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 1);
|
|
|
|
break;
|
2006-01-21 12:07:25 +01:00
|
|
|
case GUIM_MOUSE_DBLCLICK_RIGHT:
|
2015-08-21 19:08:41 +02:00
|
|
|
CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 2);
|
|
|
|
break;
|
2006-01-21 12:07:25 +01:00
|
|
|
case GUIM_MOUSE_MOTION:
|
2015-08-21 19:08:41 +02:00
|
|
|
if (m_MouseHovering && m_Clicking)
|
|
|
|
SetCameraPos();
|
|
|
|
break;
|
2011-04-28 22:42:11 +02:00
|
|
|
case GUIM_MOUSE_WHEEL_DOWN:
|
|
|
|
case GUIM_MOUSE_WHEEL_UP:
|
|
|
|
Message.Skip();
|
|
|
|
break;
|
2005-10-20 17:27:39 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-08-21 19:08:41 +02:00
|
|
|
}
|
2005-10-19 19:16:34 +02:00
|
|
|
}
|
|
|
|
|
2019-08-23 01:51:10 +02:00
|
|
|
bool CMiniMap::IsMouseOver() const
|
2014-03-07 23:43:57 +01:00
|
|
|
{
|
|
|
|
// Get the mouse position.
|
2019-08-21 12:12:33 +02:00
|
|
|
const CPos& mousePos = m_pGUI.GetMousePos();
|
2014-03-07 23:43:57 +01:00
|
|
|
// Get the position of the center of the minimap.
|
|
|
|
CPos minimapCenter = CPos(m_CachedActualSize.left + m_CachedActualSize.GetWidth() / 2.0, m_CachedActualSize.bottom - m_CachedActualSize.GetHeight() / 2.0);
|
|
|
|
// Take the magnitude of the difference of the mouse position and minimap center.
|
|
|
|
double distFromCenter = sqrt(pow((mousePos.x - minimapCenter.x), 2) + pow((mousePos.y - minimapCenter.y), 2));
|
|
|
|
// If the distance is less then the radius of the minimap (half the width) the mouse is over the minimap.
|
|
|
|
if (distFromCenter < m_CachedActualSize.GetWidth() / 2.0)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-23 01:51:10 +02:00
|
|
|
void CMiniMap::GetMouseWorldCoordinates(float& x, float& z) const
|
2010-10-25 23:59:52 +02:00
|
|
|
{
|
|
|
|
// Determine X and Z according to proportion of mouse position and minimap
|
|
|
|
|
2019-08-21 12:12:33 +02:00
|
|
|
const CPos& mousePos = m_pGUI.GetMousePos();
|
2010-10-25 23:59:52 +02:00
|
|
|
|
|
|
|
float px = (mousePos.x - m_CachedActualSize.left) / m_CachedActualSize.GetWidth();
|
|
|
|
float py = (m_CachedActualSize.bottom - mousePos.y) / m_CachedActualSize.GetHeight();
|
|
|
|
|
|
|
|
float angle = GetAngle();
|
|
|
|
|
2011-05-27 05:04:59 +02:00
|
|
|
// Scale world coordinates for shrunken square map
|
2012-01-12 13:51:10 +01:00
|
|
|
x = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(px-0.5) - sin(angle)*(py-0.5)) + 0.5);
|
|
|
|
z = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(py-0.5) + sin(angle)*(px-0.5)) + 0.5);
|
2010-10-25 23:59:52 +02:00
|
|
|
}
|
|
|
|
|
2006-01-21 12:07:25 +01:00
|
|
|
void CMiniMap::SetCameraPos()
|
|
|
|
{
|
2010-08-13 15:26:29 +02:00
|
|
|
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
|
|
|
|
|
|
|
|
CVector3D target;
|
2010-10-25 23:59:52 +02:00
|
|
|
GetMouseWorldCoordinates(target.X, target.Z);
|
2010-08-13 15:26:29 +02:00
|
|
|
target.Y = terrain->GetExactGroundLevel(target.X, target.Z);
|
2011-12-10 08:07:04 +01:00
|
|
|
g_Game->GetView()->MoveCameraTarget(target);
|
2006-01-21 12:07:25 +01:00
|
|
|
}
|
2010-05-09 02:53:25 +02:00
|
|
|
|
2019-08-23 01:51:10 +02:00
|
|
|
float CMiniMap::GetAngle() const
|
2010-10-25 23:59:52 +02:00
|
|
|
{
|
2011-05-27 05:04:59 +02:00
|
|
|
CVector3D cameraIn = m_Camera->m_Orientation.GetIn();
|
|
|
|
return -atan2(cameraIn.X, cameraIn.Z);
|
2010-10-25 23:59:52 +02:00
|
|
|
}
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
void CMiniMap::FireWorldClickEvent(int UNUSED(button), int UNUSED(clicks))
|
2006-01-21 12:07:25 +01:00
|
|
|
{
|
2014-07-27 00:33:16 +02:00
|
|
|
JSContext* cx = g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext();
|
|
|
|
JSAutoRequest rq(cx);
|
2015-08-21 19:08:41 +02:00
|
|
|
|
2010-10-25 23:59:52 +02:00
|
|
|
float x, z;
|
|
|
|
GetMouseWorldCoordinates(x, z);
|
2010-09-11 21:49:21 +02:00
|
|
|
|
2014-07-27 00:33:16 +02:00
|
|
|
JS::RootedValue coords(cx);
|
2019-09-13 02:56:51 +02:00
|
|
|
ScriptInterface::CreateObject(cx, &coords, "x", x, "z", z);
|
2019-07-19 23:15:04 +02:00
|
|
|
|
|
|
|
JS::AutoValueVector paramData(cx);
|
|
|
|
paramData.append(coords);
|
|
|
|
|
|
|
|
ScriptEvent("worldclick", paramData);
|
2006-01-21 12:07:25 +01:00
|
|
|
}
|
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
// This sets up and draws the rectangle on the minimap
|
|
|
|
// which represents the view of the camera in the world.
|
2019-08-23 01:51:10 +02:00
|
|
|
void CMiniMap::DrawViewRect(CMatrix3D transform) const
|
2005-10-19 19:16:34 +02:00
|
|
|
{
|
2010-08-22 00:06:44 +02:00
|
|
|
// Compute the camera frustum intersected with a fixed-height plane.
|
2015-04-01 16:17:18 +02:00
|
|
|
// Use the water height as a fixed base height, which should be the lowest we can go
|
|
|
|
float h = g_Renderer.GetWaterManager()->m_WaterHeight;
|
2014-07-14 19:15:22 +02:00
|
|
|
const float width = m_CachedActualSize.GetWidth();
|
|
|
|
const float height = m_CachedActualSize.GetHeight();
|
|
|
|
const float invTileMapSize = 1.0f / float(TERRAIN_TILE_SIZE * m_MapSize);
|
2010-08-22 00:06:44 +02:00
|
|
|
|
2005-10-19 19:16:34 +02:00
|
|
|
CVector3D hitPt[4];
|
2014-07-14 19:15:22 +02:00
|
|
|
hitPt[0] = m_Camera->GetWorldCoordinates(0, 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[3] = m_Camera->GetWorldCoordinates(0, 0, h);
|
2005-10-19 19:16:34 +02:00
|
|
|
|
|
|
|
float ViewRect[4][2];
|
2015-08-21 19:08:41 +02:00
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
{
|
2005-10-19 19:16:34 +02:00
|
|
|
// convert to minimap space
|
2014-07-14 19:15:22 +02:00
|
|
|
ViewRect[i][0] = (width * hitPt[i].X * invTileMapSize);
|
|
|
|
ViewRect[i][1] = (height * hitPt[i].Z * invTileMapSize);
|
2005-10-19 19:16:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
float viewVerts[] = {
|
|
|
|
ViewRect[0][0], -ViewRect[0][1],
|
|
|
|
ViewRect[1][0], -ViewRect[1][1],
|
|
|
|
ViewRect[2][0], -ViewRect[2][1],
|
|
|
|
ViewRect[3][0], -ViewRect[3][1]
|
|
|
|
};
|
|
|
|
|
|
|
|
// Enable Scissoring to restrict the rectangle to only the minimap.
|
2015-01-24 21:06:37 +01:00
|
|
|
glScissor(
|
2017-06-14 19:13:44 +02:00
|
|
|
m_CachedActualSize.left * g_GuiScale,
|
|
|
|
g_Renderer.GetHeight() - m_CachedActualSize.bottom * g_GuiScale,
|
|
|
|
width * g_GuiScale,
|
|
|
|
height * g_GuiScale);
|
2005-10-19 19:16:34 +02:00
|
|
|
glEnable(GL_SCISSOR_TEST);
|
2006-07-09 00:40:01 +02:00
|
|
|
glLineWidth(2.0f);
|
2005-10-19 19:16:34 +02:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
CShaderDefines lineDefines;
|
|
|
|
lineDefines.Add(str_MINIMAP_LINE, str_1);
|
|
|
|
CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), lineDefines);
|
|
|
|
tech->BeginPass();
|
|
|
|
CShaderProgramPtr shader = tech->GetShader();
|
|
|
|
shader->Uniform(str_transform, transform);
|
|
|
|
shader->Uniform(str_color, 1.0f, 0.3f, 0.3f, 1.0f);
|
|
|
|
|
|
|
|
shader->VertexPointer(2, GL_FLOAT, 0, viewVerts);
|
|
|
|
shader->AssertPointersBound();
|
|
|
|
|
|
|
|
if (!g_Renderer.m_SkipSubmit)
|
|
|
|
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
|
|
|
|
|
|
|
tech->EndPass();
|
2005-10-19 19:16:34 +02:00
|
|
|
|
|
|
|
glLineWidth(1.0f);
|
2014-07-14 19:15:22 +02:00
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2005-10-19 19:16:34 +02:00
|
|
|
}
|
|
|
|
|
2006-08-28 00:51:53 +02:00
|
|
|
struct MinimapUnitVertex
|
|
|
|
{
|
Use NONCOPYABLE for most GUI classes and structs to have the compiler indicate unintended copies, refs 3028551b91 / D2163.
That is CChartData, CGUIList, CGUISeries, COListColumn, GUITooltip,
SGUIMessage, SSpriteCall, STextCall, SFeedback, IGUISetting,
CGUISetting, GUI, IGUIObject, IGUIScrollBar.
Drop copying GetSetting and SetSetting template functions for CGUIList,
CGUISeries, CClientArea, CGUIString.
Stop copying COListColumn.
Drop copying GUI<CClientArea>::GetSetting call in
IGUIObject::UpdateCachedSize() and four copying
GUI<CGUIString>::GetSetting calls in SetupText() functions.
Delete unused GUIRenderer IGLState class from 849f50a500 obsolete since
1f5b8f1c9a.
Differential Revision: https://code.wildfiregames.com/D2164
This was SVN commit r22638.
2019-08-10 02:04:17 +02:00
|
|
|
// This struct is copyable for convenience and because to move is to copy for primitives.
|
2006-08-28 00:51:53 +02:00
|
|
|
u8 r, g, b, a;
|
|
|
|
float x, y;
|
|
|
|
};
|
|
|
|
|
2013-10-06 06:49:38 +02:00
|
|
|
// Adds a vertex to the passed VertexArray
|
|
|
|
static void inline addVertex(const MinimapUnitVertex& v,
|
|
|
|
VertexArrayIterator<u8[4]>& attrColor,
|
|
|
|
VertexArrayIterator<float[2]>& attrPos)
|
|
|
|
{
|
|
|
|
(*attrColor)[0] = v.r;
|
|
|
|
(*attrColor)[1] = v.g;
|
|
|
|
(*attrColor)[2] = v.b;
|
|
|
|
(*attrColor)[3] = v.a;
|
|
|
|
++attrColor;
|
|
|
|
|
|
|
|
(*attrPos)[0] = v.x;
|
|
|
|
(*attrPos)[1] = v.y;
|
|
|
|
|
|
|
|
++attrPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-23 01:51:10 +02:00
|
|
|
void CMiniMap::DrawTexture(CShaderProgramPtr shader, float coordMax, float angle, float x, float y, float x2, float y2, float z) const
|
2010-10-25 23:59:52 +02:00
|
|
|
{
|
|
|
|
// Rotate the texture coordinates (0,0)-(coordMax,coordMax) around their center point (m,m)
|
2011-05-27 05:04:59 +02:00
|
|
|
// Scale square maps to fit in circular minimap area
|
|
|
|
const float s = sin(angle) * m_MapScale;
|
|
|
|
const float c = cos(angle) * m_MapScale;
|
2010-10-25 23:59:52 +02:00
|
|
|
const float m = coordMax / 2.f;
|
|
|
|
|
2013-11-12 02:31:52 +01:00
|
|
|
float quadTex[] = {
|
|
|
|
m*(-c + s + 1.f), m*(-c + -s + 1.f),
|
|
|
|
m*(c + s + 1.f), m*(-c + s + 1.f),
|
|
|
|
m*(c + -s + 1.f), m*(c + s + 1.f),
|
|
|
|
|
|
|
|
m*(c + -s + 1.f), m*(c + s + 1.f),
|
|
|
|
m*(-c + -s + 1.f), m*(c + -s + 1.f),
|
|
|
|
m*(-c + s + 1.f), m*(-c + -s + 1.f)
|
|
|
|
};
|
|
|
|
float quadVerts[] = {
|
|
|
|
x, y, z,
|
|
|
|
x2, y, z,
|
|
|
|
x2, y2, z,
|
|
|
|
|
|
|
|
x2, y2, z,
|
|
|
|
x, y2, z,
|
|
|
|
x, y, z
|
|
|
|
};
|
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 0, quadTex);
|
|
|
|
shader->VertexPointer(3, GL_FLOAT, 0, quadVerts);
|
|
|
|
shader->AssertPointersBound();
|
2013-11-12 02:31:52 +01:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
if (!g_Renderer.m_SkipSubmit)
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
2010-10-25 23:59:52 +02:00
|
|
|
}
|
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
// TODO: render the minimap in a framebuffer and just draw the frambuffer texture
|
|
|
|
// most of the time, updating the framebuffer twice a frame.
|
|
|
|
// Here it updates as ping-pong either texture or vertex array each sec to lower gpu stalling
|
|
|
|
// (those operations cause a gpu sync, which slows down the way gpu works)
|
2004-10-08 03:10:14 +02:00
|
|
|
void CMiniMap::Draw()
|
|
|
|
{
|
2011-11-04 02:35:50 +01:00
|
|
|
PROFILE3("render minimap");
|
2006-08-28 00:51:53 +02:00
|
|
|
|
2005-02-02 18:03:37 +01:00
|
|
|
// The terrain isn't actually initialized until the map is loaded, which
|
2005-10-19 19:16:34 +02:00
|
|
|
// happens when the game is started, so abort until then.
|
2019-08-21 12:12:33 +02:00
|
|
|
if (!g_Game || !g_Game->IsGameStarted())
|
2005-10-19 08:11:21 +02:00
|
|
|
return;
|
2010-10-25 23:59:52 +02:00
|
|
|
|
2011-05-27 05:04:59 +02:00
|
|
|
CSimulation2* sim = g_Game->GetSimulation2();
|
|
|
|
CmpPtr<ICmpRangeManager> cmpRangeManager(*sim, SYSTEM_ENTITY);
|
2012-02-08 03:46:15 +01:00
|
|
|
ENSURE(cmpRangeManager);
|
2011-05-27 05:04:59 +02:00
|
|
|
|
2005-10-19 08:11:21 +02:00
|
|
|
// Set our globals in case they hadn't been set before
|
2014-07-14 19:15:22 +02:00
|
|
|
m_Camera = g_Game->GetView()->GetCamera();
|
|
|
|
m_Terrain = g_Game->GetWorld()->GetTerrain();
|
2005-10-19 19:16:34 +02:00
|
|
|
m_Width = (u32)(m_CachedActualSize.right - m_CachedActualSize.left);
|
2005-10-19 08:11:21 +02:00
|
|
|
m_Height = (u32)(m_CachedActualSize.bottom - m_CachedActualSize.top);
|
|
|
|
m_MapSize = m_Terrain->GetVerticesPerSide();
|
2010-01-01 16:33:07 +01:00
|
|
|
m_TextureSize = (GLsizei)round_up_to_pow2((size_t)m_MapSize);
|
2011-05-27 05:04:59 +02:00
|
|
|
m_MapScale = (cmpRangeManager->GetLosCircular() ? 1.f : 1.414f);
|
2005-10-19 08:11:21 +02:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
if (!m_TerrainTexture || g_GameRestarted)
|
2005-10-19 08:11:21 +02:00
|
|
|
CreateTextures();
|
|
|
|
|
2005-11-06 05:22:47 +01:00
|
|
|
|
2010-09-24 18:52:29 +02:00
|
|
|
// only update 2x / second
|
2005-11-06 03:02:44 +01:00
|
|
|
// (note: since units only move a few pixels per second on the minimap,
|
2010-09-24 18:52:29 +02:00
|
|
|
// we can get away with infrequent updates; this is slow)
|
2014-07-14 19:15:22 +02:00
|
|
|
// TODO: Update all but camera at same speed as simulation
|
2005-11-06 03:02:44 +01:00
|
|
|
static double last_time;
|
2008-01-07 21:03:19 +01:00
|
|
|
const double cur_time = timer_Time();
|
2013-06-06 02:10:58 +02:00
|
|
|
const bool doUpdate = cur_time - last_time > 0.5;
|
2014-07-14 19:15:22 +02:00
|
|
|
if (doUpdate)
|
2015-08-21 19:08:41 +02:00
|
|
|
{
|
2005-11-06 03:02:44 +01:00
|
|
|
last_time = cur_time;
|
2017-04-17 00:13:32 +02:00
|
|
|
if (m_TerrainDirty || m_WaterHeight != g_Renderer.GetWaterManager()->m_WaterHeight)
|
2010-09-10 23:02:10 +02:00
|
|
|
RebuildTerrainTexture();
|
2005-11-06 03:02:44 +01:00
|
|
|
}
|
2005-10-19 08:11:21 +02:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
const float x = m_CachedActualSize.left, y = m_CachedActualSize.bottom;
|
|
|
|
const float x2 = m_CachedActualSize.right, y2 = m_CachedActualSize.top;
|
|
|
|
const float z = GetBufferedZ();
|
|
|
|
const float texCoordMax = (float)(m_MapSize - 1) / (float)m_TextureSize;
|
|
|
|
const float angle = GetAngle();
|
|
|
|
const float unitScale = (cmpRangeManager->GetLosCircular() ? 1.f : m_MapScale/2.f);
|
2012-01-29 21:04:21 +01:00
|
|
|
|
2012-02-09 21:45:19 +01:00
|
|
|
// Disable depth updates to prevent apparent z-fighting-related issues
|
2014-07-14 19:15:22 +02:00
|
|
|
// with some drivers causing units to get drawn behind the texture.
|
2012-02-09 21:45:19 +01:00
|
|
|
glDepthMask(0);
|
2014-07-14 19:15:22 +02:00
|
|
|
|
2012-08-30 01:07:53 +02:00
|
|
|
CShaderProgramPtr shader;
|
|
|
|
CShaderTechniquePtr tech;
|
2012-02-09 21:45:19 +01:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
CShaderDefines baseDefines;
|
|
|
|
baseDefines.Add(str_MINIMAP_BASE, str_1);
|
|
|
|
tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), baseDefines);
|
|
|
|
tech->BeginPass();
|
|
|
|
shader = tech->GetShader();
|
2005-10-19 08:11:21 +02:00
|
|
|
|
|
|
|
// Draw the main textured quad
|
2014-07-14 19:15:22 +02:00
|
|
|
shader->BindTexture(str_baseTex, m_TerrainTexture);
|
|
|
|
const CMatrix3D baseTransform = GetDefaultGuiMatrix();
|
|
|
|
CMatrix3D baseTextureTransform;
|
|
|
|
baseTextureTransform.SetIdentity();
|
|
|
|
shader->Uniform(str_transform, baseTransform);
|
|
|
|
shader->Uniform(str_textureTransform, baseTextureTransform);
|
2005-10-19 08:11:21 +02:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
DrawTexture(shader, texCoordMax, angle, x, y, x2, y2, z);
|
2006-08-28 00:51:53 +02:00
|
|
|
|
2011-07-20 21:48:06 +02:00
|
|
|
// Draw territory boundaries
|
2006-07-09 00:40:01 +02:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
CTerritoryTexture& territoryTexture = g_Game->GetView()->GetTerritoryTexture();
|
2006-08-28 00:51:53 +02:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
shader->BindTexture(str_baseTex, territoryTexture.GetTexture());
|
2015-08-21 19:08:41 +02:00
|
|
|
const CMatrix3D* territoryTransform = territoryTexture.GetMinimapTextureMatrix();
|
2014-07-14 19:15:22 +02:00
|
|
|
shader->Uniform(str_transform, baseTransform);
|
|
|
|
shader->Uniform(str_textureTransform, *territoryTransform);
|
2011-07-20 21:48:06 +02:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
DrawTexture(shader, 1.0f, angle, x, y, x2, y2, z);
|
|
|
|
tech->EndPass();
|
2006-07-09 00:40:01 +02:00
|
|
|
|
2005-10-19 08:11:21 +02:00
|
|
|
// Draw the LOS quad in black, using alpha values from the LOS texture
|
2011-02-03 02:12:24 +01:00
|
|
|
CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture();
|
2014-07-14 19:15:22 +02:00
|
|
|
|
|
|
|
CShaderDefines losDefines;
|
|
|
|
losDefines.Add(str_MINIMAP_LOS, str_1);
|
|
|
|
tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), losDefines);
|
|
|
|
tech->BeginPass();
|
|
|
|
shader = tech->GetShader();
|
|
|
|
shader->BindTexture(str_baseTex, losTexture.GetTexture());
|
|
|
|
|
2005-10-19 08:11:21 +02:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2011-02-03 02:12:24 +01:00
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
const CMatrix3D* losTransform = losTexture.GetMinimapTextureMatrix();
|
2014-07-14 19:15:22 +02:00
|
|
|
shader->Uniform(str_transform, baseTransform);
|
|
|
|
shader->Uniform(str_textureTransform, *losTransform);
|
2011-02-03 02:12:24 +01:00
|
|
|
|
2013-11-12 02:31:52 +01:00
|
|
|
DrawTexture(shader, 1.0f, angle, x, y, x2, y2, z);
|
2014-07-14 19:15:22 +02:00
|
|
|
tech->EndPass();
|
2011-02-03 02:12:24 +01:00
|
|
|
|
2005-10-19 08:11:21 +02:00
|
|
|
glDisable(GL_BLEND);
|
2010-10-25 23:59:52 +02:00
|
|
|
|
2006-08-28 00:51:53 +02:00
|
|
|
PROFILE_START("minimap units");
|
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
CShaderDefines pointDefines;
|
|
|
|
pointDefines.Add(str_MINIMAP_POINT, str_1);
|
|
|
|
tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), pointDefines);
|
|
|
|
tech->BeginPass();
|
|
|
|
shader = tech->GetShader();
|
|
|
|
shader->Uniform(str_transform, baseTransform);
|
2014-10-26 05:37:26 +01:00
|
|
|
shader->Uniform(str_pointSize, 3.f);
|
2014-07-14 19:15:22 +02:00
|
|
|
|
|
|
|
CMatrix3D unitMatrix;
|
|
|
|
unitMatrix.SetIdentity();
|
|
|
|
// Center the minimap on the origin of the axis of rotation.
|
|
|
|
unitMatrix.Translate(-(x2 - x) / 2.f, -(y2 - y) / 2.f, 0.f);
|
|
|
|
// Rotate the map.
|
|
|
|
unitMatrix.RotateZ(angle);
|
|
|
|
// Scale square maps to fit.
|
|
|
|
unitMatrix.Scale(unitScale, unitScale, 1.f);
|
|
|
|
// Move the minimap back to it's starting position.
|
|
|
|
unitMatrix.Translate((x2 - x) / 2.f, (y2 - y) / 2.f, 0.f);
|
|
|
|
// Move the minimap to it's final location.
|
|
|
|
unitMatrix.Translate(x, y, z);
|
|
|
|
// Apply the gui matrix.
|
|
|
|
unitMatrix *= GetDefaultGuiMatrix();
|
|
|
|
// Load the transform into the shader.
|
|
|
|
shader->Uniform(str_transform, unitMatrix);
|
2006-08-28 00:51:53 +02:00
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
const float sx = (float)m_Width / ((m_MapSize - 1) * TERRAIN_TILE_SIZE);
|
|
|
|
const float sy = (float)m_Height / ((m_MapSize - 1) * TERRAIN_TILE_SIZE);
|
2005-09-14 21:43:16 +02:00
|
|
|
|
2011-03-03 01:16:14 +01:00
|
|
|
CSimulation2::InterfaceList ents = sim->GetEntitiesWithInterface(IID_Minimap);
|
2010-07-05 21:18:40 +02:00
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
if (doUpdate)
|
2010-04-23 20:36:48 +02:00
|
|
|
{
|
2013-06-06 02:10:58 +02:00
|
|
|
VertexArrayIterator<float[2]> attrPos = m_AttributePos.GetIterator<float[2]>();
|
|
|
|
VertexArrayIterator<u8[4]> attrColor = m_AttributeColor.GetIterator<u8[4]>();
|
|
|
|
|
|
|
|
m_EntitiesDrawn = 0;
|
2010-05-20 20:09:23 +02:00
|
|
|
MinimapUnitVertex v;
|
2013-10-06 06:49:38 +02:00
|
|
|
std::vector<MinimapUnitVertex> pingingVertices;
|
2014-07-14 19:15:22 +02:00
|
|
|
pingingVertices.reserve(MAX_ENTITIES_DRAWN / 2);
|
2013-10-06 06:49:38 +02:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
if (cur_time > m_NextBlinkTime)
|
2013-10-06 06:49:38 +02:00
|
|
|
{
|
|
|
|
m_BlinkState = !m_BlinkState;
|
2014-07-14 19:15:22 +02:00
|
|
|
m_NextBlinkTime = cur_time + m_HalfBlinkDuration;
|
2013-10-06 06:49:38 +02:00
|
|
|
}
|
|
|
|
|
2010-09-23 14:13:13 +02:00
|
|
|
entity_pos_t posX, posZ;
|
2013-06-06 02:10:58 +02:00
|
|
|
for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it)
|
2010-04-23 20:36:48 +02:00
|
|
|
{
|
2013-06-06 02:10:58 +02:00
|
|
|
ICmpMinimap* cmpMinimap = static_cast<ICmpMinimap*>(it->second);
|
|
|
|
if (cmpMinimap->GetRenderData(v.r, v.g, v.b, posX, posZ))
|
2010-09-23 14:13:13 +02:00
|
|
|
{
|
2016-02-06 13:56:41 +01:00
|
|
|
ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(it->first, g_Game->GetSimulation2()->GetSimContext().GetCurrentDisplayedPlayer());
|
2013-06-06 02:10:58 +02:00
|
|
|
if (vis != ICmpRangeManager::VIS_HIDDEN)
|
|
|
|
{
|
|
|
|
v.a = 255;
|
2014-07-14 19:15:22 +02:00
|
|
|
v.x = posX.ToFloat() * sx;
|
|
|
|
v.y = -posZ.ToFloat() * sy;
|
|
|
|
|
2013-10-06 06:49:38 +02:00
|
|
|
// Check minimap pinging to indicate something
|
2014-07-14 19:15:22 +02:00
|
|
|
if (m_BlinkState && cmpMinimap->CheckPing(cur_time, m_PingDuration))
|
2013-10-06 06:49:38 +02:00
|
|
|
{
|
|
|
|
v.r = 255; // ping color is white
|
|
|
|
v.g = 255;
|
|
|
|
v.b = 255;
|
|
|
|
pingingVertices.push_back(v);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addVertex(v, attrColor, attrPos);
|
|
|
|
++m_EntitiesDrawn;
|
|
|
|
}
|
2013-06-06 02:10:58 +02:00
|
|
|
}
|
2010-09-23 14:13:13 +02:00
|
|
|
}
|
2005-05-13 03:15:53 +02:00
|
|
|
}
|
2013-10-06 06:49:38 +02:00
|
|
|
|
|
|
|
// Add the pinged vertices at the end, so they are drawn on top
|
|
|
|
for (size_t v = 0; v < pingingVertices.size(); ++v)
|
|
|
|
{
|
|
|
|
addVertex(pingingVertices[v], attrColor, attrPos);
|
|
|
|
++m_EntitiesDrawn;
|
|
|
|
}
|
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
ENSURE(m_EntitiesDrawn < MAX_ENTITIES_DRAWN);
|
|
|
|
m_VertexArray.Upload();
|
2010-04-23 20:36:48 +02:00
|
|
|
}
|
2006-08-28 00:51:53 +02:00
|
|
|
|
2015-01-28 01:48:00 +01:00
|
|
|
m_VertexArray.PrepareForRendering();
|
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
if (m_EntitiesDrawn > 0)
|
2014-07-14 19:15:22 +02:00
|
|
|
{
|
2014-10-26 05:37:26 +01:00
|
|
|
#if !CONFIG2_GLES
|
2019-08-04 10:28:30 +02:00
|
|
|
if (g_RenderingOptions.GetRenderPath() == RenderPath::SHADER)
|
2014-10-26 05:37:26 +01:00
|
|
|
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
|
|
|
#endif
|
2013-06-06 02:10:58 +02:00
|
|
|
|
|
|
|
u8* indexBase = m_IndexArray.Bind();
|
|
|
|
u8* base = m_VertexArray.Bind();
|
|
|
|
const GLsizei stride = (GLsizei)m_VertexArray.GetStride();
|
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
shader->VertexPointer(2, GL_FLOAT, stride, base + m_AttributePos.offset);
|
|
|
|
shader->ColorPointer(4, GL_UNSIGNED_BYTE, stride, base + m_AttributeColor.offset);
|
|
|
|
shader->AssertPointersBound();
|
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
if (!g_Renderer.m_SkipSubmit)
|
|
|
|
glDrawElements(GL_POINTS, (GLsizei)(m_EntitiesDrawn), GL_UNSIGNED_SHORT, indexBase);
|
2011-10-22 12:25:09 +02:00
|
|
|
|
2013-06-06 02:10:58 +02:00
|
|
|
g_Renderer.GetStats().m_DrawCalls++;
|
|
|
|
CVertexBuffer::Unbind();
|
2012-08-30 01:07:53 +02:00
|
|
|
|
2014-10-26 05:37:26 +01:00
|
|
|
#if !CONFIG2_GLES
|
2019-08-04 10:28:30 +02:00
|
|
|
if (g_RenderingOptions.GetRenderPath() == RenderPath::SHADER)
|
2014-10-26 05:37:26 +01:00
|
|
|
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
|
|
|
#endif
|
2013-06-06 02:10:58 +02:00
|
|
|
}
|
2005-10-19 08:11:21 +02:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
tech->EndPass();
|
2006-01-07 02:04:26 +01:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
DrawViewRect(unitMatrix);
|
2012-01-29 21:04:21 +01:00
|
|
|
|
2014-07-14 19:15:22 +02:00
|
|
|
PROFILE_END("minimap units");
|
|
|
|
|
|
|
|
// Reset depth mask
|
2012-02-09 21:45:19 +01:00
|
|
|
glDepthMask(1);
|
2004-10-08 03:10:14 +02:00
|
|
|
}
|
|
|
|
|
2005-10-19 05:02:51 +02:00
|
|
|
void CMiniMap::CreateTextures()
|
2004-10-08 03:10:14 +02:00
|
|
|
{
|
2005-05-13 03:15:53 +02:00
|
|
|
Destroy();
|
2004-10-08 03:10:14 +02:00
|
|
|
|
2005-10-19 05:02:51 +02:00
|
|
|
// Create terrain texture
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
glGenTextures(1, &m_TerrainTexture);
|
2005-10-19 05:02:51 +02:00
|
|
|
g_Renderer.BindTexture(0, m_TerrainTexture);
|
2011-06-26 23:47:07 +02:00
|
|
|
|
|
|
|
// Initialise texture with solid black, for the areas we don't
|
|
|
|
// overwrite with glTexSubImage2D later
|
|
|
|
u32* texData = new u32[m_TextureSize * m_TextureSize];
|
|
|
|
for (ssize_t i = 0; i < m_TextureSize * m_TextureSize; ++i)
|
|
|
|
texData[i] = 0xFF000000;
|
2013-11-12 02:11:08 +01:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_TextureSize, m_TextureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
|
2011-06-26 23:47:07 +02:00
|
|
|
delete[] texData;
|
|
|
|
|
2005-10-19 05:02:51 +02:00
|
|
|
m_TerrainData = new u32[(m_MapSize - 1) * (m_MapSize - 1)];
|
2012-02-09 18:55:25 +01:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2004-10-08 03:10:14 +02:00
|
|
|
|
2005-10-19 05:02:51 +02:00
|
|
|
// Rebuild and upload both of them
|
|
|
|
RebuildTerrainTexture();
|
2004-10-08 03:10:14 +02:00
|
|
|
}
|
|
|
|
|
2005-10-19 19:16:34 +02:00
|
|
|
|
2005-10-19 05:02:51 +02:00
|
|
|
void CMiniMap::RebuildTerrainTexture()
|
2004-10-08 03:10:14 +02:00
|
|
|
{
|
2005-05-13 03:15:53 +02:00
|
|
|
u32 x = 0;
|
|
|
|
u32 y = 0;
|
|
|
|
u32 w = m_MapSize - 1;
|
|
|
|
u32 h = m_MapSize - 1;
|
2017-04-17 00:13:32 +02:00
|
|
|
m_WaterHeight = g_Renderer.GetWaterManager()->m_WaterHeight;
|
2005-05-13 03:15:53 +02:00
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
m_TerrainDirty = false;
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
for (u32 j = 0; j < h; ++j)
|
2005-05-13 03:15:53 +02:00
|
|
|
{
|
2015-08-21 19:08:41 +02:00
|
|
|
u32* dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x;
|
|
|
|
for (u32 i = 0; i < w; ++i)
|
2005-05-13 03:15:53 +02:00
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
float avgHeight = ( m_Terrain->GetVertexGroundLevel((int)i, (int)j)
|
|
|
|
+ m_Terrain->GetVertexGroundLevel((int)i+1, (int)j)
|
|
|
|
+ m_Terrain->GetVertexGroundLevel((int)i, (int)j+1)
|
|
|
|
+ m_Terrain->GetVertexGroundLevel((int)i+1, (int)j+1)
|
2005-10-19 05:02:51 +02:00
|
|
|
) / 4.0f;
|
|
|
|
|
2017-04-17 00:13:32 +02:00
|
|
|
if (avgHeight < m_WaterHeight && avgHeight > m_WaterHeight - m_ShallowPassageHeight)
|
2012-08-04 20:52:02 +02:00
|
|
|
{
|
|
|
|
// shallow water
|
2013-11-12 02:11:08 +01:00
|
|
|
*dataPtr++ = 0xffc09870;
|
|
|
|
}
|
2017-04-17 00:13:32 +02:00
|
|
|
else if (avgHeight < m_WaterHeight)
|
2005-05-13 03:15:53 +02:00
|
|
|
{
|
2012-02-29 02:12:52 +01:00
|
|
|
// Set water as constant color for consistency on different maps
|
2013-11-12 02:11:08 +01:00
|
|
|
*dataPtr++ = 0xffa07850;
|
2005-05-13 03:15:53 +02:00
|
|
|
}
|
|
|
|
else
|
2005-10-09 05:43:03 +02:00
|
|
|
{
|
2005-10-19 05:02:51 +02:00
|
|
|
int hmap = ((int)m_Terrain->GetHeightMap()[(y + j) * m_MapSize + x + i]) >> 8;
|
|
|
|
int val = (hmap / 3) + 170;
|
2005-10-09 05:43:03 +02:00
|
|
|
|
2009-11-08 17:49:52 +01:00
|
|
|
u32 color = 0xFFFFFFFF;
|
2005-10-09 05:43:03 +02:00
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
CMiniPatch* mp = m_Terrain->GetTile(x + i, y + j);
|
|
|
|
if (mp)
|
2005-10-09 05:43:03 +02:00
|
|
|
{
|
2015-08-21 19:08:41 +02:00
|
|
|
CTerrainTextureEntry* tex = mp->GetTextureEntry();
|
|
|
|
if (tex)
|
2010-09-10 23:02:10 +02:00
|
|
|
{
|
|
|
|
// If the texture can't be loaded yet, set the dirty flags
|
|
|
|
// so we'll try regenerating the terrain texture again soon
|
|
|
|
if(!tex->GetTexture()->TryLoad())
|
|
|
|
m_TerrainDirty = true;
|
|
|
|
|
2009-11-08 17:49:52 +01:00
|
|
|
color = tex->GetBaseColor();
|
2010-09-10 23:02:10 +02:00
|
|
|
}
|
2005-10-09 05:43:03 +02:00
|
|
|
}
|
|
|
|
|
2005-10-19 05:02:51 +02:00
|
|
|
*dataPtr++ = ScaleColor(color, float(val) / 255.0f);
|
2005-10-09 05:43:03 +02:00
|
|
|
}
|
2005-05-13 03:15:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-19 05:02:51 +02:00
|
|
|
// Upload the texture
|
|
|
|
g_Renderer.BindTexture(0, m_TerrainTexture);
|
2013-11-12 02:11:08 +01:00
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_MapSize - 1, m_MapSize - 1, GL_RGBA, GL_UNSIGNED_BYTE, m_TerrainData);
|
2004-10-08 03:10:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMiniMap::Destroy()
|
|
|
|
{
|
2015-08-21 19:08:41 +02:00
|
|
|
if (m_TerrainTexture)
|
2010-09-24 18:52:29 +02:00
|
|
|
{
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
glDeleteTextures(1, &m_TerrainTexture);
|
2010-09-24 18:52:29 +02:00
|
|
|
m_TerrainTexture = 0;
|
|
|
|
}
|
2005-10-19 05:02:51 +02:00
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
SAFE_ARRAY_DELETE(m_TerrainData);
|
2004-10-08 03:10:14 +02:00
|
|
|
}
|