BsScriptObjectManager.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsModule.h"
  4. namespace BansheeEngine
  5. {
  6. class BS_SCR_BE_EXPORT ScriptObjectManager : public Module <ScriptObjectManager>
  7. {
  8. public:
  9. ScriptObjectManager();
  10. ~ScriptObjectManager();
  11. void registerScriptObject(ScriptObjectBase* instance);
  12. void unregisterScriptObject(ScriptObjectBase* instance);
  13. void refreshAssemblies();
  14. void update();
  15. /**
  16. * @brief Call this when object finalizer is triggered. At the end of the frame
  17. * all objects queued with this method will have their _onManagedInstanceDeleted methods
  18. * triggered.
  19. *
  20. * @note Thread safe.
  21. */
  22. void notifyObjectFinalized(ScriptObjectBase* instance);
  23. /**
  24. * @brief Triggers _onManagedInstanceDeleted deleted callbacks on all objects that were finalized this frame.
  25. * This allows the native portions of those objects to properly clean up any resources.
  26. *
  27. * @note Sim thread.
  28. */
  29. void processFinalizedObjects();
  30. /**
  31. * @brief Triggered right after a domain was reloaded. This signals the outside world that they should
  32. * update any kept Mono references as the old ones will no longer be valid.
  33. */
  34. Event<void()> onRefreshDomainLoaded;
  35. Event<void()> onRefreshStarted;
  36. Event<void()> onRefreshComplete;
  37. private:
  38. Set<ScriptObjectBase*> mScriptObjects;
  39. Vector<ScriptObjectBase*> mFinalizedObjects[2];
  40. std::atomic<UINT32> mFinalizedQueueIdx;
  41. };
  42. }