2
0

BsScriptObjectManager.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. @p assemblyRefresh lets the
  41. * script objects know if finalization is happening due to assembly refresh.
  42. */
  43. void processFinalizedObjects(bool assemblyRefresh = false);
  44. /**
  45. * Triggered right after a domain was reloaded. This signals the outside world that they should update any kept Mono
  46. * references as the old ones will no longer be valid.
  47. */
  48. Event<void()> onRefreshDomainLoaded;
  49. /**
  50. * Triggered just before the assembly refresh starts. At this point all managed objects are still valid, but are
  51. * about to be destroyed.
  52. */
  53. Event<void()> onRefreshStarted;
  54. /** Triggered after the assembly refresh ends. New assemblies should be loaded at this point. */
  55. Event<void()> onRefreshComplete;
  56. private:
  57. Set<ScriptObjectBase*> mScriptObjects;
  58. Vector<ScriptObjectBase*> mFinalizedObjects[2];
  59. UINT32 mFinalizedQueueIdx;
  60. Mutex mMutex;
  61. };
  62. /** @} */
  63. }