Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/config/engine.h
20806 views
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
#pragma once
32
33
#include "core/string/string_name.h"
34
#include "core/templates/hash_map.h"
35
#include "core/templates/list.h"
36
37
class Object;
38
class Dictionary;
39
40
template <typename T>
41
class TypedArray;
42
43
class Engine {
44
public:
45
struct Singleton {
46
StringName name;
47
Object *ptr = nullptr;
48
StringName class_name; // Used for binding generation hinting.
49
// Singleton scope flags.
50
bool user_created = false;
51
bool editor_only = false;
52
53
Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr, const StringName &p_class_name = StringName());
54
};
55
56
private:
57
friend class Main;
58
59
uint64_t frames_drawn = 0;
60
uint32_t _frame_delay = 0;
61
uint64_t _frame_ticks = 0;
62
double _process_step = 0;
63
64
int ips = 60;
65
int user_ips = 60;
66
double physics_jitter_fix = 0.5;
67
double _fps = 1;
68
int _max_fps = 0;
69
int _audio_output_latency = 0;
70
double _time_scale = 1.0;
71
double _game_time_scale = 1.0;
72
double _user_time_scale = 1.0;
73
uint64_t _physics_frames = 0;
74
int max_physics_steps_per_frame = 8;
75
int max_user_physics_steps_per_frame = 8;
76
double _physics_interpolation_fraction = 0.0f;
77
bool abort_on_gpu_errors = false;
78
bool use_validation_layers = false;
79
bool generate_spirv_debug_info = false;
80
bool extra_gpu_memory_tracking = false;
81
#if defined(DEBUG_ENABLED) || defined(DEV_ENABLED)
82
bool accurate_breadcrumbs = false;
83
#endif
84
int32_t gpu_idx = -1;
85
86
uint64_t _process_frames = 0;
87
bool _in_physics = false;
88
89
List<Singleton> singletons;
90
HashMap<StringName, Object *> singleton_ptrs;
91
92
bool editor_hint = false;
93
bool project_manager_hint = false;
94
bool extension_reloading = false;
95
bool embedded_in_editor = false;
96
bool recovery_mode_hint = false;
97
98
bool _print_header = true;
99
100
static inline Engine *singleton = nullptr;
101
102
String write_movie_path;
103
String shader_cache_path;
104
105
static constexpr int SERVER_SYNC_FRAME_COUNT_WARNING = 5;
106
int server_syncs = 0;
107
bool frame_server_synced = false;
108
109
bool freeze_time_scale = false;
110
111
protected:
112
void _update_time_scale();
113
114
public:
115
static Engine *get_singleton();
116
117
virtual void set_physics_ticks_per_second(int p_ips);
118
virtual int get_physics_ticks_per_second() const;
119
virtual int get_user_physics_ticks_per_second() const;
120
121
virtual void set_max_physics_steps_per_frame(int p_max_physics_steps);
122
virtual int get_max_physics_steps_per_frame() const;
123
virtual int get_user_max_physics_steps_per_frame() const;
124
125
void set_physics_jitter_fix(double p_threshold);
126
double get_physics_jitter_fix() const;
127
128
virtual void set_max_fps(int p_fps);
129
virtual int get_max_fps() const;
130
131
virtual void set_audio_output_latency(int p_msec);
132
virtual int get_audio_output_latency() const;
133
134
virtual double get_frames_per_second() const { return _fps; }
135
136
uint64_t get_frames_drawn();
137
138
uint64_t get_physics_frames() const { return _physics_frames; }
139
uint64_t get_process_frames() const { return _process_frames; }
140
bool is_in_physics_frame() const { return _in_physics; }
141
uint64_t get_frame_ticks() const { return _frame_ticks; }
142
double get_process_step() const { return _process_step; }
143
double get_physics_interpolation_fraction() const { return _physics_interpolation_fraction; }
144
145
void set_time_scale(double p_scale);
146
double get_time_scale() const;
147
void set_user_time_scale(double p_scale);
148
double get_effective_time_scale() const;
149
double get_unfrozen_time_scale() const;
150
151
void set_print_to_stdout(bool p_enabled);
152
bool is_printing_to_stdout() const;
153
154
void set_print_error_messages(bool p_enabled);
155
bool is_printing_error_messages() const;
156
void print_header(const String &p_string) const;
157
void print_header_rich(const String &p_string) const;
158
159
void set_frame_delay(uint32_t p_msec);
160
uint32_t get_frame_delay() const;
161
162
void add_singleton(const Singleton &p_singleton);
163
void get_singletons(List<Singleton> *p_singletons);
164
bool has_singleton(const StringName &p_name) const;
165
Object *get_singleton_object(const StringName &p_name) const;
166
void remove_singleton(const StringName &p_name);
167
bool is_singleton_user_created(const StringName &p_name) const;
168
bool is_singleton_editor_only(const StringName &p_name) const;
169
170
#ifdef TOOLS_ENABLED
171
_FORCE_INLINE_ void set_editor_hint(bool p_enabled) { editor_hint = p_enabled; }
172
_FORCE_INLINE_ bool is_editor_hint() const { return editor_hint; }
173
174
_FORCE_INLINE_ void set_project_manager_hint(bool p_enabled) { project_manager_hint = p_enabled; }
175
_FORCE_INLINE_ bool is_project_manager_hint() const { return project_manager_hint; }
176
177
_FORCE_INLINE_ void set_extension_reloading_enabled(bool p_enabled) { extension_reloading = p_enabled; }
178
_FORCE_INLINE_ bool is_extension_reloading_enabled() const { return extension_reloading; }
179
180
_FORCE_INLINE_ void set_recovery_mode_hint(bool p_enabled) { recovery_mode_hint = p_enabled; }
181
_FORCE_INLINE_ bool is_recovery_mode_hint() const { return recovery_mode_hint; }
182
#else
183
_FORCE_INLINE_ void set_editor_hint(bool p_enabled) {}
184
_FORCE_INLINE_ bool is_editor_hint() const { return false; }
185
186
_FORCE_INLINE_ void set_project_manager_hint(bool p_enabled) {}
187
_FORCE_INLINE_ bool is_project_manager_hint() const { return false; }
188
189
_FORCE_INLINE_ void set_extension_reloading_enabled(bool p_enabled) {}
190
_FORCE_INLINE_ bool is_extension_reloading_enabled() const { return false; }
191
192
_FORCE_INLINE_ void set_recovery_mode_hint(bool p_enabled) {}
193
_FORCE_INLINE_ bool is_recovery_mode_hint() const { return false; }
194
#endif
195
196
Dictionary get_version_info() const;
197
Dictionary get_author_info() const;
198
TypedArray<Dictionary> get_copyright_info() const;
199
Dictionary get_donor_info() const;
200
Dictionary get_license_info() const;
201
String get_license_text() const;
202
203
void set_write_movie_path(const String &p_path);
204
String get_write_movie_path() const;
205
206
String get_architecture_name() const;
207
208
void set_shader_cache_path(const String &p_path);
209
String get_shader_cache_path() const;
210
211
bool is_abort_on_gpu_errors_enabled() const;
212
bool is_validation_layers_enabled() const;
213
bool is_generate_spirv_debug_info_enabled() const;
214
bool is_extra_gpu_memory_tracking_enabled() const;
215
#if defined(DEBUG_ENABLED) || defined(DEV_ENABLED)
216
bool is_accurate_breadcrumbs_enabled() const;
217
#endif
218
int32_t get_gpu_index() const;
219
220
void increment_frames_drawn();
221
bool notify_frame_server_synced();
222
223
void set_freeze_time_scale(bool p_frozen);
224
void set_embedded_in_editor(bool p_enabled);
225
bool is_embedded_in_editor() const;
226
227
Engine();
228
virtual ~Engine();
229
};
230
231