AEApplication.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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/Resource/ResourceCache.h>
  11. #include <Atomic/Resource/ResourceEvents.h>
  12. #include <Atomic/DebugNew.h>
  13. #include <Atomic/Engine/Console.h>
  14. #include <Atomic/Engine/DebugHud.h>
  15. #include <Atomic/Input/Input.h>
  16. #include <Atomic/UI/TBUI.h>
  17. #include <Atomic/Javascript/Javascript.h>
  18. #include <Atomic/Environment/Environment.h>
  19. #include <Atomic/Graphics/Renderer.h>
  20. #include "Project/ProjectUtils.h"
  21. #include "Subprocess/AESubprocessSystem.h"
  22. #include "Build/BuildSystem.h"
  23. #include "License/AELicenseSystem.h"
  24. #include "Net/CurlManager.h"
  25. // just for testing, remove me
  26. #include "Import/AEImportJSON.h"
  27. #include "Import/AEJSONSceneProcess.h"
  28. #include "AEEditor.h"
  29. #include "AEApplication.h"
  30. #include "Tools/External/AEExternalTooling.h"
  31. DEFINE_APPLICATION_MAIN(AtomicEditor::AEApplication);
  32. namespace AtomicEditor
  33. {
  34. AEApplication::AEApplication(Context* context) :
  35. Application(context)
  36. {
  37. }
  38. void AEApplication::Start()
  39. {
  40. // refactor this
  41. RegisterEnvironmenttLibrary(context_);
  42. // Get default style
  43. ResourceCache* cache = GetSubsystem<ResourceCache>();
  44. cache->SetAutoReloadResources(true);
  45. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  46. #ifdef __APPLE__
  47. String editorResources = fileSystem->GetAppBundleResourceFolder() + "EditorResources/";
  48. #else
  49. String editorResources = fileSystem->GetProgramDir() + "EditorResources/";
  50. #endif
  51. assert(fileSystem->DirExists(editorResources));
  52. cache->AddResourceDir(editorResources);
  53. // initialize after EditorResources set
  54. TBUI* tbui = GetSubsystem<TBUI>();
  55. tbui->Initialize();
  56. XMLFile* xmlFile = cache->GetResource<XMLFile>("UI/DefaultStyle.xml");
  57. // Create console
  58. Console* console = engine_->CreateConsole();
  59. console->SetDefaultStyle(xmlFile);
  60. console->GetBackground()->SetOpacity(0.8f);
  61. // Create debug HUD.
  62. DebugHud* debugHud = engine_->CreateDebugHud();
  63. debugHud->SetDefaultStyle(xmlFile);
  64. Input* input = GetSubsystem<Input>();
  65. // The mouse isn't showing up on OSX until I tab, this is a hack and temp workaround
  66. input->SetMouseVisible(true);
  67. input->SetMouseVisible(false);
  68. input->SetMouseVisible(true);
  69. input->SetMouseVisible(false);
  70. input->SetMouseVisible(true);
  71. context_->RegisterSubsystem(new ProjectUtils(context_));
  72. context_->RegisterSubsystem(new Javascript(context_));
  73. context_->RegisterSubsystem(new SubprocessSystem(context_));
  74. context_->RegisterSubsystem(new ExternalTooling(context_));
  75. context_->RegisterSubsystem(new BuildSystem(context_));
  76. context_->RegisterSubsystem(new CurlManager(context_));
  77. // BEGIN LICENSE MANAGEMENT
  78. context_->RegisterSubsystem(new LicenseSystem(context_));
  79. // END LICENSE MANAGEMENT
  80. Editor* editor = new Editor(context_);
  81. context_->RegisterSubsystem(editor);
  82. #ifdef ATOMIC_PLATFORM_OSX
  83. editor->RequestPlatformChange(AE_PLATFORM_MAC);
  84. #else
  85. editor->RequestPlatformChange(AE_PLATFORM_WINDOWS);
  86. #endif
  87. bool process = false;
  88. if (process)
  89. {
  90. SharedPtr<JSONSceneImporter> jimporter;
  91. jimporter = new JSONSceneImporter(context_);
  92. jimporter->Import("/Users/josh/Desktop/Blah.js");
  93. SharedPtr<JSONSceneProcess> sceneProcess;
  94. sceneProcess = new JSONSceneProcess(context_, jimporter);
  95. sceneProcess->Process();
  96. sceneProcess->Write();
  97. }
  98. }
  99. void AEApplication::Setup()
  100. {
  101. FileSystem* filesystem = GetSubsystem<FileSystem>();
  102. engineParameters_["WindowTitle"] = "AtomicEditor";
  103. engineParameters_["WindowResizable"] = true;
  104. engineParameters_["FullScreen"] = false;
  105. #ifdef __APPLE__
  106. engineParameters_["ResourcePrefixPath"] = "../Resources";
  107. #endif
  108. engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "AtomicEditor.log";
  109. // Show usage if not found
  110. if (false)//scriptFileName_.Empty())
  111. {
  112. ErrorExit("Usage: AtomicEditor <scriptfile> [options]\n\n"
  113. "The script file should implement the function void Start() for initializing the "
  114. "application and subscribing to all necessary events, such as the frame update.\n"
  115. #ifndef WIN32
  116. "\nCommand line options:\n"
  117. "-x <res> Horizontal resolution\n"
  118. "-y <res> Vertical resolution\n"
  119. "-m <level> Enable hardware multisampling\n"
  120. "-v Enable vertical sync\n"
  121. "-t Enable triple buffering\n"
  122. "-w Start in windowed mode\n"
  123. "-s Enable resizing when in windowed mode\n"
  124. "-q Enable quiet mode which does not log to standard output stream\n"
  125. "-b <length> Sound buffer length in milliseconds\n"
  126. "-r <freq> Sound mixing frequency in Hz\n"
  127. "-p <paths> Resource path(s) to use, separated by semicolons\n"
  128. "-ap <paths> Autoload resource path(s) to use, seperated by semicolons\n"
  129. "-log <level> Change the log level, valid 'level' values are 'debug', 'info', 'warning', 'error'\n"
  130. "-ds <file> Dump used shader variations to a file for precaching\n"
  131. "-mq <level> Material quality level, default 2 (high)\n"
  132. "-tq <level> Texture quality level, default 2 (high)\n"
  133. "-tf <level> Texture filter mode, default 2 (trilinear)\n"
  134. "-af <level> Texture anisotropy level, default 4. Also sets anisotropic filter mode\n"
  135. "-flushgpu Flush GPU command queue each frame. Effective only on Direct3D9\n"
  136. "-borderless Borderless window mode\n"
  137. "-headless Headless mode. No application window will be created\n"
  138. "-landscape Use landscape orientations (iOS only, default)\n"
  139. "-portrait Use portrait orientations (iOS only)\n"
  140. "-prepass Use light pre-pass rendering\n"
  141. "-deferred Use deferred rendering\n"
  142. "-lqshadows Use low-quality (1-sample) shadow filtering\n"
  143. "-noshadows Disable shadow rendering\n"
  144. "-nolimit Disable frame limiter\n"
  145. "-nothreads Disable worker threads\n"
  146. "-nosound Disable sound output\n"
  147. "-noip Disable sound mixing interpolation\n"
  148. "-sm2 Force SM2.0 rendering\n"
  149. "-touch Touch emulation on desktop platform\n"
  150. #endif
  151. );
  152. }
  153. else
  154. {
  155. // Use the script file name as the base name for the log file
  156. }
  157. }
  158. void AEApplication::Stop()
  159. {
  160. context_->RemoveSubsystem<Editor>();
  161. }
  162. }