AtomicPlayer.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 <Atomic/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. RegisterEnvironmenttLibrary(context_);
  44. }
  45. void AtomicPlayer::Setup()
  46. {
  47. FileSystem* filesystem = GetSubsystem<FileSystem>();
  48. engineParameters_["WindowTitle"] = "AtomicPlayer";
  49. #if (ATOMIC_PLATFORM_ANDROID)
  50. engineParameters_["FullScreen"] = true;
  51. engineParameters_["ResourcePaths"] = "CoreData;Data;AtomicResources";
  52. #elif ATOMIC_PLATFORM_WEB
  53. engineParameters_["FullScreen"] = false;
  54. engineParameters_["ResourcePaths"] = "AtomicResources";
  55. engineParameters_["WindowWidth"] = 1280;
  56. engineParameters_["WindowHeight"] = 720;
  57. #elif ATOMIC_PLATFORM_IOS
  58. engineParameters_["FullScreen"] = false;
  59. engineParameters_["ResourcePaths"] = "AtomicResources";
  60. #else
  61. engineParameters_["ResourcePaths"] = "AtomicResources";
  62. engineParameters_["FullScreen"] = false;
  63. engineParameters_["WindowWidth"] = 1280;
  64. engineParameters_["WindowHeight"] = 720;
  65. #endif
  66. #if ATOMIC_PLATFORM_WINDOWS
  67. engineParameters_["ResourcePrefixPath"] = "AtomicPlayer_Resources";
  68. #elif ATOMIC_PLATFORM_ANDROID
  69. //engineParameters_["ResourcePrefixPath"] = "assets";
  70. #elif ATOMIC_PLATFORM_OSX
  71. engineParameters_["ResourcePrefixPath"] = "../Resources";
  72. #endif
  73. // Use the script file name as the base name for the log file
  74. engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicPlayer", "Logs") + "AtomicPlayer.log";
  75. }
  76. void AtomicPlayer::Start()
  77. {
  78. // Instantiate and register the Javascript subsystem
  79. javascript = new Javascript(context_);
  80. context_->RegisterSubsystem(javascript);
  81. vm = javascript->InstantiateVM("MainVM");
  82. vm->InitJSContext();
  83. vm->SetModuleSearchPath("Modules");
  84. if (!vm->ExecuteMain())
  85. {
  86. ErrorExit("Error executing Scripts/main.js");
  87. }
  88. return;
  89. }
  90. void AtomicPlayer::Stop()
  91. {
  92. context_->RemoveSubsystem<Javascript>();
  93. }
  94. void AtomicPlayer::HandleScriptReloadStarted(StringHash eventType, VariantMap& eventData)
  95. {
  96. }
  97. void AtomicPlayer::HandleScriptReloadFinished(StringHash eventType, VariantMap& eventData)
  98. {
  99. }
  100. void AtomicPlayer::HandleScriptReloadFailed(StringHash eventType, VariantMap& eventData)
  101. {
  102. ErrorExit();
  103. }