AEEditorCommon.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. #include <ToolCore/ToolSystem.h>
  15. #include <ToolCore/ToolEnvironment.h>
  16. #ifdef ATOMIC_DOTNET
  17. #include <AtomicNET/NETCore/NETHost.h>
  18. #include <AtomicNET/NETCore/NETCore.h>
  19. #include <AtomicNET/NETScript/NETScript.h>
  20. #endif
  21. #include "AEEditorCommon.h"
  22. namespace Atomic
  23. {
  24. void jsapi_init_atomicnet(JSVM* vm);
  25. }
  26. using namespace ToolCore;
  27. namespace ToolCore
  28. {
  29. extern void jsapi_init_toolcore(JSVM* vm);
  30. }
  31. namespace AtomicEditor
  32. {
  33. AEEditorCommon::AEEditorCommon(Context* context) :
  34. Application(context)
  35. {
  36. }
  37. void AEEditorCommon::Start()
  38. {
  39. Input* input = GetSubsystem<Input>();
  40. input->SetMouseVisible(true);
  41. Javascript* javascript = GetSubsystem<Javascript>();
  42. vm_ = javascript->InstantiateVM("MainVM");
  43. vm_->InitJSContext();
  44. jsapi_init_toolcore(vm_);
  45. #ifdef ATOMIC_DOTNET
  46. jsapi_init_atomicnet(vm_);
  47. #endif
  48. }
  49. void AEEditorCommon::Setup()
  50. {
  51. #ifdef ATOMIC_3D
  52. RegisterEnvironmentLibrary(context_);
  53. #endif
  54. #ifdef ATOMIC_DOTNET
  55. RegisterNETScriptLibrary(context_);
  56. #endif
  57. // Register IPC system
  58. context_->RegisterSubsystem(new IPC(context_));
  59. context_->RegisterSubsystem(new ScriptSystem(context_));
  60. // Instantiate and register the Javascript subsystem
  61. Javascript* javascript = new Javascript(context_);
  62. context_->RegisterSubsystem(javascript);
  63. ToolEnvironment* env = new ToolEnvironment(context_);
  64. context_->RegisterSubsystem(env);
  65. #ifdef ATOMIC_DEV_BUILD
  66. if (!env->InitFromJSON())
  67. {
  68. ErrorExit(ToString("Unable to initialize tool environment from %s", env->GetDevConfigFilename().CString()));
  69. return;
  70. }
  71. #else
  72. env->InitFromPackage();
  73. #endif
  74. #ifdef ATOMIC_DOTNET
  75. // Instantiate and register the AtomicNET subsystem
  76. SharedPtr<NETCore> netCore (new NETCore(context_));
  77. context_->RegisterSubsystem(netCore);
  78. String netCoreErrorMsg;
  79. NETHost::SetCoreCLRFilesAbsPath(env->GetNETCoreCLRAbsPath());
  80. NETHost::SetCoreCLRTPAPaths(env->GetNETTPAPaths());
  81. NETHost::SetCoreCLRAssemblyLoadPaths(env->GetNETAssemblyLoadPaths());
  82. if (!netCore->Initialize(netCoreErrorMsg))
  83. {
  84. LOGERRORF("NetCore: Unable to initialize! %s", netCoreErrorMsg.CString());
  85. context_->RemoveSubsystem(NETCore::GetTypeStatic());
  86. }
  87. else
  88. {
  89. }
  90. #endif
  91. ToolSystem* system = new ToolSystem(context_);
  92. context_->RegisterSubsystem(system);
  93. }
  94. void AEEditorCommon::Stop()
  95. {
  96. context_->RemoveSubsystem<IPC>();
  97. vm_ = 0;
  98. context_->RemoveSubsystem<Javascript>();
  99. // make sure JSVM is really down and no outstanding refs
  100. // as if not, will hold on engine subsystems, which is bad
  101. assert(!JSVM::GetJSVM(0));
  102. #ifdef ATOMIC_DOTNET
  103. NETCore* netCore = GetSubsystem<NETCore>();
  104. if (netCore)
  105. {
  106. netCore->Shutdown();
  107. context_->RemoveSubsystem<NETCore>();
  108. }
  109. #endif
  110. }
  111. }