Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/CCmpVisualActor.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 9 Lines | |||||
#include "simulation2/system/Component.h" | #include "simulation2/system/Component.h" | ||||
#include "ICmpVisual.h" | #include "ICmpVisual.h" | ||||
#include "simulation2/MessageTypes.h" | #include "simulation2/MessageTypes.h" | ||||
#include "ICmpFootprint.h" | #include "ICmpFootprint.h" | ||||
#include "ICmpIdentity.h" | #include "ICmpIdentity.h" | ||||
#include "ICmpUnitRenderer.h" | #include "ICmpMirage.h" | ||||
#include "ICmpOwnership.h" | #include "ICmpOwnership.h" | ||||
#include "ICmpPosition.h" | #include "ICmpPosition.h" | ||||
#include "ICmpTemplateManager.h" | #include "ICmpTemplateManager.h" | ||||
#include "ICmpTerrain.h" | #include "ICmpTerrain.h" | ||||
#include "ICmpUnitMotion.h" | #include "ICmpUnitMotion.h" | ||||
#include "ICmpUnitRenderer.h" | |||||
#include "ICmpValueModificationManager.h" | #include "ICmpValueModificationManager.h" | ||||
#include "ICmpVisibility.h" | #include "ICmpVisibility.h" | ||||
#include "ICmpSound.h" | #include "ICmpSound.h" | ||||
#include "simulation2/serialization/SerializeTemplates.h" | #include "simulation2/serialization/SerializeTemplates.h" | ||||
#include "graphics/Decal.h" | #include "graphics/Decal.h" | ||||
#include "graphics/Frustum.h" | #include "graphics/Frustum.h" | ||||
▲ Show 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)) | virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)) | ||||
{ | { | ||||
switch (msg.GetType()) | switch (msg.GetType()) | ||||
{ | { | ||||
case MT_OwnershipChanged: | case MT_OwnershipChanged: | ||||
{ | { | ||||
RecomputeActorName(); | |||||
if (!m_Unit) | if (!m_Unit) | ||||
break; | break; | ||||
const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg); | const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg); | ||||
m_Unit->GetModel().SetPlayerID(msgData.to); | m_Unit->GetModel().SetPlayerID(msgData.to); | ||||
break; | break; | ||||
} | } | ||||
case MT_TerrainChanged: | case MT_TerrainChanged: | ||||
{ | { | ||||
if (!m_Unit) | if (!m_Unit) | ||||
break; | break; | ||||
const CMessageTerrainChanged& msgData = static_cast<const CMessageTerrainChanged&> (msg); | const CMessageTerrainChanged& msgData = static_cast<const CMessageTerrainChanged&> (msg); | ||||
m_Unit->GetModel().SetTerrainDirty(msgData.i0, msgData.j0, msgData.i1, msgData.j1); | m_Unit->GetModel().SetTerrainDirty(msgData.i0, msgData.j0, msgData.i1, msgData.j1); | ||||
break; | break; | ||||
} | } | ||||
case MT_ValueModification: | case MT_ValueModification: | ||||
{ | { | ||||
// Mirages don't respond to technology modifications. | |||||
CmpPtr<ICmpMirage> cmpMirage(GetEntityHandle()); | |||||
if (cmpMirage) | |||||
return; | |||||
const CMessageValueModification& msgData = static_cast<const CMessageValueModification&> (msg); | const CMessageValueModification& msgData = static_cast<const CMessageValueModification&> (msg); | ||||
if (msgData.component != L"VisualActor") | if (msgData.component != L"VisualActor") | ||||
break; | break; | ||||
CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity()); | |||||
std::wstring newActorName; | RecomputeActorName(); | ||||
if (m_IsFoundationActor) | |||||
newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/FoundationActor", m_BaseActorName, GetEntityId()); | |||||
else | |||||
newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/Actor", m_BaseActorName, GetEntityId()); | |||||
if (newActorName != m_ActorName) | |||||
{ | |||||
ParseActorName(newActorName); | |||||
ReloadActor(); | |||||
} | |||||
break; | break; | ||||
} | } | ||||
case MT_InterpolatedPositionChanged: | case MT_InterpolatedPositionChanged: | ||||
{ | { | ||||
const CMessageInterpolatedPositionChanged& msgData = static_cast<const CMessageInterpolatedPositionChanged&> (msg); | const CMessageInterpolatedPositionChanged& msgData = static_cast<const CMessageInterpolatedPositionChanged&> (msg); | ||||
if (m_ModelTag.valid()) | if (m_ModelTag.valid()) | ||||
{ | { | ||||
CmpPtr<ICmpUnitRenderer> cmpModelRenderer(GetSystemEntity()); | CmpPtr<ICmpUnitRenderer> cmpModelRenderer(GetSystemEntity()); | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | public: | ||||
{ | { | ||||
if (seed == m_Seed) | if (seed == m_Seed) | ||||
return; | return; | ||||
m_Seed = seed; | m_Seed = seed; | ||||
ReloadActor(); | ReloadActor(); | ||||
} | } | ||||
virtual void RecomputeActorName() | |||||
{ | |||||
CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity()); | |||||
std::wstring newActorName; | |||||
if (m_IsFoundationActor) | |||||
newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/FoundationActor", m_BaseActorName, GetEntityId()); | |||||
else | |||||
newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/Actor", m_BaseActorName, GetEntityId()); | |||||
if (newActorName != m_ActorName) | |||||
{ | |||||
ParseActorName(newActorName); | |||||
ReloadActor(); | |||||
} | |||||
} | |||||
virtual bool HasConstructionPreview() const | virtual bool HasConstructionPreview() const | ||||
{ | { | ||||
return m_ConstructionPreview; | return m_ConstructionPreview; | ||||
} | } | ||||
virtual void Hotload(const VfsPath& name) | virtual void Hotload(const VfsPath& name) | ||||
{ | { | ||||
if (!m_Unit) | if (!m_Unit) | ||||
▲ Show 20 Lines • Show All 239 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator