Changeset View
Standalone View
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 209 Lines • ▼ Show 20 Lines | void SerializeCommon(S& serialize) | ||||
serialize.NumberU32_Unbounded("seed", m_Seed); | serialize.NumberU32_Unbounded("seed", m_Seed); | ||||
serialize.String("actor", m_ActorName, 0, 256); | serialize.String("actor", m_ActorName, 0, 256); | ||||
// TODO: store actor variables? | // TODO: store actor variables? | ||||
} | } | ||||
virtual void Serialize(ISerializer& serialize) | virtual void Serialize(ISerializer& serialize) | ||||
{ | { | ||||
// TODO: store the actor name, if !debug and it differs from the template | // TODO: store the actor name, if !debug and it differs from the template | ||||
leper: Now I do wonder why that comment is here, given that we do serialize `m_ActorName` in… | |||||
Not Done Inline ActionsSandarac: I took a look at the history, and it seems this comment simply wasn't removed/updated when… | |||||
Not Done Inline Actions@wraitii still accurate? Stan: @wraitii still accurate? | |||||
if (serialize.IsDebug()) | if (serialize.IsDebug()) | ||||
{ | { | ||||
serialize.String("base actor", m_BaseActorName, 0, 256); | serialize.String("base actor", m_BaseActorName, 0, 256); | ||||
} | } | ||||
SerializeCommon(serialize); | SerializeCommon(serialize); | ||||
} | } | ||||
Show All 23 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) | ||||
Not Done Inline ActionsIsn't that needed for nonvisual? Stan: Isn't that needed for nonvisual? | |||||
Done Inline ActionsI need to move this below as actor name is serialised, and this changes serialised actor names. I might have to still use the check below though, I haven't actually checked if this worked in non-visual and it probably doesn't. wraitii: I need to move this below as actor name is serialised, and this changes serialised actor names. | |||||
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: | ||||
Not Done Inline Actionsternary? Stan: ternary? | |||||
Done Inline ActionsMeh, line too long for that to really improve readability. wraitii: Meh, line too long for that to really improve readability. | |||||
{ | { | ||||
if (!m_Unit) | if (!m_Unit) | ||||
break; | break; | ||||
Done Inline Actionsdebug code left in, need to delete this obviously wraitii: debug code left in, need to delete this obviously | |||||
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. | |||||
Not Done Inline ActionsCan this be another patch? Should be mostly straightforward. Stan: Can this be another patch? Should be mostly straightforward. | |||||
Done Inline ActionsI mean it can, but it also makes sense as part of this patch, doesn't it? wraitii: I mean it can, but it also makes sense as part of this patch, doesn't it? | |||||
Not Done Inline ActionsI guess, but if it's an optimization, it could be profiled in it's own patch :D Stan: I guess, but if it's an optimization, it could be profiled in it's own patch :D | |||||
Done Inline ActionsIt's not an optimisation, it's a bug fix. Otherwise, a fogged entity that receives a ValueModification will update its actor, so you can actually see in FOW that the actor changed, which is not correct. wraitii: It's not an optimisation, it's a bug fix.
Otherwise, a fogged entity that receives a… | |||||
Not Done Inline ActionsCan't we do this more upstream? Like in the ModifiersManager, don't send the message when it is a mirage? For I guess mirages should never respond to tech modifications? Freagarach: Can't we do this more upstream? Like in the ModifiersManager, don't send the message when it is… | |||||
Done Inline ActionsSome modifications affect whole templates, so I don't think we can, but you're correct that it's a design footgun :/ wraitii: Some modifications affect whole templates, so I don't think we can, but you're correct that… | |||||
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()); | |||||
Done Inline ActionsThis needs to be done regardless of whether m_Unit is valid or not, otherwise we will have differences when trying to do a non-visual replay or a serialization test (both of which will result in m_Unit not being valid. leper: This needs to be done regardless of whether `m_Unit` is valid or not, otherwise we will have… | |||||
Not Done Inline ActionsOkay. Sandarac: Okay. | |||||
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 |
Now I do wonder why that comment is here, given that we do serialize m_ActorName in SerializeCommon. Care to investigate?