AtomicPlayer.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. // Move me
  31. #include <Atomic/Environment/Environment.h>
  32. #include <AtomicJS/Javascript/Javascript.h>
  33. #include "AtomicPlayer.h"
  34. #include <Atomic/DebugNew.h>
  35. #include <Atomic/UI/TBUI.h>
  36. DEFINE_APPLICATION_MAIN(AtomicPlayer);
  37. // fixme
  38. static JSVM* vm = NULL;
  39. static Javascript* javascript = NULL;
  40. AtomicPlayer::AtomicPlayer(Context* context) :
  41. Application(context)
  42. {
  43. #ifdef ATOMIC_3D
  44. RegisterEnvironmentLibrary(context_);
  45. #endif
  46. }
  47. void AtomicPlayer::Setup()
  48. {
  49. FileSystem* filesystem = GetSubsystem<FileSystem>();
  50. engineParameters_["WindowTitle"] = "AtomicPlayer";
  51. #if (ATOMIC_PLATFORM_ANDROID)
  52. engineParameters_["FullScreen"] = true;
  53. engineParameters_["ResourcePaths"] = "CoreData;AtomicResources";
  54. #elif ATOMIC_PLATFORM_WEB
  55. engineParameters_["FullScreen"] = false;
  56. engineParameters_["ResourcePaths"] = "AtomicResources";
  57. engineParameters_["WindowWidth"] = 1280;
  58. engineParameters_["WindowHeight"] = 720;
  59. #elif ATOMIC_PLATFORM_IOS
  60. engineParameters_["FullScreen"] = false;
  61. engineParameters_["ResourcePaths"] = "AtomicResources";
  62. #else
  63. engineParameters_["ResourcePaths"] = "AtomicResources";
  64. engineParameters_["FullScreen"] = false;
  65. engineParameters_["WindowWidth"] = 1280;
  66. engineParameters_["WindowHeight"] = 720;
  67. #endif
  68. #if ATOMIC_PLATFORM_WINDOWS
  69. engineParameters_["WindowIcon"] = "Images/AtomicLogo32.png";
  70. engineParameters_["ResourcePrefixPath"] = "AtomicPlayer_Resources";
  71. #elif ATOMIC_PLATFORM_ANDROID
  72. //engineParameters_["ResourcePrefixPath"] = "assets";
  73. #elif ATOMIC_PLATFORM_OSX
  74. engineParameters_["ResourcePrefixPath"] = "../Resources";
  75. #endif
  76. // Use the script file name as the base name for the log file
  77. engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicPlayer", "Logs") + "AtomicPlayer.log";
  78. }
  79. void AtomicPlayer::Start()
  80. {
  81. // Instantiate and register the Javascript subsystem
  82. javascript = new Javascript(context_);
  83. context_->RegisterSubsystem(javascript);
  84. vm = javascript->InstantiateVM("MainVM");
  85. vm->InitJSContext();
  86. vm->SetModuleSearchPath("Modules");
  87. if (!vm->ExecuteMain())
  88. {
  89. ErrorExit("Error executing Scripts/main.js");
  90. }
  91. return;
  92. }
  93. void AtomicPlayer::Stop()
  94. {
  95. context_->RemoveSubsystem<Javascript>();
  96. }
  97. void AtomicPlayer::HandleScriptReloadStarted(StringHash eventType, VariantMap& eventData)
  98. {
  99. }
  100. void AtomicPlayer::HandleScriptReloadFinished(StringHash eventType, VariantMap& eventData)
  101. {
  102. }
  103. void AtomicPlayer::HandleScriptReloadFailed(StringHash eventType, VariantMap& eventData)
  104. {
  105. ErrorExit();
  106. }