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