Pyrogenesis  trunk
ObjectManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2009 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_OBJECTMANAGER
19 #define INCLUDED_OBJECTMANAGER
20 
21 #include <vector>
22 #include <map>
23 #include <set>
24 
25 #include "ps/CStr.h"
26 #include "lib/file/vfs/vfs_path.h"
27 
28 class CMeshManager;
29 class CObjectBase;
30 class CObjectEntry;
32 class CSimulation2;
33 class CTerrain;
34 
35 ///////////////////////////////////////////////////////////////////////////////////////////
36 // CObjectManager: manager class for all possible actor types
38 {
40 public:
41  // Unique identifier of an actor variation
42  struct ObjectKey
43  {
44  ObjectKey(const CStrW& name, const std::vector<u8>& var)
45  : ActorName(name), ActorVariation(var) {}
46 
47  bool operator< (const CObjectManager::ObjectKey& a) const;
48 
49  private:
50  CStrW ActorName;
51  std::vector<u8> ActorVariation;
52  };
53 
54 public:
55 
56  // constructor, destructor
57  CObjectManager(CMeshManager& meshManager, CSkeletonAnimManager& skeletonAnimManager, CSimulation2& simulation);
59 
60  // Provide access to the manager classes for meshes and animations - they're
61  // needed when objects are being created and so this seems like a convenient
62  // place to centralise access.
65 
66  void UnloadObjects();
67 
68  CObjectEntry* FindObject(const CStrW& objname);
69  void DeleteObject(CObjectEntry* entry);
70 
71  CObjectBase* FindObjectBase(const CStrW& objname);
72 
73  CObjectEntry* FindObjectVariation(const CStrW& objname, const std::vector<std::set<CStr> >& selections);
74  CObjectEntry* FindObjectVariation(CObjectBase* base, const std::vector<std::set<CStr> >& selections);
75 
76  /**
77  * Get the terrain object that actors managed by this manager should be linked
78  * with (primarily for the purpose of decals)
79  */
81 
82  /**
83  * Reload any scripts that were loaded from the given filename.
84  * (This is used to implement hotloading.)
85  */
86  Status ReloadChangedFile(const VfsPath& path);
87 
88 private:
92 
93  std::map<ObjectKey, CObjectEntry*> m_Objects;
94  std::map<CStrW, CObjectBase*> m_ObjectBases;
95 };
96 
97 #endif
CObjectEntry * FindObject(const CStrW &objname)
Definition: ObjectManager.cpp:95
CObjectBase * FindObjectBase(const CStrW &objname)
Definition: ObjectManager.cpp:66
Definition: ObjectManager.h:37
std::vector< u8 > ActorVariation
Definition: ObjectManager.h:51
Definition: Terrain.h:51
ObjectKey(const CStrW &name, const std::vector< u8 > &var)
Definition: ObjectManager.h:44
CSkeletonAnimManager & GetSkeletonAnimManager() const
Definition: ObjectManager.h:64
Public API for simulation system.
Definition: Simulation2.h:47
Status ReloadChangedFile(const VfsPath &path)
Reload any scripts that were loaded from the given filename.
Definition: ObjectManager.cpp:182
CTerrain * GetTerrain()
Get the terrain object that actors managed by this manager should be linked with (primarily for the p...
Definition: ObjectManager.cpp:150
CMeshManager & GetMeshManager() const
Definition: ObjectManager.h:63
CMeshManager & m_MeshManager
Definition: ObjectManager.h:89
CObjectEntry * FindObjectVariation(const CStrW &objname, const std::vector< std::set< CStr > > &selections)
Definition: ObjectManager.cpp:101
Definition: path.h:77
~CObjectManager()
Definition: ObjectManager.cpp:58
CSkeletonAnimManager & m_SkeletonAnimManager
Definition: ObjectManager.h:90
i64 Status
Error handling system.
Definition: status.h:171
std::map< CStrW, CObjectBase * > m_ObjectBases
Definition: ObjectManager.h:94
bool operator<(const CObjectManager::ObjectKey &a) const
Definition: ObjectManager.cpp:34
void UnloadObjects()
Definition: ObjectManager.cpp:171
Definition: SkeletonAnimManager.h:37
Definition: ObjectBase.h:37
Definition: MeshManager.h:31
void DeleteObject(CObjectEntry *entry)
Definition: ObjectManager.cpp:158
std::map< ObjectKey, CObjectEntry * > m_Objects
Definition: ObjectManager.h:93
NONCOPYABLE(CObjectManager)
CObjectManager(CMeshManager &meshManager, CSkeletonAnimManager &skeletonAnimManager, CSimulation2 &simulation)
Definition: ObjectManager.cpp:49
CSimulation2 & m_Simulation
Definition: ObjectManager.h:91
CStrW ActorName
Definition: ObjectManager.h:50
Definition: ObjectEntry.h:38
Definition: ObjectManager.h:42