AEEditorCommon.cpp 3.2 KB

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