Emergency 2017 Dokumentation  v3.0.1
qsf::PrototypeManager Class Reference

Prototype manager class. More...

#include <PrototypeManager.h>

Public Member Functions

PrototypecreatePrototypeById (uint64 id)
 Create a new and empty prototype instance. More...
 
PrototypecreatePrototypeClone (const Prototype &originalPrototype, uint64 prototypeId, bool copyOverrideState)
 Create a new prototype instance by cloning from another prototype. More...
 
void destroyAllPrototypes ()
 Destroy all prototypes within this prototype manager. More...
 
std::string generateUnusedPrototypeName (const std::string &firstPart)
 Return a prototype name that is not used by another prototype. More...
 
PrototypecreatePrefabCloneByGlobalAssetId (const Prototype &originalPrototype, uint64 prototypeId, bool copyOverrideState, GlobalAssetId globalPrefabAssetId)
 Create a new prefab instance by cloning from another prefab. More...
 
GlobalAssetId getPrefabGlobalAssetIdByPrototypeId (uint64 id) const
 Return the global asset ID by using a given prototype ID. More...
 
LocalAssetId getPrefabLocalAssetIdByPrototypeId (uint64 id) const
 Return the local asset ID by using a given prototype ID. More...
 
PrototypegetPrefabByGlobalAssetId (GlobalAssetId globalAssetId, bool load=true)
 Return a prefab's main prototype instance by using its global asset ID. More...
 
PrototypegetPrefabByLocalAssetId (const StringHash &stringHash, bool load=true)
 Return a prefab's main prototype instance by using its local asset ID. More...
 
bool destroyPrefabById (uint64 id)
 Destroy a prefab instance by using its main prototype unique ID. More...
 
bool destroyPrefabByGlobalAssetId (GlobalAssetId globalPrefabAssetId)
 Destroy a prefab instance by using its global asset identifier. More...
 
bool savePrefabByFilename (Prototype &mainPrototype, const std::string &filename, bool differenceToDefault=true) const
 Save a prefab by using a given filename. More...
 
virtual bool destroyPrototypeById (uint64 id) override
 Destroy a prototype instance by using its ID. More...
 
virtual bool changePrototypeId (uint64 oldId, uint64 newId) override
 Change a prototype's ID. More...
 
- Public Member Functions inherited from qsf::BasePrototypeManager
uint32 getId () const
 Return the unique prototype manager identifier. More...
 
ComponentManagergetComponentManager () const
 Return the component manager. More...
 
PrototypegetPrototypeById (uint64 id) const
 Return a prototype instance by using its local asset ID. More...
 
const PrototypeHashMapgetPrototypes () const
 Return the prototype list. More...
 
uint64 generatePrototypeId ()
 Generate a new unused prototype ID. More...
 
void applyIdMatchingMap (const Prototype &toPrototype, const UniqueIdMap &uniqueIdMap)
 Apply prototype ID matching map. More...
 
void buildIdMatchingMapWithGeneratedIds (const Prototype &fromPrototype, UniqueIdMap &outUniqueIdMap, std::vector< const Prototype * > *outFromPrototypes=nullptr, bool followAllLinks=false)
 Build prototype ID matching map with newly generated unique IDs as targets. More...
 
void buildIdMatchingMapWithUntranslatedIds (const Prototype &fromPrototype, UniqueIdMap &outUniqueIdMap, std::vector< const Prototype * > *outFromPrototypes=nullptr, bool followAllLinks=false)
 Build prototype ID matching map of all child prototype IDs to themselves. More...
 
virtual bool containsEntities () const
 

Protected Member Functions

virtual PrototypecreatePrototypeInstance (uint64 id) override
 
virtual uint64 generatePrototypeIdInternal () override
 
- Protected Member Functions inherited from qsf::BasePrototypeManager
 BasePrototypeManager (uint32 id)
 Constructor. More...
 
virtual ~BasePrototypeManager ()
 Destructor. More...
 
void reservePrototypes (size_t numberOfPrototypes)
 Reserve prototypes. More...
 
PrototypecreatePrototype ()
 Create a new and empty prototype instance. More...
 
PrototypecreatePrototypeById (uint64 id)
 Create a new and empty prototype instance. More...
 
PrototypeunregisterPrototypeById (uint64 id)
 Unregister a prototype from this manager. More...
 
void unregisterAllPrototypes ()
 Unregister all prototypes, i.e. clear internal management. More...
 
void pushLastPrototypeToFront ()
 
- Protected Member Functions inherited from qsf::Manager
 Manager ()
 Default constructor. More...
 
virtual ~Manager ()
 Destructor. More...
 

Friends

class PrototypeSystem
 

Additional Inherited Members

- Public Types inherited from qsf::BasePrototypeManager
typedef std::unordered_map< uint64, uint64UniqueIdMap
 Maps unique IDs, e.g. of prototypes in one prefab or object to another. More...
 
- Static Public Member Functions inherited from qsf::BasePrototypeManager
static void fillIdMatchingMap (const Prototype &fromPrototype, const Prototype &toPrototype, UniqueIdMap &outUniqueIdMap)
 Fill prototype ID matching map. More...
 

Detailed Description

Prototype manager class.

Remarks
The following example shows how to get the instance of a certain prefab main prototype:
qsf::Prototype* prototype = QSF_MAINPROTOTYPE.getPrefabByLocalAssetId("sample/prefab/vehicle/ambulance");
Note
  • The order of the prototype instances inside the prototype manager does not matter
See also
  • "qsf::Prototype" class documentation for information about the prototype concept, e.g. for how to get component instances

Definition at line 57 of file PrototypeManager.h.

Member Function Documentation

virtual bool qsf::PrototypeManager::changePrototypeId ( uint64  oldId,
uint64  newId 
)
overridevirtual

