AEApplication.cpp 7.4 KB

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