AEEditorCommon.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #include <Atomic/Engine/Engine.h>
  8. #include <Atomic/Input/Input.h>
  9. #include <Atomic/IPC/IPC.h>
  10. // Move me to Engine
  11. #include <Atomic/Environment/Environment.h>
  12. #include <Atomic/Script/ScriptSystem.h>
  13. #include <AtomicJS/Javascript/Javascript.h>
  14. #ifdef ATOMIC_DOTNET
  15. #include <AtomicNET/NETCore/NETHost.h>
  16. #include <AtomicNET/NETCore/NETCore.h>
  17. #endif
  18. #include "AEEditorCommon.h"
  19. namespace Atomic
  20. {
  21. void jsapi_init_atomicnet(JSVM* vm);
  22. }
  23. namespace AtomicEditor
  24. {
  25. AEEditorCommon::AEEditorCommon(Context* context) :
  26. Application(context)
  27. {
  28. }
  29. void AEEditorCommon::Start()
  30. {
  31. Input* input = GetSubsystem<Input>();
  32. input->SetMouseVisible(true);
  33. Javascript* javascript = GetSubsystem<Javascript>();
  34. vm_ = javascript->InstantiateVM("MainVM");
  35. vm_->InitJSContext();
  36. #ifdef ATOMIC_DOTNET
  37. jsapi_init_atomicnet(vm_);
  38. #endif
  39. }
  40. void AEEditorCommon::Setup()
  41. {
  42. #ifdef ATOMIC_3D
  43. RegisterEnvironmentLibrary(context_);
  44. #endif
  45. // Register IPC system
  46. context_->RegisterSubsystem(new IPC(context_));
  47. context_->RegisterSubsystem(new ScriptSystem(context_));
  48. // Instantiate and register the Javascript subsystem
  49. Javascript* javascript = new Javascript(context_);
  50. context_->RegisterSubsystem(javascript);
  51. #ifdef ATOMIC_DOTNET
  52. // Instantiate and register the AtomicNET subsystem
  53. SharedPtr<NETCore> netCore (new NETCore(context_));
  54. context_->RegisterSubsystem(netCore);
  55. String netCoreErrorMsg;
  56. #ifdef ATOMIC_DEV_BUILD
  57. String assemblyLoadPaths = GetNativePath(ToString("%s/Artifacts/AtomicNET/", ATOMIC_ROOT_SOURCE_DIR));
  58. #ifdef ATOMIC_PLATFORM_WINDOWS
  59. String coreCLRAbsPath = GetNativePath(ToString("%s/Submodules/CoreCLR/Windows/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR));
  60. String coreCLRTPAPaths = ToString("%s/Submodules/CoreCLR/Windows/Debug/AnyCPU/TPA/", ATOMIC_ROOT_SOURCE_DIR);
  61. coreCLRTPAPaths += ToString(";%s/Artifacts/AtomicNET/TPA/", ATOMIC_ROOT_SOURCE_DIR);
  62. #else
  63. String coreCLRAbsPath = GetNativePath(ToString("%s/Submodules/CoreCLR/OSX/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR);
  64. #endif
  65. #else
  66. assert(0);
  67. #endif
  68. NETHost::SetCoreCLRFilesAbsPath(coreCLRAbsPath);
  69. NETHost::SetCoreCLRTPAPaths(coreCLRTPAPaths);
  70. NETHost::SetCoreCLRAssemblyLoadPaths(assemblyLoadPaths);
  71. if (!netCore->Initialize(netCoreErrorMsg))
  72. {
  73. LOGERRORF("NetCore: Unable to initialize! %s", netCoreErrorMsg.CString());
  74. context_->RemoveSubsystem(NETCore::GetTypeStatic());
  75. }
  76. else
  77. {
  78. }
  79. #endif
  80. }
  81. void AEEditorCommon::Stop()
  82. {
  83. context_->RemoveSubsystem<IPC>();
  84. vm_ = 0;
  85. context_->RemoveSubsystem<Javascript>();
  86. // make sure JSVM is really down and no outstanding refs
  87. // as if not, will hold on engine subsystems, which is bad
  88. assert(!JSVM::GetJSVM(0));
  89. #ifdef ATOMIC_DOTNET
  90. NETCore* netCore = GetSubsystem<NETCore>();
  91. if (netCore)
  92. {
  93. netCore->Shutdown();
  94. context_->RemoveSubsystem<NETCore>();
  95. }
  96. #endif
  97. }
  98. }