BsPlayInEditorManager.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsModule.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief States the game in editor can be in.
  8. */
  9. enum class PlayInEditorState
  10. {
  11. Stopped,
  12. Playing,
  13. Paused
  14. };
  15. /**
  16. * @brief Handles functionality specific to running the game in editor.
  17. *
  18. * @note Play-in-editor functionality is only available for managed code, but can be easily extended to
  19. * native code if needed (this would involve moving play in editor code into BansheeEngine library).
  20. */
  21. class BS_SCR_BE_EXPORT PlayInEditorManager : public Module<PlayInEditorManager>
  22. {
  23. public:
  24. PlayInEditorManager();
  25. /**
  26. * @brief Returns the current play state of the game.
  27. */
  28. PlayInEditorState getState() const { return mState; }
  29. /**
  30. * @brief Updates the play state of the game, making the game stop or start running.
  31. */
  32. void setState(PlayInEditorState state);
  33. /**
  34. * @brief Gets the number of seconds that have elapsed since the game was started. This time does not
  35. * include time passed while the game is paused.
  36. */
  37. float getPausableTime() const { return mPausableTime; }
  38. /**
  39. * @brief Runs the game for a single frame and then pauses it.
  40. */
  41. void frameStep();
  42. /**
  43. * @brief Called once per frame.
  44. *
  45. * @note Internal method.
  46. */
  47. void update();
  48. private:
  49. /**
  50. * @brief Updates the play state of the game, making the game stop or start running. Unlike ::setState this
  51. * will trigger the state change right away.
  52. */
  53. void setStateImmediate(PlayInEditorState state);
  54. PlayInEditorState mState;
  55. PlayInEditorState mNextState;
  56. bool mFrameStepActive;
  57. bool mScheduledStateChange;
  58. float mPausableTime;
  59. HSceneObject mSavedScene;
  60. };
  61. }