BsScriptObjectManager.h 2.8 KB

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