2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* core_bind.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2016-06-18 14:46:12 +02:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "core_bind.h"
|
|
|
|
#include "os/os.h"
|
|
|
|
#include "geometry.h"
|
|
|
|
#include "io/marshalls.h"
|
|
|
|
#include "io/base64.h"
|
|
|
|
#include "core/globals.h"
|
2014-04-15 03:43:44 +02:00
|
|
|
#include "io/file_access_encrypted.h"
|
2015-05-17 18:11:55 +02:00
|
|
|
#include "os/keyboard.h"
|
2016-03-04 07:31:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Time constants borrowed from loc_time.h
|
|
|
|
*/
|
|
|
|
#define EPOCH_YR 1970 /* EPOCH = Jan 1 1970 00:00:00 */
|
|
|
|
#define SECS_DAY (24L * 60L * 60L)
|
|
|
|
#define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
|
|
|
|
#define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
|
2016-03-16 05:17:10 +01:00
|
|
|
#define SECOND_KEY "second"
|
|
|
|
#define MINUTE_KEY "minute"
|
|
|
|
#define HOUR_KEY "hour"
|
|
|
|
#define DAY_KEY "day"
|
|
|
|
#define MONTH_KEY "month"
|
|
|
|
#define YEAR_KEY "year"
|
|
|
|
#define WEEKDAY_KEY "weekday"
|
|
|
|
#define DST_KEY "dst"
|
|
|
|
|
|
|
|
/// Table of number of days in each month (for regular year and leap year)
|
|
|
|
static const unsigned int MONTH_DAYS_TABLE[2][12] = {
|
|
|
|
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
|
|
|
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
|
|
|
};
|
2016-03-04 07:31:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
_ResourceLoader *_ResourceLoader::singleton=NULL;
|
|
|
|
|
|
|
|
Ref<ResourceInteractiveLoader> _ResourceLoader::load_interactive(const String& p_path,const String& p_type_hint) {
|
|
|
|
return ResourceLoader::load_interactive(p_path,p_type_hint);
|
|
|
|
}
|
|
|
|
|
2014-12-20 19:30:06 +01:00
|
|
|
RES _ResourceLoader::load(const String &p_path,const String& p_type_hint, bool p_no_cache) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-12-20 19:30:06 +01:00
|
|
|
RES ret = ResourceLoader::load(p_path,p_type_hint, p_no_cache);
|
2014-02-10 02:10:30 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<String> _ResourceLoader::get_recognized_extensions_for_type(const String& p_type) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
List<String> exts;
|
|
|
|
ResourceLoader::get_recognized_extensions_for_type(p_type,&exts);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<String> ret;
|
2014-02-10 02:10:30 +01:00
|
|
|
for(List<String>::Element *E=exts.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
ret.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _ResourceLoader::set_abort_on_missing_resources(bool p_abort) {
|
|
|
|
|
|
|
|
ResourceLoader::set_abort_on_missing_resources(p_abort);
|
|
|
|
}
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
PoolStringArray _ResourceLoader::get_dependencies(const String& p_path) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
List<String> deps;
|
|
|
|
ResourceLoader::get_dependencies(p_path, &deps);
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
PoolStringArray ret;
|
2014-02-10 02:10:30 +01:00
|
|
|
for(List<String>::Element *E=deps.front();E;E=E->next()) {
|
|
|
|
ret.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool _ResourceLoader::has(const String &p_path) {
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
String local_path = GlobalConfig::get_singleton()->localize_path(p_path);
|
2014-02-10 02:10:30 +01:00
|
|
|
return ResourceCache::has(local_path);
|
|
|
|
};
|
|
|
|
|
2016-02-28 03:10:44 +01:00
|
|
|
Ref<ResourceImportMetadata> _ResourceLoader::load_import_metadata(const String& p_path) {
|
|
|
|
|
|
|
|
return ResourceLoader::load_import_metadata(p_path);
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _ResourceLoader::_bind_methods() {
|
|
|
|
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("load_interactive:ResourceInteractiveLoader","path","type_hint"),&_ResourceLoader::load_interactive,DEFVAL(""));
|
|
|
|
ClassDB::bind_method(_MD("load:Resource","path","type_hint", "p_no_cache"),&_ResourceLoader::load,DEFVAL(""), DEFVAL(false));
|
|
|
|
ClassDB::bind_method(_MD("load_import_metadata:ResourceImportMetadata","path"),&_ResourceLoader::load_import_metadata);
|
|
|
|
ClassDB::bind_method(_MD("get_recognized_extensions_for_type","type"),&_ResourceLoader::get_recognized_extensions_for_type);
|
|
|
|
ClassDB::bind_method(_MD("set_abort_on_missing_resources","abort"),&_ResourceLoader::set_abort_on_missing_resources);
|
|
|
|
ClassDB::bind_method(_MD("get_dependencies","path"),&_ResourceLoader::get_dependencies);
|
|
|
|
ClassDB::bind_method(_MD("has","path"),&_ResourceLoader::has);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_ResourceLoader::_ResourceLoader() {
|
|
|
|
|
|
|
|
singleton=this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Error _ResourceSaver::save(const String &p_path,const RES& p_resource, uint32_t p_flags) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(p_resource.is_null(),ERR_INVALID_PARAMETER);
|
|
|
|
return ResourceSaver::save(p_path,p_resource, p_flags);
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<String> _ResourceSaver::get_recognized_extensions(const RES& p_resource) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
ERR_FAIL_COND_V(p_resource.is_null(),PoolVector<String>());
|
2014-02-10 02:10:30 +01:00
|
|
|
List<String> exts;
|
|
|
|
ResourceSaver::get_recognized_extensions(p_resource,&exts);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<String> ret;
|
2014-02-10 02:10:30 +01:00
|
|
|
for(List<String>::Element *E=exts.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
ret.push_back(E->get());
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
_ResourceSaver *_ResourceSaver::singleton=NULL;
|
|
|
|
|
|
|
|
|
|
|
|
void _ResourceSaver::_bind_methods() {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("save","path","resource:Resource","flags"),&_ResourceSaver::save,DEFVAL(0));
|
|
|
|
ClassDB::bind_method(_MD("get_recognized_extensions","type"),&_ResourceSaver::get_recognized_extensions);
|
2014-05-24 06:35:47 +02:00
|
|
|
|
|
|
|
BIND_CONSTANT(FLAG_RELATIVE_PATHS);
|
|
|
|
BIND_CONSTANT(FLAG_BUNDLE_RESOURCES);
|
|
|
|
BIND_CONSTANT(FLAG_CHANGE_PATH);
|
|
|
|
BIND_CONSTANT(FLAG_OMIT_EDITOR_PROPERTIES);
|
|
|
|
BIND_CONSTANT(FLAG_SAVE_BIG_ENDIAN);
|
|
|
|
BIND_CONSTANT(FLAG_COMPRESS);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_ResourceSaver::_ResourceSaver() {
|
|
|
|
|
|
|
|
singleton=this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////OS
|
|
|
|
|
|
|
|
|
|
|
|
Point2 _OS::get_mouse_pos() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_mouse_pos();
|
|
|
|
}
|
|
|
|
void _OS::set_window_title(const String& p_title) {
|
|
|
|
|
|
|
|
OS::get_singleton()->set_window_title(p_title);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int _OS::get_mouse_button_state() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_mouse_button_state();
|
|
|
|
}
|
|
|
|
|
|
|
|
String _OS::get_unique_ID() const {
|
|
|
|
return OS::get_singleton()->get_unique_ID();
|
|
|
|
}
|
|
|
|
bool _OS::has_touchscreen_ui_hint() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->has_touchscreen_ui_hint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::set_clipboard(const String& p_text) {
|
|
|
|
|
|
|
|
|
|
|
|
OS::get_singleton()->set_clipboard(p_text);
|
|
|
|
}
|
|
|
|
String _OS::get_clipboard() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_clipboard();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::set_video_mode(const Size2& p_size, bool p_fullscreen,bool p_resizeable,int p_screen) {
|
|
|
|
|
|
|
|
OS::VideoMode vm;
|
|
|
|
vm.width=p_size.width;
|
|
|
|
vm.height=p_size.height;
|
|
|
|
vm.fullscreen=p_fullscreen;
|
|
|
|
vm.resizable=p_resizeable;
|
|
|
|
OS::get_singleton()->set_video_mode( vm,p_screen);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
Size2 _OS::get_video_mode(int p_screen) const {
|
|
|
|
|
|
|
|
OS::VideoMode vm;
|
|
|
|
vm = OS::get_singleton()->get_video_mode(p_screen);
|
|
|
|
return Size2(vm.width,vm.height);
|
|
|
|
|
|
|
|
}
|
|
|
|
bool _OS::is_video_mode_fullscreen(int p_screen) const {
|
|
|
|
|
|
|
|
OS::VideoMode vm;
|
|
|
|
vm = OS::get_singleton()->get_video_mode(p_screen);
|
|
|
|
return vm.fullscreen;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-22 23:00:50 +01:00
|
|
|
|
2015-01-11 11:52:42 +01:00
|
|
|
int _OS::get_screen_count() const {
|
|
|
|
return OS::get_singleton()->get_screen_count();
|
|
|
|
}
|
|
|
|
|
2015-03-22 23:00:50 +01:00
|
|
|
int _OS::get_current_screen() const {
|
|
|
|
return OS::get_singleton()->get_current_screen();
|
2015-01-14 05:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-03-22 23:00:50 +01:00
|
|
|
void _OS::set_current_screen(int p_screen) {
|
|
|
|
OS::get_singleton()->set_current_screen(p_screen);
|
2015-01-14 05:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-01-13 10:25:50 +01:00
|
|
|
Point2 _OS::get_screen_position(int p_screen) const {
|
|
|
|
return OS::get_singleton()->get_screen_position(p_screen);
|
|
|
|
}
|
|
|
|
|
2015-01-11 12:35:53 +01:00
|
|
|
Size2 _OS::get_screen_size(int p_screen) const {
|
|
|
|
return OS::get_singleton()->get_screen_size(p_screen);
|
|
|
|
}
|
|
|
|
|
2016-05-29 18:40:00 +02:00
|
|
|
int _OS::get_screen_dpi(int p_screen) const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_screen_dpi(p_screen);
|
|
|
|
}
|
|
|
|
|
2015-01-11 08:47:27 +01:00
|
|
|
Point2 _OS::get_window_position() const {
|
|
|
|
return OS::get_singleton()->get_window_position();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::set_window_position(const Point2& p_position) {
|
|
|
|
OS::get_singleton()->set_window_position(p_position);
|
|
|
|
}
|
|
|
|
|
2015-01-11 10:36:56 +01:00
|
|
|
Size2 _OS::get_window_size() const {
|
|
|
|
return OS::get_singleton()->get_window_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::set_window_size(const Size2& p_size) {
|
|
|
|
OS::get_singleton()->set_window_size(p_size);
|
|
|
|
}
|
|
|
|
|
2015-03-22 23:00:50 +01:00
|
|
|
void _OS::set_window_fullscreen(bool p_enabled) {
|
|
|
|
OS::get_singleton()->set_window_fullscreen(p_enabled);
|
2015-01-10 08:47:34 +01:00
|
|
|
}
|
|
|
|
|
2015-03-22 23:00:50 +01:00
|
|
|
bool _OS::is_window_fullscreen() const {
|
|
|
|
return OS::get_singleton()->is_window_fullscreen();
|
2015-01-10 08:47:34 +01:00
|
|
|
}
|
2015-01-15 14:50:23 +01:00
|
|
|
|
2015-03-22 23:00:50 +01:00
|
|
|
void _OS::set_window_resizable(bool p_enabled) {
|
|
|
|
OS::get_singleton()->set_window_resizable(p_enabled);
|
2015-01-15 14:50:23 +01:00
|
|
|
}
|
|
|
|
|
2015-03-22 23:00:50 +01:00
|
|
|
bool _OS::is_window_resizable() const {
|
|
|
|
return OS::get_singleton()->is_window_resizable();
|
2015-01-15 14:50:23 +01:00
|
|
|
}
|
2015-01-16 16:18:45 +01:00
|
|
|
|
2015-03-22 23:00:50 +01:00
|
|
|
void _OS::set_window_minimized(bool p_enabled) {
|
|
|
|
OS::get_singleton()->set_window_minimized(p_enabled);
|
2015-01-16 16:18:45 +01:00
|
|
|
}
|
|
|
|
|
2015-03-22 23:00:50 +01:00
|
|
|
bool _OS::is_window_minimized() const {
|
|
|
|
return OS::get_singleton()->is_window_minimized();
|
2015-01-16 16:18:45 +01:00
|
|
|
}
|
|
|
|
|
2015-03-22 23:00:50 +01:00
|
|
|
void _OS::set_window_maximized(bool p_enabled) {
|
|
|
|
OS::get_singleton()->set_window_maximized(p_enabled);
|
2015-01-16 16:18:45 +01:00
|
|
|
}
|
|
|
|
|
2015-03-22 23:00:50 +01:00
|
|
|
bool _OS::is_window_maximized() const {
|
|
|
|
return OS::get_singleton()->is_window_maximized();
|
2015-01-16 16:18:45 +01:00
|
|
|
}
|
2015-03-22 23:00:50 +01:00
|
|
|
|
2016-01-03 05:18:28 +01:00
|
|
|
void _OS::set_borderless_window(bool p_borderless) {
|
|
|
|
OS::get_singleton()->set_borderless_window(p_borderless);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _OS::get_borderless_window() const {
|
|
|
|
return OS::get_singleton()->get_borderless_window();
|
|
|
|
}
|
2015-01-10 08:47:34 +01:00
|
|
|
|
2014-08-02 03:10:38 +02:00
|
|
|
void _OS::set_use_file_access_save_and_swap(bool p_enable) {
|
|
|
|
|
|
|
|
FileAccess::set_backup_save(p_enable);
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool _OS::is_video_mode_resizable(int p_screen) const {
|
|
|
|
|
|
|
|
OS::VideoMode vm;
|
|
|
|
vm = OS::get_singleton()->get_video_mode(p_screen);
|
|
|
|
return vm.resizable;
|
|
|
|
}
|
|
|
|
|
|
|
|
Array _OS::get_fullscreen_mode_list(int p_screen) const {
|
|
|
|
|
|
|
|
List<OS::VideoMode> vmlist;
|
|
|
|
OS::get_singleton()->get_fullscreen_mode_list(&vmlist,p_screen);
|
|
|
|
Array vmarr;
|
|
|
|
for(List<OS::VideoMode>::Element *E=vmlist.front();E;E=E->next() ){
|
|
|
|
|
|
|
|
vmarr.push_back(Size2(E->get().width,E->get().height));
|
|
|
|
}
|
|
|
|
|
|
|
|
return vmarr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::set_low_processor_usage_mode(bool p_enabled) {
|
|
|
|
|
|
|
|
OS::get_singleton()->set_low_processor_usage_mode(p_enabled);
|
|
|
|
}
|
|
|
|
bool _OS::is_in_low_processor_usage_mode() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->is_in_low_processor_usage_mode();
|
|
|
|
}
|
|
|
|
|
|
|
|
String _OS::get_executable_path() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_executable_path();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error _OS::shell_open(String p_uri) {
|
|
|
|
|
|
|
|
return OS::get_singleton()->shell_open(p_uri);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-06-30 04:24:05 +02:00
|
|
|
int _OS::execute(const String& p_path, const Vector<String> & p_arguments, bool p_blocking, Array p_output) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
OS::ProcessID pid;
|
|
|
|
List<String> args;
|
|
|
|
for(int i=0;i<p_arguments.size();i++)
|
|
|
|
args.push_back(p_arguments[i]);
|
|
|
|
String pipe;
|
|
|
|
Error err = OS::get_singleton()->execute(p_path,args,p_blocking,&pid, &pipe);
|
2014-06-30 04:24:05 +02:00
|
|
|
p_output.clear();
|
|
|
|
p_output.push_back(pipe);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (err != OK)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return pid;
|
|
|
|
|
|
|
|
}
|
|
|
|
Error _OS::kill(int p_pid) {
|
|
|
|
|
|
|
|
return OS::get_singleton()->kill(p_pid);
|
|
|
|
}
|
|
|
|
|
2014-04-05 17:39:30 +02:00
|
|
|
int _OS::get_process_ID() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_process_ID();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool _OS::has_environment(const String& p_var) const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->has_environment(p_var);
|
|
|
|
}
|
|
|
|
String _OS::get_environment(const String& p_var) const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_environment(p_var);
|
|
|
|
}
|
|
|
|
|
|
|
|
String _OS::get_name() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_name();
|
|
|
|
}
|
|
|
|
Vector<String> _OS::get_cmdline_args() {
|
|
|
|
|
|
|
|
List<String> cmdline = OS::get_singleton()->get_cmdline_args();
|
|
|
|
Vector<String> cmdlinev;
|
|
|
|
for(List<String>::Element *E=cmdline.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
cmdlinev.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmdlinev;
|
|
|
|
}
|
|
|
|
|
|
|
|
String _OS::get_locale() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_locale();
|
|
|
|
}
|
|
|
|
|
2016-07-02 20:52:36 +02:00
|
|
|
String _OS::get_latin_keyboard_variant() const {
|
|
|
|
switch( OS::get_singleton()->get_latin_keyboard_variant() ) {
|
|
|
|
case OS::LATIN_KEYBOARD_QWERTY: return "QWERTY";
|
|
|
|
case OS::LATIN_KEYBOARD_QWERTZ: return "QWERTZ";
|
|
|
|
case OS::LATIN_KEYBOARD_AZERTY: return "AZERTY";
|
|
|
|
case OS::LATIN_KEYBOARD_QZERTY: return "QZERTY";
|
|
|
|
case OS::LATIN_KEYBOARD_DVORAK: return "DVORAK";
|
|
|
|
case OS::LATIN_KEYBOARD_NEO : return "NEO";
|
|
|
|
default: return "ERROR";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String _OS::get_model_name() const {
|
|
|
|
|
2017-01-14 17:01:43 +01:00
|
|
|
return OS::get_singleton()->get_model_name();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-21 06:43:42 +02:00
|
|
|
|
2015-02-15 05:19:46 +01:00
|
|
|
bool _OS::is_ok_left_and_cancel_right() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_swap_ok_cancel();
|
|
|
|
}
|
|
|
|
|
2016-02-01 00:22:38 +01:00
|
|
|
Error _OS::set_thread_name(const String& p_name) {
|
|
|
|
|
|
|
|
return Thread::set_name(p_name);
|
|
|
|
};
|
|
|
|
|
2016-06-06 00:14:33 +02:00
|
|
|
void _OS::set_use_vsync(bool p_enable) {
|
|
|
|
OS::get_singleton()->set_use_vsync(p_enable);
|
|
|
|
}
|
|
|
|
|
2016-11-08 15:06:57 +01:00
|
|
|
bool _OS::is_vsync_enabled() const {
|
2016-06-06 00:14:33 +02:00
|
|
|
|
2016-11-08 15:06:57 +01:00
|
|
|
return OS::get_singleton()->is_vsync_enabled();
|
2016-06-06 00:14:33 +02:00
|
|
|
}
|
|
|
|
|
2016-02-01 00:22:38 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/*
|
|
|
|
enum Weekday {
|
|
|
|
DAY_SUNDAY,
|
|
|
|
DAY_MONDAY,
|
|
|
|
DAY_TUESDAY,
|
|
|
|
DAY_WEDNESDAY,
|
|
|
|
DAY_THURSDAY,
|
|
|
|
DAY_FRIDAY,
|
|
|
|
DAY_SATURDAY
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Month {
|
|
|
|
MONTH_JANUARY,
|
|
|
|
MONTH_FEBRUARY,
|
|
|
|
MONTH_MARCH,
|
|
|
|
MONTH_APRIL,
|
|
|
|
MONTH_MAY,
|
|
|
|
MONTH_JUNE,
|
|
|
|
MONTH_JULY,
|
|
|
|
MONTH_AUGUST,
|
|
|
|
MONTH_SEPTEMBER,
|
|
|
|
MONTH_OCTOBER,
|
|
|
|
MONTH_NOVEMBER,
|
|
|
|
MONTH_DECEMBER
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
struct Date {
|
|
|
|
|
|
|
|
int year;
|
|
|
|
Month month;
|
|
|
|
int day;
|
|
|
|
Weekday weekday;
|
|
|
|
bool dst;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Time {
|
|
|
|
|
|
|
|
int hour;
|
|
|
|
int min;
|
|
|
|
int sec;
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
|
|
|
int _OS::get_static_memory_usage() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_static_memory_usage();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int _OS::get_static_memory_peak_usage() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_static_memory_peak_usage();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int _OS::get_dynamic_memory_usage() const{
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_dynamic_memory_usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _OS::set_icon(const Image& p_icon) {
|
|
|
|
|
|
|
|
OS::get_singleton()->set_icon(p_icon);
|
|
|
|
}
|
|
|
|
|
2017-01-07 18:55:48 +01:00
|
|
|
int _OS::get_exit_code() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_exit_code();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::set_exit_code(int p_code) {
|
|
|
|
|
|
|
|
OS::get_singleton()->set_exit_code(p_code);
|
|
|
|
}
|
|
|
|
|
2016-03-16 05:17:10 +01:00
|
|
|
/**
|
2016-05-21 15:29:25 +02:00
|
|
|
* Get current datetime with consideration for utc and
|
2016-03-16 05:17:10 +01:00
|
|
|
* dst
|
2016-05-21 15:29:25 +02:00
|
|
|
*/
|
2016-03-16 05:17:10 +01:00
|
|
|
Dictionary _OS::get_datetime(bool utc) const {
|
|
|
|
|
|
|
|
Dictionary dated = get_date(utc);
|
|
|
|
Dictionary timed = get_time(utc);
|
|
|
|
|
|
|
|
List<Variant> keys;
|
|
|
|
timed.get_key_list(&keys);
|
|
|
|
|
|
|
|
for(int i = 0; i < keys.size(); i++) {
|
|
|
|
dated[keys[i]] = timed[keys[i]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return dated;
|
|
|
|
}
|
|
|
|
|
2015-06-06 03:40:56 +02:00
|
|
|
Dictionary _OS::get_date(bool utc) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-06-06 03:40:56 +02:00
|
|
|
OS::Date date = OS::get_singleton()->get_date(utc);
|
2014-02-10 02:10:30 +01:00
|
|
|
Dictionary dated;
|
2016-03-16 05:17:10 +01:00
|
|
|
dated[YEAR_KEY]=date.year;
|
|
|
|
dated[MONTH_KEY]=date.month;
|
|
|
|
dated[DAY_KEY]=date.day;
|
|
|
|
dated[WEEKDAY_KEY]=date.weekday;
|
|
|
|
dated[DST_KEY]=date.dst;
|
2014-02-10 02:10:30 +01:00
|
|
|
return dated;
|
|
|
|
}
|
2016-03-04 07:31:27 +01:00
|
|
|
|
2015-06-06 03:40:56 +02:00
|
|
|
Dictionary _OS::get_time(bool utc) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-06-06 03:40:56 +02:00
|
|
|
OS::Time time = OS::get_singleton()->get_time(utc);
|
2014-02-10 02:10:30 +01:00
|
|
|
Dictionary timed;
|
2016-03-16 05:17:10 +01:00
|
|
|
timed[HOUR_KEY]=time.hour;
|
|
|
|
timed[MINUTE_KEY]=time.min;
|
|
|
|
timed[SECOND_KEY]=time.sec;
|
2014-02-10 02:10:30 +01:00
|
|
|
return timed;
|
2016-03-04 07:31:27 +01:00
|
|
|
}
|
|
|
|
|
2016-03-16 05:17:10 +01:00
|
|
|
/**
|
|
|
|
* Get a epoch time value from a dictionary of time values
|
|
|
|
* @p datetime must be populated with the following keys:
|
|
|
|
* day, hour, minute, month, second, year. (dst is ignored).
|
|
|
|
*
|
|
|
|
* You can pass the output from
|
|
|
|
* get_datetime_from_unix_time directly into this function
|
|
|
|
*
|
|
|
|
* @param datetime dictionary of date and time values to convert
|
|
|
|
*
|
|
|
|
* @return epoch calculated
|
|
|
|
*/
|
|
|
|
uint64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const {
|
|
|
|
|
|
|
|
// Bunch of conversion constants
|
|
|
|
static const unsigned int SECONDS_PER_MINUTE = 60;
|
|
|
|
static const unsigned int MINUTES_PER_HOUR = 60;
|
|
|
|
static const unsigned int HOURS_PER_DAY = 24;
|
2017-01-14 17:55:06 +01:00
|
|
|
static const unsigned int SECONDS_PER_HOUR = MINUTES_PER_HOUR * SECONDS_PER_MINUTE;
|
2016-03-16 05:17:10 +01:00
|
|
|
static const unsigned int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;
|
|
|
|
|
|
|
|
// Get all time values from the dictionary, set to zero if it doesn't exist.
|
|
|
|
// Risk incorrect calculation over throwing errors
|
2017-01-14 17:55:06 +01:00
|
|
|
unsigned int second = ((datetime.has(SECOND_KEY)) ? static_cast<unsigned int>(datetime[SECOND_KEY]): 0);
|
|
|
|
unsigned int minute = ((datetime.has(MINUTE_KEY)) ? static_cast<unsigned int>(datetime[MINUTE_KEY]): 0);
|
|
|
|
unsigned int hour = ((datetime.has(HOUR_KEY)) ? static_cast<unsigned int>(datetime[HOUR_KEY]): 0);
|
|
|
|
unsigned int day = ((datetime.has(DAY_KEY)) ? static_cast<unsigned int>(datetime[DAY_KEY]): 0);
|
|
|
|
unsigned int month = ((datetime.has(MONTH_KEY)) ? static_cast<unsigned int>(datetime[MONTH_KEY]) -1: 0);
|
|
|
|
unsigned int year = ((datetime.has(YEAR_KEY)) ? static_cast<unsigned int>(datetime[YEAR_KEY]):0);
|
2016-03-16 05:17:10 +01:00
|
|
|
|
|
|
|
/// How many days come before each month (0-12)
|
2017-01-14 17:51:21 +01:00
|
|
|
static const unsigned short int DAYS_PAST_THIS_YEAR_TABLE[2][13] = {
|
2016-03-16 05:17:10 +01:00
|
|
|
/* Normal years. */
|
|
|
|
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
|
|
|
|
/* Leap years. */
|
|
|
|
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
|
|
|
|
};
|
|
|
|
|
|
|
|
ERR_EXPLAIN("Invalid second value of: " + itos(second));
|
|
|
|
ERR_FAIL_COND_V( second > 59, 0);
|
|
|
|
|
|
|
|
ERR_EXPLAIN("Invalid minute value of: " + itos(minute));
|
|
|
|
ERR_FAIL_COND_V( minute > 59, 0);
|
|
|
|
|
|
|
|
ERR_EXPLAIN("Invalid hour value of: " + itos(hour));
|
|
|
|
ERR_FAIL_COND_V( hour > 23, 0);
|
|
|
|
|
|
|
|
ERR_EXPLAIN("Invalid month value of: " + itos(month+1));
|
|
|
|
ERR_FAIL_COND_V( month+1 > 12, 0);
|
|
|
|
|
|
|
|
// Do this check after month is tested as valid
|
2017-01-14 17:55:06 +01:00
|
|
|
ERR_EXPLAIN("Invalid day value of: " + itos(day) + " which is larger than "+ itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month]));
|
2016-03-16 05:17:10 +01:00
|
|
|
ERR_FAIL_COND_V( day > MONTH_DAYS_TABLE[LEAPYEAR(year)][month], 0);
|
|
|
|
|
|
|
|
// Calculate all the seconds from months past in this year
|
2017-01-14 17:55:06 +01:00
|
|
|
uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR = DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month] * SECONDS_PER_DAY;
|
2016-03-16 05:17:10 +01:00
|
|
|
|
|
|
|
uint64_t SECONDS_FROM_YEARS_PAST = 0;
|
|
|
|
for(unsigned int iyear = EPOCH_YR; iyear < year; iyear++) {
|
|
|
|
|
2017-01-14 17:55:06 +01:00
|
|
|
SECONDS_FROM_YEARS_PAST += YEARSIZE(iyear) * SECONDS_PER_DAY;
|
2016-03-16 05:17:10 +01:00
|
|
|
}
|
|
|
|
|
2016-05-21 15:29:25 +02:00
|
|
|
uint64_t epoch =
|
|
|
|
second +
|
|
|
|
minute * SECONDS_PER_MINUTE +
|
2016-03-16 05:17:10 +01:00
|
|
|
hour * SECONDS_PER_HOUR +
|
|
|
|
// Subtract 1 from day, since the current day isn't over yet
|
|
|
|
// and we cannot count all 24 hours.
|
2016-05-21 15:29:25 +02:00
|
|
|
(day-1) * SECONDS_PER_DAY +
|
2016-03-16 05:17:10 +01:00
|
|
|
SECONDS_FROM_MONTHS_PAST_THIS_YEAR +
|
|
|
|
SECONDS_FROM_YEARS_PAST;
|
|
|
|
return epoch;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-04 07:31:27 +01:00
|
|
|
/**
|
2016-03-13 03:13:57 +01:00
|
|
|
* Get a dictionary of time values when given epoch time
|
2016-03-04 07:31:27 +01:00
|
|
|
*
|
|
|
|
* Dictionary Time values will be a union if values from #get_time
|
2016-05-21 15:29:25 +02:00
|
|
|
* and #get_date dictionaries (with the exception of dst =
|
2016-03-13 03:13:57 +01:00
|
|
|
* day light standard time, as it cannot be determined from epoch)
|
2016-03-16 05:17:10 +01:00
|
|
|
*
|
|
|
|
* @param unix_time_val epoch time to convert
|
|
|
|
*
|
|
|
|
* @return dictionary of date and time values
|
2016-03-04 07:31:27 +01:00
|
|
|
*/
|
2016-03-16 05:17:10 +01:00
|
|
|
Dictionary _OS::get_datetime_from_unix_time( uint64_t unix_time_val) const {
|
|
|
|
|
|
|
|
// Just fail if unix time is negative (when interpreted as an int).
|
|
|
|
// This means the user passed in a negative value by accident
|
2017-01-14 17:55:06 +01:00
|
|
|
ERR_EXPLAIN("unix_time_val was really huge!"+ itos(unix_time_val) + " You probably passed in a negative value!");
|
2016-03-16 05:17:10 +01:00
|
|
|
ERR_FAIL_COND_V( (int64_t)unix_time_val < 0, Dictionary());
|
2016-03-04 07:31:27 +01:00
|
|
|
|
|
|
|
OS::Date date;
|
|
|
|
OS::Time time;
|
|
|
|
|
|
|
|
unsigned long dayclock, dayno;
|
|
|
|
int year = EPOCH_YR;
|
|
|
|
|
|
|
|
dayclock = (unsigned long)unix_time_val % SECS_DAY;
|
|
|
|
dayno = (unsigned long)unix_time_val / SECS_DAY;
|
|
|
|
|
|
|
|
time.sec = dayclock % 60;
|
|
|
|
time.min = (dayclock % 3600) / 60;
|
|
|
|
time.hour = dayclock / 3600;
|
|
|
|
|
|
|
|
/* day 0 was a thursday */
|
2016-05-21 15:29:25 +02:00
|
|
|
date.weekday = static_cast<OS::Weekday>((dayno + 4) % 7);
|
2016-03-04 07:31:27 +01:00
|
|
|
|
|
|
|
while (dayno >= YEARSIZE(year)) {
|
|
|
|
dayno -= YEARSIZE(year);
|
|
|
|
year++;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-21 15:29:25 +02:00
|
|
|
date.year = year;
|
2016-03-04 07:31:27 +01:00
|
|
|
|
|
|
|
size_t imonth = 0;
|
|
|
|
|
2016-03-16 05:17:10 +01:00
|
|
|
while (dayno >= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth]) {
|
|
|
|
dayno -= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth];
|
2016-03-04 07:31:27 +01:00
|
|
|
imonth++;
|
|
|
|
}
|
|
|
|
|
2016-03-13 03:13:57 +01:00
|
|
|
/// Add 1 to month to make sure months are indexed starting at 1
|
|
|
|
date.month = static_cast<OS::Month>(imonth+1);
|
2016-03-04 07:31:27 +01:00
|
|
|
|
|
|
|
date.day = dayno + 1;
|
|
|
|
|
|
|
|
Dictionary timed;
|
2016-03-16 05:17:10 +01:00
|
|
|
timed[HOUR_KEY]=time.hour;
|
|
|
|
timed[MINUTE_KEY]=time.min;
|
|
|
|
timed[SECOND_KEY]=time.sec;
|
|
|
|
timed[YEAR_KEY]=date.year;
|
|
|
|
timed[MONTH_KEY]=date.month;
|
|
|
|
timed[DAY_KEY]=date.day;
|
|
|
|
timed[WEEKDAY_KEY]=date.weekday;
|
2016-03-04 07:31:27 +01:00
|
|
|
|
|
|
|
return timed;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2015-06-06 05:35:38 +02:00
|
|
|
|
|
|
|
Dictionary _OS::get_time_zone_info() const {
|
|
|
|
OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info();
|
|
|
|
Dictionary infod;
|
|
|
|
infod["bias"] = info.bias;
|
|
|
|
infod["name"] = info.name;
|
|
|
|
return infod;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
uint64_t _OS::get_unix_time() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_unix_time();
|
2016-03-16 05:17:10 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-01-10 22:24:55 +01:00
|
|
|
uint64_t _OS::get_system_time_secs() const {
|
|
|
|
return OS::get_singleton()->get_system_time_secs();
|
2015-08-06 19:29:33 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _OS::delay_usec(uint32_t p_usec) const {
|
|
|
|
|
|
|
|
OS::get_singleton()->delay_usec(p_usec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::delay_msec(uint32_t p_msec) const {
|
|
|
|
|
|
|
|
OS::get_singleton()->delay_usec(int64_t(p_msec)*1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t _OS::get_ticks_msec() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_ticks_msec();
|
|
|
|
}
|
|
|
|
|
2015-04-12 22:55:01 +02:00
|
|
|
uint32_t _OS::get_splash_tick_msec() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_splash_tick_msec();
|
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
|
|
|
|
bool _OS::can_use_threads() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->can_use_threads();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool _OS::can_draw() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->can_draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int _OS::get_processor_count() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_processor_count();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _OS::is_stdout_verbose() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->is_stdout_verbose();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::dump_memory_to_file(const String& p_file) {
|
|
|
|
|
|
|
|
OS::get_singleton()->dump_memory_to_file(p_file.utf8().get_data());
|
|
|
|
}
|
|
|
|
|
2014-02-26 14:08:17 +01:00
|
|
|
struct _OSCoreBindImg {
|
|
|
|
|
|
|
|
String path;
|
|
|
|
Size2 size;
|
|
|
|
int fmt;
|
|
|
|
ObjectID id;
|
|
|
|
int vram;
|
|
|
|
bool operator<(const _OSCoreBindImg& p_img) const { return vram==p_img.vram ? id<p_img.id : vram > p_img.vram; }
|
|
|
|
};
|
|
|
|
|
|
|
|
void _OS::print_all_textures_by_size() {
|
|
|
|
|
|
|
|
|
|
|
|
List<_OSCoreBindImg> imgs;
|
|
|
|
int total=0;
|
|
|
|
{
|
|
|
|
List<Ref<Resource> > rsrc;
|
|
|
|
ResourceCache::get_cached_resources(&rsrc);
|
|
|
|
|
|
|
|
for (List<Ref<Resource> >::Element *E=rsrc.front();E;E=E->next()) {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
if (!E->get()->is_class("ImageTexture"))
|
2014-02-26 14:08:17 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Size2 size = E->get()->call("get_size");
|
|
|
|
int fmt = E->get()->call("get_format");
|
|
|
|
|
|
|
|
_OSCoreBindImg img;
|
|
|
|
img.size=size;
|
|
|
|
img.fmt=fmt;
|
|
|
|
img.path=E->get()->get_path();
|
|
|
|
img.vram=Image::get_image_data_size(img.size.width,img.size.height,Image::Format(img.fmt));
|
|
|
|
img.id=E->get()->get_instance_ID();
|
|
|
|
total+=img.vram;
|
|
|
|
imgs.push_back(img);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
imgs.sort();
|
|
|
|
|
|
|
|
for(List<_OSCoreBindImg>::Element *E=imgs.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
total-=E->get().vram;
|
|
|
|
}
|
2014-05-14 06:22:15 +02:00
|
|
|
}
|
2014-02-26 14:08:17 +01:00
|
|
|
|
2014-05-14 06:22:15 +02:00
|
|
|
void _OS::print_resources_by_type(const Vector<String>& p_types) {
|
2014-02-26 14:08:17 +01:00
|
|
|
|
2014-05-14 06:22:15 +02:00
|
|
|
Map<String,int> type_count;
|
|
|
|
|
|
|
|
List<Ref<Resource> > resources;
|
|
|
|
ResourceCache::get_cached_resources(&resources);
|
|
|
|
|
|
|
|
List<Ref<Resource> > rsrc;
|
|
|
|
ResourceCache::get_cached_resources(&rsrc);
|
|
|
|
|
|
|
|
for (List<Ref<Resource> >::Element *E=rsrc.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
Ref<Resource> r = E->get();
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (int i=0; i<p_types.size(); i++) {
|
2017-01-03 03:03:46 +01:00
|
|
|
if (r->is_class(p_types[i]))
|
2014-05-14 06:22:15 +02:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
continue;
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
if (!type_count.has(r->get_class())) {
|
|
|
|
type_count[r->get_class()]=0;
|
2014-05-14 06:22:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
type_count[r->get_class()]++;
|
2014-05-14 06:22:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2014-02-26 14:08:17 +01:00
|
|
|
|
2016-07-21 23:58:58 +02:00
|
|
|
bool _OS::has_virtual_keyboard() const {
|
|
|
|
return OS::get_singleton()->has_virtual_keyboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::show_virtual_keyboard(const String& p_existing_text) {
|
|
|
|
OS::get_singleton()->show_virtual_keyboard(p_existing_text, Rect2());
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::hide_virtual_keyboard() {
|
|
|
|
OS::get_singleton()->hide_virtual_keyboard();
|
|
|
|
}
|
2014-02-26 14:08:17 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _OS::print_all_resources(const String& p_to_file ) {
|
|
|
|
|
|
|
|
OS::get_singleton()->print_all_resources(p_to_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::print_resources_in_use(bool p_short) {
|
|
|
|
|
|
|
|
OS::get_singleton()->print_resources_in_use(p_short);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _OS::dump_resources_to_file(const String& p_file) {
|
|
|
|
|
|
|
|
OS::get_singleton()->dump_resources_to_file(p_file.utf8().get_data());
|
|
|
|
}
|
|
|
|
|
|
|
|
String _OS::get_data_dir() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_data_dir();
|
|
|
|
};
|
|
|
|
|
2014-11-17 11:46:11 +01:00
|
|
|
Error _OS::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2014-11-17 11:46:11 +01:00
|
|
|
return OS::get_singleton()->native_video_play(p_path, p_volume, p_audio_track, p_subtitle_track);
|
2014-03-14 02:57:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
bool _OS::native_video_is_playing() {
|
|
|
|
|
|
|
|
return OS::get_singleton()->native_video_is_playing();
|
|
|
|
};
|
|
|
|
|
|
|
|
void _OS::native_video_pause() {
|
|
|
|
|
|
|
|
OS::get_singleton()->native_video_pause();
|
|
|
|
};
|
|
|
|
|
2016-02-19 05:09:06 +01:00
|
|
|
void _OS::native_video_unpause() {
|
|
|
|
OS::get_singleton()->native_video_unpause();
|
|
|
|
};
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
void _OS::native_video_stop() {
|
|
|
|
|
|
|
|
OS::get_singleton()->native_video_stop();
|
|
|
|
};
|
|
|
|
|
2016-07-05 17:29:08 +02:00
|
|
|
void _OS::request_attention() {
|
|
|
|
|
|
|
|
OS::get_singleton()->request_attention();
|
|
|
|
}
|
|
|
|
|
2014-11-02 15:31:01 +01:00
|
|
|
bool _OS::is_debug_build() const {
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2014-11-02 15:31:01 +01:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
2014-12-02 18:02:41 +01:00
|
|
|
|
2015-08-04 23:09:51 +02:00
|
|
|
void _OS::set_screen_orientation(ScreenOrientation p_orientation) {
|
|
|
|
|
|
|
|
OS::get_singleton()->set_screen_orientation(OS::ScreenOrientation(p_orientation));
|
|
|
|
}
|
|
|
|
|
|
|
|
_OS::ScreenOrientation _OS::get_screen_orientation() const {
|
|
|
|
|
|
|
|
return ScreenOrientation(OS::get_singleton()->get_screen_orientation());
|
|
|
|
}
|
|
|
|
|
2015-11-27 15:40:04 +01:00
|
|
|
void _OS::set_keep_screen_on(bool p_enabled) {
|
|
|
|
|
|
|
|
OS::get_singleton()->set_keep_screen_on(p_enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _OS::is_keep_screen_on() const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->is_keep_screen_on();
|
|
|
|
}
|
2015-08-04 23:09:51 +02:00
|
|
|
|
2014-12-02 18:02:41 +01:00
|
|
|
String _OS::get_system_dir(SystemDir p_dir) const {
|
|
|
|
|
|
|
|
return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir));
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-05-17 18:11:55 +02:00
|
|
|
|
|
|
|
String _OS::get_scancode_string(uint32_t p_code) const {
|
|
|
|
|
|
|
|
return keycode_get_string(p_code);
|
|
|
|
}
|
|
|
|
bool _OS::is_scancode_unicode(uint32_t p_unicode) const {
|
|
|
|
|
|
|
|
return keycode_has_unicode(p_unicode);
|
|
|
|
}
|
|
|
|
int _OS::find_scancode_from_string(const String& p_code) const {
|
|
|
|
|
|
|
|
return find_keycode(p_code);
|
|
|
|
}
|
|
|
|
|
2015-09-21 14:39:46 +02:00
|
|
|
void _OS::alert(const String& p_alert,const String& p_title) {
|
|
|
|
|
|
|
|
OS::get_singleton()->alert(p_alert,p_title);
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
_OS *_OS::singleton=NULL;
|
|
|
|
|
|
|
|
void _OS::_bind_methods() {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
//ClassDB::bind_method(_MD("get_mouse_pos"),&_OS::get_mouse_pos);
|
|
|
|
//ClassDB::bind_method(_MD("is_mouse_grab_enabled"),&_OS::is_mouse_grab_enabled);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("set_clipboard","clipboard"),&_OS::set_clipboard);
|
|
|
|
ClassDB::bind_method(_MD("get_clipboard"),&_OS::get_clipboard);
|
|
|
|
|
2017-01-14 14:06:15 +01:00
|
|
|
//will not delete for now, just unexpose
|
|
|
|
//ClassDB::bind_method(_MD("set_video_mode","size","fullscreen","resizable","screen"),&_OS::set_video_mode,DEFVAL(0));
|
|
|
|
//ClassDB::bind_method(_MD("get_video_mode_size","screen"),&_OS::get_video_mode,DEFVAL(0));
|
|
|
|
//ClassDB::bind_method(_MD("is_video_mode_fullscreen","screen"),&_OS::is_video_mode_fullscreen,DEFVAL(0));
|
|
|
|
//ClassDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0));
|
|
|
|
//ClassDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0));
|
2017-01-03 03:03:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count);
|
|
|
|
ClassDB::bind_method(_MD("get_current_screen"),&_OS::get_current_screen);
|
|
|
|
ClassDB::bind_method(_MD("set_current_screen","screen"),&_OS::set_current_screen);
|
|
|
|
ClassDB::bind_method(_MD("get_screen_position","screen"),&_OS::get_screen_position,DEFVAL(0));
|
|
|
|
ClassDB::bind_method(_MD("get_screen_size","screen"),&_OS::get_screen_size,DEFVAL(0));
|
|
|
|
ClassDB::bind_method(_MD("get_screen_dpi","screen"),&_OS::get_screen_dpi,DEFVAL(0));
|
|
|
|
ClassDB::bind_method(_MD("get_window_position"),&_OS::get_window_position);
|
|
|
|
ClassDB::bind_method(_MD("set_window_position","position"),&_OS::set_window_position);
|
|
|
|
ClassDB::bind_method(_MD("get_window_size"),&_OS::get_window_size);
|
|
|
|
ClassDB::bind_method(_MD("set_window_size","size"),&_OS::set_window_size);
|
|
|
|
ClassDB::bind_method(_MD("set_window_fullscreen","enabled"),&_OS::set_window_fullscreen);
|
|
|
|
ClassDB::bind_method(_MD("is_window_fullscreen"),&_OS::is_window_fullscreen);
|
|
|
|
ClassDB::bind_method(_MD("set_window_resizable","enabled"),&_OS::set_window_resizable);
|
|
|
|
ClassDB::bind_method(_MD("is_window_resizable"),&_OS::is_window_resizable);
|
|
|
|
ClassDB::bind_method(_MD("set_window_minimized", "enabled"),&_OS::set_window_minimized);
|
|
|
|
ClassDB::bind_method(_MD("is_window_minimized"),&_OS::is_window_minimized);
|
|
|
|
ClassDB::bind_method(_MD("set_window_maximized", "enabled"),&_OS::set_window_maximized);
|
|
|
|
ClassDB::bind_method(_MD("is_window_maximized"),&_OS::is_window_maximized);
|
|
|
|
ClassDB::bind_method(_MD("request_attention"), &_OS::request_attention);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("set_borderless_window", "borderless"), &_OS::set_borderless_window);
|
|
|
|
ClassDB::bind_method(_MD("get_borderless_window"), &_OS::get_borderless_window);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("set_screen_orientation","orientation"),&_OS::set_screen_orientation);
|
|
|
|
ClassDB::bind_method(_MD("get_screen_orientation"),&_OS::get_screen_orientation);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("set_keep_screen_on","enabled"),&_OS::set_keep_screen_on);
|
|
|
|
ClassDB::bind_method(_MD("is_keep_screen_on"),&_OS::is_keep_screen_on);
|
|
|
|
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("has_touchscreen_ui_hint"),&_OS::has_touchscreen_ui_hint);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("set_window_title","title"),&_OS::set_window_title);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("set_low_processor_usage_mode","enable"),&_OS::set_low_processor_usage_mode);
|
|
|
|
ClassDB::bind_method(_MD("is_in_low_processor_usage_mode"),&_OS::is_in_low_processor_usage_mode);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("get_processor_count"),&_OS::get_processor_count);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("get_executable_path"),&_OS::get_executable_path);
|
|
|
|
ClassDB::bind_method(_MD("execute","path","arguments","blocking","output"),&_OS::execute,DEFVAL(Array()));
|
|
|
|
ClassDB::bind_method(_MD("kill","pid"),&_OS::kill);
|
|
|
|
ClassDB::bind_method(_MD("shell_open","uri"),&_OS::shell_open);
|
|
|
|
ClassDB::bind_method(_MD("get_process_ID"),&_OS::get_process_ID);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("get_environment","environment"),&_OS::get_environment);
|
|
|
|
ClassDB::bind_method(_MD("has_environment","environment"),&_OS::has_environment);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("get_name"),&_OS::get_name);
|
|
|
|
ClassDB::bind_method(_MD("get_cmdline_args"),&_OS::get_cmdline_args);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("get_datetime","utc"),&_OS::get_datetime,DEFVAL(false));
|
|
|
|
ClassDB::bind_method(_MD("get_date","utc"),&_OS::get_date,DEFVAL(false));
|
|
|
|
ClassDB::bind_method(_MD("get_time","utc"),&_OS::get_time,DEFVAL(false));
|
|
|
|
ClassDB::bind_method(_MD("get_time_zone_info"),&_OS::get_time_zone_info);
|
|
|
|
ClassDB::bind_method(_MD("get_unix_time"),&_OS::get_unix_time);
|
|
|
|
ClassDB::bind_method(_MD("get_datetime_from_unix_time", "unix_time_val"),
|
2016-03-16 05:17:10 +01:00
|
|
|
&_OS::get_datetime_from_unix_time);
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("get_unix_time_from_datetime", "datetime"),
|
2016-03-16 05:17:10 +01:00
|
|
|
&_OS::get_unix_time_from_datetime);
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("get_system_time_secs"), &_OS::get_system_time_secs);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("set_icon","icon"),&_OS::set_icon);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 18:55:48 +01:00
|
|
|
ClassDB::bind_method(_MD("get_exit_code"),&_OS::get_exit_code);
|
|
|
|
ClassDB::bind_method(_MD("set_exit_code","code"),&_OS::set_exit_code);
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("delay_usec","usec"),&_OS::delay_usec);
|
|
|
|
ClassDB::bind_method(_MD("delay_msec","msec"),&_OS::delay_msec);
|
|
|
|
ClassDB::bind_method(_MD("get_ticks_msec"),&_OS::get_ticks_msec);
|
|
|
|
ClassDB::bind_method(_MD("get_splash_tick_msec"),&_OS::get_splash_tick_msec);
|
|
|
|
ClassDB::bind_method(_MD("get_locale"),&_OS::get_locale);
|
|
|
|
ClassDB::bind_method(_MD("get_latin_keyboard_variant"),&_OS::get_latin_keyboard_variant);
|
|
|
|
ClassDB::bind_method(_MD("get_model_name"),&_OS::get_model_name);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("can_draw"),&_OS::can_draw);
|
|
|
|
ClassDB::bind_method(_MD("is_stdout_verbose"),&_OS::is_stdout_verbose);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("can_use_threads"),&_OS::can_use_threads);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("is_debug_build"),&_OS::is_debug_build);
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
//ClassDB::bind_method(_MD("get_mouse_button_state"),&_OS::get_mouse_button_state);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("dump_memory_to_file","file"),&_OS::dump_memory_to_file);
|
|
|
|
ClassDB::bind_method(_MD("dump_resources_to_file","file"),&_OS::dump_resources_to_file);
|
|
|
|
ClassDB::bind_method(_MD("has_virtual_keyboard"),&_OS::has_virtual_keyboard);
|
|
|
|
ClassDB::bind_method(_MD("show_virtual_keyboard", "existing_text"),&_OS::show_virtual_keyboard,DEFVAL(""));
|
|
|
|
ClassDB::bind_method(_MD("hide_virtual_keyboard"),&_OS::hide_virtual_keyboard);
|
|
|
|
ClassDB::bind_method(_MD("print_resources_in_use","short"),&_OS::print_resources_in_use,DEFVAL(false));
|
|
|
|
ClassDB::bind_method(_MD("print_all_resources","tofile"),&_OS::print_all_resources,DEFVAL(""));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("get_static_memory_usage"),&_OS::get_static_memory_usage);
|
|
|
|
ClassDB::bind_method(_MD("get_static_memory_peak_usage"),&_OS::get_static_memory_peak_usage);
|
|
|
|
ClassDB::bind_method(_MD("get_dynamic_memory_usage"),&_OS::get_dynamic_memory_usage);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("get_data_dir"),&_OS::get_data_dir);
|
|
|
|
ClassDB::bind_method(_MD("get_system_dir","dir"),&_OS::get_system_dir);
|
|
|
|
ClassDB::bind_method(_MD("get_unique_ID"),&_OS::get_unique_ID);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("is_ok_left_and_cancel_right"),&_OS::is_ok_left_and_cancel_right);
|
2015-02-15 05:19:46 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("print_all_textures_by_size"),&_OS::print_all_textures_by_size);
|
|
|
|
ClassDB::bind_method(_MD("print_resources_by_type","types"),&_OS::print_resources_by_type);
|
2014-02-26 14:08:17 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("native_video_play","path","volume","audio_track","subtitle_track"),&_OS::native_video_play);
|
|
|
|
ClassDB::bind_method(_MD("native_video_is_playing"),&_OS::native_video_is_playing);
|
|
|
|
ClassDB::bind_method(_MD("native_video_stop"),&_OS::native_video_stop);
|
|
|
|
ClassDB::bind_method(_MD("native_video_pause"),&_OS::native_video_pause);
|
|
|
|
ClassDB::bind_method(_MD("native_video_unpause"),&_OS::native_video_unpause);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("get_scancode_string","code"),&_OS::get_scancode_string);
|
|
|
|
ClassDB::bind_method(_MD("is_scancode_unicode","code"),&_OS::is_scancode_unicode);
|
|
|
|
ClassDB::bind_method(_MD("find_scancode_from_string","string"),&_OS::find_scancode_from_string);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("set_use_file_access_save_and_swap","enabled"),&_OS::set_use_file_access_save_and_swap);
|
2014-08-02 03:10:38 +02:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("alert","text","title"),&_OS::alert,DEFVAL("Alert!"));
|
2014-08-02 03:10:38 +02:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("set_thread_name","name"),&_OS::set_thread_name);
|
2016-02-01 00:22:38 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("set_use_vsync","enable"),&_OS::set_use_vsync);
|
|
|
|
ClassDB::bind_method(_MD("is_vsync_enabled"),&_OS::is_vsync_enabled);
|
2014-08-02 03:10:38 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
BIND_CONSTANT( DAY_SUNDAY );
|
|
|
|
BIND_CONSTANT( DAY_MONDAY );
|
|
|
|
BIND_CONSTANT( DAY_TUESDAY );
|
|
|
|
BIND_CONSTANT( DAY_WEDNESDAY );
|
|
|
|
BIND_CONSTANT( DAY_THURSDAY );
|
|
|
|
BIND_CONSTANT( DAY_FRIDAY );
|
|
|
|
BIND_CONSTANT( DAY_SATURDAY );
|
|
|
|
|
|
|
|
BIND_CONSTANT( MONTH_JANUARY );
|
|
|
|
BIND_CONSTANT( MONTH_FEBRUARY );
|
|
|
|
BIND_CONSTANT( MONTH_MARCH );
|
|
|
|
BIND_CONSTANT( MONTH_APRIL );
|
|
|
|
BIND_CONSTANT( MONTH_MAY );
|
|
|
|
BIND_CONSTANT( MONTH_JUNE );
|
|
|
|
BIND_CONSTANT( MONTH_JULY );
|
|
|
|
BIND_CONSTANT( MONTH_AUGUST );
|
|
|
|
BIND_CONSTANT( MONTH_SEPTEMBER );
|
|
|
|
BIND_CONSTANT( MONTH_OCTOBER );
|
|
|
|
BIND_CONSTANT( MONTH_NOVEMBER );
|
|
|
|
BIND_CONSTANT( MONTH_DECEMBER );
|
|
|
|
|
2015-08-04 23:09:51 +02:00
|
|
|
BIND_CONSTANT( SCREEN_ORIENTATION_LANDSCAPE );
|
|
|
|
BIND_CONSTANT( SCREEN_ORIENTATION_PORTRAIT );
|
|
|
|
BIND_CONSTANT( SCREEN_ORIENTATION_REVERSE_LANDSCAPE );
|
|
|
|
BIND_CONSTANT( SCREEN_ORIENTATION_REVERSE_PORTRAIT );
|
|
|
|
BIND_CONSTANT( SCREEN_ORIENTATION_SENSOR_LANDSCAPE );
|
|
|
|
BIND_CONSTANT( SCREEN_ORIENTATION_SENSOR_PORTRAIT );
|
|
|
|
BIND_CONSTANT( SCREEN_ORIENTATION_SENSOR );
|
|
|
|
|
2014-12-02 18:02:41 +01:00
|
|
|
BIND_CONSTANT( SYSTEM_DIR_DESKTOP);
|
|
|
|
BIND_CONSTANT( SYSTEM_DIR_DCIM );
|
|
|
|
BIND_CONSTANT( SYSTEM_DIR_DOCUMENTS );
|
|
|
|
BIND_CONSTANT( SYSTEM_DIR_DOWNLOADS );
|
|
|
|
BIND_CONSTANT( SYSTEM_DIR_MOVIES );
|
|
|
|
BIND_CONSTANT( SYSTEM_DIR_MUSIC );
|
|
|
|
BIND_CONSTANT( SYSTEM_DIR_PICTURES );
|
|
|
|
BIND_CONSTANT( SYSTEM_DIR_RINGTONES );
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_OS::_OS() {
|
|
|
|
|
|
|
|
singleton=this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////// GEOMETRY
|
|
|
|
|
|
|
|
|
|
|
|
_Geometry *_Geometry::singleton=NULL;
|
|
|
|
|
|
|
|
_Geometry *_Geometry::get_singleton() {
|
|
|
|
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Plane> _Geometry::build_box_planes(const Vector3& p_extents) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return Geometry::build_box_planes(p_extents);
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Plane> _Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return Geometry::build_cylinder_planes(p_radius,p_height,p_sides,p_axis);
|
|
|
|
}
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Plane> _Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return Geometry::build_capsule_planes(p_radius,p_height,p_sides,p_lats,p_axis);
|
|
|
|
}
|
|
|
|
|
|
|
|
real_t _Geometry::segment_intersects_circle(const Vector2& p_from, const Vector2& p_to, const Vector2& p_circle_pos, real_t p_circle_radius) {
|
|
|
|
|
|
|
|
return Geometry::segment_intersects_circle(p_from,p_to,p_circle_pos,p_circle_radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
Vector2 result;
|
|
|
|
if (Geometry::segment_intersects_segment_2d(p_from_a, p_to_a, p_from_b, p_to_b, &result)) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return Variant();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> _Geometry::get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector2 r1, r2;
|
|
|
|
Geometry::get_closest_points_between_segments(p1,q1,p2,q2,r1,r2);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> r;
|
2014-02-10 02:10:30 +01:00
|
|
|
r.resize(2);
|
|
|
|
r.set(0,r1);
|
|
|
|
r.set(1,r2);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector3 r1, r2;
|
|
|
|
Geometry::get_closest_points_between_segments(p1,p2,q1,q2,r1,r2);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> r;
|
2014-02-10 02:10:30 +01:00
|
|
|
r.resize(2);
|
|
|
|
r.set(0,r1);
|
|
|
|
r.set(1,r2);
|
|
|
|
return r;
|
|
|
|
|
|
|
|
}
|
|
|
|
Vector3 _Geometry::get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b) {
|
|
|
|
|
|
|
|
Vector3 s[2]={p_a,p_b};
|
|
|
|
return Geometry::get_closest_point_to_segment(p_point,s);
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
|
|
|
|
Vector3 res;
|
|
|
|
if (Geometry::ray_intersects_triangle(p_from,p_dir,p_v0,p_v1,p_v2,&res))
|
|
|
|
return res;
|
|
|
|
else
|
|
|
|
return Variant();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
|
|
|
|
Vector3 res;
|
|
|
|
if (Geometry::segment_intersects_triangle(p_from,p_to,p_v0,p_v1,p_v2,&res))
|
|
|
|
return res;
|
|
|
|
else
|
|
|
|
return Variant();
|
|
|
|
|
|
|
|
}
|
2015-02-14 16:09:52 +01:00
|
|
|
|
|
|
|
bool _Geometry::point_is_inside_triangle(const Vector2& s, const Vector2& a, const Vector2& b, const Vector2& c) const {
|
|
|
|
|
|
|
|
return Geometry::is_point_in_triangle(s,a,b,c);
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> _Geometry::segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> r;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 res,norm;
|
|
|
|
if (!Geometry::segment_intersects_sphere(p_from,p_to,p_sphere_pos,p_sphere_radius,&res,&norm))
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r.resize(2);
|
|
|
|
r.set(0,res);
|
|
|
|
r.set(1,norm);
|
|
|
|
return r;
|
|
|
|
}
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> _Geometry::segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> r;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 res,norm;
|
|
|
|
if (!Geometry::segment_intersects_cylinder(p_from,p_to,p_height,p_radius,&res,&norm))
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r.resize(2);
|
|
|
|
r.set(0,res);
|
|
|
|
r.set(1,norm);
|
|
|
|
return r;
|
|
|
|
|
|
|
|
}
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> _Geometry::segment_intersects_convex(const Vector3& p_from, const Vector3& p_to,const Vector<Plane>& p_planes) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> r;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 res,norm;
|
|
|
|
if (!Geometry::segment_intersects_convex(p_from,p_to,p_planes.ptr(),p_planes.size(),&res,&norm))
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r.resize(2);
|
|
|
|
r.set(0,res);
|
|
|
|
r.set(1,norm);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<int> _Geometry::triangulate_polygon(const Vector<Vector2>& p_polygon) {
|
|
|
|
|
|
|
|
return Geometry::triangulate_polygon(p_polygon);
|
|
|
|
}
|
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
Dictionary _Geometry::make_atlas(const Vector<Size2>& p_rects) {
|
|
|
|
|
|
|
|
Dictionary ret;
|
|
|
|
|
|
|
|
Vector<Size2i> rects;
|
|
|
|
for (int i=0; i<p_rects.size(); i++) {
|
|
|
|
|
|
|
|
rects.push_back(p_rects[i]);
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Point2i> result;
|
|
|
|
Size2i size;
|
|
|
|
|
|
|
|
Geometry::make_atlas(rects, result, size);
|
|
|
|
|
|
|
|
Size2 r_size = size;
|
|
|
|
Vector<Point2> r_result;
|
|
|
|
for (int i=0; i<result.size(); i++) {
|
|
|
|
|
|
|
|
r_result.push_back(result[i]);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ret["points"] = r_result;
|
|
|
|
ret["size"] = r_size;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-07 06:31:49 +02:00
|
|
|
int _Geometry::get_uv84_normal_bit(const Vector3& p_vector) {
|
|
|
|
|
|
|
|
return Geometry::get_uv84_normal_bit(p_vector);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _Geometry::_bind_methods() {
|
|
|
|
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("build_box_planes","extents"),&_Geometry::build_box_planes);
|
|
|
|
ClassDB::bind_method(_MD("build_cylinder_planes","radius","height","sides","axis"),&_Geometry::build_cylinder_planes,DEFVAL(Vector3::AXIS_Z));
|
|
|
|
ClassDB::bind_method(_MD("build_capsule_planes","radius","height","sides","lats","axis"),&_Geometry::build_capsule_planes,DEFVAL(Vector3::AXIS_Z));
|
|
|
|
ClassDB::bind_method(_MD("segment_intersects_circle","segment_from","segment_to","circle_pos","circle_radius"),&_Geometry::segment_intersects_circle);
|
|
|
|
ClassDB::bind_method(_MD("segment_intersects_segment_2d","from_a","to_a","from_b","to_b"),&_Geometry::segment_intersects_segment_2d);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("get_closest_points_between_segments_2d","p1","q1","p2","q2"),&_Geometry::get_closest_points_between_segments_2d);
|
|
|
|
ClassDB::bind_method(_MD("get_closest_points_between_segments","p1","p2","q1","q2"),&_Geometry::get_closest_points_between_segments);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("get_closest_point_to_segment","point","s1","s2"),&_Geometry::get_closest_point_to_segment);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("get_uv84_normal_bit","normal"),&_Geometry::get_uv84_normal_bit);
|
2014-10-07 06:31:49 +02:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("ray_intersects_triangle","from","dir","a","b","c"),&_Geometry::ray_intersects_triangle);
|
|
|
|
ClassDB::bind_method(_MD("segment_intersects_triangle","from","to","a","b","c"),&_Geometry::segment_intersects_triangle);
|
|
|
|
ClassDB::bind_method(_MD("segment_intersects_sphere","from","to","spos","sradius"),&_Geometry::segment_intersects_sphere);
|
|
|
|
ClassDB::bind_method(_MD("segment_intersects_cylinder","from","to","height","radius"),&_Geometry::segment_intersects_cylinder);
|
|
|
|
ClassDB::bind_method(_MD("segment_intersects_convex","from","to","planes"),&_Geometry::segment_intersects_convex);
|
|
|
|
ClassDB::bind_method(_MD("point_is_inside_triangle","point","a","b","c"),&_Geometry::point_is_inside_triangle);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("triangulate_polygon","polygon"),&_Geometry::triangulate_polygon);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("make_atlas","sizes"),&_Geometry::make_atlas);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_Geometry::_Geometry() {
|
|
|
|
singleton=this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////// FILE
|
|
|
|
|
|
|
|
|
2014-04-15 03:43:44 +02:00
|
|
|
|
|
|
|
Error _File::open_encrypted(const String& p_path, int p_mode_flags,const Vector<uint8_t>& p_key) {
|
|
|
|
|
|
|
|
Error err = open(p_path,p_mode_flags);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
FileAccessEncrypted *fae = memnew( FileAccessEncrypted );
|
|
|
|
err = fae->open_and_parse(f,p_key,(p_mode_flags==WRITE)?FileAccessEncrypted::MODE_WRITE_AES256:FileAccessEncrypted::MODE_READ);
|
|
|
|
if (err) {
|
|
|
|
memdelete(fae);
|
|
|
|
close();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
f=fae;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error _File::open_encrypted_pass(const String& p_path, int p_mode_flags,const String& p_pass) {
|
|
|
|
|
|
|
|
Error err = open(p_path,p_mode_flags);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
FileAccessEncrypted *fae = memnew( FileAccessEncrypted );
|
|
|
|
err = fae->open_and_parse_password(f,p_pass,(p_mode_flags==WRITE)?FileAccessEncrypted::MODE_WRITE_AES256:FileAccessEncrypted::MODE_READ);
|
|
|
|
if (err) {
|
|
|
|
memdelete(fae);
|
|
|
|
close();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
f=fae;
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Error _File::open(const String& p_path, int p_mode_flags) {
|
|
|
|
|
|
|
|
close();
|
|
|
|
Error err;
|
|
|
|
f = FileAccess::open(p_path,p_mode_flags,&err);
|
|
|
|
if (f)
|
|
|
|
f->set_endian_swap(eswap);
|
|
|
|
return err;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void _File::close(){
|
|
|
|
|
|
|
|
if (f)
|
|
|
|
memdelete(f);
|
|
|
|
f=NULL;
|
|
|
|
}
|
|
|
|
bool _File::is_open() const{
|
|
|
|
|
|
|
|
|
|
|
|
return f!=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _File::seek(int64_t p_position){
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
f->seek(p_position);
|
|
|
|
|
|
|
|
}
|
|
|
|
void _File::seek_end(int64_t p_position){
|
|
|
|
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
f->seek_end(p_position);
|
|
|
|
}
|
|
|
|
int64_t _File::get_pos() const{
|
|
|
|
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,0);
|
|
|
|
return f->get_pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t _File::get_len() const{
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,0);
|
|
|
|
return f->get_len();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _File::eof_reached() const{
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,false);
|
|
|
|
return f->eof_reached();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t _File::get_8() const{
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,0);
|
|
|
|
return f->get_8();
|
|
|
|
|
|
|
|
}
|
|
|
|
uint16_t _File::get_16() const{
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,0);
|
|
|
|
return f->get_16();
|
|
|
|
|
|
|
|
}
|
|
|
|
uint32_t _File::get_32() const{
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,0);
|
|
|
|
return f->get_32();
|
|
|
|
|
|
|
|
}
|
|
|
|
uint64_t _File::get_64() const{
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,0);
|
|
|
|
return f->get_64();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
float _File::get_float() const{
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,0);
|
|
|
|
return f->get_float();
|
|
|
|
|
|
|
|
}
|
|
|
|
double _File::get_double() const{
|
|
|
|
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,0);
|
|
|
|
return f->get_double();
|
|
|
|
}
|
|
|
|
real_t _File::get_real() const{
|
|
|
|
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,0);
|
|
|
|
return f->get_real();
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> _File::get_buffer(int p_length) const{
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> data;
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND_V(!f,data);
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(p_length<0,data);
|
|
|
|
if (p_length==0)
|
|
|
|
return data;
|
|
|
|
Error err = data.resize(p_length);
|
|
|
|
ERR_FAIL_COND_V(err!=OK,data);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write w = data.write();
|
2014-02-10 02:10:30 +01:00
|
|
|
int len = f->get_buffer(&w[0],p_length);
|
2017-01-07 22:25:37 +01:00
|
|
|
ERR_FAIL_COND_V( len < 0 , PoolVector<uint8_t>());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
w = PoolVector<uint8_t>::Write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (len < p_length)
|
|
|
|
data.resize(p_length);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String _File::get_as_text() const {
|
|
|
|
|
2016-06-20 23:39:37 +02:00
|
|
|
ERR_FAIL_COND_V(!f, String());
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String text;
|
2016-06-20 23:39:37 +02:00
|
|
|
size_t original_pos = f->get_pos();
|
|
|
|
f->seek(0);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String l = get_line();
|
|
|
|
while(!eof_reached()) {
|
|
|
|
text+=l+"\n";
|
|
|
|
l = get_line();
|
|
|
|
}
|
2014-12-21 16:12:59 +01:00
|
|
|
text+=l;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-06-20 23:39:37 +02:00
|
|
|
f->seek(original_pos);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return text;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2016-02-25 19:25:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
String _File::get_md5(const String& p_path) const {
|
|
|
|
|
|
|
|
return FileAccess::get_md5(p_path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-17 09:55:16 +02:00
|
|
|
String _File::get_sha256(const String& p_path) const {
|
|
|
|
|
|
|
|
return FileAccess::get_sha256(p_path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-25 19:25:29 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String _File::get_line() const{
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,String());
|
|
|
|
return f->get_line();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-28 15:58:39 +01:00
|
|
|
Vector<String> _File::get_csv_line(String delim) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND_V(!f,Vector<String>());
|
2016-01-28 15:58:39 +01:00
|
|
|
return f->get_csv_line(delim);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
|
|
|
|
* It's not about the current CPU type but file formats.
|
|
|
|
* this flags get reset to false (little endian) on each open
|
|
|
|
*/
|
|
|
|
|
|
|
|
void _File::set_endian_swap(bool p_swap){
|
|
|
|
|
|
|
|
|
|
|
|
eswap=p_swap;
|
|
|
|
if (f)
|
|
|
|
f->set_endian_swap(p_swap);
|
|
|
|
|
|
|
|
}
|
|
|
|
bool _File::get_endian_swap(){
|
|
|
|
|
|
|
|
|
|
|
|
return eswap;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error _File::get_error() const{
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return ERR_UNCONFIGURED;
|
|
|
|
return f->get_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _File::store_8(uint8_t p_dest){
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
|
|
|
|
f->store_8(p_dest);
|
|
|
|
}
|
|
|
|
void _File::store_16(uint16_t p_dest){
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
|
|
|
|
f->store_16(p_dest);
|
|
|
|
}
|
|
|
|
void _File::store_32(uint32_t p_dest){
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
|
|
|
|
f->store_32(p_dest);
|
|
|
|
}
|
|
|
|
void _File::store_64(uint64_t p_dest){
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
|
|
|
|
f->store_64(p_dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _File::store_float(float p_dest){
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
|
|
|
|
f->store_float(p_dest);
|
|
|
|
}
|
|
|
|
void _File::store_double(double p_dest){
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
|
|
|
|
f->store_double(p_dest);
|
|
|
|
}
|
|
|
|
void _File::store_real(real_t p_real){
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
|
|
|
|
f->store_real(p_real);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _File::store_string(const String& p_string){
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
|
|
|
|
f->store_string(p_string);
|
|
|
|
}
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
void _File::store_pascal_string(const String& p_string) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
|
|
|
|
f->store_pascal_string(p_string);
|
|
|
|
};
|
|
|
|
|
|
|
|
String _File::get_pascal_string() {
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f, "");
|
|
|
|
|
|
|
|
return f->get_pascal_string();
|
|
|
|
};
|
|
|
|
|
|
|
|
void _File::store_line(const String& p_string){
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
f->store_line(p_string);
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
void _File::store_buffer(const PoolVector<uint8_t>& p_buffer){
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
|
|
|
|
int len = p_buffer.size();
|
|
|
|
if (len==0)
|
|
|
|
return;
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Read r = p_buffer.read();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
f->store_buffer(&r[0],len);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _File::file_exists(const String& p_name) const{
|
|
|
|
|
|
|
|
return FileAccess::exists(p_name);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void _File::store_var(const Variant& p_var) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
int len;
|
|
|
|
Error err = encode_variant(p_var,NULL,len);
|
|
|
|
ERR_FAIL_COND( err != OK );
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> buff;
|
2014-02-10 02:10:30 +01:00
|
|
|
buff.resize(len);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write w = buff.write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
err = encode_variant(p_var,&w[0],len);
|
|
|
|
ERR_FAIL_COND( err != OK );
|
2017-01-07 22:25:37 +01:00
|
|
|
w=PoolVector<uint8_t>::Write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
store_32(len);
|
|
|
|
store_buffer(buff);
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant _File::get_var() const {
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!f,Variant());
|
|
|
|
uint32_t len = get_32();
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> buff = get_buffer(len);
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND_V(buff.size() != len, Variant());
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Read r = buff.read();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Variant v;
|
|
|
|
Error err = decode_variant(v,&r[0],len);
|
|
|
|
ERR_FAIL_COND_V( err!=OK, Variant() );
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-01-23 22:33:02 +01:00
|
|
|
uint64_t _File::get_modified_time(const String &p_file) const {
|
|
|
|
|
|
|
|
return FileAccess::get_modified_time(p_file);
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _File::_bind_methods() {
|
|
|
|
|
2014-04-15 03:43:44 +02:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("open_encrypted","path","mode_flags","key"),&_File::open_encrypted);
|
|
|
|
ClassDB::bind_method(_MD("open_encrypted_with_pass","path","mode_flags","pass"),&_File::open_encrypted_pass);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("open","path","flags"),&_File::open);
|
|
|
|
ClassDB::bind_method(_MD("close"),&_File::close);
|
|
|
|
ClassDB::bind_method(_MD("is_open"),&_File::is_open);
|
|
|
|
ClassDB::bind_method(_MD("seek","pos"),&_File::seek);
|
|
|
|
ClassDB::bind_method(_MD("seek_end","pos"),&_File::seek_end,DEFVAL(0));
|
|
|
|
ClassDB::bind_method(_MD("get_pos"),&_File::get_pos);
|
|
|
|
ClassDB::bind_method(_MD("get_len"),&_File::get_len);
|
|
|
|
ClassDB::bind_method(_MD("eof_reached"),&_File::eof_reached);
|
|
|
|
ClassDB::bind_method(_MD("get_8"),&_File::get_8);
|
|
|
|
ClassDB::bind_method(_MD("get_16"),&_File::get_16);
|
|
|
|
ClassDB::bind_method(_MD("get_32"),&_File::get_32);
|
|
|
|
ClassDB::bind_method(_MD("get_64"),&_File::get_64);
|
|
|
|
ClassDB::bind_method(_MD("get_float"),&_File::get_float);
|
|
|
|
ClassDB::bind_method(_MD("get_double"),&_File::get_double);
|
|
|
|
ClassDB::bind_method(_MD("get_real"),&_File::get_real);
|
|
|
|
ClassDB::bind_method(_MD("get_buffer","len"),&_File::get_buffer);
|
|
|
|
ClassDB::bind_method(_MD("get_line"),&_File::get_line);
|
|
|
|
ClassDB::bind_method(_MD("get_as_text"),&_File::get_as_text);
|
|
|
|
ClassDB::bind_method(_MD("get_md5","path"),&_File::get_md5);
|
|
|
|
ClassDB::bind_method(_MD("get_sha256","path"),&_File::get_sha256);
|
|
|
|
ClassDB::bind_method(_MD("get_endian_swap"),&_File::get_endian_swap);
|
|
|
|
ClassDB::bind_method(_MD("set_endian_swap","enable"),&_File::set_endian_swap);
|
|
|
|
ClassDB::bind_method(_MD("get_error:Error"),&_File::get_error);
|
|
|
|
ClassDB::bind_method(_MD("get_var"),&_File::get_var);
|
|
|
|
ClassDB::bind_method(_MD("get_csv_line","delim"),&_File::get_csv_line,DEFVAL(","));
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("store_8","value"),&_File::store_8);
|
|
|
|
ClassDB::bind_method(_MD("store_16","value"),&_File::store_16);
|
|
|
|
ClassDB::bind_method(_MD("store_32","value"),&_File::store_32);
|
|
|
|
ClassDB::bind_method(_MD("store_64","value"),&_File::store_64);
|
|
|
|
ClassDB::bind_method(_MD("store_float","value"),&_File::store_float);
|
|
|
|
ClassDB::bind_method(_MD("store_double","value"),&_File::store_double);
|
|
|
|
ClassDB::bind_method(_MD("store_real","value"),&_File::store_real);
|
|
|
|
ClassDB::bind_method(_MD("store_buffer","buffer"),&_File::store_buffer);
|
|
|
|
ClassDB::bind_method(_MD("store_line","line"),&_File::store_line);
|
|
|
|
ClassDB::bind_method(_MD("store_string","string"),&_File::store_string);
|
|
|
|
ClassDB::bind_method(_MD("store_var","value"),&_File::store_var);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("store_pascal_string","string"),&_File::store_pascal_string);
|
|
|
|
ClassDB::bind_method(_MD("get_pascal_string"),&_File::get_pascal_string);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("file_exists","path"),&_File::file_exists);
|
2017-01-23 22:33:02 +01:00
|
|
|
ClassDB::bind_method(_MD("get_modified_time", "file"),&_File::get_modified_time);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BIND_CONSTANT( READ );
|
|
|
|
BIND_CONSTANT( WRITE );
|
|
|
|
BIND_CONSTANT( READ_WRITE );
|
2016-01-10 19:15:04 +01:00
|
|
|
BIND_CONSTANT( WRITE_READ );
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_File::_File(){
|
|
|
|
|
|
|
|
f = NULL;
|
|
|
|
eswap=false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_File::~_File(){
|
|
|
|
|
|
|
|
if (f)
|
|
|
|
memdelete(f);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Error _Directory::open(const String& p_path) {
|
|
|
|
Error err;
|
|
|
|
DirAccess *alt=DirAccess::open(p_path,&err);
|
|
|
|
|
|
|
|
if (!alt)
|
|
|
|
return err;
|
|
|
|
if (d)
|
|
|
|
memdelete(d);
|
|
|
|
d=alt;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-01-14 13:16:41 +01:00
|
|
|
Error _Directory::list_dir_begin() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-14 13:16:41 +01:00
|
|
|
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
|
2014-02-10 02:10:30 +01:00
|
|
|
return d->list_dir_begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
String _Directory::get_next(){
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,"");
|
|
|
|
return d->get_next();
|
|
|
|
}
|
|
|
|
bool _Directory::current_is_dir() const{
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,false);
|
|
|
|
return d->current_is_dir();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _Directory::list_dir_end(){
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!d);
|
|
|
|
return d->list_dir_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
int _Directory::get_drive_count(){
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,0);
|
|
|
|
return d->get_drive_count();
|
|
|
|
}
|
|
|
|
String _Directory::get_drive(int p_drive){
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,"");
|
|
|
|
return d->get_drive(p_drive);
|
|
|
|
}
|
2017-01-14 17:01:43 +01:00
|
|
|
int _Directory::get_current_drive() {
|
2017-01-14 18:47:06 +01:00
|
|
|
ERR_FAIL_COND_V(!d,0);
|
2017-01-14 17:01:43 +01:00
|
|
|
return d->get_current_drive();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Error _Directory::change_dir(String p_dir){
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
|
|
|
|
return d->change_dir(p_dir);
|
|
|
|
}
|
|
|
|
String _Directory::get_current_dir() {
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,"");
|
|
|
|
return d->get_current_dir();
|
|
|
|
}
|
|
|
|
Error _Directory::make_dir(String p_dir){
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
|
2016-06-18 17:11:48 +02:00
|
|
|
if (!p_dir.is_rel_path()) {
|
|
|
|
DirAccess *d = DirAccess::create_for_path(p_dir);
|
|
|
|
Error err = d->make_dir(p_dir);
|
|
|
|
memdelete(d);
|
|
|
|
return err;
|
|
|
|
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
return d->make_dir(p_dir);
|
|
|
|
}
|
|
|
|
Error _Directory::make_dir_recursive(String p_dir){
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
|
2016-08-08 23:20:16 +02:00
|
|
|
if (!p_dir.is_rel_path()) {
|
|
|
|
DirAccess *d = DirAccess::create_for_path(p_dir);
|
|
|
|
Error err = d->make_dir_recursive(p_dir);
|
|
|
|
memdelete(d);
|
|
|
|
return err;
|
|
|
|
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
return d->make_dir_recursive(p_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _Directory::file_exists(String p_file){
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,false);
|
2016-06-18 17:11:48 +02:00
|
|
|
|
|
|
|
if (!p_file.is_rel_path()) {
|
|
|
|
return FileAccess::exists(p_file);
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return d->file_exists(p_file);
|
|
|
|
}
|
|
|
|
|
2014-05-25 05:34:51 +02:00
|
|
|
bool _Directory::dir_exists(String p_dir) {
|
|
|
|
ERR_FAIL_COND_V(!d,false);
|
2016-06-18 17:11:48 +02:00
|
|
|
if (!p_dir.is_rel_path()) {
|
|
|
|
|
|
|
|
DirAccess *d = DirAccess::create_for_path(p_dir);
|
|
|
|
bool exists = d->dir_exists(p_dir);
|
|
|
|
memdelete(d);
|
|
|
|
return exists;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return d->dir_exists(p_dir);
|
|
|
|
}
|
2014-05-25 05:34:51 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int _Directory::get_space_left(){
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,0);
|
2016-06-18 16:32:45 +02:00
|
|
|
return d->get_space_left()/1024*1024; //return value in megabytes, given binding is int
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Error _Directory::copy(String p_from,String p_to){
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
|
|
|
|
return d->copy(p_from,p_to);
|
|
|
|
}
|
|
|
|
Error _Directory::rename(String p_from, String p_to){
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
|
2016-06-18 17:11:48 +02:00
|
|
|
if (!p_from.is_rel_path()) {
|
|
|
|
DirAccess *d = DirAccess::create_for_path(p_from);
|
|
|
|
Error err = d->rename(p_from,p_to);
|
|
|
|
memdelete(d);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return d->rename(p_from,p_to);
|
|
|
|
|
|
|
|
}
|
|
|
|
Error _Directory::remove(String p_name){
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
|
2016-06-18 17:11:48 +02:00
|
|
|
if (!p_name.is_rel_path()) {
|
|
|
|
DirAccess *d = DirAccess::create_for_path(p_name);
|
|
|
|
Error err = d->remove(p_name);
|
|
|
|
memdelete(d);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return d->remove(p_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _Directory::_bind_methods() {
|
|
|
|
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("open:Error","path"),&_Directory::open);
|
|
|
|
ClassDB::bind_method(_MD("list_dir_begin"),&_Directory::list_dir_begin);
|
|
|
|
ClassDB::bind_method(_MD("get_next"),&_Directory::get_next);
|
|
|
|
ClassDB::bind_method(_MD("current_is_dir"),&_Directory::current_is_dir);
|
|
|
|
ClassDB::bind_method(_MD("list_dir_end"),&_Directory::list_dir_end);
|
|
|
|
ClassDB::bind_method(_MD("get_drive_count"),&_Directory::get_drive_count);
|
|
|
|
ClassDB::bind_method(_MD("get_drive","idx"),&_Directory::get_drive);
|
2017-01-14 17:01:43 +01:00
|
|
|
ClassDB::bind_method(_MD("get_current_drive"),&_Directory::get_current_drive);
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("change_dir:Error","todir"),&_Directory::change_dir);
|
|
|
|
ClassDB::bind_method(_MD("get_current_dir"),&_Directory::get_current_dir);
|
|
|
|
ClassDB::bind_method(_MD("make_dir:Error","path"),&_Directory::make_dir);
|
|
|
|
ClassDB::bind_method(_MD("make_dir_recursive:Error","path"),&_Directory::make_dir_recursive);
|
|
|
|
ClassDB::bind_method(_MD("file_exists","path"),&_Directory::file_exists);
|
|
|
|
ClassDB::bind_method(_MD("dir_exists","path"),&_Directory::dir_exists);
|
2017-01-14 12:26:56 +01:00
|
|
|
//ClassDB::bind_method(_MD("get_modified_time","file"),&_Directory::get_modified_time);
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("get_space_left"),&_Directory::get_space_left);
|
|
|
|
ClassDB::bind_method(_MD("copy:Error","from","to"),&_Directory::copy);
|
|
|
|
ClassDB::bind_method(_MD("rename:Error","from","to"),&_Directory::rename);
|
|
|
|
ClassDB::bind_method(_MD("remove:Error","path"),&_Directory::remove);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_Directory::_Directory() {
|
|
|
|
|
|
|
|
d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
_Directory::~_Directory() {
|
|
|
|
|
|
|
|
if (d)
|
|
|
|
memdelete(d);
|
|
|
|
}
|
|
|
|
|
2016-11-05 17:13:04 +01:00
|
|
|
_Marshalls* _Marshalls::singleton=NULL;
|
|
|
|
|
|
|
|
_Marshalls *_Marshalls::get_singleton()
|
|
|
|
{
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String _Marshalls::variant_to_base64(const Variant& p_var) {
|
|
|
|
|
|
|
|
int len;
|
|
|
|
Error err = encode_variant(p_var,NULL,len);
|
|
|
|
ERR_FAIL_COND_V( err != OK, "" );
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> buff;
|
2014-02-10 02:10:30 +01:00
|
|
|
buff.resize(len);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write w = buff.write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
err = encode_variant(p_var,&w[0],len);
|
|
|
|
ERR_FAIL_COND_V( err != OK, "" );
|
|
|
|
|
2014-06-11 15:41:03 +02:00
|
|
|
int b64len = len / 3 * 4 + 4 + 1;
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> b64buff;
|
2014-02-10 02:10:30 +01:00
|
|
|
b64buff.resize(b64len);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write w64 = b64buff.write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int strlen = base64_encode((char*)(&w64[0]), (char*)(&w[0]), len);
|
|
|
|
//OS::get_singleton()->print("len is %i, vector size is %i\n", b64len, strlen);
|
|
|
|
w64[strlen] = 0;
|
|
|
|
String ret = (char*)&w64[0];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
Variant _Marshalls::base64_to_variant(const String& p_str) {
|
|
|
|
|
|
|
|
int strlen = p_str.length();
|
|
|
|
CharString cstr = p_str.ascii();
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> buf;
|
2014-06-11 15:41:03 +02:00
|
|
|
buf.resize(strlen / 4 * 3 + 1);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write w = buf.write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen);
|
|
|
|
|
|
|
|
Variant v;
|
|
|
|
Error err = decode_variant(v, &w[0], len);
|
|
|
|
ERR_FAIL_COND_V( err!=OK, Variant() );
|
|
|
|
|
|
|
|
return v;
|
|
|
|
};
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
String _Marshalls::raw_to_base64(const PoolVector<uint8_t> &p_arr) {
|
2015-07-28 12:50:52 +02:00
|
|
|
|
|
|
|
int len = p_arr.size();
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Read r = p_arr.read();
|
2015-07-28 12:50:52 +02:00
|
|
|
|
|
|
|
int b64len = len / 3 * 4 + 4 + 1;
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> b64buff;
|
2015-07-28 12:50:52 +02:00
|
|
|
b64buff.resize(b64len);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write w64 = b64buff.write();
|
2015-07-28 12:50:52 +02:00
|
|
|
|
|
|
|
int strlen = base64_encode((char*)(&w64[0]), (char*)(&r[0]), len);
|
|
|
|
w64[strlen] = 0;
|
|
|
|
String ret = (char*)&w64[0];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) {
|
2015-07-28 12:50:52 +02:00
|
|
|
|
|
|
|
int strlen = p_str.length();
|
|
|
|
CharString cstr = p_str.ascii();
|
|
|
|
|
|
|
|
int arr_len;
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> buf;
|
2015-07-28 12:50:52 +02:00
|
|
|
{
|
|
|
|
buf.resize(strlen / 4 * 3 + 1);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write w = buf.write();
|
2015-07-28 12:50:52 +02:00
|
|
|
|
|
|
|
arr_len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen);
|
|
|
|
};
|
|
|
|
buf.resize(arr_len);
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
// conversion from PoolVector<uint8_t> to raw array?
|
2015-07-28 12:50:52 +02:00
|
|
|
return buf;
|
|
|
|
};
|
|
|
|
|
|
|
|
String _Marshalls::utf8_to_base64(const String& p_str) {
|
|
|
|
|
|
|
|
CharString cstr = p_str.utf8();
|
|
|
|
int len = cstr.length();
|
|
|
|
|
|
|
|
int b64len = len / 3 * 4 + 4 + 1;
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> b64buff;
|
2015-07-28 12:50:52 +02:00
|
|
|
b64buff.resize(b64len);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write w64 = b64buff.write();
|
2015-07-28 12:50:52 +02:00
|
|
|
|
|
|
|
int strlen = base64_encode((char*)(&w64[0]), (char*)cstr.get_data(), len);
|
|
|
|
|
|
|
|
w64[strlen] = 0;
|
|
|
|
String ret = (char*)&w64[0];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
String _Marshalls::base64_to_utf8(const String& p_str) {
|
|
|
|
|
|
|
|
int strlen = p_str.length();
|
|
|
|
CharString cstr = p_str.ascii();
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> buf;
|
2015-07-28 12:50:52 +02:00
|
|
|
buf.resize(strlen / 4 * 3 + 1 + 1);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write w = buf.write();
|
2015-07-28 12:50:52 +02:00
|
|
|
|
|
|
|
int len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen);
|
|
|
|
|
|
|
|
w[len] = 0;
|
|
|
|
String ret = String::utf8((char*)&w[0]);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void _Marshalls::_bind_methods() {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("variant_to_base64:String","variant"),&_Marshalls::variant_to_base64);
|
|
|
|
ClassDB::bind_method(_MD("base64_to_variant:Variant","base64_str"),&_Marshalls::base64_to_variant);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("raw_to_base64:String","array"),&_Marshalls::raw_to_base64);
|
|
|
|
ClassDB::bind_method(_MD("base64_to_raw:RawArray","base64_str"),&_Marshalls::base64_to_raw);
|
2015-07-28 12:50:52 +02:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("utf8_to_base64:String","utf8_str"),&_Marshalls::utf8_to_base64);
|
|
|
|
ClassDB::bind_method(_MD("base64_to_utf8:String","base64_str"),&_Marshalls::base64_to_utf8);
|
2015-07-28 12:50:52 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Error _Semaphore::wait() {
|
|
|
|
|
|
|
|
return semaphore->wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error _Semaphore::post() {
|
|
|
|
|
|
|
|
return semaphore->post();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _Semaphore::_bind_methods() {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("wait:Error"),&_Semaphore::wait);
|
|
|
|
ClassDB::bind_method(_MD("post:Error"),&_Semaphore::post);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_Semaphore::_Semaphore() {
|
|
|
|
|
|
|
|
semaphore =Semaphore::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
_Semaphore::~_Semaphore(){
|
|
|
|
|
|
|
|
memdelete(semaphore);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
|
|
|
|
|
|
|
|
void _Mutex::lock() {
|
|
|
|
|
|
|
|
mutex->lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error _Mutex::try_lock(){
|
|
|
|
|
|
|
|
return mutex->try_lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _Mutex::unlock(){
|
|
|
|
|
|
|
|
mutex->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _Mutex::_bind_methods() {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("lock"),&_Mutex::lock);
|
|
|
|
ClassDB::bind_method(_MD("try_lock:Error"),&_Mutex::try_lock);
|
|
|
|
ClassDB::bind_method(_MD("unlock"),&_Mutex::unlock);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_Mutex::_Mutex() {
|
|
|
|
|
|
|
|
mutex =Mutex::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
_Mutex::~_Mutex(){
|
|
|
|
|
|
|
|
memdelete(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _Thread::_start_func(void *ud) {
|
|
|
|
|
2015-05-18 17:45:53 +02:00
|
|
|
Ref<_Thread>* tud=(Ref<_Thread>*)ud;
|
|
|
|
Ref<_Thread> t=*tud;
|
|
|
|
memdelete(tud);
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant::CallError ce;
|
|
|
|
const Variant* arg[1]={&t->userdata};
|
2015-06-29 05:29:49 +02:00
|
|
|
|
2016-02-01 00:22:38 +01:00
|
|
|
Thread::set_name(t->target_method);
|
2015-12-18 07:06:51 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
t->ret=t->target_instance->call(t->target_method,arg,1,ce);
|
|
|
|
if (ce.error!=Variant::CallError::CALL_OK) {
|
|
|
|
|
|
|
|
String reason;
|
|
|
|
switch(ce.error) {
|
|
|
|
case Variant::CallError::CALL_ERROR_INVALID_ARGUMENT: {
|
|
|
|
|
|
|
|
reason="Invalid Argument #"+itos(ce.argument);
|
|
|
|
} break;
|
|
|
|
case Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: {
|
|
|
|
|
|
|
|
reason="Too Many Arguments";
|
|
|
|
} break;
|
|
|
|
case Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: {
|
|
|
|
|
|
|
|
reason="Too Many Arguments";
|
|
|
|
} break;
|
|
|
|
case Variant::CallError::CALL_ERROR_INVALID_METHOD: {
|
|
|
|
|
|
|
|
reason="Method Not Found";
|
|
|
|
} break;
|
|
|
|
default: {}
|
|
|
|
}
|
|
|
|
|
2015-06-29 05:29:49 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_EXPLAIN("Could not call function '"+t->target_method.operator String()+"'' starting thread ID: "+t->get_id()+" Reason: "+reason);
|
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Error _Thread::start(Object *p_instance,const StringName& p_method,const Variant& p_userdata,int p_priority) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(active,ERR_ALREADY_IN_USE);
|
|
|
|
ERR_FAIL_COND_V(!p_instance,ERR_INVALID_PARAMETER);
|
|
|
|
ERR_FAIL_COND_V(p_method==StringName(),ERR_INVALID_PARAMETER);
|
|
|
|
ERR_FAIL_INDEX_V(p_priority,3,ERR_INVALID_PARAMETER);
|
|
|
|
|
|
|
|
|
|
|
|
ret=Variant();
|
|
|
|
target_method=p_method;
|
|
|
|
target_instance=p_instance;
|
|
|
|
userdata=p_userdata;
|
|
|
|
active=true;
|
|
|
|
|
2015-05-18 17:45:53 +02:00
|
|
|
Ref<_Thread> *ud = memnew( Ref<_Thread>(this) );
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Thread::Settings s;
|
|
|
|
s.priority=(Thread::Priority)p_priority;
|
2015-05-18 17:45:53 +02:00
|
|
|
thread = Thread::create(_start_func,ud,s);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!thread) {
|
|
|
|
active=false;
|
|
|
|
target_method=StringName();
|
|
|
|
target_instance=NULL;
|
|
|
|
userdata=Variant();
|
|
|
|
return ERR_CANT_CREATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
String _Thread::get_id() const {
|
|
|
|
|
|
|
|
if (!thread)
|
|
|
|
return String();
|
|
|
|
|
|
|
|
return itos(thread->get_ID());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _Thread::is_active() const {
|
|
|
|
|
|
|
|
return active;
|
|
|
|
}
|
|
|
|
Variant _Thread::wait_to_finish() {
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!thread,Variant());
|
|
|
|
ERR_FAIL_COND_V(!active,Variant());
|
|
|
|
Thread::wait_to_finish(thread);
|
|
|
|
Variant r = ret;
|
|
|
|
active=false;
|
|
|
|
target_method=StringName();
|
|
|
|
target_instance=NULL;
|
|
|
|
userdata=Variant();
|
|
|
|
thread=NULL;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _Thread::_bind_methods() {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("start:Error","instance","method","userdata","priority"),&_Thread::start,DEFVAL(Variant()),DEFVAL(PRIORITY_NORMAL));
|
|
|
|
ClassDB::bind_method(_MD("get_id"),&_Thread::get_id);
|
|
|
|
ClassDB::bind_method(_MD("is_active"),&_Thread::is_active);
|
|
|
|
ClassDB::bind_method(_MD("wait_to_finish:Variant"),&_Thread::wait_to_finish);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BIND_CONSTANT( PRIORITY_LOW );
|
|
|
|
BIND_CONSTANT( PRIORITY_NORMAL );
|
|
|
|
BIND_CONSTANT( PRIORITY_HIGH );
|
|
|
|
|
|
|
|
}
|
|
|
|
_Thread::_Thread() {
|
|
|
|
|
|
|
|
active=false;
|
|
|
|
thread=NULL;
|
|
|
|
target_instance=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
_Thread::~_Thread() {
|
|
|
|
|
2015-05-18 17:45:53 +02:00
|
|
|
if (active) {
|
2015-05-20 04:37:04 +02:00
|
|
|
ERR_EXPLAIN("Reference to a Thread object object was lost while the thread is still running..");
|
2015-05-18 17:45:53 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(active==true);
|
|
|
|
}
|
2017-01-03 03:03:46 +01:00
|
|
|
/////////////////////////////////////
|
|
|
|
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
PoolStringArray _ClassDB::get_class_list() const {
|
2017-01-03 03:03:46 +01:00
|
|
|
|
|
|
|
List<StringName> classes;
|
|
|
|
ClassDB::get_class_list(&classes);
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
PoolStringArray ret;
|
2017-01-03 03:03:46 +01:00
|
|
|
ret.resize(classes.size());
|
|
|
|
int idx=0;
|
|
|
|
for (List<StringName>::Element *E=classes.front();E;E=E->next()) {
|
|
|
|
ret.set(idx++,E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
2017-01-11 04:52:51 +01:00
|
|
|
PoolStringArray _ClassDB::get_inheriters_from_class( const StringName& p_class) const {
|
2017-01-03 03:03:46 +01:00
|
|
|
|
|
|
|
List<StringName> classes;
|
|
|
|
ClassDB::get_inheriters_from_class(p_class,&classes);
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
PoolStringArray ret;
|
2017-01-03 03:03:46 +01:00
|
|
|
ret.resize(classes.size());
|
|
|
|
int idx=0;
|
|
|
|
for (List<StringName>::Element *E=classes.front();E;E=E->next()) {
|
|
|
|
ret.set(idx++,E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
StringName _ClassDB::get_parent_class(const StringName& p_class) const {
|
|
|
|
|
|
|
|
return ClassDB::get_parent_class(p_class);
|
|
|
|
}
|
|
|
|
bool _ClassDB::class_exists(const StringName &p_class) const {
|
|
|
|
|
|
|
|
return ClassDB::class_exists(p_class);
|
|
|
|
}
|
|
|
|
bool _ClassDB::is_parent_class(const StringName &p_class,const StringName& p_inherits) const {
|
|
|
|
|
|
|
|
return ClassDB::is_parent_class(p_class,p_inherits);
|
|
|
|
}
|
|
|
|
bool _ClassDB::can_instance(const StringName &p_class) const {
|
|
|
|
|
|
|
|
return ClassDB::can_instance(p_class);
|
|
|
|
}
|
|
|
|
Variant _ClassDB::instance(const StringName &p_class) const {
|
|
|
|
|
|
|
|
Object *obj = ClassDB::instance(p_class);
|
|
|
|
if (!obj)
|
|
|
|
return Variant();
|
|
|
|
|
|
|
|
Reference *r = obj->cast_to<Reference>();
|
|
|
|
if (r) {
|
|
|
|
return REF(r);
|
|
|
|
} else {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _ClassDB::has_signal(StringName p_class,StringName p_signal) const {
|
|
|
|
|
|
|
|
return ClassDB::has_signal(p_class,p_signal);
|
|
|
|
}
|
|
|
|
Dictionary _ClassDB::get_signal(StringName p_class,StringName p_signal) const {
|
|
|
|
|
|
|
|
MethodInfo signal;
|
|
|
|
if (ClassDB::get_signal(p_class,p_signal,&signal)) {
|
|
|
|
return signal.operator Dictionary();
|
|
|
|
} else {
|
|
|
|
return Dictionary();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
Array _ClassDB::get_signal_list(StringName p_class,bool p_no_inheritance) const {
|
|
|
|
|
|
|
|
List<MethodInfo> signals;
|
|
|
|
ClassDB::get_signal_list(p_class,&signals,p_no_inheritance);
|
|
|
|
Array ret;
|
|
|
|
|
|
|
|
for (List<MethodInfo>::Element *E=signals.front();E;E=E->next()) {
|
|
|
|
ret.push_back(E->get().operator Dictionary());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) const {
|
|
|
|
|
|
|
|
List<PropertyInfo> plist;
|
|
|
|
ClassDB::get_property_list(p_class,&plist,p_no_inheritance);
|
|
|
|
Array ret;
|
|
|
|
for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
|
|
|
|
ret.push_back(E->get().operator Dictionary());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _ClassDB::has_method(StringName p_class,StringName p_method,bool p_no_inheritance) const {
|
|
|
|
|
|
|
|
return ClassDB::has_method(p_class,p_method,p_no_inheritance);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Array _ClassDB::get_method_list(StringName p_class,bool p_no_inheritance) const {
|
|
|
|
|
|
|
|
List<MethodInfo> methods;
|
|
|
|
ClassDB::get_method_list(p_class,&methods,p_no_inheritance);
|
|
|
|
Array ret;
|
|
|
|
|
|
|
|
for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
|
|
|
|
ret.push_back(E->get().operator Dictionary());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
PoolStringArray _ClassDB::get_integer_constant_list(const StringName& p_class, bool p_no_inheritance) const {
|
2017-01-03 03:03:46 +01:00
|
|
|
|
|
|
|
List<String> constants;
|
|
|
|
ClassDB::get_integer_constant_list(p_class,&constants,p_no_inheritance);
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
PoolStringArray ret;
|
2017-01-03 03:03:46 +01:00
|
|
|
ret.resize(constants.size());
|
|
|
|
int idx=0;
|
|
|
|
for (List<String>::Element *E=constants.front();E;E=E->next()) {
|
|
|
|
ret.set(idx++,E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _ClassDB::has_integer_constant(const StringName& p_class, const StringName &p_name) const {
|
|
|
|
|
|
|
|
bool success;
|
|
|
|
ClassDB::get_integer_constant(p_class,p_name,&success);
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
int _ClassDB::get_integer_constant(const StringName& p_class, const StringName &p_name) const {
|
|
|
|
|
|
|
|
bool found;
|
|
|
|
int c = ClassDB::get_integer_constant(p_class,p_name,&found);
|
|
|
|
ERR_FAIL_COND_V(!found,0);
|
|
|
|
return c;
|
|
|
|
|
|
|
|
}
|
|
|
|
StringName _ClassDB::get_category(const StringName& p_node) const {
|
|
|
|
|
|
|
|
return ClassDB::get_category(p_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _ClassDB::is_class_enabled(StringName p_class) const {
|
|
|
|
|
|
|
|
return ClassDB::is_class_enabled(p_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _ClassDB::_bind_methods() {
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("get_class_list"),&_ClassDB::get_class_list);
|
|
|
|
ClassDB::bind_method(_MD("get_inheriters_from_class","class"),&_ClassDB::get_inheriters_from_class);
|
|
|
|
ClassDB::bind_method(_MD("get_parent_class","class"),&_ClassDB::get_parent_class);
|
|
|
|
ClassDB::bind_method(_MD("class_exists","class"),&_ClassDB::class_exists);
|
|
|
|
ClassDB::bind_method(_MD("is_parent_class","class","inherits"),&_ClassDB::is_parent_class);
|
|
|
|
ClassDB::bind_method(_MD("can_instance","class"),&_ClassDB::can_instance);
|
|
|
|
ClassDB::bind_method(_MD("instance","class"),&_ClassDB::instance);
|
|
|
|
|
2017-01-14 15:07:57 +01:00
|
|
|
ClassDB::bind_method(_MD("class_has_signal","class","signal"),&_ClassDB::has_signal);
|
|
|
|
ClassDB::bind_method(_MD("class_get_signal","class","signal"),&_ClassDB::get_signal);
|
|
|
|
ClassDB::bind_method(_MD("class_get_signal_list","class","no_inheritance"),&_ClassDB::get_signal_list,DEFVAL(false));
|
2017-01-03 03:03:46 +01:00
|
|
|
|
2017-01-14 15:07:57 +01:00
|
|
|
ClassDB::bind_method(_MD("class_get_property_list","class","no_inheritance"),&_ClassDB::get_property_list,DEFVAL(false));
|
2017-01-03 03:03:46 +01:00
|
|
|
|
2017-01-14 15:07:57 +01:00
|
|
|
ClassDB::bind_method(_MD("class_has_method","class","method","no_inheritance"),&_ClassDB::has_method,DEFVAL(false));
|
2017-01-03 03:03:46 +01:00
|
|
|
|
2017-01-14 15:07:57 +01:00
|
|
|
ClassDB::bind_method(_MD("class_get_method_list","class","no_inheritance"),&_ClassDB::get_method_list,DEFVAL(false));
|
2017-01-03 03:03:46 +01:00
|
|
|
|
2017-01-14 15:07:57 +01:00
|
|
|
ClassDB::bind_method(_MD("class_get_integer_constant_list","class","no_inheritance"),&_ClassDB::get_integer_constant_list,DEFVAL(false));
|
2017-01-03 03:03:46 +01:00
|
|
|
|
2017-01-14 15:07:57 +01:00
|
|
|
ClassDB::bind_method(_MD("class_has_integer_constant","class","name"),&_ClassDB::has_integer_constant);
|
|
|
|
ClassDB::bind_method(_MD("class_get_integer_constant","class","name"),&_ClassDB::get_integer_constant);
|
2017-01-03 03:03:46 +01:00
|
|
|
|
2017-01-14 15:07:57 +01:00
|
|
|
ClassDB::bind_method(_MD("class_get_category","class"),&_ClassDB::get_category);
|
2017-01-03 03:03:46 +01:00
|
|
|
ClassDB::bind_method(_MD("is_class_enabled","class"),&_ClassDB::is_class_enabled);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ClassDB::_ClassDB(){
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
_ClassDB::~_ClassDB(){
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-01-13 16:51:14 +01:00
|
|
|
///////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
void _Engine::set_iterations_per_second(int p_ips) {
|
|
|
|
|
|
|
|
Engine::get_singleton()->set_iterations_per_second(p_ips);
|
|
|
|
}
|
|
|
|
int _Engine::get_iterations_per_second() const {
|
|
|
|
|
|
|
|
return Engine::get_singleton()->get_iterations_per_second();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void _Engine::set_target_fps(int p_fps) {
|
|
|
|
Engine::get_singleton()->set_target_fps(p_fps);
|
|
|
|
}
|
|
|
|
|
|
|
|
float _Engine::get_target_fps() const {
|
|
|
|
return Engine::get_singleton()->get_target_fps();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float _Engine::get_frames_per_second() const {
|
|
|
|
|
|
|
|
return Engine::get_singleton()->get_frames_per_second();
|
|
|
|
}
|
|
|
|
|
|
|
|
String _Engine::get_custom_level() const {
|
|
|
|
|
|
|
|
return Engine::get_singleton()->get_custom_level();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _Engine::set_time_scale(float p_scale) {
|
|
|
|
Engine::get_singleton()->set_time_scale(p_scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
float _Engine::get_time_scale() {
|
|
|
|
|
|
|
|
return Engine::get_singleton()->get_time_scale();
|
|
|
|
}
|
|
|
|
|
|
|
|
int _Engine::get_frames_drawn() {
|
|
|
|
|
|
|
|
return Engine::get_singleton()->get_frames_drawn();
|
|
|
|
}
|
|
|
|
|
|
|
|
MainLoop *_Engine::get_main_loop() const {
|
|
|
|
|
|
|
|
//needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
|
|
|
|
return OS::get_singleton()->get_main_loop();
|
|
|
|
}
|
|
|
|
|
2017-01-13 18:25:43 +01:00
|
|
|
Dictionary _Engine::get_version_info() const {
|
2017-01-13 16:51:14 +01:00
|
|
|
|
2017-01-13 18:25:43 +01:00
|
|
|
return Engine::get_singleton()->get_version_info();
|
2017-01-13 16:51:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _Engine::_bind_methods() {
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_Engine::set_iterations_per_second);
|
|
|
|
ClassDB::bind_method(_MD("get_iterations_per_second"),&_Engine::get_iterations_per_second);
|
|
|
|
ClassDB::bind_method(_MD("set_target_fps","target_fps"),&_Engine::set_target_fps);
|
|
|
|
ClassDB::bind_method(_MD("get_target_fps"),&_Engine::get_target_fps);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("set_time_scale","time_scale"),&_Engine::set_time_scale);
|
|
|
|
ClassDB::bind_method(_MD("get_time_scale"),&_Engine::get_time_scale);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("get_custom_level"),&_Engine::get_custom_level);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("get_frames_drawn"),&_Engine::get_frames_drawn);
|
|
|
|
ClassDB::bind_method(_MD("get_frames_per_second"),&_Engine::get_frames_per_second);
|
|
|
|
|
|
|
|
ClassDB::bind_method(_MD("get_main_loop:MainLoop"),&_Engine::get_main_loop);
|
|
|
|
|
2017-01-13 18:25:43 +01:00
|
|
|
ClassDB::bind_method(_MD("get_version_info"),&_Engine::get_version_info);
|
2017-01-13 16:51:14 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_Engine *_Engine::singleton = NULL;
|
|
|
|
|
|
|
|
_Engine::_Engine() {
|
|
|
|
singleton=this;
|
|
|
|
}
|