BsScriptObjectManager.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEnginePrerequisites.h"
  5. #include "Utility/BsModule.h"
  6. namespace bs
  7. {
  8. /** @addtogroup SBansheeEngine
  9. * @{
  10. */
  11. /** Keeps track of all script interop objects and handles assembly refresh. */
  12. class BS_SCR_BE_EXPORT ScriptObjectManager : public Module <ScriptObjectManager>
  13. {
  14. public:
  15. ScriptObjectManager();
  16. ~ScriptObjectManager();
  17. /** Registers a newly created script interop object. */
  18. void registerScriptObject(ScriptObjectBase* instance);
  19. /** Unregisters a script interop object that is no longer valid. */
  20. void unregisterScriptObject(ScriptObjectBase* instance);
  21. /**
  22. * Refreshes the list of active assemblies. Unloads all current assemblies and loads the newly provided set. This
  23. * involves backup up managed object data, destroying all managed objects and restoring the objects after reload.
  24. *
  25. * @param[in] assemblies A list of assembly names and paths to load. First value represents the assembly name,
  26. * and second a path its the assembly .dll. Assemblies will be loaded in order specified.
  27. */
  28. void refreshAssemblies(const Vector<std::pair<String, Path>>& assemblies);
  29. /** Called once per frame. Triggers queued finalizer callbacks. */
  30. void update();
  31. /**
  32. * Call this when object finalizer is triggered. At the end of the frame all objects queued with this method will
  33. * have their _onManagedInstanceDeleted methods triggered.
  34. *
  35. * @note Thread safe.
  36. */
  37. void notifyObjectFinalized(ScriptObjectBase* instance);
  38. /**
  39. * Triggers _onManagedInstanceDeleted deleted callbacks on all objects that were finalized this frame. This allows
  40. * the native portions of those objects to properly clean up any resources.
  41. */
  42. void processFinalizedObjects();
  43. /**
  44. * Triggered right after a domain was reloaded. This signals the outside world that they should update any kept Mono
  45. * references as the old ones will no longer be valid.
  46. */
  47. Event<void()> onRefreshDomainLoaded;
  48. /**
  49. * Triggered just before the assembly refresh starts. At this point all managed objects are still valid, but are
  50. * about to be destroyed.
  51. */
  52. Event<void()> onRefreshStarted;
  53. /** Triggered after the assembly refresh ends. New assemblies should be loaded at this point. */
  54. Event<void()> onRefreshComplete;
  55. private:
  56. Set<ScriptObjectBase*> mScriptObjects;
  57. Vector<ScriptObjectBase*> mFinalizedObjects[2];
  58. UINT32 mFinalizedQueueIdx;
  59. Mutex mMutex;
  60. };
  61. /** @} */
  62. }