PlayerApp.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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/InputEvents.h>
  23. #include <Atomic/Engine/Engine.h>
  24. #include <Atomic/Graphics/Graphics.h>
  25. #include <Atomic/Resource/ResourceMapRouter.h>
  26. #include <Atomic/UI/UI.h>
  27. #include <Atomic/Metrics/Metrics.h>
  28. #include <AtomicJS/Javascript/Javascript.h>
  29. #include <AtomicPlayer/Player.h>
  30. #include "PlayerApp.h"
  31. namespace AtomicPlayer
  32. {
  33. extern void jsapi_init_atomicplayer(JSVM* vm);
  34. }
  35. namespace Atomic
  36. {
  37. PlayerLaunchMode PlayerApp::launchMode_ = PLAYER_LAUNCH_STANDALONE;
  38. PlayerApp::PlayerApp(Context* context) :
  39. AppBase(context),
  40. executeJSMain_(true),
  41. playerMetrics_(false)
  42. {
  43. }
  44. PlayerApp::~PlayerApp()
  45. {
  46. }
  47. void PlayerApp::Setup()
  48. {
  49. AppBase::Setup();
  50. FileSystem *filesystem = GetSubsystem<FileSystem>();
  51. engineParameters_.InsertNew("WindowTitle", "AtomicPlayer");
  52. #if (ATOMIC_PLATFORM_ANDROID)
  53. engineParameters_.InsertNew("FullScreen", true);
  54. engineParameters_.InsertNew("ResourcePaths", "CoreData;PlayerData;Cache;AtomicResources");
  55. #elif ATOMIC_PLATFORM_WEB
  56. engineParameters_.InsertNew("FullScreen", false);
  57. engineParameters_.InsertNew("ResourcePaths", "AtomicResources");
  58. // engineParameters_.InsertNew("WindowWidth", 1280);
  59. // engineParameters_.InsertNew("WindowHeight", 720);
  60. #elif ATOMIC_PLATFORM_IOS
  61. engineParameters_.InsertNew("FullScreen", false);
  62. engineParameters_.InsertNew("ResourcePaths", "AtomicResources");
  63. #else
  64. engineParameters_.InsertNew("FullScreen", false);
  65. engineParameters_.InsertNew("WindowWidth", 1280);
  66. engineParameters_.InsertNew("WindowHeight", 720);
  67. engineParameters_.InsertNew("ResourcePaths", "AtomicResources");
  68. #endif
  69. #if ATOMIC_PLATFORM_WINDOWS || ATOMIC_PLATFORM_LINUX
  70. engineParameters_.InsertNew("WindowIcon", "Images/AtomicLogo32.png");
  71. engineParameters_.InsertNew("ResourcePrefixPaths", "AtomicPlayer_Resources");
  72. #elif ATOMIC_PLATFORM_ANDROID
  73. //engineParameters_.InsertNew("ResourcePrefixPaths"], "assets");
  74. #elif ATOMIC_PLATFORM_OSX
  75. engineParameters_.InsertNew("ResourcePrefixPaths", filesystem->GetProgramDir() + "../Resources");
  76. #endif
  77. // Setup player log
  78. engineParameters_.InsertNew("LogName", filesystem->GetAppPreferencesDir("AtomicPlayer", "Logs") + "AtomicPlayer.log");
  79. // Register JS packages
  80. JSVM::RegisterPackage(AtomicPlayer::jsapi_init_atomicplayer);
  81. }
  82. void PlayerApp::Start()
  83. {
  84. // Initialize resource mapper
  85. SharedPtr<ResourceMapRouter> router(new ResourceMapRouter(context_, "__atomic_ResourceCacheMap.json"));
  86. UI* ui = GetSubsystem<UI>();
  87. ui->Initialize("DefaultUI/language/lng_en.tb.txt");
  88. ui->LoadDefaultPlayerSkin();
  89. vm_->SetModuleSearchPaths("Modules");
  90. // Instantiate and register the Player subsystem
  91. context_->RegisterSubsystem(new AtomicPlayer::Player(context_));
  92. AppBase::Start();
  93. if (playerMetrics_)
  94. {
  95. Metrics* metrics = GetSubsystem<Metrics>();
  96. if (metrics && !metrics->GetEnabled())
  97. {
  98. metrics->Enable();
  99. }
  100. }
  101. if (executeJSMain_)
  102. {
  103. JSVM* vm = JSVM::GetJSVM(0);
  104. if (!vm->ExecuteMain())
  105. {
  106. SendEvent(E_EXITREQUESTED);
  107. }
  108. }
  109. GetSubsystem<Graphics>()->RaiseWindow();
  110. }
  111. void PlayerApp::Stop()
  112. {
  113. AppBase::Stop();
  114. }
  115. void PlayerApp::ProcessArguments()
  116. {
  117. AppBase::ProcessArguments();
  118. for (unsigned i = 0; i < arguments_.Size(); ++i)
  119. {
  120. if (arguments_[i].Length() > 1)
  121. {
  122. String argument = arguments_[i].ToLower();
  123. String value = i + 1 < arguments_.Size() ? arguments_[i + 1] : String::EMPTY;
  124. if (argument == "--windowposx" && value.Length())
  125. {
  126. engineParameters_["WindowPositionX"] = atoi(value.CString());
  127. }
  128. else if (argument == "--windowposy" && value.Length())
  129. {
  130. engineParameters_["WindowPositionY"] = atoi(value.CString());
  131. }
  132. else if (argument == "--windowwidth" && value.Length())
  133. {
  134. engineParameters_["WindowWidth"] = atoi(value.CString());
  135. }
  136. else if (argument == "--windowheight" && value.Length())
  137. {
  138. engineParameters_["WindowHeight"] = atoi(value.CString());
  139. }
  140. else if (argument == "--resizable")
  141. {
  142. engineParameters_["WindowResizable"] = true;
  143. }
  144. else if (argument == "--maximize")
  145. {
  146. engineParameters_["WindowMaximized"] = true;
  147. }
  148. else if (argument == "--playermetrics")
  149. {
  150. playerMetrics_ = true;
  151. }
  152. }
  153. }
  154. }
  155. }