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