18 #include "precompiled.h"
52 static unsigned int ScaleColor(
unsigned int color,
float x)
54 unsigned int r = unsigned(
float(color & 0xff) * x);
55 unsigned int g = unsigned(
float((color>>8) & 0xff) * x);
56 unsigned int b = unsigned(
float((color>>16) & 0xff) * x);
57 return (0xff000000 | r | g<<8 | b<<16);
61 m_TerrainTexture(0), m_TerrainData(0), m_MapSize(0), m_Terrain(0), m_TerrainDirty(true), m_MapScale(1.f),
62 m_EntitiesDrawn(0), m_IndexArray(GL_STATIC_DRAW), m_VertexArray(GL_DYNAMIC_DRAW),
63 m_NextBlinkTime(0.0), m_PingDuration(25.0), m_BlinkState(false)
112 (*attrPos)[0] = -10000.0f;
113 (*attrPos)[1] = -10000.0f;
120 double blinkDuration = 1.0;
126 CFG_GET_VAL(
"gui.session.minimap.blinkduration", Double, blinkDuration);
235 return -atan2(cameraIn.
X, cameraIn.
Z);
254 #warning TODO: implement minimap for GLES
277 float ViewRect[4][2];
279 for (
int i=0;i<4;i++) {
281 const float px=hitPt[i].
X;
282 const float pz=hitPt[i].
Z;
292 glEnable(GL_SCISSOR_TEST);
293 glEnable(GL_LINE_SMOOTH);
295 glColor3f(1.0f, 0.3f, 0.3f);
298 glBegin(GL_LINE_LOOP);
299 glVertex2f(ViewRect[0][0], -ViewRect[0][1]);
300 glVertex2f(ViewRect[1][0], -ViewRect[1][1]);
301 glVertex2f(ViewRect[2][0], -ViewRect[2][1]);
302 glVertex2f(ViewRect[3][0], -ViewRect[3][1]);
306 glDisable(GL_SCISSOR_TEST);
307 glDisable(GL_LINE_SMOOTH);
322 (*attrColor)[0] = v.
r;
323 (*attrColor)[1] = v.
g;
324 (*attrColor)[2] = v.
b;
325 (*attrColor)[3] = v.
a;
341 const float m = coordMax / 2.f;
344 glTexCoord2f(m*(-c + s + 1.f), m*(-c + -s + 1.f));
346 glTexCoord2f(m*(c + s + 1.f), m*(-c + s + 1.f));
347 glVertex3f(x2, y, z);
348 glTexCoord2f(m*(c + -s + 1.f), m*(c + s + 1.f));
349 glVertex3f(x2, y2, z);
350 glTexCoord2f(m*(-c + -s + 1.f), m*(c + -s + 1.f));
351 glVertex3f(x, y2, z);
389 static double last_time;
391 const bool doUpdate = cur_time - last_time > 0.5;
394 last_time = cur_time;
399 glMatrixMode(GL_PROJECTION);
402 glMatrixMode(GL_MODELVIEW);
405 glLoadMatrixf(&matrix.
_11);
417 defines.
Add(str_MINIMAP_BASE, str_1);
418 tech =
g_Renderer.GetShaderManager().LoadEffect(str_minimap,
g_Renderer.GetSystemShaderDefines(), defines);
420 shader = tech->GetShader();
435 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
436 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
437 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
450 glMatrixMode(GL_TEXTURE);
452 glMatrixMode(GL_MODELVIEW);
456 glMatrixMode(GL_TEXTURE);
458 glMatrixMode(GL_MODELVIEW);
470 defines.
Add(str_MINIMAP_LOS, str_1);
471 tech =
g_Renderer.GetShaderManager().LoadEffect(str_minimap,
g_Renderer.GetSystemShaderDefines(), defines);
473 shader = tech->GetShader();
474 shader->BindTexture(str_baseTex, losTexture.
GetTexture());
481 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
482 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
483 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PRIMARY_COLOR_ARB);
484 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
485 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
486 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
487 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_ONE_MINUS_SRC_ALPHA);
489 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
490 glColor3f(0.0f, 0.0f, 0.0f);
492 glMatrixMode(GL_TEXTURE);
494 glMatrixMode(GL_MODELVIEW);
498 glMatrixMode(GL_TEXTURE);
500 glMatrixMode(GL_MODELVIEW);
509 defines.
Add(str_MINIMAP_POINT, str_1);
510 tech =
g_Renderer.GetShaderManager().LoadEffect(str_minimap,
g_Renderer.GetSystemShaderDefines(), defines);
512 shader = tech->GetShader();
517 glTranslatef(x, y, z);
519 glTranslatef((x2-x)/2.f, (y2-y)/2.f, 0.f);
522 glScalef(unitScale, unitScale, 1.f);
523 glRotatef(angle * 180.f/
M_PI, 0.f, 0.f, 1.f);
524 glTranslatef(-(x2-x)/2.f, -(y2-y)/2.f, 0.f);
542 std::vector<MinimapUnitVertex> pingingVertices;
554 for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it)
573 pingingVertices.push_back(v);
585 for (
size_t v = 0; v < pingingVertices.size(); ++v)
587 addVertex(pingingVertices[v], attrColor, attrPos);
609 shader->AssertPointersBound();
613 glEnableClientState(GL_VERTEX_ARRAY);
614 glEnableClientState(GL_COLOR_ARRAY);
616 glDisable(GL_TEXTURE_2D);
623 glDrawElements(GL_POINTS, (GLsizei)(
m_EntitiesDrawn), GL_UNSIGNED_SHORT, indexBase);
638 defines.
Add(str_MINIMAP_LINE, str_1);
639 tech =
g_Renderer.GetShaderManager().LoadEffect(str_minimap,
g_Renderer.GetSystemShaderDefines(), defines);
641 shader = tech->GetShader();
645 glEnable(GL_TEXTURE_2D);
646 glDisableClientState(GL_VERTEX_ARRAY);
647 glDisableClientState(GL_COLOR_ARRAY);
654 glMatrixMode(GL_PROJECTION);
656 glMatrixMode(GL_MODELVIEW);
666 glEnable(GL_TEXTURE_2D);
670 #endif // CONFIG2_GLES
684 texData[i] = 0xFF000000;
685 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_TextureSize, m_TextureSize, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, texData);
689 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
690 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
691 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
692 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
705 float waterHeight =
g_Renderer.GetWaterManager()->m_WaterHeight;
709 for(
u32 j = 0; j < h; j++)
712 for(
u32 i = 0; i < w; i++)
723 *dataPtr++ = 0xff7098c0;
724 }
else if (avgHeight < waterHeight)
727 *dataPtr++ = 0xff5078a0;
732 int val = (hmap / 3) + 170;
734 u32 color = 0xFFFFFFFF;
751 *dataPtr++ =
ScaleColor(color,
float(val) / 255.0f);
An entity initialisation parameter node.
const u16 MAX_ENTITIES_DRAWN
void Add(CStrIntern name, CStrIntern value)
Add a name and associated value to the map of defines.
A simple fixed-point number class.
CTerrainTextureEntry * GetTextureEntry()
CMatrix3D GetDefaultGuiMatrix()
const ssize_t TERRAIN_TILE_SIZE
metres [world space units] per tile in x and z
void ScriptEvent(const CStr &Action)
Execute the script for a particular action.
void Destroy()
Calls Destroy on all children, and deallocates all memory.
bool IsOk() const
Returns true if this is a valid CParamNode, false if it represents a non-existent node...
VertexArrayIterator< u16 > GetIterator() const
Gets the iterator over the (only) attribute in this array, i.e. a u16.
float left
Returning CPos representing each corner.
#define CFG_GET_VAL(name, type, destination)
void RebuildTerrainTexture()
const CTerrain * m_Terrain
ssize_t GetVerticesPerSide() const
void AddAttribute(Attribute *attr)
shared_ptr< CShaderTechnique > CShaderTechniquePtr
const float * GetMinimapTextureMatrix()
Returns a matrix to map (0,0)-(1,1) texture coordinates onto texture coordinates, in the form expecte...
float GetExactGroundLevel(float x, float z) const
VertexArray::Attribute m_AttributePos
CVector3D GetWorldCoordinates(int px, int py, bool aboveWater=false) const
void BindTexture(int unit)
Recomputes the territory texture if necessary, and binds it to the requested texture unit...
#define PROFILE_END(name)
virtual void HandleMessage(SGUIMessage &Message)
virtual bool CheckPing(double currentTime, double pingDuration)=0
Return true if entity is actively pinging based on the current time.
virtual bool GetLosCircular()=0
Returns whether the LOS is restricted to a circular map.
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
virtual ELosVisibility GetLosVisibility(CEntityHandle ent, player_id_t player, bool forceRetainInFog=false)=0
Returns the visibility status of the given entity, with respect to the given player.
Public API for simulation system.
virtual float GetBufferedZ() const
Returns not the Z value, but the actual buffered Z value, i.e.
virtual bool GetRenderData(u8 &r, u8 &g, u8 &b, entity_pos_t &x, entity_pos_t &z)=0
Get the data for rendering this entity on the minimap.
CTerrain * GetTerrain()
Get the pointer to the terrain object.
static void LoadXML(CParamNode &ret, const XMBFile &file, const wchar_t *sourceIdentifier=NULL)
Loads the XML data specified by file into the node ret.
std::vector< std::pair< entity_id_t, IComponent * > > InterfaceList
float m_ShallowPassageHeight
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning...
T round_up_to_pow2(T x)
round up to next larger power of two.
const CParamNode & GetChild(const char *name) const
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none...
VertexArray::Attribute m_AttributeColor
const float HEIGHT_SCALE
metres per u16 height unit
float ToFloat() const
Parses the content of this node as a floating-point number.
CMiniPatch * GetTile(ssize_t i, ssize_t j) const
float ToFloat() const
Convert to float. May be lossy - float can't represent all values.
void GetMouseWorldCoordinates(float &x, float &z)
static unsigned int ScaleColor(unsigned int color, float x)
void DrawTexture(float coordMax, float angle, float x, float y, float x2, float y2, float z)
const CTexturePtr & GetTexture()
GLuint GetTexture()
Recomputes the LOS texture if necessary, and returns the texture handle.
GLuint GetTexture()
Recomputes the territory texture if necessary, and returns the texture handle.
void SetNumVertices(size_t num)
void AddSetting(const EGUISettingType &Type, const CStr &Name)
Add a setting to m_Settings.
#define PROFILE_START(name)
CGame * g_Game
Globally accessible pointer to the CGame object.
static bool IsInitialised()
virtual CTerritoryTexture & GetTerritoryTexture()
Return the territory texture to be used for rendering this scene.
void Skip(bool skip=true)
This method can be used to allow other event handlers to process this GUI event, by default an event ...
A simplified syntax for accessing entity components.
VertexArrayIterator< T > GetIterator() const
CRect m_CachedActualSize
Cached size, real size m_Size is actually dependent on resolution and can have different real outcome...
VertexIndexArray m_IndexArray
Made to represent screen positions and delta values.
CSimulation2 * GetSimulation2()
Get the pointer to the simulation2 object.
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
void FireWorldClickEvent(int button, int clicks)
CGameView * GetView()
Get the pointer to the game view object.
const float * GetMinimapTextureMatrix()
Returns a matrix to map (0,0)-(1,1) texture coordinates onto LOS texture coordinates, in the form expected by glLoadMatrixf.
CPos GetMousePos() const
Get Mouse from CGUI.
virtual CLOSTexture & GetLOSTexture()
Return the LOS texture to be used for rendering this scene.
InterfaceList GetEntitiesWithInterface(int iid)
Returns a list of components implementing the given interface, and their associated entities...
float GetVertexGroundLevel(ssize_t i, ssize_t j) const
bool IsGameStarted() const
Get m_GameStarted.
void BindTexture(int unit)
Recomputes the LOS texture if necessary, and binds it to the requested texture unit.
jsval get() const
Returns the current value (or JSVAL_VOID if uninitialised).
CWorld * GetWorld()
Get the pointer to the game world object.
Maintains the LOS (fog-of-war / shroud-of-darkness) texture, used for rendering and for the minimap...
bool m_MouseHovering
This is an array of true or false, each element is associated with a string representing a setting...
static void Unbind()
Unbind any currently-bound buffer, so glVertexPointer etc calls will not attempt to use it...
u16 * GetHeightMap() const
VertexArray m_VertexArray
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
EGUIMessageType type
Describes what the message regards.
void MoveCameraTarget(const CVector3D &target)
shared_ptr< CShaderProgram > CShaderProgramPtr
Maintains the territory boundary texture, used for rendering and for the minimap. ...
virtual void Draw()
Draws the object.
static void addVertex(const MinimapUnitVertex &v, VertexArrayIterator< u8[4]> &attrColor, VertexArrayIterator< float[2]> &attrPos)
double m_HalfBlinkDuration