2012-01-13 00:32:27 +01:00
|
|
|
/* Copyright (C) 2012 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"
|
2006-06-09 18:44:16 +02:00
|
|
|
#include "lib/ogl.h"
|
2012-01-13 00:32:27 +01:00
|
|
|
#include "lib/external_libraries/libsdl.h"
|
2007-05-09 23:01:11 +02:00
|
|
|
#include "lib/bits.h"
|
2007-01-21 04:33:52 +01:00
|
|
|
#include "lib/timer.h"
|
2006-06-09 18:44:16 +02:00
|
|
|
#include "ps/Game.h"
|
|
|
|
#include "ps/Profile.h"
|
2007-01-13 23:44:42 +01:00
|
|
|
#include "ps/World.h"
|
2006-06-09 18:44:16 +02:00
|
|
|
#include "renderer/Renderer.h"
|
|
|
|
#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"
|
2011-07-20 21:48:06 +02:00
|
|
|
#include "simulation2/components/ICmpTerritoryManager.h"
|
2005-10-20 17:27:39 +02:00
|
|
|
|
2006-10-08 05:28:22 +02:00
|
|
|
bool g_GameRestarted = false;
|
2005-10-19 05:02:51 +02:00
|
|
|
|
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);
|
2005-05-13 03:15:53 +02:00
|
|
|
return (0xff000000 | r | g<<8 | b<<16);
|
2004-10-08 03:10:14 +02:00
|
|
|
}
|
|
|
|
|
2011-02-03 02:12:24 +01:00
|
|
|
CMiniMap::CMiniMap() :
|
2011-05-27 05:04:59 +02:00
|
|
|
m_TerrainTexture(0), m_TerrainData(0), m_MapSize(0), m_Terrain(0), m_TerrainDirty(true), m_MapScale(1.f)
|
2004-10-08 03:10:14 +02:00
|
|
|
{
|
2005-05-13 03:15:53 +02:00
|
|
|
AddSetting(GUIST_CColor, "fov_wedge_color");
|
2011-02-18 23:36:39 +01:00
|
|
|
AddSetting(GUIST_CStrW, "tooltip");
|
2005-01-01 13:06:17 +01:00
|
|
|
AddSetting(GUIST_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;
|
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
|
|
|
}
|
|
|
|
|
2011-04-28 22:42:11 +02:00
|
|
|
void CMiniMap::HandleMessage(SGUIMessage &Message)
|
2005-10-19 19:16:34 +02:00
|
|
|
{
|
2005-10-20 17:27:39 +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:
|
2005-10-19 19:16:34 +02:00
|
|
|
{
|
2012-05-04 19:44:28 +02:00
|
|
|
if (m_MouseHovering)
|
2010-11-14 23:47:39 +01:00
|
|
|
{
|
|
|
|
SetCameraPos();
|
|
|
|
m_Clicking = true;
|
|
|
|
}
|
2006-01-21 12:07:25 +01:00
|
|
|
break;
|
2005-10-19 19:16:34 +02:00
|
|
|
}
|
2006-01-21 12:07:25 +01:00
|
|
|
case GUIM_MOUSE_RELEASE_LEFT:
|
|
|
|
{
|
2012-05-04 19:44:28 +02:00
|
|
|
if(m_MouseHovering && m_Clicking)
|
2010-11-14 23:47:39 +01:00
|
|
|
{
|
2006-12-20 06:41:54 +01:00
|
|
|
SetCameraPos();
|
2010-11-14 23:47:39 +01:00
|
|
|
}
|
2006-12-20 06:41:54 +01:00
|
|
|
m_Clicking = false;
|
|
|
|
break;
|
2006-01-21 12:07:25 +01:00
|
|
|
}
|
2008-07-29 08:56:38 +02:00
|
|
|
case GUIM_MOUSE_DBLCLICK_LEFT:
|
|
|
|
{
|
2012-05-04 19:44:28 +02:00
|
|
|
if(m_MouseHovering && m_Clicking)
|
2011-04-28 22:42:11 +02:00
|
|
|
{
|
2008-07-29 08:56:38 +02:00
|
|
|
SetCameraPos();
|
2011-04-28 22:42:11 +02:00
|
|
|
}
|
2008-07-29 08:56:38 +02:00
|
|
|
m_Clicking = false;
|
|
|
|
break;
|
|
|
|
}
|
2006-01-21 12:07:25 +01:00
|
|
|
case GUIM_MOUSE_ENTER:
|
|
|
|
{
|
2012-05-04 19:44:28 +02:00
|
|
|
m_MouseHovering = true;
|
2006-01-21 12:07:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GUIM_MOUSE_LEAVE:
|
|
|
|
{
|
2011-04-28 22:42:11 +02:00
|
|
|
m_Clicking = false;
|
2012-05-04 19:44:28 +02:00
|
|
|
m_MouseHovering = false;
|
2006-01-21 12:07:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GUIM_MOUSE_RELEASE_RIGHT:
|
|
|
|
{
|
|
|
|
CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GUIM_MOUSE_DBLCLICK_RIGHT:
|
|
|
|
{
|
|
|
|
CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GUIM_MOUSE_MOTION:
|
|
|
|
{
|
2012-05-04 19:44:28 +02:00
|
|
|
if (m_MouseHovering && m_Clicking)
|
2011-04-28 22:42:11 +02:00
|
|
|
{
|
2006-01-21 12:07:25 +01:00
|
|
|
SetCameraPos();
|
2011-04-28 22:42:11 +02:00
|
|
|
}
|
2006-01-21 12:07:25 +01:00
|
|
|
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;
|
|
|
|
} // switch
|
2005-10-19 19:16:34 +02:00
|
|
|
}
|
|
|
|
|
2010-10-25 23:59:52 +02:00
|
|
|
void CMiniMap::GetMouseWorldCoordinates(float& x, float& z)
|
|
|
|
{
|
|
|
|
// Determine X and Z according to proportion of mouse position and minimap
|
|
|
|
|
|
|
|
CPos mousePos = GetMousePos();
|
|
|
|
|
|
|
|
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
|
|
|
|
2010-10-25 23:59:52 +02:00
|
|
|
float CMiniMap::GetAngle()
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
void CMiniMap::FireWorldClickEvent(int button, int clicks)
|
2006-01-21 12:07:25 +01:00
|
|
|
{
|
2010-10-25 23:59:52 +02:00
|
|
|
float x, z;
|
|
|
|
GetMouseWorldCoordinates(x, z);
|
2010-09-11 21:49:21 +02:00
|
|
|
|
|
|
|
CScriptValRooted coords;
|
|
|
|
g_ScriptingHost.GetScriptInterface().Eval("({})", coords);
|
|
|
|
g_ScriptingHost.GetScriptInterface().SetProperty(coords.get(), "x", x, false);
|
|
|
|
g_ScriptingHost.GetScriptInterface().SetProperty(coords.get(), "z", z, false);
|
|
|
|
ScriptEvent("worldclick", coords);
|
2006-01-21 12:07:25 +01:00
|
|
|
|
2010-05-20 19:58:37 +02:00
|
|
|
UNUSED2(button);
|
|
|
|
UNUSED2(clicks);
|
2006-01-21 12:07:25 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 18:55:25 +01:00
|
|
|
#if CONFIG2_GLES
|
|
|
|
#warning TODO: implement minimap for GLES
|
|
|
|
void CMiniMap::Draw()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
2005-10-19 19:16:34 +02:00
|
|
|
// render view rect : John M. Mena
|
|
|
|
// This sets up and draws the rectangle on the mini-map
|
|
|
|
// which represents the view of the camera in the world.
|
|
|
|
void CMiniMap::DrawViewRect()
|
|
|
|
{
|
2010-08-22 00:06:44 +02:00
|
|
|
// Compute the camera frustum intersected with a fixed-height plane.
|
|
|
|
// TODO: Currently we hard-code the height, so this'll be dodgy when maps aren't the
|
|
|
|
// expected height - how can we make it better without the view rect wobbling in
|
|
|
|
// size while the player scrolls?
|
|
|
|
float h = 16384.f * HEIGHT_SCALE;
|
|
|
|
|
2005-10-19 19:16:34 +02:00
|
|
|
CVector3D hitPt[4];
|
2010-08-22 00:06:44 +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];
|
|
|
|
for (int i=0;i<4;i++) {
|
|
|
|
// convert to minimap space
|
|
|
|
float px=hitPt[i].X;
|
|
|
|
float pz=hitPt[i].Z;
|
2012-01-12 13:51:10 +01:00
|
|
|
ViewRect[i][0]=(m_CachedActualSize.GetWidth()*px/float(TERRAIN_TILE_SIZE*m_MapSize));
|
|
|
|
ViewRect[i][1]=(m_CachedActualSize.GetHeight()*pz/float(TERRAIN_TILE_SIZE*m_MapSize));
|
2005-10-19 19:16:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enable Scissoring as to restrict the rectangle
|
|
|
|
// to only the mini-map below by retrieving the mini-maps
|
|
|
|
// screen coords.
|
2010-08-29 15:31:19 +02:00
|
|
|
const float x = m_CachedActualSize.left, y = m_CachedActualSize.bottom;
|
|
|
|
glScissor((int)x, g_Renderer.GetHeight()-(int)y, (int)m_CachedActualSize.GetWidth(), (int)m_CachedActualSize.GetHeight());
|
2005-10-19 19:16:34 +02:00
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
glEnable(GL_LINE_SMOOTH);
|
2006-07-09 00:40:01 +02:00
|
|
|
glLineWidth(2.0f);
|
2005-10-19 19:16:34 +02:00
|
|
|
glColor3f(1.0f, 0.3f, 0.3f);
|
|
|
|
|
|
|
|
// Draw the viewing rectangle with the ScEd's conversion algorithm
|
|
|
|
glBegin(GL_LINE_LOOP);
|
2010-10-25 23:59:52 +02:00
|
|
|
glVertex2f(ViewRect[0][0], -ViewRect[0][1]);
|
|
|
|
glVertex2f(ViewRect[1][0], -ViewRect[1][1]);
|
|
|
|
glVertex2f(ViewRect[2][0], -ViewRect[2][1]);
|
|
|
|
glVertex2f(ViewRect[3][0], -ViewRect[3][1]);
|
2005-10-19 19:16:34 +02:00
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// restore state
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2006-07-09 00:40:01 +02:00
|
|
|
glDisable(GL_LINE_SMOOTH);
|
2005-10-19 19:16:34 +02:00
|
|
|
glLineWidth(1.0f);
|
|
|
|
}
|
|
|
|
|
2006-08-28 00:51:53 +02:00
|
|
|
struct MinimapUnitVertex
|
|
|
|
{
|
|
|
|
u8 r, g, b, a;
|
|
|
|
float x, y;
|
|
|
|
};
|
|
|
|
|
2010-10-25 23:59:52 +02:00
|
|
|
void CMiniMap::DrawTexture(float coordMax, float angle, float x, float y, float x2, float y2, float z)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glTexCoord2f(m*(-c + s + 1.f), m*(-c + -s + 1.f));
|
|
|
|
glVertex3f(x, y, z);
|
|
|
|
glTexCoord2f(m*(c + s + 1.f), m*(-c + s + 1.f));
|
|
|
|
glVertex3f(x2, y, z);
|
|
|
|
glTexCoord2f(m*(c + -s + 1.f), m*(c + s + 1.f));
|
|
|
|
glVertex3f(x2, y2, z);
|
|
|
|
glTexCoord2f(m*(-c + -s + 1.f), m*(c + -s + 1.f));
|
|
|
|
glVertex3f(x, y2, z);
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
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.
|
2005-10-19 08:11:21 +02:00
|
|
|
if(!(GetGUI() && g_Game && g_Game->IsGameStarted()))
|
|
|
|
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
|
2005-10-19 19:16:34 +02:00
|
|
|
m_Camera = g_Game->GetView()->GetCamera();
|
|
|
|
m_Terrain = g_Game->GetWorld()->GetTerrain();
|
|
|
|
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
|
|
|
|
2006-10-08 05:28: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)
|
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();
|
2010-09-24 18:52:29 +02:00
|
|
|
if(cur_time - last_time > 0.5)
|
2005-11-06 03:02:44 +01:00
|
|
|
{
|
|
|
|
last_time = cur_time;
|
2005-10-19 08:11:21 +02:00
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
if(m_TerrainDirty)
|
|
|
|
RebuildTerrainTexture();
|
2005-11-06 03:02:44 +01:00
|
|
|
}
|
2005-10-19 08:11:21 +02:00
|
|
|
|
2012-02-08 21:43:38 +01:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2012-01-29 21:04:21 +01:00
|
|
|
glPushMatrix();
|
|
|
|
CMatrix3D matrix = GetDefaultGuiMatrix();
|
|
|
|
glLoadMatrixf(&matrix._11);
|
|
|
|
|
2012-02-09 21:45:19 +01:00
|
|
|
// Disable depth updates to prevent apparent z-fighting-related issues
|
|
|
|
// with some drivers causing units to get drawn behind the texture
|
|
|
|
glDepthMask(0);
|
|
|
|
|
2005-10-19 19:16:34 +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();
|
2010-10-25 23:59:52 +02:00
|
|
|
const float texCoordMax = (float)(m_MapSize - 1) / (float)m_TextureSize;
|
|
|
|
const float angle = GetAngle();
|
2005-10-19 08:11:21 +02:00
|
|
|
|
|
|
|
// Draw the main textured quad
|
|
|
|
g_Renderer.BindTexture(0, m_TerrainTexture);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2010-10-25 23:59:52 +02:00
|
|
|
DrawTexture(texCoordMax, angle, x, y, x2, y2, z);
|
2005-10-19 08:11:21 +02:00
|
|
|
|
2006-08-28 00:51:53 +02:00
|
|
|
|
2011-07-20 21:48:06 +02:00
|
|
|
// Draw territory boundaries
|
|
|
|
CTerritoryTexture& territoryTexture = g_Game->GetView()->GetTerritoryTexture();
|
|
|
|
territoryTexture.BindTexture(0);
|
2006-07-09 00:40:01 +02:00
|
|
|
glEnable(GL_BLEND);
|
2011-07-20 21:48:06 +02:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadMatrixf(territoryTexture.GetMinimapTextureMatrix());
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2006-07-09 00:40:01 +02:00
|
|
|
|
2011-07-20 21:48:06 +02:00
|
|
|
DrawTexture(1.0f, angle, x, y, x2, y2, z);
|
2006-08-28 00:51:53 +02:00
|
|
|
|
2011-07-20 21:48:06 +02:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2006-07-09 00:40:01 +02:00
|
|
|
glDisable(GL_BLEND);
|
2011-07-20 21:48:06 +02:00
|
|
|
|
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();
|
|
|
|
losTexture.BindTexture(0);
|
2005-10-19 08:11:21 +02:00
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PRIMARY_COLOR_ARB);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
2011-02-03 02:12:24 +01:00
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_ONE_MINUS_SRC_ALPHA);
|
2005-10-19 08:11:21 +02:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glColor3f(0.0f, 0.0f, 0.0f);
|
2011-02-03 02:12:24 +01:00
|
|
|
|
|
|
|
glMatrixMode(GL_TEXTURE);
|
2011-02-03 03:33:37 +01:00
|
|
|
glLoadMatrixf(losTexture.GetMinimapTextureMatrix());
|
2011-02-03 02:12:24 +01:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
|
|
|
DrawTexture(1.0f, angle, x, y, x2, y2, z);
|
|
|
|
|
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
2005-10-19 08:11:21 +02:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
2010-10-25 23:59:52 +02:00
|
|
|
// Set up the matrix for drawing points and lines
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(x, y, z);
|
|
|
|
// Rotate around the center of the map
|
|
|
|
glTranslatef((x2-x)/2.f, (y2-y)/2.f, 0.f);
|
2011-05-27 05:04:59 +02:00
|
|
|
// Scale square maps to fit in circular minimap area
|
|
|
|
float unitScale = (cmpRangeManager->GetLosCircular() ? 1.f : m_MapScale/2.f);
|
|
|
|
glScalef(unitScale, unitScale, 1.f);
|
2010-10-25 23:59:52 +02:00
|
|
|
glRotatef(angle * 180.f/M_PI, 0.f, 0.f, 1.f);
|
|
|
|
glTranslatef(-(x2-x)/2.f, -(y2-y)/2.f, 0.f);
|
|
|
|
|
2006-08-28 00:51:53 +02:00
|
|
|
PROFILE_START("minimap units");
|
|
|
|
|
|
|
|
// Don't enable GL_POINT_SMOOTH because it's far too slow
|
|
|
|
// (~70msec/frame on a GF4 rendering a thousand points)
|
|
|
|
glPointSize(3.f);
|
|
|
|
|
2012-01-12 13:51:10 +01:00
|
|
|
float sx = (float)m_Width / ((m_MapSize - 1) * TERRAIN_TILE_SIZE);
|
|
|
|
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
|
|
|
|
|
|
|
std::vector<MinimapUnitVertex> vertexArray;
|
|
|
|
vertexArray.reserve(ents.size());
|
|
|
|
|
2010-05-20 20:09:23 +02:00
|
|
|
for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it)
|
2010-04-23 20:36:48 +02:00
|
|
|
{
|
2010-05-20 20:09:23 +02:00
|
|
|
MinimapUnitVertex v;
|
|
|
|
ICmpMinimap* cmpMinimap = static_cast<ICmpMinimap*>(it->second);
|
2010-09-23 14:13:13 +02:00
|
|
|
entity_pos_t posX, posZ;
|
|
|
|
if (cmpMinimap->GetRenderData(v.r, v.g, v.b, posX, posZ))
|
2010-04-23 20:36:48 +02:00
|
|
|
{
|
2010-09-23 14:13:13 +02:00
|
|
|
ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(it->first, g_Game->GetPlayerID());
|
|
|
|
if (vis != ICmpRangeManager::VIS_HIDDEN)
|
|
|
|
{
|
|
|
|
v.a = 255;
|
2010-10-25 23:59:52 +02:00
|
|
|
v.x = posX.ToFloat()*sx;
|
|
|
|
v.y = -posZ.ToFloat()*sy;
|
2010-09-23 14:13:13 +02:00
|
|
|
vertexArray.push_back(v);
|
|
|
|
}
|
2005-05-13 03:15:53 +02:00
|
|
|
}
|
2010-04-23 20:36:48 +02:00
|
|
|
}
|
2006-08-28 00:51:53 +02:00
|
|
|
|
2010-04-23 20:36:48 +02:00
|
|
|
if (!vertexArray.empty())
|
2006-08-28 00:51:53 +02:00
|
|
|
{
|
2011-10-22 12:25:09 +02:00
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(MinimapUnitVertex), &vertexArray[0].x);
|
|
|
|
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(MinimapUnitVertex), &vertexArray[0].r);
|
|
|
|
|
2006-08-28 00:51:53 +02:00
|
|
|
glDrawArrays(GL_POINTS, 0, (GLsizei)vertexArray.size());
|
|
|
|
|
|
|
|
glDisableClientState(GL_COLOR_ARRAY);
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
2005-10-19 08:11:21 +02:00
|
|
|
}
|
2006-08-28 00:51:53 +02:00
|
|
|
|
|
|
|
PROFILE_END("minimap units");
|
2005-10-19 08:11:21 +02:00
|
|
|
|
2005-10-19 19:16:34 +02:00
|
|
|
DrawViewRect();
|
2006-01-07 02:04:26 +01:00
|
|
|
|
2010-10-25 23:59:52 +02:00
|
|
|
glPopMatrix();
|
|
|
|
|
2012-02-08 21:43:38 +01:00
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPopMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2012-01-29 21:04:21 +01:00
|
|
|
glPopMatrix();
|
|
|
|
|
2005-10-19 08:11:21 +02:00
|
|
|
// Reset everything back to normal
|
|
|
|
glPointSize(1.0f);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
2012-02-09 21:45:19 +01:00
|
|
|
glDepthMask(1);
|
2004-10-08 03:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-02-09 18:55:25 +01:00
|
|
|
#endif // CONFIG2_GLES
|
|
|
|
|
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;
|
2012-02-09 18:55:25 +01:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_TextureSize, m_TextureSize, 0, GL_BGRA_EXT, 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;
|
2006-01-07 02:04:26 +01:00
|
|
|
float 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;
|
|
|
|
|
2005-05-13 03:15:53 +02:00
|
|
|
for(u32 j = 0; j < h; j++)
|
|
|
|
{
|
2005-10-19 05:02:51 +02:00
|
|
|
u32 *dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x;
|
2005-05-13 03:15:53 +02:00
|
|
|
for(u32 i = 0; i < w; i++)
|
|
|
|
{
|
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;
|
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
if(avgHeight < 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
|
|
|
|
*dataPtr++ = 0xff5078a0;
|
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
|
|
|
|
2005-10-19 05:02:51 +02:00
|
|
|
CMiniPatch *mp = m_Terrain->GetTile(x + i, y + j);
|
2010-05-28 01:31:03 +02:00
|
|
|
if(mp)
|
2005-10-09 05:43:03 +02:00
|
|
|
{
|
2010-09-04 23:26:52 +02:00
|
|
|
CTerrainTextureEntry *tex = mp->GetTextureEntry();
|
2009-11-08 17:49:52 +01:00
|
|
|
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);
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_MapSize - 1, m_MapSize - 1, GL_BGRA_EXT, GL_UNSIGNED_BYTE, m_TerrainData);
|
2004-10-08 03:10:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMiniMap::Destroy()
|
|
|
|
{
|
2005-10-19 05:02:51 +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
|
|
|
|
2011-02-03 02:12:24 +01:00
|
|
|
delete[] m_TerrainData;
|
|
|
|
m_TerrainData = 0;
|
2004-10-08 03:10:14 +02:00
|
|
|
}
|