BsCoreObjectManager.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #include "BsCoreObjectManager.h"
  5. #include "BsCoreObject.h"
  6. #include "BsException.h"
  7. namespace BansheeEngine
  8. {
  9. CoreObjectManager::CoreObjectManager()
  10. :mNextAvailableID(1)
  11. {
  12. }
  13. CoreObjectManager::~CoreObjectManager()
  14. {
  15. #if BS_DEBUG_MODE
  16. BS_LOCK_MUTEX(mObjectsMutex);
  17. if(mObjects.size() > 0)
  18. {
  19. // All objects MUST be destroyed at this point, otherwise there might be memory corruption.
  20. // (Reason: This is called on application shutdown and at that point we also unload any dynamic libraries,
  21. // which will invalidate any pointers to objects created from those libraries. Therefore we require of the user to
  22. // clean up all objects manually before shutting down the application).
  23. BS_EXCEPT(InternalErrorException, "Core object manager shut down, but not all objects were released. Application must release ALL " \
  24. "engine objects before shutdown.");
  25. }
  26. #endif
  27. }
  28. UINT64 CoreObjectManager::registerObject(CoreObject* object)
  29. {
  30. assert(object != nullptr);
  31. BS_LOCK_MUTEX(mObjectsMutex);
  32. mObjects[mNextAvailableID] = object;
  33. return mNextAvailableID++;
  34. }
  35. void CoreObjectManager::unregisterObject(CoreObject* object)
  36. {
  37. assert(object != nullptr);
  38. BS_LOCK_MUTEX(mObjectsMutex);
  39. mObjects.erase(object->getInternalID());
  40. }
  41. }