AtomicGlowApp.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // Copyright (c) 2008-2016 the Urho3D project.
  3. // Copyright (c) 2014-2016, THUNDERBEAST GAMES LLC All rights reserved
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include <Atomic/Core/CoreEvents.h>
  24. #include <Atomic/Engine/Engine.h>
  25. #include <Atomic/IO/Log.h>
  26. #include <Atomic/IO/FileSystem.h>
  27. #include <ToolCore/ToolSystem.h>
  28. #include <ToolCore/ToolEnvironment.h>
  29. #include "AtomicGlowApp.h"
  30. // Test
  31. #include "ModelAOBake.h"
  32. #ifdef ATOMIC_PLATFORM_OSX
  33. #include <unistd.h>
  34. #endif
  35. #ifdef ATOMIC_PLATFORM_WINDOWS
  36. #include <stdio.h>
  37. #endif
  38. using namespace ToolCore;
  39. ATOMIC_DEFINE_APPLICATION_MAIN(AtomicGlow::AtomicGlowApp)
  40. namespace AtomicGlow
  41. {
  42. AtomicGlowApp::AtomicGlowApp(Context* context) :
  43. IPCClientApp(context)
  44. {
  45. SubscribeToEvent(E_UPDATE, ATOMIC_HANDLER(AtomicGlowApp, HandleUpdate));
  46. }
  47. void AtomicGlowApp::Setup()
  48. {
  49. IPCClientApp::Setup();
  50. // AtomicGlow is always headless
  51. engineParameters_["Headless"] = true;
  52. FileSystem* filesystem = GetSubsystem<FileSystem>();
  53. engineParameters_.InsertNew("LogName", filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "AtomicGlow.log");
  54. ToolSystem* tsystem = new ToolSystem(context_);
  55. context_->RegisterSubsystem(tsystem);
  56. ToolEnvironment* env = new ToolEnvironment(context_);
  57. context_->RegisterSubsystem(env);
  58. String projectPath;
  59. for (unsigned i = 0; i < arguments_.Size(); ++i)
  60. {
  61. if (arguments_[i].Length() > 1)
  62. {
  63. String argument = arguments_[i].ToLower();
  64. String value = i + 1 < arguments_.Size() ? arguments_[i + 1] : String::EMPTY;
  65. if (argument == "--project" && value.Length())
  66. {
  67. if (GetExtension(value) == ".atomic")
  68. {
  69. value = GetPath(value);
  70. }
  71. if (filesystem->DirExists(value))
  72. {
  73. }
  74. else
  75. {
  76. ErrorExit(ToString("%s project path does not exist", value.CString()));
  77. }
  78. projectPath = AddTrailingSlash(value);
  79. }
  80. }
  81. }
  82. if (!env->InitFromJSON())
  83. {
  84. ErrorExit(ToString("Unable to initialize tool environment from %s", env->GetDevConfigFilename().CString()));
  85. return;
  86. }
  87. tsystem->SetCLI();
  88. tsystem->SetDataPath(env->GetRootSourceDir() + "/Resources/");
  89. engineParameters_["ResourcePrefixPaths"] = env->GetRootSourceDir() + "/Resources/";
  90. engineParameters_["ResourcePaths"] = ToString("CoreData;EditorData;%sResources;%sCache", projectPath.CString(), projectPath.CString());
  91. }
  92. int AtomicGlowApp::Initialize()
  93. {
  94. Setup();
  95. if (exitCode_)
  96. return exitCode_;
  97. if (!engine_->Initialize(engineParameters_))
  98. {
  99. ErrorExit("engine_->Initialize(engineParameters_) failed");
  100. return exitCode_;
  101. }
  102. Start();
  103. if (exitCode_)
  104. return exitCode_;
  105. IPCClientApp::Initialize(arguments_);
  106. return 0;
  107. }
  108. void AtomicGlowApp::HandleUpdate(StringHash eventType, VariantMap& eventData)
  109. {
  110. SharedPtr<ModelAOBake> baker(new ModelAOBake(context_));
  111. baker->LoadModel("5630bdba26c7d8ab29daf2ceaba45cd2.mdl");
  112. exitCode_ = EXIT_SUCCESS;
  113. engine_->Exit();
  114. }
  115. void AtomicGlowApp::Stop()
  116. {
  117. Application::Stop();
  118. }
  119. void AtomicGlowApp::ErrorExit(const String& message)
  120. {
  121. engine_->Exit();
  122. exitCode_ = EXIT_FAILURE;
  123. // Only for WIN32, otherwise the error messages would be double posted on Mac OS X and Linux platforms
  124. if (!message.Length())
  125. {
  126. #ifdef WIN32
  127. Atomic::ErrorExit(startupErrors_.Length() ? startupErrors_ :
  128. "Application has been terminated due to unexpected error.", exitCode_);
  129. #endif
  130. }
  131. else
  132. Atomic::ErrorExit(message, exitCode_);
  133. }
  134. }