Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/ObjectManager.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
CObjectManager::CObjectManager(CMeshManager& meshManager, CSkeletonAnimManager& skeletonAnimManager, CSimulation2& simulation) | CObjectManager::CObjectManager(CMeshManager& meshManager, CSkeletonAnimManager& skeletonAnimManager, CSimulation2& simulation) | ||||
: m_MeshManager(meshManager), m_SkeletonAnimManager(skeletonAnimManager), m_Simulation(simulation) | : m_MeshManager(meshManager), m_SkeletonAnimManager(skeletonAnimManager), m_Simulation(simulation) | ||||
{ | { | ||||
RegisterFileReloadFunc(ReloadChangedFileCB, this); | RegisterFileReloadFunc(ReloadChangedFileCB, this); | ||||
m_QualityHook = std::make_unique<CConfigDBHook>(g_ConfigDB.RegisterHookAndCall("max_actor_quality", [this]() { ActorQualityChanged(); })); | m_QualityHook = std::make_unique<CConfigDBHook>(g_ConfigDB.RegisterHookAndCall("max_actor_quality", [this]() { ActorQualityChanged(); })); | ||||
m_VariantDiversityHook = std::make_unique<CConfigDBHook>(g_ConfigDB.RegisterHookAndCall("variant_diversity", [this]() { VariantDiversityChanged(); })); | |||||
if (!CXeromyces::AddValidator(g_VFS, "actor", "art/actors/actor.rng")) | if (!CXeromyces::AddValidator(g_VFS, "actor", "art/actors/actor.rng")) | ||||
LOGERROR("CObjectManager: failed to load actor grammar file 'art/actors/actor.rng'"); | LOGERROR("CObjectManager: failed to load actor grammar file 'art/actors/actor.rng'"); | ||||
} | } | ||||
CObjectManager::~CObjectManager() | CObjectManager::~CObjectManager() | ||||
{ | { | ||||
UnloadObjects(); | UnloadObjects(); | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | |||||
CTerrain* CObjectManager::GetTerrain() | CTerrain* CObjectManager::GetTerrain() | ||||
{ | { | ||||
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY); | CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY); | ||||
if (!cmpTerrain) | if (!cmpTerrain) | ||||
return NULL; | return NULL; | ||||
return cmpTerrain->GetCTerrain(); | return cmpTerrain->GetCTerrain(); | ||||
} | } | ||||
CObjectManager::VariantDiversity CObjectManager::GetVariantDiversity() const | |||||
{ | |||||
return m_VariantDiversity; | |||||
} | |||||
void CObjectManager::UnloadObjects() | void CObjectManager::UnloadObjects() | ||||
{ | { | ||||
m_Objects.clear(); | m_Objects.clear(); | ||||
m_ActorDefs.clear(); | m_ActorDefs.clear(); | ||||
} | } | ||||
Status CObjectManager::ReloadChangedFile(const VfsPath& path) | Status CObjectManager::ReloadChangedFile(const VfsPath& path) | ||||
{ | { | ||||
Show All 32 Lines | void CObjectManager::ActorQualityChanged() | ||||
// No need to reload entries or actors, but we do need to reload all units. | // No need to reload entries or actors, but we do need to reload all units. | ||||
const CSimulation2::InterfaceListUnordered& cmps = m_Simulation.GetEntitiesWithInterfaceUnordered(IID_Visual); | const CSimulation2::InterfaceListUnordered& cmps = m_Simulation.GetEntitiesWithInterfaceUnordered(IID_Visual); | ||||
for (CSimulation2::InterfaceListUnordered::const_iterator eit = cmps.begin(); eit != cmps.end(); ++eit) | for (CSimulation2::InterfaceListUnordered::const_iterator eit = cmps.begin(); eit != cmps.end(); ++eit) | ||||
static_cast<ICmpVisual*>(eit->second)->Hotload(); | static_cast<ICmpVisual*>(eit->second)->Hotload(); | ||||
// Trigger an interpolate call - needed because the game is generally paused & models disappear otherwise. | // Trigger an interpolate call - needed because the game is generally paused & models disappear otherwise. | ||||
m_Simulation.Interpolate(0.f, 0.f, 0.f); | m_Simulation.Interpolate(0.f, 0.f, 0.f); | ||||
} | } | ||||
void CObjectManager::VariantDiversityChanged() | |||||
{ | |||||
CStr value; | |||||
CFG_GET_VAL("variant_diversity", value); | |||||
VariantDiversity variantDiversity = VariantDiversity::FULL; | |||||
if (value == "none") | |||||
variantDiversity = VariantDiversity::NONE; | |||||
else if (value == "limited") | |||||
variantDiversity = VariantDiversity::LIMITED; | |||||
// Otherwise assume full. | |||||
if (variantDiversity == m_VariantDiversity) | |||||
return; | |||||
m_VariantDiversity = variantDiversity; | |||||
// Mark old entries as outdated so we don't reload them from the cache. | |||||
for (std::pair<const ObjectKey, Hotloadable<CObjectEntry>>& object : m_Objects) | |||||
object.second.outdated = true; | |||||
// Reload actors. | |||||
for (std::pair<const CStrW, Hotloadable<CActorDef>>& actor : m_ActorDefs) | |||||
actor.second.outdated = true; | |||||
// Reload visual actor components. | |||||
const CSimulation2::InterfaceListUnordered& cmps = m_Simulation.GetEntitiesWithInterfaceUnordered(IID_Visual); | |||||
for (CSimulation2::InterfaceListUnordered::const_iterator eit = cmps.begin(); eit != cmps.end(); ++eit) | |||||
static_cast<ICmpVisual*>(eit->second)->Hotload(); | |||||
// Trigger an interpolate call - needed because the game is generally paused & models disappear otherwise. | |||||
m_Simulation.Interpolate(0.f, 0.f, 0.f); | |||||
} |
Wildfire Games · Phabricator