AEEditorApp.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. // This can be removed once bone hack is fixed
  27. #include <Atomic/Graphics/AnimatedModel.h>
  28. #include <ToolCore/License/LicenseSystem.h>
  29. #include <ToolCore/ToolSystem.h>
  30. #include <ToolCore/ToolEnvironment.h>
  31. #include <ToolCore/NETTools/NETBuildSystem.h>
  32. #include "../EditorMode/AEEditorMode.h"
  33. #include "../EditorMode/AEEditorNETService.h"
  34. #include "../Components/EditorComponents.h"
  35. #include "AEEditorPrefs.h"
  36. #include "AEEditorApp.h"
  37. using namespace ToolCore;
  38. // Fix these externs
  39. namespace Atomic
  40. {
  41. void jsapi_init_webview(JSVM* vm, const VariantMap& engineParameters);
  42. extern void jsb_package_atomicnetscript_init(JSVM* vm);
  43. }
  44. namespace ToolCore
  45. {
  46. extern void jsapi_init_toolcore(JSVM* vm);
  47. }
  48. using namespace ToolCore;
  49. namespace AtomicEditor
  50. {
  51. extern void jsapi_init_editor(JSVM* vm);
  52. AEEditorApp::AEEditorApp(Context* context) :
  53. AppBase(context)
  54. {
  55. }
  56. AEEditorApp::~AEEditorApp()
  57. {
  58. }
  59. void AEEditorApp::Setup()
  60. {
  61. context_->RegisterSubsystem(new AEEditorPrefs(context_));
  62. context_->SetEditorContext(true);
  63. AppBase::Setup();
  64. RegisterEditorComponentLibrary(context_);
  65. // Register IPC system
  66. context_->RegisterSubsystem(new IPC(context_));
  67. ToolEnvironment* env = new ToolEnvironment(context_);
  68. context_->RegisterSubsystem(env);
  69. env->Initialize();
  70. ToolSystem* system = new ToolSystem(context_);
  71. context_->RegisterSubsystem(system);
  72. engineParameters_["WindowTitle"] = "AtomicEditor";
  73. engineParameters_["WindowResizable"] = true;
  74. engineParameters_["FullScreen"] = false;
  75. engineParameters_["LogLevel"] = LOG_DEBUG;
  76. FileSystem* filesystem = GetSubsystem<FileSystem>();
  77. engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "AtomicEditor.log";
  78. #ifdef ATOMIC_PLATFORM_OSX
  79. engineParameters_["WindowIcon"] = "Images/AtomicLogo32.png";
  80. #endif
  81. #ifdef ATOMIC_DEV_BUILD
  82. engineParameters_["ResourcePrefixPaths"] = "";
  83. String resourcePaths = env->GetCoreDataDir() + ";" + env->GetEditorDataDir();
  84. // for dev builds, add the compile editor scripts from artifacts
  85. resourcePaths += ";" + env->GetRootSourceDir() + "Artifacts/Build/Resources/EditorData/";
  86. engineParameters_["ResourcePaths"] = resourcePaths;
  87. #else
  88. #ifdef ATOMIC_PLATFORM_OSX
  89. engineParameters_["ResourcePrefixPaths"] = filesystem->GetProgramDir() + "../Resources";
  90. #else
  91. engineParameters_["ResourcePrefixPaths"] = filesystem->GetProgramDir() + "Resources";
  92. #endif
  93. engineParameters_["ResourcePaths"] = "CoreData;EditorData";
  94. #endif // ATOMIC_DEV_BUILD
  95. GetSubsystem<AEEditorPrefs>()->ReadPreferences(engineParameters_);
  96. // Register JS packages
  97. JSVM::RegisterPackage(jsapi_init_toolcore);
  98. JSVM::RegisterPackage(jsapi_init_editor);
  99. JSVM::RegisterPackage(jsb_package_atomicnetscript_init);
  100. #ifdef ATOMIC_WEBVIEW
  101. JSVM::RegisterPackage(jsapi_init_webview, engineParameters_);
  102. #endif
  103. }
  104. void AEEditorApp::Start()
  105. {
  106. GetSubsystem<AEEditorPrefs>()->ValidateWindow();
  107. context_->RegisterSubsystem(new EditorMode(context_));
  108. context_->RegisterSubsystem(new NETBuildSystem(context_));
  109. context_->RegisterSubsystem(new EditorNETService(context_));
  110. AppBase::Start();
  111. vm_->SetModuleSearchPaths("AtomicEditor/JavaScript;AtomicEditor/EditorScripts;AtomicEditor/EditorScripts/AtomicEditor");
  112. // move UI initialization to JS
  113. UI* ui = GetSubsystem<UI>();
  114. ui->Initialize("AtomicEditor/resources/language/lng_en.tb.txt");
  115. duk_get_global_string(vm_->GetJSContext(), "require");
  116. duk_push_string(vm_->GetJSContext(), "main");
  117. if (duk_pcall(vm_->GetJSContext(), 1) != 0)
  118. {
  119. vm_->SendJSErrorEvent();
  120. ErrorExit("Error executing main.js");
  121. }
  122. GetSubsystem<LicenseSystem>()->Initialize();
  123. Input* input = GetSubsystem<Input>();
  124. // Ensure exclusive fullscreen is disabled in Editor application
  125. input->SetToggleFullscreen(false);
  126. input->SetMouseVisible(true);
  127. }
  128. void AEEditorApp::Stop()
  129. {
  130. IPC* ipc = GetSubsystem<IPC>();
  131. if (ipc)
  132. {
  133. ipc->Shutdown();
  134. }
  135. AppBase::Stop();
  136. }
  137. void AEEditorApp::ProcessArguments()
  138. {
  139. AppBase::ProcessArguments();
  140. }
  141. }