Changeset View
Changeset View
Standalone 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 11 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 All 9 Lines | |||||
#include "graphics/UnitManager.h" | #include "graphics/UnitManager.h" | ||||
#include "maths/BoundingSphere.h" | #include "maths/BoundingSphere.h" | ||||
#include "maths/Matrix3D.h" | #include "maths/Matrix3D.h" | ||||
#include "maths/Vector3D.h" | #include "maths/Vector3D.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/GameSetup/Config.h" | #include "ps/GameSetup/Config.h" | ||||
#include "renderer/Scene.h" | #include "renderer/Scene.h" | ||||
#include <boost/algorithm/string.hpp> | |||||
class CCmpVisualActor : public ICmpVisual | class CCmpVisualActor : public ICmpVisual | ||||
{ | { | ||||
public: | public: | ||||
static void ClassInit(CComponentManager& componentManager) | static void ClassInit(CComponentManager& componentManager) | ||||
{ | { | ||||
componentManager.SubscribeToMessageType(MT_InterpolatedPositionChanged); | componentManager.SubscribeToMessageType(MT_InterpolatedPositionChanged); | ||||
componentManager.SubscribeToMessageType(MT_OwnershipChanged); | componentManager.SubscribeToMessageType(MT_OwnershipChanged); | ||||
componentManager.SubscribeToMessageType(MT_ValueModification); | componentManager.SubscribeToMessageType(MT_ValueModification); | ||||
▲ Show 20 Lines • Show All 400 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); | ||||
/// 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::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); | boost::replace_all(base, L"{phenotype}", cmpIdentity->GetPhenotype()); | ||||
while (pos != std::string::npos) | boost::replace_all(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? | |||||
// 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... | |||||
CmpPtr<ICmpOwnership> cmpOwnership(GetEntityHandle()); | |||||
if (cmpOwnership) | |||||
{ | |||||
player_id_t ownerId = cmpOwnership->GetOwner(); | |||||
if (ownerId != INVALID_PLAYER) | |||||
{ | |||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity()); | |||||
if (cmpPlayerManager) | |||||
{ | { | ||||
base.replace(pos, pattern.size(), cmpIdentity->GetPhenotype()); | CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(ownerId)); | ||||
pos = base.find(pattern, pos + pattern.size()); | if (cmpPlayer) | ||||
boost::replace_all(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