BsScriptObjectManager.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsModule.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Keeps track of all script interop objects and handles assembly refresh.
  8. */
  9. class BS_SCR_BE_EXPORT ScriptObjectManager : public Module <ScriptObjectManager>
  10. {
  11. public:
  12. ScriptObjectManager();
  13. ~ScriptObjectManager();
  14. /**
  15. * @brief Registers a newly created script interop object.
  16. */
  17. void registerScriptObject(ScriptObjectBase* instance);
  18. /**
  19. * @brief Unregisters a script interop object that is no longer valid.
  20. */
  21. void unregisterScriptObject(ScriptObjectBase* instance);
  22. /**
  23. * @brief Reloads all script assemblies. This involves backup up managed
  24. * object data, destroying all managed objects and restoring
  25. * the objects after reload.
  26. */
  27. void refreshAssemblies();
  28. /**
  29. * @brief Called once per frame. Triggers queued finalizer callbacks.
  30. */
  31. void update();
  32. /**
  33. * @brief Call this when object finalizer is triggered. At the end of the frame
  34. * all objects queued with this method will have their _onManagedInstanceDeleted methods
  35. * triggered.
  36. *
  37. * @note Thread safe.
  38. */
  39. void notifyObjectFinalized(ScriptObjectBase* instance);
  40. /**
  41. * @brief Triggers _onManagedInstanceDeleted deleted callbacks on all objects that were finalized this frame.
  42. * This allows the native portions of those objects to properly clean up any resources.
  43. */
  44. void processFinalizedObjects();
  45. /**
  46. * @brief Triggered right after a domain was reloaded. This signals the outside world that they should
  47. * update any kept Mono references as the old ones will no longer be valid.
  48. */
  49. Event<void()> onRefreshDomainLoaded;
  50. /**
  51. * @brief Triggered just before the assembly refresh starts. At this point all managed
  52. * objects are still valid, but are about to be destroyed.
  53. */
  54. Event<void()> onRefreshStarted;
  55. /**
  56. * @brief Triggered after the assembly refresh ends. New assemblies should be loaded at
  57. * this point.
  58. */
  59. Event<void()> onRefreshComplete;
  60. private:
  61. Set<ScriptObjectBase*> mScriptObjects;
  62. Vector<ScriptObjectBase*> mFinalizedObjects[2];
  63. UINT32 mFinalizedQueueIdx;
  64. BS_MUTEX(mMutex);
  65. };
  66. }