AEEditorCommon.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. RegisterNETScriptLibrary(context_);
  55. // Register IPC system
  56. context_->RegisterSubsystem(new IPC(context_));
  57. context_->RegisterSubsystem(new ScriptSystem(context_));
  58. // Instantiate and register the Javascript subsystem
  59. Javascript* javascript = new Javascript(context_);
  60. context_->RegisterSubsystem(javascript);
  61. ToolEnvironment* env = new ToolEnvironment(context_);
  62. context_->RegisterSubsystem(env);
  63. #ifdef ATOMIC_DEV_BUILD
  64. if (!env->InitFromJSON())
  65. {
  66. ErrorExit(ToString("Unable to initialize tool environment from %s", env->GetDevConfigFilename().CString()));
  67. return;
  68. }
  69. #else
  70. env->InitFromPackage();
  71. #endif
  72. #ifdef ATOMIC_DOTNET
  73. // Instantiate and register the AtomicNET subsystem
  74. SharedPtr<NETCore> netCore (new NETCore(context_));
  75. context_->RegisterSubsystem(netCore);
  76. String netCoreErrorMsg;
  77. NETHost::SetCoreCLRFilesAbsPath(env->GetNETCoreCLRAbsPath());
  78. NETHost::SetCoreCLRTPAPaths(env->GetNETTPAPaths());
  79. NETHost::SetCoreCLRAssemblyLoadPaths(env->GetNETAssemblyLoadPaths());
  80. if (!netCore->Initialize(netCoreErrorMsg))
  81. {
  82. LOGERRORF("NetCore: Unable to initialize! %s", netCoreErrorMsg.CString());
  83. context_->RemoveSubsystem(NETCore::GetTypeStatic());
  84. }
  85. else
  86. {
  87. }
  88. #endif
  89. ToolSystem* system = new ToolSystem(context_);
  90. context_->RegisterSubsystem(system);
  91. }
  92. void AEEditorCommon::Stop()
  93. {
  94. context_->RemoveSubsystem<IPC>();
  95. vm_ = 0;
  96. context_->RemoveSubsystem<Javascript>();
  97. // make sure JSVM is really down and no outstanding refs
  98. // as if not, will hold on engine subsystems, which is bad
  99. assert(!JSVM::GetJSVM(0));
  100. #ifdef ATOMIC_DOTNET
  101. NETCore* netCore = GetSubsystem<NETCore>();
  102. if (netCore)
  103. {
  104. netCore->Shutdown();
  105. context_->RemoveSubsystem<NETCore>();
  106. }
  107. #endif
  108. }
  109. }