1 /*************************************************************************/
2 /* engine.cpp */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
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 #include "engine.h"
32
33 #include "core/authors.gen.h"
34 #include "core/donors.gen.h"
35 #include "core/license.gen.h"
36 #include "core/version.h"
37 #include "core/version_hash.gen.h"
38
set_iterations_per_second(int p_ips)39 void Engine::set_iterations_per_second(int p_ips) {
40
41 ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0.");
42 ips = p_ips;
43 }
get_iterations_per_second() const44 int Engine::get_iterations_per_second() const {
45
46 return ips;
47 }
48
set_physics_jitter_fix(float p_threshold)49 void Engine::set_physics_jitter_fix(float p_threshold) {
50 if (p_threshold < 0)
51 p_threshold = 0;
52 physics_jitter_fix = p_threshold;
53 }
54
get_physics_jitter_fix() const55 float Engine::get_physics_jitter_fix() const {
56 return physics_jitter_fix;
57 }
58
set_target_fps(int p_fps)59 void Engine::set_target_fps(int p_fps) {
60 _target_fps = p_fps > 0 ? p_fps : 0;
61 }
62
get_target_fps() const63 int Engine::get_target_fps() const {
64 return _target_fps;
65 }
66
get_frames_drawn()67 uint64_t Engine::get_frames_drawn() {
68
69 return frames_drawn;
70 }
71
set_frame_delay(uint32_t p_msec)72 void Engine::set_frame_delay(uint32_t p_msec) {
73
74 _frame_delay = p_msec;
75 }
76
get_frame_delay() const77 uint32_t Engine::get_frame_delay() const {
78
79 return _frame_delay;
80 }
81
set_time_scale(float p_scale)82 void Engine::set_time_scale(float p_scale) {
83
84 _time_scale = p_scale;
85 }
86
get_time_scale() const87 float Engine::get_time_scale() const {
88
89 return _time_scale;
90 }
91
get_version_info() const92 Dictionary Engine::get_version_info() const {
93
94 Dictionary dict;
95 dict["major"] = VERSION_MAJOR;
96 dict["minor"] = VERSION_MINOR;
97 dict["patch"] = VERSION_PATCH;
98 dict["hex"] = VERSION_HEX;
99 dict["status"] = VERSION_STATUS;
100 dict["build"] = VERSION_BUILD;
101 dict["year"] = VERSION_YEAR;
102
103 String hash = VERSION_HASH;
104 dict["hash"] = hash.length() == 0 ? String("unknown") : hash;
105
106 String stringver = String(dict["major"]) + "." + String(dict["minor"]);
107 if ((int)dict["patch"] != 0)
108 stringver += "." + String(dict["patch"]);
109 stringver += "-" + String(dict["status"]) + " (" + String(dict["build"]) + ")";
110 dict["string"] = stringver;
111
112 return dict;
113 }
114
array_from_info(const char * const * info_list)115 static Array array_from_info(const char *const *info_list) {
116 Array arr;
117 for (int i = 0; info_list[i] != NULL; i++) {
118 arr.push_back(info_list[i]);
119 }
120 return arr;
121 }
122
array_from_info_count(const char * const * info_list,int info_count)123 static Array array_from_info_count(const char *const *info_list, int info_count) {
124 Array arr;
125 for (int i = 0; i < info_count; i++) {
126 arr.push_back(info_list[i]);
127 }
128 return arr;
129 }
130
get_author_info() const131 Dictionary Engine::get_author_info() const {
132 Dictionary dict;
133
134 dict["lead_developers"] = array_from_info(AUTHORS_LEAD_DEVELOPERS);
135 dict["project_managers"] = array_from_info(AUTHORS_PROJECT_MANAGERS);
136 dict["founders"] = array_from_info(AUTHORS_FOUNDERS);
137 dict["developers"] = array_from_info(AUTHORS_DEVELOPERS);
138
139 return dict;
140 }
141
get_copyright_info() const142 Array Engine::get_copyright_info() const {
143 Array components;
144 for (int component_index = 0; component_index < COPYRIGHT_INFO_COUNT; component_index++) {
145 const ComponentCopyright &cp_info = COPYRIGHT_INFO[component_index];
146 Dictionary component_dict;
147 component_dict["name"] = cp_info.name;
148 Array parts;
149 for (int i = 0; i < cp_info.part_count; i++) {
150 const ComponentCopyrightPart &cp_part = cp_info.parts[i];
151 Dictionary part_dict;
152 part_dict["files"] = array_from_info_count(cp_part.files, cp_part.file_count);
153 part_dict["copyright"] = array_from_info_count(cp_part.copyright_statements, cp_part.copyright_count);
154 part_dict["license"] = cp_part.license;
155 parts.push_back(part_dict);
156 }
157 component_dict["parts"] = parts;
158
159 components.push_back(component_dict);
160 }
161 return components;
162 }
163
get_donor_info() const164 Dictionary Engine::get_donor_info() const {
165 Dictionary donors;
166 donors["platinum_sponsors"] = array_from_info(DONORS_SPONSOR_PLATINUM);
167 donors["gold_sponsors"] = array_from_info(DONORS_SPONSOR_GOLD);
168 donors["silver_sponsors"] = array_from_info(DONORS_SPONSOR_SILVER);
169 donors["bronze_sponsors"] = array_from_info(DONORS_SPONSOR_BRONZE);
170 donors["mini_sponsors"] = array_from_info(DONORS_SPONSOR_MINI);
171 donors["gold_donors"] = array_from_info(DONORS_GOLD);
172 donors["silver_donors"] = array_from_info(DONORS_SILVER);
173 donors["bronze_donors"] = array_from_info(DONORS_BRONZE);
174 return donors;
175 }
176
get_license_info() const177 Dictionary Engine::get_license_info() const {
178 Dictionary licenses;
179 for (int i = 0; i < LICENSE_COUNT; i++) {
180 licenses[LICENSE_NAMES[i]] = LICENSE_BODIES[i];
181 }
182 return licenses;
183 }
184
get_license_text() const185 String Engine::get_license_text() const {
186 return String(GODOT_LICENSE_TEXT);
187 }
188
add_singleton(const Singleton & p_singleton)189 void Engine::add_singleton(const Singleton &p_singleton) {
190
191 singletons.push_back(p_singleton);
192 singleton_ptrs[p_singleton.name] = p_singleton.ptr;
193 }
194
get_singleton_object(const String & p_name) const195 Object *Engine::get_singleton_object(const String &p_name) const {
196
197 const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name);
198 ERR_FAIL_COND_V_MSG(!E, NULL, "Failed to retrieve non-existent singleton '" + p_name + "'.");
199 return E->get();
200 };
201
has_singleton(const String & p_name) const202 bool Engine::has_singleton(const String &p_name) const {
203
204 return singleton_ptrs.has(p_name);
205 };
206
get_singletons(List<Singleton> * p_singletons)207 void Engine::get_singletons(List<Singleton> *p_singletons) {
208
209 for (List<Singleton>::Element *E = singletons.front(); E; E = E->next())
210 p_singletons->push_back(E->get());
211 }
212
213 Engine *Engine::singleton = NULL;
214
get_singleton()215 Engine *Engine::get_singleton() {
216 return singleton;
217 }
218
Engine()219 Engine::Engine() {
220
221 singleton = this;
222 frames_drawn = 0;
223 ips = 60;
224 physics_jitter_fix = 0.5;
225 _physics_interpolation_fraction = 0.0f;
226 _frame_delay = 0;
227 _fps = 1;
228 _target_fps = 0;
229 _time_scale = 1.0;
230 _pixel_snap = false;
231 _physics_frames = 0;
232 _idle_frames = 0;
233 _in_physics = false;
234 _frame_ticks = 0;
235 _frame_step = 0;
236 editor_hint = false;
237 }
238