BsMonoManager.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsMonoPrerequisites.h"
  5. #include "BsScriptMeta.h"
  6. #include "BsModule.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Mono
  10. * @{
  11. */
  12. /** Available Mono versions. */
  13. enum class MonoVersion
  14. {
  15. v4_5
  16. };
  17. /** Loads Mono script assemblies and manages script objects. */
  18. class BS_MONO_EXPORT MonoManager : public Module<MonoManager>
  19. {
  20. public:
  21. MonoManager();
  22. ~MonoManager();
  23. /**
  24. * Loads a new assembly from the provided path.
  25. *
  26. * @param[in] path Absolute path to the assembly .dll.
  27. * @param[in] name Unique name for the assembly.
  28. */
  29. MonoAssembly& loadAssembly(const WString& path, const String& name);
  30. /** Searches all loaded assemblies for the specified class. */
  31. MonoClass* findClass(const String& ns, const String& typeName);
  32. /** Searches all loaded assemblies for the specified class. */
  33. MonoClass* findClass(::MonoClass* rawMonoClass);
  34. /** Returns the current Mono domain. */
  35. MonoDomain* getDomain() const { return mScriptDomain; }
  36. /**
  37. * Attempts to find a previously loaded assembly with the specified name. Returns null if assembly cannot be found.
  38. */
  39. MonoAssembly* getAssembly(const String& name) const;
  40. /**
  41. * Unloads the active domain (in which all script assemblies are loaded) and destroys any managed objects
  42. * associated with it.
  43. */
  44. void unloadScriptDomain();
  45. /**
  46. * Loads a new script domain. If another domain already exists it will be unloaded. This will also restore any
  47. * previously loaded assemblies.
  48. */
  49. void loadScriptDomain();
  50. /**
  51. * Returns the path of the folder where Mono framework assemblies are located. Path is relative to the application
  52. * executable.
  53. */
  54. Path getFrameworkAssembliesFolder() const;
  55. /**
  56. * Returns the path to the Mono /etc folder that is required for initializing Mono. Path is relative to the
  57. * application executable.
  58. */
  59. Path getMonoEtcFolder() const;
  60. /** Returns the absolute path to the Mono compiler. */
  61. Path getCompilerPath() const;
  62. /**
  63. * Registers a new script type. This should be done before any assembly loading is done. Upon assembly load these
  64. * script types will be initialized with necessary information about their managed counterparts.
  65. */
  66. static void registerScriptType(ScriptMeta* metaData);
  67. /** Triggered when the assembly domain and all relevant assemblies are about to be unloaded. */
  68. Event<void()> onDomainUnload;
  69. private:
  70. /** Initializes a previous loaded assembly. */
  71. void initializeAssembly(MonoAssembly& assembly);
  72. /** Returns a list of all types that will be initializes with their assembly gets loaded. */
  73. static UnorderedMap<String, Vector<ScriptMeta*>>& getScriptMetaData()
  74. {
  75. static UnorderedMap<String, Vector<ScriptMeta*>> mTypesToInitialize;
  76. return mTypesToInitialize;
  77. }
  78. UnorderedMap<String, MonoAssembly*> mAssemblies;
  79. MonoDomain* mScriptDomain;
  80. MonoDomain* mRootDomain;
  81. bool mIsCoreLoaded;
  82. };
  83. /** @} */
  84. }