AEEditorCommon.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/NETCore.h>
  16. #endif
  17. #include "AEEditorCommon.h"
  18. namespace Atomic
  19. {
  20. void jsapi_init_atomicnet(JSVM* vm);
  21. }
  22. namespace AtomicEditor
  23. {
  24. AEEditorCommon::AEEditorCommon(Context* context) :
  25. Application(context)
  26. {
  27. }
  28. void AEEditorCommon::Start()
  29. {
  30. Input* input = GetSubsystem<Input>();
  31. input->SetMouseVisible(true);
  32. Javascript* javascript = GetSubsystem<Javascript>();
  33. vm_ = javascript->InstantiateVM("MainVM");
  34. vm_->InitJSContext();
  35. #ifdef ATOMIC_DOTNET
  36. jsapi_init_atomicnet(vm_);
  37. #endif
  38. }
  39. void AEEditorCommon::Setup()
  40. {
  41. #ifdef ATOMIC_3D
  42. RegisterEnvironmentLibrary(context_);
  43. #endif
  44. // Register IPC system
  45. context_->RegisterSubsystem(new IPC(context_));
  46. context_->RegisterSubsystem(new ScriptSystem(context_));
  47. // Instantiate and register the Javascript subsystem
  48. Javascript* javascript = new Javascript(context_);
  49. context_->RegisterSubsystem(javascript);
  50. #ifdef ATOMIC_DOTNET
  51. // Instantiate and register the AtomicNET subsystem
  52. SharedPtr<NETCore> netCore (new NETCore(context_));
  53. context_->RegisterSubsystem(netCore);
  54. String netCoreErrorMsg;
  55. if (!netCore->Initialize("/Users/josh/Desktop/OSX.x64.Debug/", netCoreErrorMsg))
  56. {
  57. LOGERRORF("NetCore: Unable to initialize! %s", netCoreErrorMsg.CString());
  58. context_->RemoveSubsystem(NETCore::GetTypeStatic());
  59. }
  60. else
  61. {
  62. }
  63. #endif
  64. }
  65. void AEEditorCommon::Stop()
  66. {
  67. context_->RemoveSubsystem<IPC>();
  68. vm_ = 0;
  69. context_->RemoveSubsystem<Javascript>();
  70. // make sure JSVM is really down and no outstanding refs
  71. // as if not, will hold on engine subsystems, which is bad
  72. assert(!JSVM::GetJSVM(0));
  73. #ifdef ATOMIC_DOTNET
  74. NETCore* netCore = GetSubsystem<NETCore>();
  75. if (netCore)
  76. {
  77. netCore->Shutdown();
  78. context_->RemoveSubsystem<NETCore>();
  79. }
  80. #endif
  81. }
  82. }