BsScriptObjectManager.h 1.4 KB

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