BsPlayInEditorManager.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /**
  55. * @brief Saves the current state of the scene in memory.
  56. */
  57. void saveSceneInMemory();
  58. PlayInEditorState mState;
  59. PlayInEditorState mNextState;
  60. bool mFrameStepActive;
  61. bool mScheduledStateChange;
  62. float mPausableTime;
  63. HSceneObject mSavedScene;
  64. };
  65. }