PlayerApp.cpp 6.1 KB

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