CmGameObjectManager.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmModule.h"
  4. #include "CmGameObject.h"
  5. namespace CamelotFramework
  6. {
  7. class CM_EXPORT GameObjectManager : public Module<GameObjectManager>
  8. {
  9. public:
  10. GameObjectManager();
  11. ~GameObjectManager();
  12. GameObjectHandleBase registerObject(const std::shared_ptr<GameObject>& object);
  13. void unregisterObject(const GameObjectHandleBase& object);
  14. GameObjectHandleBase getObject(UINT64 id) const;
  15. bool objectExists(UINT64 id) const;
  16. /************************************************************************/
  17. /* DESERIALIZATION */
  18. /************************************************************************/
  19. // Note: GameObjects need a bit of special handling when it comes to deserialization,
  20. // which is what this part of the code is used for. It performs two main actions:
  21. // - 1. Resolves all GameObjectHandles on deserialization end
  22. // - We can't just resolve them as we go because during deserialization not all objects
  23. // have necessarily been created.
  24. // - 2. Maps serialized IDs to actual in-engine ids.
  25. /**
  26. * @brief Needs to be called whenever GameObject deserialization starts. Must be followed
  27. * by notifyDeserializationEnded call.
  28. */
  29. void notifyDeserializationStarted(GameObject* object);
  30. /**
  31. * @brief Needs to be called whenever GameObject deserialization ends. Must be preceded
  32. * by notifyDeserializationStarted call.
  33. */
  34. void notifyDeserializationEnded(GameObject* object);
  35. /**
  36. * @brief Registers an id that was deserialized, and has been remapped to
  37. * an actual in-engine ID. This will be used when resolving GameObjectHandles
  38. * (since they might point to the invalid deserialized id).
  39. */
  40. void registerDeserializedId(UINT64 deserializedId, UINT64 actualId);
  41. /**
  42. * @brief Queues the specified handle and resolves it when deserialization ends.
  43. */
  44. void registerUnresolvedHandle(const GameObjectHandleBase& object);
  45. private:
  46. UINT64 mNextAvailableID; // 0 is not a valid ID
  47. Map<UINT64, GameObjectHandleBase>::type mObjects;
  48. GameObject* mActiveDeserializedObject;
  49. bool mIsDeserializationActive;
  50. Map<UINT64, UINT64>::type mIdMapping;
  51. Vector<GameObjectHandleBase>::type mUnresolvedHandles;
  52. };
  53. }