AEEditorApp.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include <Atomic/Input/Input.h>
  23. #include <Atomic/UI/UI.h>
  24. #include <AtomicJS/Javascript/Javascript.h>
  25. #include <Atomic/IPC/IPC.h>
  26. #include <Atomic/Engine/EngineDefs.h>
  27. // This can be removed once bone hack is fixed
  28. #include <Atomic/Graphics/AnimatedModel.h>
  29. #include <ToolCore/License/LicenseSystem.h>
  30. #include <ToolCore/ToolSystem.h>
  31. #include <ToolCore/ToolEnvironment.h>
  32. #include <ToolCore/NETTools/NETBuildSystem.h>
  33. #include "../EditorMode/AEEditorMode.h"
  34. #include "../EditorMode/AEEditorNETService.h"
  35. #include "../Components/EditorComponents.h"
  36. #ifdef ATOMIC_GLOW
  37. #include <AtomicGlow/GlowService/GlowService.h>
  38. using namespace AtomicGlow;
  39. #endif
  40. #include "AEEditorPrefs.h"
  41. #include "AEEditorApp.h"
  42. using namespace ToolCore;
  43. // Fix these externs
  44. namespace Atomic
  45. {
  46. void jsapi_init_webview(JSVM* vm, const VariantMap& engineParameters);
  47. extern void jsb_package_atomicnetscript_init(JSVM* vm);
  48. }
  49. namespace ToolCore
  50. {
  51. extern void jsapi_init_toolcore(JSVM* vm);
  52. }
  53. using namespace ToolCore;
  54. namespace AtomicEditor
  55. {
  56. extern void jsapi_init_editor(JSVM* vm);
  57. AEEditorApp::AEEditorApp(Context* context) :
  58. AppBase(context)
  59. {
  60. }
  61. AEEditorApp::~AEEditorApp()
  62. {
  63. }
  64. void AEEditorApp::Setup()
  65. {
  66. context_->RegisterSubsystem(new AEEditorPrefs(context_));
  67. context_->SetEditorContext(true);
  68. AppBase::Setup();
  69. RegisterEditorComponentLibrary(context_);
  70. // Register IPC system
  71. context_->RegisterSubsystem(new IPC(context_));
  72. ToolEnvironment* env = new ToolEnvironment(context_);
  73. context_->RegisterSubsystem(env);
  74. env->Initialize();
  75. ToolSystem* system = new ToolSystem(context_);
  76. context_->RegisterSubsystem(system);
  77. engineParameters_["WindowTitle"] = "AtomicEditor";
  78. engineParameters_["WindowResizable"] = true;
  79. engineParameters_["FullScreen"] = false;
  80. engineParameters_["LogLevel"] = LOG_DEBUG;
  81. FileSystem* filesystem = GetSubsystem<FileSystem>();
  82. engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "AtomicEditor.log";
  83. #ifdef ATOMIC_PLATFORM_OSX
  84. engineParameters_["WindowIcon"] = "Images/AtomicLogo32.png";
  85. #endif
  86. #ifdef ATOMIC_DEV_BUILD
  87. engineParameters_["ResourcePrefixPaths"] = "";
  88. String resourcePaths = env->GetCoreDataDir() + ";" + env->GetEditorDataDir();
  89. // for dev builds, add the compile editor scripts from artifacts
  90. resourcePaths += ";" + env->GetRootSourceDir() + "Artifacts/Build/Resources/EditorData/";
  91. engineParameters_["ResourcePaths"] = resourcePaths;
  92. #else
  93. #ifdef ATOMIC_PLATFORM_OSX
  94. engineParameters_["ResourcePrefixPaths"] = filesystem->GetProgramDir() + "../Resources";
  95. #else
  96. engineParameters_["ResourcePrefixPaths"] = filesystem->GetProgramDir() + "Resources";
  97. #endif
  98. engineParameters_["ResourcePaths"] = "CoreData;EditorData";
  99. #endif // ATOMIC_DEV_BUILD
  100. engineParameters_[EP_PROFILER_LISTEN] = false;
  101. GetSubsystem<AEEditorPrefs>()->ReadPreferences(engineParameters_);
  102. // Register JS packages
  103. JSVM::RegisterPackage(jsapi_init_toolcore);
  104. JSVM::RegisterPackage(jsapi_init_editor);
  105. JSVM::RegisterPackage(jsb_package_atomicnetscript_init);
  106. #ifdef ATOMIC_WEBVIEW
  107. JSVM::RegisterPackage(jsapi_init_webview, engineParameters_);
  108. #endif
  109. }
  110. void AEEditorApp::Start()
  111. {
  112. GetSubsystem<AEEditorPrefs>()->ValidateWindow();
  113. context_->RegisterSubsystem(new EditorMode(context_));
  114. context_->RegisterSubsystem(new NETBuildSystem(context_));
  115. context_->RegisterSubsystem(new EditorNETService(context_));
  116. #ifdef ATOMIC_GLOW
  117. SharedPtr<GlowService> glowService(new GlowService(context_));
  118. if (glowService->Start())
  119. {
  120. context_->RegisterSubsystem(glowService);
  121. }
  122. #endif
  123. AppBase::Start();
  124. vm_->SetModuleSearchPaths("AtomicEditor/JavaScript;AtomicEditor/EditorScripts;AtomicEditor/EditorScripts/AtomicEditor");
  125. // move UI initialization to JS
  126. UI* ui = GetSubsystem<UI>();
  127. ui->Initialize("AtomicEditor/resources/language/lng_en.tb.txt");
  128. duk_get_global_string(vm_->GetJSContext(), "require");
  129. duk_push_string(vm_->GetJSContext(), "main");
  130. if (duk_pcall(vm_->GetJSContext(), 1) != 0)
  131. {
  132. vm_->SendJSErrorEvent();
  133. ErrorExit("Error executing main.js");
  134. }
  135. GetSubsystem<LicenseSystem>()->Initialize();
  136. Input* input = GetSubsystem<Input>();
  137. // Ensure exclusive fullscreen is disabled in Editor application
  138. input->SetToggleFullscreen(false);
  139. input->SetMouseVisible(true);
  140. }
  141. void AEEditorApp::Stop()
  142. {
  143. IPC* ipc = GetSubsystem<IPC>();
  144. if (ipc)
  145. {
  146. ipc->Shutdown();
  147. }
  148. AppBase::Stop();
  149. }
  150. void AEEditorApp::ProcessArguments()
  151. {
  152. AppBase::ProcessArguments();
  153. }
  154. }