| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- //
- // Copyright (c) 2008-2014 the Urho3D project.
- //
- // 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/Atomic.h>
- #include <Atomic/Engine/Engine.h>
- #include <Atomic/IO/FileSystem.h>
- #include <Atomic/IO/Log.h>
- #include <Atomic/Core/Main.h>
- #include <Atomic/Core/ProcessUtils.h>
- #include <Atomic/Resource/ResourceCache.h>
- #include <Atomic/Resource/ResourceEvents.h>
- #include <Atomic/IPC/IPC.h>
- #include <Atomic/IPC/IPCWorker.h>
- // Move me
- #include <Atomic/Environment/Environment.h>
- #include <AtomicJS/Javascript/Javascript.h>
- #include "AEPlayerApplication.h"
- #include <Atomic/DebugNew.h>
- #include <Atomic/UI/UI.h>
- #ifdef __APPLE__
- #include <unistd.h>
- #endif
- namespace AtomicEditor
- {
- // fixme
- static JSVM* vm = NULL;
- static Javascript* javascript = NULL;
- AEPlayerApplication::AEPlayerApplication(Context* context) :
- Application(context)
- {
- fd_[0] = -1;
- fd_[1] = -1;
- #ifdef ATOMIC_3D
- RegisterEnvironmentLibrary(context_);
- #endif
- }
- void AEPlayerApplication::Setup()
- {
- FileSystem* filesystem = GetSubsystem<FileSystem>();
- engineParameters_["WindowTitle"] = "AtomicPlayer";
- #if (ATOMIC_PLATFORM_ANDROID)
- engineParameters_["FullScreen"] = true;
- engineParameters_["ResourcePaths"] = "CoreData;AtomicResources";
- #elif ATOMIC_PLATFORM_WEB
- engineParameters_["FullScreen"] = false;
- engineParameters_["ResourcePaths"] = "AtomicResources";
- // engineParameters_["WindowWidth"] = 1280;
- // engineParameters_["WindowHeight"] = 720;
- #elif ATOMIC_PLATFORM_IOS
- engineParameters_["FullScreen"] = false;
- engineParameters_["ResourcePaths"] = "AtomicResources";
- #else
- engineParameters_["ResourcePaths"] = "AtomicResources";
- engineParameters_["FullScreen"] = false;
- engineParameters_["WindowWidth"] = 1280;
- engineParameters_["WindowHeight"] = 720;
- #endif
- #if ATOMIC_PLATFORM_WINDOWS
- engineParameters_["WindowIcon"] = "Images/AtomicLogo32.png";
- engineParameters_["ResourcePrefixPath"] = "AtomicPlayer_Resources";
- #elif ATOMIC_PLATFORM_ANDROID
- //engineParameters_["ResourcePrefixPath"] = "assets";
- #elif ATOMIC_PLATFORM_OSX
- engineParameters_["ResourcePrefixPath"] = "../Resources";
- #endif
- const Vector<String>& arguments = GetArguments();
- 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;
- LOGERRORF("Starting IPCWorker %s", argument.CString());
- if (argument.StartsWith("--ipc-server=") || argument.StartsWith("--ipc-client="))
- {
- Vector<String> ipc = argument.Split(argument.CString(), '=');
- if (ipc.Size() == 2)
- {
- int fd = ToInt(ipc[1].CString());
- if (argument.StartsWith("--ipc-server="))
- fd_[0] = fd;
- else
- {
- fd_[1] = fd;
- }
- }
- }
- else if (argument == "--editor-resource-paths" && value.Length())
- {
- engineParameters_["ResourcePrefixPath"] = "";
- value.Replace("!", ";");
- engineParameters_["ResourcePaths"] = value;
- }
- }
- }
- // Use the script file name as the base name for the log file
- engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicPlayer", "Logs") + "AtomicPlayer.log";
- }
- void AEPlayerApplication::Start()
- {
- context_->RegisterSubsystem(new IPC(context_, fd_[0], fd_[1]));
- // Instantiate and register the Javascript subsystem
- javascript = new Javascript(context_);
- context_->RegisterSubsystem(javascript);
- vm = javascript->InstantiateVM("MainVM");
- vm->InitJSContext();
- vm->SetModuleSearchPath("Modules");
- if (!vm->ExecuteMain())
- {
- ErrorExit("Error executing Scripts/main.js");
- }
- return;
- }
- void AEPlayerApplication::Stop()
- {
- context_->RemoveSubsystem<Javascript>();
- }
- void AEPlayerApplication::HandleScriptReloadStarted(StringHash eventType, VariantMap& eventData)
- {
- }
- void AEPlayerApplication::HandleScriptReloadFinished(StringHash eventType, VariantMap& eventData)
- {
- }
- void AEPlayerApplication::HandleScriptReloadFailed(StringHash eventType, VariantMap& eventData)
- {
- ErrorExit();
- }
- }
|