1 /*************************************************************************/
2 /*  core_bind.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 "core_bind.h"
32 
33 #include "core/crypto/crypto_core.h"
34 #include "core/io/file_access_compressed.h"
35 #include "core/io/file_access_encrypted.h"
36 #include "core/io/json.h"
37 #include "core/io/marshalls.h"
38 #include "core/math/geometry.h"
39 #include "core/os/keyboard.h"
40 #include "core/os/os.h"
41 #include "core/project_settings.h"
42 
43 /**
44  *  Time constants borrowed from loc_time.h
45  */
46 #define EPOCH_YR 1970 /* EPOCH = Jan 1 1970 00:00:00 */
47 #define SECS_DAY (24L * 60L * 60L)
48 #define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
49 #define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
50 #define SECOND_KEY "second"
51 #define MINUTE_KEY "minute"
52 #define HOUR_KEY "hour"
53 #define DAY_KEY "day"
54 #define MONTH_KEY "month"
55 #define YEAR_KEY "year"
56 #define WEEKDAY_KEY "weekday"
57 #define DST_KEY "dst"
58 
59 /// Table of number of days in each month (for regular year and leap year)
60 static const unsigned int MONTH_DAYS_TABLE[2][12] = {
61 	{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
62 	{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
63 };
64 
65 _ResourceLoader *_ResourceLoader::singleton = NULL;
66 
load_interactive(const String & p_path,const String & p_type_hint)67 Ref<ResourceInteractiveLoader> _ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint) {
68 	return ResourceLoader::load_interactive(p_path, p_type_hint);
69 }
70 
load(const String & p_path,const String & p_type_hint,bool p_no_cache)71 RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache) {
72 
73 	Error err = OK;
74 	RES ret = ResourceLoader::load(p_path, p_type_hint, p_no_cache, &err);
75 
76 	ERR_FAIL_COND_V_MSG(err != OK, ret, "Error loading resource: '" + p_path + "'.");
77 	return ret;
78 }
79 
get_recognized_extensions_for_type(const String & p_type)80 PoolVector<String> _ResourceLoader::get_recognized_extensions_for_type(const String &p_type) {
81 
82 	List<String> exts;
83 	ResourceLoader::get_recognized_extensions_for_type(p_type, &exts);
84 	PoolVector<String> ret;
85 	for (List<String>::Element *E = exts.front(); E; E = E->next()) {
86 
87 		ret.push_back(E->get());
88 	}
89 
90 	return ret;
91 }
92 
set_abort_on_missing_resources(bool p_abort)93 void _ResourceLoader::set_abort_on_missing_resources(bool p_abort) {
94 
95 	ResourceLoader::set_abort_on_missing_resources(p_abort);
96 }
97 
get_dependencies(const String & p_path)98 PoolStringArray _ResourceLoader::get_dependencies(const String &p_path) {
99 
100 	List<String> deps;
101 	ResourceLoader::get_dependencies(p_path, &deps);
102 
103 	PoolStringArray ret;
104 	for (List<String>::Element *E = deps.front(); E; E = E->next()) {
105 		ret.push_back(E->get());
106 	}
107 
108 	return ret;
109 };
110 
111 #ifndef DISABLE_DEPRECATED
has(const String & p_path)112 bool _ResourceLoader::has(const String &p_path) {
113 	WARN_PRINTS("ResourceLoader.has() is deprecated, please replace it with the equivalent has_cached() or the new exists().");
114 	return has_cached(p_path);
115 }
116 #endif // DISABLE_DEPRECATED
117 
has_cached(const String & p_path)118 bool _ResourceLoader::has_cached(const String &p_path) {
119 
120 	String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
121 	return ResourceCache::has(local_path);
122 }
123 
exists(const String & p_path,const String & p_type_hint)124 bool _ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
125 	return ResourceLoader::exists(p_path, p_type_hint);
126 }
127 
_bind_methods()128 void _ResourceLoader::_bind_methods() {
129 
130 	ClassDB::bind_method(D_METHOD("load_interactive", "path", "type_hint"), &_ResourceLoader::load_interactive, DEFVAL(""));
131 	ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "no_cache"), &_ResourceLoader::load, DEFVAL(""), DEFVAL(false));
132 	ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &_ResourceLoader::get_recognized_extensions_for_type);
133 	ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources", "abort"), &_ResourceLoader::set_abort_on_missing_resources);
134 	ClassDB::bind_method(D_METHOD("get_dependencies", "path"), &_ResourceLoader::get_dependencies);
135 	ClassDB::bind_method(D_METHOD("has_cached", "path"), &_ResourceLoader::has_cached);
136 	ClassDB::bind_method(D_METHOD("exists", "path", "type_hint"), &_ResourceLoader::exists, DEFVAL(""));
137 #ifndef DISABLE_DEPRECATED
138 	ClassDB::bind_method(D_METHOD("has", "path"), &_ResourceLoader::has);
139 #endif // DISABLE_DEPRECATED
140 }
141 
_ResourceLoader()142 _ResourceLoader::_ResourceLoader() {
143 
144 	singleton = this;
145 }
146 
save(const String & p_path,const RES & p_resource,SaverFlags p_flags)147 Error _ResourceSaver::save(const String &p_path, const RES &p_resource, SaverFlags p_flags) {
148 	ERR_FAIL_COND_V_MSG(p_resource.is_null(), ERR_INVALID_PARAMETER, "Can't save empty resource to path '" + String(p_path) + "'.");
149 	return ResourceSaver::save(p_path, p_resource, p_flags);
150 }
151 
get_recognized_extensions(const RES & p_resource)152 PoolVector<String> _ResourceSaver::get_recognized_extensions(const RES &p_resource) {
153 
154 	ERR_FAIL_COND_V_MSG(p_resource.is_null(), PoolVector<String>(), "It's not a reference to a valid Resource object.");
155 	List<String> exts;
156 	ResourceSaver::get_recognized_extensions(p_resource, &exts);
157 	PoolVector<String> ret;
158 	for (List<String>::Element *E = exts.front(); E; E = E->next()) {
159 
160 		ret.push_back(E->get());
161 	}
162 	return ret;
163 }
164 
165 _ResourceSaver *_ResourceSaver::singleton = NULL;
166 
_bind_methods()167 void _ResourceSaver::_bind_methods() {
168 
169 	ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &_ResourceSaver::save, DEFVAL(0));
170 	ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &_ResourceSaver::get_recognized_extensions);
171 
172 	BIND_ENUM_CONSTANT(FLAG_RELATIVE_PATHS);
173 	BIND_ENUM_CONSTANT(FLAG_BUNDLE_RESOURCES);
174 	BIND_ENUM_CONSTANT(FLAG_CHANGE_PATH);
175 	BIND_ENUM_CONSTANT(FLAG_OMIT_EDITOR_PROPERTIES);
176 	BIND_ENUM_CONSTANT(FLAG_SAVE_BIG_ENDIAN);
177 	BIND_ENUM_CONSTANT(FLAG_COMPRESS);
178 	BIND_ENUM_CONSTANT(FLAG_REPLACE_SUBRESOURCE_PATHS);
179 }
180 
_ResourceSaver()181 _ResourceSaver::_ResourceSaver() {
182 
183 	singleton = this;
184 }
185 
186 /////////////////OS
187 
global_menu_add_item(const String & p_menu,const String & p_label,const Variant & p_signal,const Variant & p_meta)188 void _OS::global_menu_add_item(const String &p_menu, const String &p_label, const Variant &p_signal, const Variant &p_meta) {
189 
190 	OS::get_singleton()->global_menu_add_item(p_menu, p_label, p_signal, p_meta);
191 }
192 
global_menu_add_separator(const String & p_menu)193 void _OS::global_menu_add_separator(const String &p_menu) {
194 
195 	OS::get_singleton()->global_menu_add_separator(p_menu);
196 }
197 
global_menu_remove_item(const String & p_menu,int p_idx)198 void _OS::global_menu_remove_item(const String &p_menu, int p_idx) {
199 
200 	OS::get_singleton()->global_menu_remove_item(p_menu, p_idx);
201 }
202 
global_menu_clear(const String & p_menu)203 void _OS::global_menu_clear(const String &p_menu) {
204 
205 	OS::get_singleton()->global_menu_clear(p_menu);
206 }
207 
get_mouse_position() const208 Point2 _OS::get_mouse_position() const {
209 
210 	return OS::get_singleton()->get_mouse_position();
211 }
212 
set_window_title(const String & p_title)213 void _OS::set_window_title(const String &p_title) {
214 
215 	OS::get_singleton()->set_window_title(p_title);
216 }
217 
get_mouse_button_state() const218 int _OS::get_mouse_button_state() const {
219 
220 	return OS::get_singleton()->get_mouse_button_state();
221 }
222 
get_unique_id() const223 String _OS::get_unique_id() const {
224 	return OS::get_singleton()->get_unique_id();
225 }
226 
has_touchscreen_ui_hint() const227 bool _OS::has_touchscreen_ui_hint() const {
228 
229 	return OS::get_singleton()->has_touchscreen_ui_hint();
230 }
231 
set_clipboard(const String & p_text)232 void _OS::set_clipboard(const String &p_text) {
233 
234 	OS::get_singleton()->set_clipboard(p_text);
235 }
236 
get_clipboard() const237 String _OS::get_clipboard() const {
238 
239 	return OS::get_singleton()->get_clipboard();
240 }
241 
get_video_driver_count() const242 int _OS::get_video_driver_count() const {
243 	return OS::get_singleton()->get_video_driver_count();
244 }
245 
get_video_driver_name(VideoDriver p_driver) const246 String _OS::get_video_driver_name(VideoDriver p_driver) const {
247 	return OS::get_singleton()->get_video_driver_name((int)p_driver);
248 }
249 
get_current_video_driver() const250 _OS::VideoDriver _OS::get_current_video_driver() const {
251 	return (VideoDriver)OS::get_singleton()->get_current_video_driver();
252 }
253 
get_audio_driver_count() const254 int _OS::get_audio_driver_count() const {
255 	return OS::get_singleton()->get_audio_driver_count();
256 }
257 
get_audio_driver_name(int p_driver) const258 String _OS::get_audio_driver_name(int p_driver) const {
259 	return OS::get_singleton()->get_audio_driver_name(p_driver);
260 }
261 
get_connected_midi_inputs()262 PoolStringArray _OS::get_connected_midi_inputs() {
263 	return OS::get_singleton()->get_connected_midi_inputs();
264 }
265 
open_midi_inputs()266 void _OS::open_midi_inputs() {
267 	OS::get_singleton()->open_midi_inputs();
268 }
269 
close_midi_inputs()270 void _OS::close_midi_inputs() {
271 	OS::get_singleton()->close_midi_inputs();
272 }
273 
set_video_mode(const Size2 & p_size,bool p_fullscreen,bool p_resizeable,int p_screen)274 void _OS::set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen) {
275 
276 	OS::VideoMode vm;
277 	vm.width = p_size.width;
278 	vm.height = p_size.height;
279 	vm.fullscreen = p_fullscreen;
280 	vm.resizable = p_resizeable;
281 	OS::get_singleton()->set_video_mode(vm, p_screen);
282 }
283 
get_video_mode(int p_screen) const284 Size2 _OS::get_video_mode(int p_screen) const {
285 
286 	OS::VideoMode vm;
287 	vm = OS::get_singleton()->get_video_mode(p_screen);
288 	return Size2(vm.width, vm.height);
289 }
290 
is_video_mode_fullscreen(int p_screen) const291 bool _OS::is_video_mode_fullscreen(int p_screen) const {
292 
293 	OS::VideoMode vm;
294 	vm = OS::get_singleton()->get_video_mode(p_screen);
295 	return vm.fullscreen;
296 }
297 
get_screen_count() const298 int _OS::get_screen_count() const {
299 	return OS::get_singleton()->get_screen_count();
300 }
301 
get_current_screen() const302 int _OS::get_current_screen() const {
303 	return OS::get_singleton()->get_current_screen();
304 }
305 
set_current_screen(int p_screen)306 void _OS::set_current_screen(int p_screen) {
307 	OS::get_singleton()->set_current_screen(p_screen);
308 }
309 
get_screen_position(int p_screen) const310 Point2 _OS::get_screen_position(int p_screen) const {
311 	return OS::get_singleton()->get_screen_position(p_screen);
312 }
313 
get_screen_size(int p_screen) const314 Size2 _OS::get_screen_size(int p_screen) const {
315 	return OS::get_singleton()->get_screen_size(p_screen);
316 }
317 
get_screen_dpi(int p_screen) const318 int _OS::get_screen_dpi(int p_screen) const {
319 
320 	return OS::get_singleton()->get_screen_dpi(p_screen);
321 }
322 
get_screen_scale(int p_screen) const323 float _OS::get_screen_scale(int p_screen) const {
324 	return OS::get_singleton()->get_screen_scale(p_screen);
325 }
326 
get_screen_max_scale() const327 float _OS::get_screen_max_scale() const {
328 	return OS::get_singleton()->get_screen_max_scale();
329 }
330 
get_window_position() const331 Point2 _OS::get_window_position() const {
332 	return OS::get_singleton()->get_window_position();
333 }
334 
set_window_position(const Point2 & p_position)335 void _OS::set_window_position(const Point2 &p_position) {
336 	OS::get_singleton()->set_window_position(p_position);
337 }
338 
get_max_window_size() const339 Size2 _OS::get_max_window_size() const {
340 	return OS::get_singleton()->get_max_window_size();
341 }
342 
get_min_window_size() const343 Size2 _OS::get_min_window_size() const {
344 	return OS::get_singleton()->get_min_window_size();
345 }
346 
get_window_size() const347 Size2 _OS::get_window_size() const {
348 	return OS::get_singleton()->get_window_size();
349 }
350 
get_real_window_size() const351 Size2 _OS::get_real_window_size() const {
352 	return OS::get_singleton()->get_real_window_size();
353 }
354 
set_max_window_size(const Size2 & p_size)355 void _OS::set_max_window_size(const Size2 &p_size) {
356 	OS::get_singleton()->set_max_window_size(p_size);
357 }
358 
set_min_window_size(const Size2 & p_size)359 void _OS::set_min_window_size(const Size2 &p_size) {
360 	OS::get_singleton()->set_min_window_size(p_size);
361 }
362 
set_window_size(const Size2 & p_size)363 void _OS::set_window_size(const Size2 &p_size) {
364 	OS::get_singleton()->set_window_size(p_size);
365 }
366 
get_window_safe_area() const367 Rect2 _OS::get_window_safe_area() const {
368 	return OS::get_singleton()->get_window_safe_area();
369 }
370 
set_window_fullscreen(bool p_enabled)371 void _OS::set_window_fullscreen(bool p_enabled) {
372 	OS::get_singleton()->set_window_fullscreen(p_enabled);
373 }
374 
is_window_fullscreen() const375 bool _OS::is_window_fullscreen() const {
376 	return OS::get_singleton()->is_window_fullscreen();
377 }
378 
set_window_resizable(bool p_enabled)379 void _OS::set_window_resizable(bool p_enabled) {
380 	OS::get_singleton()->set_window_resizable(p_enabled);
381 }
382 
is_window_resizable() const383 bool _OS::is_window_resizable() const {
384 	return OS::get_singleton()->is_window_resizable();
385 }
386 
set_window_minimized(bool p_enabled)387 void _OS::set_window_minimized(bool p_enabled) {
388 	OS::get_singleton()->set_window_minimized(p_enabled);
389 }
390 
is_window_minimized() const391 bool _OS::is_window_minimized() const {
392 	return OS::get_singleton()->is_window_minimized();
393 }
394 
set_window_maximized(bool p_enabled)395 void _OS::set_window_maximized(bool p_enabled) {
396 	OS::get_singleton()->set_window_maximized(p_enabled);
397 }
398 
is_window_maximized() const399 bool _OS::is_window_maximized() const {
400 	return OS::get_singleton()->is_window_maximized();
401 }
402 
set_window_always_on_top(bool p_enabled)403 void _OS::set_window_always_on_top(bool p_enabled) {
404 	OS::get_singleton()->set_window_always_on_top(p_enabled);
405 }
406 
is_window_always_on_top() const407 bool _OS::is_window_always_on_top() const {
408 	return OS::get_singleton()->is_window_always_on_top();
409 }
410 
is_window_focused() const411 bool _OS::is_window_focused() const {
412 	return OS::get_singleton()->is_window_focused();
413 }
414 
set_borderless_window(bool p_borderless)415 void _OS::set_borderless_window(bool p_borderless) {
416 	OS::get_singleton()->set_borderless_window(p_borderless);
417 }
418 
get_window_per_pixel_transparency_enabled() const419 bool _OS::get_window_per_pixel_transparency_enabled() const {
420 	return OS::get_singleton()->get_window_per_pixel_transparency_enabled();
421 }
422 
set_window_per_pixel_transparency_enabled(bool p_enabled)423 void _OS::set_window_per_pixel_transparency_enabled(bool p_enabled) {
424 	OS::get_singleton()->set_window_per_pixel_transparency_enabled(p_enabled);
425 }
426 
get_borderless_window() const427 bool _OS::get_borderless_window() const {
428 	return OS::get_singleton()->get_borderless_window();
429 }
430 
set_ime_active(const bool p_active)431 void _OS::set_ime_active(const bool p_active) {
432 
433 	OS::get_singleton()->set_ime_active(p_active);
434 }
435 
set_ime_position(const Point2 & p_pos)436 void _OS::set_ime_position(const Point2 &p_pos) {
437 
438 	OS::get_singleton()->set_ime_position(p_pos);
439 }
440 
get_ime_selection() const441 Point2 _OS::get_ime_selection() const {
442 	return OS::get_singleton()->get_ime_selection();
443 }
444 
get_ime_text() const445 String _OS::get_ime_text() const {
446 	return OS::get_singleton()->get_ime_text();
447 }
448 
set_use_file_access_save_and_swap(bool p_enable)449 void _OS::set_use_file_access_save_and_swap(bool p_enable) {
450 
451 	FileAccess::set_backup_save(p_enable);
452 }
453 
is_video_mode_resizable(int p_screen) const454 bool _OS::is_video_mode_resizable(int p_screen) const {
455 
456 	OS::VideoMode vm;
457 	vm = OS::get_singleton()->get_video_mode(p_screen);
458 	return vm.resizable;
459 }
460 
get_fullscreen_mode_list(int p_screen) const461 Array _OS::get_fullscreen_mode_list(int p_screen) const {
462 
463 	List<OS::VideoMode> vmlist;
464 	OS::get_singleton()->get_fullscreen_mode_list(&vmlist, p_screen);
465 	Array vmarr;
466 	for (List<OS::VideoMode>::Element *E = vmlist.front(); E; E = E->next()) {
467 
468 		vmarr.push_back(Size2(E->get().width, E->get().height));
469 	}
470 
471 	return vmarr;
472 }
473 
set_low_processor_usage_mode(bool p_enabled)474 void _OS::set_low_processor_usage_mode(bool p_enabled) {
475 
476 	OS::get_singleton()->set_low_processor_usage_mode(p_enabled);
477 }
is_in_low_processor_usage_mode() const478 bool _OS::is_in_low_processor_usage_mode() const {
479 
480 	return OS::get_singleton()->is_in_low_processor_usage_mode();
481 }
482 
set_low_processor_usage_mode_sleep_usec(int p_usec)483 void _OS::set_low_processor_usage_mode_sleep_usec(int p_usec) {
484 
485 	OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(p_usec);
486 }
487 
get_low_processor_usage_mode_sleep_usec() const488 int _OS::get_low_processor_usage_mode_sleep_usec() const {
489 
490 	return OS::get_singleton()->get_low_processor_usage_mode_sleep_usec();
491 }
492 
get_executable_path() const493 String _OS::get_executable_path() const {
494 
495 	return OS::get_singleton()->get_executable_path();
496 }
497 
shell_open(String p_uri)498 Error _OS::shell_open(String p_uri) {
499 
500 	if (p_uri.begins_with("res://")) {
501 		WARN_PRINT("Attempting to open an URL with the \"res://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_open()`.");
502 	} else if (p_uri.begins_with("user://")) {
503 		WARN_PRINT("Attempting to open an URL with the \"user://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_open()`.");
504 	}
505 	return OS::get_singleton()->shell_open(p_uri);
506 };
507 
execute(const String & p_path,const Vector<String> & p_arguments,bool p_blocking,Array p_output,bool p_read_stderr)508 int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output, bool p_read_stderr) {
509 
510 	OS::ProcessID pid = -2;
511 	int exitcode = 0;
512 	List<String> args;
513 	for (int i = 0; i < p_arguments.size(); i++)
514 		args.push_back(p_arguments[i]);
515 	String pipe;
516 	Error err = OS::get_singleton()->execute(p_path, args, p_blocking, &pid, &pipe, &exitcode, p_read_stderr);
517 	p_output.clear();
518 	p_output.push_back(pipe);
519 	if (err != OK)
520 		return -1;
521 	else if (p_blocking)
522 		return exitcode;
523 	else
524 		return pid;
525 }
526 
kill(int p_pid)527 Error _OS::kill(int p_pid) {
528 
529 	return OS::get_singleton()->kill(p_pid);
530 }
531 
get_process_id() const532 int _OS::get_process_id() const {
533 
534 	return OS::get_singleton()->get_process_id();
535 };
536 
has_environment(const String & p_var) const537 bool _OS::has_environment(const String &p_var) const {
538 
539 	return OS::get_singleton()->has_environment(p_var);
540 }
get_environment(const String & p_var) const541 String _OS::get_environment(const String &p_var) const {
542 
543 	return OS::get_singleton()->get_environment(p_var);
544 }
545 
get_name() const546 String _OS::get_name() const {
547 
548 	return OS::get_singleton()->get_name();
549 }
get_cmdline_args()550 Vector<String> _OS::get_cmdline_args() {
551 
552 	List<String> cmdline = OS::get_singleton()->get_cmdline_args();
553 	Vector<String> cmdlinev;
554 	for (List<String>::Element *E = cmdline.front(); E; E = E->next()) {
555 
556 		cmdlinev.push_back(E->get());
557 	}
558 
559 	return cmdlinev;
560 }
561 
get_locale() const562 String _OS::get_locale() const {
563 
564 	return OS::get_singleton()->get_locale();
565 }
566 
get_latin_keyboard_variant() const567 String _OS::get_latin_keyboard_variant() const {
568 	switch (OS::get_singleton()->get_latin_keyboard_variant()) {
569 		case OS::LATIN_KEYBOARD_QWERTY: return "QWERTY";
570 		case OS::LATIN_KEYBOARD_QWERTZ: return "QWERTZ";
571 		case OS::LATIN_KEYBOARD_AZERTY: return "AZERTY";
572 		case OS::LATIN_KEYBOARD_QZERTY: return "QZERTY";
573 		case OS::LATIN_KEYBOARD_DVORAK: return "DVORAK";
574 		case OS::LATIN_KEYBOARD_NEO: return "NEO";
575 		case OS::LATIN_KEYBOARD_COLEMAK: return "COLEMAK";
576 		default: return "ERROR";
577 	}
578 }
579 
keyboard_get_layout_count() const580 int _OS::keyboard_get_layout_count() const {
581 	return OS::get_singleton()->keyboard_get_layout_count();
582 }
583 
keyboard_get_current_layout() const584 int _OS::keyboard_get_current_layout() const {
585 	return OS::get_singleton()->keyboard_get_current_layout();
586 }
587 
keyboard_set_current_layout(int p_index)588 void _OS::keyboard_set_current_layout(int p_index) {
589 	OS::get_singleton()->keyboard_set_current_layout(p_index);
590 }
591 
keyboard_get_layout_language(int p_index) const592 String _OS::keyboard_get_layout_language(int p_index) const {
593 	return OS::get_singleton()->keyboard_get_layout_language(p_index);
594 }
595 
keyboard_get_layout_name(int p_index) const596 String _OS::keyboard_get_layout_name(int p_index) const {
597 	return OS::get_singleton()->keyboard_get_layout_name(p_index);
598 }
599 
get_model_name() const600 String _OS::get_model_name() const {
601 
602 	return OS::get_singleton()->get_model_name();
603 }
604 
is_ok_left_and_cancel_right() const605 bool _OS::is_ok_left_and_cancel_right() const {
606 
607 	return OS::get_singleton()->get_swap_ok_cancel();
608 }
609 
set_thread_name(const String & p_name)610 Error _OS::set_thread_name(const String &p_name) {
611 
612 	return Thread::set_name(p_name);
613 };
614 
set_use_vsync(bool p_enable)615 void _OS::set_use_vsync(bool p_enable) {
616 	OS::get_singleton()->set_use_vsync(p_enable);
617 }
618 
is_vsync_enabled() const619 bool _OS::is_vsync_enabled() const {
620 
621 	return OS::get_singleton()->is_vsync_enabled();
622 }
623 
set_vsync_via_compositor(bool p_enable)624 void _OS::set_vsync_via_compositor(bool p_enable) {
625 	OS::get_singleton()->set_vsync_via_compositor(p_enable);
626 }
627 
is_vsync_via_compositor_enabled() const628 bool _OS::is_vsync_via_compositor_enabled() const {
629 
630 	return OS::get_singleton()->is_vsync_via_compositor_enabled();
631 }
632 
get_power_state()633 _OS::PowerState _OS::get_power_state() {
634 	return _OS::PowerState(OS::get_singleton()->get_power_state());
635 }
636 
get_power_seconds_left()637 int _OS::get_power_seconds_left() {
638 	return OS::get_singleton()->get_power_seconds_left();
639 }
640 
get_power_percent_left()641 int _OS::get_power_percent_left() {
642 	return OS::get_singleton()->get_power_percent_left();
643 }
644 
has_feature(const String & p_feature) const645 bool _OS::has_feature(const String &p_feature) const {
646 
647 	return OS::get_singleton()->has_feature(p_feature);
648 }
649 
650 /*
651 enum Weekday {
652 	DAY_SUNDAY,
653 	DAY_MONDAY,
654 	DAY_TUESDAY,
655 	DAY_WEDNESDAY,
656 	DAY_THURSDAY,
657 	DAY_FRIDAY,
658 	DAY_SATURDAY
659 };
660 
661 enum Month {
662 	MONTH_JANUARY,
663 	MONTH_FEBRUARY,
664 	MONTH_MARCH,
665 	MONTH_APRIL,
666 	MONTH_MAY,
667 	MONTH_JUNE,
668 	MONTH_JULY,
669 	MONTH_AUGUST,
670 	MONTH_SEPTEMBER,
671 	MONTH_OCTOBER,
672 	MONTH_NOVEMBER,
673 	MONTH_DECEMBER
674 };
675 */
676 /*
677 struct Date {
678 
679 	int year;
680 	Month month;
681 	int day;
682 	Weekday weekday;
683 	bool dst;
684 };
685 
686 struct Time {
687 
688 	int hour;
689 	int min;
690 	int sec;
691 };
692 */
693 
get_static_memory_usage() const694 uint64_t _OS::get_static_memory_usage() const {
695 
696 	return OS::get_singleton()->get_static_memory_usage();
697 }
698 
get_static_memory_peak_usage() const699 uint64_t _OS::get_static_memory_peak_usage() const {
700 
701 	return OS::get_singleton()->get_static_memory_peak_usage();
702 }
703 
get_dynamic_memory_usage() const704 uint64_t _OS::get_dynamic_memory_usage() const {
705 
706 	return OS::get_singleton()->get_dynamic_memory_usage();
707 }
708 
set_native_icon(const String & p_filename)709 void _OS::set_native_icon(const String &p_filename) {
710 
711 	OS::get_singleton()->set_native_icon(p_filename);
712 }
713 
set_icon(const Ref<Image> & p_icon)714 void _OS::set_icon(const Ref<Image> &p_icon) {
715 
716 	OS::get_singleton()->set_icon(p_icon);
717 }
718 
get_exit_code() const719 int _OS::get_exit_code() const {
720 
721 	return OS::get_singleton()->get_exit_code();
722 }
723 
set_exit_code(int p_code)724 void _OS::set_exit_code(int p_code) {
725 
726 	if (p_code < 0 || p_code > 125) {
727 		WARN_PRINT("For portability reasons, the exit code should be set between 0 and 125 (inclusive).");
728 	}
729 
730 	OS::get_singleton()->set_exit_code(p_code);
731 }
732 
733 /**
734  *  Get current datetime with consideration for utc and
735  *     dst
736  */
get_datetime(bool utc) const737 Dictionary _OS::get_datetime(bool utc) const {
738 
739 	Dictionary dated = get_date(utc);
740 	Dictionary timed = get_time(utc);
741 
742 	List<Variant> keys;
743 	timed.get_key_list(&keys);
744 
745 	for (int i = 0; i < keys.size(); i++) {
746 		dated[keys[i]] = timed[keys[i]];
747 	}
748 
749 	return dated;
750 }
751 
get_date(bool utc) const752 Dictionary _OS::get_date(bool utc) const {
753 
754 	OS::Date date = OS::get_singleton()->get_date(utc);
755 	Dictionary dated;
756 	dated[YEAR_KEY] = date.year;
757 	dated[MONTH_KEY] = date.month;
758 	dated[DAY_KEY] = date.day;
759 	dated[WEEKDAY_KEY] = date.weekday;
760 	dated[DST_KEY] = date.dst;
761 	return dated;
762 }
763 
get_time(bool utc) const764 Dictionary _OS::get_time(bool utc) const {
765 
766 	OS::Time time = OS::get_singleton()->get_time(utc);
767 	Dictionary timed;
768 	timed[HOUR_KEY] = time.hour;
769 	timed[MINUTE_KEY] = time.min;
770 	timed[SECOND_KEY] = time.sec;
771 	return timed;
772 }
773 
774 /**
775  *  Get an epoch time value from a dictionary of time values
776  *  @p datetime must be populated with the following keys:
777  *    day, hour, minute, month, second, year. (dst is ignored).
778  *
779  *    You can pass the output from
780  *   get_datetime_from_unix_time directly into this function
781  *
782  * @param datetime dictionary of date and time values to convert
783  *
784  * @return epoch calculated
785  */
get_unix_time_from_datetime(Dictionary datetime) const786 int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const {
787 
788 	// Bunch of conversion constants
789 	static const unsigned int SECONDS_PER_MINUTE = 60;
790 	static const unsigned int MINUTES_PER_HOUR = 60;
791 	static const unsigned int HOURS_PER_DAY = 24;
792 	static const unsigned int SECONDS_PER_HOUR = MINUTES_PER_HOUR * SECONDS_PER_MINUTE;
793 	static const unsigned int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;
794 
795 	// Get all time values from the dictionary, set to zero if it doesn't exist.
796 	//   Risk incorrect calculation over throwing errors
797 	unsigned int second = ((datetime.has(SECOND_KEY)) ? static_cast<unsigned int>(datetime[SECOND_KEY]) : 0);
798 	unsigned int minute = ((datetime.has(MINUTE_KEY)) ? static_cast<unsigned int>(datetime[MINUTE_KEY]) : 0);
799 	unsigned int hour = ((datetime.has(HOUR_KEY)) ? static_cast<unsigned int>(datetime[HOUR_KEY]) : 0);
800 	unsigned int day = ((datetime.has(DAY_KEY)) ? static_cast<unsigned int>(datetime[DAY_KEY]) : 1);
801 	unsigned int month = ((datetime.has(MONTH_KEY)) ? static_cast<unsigned int>(datetime[MONTH_KEY]) : 1);
802 	unsigned int year = ((datetime.has(YEAR_KEY)) ? static_cast<unsigned int>(datetime[YEAR_KEY]) : 0);
803 
804 	/// How many days come before each month (0-12)
805 	static const unsigned short int DAYS_PAST_THIS_YEAR_TABLE[2][13] = {
806 		/* Normal years.  */
807 		{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
808 		/* Leap years.  */
809 		{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
810 	};
811 
812 	ERR_FAIL_COND_V_MSG(second > 59, 0, "Invalid second value of: " + itos(second) + ".");
813 
814 	ERR_FAIL_COND_V_MSG(minute > 59, 0, "Invalid minute value of: " + itos(minute) + ".");
815 
816 	ERR_FAIL_COND_V_MSG(hour > 23, 0, "Invalid hour value of: " + itos(hour) + ".");
817 
818 	ERR_FAIL_COND_V_MSG(month > 12 || month == 0, 0, "Invalid month value of: " + itos(month) + ".");
819 
820 	// Do this check after month is tested as valid
821 	ERR_FAIL_COND_V_MSG(day > MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1] || day == 0, 0, "Invalid day value of '" + itos(day) + "' which is larger than '" + itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1]) + "' or 0.");
822 	// Calculate all the seconds from months past in this year
823 	uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR = DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month - 1] * SECONDS_PER_DAY;
824 
825 	int64_t SECONDS_FROM_YEARS_PAST = 0;
826 	if (year >= EPOCH_YR) {
827 		for (unsigned int iyear = EPOCH_YR; iyear < year; iyear++) {
828 			SECONDS_FROM_YEARS_PAST += YEARSIZE(iyear) * SECONDS_PER_DAY;
829 		}
830 	} else {
831 		for (unsigned int iyear = EPOCH_YR - 1; iyear >= year; iyear--) {
832 			SECONDS_FROM_YEARS_PAST -= YEARSIZE(iyear) * SECONDS_PER_DAY;
833 		}
834 	}
835 
836 	int64_t epoch =
837 			second +
838 			minute * SECONDS_PER_MINUTE +
839 			hour * SECONDS_PER_HOUR +
840 			// Subtract 1 from day, since the current day isn't over yet
841 			//   and we cannot count all 24 hours.
842 			(day - 1) * SECONDS_PER_DAY +
843 			SECONDS_FROM_MONTHS_PAST_THIS_YEAR +
844 			SECONDS_FROM_YEARS_PAST;
845 	return epoch;
846 }
847 
848 /**
849  *  Get a dictionary of time values when given epoch time
850  *
851  *  Dictionary Time values will be a union if values from #get_time
852  *    and #get_date dictionaries (with the exception of dst =
853  *    day light standard time, as it cannot be determined from epoch)
854  *
855  * @param unix_time_val epoch time to convert
856  *
857  * @return dictionary of date and time values
858  */
get_datetime_from_unix_time(int64_t unix_time_val) const859 Dictionary _OS::get_datetime_from_unix_time(int64_t unix_time_val) const {
860 
861 	OS::Date date;
862 	OS::Time time;
863 
864 	long dayclock, dayno;
865 	int year = EPOCH_YR;
866 
867 	if (unix_time_val >= 0) {
868 		dayno = unix_time_val / SECS_DAY;
869 		dayclock = unix_time_val % SECS_DAY;
870 		/* day 0 was a thursday */
871 		date.weekday = static_cast<OS::Weekday>((dayno + 4) % 7);
872 		while (dayno >= YEARSIZE(year)) {
873 			dayno -= YEARSIZE(year);
874 			year++;
875 		}
876 	} else {
877 		dayno = (unix_time_val - SECS_DAY + 1) / SECS_DAY;
878 		dayclock = unix_time_val - dayno * SECS_DAY;
879 		date.weekday = static_cast<OS::Weekday>(((dayno % 7) + 11) % 7);
880 		do {
881 			year--;
882 			dayno += YEARSIZE(year);
883 		} while (dayno < 0);
884 	}
885 
886 	time.sec = dayclock % 60;
887 	time.min = (dayclock % 3600) / 60;
888 	time.hour = dayclock / 3600;
889 	date.year = year;
890 
891 	size_t imonth = 0;
892 
893 	while ((unsigned long)dayno >= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth]) {
894 		dayno -= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth];
895 		imonth++;
896 	}
897 
898 	/// Add 1 to month to make sure months are indexed starting at 1
899 	date.month = static_cast<OS::Month>(imonth + 1);
900 
901 	date.day = dayno + 1;
902 
903 	Dictionary timed;
904 	timed[HOUR_KEY] = time.hour;
905 	timed[MINUTE_KEY] = time.min;
906 	timed[SECOND_KEY] = time.sec;
907 	timed[YEAR_KEY] = date.year;
908 	timed[MONTH_KEY] = date.month;
909 	timed[DAY_KEY] = date.day;
910 	timed[WEEKDAY_KEY] = date.weekday;
911 
912 	return timed;
913 }
914 
get_time_zone_info() const915 Dictionary _OS::get_time_zone_info() const {
916 	OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info();
917 	Dictionary infod;
918 	infod["bias"] = info.bias;
919 	infod["name"] = info.name;
920 	return infod;
921 }
922 
get_unix_time() const923 uint64_t _OS::get_unix_time() const {
924 
925 	return OS::get_singleton()->get_unix_time();
926 }
927 
get_system_time_secs() const928 uint64_t _OS::get_system_time_secs() const {
929 	return OS::get_singleton()->get_system_time_secs();
930 }
931 
get_system_time_msecs() const932 uint64_t _OS::get_system_time_msecs() const {
933 	return OS::get_singleton()->get_system_time_msecs();
934 }
935 
delay_usec(uint32_t p_usec) const936 void _OS::delay_usec(uint32_t p_usec) const {
937 
938 	OS::get_singleton()->delay_usec(p_usec);
939 }
940 
delay_msec(uint32_t p_msec) const941 void _OS::delay_msec(uint32_t p_msec) const {
942 
943 	OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000);
944 }
945 
get_ticks_msec() const946 uint32_t _OS::get_ticks_msec() const {
947 
948 	return OS::get_singleton()->get_ticks_msec();
949 }
950 
get_ticks_usec() const951 uint64_t _OS::get_ticks_usec() const {
952 
953 	return OS::get_singleton()->get_ticks_usec();
954 }
955 
get_splash_tick_msec() const956 uint32_t _OS::get_splash_tick_msec() const {
957 
958 	return OS::get_singleton()->get_splash_tick_msec();
959 }
960 
can_use_threads() const961 bool _OS::can_use_threads() const {
962 
963 	return OS::get_singleton()->can_use_threads();
964 }
965 
can_draw() const966 bool _OS::can_draw() const {
967 
968 	return OS::get_singleton()->can_draw();
969 }
970 
is_userfs_persistent() const971 bool _OS::is_userfs_persistent() const {
972 
973 	return OS::get_singleton()->is_userfs_persistent();
974 }
975 
get_processor_count() const976 int _OS::get_processor_count() const {
977 
978 	return OS::get_singleton()->get_processor_count();
979 }
980 
is_stdout_verbose() const981 bool _OS::is_stdout_verbose() const {
982 
983 	return OS::get_singleton()->is_stdout_verbose();
984 }
985 
dump_memory_to_file(const String & p_file)986 void _OS::dump_memory_to_file(const String &p_file) {
987 
988 	OS::get_singleton()->dump_memory_to_file(p_file.utf8().get_data());
989 }
990 
991 struct _OSCoreBindImg {
992 
993 	String path;
994 	Size2 size;
995 	int fmt;
996 	ObjectID id;
997 	int vram;
operator <_OSCoreBindImg998 	bool operator<(const _OSCoreBindImg &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }
999 };
1000 
print_all_textures_by_size()1001 void _OS::print_all_textures_by_size() {
1002 
1003 	List<_OSCoreBindImg> imgs;
1004 	int total = 0;
1005 	{
1006 		List<Ref<Resource> > rsrc;
1007 		ResourceCache::get_cached_resources(&rsrc);
1008 
1009 		for (List<Ref<Resource> >::Element *E = rsrc.front(); E; E = E->next()) {
1010 
1011 			if (!E->get()->is_class("ImageTexture"))
1012 				continue;
1013 
1014 			Size2 size = E->get()->call("get_size");
1015 			int fmt = E->get()->call("get_format");
1016 
1017 			_OSCoreBindImg img;
1018 			img.size = size;
1019 			img.fmt = fmt;
1020 			img.path = E->get()->get_path();
1021 			img.vram = Image::get_image_data_size(img.size.width, img.size.height, Image::Format(img.fmt));
1022 			img.id = E->get()->get_instance_id();
1023 			total += img.vram;
1024 			imgs.push_back(img);
1025 		}
1026 	}
1027 
1028 	imgs.sort();
1029 
1030 	for (List<_OSCoreBindImg>::Element *E = imgs.front(); E; E = E->next()) {
1031 
1032 		total -= E->get().vram;
1033 	}
1034 }
1035 
print_resources_by_type(const Vector<String> & p_types)1036 void _OS::print_resources_by_type(const Vector<String> &p_types) {
1037 
1038 	Map<String, int> type_count;
1039 
1040 	List<Ref<Resource> > resources;
1041 	ResourceCache::get_cached_resources(&resources);
1042 
1043 	List<Ref<Resource> > rsrc;
1044 	ResourceCache::get_cached_resources(&rsrc);
1045 
1046 	for (List<Ref<Resource> >::Element *E = rsrc.front(); E; E = E->next()) {
1047 
1048 		Ref<Resource> r = E->get();
1049 
1050 		bool found = false;
1051 
1052 		for (int i = 0; i < p_types.size(); i++) {
1053 			if (r->is_class(p_types[i]))
1054 				found = true;
1055 		}
1056 		if (!found)
1057 			continue;
1058 
1059 		if (!type_count.has(r->get_class())) {
1060 			type_count[r->get_class()] = 0;
1061 		}
1062 
1063 		type_count[r->get_class()]++;
1064 	}
1065 };
1066 
has_virtual_keyboard() const1067 bool _OS::has_virtual_keyboard() const {
1068 	return OS::get_singleton()->has_virtual_keyboard();
1069 }
1070 
show_virtual_keyboard(const String & p_existing_text,bool p_multiline)1071 void _OS::show_virtual_keyboard(const String &p_existing_text, bool p_multiline) {
1072 	OS::get_singleton()->show_virtual_keyboard(p_existing_text, Rect2(), p_multiline);
1073 }
1074 
hide_virtual_keyboard()1075 void _OS::hide_virtual_keyboard() {
1076 	OS::get_singleton()->hide_virtual_keyboard();
1077 }
1078 
get_virtual_keyboard_height()1079 int _OS::get_virtual_keyboard_height() {
1080 	return OS::get_singleton()->get_virtual_keyboard_height();
1081 }
1082 
print_all_resources(const String & p_to_file)1083 void _OS::print_all_resources(const String &p_to_file) {
1084 
1085 	OS::get_singleton()->print_all_resources(p_to_file);
1086 }
1087 
print_resources_in_use(bool p_short)1088 void _OS::print_resources_in_use(bool p_short) {
1089 
1090 	OS::get_singleton()->print_resources_in_use(p_short);
1091 }
1092 
dump_resources_to_file(const String & p_file)1093 void _OS::dump_resources_to_file(const String &p_file) {
1094 
1095 	OS::get_singleton()->dump_resources_to_file(p_file.utf8().get_data());
1096 }
1097 
get_user_data_dir() const1098 String _OS::get_user_data_dir() const {
1099 
1100 	return OS::get_singleton()->get_user_data_dir();
1101 };
1102 
native_video_play(String p_path,float p_volume,String p_audio_track,String p_subtitle_track)1103 Error _OS::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
1104 
1105 	return OS::get_singleton()->native_video_play(p_path, p_volume, p_audio_track, p_subtitle_track);
1106 };
1107 
native_video_is_playing()1108 bool _OS::native_video_is_playing() {
1109 
1110 	return OS::get_singleton()->native_video_is_playing();
1111 };
1112 
native_video_pause()1113 void _OS::native_video_pause() {
1114 
1115 	OS::get_singleton()->native_video_pause();
1116 };
1117 
native_video_unpause()1118 void _OS::native_video_unpause() {
1119 	OS::get_singleton()->native_video_unpause();
1120 };
1121 
native_video_stop()1122 void _OS::native_video_stop() {
1123 
1124 	OS::get_singleton()->native_video_stop();
1125 };
1126 
request_attention()1127 void _OS::request_attention() {
1128 
1129 	OS::get_singleton()->request_attention();
1130 }
1131 
center_window()1132 void _OS::center_window() {
1133 
1134 	OS::get_singleton()->center_window();
1135 }
1136 
move_window_to_foreground()1137 void _OS::move_window_to_foreground() {
1138 
1139 	OS::get_singleton()->move_window_to_foreground();
1140 }
1141 
is_debug_build() const1142 bool _OS::is_debug_build() const {
1143 
1144 #ifdef DEBUG_ENABLED
1145 	return true;
1146 #else
1147 	return false;
1148 #endif
1149 }
1150 
set_screen_orientation(ScreenOrientation p_orientation)1151 void _OS::set_screen_orientation(ScreenOrientation p_orientation) {
1152 
1153 	OS::get_singleton()->set_screen_orientation(OS::ScreenOrientation(p_orientation));
1154 }
1155 
get_screen_orientation() const1156 _OS::ScreenOrientation _OS::get_screen_orientation() const {
1157 
1158 	return ScreenOrientation(OS::get_singleton()->get_screen_orientation());
1159 }
1160 
set_keep_screen_on(bool p_enabled)1161 void _OS::set_keep_screen_on(bool p_enabled) {
1162 
1163 	OS::get_singleton()->set_keep_screen_on(p_enabled);
1164 }
1165 
is_keep_screen_on() const1166 bool _OS::is_keep_screen_on() const {
1167 
1168 	return OS::get_singleton()->is_keep_screen_on();
1169 }
1170 
get_system_dir(SystemDir p_dir) const1171 String _OS::get_system_dir(SystemDir p_dir) const {
1172 
1173 	return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir));
1174 }
1175 
get_scancode_string(uint32_t p_code) const1176 String _OS::get_scancode_string(uint32_t p_code) const {
1177 
1178 	return keycode_get_string(p_code);
1179 }
is_scancode_unicode(uint32_t p_unicode) const1180 bool _OS::is_scancode_unicode(uint32_t p_unicode) const {
1181 
1182 	return keycode_has_unicode(p_unicode);
1183 }
find_scancode_from_string(const String & p_code) const1184 int _OS::find_scancode_from_string(const String &p_code) const {
1185 
1186 	return find_keycode(p_code);
1187 }
1188 
alert(const String & p_alert,const String & p_title)1189 void _OS::alert(const String &p_alert, const String &p_title) {
1190 
1191 	OS::get_singleton()->alert(p_alert, p_title);
1192 }
1193 
request_permission(const String & p_name)1194 bool _OS::request_permission(const String &p_name) {
1195 
1196 	return OS::get_singleton()->request_permission(p_name);
1197 }
1198 
request_permissions()1199 bool _OS::request_permissions() {
1200 
1201 	return OS::get_singleton()->request_permissions();
1202 }
1203 
get_granted_permissions() const1204 Vector<String> _OS::get_granted_permissions() const {
1205 
1206 	return OS::get_singleton()->get_granted_permissions();
1207 }
1208 
get_tablet_driver_count() const1209 int _OS::get_tablet_driver_count() const {
1210 	return OS::get_singleton()->get_tablet_driver_count();
1211 }
1212 
get_tablet_driver_name(int p_driver) const1213 String _OS::get_tablet_driver_name(int p_driver) const {
1214 	return OS::get_singleton()->get_tablet_driver_name(p_driver);
1215 }
1216 
get_current_tablet_driver() const1217 String _OS::get_current_tablet_driver() const {
1218 	return OS::get_singleton()->get_current_tablet_driver();
1219 }
1220 
set_current_tablet_driver(const String & p_driver)1221 void _OS::set_current_tablet_driver(const String &p_driver) {
1222 	OS::get_singleton()->set_current_tablet_driver(p_driver);
1223 }
1224 
1225 _OS *_OS::singleton = NULL;
1226 
_bind_methods()1227 void _OS::_bind_methods() {
1228 
1229 	//ClassDB::bind_method(D_METHOD("get_mouse_position"),&_OS::get_mouse_position);
1230 	//ClassDB::bind_method(D_METHOD("is_mouse_grab_enabled"),&_OS::is_mouse_grab_enabled);
1231 
1232 	ClassDB::bind_method(D_METHOD("set_clipboard", "clipboard"), &_OS::set_clipboard);
1233 	ClassDB::bind_method(D_METHOD("get_clipboard"), &_OS::get_clipboard);
1234 
1235 	//will not delete for now, just unexpose
1236 	//ClassDB::bind_method(D_METHOD("set_video_mode","size","fullscreen","resizable","screen"),&_OS::set_video_mode,DEFVAL(0));
1237 	//ClassDB::bind_method(D_METHOD("get_video_mode_size","screen"),&_OS::get_video_mode,DEFVAL(0));
1238 	//ClassDB::bind_method(D_METHOD("is_video_mode_fullscreen","screen"),&_OS::is_video_mode_fullscreen,DEFVAL(0));
1239 	//ClassDB::bind_method(D_METHOD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0));
1240 	//ClassDB::bind_method(D_METHOD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0));
1241 
1242 	ClassDB::bind_method(D_METHOD("global_menu_add_item", "menu", "label", "id", "meta"), &_OS::global_menu_add_item);
1243 	ClassDB::bind_method(D_METHOD("global_menu_add_separator", "menu"), &_OS::global_menu_add_separator);
1244 	ClassDB::bind_method(D_METHOD("global_menu_remove_item", "menu", "idx"), &_OS::global_menu_remove_item);
1245 	ClassDB::bind_method(D_METHOD("global_menu_clear", "menu"), &_OS::global_menu_clear);
1246 
1247 	ClassDB::bind_method(D_METHOD("get_video_driver_count"), &_OS::get_video_driver_count);
1248 	ClassDB::bind_method(D_METHOD("get_video_driver_name", "driver"), &_OS::get_video_driver_name);
1249 	ClassDB::bind_method(D_METHOD("get_current_video_driver"), &_OS::get_current_video_driver);
1250 
1251 	ClassDB::bind_method(D_METHOD("get_audio_driver_count"), &_OS::get_audio_driver_count);
1252 	ClassDB::bind_method(D_METHOD("get_audio_driver_name", "driver"), &_OS::get_audio_driver_name);
1253 	ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &_OS::get_connected_midi_inputs);
1254 	ClassDB::bind_method(D_METHOD("open_midi_inputs"), &_OS::open_midi_inputs);
1255 	ClassDB::bind_method(D_METHOD("close_midi_inputs"), &_OS::close_midi_inputs);
1256 
1257 	ClassDB::bind_method(D_METHOD("get_screen_count"), &_OS::get_screen_count);
1258 	ClassDB::bind_method(D_METHOD("get_current_screen"), &_OS::get_current_screen);
1259 	ClassDB::bind_method(D_METHOD("set_current_screen", "screen"), &_OS::set_current_screen);
1260 	ClassDB::bind_method(D_METHOD("get_screen_position", "screen"), &_OS::get_screen_position, DEFVAL(-1));
1261 	ClassDB::bind_method(D_METHOD("get_screen_size", "screen"), &_OS::get_screen_size, DEFVAL(-1));
1262 	ClassDB::bind_method(D_METHOD("get_screen_dpi", "screen"), &_OS::get_screen_dpi, DEFVAL(-1));
1263 	ClassDB::bind_method(D_METHOD("get_screen_scale", "screen"), &_OS::get_screen_scale, DEFVAL(-1));
1264 	ClassDB::bind_method(D_METHOD("get_screen_max_scale"), &_OS::get_screen_max_scale);
1265 	ClassDB::bind_method(D_METHOD("get_window_position"), &_OS::get_window_position);
1266 	ClassDB::bind_method(D_METHOD("set_window_position", "position"), &_OS::set_window_position);
1267 	ClassDB::bind_method(D_METHOD("get_window_size"), &_OS::get_window_size);
1268 	ClassDB::bind_method(D_METHOD("get_max_window_size"), &_OS::get_max_window_size);
1269 	ClassDB::bind_method(D_METHOD("get_min_window_size"), &_OS::get_min_window_size);
1270 	ClassDB::bind_method(D_METHOD("set_max_window_size", "size"), &_OS::set_max_window_size);
1271 	ClassDB::bind_method(D_METHOD("set_min_window_size", "size"), &_OS::set_min_window_size);
1272 	ClassDB::bind_method(D_METHOD("set_window_size", "size"), &_OS::set_window_size);
1273 	ClassDB::bind_method(D_METHOD("get_window_safe_area"), &_OS::get_window_safe_area);
1274 	ClassDB::bind_method(D_METHOD("set_window_fullscreen", "enabled"), &_OS::set_window_fullscreen);
1275 	ClassDB::bind_method(D_METHOD("is_window_fullscreen"), &_OS::is_window_fullscreen);
1276 	ClassDB::bind_method(D_METHOD("set_window_resizable", "enabled"), &_OS::set_window_resizable);
1277 	ClassDB::bind_method(D_METHOD("is_window_resizable"), &_OS::is_window_resizable);
1278 	ClassDB::bind_method(D_METHOD("set_window_minimized", "enabled"), &_OS::set_window_minimized);
1279 	ClassDB::bind_method(D_METHOD("is_window_minimized"), &_OS::is_window_minimized);
1280 	ClassDB::bind_method(D_METHOD("set_window_maximized", "enabled"), &_OS::set_window_maximized);
1281 	ClassDB::bind_method(D_METHOD("is_window_maximized"), &_OS::is_window_maximized);
1282 	ClassDB::bind_method(D_METHOD("set_window_always_on_top", "enabled"), &_OS::set_window_always_on_top);
1283 	ClassDB::bind_method(D_METHOD("is_window_always_on_top"), &_OS::is_window_always_on_top);
1284 	ClassDB::bind_method(D_METHOD("is_window_focused"), &_OS::is_window_focused);
1285 	ClassDB::bind_method(D_METHOD("request_attention"), &_OS::request_attention);
1286 	ClassDB::bind_method(D_METHOD("get_real_window_size"), &_OS::get_real_window_size);
1287 	ClassDB::bind_method(D_METHOD("center_window"), &_OS::center_window);
1288 	ClassDB::bind_method(D_METHOD("move_window_to_foreground"), &_OS::move_window_to_foreground);
1289 
1290 	ClassDB::bind_method(D_METHOD("set_borderless_window", "borderless"), &_OS::set_borderless_window);
1291 	ClassDB::bind_method(D_METHOD("get_borderless_window"), &_OS::get_borderless_window);
1292 
1293 	ClassDB::bind_method(D_METHOD("get_window_per_pixel_transparency_enabled"), &_OS::get_window_per_pixel_transparency_enabled);
1294 	ClassDB::bind_method(D_METHOD("set_window_per_pixel_transparency_enabled", "enabled"), &_OS::set_window_per_pixel_transparency_enabled);
1295 
1296 	ClassDB::bind_method(D_METHOD("set_ime_active", "active"), &_OS::set_ime_active);
1297 	ClassDB::bind_method(D_METHOD("set_ime_position", "position"), &_OS::set_ime_position);
1298 	ClassDB::bind_method(D_METHOD("get_ime_selection"), &_OS::get_ime_selection);
1299 	ClassDB::bind_method(D_METHOD("get_ime_text"), &_OS::get_ime_text);
1300 
1301 	ClassDB::bind_method(D_METHOD("set_screen_orientation", "orientation"), &_OS::set_screen_orientation);
1302 	ClassDB::bind_method(D_METHOD("get_screen_orientation"), &_OS::get_screen_orientation);
1303 
1304 	ClassDB::bind_method(D_METHOD("set_keep_screen_on", "enabled"), &_OS::set_keep_screen_on);
1305 	ClassDB::bind_method(D_METHOD("is_keep_screen_on"), &_OS::is_keep_screen_on);
1306 
1307 	ClassDB::bind_method(D_METHOD("has_touchscreen_ui_hint"), &_OS::has_touchscreen_ui_hint);
1308 
1309 	ClassDB::bind_method(D_METHOD("set_window_title", "title"), &_OS::set_window_title);
1310 
1311 	ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode", "enable"), &_OS::set_low_processor_usage_mode);
1312 	ClassDB::bind_method(D_METHOD("is_in_low_processor_usage_mode"), &_OS::is_in_low_processor_usage_mode);
1313 
1314 	ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode_sleep_usec", "usec"), &_OS::set_low_processor_usage_mode_sleep_usec);
1315 	ClassDB::bind_method(D_METHOD("get_low_processor_usage_mode_sleep_usec"), &_OS::get_low_processor_usage_mode_sleep_usec);
1316 
1317 	ClassDB::bind_method(D_METHOD("get_processor_count"), &_OS::get_processor_count);
1318 
1319 	ClassDB::bind_method(D_METHOD("get_executable_path"), &_OS::get_executable_path);
1320 	ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "blocking", "output", "read_stderr"), &_OS::execute, DEFVAL(true), DEFVAL(Array()), DEFVAL(false));
1321 	ClassDB::bind_method(D_METHOD("kill", "pid"), &_OS::kill);
1322 	ClassDB::bind_method(D_METHOD("shell_open", "uri"), &_OS::shell_open);
1323 	ClassDB::bind_method(D_METHOD("get_process_id"), &_OS::get_process_id);
1324 
1325 	ClassDB::bind_method(D_METHOD("get_environment", "environment"), &_OS::get_environment);
1326 	ClassDB::bind_method(D_METHOD("has_environment", "environment"), &_OS::has_environment);
1327 
1328 	ClassDB::bind_method(D_METHOD("get_name"), &_OS::get_name);
1329 	ClassDB::bind_method(D_METHOD("get_cmdline_args"), &_OS::get_cmdline_args);
1330 
1331 	ClassDB::bind_method(D_METHOD("get_datetime", "utc"), &_OS::get_datetime, DEFVAL(false));
1332 	ClassDB::bind_method(D_METHOD("get_date", "utc"), &_OS::get_date, DEFVAL(false));
1333 	ClassDB::bind_method(D_METHOD("get_time", "utc"), &_OS::get_time, DEFVAL(false));
1334 	ClassDB::bind_method(D_METHOD("get_time_zone_info"), &_OS::get_time_zone_info);
1335 	ClassDB::bind_method(D_METHOD("get_unix_time"), &_OS::get_unix_time);
1336 	ClassDB::bind_method(D_METHOD("get_datetime_from_unix_time", "unix_time_val"), &_OS::get_datetime_from_unix_time);
1337 	ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime", "datetime"), &_OS::get_unix_time_from_datetime);
1338 	ClassDB::bind_method(D_METHOD("get_system_time_secs"), &_OS::get_system_time_secs);
1339 	ClassDB::bind_method(D_METHOD("get_system_time_msecs"), &_OS::get_system_time_msecs);
1340 
1341 	ClassDB::bind_method(D_METHOD("set_native_icon", "filename"), &_OS::set_native_icon);
1342 	ClassDB::bind_method(D_METHOD("set_icon", "icon"), &_OS::set_icon);
1343 
1344 	ClassDB::bind_method(D_METHOD("get_exit_code"), &_OS::get_exit_code);
1345 	ClassDB::bind_method(D_METHOD("set_exit_code", "code"), &_OS::set_exit_code);
1346 
1347 	ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &_OS::delay_usec);
1348 	ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &_OS::delay_msec);
1349 	ClassDB::bind_method(D_METHOD("get_ticks_msec"), &_OS::get_ticks_msec);
1350 	ClassDB::bind_method(D_METHOD("get_ticks_usec"), &_OS::get_ticks_usec);
1351 	ClassDB::bind_method(D_METHOD("get_splash_tick_msec"), &_OS::get_splash_tick_msec);
1352 	ClassDB::bind_method(D_METHOD("get_locale"), &_OS::get_locale);
1353 	ClassDB::bind_method(D_METHOD("get_latin_keyboard_variant"), &_OS::get_latin_keyboard_variant);
1354 	ClassDB::bind_method(D_METHOD("get_model_name"), &_OS::get_model_name);
1355 
1356 	ClassDB::bind_method(D_METHOD("keyboard_get_layout_count"), &_OS::keyboard_get_layout_count);
1357 	ClassDB::bind_method(D_METHOD("keyboard_get_current_layout"), &_OS::keyboard_get_current_layout);
1358 	ClassDB::bind_method(D_METHOD("keyboard_set_current_layout", "index"), &_OS::keyboard_set_current_layout);
1359 	ClassDB::bind_method(D_METHOD("keyboard_get_layout_language", "index"), &_OS::keyboard_get_layout_language);
1360 	ClassDB::bind_method(D_METHOD("keyboard_get_layout_name", "index"), &_OS::keyboard_get_layout_name);
1361 
1362 	ClassDB::bind_method(D_METHOD("can_draw"), &_OS::can_draw);
1363 	ClassDB::bind_method(D_METHOD("is_userfs_persistent"), &_OS::is_userfs_persistent);
1364 	ClassDB::bind_method(D_METHOD("is_stdout_verbose"), &_OS::is_stdout_verbose);
1365 
1366 	ClassDB::bind_method(D_METHOD("can_use_threads"), &_OS::can_use_threads);
1367 
1368 	ClassDB::bind_method(D_METHOD("is_debug_build"), &_OS::is_debug_build);
1369 
1370 	//ClassDB::bind_method(D_METHOD("get_mouse_button_state"),&_OS::get_mouse_button_state);
1371 
1372 	ClassDB::bind_method(D_METHOD("dump_memory_to_file", "file"), &_OS::dump_memory_to_file);
1373 	ClassDB::bind_method(D_METHOD("dump_resources_to_file", "file"), &_OS::dump_resources_to_file);
1374 	ClassDB::bind_method(D_METHOD("has_virtual_keyboard"), &_OS::has_virtual_keyboard);
1375 	ClassDB::bind_method(D_METHOD("show_virtual_keyboard", "existing_text", "multiline"), &_OS::show_virtual_keyboard, DEFVAL(""), DEFVAL(false));
1376 	ClassDB::bind_method(D_METHOD("hide_virtual_keyboard"), &_OS::hide_virtual_keyboard);
1377 	ClassDB::bind_method(D_METHOD("get_virtual_keyboard_height"), &_OS::get_virtual_keyboard_height);
1378 	ClassDB::bind_method(D_METHOD("print_resources_in_use", "short"), &_OS::print_resources_in_use, DEFVAL(false));
1379 	ClassDB::bind_method(D_METHOD("print_all_resources", "tofile"), &_OS::print_all_resources, DEFVAL(""));
1380 
1381 	ClassDB::bind_method(D_METHOD("get_static_memory_usage"), &_OS::get_static_memory_usage);
1382 	ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &_OS::get_static_memory_peak_usage);
1383 	ClassDB::bind_method(D_METHOD("get_dynamic_memory_usage"), &_OS::get_dynamic_memory_usage);
1384 
1385 	ClassDB::bind_method(D_METHOD("get_user_data_dir"), &_OS::get_user_data_dir);
1386 	ClassDB::bind_method(D_METHOD("get_system_dir", "dir"), &_OS::get_system_dir);
1387 	ClassDB::bind_method(D_METHOD("get_unique_id"), &_OS::get_unique_id);
1388 
1389 	ClassDB::bind_method(D_METHOD("is_ok_left_and_cancel_right"), &_OS::is_ok_left_and_cancel_right);
1390 
1391 	ClassDB::bind_method(D_METHOD("print_all_textures_by_size"), &_OS::print_all_textures_by_size);
1392 	ClassDB::bind_method(D_METHOD("print_resources_by_type", "types"), &_OS::print_resources_by_type);
1393 
1394 	ClassDB::bind_method(D_METHOD("native_video_play", "path", "volume", "audio_track", "subtitle_track"), &_OS::native_video_play);
1395 	ClassDB::bind_method(D_METHOD("native_video_is_playing"), &_OS::native_video_is_playing);
1396 	ClassDB::bind_method(D_METHOD("native_video_stop"), &_OS::native_video_stop);
1397 	ClassDB::bind_method(D_METHOD("native_video_pause"), &_OS::native_video_pause);
1398 	ClassDB::bind_method(D_METHOD("native_video_unpause"), &_OS::native_video_unpause);
1399 
1400 	ClassDB::bind_method(D_METHOD("get_scancode_string", "code"), &_OS::get_scancode_string);
1401 	ClassDB::bind_method(D_METHOD("is_scancode_unicode", "code"), &_OS::is_scancode_unicode);
1402 	ClassDB::bind_method(D_METHOD("find_scancode_from_string", "string"), &_OS::find_scancode_from_string);
1403 
1404 	ClassDB::bind_method(D_METHOD("set_use_file_access_save_and_swap", "enabled"), &_OS::set_use_file_access_save_and_swap);
1405 
1406 	ClassDB::bind_method(D_METHOD("alert", "text", "title"), &_OS::alert, DEFVAL("Alert!"));
1407 
1408 	ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &_OS::set_thread_name);
1409 
1410 	ClassDB::bind_method(D_METHOD("set_use_vsync", "enable"), &_OS::set_use_vsync);
1411 	ClassDB::bind_method(D_METHOD("is_vsync_enabled"), &_OS::is_vsync_enabled);
1412 
1413 	ClassDB::bind_method(D_METHOD("set_vsync_via_compositor", "enable"), &_OS::set_vsync_via_compositor);
1414 	ClassDB::bind_method(D_METHOD("is_vsync_via_compositor_enabled"), &_OS::is_vsync_via_compositor_enabled);
1415 
1416 	ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &_OS::has_feature);
1417 
1418 	ClassDB::bind_method(D_METHOD("get_power_state"), &_OS::get_power_state);
1419 	ClassDB::bind_method(D_METHOD("get_power_seconds_left"), &_OS::get_power_seconds_left);
1420 	ClassDB::bind_method(D_METHOD("get_power_percent_left"), &_OS::get_power_percent_left);
1421 
1422 	ClassDB::bind_method(D_METHOD("request_permission", "name"), &_OS::request_permission);
1423 	ClassDB::bind_method(D_METHOD("request_permissions"), &_OS::request_permissions);
1424 	ClassDB::bind_method(D_METHOD("get_granted_permissions"), &_OS::get_granted_permissions);
1425 
1426 	ClassDB::bind_method(D_METHOD("get_tablet_driver_count"), &_OS::get_tablet_driver_count);
1427 	ClassDB::bind_method(D_METHOD("get_tablet_driver_name", "idx"), &_OS::get_tablet_driver_name);
1428 	ClassDB::bind_method(D_METHOD("get_current_tablet_driver"), &_OS::get_current_tablet_driver);
1429 	ClassDB::bind_method(D_METHOD("set_current_tablet_driver", "name"), &_OS::set_current_tablet_driver);
1430 
1431 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "tablet_driver"), "set_current_tablet_driver", "get_current_tablet_driver");
1432 
1433 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "clipboard"), "set_clipboard", "get_clipboard");
1434 	ADD_PROPERTY(PropertyInfo(Variant::INT, "current_screen"), "set_current_screen", "get_current_screen");
1435 	ADD_PROPERTY(PropertyInfo(Variant::INT, "exit_code"), "set_exit_code", "get_exit_code");
1436 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vsync_enabled"), "set_use_vsync", "is_vsync_enabled");
1437 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vsync_via_compositor"), "set_vsync_via_compositor", "is_vsync_via_compositor_enabled");
1438 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
1439 	ADD_PROPERTY(PropertyInfo(Variant::INT, "low_processor_usage_mode_sleep_usec"), "set_low_processor_usage_mode_sleep_usec", "get_low_processor_usage_mode_sleep_usec");
1440 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_screen_on"), "set_keep_screen_on", "is_keep_screen_on");
1441 	ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "min_window_size"), "set_min_window_size", "get_min_window_size");
1442 	ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "max_window_size"), "set_max_window_size", "get_max_window_size");
1443 	ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor"), "set_screen_orientation", "get_screen_orientation");
1444 	ADD_GROUP("Window", "window_");
1445 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_borderless"), "set_borderless_window", "get_borderless_window");
1446 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_per_pixel_transparency_enabled"), "set_window_per_pixel_transparency_enabled", "get_window_per_pixel_transparency_enabled");
1447 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_fullscreen"), "set_window_fullscreen", "is_window_fullscreen");
1448 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_maximized"), "set_window_maximized", "is_window_maximized");
1449 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_minimized"), "set_window_minimized", "is_window_minimized");
1450 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_resizable"), "set_window_resizable", "is_window_resizable");
1451 	ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "window_position"), "set_window_position", "get_window_position");
1452 	ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "window_size"), "set_window_size", "get_window_size");
1453 
1454 	// Those default values need to be specified for the docs generator,
1455 	// to avoid using values from the documentation writer's own OS instance.
1456 	ADD_PROPERTY_DEFAULT("clipboard", "");
1457 	ADD_PROPERTY_DEFAULT("current_screen", 0);
1458 	ADD_PROPERTY_DEFAULT("exit_code", 0);
1459 	ADD_PROPERTY_DEFAULT("vsync_enabled", true);
1460 	ADD_PROPERTY_DEFAULT("vsync_via_compositor", false);
1461 	ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false);
1462 	ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900);
1463 	ADD_PROPERTY_DEFAULT("keep_screen_on", true);
1464 	ADD_PROPERTY_DEFAULT("min_window_size", Vector2());
1465 	ADD_PROPERTY_DEFAULT("max_window_size", Vector2());
1466 	ADD_PROPERTY_DEFAULT("screen_orientation", 0);
1467 	ADD_PROPERTY_DEFAULT("window_borderless", false);
1468 	ADD_PROPERTY_DEFAULT("window_per_pixel_transparency_enabled", false);
1469 	ADD_PROPERTY_DEFAULT("window_fullscreen", false);
1470 	ADD_PROPERTY_DEFAULT("window_maximized", false);
1471 	ADD_PROPERTY_DEFAULT("window_minimized", false);
1472 	ADD_PROPERTY_DEFAULT("window_resizable", true);
1473 	ADD_PROPERTY_DEFAULT("window_position", Vector2());
1474 	ADD_PROPERTY_DEFAULT("window_size", Vector2());
1475 
1476 	BIND_ENUM_CONSTANT(VIDEO_DRIVER_GLES2);
1477 	BIND_ENUM_CONSTANT(VIDEO_DRIVER_GLES3);
1478 
1479 	BIND_ENUM_CONSTANT(DAY_SUNDAY);
1480 	BIND_ENUM_CONSTANT(DAY_MONDAY);
1481 	BIND_ENUM_CONSTANT(DAY_TUESDAY);
1482 	BIND_ENUM_CONSTANT(DAY_WEDNESDAY);
1483 	BIND_ENUM_CONSTANT(DAY_THURSDAY);
1484 	BIND_ENUM_CONSTANT(DAY_FRIDAY);
1485 	BIND_ENUM_CONSTANT(DAY_SATURDAY);
1486 
1487 	BIND_ENUM_CONSTANT(MONTH_JANUARY);
1488 	BIND_ENUM_CONSTANT(MONTH_FEBRUARY);
1489 	BIND_ENUM_CONSTANT(MONTH_MARCH);
1490 	BIND_ENUM_CONSTANT(MONTH_APRIL);
1491 	BIND_ENUM_CONSTANT(MONTH_MAY);
1492 	BIND_ENUM_CONSTANT(MONTH_JUNE);
1493 	BIND_ENUM_CONSTANT(MONTH_JULY);
1494 	BIND_ENUM_CONSTANT(MONTH_AUGUST);
1495 	BIND_ENUM_CONSTANT(MONTH_SEPTEMBER);
1496 	BIND_ENUM_CONSTANT(MONTH_OCTOBER);
1497 	BIND_ENUM_CONSTANT(MONTH_NOVEMBER);
1498 	BIND_ENUM_CONSTANT(MONTH_DECEMBER);
1499 
1500 	BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_LANDSCAPE);
1501 	BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_PORTRAIT);
1502 	BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
1503 	BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_REVERSE_PORTRAIT);
1504 	BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
1505 	BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_SENSOR_PORTRAIT);
1506 	BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_SENSOR);
1507 
1508 	BIND_ENUM_CONSTANT(SYSTEM_DIR_DESKTOP);
1509 	BIND_ENUM_CONSTANT(SYSTEM_DIR_DCIM);
1510 	BIND_ENUM_CONSTANT(SYSTEM_DIR_DOCUMENTS);
1511 	BIND_ENUM_CONSTANT(SYSTEM_DIR_DOWNLOADS);
1512 	BIND_ENUM_CONSTANT(SYSTEM_DIR_MOVIES);
1513 	BIND_ENUM_CONSTANT(SYSTEM_DIR_MUSIC);
1514 	BIND_ENUM_CONSTANT(SYSTEM_DIR_PICTURES);
1515 	BIND_ENUM_CONSTANT(SYSTEM_DIR_RINGTONES);
1516 
1517 	BIND_ENUM_CONSTANT(POWERSTATE_UNKNOWN);
1518 	BIND_ENUM_CONSTANT(POWERSTATE_ON_BATTERY);
1519 	BIND_ENUM_CONSTANT(POWERSTATE_NO_BATTERY);
1520 	BIND_ENUM_CONSTANT(POWERSTATE_CHARGING);
1521 	BIND_ENUM_CONSTANT(POWERSTATE_CHARGED);
1522 }
1523 
_OS()1524 _OS::_OS() {
1525 
1526 	singleton = this;
1527 }
1528 
1529 ///////////////////// GEOMETRY
1530 
1531 _Geometry *_Geometry::singleton = NULL;
1532 
get_singleton()1533 _Geometry *_Geometry::get_singleton() {
1534 
1535 	return singleton;
1536 }
1537 
build_box_planes(const Vector3 & p_extents)1538 PoolVector<Plane> _Geometry::build_box_planes(const Vector3 &p_extents) {
1539 
1540 	return Geometry::build_box_planes(p_extents);
1541 }
1542 
build_cylinder_planes(float p_radius,float p_height,int p_sides,Vector3::Axis p_axis)1543 PoolVector<Plane> _Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
1544 
1545 	return Geometry::build_cylinder_planes(p_radius, p_height, p_sides, p_axis);
1546 }
build_capsule_planes(float p_radius,float p_height,int p_sides,int p_lats,Vector3::Axis p_axis)1547 PoolVector<Plane> _Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
1548 
1549 	return Geometry::build_capsule_planes(p_radius, p_height, p_sides, p_lats, p_axis);
1550 }
1551 
is_point_in_circle(const Vector2 & p_point,const Vector2 & p_circle_pos,real_t p_circle_radius)1552 bool _Geometry::is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) {
1553 
1554 	return Geometry::is_point_in_circle(p_point, p_circle_pos, p_circle_radius);
1555 }
1556 
segment_intersects_circle(const Vector2 & p_from,const Vector2 & p_to,const Vector2 & p_circle_pos,real_t p_circle_radius)1557 real_t _Geometry::segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) {
1558 
1559 	return Geometry::segment_intersects_circle(p_from, p_to, p_circle_pos, p_circle_radius);
1560 }
1561 
segment_intersects_segment_2d(const Vector2 & p_from_a,const Vector2 & p_to_a,const Vector2 & p_from_b,const Vector2 & p_to_b)1562 Variant _Geometry::segment_intersects_segment_2d(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b) {
1563 
1564 	Vector2 result;
1565 	if (Geometry::segment_intersects_segment_2d(p_from_a, p_to_a, p_from_b, p_to_b, &result)) {
1566 
1567 		return result;
1568 	} else {
1569 		return Variant();
1570 	};
1571 };
1572 
line_intersects_line_2d(const Vector2 & p_from_a,const Vector2 & p_dir_a,const Vector2 & p_from_b,const Vector2 & p_dir_b)1573 Variant _Geometry::line_intersects_line_2d(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b) {
1574 
1575 	Vector2 result;
1576 	if (Geometry::line_intersects_line_2d(p_from_a, p_dir_a, p_from_b, p_dir_b, result)) {
1577 		return result;
1578 	} else {
1579 		return Variant();
1580 	}
1581 }
1582 
get_closest_points_between_segments_2d(const Vector2 & p1,const Vector2 & q1,const Vector2 & p2,const Vector2 & q2)1583 PoolVector<Vector2> _Geometry::get_closest_points_between_segments_2d(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2) {
1584 
1585 	Vector2 r1, r2;
1586 	Geometry::get_closest_points_between_segments(p1, q1, p2, q2, r1, r2);
1587 	PoolVector<Vector2> r;
1588 	r.resize(2);
1589 	r.set(0, r1);
1590 	r.set(1, r2);
1591 	return r;
1592 }
1593 
get_closest_points_between_segments(const Vector3 & p1,const Vector3 & p2,const Vector3 & q1,const Vector3 & q2)1594 PoolVector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2) {
1595 
1596 	Vector3 r1, r2;
1597 	Geometry::get_closest_points_between_segments(p1, p2, q1, q2, r1, r2);
1598 	PoolVector<Vector3> r;
1599 	r.resize(2);
1600 	r.set(0, r1);
1601 	r.set(1, r2);
1602 	return r;
1603 }
get_closest_point_to_segment_2d(const Vector2 & p_point,const Vector2 & p_a,const Vector2 & p_b)1604 Vector2 _Geometry::get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
1605 
1606 	Vector2 s[2] = { p_a, p_b };
1607 	return Geometry::get_closest_point_to_segment_2d(p_point, s);
1608 }
get_closest_point_to_segment(const Vector3 & p_point,const Vector3 & p_a,const Vector3 & p_b)1609 Vector3 _Geometry::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
1610 
1611 	Vector3 s[2] = { p_a, p_b };
1612 	return Geometry::get_closest_point_to_segment(p_point, s);
1613 }
get_closest_point_to_segment_uncapped_2d(const Vector2 & p_point,const Vector2 & p_a,const Vector2 & p_b)1614 Vector2 _Geometry::get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
1615 
1616 	Vector2 s[2] = { p_a, p_b };
1617 	return Geometry::get_closest_point_to_segment_uncapped_2d(p_point, s);
1618 }
get_closest_point_to_segment_uncapped(const Vector3 & p_point,const Vector3 & p_a,const Vector3 & p_b)1619 Vector3 _Geometry::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
1620 
1621 	Vector3 s[2] = { p_a, p_b };
1622 	return Geometry::get_closest_point_to_segment_uncapped(p_point, s);
1623 }
ray_intersects_triangle(const Vector3 & p_from,const Vector3 & p_dir,const Vector3 & p_v0,const Vector3 & p_v1,const Vector3 & p_v2)1624 Variant _Geometry::ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
1625 
1626 	Vector3 res;
1627 	if (Geometry::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res))
1628 		return res;
1629 	else
1630 		return Variant();
1631 }
segment_intersects_triangle(const Vector3 & p_from,const Vector3 & p_to,const Vector3 & p_v0,const Vector3 & p_v1,const Vector3 & p_v2)1632 Variant _Geometry::segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
1633 
1634 	Vector3 res;
1635 	if (Geometry::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res))
1636 		return res;
1637 	else
1638 		return Variant();
1639 }
1640 
point_is_inside_triangle(const Vector2 & s,const Vector2 & a,const Vector2 & b,const Vector2 & c) const1641 bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
1642 
1643 	return Geometry::is_point_in_triangle(s, a, b, c);
1644 }
1645 
segment_intersects_sphere(const Vector3 & p_from,const Vector3 & p_to,const Vector3 & p_sphere_pos,real_t p_sphere_radius)1646 PoolVector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) {
1647 
1648 	PoolVector<Vector3> r;
1649 	Vector3 res, norm;
1650 	if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm))
1651 		return r;
1652 
1653 	r.resize(2);
1654 	r.set(0, res);
1655 	r.set(1, norm);
1656 	return r;
1657 }
segment_intersects_cylinder(const Vector3 & p_from,const Vector3 & p_to,float p_height,float p_radius)1658 PoolVector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
1659 
1660 	PoolVector<Vector3> r;
1661 	Vector3 res, norm;
1662 	if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm))
1663 		return r;
1664 
1665 	r.resize(2);
1666 	r.set(0, res);
1667 	r.set(1, norm);
1668 	return r;
1669 }
segment_intersects_convex(const Vector3 & p_from,const Vector3 & p_to,const Vector<Plane> & p_planes)1670 PoolVector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes) {
1671 
1672 	PoolVector<Vector3> r;
1673 	Vector3 res, norm;
1674 	if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm))
1675 		return r;
1676 
1677 	r.resize(2);
1678 	r.set(0, res);
1679 	r.set(1, norm);
1680 	return r;
1681 }
1682 
is_polygon_clockwise(const Vector<Vector2> & p_polygon)1683 bool _Geometry::is_polygon_clockwise(const Vector<Vector2> &p_polygon) {
1684 
1685 	return Geometry::is_polygon_clockwise(p_polygon);
1686 }
1687 
is_point_in_polygon(const Point2 & p_point,const Vector<Vector2> & p_polygon)1688 bool _Geometry::is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon) {
1689 
1690 	return Geometry::is_point_in_polygon(p_point, p_polygon);
1691 }
1692 
triangulate_polygon(const Vector<Vector2> & p_polygon)1693 Vector<int> _Geometry::triangulate_polygon(const Vector<Vector2> &p_polygon) {
1694 
1695 	return Geometry::triangulate_polygon(p_polygon);
1696 }
1697 
triangulate_delaunay_2d(const Vector<Vector2> & p_points)1698 Vector<int> _Geometry::triangulate_delaunay_2d(const Vector<Vector2> &p_points) {
1699 
1700 	return Geometry::triangulate_delaunay_2d(p_points);
1701 }
1702 
convex_hull_2d(const Vector<Point2> & p_points)1703 Vector<Point2> _Geometry::convex_hull_2d(const Vector<Point2> &p_points) {
1704 
1705 	return Geometry::convex_hull_2d(p_points);
1706 }
1707 
clip_polygon(const Vector<Vector3> & p_points,const Plane & p_plane)1708 Vector<Vector3> _Geometry::clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane) {
1709 
1710 	return Geometry::clip_polygon(p_points, p_plane);
1711 }
1712 
merge_polygons_2d(const Vector<Vector2> & p_polygon_a,const Vector<Vector2> & p_polygon_b)1713 Array _Geometry::merge_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
1714 
1715 	Vector<Vector<Point2> > polys = Geometry::merge_polygons_2d(p_polygon_a, p_polygon_b);
1716 
1717 	Array ret;
1718 
1719 	for (int i = 0; i < polys.size(); ++i) {
1720 		ret.push_back(polys[i]);
1721 	}
1722 	return ret;
1723 }
1724 
clip_polygons_2d(const Vector<Vector2> & p_polygon_a,const Vector<Vector2> & p_polygon_b)1725 Array _Geometry::clip_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
1726 
1727 	Vector<Vector<Point2> > polys = Geometry::clip_polygons_2d(p_polygon_a, p_polygon_b);
1728 
1729 	Array ret;
1730 
1731 	for (int i = 0; i < polys.size(); ++i) {
1732 		ret.push_back(polys[i]);
1733 	}
1734 	return ret;
1735 }
1736 
intersect_polygons_2d(const Vector<Vector2> & p_polygon_a,const Vector<Vector2> & p_polygon_b)1737 Array _Geometry::intersect_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
1738 
1739 	Vector<Vector<Point2> > polys = Geometry::intersect_polygons_2d(p_polygon_a, p_polygon_b);
1740 
1741 	Array ret;
1742 
1743 	for (int i = 0; i < polys.size(); ++i) {
1744 		ret.push_back(polys[i]);
1745 	}
1746 	return ret;
1747 }
1748 
exclude_polygons_2d(const Vector<Vector2> & p_polygon_a,const Vector<Vector2> & p_polygon_b)1749 Array _Geometry::exclude_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
1750 
1751 	Vector<Vector<Point2> > polys = Geometry::exclude_polygons_2d(p_polygon_a, p_polygon_b);
1752 
1753 	Array ret;
1754 
1755 	for (int i = 0; i < polys.size(); ++i) {
1756 		ret.push_back(polys[i]);
1757 	}
1758 	return ret;
1759 }
1760 
clip_polyline_with_polygon_2d(const Vector<Vector2> & p_polyline,const Vector<Vector2> & p_polygon)1761 Array _Geometry::clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
1762 
1763 	Vector<Vector<Point2> > polys = Geometry::clip_polyline_with_polygon_2d(p_polyline, p_polygon);
1764 
1765 	Array ret;
1766 
1767 	for (int i = 0; i < polys.size(); ++i) {
1768 		ret.push_back(polys[i]);
1769 	}
1770 	return ret;
1771 }
1772 
intersect_polyline_with_polygon_2d(const Vector<Vector2> & p_polyline,const Vector<Vector2> & p_polygon)1773 Array _Geometry::intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
1774 
1775 	Vector<Vector<Point2> > polys = Geometry::intersect_polyline_with_polygon_2d(p_polyline, p_polygon);
1776 
1777 	Array ret;
1778 
1779 	for (int i = 0; i < polys.size(); ++i) {
1780 		ret.push_back(polys[i]);
1781 	}
1782 	return ret;
1783 }
1784 
offset_polygon_2d(const Vector<Vector2> & p_polygon,real_t p_delta,PolyJoinType p_join_type)1785 Array _Geometry::offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
1786 
1787 	Vector<Vector<Point2> > polys = Geometry::offset_polygon_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type));
1788 
1789 	Array ret;
1790 
1791 	for (int i = 0; i < polys.size(); ++i) {
1792 		ret.push_back(polys[i]);
1793 	}
1794 	return ret;
1795 }
1796 
offset_polyline_2d(const Vector<Vector2> & p_polygon,real_t p_delta,PolyJoinType p_join_type,PolyEndType p_end_type)1797 Array _Geometry::offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
1798 
1799 	Vector<Vector<Point2> > polys = Geometry::offset_polyline_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type), Geometry::PolyEndType(p_end_type));
1800 
1801 	Array ret;
1802 
1803 	for (int i = 0; i < polys.size(); ++i) {
1804 		ret.push_back(polys[i]);
1805 	}
1806 	return ret;
1807 }
1808 
make_atlas(const Vector<Size2> & p_rects)1809 Dictionary _Geometry::make_atlas(const Vector<Size2> &p_rects) {
1810 
1811 	Dictionary ret;
1812 
1813 	Vector<Size2i> rects;
1814 	for (int i = 0; i < p_rects.size(); i++) {
1815 
1816 		rects.push_back(p_rects[i]);
1817 	};
1818 
1819 	Vector<Point2i> result;
1820 	Size2i size;
1821 
1822 	Geometry::make_atlas(rects, result, size);
1823 
1824 	Size2 r_size = size;
1825 	Vector<Point2> r_result;
1826 	for (int i = 0; i < result.size(); i++) {
1827 
1828 		r_result.push_back(result[i]);
1829 	};
1830 
1831 	ret["points"] = r_result;
1832 	ret["size"] = r_size;
1833 
1834 	return ret;
1835 };
1836 
get_uv84_normal_bit(const Vector3 & p_vector)1837 int _Geometry::get_uv84_normal_bit(const Vector3 &p_vector) {
1838 
1839 	return Geometry::get_uv84_normal_bit(p_vector);
1840 }
1841 
_bind_methods()1842 void _Geometry::_bind_methods() {
1843 
1844 	ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &_Geometry::build_box_planes);
1845 	ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &_Geometry::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
1846 	ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &_Geometry::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
1847 	ClassDB::bind_method(D_METHOD("is_point_in_circle", "point", "circle_position", "circle_radius"), &_Geometry::is_point_in_circle);
1848 	ClassDB::bind_method(D_METHOD("segment_intersects_circle", "segment_from", "segment_to", "circle_position", "circle_radius"), &_Geometry::segment_intersects_circle);
1849 	ClassDB::bind_method(D_METHOD("segment_intersects_segment_2d", "from_a", "to_a", "from_b", "to_b"), &_Geometry::segment_intersects_segment_2d);
1850 	ClassDB::bind_method(D_METHOD("line_intersects_line_2d", "from_a", "dir_a", "from_b", "dir_b"), &_Geometry::line_intersects_line_2d);
1851 
1852 	ClassDB::bind_method(D_METHOD("get_closest_points_between_segments_2d", "p1", "q1", "p2", "q2"), &_Geometry::get_closest_points_between_segments_2d);
1853 	ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "p2", "q1", "q2"), &_Geometry::get_closest_points_between_segments);
1854 
1855 	ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_2d", "point", "s1", "s2"), &_Geometry::get_closest_point_to_segment_2d);
1856 	ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &_Geometry::get_closest_point_to_segment);
1857 
1858 	ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped_2d", "point", "s1", "s2"), &_Geometry::get_closest_point_to_segment_uncapped_2d);
1859 	ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &_Geometry::get_closest_point_to_segment_uncapped);
1860 
1861 	ClassDB::bind_method(D_METHOD("get_uv84_normal_bit", "normal"), &_Geometry::get_uv84_normal_bit);
1862 
1863 	ClassDB::bind_method(D_METHOD("ray_intersects_triangle", "from", "dir", "a", "b", "c"), &_Geometry::ray_intersects_triangle);
1864 	ClassDB::bind_method(D_METHOD("segment_intersects_triangle", "from", "to", "a", "b", "c"), &_Geometry::segment_intersects_triangle);
1865 	ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "sphere_position", "sphere_radius"), &_Geometry::segment_intersects_sphere);
1866 	ClassDB::bind_method(D_METHOD("segment_intersects_cylinder", "from", "to", "height", "radius"), &_Geometry::segment_intersects_cylinder);
1867 	ClassDB::bind_method(D_METHOD("segment_intersects_convex", "from", "to", "planes"), &_Geometry::segment_intersects_convex);
1868 	ClassDB::bind_method(D_METHOD("point_is_inside_triangle", "point", "a", "b", "c"), &_Geometry::point_is_inside_triangle);
1869 
1870 	ClassDB::bind_method(D_METHOD("is_polygon_clockwise", "polygon"), &_Geometry::is_polygon_clockwise);
1871 	ClassDB::bind_method(D_METHOD("is_point_in_polygon", "point", "polygon"), &_Geometry::is_point_in_polygon);
1872 	ClassDB::bind_method(D_METHOD("triangulate_polygon", "polygon"), &_Geometry::triangulate_polygon);
1873 	ClassDB::bind_method(D_METHOD("triangulate_delaunay_2d", "points"), &_Geometry::triangulate_delaunay_2d);
1874 	ClassDB::bind_method(D_METHOD("convex_hull_2d", "points"), &_Geometry::convex_hull_2d);
1875 	ClassDB::bind_method(D_METHOD("clip_polygon", "points", "plane"), &_Geometry::clip_polygon);
1876 
1877 	ClassDB::bind_method(D_METHOD("merge_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::merge_polygons_2d);
1878 	ClassDB::bind_method(D_METHOD("clip_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::clip_polygons_2d);
1879 	ClassDB::bind_method(D_METHOD("intersect_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::intersect_polygons_2d);
1880 	ClassDB::bind_method(D_METHOD("exclude_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::exclude_polygons_2d);
1881 
1882 	ClassDB::bind_method(D_METHOD("clip_polyline_with_polygon_2d", "polyline", "polygon"), &_Geometry::clip_polyline_with_polygon_2d);
1883 	ClassDB::bind_method(D_METHOD("intersect_polyline_with_polygon_2d", "polyline", "polygon"), &_Geometry::intersect_polyline_with_polygon_2d);
1884 
1885 	ClassDB::bind_method(D_METHOD("offset_polygon_2d", "polygon", "delta", "join_type"), &_Geometry::offset_polygon_2d, DEFVAL(JOIN_SQUARE));
1886 	ClassDB::bind_method(D_METHOD("offset_polyline_2d", "polyline", "delta", "join_type", "end_type"), &_Geometry::offset_polyline_2d, DEFVAL(JOIN_SQUARE), DEFVAL(END_SQUARE));
1887 
1888 	ClassDB::bind_method(D_METHOD("make_atlas", "sizes"), &_Geometry::make_atlas);
1889 
1890 	BIND_ENUM_CONSTANT(OPERATION_UNION);
1891 	BIND_ENUM_CONSTANT(OPERATION_DIFFERENCE);
1892 	BIND_ENUM_CONSTANT(OPERATION_INTERSECTION);
1893 	BIND_ENUM_CONSTANT(OPERATION_XOR);
1894 
1895 	BIND_ENUM_CONSTANT(JOIN_SQUARE);
1896 	BIND_ENUM_CONSTANT(JOIN_ROUND);
1897 	BIND_ENUM_CONSTANT(JOIN_MITER);
1898 
1899 	BIND_ENUM_CONSTANT(END_POLYGON);
1900 	BIND_ENUM_CONSTANT(END_JOINED);
1901 	BIND_ENUM_CONSTANT(END_BUTT);
1902 	BIND_ENUM_CONSTANT(END_SQUARE);
1903 	BIND_ENUM_CONSTANT(END_ROUND);
1904 }
1905 
_Geometry()1906 _Geometry::_Geometry() {
1907 	singleton = this;
1908 }
1909 
1910 ///////////////////////// FILE
1911 
open_encrypted(const String & p_path,ModeFlags p_mode_flags,const Vector<uint8_t> & p_key)1912 Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key) {
1913 
1914 	Error err = open(p_path, p_mode_flags);
1915 	if (err)
1916 		return err;
1917 
1918 	FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
1919 	err = fae->open_and_parse(f, p_key, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
1920 	if (err) {
1921 		memdelete(fae);
1922 		close();
1923 		return err;
1924 	}
1925 	f = fae;
1926 	return OK;
1927 }
1928 
open_encrypted_pass(const String & p_path,ModeFlags p_mode_flags,const String & p_pass)1929 Error _File::open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass) {
1930 
1931 	Error err = open(p_path, p_mode_flags);
1932 	if (err)
1933 		return err;
1934 
1935 	FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
1936 	err = fae->open_and_parse_password(f, p_pass, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
1937 	if (err) {
1938 		memdelete(fae);
1939 		close();
1940 		return err;
1941 	}
1942 
1943 	f = fae;
1944 	return OK;
1945 }
1946 
open_compressed(const String & p_path,ModeFlags p_mode_flags,CompressionMode p_compress_mode)1947 Error _File::open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode) {
1948 
1949 	FileAccessCompressed *fac = memnew(FileAccessCompressed);
1950 
1951 	fac->configure("GCPF", (Compression::Mode)p_compress_mode);
1952 
1953 	Error err = fac->_open(p_path, p_mode_flags);
1954 
1955 	if (err) {
1956 		memdelete(fac);
1957 		return err;
1958 	}
1959 
1960 	f = fac;
1961 	return OK;
1962 }
1963 
open(const String & p_path,ModeFlags p_mode_flags)1964 Error _File::open(const String &p_path, ModeFlags p_mode_flags) {
1965 
1966 	close();
1967 	Error err;
1968 	f = FileAccess::open(p_path, p_mode_flags, &err);
1969 	if (f)
1970 		f->set_endian_swap(eswap);
1971 	return err;
1972 }
1973 
close()1974 void _File::close() {
1975 
1976 	if (f)
1977 		memdelete(f);
1978 	f = NULL;
1979 }
is_open() const1980 bool _File::is_open() const {
1981 
1982 	return f != NULL;
1983 }
get_path() const1984 String _File::get_path() const {
1985 
1986 	ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use.");
1987 	return f->get_path();
1988 }
1989 
get_path_absolute() const1990 String _File::get_path_absolute() const {
1991 
1992 	ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use.");
1993 	return f->get_path_absolute();
1994 }
1995 
seek(int64_t p_position)1996 void _File::seek(int64_t p_position) {
1997 
1998 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
1999 	f->seek(p_position);
2000 }
seek_end(int64_t p_position)2001 void _File::seek_end(int64_t p_position) {
2002 
2003 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2004 	f->seek_end(p_position);
2005 }
get_position() const2006 int64_t _File::get_position() const {
2007 
2008 	ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
2009 	return f->get_position();
2010 }
2011 
get_len() const2012 int64_t _File::get_len() const {
2013 
2014 	ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
2015 	return f->get_len();
2016 }
2017 
eof_reached() const2018 bool _File::eof_reached() const {
2019 
2020 	ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use.");
2021 	return f->eof_reached();
2022 }
2023 
get_8() const2024 uint8_t _File::get_8() const {
2025 
2026 	ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
2027 	return f->get_8();
2028 }
get_16() const2029 uint16_t _File::get_16() const {
2030 
2031 	ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
2032 	return f->get_16();
2033 }
get_32() const2034 uint32_t _File::get_32() const {
2035 
2036 	ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
2037 	return f->get_32();
2038 }
get_64() const2039 uint64_t _File::get_64() const {
2040 
2041 	ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
2042 	return f->get_64();
2043 }
2044 
get_float() const2045 float _File::get_float() const {
2046 
2047 	ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
2048 	return f->get_float();
2049 }
get_double() const2050 double _File::get_double() const {
2051 
2052 	ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
2053 	return f->get_double();
2054 }
get_real() const2055 real_t _File::get_real() const {
2056 
2057 	ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
2058 	return f->get_real();
2059 }
2060 
get_buffer(int p_length) const2061 PoolVector<uint8_t> _File::get_buffer(int p_length) const {
2062 
2063 	PoolVector<uint8_t> data;
2064 	ERR_FAIL_COND_V_MSG(!f, data, "File must be opened before use.");
2065 
2066 	ERR_FAIL_COND_V_MSG(p_length < 0, data, "Length of buffer cannot be smaller than 0.");
2067 	if (p_length == 0)
2068 		return data;
2069 
2070 	Error err = data.resize(p_length);
2071 	ERR_FAIL_COND_V_MSG(err != OK, data, "Can't resize data to " + itos(p_length) + " elements.");
2072 
2073 	PoolVector<uint8_t>::Write w = data.write();
2074 	int len = f->get_buffer(&w[0], p_length);
2075 	ERR_FAIL_COND_V(len < 0, PoolVector<uint8_t>());
2076 
2077 	w.release();
2078 
2079 	if (len < p_length)
2080 		data.resize(p_length);
2081 
2082 	return data;
2083 }
2084 
get_as_text() const2085 String _File::get_as_text() const {
2086 
2087 	ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use.");
2088 
2089 	String text;
2090 	size_t original_pos = f->get_position();
2091 	f->seek(0);
2092 
2093 	String l = get_line();
2094 	while (!eof_reached()) {
2095 		text += l + "\n";
2096 		l = get_line();
2097 	}
2098 	text += l;
2099 
2100 	f->seek(original_pos);
2101 
2102 	return text;
2103 }
2104 
get_md5(const String & p_path) const2105 String _File::get_md5(const String &p_path) const {
2106 
2107 	return FileAccess::get_md5(p_path);
2108 }
2109 
get_sha256(const String & p_path) const2110 String _File::get_sha256(const String &p_path) const {
2111 
2112 	return FileAccess::get_sha256(p_path);
2113 }
2114 
get_line() const2115 String _File::get_line() const {
2116 
2117 	ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use.");
2118 	return f->get_line();
2119 }
2120 
get_csv_line(const String & p_delim) const2121 Vector<String> _File::get_csv_line(const String &p_delim) const {
2122 	ERR_FAIL_COND_V_MSG(!f, Vector<String>(), "File must be opened before use.");
2123 	return f->get_csv_line(p_delim);
2124 }
2125 
2126 /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
2127  * It's not about the current CPU type but file formats.
2128  * this flags get reset to false (little endian) on each open
2129  */
2130 
set_endian_swap(bool p_swap)2131 void _File::set_endian_swap(bool p_swap) {
2132 
2133 	eswap = p_swap;
2134 	if (f)
2135 		f->set_endian_swap(p_swap);
2136 }
get_endian_swap()2137 bool _File::get_endian_swap() {
2138 
2139 	return eswap;
2140 }
2141 
get_error() const2142 Error _File::get_error() const {
2143 
2144 	if (!f)
2145 		return ERR_UNCONFIGURED;
2146 	return f->get_error();
2147 }
2148 
store_8(uint8_t p_dest)2149 void _File::store_8(uint8_t p_dest) {
2150 
2151 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2152 
2153 	f->store_8(p_dest);
2154 }
store_16(uint16_t p_dest)2155 void _File::store_16(uint16_t p_dest) {
2156 
2157 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2158 
2159 	f->store_16(p_dest);
2160 }
store_32(uint32_t p_dest)2161 void _File::store_32(uint32_t p_dest) {
2162 
2163 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2164 
2165 	f->store_32(p_dest);
2166 }
store_64(uint64_t p_dest)2167 void _File::store_64(uint64_t p_dest) {
2168 
2169 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2170 
2171 	f->store_64(p_dest);
2172 }
2173 
store_float(float p_dest)2174 void _File::store_float(float p_dest) {
2175 
2176 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2177 
2178 	f->store_float(p_dest);
2179 }
store_double(double p_dest)2180 void _File::store_double(double p_dest) {
2181 
2182 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2183 
2184 	f->store_double(p_dest);
2185 }
store_real(real_t p_real)2186 void _File::store_real(real_t p_real) {
2187 
2188 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2189 
2190 	f->store_real(p_real);
2191 }
2192 
store_string(const String & p_string)2193 void _File::store_string(const String &p_string) {
2194 
2195 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2196 
2197 	f->store_string(p_string);
2198 }
2199 
store_pascal_string(const String & p_string)2200 void _File::store_pascal_string(const String &p_string) {
2201 
2202 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2203 
2204 	f->store_pascal_string(p_string);
2205 };
2206 
get_pascal_string()2207 String _File::get_pascal_string() {
2208 
2209 	ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use.");
2210 
2211 	return f->get_pascal_string();
2212 };
2213 
store_line(const String & p_string)2214 void _File::store_line(const String &p_string) {
2215 
2216 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2217 	f->store_line(p_string);
2218 }
2219 
store_csv_line(const Vector<String> & p_values,const String & p_delim)2220 void _File::store_csv_line(const Vector<String> &p_values, const String &p_delim) {
2221 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2222 	f->store_csv_line(p_values, p_delim);
2223 }
2224 
store_buffer(const PoolVector<uint8_t> & p_buffer)2225 void _File::store_buffer(const PoolVector<uint8_t> &p_buffer) {
2226 
2227 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2228 
2229 	int len = p_buffer.size();
2230 	if (len == 0)
2231 		return;
2232 
2233 	PoolVector<uint8_t>::Read r = p_buffer.read();
2234 
2235 	f->store_buffer(&r[0], len);
2236 }
2237 
file_exists(const String & p_name) const2238 bool _File::file_exists(const String &p_name) const {
2239 
2240 	return FileAccess::exists(p_name);
2241 }
2242 
store_var(const Variant & p_var,bool p_full_objects)2243 void _File::store_var(const Variant &p_var, bool p_full_objects) {
2244 
2245 	ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
2246 	int len;
2247 	Error err = encode_variant(p_var, NULL, len, p_full_objects);
2248 	ERR_FAIL_COND_MSG(err != OK, "Error when trying to encode Variant.");
2249 
2250 	PoolVector<uint8_t> buff;
2251 	buff.resize(len);
2252 
2253 	PoolVector<uint8_t>::Write w = buff.write();
2254 	err = encode_variant(p_var, &w[0], len, p_full_objects);
2255 	ERR_FAIL_COND_MSG(err != OK, "Error when trying to encode Variant.");
2256 	w.release();
2257 
2258 	store_32(len);
2259 	store_buffer(buff);
2260 }
2261 
get_var(bool p_allow_objects) const2262 Variant _File::get_var(bool p_allow_objects) const {
2263 
2264 	ERR_FAIL_COND_V_MSG(!f, Variant(), "File must be opened before use.");
2265 	uint32_t len = get_32();
2266 	PoolVector<uint8_t> buff = get_buffer(len);
2267 	ERR_FAIL_COND_V((uint32_t)buff.size() != len, Variant());
2268 
2269 	PoolVector<uint8_t>::Read r = buff.read();
2270 
2271 	Variant v;
2272 	Error err = decode_variant(v, &r[0], len, NULL, p_allow_objects);
2273 	ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to encode Variant.");
2274 
2275 	return v;
2276 }
2277 
get_modified_time(const String & p_file) const2278 uint64_t _File::get_modified_time(const String &p_file) const {
2279 
2280 	return FileAccess::get_modified_time(p_file);
2281 }
2282 
_bind_methods()2283 void _File::_bind_methods() {
2284 
2285 	ClassDB::bind_method(D_METHOD("open_encrypted", "path", "mode_flags", "key"), &_File::open_encrypted);
2286 	ClassDB::bind_method(D_METHOD("open_encrypted_with_pass", "path", "mode_flags", "pass"), &_File::open_encrypted_pass);
2287 	ClassDB::bind_method(D_METHOD("open_compressed", "path", "mode_flags", "compression_mode"), &_File::open_compressed, DEFVAL(0));
2288 
2289 	ClassDB::bind_method(D_METHOD("open", "path", "flags"), &_File::open);
2290 	ClassDB::bind_method(D_METHOD("close"), &_File::close);
2291 	ClassDB::bind_method(D_METHOD("get_path"), &_File::get_path);
2292 	ClassDB::bind_method(D_METHOD("get_path_absolute"), &_File::get_path_absolute);
2293 	ClassDB::bind_method(D_METHOD("is_open"), &_File::is_open);
2294 	ClassDB::bind_method(D_METHOD("seek", "position"), &_File::seek);
2295 	ClassDB::bind_method(D_METHOD("seek_end", "position"), &_File::seek_end, DEFVAL(0));
2296 	ClassDB::bind_method(D_METHOD("get_position"), &_File::get_position);
2297 	ClassDB::bind_method(D_METHOD("get_len"), &_File::get_len);
2298 	ClassDB::bind_method(D_METHOD("eof_reached"), &_File::eof_reached);
2299 	ClassDB::bind_method(D_METHOD("get_8"), &_File::get_8);
2300 	ClassDB::bind_method(D_METHOD("get_16"), &_File::get_16);
2301 	ClassDB::bind_method(D_METHOD("get_32"), &_File::get_32);
2302 	ClassDB::bind_method(D_METHOD("get_64"), &_File::get_64);
2303 	ClassDB::bind_method(D_METHOD("get_float"), &_File::get_float);
2304 	ClassDB::bind_method(D_METHOD("get_double"), &_File::get_double);
2305 	ClassDB::bind_method(D_METHOD("get_real"), &_File::get_real);
2306 	ClassDB::bind_method(D_METHOD("get_buffer", "len"), &_File::get_buffer);
2307 	ClassDB::bind_method(D_METHOD("get_line"), &_File::get_line);
2308 	ClassDB::bind_method(D_METHOD("get_csv_line", "delim"), &_File::get_csv_line, DEFVAL(","));
2309 	ClassDB::bind_method(D_METHOD("get_as_text"), &_File::get_as_text);
2310 	ClassDB::bind_method(D_METHOD("get_md5", "path"), &_File::get_md5);
2311 	ClassDB::bind_method(D_METHOD("get_sha256", "path"), &_File::get_sha256);
2312 	ClassDB::bind_method(D_METHOD("get_endian_swap"), &_File::get_endian_swap);
2313 	ClassDB::bind_method(D_METHOD("set_endian_swap", "enable"), &_File::set_endian_swap);
2314 	ClassDB::bind_method(D_METHOD("get_error"), &_File::get_error);
2315 	ClassDB::bind_method(D_METHOD("get_var", "allow_objects"), &_File::get_var, DEFVAL(false));
2316 
2317 	ClassDB::bind_method(D_METHOD("store_8", "value"), &_File::store_8);
2318 	ClassDB::bind_method(D_METHOD("store_16", "value"), &_File::store_16);
2319 	ClassDB::bind_method(D_METHOD("store_32", "value"), &_File::store_32);
2320 	ClassDB::bind_method(D_METHOD("store_64", "value"), &_File::store_64);
2321 	ClassDB::bind_method(D_METHOD("store_float", "value"), &_File::store_float);
2322 	ClassDB::bind_method(D_METHOD("store_double", "value"), &_File::store_double);
2323 	ClassDB::bind_method(D_METHOD("store_real", "value"), &_File::store_real);
2324 	ClassDB::bind_method(D_METHOD("store_buffer", "buffer"), &_File::store_buffer);
2325 	ClassDB::bind_method(D_METHOD("store_line", "line"), &_File::store_line);
2326 	ClassDB::bind_method(D_METHOD("store_csv_line", "values", "delim"), &_File::store_csv_line, DEFVAL(","));
2327 	ClassDB::bind_method(D_METHOD("store_string", "string"), &_File::store_string);
2328 	ClassDB::bind_method(D_METHOD("store_var", "value", "full_objects"), &_File::store_var, DEFVAL(false));
2329 
2330 	ClassDB::bind_method(D_METHOD("store_pascal_string", "string"), &_File::store_pascal_string);
2331 	ClassDB::bind_method(D_METHOD("get_pascal_string"), &_File::get_pascal_string);
2332 
2333 	ClassDB::bind_method(D_METHOD("file_exists", "path"), &_File::file_exists);
2334 	ClassDB::bind_method(D_METHOD("get_modified_time", "file"), &_File::get_modified_time);
2335 
2336 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "endian_swap"), "set_endian_swap", "get_endian_swap");
2337 
2338 	BIND_ENUM_CONSTANT(READ);
2339 	BIND_ENUM_CONSTANT(WRITE);
2340 	BIND_ENUM_CONSTANT(READ_WRITE);
2341 	BIND_ENUM_CONSTANT(WRITE_READ);
2342 
2343 	BIND_ENUM_CONSTANT(COMPRESSION_FASTLZ);
2344 	BIND_ENUM_CONSTANT(COMPRESSION_DEFLATE);
2345 	BIND_ENUM_CONSTANT(COMPRESSION_ZSTD);
2346 	BIND_ENUM_CONSTANT(COMPRESSION_GZIP);
2347 }
2348 
_File()2349 _File::_File() {
2350 
2351 	f = NULL;
2352 	eswap = false;
2353 }
2354 
~_File()2355 _File::~_File() {
2356 
2357 	if (f)
2358 		memdelete(f);
2359 }
2360 
2361 ///////////////////////////////////////////////////////
2362 
open(const String & p_path)2363 Error _Directory::open(const String &p_path) {
2364 	Error err;
2365 	DirAccess *alt = DirAccess::open(p_path, &err);
2366 
2367 	if (!alt)
2368 		return err;
2369 	if (d)
2370 		memdelete(d);
2371 	d = alt;
2372 
2373 	return OK;
2374 }
2375 
list_dir_begin(bool p_skip_navigational,bool p_skip_hidden)2376 Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) {
2377 
2378 	ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
2379 
2380 	_list_skip_navigational = p_skip_navigational;
2381 	_list_skip_hidden = p_skip_hidden;
2382 
2383 	return d->list_dir_begin();
2384 }
2385 
get_next()2386 String _Directory::get_next() {
2387 
2388 	ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
2389 
2390 	String next = d->get_next();
2391 	while (next != "" && ((_list_skip_navigational && (next == "." || next == "..")) || (_list_skip_hidden && d->current_is_hidden()))) {
2392 
2393 		next = d->get_next();
2394 	}
2395 	return next;
2396 }
current_is_dir() const2397 bool _Directory::current_is_dir() const {
2398 
2399 	ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
2400 	return d->current_is_dir();
2401 }
2402 
list_dir_end()2403 void _Directory::list_dir_end() {
2404 
2405 	ERR_FAIL_COND_MSG(!d, "Directory must be opened before use.");
2406 	d->list_dir_end();
2407 }
2408 
get_drive_count()2409 int _Directory::get_drive_count() {
2410 
2411 	ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
2412 	return d->get_drive_count();
2413 }
get_drive(int p_drive)2414 String _Directory::get_drive(int p_drive) {
2415 
2416 	ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
2417 	return d->get_drive(p_drive);
2418 }
get_current_drive()2419 int _Directory::get_current_drive() {
2420 	ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
2421 	return d->get_current_drive();
2422 }
2423 
change_dir(String p_dir)2424 Error _Directory::change_dir(String p_dir) {
2425 
2426 	ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
2427 	return d->change_dir(p_dir);
2428 }
get_current_dir()2429 String _Directory::get_current_dir() {
2430 
2431 	ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
2432 	return d->get_current_dir();
2433 }
make_dir(String p_dir)2434 Error _Directory::make_dir(String p_dir) {
2435 
2436 	ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
2437 	if (!p_dir.is_rel_path()) {
2438 		DirAccess *d = DirAccess::create_for_path(p_dir);
2439 		Error err = d->make_dir(p_dir);
2440 		memdelete(d);
2441 		return err;
2442 	}
2443 	return d->make_dir(p_dir);
2444 }
make_dir_recursive(String p_dir)2445 Error _Directory::make_dir_recursive(String p_dir) {
2446 
2447 	ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
2448 	if (!p_dir.is_rel_path()) {
2449 		DirAccess *d = DirAccess::create_for_path(p_dir);
2450 		Error err = d->make_dir_recursive(p_dir);
2451 		memdelete(d);
2452 		return err;
2453 	}
2454 	return d->make_dir_recursive(p_dir);
2455 }
2456 
file_exists(String p_file)2457 bool _Directory::file_exists(String p_file) {
2458 
2459 	ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
2460 
2461 	if (!p_file.is_rel_path()) {
2462 		return FileAccess::exists(p_file);
2463 	}
2464 
2465 	return d->file_exists(p_file);
2466 }
2467 
dir_exists(String p_dir)2468 bool _Directory::dir_exists(String p_dir) {
2469 	ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
2470 	if (!p_dir.is_rel_path()) {
2471 
2472 		DirAccess *d = DirAccess::create_for_path(p_dir);
2473 		bool exists = d->dir_exists(p_dir);
2474 		memdelete(d);
2475 		return exists;
2476 
2477 	} else {
2478 		return d->dir_exists(p_dir);
2479 	}
2480 }
2481 
get_space_left()2482 int _Directory::get_space_left() {
2483 
2484 	ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
2485 	return d->get_space_left() / 1024 * 1024; //return value in megabytes, given binding is int
2486 }
2487 
copy(String p_from,String p_to)2488 Error _Directory::copy(String p_from, String p_to) {
2489 
2490 	ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
2491 	return d->copy(p_from, p_to);
2492 }
rename(String p_from,String p_to)2493 Error _Directory::rename(String p_from, String p_to) {
2494 
2495 	ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
2496 	if (!p_from.is_rel_path()) {
2497 		DirAccess *d = DirAccess::create_for_path(p_from);
2498 		Error err = d->rename(p_from, p_to);
2499 		memdelete(d);
2500 		return err;
2501 	}
2502 
2503 	return d->rename(p_from, p_to);
2504 }
remove(String p_name)2505 Error _Directory::remove(String p_name) {
2506 
2507 	ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
2508 	if (!p_name.is_rel_path()) {
2509 		DirAccess *d = DirAccess::create_for_path(p_name);
2510 		Error err = d->remove(p_name);
2511 		memdelete(d);
2512 		return err;
2513 	}
2514 
2515 	return d->remove(p_name);
2516 }
2517 
_bind_methods()2518 void _Directory::_bind_methods() {
2519 
2520 	ClassDB::bind_method(D_METHOD("open", "path"), &_Directory::open);
2521 	ClassDB::bind_method(D_METHOD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false));
2522 	ClassDB::bind_method(D_METHOD("get_next"), &_Directory::get_next);
2523 	ClassDB::bind_method(D_METHOD("current_is_dir"), &_Directory::current_is_dir);
2524 	ClassDB::bind_method(D_METHOD("list_dir_end"), &_Directory::list_dir_end);
2525 	ClassDB::bind_method(D_METHOD("get_drive_count"), &_Directory::get_drive_count);
2526 	ClassDB::bind_method(D_METHOD("get_drive", "idx"), &_Directory::get_drive);
2527 	ClassDB::bind_method(D_METHOD("get_current_drive"), &_Directory::get_current_drive);
2528 	ClassDB::bind_method(D_METHOD("change_dir", "todir"), &_Directory::change_dir);
2529 	ClassDB::bind_method(D_METHOD("get_current_dir"), &_Directory::get_current_dir);
2530 	ClassDB::bind_method(D_METHOD("make_dir", "path"), &_Directory::make_dir);
2531 	ClassDB::bind_method(D_METHOD("make_dir_recursive", "path"), &_Directory::make_dir_recursive);
2532 	ClassDB::bind_method(D_METHOD("file_exists", "path"), &_Directory::file_exists);
2533 	ClassDB::bind_method(D_METHOD("dir_exists", "path"), &_Directory::dir_exists);
2534 	//ClassDB::bind_method(D_METHOD("get_modified_time","file"),&_Directory::get_modified_time);
2535 	ClassDB::bind_method(D_METHOD("get_space_left"), &_Directory::get_space_left);
2536 	ClassDB::bind_method(D_METHOD("copy", "from", "to"), &_Directory::copy);
2537 	ClassDB::bind_method(D_METHOD("rename", "from", "to"), &_Directory::rename);
2538 	ClassDB::bind_method(D_METHOD("remove", "path"), &_Directory::remove);
2539 }
2540 
_Directory()2541 _Directory::_Directory() {
2542 
2543 	d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
2544 }
2545 
~_Directory()2546 _Directory::~_Directory() {
2547 
2548 	if (d)
2549 		memdelete(d);
2550 }
2551 
2552 _Marshalls *_Marshalls::singleton = NULL;
2553 
get_singleton()2554 _Marshalls *_Marshalls::get_singleton() {
2555 	return singleton;
2556 }
2557 
variant_to_base64(const Variant & p_var,bool p_full_objects)2558 String _Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) {
2559 
2560 	int len;
2561 	Error err = encode_variant(p_var, NULL, len, p_full_objects);
2562 	ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
2563 
2564 	PoolVector<uint8_t> buff;
2565 	buff.resize(len);
2566 	PoolVector<uint8_t>::Write w = buff.write();
2567 
2568 	err = encode_variant(p_var, &w[0], len, p_full_objects);
2569 	ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
2570 
2571 	String ret = CryptoCore::b64_encode_str(&w[0], len);
2572 	ERR_FAIL_COND_V(ret == "", ret);
2573 
2574 	return ret;
2575 };
2576 
base64_to_variant(const String & p_str,bool p_allow_objects)2577 Variant _Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) {
2578 
2579 	int strlen = p_str.length();
2580 	CharString cstr = p_str.ascii();
2581 
2582 	PoolVector<uint8_t> buf;
2583 	buf.resize(strlen / 4 * 3 + 1);
2584 	PoolVector<uint8_t>::Write w = buf.write();
2585 
2586 	size_t len = 0;
2587 	ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, Variant());
2588 
2589 	Variant v;
2590 	Error err = decode_variant(v, &w[0], len, NULL, p_allow_objects);
2591 	ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant.");
2592 
2593 	return v;
2594 };
2595 
raw_to_base64(const PoolVector<uint8_t> & p_arr)2596 String _Marshalls::raw_to_base64(const PoolVector<uint8_t> &p_arr) {
2597 
2598 	String ret = CryptoCore::b64_encode_str(p_arr.read().ptr(), p_arr.size());
2599 	ERR_FAIL_COND_V(ret == "", ret);
2600 	return ret;
2601 };
2602 
base64_to_raw(const String & p_str)2603 PoolVector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) {
2604 
2605 	int strlen = p_str.length();
2606 	CharString cstr = p_str.ascii();
2607 
2608 	size_t arr_len = 0;
2609 	PoolVector<uint8_t> buf;
2610 	{
2611 		buf.resize(strlen / 4 * 3 + 1);
2612 		PoolVector<uint8_t>::Write w = buf.write();
2613 
2614 		ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &arr_len, (unsigned char *)cstr.get_data(), strlen) != OK, PoolVector<uint8_t>());
2615 	}
2616 	buf.resize(arr_len);
2617 
2618 	return buf;
2619 };
2620 
utf8_to_base64(const String & p_str)2621 String _Marshalls::utf8_to_base64(const String &p_str) {
2622 
2623 	CharString cstr = p_str.utf8();
2624 	String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length());
2625 	ERR_FAIL_COND_V(ret == "", ret);
2626 	return ret;
2627 };
2628 
base64_to_utf8(const String & p_str)2629 String _Marshalls::base64_to_utf8(const String &p_str) {
2630 
2631 	int strlen = p_str.length();
2632 	CharString cstr = p_str.ascii();
2633 
2634 	PoolVector<uint8_t> buf;
2635 	buf.resize(strlen / 4 * 3 + 1 + 1);
2636 	PoolVector<uint8_t>::Write w = buf.write();
2637 
2638 	size_t len = 0;
2639 	ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, String());
2640 
2641 	w[len] = 0;
2642 	String ret = String::utf8((char *)&w[0]);
2643 
2644 	return ret;
2645 };
2646 
_bind_methods()2647 void _Marshalls::_bind_methods() {
2648 
2649 	ClassDB::bind_method(D_METHOD("variant_to_base64", "variant", "full_objects"), &_Marshalls::variant_to_base64, DEFVAL(false));
2650 	ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str", "allow_objects"), &_Marshalls::base64_to_variant, DEFVAL(false));
2651 
2652 	ClassDB::bind_method(D_METHOD("raw_to_base64", "array"), &_Marshalls::raw_to_base64);
2653 	ClassDB::bind_method(D_METHOD("base64_to_raw", "base64_str"), &_Marshalls::base64_to_raw);
2654 
2655 	ClassDB::bind_method(D_METHOD("utf8_to_base64", "utf8_str"), &_Marshalls::utf8_to_base64);
2656 	ClassDB::bind_method(D_METHOD("base64_to_utf8", "base64_str"), &_Marshalls::base64_to_utf8);
2657 };
2658 
2659 ////////////////
2660 
wait()2661 Error _Semaphore::wait() {
2662 
2663 	return semaphore->wait();
2664 }
2665 
post()2666 Error _Semaphore::post() {
2667 
2668 	return semaphore->post();
2669 }
2670 
_bind_methods()2671 void _Semaphore::_bind_methods() {
2672 
2673 	ClassDB::bind_method(D_METHOD("wait"), &_Semaphore::wait);
2674 	ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post);
2675 }
2676 
_Semaphore()2677 _Semaphore::_Semaphore() {
2678 
2679 	semaphore = Semaphore::create();
2680 }
2681 
~_Semaphore()2682 _Semaphore::~_Semaphore() {
2683 
2684 	memdelete(semaphore);
2685 }
2686 
2687 ///////////////
2688 
lock()2689 void _Mutex::lock() {
2690 
2691 	mutex->lock();
2692 }
2693 
try_lock()2694 Error _Mutex::try_lock() {
2695 
2696 	return mutex->try_lock();
2697 }
2698 
unlock()2699 void _Mutex::unlock() {
2700 
2701 	mutex->unlock();
2702 }
2703 
_bind_methods()2704 void _Mutex::_bind_methods() {
2705 
2706 	ClassDB::bind_method(D_METHOD("lock"), &_Mutex::lock);
2707 	ClassDB::bind_method(D_METHOD("try_lock"), &_Mutex::try_lock);
2708 	ClassDB::bind_method(D_METHOD("unlock"), &_Mutex::unlock);
2709 }
2710 
_Mutex()2711 _Mutex::_Mutex() {
2712 
2713 	mutex = Mutex::create();
2714 }
2715 
~_Mutex()2716 _Mutex::~_Mutex() {
2717 
2718 	memdelete(mutex);
2719 }
2720 
2721 ///////////////
2722 
_start_func(void * ud)2723 void _Thread::_start_func(void *ud) {
2724 
2725 	Ref<_Thread> *tud = (Ref<_Thread> *)ud;
2726 	Ref<_Thread> t = *tud;
2727 	memdelete(tud);
2728 	Variant::CallError ce;
2729 	const Variant *arg[1] = { &t->userdata };
2730 
2731 	Thread::set_name(t->target_method);
2732 
2733 	t->ret = t->target_instance->call(t->target_method, arg, 1, ce);
2734 	if (ce.error != Variant::CallError::CALL_OK) {
2735 
2736 		String reason;
2737 		switch (ce.error) {
2738 			case Variant::CallError::CALL_ERROR_INVALID_ARGUMENT: {
2739 
2740 				reason = "Invalid Argument #" + itos(ce.argument);
2741 			} break;
2742 			case Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: {
2743 
2744 				reason = "Too Many Arguments";
2745 			} break;
2746 			case Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: {
2747 
2748 				reason = "Too Few Arguments";
2749 			} break;
2750 			case Variant::CallError::CALL_ERROR_INVALID_METHOD: {
2751 
2752 				reason = "Method Not Found";
2753 			} break;
2754 			default: {
2755 			}
2756 		}
2757 
2758 		ERR_FAIL_MSG("Could not call function '" + t->target_method.operator String() + "' to start thread " + t->get_id() + ": " + reason + ".");
2759 	}
2760 }
2761 
start(Object * p_instance,const StringName & p_method,const Variant & p_userdata,Priority p_priority)2762 Error _Thread::start(Object *p_instance, const StringName &p_method, const Variant &p_userdata, Priority p_priority) {
2763 
2764 	ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "Thread already started.");
2765 	ERR_FAIL_COND_V(!p_instance, ERR_INVALID_PARAMETER);
2766 	ERR_FAIL_COND_V(p_method == StringName(), ERR_INVALID_PARAMETER);
2767 	ERR_FAIL_INDEX_V(p_priority, PRIORITY_MAX, ERR_INVALID_PARAMETER);
2768 
2769 	ret = Variant();
2770 	target_method = p_method;
2771 	target_instance = p_instance;
2772 	userdata = p_userdata;
2773 	active = true;
2774 
2775 	Ref<_Thread> *ud = memnew(Ref<_Thread>(this));
2776 
2777 	Thread::Settings s;
2778 	s.priority = (Thread::Priority)p_priority;
2779 	thread = Thread::create(_start_func, ud, s);
2780 	if (!thread) {
2781 		active = false;
2782 		target_method = StringName();
2783 		target_instance = NULL;
2784 		userdata = Variant();
2785 		return ERR_CANT_CREATE;
2786 	}
2787 
2788 	return OK;
2789 }
2790 
get_id() const2791 String _Thread::get_id() const {
2792 
2793 	if (!thread)
2794 		return String();
2795 
2796 	return itos(thread->get_id());
2797 }
2798 
is_active() const2799 bool _Thread::is_active() const {
2800 
2801 	return active;
2802 }
wait_to_finish()2803 Variant _Thread::wait_to_finish() {
2804 
2805 	ERR_FAIL_COND_V_MSG(!thread, Variant(), "Thread must exist to wait for its completion.");
2806 	ERR_FAIL_COND_V_MSG(!active, Variant(), "Thread must be active to wait for its completion.");
2807 	Thread::wait_to_finish(thread);
2808 	Variant r = ret;
2809 	active = false;
2810 	target_method = StringName();
2811 	target_instance = NULL;
2812 	userdata = Variant();
2813 	if (thread)
2814 		memdelete(thread);
2815 	thread = NULL;
2816 
2817 	return r;
2818 }
2819 
_bind_methods()2820 void _Thread::_bind_methods() {
2821 
2822 	ClassDB::bind_method(D_METHOD("start", "instance", "method", "userdata", "priority"), &_Thread::start, DEFVAL(Variant()), DEFVAL(PRIORITY_NORMAL));
2823 	ClassDB::bind_method(D_METHOD("get_id"), &_Thread::get_id);
2824 	ClassDB::bind_method(D_METHOD("is_active"), &_Thread::is_active);
2825 	ClassDB::bind_method(D_METHOD("wait_to_finish"), &_Thread::wait_to_finish);
2826 
2827 	BIND_ENUM_CONSTANT(PRIORITY_LOW);
2828 	BIND_ENUM_CONSTANT(PRIORITY_NORMAL);
2829 	BIND_ENUM_CONSTANT(PRIORITY_HIGH);
2830 }
_Thread()2831 _Thread::_Thread() {
2832 
2833 	active = false;
2834 	thread = NULL;
2835 	target_instance = NULL;
2836 }
2837 
~_Thread()2838 _Thread::~_Thread() {
2839 
2840 	ERR_FAIL_COND_MSG(active, "Reference to a Thread object was lost while the thread is still running...");
2841 }
2842 
2843 /////////////////////////////////////
2844 
get_class_list() const2845 PoolStringArray _ClassDB::get_class_list() const {
2846 
2847 	List<StringName> classes;
2848 	ClassDB::get_class_list(&classes);
2849 
2850 	PoolStringArray ret;
2851 	ret.resize(classes.size());
2852 	int idx = 0;
2853 	for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
2854 		ret.set(idx++, E->get());
2855 	}
2856 
2857 	return ret;
2858 }
get_inheriters_from_class(const StringName & p_class) const2859 PoolStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class) const {
2860 
2861 	List<StringName> classes;
2862 	ClassDB::get_inheriters_from_class(p_class, &classes);
2863 
2864 	PoolStringArray ret;
2865 	ret.resize(classes.size());
2866 	int idx = 0;
2867 	for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
2868 		ret.set(idx++, E->get());
2869 	}
2870 
2871 	return ret;
2872 }
get_parent_class(const StringName & p_class) const2873 StringName _ClassDB::get_parent_class(const StringName &p_class) const {
2874 
2875 	return ClassDB::get_parent_class(p_class);
2876 }
class_exists(const StringName & p_class) const2877 bool _ClassDB::class_exists(const StringName &p_class) const {
2878 
2879 	return ClassDB::class_exists(p_class);
2880 }
is_parent_class(const StringName & p_class,const StringName & p_inherits) const2881 bool _ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const {
2882 
2883 	return ClassDB::is_parent_class(p_class, p_inherits);
2884 }
can_instance(const StringName & p_class) const2885 bool _ClassDB::can_instance(const StringName &p_class) const {
2886 
2887 	return ClassDB::can_instance(p_class);
2888 }
instance(const StringName & p_class) const2889 Variant _ClassDB::instance(const StringName &p_class) const {
2890 
2891 	Object *obj = ClassDB::instance(p_class);
2892 	if (!obj)
2893 		return Variant();
2894 
2895 	Reference *r = Object::cast_to<Reference>(obj);
2896 	if (r) {
2897 		return REF(r);
2898 	} else {
2899 		return obj;
2900 	}
2901 }
2902 
has_signal(StringName p_class,StringName p_signal) const2903 bool _ClassDB::has_signal(StringName p_class, StringName p_signal) const {
2904 
2905 	return ClassDB::has_signal(p_class, p_signal);
2906 }
get_signal(StringName p_class,StringName p_signal) const2907 Dictionary _ClassDB::get_signal(StringName p_class, StringName p_signal) const {
2908 
2909 	MethodInfo signal;
2910 	if (ClassDB::get_signal(p_class, p_signal, &signal)) {
2911 		return signal.operator Dictionary();
2912 	} else {
2913 		return Dictionary();
2914 	}
2915 }
get_signal_list(StringName p_class,bool p_no_inheritance) const2916 Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const {
2917 
2918 	List<MethodInfo> signals;
2919 	ClassDB::get_signal_list(p_class, &signals, p_no_inheritance);
2920 	Array ret;
2921 
2922 	for (List<MethodInfo>::Element *E = signals.front(); E; E = E->next()) {
2923 		ret.push_back(E->get().operator Dictionary());
2924 	}
2925 
2926 	return ret;
2927 }
2928 
get_property_list(StringName p_class,bool p_no_inheritance) const2929 Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) const {
2930 
2931 	List<PropertyInfo> plist;
2932 	ClassDB::get_property_list(p_class, &plist, p_no_inheritance);
2933 	Array ret;
2934 	for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
2935 		ret.push_back(E->get().operator Dictionary());
2936 	}
2937 
2938 	return ret;
2939 }
2940 
get_property(Object * p_object,const StringName & p_property) const2941 Variant _ClassDB::get_property(Object *p_object, const StringName &p_property) const {
2942 	Variant ret;
2943 	ClassDB::get_property(p_object, p_property, ret);
2944 	return ret;
2945 }
2946 
set_property(Object * p_object,const StringName & p_property,const Variant & p_value) const2947 Error _ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const {
2948 	Variant ret;
2949 	bool valid;
2950 	if (!ClassDB::set_property(p_object, p_property, p_value, &valid)) {
2951 		return ERR_UNAVAILABLE;
2952 	} else if (!valid) {
2953 		return ERR_INVALID_DATA;
2954 	}
2955 	return OK;
2956 }
2957 
has_method(StringName p_class,StringName p_method,bool p_no_inheritance) const2958 bool _ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) const {
2959 
2960 	return ClassDB::has_method(p_class, p_method, p_no_inheritance);
2961 }
2962 
get_method_list(StringName p_class,bool p_no_inheritance) const2963 Array _ClassDB::get_method_list(StringName p_class, bool p_no_inheritance) const {
2964 
2965 	List<MethodInfo> methods;
2966 	ClassDB::get_method_list(p_class, &methods, p_no_inheritance);
2967 	Array ret;
2968 
2969 	for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
2970 #ifdef DEBUG_METHODS_ENABLED
2971 		ret.push_back(E->get().operator Dictionary());
2972 #else
2973 		Dictionary dict;
2974 		dict["name"] = E->get().name;
2975 		ret.push_back(dict);
2976 #endif
2977 	}
2978 
2979 	return ret;
2980 }
2981 
get_integer_constant_list(const StringName & p_class,bool p_no_inheritance) const2982 PoolStringArray _ClassDB::get_integer_constant_list(const StringName &p_class, bool p_no_inheritance) const {
2983 
2984 	List<String> constants;
2985 	ClassDB::get_integer_constant_list(p_class, &constants, p_no_inheritance);
2986 
2987 	PoolStringArray ret;
2988 	ret.resize(constants.size());
2989 	int idx = 0;
2990 	for (List<String>::Element *E = constants.front(); E; E = E->next()) {
2991 		ret.set(idx++, E->get());
2992 	}
2993 
2994 	return ret;
2995 }
2996 
has_integer_constant(const StringName & p_class,const StringName & p_name) const2997 bool _ClassDB::has_integer_constant(const StringName &p_class, const StringName &p_name) const {
2998 
2999 	bool success;
3000 	ClassDB::get_integer_constant(p_class, p_name, &success);
3001 	return success;
3002 }
3003 
get_integer_constant(const StringName & p_class,const StringName & p_name) const3004 int _ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name) const {
3005 
3006 	bool found;
3007 	int c = ClassDB::get_integer_constant(p_class, p_name, &found);
3008 	ERR_FAIL_COND_V(!found, 0);
3009 	return c;
3010 }
get_category(const StringName & p_node) const3011 StringName _ClassDB::get_category(const StringName &p_node) const {
3012 
3013 	return ClassDB::get_category(p_node);
3014 }
3015 
is_class_enabled(StringName p_class) const3016 bool _ClassDB::is_class_enabled(StringName p_class) const {
3017 
3018 	return ClassDB::is_class_enabled(p_class);
3019 }
3020 
_bind_methods()3021 void _ClassDB::_bind_methods() {
3022 
3023 	ClassDB::bind_method(D_METHOD("get_class_list"), &_ClassDB::get_class_list);
3024 	ClassDB::bind_method(D_METHOD("get_inheriters_from_class", "class"), &_ClassDB::get_inheriters_from_class);
3025 	ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &_ClassDB::get_parent_class);
3026 	ClassDB::bind_method(D_METHOD("class_exists", "class"), &_ClassDB::class_exists);
3027 	ClassDB::bind_method(D_METHOD("is_parent_class", "class", "inherits"), &_ClassDB::is_parent_class);
3028 	ClassDB::bind_method(D_METHOD("can_instance", "class"), &_ClassDB::can_instance);
3029 	ClassDB::bind_method(D_METHOD("instance", "class"), &_ClassDB::instance);
3030 
3031 	ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &_ClassDB::has_signal);
3032 	ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &_ClassDB::get_signal);
3033 	ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &_ClassDB::get_signal_list, DEFVAL(false));
3034 
3035 	ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &_ClassDB::get_property_list, DEFVAL(false));
3036 	ClassDB::bind_method(D_METHOD("class_get_property", "object", "property"), &_ClassDB::get_property);
3037 	ClassDB::bind_method(D_METHOD("class_set_property", "object", "property", "value"), &_ClassDB::set_property);
3038 
3039 	ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &_ClassDB::has_method, DEFVAL(false));
3040 
3041 	ClassDB::bind_method(D_METHOD("class_get_method_list", "class", "no_inheritance"), &_ClassDB::get_method_list, DEFVAL(false));
3042 
3043 	ClassDB::bind_method(D_METHOD("class_get_integer_constant_list", "class", "no_inheritance"), &_ClassDB::get_integer_constant_list, DEFVAL(false));
3044 
3045 	ClassDB::bind_method(D_METHOD("class_has_integer_constant", "class", "name"), &_ClassDB::has_integer_constant);
3046 	ClassDB::bind_method(D_METHOD("class_get_integer_constant", "class", "name"), &_ClassDB::get_integer_constant);
3047 
3048 	ClassDB::bind_method(D_METHOD("class_get_category", "class"), &_ClassDB::get_category);
3049 	ClassDB::bind_method(D_METHOD("is_class_enabled", "class"), &_ClassDB::is_class_enabled);
3050 }
3051 
_ClassDB()3052 _ClassDB::_ClassDB() {
3053 }
~_ClassDB()3054 _ClassDB::~_ClassDB() {
3055 }
3056 ///////////////////////////////
3057 
set_iterations_per_second(int p_ips)3058 void _Engine::set_iterations_per_second(int p_ips) {
3059 
3060 	Engine::get_singleton()->set_iterations_per_second(p_ips);
3061 }
get_iterations_per_second() const3062 int _Engine::get_iterations_per_second() const {
3063 
3064 	return Engine::get_singleton()->get_iterations_per_second();
3065 }
3066 
set_physics_jitter_fix(float p_threshold)3067 void _Engine::set_physics_jitter_fix(float p_threshold) {
3068 	Engine::get_singleton()->set_physics_jitter_fix(p_threshold);
3069 }
3070 
get_physics_jitter_fix() const3071 float _Engine::get_physics_jitter_fix() const {
3072 	return Engine::get_singleton()->get_physics_jitter_fix();
3073 }
3074 
get_physics_interpolation_fraction() const3075 float _Engine::get_physics_interpolation_fraction() const {
3076 	return Engine::get_singleton()->get_physics_interpolation_fraction();
3077 }
3078 
set_target_fps(int p_fps)3079 void _Engine::set_target_fps(int p_fps) {
3080 	Engine::get_singleton()->set_target_fps(p_fps);
3081 }
3082 
get_target_fps() const3083 int _Engine::get_target_fps() const {
3084 	return Engine::get_singleton()->get_target_fps();
3085 }
3086 
get_frames_per_second() const3087 float _Engine::get_frames_per_second() const {
3088 
3089 	return Engine::get_singleton()->get_frames_per_second();
3090 }
3091 
get_physics_frames() const3092 uint64_t _Engine::get_physics_frames() const {
3093 
3094 	return Engine::get_singleton()->get_physics_frames();
3095 }
3096 
get_idle_frames() const3097 uint64_t _Engine::get_idle_frames() const {
3098 
3099 	return Engine::get_singleton()->get_idle_frames();
3100 }
3101 
set_time_scale(float p_scale)3102 void _Engine::set_time_scale(float p_scale) {
3103 	Engine::get_singleton()->set_time_scale(p_scale);
3104 }
3105 
get_time_scale()3106 float _Engine::get_time_scale() {
3107 
3108 	return Engine::get_singleton()->get_time_scale();
3109 }
3110 
get_frames_drawn()3111 int _Engine::get_frames_drawn() {
3112 
3113 	return Engine::get_singleton()->get_frames_drawn();
3114 }
3115 
get_main_loop() const3116 MainLoop *_Engine::get_main_loop() const {
3117 
3118 	//needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
3119 	return OS::get_singleton()->get_main_loop();
3120 }
3121 
get_version_info() const3122 Dictionary _Engine::get_version_info() const {
3123 
3124 	return Engine::get_singleton()->get_version_info();
3125 }
3126 
get_author_info() const3127 Dictionary _Engine::get_author_info() const {
3128 	return Engine::get_singleton()->get_author_info();
3129 }
3130 
get_copyright_info() const3131 Array _Engine::get_copyright_info() const {
3132 	return Engine::get_singleton()->get_copyright_info();
3133 }
3134 
get_donor_info() const3135 Dictionary _Engine::get_donor_info() const {
3136 	return Engine::get_singleton()->get_donor_info();
3137 }
3138 
get_license_info() const3139 Dictionary _Engine::get_license_info() const {
3140 	return Engine::get_singleton()->get_license_info();
3141 }
3142 
get_license_text() const3143 String _Engine::get_license_text() const {
3144 	return Engine::get_singleton()->get_license_text();
3145 }
3146 
is_in_physics_frame() const3147 bool _Engine::is_in_physics_frame() const {
3148 	return Engine::get_singleton()->is_in_physics_frame();
3149 }
3150 
has_singleton(const String & p_name) const3151 bool _Engine::has_singleton(const String &p_name) const {
3152 
3153 	return Engine::get_singleton()->has_singleton(p_name);
3154 }
3155 
get_singleton_object(const String & p_name) const3156 Object *_Engine::get_singleton_object(const String &p_name) const {
3157 
3158 	return Engine::get_singleton()->get_singleton_object(p_name);
3159 }
3160 
set_editor_hint(bool p_enabled)3161 void _Engine::set_editor_hint(bool p_enabled) {
3162 
3163 	Engine::get_singleton()->set_editor_hint(p_enabled);
3164 }
3165 
is_editor_hint() const3166 bool _Engine::is_editor_hint() const {
3167 
3168 	return Engine::get_singleton()->is_editor_hint();
3169 }
3170 
_bind_methods()3171 void _Engine::_bind_methods() {
3172 
3173 	ClassDB::bind_method(D_METHOD("set_iterations_per_second", "iterations_per_second"), &_Engine::set_iterations_per_second);
3174 	ClassDB::bind_method(D_METHOD("get_iterations_per_second"), &_Engine::get_iterations_per_second);
3175 	ClassDB::bind_method(D_METHOD("set_physics_jitter_fix", "physics_jitter_fix"), &_Engine::set_physics_jitter_fix);
3176 	ClassDB::bind_method(D_METHOD("get_physics_jitter_fix"), &_Engine::get_physics_jitter_fix);
3177 	ClassDB::bind_method(D_METHOD("get_physics_interpolation_fraction"), &_Engine::get_physics_interpolation_fraction);
3178 	ClassDB::bind_method(D_METHOD("set_target_fps", "target_fps"), &_Engine::set_target_fps);
3179 	ClassDB::bind_method(D_METHOD("get_target_fps"), &_Engine::get_target_fps);
3180 
3181 	ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &_Engine::set_time_scale);
3182 	ClassDB::bind_method(D_METHOD("get_time_scale"), &_Engine::get_time_scale);
3183 
3184 	ClassDB::bind_method(D_METHOD("get_frames_drawn"), &_Engine::get_frames_drawn);
3185 	ClassDB::bind_method(D_METHOD("get_frames_per_second"), &_Engine::get_frames_per_second);
3186 	ClassDB::bind_method(D_METHOD("get_physics_frames"), &_Engine::get_physics_frames);
3187 	ClassDB::bind_method(D_METHOD("get_idle_frames"), &_Engine::get_idle_frames);
3188 
3189 	ClassDB::bind_method(D_METHOD("get_main_loop"), &_Engine::get_main_loop);
3190 
3191 	ClassDB::bind_method(D_METHOD("get_version_info"), &_Engine::get_version_info);
3192 	ClassDB::bind_method(D_METHOD("get_author_info"), &_Engine::get_author_info);
3193 	ClassDB::bind_method(D_METHOD("get_copyright_info"), &_Engine::get_copyright_info);
3194 	ClassDB::bind_method(D_METHOD("get_donor_info"), &_Engine::get_donor_info);
3195 	ClassDB::bind_method(D_METHOD("get_license_info"), &_Engine::get_license_info);
3196 	ClassDB::bind_method(D_METHOD("get_license_text"), &_Engine::get_license_text);
3197 
3198 	ClassDB::bind_method(D_METHOD("is_in_physics_frame"), &_Engine::is_in_physics_frame);
3199 
3200 	ClassDB::bind_method(D_METHOD("has_singleton", "name"), &_Engine::has_singleton);
3201 	ClassDB::bind_method(D_METHOD("get_singleton", "name"), &_Engine::get_singleton_object);
3202 
3203 	ClassDB::bind_method(D_METHOD("set_editor_hint", "enabled"), &_Engine::set_editor_hint);
3204 	ClassDB::bind_method(D_METHOD("is_editor_hint"), &_Engine::is_editor_hint);
3205 
3206 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_hint"), "set_editor_hint", "is_editor_hint");
3207 	ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations_per_second"), "set_iterations_per_second", "get_iterations_per_second");
3208 	ADD_PROPERTY(PropertyInfo(Variant::INT, "target_fps"), "set_target_fps", "get_target_fps");
3209 	ADD_PROPERTY(PropertyInfo(Variant::REAL, "time_scale"), "set_time_scale", "get_time_scale");
3210 	ADD_PROPERTY(PropertyInfo(Variant::REAL, "physics_jitter_fix"), "set_physics_jitter_fix", "get_physics_jitter_fix");
3211 }
3212 
3213 _Engine *_Engine::singleton = NULL;
3214 
_Engine()3215 _Engine::_Engine() {
3216 	singleton = this;
3217 }
3218 
_bind_methods()3219 void JSONParseResult::_bind_methods() {
3220 	ClassDB::bind_method(D_METHOD("get_error"), &JSONParseResult::get_error);
3221 	ClassDB::bind_method(D_METHOD("get_error_string"), &JSONParseResult::get_error_string);
3222 	ClassDB::bind_method(D_METHOD("get_error_line"), &JSONParseResult::get_error_line);
3223 	ClassDB::bind_method(D_METHOD("get_result"), &JSONParseResult::get_result);
3224 
3225 	ClassDB::bind_method(D_METHOD("set_error", "error"), &JSONParseResult::set_error);
3226 	ClassDB::bind_method(D_METHOD("set_error_string", "error_string"), &JSONParseResult::set_error_string);
3227 	ClassDB::bind_method(D_METHOD("set_error_line", "error_line"), &JSONParseResult::set_error_line);
3228 	ClassDB::bind_method(D_METHOD("set_result", "result"), &JSONParseResult::set_result);
3229 
3230 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "error", PROPERTY_HINT_NONE, "Error", PROPERTY_USAGE_CLASS_IS_ENUM), "set_error", "get_error");
3231 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "error_string"), "set_error_string", "get_error_string");
3232 	ADD_PROPERTY(PropertyInfo(Variant::INT, "error_line"), "set_error_line", "get_error_line");
3233 	ADD_PROPERTY(PropertyInfo(Variant::NIL, "result", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_result", "get_result");
3234 }
3235 
set_error(Error p_error)3236 void JSONParseResult::set_error(Error p_error) {
3237 	error = p_error;
3238 }
3239 
get_error() const3240 Error JSONParseResult::get_error() const {
3241 	return error;
3242 }
3243 
set_error_string(const String & p_error_string)3244 void JSONParseResult::set_error_string(const String &p_error_string) {
3245 	error_string = p_error_string;
3246 }
3247 
get_error_string() const3248 String JSONParseResult::get_error_string() const {
3249 	return error_string;
3250 }
3251 
set_error_line(int p_error_line)3252 void JSONParseResult::set_error_line(int p_error_line) {
3253 	error_line = p_error_line;
3254 }
3255 
get_error_line() const3256 int JSONParseResult::get_error_line() const {
3257 	return error_line;
3258 }
3259 
set_result(const Variant & p_result)3260 void JSONParseResult::set_result(const Variant &p_result) {
3261 	result = p_result;
3262 }
3263 
get_result() const3264 Variant JSONParseResult::get_result() const {
3265 	return result;
3266 }
3267 
_bind_methods()3268 void _JSON::_bind_methods() {
3269 	ClassDB::bind_method(D_METHOD("print", "value", "indent", "sort_keys"), &_JSON::print, DEFVAL(String()), DEFVAL(false));
3270 	ClassDB::bind_method(D_METHOD("parse", "json"), &_JSON::parse);
3271 }
3272 
print(const Variant & p_value,const String & p_indent,bool p_sort_keys)3273 String _JSON::print(const Variant &p_value, const String &p_indent, bool p_sort_keys) {
3274 	return JSON::print(p_value, p_indent, p_sort_keys);
3275 }
3276 
parse(const String & p_json)3277 Ref<JSONParseResult> _JSON::parse(const String &p_json) {
3278 	Ref<JSONParseResult> result;
3279 	result.instance();
3280 
3281 	result->error = JSON::parse(p_json, result->result, result->error_string, result->error_line);
3282 
3283 	if (result->error != OK) {
3284 		ERR_PRINTS(vformat("Error parsing JSON at line %s: %s", result->error_line, result->error_string));
3285 	}
3286 	return result;
3287 }
3288 
3289 _JSON *_JSON::singleton = NULL;
3290 
_JSON()3291 _JSON::_JSON() {
3292 	singleton = this;
3293 }
3294