| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- //
- // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #include <Atomic/Input/InputEvents.h>
- #include <Atomic/Engine/Engine.h>
- #include <Atomic/Graphics/Graphics.h>
- #include <Atomic/Resource/ResourceMapRouter.h>
- #include <Atomic/UI/UI.h>
- #include <Atomic/Metrics/Metrics.h>
- #include <AtomicJS/Javascript/Javascript.h>
- #include <AtomicPlayer/Player.h>
- #include "PlayerApp.h"
- namespace AtomicPlayer
- {
- extern void jsapi_init_atomicplayer(JSVM* vm);
- }
- namespace Atomic
- {
- PlayerLaunchMode PlayerApp::launchMode_ = PLAYER_LAUNCH_STANDALONE;
- PlayerApp::PlayerApp(Context* context) :
- AppBase(context),
- executeJSMain_(true),
- playerMetrics_(false)
- {
- }
- PlayerApp::~PlayerApp()
- {
- }
- void PlayerApp::Setup()
- {
- AppBase::Setup();
- FileSystem *filesystem = GetSubsystem<FileSystem>();
- engineParameters_.InsertNew("WindowTitle", "AtomicPlayer");
- #if (ATOMIC_PLATFORM_ANDROID)
- engineParameters_.InsertNew("FullScreen", true);
- engineParameters_.InsertNew("ResourcePaths", "CoreData;PlayerData;Cache;AtomicResources");
- #elif ATOMIC_PLATFORM_WEB
- engineParameters_.InsertNew("FullScreen", false);
- engineParameters_.InsertNew("ResourcePaths", "AtomicResources");
- // engineParameters_.InsertNew("WindowWidth", 1280);
- // engineParameters_.InsertNew("WindowHeight", 720);
- #elif ATOMIC_PLATFORM_IOS
- engineParameters_.InsertNew("FullScreen", false);
- engineParameters_.InsertNew("ResourcePaths", "AtomicResources");
- #else
- engineParameters_.InsertNew("FullScreen", false);
- engineParameters_.InsertNew("WindowWidth", 1280);
- engineParameters_.InsertNew("WindowHeight", 720);
- engineParameters_.InsertNew("ResourcePaths", "AtomicResources");
- #endif
- #if ATOMIC_PLATFORM_WINDOWS || ATOMIC_PLATFORM_LINUX
- engineParameters_.InsertNew("WindowIcon", "Images/AtomicLogo32.png");
- engineParameters_.InsertNew("ResourcePrefixPaths", "AtomicPlayer_Resources");
- #elif ATOMIC_PLATFORM_ANDROID
- //engineParameters_.InsertNew("ResourcePrefixPaths"], "assets");
- #elif ATOMIC_PLATFORM_OSX
- engineParameters_.InsertNew("ResourcePrefixPaths", filesystem->GetProgramDir() + "../Resources");
- #endif
- // Setup player log
- engineParameters_.InsertNew("LogName", filesystem->GetAppPreferencesDir("AtomicPlayer", "Logs") + "AtomicPlayer.log");
- // Register JS packages
- JSVM::RegisterPackage(AtomicPlayer::jsapi_init_atomicplayer);
- }
- void PlayerApp::Start()
- {
- // Initialize resource mapper
- SharedPtr<ResourceMapRouter> router(new ResourceMapRouter(context_, "__atomic_ResourceCacheMap.json"));
- UI* ui = GetSubsystem<UI>();
- ui->Initialize("DefaultUI/language/lng_en.tb.txt");
- ui->LoadDefaultPlayerSkin();
- vm_->SetModuleSearchPaths("Modules");
- // Instantiate and register the Player subsystem
- context_->RegisterSubsystem(new AtomicPlayer::Player(context_));
- AppBase::Start();
- if (playerMetrics_)
- {
- Metrics* metrics = GetSubsystem<Metrics>();
- if (metrics && !metrics->GetEnabled())
- {
- metrics->Enable();
- }
- }
- if (executeJSMain_)
- {
- JSVM* vm = JSVM::GetJSVM(0);
- if (!vm->ExecuteMain())
- {
- SendEvent(E_EXITREQUESTED);
- }
- }
- GetSubsystem<Graphics>()->RaiseWindow();
- }
- void PlayerApp::Stop()
- {
- AppBase::Stop();
- }
- void PlayerApp::ProcessArguments()
- {
- AppBase::ProcessArguments();
- for (unsigned i = 0; i < arguments_.Size(); ++i)
- {
- if (arguments_[i].Length() > 1)
- {
- String argument = arguments_[i].ToLower();
- String value = i + 1 < arguments_.Size() ? arguments_[i + 1] : String::EMPTY;
- if (argument == "--windowposx" && value.Length())
- {
- engineParameters_["WindowPositionX"] = atoi(value.CString());
- }
- else if (argument == "--windowposy" && value.Length())
- {
- engineParameters_["WindowPositionY"] = atoi(value.CString());
- }
- else if (argument == "--windowwidth" && value.Length())
- {
- engineParameters_["WindowWidth"] = atoi(value.CString());
- }
- else if (argument == "--windowheight" && value.Length())
- {
- engineParameters_["WindowHeight"] = atoi(value.CString());
- }
- else if (argument == "--resizable")
- {
- engineParameters_["WindowResizable"] = true;
- }
- else if (argument == "--maximize")
- {
- engineParameters_["WindowMaximized"] = true;
- }
- else if (argument == "--playermetrics")
- {
- playerMetrics_ = true;
- }
- }
- }
- }
- }
|