BsPlayInEditorManager.h 2.1 KB

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