AEPlayer.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include "../Subprocess/AESubprocessSystem.h"
  6. #include <Atomic/Core/Context.h>
  7. #include <Atomic/Core/StringUtils.h>
  8. #include <Atomic/IO/FileSystem.h>
  9. #include <Atomic/IO/Log.h>
  10. #include <Atomic/Input/Input.h>
  11. #include <Atomic/Resource/ResourceCache.h>
  12. #include <Atomic/UI/UI.h>
  13. #include <ToolCore/ToolEnvironment.h>
  14. #include "AEPlayer.h"
  15. #include "AEEvents.h"
  16. #include "AEEditor.h"
  17. #include "Project/AEProject.h"
  18. #include "UIPlayer.h"
  19. #include "UI/Modal/UIModalOps.h"
  20. namespace AtomicEditor
  21. {
  22. AEPlayer::AEPlayer(Context* context) :
  23. Object(context),
  24. mode_(AE_PLAYERMODE_WIDGET)
  25. {
  26. SubscribeToEvent(E_EDITORSHUTDOWN, HANDLER(AEPlayer, HandleEditorShutdown));
  27. SubscribeToEvent(E_IPCWORKERSTART, HANDLER(AEPlayer, HandleIPCWorkerStarted));
  28. assert(!context->GetSubsystem<AEPlayer>());
  29. context->RegisterSubsystem(this);
  30. }
  31. AEPlayer::~AEPlayer()
  32. {
  33. }
  34. void AEPlayer::Invalidate()
  35. {
  36. UIModalOps* ops = GetSubsystem<UIModalOps>();
  37. ops->Hide();
  38. context_->RemoveSubsystem<AEPlayer>();
  39. }
  40. void AEPlayer::HandleJSError(StringHash eventType, VariantMap& eventData)
  41. {
  42. }
  43. void AEPlayer::HandleIPCWorkerStarted(StringHash eventType, VariantMap& eventData)
  44. {
  45. //VariantMap weventData;
  46. //broker_->PostMessage(E_IPCSTARTUP, weventData);
  47. }
  48. void AEPlayer::HandleIPCWorkerExit(StringHash eventType, VariantMap& eventData)
  49. {
  50. SendEvent(E_EDITORPLAYSTOP);
  51. }
  52. bool AEPlayer::Play(AEPlayerMode mode, const IntRect &rect)
  53. {
  54. Editor* editor = GetSubsystem<Editor>();
  55. ToolCore::ToolEnvironment* env = GetSubsystem<ToolCore::ToolEnvironment>();
  56. const String& editorBinary = env->GetEditorBinary();
  57. Project* project = editor->GetProject();
  58. Vector<String> paths;
  59. paths.Push(env->GetCoreDataDir());
  60. paths.Push(env->GetPlayerDataDir());
  61. paths.Push(project->GetResourcePath());
  62. String resourcePaths;
  63. resourcePaths.Join(paths, "!");
  64. Vector<String> vargs;
  65. String args = ToString("--editor-resource-paths \"%s\"", resourcePaths.CString());
  66. vargs = args.Split(' ');
  67. vargs.Insert(0, "--player");
  68. String dump;
  69. dump.Join(vargs, " ");
  70. LOGINFOF("Launching Broker %s %s", editorBinary.CString(), dump.CString());
  71. IPC* ipc = GetSubsystem<IPC>();
  72. broker_ = ipc->SpawnWorker(editorBinary, vargs);
  73. if (broker_)
  74. {
  75. SubscribeToEvent(broker_, E_IPCWORKEREXIT, HANDLER(AEPlayer, HandleIPCWorkerExit));
  76. }
  77. return broker_.NotNull();
  78. }
  79. void AEPlayer::SetUIPlayer(UIPlayer* uiPlayer)
  80. {
  81. uiPlayer_ = uiPlayer;
  82. }
  83. void AEPlayer::HandleEditorShutdown(StringHash eventType, VariantMap& eventData)
  84. {
  85. context_->RemoveSubsystem(GetType());
  86. }
  87. }