AEEditorApp.cpp 5.8 KB

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