forked from 0ad/0ad
# Display units on the minimap
This was SVN commit r7480.
This commit is contained in:
parent
29b458da40
commit
f4ad5906c9
@ -18,6 +18,15 @@ Player.prototype.Init = function()
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Player.prototype.GetColour = function()
|
||||||
|
{
|
||||||
|
// TODO: need proper colour support
|
||||||
|
if (this.playerID == 1)
|
||||||
|
return { "r": 0.0, "g": 0.0, "b": 1.0, "a": 1.0 };
|
||||||
|
else
|
||||||
|
return { "r": 1.0, "g": 0.0, "b": 0.0, "a": 1.0 };
|
||||||
|
};
|
||||||
|
|
||||||
Player.prototype.SetPlayerID = function(id)
|
Player.prototype.SetPlayerID = function(id)
|
||||||
{
|
{
|
||||||
this.playerID = id;
|
this.playerID = id;
|
||||||
|
@ -45,7 +45,8 @@
|
|||||||
#include "simulation/EntityTemplate.h"
|
#include "simulation/EntityTemplate.h"
|
||||||
#include "simulation/LOSManager.h"
|
#include "simulation/LOSManager.h"
|
||||||
#include "simulation/TerritoryManager.h"
|
#include "simulation/TerritoryManager.h"
|
||||||
|
#include "simulation2/Simulation2.h"
|
||||||
|
#include "simulation2/components/ICmpMinimap.h"
|
||||||
|
|
||||||
bool g_TerrainModified = false;
|
bool g_TerrainModified = false;
|
||||||
bool g_GameRestarted = false;
|
bool g_GameRestarted = false;
|
||||||
@ -397,13 +398,6 @@ void CMiniMap::Draw()
|
|||||||
|
|
||||||
PROFILE_START("minimap units");
|
PROFILE_START("minimap units");
|
||||||
|
|
||||||
// Draw unit points
|
|
||||||
const std::vector<CUnit *> &units = m_UnitManager->GetUnits();
|
|
||||||
std::vector<CUnit *>::const_iterator iter = units.begin();
|
|
||||||
CUnit *unit = 0;
|
|
||||||
CVector2D pos;
|
|
||||||
CLOSManager* losMgr = g_Game->GetWorld()->GetLOSManager();
|
|
||||||
|
|
||||||
std::vector<MinimapUnitVertex> vertexArray;
|
std::vector<MinimapUnitVertex> vertexArray;
|
||||||
// TODO: don't reallocate this after every frame (but don't waste memory
|
// TODO: don't reallocate this after every frame (but don't waste memory
|
||||||
// after the number of units decreases substantially)
|
// after the number of units decreases substantially)
|
||||||
@ -412,6 +406,35 @@ void CMiniMap::Draw()
|
|||||||
// (~70msec/frame on a GF4 rendering a thousand points)
|
// (~70msec/frame on a GF4 rendering a thousand points)
|
||||||
glPointSize(3.f);
|
glPointSize(3.f);
|
||||||
|
|
||||||
|
if (g_UseSimulation2)
|
||||||
|
{
|
||||||
|
float sx = m_scaleX / CELL_SIZE;
|
||||||
|
float sy = m_scaleY / CELL_SIZE;
|
||||||
|
|
||||||
|
CSimulation2* sim = g_Game->GetSimulation2();
|
||||||
|
const CSimulation2::InterfaceList& ents = sim->GetEntitiesWithInterface(IID_Minimap);
|
||||||
|
for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it)
|
||||||
|
{
|
||||||
|
MinimapUnitVertex v;
|
||||||
|
ICmpMinimap* cmpMinimap = static_cast<ICmpMinimap*>(it->second);
|
||||||
|
if (cmpMinimap->GetRenderData(v.r, v.g, v.b, v.x, v.y))
|
||||||
|
{
|
||||||
|
v.a = 255;
|
||||||
|
v.x = x + v.x*sx;
|
||||||
|
v.y = y - v.y*sy;
|
||||||
|
vertexArray.push_back(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Draw unit points
|
||||||
|
const std::vector<CUnit *> &units = m_UnitManager->GetUnits();
|
||||||
|
std::vector<CUnit *>::const_iterator iter = units.begin();
|
||||||
|
CUnit *unit = 0;
|
||||||
|
CVector2D pos;
|
||||||
|
CLOSManager* losMgr = g_Game->GetWorld()->GetLOSManager();
|
||||||
|
|
||||||
for(; iter != units.end(); ++iter)
|
for(; iter != units.end(); ++iter)
|
||||||
{
|
{
|
||||||
unit = (CUnit *)(*iter);
|
unit = (CUnit *)(*iter);
|
||||||
@ -445,8 +468,9 @@ void CMiniMap::Draw()
|
|||||||
vertexArray.push_back(v);
|
vertexArray.push_back(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (vertexArray.size())
|
if (!vertexArray.empty())
|
||||||
{
|
{
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(0, 0, z);
|
glTranslatef(0, 0, z);
|
||||||
|
@ -59,6 +59,9 @@ COMPONENT(Footprint)
|
|||||||
INTERFACE(GuiInterface)
|
INTERFACE(GuiInterface)
|
||||||
COMPONENT(GuiInterfaceScripted)
|
COMPONENT(GuiInterfaceScripted)
|
||||||
|
|
||||||
|
INTERFACE(Minimap)
|
||||||
|
COMPONENT(Minimap)
|
||||||
|
|
||||||
INTERFACE(Motion)
|
INTERFACE(Motion)
|
||||||
COMPONENT(MotionBall)
|
COMPONENT(MotionBall)
|
||||||
COMPONENT(MotionScripted)
|
COMPONENT(MotionScripted)
|
||||||
|
173
source/simulation2/components/CCmpMinimap.cpp
Normal file
173
source/simulation2/components/CCmpMinimap.cpp
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
/* Copyright (C) 2010 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "precompiled.h"
|
||||||
|
|
||||||
|
#include "simulation2/system/Component.h"
|
||||||
|
#include "ICmpMinimap.h"
|
||||||
|
|
||||||
|
#include "simulation2/components/ICmpPlayerManager.h"
|
||||||
|
#include "simulation2/components/ICmpPlayer.h"
|
||||||
|
#include "simulation2/MessageTypes.h"
|
||||||
|
|
||||||
|
#include "ps/Overlay.h"
|
||||||
|
|
||||||
|
class CCmpMinimap : public ICmpMinimap
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void ClassInit(CComponentManager& componentManager)
|
||||||
|
{
|
||||||
|
componentManager.SubscribeToMessageType(MT_PositionChanged);
|
||||||
|
componentManager.SubscribeToMessageType(MT_OwnershipChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFAULT_COMPONENT_ALLOCATOR(Minimap)
|
||||||
|
|
||||||
|
bool m_Active;
|
||||||
|
bool m_UsePlayerColour;
|
||||||
|
u8 m_R, m_G, m_B;
|
||||||
|
entity_pos_t m_X, m_Z; // cache the latest position for more efficient rendering
|
||||||
|
|
||||||
|
static std::string GetSchema()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
"<element name='Type'>"
|
||||||
|
"<choice>"
|
||||||
|
"<value>food</value>"
|
||||||
|
"<value>wood</value>"
|
||||||
|
"<value>stone</value>"
|
||||||
|
"<value>metal</value>"
|
||||||
|
"<value>structure</value>"
|
||||||
|
"<value>settlement</value>"
|
||||||
|
"<value>unit</value>"
|
||||||
|
"<value>support</value>"
|
||||||
|
"<value>hero</value>"
|
||||||
|
"</choice>"
|
||||||
|
"</element>"
|
||||||
|
"<optional>"
|
||||||
|
"<element name='Colour'>"
|
||||||
|
"<attribute name='r'>"
|
||||||
|
"<data type='integer'><param name='minInclusive'>0</param><param name='maxInclusive'>255</param></data>"
|
||||||
|
"</attribute>"
|
||||||
|
"<attribute name='g'>"
|
||||||
|
"<data type='integer'><param name='minInclusive'>0</param><param name='maxInclusive'>255</param></data>"
|
||||||
|
"</attribute>"
|
||||||
|
"<attribute name='b'>"
|
||||||
|
"<data type='integer'><param name='minInclusive'>0</param><param name='maxInclusive'>255</param></data>"
|
||||||
|
"</attribute>"
|
||||||
|
"</element>"
|
||||||
|
"</optional>";
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Init(const CSimContext& context, const CParamNode& paramNode)
|
||||||
|
{
|
||||||
|
m_Active = true;
|
||||||
|
|
||||||
|
const CParamNode& colour = paramNode.GetChild("Colour");
|
||||||
|
if (colour.IsOk())
|
||||||
|
{
|
||||||
|
m_UsePlayerColour = false;
|
||||||
|
m_R = colour.GetChild("@r").ToInt();
|
||||||
|
m_G = colour.GetChild("@g").ToInt();
|
||||||
|
m_B = colour.GetChild("@b").ToInt();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_UsePlayerColour = true;
|
||||||
|
// Choose a bogus colour which will get replaced once we have an owner
|
||||||
|
m_R = 255;
|
||||||
|
m_G = 0;
|
||||||
|
m_B = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Deinit(const CSimContext& UNUSED(context))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Serialize(ISerializer& serialize)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Deserialize(const CSimContext& context, const CParamNode& paramNode, IDeserializer& deserialize)
|
||||||
|
{
|
||||||
|
Init(context, paramNode);
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void HandleMessage(const CSimContext& context, const CMessage& msg, bool UNUSED(global))
|
||||||
|
{
|
||||||
|
switch (msg.GetType())
|
||||||
|
{
|
||||||
|
case MT_PositionChanged:
|
||||||
|
{
|
||||||
|
const CMessagePositionChanged& data = static_cast<const CMessagePositionChanged&> (msg);
|
||||||
|
|
||||||
|
if (data.inWorld)
|
||||||
|
{
|
||||||
|
m_Active = true;
|
||||||
|
m_X = data.x;
|
||||||
|
m_Z = data.z;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_Active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MT_OwnershipChanged:
|
||||||
|
{
|
||||||
|
if (!m_UsePlayerColour)
|
||||||
|
break;
|
||||||
|
|
||||||
|
const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg);
|
||||||
|
|
||||||
|
// Find the new player's colour
|
||||||
|
CmpPtr<ICmpPlayerManager> cmpPlayerManager(context, SYSTEM_ENTITY);
|
||||||
|
if (cmpPlayerManager.null())
|
||||||
|
break;
|
||||||
|
CmpPtr<ICmpPlayer> cmpPlayer(context, cmpPlayerManager->GetPlayerByID(msgData.to));
|
||||||
|
if (cmpPlayer.null())
|
||||||
|
break;
|
||||||
|
CColor colour = cmpPlayer->GetColour();
|
||||||
|
m_R = (int)(colour.r*255.0);
|
||||||
|
m_G = (int)(colour.g*255.0);
|
||||||
|
m_B = (int)(colour.b*255.0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool GetRenderData(u8& r, u8& g, u8& b, float& x, float& z)
|
||||||
|
{
|
||||||
|
if (!m_Active)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
r = m_R;
|
||||||
|
g = m_G;
|
||||||
|
b = m_B;
|
||||||
|
x = m_X.ToFloat();
|
||||||
|
z = m_Z.ToFloat();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
REGISTER_COMPONENT_TYPE(Minimap)
|
25
source/simulation2/components/ICmpMinimap.cpp
Normal file
25
source/simulation2/components/ICmpMinimap.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* Copyright (C) 2010 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "precompiled.h"
|
||||||
|
|
||||||
|
#include "ICmpMinimap.h"
|
||||||
|
|
||||||
|
#include "simulation2/system/InterfaceScripted.h"
|
||||||
|
|
||||||
|
BEGIN_INTERFACE_WRAPPER(Minimap)
|
||||||
|
END_INTERFACE_WRAPPER(Minimap)
|
39
source/simulation2/components/ICmpMinimap.h
Normal file
39
source/simulation2/components/ICmpMinimap.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* Copyright (C) 2010 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INCLUDED_ICMPMINIMAP
|
||||||
|
#define INCLUDED_ICMPMINIMAP
|
||||||
|
|
||||||
|
#include "simulation2/system/Interface.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per-unit minimap data.
|
||||||
|
*/
|
||||||
|
class ICmpMinimap : public IComponent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Get the data for rendering this entity on the minimap.
|
||||||
|
* If it should not be drawn, returns false; otherwise the arguments are set
|
||||||
|
* to the colour and world position.
|
||||||
|
*/
|
||||||
|
virtual bool GetRenderData(u8& r, u8& g, u8& b, float& x, float& z) = 0;
|
||||||
|
|
||||||
|
DECLARE_INTERFACE_TYPE(Minimap)
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // INCLUDED_ICMPMINIMAP
|
@ -22,6 +22,8 @@
|
|||||||
#include "simulation2/system/InterfaceScripted.h"
|
#include "simulation2/system/InterfaceScripted.h"
|
||||||
#include "simulation2/scripting/ScriptComponent.h"
|
#include "simulation2/scripting/ScriptComponent.h"
|
||||||
|
|
||||||
|
#include "ps/Overlay.h"
|
||||||
|
|
||||||
BEGIN_INTERFACE_WRAPPER(Player)
|
BEGIN_INTERFACE_WRAPPER(Player)
|
||||||
END_INTERFACE_WRAPPER(Player)
|
END_INTERFACE_WRAPPER(Player)
|
||||||
|
|
||||||
@ -34,6 +36,11 @@ public:
|
|||||||
{
|
{
|
||||||
m_Script.CallVoid("SetName", name);
|
m_Script.CallVoid("SetName", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual CColor GetColour()
|
||||||
|
{
|
||||||
|
return m_Script.Call<CColor>("GetColour");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_COMPONENT_SCRIPT_WRAPPER(PlayerScripted)
|
REGISTER_COMPONENT_SCRIPT_WRAPPER(PlayerScripted)
|
||||||
|
@ -20,10 +20,12 @@
|
|||||||
|
|
||||||
#include "simulation2/system/Interface.h"
|
#include "simulation2/system/Interface.h"
|
||||||
|
|
||||||
|
struct CColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Player data.
|
* Player data.
|
||||||
* (This interface only includes the functions needed by native code for loading maps;
|
* (This interface only includes the functions needed by native code for loading maps,
|
||||||
* most player interaction is handled by scripts instead.)
|
* and for minimap rendering; most player interaction is handled by scripts instead.)
|
||||||
*/
|
*/
|
||||||
class ICmpPlayer : public IComponent
|
class ICmpPlayer : public IComponent
|
||||||
{
|
{
|
||||||
@ -31,6 +33,8 @@ public:
|
|||||||
virtual void SetName(const std::wstring& name) = 0;
|
virtual void SetName(const std::wstring& name) = 0;
|
||||||
// TODO: some more data
|
// TODO: some more data
|
||||||
|
|
||||||
|
virtual CColor GetColour() = 0;
|
||||||
|
|
||||||
DECLARE_INTERFACE_TYPE(Player)
|
DECLARE_INTERFACE_TYPE(Player)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -34,6 +34,11 @@ public:
|
|||||||
{
|
{
|
||||||
m_Script.CallVoid("AddPlayer", (int)ent);
|
m_Script.CallVoid("AddPlayer", (int)ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual entity_id_t GetPlayerByID(int32_t id)
|
||||||
|
{
|
||||||
|
return m_Script.Call<entity_id_t>("GetPlayerByID", (int)id);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_COMPONENT_SCRIPT_WRAPPER(PlayerManagerScripted)
|
REGISTER_COMPONENT_SCRIPT_WRAPPER(PlayerManagerScripted)
|
||||||
|
@ -28,7 +28,7 @@ class ICmpPlayerManager : public IComponent
|
|||||||
public:
|
public:
|
||||||
virtual void AddPlayer(entity_id_t ent) = 0;
|
virtual void AddPlayer(entity_id_t ent) = 0;
|
||||||
|
|
||||||
// Accessors are currently only available to scripts, since no C++ code needed them yet
|
virtual entity_id_t GetPlayerByID(int32_t id) = 0;
|
||||||
|
|
||||||
DECLARE_INTERFACE_TYPE(PlayerManager)
|
DECLARE_INTERFACE_TYPE(PlayerManager)
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user