AEApplication.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <Atomic/Engine/Engine.h>
  6. #include <Atomic/IO/FileSystem.h>
  7. #include <Atomic/IO/Log.h>
  8. #include <Atomic/Core/Main.h>
  9. #include <Atomic/Core/ProcessUtils.h>
  10. #include <Atomic/Graphics/Graphics.h>
  11. #include <Atomic/Resource/XMLFile.h>
  12. #include <Atomic/Resource/ResourceCache.h>
  13. #include <Atomic/Resource/ResourceEvents.h>
  14. #include <Atomic/DebugNew.h>
  15. #include <Atomic/Engine/Console.h>
  16. #include <Atomic/Engine/DebugHud.h>
  17. #include <Atomic/Input/Input.h>
  18. #include <Atomic/UI/UI.h>
  19. #include <Atomic/Environment/Environment.h>
  20. #include <Atomic/Graphics/Renderer.h>
  21. #include "AEEditorStrings.h"
  22. #include "AEEditorShortcuts.h"
  23. #include "Project/ProjectUtils.h"
  24. #include "Subprocess/AESubprocessSystem.h"
  25. #include "Build/BuildSystem.h"
  26. #include "License/AELicenseSystem.h"
  27. #include "License/AEVersionCheck.h"
  28. #include "Net/CurlManager.h"
  29. // just for testing, remove me
  30. #include "Import/AEImportJSON.h"
  31. #include "Import/AEJSONSceneProcess.h"
  32. #include "AEEditor.h"
  33. #include "AEPreferences.h"
  34. #include "AEApplication.h"
  35. #include "Tools/External/AEExternalTooling.h"
  36. #include <AtomicJS/Javascript/Javascript.h>
  37. #include <ToolCore/ToolSystem.h>
  38. #include <ToolCore/ToolEnvironment.h>
  39. using namespace ToolCore;
  40. namespace AtomicEditor
  41. {
  42. AEApplication::AEApplication(Context* context) :
  43. Application(context)
  44. {
  45. }
  46. void AEApplication::Start()
  47. {
  48. // refactor this
  49. RegisterEnvironmentLibrary(context_);
  50. ToolSystem* tsystem = new ToolSystem(context_);
  51. context_->RegisterSubsystem(tsystem);
  52. Engine* engine = GetSubsystem<Engine>();
  53. engine->SetAutoExit(false);
  54. // Get default style
  55. ResourceCache* cache = GetSubsystem<ResourceCache>();
  56. cache->SetAutoReloadResources(true);
  57. #ifndef ATOMIC_DEV_BUILD
  58. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  59. #ifdef __APPLE__
  60. String editorResources = fileSystem->GetAppBundleResourceFolder() + "EditorData.pak";
  61. #else
  62. String editorResources = fileSystem->GetProgramDir() + "EditorData.pak";
  63. #endif
  64. assert(fileSystem->FileExists(editorResources));
  65. cache->AddPackageFile(editorResources);
  66. #endif
  67. // initialize after EditorResources set
  68. UI* tbui = GetSubsystem<UI>();
  69. tbui->Initialize();
  70. Input* input = GetSubsystem<Input>();
  71. input->SetMouseVisible(true);
  72. #ifdef ATOMIC_PLATFORM_WINDOWS
  73. // on windows maximize, otherwise window does funky thing with "restore down"
  74. // todo: better way of handling this? Windows 8 restore down goes below taskbar :(
  75. Graphics* graphics = GetSubsystem<Graphics>();
  76. IntVector2 resolution = graphics->GetDesktopResolution();
  77. int height = graphics->GetHeight();
  78. if ( Abs(height - resolution.y_) < 128)
  79. GetSubsystem<Graphics>()->Maximize();
  80. #endif
  81. context_->RegisterSubsystem(new EditorStrings(context_));
  82. context_->RegisterSubsystem(new EditorShortcuts(context_));
  83. context_->RegisterSubsystem(new ProjectUtils(context_));
  84. context_->RegisterSubsystem(new Javascript(context_));
  85. context_->RegisterSubsystem(new SubprocessSystem(context_));
  86. context_->RegisterSubsystem(new ExternalTooling(context_));
  87. context_->RegisterSubsystem(new BuildSystem(context_));
  88. context_->RegisterSubsystem(new CurlManager(context_));
  89. // BEGIN LICENSE MANAGEMENT
  90. context_->RegisterSubsystem(new LicenseSystem(context_));
  91. context_->RegisterSubsystem(new VersionCheck(context_));
  92. // END LICENSE MANAGEMENT
  93. Editor* editor = new Editor(context_);
  94. context_->RegisterSubsystem(editor);
  95. #ifdef ATOMIC_PLATFORM_OSX
  96. editor->RequestPlatformChange(AE_PLATFORM_MAC);
  97. #else
  98. editor->RequestPlatformChange(AE_PLATFORM_WINDOWS);
  99. #endif
  100. bool process = false;
  101. if (process)
  102. {
  103. SharedPtr<JSONSceneImporter> jimporter;
  104. jimporter = new JSONSceneImporter(context_);
  105. jimporter->Import("/Users/josh/Desktop/Blah.js");
  106. SharedPtr<JSONSceneProcess> sceneProcess;
  107. sceneProcess = new JSONSceneProcess(context_, jimporter);
  108. sceneProcess->Process();
  109. sceneProcess->Write();
  110. }
  111. if (cmdLineProjectFile_.Length())
  112. {
  113. editor->LoadProject(cmdLineProjectFile_);
  114. }
  115. }
  116. void AEApplication::Setup()
  117. {
  118. FileSystem* filesystem = GetSubsystem<FileSystem>();
  119. ToolEnvironment* env = new ToolEnvironment(context_);
  120. context_->RegisterSubsystem(env);
  121. #ifdef ATOMIC_DEV_BUILD
  122. if (!env->InitFromJSON())
  123. {
  124. ErrorExit(ToString("Unable to initialize tool environment from %s", env->GetDevConfigFilename().CString()));
  125. return;
  126. }
  127. #endif
  128. const Vector<String>& arguments = GetArguments();
  129. for (unsigned i = 0; i < arguments.Size(); ++i)
  130. {
  131. if (arguments[i].Length() > 1 && arguments[i][0] == '-')
  132. {
  133. String argument = arguments[i].Substring(1).ToLower();
  134. String value = i + 1 < arguments.Size() ? arguments[i + 1] : String::EMPTY;
  135. if (argument == "project" && value.Length())
  136. {
  137. Vector<String> projectFiles;
  138. filesystem->ScanDir(projectFiles, value, "*.atomic", SCAN_FILES, false);
  139. if (!projectFiles.Size())
  140. {
  141. ErrorExit(ToString("No .atomic project file in %s", value.CString()));
  142. return;
  143. }
  144. else if (projectFiles.Size() > 1)
  145. {
  146. ErrorExit(ToString("Multiple .atomic project files found in %s", value.CString()));
  147. return;
  148. }
  149. cmdLineProjectFile_ = value + "/" + projectFiles[0];
  150. }
  151. }
  152. }
  153. engineParameters_["WindowTitle"] = "AtomicEditor";
  154. engineParameters_["WindowResizable"] = true;
  155. engineParameters_["FullScreen"] = false;
  156. AEPreferences::StartupPreferences prefs;
  157. if (AEPreferences::ReadStartupPrefs(context_, prefs))
  158. {
  159. engineParameters_["WindowWidth"] = prefs.windowWidth;
  160. engineParameters_["WindowHeight"] = prefs.windowHeight;
  161. }
  162. #ifdef ATOMIC_DEV_BUILD
  163. engineParameters_["ResourcePrefixPath"] = "";
  164. String resourcePaths = env->GetCoreDataDir() + ";" + env->GetEditorDataDir();
  165. engineParameters_["ResourcePaths"] = resourcePaths;
  166. #else
  167. #ifdef __APPLE__
  168. engineParameters_["ResourcePrefixPath"] = "../Resources";
  169. #endif
  170. #endif // ATOMIC_DEV_BUILD
  171. #ifndef __APPLE__
  172. engineParameters_["WindowIcon"] = "Images/AtomicLogo32.png";
  173. #endif
  174. engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "AtomicEditor.log";
  175. }
  176. void AEApplication::Stop()
  177. {
  178. context_->RemoveSubsystem<Editor>();
  179. }
  180. }