Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpVisualActor.cpp
Show All 20 Lines | |||||
#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 "ICmpUnitRenderer.h" | ||||
#include "ICmpOwnership.h" | #include "ICmpOwnership.h" | ||||
#include "ICmpPlayer.h" | |||||
#include "ICmpPlayerManager.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 "ICmpValueModificationManager.h" | #include "ICmpValueModificationManager.h" | ||||
#include "ICmpVisibility.h" | #include "ICmpVisibility.h" | ||||
#include "ICmpSound.h" | #include "ICmpSound.h" | ||||
▲ Show 20 Lines • Show All 425 Lines • ▼ Show 20 Lines | virtual void SelectAnimation(const std::string& name, bool once = false, fixed speed = fixed::FromInt(1)) | ||||
CmpPtr<ICmpSound> cmpSound(GetEntityHandle()); | CmpPtr<ICmpSound> cmpSound(GetEntityHandle()); | ||||
if (cmpSound) | if (cmpSound) | ||||
m_SoundGroup = cmpSound->GetSoundGroup(wstring_from_utf8(m_AnimName)); | m_SoundGroup = cmpSound->GetSoundGroup(wstring_from_utf8(m_AnimName)); | ||||
if (!m_Unit || !m_Unit->GetAnimation() || !m_Unit->GetID()) | if (!m_Unit || !m_Unit->GetAnimation() || !m_Unit->GetID()) | ||||
return; | return; | ||||
m_Unit->GetAnimation()->SetAnimationState(m_AnimName, m_AnimOnce, m_AnimSpeed.ToFloat(), m_AnimDesync.ToFloat(), m_SoundGroup.c_str()); | m_Unit->GetAnimation()->SetAnimationState(m_AnimName, m_AnimOnce, m_AnimSpeed.ToFloat(), m_AnimDesync.ToFloat(), m_SoundGroup.c_str()); | ||||
} | } | ||||
virtual void SelectMovementAnimation(const std::string& name, fixed speed) | virtual void SelectMovementAnimation(const std::string& name, fixed speed) | ||||
{ | { | ||||
ENSURE(name == "idle" || name == "walk" || name == "run"); | ENSURE(name == "idle" || name == "walk" || name == "run"); | ||||
if (m_AnimName != "idle" && m_AnimName != "walk" && m_AnimName != "run") | if (m_AnimName != "idle" && m_AnimName != "walk" && m_AnimName != "run") | ||||
return; | return; | ||||
SelectAnimation(name, false, speed); | SelectAnimation(name, false, speed); | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | virtual void Hotload(const VfsPath& name) | ||||
if (name != m_ActorName) | if (name != m_ActorName) | ||||
return; | return; | ||||
ReloadActor(); | ReloadActor(); | ||||
} | } | ||||
private: | private: | ||||
// Replace {phenotype} with the correct value in m_ActorName | // Replace {phenotype} and {civ} with the correct value in m_ActorName | ||||
void ParseActorName(std::wstring base); | void ParseActorName(std::wstring base); | ||||
void ReplacePatternInString(std::wstring& base, std::wstring pattern, std::wstring value) const; | |||||
/// Helper function shared by component init and actor reloading | /// Helper function shared by component init and actor reloading | ||||
void InitModel(); | void InitModel(); | ||||
/// Helper method; initializes the model selection shape descriptor from XML. Factored out for readability of @ref Init. | /// Helper method; initializes the model selection shape descriptor from XML. Factored out for readability of @ref Init. | ||||
void InitSelectionShapeDescriptor(const CParamNode& paramNode); | void InitSelectionShapeDescriptor(const CParamNode& paramNode); | ||||
// ReloadActor is used when the actor or seed changes. | // ReloadActor is used when the actor or seed changes. | ||||
void ReloadActor(); | void ReloadActor(); | ||||
// ReloadUnitAnimation is used for a minimal reloading upon deserialization, when the actor and seed are identical. | // ReloadUnitAnimation is used for a minimal reloading upon deserialization, when the actor and seed are identical. | ||||
// It is also used by ReloadActor. | // It is also used by ReloadActor. | ||||
void ReloadUnitAnimation(); | void ReloadUnitAnimation(); | ||||
}; | }; | ||||
REGISTER_COMPONENT_TYPE(VisualActor) | REGISTER_COMPONENT_TYPE(VisualActor) | ||||
// ------------------------------------------------------------------------------------------------------------------ | // ------------------------------------------------------------------------------------------------------------------ | ||||
void CCmpVisualActor::ReplacePatternInString(std::wstring& base, std::wstring pattern, std::wstring value) const | |||||
{ | |||||
size_t pos = base.find(pattern); | |||||
while (pos != std::string::npos) | |||||
{ | |||||
base.replace(pos, pattern.size(), value); | |||||
pos = base.find(pattern, pos + pattern.size()); | |||||
} | |||||
} | |||||
void CCmpVisualActor::ParseActorName(std::wstring base) | void CCmpVisualActor::ParseActorName(std::wstring base) | ||||
{ | { | ||||
CmpPtr<ICmpIdentity> cmpIdentity(GetEntityHandle()); | CmpPtr<ICmpIdentity> cmpIdentity(GetEntityHandle()); | ||||
const std::wstring pattern = L"{phenotype}"; | |||||
if (cmpIdentity) | if (cmpIdentity) | ||||
{ | { | ||||
size_t pos = base.find(pattern); | ReplacePatternInString(base, L"{phenotype}", cmpIdentity->GetPhenotype()); | ||||
while (pos != std::string::npos) | ReplacePatternInString(base, L"{civ}", cmpIdentity->GetCiv()); | ||||
} | |||||
else | |||||
{ | { | ||||
bb: So in this case all `phenotypes` will stay? sounds like trouble | |||||
Done Inline ActionsNo identity no phenotype? Stan: No identity no phenotype? | |||||
base.replace(pos, pattern.size(), cmpIdentity->GetPhenotype()); | // Template might have no civ but might be owned by something that does. | ||||
Done Inline ActionsSo captured entities will show the old-civs actor, is that intended? (could be dunno) If I understand the checkrefs script well, then this else block should never do something right? bb: So captured entities will show the old-civs actor, is that intended? (could be dunno)
If I… | |||||
Done Inline ActionsI guess I need to do that on ownership changed too then. Stan: I guess I need to do that on ownership changed too then. | |||||
Done Inline Actionsthat too, but if the ent has an identity component, this code will not be executed... bb: that too, but if the ent has an identity component, this code will not be executed... | |||||
pos = base.find(pattern, pos + pattern.size()); | CmpPtr<ICmpOwnership> cmpOwnership(GetEntityHandle()); | ||||
if (cmpOwnership) | |||||
{ | |||||
player_id_t ownerId = cmpOwnership->GetOwner(); | |||||
if (ownerId != INVALID_PLAYER) | |||||
{ | |||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity()); | |||||
if (cmpPlayerManager) | |||||
{ | |||||
CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(ownerId)); | |||||
if (cmpPlayer) | |||||
ReplacePatternInString(base, L"{civ}", cmpPlayer->GetCiv()); | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
m_ActorName = base; | m_ActorName = base; | ||||
} | } | ||||
void CCmpVisualActor::InitModel() | void CCmpVisualActor::InitModel() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 191 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
So in this case all phenotypes will stay? sounds like trouble