Change a prototype's ID.

Parameters
[in]oldIdThe prototype's current ID
[in]newIdThe new ID to assign to the prototype
Returns
"true" if all went fine, else "false" (unknown prototype identifier?)
Note
  • Use with care: all references to the old prototype ID will become invalid

Reimplemented from qsf::BasePrototypeManager.

Prototype* qsf::PrototypeManager::createPrefabCloneByGlobalAssetId ( const Prototype originalPrototype,
uint64  prototypeId,
bool  copyOverrideState,
GlobalAssetId  globalPrefabAssetId 
)

Create a new prefab instance by cloning from another prefab.

Returns
The created prototype instance; you are responsible for destroying the instance
Note
  • Use this method only in case you know exactly what you are doing
Prototype * qsf::PrototypeManager::createPrototypeById ( uint64  id)
inline

Create a new and empty prototype instance.

Parameters
[in]idThe ID to assign to the new prototype
Returns
The created prototype instance, null pointer on error (unique prototype identifier already used?), do no destroy the returned instance and do need keep a reference to it outside the C runtime stack (use the unique prototype ID instead)
Note
  • The new prototype instance has no components at all. There's e.g. no "qsf::MetadataComponent"-instance holding the human readable unique prefab name. We have to be able to use customized "qsf::MetadataComponent"-versions, so we can't build something like that into the QSF core.

Definition at line 14 of file PrototypeManager-inl.h.

Prototype* qsf::PrototypeManager::createPrototypeClone ( const Prototype originalPrototype,
uint64  prototypeId,
bool  copyOverrideState 
)

Create a new prototype instance by cloning from another prototype.

Returns
The created prototype instance; you are responsible for destroying the instance
Note
  • Use this method only in case you know exactly what you are doing
virtual Prototype* qsf::PrototypeManager::createPrototypeInstance ( uint64  id)
overrideprotectedvirtual
void qsf::PrototypeManager::destroyAllPrototypes ( )

Destroy all prototypes within this prototype manager.

bool qsf::PrototypeManager::destroyPrefabByGlobalAssetId ( GlobalAssetId  globalPrefabAssetId)

Destroy a prefab instance by using its global asset identifier.

Parameters
[in]globalPrefabAssetIdThe global prefab asset identifier
Returns
"true" if all went fine, else "false" (unknown prefab identifier?)
Note
  • Does not destroy linked prefabs
bool qsf::PrototypeManager::destroyPrefabById ( uint64  id)

Destroy a prefab instance by using its main prototype unique ID.

Parameters
[in]idThe prototype unique ID
Returns
"true" if all went fine, else "false" (unknown prototype ID?)
virtual bool qsf::PrototypeManager::destroyPrototypeById ( uint64  id)
overridevirtual

Destroy a prototype instance by using its ID.

Parameters
[in]idThe prototype's ID
Returns
"true" if all went fine, else "false" (unknown prototype identifier?)
Note
  • Does not destroy linked prototypes

Reimplemented from qsf::BasePrototypeManager.

virtual uint64 qsf::PrototypeManager::generatePrototypeIdInternal ( )
overrideprotectedvirtual
std::string qsf::PrototypeManager::generateUnusedPrototypeName ( const std::string &  firstPart)

Return a prototype name that is not used by another prototype.

Parameters
[in]firstPartThe first part of the desired prototype name, it will be expanded by a number
Returns
A free name that can be used for a new prototyep
Prototype* qsf::PrototypeManager::getPrefabByGlobalAssetId ( GlobalAssetId  globalAssetId,
bool  load = true 
)

Return a prefab's main prototype instance by using its global asset ID.

Parameters
[in]globalAssetIdThe global prefab asset ID
[in]loadIn case the prefab is not loaded, yet, do automatically load it?
Returns
The requested main prototype instance, null pointer on error
Note
  • In case there's no instance of the given asset, yet, an instance will be created on-the-fly
Prototype* qsf::PrototypeManager::getPrefabByLocalAssetId ( const StringHash stringHash,
bool  load = true 
)

Return a prefab's main prototype instance by using its local asset ID.

Parameters
[in]stringHashThe local prefab asset ID generated by "qsf::StringHash" (example: "sample/prefab/vehicle/ambulance")
[in]loadIn case the prefab is not loaded, yet, do automatically load it?
Returns
The requested main prototype instance, null pointer on error
Note
  • In case there's no instance of the given asset, yet, an instance will be created on-the-fly
GlobalAssetId qsf::PrototypeManager::getPrefabGlobalAssetIdByPrototypeId ( uint64  id) const

Return the global asset ID by using a given prototype ID.

Parameters
[in]idThe prototype unique ID
Returns
The requested global asset ID, "qsf::getUninitialized<GlobalAssetId>()" on error
LocalAssetId qsf::PrototypeManager::getPrefabLocalAssetIdByPrototypeId ( uint64  id) const

Return the local asset ID by using a given prototype ID.

Parameters
[in]idThe prototype unique ID
Returns
The requested local asset ID, "qsf::getUninitialized<LocalAssetId>()" on error
bool qsf::PrototypeManager::savePrefabByFilename ( Prototype mainPrototype,
const std::string &  filename,
bool  differenceToDefault = true 
) const

Save a prefab by using a given filename.

Parameters
[in]mainPrototypeMain prototype of the prefab to save
[in]filenameUTF-8 filename in platform-independent notation of the prototype to save
[in]differenceToDefaultDo not save properties which have the default value (meaning we already know its value without having to read it when loading)
Returns
"true" if all went fine, else "false"
Todo:
  • TODO(co) For now, we only support JSON

Friends And Related Function Documentation

friend class PrototypeSystem
friend

Definition at line 64 of file PrototypeManager.h.


The documentation for this class was generated from the following files: