Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/ObjectManager.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2022 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 "graphics/ObjectBase.h" | #include "graphics/ObjectBase.h" | ||||
#include "graphics/ObjectEntry.h" | #include "graphics/ObjectEntry.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/ConfigDB.h" | #include "ps/ConfigDB.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/World.h" | |||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/components/ICmpTerrain.h" | |||||
#include "simulation2/components/ICmpVisual.h" | #include "simulation2/components/ICmpVisual.h" | ||||
bool CObjectManager::ObjectKey::operator< (const CObjectManager::ObjectKey& a) const | bool CObjectManager::ObjectKey::operator< (const CObjectManager::ObjectKey& a) const | ||||
{ | { | ||||
if (ObjectBaseIdentifier < a.ObjectBaseIdentifier) | if (ObjectBaseIdentifier < a.ObjectBaseIdentifier) | ||||
return true; | return true; | ||||
else if (ObjectBaseIdentifier > a.ObjectBaseIdentifier) | else if (ObjectBaseIdentifier > a.ObjectBaseIdentifier) | ||||
return false; | return false; | ||||
else | else | ||||
return ActorVariation < a.ActorVariation; | return ActorVariation < a.ActorVariation; | ||||
} | } | ||||
static Status ReloadChangedFileCB(void* param, const VfsPath& path) | static Status ReloadChangedFileCB(void* param, const VfsPath& path) | ||||
{ | { | ||||
return static_cast<CObjectManager*>(param)->ReloadChangedFile(path); | return static_cast<CObjectManager*>(param)->ReloadChangedFile(path); | ||||
} | } | ||||
CObjectManager::CObjectManager(CMeshManager& meshManager, CSkeletonAnimManager& skeletonAnimManager, CSimulation2& simulation) | CObjectManager::CObjectManager(CMeshManager& meshManager, CSkeletonAnimManager& skeletonAnimManager, CWorld& world, CSimulation2& simulation) | ||||
: m_MeshManager(meshManager), m_SkeletonAnimManager(skeletonAnimManager), m_Simulation(simulation) | : m_MeshManager(meshManager), m_SkeletonAnimManager(skeletonAnimManager), m_World(world), 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(); })); | 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'"); | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | CObjectEntry* CObjectManager::FindObjectVariation(const std::shared_ptr<CObjectBase>& base, const std::vector<const std::set<CStr>*>& completeSelections) | ||||
std::vector<u8> choices = base->CalculateVariationKey(completeSelections); | std::vector<u8> choices = base->CalculateVariationKey(completeSelections); | ||||
ObjectKey key (base->GetIdentifier(), choices); | ObjectKey key (base->GetIdentifier(), choices); | ||||
decltype(m_Objects)::iterator it = m_Objects.find(key); | decltype(m_Objects)::iterator it = m_Objects.find(key); | ||||
if (it != m_Objects.end() && !it->second.outdated) | if (it != m_Objects.end() && !it->second.outdated) | ||||
return it->second.obj.get(); | return it->second.obj.get(); | ||||
// If it hasn't been loaded, load it now. | // If it hasn't been loaded, load it now. | ||||
std::unique_ptr<CObjectEntry> obj = std::make_unique<CObjectEntry>(base, m_Simulation); | std::unique_ptr<CObjectEntry> obj = std::make_unique<CObjectEntry>(base); | ||||
// TODO (for some efficiency): use the pre-calculated choices for this object, | // TODO (for some efficiency): use the pre-calculated choices for this object, | ||||
// which has already worked out what to do for props, instead of passing the | // which has already worked out what to do for props, instead of passing the | ||||
// selections into BuildVariation and having it recalculate the props' choices. | // selections into BuildVariation and having it recalculate the props' choices. | ||||
if (!obj->BuildVariation(completeSelections, choices, *this)) | if (!obj->BuildVariation(completeSelections, choices, *this)) | ||||
return nullptr; | return nullptr; | ||||
return m_Objects.insert_or_assign(key, std::move(obj)).first->second.obj.get(); | return m_Objects.insert_or_assign(key, std::move(obj)).first->second.obj.get(); | ||||
} | } | ||||
CTerrain* CObjectManager::GetTerrain() | CTerrain* CObjectManager::GetTerrain() | ||||
{ | { | ||||
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY); | return m_World.GetTerrain(); | ||||
if (!cmpTerrain) | } | ||||
return NULL; | |||||
return cmpTerrain->GetCTerrain(); | CWater* CObjectManager::GetWater() | ||||
{ | |||||
return m_World.GetWater(); | |||||
} | } | ||||
CObjectManager::VariantDiversity CObjectManager::GetVariantDiversity() const | CObjectManager::VariantDiversity CObjectManager::GetVariantDiversity() const | ||||
{ | { | ||||
return m_VariantDiversity; | return m_VariantDiversity; | ||||
} | } | ||||
void CObjectManager::UnloadObjects() | void CObjectManager::UnloadObjects() | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator