AEPlayerApplication.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  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/Atomic.h>
  23. #include <Atomic/Engine/Engine.h>
  24. #include <Atomic/IO/FileSystem.h>
  25. #include <Atomic/IO/Log.h>
  26. #include <Atomic/Core/Main.h>
  27. #include <Atomic/Core/ProcessUtils.h>
  28. #include <Atomic/Resource/ResourceCache.h>
  29. #include <Atomic/Resource/ResourceEvents.h>
  30. #include <Atomic/IPC/IPC.h>
  31. #include <Atomic/IPC/IPCWorker.h>
  32. // Move me
  33. #include <Atomic/Environment/Environment.h>
  34. #include <AtomicJS/Javascript/Javascript.h>
  35. #include "AEPlayerApplication.h"
  36. #include <Atomic/DebugNew.h>
  37. #include <Atomic/UI/UI.h>
  38. #ifdef __APPLE__
  39. #include <unistd.h>
  40. #endif
  41. namespace AtomicEditor
  42. {
  43. // fixme
  44. static JSVM* vm = NULL;
  45. static Javascript* javascript = NULL;
  46. AEPlayerApplication::AEPlayerApplication(Context* context) :
  47. Application(context)
  48. {
  49. fd_[0] = -1;
  50. fd_[1] = -1;
  51. #ifdef ATOMIC_3D
  52. RegisterEnvironmentLibrary(context_);
  53. #endif
  54. }
  55. void AEPlayerApplication::Setup()
  56. {
  57. FileSystem* filesystem = GetSubsystem<FileSystem>();
  58. engineParameters_["WindowTitle"] = "AtomicPlayer";
  59. #if (ATOMIC_PLATFORM_ANDROID)
  60. engineParameters_["FullScreen"] = true;
  61. engineParameters_["ResourcePaths"] = "CoreData;AtomicResources";
  62. #elif ATOMIC_PLATFORM_WEB
  63. engineParameters_["FullScreen"] = false;
  64. engineParameters_["ResourcePaths"] = "AtomicResources";
  65. // engineParameters_["WindowWidth"] = 1280;
  66. // engineParameters_["WindowHeight"] = 720;
  67. #elif ATOMIC_PLATFORM_IOS
  68. engineParameters_["FullScreen"] = false;
  69. engineParameters_["ResourcePaths"] = "AtomicResources";
  70. #else
  71. engineParameters_["ResourcePaths"] = "AtomicResources";
  72. engineParameters_["FullScreen"] = false;
  73. engineParameters_["WindowWidth"] = 1280;
  74. engineParameters_["WindowHeight"] = 720;
  75. #endif
  76. #if ATOMIC_PLATFORM_WINDOWS
  77. engineParameters_["WindowIcon"] = "Images/AtomicLogo32.png";
  78. engineParameters_["ResourcePrefixPath"] = "AtomicPlayer_Resources";
  79. #elif ATOMIC_PLATFORM_ANDROID
  80. //engineParameters_["ResourcePrefixPath"] = "assets";
  81. #elif ATOMIC_PLATFORM_OSX
  82. engineParameters_["ResourcePrefixPath"] = "../Resources";
  83. #endif
  84. const Vector<String>& arguments = GetArguments();
  85. for (unsigned i = 0; i < arguments.Size(); ++i)
  86. {
  87. if (arguments[i].Length() > 1)
  88. {
  89. String argument = arguments[i].ToLower();
  90. String value = i + 1 < arguments.Size() ? arguments[i + 1] : String::EMPTY;
  91. LOGERRORF("Starting IPCWorker %s", argument.CString());
  92. if (argument.StartsWith("--ipc-server=") || argument.StartsWith("--ipc-client="))
  93. {
  94. Vector<String> ipc = argument.Split(argument.CString(), '=');
  95. if (ipc.Size() == 2)
  96. {
  97. int fd = ToInt(ipc[1].CString());
  98. if (argument.StartsWith("--ipc-server="))
  99. fd_[0] = fd;
  100. else
  101. {
  102. fd_[1] = fd;
  103. }
  104. }
  105. }
  106. else if (argument == "--editor-resource-paths" && value.Length())
  107. {
  108. engineParameters_["ResourcePrefixPath"] = "";
  109. value.Replace("!", ";");
  110. engineParameters_["ResourcePaths"] = value;
  111. }
  112. }
  113. }
  114. // Use the script file name as the base name for the log file
  115. engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicPlayer", "Logs") + "AtomicPlayer.log";
  116. }
  117. void AEPlayerApplication::Start()
  118. {
  119. context_->RegisterSubsystem(new IPC(context_, fd_[0], fd_[1]));
  120. // Instantiate and register the Javascript subsystem
  121. javascript = new Javascript(context_);
  122. context_->RegisterSubsystem(javascript);
  123. vm = javascript->InstantiateVM("MainVM");
  124. vm->InitJSContext();
  125. vm->SetModuleSearchPath("Modules");
  126. if (!vm->ExecuteMain())
  127. {
  128. ErrorExit("Error executing Scripts/main.js");
  129. }
  130. return;
  131. }
  132. void AEPlayerApplication::Stop()
  133. {
  134. context_->RemoveSubsystem<Javascript>();
  135. }
  136. void AEPlayerApplication::HandleScriptReloadStarted(StringHash eventType, VariantMap& eventData)
  137. {
  138. }
  139. void AEPlayerApplication::HandleScriptReloadFinished(StringHash eventType, VariantMap& eventData)
  140. {
  141. }
  142. void AEPlayerApplication::HandleScriptReloadFailed(StringHash eventType, VariantMap& eventData)
  143. {
  144. ErrorExit();
  145. }
  146. }