engine.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**************************************************************************/
  2. /* engine.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef ENGINE_H
  31. #define ENGINE_H
  32. #include "core/list.h"
  33. #include "core/os/main_loop.h"
  34. #include "core/ustring.h"
  35. #include "core/vector.h"
  36. class Engine {
  37. public:
  38. struct Singleton {
  39. StringName name;
  40. Object *ptr;
  41. Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr);
  42. };
  43. private:
  44. friend class Main;
  45. uint64_t frames_drawn;
  46. uint32_t _frame_delay;
  47. uint64_t _frame_ticks;
  48. float _frame_step;
  49. int ips;
  50. float physics_jitter_fix;
  51. float _fps;
  52. int _target_fps;
  53. float _time_scale;
  54. bool _gpu_pixel_snap;
  55. uint64_t _physics_frames;
  56. float _physics_interpolation_fraction;
  57. bool _portals_active;
  58. bool _occlusion_culling_active;
  59. uint64_t _idle_frames;
  60. bool _in_physics;
  61. List<Singleton> singletons;
  62. Map<StringName, Object *> singleton_ptrs;
  63. bool editor_hint;
  64. static Engine *singleton;
  65. public:
  66. static Engine *get_singleton();
  67. virtual void set_iterations_per_second(int p_ips);
  68. virtual int get_iterations_per_second() const;
  69. void set_physics_jitter_fix(float p_threshold);
  70. float get_physics_jitter_fix() const;
  71. virtual void set_target_fps(int p_fps);
  72. virtual int get_target_fps() const;
  73. virtual float get_frames_per_second() const { return _fps; }
  74. uint64_t get_frames_drawn();
  75. uint64_t get_physics_frames() const { return _physics_frames; }
  76. uint64_t get_idle_frames() const { return _idle_frames; }
  77. bool is_in_physics_frame() const { return _in_physics; }
  78. uint64_t get_idle_frame_ticks() const { return _frame_ticks; }
  79. float get_idle_frame_step() const { return _frame_step; }
  80. float get_physics_interpolation_fraction() const { return _physics_interpolation_fraction; }
  81. void set_time_scale(float p_scale);
  82. float get_time_scale() const;
  83. void set_frame_delay(uint32_t p_msec);
  84. uint32_t get_frame_delay() const;
  85. void set_print_error_messages(bool p_enabled);
  86. bool is_printing_error_messages() const;
  87. void add_singleton(const Singleton &p_singleton);
  88. void get_singletons(List<Singleton> *p_singletons);
  89. bool has_singleton(const String &p_name) const;
  90. Object *get_singleton_object(const String &p_name) const;
  91. _FORCE_INLINE_ bool get_use_gpu_pixel_snap() const { return _gpu_pixel_snap; }
  92. bool are_portals_active() const { return _portals_active; }
  93. void set_portals_active(bool p_active);
  94. #ifdef TOOLS_ENABLED
  95. _FORCE_INLINE_ void set_editor_hint(bool p_enabled) { editor_hint = p_enabled; }
  96. _FORCE_INLINE_ bool is_editor_hint() const { return editor_hint; }
  97. #else
  98. _FORCE_INLINE_ void set_editor_hint(bool p_enabled) {}
  99. _FORCE_INLINE_ bool is_editor_hint() const { return false; }
  100. #endif
  101. Dictionary get_version_info() const;
  102. Dictionary get_author_info() const;
  103. Array get_copyright_info() const;
  104. Dictionary get_donor_info() const;
  105. Dictionary get_license_info() const;
  106. String get_license_text() const;
  107. Engine();
  108. virtual ~Engine() {}
  109. };
  110. #endif // ENGINE_H