diff options
Diffstat (limited to 'core')
92 files changed, 1457 insertions, 702 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 3e289eeaf3..1c9eef3d16 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -112,8 +112,8 @@ bool _ResourceLoader::has(const String &p_path) { void _ResourceLoader::_bind_methods() { - ClassDB::bind_method(D_METHOD("load_interactive:ResourceInteractiveLoader", "path", "type_hint"), &_ResourceLoader::load_interactive, DEFVAL("")); - ClassDB::bind_method(D_METHOD("load:Resource", "path", "type_hint", "p_no_cache"), &_ResourceLoader::load, DEFVAL(""), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("load_interactive", "path", "type_hint"), &_ResourceLoader::load_interactive, DEFVAL("")); + ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "p_no_cache"), &_ResourceLoader::load, DEFVAL(""), DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &_ResourceLoader::get_recognized_extensions_for_type); ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources", "abort"), &_ResourceLoader::set_abort_on_missing_resources); ClassDB::bind_method(D_METHOD("get_dependencies", "path"), &_ResourceLoader::get_dependencies); @@ -148,8 +148,8 @@ _ResourceSaver *_ResourceSaver::singleton = NULL; void _ResourceSaver::_bind_methods() { - ClassDB::bind_method(D_METHOD("save", "path", "resource:Resource", "flags"), &_ResourceSaver::save, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type:Resource"), &_ResourceSaver::get_recognized_extensions); + ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &_ResourceSaver::save, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &_ResourceSaver::get_recognized_extensions); BIND_CONSTANT(FLAG_RELATIVE_PATHS); BIND_CONSTANT(FLAG_BUNDLE_RESOURCES); @@ -1038,7 +1038,7 @@ void _OS::_bind_methods() { &_OS::get_unix_time_from_datetime); ClassDB::bind_method(D_METHOD("get_system_time_secs"), &_OS::get_system_time_secs); - ClassDB::bind_method(D_METHOD("set_icon", "icon:Image"), &_OS::set_icon); + ClassDB::bind_method(D_METHOD("set_icon", "icon"), &_OS::set_icon); ClassDB::bind_method(D_METHOD("get_exit_code"), &_OS::get_exit_code); ClassDB::bind_method(D_METHOD("set_exit_code", "code"), &_OS::set_exit_code); @@ -1750,7 +1750,7 @@ void _File::_bind_methods() { ClassDB::bind_method(D_METHOD("get_sha256", "path"), &_File::get_sha256); ClassDB::bind_method(D_METHOD("get_endian_swap"), &_File::get_endian_swap); ClassDB::bind_method(D_METHOD("set_endian_swap", "enable"), &_File::set_endian_swap); - ClassDB::bind_method(D_METHOD("get_error:Error"), &_File::get_error); + ClassDB::bind_method(D_METHOD("get_error"), &_File::get_error); ClassDB::bind_method(D_METHOD("get_var"), &_File::get_var); ClassDB::bind_method(D_METHOD("get_csv_line", "delim"), &_File::get_csv_line, DEFVAL(",")); @@ -1954,7 +1954,7 @@ Error _Directory::remove(String p_name) { void _Directory::_bind_methods() { - ClassDB::bind_method(D_METHOD("open:Error", "path"), &_Directory::open); + ClassDB::bind_method(D_METHOD("open", "path"), &_Directory::open); ClassDB::bind_method(D_METHOD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_next"), &_Directory::get_next); ClassDB::bind_method(D_METHOD("current_is_dir"), &_Directory::current_is_dir); @@ -1962,17 +1962,17 @@ void _Directory::_bind_methods() { ClassDB::bind_method(D_METHOD("get_drive_count"), &_Directory::get_drive_count); ClassDB::bind_method(D_METHOD("get_drive", "idx"), &_Directory::get_drive); ClassDB::bind_method(D_METHOD("get_current_drive"), &_Directory::get_current_drive); - ClassDB::bind_method(D_METHOD("change_dir:Error", "todir"), &_Directory::change_dir); + ClassDB::bind_method(D_METHOD("change_dir", "todir"), &_Directory::change_dir); ClassDB::bind_method(D_METHOD("get_current_dir"), &_Directory::get_current_dir); - ClassDB::bind_method(D_METHOD("make_dir:Error", "path"), &_Directory::make_dir); - ClassDB::bind_method(D_METHOD("make_dir_recursive:Error", "path"), &_Directory::make_dir_recursive); + ClassDB::bind_method(D_METHOD("make_dir", "path"), &_Directory::make_dir); + ClassDB::bind_method(D_METHOD("make_dir_recursive", "path"), &_Directory::make_dir_recursive); ClassDB::bind_method(D_METHOD("file_exists", "path"), &_Directory::file_exists); ClassDB::bind_method(D_METHOD("dir_exists", "path"), &_Directory::dir_exists); //ClassDB::bind_method(D_METHOD("get_modified_time","file"),&_Directory::get_modified_time); ClassDB::bind_method(D_METHOD("get_space_left"), &_Directory::get_space_left); - ClassDB::bind_method(D_METHOD("copy:Error", "from", "to"), &_Directory::copy); - ClassDB::bind_method(D_METHOD("rename:Error", "from", "to"), &_Directory::rename); - ClassDB::bind_method(D_METHOD("remove:Error", "path"), &_Directory::remove); + ClassDB::bind_method(D_METHOD("copy", "from", "to"), &_Directory::copy); + ClassDB::bind_method(D_METHOD("rename", "from", "to"), &_Directory::rename); + ClassDB::bind_method(D_METHOD("remove", "path"), &_Directory::remove); } _Directory::_Directory() { @@ -2109,14 +2109,14 @@ String _Marshalls::base64_to_utf8(const String &p_str) { void _Marshalls::_bind_methods() { - ClassDB::bind_method(D_METHOD("variant_to_base64:String", "variant"), &_Marshalls::variant_to_base64); - ClassDB::bind_method(D_METHOD("base64_to_variant:Variant", "base64_str"), &_Marshalls::base64_to_variant); + ClassDB::bind_method(D_METHOD("variant_to_base64", "variant"), &_Marshalls::variant_to_base64); + ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str"), &_Marshalls::base64_to_variant); - ClassDB::bind_method(D_METHOD("raw_to_base64:String", "array"), &_Marshalls::raw_to_base64); - ClassDB::bind_method(D_METHOD("base64_to_raw:PoolByteArray", "base64_str"), &_Marshalls::base64_to_raw); + ClassDB::bind_method(D_METHOD("raw_to_base64", "array"), &_Marshalls::raw_to_base64); + ClassDB::bind_method(D_METHOD("base64_to_raw", "base64_str"), &_Marshalls::base64_to_raw); - ClassDB::bind_method(D_METHOD("utf8_to_base64:String", "utf8_str"), &_Marshalls::utf8_to_base64); - ClassDB::bind_method(D_METHOD("base64_to_utf8:String", "base64_str"), &_Marshalls::base64_to_utf8); + ClassDB::bind_method(D_METHOD("utf8_to_base64", "utf8_str"), &_Marshalls::utf8_to_base64); + ClassDB::bind_method(D_METHOD("base64_to_utf8", "base64_str"), &_Marshalls::base64_to_utf8); }; //////////////// @@ -2133,8 +2133,8 @@ Error _Semaphore::post() { void _Semaphore::_bind_methods() { - ClassDB::bind_method(D_METHOD("wait:Error"), &_Semaphore::wait); - ClassDB::bind_method(D_METHOD("post:Error"), &_Semaphore::post); + ClassDB::bind_method(D_METHOD("wait"), &_Semaphore::wait); + ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post); } _Semaphore::_Semaphore() { @@ -2167,7 +2167,7 @@ void _Mutex::unlock() { void _Mutex::_bind_methods() { ClassDB::bind_method(D_METHOD("lock"), &_Mutex::lock); - ClassDB::bind_method(D_METHOD("try_lock:Error"), &_Mutex::try_lock); + ClassDB::bind_method(D_METHOD("try_lock"), &_Mutex::try_lock); ClassDB::bind_method(D_METHOD("unlock"), &_Mutex::unlock); } @@ -2280,10 +2280,10 @@ Variant _Thread::wait_to_finish() { void _Thread::_bind_methods() { - ClassDB::bind_method(D_METHOD("start:Error", "instance", "method", "userdata", "priority"), &_Thread::start, DEFVAL(Variant()), DEFVAL(PRIORITY_NORMAL)); + ClassDB::bind_method(D_METHOD("start", "instance", "method", "userdata", "priority"), &_Thread::start, DEFVAL(Variant()), DEFVAL(PRIORITY_NORMAL)); ClassDB::bind_method(D_METHOD("get_id"), &_Thread::get_id); ClassDB::bind_method(D_METHOD("is_active"), &_Thread::is_active); - ClassDB::bind_method(D_METHOD("wait_to_finish:Variant"), &_Thread::wait_to_finish); + ClassDB::bind_method(D_METHOD("wait_to_finish"), &_Thread::wait_to_finish); BIND_CONSTANT(PRIORITY_LOW); BIND_CONSTANT(PRIORITY_NORMAL); @@ -2483,15 +2483,15 @@ void _ClassDB::_bind_methods() { ClassDB::bind_method(D_METHOD("class_exists", "class"), &_ClassDB::class_exists); ClassDB::bind_method(D_METHOD("is_parent_class", "class", "inherits"), &_ClassDB::is_parent_class); ClassDB::bind_method(D_METHOD("can_instance", "class"), &_ClassDB::can_instance); - ClassDB::bind_method(D_METHOD("instance:Variant", "class"), &_ClassDB::instance); + ClassDB::bind_method(D_METHOD("instance", "class"), &_ClassDB::instance); ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &_ClassDB::has_signal); ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &_ClassDB::get_signal); ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &_ClassDB::get_signal_list, DEFVAL(false)); ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &_ClassDB::get_property_list, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("class_get_property:Variant", "object", "property"), &_ClassDB::get_property); - ClassDB::bind_method(D_METHOD("class_set_property:Error", "object", "property", "value"), &_ClassDB::set_property); + ClassDB::bind_method(D_METHOD("class_get_property", "object", "property"), &_ClassDB::get_property); + ClassDB::bind_method(D_METHOD("class_set_property", "object", "property", "value"), &_ClassDB::set_property); ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &_ClassDB::has_method, DEFVAL(false)); @@ -2534,11 +2534,6 @@ float _Engine::get_frames_per_second() const { return Engine::get_singleton()->get_frames_per_second(); } -String _Engine::get_custom_level() const { - - return Engine::get_singleton()->get_custom_level(); -} - void _Engine::set_time_scale(float p_scale) { Engine::get_singleton()->set_time_scale(p_scale); } @@ -2568,6 +2563,16 @@ bool _Engine::is_in_fixed_frame() const { return Engine::get_singleton()->is_in_fixed_frame(); } +void _Engine::set_editor_hint(bool p_enabled) { + + Engine::get_singleton()->set_editor_hint(p_enabled); +} + +bool _Engine::is_editor_hint() const { + + return Engine::get_singleton()->is_editor_hint(); +} + void _Engine::_bind_methods() { ClassDB::bind_method(D_METHOD("set_iterations_per_second", "iterations_per_second"), &_Engine::set_iterations_per_second); @@ -2578,16 +2583,17 @@ void _Engine::_bind_methods() { ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &_Engine::set_time_scale); ClassDB::bind_method(D_METHOD("get_time_scale"), &_Engine::get_time_scale); - ClassDB::bind_method(D_METHOD("get_custom_level"), &_Engine::get_custom_level); - ClassDB::bind_method(D_METHOD("get_frames_drawn"), &_Engine::get_frames_drawn); ClassDB::bind_method(D_METHOD("get_frames_per_second"), &_Engine::get_frames_per_second); - ClassDB::bind_method(D_METHOD("get_main_loop:MainLoop"), &_Engine::get_main_loop); + ClassDB::bind_method(D_METHOD("get_main_loop"), &_Engine::get_main_loop); ClassDB::bind_method(D_METHOD("get_version_info"), &_Engine::get_version_info); ClassDB::bind_method(D_METHOD("is_in_fixed_frame"), &_Engine::is_in_fixed_frame); + + ClassDB::bind_method(D_METHOD("set_editor_hint", "enabled"), &_Engine::set_editor_hint); + ClassDB::bind_method(D_METHOD("is_editor_hint"), &_Engine::is_editor_hint); } _Engine *_Engine::singleton = NULL; diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index e18d663d85..d3314cc3b3 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -458,7 +458,7 @@ protected: public: Error open(const String &p_path); - Error list_dir_begin(bool p_skip_internal = false, bool p_skip_hidden = false); ///< This starts dir listing + Error list_dir_begin(bool p_skip_navigational = false, bool p_skip_hidden = false); ///< This starts dir listing String get_next(); bool current_is_dir() const; @@ -639,14 +639,15 @@ public: void set_time_scale(float p_scale); float get_time_scale(); - String get_custom_level() const; - MainLoop *get_main_loop() const; Dictionary get_version_info() const; bool is_in_fixed_frame() const; + void set_editor_hint(bool p_enabled); + bool is_editor_hint() const; + _Engine(); }; diff --git a/core/class_db.cpp b/core/class_db.cpp index 24d71f86b0..0503f7c6fc 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -46,9 +46,9 @@ #ifdef DEBUG_METHODS_ENABLED -ParamDef::ParamDef(const Variant &p_variant) { - used = true; - val = p_variant; +ParamDef::ParamDef(const Variant &p_variant) + : used(true), + val(p_variant) { } MethodDefinition D_METHOD(const char *p_name) { @@ -1082,12 +1082,6 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c StringName mdname = StaticCString::create(method_name); #endif - StringName rettype; - if (mdname.operator String().find(":") != -1) { - rettype = mdname.operator String().get_slice(":", 1); - mdname = mdname.operator String().get_slice(":", 0); - } - OBJTYPE_WLOCK; ERR_FAIL_COND_V(!p_bind, NULL); p_bind->set_name(mdname); @@ -1106,7 +1100,7 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c if (!type) { ERR_PRINTS("Couldn't bind method '" + mdname + "' for instance: " + instance_type); memdelete(p_bind); - ERR_FAIL_COND_V(!type, NULL); + ERR_FAIL_V(NULL); } if (type->method_map.has(mdname)) { @@ -1115,11 +1109,20 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c ERR_EXPLAIN("Method already bound: " + instance_type + "::" + mdname); ERR_FAIL_V(NULL); } + #ifdef DEBUG_METHODS_ENABLED + + if (method_name.args.size() > p_bind->get_argument_count()) { + memdelete(p_bind); + ERR_EXPLAIN("Method definition provides more arguments than the method actually has: " + instance_type + "::" + mdname); + ERR_FAIL_V(NULL); + } + p_bind->set_argument_names(method_name.args); - p_bind->set_return_type(rettype); + type->method_order.push_back(mdname); #endif + type->method_map[mdname] = p_bind; Vector<Variant> defvals; diff --git a/core/class_db.h b/core/class_db.h index 02eac0dbbc..4287c5990f 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -45,12 +45,11 @@ struct ParamHint { String hint_text; Variant default_val; - ParamHint(const String &p_name = "", PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_text = "", Variant p_default_val = Variant()) { - - name = p_name; - hint = p_hint; - hint_text = p_hint_text; - default_val = p_default_val; + ParamHint(const String &p_name = "", PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_text = "", const Variant &p_default_val = Variant()) + : name(p_name), + hint(p_hint), + hint_text(p_hint_text), + default_val(p_default_val) { } }; @@ -73,8 +72,10 @@ struct MethodDefinition { StringName name; Vector<StringName> args; MethodDefinition() {} - MethodDefinition(const char *p_name) { name = p_name; } - MethodDefinition(const StringName &p_name) { name = p_name; } + MethodDefinition(const char *p_name) + : name(p_name) {} + MethodDefinition(const StringName &p_name) + : name(p_name) {} }; MethodDefinition D_METHOD(const char *p_name); @@ -436,12 +437,6 @@ public: MethodBind *bind = create_vararg_method_bind(p_method, p_info); ERR_FAIL_COND_V(!bind, NULL); - String rettype; - if (p_name.operator String().find(":") != -1) { - rettype = p_name.operator String().get_slice(":", 1); - p_name = p_name.operator String().get_slice(":", 0); - } - bind->set_name(p_name); bind->set_default_arguments(p_default_args); @@ -461,8 +456,7 @@ public: } type->method_map[p_name] = bind; #ifdef DEBUG_METHODS_ENABLED - if (!rettype.empty()) - bind->set_return_type(rettype); + bind->set_return_type("Variant"); type->method_order.push_back(p_name); #endif diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index 823494ff67..c9edd1d47b 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -55,6 +55,7 @@ CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() { while (true) { + lock(); for (int i = 0; i < SYNC_SEMAPHORES; i++) { if (!sync_sems[i].in_use) { @@ -63,6 +64,7 @@ CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() { break; } } + unlock(); if (idx == -1) { wait_for_flush(); diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index 2e0c478108..c3e44f731f 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -911,12 +911,14 @@ public: template <class T, class M, class R> void push_and_ret(T *p_instance, M p_method, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet0<T, M, R> *cmd = allocate_and_lock<CommandRet0<T, M, R> >(); cmd->instance = p_instance; cmd->method = p_method; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -928,13 +930,15 @@ public: template <class T, class M, class P1, class R> void push_and_ret(T *p_instance, M p_method, P1 p1, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet1<T, M, P1, R> *cmd = allocate_and_lock<CommandRet1<T, M, P1, R> >(); cmd->instance = p_instance; cmd->method = p_method; cmd->p1 = p1; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -946,6 +950,8 @@ public: template <class T, class M, class P1, class P2, class R> void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet2<T, M, P1, P2, R> *cmd = allocate_and_lock<CommandRet2<T, M, P1, P2, R> >(); cmd->instance = p_instance; @@ -953,7 +959,7 @@ public: cmd->p1 = p1; cmd->p2 = p2; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -965,6 +971,8 @@ public: template <class T, class M, class P1, class P2, class P3, class R> void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet3<T, M, P1, P2, P3, R> *cmd = allocate_and_lock<CommandRet3<T, M, P1, P2, P3, R> >(); cmd->instance = p_instance; @@ -973,7 +981,7 @@ public: cmd->p2 = p2; cmd->p3 = p3; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -985,6 +993,8 @@ public: template <class T, class M, class P1, class P2, class P3, class P4, class R> void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet4<T, M, P1, P2, P3, P4, R> *cmd = allocate_and_lock<CommandRet4<T, M, P1, P2, P3, P4, R> >(); cmd->instance = p_instance; @@ -994,7 +1004,7 @@ public: cmd->p3 = p3; cmd->p4 = p4; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -1006,6 +1016,8 @@ public: template <class T, class M, class P1, class P2, class P3, class P4, class P5, class R> void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet5<T, M, P1, P2, P3, P4, P5, R> *cmd = allocate_and_lock<CommandRet5<T, M, P1, P2, P3, P4, P5, R> >(); cmd->instance = p_instance; @@ -1016,7 +1028,7 @@ public: cmd->p4 = p4; cmd->p5 = p5; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -1028,6 +1040,8 @@ public: template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class R> void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet6<T, M, P1, P2, P3, P4, P5, P6, R> *cmd = allocate_and_lock<CommandRet6<T, M, P1, P2, P3, P4, P5, P6, R> >(); cmd->instance = p_instance; @@ -1039,7 +1053,7 @@ public: cmd->p5 = p5; cmd->p6 = p6; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -1051,6 +1065,8 @@ public: template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class R> void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet7<T, M, P1, P2, P3, P4, P5, P6, P7, R> *cmd = allocate_and_lock<CommandRet7<T, M, P1, P2, P3, P4, P5, P6, P7, R> >(); cmd->instance = p_instance; @@ -1063,7 +1079,7 @@ public: cmd->p6 = p6; cmd->p7 = p7; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -1075,6 +1091,8 @@ public: template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class R> void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, R *r_ret) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandRet8<T, M, P1, P2, P3, P4, P5, P6, P7, P8, R> *cmd = allocate_and_lock<CommandRet8<T, M, P1, P2, P3, P4, P5, P6, P7, P8, R> >(); cmd->instance = p_instance; @@ -1088,7 +1106,7 @@ public: cmd->p7 = p7; cmd->p8 = p8; cmd->ret = r_ret; - SyncSemaphore *ss = _alloc_sync_sem(); + cmd->sync = ss; unlock(); @@ -1100,12 +1118,13 @@ public: template <class T, class M> void push_and_sync(T *p_instance, M p_method) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync0<T, M> *cmd = allocate_and_lock<CommandSync0<T, M> >(); cmd->instance = p_instance; cmd->method = p_method; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1117,13 +1136,14 @@ public: template <class T, class M, class P1> void push_and_sync(T *p_instance, M p_method, P1 p1) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync1<T, M, P1> *cmd = allocate_and_lock<CommandSync1<T, M, P1> >(); cmd->instance = p_instance; cmd->method = p_method; cmd->p1 = p1; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1135,6 +1155,8 @@ public: template <class T, class M, class P1, class P2> void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync2<T, M, P1, P2> *cmd = allocate_and_lock<CommandSync2<T, M, P1, P2> >(); cmd->instance = p_instance; @@ -1142,7 +1164,6 @@ public: cmd->p1 = p1; cmd->p2 = p2; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1154,6 +1175,8 @@ public: template <class T, class M, class P1, class P2, class P3> void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync3<T, M, P1, P2, P3> *cmd = allocate_and_lock<CommandSync3<T, M, P1, P2, P3> >(); cmd->instance = p_instance; @@ -1162,7 +1185,6 @@ public: cmd->p2 = p2; cmd->p3 = p3; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1174,6 +1196,8 @@ public: template <class T, class M, class P1, class P2, class P3, class P4> void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync4<T, M, P1, P2, P3, P4> *cmd = allocate_and_lock<CommandSync4<T, M, P1, P2, P3, P4> >(); cmd->instance = p_instance; @@ -1183,7 +1207,6 @@ public: cmd->p3 = p3; cmd->p4 = p4; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1195,6 +1218,8 @@ public: template <class T, class M, class P1, class P2, class P3, class P4, class P5> void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync5<T, M, P1, P2, P3, P4, P5> *cmd = allocate_and_lock<CommandSync5<T, M, P1, P2, P3, P4, P5> >(); cmd->instance = p_instance; @@ -1205,7 +1230,6 @@ public: cmd->p4 = p4; cmd->p5 = p5; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1217,6 +1241,8 @@ public: template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6> void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync6<T, M, P1, P2, P3, P4, P5, P6> *cmd = allocate_and_lock<CommandSync6<T, M, P1, P2, P3, P4, P5, P6> >(); cmd->instance = p_instance; @@ -1228,7 +1254,6 @@ public: cmd->p5 = p5; cmd->p6 = p6; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1240,6 +1265,8 @@ public: template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7> void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync7<T, M, P1, P2, P3, P4, P5, P6, P7> *cmd = allocate_and_lock<CommandSync7<T, M, P1, P2, P3, P4, P5, P6, P7> >(); cmd->instance = p_instance; @@ -1252,7 +1279,6 @@ public: cmd->p6 = p6; cmd->p7 = p7; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); @@ -1264,6 +1290,8 @@ public: template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8> void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) { + SyncSemaphore *ss = _alloc_sync_sem(); + CommandSync8<T, M, P1, P2, P3, P4, P5, P6, P7, P8> *cmd = allocate_and_lock<CommandSync8<T, M, P1, P2, P3, P4, P5, P6, P7, P8> >(); cmd->instance = p_instance; @@ -1277,7 +1305,6 @@ public: cmd->p7 = p7; cmd->p8 = p8; - SyncSemaphore *ss = _alloc_sync_sem(); cmd->sync = ss; unlock(); diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp index 9bdd960424..172249c5d7 100644 --- a/core/compressed_translation.cpp +++ b/core/compressed_translation.cpp @@ -306,7 +306,7 @@ void PHashTranslation::_get_property_list(List<PropertyInfo> *p_list) const { } void PHashTranslation::_bind_methods() { - ClassDB::bind_method(D_METHOD("generate", "from:Translation"), &PHashTranslation::generate); + ClassDB::bind_method(D_METHOD("generate", "from"), &PHashTranslation::generate); } PHashTranslation::PHashTranslation() { diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp index 2adc15447a..2f5a684373 100644 --- a/core/core_string_names.cpp +++ b/core/core_string_names.cpp @@ -31,21 +31,20 @@ CoreStringNames *CoreStringNames::singleton = NULL; -CoreStringNames::CoreStringNames() { - - _free = StaticCString::create("free"); - changed = StaticCString::create("changed"); - _meta = StaticCString::create("__meta__"); - _script = StaticCString::create("script"); - script_changed = StaticCString::create("script_changed"); - ___pdcdata = StaticCString::create("___pdcdata"); - __getvar = StaticCString::create("__getvar"); - _iter_init = StaticCString::create("_iter_init"); - _iter_next = StaticCString::create("_iter_next"); - _iter_get = StaticCString::create("_iter_get"); - get_rid = StaticCString::create("get_rid"); - _custom_features = StaticCString::create("_custom_features"); +CoreStringNames::CoreStringNames() + : _free(StaticCString::create("free")), + changed(StaticCString::create("changed")), + _meta(StaticCString::create("__meta__")), + _script(StaticCString::create("script")), + script_changed(StaticCString::create("script_changed")), + ___pdcdata(StaticCString::create("___pdcdata")), + __getvar(StaticCString::create("__getvar")), + _iter_init(StaticCString::create("_iter_init")), + _iter_next(StaticCString::create("_iter_next")), + _iter_get(StaticCString::create("_iter_get")), + get_rid(StaticCString::create("get_rid")), #ifdef TOOLS_ENABLED - _sections_unfolded = StaticCString::create("_sections_unfolded"); + _sections_unfolded(StaticCString::create("_sections_unfolded")), #endif + _custom_features(StaticCString::create("_custom_features")) { } diff --git a/core/core_string_names.h b/core/core_string_names.h index 501185f5b7..40f76aa9c0 100644 --- a/core/core_string_names.h +++ b/core/core_string_names.h @@ -61,10 +61,10 @@ public: StringName _iter_next; StringName _iter_get; StringName get_rid; - StringName _custom_features; #ifdef TOOLS_ENABLED StringName _sections_unfolded; #endif + StringName _custom_features; }; #endif // SCENE_STRING_NAMES_H diff --git a/core/engine.cpp b/core/engine.cpp index c16a2903d3..c8218e47ac 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -121,4 +121,5 @@ Engine::Engine() { _in_fixed = false; _frame_ticks = 0; _frame_step = 0; + editor_hint = false; } diff --git a/core/engine.h b/core/engine.h index 16dfb77593..c46ae1cb64 100644 --- a/core/engine.h +++ b/core/engine.h @@ -39,7 +39,6 @@ class Engine { friend class Main; - String _custom_level; uint64_t frames_drawn; uint32_t _frame_delay; uint64_t _frame_ticks; @@ -51,9 +50,12 @@ class Engine { float _time_scale; bool _pixel_snap; uint64_t _fixed_frames; + uint64_t _idle_frames; bool _in_fixed; + bool editor_hint; + static Engine *singleton; public: @@ -67,8 +69,6 @@ public: virtual float get_frames_per_second() const { return _fps; } - String get_custom_level() const { return _custom_level; } - uint64_t get_frames_drawn(); uint64_t get_fixed_frames() const { return _fixed_frames; } @@ -85,6 +85,14 @@ public: _FORCE_INLINE_ bool get_use_pixel_snap() const { return _pixel_snap; } +#ifdef TOOLS_ENABLED + _FORCE_INLINE_ void set_editor_hint(bool p_enabled) { editor_hint = p_enabled; } + _FORCE_INLINE_ bool is_editor_hint() const { return editor_hint; } +#else + _FORCE_INLINE_ void set_editor_hint(bool p_enabled) {} + _FORCE_INLINE_ bool is_editor_hint() const { return false; } +#endif + Dictionary get_version_info() const; Engine(); diff --git a/core/func_ref.cpp b/core/func_ref.cpp index 2d74efd822..5622a03665 100644 --- a/core/func_ref.cpp +++ b/core/func_ref.cpp @@ -61,7 +61,7 @@ void FuncRef::_bind_methods() { MethodInfo mi; mi.name = "call_func"; Vector<Variant> defargs; - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_func:Variant", &FuncRef::call_func, mi, defargs); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_func", &FuncRef::call_func, mi, defargs); } ClassDB::bind_method(D_METHOD("set_instance", "instance"), &FuncRef::set_instance); diff --git a/core/hash_map.h b/core/hash_map.h index 45e7b82d24..2d7249e2fc 100644 --- a/core/hash_map.h +++ b/core/hash_map.h @@ -96,9 +96,9 @@ public: TData data; Pair() {} - Pair(const TKey &p_key, const TData &p_data) { - key = p_key; - data = p_data; + Pair(const TKey &p_key, const TData &p_data) + : key(p_key), + data(p_data) { } }; diff --git a/core/image.cpp b/core/image.cpp index 50dc9c109d..a4864458b5 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -676,8 +676,8 @@ void Image::resize_to_po2(bool p_square) { ERR_FAIL(); } - int w = nearest_power_of_2(width); - int h = nearest_power_of_2(height); + int w = next_power_of_2(width); + int h = next_power_of_2(height); if (w == width && h == height) { @@ -1060,7 +1060,7 @@ Error Image::generate_mipmaps() { PoolVector<uint8_t>::Write wp = data.write(); - if (nearest_power_of_2(width) == uint32_t(width) && nearest_power_of_2(height) == uint32_t(height)) { + if (next_power_of_2(width) == uint32_t(width) && next_power_of_2(height) == uint32_t(height)) { //use fast code for powers of 2 int prev_ofs = 0; int prev_h = height; @@ -2254,16 +2254,16 @@ void Image::_bind_methods() { ClassDB::bind_method(D_METHOD("srgb_to_linear"), &Image::srgb_to_linear); ClassDB::bind_method(D_METHOD("normalmap_to_xy"), &Image::normalmap_to_xy); - ClassDB::bind_method(D_METHOD("blit_rect", "src:Image", "src_rect", "dst"), &Image::blit_rect); - ClassDB::bind_method(D_METHOD("blit_rect_mask", "src:Image", "mask:Image", "src_rect", "dst"), &Image::blit_rect_mask); - ClassDB::bind_method(D_METHOD("blend_rect", "src:Image", "src_rect", "dst"), &Image::blend_rect); - ClassDB::bind_method(D_METHOD("blend_rect_mask", "src:Image", "mask:Image", "src_rect", "dst"), &Image::blend_rect_mask); + ClassDB::bind_method(D_METHOD("blit_rect", "src", "src_rect", "dst"), &Image::blit_rect); + ClassDB::bind_method(D_METHOD("blit_rect_mask", "src", "mask", "src_rect", "dst"), &Image::blit_rect_mask); + ClassDB::bind_method(D_METHOD("blend_rect", "src", "src_rect", "dst"), &Image::blend_rect); + ClassDB::bind_method(D_METHOD("blend_rect_mask", "src", "mask", "src_rect", "dst"), &Image::blend_rect_mask); ClassDB::bind_method(D_METHOD("fill", "color"), &Image::fill); ClassDB::bind_method(D_METHOD("get_used_rect"), &Image::get_used_rect); - ClassDB::bind_method(D_METHOD("get_rect:Image", "rect"), &Image::get_rect); + ClassDB::bind_method(D_METHOD("get_rect", "rect"), &Image::get_rect); - ClassDB::bind_method(D_METHOD("copy_from", "src:Image"), &Image::copy_internals_from); + ClassDB::bind_method(D_METHOD("copy_from", "src"), &Image::copy_internals_from); ClassDB::bind_method(D_METHOD("_set_data", "data"), &Image::_set_data); ClassDB::bind_method(D_METHOD("_get_data"), &Image::_get_data); diff --git a/core/input_map.cpp b/core/input_map.cpp index 85e627f352..8435882325 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -41,11 +41,11 @@ void InputMap::_bind_methods() { ClassDB::bind_method(D_METHOD("add_action", "action"), &InputMap::add_action); ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action); - ClassDB::bind_method(D_METHOD("action_add_event", "action", "event:InputEvent"), &InputMap::action_add_event); - ClassDB::bind_method(D_METHOD("action_has_event", "action", "event:InputEvent"), &InputMap::action_has_event); - ClassDB::bind_method(D_METHOD("action_erase_event", "action", "event:InputEvent"), &InputMap::action_erase_event); + ClassDB::bind_method(D_METHOD("action_add_event", "action", "event"), &InputMap::action_add_event); + ClassDB::bind_method(D_METHOD("action_has_event", "action", "event"), &InputMap::action_has_event); + ClassDB::bind_method(D_METHOD("action_erase_event", "action", "event"), &InputMap::action_erase_event); ClassDB::bind_method(D_METHOD("get_action_list", "action"), &InputMap::_get_action_list); - ClassDB::bind_method(D_METHOD("event_is_action", "event:InputEvent", "action"), &InputMap::event_is_action); + ClassDB::bind_method(D_METHOD("event_is_action", "event", "action"), &InputMap::event_is_action); ClassDB::bind_method(D_METHOD("load_from_globals"), &InputMap::load_from_globals); } diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 4067899068..edd090adf2 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -205,7 +205,7 @@ Error ConfigFile::load(const String &p_path) { void ConfigFile::_bind_methods() { ClassDB::bind_method(D_METHOD("set_value", "section", "key", "value"), &ConfigFile::set_value); - ClassDB::bind_method(D_METHOD("get_value:Variant", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("get_value", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("has_section", "section"), &ConfigFile::has_section); ClassDB::bind_method(D_METHOD("has_section_key", "section", "key"), &ConfigFile::has_section_key); @@ -215,8 +215,8 @@ void ConfigFile::_bind_methods() { ClassDB::bind_method(D_METHOD("erase_section", "section"), &ConfigFile::erase_section); - ClassDB::bind_method(D_METHOD("load:Error", "path"), &ConfigFile::load); - ClassDB::bind_method(D_METHOD("save:Error", "path"), &ConfigFile::save); + ClassDB::bind_method(D_METHOD("load", "path"), &ConfigFile::load); + ClassDB::bind_method(D_METHOD("save", "path"), &ConfigFile::save); } ConfigFile::ConfigFile() { diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp index 81adbbbaf7..126ec7575e 100644 --- a/core/io/file_access_buffered.cpp +++ b/core/io/file_access_buffered.cpp @@ -106,11 +106,11 @@ uint8_t FileAccessBuffered::get_8() const { return byte; }; -int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_elements) const { +int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const { ERR_FAIL_COND_V(!file.open, -1); - if (p_elements > cache_size) { + if (p_length > cache_size) { int total_read = 0; @@ -122,12 +122,12 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_elements) const { //memcpy(p_dest, read.ptr() + (file.offset - cache.offset), size); memcpy(p_dest, cache.buffer.ptr() + (file.offset - cache.offset), size); p_dest += size; - p_elements -= size; + p_length -= size; file.offset += size; total_read += size; }; - int err = read_data_block(file.offset, p_elements, p_dest); + int err = read_data_block(file.offset, p_length, p_dest); if (err >= 0) { total_read += err; file.offset += err; @@ -136,7 +136,7 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_elements) const { return total_read; }; - int to_read = p_elements; + int to_read = p_length; int total_read = 0; while (to_read > 0) { @@ -161,7 +161,7 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_elements) const { to_read -= r; }; - return p_elements; + return p_length; }; bool FileAccessBuffered::is_open() const { diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h index c5bf120890..0ad2d0e929 100644 --- a/core/io/file_access_buffered.h +++ b/core/io/file_access_buffered.h @@ -81,7 +81,7 @@ public: virtual bool eof_reached() const; virtual uint8_t get_8() const; - virtual int get_buffer(uint8_t *p_dst, int p_length) const; ///< get an array of bytes + virtual int get_buffer(uint8_t *p_dest, int p_length) const; ///< get an array of bytes virtual bool is_open() const; diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index 4e802579c6..34bce3f04f 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -43,16 +43,16 @@ void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_ block_size = p_block_size; } -#define WRITE_FIT(m_bytes) \ - { \ - if (write_pos + (m_bytes) > write_max) { \ - write_max = write_pos + (m_bytes); \ - } \ - if (write_max > write_buffer_size) { \ - write_buffer_size = nearest_power_of_2(write_max); \ - buffer.resize(write_buffer_size); \ - write_ptr = buffer.ptr(); \ - } \ +#define WRITE_FIT(m_bytes) \ + { \ + if (write_pos + (m_bytes) > write_max) { \ + write_max = write_pos + (m_bytes); \ + } \ + if (write_max > write_buffer_size) { \ + write_buffer_size = next_power_of_2(write_max); \ + buffer.resize(write_buffer_size); \ + write_ptr = buffer.ptr(); \ + } \ } Error FileAccessCompressed::open_after_magic(FileAccess *p_base) { diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h index 8b6abe7e81..ea858c547e 100644 --- a/core/io/file_access_memory.h +++ b/core/io/file_access_memory.h @@ -62,7 +62,7 @@ public: virtual Error get_error() const; ///< get last error - virtual void store_8(uint8_t p_dest); ///< store a byte + virtual void store_8(uint8_t p_byte); ///< store a byte virtual void store_buffer(const uint8_t *p_src, int p_length); ///< store an array of bytes virtual bool file_exists(const String &p_name); ///< return true if a file exists diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index 79aa39521f..c3bcfc840b 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -308,10 +308,9 @@ bool FileAccessPack::file_exists(const String &p_name) { return false; } -FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file) { - - pf = p_file; - f = FileAccess::open(pf.pack, FileAccess::READ); +FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file) + : pf(p_file), + f(FileAccess::open(pf.pack, FileAccess::READ)) { if (!f) { ERR_EXPLAIN("Can't open pack-referenced file: " + String(pf.pack)); ERR_FAIL_COND(!f); diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index a92014000d..d748d5c773 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -159,15 +159,15 @@ unzFile ZipArchive::get_file_handle(String p_file) const { return pkg; }; -bool ZipArchive::try_open_pack(const String &p_name) { +bool ZipArchive::try_open_pack(const String &p_path) { //printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz")); - if (p_name.get_extension().nocasecmp_to("zip") != 0 && p_name.get_extension().nocasecmp_to("pcz") != 0) + if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0) return false; zlib_filefunc_def io; - FileAccess *f = FileAccess::open(p_name, FileAccess::READ); + FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) return false; io.opaque = f; @@ -180,7 +180,7 @@ bool ZipArchive::try_open_pack(const String &p_name) { io.zclose_file = godot_close; io.zerror_file = godot_testerror; - unzFile zfile = unzOpen2(p_name.utf8().get_data(), &io); + unzFile zfile = unzOpen2(p_path.utf8().get_data(), &io); ERR_FAIL_COND_V(!zfile, false); unz_global_info64 gi; @@ -188,7 +188,7 @@ bool ZipArchive::try_open_pack(const String &p_name) { ERR_FAIL_COND_V(err != UNZ_OK, false); Package pkg; - pkg.filename = p_name; + pkg.filename = p_path; pkg.zfile = zfile; packages.push_back(pkg); int pkg_num = packages.size() - 1; @@ -209,7 +209,7 @@ bool ZipArchive::try_open_pack(const String &p_name) { files[fname] = f; uint8_t md5[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - PackedData::get_singleton()->add_path(p_name, fname, 1, 0, md5, this); + PackedData::get_singleton()->add_path(p_path, fname, 1, 0, md5, this); //printf("packed data add path %ls, %ls\n", p_name.c_str(), fname.c_str()); if ((i + 1) < gi.number_entry) { diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 0c84a5213f..4d5b88cfa1 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -624,9 +624,9 @@ Error HTTPClient::_get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received void HTTPClient::_bind_methods() { - ClassDB::bind_method(D_METHOD("connect_to_host:Error", "host", "port", "use_ssl", "verify_host"), &HTTPClient::connect_to_host, DEFVAL(false), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("set_connection", "connection:StreamPeer"), &HTTPClient::set_connection); - ClassDB::bind_method(D_METHOD("get_connection:StreamPeer"), &HTTPClient::get_connection); + ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port", "use_ssl", "verify_host"), &HTTPClient::connect_to_host, DEFVAL(false), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("set_connection", "connection"), &HTTPClient::set_connection); + ClassDB::bind_method(D_METHOD("get_connection"), &HTTPClient::get_connection); ClassDB::bind_method(D_METHOD("request_raw", "method", "url", "headers", "body"), &HTTPClient::request_raw); ClassDB::bind_method(D_METHOD("request", "method", "url", "headers", "body"), &HTTPClient::request, DEFVAL(String())); ClassDB::bind_method(D_METHOD("send_body_text", "body"), &HTTPClient::send_body_text); @@ -646,9 +646,9 @@ void HTTPClient::_bind_methods() { ClassDB::bind_method(D_METHOD("is_blocking_mode_enabled"), &HTTPClient::is_blocking_mode_enabled); ClassDB::bind_method(D_METHOD("get_status"), &HTTPClient::get_status); - ClassDB::bind_method(D_METHOD("poll:Error"), &HTTPClient::poll); + ClassDB::bind_method(D_METHOD("poll"), &HTTPClient::poll); - ClassDB::bind_method(D_METHOD("query_string_from_dict:String", "fields"), &HTTPClient::query_string_from_dict); + ClassDB::bind_method(D_METHOD("query_string_from_dict", "fields"), &HTTPClient::query_string_from_dict); BIND_CONSTANT(METHOD_GET); BIND_CONSTANT(METHOD_HEAD); diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 23719940be..7b5b4a13ea 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -43,7 +43,7 @@ bool ImageFormatLoader::recognize(const String &p_extension) const { return false; } -Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom, bool p_force_linear) { +Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom, bool p_force_linear, float p_scale) { ERR_FAIL_COND_V(p_image.is_null(), ERR_INVALID_PARAMETER); FileAccess *f = p_custom; @@ -62,7 +62,7 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c if (!loader[i]->recognize(extension)) continue; - Error err = loader[i]->load_image(p_image, f, p_force_linear); + Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale); if (err != ERR_FILE_UNRECOGNIZED) { diff --git a/core/io/image_loader.h b/core/io/image_loader.h index e528d1423b..f79d9789bf 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -56,7 +56,7 @@ class ImageFormatLoader { friend class ImageLoader; protected: - virtual Error load_image(Ref<Image> p_image, FileAccess *p_fileaccess, bool p_force_linear) = 0; + virtual Error load_image(Ref<Image> p_image, FileAccess *p_fileaccess, bool p_force_linear, float p_scale) = 0; virtual void get_recognized_extensions(List<String> *p_extensions) const = 0; bool recognize(const String &p_extension) const; @@ -75,7 +75,7 @@ class ImageLoader { protected: public: - static Error load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom = NULL, bool p_force_linear = false); + static Error load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom = NULL, bool p_force_linear = false, float p_scale = 1.0); static void get_recognized_extensions(List<String> *p_extensions); static bool recognize(const String &p_extension); diff --git a/core/io/ip_address.h b/core/io/ip_address.h index ac58283605..da16622a9b 100644 --- a/core/io/ip_address.h +++ b/core/io/ip_address.h @@ -75,7 +75,7 @@ public: void set_ipv4(const uint8_t *p_ip); const uint8_t *get_ipv6() const; - void set_ipv6(const uint8_t *buf); + void set_ipv6(const uint8_t *p_buf); operator String() const; IP_Address(const String &p_string); diff --git a/core/io/json.cpp b/core/io/json.cpp index 10fd60abf7..d537061c5b 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -94,15 +94,15 @@ String JSON::print(const Variant &p_var) { return _print_var(p_var); } -Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_token, int &line, String &r_err_str) { +Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) { while (p_len > 0) { - switch (p_str[idx]) { + switch (p_str[index]) { case '\n': { line++; - idx++; + index++; break; }; case 0: { @@ -112,54 +112,54 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_toke case '{': { r_token.type = TK_CURLY_BRACKET_OPEN; - idx++; + index++; return OK; }; case '}': { r_token.type = TK_CURLY_BRACKET_CLOSE; - idx++; + index++; return OK; }; case '[': { r_token.type = TK_BRACKET_OPEN; - idx++; + index++; return OK; }; case ']': { r_token.type = TK_BRACKET_CLOSE; - idx++; + index++; return OK; }; case ':': { r_token.type = TK_COLON; - idx++; + index++; return OK; }; case ',': { r_token.type = TK_COMMA; - idx++; + index++; return OK; }; case '"': { - idx++; + index++; String str; while (true) { - if (p_str[idx] == 0) { + if (p_str[index] == 0) { r_err_str = "Unterminated String"; return ERR_PARSE_ERROR; - } else if (p_str[idx] == '"') { - idx++; + } else if (p_str[index] == '"') { + index++; break; - } else if (p_str[idx] == '\\') { + } else if (p_str[index] == '\\') { //escaped characters... - idx++; - CharType next = p_str[idx]; + index++; + CharType next = p_str[index]; if (next == 0) { r_err_str = "Unterminated String"; return ERR_PARSE_ERROR; @@ -177,7 +177,7 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_toke //hexnumbarh - oct is deprecated for (int j = 0; j < 4; j++) { - CharType c = p_str[idx + j + 1]; + CharType c = p_str[index + j + 1]; if (c == 0) { r_err_str = "Unterminated String"; return ERR_PARSE_ERROR; @@ -204,7 +204,7 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_toke res <<= 4; res |= v; } - idx += 4; //will add at the end anyway + index += 4; //will add at the end anyway } break; //case '\"': res='\"'; break; @@ -220,11 +220,11 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_toke str += res; } else { - if (p_str[idx] == '\n') + if (p_str[index] == '\n') line++; - str += p_str[idx]; + str += p_str[index]; } - idx++; + index++; } r_token.type = TK_STRING; @@ -234,28 +234,28 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_toke } break; default: { - if (p_str[idx] <= 32) { - idx++; + if (p_str[index] <= 32) { + index++; break; } - if (p_str[idx] == '-' || (p_str[idx] >= '0' && p_str[idx] <= '9')) { + if (p_str[index] == '-' || (p_str[index] >= '0' && p_str[index] <= '9')) { //a number const CharType *rptr; - double number = String::to_double(&p_str[idx], &rptr); - idx += (rptr - &p_str[idx]); + double number = String::to_double(&p_str[index], &rptr); + index += (rptr - &p_str[index]); r_token.type = TK_NUMBER; r_token.value = number; return OK; - } else if ((p_str[idx] >= 'A' && p_str[idx] <= 'Z') || (p_str[idx] >= 'a' && p_str[idx] <= 'z')) { + } else if ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) { String id; - while ((p_str[idx] >= 'A' && p_str[idx] <= 'Z') || (p_str[idx] >= 'a' && p_str[idx] <= 'z')) { + while ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) { - id += p_str[idx]; - idx++; + id += p_str[index]; + index++; } r_token.type = TK_IDENTIFIER; diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 75dfd563dd..e701a89c78 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -30,12 +30,60 @@ #include "marshalls.h" #include "os/keyboard.h" #include "print_string.h" +#include "reference.h" #include <stdio.h> +void EncodedObjectAsID::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_object_id", "id"), &EncodedObjectAsID::set_object_id); + ClassDB::bind_method(D_METHOD("get_object_id"), &EncodedObjectAsID::get_object_id); +} + +void EncodedObjectAsID::set_object_id(ObjectID p_id) { + id = p_id; +} + +ObjectID EncodedObjectAsID::get_object_id() const { + + return id; +} + +EncodedObjectAsID::EncodedObjectAsID() { + + id = 0; +} + #define ENCODE_MASK 0xFF #define ENCODE_FLAG_64 1 << 16 +#define ENCODE_FLAG_OBJECT_AS_ID 1 << 16 + +static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r_string) { + ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); + + uint32_t strlen = decode_uint32(buf); + buf += 4; + len -= 4; + ERR_FAIL_COND_V((int)strlen > len, ERR_FILE_EOF); -Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len) { + String str; + str.parse_utf8((const char *)buf, strlen); + r_string = str; + + //handle padding + if (strlen % 4) { + strlen += 4 - strlen % 4; + } + + buf += strlen; + len -= strlen; + + if (r_len) { + (*r_len) += 4 + strlen; + } + + return OK; +} + +Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects) { const uint8_t *buf = p_buffer; int len = p_len; @@ -104,22 +152,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::STRING: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); - uint32_t strlen = decode_uint32(buf); - buf += 4; - len -= 4; - ERR_FAIL_COND_V((int)strlen > len, ERR_INVALID_DATA); - String str; - str.parse_utf8((const char *)buf, strlen); + Error err = _decode_string(buf, len, r_len, str); + if (err) + return err; r_variant = str; - if (r_len) { - if (strlen % 4) - (*r_len) += 4 - strlen % 4; - (*r_len) += 4 + strlen; - } - } break; // math types @@ -363,7 +401,77 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::OBJECT: { - r_variant = (Object *)NULL; + if (type & ENCODE_FLAG_OBJECT_AS_ID) { + //this _is_ allowed + ObjectID val = decode_uint64(buf); + if (r_len) + (*r_len) += 8; + + if (val == 0) { + r_variant = (Object *)NULL; + } else { + Ref<EncodedObjectAsID> obj_as_id; + obj_as_id.instance(); + obj_as_id->set_object_id(val); + + r_variant = obj_as_id; + } + + } else { + ERR_FAIL_COND_V(!p_allow_objects, ERR_UNAUTHORIZED); + + String str; + Error err = _decode_string(buf, len, r_len, str); + if (err) + return err; + + if (str == String()) { + r_variant = (Object *)NULL; + } else { + + Object *obj = ClassDB::instance(str); + + ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE); + ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); + + int32_t count = decode_uint32(buf); + buf += 4; + len -= 4; + if (r_len) { + (*r_len) += 4; + } + + for (int i = 0; i < count; i++) { + + str = String(); + err = _decode_string(buf, len, r_len, str); + if (err) + return err; + + Variant value; + int used; + err = decode_variant(value, buf, len, &used, p_allow_objects); + if (err) + return err; + + buf += used; + len -= used; + if (r_len) { + (*r_len) += used; + } + + obj->set(str, value); + } + + if (obj->cast_to<Reference>()) { + REF ref = REF(obj->cast_to<Reference>()); + r_variant = ref; + } else { + r_variant = obj; + } + } + } + } break; case Variant::DICTIONARY: { @@ -386,7 +494,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Variant key, value; int used; - Error err = decode_variant(key, buf, len, &used); + Error err = decode_variant(key, buf, len, &used, p_allow_objects); ERR_FAIL_COND_V(err, err); buf += used; @@ -395,7 +503,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int (*r_len) += used; } - err = decode_variant(value, buf, len, &used); + err = decode_variant(value, buf, len, &used, p_allow_objects); ERR_FAIL_COND_V(err, err); buf += used; @@ -430,7 +538,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int int used = 0; Variant v; - Error err = decode_variant(v, buf, len, &used); + Error err = decode_variant(v, buf, len, &used, p_allow_objects); ERR_FAIL_COND_V(err, err); buf += used; len -= used; @@ -691,7 +799,27 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int return OK; } -Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { +static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { + + CharString utf8 = p_string.utf8(); + + if (buf) { + encode_uint32(utf8.length(), buf); + buf += 4; + copymem(buf, utf8.get_data(), utf8.length()); + buf += utf8.length(); + } + + r_len += 4 + utf8.length(); + while (r_len % 4) { + r_len++; //pad + if (buf) { + buf++; + } + } +} + +Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_object_as_id) { uint8_t *buf = r_buffer; @@ -715,6 +843,11 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { flags |= ENCODE_FLAG_64; //always encode real as double } } break; + case Variant::OBJECT: { + if (p_object_as_id) { + flags |= ENCODE_FLAG_OBJECT_AS_ID; + } + } break; } if (buf) { @@ -831,17 +964,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { } break; case Variant::STRING: { - CharString utf8 = p_variant.operator String().utf8(); - - if (buf) { - encode_uint32(utf8.length(), buf); - buf += 4; - copymem(buf, utf8.get_data(), utf8.length()); - } - - r_len += 4 + utf8.length(); - while (r_len % 4) - r_len++; //pad + _encode_string(p_variant, buf, r_len); } break; // math types @@ -991,9 +1114,74 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { ERR_EXPLAIN("Can't marshallize resources"); ERR_FAIL_V(ERR_INVALID_DATA); //no, i'm sorry, no go } break;*/ - case Variant::_RID: + case Variant::_RID: { + + } break; case Variant::OBJECT: { + if (p_object_as_id) { + + if (buf) { + + Object *obj = p_variant; + ObjectID id = 0; + if (obj && ObjectDB::instance_validate(obj)) { + id = obj->get_instance_id(); + } + + encode_uint64(id, buf); + } + + r_len += 8; + + } else { + Object *obj = p_variant; + if (!obj) { + if (buf) { + encode_uint32(0, buf); + buf += 4; + r_len += 4; + } + } else { + _encode_string(obj->get_class(), buf, r_len); + + List<PropertyInfo> props; + obj->get_property_list(&props); + + int pc = 0; + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + continue; + pc++; + } + + if (buf) { + encode_uint32(pc, buf); + buf += 4; + } + + r_len += 4; + + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + continue; + + _encode_string(E->get().name, buf, r_len); + + int len; + Error err = encode_variant(obj->get(E->get().name), buf, len, p_object_as_id); + if (err) + return err; + ERR_FAIL_COND_V(len % 4, ERR_BUG); + r_len += len; + if (buf) + buf += len; + } + } + } + } break; case Variant::DICTIONARY: { @@ -1024,12 +1212,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { r_len++; //pad */ int len; - encode_variant(E->get(), buf, len); + encode_variant(E->get(), buf, len, p_object_as_id); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) buf += len; - encode_variant(d[E->get()], buf, len); + encode_variant(d[E->get()], buf, len, p_object_as_id); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) @@ -1051,7 +1239,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { for (int i = 0; i < v.size(); i++) { int len; - encode_variant(v.get(i), buf, len); + encode_variant(v.get(i), buf, len, p_object_as_id); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) diff --git a/core/io/marshalls.h b/core/io/marshalls.h index eb2785aa4e..234ae3b183 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -32,8 +32,8 @@ #include "typedefs.h" +#include "reference.h" #include "variant.h" - /** * Miscellaneous helpers for marshalling data types, and encoding * in an endian independent way @@ -183,7 +183,22 @@ static inline double decode_double(const uint8_t *p_arr) { return md.d; } -Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = NULL); -Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len); +class EncodedObjectAsID : public Reference { + GDCLASS(EncodedObjectAsID, Reference); + + ObjectID id; + +protected: + static void _bind_methods(); + +public: + void set_object_id(ObjectID p_id); + ObjectID get_object_id() const; + + EncodedObjectAsID(); +}; + +Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = NULL, bool p_allow_objects = true); +Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_object_as_id = false); #endif diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 40082cc481..ca00b8b480 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -35,9 +35,20 @@ PacketPeer::PacketPeer() { + allow_object_decoding = false; last_get_error = OK; } +void PacketPeer::set_allow_object_decoding(bool p_enable) { + + allow_object_decoding = p_enable; +} + +bool PacketPeer::is_object_decoding_allowed() const { + + return allow_object_decoding; +} + Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) const { const uint8_t *buffer; @@ -75,13 +86,13 @@ Error PacketPeer::get_var(Variant &r_variant) const { if (err) return err; - return decode_variant(r_variant, buffer, buffer_size); + return decode_variant(r_variant, buffer, buffer_size, NULL, allow_object_decoding); } Error PacketPeer::put_var(const Variant &p_packet) { int len; - Error err = encode_variant(p_packet, NULL, len); // compute len first + Error err = encode_variant(p_packet, NULL, len, !allow_object_decoding); // compute len first if (err) return err; @@ -90,7 +101,7 @@ Error PacketPeer::put_var(const Variant &p_packet) { uint8_t *buf = (uint8_t *)alloca(len); ERR_FAIL_COND_V(!buf, ERR_OUT_OF_MEMORY); - err = encode_variant(p_packet, buf, len); + err = encode_variant(p_packet, buf, len, !allow_object_decoding); ERR_FAIL_COND_V(err, err); return put_packet(buf, len); @@ -120,12 +131,15 @@ Error PacketPeer::_get_packet_error() const { void PacketPeer::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_var:Variant"), &PacketPeer::_bnd_get_var); - ClassDB::bind_method(D_METHOD("put_var", "var:Variant"), &PacketPeer::put_var); + ClassDB::bind_method(D_METHOD("get_var"), &PacketPeer::_bnd_get_var); + ClassDB::bind_method(D_METHOD("put_var", "var"), &PacketPeer::put_var); ClassDB::bind_method(D_METHOD("get_packet"), &PacketPeer::_get_packet); - ClassDB::bind_method(D_METHOD("put_packet:Error", "buffer"), &PacketPeer::_put_packet); - ClassDB::bind_method(D_METHOD("get_packet_error:Error"), &PacketPeer::_get_packet_error); + ClassDB::bind_method(D_METHOD("put_packet", "buffer"), &PacketPeer::_put_packet); + ClassDB::bind_method(D_METHOD("get_packet_error"), &PacketPeer::_get_packet_error); ClassDB::bind_method(D_METHOD("get_available_packet_count"), &PacketPeer::get_available_packet_count); + + ClassDB::bind_method(D_METHOD("set_allow_object_decoding", "enable"), &PacketPeer::set_allow_object_decoding); + ClassDB::bind_method(D_METHOD("is_object_decoding_allowed"), &PacketPeer::is_object_decoding_allowed); }; /***************/ @@ -138,9 +152,11 @@ void PacketPeerStream::_set_stream_peer(REF p_peer) { void PacketPeerStream::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_stream_peer", "peer:StreamPeer"), &PacketPeerStream::_set_stream_peer); + ClassDB::bind_method(D_METHOD("set_stream_peer", "peer"), &PacketPeerStream::_set_stream_peer); ClassDB::bind_method(D_METHOD("set_input_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_input_buffer_max_size); ClassDB::bind_method(D_METHOD("set_output_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_output_buffer_max_size); + ClassDB::bind_method(D_METHOD("get_input_buffer_max_size"), &PacketPeerStream::get_input_buffer_max_size); + ClassDB::bind_method(D_METHOD("get_output_buffer_max_size"), &PacketPeerStream::get_output_buffer_max_size); } Error PacketPeerStream::_poll_buffer() const { @@ -251,12 +267,22 @@ void PacketPeerStream::set_input_buffer_max_size(int p_max_size) { ERR_EXPLAIN("Buffer in use, resizing would cause loss of data"); ERR_FAIL_COND(ring_buffer.data_left()); ring_buffer.resize(nearest_shift(p_max_size + 4)); - input_buffer.resize(nearest_power_of_2(p_max_size + 4)); + input_buffer.resize(next_power_of_2(p_max_size + 4)); +} + +int PacketPeerStream::get_input_buffer_max_size() const { + + return input_buffer.size() - 4; } void PacketPeerStream::set_output_buffer_max_size(int p_max_size) { - output_buffer.resize(nearest_power_of_2(p_max_size + 4)); + output_buffer.resize(next_power_of_2(p_max_size + 4)); +} + +int PacketPeerStream::get_output_buffer_max_size() const { + + return output_buffer.size() - 4; } PacketPeerStream::PacketPeerStream() { diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h index ed6b252d80..597119f7f4 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -48,6 +48,8 @@ class PacketPeer : public Reference { mutable Error last_get_error; + bool allow_object_decoding; + public: virtual int get_available_packet_count() const = 0; virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) const = 0; ///< buffer is GONE after next get_packet @@ -63,6 +65,9 @@ public: virtual Error get_var(Variant &r_variant) const; virtual Error put_var(const Variant &p_packet); + void set_allow_object_decoding(bool p_enable); + bool is_object_decoding_allowed() const; + PacketPeer(); ~PacketPeer() {} }; @@ -93,7 +98,9 @@ public: void set_stream_peer(const Ref<StreamPeer> &p_peer); void set_input_buffer_max_size(int p_max_size); + int get_input_buffer_max_size() const; void set_output_buffer_max_size(int p_max_size); + int get_output_buffer_max_size() const; PacketPeerStream(); }; diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 8bc3241cc5..d1729819a8 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -59,9 +59,9 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) { void PacketPeerUDP::_bind_methods() { - ClassDB::bind_method(D_METHOD("listen:Error", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536)); + ClassDB::bind_method(D_METHOD("listen", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536)); ClassDB::bind_method(D_METHOD("close"), &PacketPeerUDP::close); - ClassDB::bind_method(D_METHOD("wait:Error"), &PacketPeerUDP::wait); + ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait); ClassDB::bind_method(D_METHOD("is_listening"), &PacketPeerUDP::is_listening); ClassDB::bind_method(D_METHOD("get_packet_ip"), &PacketPeerUDP::_get_packet_ip); //ClassDB::bind_method(D_METHOD("get_packet_address"),&PacketPeerUDP::_get_packet_address); diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index a39eb6bcfd..007b810b67 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -49,7 +49,7 @@ protected: public: void set_blocking_mode(bool p_enable); - virtual Error listen(int p_port, IP_Address p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536) = 0; + virtual Error listen(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536) = 0; virtual void close() = 0; virtual Error wait() = 0; virtual bool is_listening() const = 0; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 9aa16ed7e7..fd8928b8a0 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -717,7 +717,7 @@ Error ResourceInteractiveLoaderBinary::poll() { if (!r) { error = ERR_FILE_CORRUPT; memdelete(obj); //bye - ERR_EXPLAIN(local_path + ":Resoucre type in resource field not a resource, type is: " + obj->get_class()); + ERR_EXPLAIN(local_path + ":Resource type in resource field not a resource, type is: " + obj->get_class()); ERR_FAIL_COND_V(!r, ERR_FILE_CORRUPT); } @@ -901,7 +901,7 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { uint32_t ext_resources_size = f->get_32(); for (uint32_t i = 0; i < ext_resources_size; i++) { - ExtResoucre er; + ExtResource er; er.type = get_unicode_string(); er.path = get_unicode_string(); external_resources.push_back(er); @@ -926,7 +926,7 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { for (uint32_t i = 0; i < int_resources_size; i++) { - IntResoucre ir; + IntResource ir; ir.path = get_unicode_string(); ir.offset = f->get_64(); internal_resources.push_back(ir); diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 5da5a0fc37..1c66344e3e 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -56,19 +56,19 @@ class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader { StringName _get_string(); - struct ExtResoucre { + struct ExtResource { String path; String type; }; - Vector<ExtResoucre> external_resources; + Vector<ExtResource> external_resources; - struct IntResoucre { + struct IntResource { String path; uint64_t offset; }; - Vector<IntResoucre> internal_resources; + Vector<IntResource> internal_resources; String get_unicode_string(); void _advance_padding(uint32_t p_len); diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp index 61da4f3350..7033dbe5fb 100644 --- a/core/io/resource_import.cpp +++ b/core/io/resource_import.cpp @@ -199,6 +199,52 @@ String ResourceFormatImporter::get_internal_resource_path(const String &p_path) return pat.path; } +void ResourceFormatImporter::get_internal_resource_path_list(const String &p_path, List<String> *r_paths) { + + Error err; + FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); + + if (!f) + return; + + VariantParser::StreamFile stream; + stream.f = f; + + String assign; + Variant value; + VariantParser::Tag next_tag; + + int lines = 0; + String error_text; + while (true) { + + assign = Variant(); + next_tag.fields.clear(); + next_tag.name = String(); + + err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); + if (err == ERR_FILE_EOF) { + memdelete(f); + return; + } else if (err != OK) { + ERR_PRINTS("ResourceFormatImporter::get_internal_resource_path_list - " + p_path + ".import:" + itos(lines) + " error: " + error_text); + memdelete(f); + return; + } + + if (assign != String()) { + if (assign.begins_with("path.")) { + r_paths->push_back(value); + } else if (assign == "path") { + r_paths->push_back(value); + } + } else if (next_tag.name != "remap") { + break; + } + } + memdelete(f); +} + String ResourceFormatImporter::get_resource_type(const String &p_path) const { PathAndType pat; diff --git a/core/io/resource_import.h b/core/io/resource_import.h index 9d2a5180dc..67fd870178 100644 --- a/core/io/resource_import.h +++ b/core/io/resource_import.h @@ -59,6 +59,7 @@ public: virtual bool can_be_imported(const String &p_path) const; String get_internal_resource_path(const String &p_path) const; + void get_internal_resource_path_list(const String &p_path, List<String> *r_paths); void add_importer(const Ref<ResourceImporter> &p_importer) { importers.insert(p_importer); } void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); } @@ -85,9 +86,9 @@ public: PropertyInfo option; Variant default_value; - ImportOption(const PropertyInfo &p_info, const Variant &p_default) { - option = p_info; - default_value = p_default; + ImportOption(const PropertyInfo &p_info, const Variant &p_default) + : option(p_info), + default_value(p_default) { } ImportOption() {} }; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 9b89fa3399..5347cd6ee1 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -84,7 +84,7 @@ void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, Li void ResourceInteractiveLoader::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_resource:Resource"), &ResourceInteractiveLoader::get_resource); + ClassDB::bind_method(D_METHOD("get_resource"), &ResourceInteractiveLoader::get_resource); ClassDB::bind_method(D_METHOD("poll"), &ResourceInteractiveLoader::poll); ClassDB::bind_method(D_METHOD("wait"), &ResourceInteractiveLoader::wait); ClassDB::bind_method(D_METHOD("get_stage"), &ResourceInteractiveLoader::get_stage); diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index 0dbcb3cf56..7042700d92 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -210,7 +210,7 @@ void StreamPeer::put_double(double p_val) { void StreamPeer::put_utf8_string(const String &p_string) { CharString cs = p_string.utf8(); - put_u32(p_string.length()); + put_u32(cs.length()); put_data((const uint8_t *)cs.get_data(), cs.length()); } void StreamPeer::put_var(const Variant &p_variant) { @@ -385,7 +385,7 @@ void StreamPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("put_float", "val"), &StreamPeer::put_float); ClassDB::bind_method(D_METHOD("put_double", "val"), &StreamPeer::put_double); ClassDB::bind_method(D_METHOD("put_utf8_string", "val"), &StreamPeer::put_utf8_string); - ClassDB::bind_method(D_METHOD("put_var", "val:Variant"), &StreamPeer::put_var); + ClassDB::bind_method(D_METHOD("put_var", "val"), &StreamPeer::put_var); ClassDB::bind_method(D_METHOD("get_8"), &StreamPeer::get_8); ClassDB::bind_method(D_METHOD("get_u8"), &StreamPeer::get_u8); @@ -399,7 +399,7 @@ void StreamPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_double"), &StreamPeer::get_double); ClassDB::bind_method(D_METHOD("get_string", "bytes"), &StreamPeer::get_string); ClassDB::bind_method(D_METHOD("get_utf8_string", "bytes"), &StreamPeer::get_utf8_string); - ClassDB::bind_method(D_METHOD("get_var:Variant"), &StreamPeer::get_var); + ClassDB::bind_method(D_METHOD("get_var"), &StreamPeer::get_var); } //////////////////////////////// @@ -412,7 +412,7 @@ void StreamPeerBuffer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_data_array", "data"), &StreamPeerBuffer::set_data_array); ClassDB::bind_method(D_METHOD("get_data_array"), &StreamPeerBuffer::get_data_array); ClassDB::bind_method(D_METHOD("clear"), &StreamPeerBuffer::clear); - ClassDB::bind_method(D_METHOD("duplicate:StreamPeerBuffer"), &StreamPeerBuffer::duplicate); + ClassDB::bind_method(D_METHOD("duplicate"), &StreamPeerBuffer::duplicate); } Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) { @@ -459,8 +459,9 @@ Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_ } PoolVector<uint8_t>::Read r = data.read(); - copymem(p_buffer, r.ptr(), r_received); + copymem(p_buffer, r.ptr() + pointer, r_received); + pointer += r_received; // FIXME: return what? OK or ERR_* } diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp index 57cffd073a..ef3c264375 100644 --- a/core/io/stream_peer_ssl.cpp +++ b/core/io/stream_peer_ssl.cpp @@ -51,8 +51,8 @@ bool StreamPeerSSL::is_available() { void StreamPeerSSL::_bind_methods() { - ClassDB::bind_method(D_METHOD("accept_stream:Error", "stream:StreamPeer"), &StreamPeerSSL::accept_stream); - ClassDB::bind_method(D_METHOD("connect_to_stream:Error", "stream:StreamPeer", "validate_certs", "for_hostname"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String())); + ClassDB::bind_method(D_METHOD("accept_stream", "stream"), &StreamPeerSSL::accept_stream); + ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "validate_certs", "for_hostname"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String())); ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerSSL::get_status); ClassDB::bind_method(D_METHOD("disconnect_from_stream"), &StreamPeerSSL::disconnect_from_stream); BIND_CONSTANT(STATUS_DISCONNECTED); diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 4c891188ee..29a80ecc19 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -49,7 +49,7 @@ void TCP_Server::_bind_methods() { ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCP_Server::listen, DEFVAL("*")); ClassDB::bind_method(D_METHOD("is_connection_available"), &TCP_Server::is_connection_available); - ClassDB::bind_method(D_METHOD("take_connection:StreamPeerTCP"), &TCP_Server::take_connection); + ClassDB::bind_method(D_METHOD("take_connection"), &TCP_Server::take_connection); ClassDB::bind_method(D_METHOD("stop"), &TCP_Server::stop); } diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index 4e7fa7cf3e..b4ff3246ad 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -45,7 +45,7 @@ protected: static void _bind_methods(); public: - virtual Error listen(uint16_t p_port, const IP_Address p_bind_address = IP_Address("*")) = 0; + virtual Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*")) = 0; virtual bool is_connection_available() const = 0; virtual Ref<StreamPeerTCP> take_connection() = 0; diff --git a/core/make_binders.py b/core/make_binders.py index 74b5e9fda3..a5cdb78443 100644 --- a/core/make_binders.py +++ b/core/make_binders.py @@ -11,11 +11,18 @@ public: #ifdef DEBUG_METHODS_ENABLED virtual Variant::Type _gen_argument_type(int p_arg) const { return _get_argument_type(p_arg); } Variant::Type _get_argument_type(int p_argument) const { - $ifret if (p_argument==-1) return Variant::get_type_for<R>();$ - $arg if (p_argument==(@-1)) return Variant::get_type_for<P@>(); + $ifret if (p_argument==-1) return (Variant::Type)GetTypeInfo<R>::VARIANT_TYPE;$ + $arg if (p_argument==(@-1)) return (Variant::Type)GetTypeInfo<P@>::VARIANT_TYPE; $ return Variant::NIL; } + virtual StringName _gen_argument_type_name(int p_arg) const { return _gen_argument_type_hint(p_arg); } + StringName _gen_argument_type_hint(int p_argument) const { + $ifret if (p_argument==-1) return GetTypeInfo<R>::get_class_name();$ + $arg if (p_argument==(@-1)) return GetTypeInfo<P@>::get_class_name(); + $ + return StringName(); + } #endif virtual String get_instance_class() const { return T::get_class_static(); @@ -91,11 +98,20 @@ public: virtual Variant::Type _gen_argument_type(int p_arg) const { return _get_argument_type(p_arg); } Variant::Type _get_argument_type(int p_argument) const { - $ifret if (p_argument==-1) return Variant::get_type_for<R>();$ - $arg if (p_argument==(@-1)) return Variant::get_type_for<P@>(); + $ifret if (p_argument==-1) return (Variant::Type)GetTypeInfo<R>::VARIANT_TYPE;$ + $arg if (p_argument==(@-1)) return (Variant::Type)GetTypeInfo<P@>::VARIANT_TYPE; $ return Variant::NIL; } + + virtual StringName _gen_argument_type_name(int p_arg) const { return _gen_argument_type_hint(p_arg); } + + StringName _gen_argument_type_hint(int p_argument) const { + $ifret if (p_argument==-1) return GetTypeInfo<R>::get_class_name();$ + $arg if (p_argument==(@-1)) return GetTypeInfo<P@>::get_class_name(); + $ + return StringName(); + } #endif virtual String get_instance_class() const { return type_name; diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp index 327a6017c3..e22bc2b05e 100644 --- a/core/math/bsp_tree.cpp +++ b/core/math/bsp_tree.cpp @@ -577,12 +577,11 @@ BSP_Tree::BSP_Tree(const PoolVector<Face3> &p_faces, real_t p_error_radius) { error_radius = p_error_radius; } -BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3 &p_aabb, real_t p_error_radius) { - - nodes = p_nodes; - planes = p_planes; - aabb = p_aabb; - error_radius = p_error_radius; +BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3 &p_aabb, real_t p_error_radius) + : nodes(p_nodes), + planes(p_planes), + aabb(p_aabb), + error_radius(p_error_radius) { } BSP_Tree::~BSP_Tree() { diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index 2bea514d37..9a5811244a 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -1076,8 +1076,8 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu for (int i = 0; i < results.size(); i++) { - real_t h = nearest_power_of_2(results[i].max_h); - real_t w = nearest_power_of_2(results[i].max_w); + real_t h = next_power_of_2(results[i].max_h); + real_t w = next_power_of_2(results[i].max_w); real_t aspect = h > w ? h / w : w / h; if (aspect < best_aspect) { best = i; diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index 52e240ed47..956cfe5258 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -281,22 +281,22 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c } // slide returns the component of the vector along the given plane, specified by its normal vector. -Vector2 Vector2::slide(const Vector2 &p_n) const { +Vector2 Vector2::slide(const Vector2 &p_normal) const { #ifdef MATH_CHECKS - ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector2()); + ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector2()); #endif - return *this - p_n * this->dot(p_n); + return *this - p_normal * this->dot(p_normal); } -Vector2 Vector2::bounce(const Vector2 &p_n) const { - return -reflect(p_n); +Vector2 Vector2::bounce(const Vector2 &p_normal) const { + return -reflect(p_normal); } -Vector2 Vector2::reflect(const Vector2 &p_n) const { +Vector2 Vector2::reflect(const Vector2 &p_normal) const { #ifdef MATH_CHECKS - ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector2()); + ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector2()); #endif - return 2.0 * p_n * this->dot(p_n) - *this; + return 2.0 * p_normal * this->dot(p_normal) - *this; } bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos, Point2 *r_normal) const { diff --git a/core/math/math_2d.h b/core/math/math_2d.h index 780bb532d7..6fea6c8adb 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -43,6 +43,14 @@ enum Margin { MARGIN_BOTTOM }; +enum Corner { + + CORNER_TOP_LEFT, + CORNER_TOP_RIGHT, + CORNER_BOTTOM_RIGHT, + CORNER_BOTTOM_LEFT +}; + enum Orientation { HORIZONTAL, @@ -107,9 +115,9 @@ struct Vector2 { Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const; Vector2 cubic_interpolate_soft(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const; - Vector2 slide(const Vector2 &p_vec) const; - Vector2 bounce(const Vector2 &p_vec) const; - Vector2 reflect(const Vector2 &p_vec) const; + Vector2 slide(const Vector2 &p_normal) const; + Vector2 bounce(const Vector2 &p_normal) const; + Vector2 reflect(const Vector2 &p_normal) const; Vector2 operator+(const Vector2 &p_v) const; void operator+=(const Vector2 &p_v); @@ -378,13 +386,13 @@ struct Rect2 { operator String() const { return String(position) + ", " + String(size); } Rect2() {} - Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) { - position = Point2(p_x, p_y); - size = Size2(p_width, p_height); + Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) + : position(Point2(p_x, p_y)), + size(Size2(p_width, p_height)) { } - Rect2(const Point2 &p_pos, const Size2 &p_size) { - position = p_pos; - size = p_size; + Rect2(const Point2 &p_pos, const Size2 &p_size) + : position(p_pos), + size(p_size) { } }; @@ -571,18 +579,18 @@ struct Rect2i { operator String() const { return String(position) + ", " + String(size); } operator Rect2() const { return Rect2(position, size); } - Rect2i(const Rect2 &p_r2) { - position = p_r2.position; - size = p_r2.size; + Rect2i(const Rect2 &p_r2) + : position(p_r2.position), + size(p_r2.size) { } Rect2i() {} - Rect2i(int p_x, int p_y, int p_width, int p_height) { - position = Point2(p_x, p_y); - size = Size2(p_width, p_height); + Rect2i(int p_x, int p_y, int p_width, int p_height) + : position(Point2(p_x, p_y)), + size(Size2(p_width, p_height)) { } - Rect2i(const Point2 &p_pos, const Size2 &p_size) { - position = p_pos; - size = p_size; + Rect2i(const Point2 &p_pos, const Size2 &p_size) + : position(p_pos), + size(p_size) { } }; @@ -621,9 +629,9 @@ struct Transform2D { void affine_invert(); Transform2D affine_inverse() const; - void set_rotation(real_t p_phi); + void set_rotation(real_t p_rot); real_t get_rotation() const; - _FORCE_INLINE_ void set_rotation_and_scale(real_t p_phi, const Size2 &p_scale); + _FORCE_INLINE_ void set_rotation_and_scale(real_t p_rot, const Size2 &p_scale); void rotate(real_t p_phi); void scale(const Size2 &p_scale); @@ -660,8 +668,8 @@ struct Transform2D { _FORCE_INLINE_ Vector2 basis_xform_inv(const Vector2 &p_vec) const; _FORCE_INLINE_ Vector2 xform(const Vector2 &p_vec) const; _FORCE_INLINE_ Vector2 xform_inv(const Vector2 &p_vec) const; - _FORCE_INLINE_ Rect2 xform(const Rect2 &p_vec) const; - _FORCE_INLINE_ Rect2 xform_inv(const Rect2 &p_vec) const; + _FORCE_INLINE_ Rect2 xform(const Rect2 &p_rect) const; + _FORCE_INLINE_ Rect2 xform_inv(const Rect2 &p_rect) const; operator String() const; @@ -833,25 +841,25 @@ next4: return true; } -Vector2 Transform2D::basis_xform(const Vector2 &v) const { +Vector2 Transform2D::basis_xform(const Vector2 &p_vec) const { return Vector2( - tdotx(v), - tdoty(v)); + tdotx(p_vec), + tdoty(p_vec)); } -Vector2 Transform2D::basis_xform_inv(const Vector2 &v) const { +Vector2 Transform2D::basis_xform_inv(const Vector2 &p_vec) const { return Vector2( - elements[0].dot(v), - elements[1].dot(v)); + elements[0].dot(p_vec), + elements[1].dot(p_vec)); } -Vector2 Transform2D::xform(const Vector2 &v) const { +Vector2 Transform2D::xform(const Vector2 &p_vec) const { return Vector2( - tdotx(v), - tdoty(v)) + + tdotx(p_vec), + tdoty(p_vec)) + elements[2]; } Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const { diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp index b64f34d977..f2f6ff93cf 100644 --- a/core/math/matrix3.cpp +++ b/core/math/matrix3.cpp @@ -338,7 +338,7 @@ void Basis::set_rotation_axis_angle(const Vector3 &p_axis, real_t p_angle) { rotate(p_axis, p_angle); } -// get_euler returns a vector containing the Euler angles in the format +// get_euler_xyz returns a vector containing the Euler angles in the format // (a1,a2,a3), where a3 is the angle of the first rotation, and a1 is the last // (following the convention they are commonly defined in the literature). // @@ -348,7 +348,7 @@ void Basis::set_rotation_axis_angle(const Vector3 &p_axis, real_t p_angle) { // And thus, assuming the matrix is a rotation matrix, this function returns // the angles in the decomposition R = X(a1).Y(a2).Z(a3) where Z(a) rotates // around the z-axis by a and so on. -Vector3 Basis::get_euler() const { +Vector3 Basis::get_euler_xyz() const { // Euler angles in XYZ convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix @@ -366,6 +366,9 @@ Vector3 Basis::get_euler() const { if (euler.y > -Math_PI * 0.5) { //if rotation is Y-only, return a proper -pi,pi range like in x or z for the same case. if (elements[1][0] == 0.0 && elements[0][1] == 0.0 && elements[0][0] < 0.0) { + euler.x = 0; + euler.z = 0; + if (euler.y > 0.0) euler.y = Math_PI - euler.y; else @@ -389,10 +392,11 @@ Vector3 Basis::get_euler() const { return euler; } -// set_euler expects a vector containing the Euler angles in the format -// (c,b,a), where a is the angle of the first rotation, and c is the last. +// set_euler_xyz expects a vector containing the Euler angles in the format +// (ax,ay,az), where ax is the angle of rotation around x axis, +// and similar for other axes. // The current implementation uses XYZ convention (Z is the first rotation). -void Basis::set_euler(const Vector3 &p_euler) { +void Basis::set_euler_xyz(const Vector3 &p_euler) { real_t c, s; @@ -412,6 +416,78 @@ void Basis::set_euler(const Vector3 &p_euler) { *this = xmat * (ymat * zmat); } +// get_euler_yxz returns a vector containing the Euler angles in the YXZ convention, +// as in first-Z, then-X, last-Y. The angles for X, Y, and Z rotations are returned +// as the x, y, and z components of a Vector3 respectively. +Vector3 Basis::get_euler_yxz() const { + + // Euler angles in YXZ convention. + // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix + // + // rot = cy*cz+sy*sx*sz cz*sy*sx-cy*sz cx*sy + // cx*sz cx*cz -sx + // cy*sx*sz-cz*sy cy*cz*sx+sy*sz cy*cx + + Vector3 euler; +#ifdef MATH_CHECKS + ERR_FAIL_COND_V(is_rotation() == false, euler); +#endif + real_t m12 = elements[1][2]; + + if (m12 < 1) { + if (m12 > -1) { + if (elements[1][0] == 0 && elements[0][1] == 0 && elements[2][2] < 0) { // use pure x rotation + real_t x = asin(-m12); + euler.y = 0; + euler.z = 0; + + if (x > 0.0) + euler.x = Math_PI - x; + else + euler.x = -(Math_PI + x); + } else { + euler.x = asin(-m12); + euler.y = atan2(elements[0][2], elements[2][2]); + euler.z = atan2(elements[1][0], elements[1][1]); + } + } else { // m12 == -1 + euler.x = Math_PI * 0.5; + euler.y = -atan2(-elements[0][1], elements[0][0]); + euler.z = 0; + } + } else { // m12 == 1 + euler.x = -Math_PI * 0.5; + euler.y = -atan2(-elements[0][1], elements[0][0]); + euler.z = 0; + } + + return euler; +} + +// set_euler_yxz expects a vector containing the Euler angles in the format +// (ax,ay,az), where ax is the angle of rotation around x axis, +// and similar for other axes. +// The current implementation uses YXZ convention (Z is the first rotation). +void Basis::set_euler_yxz(const Vector3 &p_euler) { + + real_t c, s; + + c = Math::cos(p_euler.x); + s = Math::sin(p_euler.x); + Basis xmat(1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c); + + c = Math::cos(p_euler.y); + s = Math::sin(p_euler.y); + Basis ymat(c, 0.0, s, 0.0, 1.0, 0.0, -s, 0.0, c); + + c = Math::cos(p_euler.z); + s = Math::sin(p_euler.z); + Basis zmat(c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0); + + //optimizer will optimize away all this anyway + *this = ymat * xmat * zmat; +} + bool Basis::is_equal_approx(const Basis &a, const Basis &b) const { for (int i = 0; i < 3; i++) { diff --git a/core/math/matrix3.h b/core/math/matrix3.h index 8897c692f7..74e6564578 100644 --- a/core/math/matrix3.h +++ b/core/math/matrix3.h @@ -84,8 +84,13 @@ public: void set_rotation_euler(const Vector3 &p_euler); void set_rotation_axis_angle(const Vector3 &p_axis, real_t p_angle); - Vector3 get_euler() const; - void set_euler(const Vector3 &p_euler); + Vector3 get_euler_xyz() const; + void set_euler_xyz(const Vector3 &p_euler); + Vector3 get_euler_yxz() const; + void set_euler_yxz(const Vector3 &p_euler); + + Vector3 get_euler() const { return get_euler_yxz(); }; + void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }; void get_axis_angle(Vector3 &r_axis, real_t &r_angle) const; void set_axis_angle(const Vector3 &p_axis, real_t p_phi); diff --git a/core/math/octree.h b/core/math/octree.h index 010c1b18f7..2e37056030 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -351,7 +351,7 @@ private: }; void _cull_convex(Octant *p_octant, _CullConvexData *p_cull); - void _cull_AABB(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); + void _cull_aabb(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); void _cull_segment(Octant *p_octant, const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); void _cull_point(Octant *p_octant, const Vector3 &p_point, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); @@ -380,7 +380,7 @@ public: int get_subindex(OctreeElementID p_id) const; int cull_convex(const Vector<Plane> &p_convex, T **p_result_array, int p_result_max, uint32_t p_mask = 0xFFFFFFFF); - int cull_AABB(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); + int cull_aabb(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); int cull_segment(const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); int cull_point(const Vector3 &p_point, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); @@ -1095,7 +1095,7 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p } template <class T, bool use_pairs, class AL> -void Octree<T, use_pairs, AL>::_cull_AABB(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { +void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { if (*p_result_idx == p_result_max) return; //pointless @@ -1160,7 +1160,7 @@ void Octree<T, use_pairs, AL>::_cull_AABB(Octant *p_octant, const Rect3 &p_aabb, for (int i = 0; i < 8; i++) { if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_inclusive(p_aabb)) { - _cull_AABB(p_octant->children[i], p_aabb, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); + _cull_aabb(p_octant->children[i], p_aabb, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); } } } @@ -1336,14 +1336,14 @@ int Octree<T, use_pairs, AL>::cull_convex(const Vector<Plane> &p_convex, T **p_r } template <class T, bool use_pairs, class AL> -int Octree<T, use_pairs, AL>::cull_AABB(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { +int Octree<T, use_pairs, AL>::cull_aabb(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { if (!root) return 0; int result_count = 0; pass++; - _cull_AABB(root, p_aabb, p_result_array, &result_count, p_result_max, p_subindex_array, p_mask); + _cull_aabb(root, p_aabb, p_result_array, &result_count, p_result_max, p_subindex_array, p_mask); return result_count; } diff --git a/core/math/plane.cpp b/core/math/plane.cpp index f5e92866c4..17928d07c3 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -103,7 +103,7 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r return true; } -bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersection) const { +bool Plane::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const { Vector3 segment = p_dir; real_t den = normal.dot(segment); @@ -128,7 +128,7 @@ bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersectio return true; } -bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_intersection) const { +bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const { Vector3 segment = p_begin - p_end; real_t den = normal.dot(segment); diff --git a/core/math/plane.h b/core/math/plane.h index 5a048674e4..73d584e553 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -56,8 +56,8 @@ public: /* intersections */ bool intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result = 0) const; - bool intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersection) const; - bool intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_intersection) const; + bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const; + bool intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const; _FORCE_INLINE_ Vector3 project(const Vector3 &p_point) const { @@ -75,7 +75,8 @@ public: _FORCE_INLINE_ Plane() { d = 0; } _FORCE_INLINE_ Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d) - : normal(p_a, p_b, p_c), d(p_d){}; + : normal(p_a, p_b, p_c), + d(p_d){}; _FORCE_INLINE_ Plane(const Vector3 &p_normal, real_t p_d); _FORCE_INLINE_ Plane(const Vector3 &p_point, const Vector3 &p_normal); @@ -99,16 +100,14 @@ bool Plane::has_point(const Vector3 &p_point, real_t _epsilon) const { return (dist <= _epsilon); } -Plane::Plane(const Vector3 &p_normal, real_t p_d) { - - normal = p_normal; - d = p_d; +Plane::Plane(const Vector3 &p_normal, real_t p_d) + : normal(p_normal), + d(p_d) { } -Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal) { - - normal = p_normal; - d = p_normal.dot(p_point); +Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal) + : normal(p_normal), + d(p_normal.dot(p_point)) { } Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir) { diff --git a/core/math/quat.cpp b/core/math/quat.cpp index 0bea97c2e8..5984cdf657 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -31,10 +31,11 @@ #include "matrix3.h" #include "print_string.h" -// set_euler expects a vector containing the Euler angles in the format -// (c,b,a), where a is the angle of the first rotation, and c is the last. -// The current implementation uses XYZ convention (Z is the first rotation). -void Quat::set_euler(const Vector3 &p_euler) { +// set_euler_xyz expects a vector containing the Euler angles in the format +// (ax,ay,az), where ax is the angle of rotation around x axis, +// and similar for other axes. +// This implementation uses XYZ convention (Z is the first rotation). +void Quat::set_euler_xyz(const Vector3 &p_euler) { real_t half_a1 = p_euler.x * 0.5; real_t half_a2 = p_euler.y * 0.5; real_t half_a3 = p_euler.z * 0.5; @@ -56,12 +57,48 @@ void Quat::set_euler(const Vector3 &p_euler) { -sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3); } -// get_euler returns a vector containing the Euler angles in the format -// (a1,a2,a3), where a3 is the angle of the first rotation, and a1 is the last. -// The current implementation uses XYZ convention (Z is the first rotation). -Vector3 Quat::get_euler() const { +// get_euler_xyz returns a vector containing the Euler angles in the format +// (ax,ay,az), where ax is the angle of rotation around x axis, +// and similar for other axes. +// This implementation uses XYZ convention (Z is the first rotation). +Vector3 Quat::get_euler_xyz() const { Basis m(*this); - return m.get_euler(); + return m.get_euler_xyz(); +} + +// set_euler_yxz expects a vector containing the Euler angles in the format +// (ax,ay,az), where ax is the angle of rotation around x axis, +// and similar for other axes. +// This implementation uses YXZ convention (Z is the first rotation). +void Quat::set_euler_yxz(const Vector3 &p_euler) { + real_t half_a1 = p_euler.y * 0.5; + real_t half_a2 = p_euler.x * 0.5; + real_t half_a3 = p_euler.z * 0.5; + + // R = Y(a1).X(a2).Z(a3) convention for Euler angles. + // Conversion to quaternion as listed in https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19770024290.pdf (page A-6) + // a3 is the angle of the first rotation, following the notation in this reference. + + real_t cos_a1 = Math::cos(half_a1); + real_t sin_a1 = Math::sin(half_a1); + real_t cos_a2 = Math::cos(half_a2); + real_t sin_a2 = Math::sin(half_a2); + real_t cos_a3 = Math::cos(half_a3); + real_t sin_a3 = Math::sin(half_a3); + + set(sin_a1 * cos_a2 * sin_a3 + cos_a1 * sin_a2 * cos_a3, + sin_a1 * cos_a2 * cos_a3 - cos_a1 * sin_a2 * sin_a3, + -sin_a1 * sin_a2 * cos_a3 + cos_a1 * sin_a2 * sin_a3, + sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3); +} + +// get_euler_yxz returns a vector containing the Euler angles in the format +// (ax,ay,az), where ax is the angle of rotation around x axis, +// and similar for other axes. +// This implementation uses YXZ convention (Z is the first rotation). +Vector3 Quat::get_euler_yxz() const { + Basis m(*this); + return m.get_euler_yxz(); } void Quat::operator*=(const Quat &q) { diff --git a/core/math/quat.h b/core/math/quat.h index f22275b457..0e378eb4e4 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -51,8 +51,15 @@ public: bool is_normalized() const; Quat inverse() const; _FORCE_INLINE_ real_t dot(const Quat &q) const; - void set_euler(const Vector3 &p_euler); - Vector3 get_euler() const; + + void set_euler_xyz(const Vector3 &p_euler); + Vector3 get_euler_xyz() const; + void set_euler_yxz(const Vector3 &p_euler); + Vector3 get_euler_yxz() const; + + void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }; + Vector3 get_euler() const { return get_euler_yxz(); }; + Quat slerp(const Quat &q, const real_t &t) const; Quat slerpni(const Quat &q, const real_t &t) const; Quat cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const; diff --git a/core/math/rect3.h b/core/math/rect3.h index b7c94ad9f7..4890a19d99 100644 --- a/core/math/rect3.h +++ b/core/math/rect3.h @@ -47,12 +47,12 @@ public: real_t get_area() const; /// get area _FORCE_INLINE_ bool has_no_area() const { - return (size.x <= CMP_EPSILON || size.y <= CMP_EPSILON || size.z <= CMP_EPSILON); + return (size.x <= 0 || size.y <= 0 || size.z <= 0); } _FORCE_INLINE_ bool has_no_surface() const { - return (size.x <= CMP_EPSILON && size.y <= CMP_EPSILON && size.z <= CMP_EPSILON); + return (size.x <= 0 && size.y <= 0 && size.z <= 0); } const Vector3 &get_position() const { return position; } @@ -72,9 +72,9 @@ public: Rect3 intersection(const Rect3 &p_aabb) const; ///get box where two intersect, empty if no intersection occurs bool intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip = NULL, Vector3 *r_normal = NULL) const; bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip = NULL, Vector3 *r_normal = NULL) const; - _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &from, const Vector3 &p_dir, real_t t0, real_t t1) const; + _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const; - _FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const; + _FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_planes, int p_plane_count) const; bool intersects_plane(const Plane &p_plane) const; _FORCE_INLINE_ bool has_point(const Vector3 &p_point) const; @@ -101,9 +101,9 @@ public: operator String() const; _FORCE_INLINE_ Rect3() {} - inline Rect3(const Vector3 &p_pos, const Vector3 &p_size) { - position = p_pos; - size = p_size; + inline Rect3(const Vector3 &p_pos, const Vector3 &p_size) + : position(p_pos), + size(p_size) { } }; @@ -326,27 +326,27 @@ inline real_t Rect3::get_shortest_axis_size() const { return max_size; } -bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t t0, real_t t1) const { +bool Rect3::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const { - real_t divx = 1.0 / dir.x; - real_t divy = 1.0 / dir.y; - real_t divz = 1.0 / dir.z; + real_t divx = 1.0 / p_dir.x; + real_t divy = 1.0 / p_dir.y; + real_t divz = 1.0 / p_dir.z; Vector3 upbound = position + size; real_t tmin, tmax, tymin, tymax, tzmin, tzmax; - if (dir.x >= 0) { - tmin = (position.x - from.x) * divx; - tmax = (upbound.x - from.x) * divx; + if (p_dir.x >= 0) { + tmin = (position.x - p_from.x) * divx; + tmax = (upbound.x - p_from.x) * divx; } else { - tmin = (upbound.x - from.x) * divx; - tmax = (position.x - from.x) * divx; + tmin = (upbound.x - p_from.x) * divx; + tmax = (position.x - p_from.x) * divx; } - if (dir.y >= 0) { - tymin = (position.y - from.y) * divy; - tymax = (upbound.y - from.y) * divy; + if (p_dir.y >= 0) { + tymin = (position.y - p_from.y) * divy; + tymax = (upbound.y - p_from.y) * divy; } else { - tymin = (upbound.y - from.y) * divy; - tymax = (position.y - from.y) * divy; + tymin = (upbound.y - p_from.y) * divy; + tymax = (position.y - p_from.y) * divy; } if ((tmin > tymax) || (tymin > tmax)) return false; @@ -354,12 +354,12 @@ bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t tmin = tymin; if (tymax < tmax) tmax = tymax; - if (dir.z >= 0) { - tzmin = (position.z - from.z) * divz; - tzmax = (upbound.z - from.z) * divz; + if (p_dir.z >= 0) { + tzmin = (position.z - p_from.z) * divz; + tzmax = (upbound.z - p_from.z) * divz; } else { - tzmin = (upbound.z - from.z) * divz; - tzmax = (position.z - from.z) * divz; + tzmin = (upbound.z - p_from.z) * divz; + tzmax = (position.z - p_from.z) * divz; } if ((tmin > tzmax) || (tzmin > tmax)) return false; diff --git a/core/math/transform.cpp b/core/math/transform.cpp index 7a50214596..3a86fbfc6c 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -208,8 +208,7 @@ Transform::operator String() const { return basis.operator String() + " - " + origin.operator String(); } -Transform::Transform(const Basis &p_basis, const Vector3 &p_origin) { - - basis = p_basis; - origin = p_origin; +Transform::Transform(const Basis &p_basis, const Vector3 &p_origin) + : basis(p_basis), + origin(p_origin) { } diff --git a/core/math/vector3.h b/core/math/vector3.h index 6a7974681e..c58a86fbdb 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -108,9 +108,9 @@ struct Vector3 { _FORCE_INLINE_ real_t angle_to(const Vector3 &p_b) const; - _FORCE_INLINE_ Vector3 slide(const Vector3 &p_vec) const; - _FORCE_INLINE_ Vector3 bounce(const Vector3 &p_vec) const; - _FORCE_INLINE_ Vector3 reflect(const Vector3 &p_vec) const; + _FORCE_INLINE_ Vector3 slide(const Vector3 &p_normal) const; + _FORCE_INLINE_ Vector3 bounce(const Vector3 &p_normal) const; + _FORCE_INLINE_ Vector3 reflect(const Vector3 &p_normal) const; /* Operators */ @@ -410,22 +410,22 @@ void Vector3::zero() { } // slide returns the component of the vector along the given plane, specified by its normal vector. -Vector3 Vector3::slide(const Vector3 &p_n) const { +Vector3 Vector3::slide(const Vector3 &p_normal) const { #ifdef MATH_CHECKS - ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector3()); + ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector3()); #endif - return *this - p_n * this->dot(p_n); + return *this - p_normal * this->dot(p_normal); } -Vector3 Vector3::bounce(const Vector3 &p_n) const { - return -reflect(p_n); +Vector3 Vector3::bounce(const Vector3 &p_normal) const { + return -reflect(p_normal); } -Vector3 Vector3::reflect(const Vector3 &p_n) const { +Vector3 Vector3::reflect(const Vector3 &p_normal) const { #ifdef MATH_CHECKS - ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector3()); + ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector3()); #endif - return 2.0 * p_n * this->dot(p_n) - *this; + return 2.0 * p_normal * this->dot(p_normal) - *this; } #endif diff --git a/core/method_bind.cpp b/core/method_bind.cpp index 51c0e72bc7..6792b62703 100644 --- a/core/method_bind.cpp +++ b/core/method_bind.cpp @@ -38,12 +38,16 @@ PropertyInfo MethodBind::get_argument_info(int p_argument) const { if (p_argument >= 0) { - String name = (p_argument < arg_names.size()) ? String(arg_names[p_argument]) : String("arg" + itos(p_argument)); + String name = p_argument < arg_names.size() ? String(arg_names[p_argument]) : String("arg" + itos(p_argument)); PropertyInfo pi(get_argument_type(p_argument), name); - if ((pi.type == Variant::OBJECT) && name.find(":") != -1) { - pi.hint = PROPERTY_HINT_RESOURCE_TYPE; - pi.hint_string = name.get_slicec(':', 1); - pi.name = name.get_slicec(':', 0); + + if (!is_vararg() && pi.type == Variant::OBJECT) { + StringName type_hint = arg_type_hints[p_argument]; + + if (type_hint != StringName()) { + pi.hint = PROPERTY_HINT_RESOURCE_TYPE; + pi.hint_string = type_hint.operator String(); + } } return pi; @@ -87,6 +91,16 @@ Vector<StringName> MethodBind::get_argument_names() const { return arg_names; } +void MethodBind::set_argument_type_hints(const Vector<StringName> &p_type_hints) { + + arg_type_hints = p_type_hints; +} + +Vector<StringName> MethodBind::get_argument_type_hints() const { + + return arg_type_hints; +} + #endif void MethodBind::set_default_arguments(const Vector<Variant> &p_defargs) { @@ -98,11 +112,19 @@ void MethodBind::set_default_arguments(const Vector<Variant> &p_defargs) { void MethodBind::_generate_argument_types(int p_count) { set_argument_count(p_count); + Variant::Type *argt = memnew_arr(Variant::Type, p_count + 1); - argt[0] = _gen_argument_type(-1); + + arg_type_hints.resize(p_count); + + argt[0] = _gen_argument_type(-1); // return type + set_return_type(_gen_argument_type_hint(-1)); + for (int i = 0; i < p_count; i++) { argt[i + 1] = _gen_argument_type(i); + arg_type_hints[i] = _gen_argument_type_hint(i); } + set_argument_types(argt); } diff --git a/core/method_bind.h b/core/method_bind.h index dbc9cca082..9bf0323733 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -44,6 +44,8 @@ #define DEBUG_METHODS_ENABLED #endif +#include "type_info.h" + enum MethodFlags { METHOD_FLAG_NORMAL = 1, @@ -87,12 +89,10 @@ struct VariantCaster<const T &> { #define _VC(m_idx) \ (VariantCaster<P##m_idx>::cast((m_idx - 1) >= p_arg_count ? get_default_argument(m_idx - 1) : *p_args[m_idx - 1])) -//SIMPLE_NUMERIC_TYPE is used to avoid a warning on Variant::get_type_for - #ifdef PTRCALL_ENABLED #define VARIANT_ENUM_CAST(m_enum) \ - SIMPLE_NUMERIC_TYPE(m_enum); \ + MAKE_ENUM_TYPE_INFO(m_enum) \ template <> \ struct VariantCaster<m_enum> { \ \ @@ -113,7 +113,7 @@ struct VariantCaster<const T &> { #else #define VARIANT_ENUM_CAST(m_enum) \ - SIMPLE_NUMERIC_TYPE(m_enum); \ + MAKE_ENUM_TYPE_INFO(m_enum) \ template <> \ struct VariantCaster<m_enum> { \ \ @@ -150,6 +150,7 @@ VARIANT_ENUM_CAST(Vector3::Axis); VARIANT_ENUM_CAST(Error); VARIANT_ENUM_CAST(wchar_t); VARIANT_ENUM_CAST(Margin); +VARIANT_ENUM_CAST(Corner); VARIANT_ENUM_CAST(Orientation); VARIANT_ENUM_CAST(HAlign); VARIANT_ENUM_CAST(Variant::Type); @@ -165,6 +166,7 @@ class MethodBind { int argument_count; #ifdef DEBUG_METHODS_ENABLED Vector<StringName> arg_names; + Vector<StringName> arg_type_hints; Variant::Type *argument_types; StringName ret_type; #endif @@ -176,6 +178,7 @@ protected: void _set_returns(bool p_returns); #ifdef DEBUG_METHODS_ENABLED virtual Variant::Type _gen_argument_type(int p_arg) const = 0; + virtual StringName _gen_argument_type_hint(int p_arg) const = 0; void _generate_argument_types(int p_count); void set_argument_types(Variant::Type *p_types) { argument_types = p_types; } #endif @@ -220,6 +223,9 @@ public: void set_argument_names(const Vector<StringName> &p_names); Vector<StringName> get_argument_names() const; + + void set_argument_type_hints(const Vector<StringName> &p_type_hints); + Vector<StringName> get_argument_type_hints() const; #endif void set_hint_flags(uint32_t p_hint) { hint_flags = p_hint; } uint32_t get_hint_flags() const { return hint_flags | (is_const() ? METHOD_FLAG_CONST : 0) | (is_vararg() ? METHOD_FLAG_VARARG : 0); } @@ -282,11 +288,17 @@ public: return Variant::NIL; } + virtual StringName _gen_argument_type_hint(int p_arg) const { + + return "Variant"; + } + virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Variant::CallError &r_error) { T *instance = static_cast<T *>(p_object); return (instance->*call_method)(p_args, p_arg_count, r_error); } + void set_method_info(const MethodInfo &p_info) { set_argument_count(p_info.arguments.size()); diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h index ead58c23c8..d8755fd98b 100644 --- a/core/method_ptrcall.h +++ b/core/method_ptrcall.h @@ -80,6 +80,26 @@ struct PtrToArg { } \ } +#define MAKE_PTRARG_BY_REFERENCE(m_type) \ + template <> \ + struct PtrToArg<m_type> { \ + _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ + return *reinterpret_cast<const m_type *>(p_ptr); \ + } \ + _FORCE_INLINE_ static void encode(const m_type &p_val, void *p_ptr) { \ + *((m_type *)p_ptr) = p_val; \ + } \ + }; \ + template <> \ + struct PtrToArg<const m_type &> { \ + _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ + return *reinterpret_cast<const m_type *>(p_ptr); \ + } \ + _FORCE_INLINE_ static void encode(const m_type &p_val, void *p_ptr) { \ + *((m_type *)p_ptr) = p_val; \ + } \ + } + MAKE_PTRARG(bool); MAKE_PTRARGCONV(uint8_t, int64_t); MAKE_PTRARGCONV(int8_t, int64_t); @@ -95,14 +115,14 @@ MAKE_PTRARG(double); MAKE_PTRARG(String); MAKE_PTRARG(Vector2); MAKE_PTRARG(Rect2); -MAKE_PTRARG(Vector3); +MAKE_PTRARG_BY_REFERENCE(Vector3); MAKE_PTRARG(Transform2D); -MAKE_PTRARG(Plane); +MAKE_PTRARG_BY_REFERENCE(Plane); MAKE_PTRARG(Quat); -MAKE_PTRARG(Rect3); -MAKE_PTRARG(Basis); -MAKE_PTRARG(Transform); -MAKE_PTRARG(Color); +MAKE_PTRARG_BY_REFERENCE(Rect3); +MAKE_PTRARG_BY_REFERENCE(Basis); +MAKE_PTRARG_BY_REFERENCE(Transform); +MAKE_PTRARG_BY_REFERENCE(Color); MAKE_PTRARG(NodePath); MAKE_PTRARG(RID); MAKE_PTRARG(Dictionary); @@ -114,7 +134,7 @@ MAKE_PTRARG(PoolStringArray); MAKE_PTRARG(PoolVector2Array); MAKE_PTRARG(PoolVector3Array); MAKE_PTRARG(PoolColorArray); -MAKE_PTRARG(Variant); +MAKE_PTRARG_BY_REFERENCE(Variant); //this is for Object @@ -311,8 +331,29 @@ MAKE_DVECARR(Plane); } \ } +#define MAKE_STRINGCONV_BY_REFERENCE(m_type) \ + template <> \ + struct PtrToArg<m_type> { \ + _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ + m_type s = *reinterpret_cast<const String *>(p_ptr); \ + return s; \ + } \ + _FORCE_INLINE_ static void encode(const m_type &p_vec, void *p_ptr) { \ + String *arr = reinterpret_cast<String *>(p_ptr); \ + *arr = p_vec; \ + } \ + }; \ + \ + template <> \ + struct PtrToArg<const m_type &> { \ + _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ + m_type s = *reinterpret_cast<const String *>(p_ptr); \ + return s; \ + } \ + } + MAKE_STRINGCONV(StringName); -MAKE_STRINGCONV(IP_Address); +MAKE_STRINGCONV_BY_REFERENCE(IP_Address); template <> struct PtrToArg<PoolVector<Face3> > { diff --git a/core/object.cpp b/core/object.cpp index de75257ede..06c2603b74 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -122,10 +122,9 @@ MethodInfo::operator Dictionary() const { return d; } -MethodInfo::MethodInfo() { - - id = 0; - flags = METHOD_FLAG_NORMAL; +MethodInfo::MethodInfo() + : flags(METHOD_FLAG_NORMAL), + id(0) { } MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) { @@ -161,125 +160,114 @@ MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) { return mi; } -MethodInfo::MethodInfo(const String &p_name) { - - id = 0; - name = p_name; - flags = METHOD_FLAG_NORMAL; +MethodInfo::MethodInfo(const String &p_name) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { } -MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1) { - - id = 0; - name = p_name; +MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { arguments.push_back(p_param1); - flags = METHOD_FLAG_NORMAL; } -MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2) { - - id = 0; - name = p_name; +MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { arguments.push_back(p_param1); arguments.push_back(p_param2); - flags = METHOD_FLAG_NORMAL; } -MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3) { - - id = 0; - name = p_name; +MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { arguments.push_back(p_param1); arguments.push_back(p_param2); arguments.push_back(p_param3); - flags = METHOD_FLAG_NORMAL; } -MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4) { - - id = 0; - name = p_name; +MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { arguments.push_back(p_param1); arguments.push_back(p_param2); arguments.push_back(p_param3); arguments.push_back(p_param4); - flags = METHOD_FLAG_NORMAL; } -MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5) { - id = 0; - name = p_name; +MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { arguments.push_back(p_param1); arguments.push_back(p_param2); arguments.push_back(p_param3); arguments.push_back(p_param4); arguments.push_back(p_param5); - flags = METHOD_FLAG_NORMAL; } -MethodInfo::MethodInfo(Variant::Type ret) { - - id = 0; - flags = METHOD_FLAG_NORMAL; +MethodInfo::MethodInfo(Variant::Type ret) + : flags(METHOD_FLAG_NORMAL), + id(0) { return_val.type = ret; } -MethodInfo::MethodInfo(Variant::Type ret, const String &p_name) { - - id = 0; - name = p_name; - flags = METHOD_FLAG_NORMAL; +MethodInfo::MethodInfo(Variant::Type ret, const String &p_name) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { return_val.type = ret; } -MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1) { - - id = 0; - name = p_name; - arguments.push_back(p_param1); - flags = METHOD_FLAG_NORMAL; +MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { return_val.type = ret; + arguments.push_back(p_param1); } -MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2) { - - id = 0; - name = p_name; +MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { + return_val.type = ret; arguments.push_back(p_param1); arguments.push_back(p_param2); - flags = METHOD_FLAG_NORMAL; - return_val.type = ret; } -MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3) { - - id = 0; - name = p_name; +MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { + return_val.type = ret; arguments.push_back(p_param1); arguments.push_back(p_param2); arguments.push_back(p_param3); - flags = METHOD_FLAG_NORMAL; - return_val.type = ret; } -MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4) { - - id = 0; - name = p_name; +MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { + return_val.type = ret; arguments.push_back(p_param1); arguments.push_back(p_param2); arguments.push_back(p_param3); arguments.push_back(p_param4); - flags = METHOD_FLAG_NORMAL; - return_val.type = ret; } -MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5) { - id = 0; - name = p_name; +MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5) + : name(p_name), + flags(METHOD_FLAG_NORMAL), + id(0) { + return_val.type = ret; arguments.push_back(p_param1); arguments.push_back(p_param2); arguments.push_back(p_param3); arguments.push_back(p_param4); arguments.push_back(p_param5); - flags = METHOD_FLAG_NORMAL; - return_val.type = ret; } Object::Connection::operator Variant() const { @@ -1572,7 +1560,7 @@ void Object::initialize_class() { initialized = true; } -StringName Object::XL_MESSAGE(const StringName &p_message) const { +StringName Object::tr(const StringName &p_message) const { if (!_can_translate || !TranslationServer::get_singleton()) return p_message; @@ -1580,11 +1568,6 @@ StringName Object::XL_MESSAGE(const StringName &p_message) const { return TranslationServer::get_singleton()->translate(p_message); } -StringName Object::tr(const StringName &p_message) const { - - return XL_MESSAGE(p_message); -} - void Object::_clear_internal_resource_paths(const Variant &p_var) { switch (p_var.get_type()) { @@ -1663,17 +1646,17 @@ void Object::_bind_methods() { ClassDB::bind_method(D_METHOD("get_class"), &Object::get_class); ClassDB::bind_method(D_METHOD("is_class", "type"), &Object::is_class); ClassDB::bind_method(D_METHOD("set", "property", "value"), &Object::_set_bind); - ClassDB::bind_method(D_METHOD("get:Variant", "property"), &Object::_get_bind); + ClassDB::bind_method(D_METHOD("get", "property"), &Object::_get_bind); ClassDB::bind_method(D_METHOD("get_property_list"), &Object::_get_property_list_bind); ClassDB::bind_method(D_METHOD("get_method_list"), &Object::_get_method_list_bind); ClassDB::bind_method(D_METHOD("notification", "what", "reversed"), &Object::notification, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_instance_id"), &Object::get_instance_id); - ClassDB::bind_method(D_METHOD("set_script", "script:Script"), &Object::set_script); - ClassDB::bind_method(D_METHOD("get_script:Script"), &Object::get_script); + ClassDB::bind_method(D_METHOD("set_script", "script"), &Object::set_script); + ClassDB::bind_method(D_METHOD("get_script"), &Object::get_script); ClassDB::bind_method(D_METHOD("set_meta", "name", "value"), &Object::set_meta); - ClassDB::bind_method(D_METHOD("get_meta:Variant", "name", "value"), &Object::get_meta); + ClassDB::bind_method(D_METHOD("get_meta", "name"), &Object::get_meta); ClassDB::bind_method(D_METHOD("has_meta", "name"), &Object::has_meta); ClassDB::bind_method(D_METHOD("get_meta_list"), &Object::_get_meta_list_bind); @@ -1699,7 +1682,7 @@ void Object::_bind_methods() { mi.name = "call"; mi.arguments.push_back(PropertyInfo(Variant::STRING, "method")); - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call:Variant", &Object::_call_bind, mi); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call", &Object::_call_bind, mi); } { @@ -1710,7 +1693,7 @@ void Object::_bind_methods() { ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_deferred", &Object::_call_deferred_bind, mi); } - ClassDB::bind_method(D_METHOD("callv:Variant", "method", "arg_array"), &Object::callv); + ClassDB::bind_method(D_METHOD("callv", "method", "arg_array"), &Object::callv); ClassDB::bind_method(D_METHOD("has_method", "method"), &Object::has_method); @@ -1718,17 +1701,16 @@ void Object::_bind_methods() { ClassDB::bind_method(D_METHOD("get_signal_connection_list", "signal"), &Object::_get_signal_connection_list); ClassDB::bind_method(D_METHOD("get_incoming_connections"), &Object::_get_incoming_connections); - ClassDB::bind_method(D_METHOD("connect", "signal", "target:Object", "method", "binds", "flags"), &Object::connect, DEFVAL(Array()), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("disconnect", "signal", "target:Object", "method"), &Object::disconnect); - ClassDB::bind_method(D_METHOD("is_connected", "signal", "target:Object", "method"), &Object::is_connected); + ClassDB::bind_method(D_METHOD("connect", "signal", "target", "method", "binds", "flags"), &Object::connect, DEFVAL(Array()), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("disconnect", "signal", "target", "method"), &Object::disconnect); + ClassDB::bind_method(D_METHOD("is_connected", "signal", "target", "method"), &Object::is_connected); ClassDB::bind_method(D_METHOD("set_block_signals", "enable"), &Object::set_block_signals); ClassDB::bind_method(D_METHOD("is_blocking_signals"), &Object::is_blocking_signals); - ClassDB::bind_method(D_METHOD("set_message_translation", "enable"), &Object::set_message_translation); - ClassDB::bind_method(D_METHOD("can_translate_messages"), &Object::can_translate_messages); ClassDB::bind_method(D_METHOD("property_list_changed_notify"), &Object::property_list_changed_notify); - ClassDB::bind_method(D_METHOD("XL_MESSAGE", "message"), &Object::XL_MESSAGE); + ClassDB::bind_method(D_METHOD("set_message_translation", "enable"), &Object::set_message_translation); + ClassDB::bind_method(D_METHOD("can_translate_messages"), &Object::can_translate_messages); ClassDB::bind_method(D_METHOD("tr", "message"), &Object::tr); ClassDB::bind_method(D_METHOD("is_queued_for_deletion"), &Object::is_queued_for_deletion); @@ -1738,7 +1720,7 @@ void Object::_bind_methods() { ADD_SIGNAL(MethodInfo("script_changed")); BIND_VMETHOD(MethodInfo("_notification", PropertyInfo(Variant::INT, "what"))); - BIND_VMETHOD(MethodInfo("_set", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value"))); + BIND_VMETHOD(MethodInfo("_set:bool", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value"))); #ifdef TOOLS_ENABLED MethodInfo miget("_get", PropertyInfo(Variant::STRING, "property")); miget.return_val.name = "Variant"; diff --git a/core/object.h b/core/object.h index f0147080b4..8a858b5b00 100644 --- a/core/object.h +++ b/core/object.h @@ -83,6 +83,7 @@ enum PropertyHint { PROPERTY_HINT_PROPERTY_OF_BASE_TYPE, ///< a property of a base type PROPERTY_HINT_PROPERTY_OF_INSTANCE, ///< a property of an instance PROPERTY_HINT_PROPERTY_OF_SCRIPT, ///< a property of a script & base + PROPERTY_HINT_OBJECT_TOO_BIG, ///< object is too big to send PROPERTY_HINT_MAX, }; @@ -139,17 +140,17 @@ struct PropertyInfo { static PropertyInfo from_dict(const Dictionary &p_dict); - PropertyInfo() { - type = Variant::NIL; - hint = PROPERTY_HINT_NONE; - usage = PROPERTY_USAGE_DEFAULT; + PropertyInfo() + : type(Variant::NIL), + hint(PROPERTY_HINT_NONE), + usage(PROPERTY_USAGE_DEFAULT) { } - PropertyInfo(Variant::Type p_type, const String p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT) { - type = p_type; - name = p_name; - hint = p_hint; - hint_string = p_hint_string; - usage = p_usage; + PropertyInfo(Variant::Type p_type, const String p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT) + : type(p_type), + name(p_name), + hint(p_hint), + hint_string(p_hint_string), + usage(p_usage) { } bool operator<(const PropertyInfo &p_info) const { return name < p_info.name; @@ -401,9 +402,9 @@ private: _FORCE_INLINE_ bool operator<(const Target &p_target) const { return (_id == p_target._id) ? (method < p_target.method) : (_id < p_target._id); } - Target(const ObjectID &p_id, const StringName &p_method) { - _id = p_id; - method = p_method; + Target(const ObjectID &p_id, const StringName &p_method) + : _id(p_id), + method(p_method) { } Target() { _id = 0; } }; @@ -443,7 +444,7 @@ private: mutable StringName _class_name; mutable const StringName *_class_ptr; - void _add_user_signal(const String &p_name, const Array &p_pargs = Array()); + void _add_user_signal(const String &p_name, const Array &p_args = Array()); bool _has_user_signal(const StringName &p_name) const; Variant _emit_signal(const Variant **p_args, int p_argcount, Variant::CallError &r_error); Array _get_signal_list() const; @@ -678,8 +679,7 @@ public: virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const; - StringName XL_MESSAGE(const StringName &p_message) const; //translate message (internationalization) - StringName tr(const StringName &p_message) const; //translate message (alternative) + StringName tr(const StringName &p_message) const; // translate message (internationalization) bool _is_queued_for_deletion; // set to true by SceneTree::queue_delete() bool is_queued_for_deletion() const; diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 3bd5ac3f41..9d1fefc925 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -475,9 +475,9 @@ void FileAccess::store_buffer(const uint8_t *p_src, int p_length) { store_8(p_src[i]); } -Vector<uint8_t> FileAccess::get_file_as_array(const String &p_file) { +Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path) { - FileAccess *f = FileAccess::open(p_file, READ); + FileAccess *f = FileAccess::open(p_path, READ); ERR_FAIL_COND_V(!f, Vector<uint8_t>()); Vector<uint8_t> data; data.resize(f->get_len()); diff --git a/core/os/file_access.h b/core/os/file_access.h index 6d3e491167..beed7551fb 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -129,7 +129,7 @@ public: virtual void store_real(real_t p_real); virtual void store_string(const String &p_string); - virtual void store_line(const String &p_string); + virtual void store_line(const String &p_line); virtual void store_pascal_string(const String &p_string); virtual String get_pascal_string(); diff --git a/core/os/input.cpp b/core/os/input.cpp index a90a552d1d..c7b32b939a 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -83,8 +83,8 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("warp_mouse_pos", "to"), &Input::warp_mouse_pos); ClassDB::bind_method(D_METHOD("action_press", "action"), &Input::action_press); ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release); - ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image:Texture", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(Vector2())); - ClassDB::bind_method(D_METHOD("parse_input_event", "event:InputEvent"), &Input::parse_input_event); + ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(Vector2())); + ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event); BIND_CONSTANT(MOUSE_MODE_VISIBLE); BIND_CONSTANT(MOUSE_MODE_HIDDEN); diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 0a07b6b2b7..cb38eb67b6 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -134,12 +134,12 @@ void InputEvent::_bind_methods() { ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text); - ClassDB::bind_method(D_METHOD("action_match", "event:InputEvent"), &InputEvent::action_match); - ClassDB::bind_method(D_METHOD("shortcut_match", "event:InputEvent"), &InputEvent::shortcut_match); + ClassDB::bind_method(D_METHOD("action_match", "event"), &InputEvent::action_match); + ClassDB::bind_method(D_METHOD("shortcut_match", "event"), &InputEvent::shortcut_match); ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type); - ClassDB::bind_method(D_METHOD("xformed_by:InputEvent", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2())); + ClassDB::bind_method(D_METHOD("xformed_by", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2())); ADD_PROPERTY(PropertyInfo(Variant::INT, "device"), "set_device", "get_device"); } @@ -595,6 +595,11 @@ float InputEventJoypadMotion::get_axis_value() const { return axis_value; } +bool InputEventJoypadMotion::is_pressed() const { + + return Math::abs(axis_value) > 0.5f; +} + bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event) const { Ref<InputEventJoypadMotion> jm = p_event; diff --git a/core/os/input_event.h b/core/os/input_event.h index b120d4b840..d1fd7cc90f 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -348,6 +348,7 @@ public: void set_axis_value(float p_value); float get_axis_value() const; + virtual bool is_pressed() const; virtual bool action_match(const Ref<InputEvent> &p_event) const; virtual bool is_action_type() const { return true; } diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 1ed93e3540..1ef26de183 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -324,7 +324,7 @@ enum KeyModifierMask { }; String keycode_get_string(uint32_t p_code); -bool keycode_has_unicode(uint32_t p_unicode); +bool keycode_has_unicode(uint32_t p_keycode); int find_keycode(const String &p_code); int keycode_get_count(); int keycode_get_value_by_index(int p_index); diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 93658c07c2..248f5537c6 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -32,7 +32,7 @@ void MainLoop::_bind_methods() { - ClassDB::bind_method(D_METHOD("input_event", "ev:InputEvent"), &MainLoop::input_event); + ClassDB::bind_method(D_METHOD("input_event", "ev"), &MainLoop::input_event); ClassDB::bind_method(D_METHOD("input_text", "text"), &MainLoop::input_text); ClassDB::bind_method(D_METHOD("init"), &MainLoop::init); ClassDB::bind_method(D_METHOD("iteration", "delta"), &MainLoop::iteration); diff --git a/core/os/os.h b/core/os/os.h index 8e2257a0e4..4d64e4a9f0 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -63,6 +63,8 @@ class OS { void *_stack_bottom; public: + typedef void (*ImeCallback)(void *p_inp, String p_text, Point2 p_selection); + enum RenderThreadMode { RENDER_THREAD_UNSAFE, @@ -183,6 +185,7 @@ public: virtual bool get_borderless_window() { return 0; } virtual void set_ime_position(const Point2 &p_pos) {} + virtual void set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp) {} virtual Error open_dynamic_library(const String p_path, void *&p_library_handle) { return ERR_UNAVAILABLE; } virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; } diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp index 0565d0d3f5..eb4aeb758a 100644 --- a/core/packed_data_container.cpp +++ b/core/packed_data_container.cpp @@ -368,7 +368,7 @@ void PackedDataContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("_iter_init"), &PackedDataContainer::_iter_init); ClassDB::bind_method(D_METHOD("_iter_get"), &PackedDataContainer::_iter_get); ClassDB::bind_method(D_METHOD("_iter_next"), &PackedDataContainer::_iter_next); - ClassDB::bind_method(D_METHOD("pack:Error", "value"), &PackedDataContainer::pack); + ClassDB::bind_method(D_METHOD("pack", "value"), &PackedDataContainer::pack); ClassDB::bind_method(D_METHOD("size"), &PackedDataContainer::size); ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "__data__"), "_set_data", "_get_data"); diff --git a/core/pair.h b/core/pair.h index 761caf7791..d517339ddf 100644 --- a/core/pair.h +++ b/core/pair.h @@ -37,9 +37,9 @@ struct Pair { S second; Pair() {} - Pair(F p_first, S p_second) { - first = p_first; - second = p_second; + Pair(F p_first, const S &p_second) + : first(p_first), + second(p_second) { } }; diff --git a/core/project_settings.cpp b/core/project_settings.cpp index f6e0d2e991..4a1b35ea4a 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -900,7 +900,7 @@ void ProjectSettings::_bind_methods() { ClassDB::bind_method(D_METHOD("get_singleton", "name"), &ProjectSettings::get_singleton_object); ClassDB::bind_method(D_METHOD("load_resource_pack", "pack"), &ProjectSettings::_load_resource_pack); ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &ProjectSettings::property_can_revert); - ClassDB::bind_method(D_METHOD("property_get_revert:Variant", "name"), &ProjectSettings::property_get_revert); + ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &ProjectSettings::property_get_revert); ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd); } diff --git a/core/project_settings.h b/core/project_settings.h index c58ac3ca49..cee3b3b5f3 100644 --- a/core/project_settings.h +++ b/core/project_settings.h @@ -48,9 +48,9 @@ public: struct Singleton { StringName name; Object *ptr; - Singleton(const StringName &p_name = StringName(), Object *p_ptr = NULL) { - name = p_name; - ptr = p_ptr; + Singleton(const StringName &p_name = StringName(), Object *p_ptr = NULL) + : name(p_name), + ptr(p_ptr) { } }; enum { @@ -66,18 +66,18 @@ protected: Variant initial; bool hide_from_editor; bool overrided; - VariantContainer() { - order = 0; - hide_from_editor = false; - persist = false; - overrided = false; + VariantContainer() + : order(0), + persist(false), + hide_from_editor(false), + overrided(false) { } - VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false) { - variant = p_variant; - order = p_order; - hide_from_editor = false; - persist = p_persist; - overrided = false; + VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false) + : order(p_order), + persist(p_persist), + variant(p_variant), + hide_from_editor(false), + overrided(false) { } }; @@ -158,7 +158,7 @@ public: bool is_using_datapack() const; - void set_registering_order(bool p_registering); + void set_registering_order(bool p_enable); ProjectSettings(); ~ProjectSettings(); diff --git a/core/reference.cpp b/core/reference.cpp index 066dc8059e..e9629ee7c0 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -122,7 +122,7 @@ WeakRef::WeakRef() { void WeakRef::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_ref:Object"), &WeakRef::get_ref); + ClassDB::bind_method(D_METHOD("get_ref"), &WeakRef::get_ref); } #if 0 diff --git a/core/reference.h b/core/reference.h index 90f2791f4b..69250a4701 100644 --- a/core/reference.h +++ b/core/reference.h @@ -374,5 +374,28 @@ struct PtrToArg<const RefPtr &> { } }; -#endif +#endif // PTRCALL_ENABLED + +#ifdef DEBUG_METHODS_ENABLED + +template <class T> +struct GetTypeInfo<Ref<T> > { + enum { VARIANT_TYPE = Variant::OBJECT }; + + static inline StringName get_class_name() { + return T::get_class_static(); + } +}; + +template <class T> +struct GetTypeInfo<const Ref<T> &> { + enum { VARIANT_TYPE = Variant::OBJECT }; + + static inline StringName get_class_name() { + return T::get_class_static(); + } +}; + +#endif // DEBUG_METHODS_ENABLED + #endif // REFERENCE_H diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 43f781af55..fca9afbf5e 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -39,6 +39,7 @@ #include "input_map.h" #include "io/config_file.h" #include "io/http_client.h" +#include "io/marshalls.h" #include "io/packet_peer.h" #include "io/packet_peer_udp.h" #include "io/pck_packer.h" @@ -56,7 +57,6 @@ #include "project_settings.h" #include "translation.h" #include "undo_redo.h" - static ResourceFormatSaverBinary *resource_saver_binary = NULL; static ResourceFormatLoaderBinary *resource_loader_binary = NULL; static ResourceFormatImporter *resource_format_importer = NULL; @@ -157,6 +157,7 @@ void register_core_types() { ClassDB::register_class<PackedDataContainer>(); ClassDB::register_virtual_class<PackedDataContainerRef>(); ClassDB::register_class<AStar>(); + ClassDB::register_class<EncodedObjectAsID>(); ip = IP::create(); diff --git a/core/resource.cpp b/core/resource.cpp index 9bce343cba..a0b0fd24e1 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -337,10 +337,10 @@ void Resource::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rid"), &Resource::get_rid); ClassDB::bind_method(D_METHOD("set_local_to_scene", "enable"), &Resource::set_local_to_scene); ClassDB::bind_method(D_METHOD("is_local_to_scene"), &Resource::is_local_to_scene); - ClassDB::bind_method(D_METHOD("get_local_scene:Node"), &Resource::get_local_scene); + ClassDB::bind_method(D_METHOD("get_local_scene"), &Resource::get_local_scene); ClassDB::bind_method(D_METHOD("setup_local_to_scene"), &Resource::setup_local_to_scene); - ClassDB::bind_method(D_METHOD("duplicate:Resource", "subresources"), &Resource::duplicate, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("duplicate", "subresources"), &Resource::duplicate, DEFVAL(false)); ADD_SIGNAL(MethodInfo("changed")); ADD_GROUP("Resource", "resource_"); ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "resource_local_to_scene"), "set_local_to_scene", "is_local_to_scene"); diff --git a/core/resource.h b/core/resource.h index 5a4e45da36..bbf233d53e 100644 --- a/core/resource.h +++ b/core/resource.h @@ -107,7 +107,7 @@ public: int get_subindex() const; virtual Ref<Resource> duplicate(bool p_subresources = false) const; - Ref<Resource> duplicate_for_local_scene(Node *p_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache); + Ref<Resource> duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache); void set_local_to_scene(bool p_enable); bool is_local_to_scene() const; diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index 6f12338f66..9e4f4380c9 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -30,10 +30,10 @@ #include "script_debugger_remote.h" #include "io/ip.h" +#include "io/marshalls.h" #include "os/input.h" #include "os/os.h" #include "project_settings.h" - void ScriptDebuggerRemote::_send_video_memory() { List<ResourceUsage> usage; @@ -120,6 +120,18 @@ static ObjectID safe_get_instance_id(const Variant &p_v) { } } +void ScriptDebuggerRemote::_put_variable(const String &p_name, const Variant &p_variable) { + + packet_peer_stream->put_var(p_name); + int len = 0; + Error err = encode_variant(p_variable, NULL, len); + if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size + packet_peer_stream->put_var(Variant()); + } else { + packet_peer_stream->put_var(p_variable); + } +} + void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) { //this function is called when there is a debugger break (bug on script) @@ -130,8 +142,6 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) ERR_FAIL(); } - OS::get_singleton()->enable_for_stealing_focus(ProjectSettings::get_singleton()->get("editor_pid")); - packet_peer_stream->put_var("debug_enter"); packet_peer_stream->put_var(2); packet_peer_stream->put_var(p_can_continue); @@ -210,14 +220,7 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) while (E) { - if (F->get().get_type() == Variant::OBJECT) { - packet_peer_stream->put_var("*" + E->get()); - String pretty_print = F->get().operator String(); - packet_peer_stream->put_var(pretty_print.ascii().get_data()); - } else { - packet_peer_stream->put_var(E->get()); - packet_peer_stream->put_var(F->get()); - } + _put_variable(E->get(), F->get()); E = E->next(); F = F->next(); @@ -231,15 +234,7 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) List<Variant>::Element *F = local_vals.front(); while (E) { - - if (F->get().get_type() == Variant::OBJECT) { - packet_peer_stream->put_var("*" + E->get()); - String pretty_print = F->get().operator String(); - packet_peer_stream->put_var(pretty_print.ascii().get_data()); - } else { - packet_peer_stream->put_var(E->get()); - packet_peer_stream->put_var(F->get()); - } + _put_variable(E->get(), F->get()); E = E->next(); F = F->next(); @@ -429,9 +424,9 @@ void ScriptDebuggerRemote::_err_handler(void *ud, const char *p_func, const char sdr->mutex->unlock(); } -bool ScriptDebuggerRemote::_parse_live_edit(const Array &cmd) { +bool ScriptDebuggerRemote::_parse_live_edit(const Array &p_command) { - String cmdstr = cmd[0]; + String cmdstr = p_command[0]; if (!live_edit_funcs || !cmdstr.begins_with("live_")) return false; @@ -441,7 +436,7 @@ bool ScriptDebuggerRemote::_parse_live_edit(const Array &cmd) { if (!live_edit_funcs->root_func) return true; //print_line("root: "+Variant(cmd).get_construct_string()); - live_edit_funcs->root_func(live_edit_funcs->udata, cmd[1], cmd[2]); + live_edit_funcs->root_func(live_edit_funcs->udata, p_command[1], p_command[2]); } else if (cmdstr == "live_node_path") { @@ -449,75 +444,75 @@ bool ScriptDebuggerRemote::_parse_live_edit(const Array &cmd) { return true; //print_line("path: "+Variant(cmd).get_construct_string()); - live_edit_funcs->node_path_func(live_edit_funcs->udata, cmd[1], cmd[2]); + live_edit_funcs->node_path_func(live_edit_funcs->udata, p_command[1], p_command[2]); } else if (cmdstr == "live_res_path") { if (!live_edit_funcs->res_path_func) return true; - live_edit_funcs->res_path_func(live_edit_funcs->udata, cmd[1], cmd[2]); + live_edit_funcs->res_path_func(live_edit_funcs->udata, p_command[1], p_command[2]); } else if (cmdstr == "live_node_prop_res") { if (!live_edit_funcs->node_set_res_func) return true; - live_edit_funcs->node_set_res_func(live_edit_funcs->udata, cmd[1], cmd[2], cmd[3]); + live_edit_funcs->node_set_res_func(live_edit_funcs->udata, p_command[1], p_command[2], p_command[3]); } else if (cmdstr == "live_node_prop") { if (!live_edit_funcs->node_set_func) return true; - live_edit_funcs->node_set_func(live_edit_funcs->udata, cmd[1], cmd[2], cmd[3]); + live_edit_funcs->node_set_func(live_edit_funcs->udata, p_command[1], p_command[2], p_command[3]); } else if (cmdstr == "live_res_prop_res") { if (!live_edit_funcs->res_set_res_func) return true; - live_edit_funcs->res_set_res_func(live_edit_funcs->udata, cmd[1], cmd[2], cmd[3]); + live_edit_funcs->res_set_res_func(live_edit_funcs->udata, p_command[1], p_command[2], p_command[3]); } else if (cmdstr == "live_res_prop") { if (!live_edit_funcs->res_set_func) return true; - live_edit_funcs->res_set_func(live_edit_funcs->udata, cmd[1], cmd[2], cmd[3]); + live_edit_funcs->res_set_func(live_edit_funcs->udata, p_command[1], p_command[2], p_command[3]); } else if (cmdstr == "live_node_call") { if (!live_edit_funcs->node_call_func) return true; - live_edit_funcs->node_call_func(live_edit_funcs->udata, cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7]); + live_edit_funcs->node_call_func(live_edit_funcs->udata, p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7]); } else if (cmdstr == "live_res_call") { if (!live_edit_funcs->res_call_func) return true; - live_edit_funcs->res_call_func(live_edit_funcs->udata, cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7]); + live_edit_funcs->res_call_func(live_edit_funcs->udata, p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7]); } else if (cmdstr == "live_create_node") { - live_edit_funcs->tree_create_node_func(live_edit_funcs->udata, cmd[1], cmd[2], cmd[3]); + live_edit_funcs->tree_create_node_func(live_edit_funcs->udata, p_command[1], p_command[2], p_command[3]); } else if (cmdstr == "live_instance_node") { - live_edit_funcs->tree_instance_node_func(live_edit_funcs->udata, cmd[1], cmd[2], cmd[3]); + live_edit_funcs->tree_instance_node_func(live_edit_funcs->udata, p_command[1], p_command[2], p_command[3]); } else if (cmdstr == "live_remove_node") { - live_edit_funcs->tree_remove_node_func(live_edit_funcs->udata, cmd[1]); + live_edit_funcs->tree_remove_node_func(live_edit_funcs->udata, p_command[1]); } else if (cmdstr == "live_remove_and_keep_node") { - live_edit_funcs->tree_remove_and_keep_node_func(live_edit_funcs->udata, cmd[1], cmd[2]); + live_edit_funcs->tree_remove_and_keep_node_func(live_edit_funcs->udata, p_command[1], p_command[2]); } else if (cmdstr == "live_restore_node") { - live_edit_funcs->tree_restore_node_func(live_edit_funcs->udata, cmd[1], cmd[2], cmd[3]); + live_edit_funcs->tree_restore_node_func(live_edit_funcs->udata, p_command[1], p_command[2], p_command[3]); } else if (cmdstr == "live_duplicate_node") { - live_edit_funcs->tree_duplicate_node_func(live_edit_funcs->udata, cmd[1], cmd[2]); + live_edit_funcs->tree_duplicate_node_func(live_edit_funcs->udata, p_command[1], p_command[2]); } else if (cmdstr == "live_reparent_node") { - live_edit_funcs->tree_reparent_node_func(live_edit_funcs->udata, cmd[1], cmd[2], cmd[3], cmd[4]); + live_edit_funcs->tree_reparent_node_func(live_edit_funcs->udata, p_command[1], p_command[2], p_command[3], p_command[4]); } else { @@ -566,30 +561,19 @@ void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) { } Variant var = obj->get(E->get().name); + packet_peer_stream->put_var(E->get().type); + //only send information that can be sent.. - if (E->get().type == Variant::OBJECT || var.get_type() == Variant::OBJECT) { - - ObjectID id2; - Object *obj = var; - if (obj) { - id2 = obj->get_instance_id(); - } else { - id2 = 0; - } + int len = 0; //test how big is this to encode + encode_variant(var, NULL, len); - packet_peer_stream->put_var(Variant::INT); //hint string - packet_peer_stream->put_var(PROPERTY_HINT_OBJECT_ID); //hint - packet_peer_stream->put_var(E->get().hint_string); //hint string - packet_peer_stream->put_var(id2); //value + if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size + packet_peer_stream->put_var(PROPERTY_HINT_OBJECT_TOO_BIG); + packet_peer_stream->put_var(""); + packet_peer_stream->put_var(Variant()); } else { - packet_peer_stream->put_var(E->get().type); packet_peer_stream->put_var(E->get().hint); packet_peer_stream->put_var(E->get().hint_string); - //only send information that can be sent.. - - if (var.get_type() >= Variant::DICTIONARY) { - var = Array(); //send none for now, may be to big - } packet_peer_stream->put_var(var); } } @@ -940,29 +924,32 @@ void ScriptDebuggerRemote::profiling_set_frame_times(float p_frame_time, float p ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_func = NULL; -ScriptDebuggerRemote::ScriptDebuggerRemote() { +ScriptDebuggerRemote::ScriptDebuggerRemote() + : profiling(false), + max_frame_functions(16), + skip_profile_frame(false), + reload_all_scripts(false), + tcp_client(StreamPeerTCP::create_ref()), + packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))), + last_perf_time(0), + performance(ProjectSettings::get_singleton()->get_singleton_object("Performance")), + requested_quit(false), + mutex(Mutex::create()), + max_cps(GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second")), + char_count(0), + last_msec(0), + msec_count(0), + locking(false), + poll_every(0), + request_scene_tree(NULL), + live_edit_funcs(NULL) { - tcp_client = StreamPeerTCP::create_ref(); - packet_peer_stream = Ref<PacketPeerStream>(memnew(PacketPeerStream)); packet_peer_stream->set_stream_peer(tcp_client); packet_peer_stream->set_output_buffer_max_size(1024 * 1024 * 8); //8mb should be way more than enough - mutex = Mutex::create(); - locking = false; phl.printfunc = _print_handler; phl.userdata = this; add_print_handler(&phl); - requested_quit = false; - performance = ProjectSettings::get_singleton()->get_singleton_object("Performance"); - last_perf_time = 0; - poll_every = 0; - request_scene_tree = NULL; - live_edit_funcs = NULL; - max_cps = GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second"); - char_count = 0; - msec_count = 0; - last_msec = 0; - skip_profile_frame = false; eh.errfunc = _err_handler; eh.userdata = this; @@ -970,9 +957,6 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() { profile_info.resize(CLAMP(int(ProjectSettings::get_singleton()->get("debug/settings/profiler/max_functions")), 128, 65535)); profile_info_ptrs.resize(profile_info.size()); - profiling = false; - max_frame_functions = 16; - reload_all_scripts = false; } ScriptDebuggerRemote::~ScriptDebuggerRemote() { diff --git a/core/script_debugger_remote.h b/core/script_debugger_remote.h index 924e3774a2..cf75c0eb4a 100644 --- a/core/script_debugger_remote.h +++ b/core/script_debugger_remote.h @@ -126,6 +126,8 @@ class ScriptDebuggerRemote : public ScriptDebugger { Vector<FrameData> profile_frame_data; + void _put_variable(const String &p_name, const Variant &p_variable); + public: struct ResourceUsage { diff --git a/core/script_language.cpp b/core/script_language.cpp index bb99e0abae..4664049145 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -384,11 +384,10 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c //change notify } -PlaceHolderScriptInstance::PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner) { - - language = p_language; - script = p_script; - owner = p_owner; +PlaceHolderScriptInstance::PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner) + : owner(p_owner), + language(p_language), + script(p_script) { } PlaceHolderScriptInstance::~PlaceHolderScriptInstance() { diff --git a/core/translation.cpp b/core/translation.cpp index 50694e4a2d..c38d5d8b4d 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -923,9 +923,8 @@ void Translation::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "locale"), "set_locale", "get_locale"); } -Translation::Translation() { - - locale = "en"; +Translation::Translation() + : locale("en") { } /////////////////////////////////////////////// @@ -1125,8 +1124,8 @@ void TranslationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("translate", "message"), &TranslationServer::translate); - ClassDB::bind_method(D_METHOD("add_translation", "translation:Translation"), &TranslationServer::add_translation); - ClassDB::bind_method(D_METHOD("remove_translation", "translation:Translation"), &TranslationServer::remove_translation); + ClassDB::bind_method(D_METHOD("add_translation", "translation"), &TranslationServer::add_translation); + ClassDB::bind_method(D_METHOD("remove_translation", "translation"), &TranslationServer::remove_translation); ClassDB::bind_method(D_METHOD("clear"), &TranslationServer::clear); } @@ -1144,9 +1143,8 @@ void TranslationServer::load_translations() { } } -TranslationServer::TranslationServer() { - +TranslationServer::TranslationServer() + : locale("en"), + enabled(true) { singleton = this; - locale = "en"; - enabled = true; } diff --git a/core/type_info.h b/core/type_info.h new file mode 100644 index 0000000000..10912fd074 --- /dev/null +++ b/core/type_info.h @@ -0,0 +1,203 @@ +#ifndef GET_TYPE_INFO_H +#define GET_TYPE_INFO_H + +template <bool C, typename T = void> +struct EnableIf { + + typedef T type; +}; + +template <typename T> +struct EnableIf<false, T> { +}; + +template <typename, typename> +struct TypesAreSame { + + static bool const value = false; +}; + +template <typename A> +struct TypesAreSame<A, A> { + + static bool const value = true; +}; + +template <typename B, typename D> +struct TypeInherits { + + static D *get_d(); + + static char (&test(B *))[1]; + static char (&test(...))[2]; + + static bool const value = sizeof(test(get_d())) == sizeof(char) && + !TypesAreSame<B volatile const, void volatile const>::value; +}; + +template <class T, typename = void> +struct GetTypeInfo { + enum { VARIANT_TYPE = Variant::NIL }; + + static inline StringName get_class_name() { + ERR_PRINT("Fallback type info. Bug!"); + return ""; // Not "Nil", this is an error + } +}; + +#define MAKE_TYPE_INFO(m_type, m_var_type) \ + template <> \ + struct GetTypeInfo<m_type> { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; \ + template <> \ + struct GetTypeInfo<const m_type &> { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; + +MAKE_TYPE_INFO(bool, Variant::BOOL) +MAKE_TYPE_INFO(uint8_t, Variant::INT) +MAKE_TYPE_INFO(int8_t, Variant::INT) +MAKE_TYPE_INFO(uint16_t, Variant::INT) +MAKE_TYPE_INFO(int16_t, Variant::INT) +MAKE_TYPE_INFO(uint32_t, Variant::INT) +MAKE_TYPE_INFO(int32_t, Variant::INT) +MAKE_TYPE_INFO(int64_t, Variant::INT) +MAKE_TYPE_INFO(uint64_t, Variant::INT) +MAKE_TYPE_INFO(float, Variant::REAL) +MAKE_TYPE_INFO(double, Variant::REAL) + +MAKE_TYPE_INFO(String, Variant::STRING) +MAKE_TYPE_INFO(Vector2, Variant::VECTOR2) +MAKE_TYPE_INFO(Rect2, Variant::RECT2) +MAKE_TYPE_INFO(Vector3, Variant::VECTOR3) +MAKE_TYPE_INFO(Transform2D, Variant::TRANSFORM2D) +MAKE_TYPE_INFO(Plane, Variant::PLANE) +MAKE_TYPE_INFO(Quat, Variant::QUAT) +MAKE_TYPE_INFO(Rect3, Variant::RECT3) +MAKE_TYPE_INFO(Basis, Variant::BASIS) +MAKE_TYPE_INFO(Transform, Variant::TRANSFORM) +MAKE_TYPE_INFO(Color, Variant::COLOR) +MAKE_TYPE_INFO(NodePath, Variant::NODE_PATH) +MAKE_TYPE_INFO(RID, Variant::_RID) +MAKE_TYPE_INFO(Dictionary, Variant::DICTIONARY) +MAKE_TYPE_INFO(Array, Variant::ARRAY) +MAKE_TYPE_INFO(PoolByteArray, Variant::POOL_BYTE_ARRAY) +MAKE_TYPE_INFO(PoolIntArray, Variant::POOL_INT_ARRAY) +MAKE_TYPE_INFO(PoolRealArray, Variant::POOL_REAL_ARRAY) +MAKE_TYPE_INFO(PoolStringArray, Variant::POOL_STRING_ARRAY) +MAKE_TYPE_INFO(PoolVector2Array, Variant::POOL_VECTOR2_ARRAY) +MAKE_TYPE_INFO(PoolVector3Array, Variant::POOL_VECTOR3_ARRAY) +MAKE_TYPE_INFO(PoolColorArray, Variant::POOL_COLOR_ARRAY) + +MAKE_TYPE_INFO(StringName, Variant::STRING) +MAKE_TYPE_INFO(IP_Address, Variant::STRING) + +class BSP_Tree; +MAKE_TYPE_INFO(BSP_Tree, Variant::DICTIONARY) + +#define MAKE_TYPE_INFO_WITH_NAME(m_type, m_var_type, m_class_name) \ + template <> \ + struct GetTypeInfo<m_type> { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return m_class_name; \ + } \ + }; \ + template <> \ + struct GetTypeInfo<const m_type &> { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return m_class_name; \ + } \ + }; + +MAKE_TYPE_INFO_WITH_NAME(RefPtr, Variant::OBJECT, "Reference") +MAKE_TYPE_INFO_WITH_NAME(Variant, Variant::NIL, "Variant") + +#define MAKE_TEMPLATE_TYPE_INFO(m_template, m_type, m_var_type) \ + template <> \ + struct GetTypeInfo<m_template<m_type> > { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; \ + template <> \ + struct GetTypeInfo<const m_template<m_type> &> { \ + enum { VARIANT_TYPE = m_var_type }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; + +MAKE_TEMPLATE_TYPE_INFO(Vector, uint8_t, Variant::POOL_BYTE_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, int, Variant::POOL_INT_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, float, Variant::POOL_REAL_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, String, Variant::POOL_STRING_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, Vector2, Variant::POOL_VECTOR2_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, Vector3, Variant::POOL_VECTOR3_ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, Color, Variant::POOL_COLOR_ARRAY) + +MAKE_TEMPLATE_TYPE_INFO(Vector, Variant, Variant::ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, RID, Variant::ARRAY) +MAKE_TEMPLATE_TYPE_INFO(Vector, Plane, Variant::ARRAY) + +MAKE_TEMPLATE_TYPE_INFO(PoolVector, Plane, Variant::ARRAY) +MAKE_TEMPLATE_TYPE_INFO(PoolVector, Face3, Variant::POOL_VECTOR3_ARRAY) + +#define MAKE_ENUM_TYPE_INFO(m_enum) \ + template <> \ + struct GetTypeInfo<m_enum> { \ + enum { VARIANT_TYPE = Variant::INT }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; \ + template <> \ + struct GetTypeInfo<m_enum const> { \ + enum { VARIANT_TYPE = Variant::INT }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; \ + template <> \ + struct GetTypeInfo<m_enum &> { \ + enum { VARIANT_TYPE = Variant::INT }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; \ + template <> \ + struct GetTypeInfo<const m_enum &> { \ + enum { VARIANT_TYPE = Variant::INT }; \ + static inline StringName get_class_name() { \ + return Variant::get_type_name((Variant::Type)VARIANT_TYPE); \ + } \ + }; + +template <typename T> +struct GetTypeInfo<T *, typename EnableIf<TypeInherits<Object, T>::value>::type> { + enum { VARIANT_TYPE = Variant::OBJECT }; + + static inline StringName get_class_name() { + return T::get_class_static(); + } +}; + +template <typename T> +struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>::type> { + enum { VARIANT_TYPE = Variant::OBJECT }; + + static inline StringName get_class_name() { + return T::get_class_static(); + } +}; + +#endif // GET_TYPE_INFO_H diff --git a/core/typedefs.h b/core/typedefs.h index 40d9ea37b5..34a1a93a3b 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -162,9 +162,9 @@ inline void __swap_tmpl(T &x, T &y) { #define _add_overflow __builtin_add_overflow #endif -/** Function to find the nearest (bigger) power of 2 to an integer */ +/** Function to find the next power of 2 to an integer */ -static _FORCE_INLINE_ unsigned int nearest_power_of_2(unsigned int x) { +static _FORCE_INLINE_ unsigned int next_power_of_2(unsigned int x) { --x; x |= x >> 1; @@ -176,6 +176,23 @@ static _FORCE_INLINE_ unsigned int nearest_power_of_2(unsigned int x) { return ++x; } +static _FORCE_INLINE_ unsigned int previous_power_of_2(unsigned int x) { + + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + return x - (x >> 1); +} + +static _FORCE_INLINE_ unsigned int closest_power_of_2(unsigned int x) { + + unsigned int nx = next_power_of_2(x); + unsigned int px = previous_power_of_2(x); + return (nx - x) > (x - px) ? px : nx; +} + // We need this definition inside the function below. static inline int get_shift_from_power_of_2(unsigned int p_pixel); diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index 637fcd91d4..19b9f161b7 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -496,8 +496,8 @@ void UndoRedo::_bind_methods() { ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "add_undo_method", &UndoRedo::_add_undo_method, mi); } - ClassDB::bind_method(D_METHOD("add_do_property", "object", "property", "value:Variant"), &UndoRedo::add_do_property); - ClassDB::bind_method(D_METHOD("add_undo_property", "object", "property", "value:Variant"), &UndoRedo::add_undo_property); + ClassDB::bind_method(D_METHOD("add_do_property", "object", "property", "value"), &UndoRedo::add_do_property); + ClassDB::bind_method(D_METHOD("add_undo_property", "object", "property", "value"), &UndoRedo::add_undo_property); ClassDB::bind_method(D_METHOD("add_do_reference", "object"), &UndoRedo::add_do_reference); ClassDB::bind_method(D_METHOD("add_undo_reference", "object"), &UndoRedo::add_undo_reference); ClassDB::bind_method(D_METHOD("clear_history"), &UndoRedo::clear_history); diff --git a/core/ustring.cpp b/core/ustring.cpp index ab4528e495..0521966943 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -279,16 +279,16 @@ void String::operator=(const CharType *p_str) { copy_from(p_str); } -bool String::operator==(const StrRange &p_range) const { +bool String::operator==(const StrRange &p_str_range) const { - int len = p_range.len; + int len = p_str_range.len; if (length() != len) return false; if (empty()) return true; - const CharType *c_str = p_range.c_str; + const CharType *c_str = p_str_range.c_str; const CharType *dst = &operator[](0); /* Compare char by char */ diff --git a/core/ustring.h b/core/ustring.h index d00bfa59b5..1c61e12e85 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -78,7 +78,7 @@ public: //String operator+(CharType p_char) const; String &operator+=(const String &); - String &operator+=(CharType p_str); + String &operator+=(CharType p_char); String &operator+=(const char *p_str); String &operator+=(const CharType *p_str); @@ -156,7 +156,7 @@ public: int get_slice_count(String p_splitter) const; String get_slice(String p_splitter, int p_slice) const; - String get_slicec(CharType splitter, int p_slice) const; + String get_slicec(CharType p_splitter, int p_slice) const; Vector<String> split(const String &p_splitter, bool p_allow_empty = true) const; Vector<String> split_spaces() const; @@ -186,8 +186,8 @@ public: bool parse_utf8(const char *p_utf8, int p_len = -1); //return true on error static String utf8(const char *p_utf8, int p_len = -1); - static uint32_t hash(const CharType *p_str, int p_len); /* hash the string */ - static uint32_t hash(const CharType *p_str); /* hash the string */ + static uint32_t hash(const CharType *p_cstr, int p_len); /* hash the string */ + static uint32_t hash(const CharType *p_cstr); /* hash the string */ static uint32_t hash(const char *p_cstr, int p_len); /* hash the string */ static uint32_t hash(const char *p_cstr); /* hash the string */ uint32_t hash() const; /* hash the string */ diff --git a/core/variant.h b/core/variant.h index 95782d9619..40de1a9bce 100644 --- a/core/variant.h +++ b/core/variant.h @@ -49,7 +49,6 @@ #include "rect3.h" #include "ref_ptr.h" #include "rid.h" -#include "simple_type.h" #include "transform.h" #include "ustring.h" #include "vector3.h" @@ -154,15 +153,6 @@ public: static bool can_convert(Type p_type_from, Type p_type_to); static bool can_convert_strict(Type p_type_from, Type p_type_to); - template <class T> - static Type get_type_for() { - - GetSimpleType<T> t; - Variant v(t.type); - Type r = v.get_type(); - return r; - } - bool is_ref() const; _FORCE_INLINE_ bool is_num() const { return type == INT || type == REAL; }; _FORCE_INLINE_ bool is_array() const { return type >= ARRAY; }; diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 4a806aec6c..59d31d2586 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -130,9 +130,9 @@ struct _VariantCall { StringName name; Variant::Type type; Arg() { type = Variant::NIL; } - Arg(Variant::Type p_type, const StringName &p_name) { - name = p_name; - type = p_type; + Arg(Variant::Type p_type, const StringName &p_name) + : name(p_name), + type(p_type) { } }; @@ -747,6 +747,7 @@ struct _VariantCall { VCALL_PTR1R(Transform, translated); VCALL_PTR0R(Transform, orthonormalized); VCALL_PTR2R(Transform, looking_at); + VCALL_PTR2R(Transform, interpolate_with); static void _call_Transform_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) { @@ -1691,7 +1692,7 @@ void register_variant_methods() { ADDFUNC1(TRANSFORM2D, TRANSFORM2D, Transform2D, xform_inv, NIL, "v", varray()); ADDFUNC1(TRANSFORM2D, TRANSFORM2D, Transform2D, basis_xform, NIL, "v", varray()); ADDFUNC1(TRANSFORM2D, TRANSFORM2D, Transform2D, basis_xform_inv, NIL, "v", varray()); - ADDFUNC2(TRANSFORM2D, TRANSFORM2D, Transform2D, interpolate_with, TRANSFORM2D, "m", REAL, "c", varray()); + ADDFUNC2(TRANSFORM2D, TRANSFORM2D, Transform2D, interpolate_with, TRANSFORM2D, "transform", REAL, "weight", varray()); ADDFUNC0(BASIS, BASIS, Basis, inverse, varray()); ADDFUNC0(BASIS, BASIS, Basis, transposed, varray()); @@ -1718,6 +1719,7 @@ void register_variant_methods() { ADDFUNC1(TRANSFORM, TRANSFORM, Transform, scaled, VECTOR3, "scale", varray()); ADDFUNC1(TRANSFORM, TRANSFORM, Transform, translated, VECTOR3, "ofs", varray()); ADDFUNC2(TRANSFORM, TRANSFORM, Transform, looking_at, VECTOR3, "target", VECTOR3, "up", varray()); + ADDFUNC2(TRANSFORM, TRANSFORM, Transform, interpolate_with, TRANSFORM, "transform", REAL, "weight", varray()); ADDFUNC1(TRANSFORM, NIL, Transform, xform, NIL, "v", varray()); ADDFUNC1(TRANSFORM, NIL, Transform, xform_inv, NIL, "v", varray()); diff --git a/core/variant_construct_string.cpp b/core/variant_construct_string.cpp index 45fe367ce6..fa8a393d08 100644 --- a/core/variant_construct_string.cpp +++ b/core/variant_construct_string.cpp @@ -66,7 +66,7 @@ class VariantConstruct { static Error _get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str); static Error _parse_value(Variant &value, Token &token, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str, Variant::ObjectConstruct *p_construct, void *p_ud); static Error _parse_array(Array &array, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str, Variant::ObjectConstruct *p_construct, void *p_ud); - static Error _parse_dict(Dictionary &object, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str, Variant::ObjectConstruct *p_construct, void *p_ud); + static Error _parse_dict(Dictionary &dict, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str, Variant::ObjectConstruct *p_construct, void *p_ud); public: static Error parse(const String &p_string, Variant &r_ret, String &r_err_str, int &r_err_line, Variant::ObjectConstruct *p_construct, void *p_ud); @@ -85,15 +85,15 @@ const char *VariantConstruct::tk_name[TK_MAX] = { "EOF", }; -Error VariantConstruct::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_token, int &line, String &r_err_str) { +Error VariantConstruct::_get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) { while (true) { - switch (p_str[idx]) { + switch (p_str[index]) { case '\n': { line++; - idx++; + index++; break; }; case 0: { @@ -103,54 +103,54 @@ Error VariantConstruct::_get_token(const CharType *p_str, int &idx, int p_len, T case '{': { r_token.type = TK_CURLY_BRACKET_OPEN; - idx++; + index++; return OK; }; case '}': { r_token.type = TK_CURLY_BRACKET_CLOSE; - idx++; + index++; return OK; }; case '[': { r_token.type = TK_BRACKET_OPEN; - idx++; + index++; return OK; }; case ']': { r_token.type = TK_BRACKET_CLOSE; - idx++; + index++; return OK; }; case ':': { r_token.type = TK_COLON; - idx++; + index++; return OK; }; case ',': { r_token.type = TK_COMMA; - idx++; + index++; return OK; }; case '"': { - idx++; + index++; String str; while (true) { - if (p_str[idx] == 0) { + if (p_str[index] == 0) { r_err_str = "Unterminated String"; return ERR_PARSE_ERROR; - } else if (p_str[idx] == '"') { - idx++; + } else if (p_str[index] == '"') { + index++; break; - } else if (p_str[idx] == '\\') { + } else if (p_str[index] == '\\') { //escaped characters... - idx++; - CharType next = p_str[idx]; + index++; + CharType next = p_str[index]; if (next == 0) { r_err_str = "Unterminated String"; return ERR_PARSE_ERROR; @@ -171,7 +171,7 @@ Error VariantConstruct::_get_token(const CharType *p_str, int &idx, int p_len, T //hexnumbarh - oct is deprecated for (int j = 0; j < 4; j++) { - CharType c = p_str[idx + j + 1]; + CharType c = p_str[index + j + 1]; if (c == 0) { r_err_str = "Unterminated String"; return ERR_PARSE_ERROR; @@ -198,7 +198,7 @@ Error VariantConstruct::_get_token(const CharType *p_str, int &idx, int p_len, T res <<= 4; res |= v; } - idx += 4; //will add at the end anyway + index += 4; //will add at the end anyway } break; default: { @@ -211,11 +211,11 @@ Error VariantConstruct::_get_token(const CharType *p_str, int &idx, int p_len, T str += res; } else { - if (p_str[idx] == '\n') + if (p_str[index] == '\n') line++; - str += p_str[idx]; + str += p_str[index]; } - idx++; + index++; } r_token.type = TK_STRING; @@ -225,28 +225,28 @@ Error VariantConstruct::_get_token(const CharType *p_str, int &idx, int p_len, T } break; default: { - if (p_str[idx] <= 32) { - idx++; + if (p_str[index] <= 32) { + index++; break; } - if (p_str[idx] == '-' || (p_str[idx] >= '0' && p_str[idx] <= '9')) { + if (p_str[index] == '-' || (p_str[index] >= '0' && p_str[index] <= '9')) { //a number const CharType *rptr; - double number = String::to_double(&p_str[idx], &rptr); - idx += (rptr - &p_str[idx]); + double number = String::to_double(&p_str[index], &rptr); + index += (rptr - &p_str[index]); r_token.type = TK_NUMBER; r_token.value = number; return OK; - } else if ((p_str[idx] >= 'A' && p_str[idx] <= 'Z') || (p_str[idx] >= 'a' && p_str[idx] <= 'z')) { + } else if ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) { String id; - while ((p_str[idx] >= 'A' && p_str[idx] <= 'Z') || (p_str[idx] >= 'a' && p_str[idx] <= 'z')) { + while ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) { - id += p_str[idx]; - idx++; + id += p_str[index]; + index++; } r_token.type = TK_IDENTIFIER; diff --git a/core/vector.h b/core/vector.h index 5eed8dce96..966832ac50 100644 --- a/core/vector.h +++ b/core/vector.h @@ -71,7 +71,7 @@ class Vector { _FORCE_INLINE_ size_t _get_alloc_size(size_t p_elements) const { //return nearest_power_of_2_templated(p_elements*sizeof(T)+sizeof(SafeRefCount)+sizeof(int)); - return nearest_power_of_2(p_elements * sizeof(T)); + return next_power_of_2(p_elements * sizeof(T)); } _FORCE_INLINE_ bool _get_alloc_size_checked(size_t p_elements, size_t *out) const { @@ -79,7 +79,7 @@ class Vector { size_t o; size_t p; if (_mul_overflow(p_elements, sizeof(T), &o)) return false; - *out = nearest_power_of_2(o); + *out = next_power_of_2(o); if (_add_overflow(o, static_cast<size_t>(32), &p)) return false; //no longer allocated here return true; #else @@ -117,7 +117,7 @@ public: } _FORCE_INLINE_ bool empty() const { return _ptr == 0; } Error resize(int p_size); - bool push_back(T p_elem); + bool push_back(const T &p_elem); void remove(int p_index); void erase(const T &p_val) { @@ -129,7 +129,7 @@ public: template <class T_val> int find(const T_val &p_val, int p_from = 0) const; - void set(int p_index, T p_elem); + void set(int p_index, const T &p_elem); T get(int p_index) const; inline T &operator[](int p_index) { @@ -336,7 +336,7 @@ void Vector<T>::invert() { } template <class T> -void Vector<T>::set(int p_index, T p_elem) { +void Vector<T>::set(int p_index, const T &p_elem) { operator[](p_index) = p_elem; } @@ -348,7 +348,7 @@ T Vector<T>::get(int p_index) const { } template <class T> -bool Vector<T>::push_back(T p_elem) { +bool Vector<T>::push_back(const T &p_elem) { Error err = resize(size() + 1); ERR_FAIL_COND_V(err, true) |