engine.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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/os/main_loop.h"
  33. #include "core/string/ustring.h"
  34. #include "core/templates/list.h"
  35. #include "core/templates/vector.h"
  36. template <typename T>
  37. class TypedArray;
  38. class Engine {
  39. public:
  40. struct Singleton {
  41. StringName name;
  42. Object *ptr = nullptr;
  43. StringName class_name; //used for binding generation hinting
  44. bool user_created = false;
  45. Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr, const StringName &p_class_name = StringName());
  46. };
  47. private:
  48. friend class Main;
  49. uint64_t frames_drawn = 0;
  50. uint32_t _frame_delay = 0;
  51. uint64_t _frame_ticks = 0;
  52. double _process_step = 0;
  53. int ips = 60;
  54. double physics_jitter_fix = 0.5;
  55. double _fps = 1;
  56. int _max_fps = 0;
  57. double _time_scale = 1.0;
  58. uint64_t _physics_frames = 0;
  59. int max_physics_steps_per_frame = 8;
  60. double _physics_interpolation_fraction = 0.0f;
  61. bool abort_on_gpu_errors = false;
  62. bool use_validation_layers = false;
  63. int32_t gpu_idx = -1;
  64. uint64_t _process_frames = 0;
  65. bool _in_physics = false;
  66. List<Singleton> singletons;
  67. HashMap<StringName, Object *> singleton_ptrs;
  68. bool editor_hint = false;
  69. bool project_manager_hint = false;
  70. static Engine *singleton;
  71. String write_movie_path;
  72. String shader_cache_path;
  73. Dictionary startup_benchmark_json;
  74. String startup_benchmark_section;
  75. uint64_t startup_benchmark_from = 0;
  76. uint64_t startup_benchmark_total_from = 0;
  77. public:
  78. static Engine *get_singleton();
  79. virtual void set_physics_ticks_per_second(int p_ips);
  80. virtual int get_physics_ticks_per_second() const;
  81. virtual void set_max_physics_steps_per_frame(int p_max_physics_steps);
  82. virtual int get_max_physics_steps_per_frame() const;
  83. void set_physics_jitter_fix(double p_threshold);
  84. double get_physics_jitter_fix() const;
  85. virtual void set_max_fps(int p_fps);
  86. virtual int get_max_fps() const;
  87. virtual double get_frames_per_second() const { return _fps; }
  88. uint64_t get_frames_drawn();
  89. uint64_t get_physics_frames() const { return _physics_frames; }
  90. uint64_t get_process_frames() const { return _process_frames; }
  91. bool is_in_physics_frame() const { return _in_physics; }
  92. uint64_t get_frame_ticks() const { return _frame_ticks; }
  93. double get_process_step() const { return _process_step; }
  94. double get_physics_interpolation_fraction() const { return _physics_interpolation_fraction; }
  95. void set_time_scale(double p_scale);
  96. double get_time_scale() const;
  97. void set_print_error_messages(bool p_enabled);
  98. bool is_printing_error_messages() const;
  99. void set_frame_delay(uint32_t p_msec);
  100. uint32_t get_frame_delay() const;
  101. void add_singleton(const Singleton &p_singleton);
  102. void get_singletons(List<Singleton> *p_singletons);
  103. bool has_singleton(const StringName &p_name) const;
  104. Object *get_singleton_object(const StringName &p_name) const;
  105. void remove_singleton(const StringName &p_name);
  106. bool is_singleton_user_created(const StringName &p_name) const;
  107. #ifdef TOOLS_ENABLED
  108. _FORCE_INLINE_ void set_editor_hint(bool p_enabled) { editor_hint = p_enabled; }
  109. _FORCE_INLINE_ bool is_editor_hint() const { return editor_hint; }
  110. _FORCE_INLINE_ void set_project_manager_hint(bool p_enabled) { project_manager_hint = p_enabled; }
  111. _FORCE_INLINE_ bool is_project_manager_hint() const { return project_manager_hint; }
  112. #else
  113. _FORCE_INLINE_ void set_editor_hint(bool p_enabled) {}
  114. _FORCE_INLINE_ bool is_editor_hint() const { return false; }
  115. _FORCE_INLINE_ void set_project_manager_hint(bool p_enabled) {}
  116. _FORCE_INLINE_ bool is_project_manager_hint() const { return false; }
  117. #endif
  118. Dictionary get_version_info() const;
  119. Dictionary get_author_info() const;
  120. TypedArray<Dictionary> get_copyright_info() const;
  121. Dictionary get_donor_info() const;
  122. Dictionary get_license_info() const;
  123. String get_license_text() const;
  124. void set_write_movie_path(const String &p_path);
  125. String get_write_movie_path() const;
  126. String get_architecture_name() const;
  127. void set_shader_cache_path(const String &p_path);
  128. String get_shader_cache_path() const;
  129. bool is_abort_on_gpu_errors_enabled() const;
  130. bool is_validation_layers_enabled() const;
  131. int32_t get_gpu_index() const;
  132. void startup_begin();
  133. void startup_benchmark_begin_measure(const String &p_what);
  134. void startup_benchmark_end_measure();
  135. void startup_dump(const String &p_to_file);
  136. Engine();
  137. virtual ~Engine() {}
  138. };
  139. #endif // ENGINE_H