PlayerApp.cpp 5.4 KB

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