diff options
Diffstat (limited to 'modules')
45 files changed, 954 insertions, 734 deletions
diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index 98ae82bc5f..f5ab8221e3 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -511,12 +511,14 @@ void RigidBodyBullet::set_mode(PhysicsServer::BodyMode p_mode) { mode = PhysicsServer::BODY_MODE_RIGID; set_axis_lock(axis_lock); // Reload axis lock _internal_set_mass(0 == mass ? 1 : mass); + scratch_space_override_modificator(); break; } case PhysicsServer::BODY_MODE_CHARACTER: { mode = PhysicsServer::BODY_MODE_CHARACTER; set_axis_lock(axis_lock); // Reload axis lock _internal_set_mass(0 == mass ? 1 : mass); + scratch_space_override_modificator(); break; } } diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index e4d049b00d..853906063b 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -175,13 +175,13 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf space->dynamicsWorld->convexSweepTest(bt_convex_shape, bt_xform_from, bt_xform_to, btResult, 0.002); - if (r_info) { - if (btResult.hasHit()) { + if (btResult.hasHit()) { + p_closest_safe = p_closest_unsafe = btResult.m_closestHitFraction; + if (r_info) { if (btCollisionObject::CO_RIGID_BODY == btResult.m_hitCollisionObject->getInternalType()) { B_TO_G(static_cast<const btRigidBody *>(btResult.m_hitCollisionObject)->getVelocityInLocalPoint(btResult.m_hitPointWorld), r_info->linear_velocity); } CollisionObjectBullet *collision_object = static_cast<CollisionObjectBullet *>(btResult.m_hitCollisionObject->getUserPointer()); - p_closest_safe = p_closest_unsafe = btResult.m_closestHitFraction; B_TO_G(btResult.m_hitPointWorld, r_info->point); B_TO_G(btResult.m_hitNormalWorld, r_info->normal); r_info->rid = collision_object->get_self(); diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp index dc7d23bbd7..941df41694 100644 --- a/modules/etc/image_etc.cpp +++ b/modules/etc/image_etc.cpp @@ -129,7 +129,7 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f PoolVector<uint8_t>::Read r = img->get_data().read(); int target_size = Image::get_image_data_size(imgw, imgh, etc_format, p_img->has_mipmaps() ? -1 : 0); - int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0; + int mmc = 1 + (p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0); PoolVector<uint8_t> dst_data; dst_data.resize(target_size); @@ -155,7 +155,7 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f print_line("begin encoding, format: " + Image::get_format_name(etc_format)); uint64_t t = OS::get_singleton()->get_ticks_msec(); - for (int i = 0; i < mmc + 1; i++) { + for (int i = 0; i < mmc; i++) { // convert source image to internal etc2comp format (which is equivalent to Image::FORMAT_RGBAF) // NOTE: We can alternatively add a case to Image::convert to handle Image::FORMAT_RGBAF conversion. int mipmap_ofs = 0, mipmap_size = 0, mipmap_w = 0, mipmap_h = 0; @@ -163,9 +163,9 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f const uint8_t *src = &r[mipmap_ofs]; Etc::ColorFloatRGBA *src_rgba_f = new Etc::ColorFloatRGBA[mipmap_w * mipmap_h]; - for (int i = 0; i < mipmap_w * mipmap_h; i++) { - int si = i * 4; // RGBA8 - src_rgba_f[i] = Etc::ColorFloatRGBA::ConvertFromRGBA8(src[si], src[si + 1], src[si + 2], src[si + 3]); + for (int j = 0; j < mipmap_w * mipmap_h; j++) { + int si = j * 4; // RGBA8 + src_rgba_f[j] = Etc::ColorFloatRGBA::ConvertFromRGBA8(src[si], src[si + 1], src[si + 2], src[si + 3]); } unsigned char *etc_data = NULL; @@ -173,15 +173,17 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f unsigned int extended_width = 0, extended_height = 0; Etc::Encode((float *)src_rgba_f, mipmap_w, mipmap_h, etc2comp_etc_format, error_metric, effort, num_cpus, num_cpus, &etc_data, &etc_data_len, &extended_width, &extended_height, &encoding_time); + CRASH_COND(wofs + etc_data_len > target_size); memcpy(&w[wofs], etc_data, etc_data_len); wofs += etc_data_len; delete[] etc_data; delete[] src_rgba_f; } + print_line("time encoding: " + rtos(OS::get_singleton()->get_ticks_msec() - t)); - p_img->create(imgw, imgh, mmc > 1 ? true : false, etc_format, dst_data); + p_img->create(imgw, imgh, p_img->has_mipmaps(), etc_format, dst_data); } static void _compress_etc1(Image *p_img, float p_lossy_quality) { diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index 66b8d5cbdd..54d0672a5b 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -19,19 +19,27 @@ def _spaced(e): return e if e[-1] == '*' else e + ' ' def _build_gdnative_api_struct_header(api): - ext_wrappers = '' + gdnative_api_init_macro = [ + '\textern const godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct;' + ] for name in api['extensions']: - ext_wrappers += ' extern const godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct;' + gdnative_api_init_macro.append( + '\textern const godot_gdnative_ext_{0}_api_struct *_gdnative_wrapper_{0}_api_struct;'.format(name)) - ext_init = 'for (int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { ' - ext_init += 'switch (_gdnative_wrapper_api_struct->extensions[i]->type) {' + gdnative_api_init_macro.append('\t_gdnative_wrapper_api_struct = options->api_struct;') + gdnative_api_init_macro.append('\tfor (int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { ') + gdnative_api_init_macro.append('\t\tswitch (_gdnative_wrapper_api_struct->extensions[i]->type) {') for name in api['extensions']: - ext_init += 'case GDNATIVE_EXT_' + api['extensions'][name]['type'] + ': ' - ext_init += '_gdnative_wrapper_' + name + '_api_struct = (' + 'godot_gdnative_ext_' + name + '_api_struct *) _gdnative_wrapper_api_struct->extensions[i]; break;' - - ext_init += '}' + gdnative_api_init_macro.append( + '\t\t\tcase GDNATIVE_EXT_%s:' % api['extensions'][name]['type']) + gdnative_api_init_macro.append( + '\t\t\t\t_gdnative_wrapper_{0}_api_struct = (godot_gdnative_ext_{0}_api_struct *)' + ' _gdnative_wrapper_api_struct->extensions[i];'.format(name)) + gdnative_api_init_macro.append('\t\t\t\tbreak;') + gdnative_api_init_macro.append('\t\t}') + gdnative_api_init_macro.append('\t}') out = [ '/* THIS FILE IS GENERATED DO NOT EDIT */', @@ -43,25 +51,12 @@ def _build_gdnative_api_struct_header(api): '#include <nativescript/godot_nativescript.h>', '#include <pluginscript/godot_pluginscript.h>', '', - '#define GDNATIVE_API_INIT(options) do { extern const godot_gdnative_api_struct *_gdnative_wrapper_api_struct;' + ext_wrappers + ' _gdnative_wrapper_api_struct = options->api_struct; ' + ext_init + ' } while (0)', + '#define GDNATIVE_API_INIT(options) do { \\\n' + ' \\\n'.join(gdnative_api_init_macro) + ' \\\n } while (0)', '', '#ifdef __cplusplus', 'extern "C" {', '#endif', '', - 'typedef struct godot_gdnative_api_version {', - '\tunsigned int major;', - '\tunsigned int minor;', - '} godot_gdnative_api_version;', - '', - 'typedef struct godot_gdnative_api_struct godot_gdnative_api_struct;', - '', - 'struct godot_gdnative_api_struct {', - '\tunsigned int type;', - '\tgodot_gdnative_api_version version;', - '\tconst godot_gdnative_api_struct *next;', - '};', - '', 'enum GDNATIVE_API_TYPES {', '\tGDNATIVE_' + api['core']['type'] + ',' ] @@ -192,7 +187,7 @@ def _build_gdnative_wrapper_code(api): ] for name in api['extensions']: - out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct;') + out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct = 0;') out += [''] diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 44d6dffc85..0132ef3c5d 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -64,7 +64,6 @@ void GDNativeLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("get_current_library_path"), &GDNativeLibrary::get_current_library_path); ClassDB::bind_method(D_METHOD("get_current_dependencies"), &GDNativeLibrary::get_current_dependencies); - ClassDB::bind_method(D_METHOD("is_current_library_statically_linked"), &GDNativeLibrary::is_current_library_statically_linked); ClassDB::bind_method(D_METHOD("should_load_once"), &GDNativeLibrary::should_load_once); ClassDB::bind_method(D_METHOD("is_singleton"), &GDNativeLibrary::is_singleton); @@ -109,6 +108,9 @@ Ref<GDNativeLibrary> GDNative::get_library() { return library; } +extern "C" void _gdnative_report_version_mismatch(const godot_object *p_library, const char *p_ext, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have); +extern "C" void _gdnative_report_loading_error(const godot_object *p_library, const char *p_what); + bool GDNative::initialize() { if (library.is_null()) { ERR_PRINT("No library set, can't initialize GDNative object"); @@ -116,12 +118,18 @@ bool GDNative::initialize() { } String lib_path = library->get_current_library_path(); - if (lib_path.empty() && !library->is_current_library_statically_linked()) { + if (lib_path.empty()) { ERR_PRINT("No library set for this platform"); return false; } #ifdef IPHONE_ENABLED - String path = lib_path.replace("res://", "dylibs/"); + // on iOS we use static linking + String path = ""; +#elif defined(ANDROID_ENABLED) + // On Android dynamic libraries are located separately from resource assets, + // we should pass library name to dlopen(). The library name is flattened + // during export. + String path = lib_path.get_file(); #else String path = ProjectSettings::get_singleton()->globalize_path(lib_path); #endif @@ -137,7 +145,7 @@ bool GDNative::initialize() { } Error err = OS::get_singleton()->open_dynamic_library(path, native_handle); - if (err != OK && !library->is_current_library_statically_linked()) { + if (err != OK) { return false; } @@ -146,13 +154,12 @@ bool GDNative::initialize() { // we cheat here a little bit. you saw nothing initialized = true; - err = get_symbol(library->get_symbol_prefix() + init_symbol, library_init); + err = get_symbol(library->get_symbol_prefix() + init_symbol, library_init, false); initialized = false; if (err || !library_init) { - if (!library->is_current_library_statically_linked()) - OS::get_singleton()->close_dynamic_library(native_handle); + OS::get_singleton()->close_dynamic_library(native_handle); native_handle = NULL; ERR_PRINT("Failed to obtain godot_gdnative_init symbol"); return false; @@ -168,6 +175,8 @@ bool GDNative::initialize() { options.core_api_hash = ClassDB::get_api_hash(ClassDB::API_CORE); options.editor_api_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR); options.no_api_hash = ClassDB::get_api_hash(ClassDB::API_NONE); + options.report_version_mismatch = &_gdnative_report_version_mismatch; + options.report_loading_error = &_gdnative_report_loading_error; options.gd_native_library = (godot_object *)(get_library().ptr()); options.active_library_path = (godot_string *)&path; @@ -277,7 +286,7 @@ Variant GDNative::call_native(StringName p_native_call_type, StringName p_proced return *(Variant *)&result; } -Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle) { +Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional) { if (!initialized) { ERR_PRINT("No valid library handle, can't get symbol from GDNative object"); @@ -288,7 +297,7 @@ Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle) { native_handle, p_procedure_name, r_handle, - true); + p_optional); return result; } @@ -369,40 +378,8 @@ RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_or } } - bool is_statically_linked = false; - { - - List<String> static_linking_keys; - config->get_section_keys("static_linking", &static_linking_keys); - - for (List<String>::Element *E = static_linking_keys.front(); E; E = E->next()) { - String key = E->get(); - - Vector<String> tags = key.split("."); - - bool skip = false; - - for (int i = 0; i < tags.size(); i++) { - bool has_feature = OS::get_singleton()->has_feature(tags[i]); - - if (!has_feature) { - skip = true; - break; - } - } - - if (skip) { - continue; - } - - is_statically_linked = config->get_value("static_linking", key); - break; - } - } - lib->current_library_path = entry_lib_path; lib->current_dependencies = dependency_paths; - lib->current_library_statically_linked = is_statically_linked; return lib; } diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h index 061dff9267..bb260bdd1b 100644 --- a/modules/gdnative/gdnative.h +++ b/modules/gdnative/gdnative.h @@ -55,7 +55,6 @@ class GDNativeLibrary : public Resource { String current_library_path; Vector<String> current_dependencies; - bool current_library_statically_linked; bool singleton; bool load_once; @@ -75,9 +74,6 @@ public: _FORCE_INLINE_ Vector<String> get_current_dependencies() const { return current_dependencies; } - _FORCE_INLINE_ bool is_current_library_statically_linked() const { - return current_library_statically_linked; - } // things that are a property of the library itself, not platform specific _FORCE_INLINE_ bool should_load_once() const { @@ -103,12 +99,10 @@ public: static void _bind_methods(); }; -typedef godot_variant (*native_call_cb)(void *, godot_array *); - struct GDNativeCallRegistry { static GDNativeCallRegistry *singleton; - inline GDNativeCallRegistry *get_singleton() { + inline static GDNativeCallRegistry *get_singleton() { return singleton; } @@ -147,7 +141,7 @@ public: Variant call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments = Array()); - Error get_symbol(StringName p_procedure_name, void *&r_handle); + Error get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional = true); }; class GDNativeLibraryResourceLoader : public ResourceFormatLoader { diff --git a/modules/gdnative/gdnative/array.cpp b/modules/gdnative/gdnative/array.cpp index e0d9514985..8351c43574 100644 --- a/modules/gdnative/gdnative/array.cpp +++ b/modules/gdnative/gdnative/array.cpp @@ -302,6 +302,17 @@ void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, con self->sort_custom((Object *)p_obj, *func); } +godot_int GDAPI godot_array_bsearch(godot_array *p_self, const godot_variant *p_value, const godot_bool p_before) { + Array *self = (Array *)p_self; + return self->bsearch((const Variant *)p_value, p_before); +} + +godot_int GDAPI godot_array_bsearch_custom(godot_array *p_self, const godot_variant *p_value, godot_object *p_obj, const godot_string *p_func, const godot_bool p_before) { + Array *self = (Array *)p_self; + const String *func = (const String *)p_func; + return self->bsearch_custom((const Variant *)p_value, (Object *)p_obj, *func, p_before); +} + void GDAPI godot_array_destroy(godot_array *p_self) { ((Array *)p_self)->~Array(); } diff --git a/modules/gdnative/gdnative/gdnative.cpp b/modules/gdnative/gdnative/gdnative.cpp index 6dfa7ec20b..92a88e354b 100644 --- a/modules/gdnative/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative/gdnative.cpp @@ -36,6 +36,8 @@ #include "os/os.h" #include "variant.h" +#include "modules/gdnative/gdnative.h" + #ifdef __cplusplus extern "C" { #endif @@ -113,6 +115,10 @@ godot_dictionary GDAPI godot_get_global_constants() { } // System functions +void GDAPI godot_register_native_call_type(const char *p_call_type, native_call_cb p_callback) { + GDNativeCallRegistry::get_singleton()->register_native_call_type(StringName(p_call_type), p_callback); +} + void GDAPI *godot_alloc(int p_bytes) { return memalloc(p_bytes); } @@ -137,6 +143,32 @@ void GDAPI godot_print(const godot_string *p_message) { print_line(*(String *)p_message); } +void _gdnative_report_version_mismatch(const godot_object *p_library, const char *p_ext, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have) { + String message = "Error loading GDNative file "; + GDNativeLibrary *library = (GDNativeLibrary *)p_library; + + message += library->get_current_library_path() + ": Extension \"" + p_ext + "\" can't be loaded.\n"; + + Dictionary versions; + versions["have_major"] = p_have.major; + versions["have_minor"] = p_have.minor; + versions["want_major"] = p_want.major; + versions["want_minor"] = p_want.minor; + + message += String("Got version {have_major}.{have_minor} but needs {want_major}.{want_minor}!").format(versions); + + _err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr()); +} + +void _gdnative_report_loading_error(const godot_object *p_library, const char *p_what) { + String message = "Error loading GDNative file "; + GDNativeLibrary *library = (GDNativeLibrary *)p_library; + + message += library->get_current_library_path() + ": " + p_what; + + _err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr()); +} + #ifdef __cplusplus } #endif diff --git a/modules/gdnative/gdnative/node_path.cpp b/modules/gdnative/gdnative/node_path.cpp index 2bd278e050..8dfe151f91 100644 --- a/modules/gdnative/gdnative/node_path.cpp +++ b/modules/gdnative/gdnative/node_path.cpp @@ -91,10 +91,10 @@ godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, co return dest; } -godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_self) { +godot_string GDAPI godot_node_path_get_concatenated_subnames(const godot_node_path *p_self) { godot_string dest; const NodePath *self = (const NodePath *)p_self; - memnew_placement(&dest, String(self->get_property())); + memnew_placement(&dest, String(self->get_concatenated_subnames())); return dest; } diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index 781b8754bd..67a037736c 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -89,11 +89,6 @@ wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, cons return self->operator[](p_idx); } -const char GDAPI *godot_string_c_str(const godot_string *p_self) { - const String *self = (const String *)p_self; - return self->utf8().get_data(); -} - const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self) { const String *self = (const String *)p_self; return self->c_str(); diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 877c65dfb9..488ed93206 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -2680,6 +2680,26 @@ ] }, { + "name": "godot_array_bsearch", + "return_type": "godot_int", + "arguments": [ + ["godot_array *", "p_self"], + ["const godot_variant *", "p_value"], + ["const godot_bool", "p_before"] + ] + }, + { + "name": "godot_array_bsearch_custom", + "return_type": "godot_int", + "arguments": [ + ["godot_array *", "p_self"], + ["const godot_variant *", "p_value"], + ["godot_object *", "p_obj"], + ["const godot_string *", "p_func"], + ["const godot_bool", "p_before"] + ] + }, + { "name": "godot_array_destroy", "return_type": "void", "arguments": [ @@ -2898,7 +2918,7 @@ ] }, { - "name": "godot_node_path_get_property", + "name": "godot_node_path_get_concatenated_subnames", "return_type": "godot_string", "arguments": [ ["const godot_node_path *", "p_self"] @@ -4362,13 +4382,6 @@ ] }, { - "name": "godot_string_c_str", - "return_type": "const char *", - "arguments": [ - ["const godot_string *", "p_self"] - ] - }, - { "name": "godot_string_unicode_str", "return_type": "const wchar_t *", "arguments": [ @@ -5556,6 +5569,14 @@ ] }, { + "name": "godot_register_native_call_type", + "return_type": "void", + "arguments": [ + ["const char *", "call_type"], + ["native_call_cb", "p_callback"] + ] + }, + { "name": "godot_alloc", "return_type": "void *", "arguments": [ diff --git a/modules/gdnative/include/gdnative/array.h b/modules/gdnative/include/gdnative/array.h index 01ae61e280..484ffd10ba 100644 --- a/modules/gdnative/include/gdnative/array.h +++ b/modules/gdnative/include/gdnative/array.h @@ -124,6 +124,10 @@ void GDAPI godot_array_sort(godot_array *p_self); void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, const godot_string *p_func); +godot_int GDAPI godot_array_bsearch(godot_array *p_self, const godot_variant *p_value, const godot_bool p_before); + +godot_int GDAPI godot_array_bsearch_custom(godot_array *p_self, const godot_variant *p_value, godot_object *p_obj, const godot_string *p_func, const godot_bool p_before); + void GDAPI godot_array_destroy(godot_array *p_self); #ifdef __cplusplus diff --git a/modules/gdnative/include/gdnative/gdnative.h b/modules/gdnative/include/gdnative/gdnative.h index 38a42ab658..6e69d43469 100644 --- a/modules/gdnative/include/gdnative/gdnative.h +++ b/modules/gdnative/include/gdnative/gdnative.h @@ -53,7 +53,7 @@ extern "C" { // This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!! #ifdef _WIN32 -#define GDN_EXPORT +#define GDN_EXPORT __declspec(dllexport) #else #define GDN_EXPORT #endif @@ -229,13 +229,28 @@ void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_obj godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error); ////// Script API -struct godot_gdnative_api_struct; // Forward declaration +typedef struct godot_gdnative_api_version { + unsigned int major; + unsigned int minor; +} godot_gdnative_api_version; + +typedef struct godot_gdnative_api_struct godot_gdnative_api_struct; + +struct godot_gdnative_api_struct { + unsigned int type; + godot_gdnative_api_version version; + const godot_gdnative_api_struct *next; +}; + +#define GDNATIVE_VERSION_COMPATIBLE(want, have) (want.major == have.major && want.minor <= have.minor) typedef struct { godot_bool in_editor; uint64_t core_api_hash; uint64_t editor_api_hash; uint64_t no_api_hash; + void (*report_version_mismatch)(const godot_object *p_library, const char *p_what, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have); + void (*report_loading_error)(const godot_object *p_library, const char *p_what); godot_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized const struct godot_gdnative_core_api_struct *api_struct; const godot_string *active_library_path; @@ -259,6 +274,9 @@ typedef godot_variant (*godot_gdnative_procedure_fn)(godot_array *); ////// System Functions +typedef godot_variant (*native_call_cb)(void *, godot_array *); +void GDAPI godot_register_native_call_type(const char *p_call_type, native_call_cb p_callback); + //using these will help Godot track how much memory is in use in debug mode void GDAPI *godot_alloc(int p_bytes); void GDAPI *godot_realloc(void *p_ptr, int p_bytes); diff --git a/modules/gdnative/include/gdnative/node_path.h b/modules/gdnative/include/gdnative/node_path.h index 42446175d8..b5a59fd325 100644 --- a/modules/gdnative/include/gdnative/node_path.h +++ b/modules/gdnative/include/gdnative/node_path.h @@ -73,7 +73,7 @@ godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_self) godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, const godot_int p_idx); -godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_self); +godot_string GDAPI godot_node_path_get_concatenated_subnames(const godot_node_path *p_self); godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_self); diff --git a/modules/gdnative/include/gdnative/string.h b/modules/gdnative/include/gdnative/string.h index cca3eb2672..10358ceade 100644 --- a/modules/gdnative/include/gdnative/string.h +++ b/modules/gdnative/include/gdnative/string.h @@ -68,7 +68,6 @@ void GDAPI godot_string_get_data(const godot_string *p_self, char *p_dest, int * wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx); wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, const godot_int p_idx); -const char GDAPI *godot_string_c_str(const godot_string *p_self); const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self); godot_bool GDAPI godot_string_operator_equal(const godot_string *p_self, const godot_string *p_b); diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index 8af643df50..34099bf528 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -123,6 +123,11 @@ protected: virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features); }; +struct LibrarySymbol { + char *name; + bool is_required; +}; + void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_type, const Set<String> &p_features) { if (p_type != "GDNativeLibrary") { return; @@ -136,7 +141,6 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty Ref<ConfigFile> config = lib->get_config_file(); - String entry_lib_path; { List<String> entry_keys; @@ -161,14 +165,12 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty continue; } - entry_lib_path = config->get_value("entry", key); - break; + String entry_lib_path = config->get_value("entry", key); + add_shared_object(entry_lib_path, tags); } } - Vector<String> dependency_paths; { - List<String> dependency_keys; config->get_section_keys("dependencies", &dependency_keys); @@ -191,47 +193,54 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty continue; } - dependency_paths = config->get_value("dependencies", key); - break; + Vector<String> dependency_paths = config->get_value("dependencies", key); + for (int i = 0; i < dependency_paths.size(); i++) { + add_shared_object(dependency_paths[i], tags); + } } } - bool is_statically_linked = false; - { - - List<String> static_linking_keys; - config->get_section_keys("static_linking", &static_linking_keys); - - for (List<String>::Element *E = static_linking_keys.front(); E; E = E->next()) { - String key = E->get(); - - Vector<String> tags = key.split("."); - - bool skip = false; - - for (int i = 0; i < tags.size(); i++) { - bool has_feature = p_features.has(tags[i]); - - if (!has_feature) { - skip = true; - break; + if (p_features.has("iOS")) { + // Register symbols in the "fake" dynamic lookup table, because dlsym does not work well on iOS. + LibrarySymbol expected_symbols[] = { + { "gdnative_init", true }, + { "gdnative_terminate", false }, + { "nativescript_init", false }, + { "nativescript_frame", false }, + { "nativescript_thread_enter", false }, + { "nativescript_thread_exit", false }, + { "gdnative_singleton", false } + }; + String declare_pattern = "extern \"C\" void $name(void)$weak;\n"; + String additional_code = "extern void register_dynamic_symbol(char *name, void *address);\n" + "extern void add_ios_init_callback(void (*cb)());\n"; + String linker_flags = ""; + for (int i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) { + String full_name = lib->get_symbol_prefix() + expected_symbols[i].name; + String code = declare_pattern.replace("$name", full_name); + code = code.replace("$weak", expected_symbols[i].is_required ? "" : " __attribute__((weak))"); + additional_code += code; + + if (!expected_symbols[i].is_required) { + if (linker_flags.length() > 0) { + linker_flags += " "; } + linker_flags += "-Wl,-U,_" + full_name; } - - if (skip) { - continue; - } - - is_statically_linked = config->get_value("static_linking", key); - break; } - } - if (!is_statically_linked) - add_shared_object(entry_lib_path); + additional_code += String("void $prefixinit() {\n").replace("$prefix", lib->get_symbol_prefix()); + String register_pattern = " if (&$name) register_dynamic_symbol((char *)\"$name\", (void *)$name);\n"; + for (int i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) { + String full_name = lib->get_symbol_prefix() + expected_symbols[i].name; + additional_code += register_pattern.replace("$name", full_name); + } + additional_code += "}\n"; + additional_code += String("struct $prefixstruct {$prefixstruct() {add_ios_init_callback($prefixinit);}};\n").replace("$prefix", lib->get_symbol_prefix()); + additional_code += String("$prefixstruct $prefixstruct_instance;\n").replace("$prefix", lib->get_symbol_prefix()); - for (int i = 0; i < dependency_paths.size(); i++) { - add_shared_object(dependency_paths[i]); + add_ios_cpp_code(additional_code); + add_ios_linker_flags(linker_flags); } } @@ -271,9 +280,7 @@ void register_gdnative_types() { #ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint()) { - EditorNode::add_init_callback(editor_init_callback); - } + EditorNode::add_init_callback(editor_init_callback); #endif ClassDB::register_class<GDNativeLibrary>(); diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 55ea8a5f24..41a810ff00 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -100,7 +100,7 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco #endif instance->owner->set_script_instance(instance); -/* STEP 2, INITIALIZE AND CONSRTUCT */ + /* STEP 2, INITIALIZE AND CONSRTUCT */ #ifndef NO_THREADS GDScriptLanguage::singleton->lock->lock(); @@ -615,6 +615,23 @@ ScriptLanguage *GDScript::get_language() const { return GDScriptLanguage::get_singleton(); } +void GDScript::get_constants(Map<StringName, Variant> *p_constants) { + + if (p_constants) { + for (Map<StringName, Variant>::Element *E = constants.front(); E; E = E->next()) { + (*p_constants)[E->key()] = E->value(); + } + } +} + +void GDScript::get_members(Set<StringName> *p_members) { + if (p_members) { + for (Set<StringName>::Element *E = members.front(); E; E = E->next()) { + p_members->insert(E->get()); + } + } +} + Variant GDScript::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { GDScript *top = this; diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 3f6f431938..6e5d59ad0e 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -198,6 +198,9 @@ public: return -1; } + virtual void get_constants(Map<StringName, Variant> *p_constants); + virtual void get_members(Set<StringName> *p_members); + GDScript(); ~GDScript(); }; @@ -219,7 +222,7 @@ class GDScriptInstance : public ScriptInstance { void _ml_call_reversed(GDScript *sptr, const StringName &p_method, const Variant **p_args, int p_argcount); public: - _FORCE_INLINE_ Object *get_owner() { return owner; } + virtual Object *get_owner() { return owner; } virtual bool set(const StringName &p_name, const Variant &p_value); virtual bool get(const StringName &p_name, Variant &r_ret) const; @@ -407,7 +410,8 @@ public: virtual String debug_get_stack_level_source(int p_level) const; virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); - virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); + virtual ScriptInstance *debug_get_stack_level_instance(int p_level); + virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1); virtual void reload_all_scripts(); diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 3121a61436..4cd6472b7f 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1686,21 +1686,44 @@ Error GDScriptCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, cons base_class = p->subclasses[base]; break; } + + if (p->constants.has(base)) { + + base_class = p->constants[base]; + if (base_class.is_null()) { + _set_error("Constant is not a class: " + base, p_class); + return ERR_SCRIPT_FAILED; + } + break; + } + p = p->_owner; } if (base_class.is_valid()) { + String ident = base; + for (int i = 1; i < p_class->extends_class.size(); i++) { String subclass = p_class->extends_class[i]; + ident += ("." + subclass); + if (base_class->subclasses.has(subclass)) { base_class = base_class->subclasses[subclass]; + } else if (base_class->constants.has(subclass)) { + + Ref<GDScript> new_base_class = base_class->constants[subclass]; + if (new_base_class.is_null()) { + _set_error("Constant is not a class: " + ident, p_class); + return ERR_SCRIPT_FAILED; + } + base_class = new_base_class; } else { - _set_error("Could not find subclass: " + subclass, p_class); + _set_error("Could not find subclass: " + ident, p_class); return ERR_FILE_NOT_FOUND; } } diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index a74b8a8483..5a76acea6e 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -33,7 +33,7 @@ #include "gdscript_compiler.h" #include "global_constants.h" #include "os/file_access.h" -#include "project_settings.h" +#include "core/engine.h" #ifdef TOOLS_ENABLED #include "editor/editor_file_system.h" @@ -280,10 +280,62 @@ void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> * p_values->push_back(instance->debug_get_member_by_index(E->get().index)); } } -void GDScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - //no globals are really reachable in gdscript +ScriptInstance *GDScriptLanguage::debug_get_stack_level_instance(int p_level) { + + ERR_FAIL_COND_V(_debug_parse_err_line >= 0, NULL); + ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, NULL); + + int l = _debug_call_stack_pos - p_level - 1; + ScriptInstance *instance = _call_stack[l].instance; + + return instance; } + +void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { + + const Map<StringName, int> &name_idx = GDScriptLanguage::get_singleton()->get_global_map(); + const Variant *globals = GDScriptLanguage::get_singleton()->get_global_array(); + + List<Pair<String, Variant> > cinfo; + get_public_constants(&cinfo); + + for (const Map<StringName, int>::Element *E = name_idx.front(); E; E = E->next()) { + + if (ClassDB::class_exists(E->key()) || Engine::get_singleton()->has_singleton(E->key())) + continue; + + bool is_script_constant = false; + for (List<Pair<String, Variant> >::Element *CE = cinfo.front(); CE; CE = CE->next()) { + if (CE->get().first == E->key()) { + is_script_constant = true; + break; + } + } + if (is_script_constant) + continue; + + const Variant &var = globals[E->value()]; + if (Object *obj = var) { + if (Object::cast_to<GDScriptNativeClass>(obj)) + continue; + } + + bool skip = false; + for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) { + if (E->key() == GlobalConstants::get_global_constant_name(i)) { + skip = true; + break; + } + } + if (skip) + continue; + + p_globals->push_back(E->key()); + p_values->push_back(var); + } +} + String GDScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { if (_debug_parse_err_line >= 0) @@ -1743,7 +1795,7 @@ static void _find_type_arguments(GDScriptCompletionContext &context, const GDScr } } else { -//regular method + //regular method #if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) if (p_argidx < m->get_argument_count()) { diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index c6066ceefb..ca0a9582a7 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -84,6 +84,8 @@ const char *GDScriptFunctions::get_func_name(Function p_func) { "rad2deg", "linear2db", "db2linear", + "polar2cartesian", + "cartesian2polar", "wrapi", "wrapf", "max", @@ -408,6 +410,22 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ VALIDATE_ARG_NUM(0); r_ret = Math::db2linear((double)*p_args[0]); } break; + case MATH_POLAR2CARTESIAN: { + VALIDATE_ARG_COUNT(2); + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + double r = *p_args[0]; + double th = *p_args[1]; + r_ret = Vector2(r * Math::cos(th), r * Math::sin(th)); + } break; + case MATH_CARTESIAN2POLAR: { + VALIDATE_ARG_COUNT(2); + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + double x = *p_args[0]; + double y = *p_args[1]; + r_ret = Vector2(Math::sqrt(x * x + y * y), Math::atan2(y, x)); + } break; case MATH_WRAP: { VALIDATE_ARG_COUNT(3); r_ret = Math::wrapi((int64_t)*p_args[0], (int64_t)*p_args[1], (int64_t)*p_args[2]); @@ -1296,6 +1314,8 @@ bool GDScriptFunctions::is_deterministic(Function p_func) { case MATH_RAD2DEG: case MATH_LINEAR2DB: case MATH_DB2LINEAR: + case MATH_POLAR2CARTESIAN: + case MATH_CARTESIAN2POLAR: case MATH_WRAP: case MATH_WRAPF: case LOGIC_MAX: @@ -1526,6 +1546,16 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { mi.return_val.type = Variant::REAL; return mi; } break; + case MATH_POLAR2CARTESIAN: { + MethodInfo mi("polar2cartesian", PropertyInfo(Variant::REAL, "r"), PropertyInfo(Variant::REAL, "th")); + mi.return_val.type = Variant::VECTOR2; + return mi; + } break; + case MATH_CARTESIAN2POLAR: { + MethodInfo mi("cartesian2polar", PropertyInfo(Variant::REAL, "x"), PropertyInfo(Variant::REAL, "y")); + mi.return_val.type = Variant::VECTOR2; + return mi; + } break; case MATH_WRAP: { MethodInfo mi("wrapi", PropertyInfo(Variant::INT, "value"), PropertyInfo(Variant::INT, "min"), PropertyInfo(Variant::INT, "max")); mi.return_val.type = Variant::INT; diff --git a/modules/gdscript/gdscript_functions.h b/modules/gdscript/gdscript_functions.h index ecbede83a8..d1c5815cec 100644 --- a/modules/gdscript/gdscript_functions.h +++ b/modules/gdscript/gdscript_functions.h @@ -75,6 +75,8 @@ public: MATH_RAD2DEG, MATH_LINEAR2DB, MATH_DB2LINEAR, + MATH_POLAR2CARTESIAN, + MATH_CARTESIAN2POLAR, MATH_WRAP, MATH_WRAPF, LOGIC_MAX, diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 1e677f11c4..bee9ef1998 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2971,18 +2971,37 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) { } while (true) { - if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER) { - _set_error("Invalid 'extends' syntax, expected string constant (path) and/or identifier (parent class)."); - return; - } + switch (tokenizer->get_token()) { + + case GDScriptTokenizer::TK_IDENTIFIER: { + + StringName identifier = tokenizer->get_token_identifier(); + p_class->extends_class.push_back(identifier); + } + break; + + case GDScriptTokenizer::TK_PERIOD: + break; + + default: { - StringName identifier = tokenizer->get_token_identifier(); - p_class->extends_class.push_back(identifier); + _set_error("Invalid 'extends' syntax, expected string constant (path) and/or identifier (parent class)."); + return; + } + } tokenizer->advance(1); - if (tokenizer->get_token() != GDScriptTokenizer::TK_PERIOD) - return; + + switch (tokenizer->get_token()) { + + case GDScriptTokenizer::TK_IDENTIFIER: + case GDScriptTokenizer::TK_PERIOD: + continue; + + default: + return; + } } } diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 491adb31ee..3a5d0fd3fc 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -623,6 +623,16 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu return do_input_action(p_camera, mm->get_position(), false); } + Ref<InputEventPanGesture> pan_gesture = p_event; + if (pan_gesture.is_valid()) { + + if (pan_gesture->get_command() || pan_gesture->get_shift()) { + const real_t delta = pan_gesture->get_delta().y; + floor->set_value(floor->get_value() + SGN(delta)); + return true; + } + } + return false; } diff --git a/modules/mono/glue/cs_files/AABB.cs b/modules/mono/glue/cs_files/AABB.cs index 6ee3bbe53a..e6e12f7ba3 100644 --- a/modules/mono/glue/cs_files/AABB.cs +++ b/modules/mono/glue/cs_files/AABB.cs @@ -38,7 +38,7 @@ namespace Godot } } - public bool encloses(AABB with) + public bool Encloses(AABB with) { Vector3 src_min = position; Vector3 src_max = position + size; @@ -53,7 +53,7 @@ namespace Godot (src_max.z > dst_max.z)); } - public AABB expand(Vector3 to_point) + public AABB Expand(Vector3 to_point) { Vector3 begin = position; Vector3 end = position + size; @@ -75,12 +75,12 @@ namespace Godot return new AABB(begin, end - begin); } - public float get_area() + public float GetArea() { return size.x * size.y * size.z; } - public Vector3 get_endpoint(int idx) + public Vector3 GetEndpoint(int idx) { switch (idx) { @@ -105,7 +105,7 @@ namespace Godot } } - public Vector3 get_longest_axis() + public Vector3 GetLongestAxis() { Vector3 axis = new Vector3(1f, 0f, 0f); float max_size = size.x; @@ -125,7 +125,7 @@ namespace Godot return axis; } - public Vector3.Axis get_longest_axis_index() + public Vector3.Axis GetLongestAxisIndex() { Vector3.Axis axis = Vector3.Axis.X; float max_size = size.x; @@ -145,7 +145,7 @@ namespace Godot return axis; } - public float get_longest_axis_size() + public float GetLongestAxisSize() { float max_size = size.x; @@ -158,7 +158,7 @@ namespace Godot return max_size; } - public Vector3 get_shortest_axis() + public Vector3 GetShortestAxis() { Vector3 axis = new Vector3(1f, 0f, 0f); float max_size = size.x; @@ -178,7 +178,7 @@ namespace Godot return axis; } - public Vector3.Axis get_shortest_axis_index() + public Vector3.Axis GetShortestAxisIndex() { Vector3.Axis axis = Vector3.Axis.X; float max_size = size.x; @@ -198,7 +198,7 @@ namespace Godot return axis; } - public float get_shortest_axis_size() + public float GetShortestAxisSize() { float max_size = size.x; @@ -211,7 +211,7 @@ namespace Godot return max_size; } - public Vector3 get_support(Vector3 dir) + public Vector3 GetSupport(Vector3 dir) { Vector3 half_extents = size * 0.5f; Vector3 ofs = position + half_extents; @@ -222,7 +222,7 @@ namespace Godot (dir.z > 0f) ? -half_extents.z : half_extents.z); } - public AABB grow(float by) + public AABB Grow(float by) { AABB res = this; @@ -236,17 +236,17 @@ namespace Godot return res; } - public bool has_no_area() + public bool HasNoArea() { return size.x <= 0f || size.y <= 0f || size.z <= 0f; } - public bool has_no_surface() + public bool HasNoSurface() { return size.x <= 0f && size.y <= 0f && size.z <= 0f; } - public bool has_point(Vector3 point) + public bool HasPoint(Vector3 point) { if (point.x < position.x) return false; @@ -264,7 +264,7 @@ namespace Godot return true; } - public AABB intersection(AABB with) + public AABB Intersection(AABB with) { Vector3 src_min = position; Vector3 src_max = position + size; @@ -306,7 +306,7 @@ namespace Godot return new AABB(min, max - min); } - public bool intersects(AABB with) + public bool Intersects(AABB with) { if (position.x >= (with.position.x + with.size.x)) return false; @@ -324,7 +324,7 @@ namespace Godot return true; } - public bool intersects_plane(Plane plane) + public bool IntersectsPlane(Plane plane) { Vector3[] points = { @@ -343,7 +343,7 @@ namespace Godot for (int i = 0; i < 8; i++) { - if (plane.distance_to(points[i]) > 0) + if (plane.DistanceTo(points[i]) > 0) over = true; else under = true; @@ -352,7 +352,7 @@ namespace Godot return under && over; } - public bool intersects_segment(Vector3 from, Vector3 to) + public bool IntersectsSegment(Vector3 from, Vector3 to) { float min = 0f; float max = 1f; @@ -398,7 +398,7 @@ namespace Godot return true; } - public AABB merge(AABB with) + public AABB Merge(AABB with) { Vector3 beg_1 = position; Vector3 beg_2 = with.position; diff --git a/modules/mono/glue/cs_files/Basis.cs b/modules/mono/glue/cs_files/Basis.cs index c50e783349..ea92b1641b 100644 --- a/modules/mono/glue/cs_files/Basis.cs +++ b/modules/mono/glue/cs_files/Basis.cs @@ -56,9 +56,9 @@ namespace Godot { return new Vector3 ( - new Vector3(this[0, 0], this[1, 0], this[2, 0]).length(), - new Vector3(this[0, 1], this[1, 1], this[2, 1]).length(), - new Vector3(this[0, 2], this[1, 2], this[2, 2]).length() + new Vector3(this[0, 0], this[1, 0], this[2, 0]).Length(), + new Vector3(this[0, 1], this[1, 1], this[2, 1]).Length(), + new Vector3(this[0, 2], this[1, 2], this[2, 2]).Length() ); } } @@ -133,7 +133,7 @@ namespace Godot } } - internal static Basis create_from_axes(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis) + internal static Basis CreateFromAxes(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis) { return new Basis ( @@ -143,21 +143,21 @@ namespace Godot ); } - public float determinant() + public float Determinant() { return this[0, 0] * (this[1, 1] * this[2, 2] - this[2, 1] * this[1, 2]) - this[1, 0] * (this[0, 1] * this[2, 2] - this[2, 1] * this[0, 2]) + this[2, 0] * (this[0, 1] * this[1, 2] - this[1, 1] * this[0, 2]); } - public Vector3 get_axis(int axis) + public Vector3 GetAxis(int axis) { return new Vector3(this[0, axis], this[1, axis], this[2, axis]); } - public Vector3 get_euler() + public Vector3 GetEuler() { - Basis m = this.orthonormalized(); + Basis m = this.Orthonormalized(); Vector3 euler; euler.z = 0.0f; @@ -169,26 +169,26 @@ namespace Godot { if (mxy > -1.0f) { - euler.x = Mathf.asin(-mxy); - euler.y = Mathf.atan2(m.x[2], m.z[2]); - euler.z = Mathf.atan2(m.y[0], m.y[1]); + euler.x = Mathf.Asin(-mxy); + euler.y = Mathf.Atan2(m.x[2], m.z[2]); + euler.z = Mathf.Atan2(m.y[0], m.y[1]); } else { euler.x = Mathf.PI * 0.5f; - euler.y = -Mathf.atan2(-m.x[1], m.x[0]); + euler.y = -Mathf.Atan2(-m.x[1], m.x[0]); } } else { euler.x = -Mathf.PI * 0.5f; - euler.y = -Mathf.atan2(m.x[1], m.x[0]); + euler.y = -Mathf.Atan2(m.x[1], m.x[0]); } return euler; } - public int get_orthogonal_index() + public int GetOrthogonalIndex() { Basis orth = this; @@ -218,7 +218,7 @@ namespace Godot return 0; } - public Basis inverse() + public Basis Inverse() { Basis inv = this; @@ -259,27 +259,27 @@ namespace Godot return inv; } - public Basis orthonormalized() + public Basis Orthonormalized() { - Vector3 xAxis = get_axis(0); - Vector3 yAxis = get_axis(1); - Vector3 zAxis = get_axis(2); + Vector3 xAxis = GetAxis(0); + Vector3 yAxis = GetAxis(1); + Vector3 zAxis = GetAxis(2); - xAxis.normalize(); - yAxis = (yAxis - xAxis * (xAxis.dot(yAxis))); - yAxis.normalize(); - zAxis = (zAxis - xAxis * (xAxis.dot(zAxis)) - yAxis * (yAxis.dot(zAxis))); - zAxis.normalize(); + xAxis.Normalize(); + yAxis = (yAxis - xAxis * (xAxis.Dot(yAxis))); + yAxis.Normalize(); + zAxis = (zAxis - xAxis * (xAxis.Dot(zAxis)) - yAxis * (yAxis.Dot(zAxis))); + zAxis.Normalize(); - return Basis.create_from_axes(xAxis, yAxis, zAxis); + return Basis.CreateFromAxes(xAxis, yAxis, zAxis); } - public Basis rotated(Vector3 axis, float phi) + public Basis Rotated(Vector3 axis, float phi) { return new Basis(axis, phi) * this; } - public Basis scaled(Vector3 scale) + public Basis Scaled(Vector3 scale) { Basis m = this; @@ -296,22 +296,22 @@ namespace Godot return m; } - public float tdotx(Vector3 with) + public float Tdotx(Vector3 with) { return this[0, 0] * with[0] + this[1, 0] * with[1] + this[2, 0] * with[2]; } - public float tdoty(Vector3 with) + public float Tdoty(Vector3 with) { return this[0, 1] * with[0] + this[1, 1] * with[1] + this[2, 1] * with[2]; } - public float tdotz(Vector3 with) + public float Tdotz(Vector3 with) { return this[0, 2] * with[0] + this[1, 2] * with[1] + this[2, 2] * with[2]; } - public Basis transposed() + public Basis Transposed() { Basis tr = this; @@ -330,17 +330,17 @@ namespace Godot return tr; } - public Vector3 xform(Vector3 v) + public Vector3 Xform(Vector3 v) { return new Vector3 ( - this[0].dot(v), - this[1].dot(v), - this[2].dot(v) + this[0].Dot(v), + this[1].Dot(v), + this[2].Dot(v) ); } - public Vector3 xform_inv(Vector3 v) + public Vector3 XformInv(Vector3 v) { return new Vector3 ( @@ -354,7 +354,7 @@ namespace Godot float trace = x[0] + y[1] + z[2]; if (trace > 0.0f) { - float s = Mathf.sqrt(trace + 1.0f) * 2f; + float s = Mathf.Sqrt(trace + 1.0f) * 2f; float inv_s = 1f / s; return new Quat( (z[1] - y[2]) * inv_s, @@ -363,7 +363,7 @@ namespace Godot s * 0.25f ); } else if (x[0] > y[1] && x[0] > z[2]) { - float s = Mathf.sqrt(x[0] - y[1] - z[2] + 1.0f) * 2f; + float s = Mathf.Sqrt(x[0] - y[1] - z[2] + 1.0f) * 2f; float inv_s = 1f / s; return new Quat( s * 0.25f, @@ -372,7 +372,7 @@ namespace Godot (z[1] - y[2]) * inv_s ); } else if (y[1] > z[2]) { - float s = Mathf.sqrt(-x[0] + y[1] - z[2] + 1.0f) * 2f; + float s = Mathf.Sqrt(-x[0] + y[1] - z[2] + 1.0f) * 2f; float inv_s = 1f / s; return new Quat( (x[1] + y[0]) * inv_s, @@ -381,7 +381,7 @@ namespace Godot (x[2] - z[0]) * inv_s ); } else { - float s = Mathf.sqrt(-x[0] - y[1] + z[2] + 1.0f) * 2f; + float s = Mathf.Sqrt(-x[0] - y[1] + z[2] + 1.0f) * 2f; float inv_s = 1f / s; return new Quat( (x[2] + z[0]) * inv_s, @@ -394,7 +394,7 @@ namespace Godot public Basis(Quat quat) { - float s = 2.0f / quat.length_squared(); + float s = 2.0f / quat.LengthSquared(); float xs = quat.x * s; float ys = quat.y * s; @@ -418,8 +418,8 @@ namespace Godot { Vector3 axis_sq = new Vector3(axis.x * axis.x, axis.y * axis.y, axis.z * axis.z); - float cosine = Mathf.cos(phi); - float sine = Mathf.sin(phi); + float cosine = Mathf.Cos(phi); + float sine = Mathf.Sin(phi); this.x = new Vector3 ( @@ -461,9 +461,9 @@ namespace Godot { return new Basis ( - right.tdotx(left[0]), right.tdoty(left[0]), right.tdotz(left[0]), - right.tdotx(left[1]), right.tdoty(left[1]), right.tdotz(left[1]), - right.tdotx(left[2]), right.tdoty(left[2]), right.tdotz(left[2]) + right.Tdotx(left[0]), right.Tdoty(left[0]), right.Tdotz(left[0]), + right.Tdotx(left[1]), right.Tdoty(left[1]), right.Tdotz(left[1]), + right.Tdotx(left[2]), right.Tdoty(left[2]), right.Tdotz(left[2]) ); } diff --git a/modules/mono/glue/cs_files/Color.cs b/modules/mono/glue/cs_files/Color.cs index 0a00f83d47..db0e1fb744 100644 --- a/modules/mono/glue/cs_files/Color.cs +++ b/modules/mono/glue/cs_files/Color.cs @@ -45,8 +45,8 @@ namespace Godot { get { - float max = Mathf.max(r, Mathf.max(g, b)); - float min = Mathf.min(r, Mathf.min(g, b)); + float max = Mathf.Max(r, Mathf.Max(g, b)); + float min = Mathf.Min(r, Mathf.Min(g, b)); float delta = max - min; @@ -71,7 +71,7 @@ namespace Godot } set { - this = from_hsv(value, s, v); + this = FromHsv(value, s, v); } } @@ -79,8 +79,8 @@ namespace Godot { get { - float max = Mathf.max(r, Mathf.max(g, b)); - float min = Mathf.min(r, Mathf.min(g, b)); + float max = Mathf.Max(r, Mathf.Max(g, b)); + float min = Mathf.Min(r, Mathf.Min(g, b)); float delta = max - min; @@ -88,7 +88,7 @@ namespace Godot } set { - this = from_hsv(h, value, v); + this = FromHsv(h, value, v); } } @@ -96,11 +96,11 @@ namespace Godot { get { - return Mathf.max(r, Mathf.max(g, b)); + return Mathf.Max(r, Mathf.Max(g, b)); } set { - this = from_hsv(h, s, value); + this = FromHsv(h, s, value); } } @@ -154,10 +154,10 @@ namespace Godot } } - public static void to_hsv(Color color, out float hue, out float saturation, out float value) + public static void ToHsv(Color color, out float hue, out float saturation, out float value) { - int max = Mathf.max(color.r8, Mathf.max(color.g8, color.b8)); - int min = Mathf.min(color.r8, Mathf.min(color.g8, color.b8)); + int max = Mathf.Max(color.r8, Mathf.Max(color.g8, color.b8)); + int min = Mathf.Min(color.r8, Mathf.Min(color.g8, color.b8)); float delta = max - min; @@ -184,7 +184,7 @@ namespace Godot value = max / 255f; } - public static Color from_hsv(float hue, float saturation, float value, float alpha = 1.0f) + public static Color FromHsv(float hue, float saturation, float value, float alpha = 1.0f) { if (saturation == 0) { @@ -221,7 +221,7 @@ namespace Godot } } - public Color blend(Color over) + public Color Blend(Color over) { Color res; @@ -242,7 +242,7 @@ namespace Godot return res; } - public Color contrasted() + public Color Contrasted() { return new Color( (r + 0.5f) % 1.0f, @@ -251,12 +251,12 @@ namespace Godot ); } - public float gray() + public float Gray() { return (r + g + b) / 3.0f; } - public Color inverted() + public Color Inverted() { return new Color( 1.0f - r, @@ -265,7 +265,7 @@ namespace Godot ); } - public Color linear_interpolate(Color b, float t) + public Color LinearInterpolate(Color b, float t) { Color res = this; @@ -277,7 +277,7 @@ namespace Godot return res; } - public int to_32() + public int To32() { int c = (byte)(a * 255); c <<= 8; @@ -290,7 +290,7 @@ namespace Godot return c; } - public int to_ARGB32() + public int ToArgb32() { int c = (byte)(a * 255); c <<= 8; @@ -303,7 +303,7 @@ namespace Godot return c; } - public string to_html(bool include_alpha = true) + public string ToHtml(bool include_alpha = true) { String txt = string.Empty; @@ -375,7 +375,7 @@ namespace Godot private String _to_hex(float val) { - int v = (int)Mathf.clamp(val * 255.0f, 0, 255); + int v = (int)Mathf.Clamp(val * 255.0f, 0, 255); string ret = string.Empty; @@ -396,7 +396,7 @@ namespace Godot return ret; } - internal static bool html_is_valid(string color) + internal static bool HtmlIsValid(string color) { if (color.Length == 0) return false; diff --git a/modules/mono/glue/cs_files/GD.cs b/modules/mono/glue/cs_files/GD.cs index 40a42d23b4..99fc289161 100644 --- a/modules/mono/glue/cs_files/GD.cs +++ b/modules/mono/glue/cs_files/GD.cs @@ -6,32 +6,32 @@ namespace Godot { /*{GodotGlobalConstants}*/ - public static object bytes2var(byte[] bytes) + public static object Bytes2Var(byte[] bytes) { return NativeCalls.godot_icall_Godot_bytes2var(bytes); } - public static object convert(object what, int type) + public static object Convert(object what, int type) { return NativeCalls.godot_icall_Godot_convert(what, type); } - public static float db2linear(float db) + public static float Db2Linear(float db) { return (float)Math.Exp(db * 0.11512925464970228420089957273422); } - public static float dectime(float value, float amount, float step) + public static float Dectime(float value, float amount, float step) { float sgn = value < 0 ? -1.0f : 1.0f; - float val = Mathf.abs(value); + float val = Mathf.Abs(value); val -= amount * step; if (val < 0.0f) val = 0.0f; return val * sgn; } - public static FuncRef funcref(Object instance, string funcname) + public static FuncRef Funcref(Object instance, string funcname) { var ret = new FuncRef(); ret.SetInstance(instance); @@ -39,57 +39,57 @@ namespace Godot return ret; } - public static int hash(object var) + public static int Hash(object var) { return NativeCalls.godot_icall_Godot_hash(var); } - public static Object instance_from_id(int instance_id) + public static Object InstanceFromId(int instanceId) { - return NativeCalls.godot_icall_Godot_instance_from_id(instance_id); + return NativeCalls.godot_icall_Godot_instance_from_id(instanceId); } - public static double linear2db(double linear) + public static double Linear2Db(double linear) { return Math.Log(linear) * 8.6858896380650365530225783783321; } - public static Resource load(string path) + public static Resource Load(string path) { return ResourceLoader.Load(path); } - public static void print(params object[] what) + public static void Print(params object[] what) { NativeCalls.godot_icall_Godot_print(what); } - public static void print_stack() + public static void PrintStack() { - print(System.Environment.StackTrace); + Print(System.Environment.StackTrace); } - public static void printerr(params object[] what) + public static void Printerr(params object[] what) { NativeCalls.godot_icall_Godot_printerr(what); } - public static void printraw(params object[] what) + public static void Printraw(params object[] what) { NativeCalls.godot_icall_Godot_printraw(what); } - public static void prints(params object[] what) + public static void Prints(params object[] what) { NativeCalls.godot_icall_Godot_prints(what); } - public static void printt(params object[] what) + public static void Printt(params object[] what) { NativeCalls.godot_icall_Godot_printt(what); } - public static int[] range(int length) + public static int[] Range(int length) { int[] ret = new int[length]; @@ -101,7 +101,7 @@ namespace Godot return ret; } - public static int[] range(int from, int to) + public static int[] Range(int from, int to) { if (to < from) return new int[0]; @@ -116,7 +116,7 @@ namespace Godot return ret; } - public static int[] range(int from, int to, int increment) + public static int[] Range(int from, int to, int increment) { if (to < from && increment > 0) return new int[0]; @@ -153,37 +153,37 @@ namespace Godot return ret; } - public static void seed(int seed) + public static void Seed(int seed) { NativeCalls.godot_icall_Godot_seed(seed); } - public static string str(params object[] what) + public static string Str(params object[] what) { return NativeCalls.godot_icall_Godot_str(what); } - public static object str2var(string str) + public static object Str2Var(string str) { return NativeCalls.godot_icall_Godot_str2var(str); } - public static bool type_exists(string type) + public static bool TypeExists(string type) { return NativeCalls.godot_icall_Godot_type_exists(type); } - public static byte[] var2bytes(object var) + public static byte[] Var2Bytes(object var) { return NativeCalls.godot_icall_Godot_var2bytes(var); } - public static string var2str(object var) + public static string Var2Str(object var) { return NativeCalls.godot_icall_Godot_var2str(var); } - public static WeakRef weakref(Object obj) + public static WeakRef Weakref(Object obj) { return NativeCalls.godot_icall_Godot_weakref(Object.GetPtr(obj)); } diff --git a/modules/mono/glue/cs_files/Mathf.cs b/modules/mono/glue/cs_files/Mathf.cs index cb0eb1acdd..6951ace4fc 100644 --- a/modules/mono/glue/cs_files/Mathf.cs +++ b/modules/mono/glue/cs_files/Mathf.cs @@ -10,37 +10,42 @@ namespace Godot private const float Deg2RadConst = 0.0174532924f; private const float Rad2DegConst = 57.29578f; - public static float abs(float s) + public static float Abs(float s) { return Math.Abs(s); } - public static float acos(float s) + public static float Acos(float s) { return (float)Math.Acos(s); } - public static float asin(float s) + public static float Asin(float s) { return (float)Math.Asin(s); } - public static float atan(float s) + public static float Atan(float s) { return (float)Math.Atan(s); } - public static float atan2(float x, float y) + public static float Atan2(float x, float y) { return (float)Math.Atan2(x, y); } - public static float ceil(float s) + public static Vector2 Cartesian2Polar(float x, float y) + { + return new Vector2(Sqrt(x * x + y * y), Atan2(y, x)); + } + + public static float Ceil(float s) { return (float)Math.Ceiling(s); } - public static float clamp(float val, float min, float max) + public static float Clamp(float val, float min, float max) { if (val < min) { @@ -54,32 +59,32 @@ namespace Godot return val; } - public static float cos(float s) + public static float Cos(float s) { return (float)Math.Cos(s); } - public static float cosh(float s) + public static float Cosh(float s) { return (float)Math.Cosh(s); } - public static int decimals(float step) + public static int Decimals(float step) { - return decimals(step); + return Decimals(step); } - public static int decimals(decimal step) + public static int Decimals(decimal step) { return BitConverter.GetBytes(decimal.GetBits(step)[3])[2]; } - public static float deg2rad(float deg) + public static float Deg2Rad(float deg) { return deg * Deg2RadConst; } - public static float ease(float s, float curve) + public static float Ease(float s, float curve) { if (s < 0f) { @@ -94,35 +99,35 @@ namespace Godot { if (curve < 1.0f) { - return 1.0f - pow(1.0f - s, 1.0f / curve); + return 1.0f - Pow(1.0f - s, 1.0f / curve); } - return pow(s, curve); + return Pow(s, curve); } else if (curve < 0f) { if (s < 0.5f) { - return pow(s * 2.0f, -curve) * 0.5f; + return Pow(s * 2.0f, -curve) * 0.5f; } - return (1.0f - pow(1.0f - (s - 0.5f) * 2.0f, -curve)) * 0.5f + 0.5f; + return (1.0f - Pow(1.0f - (s - 0.5f) * 2.0f, -curve)) * 0.5f + 0.5f; } return 0f; } - public static float exp(float s) + public static float Exp(float s) { return (float)Math.Exp(s); } - public static float floor(float s) + public static float Floor(float s) { return (float)Math.Floor(s); } - public static float fposmod(float x, float y) + public static float Fposmod(float x, float y) { if (x >= 0f) { @@ -134,37 +139,37 @@ namespace Godot } } - public static float lerp(float from, float to, float weight) + public static float Lerp(float from, float to, float weight) { - return from + (to - from) * clamp(weight, 0f, 1f); + return from + (to - from) * Clamp(weight, 0f, 1f); } - public static float log(float s) + public static float Log(float s) { return (float)Math.Log(s); } - public static int max(int a, int b) + public static int Max(int a, int b) { return (a > b) ? a : b; } - public static float max(float a, float b) + public static float Max(float a, float b) { return (a > b) ? a : b; } - public static int min(int a, int b) + public static int Min(int a, int b) { return (a < b) ? a : b; } - public static float min(float a, float b) + public static float Min(float a, float b) { return (a < b) ? a : b; } - public static int nearest_po2(int val) + public static int NearestPo2(int val) { val--; val |= val >> 1; @@ -176,57 +181,62 @@ namespace Godot return val; } - public static float pow(float x, float y) + public static Vector2 Polar2Cartesian(float r, float th) + { + return new Vector2(r * Cos(th), r * Sin(th)); + } + + public static float Pow(float x, float y) { return (float)Math.Pow(x, y); } - public static float rad2deg(float rad) + public static float Rad2Deg(float rad) { return rad * Rad2DegConst; } - public static float round(float s) + public static float Round(float s) { return (float)Math.Round(s); } - public static float sign(float s) + public static float Sign(float s) { return (s < 0f) ? -1f : 1f; } - public static float sin(float s) + public static float Sin(float s) { return (float)Math.Sin(s); } - public static float sinh(float s) + public static float Sinh(float s) { return (float)Math.Sinh(s); } - public static float sqrt(float s) + public static float Sqrt(float s) { return (float)Math.Sqrt(s); } - public static float stepify(float s, float step) + public static float Stepify(float s, float step) { if (step != 0f) { - s = floor(s / step + 0.5f) * step; + s = Floor(s / step + 0.5f) * step; } return s; } - public static float tan(float s) + public static float Tan(float s) { return (float)Math.Tan(s); } - public static float tanh(float s) + public static float Tanh(float s) { return (float)Math.Tanh(s); } diff --git a/modules/mono/glue/cs_files/Plane.cs b/modules/mono/glue/cs_files/Plane.cs index 37f70aca1e..6365e71826 100644 --- a/modules/mono/glue/cs_files/Plane.cs +++ b/modules/mono/glue/cs_files/Plane.cs @@ -52,44 +52,44 @@ namespace Godot } } - public float distance_to(Vector3 point) + public float DistanceTo(Vector3 point) { - return normal.dot(point) - d; + return normal.Dot(point) - d; } - public Vector3 get_any_point() + public Vector3 GetAnyPoint() { return normal * d; } - public bool has_point(Vector3 point, float epsilon = Mathf.Epsilon) + public bool HasPoint(Vector3 point, float epsilon = Mathf.Epsilon) { - float dist = normal.dot(point) - d; - return Mathf.abs(dist) <= epsilon; + float dist = normal.Dot(point) - d; + return Mathf.Abs(dist) <= epsilon; } - public Vector3 intersect_3(Plane b, Plane c) + public Vector3 Intersect3(Plane b, Plane c) { - float denom = normal.cross(b.normal).dot(c.normal); + float denom = normal.Cross(b.normal).Dot(c.normal); - if (Mathf.abs(denom) <= Mathf.Epsilon) + if (Mathf.Abs(denom) <= Mathf.Epsilon) return new Vector3(); - Vector3 result = (b.normal.cross(c.normal) * this.d) + - (c.normal.cross(normal) * b.d) + - (normal.cross(b.normal) * c.d); + Vector3 result = (b.normal.Cross(c.normal) * this.d) + + (c.normal.Cross(normal) * b.d) + + (normal.Cross(b.normal) * c.d); return result / denom; } - public Vector3 intersect_ray(Vector3 from, Vector3 dir) + public Vector3 IntersectRay(Vector3 from, Vector3 dir) { - float den = normal.dot(dir); + float den = normal.Dot(dir); - if (Mathf.abs(den) <= Mathf.Epsilon) + if (Mathf.Abs(den) <= Mathf.Epsilon) return new Vector3(); - float dist = (normal.dot(from) - d) / den; + float dist = (normal.Dot(from) - d) / den; // This is a ray, before the emiting pos (from) does not exist if (dist > Mathf.Epsilon) @@ -98,15 +98,15 @@ namespace Godot return from + dir * -dist; } - public Vector3 intersect_segment(Vector3 begin, Vector3 end) + public Vector3 IntersectSegment(Vector3 begin, Vector3 end) { Vector3 segment = begin - end; - float den = normal.dot(segment); + float den = normal.Dot(segment); - if (Mathf.abs(den) <= Mathf.Epsilon) + if (Mathf.Abs(den) <= Mathf.Epsilon) return new Vector3(); - float dist = (normal.dot(begin) - d) / den; + float dist = (normal.Dot(begin) - d) / den; if (dist < -Mathf.Epsilon || dist > (1.0f + Mathf.Epsilon)) return new Vector3(); @@ -114,14 +114,14 @@ namespace Godot return begin + segment * -dist; } - public bool is_point_over(Vector3 point) + public bool IsPointOver(Vector3 point) { - return normal.dot(point) > d; + return normal.Dot(point) > d; } - public Plane normalized() + public Plane Normalized() { - float len = normal.length(); + float len = normal.Length(); if (len == 0) return new Plane(0, 0, 0, 0); @@ -129,9 +129,9 @@ namespace Godot return new Plane(normal / len, d / len); } - public Vector3 project(Vector3 point) + public Vector3 Project(Vector3 point) { - return point - normal * distance_to(point); + return point - normal * DistanceTo(point); } public Plane(float a, float b, float c, float d) @@ -148,9 +148,9 @@ namespace Godot public Plane(Vector3 v1, Vector3 v2, Vector3 v3) { - normal = (v1 - v3).cross(v1 - v2); - normal.normalize(); - d = normal.dot(v1); + normal = (v1 - v3).Cross(v1 - v2); + normal.Normalize(); + d = normal.Dot(v1); } public static Plane operator -(Plane plane) diff --git a/modules/mono/glue/cs_files/Quat.cs b/modules/mono/glue/cs_files/Quat.cs index 9b4b7fb297..c0ac41c5d7 100644 --- a/modules/mono/glue/cs_files/Quat.cs +++ b/modules/mono/glue/cs_files/Quat.cs @@ -58,40 +58,40 @@ namespace Godot } } - public Quat cubic_slerp(Quat b, Quat preA, Quat postB, float t) + public Quat CubicSlerp(Quat b, Quat preA, Quat postB, float t) { float t2 = (1.0f - t) * t * 2f; - Quat sp = slerp(b, t); - Quat sq = preA.slerpni(postB, t); - return sp.slerpni(sq, t2); + Quat sp = Slerp(b, t); + Quat sq = preA.Slerpni(postB, t); + return sp.Slerpni(sq, t2); } - public float dot(Quat b) + public float Dot(Quat b) { return x * b.x + y * b.y + z * b.z + w * b.w; } - public Quat inverse() + public Quat Inverse() { return new Quat(-x, -y, -z, w); } - public float length() + public float Length() { - return Mathf.sqrt(length_squared()); + return Mathf.Sqrt(LengthSquared()); } - public float length_squared() + public float LengthSquared() { - return dot(this); + return Dot(this); } - public Quat normalized() + public Quat Normalized() { - return this / length(); + return this / Length(); } - public void set(float x, float y, float z, float w) + public void Set(float x, float y, float z, float w) { this.x = x; this.y = y; @@ -99,7 +99,7 @@ namespace Godot this.w = w; } - public Quat slerp(Quat b, float t) + public Quat Slerp(Quat b, float t) { // Calculate cosine float cosom = x * b.x + y * b.y + z * b.z + w * b.w; @@ -128,10 +128,10 @@ namespace Godot if ((1.0 - cosom) > Mathf.Epsilon) { // Standard case (Slerp) - float omega = Mathf.acos(cosom); - sinom = Mathf.sin(omega); - scale0 = Mathf.sin((1.0f - t) * omega) / sinom; - scale1 = Mathf.sin(t * omega) / sinom; + float omega = Mathf.Acos(cosom); + sinom = Mathf.Sin(omega); + scale0 = Mathf.Sin((1.0f - t) * omega) / sinom; + scale1 = Mathf.Sin(t * omega) / sinom; } else { @@ -150,19 +150,19 @@ namespace Godot ); } - public Quat slerpni(Quat b, float t) + public Quat Slerpni(Quat b, float t) { - float dot = this.dot(b); + float dot = this.Dot(b); - if (Mathf.abs(dot) > 0.9999f) + if (Mathf.Abs(dot) > 0.9999f) { return this; } - float theta = Mathf.acos(dot); - float sinT = 1.0f / Mathf.sin(theta); - float newFactor = Mathf.sin(t * theta) * sinT; - float invFactor = Mathf.sin((1.0f - t) * theta) * sinT; + float theta = Mathf.Acos(dot); + float sinT = 1.0f / Mathf.Sin(theta); + float newFactor = Mathf.Sin(t * theta) * sinT; + float invFactor = Mathf.Sin((1.0f - t) * theta) * sinT; return new Quat ( @@ -173,10 +173,10 @@ namespace Godot ); } - public Vector3 xform(Vector3 v) + public Vector3 Xform(Vector3 v) { Quat q = this * v; - q *= this.inverse(); + q *= this.Inverse(); return new Vector3(q.x, q.y, q.z); } @@ -190,7 +190,7 @@ namespace Godot public Quat(Vector3 axis, float angle) { - float d = axis.length(); + float d = axis.Length(); if (d == 0f) { @@ -201,12 +201,12 @@ namespace Godot } else { - float s = Mathf.sin(angle * 0.5f) / d; + float s = Mathf.Sin(angle * 0.5f) / d; x = axis.x * s; y = axis.y * s; z = axis.z * s; - w = Mathf.cos(angle * 0.5f); + w = Mathf.Cos(angle * 0.5f); } } diff --git a/modules/mono/glue/cs_files/Rect2.cs b/modules/mono/glue/cs_files/Rect2.cs index 019342134a..f2718d7b7a 100644 --- a/modules/mono/glue/cs_files/Rect2.cs +++ b/modules/mono/glue/cs_files/Rect2.cs @@ -28,36 +28,36 @@ namespace Godot public float Area { - get { return get_area(); } + get { return GetArea(); } } - public Rect2 clip(Rect2 b) + public Rect2 Clip(Rect2 b) { Rect2 newRect = b; - if (!intersects(newRect)) + if (!Intersects(newRect)) return new Rect2(); - newRect.position.x = Mathf.max(b.position.x, position.x); - newRect.position.y = Mathf.max(b.position.y, position.y); + newRect.position.x = Mathf.Max(b.position.x, position.x); + newRect.position.y = Mathf.Max(b.position.y, position.y); Vector2 bEnd = b.position + b.size; Vector2 end = position + size; - newRect.size.x = Mathf.min(bEnd.x, end.x) - newRect.position.x; - newRect.size.y = Mathf.min(bEnd.y, end.y) - newRect.position.y; + newRect.size.x = Mathf.Min(bEnd.x, end.x) - newRect.position.x; + newRect.size.y = Mathf.Min(bEnd.y, end.y) - newRect.position.y; return newRect; } - public bool encloses(Rect2 b) + public bool Encloses(Rect2 b) { return (b.position.x >= position.x) && (b.position.y >= position.y) && ((b.position.x + b.size.x) < (position.x + size.x)) && ((b.position.y + b.size.y) < (position.y + size.y)); } - public Rect2 expand(Vector2 to) + public Rect2 Expand(Vector2 to) { Rect2 expanded = this; @@ -80,12 +80,12 @@ namespace Godot return expanded; } - public float get_area() + public float GetArea() { return size.x * size.y; } - public Rect2 grow(float by) + public Rect2 Grow(float by) { Rect2 g = this; @@ -97,7 +97,7 @@ namespace Godot return g; } - public Rect2 grow_individual(float left, float top, float right, float bottom) + public Rect2 GrowIndividual(float left, float top, float right, float bottom) { Rect2 g = this; @@ -109,11 +109,11 @@ namespace Godot return g; } - public Rect2 grow_margin(int margin, float by) + public Rect2 GrowMargin(int margin, float by) { Rect2 g = this; - g.grow_individual((GD.MARGIN_LEFT == margin) ? by : 0, + g.GrowIndividual((GD.MARGIN_LEFT == margin) ? by : 0, (GD.MARGIN_TOP == margin) ? by : 0, (GD.MARGIN_RIGHT == margin) ? by : 0, (GD.MARGIN_BOTTOM == margin) ? by : 0); @@ -121,12 +121,12 @@ namespace Godot return g; } - public bool has_no_area() + public bool HasNoArea() { return size.x <= 0 || size.y <= 0; } - public bool has_point(Vector2 point) + public bool HasPoint(Vector2 point) { if (point.x < position.x) return false; @@ -141,7 +141,7 @@ namespace Godot return true; } - public bool intersects(Rect2 b) + public bool Intersects(Rect2 b) { if (position.x > (b.position.x + b.size.x)) return false; @@ -155,15 +155,15 @@ namespace Godot return true; } - public Rect2 merge(Rect2 b) + public Rect2 Merge(Rect2 b) { Rect2 newRect; - newRect.position.x = Mathf.min(b.position.x, position.x); - newRect.position.y = Mathf.min(b.position.y, position.y); + newRect.position.x = Mathf.Min(b.position.x, position.x); + newRect.position.y = Mathf.Min(b.position.y, position.y); - newRect.size.x = Mathf.max(b.position.x + b.size.x, position.x + size.x); - newRect.size.y = Mathf.max(b.position.y + b.size.y, position.y + size.y); + newRect.size.x = Mathf.Max(b.position.x + b.size.x, position.x + size.x); + newRect.size.y = Mathf.Max(b.position.y + b.size.y, position.y + size.y); newRect.size = newRect.size - newRect.position; // Make relative again diff --git a/modules/mono/glue/cs_files/StringExtensions.cs b/modules/mono/glue/cs_files/StringExtensions.cs index 96041827aa..5c3ceff97d 100644 --- a/modules/mono/glue/cs_files/StringExtensions.cs +++ b/modules/mono/glue/cs_files/StringExtensions.cs @@ -10,15 +10,15 @@ namespace Godot { public static class StringExtensions { - private static int get_slice_count(this string instance, string splitter) + private static int GetSliceCount(this string instance, string splitter) { - if (instance.empty() || splitter.empty()) + if (instance.Empty() || splitter.Empty()) return 0; int pos = 0; int slices = 1; - while ((pos = instance.find(splitter, pos)) >= 0) + while ((pos = instance.Find(splitter, pos)) >= 0) { slices++; pos += splitter.Length; @@ -27,9 +27,9 @@ namespace Godot return slices; } - private static string get_slicec(this string instance, char splitter, int slice) + private static string GetSlicec(this string instance, char splitter, int slice) { - if (!instance.empty() && slice >= 0) + if (!instance.Empty() && slice >= 0) { int i = 0; int prev = 0; @@ -60,7 +60,7 @@ namespace Godot // <summary> // If the string is a path to a file, return the path to the file without the extension. // </summary> - public static string basename(this string instance) + public static string Basename(this string instance) { int index = instance.LastIndexOf('.'); @@ -73,7 +73,7 @@ namespace Godot // <summary> // Return true if the strings begins with the given string. // </summary> - public static bool begins_with(this string instance, string text) + public static bool BeginsWith(this string instance, string text) { return instance.StartsWith(text); } @@ -81,7 +81,7 @@ namespace Godot // <summary> // Return the bigrams (pairs of consecutive letters) of this string. // </summary> - public static string[] bigrams(this string instance) + public static string[] Bigrams(this string instance) { string[] b = new string[instance.Length - 1]; @@ -96,7 +96,7 @@ namespace Godot // <summary> // Return a copy of the string with special characters escaped using the C language standard. // </summary> - public static string c_escape(this string instance) + public static string CEscape(this string instance) { StringBuilder sb = new StringBuilder(string.Copy(instance)); @@ -118,7 +118,7 @@ namespace Godot // <summary> // Return a copy of the string with escaped characters replaced by their meanings according to the C language standard. // </summary> - public static string c_unescape(this string instance) + public static string CUnescape(this string instance) { StringBuilder sb = new StringBuilder(string.Copy(instance)); @@ -140,14 +140,14 @@ namespace Godot // <summary> // Change the case of some letters. Replace underscores with spaces, convert all letters to lowercase then capitalize first and every letter following the space character. For [code]capitalize camelCase mixed_with_underscores[/code] it will return [code]Capitalize Camelcase Mixed With Underscores[/code]. // </summary> - public static string capitalize(this string instance) + public static string Capitalize(this string instance) { string aux = instance.Replace("_", " ").ToLower(); string cap = string.Empty; - for (int i = 0; i < aux.get_slice_count(" "); i++) + for (int i = 0; i < aux.GetSliceCount(" "); i++) { - string slice = aux.get_slicec(' ', i); + string slice = aux.GetSlicec(' ', i); if (slice.Length > 0) { slice = char.ToUpper(slice[0]) + slice.Substring(1); @@ -163,12 +163,12 @@ namespace Godot // <summary> // Perform a case-sensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater. // </summary> - public static int casecmp_to(this string instance, string to) + public static int CasecmpTo(this string instance, string to) { - if (instance.empty()) - return to.empty() ? 0 : -1; + if (instance.Empty()) + return to.Empty() ? 0 : -1; - if (to.empty()) + if (to.Empty()) return 1; int instance_idx = 0; @@ -195,7 +195,7 @@ namespace Godot // <summary> // Return true if the string is empty. // </summary> - public static bool empty(this string instance) + public static bool Empty(this string instance) { return string.IsNullOrEmpty(instance); } @@ -203,7 +203,7 @@ namespace Godot // <summary> // Return true if the strings ends with the given string. // </summary> - public static bool ends_with(this string instance, string text) + public static bool EndsWith(this string instance, string text) { return instance.EndsWith(text); } @@ -211,7 +211,7 @@ namespace Godot // <summary> // Erase [code]chars[/code] characters from the string starting from [code]pos[/code]. // </summary> - public static void erase(this StringBuilder instance, int pos, int chars) + public static void Erase(this StringBuilder instance, int pos, int chars) { instance.Remove(pos, chars); } @@ -219,9 +219,9 @@ namespace Godot // <summary> // If the string is a path to a file, return the extension. // </summary> - public static string extension(this string instance) + public static string Extension(this string instance) { - int pos = instance.find_last("."); + int pos = instance.FindLast("."); if (pos < 0) return instance; @@ -232,7 +232,7 @@ namespace Godot // <summary> // Find the first occurrence of a substring, return the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed. // </summary> - public static int find(this string instance, string what, int from = 0) + public static int Find(this string instance, string what, int from = 0) { return instance.IndexOf(what, StringComparison.OrdinalIgnoreCase); } @@ -240,7 +240,7 @@ namespace Godot // <summary> // Find the last occurrence of a substring, return the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed. // </summary> - public static int find_last(this string instance, string what) + public static int FindLast(this string instance, string what) { return instance.LastIndexOf(what, StringComparison.OrdinalIgnoreCase); } @@ -248,7 +248,7 @@ namespace Godot // <summary> // Find the first occurrence of a substring but search as case-insensitive, return the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed. // </summary> - public static int findn(this string instance, string what, int from = 0) + public static int FindN(this string instance, string what, int from = 0) { return instance.IndexOf(what, StringComparison.Ordinal); } @@ -256,9 +256,9 @@ namespace Godot // <summary> // If the string is a path to a file, return the base directory. // </summary> - public static string get_base_dir(this string instance) + public static string GetBaseDir(this string instance) { - int basepos = instance.find("://"); + int basepos = instance.Find("://"); string rs = string.Empty; string @base = string.Empty; @@ -271,7 +271,7 @@ namespace Godot } else { - if (instance.begins_with("/")) + if (instance.BeginsWith("/")) { rs = instance.Substring(1, instance.Length); @base = "/"; @@ -282,7 +282,7 @@ namespace Godot } } - int sep = Mathf.max(rs.find_last("/"), rs.find_last("\\")); + int sep = Mathf.Max(rs.FindLast("/"), rs.FindLast("\\")); if (sep == -1) return @base; @@ -293,9 +293,9 @@ namespace Godot // <summary> // If the string is a path to a file, return the file and ignore the base directory. // </summary> - public static string get_file(this string instance) + public static string GetFile(this string instance) { - int sep = Mathf.max(instance.find_last("/"), instance.find_last("\\")); + int sep = Mathf.Max(instance.FindLast("/"), instance.FindLast("\\")); if (sep == -1) return instance; @@ -306,7 +306,7 @@ namespace Godot // <summary> // Hash the string and return a 32 bits integer. // </summary> - public static int hash(this string instance) + public static int Hash(this string instance) { int index = 0; int hashv = 5381; @@ -321,7 +321,7 @@ namespace Godot // <summary> // Convert a string containing an hexadecimal number into an int. // </summary> - public static int hex_to_int(this string instance) + public static int HexToInt(this string instance) { int sign = 1; @@ -340,7 +340,7 @@ namespace Godot // <summary> // Insert a substring at a given position. // </summary> - public static string insert(this string instance, int pos, string what) + public static string Insert(this string instance, int pos, string what) { return instance.Insert(pos, what); } @@ -348,7 +348,7 @@ namespace Godot // <summary> // If the string is a path to a file or directory, return true if the path is absolute. // </summary> - public static bool is_abs_path(this string instance) + public static bool IsAbsPath(this string instance) { return System.IO.Path.IsPathRooted(instance); } @@ -356,7 +356,7 @@ namespace Godot // <summary> // If the string is a path to a file or directory, return true if the path is relative. // </summary> - public static bool is_rel_path(this string instance) + public static bool IsRelPath(this string instance) { return !System.IO.Path.IsPathRooted(instance); } @@ -364,7 +364,7 @@ namespace Godot // <summary> // Check whether this string is a subsequence of the given string. // </summary> - public static bool is_subsequence_of(this string instance, string text, bool case_insensitive) + public static bool IsSubsequenceOf(this string instance, string text, bool case_insensitive) { int len = instance.Length; @@ -407,23 +407,23 @@ namespace Godot // <summary> // Check whether this string is a subsequence of the given string, considering case. // </summary> - public static bool is_subsequence_of(this string instance, string text) + public static bool IsSubsequenceOf(this string instance, string text) { - return instance.is_subsequence_of(text, false); + return instance.IsSubsequenceOf(text, false); } // <summary> // Check whether this string is a subsequence of the given string, without considering case. // </summary> - public static bool is_subsequence_ofi(this string instance, string text) + public static bool IsSubsequenceOfI(this string instance, string text) { - return instance.is_subsequence_of(text, true); + return instance.IsSubsequenceOf(text, true); } // <summary> // Check whether the string contains a valid float. // </summary> - public static bool is_valid_float(this string instance) + public static bool IsValidFloat(this string instance) { float f; return float.TryParse(instance, out f); @@ -432,15 +432,15 @@ namespace Godot // <summary> // Check whether the string contains a valid color in HTML notation. // </summary> - public static bool is_valid_html_color(this string instance) + public static bool IsValidHtmlColor(this string instance) { - return Color.html_is_valid(instance); + return Color.HtmlIsValid(instance); } // <summary> // Check whether the string is a valid identifier. As is common in programming languages, a valid identifier may contain only letters, digits and underscores (_) and the first character may not be a digit. // </summary> - public static bool is_valid_identifier(this string instance) + public static bool IsValidIdentifier(this string instance) { int len = instance.Length; @@ -467,7 +467,7 @@ namespace Godot // <summary> // Check whether the string contains a valid integer. // </summary> - public static bool is_valid_integer(this string instance) + public static bool IsValidInteger(this string instance) { int f; return int.TryParse(instance, out f); @@ -476,7 +476,7 @@ namespace Godot // <summary> // Check whether the string contains a valid IP address. // </summary> - public static bool is_valid_ip_address(this string instance) + public static bool IsValidIpAddress(this string instance) { string[] ip = instance.split("."); @@ -486,7 +486,7 @@ namespace Godot for (int i = 0; i < ip.Length; i++) { string n = ip[i]; - if (!n.is_valid_integer()) + if (!n.IsValidInteger()) return false; int val = n.to_int(); @@ -500,7 +500,7 @@ namespace Godot // <summary> // Return a copy of the string with special characters escaped using the JSON standard. // </summary> - public static string json_escape(this string instance) + public static string JsonEscape(this string instance) { StringBuilder sb = new StringBuilder(string.Copy(instance)); @@ -519,7 +519,7 @@ namespace Godot // <summary> // Return an amount of characters from the left of the string. // </summary> - public static string left(this string instance, int pos) + public static string Left(this string instance, int pos) { if (pos <= 0) return string.Empty; @@ -533,7 +533,7 @@ namespace Godot /// <summary> /// Return the length of the string in characters. /// </summary> - public static int length(this string instance) + public static int Length(this string instance) { return instance.Length; } @@ -541,7 +541,7 @@ namespace Godot // <summary> // Do a simple expression match, where '*' matches zero or more arbitrary characters and '?' matches any single character except '.'. // </summary> - public static bool expr_match(this string instance, string expr, bool case_sensitive) + public static bool ExprMatch(this string instance, string expr, bool caseSensitive) { if (expr.Length == 0 || instance.Length == 0) return false; @@ -551,21 +551,21 @@ namespace Godot case '\0': return instance[0] == 0; case '*': - return expr_match(expr + 1, instance, case_sensitive) || (instance[0] != 0 && expr_match(expr, instance + 1, case_sensitive)); + return ExprMatch(expr + 1, instance, caseSensitive) || (instance[0] != 0 && ExprMatch(expr, instance + 1, caseSensitive)); case '?': - return instance[0] != 0 && instance[0] != '.' && expr_match(expr + 1, instance + 1, case_sensitive); + return instance[0] != 0 && instance[0] != '.' && ExprMatch(expr + 1, instance + 1, caseSensitive); default: - return (case_sensitive ? instance[0] == expr[0] : char.ToUpper(instance[0]) == char.ToUpper(expr[0])) && - expr_match(expr + 1, instance + 1, case_sensitive); + return (caseSensitive ? instance[0] == expr[0] : char.ToUpper(instance[0]) == char.ToUpper(expr[0])) && + ExprMatch(expr + 1, instance + 1, caseSensitive); } } // <summary> // Do a simple case sensitive expression match, using ? and * wildcards (see [method expr_match]). // </summary> - public static bool match(this string instance, string expr) + public static bool Match(this string instance, string expr) { - return instance.expr_match(expr, true); + return instance.ExprMatch(expr, true); } // <summary> @@ -573,13 +573,13 @@ namespace Godot // </summary> public static bool matchn(this string instance, string expr) { - return instance.expr_match(expr, false); + return instance.ExprMatch(expr, false); } // <summary> // Return the MD5 hash of the string as an array of bytes. // </summary> - public static byte[] md5_buffer(this string instance) + public static byte[] Md5Buffer(this string instance) { return NativeCalls.godot_icall_String_md5_buffer(instance); } @@ -587,7 +587,7 @@ namespace Godot // <summary> // Return the MD5 hash of the string as a string. // </summary> - public static string md5_text(this string instance) + public static string Md5Text(this string instance) { return NativeCalls.godot_icall_String_md5_text(instance); } @@ -595,12 +595,12 @@ namespace Godot // <summary> // Perform a case-insensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater. // </summary> - public static int nocasecmp_to(this string instance, string to) + public static int NocasecmpTo(this string instance, string to) { - if (instance.empty()) - return to.empty() ? 0 : -1; + if (instance.Empty()) + return to.Empty() ? 0 : -1; - if (to.empty()) + if (to.Empty()) return 1; int instance_idx = 0; @@ -627,7 +627,7 @@ namespace Godot // <summary> // Return the character code at position [code]at[/code]. // </summary> - public static int ord_at(this string instance, int at) + public static int OrdAt(this string instance, int at) { return instance[at]; } @@ -635,9 +635,9 @@ namespace Godot // <summary> // Format a number to have an exact number of [code]digits[/code] after the decimal point. // </summary> - public static string pad_decimals(this string instance, int digits) + public static string PadDecimals(this string instance, int digits) { - int c = instance.find("."); + int c = instance.Find("."); if (c == -1) { @@ -671,10 +671,10 @@ namespace Godot // <summary> // Format a number to have an exact number of [code]digits[/code] before the decimal point. // </summary> - public static string pad_zeros(this string instance, int digits) + public static string PadZeros(this string instance, int digits) { string s = instance; - int end = s.find("."); + int end = s.Find("."); if (end == -1) end = s.Length; @@ -704,7 +704,7 @@ namespace Godot // <summary> // Decode a percent-encoded string. See [method percent_encode]. // </summary> - public static string percent_decode(this string instance) + public static string PercentDecode(this string instance) { return Uri.UnescapeDataString(instance); } @@ -712,7 +712,7 @@ namespace Godot // <summary> // Percent-encode a string. This is meant to encode parameters in a URL when sending a HTTP GET request and bodies of form-urlencoded POST request. // </summary> - public static string percent_encode(this string instance) + public static string PercentEncode(this string instance) { return Uri.EscapeDataString(instance); } @@ -720,7 +720,7 @@ namespace Godot // <summary> // If the string is a path, this concatenates [code]file[/code] at the end of the string as a subpath. E.g. [code]"this/is".plus_file("path") == "this/is/path"[/code]. // </summary> - public static string plus_file(this string instance, string file) + public static string PlusFile(this string instance, string file) { if (instance.Length > 0 && instance[instance.Length - 1] == '/') return instance + file; @@ -731,7 +731,7 @@ namespace Godot // <summary> // Replace occurrences of a substring for different ones inside the string. // </summary> - public static string replace(this string instance, string what, string forwhat) + public static string Replace(this string instance, string what, string forwhat) { return instance.Replace(what, forwhat); } @@ -739,7 +739,7 @@ namespace Godot // <summary> // Replace occurrences of a substring for different ones inside the string, but search case-insensitive. // </summary> - public static string replacen(this string instance, string what, string forwhat) + public static string Replacen(this string instance, string what, string forwhat) { return Regex.Replace(instance, what, forwhat, RegexOptions.IgnoreCase); } @@ -747,7 +747,7 @@ namespace Godot // <summary> // Perform a search for a substring, but start from the end of the string instead of the beginning. // </summary> - public static int rfind(this string instance, string what, int from = -1) + public static int Rfind(this string instance, string what, int from = -1) { return NativeCalls.godot_icall_String_rfind(instance, what, from); } @@ -755,7 +755,7 @@ namespace Godot // <summary> // Perform a search for a substring, but start from the end of the string instead of the beginning. Also search case-insensitive. // </summary> - public static int rfindn(this string instance, string what, int from = -1) + public static int Rfindn(this string instance, string what, int from = -1) { return NativeCalls.godot_icall_String_rfindn(instance, what, from); } @@ -763,7 +763,7 @@ namespace Godot // <summary> // Return the right side of the string from a given position. // </summary> - public static string right(this string instance, int pos) + public static string Right(this string instance, int pos) { if (pos >= instance.Length) return instance; @@ -774,7 +774,7 @@ namespace Godot return instance.Substring(pos, (instance.Length - pos)); } - public static byte[] sha256_buffer(this string instance) + public static byte[] Sha256Buffer(this string instance) { return NativeCalls.godot_icall_String_sha256_buffer(instance); } @@ -782,7 +782,7 @@ namespace Godot // <summary> // Return the SHA-256 hash of the string as a string. // </summary> - public static string sha256_text(this string instance) + public static string Sha256Text(this string instance) { return NativeCalls.godot_icall_String_sha256_text(instance); } @@ -790,7 +790,7 @@ namespace Godot // <summary> // Return the similarity index of the text compared to this string. 1 means totally similar and 0 means totally dissimilar. // </summary> - public static float similarity(this string instance, string text) + public static float Similarity(this string instance, string text) { if (instance == text) { @@ -803,11 +803,11 @@ namespace Godot return 0.0f; } - string[] src_bigrams = instance.bigrams(); - string[] tgt_bigrams = text.bigrams(); + string[] srcBigrams = instance.Bigrams(); + string[] tgtBigrams = text.Bigrams(); - int src_size = src_bigrams.Length; - int tgt_size = tgt_bigrams.Length; + int src_size = srcBigrams.Length; + int tgt_size = tgtBigrams.Length; float sum = src_size + tgt_size; float inter = 0; @@ -816,7 +816,7 @@ namespace Godot { for (int j = 0; j < tgt_size; j++) { - if (src_bigrams[i] == tgt_bigrams[j]) + if (srcBigrams[i] == tgtBigrams[j]) { inter++; break; @@ -846,7 +846,7 @@ namespace Godot while (true) { - int end = instance.find(divisor, from); + int end = instance.Find(divisor, from); if (end < 0) end = len; if (allow_empty || (end > from)) diff --git a/modules/mono/glue/cs_files/Transform.cs b/modules/mono/glue/cs_files/Transform.cs index 74271e758b..5214100d36 100644 --- a/modules/mono/glue/cs_files/Transform.cs +++ b/modules/mono/glue/cs_files/Transform.cs @@ -9,38 +9,38 @@ namespace Godot public Basis basis; public Vector3 origin; - public Transform affine_inverse() + public Transform AffineInverse() { - Basis basisInv = basis.inverse(); - return new Transform(basisInv, basisInv.xform(-origin)); + Basis basisInv = basis.Inverse(); + return new Transform(basisInv, basisInv.Xform(-origin)); } - public Transform inverse() + public Transform Inverse() { - Basis basisTr = basis.transposed(); - return new Transform(basisTr, basisTr.xform(-origin)); + Basis basisTr = basis.Transposed(); + return new Transform(basisTr, basisTr.Xform(-origin)); } - public Transform looking_at(Vector3 target, Vector3 up) + public Transform LookingAt(Vector3 target, Vector3 up) { Transform t = this; t.set_look_at(origin, target, up); return t; } - public Transform orthonormalized() + public Transform Orthonormalized() { - return new Transform(basis.orthonormalized(), origin); + return new Transform(basis.Orthonormalized(), origin); } - public Transform rotated(Vector3 axis, float phi) + public Transform Rotated(Vector3 axis, float phi) { return new Transform(new Basis(axis, phi), new Vector3()) * this; } - public Transform scaled(Vector3 scale) + public Transform Scaled(Vector3 scale) { - return new Transform(basis.scaled(scale), origin * scale); + return new Transform(basis.Scaled(scale), origin * scale); } public void set_look_at(Vector3 eye, Vector3 target, Vector3 up) @@ -49,44 +49,44 @@ namespace Godot // Z vector Vector3 zAxis = eye - target; - zAxis.normalize(); + zAxis.Normalize(); Vector3 yAxis = up; - Vector3 xAxis = yAxis.cross(zAxis); + Vector3 xAxis = yAxis.Cross(zAxis); // Recompute Y = Z cross X - yAxis = zAxis.cross(xAxis); + yAxis = zAxis.Cross(xAxis); - xAxis.normalize(); - yAxis.normalize(); + xAxis.Normalize(); + yAxis.Normalize(); - basis = Basis.create_from_axes(xAxis, yAxis, zAxis); + basis = Basis.CreateFromAxes(xAxis, yAxis, zAxis); origin = eye; } - public Transform translated(Vector3 ofs) + public Transform Translated(Vector3 ofs) { return new Transform(basis, new Vector3 ( - origin[0] += basis[0].dot(ofs), - origin[1] += basis[1].dot(ofs), - origin[2] += basis[2].dot(ofs) + origin[0] += basis[0].Dot(ofs), + origin[1] += basis[1].Dot(ofs), + origin[2] += basis[2].Dot(ofs) )); } - public Vector3 xform(Vector3 v) + public Vector3 Xform(Vector3 v) { return new Vector3 ( - basis[0].dot(v) + origin.x, - basis[1].dot(v) + origin.y, - basis[2].dot(v) + origin.z + basis[0].Dot(v) + origin.x, + basis[1].Dot(v) + origin.y, + basis[2].Dot(v) + origin.z ); } - public Vector3 xform_inv(Vector3 v) + public Vector3 XformInv(Vector3 v) { Vector3 vInv = v - origin; @@ -100,7 +100,7 @@ namespace Godot public Transform(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis, Vector3 origin) { - this.basis = Basis.create_from_axes(xAxis, yAxis, zAxis); + this.basis = Basis.CreateFromAxes(xAxis, yAxis, zAxis); this.origin = origin; } @@ -118,7 +118,7 @@ namespace Godot public static Transform operator *(Transform left, Transform right) { - left.origin = left.xform(right.origin); + left.origin = left.Xform(right.origin); left.basis *= right.basis; return left; } diff --git a/modules/mono/glue/cs_files/Transform2D.cs b/modules/mono/glue/cs_files/Transform2D.cs index 526dc767c6..fe7c5b5706 100644 --- a/modules/mono/glue/cs_files/Transform2D.cs +++ b/modules/mono/glue/cs_files/Transform2D.cs @@ -29,12 +29,12 @@ namespace Godot public float Rotation { - get { return Mathf.atan2(y.x, o.y); } + get { return Mathf.Atan2(y.x, o.y); } } public Vector2 Scale { - get { return new Vector2(x.length(), y.length()); } + get { return new Vector2(x.Length(), y.Length()); } } public Vector2 this[int index] @@ -103,7 +103,7 @@ namespace Godot } } - public Transform2D affine_inverse() + public Transform2D AffineInverse() { Transform2D inv = this; @@ -128,22 +128,22 @@ namespace Godot this[0] *= new Vector2(idet, -idet); this[1] *= new Vector2(-idet, idet); - this[2] = basis_xform(-this[2]); + this[2] = BasisXform(-this[2]); return inv; } - public Vector2 basis_xform(Vector2 v) + public Vector2 BasisXform(Vector2 v) { - return new Vector2(tdotx(v), tdoty(v)); + return new Vector2(Tdotx(v), Tdoty(v)); } - public Vector2 basis_xform_inv(Vector2 v) + public Vector2 BasisXformInv(Vector2 v) { - return new Vector2(x.dot(v), y.dot(v)); + return new Vector2(x.Dot(v), y.Dot(v)); } - public Transform2D interpolate_with(Transform2D m, float c) + public Transform2D InterpolateWith(Transform2D m, float c) { float r1 = Rotation; float r2 = m.Rotation; @@ -152,10 +152,10 @@ namespace Godot Vector2 s2 = m.Scale; // Slerp rotation - Vector2 v1 = new Vector2(Mathf.cos(r1), Mathf.sin(r1)); - Vector2 v2 = new Vector2(Mathf.cos(r2), Mathf.sin(r2)); + Vector2 v1 = new Vector2(Mathf.Cos(r1), Mathf.Sin(r1)); + Vector2 v2 = new Vector2(Mathf.Cos(r2), Mathf.Sin(r2)); - float dot = v1.dot(v2); + float dot = v1.Dot(v2); // Clamp dot to [-1, 1] dot = (dot < -1.0f) ? -1.0f : ((dot > 1.0f) ? 1.0f : dot); @@ -165,13 +165,13 @@ namespace Godot if (dot > 0.9995f) { // Linearly interpolate to avoid numerical precision issues - v = v1.linear_interpolate(v2, c).normalized(); + v = v1.LinearInterpolate(v2, c).Normalized(); } else { - float angle = c * Mathf.acos(dot); - Vector2 v3 = (v2 - v1 * dot).normalized(); - v = v1 * Mathf.cos(angle) + v3 * Mathf.sin(angle); + float angle = c * Mathf.Acos(dot); + Vector2 v3 = (v2 - v1 * dot).Normalized(); + v = v1 * Mathf.Cos(angle) + v3 * Mathf.Sin(angle); } // Extract parameters @@ -179,15 +179,15 @@ namespace Godot Vector2 p2 = m.Origin; // Construct matrix - Transform2D res = new Transform2D(Mathf.atan2(v.y, v.x), p1.linear_interpolate(p2, c)); - Vector2 scale = s1.linear_interpolate(s2, c); + Transform2D res = new Transform2D(Mathf.Atan2(v.y, v.x), p1.LinearInterpolate(p2, c)); + Vector2 scale = s1.LinearInterpolate(s2, c); res.x *= scale; res.y *= scale; return res; } - public Transform2D inverse() + public Transform2D Inverse() { Transform2D inv = this; @@ -196,21 +196,21 @@ namespace Godot inv.x.y = inv.y.x; inv.y.x = temp; - inv.o = inv.basis_xform(-inv.o); + inv.o = inv.BasisXform(-inv.o); return inv; } - public Transform2D orthonormalized() + public Transform2D Orthonormalized() { Transform2D on = this; Vector2 onX = on.x; Vector2 onY = on.y; - onX.normalize(); - onY = onY - onX * (onX.dot(onY)); - onY.normalize(); + onX.Normalize(); + onY = onY - onX * (onX.Dot(onY)); + onY.Normalize(); on.x = onX; on.y = onY; @@ -218,12 +218,12 @@ namespace Godot return on; } - public Transform2D rotated(float phi) + public Transform2D Rotated(float phi) { return this * new Transform2D(phi, new Vector2()); } - public Transform2D scaled(Vector2 scale) + public Transform2D Scaled(Vector2 scale) { Transform2D copy = this; copy.x *= scale; @@ -232,32 +232,32 @@ namespace Godot return copy; } - private float tdotx(Vector2 with) + private float Tdotx(Vector2 with) { return this[0, 0] * with[0] + this[1, 0] * with[1]; } - private float tdoty(Vector2 with) + private float Tdoty(Vector2 with) { return this[0, 1] * with[0] + this[1, 1] * with[1]; } - public Transform2D translated(Vector2 offset) + public Transform2D Translated(Vector2 offset) { Transform2D copy = this; - copy.o += copy.basis_xform(offset); + copy.o += copy.BasisXform(offset); return copy; } - public Vector2 xform(Vector2 v) + public Vector2 Xform(Vector2 v) { - return new Vector2(tdotx(v), tdoty(v)) + o; + return new Vector2(Tdotx(v), Tdoty(v)) + o; } - public Vector2 xform_inv(Vector2 v) + public Vector2 XformInv(Vector2 v) { Vector2 vInv = v - o; - return new Vector2(x.dot(vInv), y.dot(vInv)); + return new Vector2(x.Dot(vInv), y.Dot(vInv)); } public Transform2D(Vector2 xAxis, Vector2 yAxis, Vector2 origin) @@ -275,8 +275,8 @@ namespace Godot public Transform2D(float rot, Vector2 pos) { - float cr = Mathf.cos(rot); - float sr = Mathf.sin(rot); + float cr = Mathf.Cos(rot); + float sr = Mathf.Sin(rot); x.x = cr; y.y = cr; x.y = -sr; @@ -286,14 +286,14 @@ namespace Godot public static Transform2D operator *(Transform2D left, Transform2D right) { - left.o = left.xform(right.o); + left.o = left.Xform(right.o); float x0, x1, y0, y1; - x0 = left.tdotx(right.x); - x1 = left.tdoty(right.x); - y0 = left.tdotx(right.y); - y1 = left.tdoty(right.y); + x0 = left.Tdotx(right.x); + x1 = left.Tdoty(right.x); + y0 = left.Tdotx(right.y); + y1 = left.Tdoty(right.y); left.x.x = x0; left.x.y = x1; diff --git a/modules/mono/glue/cs_files/Vector2.cs b/modules/mono/glue/cs_files/Vector2.cs index 28fedc365b..238775bda2 100644 --- a/modules/mono/glue/cs_files/Vector2.cs +++ b/modules/mono/glue/cs_files/Vector2.cs @@ -46,57 +46,57 @@ namespace Godot } } - internal void normalize() + internal void Normalize() { float length = x * x + y * y; if (length != 0f) { - length = Mathf.sqrt(length); + length = Mathf.Sqrt(length); x /= length; y /= length; } } - private float cross(Vector2 b) + private float Cross(Vector2 b) { return x * b.y - y * b.x; } - public Vector2 abs() + public Vector2 Abs() { - return new Vector2(Mathf.abs(x), Mathf.abs(y)); + return new Vector2(Mathf.Abs(x), Mathf.Abs(y)); } - public float angle() + public float Angle() { - return Mathf.atan2(y, x); + return Mathf.Atan2(y, x); } - public float angle_to(Vector2 to) + public float AngleTo(Vector2 to) { - return Mathf.atan2(cross(to), dot(to)); + return Mathf.Atan2(Cross(to), Dot(to)); } - public float angle_to_point(Vector2 to) + public float AngleToPoint(Vector2 to) { - return Mathf.atan2(x - to.x, y - to.y); + return Mathf.Atan2(x - to.x, y - to.y); } - public float aspect() + public float Aspect() { return x / y; } - public Vector2 bounce(Vector2 n) + public Vector2 Bounce(Vector2 n) { - return -reflect(n); + return -Reflect(n); } - public Vector2 clamped(float length) + public Vector2 Clamped(float length) { Vector2 v = this; - float l = this.length(); + float l = this.Length(); if (l > 0 && length < l) { @@ -107,7 +107,7 @@ namespace Godot return v; } - public Vector2 cubic_interpolate(Vector2 b, Vector2 preA, Vector2 postB, float t) + public Vector2 CubicInterpolate(Vector2 b, Vector2 preA, Vector2 postB, float t) { Vector2 p0 = preA; Vector2 p1 = this; @@ -123,42 +123,42 @@ namespace Godot (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * t3); } - public float distance_squared_to(Vector2 to) + public float DistanceSquaredTo(Vector2 to) { return (x - to.x) * (x - to.x) + (y - to.y) * (y - to.y); } - public float distance_to(Vector2 to) + public float DistanceTo(Vector2 to) { - return Mathf.sqrt((x - to.x) * (x - to.x) + (y - to.y) * (y - to.y)); + return Mathf.Sqrt((x - to.x) * (x - to.x) + (y - to.y) * (y - to.y)); } - public float dot(Vector2 with) + public float Dot(Vector2 with) { return x * with.x + y * with.y; } - public Vector2 floor() + public Vector2 Floor() { - return new Vector2(Mathf.floor(x), Mathf.floor(y)); + return new Vector2(Mathf.Floor(x), Mathf.Floor(y)); } - public bool is_normalized() + public bool IsNormalized() { - return Mathf.abs(length_squared() - 1.0f) < Mathf.Epsilon; + return Mathf.Abs(LengthSquared() - 1.0f) < Mathf.Epsilon; } - public float length() + public float Length() { - return Mathf.sqrt(x * x + y * y); + return Mathf.Sqrt(x * x + y * y); } - public float length_squared() + public float LengthSquared() { return x * x + y * y; } - public Vector2 linear_interpolate(Vector2 b, float t) + public Vector2 LinearInterpolate(Vector2 b, float t) { Vector2 res = this; @@ -168,35 +168,35 @@ namespace Godot return res; } - public Vector2 normalized() + public Vector2 Normalized() { Vector2 result = this; - result.normalize(); + result.Normalize(); return result; } - public Vector2 reflect(Vector2 n) + public Vector2 Reflect(Vector2 n) { - return 2.0f * n * dot(n) - this; + return 2.0f * n * Dot(n) - this; } - public Vector2 rotated(float phi) + public Vector2 Rotated(float phi) { - float rads = angle() + phi; - return new Vector2(Mathf.cos(rads), Mathf.sin(rads)) * length(); + float rads = Angle() + phi; + return new Vector2(Mathf.Cos(rads), Mathf.Sin(rads)) * Length(); } - public Vector2 slide(Vector2 n) + public Vector2 Slide(Vector2 n) { - return this - n * dot(n); + return this - n * Dot(n); } - public Vector2 snapped(Vector2 by) + public Vector2 Snapped(Vector2 by) { - return new Vector2(Mathf.stepify(x, by.x), Mathf.stepify(y, by.y)); + return new Vector2(Mathf.Stepify(x, by.x), Mathf.Stepify(y, by.y)); } - public Vector2 tangent() + public Vector2 Tangent() { return new Vector2(y, -x); } diff --git a/modules/mono/glue/cs_files/Vector3.cs b/modules/mono/glue/cs_files/Vector3.cs index c023cd83cf..190caa4b53 100644 --- a/modules/mono/glue/cs_files/Vector3.cs +++ b/modules/mono/glue/cs_files/Vector3.cs @@ -59,9 +59,9 @@ namespace Godot } } - internal void normalize() + internal void Normalize() { - float length = this.length(); + float length = this.Length(); if (length == 0f) { @@ -75,27 +75,27 @@ namespace Godot } } - public Vector3 abs() + public Vector3 Abs() { - return new Vector3(Mathf.abs(x), Mathf.abs(y), Mathf.abs(z)); + return new Vector3(Mathf.Abs(x), Mathf.Abs(y), Mathf.Abs(z)); } - public float angle_to(Vector3 to) + public float AngleTo(Vector3 to) { - return Mathf.atan2(cross(to).length(), dot(to)); + return Mathf.Atan2(Cross(to).Length(), Dot(to)); } - public Vector3 bounce(Vector3 n) + public Vector3 Bounce(Vector3 n) { - return -reflect(n); + return -Reflect(n); } - public Vector3 ceil() + public Vector3 Ceil() { - return new Vector3(Mathf.ceil(x), Mathf.ceil(y), Mathf.ceil(z)); + return new Vector3(Mathf.Ceil(x), Mathf.Ceil(y), Mathf.Ceil(z)); } - public Vector3 cross(Vector3 b) + public Vector3 Cross(Vector3 b) { return new Vector3 ( @@ -105,7 +105,7 @@ namespace Godot ); } - public Vector3 cubic_interpolate(Vector3 b, Vector3 preA, Vector3 postB, float t) + public Vector3 CubicInterpolate(Vector3 b, Vector3 preA, Vector3 postB, float t) { Vector3 p0 = preA; Vector3 p1 = this; @@ -122,46 +122,46 @@ namespace Godot ); } - public float distance_squared_to(Vector3 b) + public float DistanceSquaredTo(Vector3 b) { - return (b - this).length_squared(); + return (b - this).LengthSquared(); } - public float distance_to(Vector3 b) + public float DistanceTo(Vector3 b) { - return (b - this).length(); + return (b - this).Length(); } - public float dot(Vector3 b) + public float Dot(Vector3 b) { return x * b.x + y * b.y + z * b.z; } - public Vector3 floor() + public Vector3 Floor() { - return new Vector3(Mathf.floor(x), Mathf.floor(y), Mathf.floor(z)); + return new Vector3(Mathf.Floor(x), Mathf.Floor(y), Mathf.Floor(z)); } - public Vector3 inverse() + public Vector3 Inverse() { return new Vector3(1.0f / x, 1.0f / y, 1.0f / z); } - public bool is_normalized() + public bool IsNormalized() { - return Mathf.abs(length_squared() - 1.0f) < Mathf.Epsilon; + return Mathf.Abs(LengthSquared() - 1.0f) < Mathf.Epsilon; } - public float length() + public float Length() { float x2 = x * x; float y2 = y * y; float z2 = z * z; - return Mathf.sqrt(x2 + y2 + z2); + return Mathf.Sqrt(x2 + y2 + z2); } - public float length_squared() + public float LengthSquared() { float x2 = x * x; float y2 = y * y; @@ -170,7 +170,7 @@ namespace Godot return x2 + y2 + z2; } - public Vector3 linear_interpolate(Vector3 b, float t) + public Vector3 LinearInterpolate(Vector3 b, float t) { return new Vector3 ( @@ -180,24 +180,24 @@ namespace Godot ); } - public Axis max_axis() + public Axis MaxAxis() { return x < y ? (y < z ? Axis.Z : Axis.Y) : (x < z ? Axis.Z : Axis.X); } - public Axis min_axis() + public Axis MinAxis() { return x < y ? (x < z ? Axis.X : Axis.Z) : (y < z ? Axis.Y : Axis.Z); } - public Vector3 normalized() + public Vector3 Normalized() { Vector3 v = this; - v.normalize(); + v.Normalize(); return v; } - public Basis outer(Vector3 b) + public Basis Outer(Vector3 b) { return new Basis( new Vector3(x * b.x, x * b.y, x * b.z), @@ -206,36 +206,36 @@ namespace Godot ); } - public Vector3 reflect(Vector3 n) + public Vector3 Reflect(Vector3 n) { #if DEBUG - if (!n.is_normalized()) + if (!n.IsNormalized()) throw new ArgumentException(String.Format("{0} is not normalized", n), nameof(n)); #endif - return 2.0f * n * dot(n) - this; + return 2.0f * n * Dot(n) - this; } - public Vector3 rotated(Vector3 axis, float phi) + public Vector3 Rotated(Vector3 axis, float phi) { - return new Basis(axis, phi).xform(this); + return new Basis(axis, phi).Xform(this); } - public Vector3 slide(Vector3 n) + public Vector3 Slide(Vector3 n) { - return this - n * dot(n); + return this - n * Dot(n); } - public Vector3 snapped(Vector3 by) + public Vector3 Snapped(Vector3 by) { return new Vector3 ( - Mathf.stepify(x, by.x), - Mathf.stepify(y, by.y), - Mathf.stepify(z, by.z) + Mathf.Stepify(x, by.x), + Mathf.Stepify(y, by.y), + Mathf.Stepify(z, by.z) ); } - public Basis to_diagonal_matrix() + public Basis ToDiagonalMatrix() { return new Basis( x, 0f, 0f, diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 951fc002b7..5c252bda86 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -36,54 +36,36 @@ #include "thirdparty/misc/stb_vorbis.c" #pragma GCC diagnostic pop -#ifndef CLAMP -#define CLAMP(m_a, m_min, m_max) (((m_a) < (m_min)) ? (m_min) : (((m_a) > (m_max)) ? m_max : m_a)) -#endif - void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) { ERR_FAIL_COND(!active); int todo = p_frames; - int start_buffer = 0; + while (todo && active) { - while (todo > 0 && active) { - float *buffer = (float *)p_buffer; - if (start_buffer > 0) { - buffer = (buffer + start_buffer * 2); - } - int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, buffer, todo * 2); + int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, (float *)p_buffer, todo * 2); if (vorbis_stream->channels == 1 && mixed > 0) { //mix mono to stereo - for (int i = start_buffer; i < mixed; i++) { + for (int i = 0; i < mixed; i++) { p_buffer[i].r = p_buffer[i].l; } } todo -= mixed; frames_mixed += mixed; - if (todo > 0) { + if (todo) { //end of file! if (vorbis_stream->loop) { - //loop to the loop_beginning - seek(vorbis_stream->loop_begin); + //loop + seek(vorbis_stream->loop_offset); loops++; - // we still have buffer to fill, start from this element in the next iteration. - start_buffer = p_frames - todo; } else { - for (int i = p_frames - todo; i < p_frames; i++) { + for (int i = mixed; i < p_frames; i++) { p_buffer[i] = AudioFrame(0, 0); } active = false; - todo = 0; } - } else if (vorbis_stream->loop && frames_mixed >= vorbis_stream->loop_end_frames) { - // We reached loop_end. Loop to loop_begin plus whatever extra length we already mixed - uint32_t frames_to_advance = uint32_t(frames_mixed - vorbis_stream->loop_end_frames); - float start_loop = vorbis_stream->loop_begin + (float(frames_to_advance) / vorbis_stream->sample_rate); - seek(start_loop); - loops++; } } } @@ -217,9 +199,6 @@ void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) { //print_line("succeeded "+itos(ogg_alloc.alloc_buffer_length_in_bytes)+" setup "+itos(info.setup_memory_required)+" setup temp "+itos(info.setup_temp_memory_required)+" temp "+itos(info.temp_memory_required)+" maxframe"+itos(info.max_frame_size)); length = stb_vorbis_stream_length_in_seconds(ogg_stream); - if (loop_end == 0) { - set_loop_end(length); - } stb_vorbis_close(ogg_stream); data = AudioServer::get_singleton()->audio_data_alloc(src_data_len, src_datar.ptr()); @@ -254,24 +233,12 @@ bool AudioStreamOGGVorbis::has_loop() const { return loop; } -void AudioStreamOGGVorbis::set_loop_begin(float p_seconds) { - p_seconds = CLAMP(p_seconds, 0, length); - loop_begin = p_seconds; - loop_begin_frames = uint32_t(sample_rate * p_seconds); -} - -float AudioStreamOGGVorbis::get_loop_begin() const { - return loop_begin; -} - -void AudioStreamOGGVorbis::set_loop_end(float p_seconds) { - p_seconds = CLAMP(p_seconds, 0, length); - loop_end = p_seconds; - loop_end_frames = uint32_t(sample_rate * p_seconds); +void AudioStreamOGGVorbis::set_loop_offset(float p_seconds) { + loop_offset = p_seconds; } -float AudioStreamOGGVorbis::get_loop_end() const { - return loop_end; +float AudioStreamOGGVorbis::get_loop_offset() const { + return loop_offset; } void AudioStreamOGGVorbis::_bind_methods() { @@ -282,16 +249,12 @@ void AudioStreamOGGVorbis::_bind_methods() { ClassDB::bind_method(D_METHOD("set_loop", "enable"), &AudioStreamOGGVorbis::set_loop); ClassDB::bind_method(D_METHOD("has_loop"), &AudioStreamOGGVorbis::has_loop); - ClassDB::bind_method(D_METHOD("set_loop_begin", "seconds"), &AudioStreamOGGVorbis::set_loop_begin); - ClassDB::bind_method(D_METHOD("get_loop_begin"), &AudioStreamOGGVorbis::get_loop_begin); - - ClassDB::bind_method(D_METHOD("set_loop_end", "seconds"), &AudioStreamOGGVorbis::set_loop_end); - ClassDB::bind_method(D_METHOD("get_loop_end"), &AudioStreamOGGVorbis::get_loop_end); + ClassDB::bind_method(D_METHOD("set_loop_offset", "seconds"), &AudioStreamOGGVorbis::set_loop_offset); + ClassDB::bind_method(D_METHOD("get_loop_offset"), &AudioStreamOGGVorbis::get_loop_offset); ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_data", "get_data"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop", "has_loop"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "loop_begin", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop_begin", "get_loop_begin"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "loop_end", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop_end", "get_loop_end"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "loop_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop_offset", "get_loop_offset"); } AudioStreamOGGVorbis::AudioStreamOGGVorbis() { @@ -300,10 +263,7 @@ AudioStreamOGGVorbis::AudioStreamOGGVorbis() { length = 0; sample_rate = 1; channels = 1; - loop_begin = 0; - loop_end = 0; - loop_begin_frames = 0; - loop_end_frames = 0; + loop_offset = 0; decode_mem_size = 0; - loop = true; + loop = false; } diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index 9297d2246b..f4d381897b 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -92,11 +92,7 @@ class AudioStreamOGGVorbis : public AudioStream { int channels; float length; bool loop; - float loop_begin; - float loop_end; - - uint32_t loop_begin_frames; - uint32_t loop_end_frames; + float loop_offset; protected: static void _bind_methods(); @@ -105,11 +101,8 @@ public: void set_loop(bool p_enable); bool has_loop() const; - void set_loop_begin(float p_seconds); - float get_loop_begin() const; - - void set_loop_end(float p_seconds); - float get_loop_end() const; + void set_loop_offset(float p_seconds); + float get_loop_offset() const; virtual Ref<AudioStreamPlayback> instance_playback(); virtual String get_stream_name() const; diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp index b7949e381c..4d28dc027b 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -72,15 +72,13 @@ String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const { void ResourceImporterOGGVorbis::get_import_options(List<ImportOption> *r_options, int p_preset) const { r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "loop"), true)); - r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "loop_begin"), 0)); - r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "loop_end"), 0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "loop_offset"), 0)); } Error ResourceImporterOGGVorbis::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { bool loop = p_options["loop"]; - float loop_begin = p_options["loop_begin"]; - float loop_end = p_options["loop_end"]; + float loop_offset = p_options["loop_offset"]; FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ); if (!f) { @@ -102,8 +100,7 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin ogg_stream->set_data(data); ogg_stream->set_loop(loop); - ogg_stream->set_loop_begin(loop_begin); - if (loop_end > 0) ogg_stream->set_loop_end(loop_end); + ogg_stream->set_loop_offset(loop_offset); return ResourceSaver::save(p_save_path + ".oggstr", ogg_stream); } diff --git a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml index 27231574d7..c45c8d2b64 100644 --- a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml +++ b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml @@ -151,68 +151,74 @@ <constant name="MATH_DB2LINEAR" value="39"> Convert the input from decibel volume to linear volume. </constant> - <constant name="MATH_WRAP" value="40"> + <constant name="MATH_POLAR2CARTESIAN" value="40"> + Converts a 2D point expressed in the polar coordinate system (a distance from the origin [code]r[/code] and an angle [code]th[/code]) to the cartesian coordinate system (x and y axis). </constant> - <constant name="MATH_WRAPF" value="41"> + <constant name="MATH_CARTESIAN2POLAR" value="41"> + Converts a 2D point expressed in the cartesian coordinate system (x and y axis) to the polar coordinate system (a distance from the origin and an angle). </constant> - <constant name="LOGIC_MAX" value="42"> + <constant name="MATH_WRAP" value="42"> + </constant> + <constant name="MATH_WRAPF" value="43"> + </constant> + <constant name="LOGIC_MAX" value="44"> Return the greater of the two numbers, also known as their maximum. </constant> - <constant name="LOGIC_MIN" value="43"> + <constant name="LOGIC_MIN" value="45"> Return the lesser of the two numbers, also known as their minimum. </constant> - <constant name="LOGIC_CLAMP" value="44"> + <constant name="LOGIC_CLAMP" value="46"> Return the input clamped inside the given range, ensuring the result is never outside it. Equivalent to `min(max(input, range_low), range_high)` </constant> - <constant name="LOGIC_NEAREST_PO2" value="45"> + <constant name="LOGIC_NEAREST_PO2" value="46"> Return the nearest power of 2 to the input. </constant> - <constant name="OBJ_WEAKREF" value="46"> + <constant name="OBJ_WEAKREF" value="47"> Create a [WeakRef] from the input. </constant> - <constant name="FUNC_FUNCREF" value="47"> + <constant name="FUNC_FUNCREF" value="48"> Create a [FuncRef] from the input. </constant> - <constant name="TYPE_CONVERT" value="48"> + <constant name="TYPE_CONVERT" value="49"> Convert between types. </constant> - <constant name="TYPE_OF" value="49"> + <constant name="TYPE_OF" value="50"> Return the type of the input as an integer. Check [enum Variant.Type] for the integers that might be returned. </constant> - <constant name="TYPE_EXISTS" value="50"> + <constant name="TYPE_EXISTS" value="51"> Checks if a type is registered in the [ClassDB]. </constant> - <constant name="TEXT_CHAR" value="51"> + <constant name="TEXT_CHAR" value="52"> Return a character with the given ascii value. </constant> - <constant name="TEXT_STR" value="52"> + <constant name="TEXT_STR" value="53"> Convert the input to a string. </constant> - <constant name="TEXT_PRINT" value="53"> + <constant name="TEXT_PRINT" value="54"> Print the given string to the output window. </constant> - <constant name="TEXT_PRINTERR" value="54"> + <constant name="TEXT_PRINTERR" value="55"> Print the given string to the standard error output. </constant> - <constant name="TEXT_PRINTRAW" value="55"> + <constant name="TEXT_PRINTRAW" value="56"> Print the given string to the standard output, without adding a newline. </constant> - <constant name="VAR_TO_STR" value="56"> + <constant name="VAR_TO_STR" value="57"> Serialize a [Variant] to a string. </constant> - <constant name="STR_TO_VAR" value="57"> + <constant name="STR_TO_VAR" value="58"> Deserialize a [Variant] from a string serialized using [VAR_TO_STR]. </constant> - <constant name="VAR_TO_BYTES" value="58"> + <constant name="VAR_TO_BYTES" value="59"> Serialize a [Variant] to a [PoolByteArray]. </constant> - <constant name="BYTES_TO_VAR" value="59"> + <constant name="BYTES_TO_VAR" value="60"> Deserialize a [Variant] from a [PoolByteArray] serialized using [VAR_TO_BYTES]. </constant> - <constant name="COLORN" value="60"> + <constant name="COLORN" value="61"> Return the [Color] with the given name and alpha ranging from 0 to 1. Note: names are defined in color_names.inc. </constant> - <constant name="FUNC_MAX" value="61"> + <constant name="FUNC_MAX" value="62"> The maximum value the [member function] property can have. </constant> </constants> diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 8f7fe58bee..32f7519125 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -78,6 +78,8 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX "rad2deg", "linear2db", "db2linear", + "polar2cartesian", + "cartesian2polar", "wrapi", "wrapf", "max", @@ -191,6 +193,8 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { case MATH_EASE: case MATH_STEPIFY: case MATH_RANDOM: + case MATH_POLAR2CARTESIAN: + case MATH_CARTESIAN2POLAR: case LOGIC_MAX: case LOGIC_MIN: case FUNC_FUNCREF: @@ -368,6 +372,18 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const case MATH_DB2LINEAR: { return PropertyInfo(Variant::REAL, "db"); } break; + case MATH_POLAR2CARTESIAN: { + if (p_idx == 0) + return PropertyInfo(Variant::REAL, "r"); + else + return PropertyInfo(Variant::REAL, "th"); + } break; + case MATH_CARTESIAN2POLAR: { + if (p_idx == 0) + return PropertyInfo(Variant::REAL, "x"); + else + return PropertyInfo(Variant::REAL, "y"); + } break; case MATH_WRAP: { if (p_idx == 0) return PropertyInfo(Variant::INT, "value"); @@ -573,6 +589,10 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons case MATH_DB2LINEAR: { t = Variant::REAL; } break; + case MATH_POLAR2CARTESIAN: + case MATH_CARTESIAN2POLAR: { + t = Variant::VECTOR2; + } break; case MATH_WRAP: { t = Variant::INT; } break; @@ -922,6 +942,20 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in VALIDATE_ARG_NUM(0); *r_return = Math::db2linear((double)*p_inputs[0]); } break; + case VisualScriptBuiltinFunc::MATH_POLAR2CARTESIAN: { + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + double r = *p_inputs[0]; + double th = *p_inputs[1]; + *r_return = Vector2(r * Math::cos(th), r * Math::sin(th)); + } break; + case VisualScriptBuiltinFunc::MATH_CARTESIAN2POLAR: { + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + double x = *p_inputs[0]; + double y = *p_inputs[1]; + *r_return = Vector2(Math::sqrt(x * x + y * y), Math::atan2(y, x)); + } break; case VisualScriptBuiltinFunc::MATH_WRAP: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); @@ -1294,6 +1328,8 @@ void VisualScriptBuiltinFunc::_bind_methods() { BIND_ENUM_CONSTANT(MATH_RAD2DEG); BIND_ENUM_CONSTANT(MATH_LINEAR2DB); BIND_ENUM_CONSTANT(MATH_DB2LINEAR); + BIND_ENUM_CONSTANT(MATH_POLAR2CARTESIAN); + BIND_ENUM_CONSTANT(MATH_CARTESIAN2POLAR); BIND_ENUM_CONSTANT(MATH_WRAP); BIND_ENUM_CONSTANT(MATH_WRAPF); BIND_ENUM_CONSTANT(LOGIC_MAX); @@ -1381,6 +1417,8 @@ void register_visual_script_builtin_func_node() { VisualScriptLanguage::singleton->add_register_func("functions/built_in/rad2deg", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RAD2DEG>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/linear2db", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LINEAR2DB>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/db2linear", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DB2LINEAR>); + VisualScriptLanguage::singleton->add_register_func("functions/built_in/polar2cartesian", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_POLAR2CARTESIAN>); + VisualScriptLanguage::singleton->add_register_func("functions/built_in/cartesian2polar", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_CARTESIAN2POLAR>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapi", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAP>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapf", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAPF>); diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index 34a2825938..54dc997b38 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -77,6 +77,8 @@ public: MATH_RAD2DEG, MATH_LINEAR2DB, MATH_DB2LINEAR, + MATH_POLAR2CARTESIAN, + MATH_CARTESIAN2POLAR, MATH_WRAP, MATH_WRAPF, LOGIC_MAX, diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 83b8d8da2d..2318149ca5 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -1389,7 +1389,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & if (String(d["type"]) == "obj_property") { #ifdef OSX_ENABLED - const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a Getter. Hold Shift to drop a generic signature.")); + const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Getter. Hold Shift to drop a generic signature."), find_keycode_name(KEY_META))); #else const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Getter. Hold Shift to drop a generic signature.")); #endif @@ -1398,7 +1398,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & if (String(d["type"]) == "nodes") { #ifdef OSX_ENABLED - const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a simple reference to the node.")); + const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a simple reference to the node."), find_keycode_name(KEY_META))); #else const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a simple reference to the node.")); #endif @@ -1407,7 +1407,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & if (String(d["type"]) == "visual_script_variable_drag") { #ifdef OSX_ENABLED - const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a Variable Setter.")); + const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Variable Setter."), find_keycode_name(KEY_META))); #else const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Variable Setter.")); #endif diff --git a/modules/webm/config.py b/modules/webm/config.py index 0374bb36f7..dcae4447d5 100644 --- a/modules/webm/config.py +++ b/modules/webm/config.py @@ -1,5 +1,5 @@ def can_build(platform): - return True + return platform != 'iphone' def configure(env): pass |