PlayerApp.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. }
  76. void PlayerApp::Start()
  77. {
  78. AppBase::Start();
  79. UI* ui = GetSubsystem<UI>();
  80. ui->Initialize("DefaultUI/language/lng_en.tb.txt");
  81. ui->LoadDefaultPlayerSkin();
  82. vm_->SetModuleSearchPaths("Modules");
  83. // Instantiate and register the Player subsystem
  84. context_->RegisterSubsystem(new AtomicPlayer::Player(context_));
  85. AtomicPlayer::jsapi_init_atomicplayer(vm_);
  86. if (executeJSMain_)
  87. {
  88. JSVM* vm = JSVM::GetJSVM(0);
  89. if (!vm->ExecuteMain())
  90. {
  91. SendEvent(E_EXITREQUESTED);
  92. }
  93. }
  94. GetSubsystem<Graphics>()->RaiseWindow();
  95. }
  96. void PlayerApp::Stop()
  97. {
  98. AppBase::Stop();
  99. }
  100. void PlayerApp::ProcessArguments()
  101. {
  102. AppBase::ProcessArguments();
  103. for (unsigned i = 0; i < arguments_.Size(); ++i)
  104. {
  105. if (arguments_[i].Length() > 1)
  106. {
  107. String argument = arguments_[i].ToLower();
  108. String value = i + 1 < arguments_.Size() ? arguments_[i + 1] : String::EMPTY;
  109. if (argument == "--windowposx" && value.Length())
  110. {
  111. engineParameters_["WindowPositionX"] = atoi(value.CString());
  112. }
  113. else if (argument == "--windowposy" && value.Length())
  114. {
  115. engineParameters_["WindowPositionY"] = atoi(value.CString());
  116. }
  117. else if (argument == "--windowwidth" && value.Length())
  118. {
  119. engineParameters_["WindowWidth"] = atoi(value.CString());
  120. }
  121. else if (argument == "--windowheight" && value.Length())
  122. {
  123. engineParameters_["WindowHeight"] = atoi(value.CString());
  124. }
  125. else if (argument == "--resizable")
  126. {
  127. engineParameters_["WindowResizable"] = true;
  128. }
  129. else if (argument == "--maximize")
  130. {
  131. engineParameters_["WindowMaximized"] = true;
  132. }
  133. }
  134. }
  135. }
  136. }