Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpMinimap.cpp
Show All 26 Lines | |||||
#include "ps/Shapes.h" | #include "ps/Shapes.h" | ||||
class CCmpMinimap : public ICmpMinimap | class CCmpMinimap : public ICmpMinimap | ||||
{ | { | ||||
public: | public: | ||||
static void ClassInit(CComponentManager& componentManager) | static void ClassInit(CComponentManager& componentManager) | ||||
{ | { | ||||
componentManager.SubscribeToMessageType(MT_PlayerColorChanged); | |||||
componentManager.SubscribeToMessageType(MT_PositionChanged); | componentManager.SubscribeToMessageType(MT_PositionChanged); | ||||
componentManager.SubscribeToMessageType(MT_OwnershipChanged); | componentManager.SubscribeToMessageType(MT_OwnershipChanged); | ||||
componentManager.SubscribeToMessageType(MT_MinimapPing); | componentManager.SubscribeToMessageType(MT_MinimapPing); | ||||
} | } | ||||
DEFAULT_COMPONENT_ALLOCATOR(Minimap) | DEFAULT_COMPONENT_ALLOCATOR(Minimap) | ||||
// Template state: | // Template state: | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | public: | ||||
virtual void Deinit() | virtual void Deinit() | ||||
{ | { | ||||
} | } | ||||
template<typename S> | template<typename S> | ||||
void SerializeCommon(S& serialize) | void SerializeCommon(S& serialize) | ||||
{ | { | ||||
if (m_UsePlayerColor) | |||||
{ | |||||
serialize.NumberU8_Unbounded("r", m_R); | |||||
serialize.NumberU8_Unbounded("g", m_G); | |||||
serialize.NumberU8_Unbounded("b", m_B); | |||||
} | |||||
serialize.Bool("active", m_Active); | serialize.Bool("active", m_Active); | ||||
if (m_Active) | if (m_Active) | ||||
{ | { | ||||
serialize.NumberFixed_Unbounded("x", m_X); | serialize.NumberFixed_Unbounded("x", m_X); | ||||
serialize.NumberFixed_Unbounded("z", m_Z); | serialize.NumberFixed_Unbounded("z", m_Z); | ||||
} | } | ||||
} | } | ||||
Show All 37 Lines | case MT_OwnershipChanged: | ||||
break; | break; | ||||
const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg); | const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg); | ||||
// If there's no new owner (e.g. the unit is dying) then don't try updating the color | // If there's no new owner (e.g. the unit is dying) then don't try updating the color | ||||
if (msgData.to == INVALID_PLAYER) | if (msgData.to == INVALID_PLAYER) | ||||
break; | break; | ||||
// Find the new player's color | UpdatePlayerColor(msgData.to); | ||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity()); | |||||
if (!cmpPlayerManager) | |||||
break; | break; | ||||
CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(msgData.to)); | } | ||||
if (!cmpPlayer) | case MT_PlayerColorChanged: | ||||
{ | |||||
if (!m_UsePlayerColor) | |||||
break; | break; | ||||
CColor color = cmpPlayer->GetColor(); | |||||
m_R = (u8)(color.r*255.0); | const CMessagePlayerColorChanged& msgData = static_cast<const CMessagePlayerColorChanged&> (msg); | ||||
m_G = (u8)(color.g*255.0); | |||||
m_B = (u8)(color.b*255.0); | CmpPtr<ICmpOwnership> cmpOwnership(GetEntityHandle()); | ||||
// TODO: probably should avoid using floating-point here | |||||
if (!cmpOwnership || msgData.player != cmpOwnership->GetOwner()) | |||||
break; | |||||
UpdatePlayerColor(msgData.player); | |||||
break; | break; | ||||
} | } | ||||
case MT_MinimapPing: | case MT_MinimapPing: | ||||
{ | { | ||||
CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId()); | CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId()); | ||||
if (!cmpOwnership || cmpOwnership->GetOwner() != (player_id_t)GetSimContext().GetCurrentDisplayedPlayer()) | if (!cmpOwnership || cmpOwnership->GetOwner() != (player_id_t)GetSimContext().GetCurrentDisplayedPlayer()) | ||||
break; | break; | ||||
Show All 31 Lines | virtual bool CheckPing(double currentTime, double pingDuration) | ||||
else if (currentTime > m_PingEndTime) | else if (currentTime > m_PingEndTime) | ||||
{ | { | ||||
m_IsPinging = false; | m_IsPinging = false; | ||||
m_PingEndTime = 0; | m_PingEndTime = 0; | ||||
} | } | ||||
return m_IsPinging; | return m_IsPinging; | ||||
} | } | ||||
void UpdatePlayerColor(player_id_t player) | |||||
{ | |||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity()); | |||||
if (!cmpPlayerManager) | |||||
return; | |||||
CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(player)); | |||||
if (!cmpPlayer) | |||||
return; | |||||
CColor color = cmpPlayer->GetColor(); | |||||
m_R = (u8)(color.r*255.0); | |||||
m_G = (u8)(color.g*255.0); | |||||
m_B = (u8)(color.b*255.0); | |||||
// TODO: probably should avoid using floating-point here | |||||
elexis: spaces between operators
(Gah who put CColor into `Shapes.h`)
.r .g .b are floats, so .0 not… | |||||
Not Done Inline ActionsWasn't my TODO, just moved it to a new place. (rP10017) temple: Wasn't my TODO, just moved it to a new place. (rP10017) | |||||
} | |||||
}; | }; | ||||
REGISTER_COMPONENT_TYPE(Minimap) | REGISTER_COMPONENT_TYPE(Minimap) |
Wildfire Games · Phabricator
spaces between operators
(Gah who put CColor into Shapes.h)
.r .g .b are floats, so .0 not needed
TODO can be dropped?