2
0

Engine.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // Copyright (c) 2008-2013 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. #pragma once
  23. #include "Object.h"
  24. #include "Timer.h"
  25. namespace Urho3D
  26. {
  27. class Console;
  28. class DebugHud;
  29. /// Urho3D engine. Creates the other subsystems.
  30. class Engine : public Object
  31. {
  32. OBJECT(Engine);
  33. public:
  34. /// Construct.
  35. Engine(Context* context);
  36. /// Destruct. Free all subsystems.
  37. virtual ~Engine();
  38. /// Initialize engine using parameters given and show the application window. Return true if successful.
  39. bool Initialize(const VariantMap& parameters);
  40. /// Initialize script subsystem and register the script API. Return true if successful (engine must be initialized first.)
  41. bool InitializeScripting();
  42. /// Run one frame.
  43. void RunFrame();
  44. /// Create the console and return it. May return null if engine configuration does not allow creation (headless mode.)
  45. Console* CreateConsole();
  46. /// Create the debug hud.
  47. DebugHud* CreateDebugHud();
  48. /// Set minimum frames per second. If FPS goes lower than this, time will appear to slow down.
  49. void SetMinFps(int fps);
  50. /// Set maximum frames per second. The engine will sleep if FPS is higher than this.
  51. void SetMaxFps(int fps);
  52. /// Set maximum frames per second when the application does not have input focus.
  53. void SetMaxInactiveFps(int fps);
  54. /// Set whether to pause update events and audio when minimized.
  55. void SetPauseMinimized(bool enable);
  56. /// Close the application window and set the exit flag.
  57. void Exit();
  58. /// Dump profiling information to the log.
  59. void DumpProfiler();
  60. /// Dump information of all resources to the log.
  61. void DumpResources();
  62. /// Dump information of all memory allocations to the log. Supported in MSVC debug mode only.
  63. void DumpMemory();
  64. /// Return the minimum frames per second.
  65. int GetMinFps() const { return minFps_; }
  66. /// Return the maximum frames per second.
  67. int GetMaxFps() const { return maxFps_; }
  68. /// Return the maximum frames per second when the application does not have input focus.
  69. int GetMaxInactiveFps() const { return maxInactiveFps_; }
  70. /// Return whether to pause update events and audio when minimized.
  71. bool GetPauseMinimized() const { return pauseMinimized_; }
  72. /// Return whether engine has been initialized.
  73. bool IsInitialized() const { return initialized_; }
  74. /// Return whether exit has been requested.
  75. bool IsExiting() const { return exiting_; }
  76. /// Return whether the engine has been created in headless mode.
  77. bool IsHeadless() const { return headless_; }
  78. /// Send frame update events.
  79. void Update();
  80. /// Render after frame update.
  81. void Render();
  82. /// Get the timestep for the next frame and sleep for frame limiting if necessary.
  83. void ApplyFrameLimit();
  84. /// Parse the engine startup parameters map from command line arguments.
  85. static VariantMap ParseParameters(const Vector<String>& arguments);
  86. /// Return whether startup parameters contains a specific parameter.
  87. static bool HasParameter(const VariantMap& parameters, const String& parameter);
  88. /// Get an engine startup parameter, with default value if missing.
  89. static const Variant& GetParameter(const VariantMap& parameters, const String& parameter, const Variant& defaultValue = Variant::EMPTY);
  90. private:
  91. /// Register object factories and attributes.
  92. void RegisterObjects();
  93. /// Create and register subsystems. In headless mode graphics, input & UI are not created.
  94. void RegisterSubsystems();
  95. /// Frame update timer.
  96. HiresTimer frameTimer_;
  97. /// Next frame timestep in seconds.
  98. float timeStep_;
  99. /// Minimum frames per second.
  100. unsigned minFps_;
  101. /// Maximum frames per second.
  102. unsigned maxFps_;
  103. /// Maximum frames per second when the application does not have input focus.
  104. unsigned maxInactiveFps_;
  105. /// Pause when minimized flag.
  106. bool pauseMinimized_;
  107. /// Initialized flag.
  108. bool initialized_;
  109. /// Exiting flag.
  110. bool exiting_;
  111. /// Headless mode flag.
  112. bool headless_;
  113. /// Audio paused flag.
  114. bool audioPaused_;
  115. };
  116. }