PlayerApp.cpp 5.6 KB

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