diff --git a/.travis.yml b/.travis.yml index 3c7ee5c1028..d76fcca791c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,8 +69,8 @@ addons: before_script: - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; brew install scons; fi - if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$GODOT_TARGET" = "android" ]; then - brew update; brew install -v android-sdk; - brew install -v android-ndk | grep -v "inflating:" | grep -v "creating:"; + brew update; travis_wait 20 brew install -v android-sdk; + travis_wait 20 brew install -v android-ndk | grep -v "inflating:" | grep -v "creating:"; export ANDROID_HOME=/usr/local/opt/android-sdk; export ANDROID_NDK_ROOT=/usr/local/opt/android-ndk; fi diff --git a/SConstruct b/SConstruct index d168820f666..365463ebad1 100644 --- a/SConstruct +++ b/SConstruct @@ -1,3 +1,5 @@ +#!/usr/bin/env python + EnsureSConsVersion(0,14); @@ -16,7 +18,6 @@ platform_list = [] # list of platforms platform_opts = {} # options for each platform platform_flags = {} # flags for each platform - active_platforms=[] active_platform_ids=[] platform_exporters=[] @@ -55,15 +56,17 @@ methods.save_active_platforms(active_platforms,active_platform_ids) custom_tools=['default'] -platform_arg = ARGUMENTS.get("platform", False) +platform_arg = ARGUMENTS.get("platform", ARGUMENTS.get("p", False)) if (os.name=="posix"): pass elif (os.name=="nt"): - if (os.getenv("VSINSTALLDIR")==None or platform_arg=="android"): + if ( os.getenv("VCINSTALLDIR")==None or platform_arg=="android"): custom_tools=['mingw'] env_base=Environment(tools=custom_tools); +if 'TERM' in os.environ: + env_base['ENV']['TERM'] = os.environ['TERM'] env_base.AppendENVPath('PATH', os.getenv('PATH')) env_base.AppendENVPath('PKG_CONFIG_PATH', os.getenv('PKG_CONFIG_PATH')) env_base.global_defaults=global_defaults @@ -98,9 +101,8 @@ env_base.__class__.disable_module = methods.disable_module env_base.__class__.add_source_files = methods.add_source_files env_base.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix -env_base["x86_opt_gcc"]=False -env_base["x86_opt_vc"]=False -env_base["armv7_opt_gcc"]=False +env_base["x86_libtheora_opt_gcc"]=False +env_base["x86_libtheora_opt_vc"]=False customs = ['custom.py'] @@ -120,32 +122,30 @@ opts.Add('platform','Platform: '+str(platform_list)+'.',"") opts.Add('p','Platform (same as platform=).',"") opts.Add('tools','Build Tools (Including Editor): (yes/no)','yes') opts.Add('gdscript','Build GDSCript support: (yes/no)','yes') -opts.Add('vorbis','Build Ogg Vorbis Support: (yes/no)','yes') -opts.Add('opus','Build Opus Audio Format Support: (yes/no)','yes') +opts.Add('libogg','Ogg library for ogg container support (system/builtin)','builtin') +opts.Add('libvorbis','Ogg Vorbis library for vorbis support (system/builtin)','builtin') +opts.Add('libtheora','Theora library for theora module (system/builtin)','builtin') +opts.Add('opus','Opus and opusfile library for Opus format support: (system/builtin)','builtin') opts.Add('minizip','Build Minizip Archive Support: (yes/no)','yes') -opts.Add('squish','Squish BC Texture Compression in editor (yes/no)','yes') -opts.Add('theora','Theora Video (yes/no)','yes') -opts.Add('theoralib','Theora Video (yes/no)','no') -opts.Add('freetype','Freetype support in editor','builtin') -opts.Add('speex','Speex Audio (yes/no)','yes') +opts.Add('squish','Squish library for BC Texture Compression in editor (system/builtin)','builtin') +opts.Add('freetype','Freetype library for TTF support via freetype module (system/builtin)','builtin') opts.Add('xml','XML Save/Load support (yes/no)','yes') -opts.Add('png','PNG Image loader support (yes/no)','yes') -opts.Add('jpg','JPG Image loader support (yes/no)','yes') -opts.Add('webp','WEBP Image loader support (yes/no)','yes') -opts.Add('dds','DDS Texture loader support (yes/no)','yes') -opts.Add('pvr','PVR (PowerVR) Texture loader support (yes/no)','yes') -opts.Add('etc1','etc1 Texture compression support (yes/no)','yes') -opts.Add('builtin_zlib','Use built-in zlib (yes/no)','yes') -opts.Add('openssl','Use OpenSSL (yes/no/builtin)','no') -opts.Add('musepack','Musepack Audio (yes/no)','yes') -opts.Add("CXX", "Compiler"); -opts.Add("CCFLAGS", "Custom flags for the C++ compiler"); +opts.Add('libpng','libpng library for image loader support (system/builtin)','builtin') +opts.Add('libwebp','libwebp library for webp module (system/builtin)','builtin') +opts.Add('openssl','OpenSSL library for openssl module (system/builtin)','builtin') +opts.Add('libmpcdec','libmpcdec library for mpc module (system/builtin)','builtin') +opts.Add('enet','ENet library (system/builtin)','builtin') +opts.Add('glew','GLEW library for the gl_context (system/builtin)','builtin') +opts.Add('xaudio2','XAudio2 audio driver (yes/no)','no') +opts.Add("CXX", "C++ Compiler") +opts.Add("CC", "C Compiler") +opts.Add("CCFLAGS", "Custom flags for the C/C++ compiler"); opts.Add("CFLAGS", "Custom flags for the C compiler"); opts.Add("LINKFLAGS", "Custom flags for the linker"); opts.Add('unix_global_settings_path', 'unix-specific path to system-wide settings. Currently only used by templates.','') opts.Add('disable_3d', 'Disable 3D nodes for smaller executable (yes/no)', "no") opts.Add('disable_advanced_gui', 'Disable advance 3D gui nodes and behaviors (yes/no)', "no") -opts.Add('colored', 'Enable colored output for the compilation (yes/no)', 'no') +opts.Add('verbose', 'Enable verbose output for the compilation (yes/no)', 'yes') opts.Add('deprecated','Enable deprecated features (yes/no)','yes') opts.Add('extra_suffix', 'Custom extra suffix added to the base filename of all generated binary files.', '') opts.Add('vsproj', 'Generate Visual Studio Project. (yes/no)', 'no') @@ -158,7 +158,7 @@ for k in platform_opts.keys(): opts.Add(o[0],o[1],o[2]) for x in module_list: - opts.Add('module_'+x+'_enabled', "Enable module '"+x+"'.", "yes") + opts.Add('module_'+x+'_enabled', "Enable module '"+x+"' (yes/no)", "yes") opts.Update(env_base) # update environment Help(opts.GenerateHelpText(env_base)) # generate help @@ -254,14 +254,6 @@ if selected_platform in platform_list: #must happen after the flags, so when flags are used by configure, stuff happens (ie, ssl on x11) detect.configure(env) - - if (env["freetype"]!="no"): - env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) - if (env["freetype"]=="builtin"): - env.Append(CPPPATH=['#drivers/freetype']) - env.Append(CPPPATH=['#drivers/freetype/freetype/include']) - - #env['platform_libsuffix'] = env['LIBSUFFIX'] suffix="."+selected_platform @@ -272,6 +264,8 @@ if selected_platform in platform_list: sys.exit(255) suffix+=".opt" + env.Append(CCFLAGS=['-DNDEBUG']); + elif (env["target"]=="release_debug"): if (env["tools"]=="yes"): suffix+=".opt.tools" @@ -322,49 +316,9 @@ if selected_platform in platform_list: if (env.use_ptrcall): env.Append(CPPFLAGS=['-DPTRCALL_ENABLED']); - if (env['musepack']=='yes'): - env.Append(CPPFLAGS=['-DMUSEPACK_ENABLED']); - - #if (env['openssl']!='no'): - # env.Append(CPPFLAGS=['-DOPENSSL_ENABLED']); - # if (env['openssl']=="builtin"): - # env.Append(CPPPATH=['#drivers/builtin_openssl2']) - - if (env["builtin_zlib"]=='yes'): - env.Append(CPPPATH=['#drivers/builtin_zlib/zlib']) - # to test 64 bits compiltion # env.Append(CPPFLAGS=['-m64']) - if (env_base['squish']=='yes'): - env.Append(CPPFLAGS=['-DSQUISH_ENABLED']); - - if (env['vorbis']=='yes'): - env.Append(CPPFLAGS=['-DVORBIS_ENABLED']); - if (env['opus']=='yes'): - env.Append(CPPFLAGS=['-DOPUS_ENABLED']); - - - if (env['theora']=='yes'): - env['theoralib']='yes' - env.Append(CPPFLAGS=['-DTHEORA_ENABLED']); - if (env['theoralib']=='yes'): - env.Append(CPPFLAGS=['-DTHEORALIB_ENABLED']); - - if (env['png']=='yes'): - env.Append(CPPFLAGS=['-DPNG_ENABLED']); - if (env['dds']=='yes'): - env.Append(CPPFLAGS=['-DDDS_ENABLED']); - if (env['pvr']=='yes'): - env.Append(CPPFLAGS=['-DPVR_ENABLED']); - if (env['jpg']=='yes'): - env.Append(CPPFLAGS=['-DJPG_ENABLED']); - if (env['webp']=='yes'): - env.Append(CPPFLAGS=['-DWEBP_ENABLED']); - - if (env['speex']=='yes'): - env.Append(CPPFLAGS=['-DSPEEX_ENABLED']); - if (env['tools']=='yes'): env.Append(CPPFLAGS=['-DTOOLS_ENABLED']) if (env['disable_3d']=='yes'): @@ -380,11 +334,8 @@ if selected_platform in platform_list: if (env['xml']=='yes'): env.Append(CPPFLAGS=['-DXML_ENABLED']) - if (env['colored']=='yes'): - methods.colored(sys,env) - - if (env['etc1']=='yes'): - env.Append(CPPFLAGS=['-DETC1_ENABLED']) + if (env['verbose']=='no'): + methods.no_verbose(sys,env) Export('env') @@ -432,9 +383,9 @@ if selected_platform in platform_list: release_variants = ['release|Win32']+['release|x64'] release_debug_variants = ['release_debug|Win32']+['release_debug|x64'] variants = debug_variants + release_variants + release_debug_variants - debug_targets = ['Debug']+['Debug'] - release_targets = ['Release']+['Release'] - release_debug_targets = ['ReleaseDebug']+['ReleaseDebug'] + debug_targets = ['bin\\godot.windows.tools.32.exe']+['bin\\godot.windows.tools.64.exe'] + release_targets = ['bin\\godot.windows.opt.32.exe']+['bin\\godot.windows.opt.64.exe'] + release_debug_targets = ['bin\\godot.windows.opt.tools.32.exe']+['bin\\godot.windows.opt.tools.64.exe'] targets = debug_targets + release_targets + release_debug_targets msvproj = env.MSVSProject(target = ['#godot' + env['MSVSPROJECTSUFFIX'] ], incs = env.vs_incs, diff --git a/bin/SCsub b/bin/SCsub index db057ed1035..6b29a44fd91 100644 --- a/bin/SCsub +++ b/bin/SCsub @@ -1,3 +1,5 @@ +#!/usr/bin/python + Import('env') Export('env') diff --git a/bin/tests/SCsub b/bin/tests/SCsub index 57c9bc63b27..26687599e1f 100644 --- a/bin/tests/SCsub +++ b/bin/tests/SCsub @@ -1,3 +1,5 @@ +#!/usr/bin/python + Import('env') env.tests_sources=[] diff --git a/bin/tests/test_math.cpp b/bin/tests/test_math.cpp index e5667bff642..9329002f769 100644 --- a/bin/tests/test_math.cpp +++ b/bin/tests/test_math.cpp @@ -516,7 +516,7 @@ MainLoop* test() { { - Vector hashes; + Vector hashes; List tl; ObjectTypeDB::get_type_list(&tl); diff --git a/bin/tests/test_string.cpp b/bin/tests/test_string.cpp index be37ce118ff..4990c58896c 100644 --- a/bin/tests/test_string.cpp +++ b/bin/tests/test_string.cpp @@ -31,7 +31,7 @@ //#include "math_funcs.h" #include #include "os/os.h" -#include "drivers/nrex/regex.h" +#include "core/io/ip_address.h" #include "test_string.h" @@ -461,18 +461,8 @@ bool test_25() { bool test_26() { - OS::get_singleton()->print("\n\nTest 26: RegEx\n"); - RegEx regexp("(.*):(.*)"); - - int res = regexp.find("name:password"); - printf("\tmatch: %s\n", (res>=0)?"true":"false"); - - printf("\t%i captures:\n", regexp.get_capture_count()); - for (int i = 0; i=0); + //TODO: Do replacement RegEx test + return true; }; struct test_27_data { @@ -843,6 +833,62 @@ bool test_28() { return state; } +bool test_29() { + + bool error = false; + bool state = true; + bool success = false; + + IP_Address ip0("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); + OS::get_singleton()->print("ip0 is %ls\n", String(ip0).c_str()); + + IP_Address ip(0x0123, 0x4567, 0x89ab, 0xcdef, IP_Address::TYPE_IPV6); + OS::get_singleton()->print("ip6 is %ls\n", String(ip).c_str()); + + IP_Address ip2("fe80::52e5:49ff:fe93:1baf"); + OS::get_singleton()->print("ip6 is %ls\n", String(ip2).c_str()); + + IP_Address ip3("::ffff:192.168.0.1"); + OS::get_singleton()->print("ip6 is %ls\n", String(ip3).c_str()); + + String ip4 = "192.168.0.1"; + success = ip4.is_valid_ip_address(); + OS::get_singleton()->print("Is valid ipv4: %ls, %s\n", ip4.c_str(), success ? "OK" : "FAIL"); + if (!success) state = false; + + ip4 = "192.368.0.1"; + success = (!ip4.is_valid_ip_address()); + OS::get_singleton()->print("Is invalid ipv4: %ls, %s\n", ip4.c_str(), success ? "OK" : "FAIL"); + if (!success) state = false; + + String ip6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; + success = ip6.is_valid_ip_address(); + OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); + if (!success) state = false; + + ip6 = "2001:0db8:85j3:0000:0000:8a2e:0370:7334"; + success = (!ip6.is_valid_ip_address()); + OS::get_singleton()->print("Is invalid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); + if (!success) state = false; + + ip6 = "2001:0db8:85f345:0000:0000:8a2e:0370:7334"; + success = (!ip6.is_valid_ip_address()); + OS::get_singleton()->print("Is invalid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); + if (!success) state = false; + + ip6 = "2001:0db8::0:8a2e:370:7334"; + success = (ip6.is_valid_ip_address()); + OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); + if (!success) state = false; + + ip6 = "::ffff:192.168.0.1"; + success = (ip6.is_valid_ip_address()); + OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); + if (!success) state = false; + + return state; +}; + typedef bool (*TestFunc)(void); TestFunc test_funcs[] = { @@ -875,6 +921,7 @@ TestFunc test_funcs[] = { test_26, test_27, test_28, + test_29, 0 }; diff --git a/core/SCsub b/core/SCsub index 4ce91c794f0..cbed2e4f35c 100644 --- a/core/SCsub +++ b/core/SCsub @@ -1,3 +1,5 @@ +#!/usr/bin/env python + Import('env') env.core_sources=[] diff --git a/core/array.cpp b/core/array.cpp index 23792f90fc4..683a43e3d02 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -276,16 +276,26 @@ void Array::push_front(const Variant& p_value) { _p->array.insert(0,p_value); } -void Array::pop_back(){ +Variant Array::pop_back(){ - if (!_p->array.empty()) - _p->array.resize( _p->array.size() -1 ); + if (!_p->array.empty()) { + int n = _p->array.size() - 1; + Variant ret = _p->array.get(n); + _p->array.resize(n); + return ret; + } + return Variant(); } -void Array::pop_front(){ - if (!_p->array.empty()) +Variant Array::pop_front(){ + + if (!_p->array.empty()) { + Variant ret = _p->array.get(0); _p->array.remove(0); + return ret; + } + return Variant(); } diff --git a/core/array.h b/core/array.h index dfc902525c9..eb79b0cf331 100644 --- a/core/array.h +++ b/core/array.h @@ -80,8 +80,8 @@ public: void erase(const Variant& p_value); void push_front(const Variant& p_value); - void pop_back(); - void pop_front(); + Variant pop_back(); + Variant pop_front(); Array(const Array& p_from); Array(bool p_shared=false); diff --git a/core/bind/SCsub b/core/bind/SCsub index 7b4a6acbc07..c2731d60e6b 100644 --- a/core/bind/SCsub +++ b/core/bind/SCsub @@ -1,3 +1,5 @@ +#!/usr/bin/env python + Import('env') env.add_source_files(env.core_sources,"*.cpp") diff --git a/core/globals.cpp b/core/globals.cpp index b822f52f157..bef40ff330a 100644 --- a/core/globals.cpp +++ b/core/globals.cpp @@ -54,7 +54,7 @@ String Globals::localize_path(const String& p_path) const { if (resource_path=="") return p_path; //not initialied yet - if (p_path.begins_with("res://") || p_path.begins_with("user://")) + if (p_path.begins_with("res://") || p_path.begins_with("user://") || p_path.is_abs_path()) return p_path.simplify_path(); diff --git a/core/hashfuncs.h b/core/hashfuncs.h index a917ee5edb8..6c029a34589 100644 --- a/core/hashfuncs.h +++ b/core/hashfuncs.h @@ -74,7 +74,10 @@ static inline uint32_t hash_djb2_one_float(float p_in,uint32_t p_prev=5381) { float f; uint32_t i; } u; - u.f=p_in; + + // handle -0 case + if (p_in==0.0f) u.f=0.0f; + else u.f=p_in; return ((p_prev<<5)+p_prev)+u.i; } diff --git a/core/io/SCsub b/core/io/SCsub index 3ff9b355a45..48cc9a5275a 100644 --- a/core/io/SCsub +++ b/core/io/SCsub @@ -1,3 +1,5 @@ +#!/usr/bin/env python + Import('env') env.add_source_files(env.core_sources,"*.cpp") diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 2a831dd9923..e3289b452c5 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -29,8 +29,9 @@ #include "http_client.h" #include "io/stream_peer_ssl.h" +VARIANT_ENUM_CAST(IP_Address::AddrType); -Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_verify_host){ +Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_verify_host, IP_Address::AddrType p_addr_type){ close(); conn_port=p_port; @@ -62,7 +63,7 @@ Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_ve status=STATUS_CONNECTING; } else { //is hostname - resolving=IP::get_singleton()->resolve_hostname_queue_item(conn_host); + resolving=IP::get_singleton()->resolve_hostname_queue_item(conn_host, p_addr_type); status=STATUS_RESOLVING; } @@ -635,7 +636,7 @@ Error HTTPClient::_get_http_data(uint8_t* p_buffer, int p_bytes,int &r_received) void HTTPClient::_bind_methods() { - ObjectTypeDB::bind_method(_MD("connect:Error","host","port","use_ssl","verify_host"),&HTTPClient::connect,DEFVAL(false),DEFVAL(true)); + ObjectTypeDB::bind_method(_MD("connect:Error","host","port","use_ssl","verify_host"),&HTTPClient::connect,DEFVAL(false),DEFVAL(true),DEFVAL(IP_Address::TYPE_ANY)); ObjectTypeDB::bind_method(_MD("set_connection","connection:StreamPeer"),&HTTPClient::set_connection); ObjectTypeDB::bind_method(_MD("get_connection:StreamPeer"),&HTTPClient::get_connection); ObjectTypeDB::bind_method(_MD("request_raw","method","url","headers","body"),&HTTPClient::request_raw); diff --git a/core/io/http_client.h b/core/io/http_client.h index 32d2e721015..ba464c34c75 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -165,7 +165,7 @@ public: //Error connect_and_get(const String& p_url,bool p_verify_host=true); //connects to a full url and perform request - Error connect(const String &p_host,int p_port,bool p_ssl=false,bool p_verify_host=true); + Error connect(const String &p_host,int p_port,bool p_ssl=false,bool p_verify_host=true, IP_Address::AddrType p_addr_type = IP_Address::TYPE_ANY); void set_connection(const Ref& p_connection); Ref get_connection() const; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index a77aace07f6..4ee1b281c45 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -32,6 +32,7 @@ #include "hash_map.h" VARIANT_ENUM_CAST(IP::ResolverStatus); +VARIANT_ENUM_CAST(IP_Address::AddrType); /************* RESOLVER ******************/ @@ -43,10 +44,12 @@ struct _IP_ResolverPrivate { volatile IP::ResolverStatus status; IP_Address response; String hostname; + IP_Address::AddrType type; void clear() { status = IP::RESOLVER_STATUS_NONE; response = IP_Address(); + type = IP_Address::TYPE_NONE; hostname=""; }; @@ -78,9 +81,9 @@ struct _IP_ResolverPrivate { if (queue[i].status!=IP::RESOLVER_STATUS_WAITING) continue; - queue[i].response=IP::get_singleton()->resolve_hostname(queue[i].hostname); + queue[i].response=IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type); - if (queue[i].response.host==0) + if (queue[i].response.type==IP_Address::TYPE_NONE) queue[i].status=IP::RESOLVER_STATUS_ERROR; else queue[i].status=IP::RESOLVER_STATUS_DONE; @@ -109,21 +112,23 @@ struct _IP_ResolverPrivate { -IP_Address IP::resolve_hostname(const String& p_hostname) { +IP_Address IP::resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type) { - GLOBAL_LOCK_FUNCTION + GLOBAL_LOCK_FUNCTION; if (resolver->cache.has(p_hostname)) - return resolver->cache[p_hostname]; + if (resolver->cache[p_hostname].type & p_type != 0) + return resolver->cache[p_hostname]; + // requested type is different from type in cache. continue resolution, if successful it'll overwrite cache - IP_Address res = _resolve_hostname(p_hostname); + IP_Address res = _resolve_hostname(p_hostname, p_type); resolver->cache[p_hostname]=res; return res; } -IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname) { +IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname, IP_Address::AddrType p_type) { - GLOBAL_LOCK_FUNCTION + GLOBAL_LOCK_FUNCTION; ResolverID id = resolver->find_empty_id(); @@ -133,7 +138,8 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname) { } resolver->queue[id].hostname=p_hostname; - if (resolver->cache.has(p_hostname)) { + resolver->queue[id].type = p_type; + if (resolver->cache.has(p_hostname) && (resolver->cache[p_hostname].type & p_type) != 0) { resolver->queue[id].response=resolver->cache[p_hostname]; resolver->queue[id].status=IP::RESOLVER_STATUS_DONE; } else { @@ -145,10 +151,6 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname) { resolver->resolve_queues(); } - - - - return id; } @@ -187,6 +189,14 @@ void IP::erase_resolve_item(ResolverID p_id) { } +void IP::clear_cache(const String &p_hostname) { + + if (p_hostname.empty()) { + resolver->cache.clear(); + } else { + resolver->cache.erase(p_hostname); + } +}; Array IP::_get_local_addresses() const { @@ -208,6 +218,7 @@ void IP::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_resolve_item_address","id"),&IP::get_resolve_item_address); ObjectTypeDB::bind_method(_MD("erase_resolve_item","id"),&IP::erase_resolve_item); ObjectTypeDB::bind_method(_MD("get_local_addresses"),&IP::_get_local_addresses); + ObjectTypeDB::bind_method(_MD("clear_cache"),&IP::clear_cache, DEFVAL("")); BIND_CONSTANT( RESOLVER_STATUS_NONE ); BIND_CONSTANT( RESOLVER_STATUS_WAITING ); diff --git a/core/io/ip.h b/core/io/ip.h index 38c86e7ba3d..742dd0e740f 100644 --- a/core/io/ip.h +++ b/core/io/ip.h @@ -48,6 +48,14 @@ public: RESOLVER_STATUS_ERROR, }; + enum AddressType { + + ADDRESS_IPV4 = 1, + ADDRESS_IPV6 = 2, + + ADDRESS_ANY = 3, + }; + enum { RESOLVER_MAX_QUERIES = 32, RESOLVER_INVALID_ID=-1 @@ -65,7 +73,7 @@ protected: static IP*singleton; static void _bind_methods(); - virtual IP_Address _resolve_hostname(const String& p_hostname)=0; + virtual IP_Address _resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type = IP_Address::TYPE_ANY)=0; Array _get_local_addresses() const; static IP* (*_create)(); @@ -73,14 +81,16 @@ public: - IP_Address resolve_hostname(const String& p_hostname); + IP_Address resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type = IP_Address::TYPE_ANY); // async resolver hostname - ResolverID resolve_hostname_queue_item(const String& p_hostname); + ResolverID resolve_hostname_queue_item(const String& p_hostname, IP_Address::AddrType p_type = IP_Address::TYPE_ANY); ResolverStatus get_resolve_item_status(ResolverID p_id) const; IP_Address get_resolve_item_address(ResolverID p_id) const; virtual void get_local_addresses(List *r_addresses) const=0; void erase_resolve_item(ResolverID p_id); + void clear_cache(const String& p_hostname = ""); + static IP* get_singleton(); static IP* create(); diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index 7a51bce7c6b..9887cd132ba 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -32,29 +32,191 @@ IP_Address::operator Variant() const { return operator String(); }*/ + +#include +#include + IP_Address::operator String() const { - return itos(field[0])+"."+itos(field[1])+"."+itos(field[2])+"."+itos(field[3]); + if (type == TYPE_NONE) + return "0.0.0.0"; + if (type == TYPE_IPV4) + return itos(field8[0])+"."+itos(field8[1])+"."+itos(field8[2])+"."+itos(field8[3]); + else { + String ret; + for (int i=0; i<8; i++) { + if (i > 0) + ret = ret + ":"; + uint16_t num = (field8[i*2] << 8) + field8[i*2+1]; + ret = ret + String::num_int64(num, 16); + }; + + return ret; + }; } -IP_Address::IP_Address(const String& p_string) { +static void _parse_hex(const String& p_string, int p_start, uint8_t* p_dst) { - host=0; - int slices = p_string.get_slice_count("."); + uint16_t ret = 0; + for (int i=p_start; i= p_string.length()) { + break; + }; + + int n = 0; + CharType c = p_string[i]; + if (c >= '0' && c <= '9') { + + n = c - '0'; + } else if (c >= 'a' && c <= 'f') { + n = 10 + (c - 'a'); + } else if (c >= 'A' && c <= 'F') { + n = 10 + (c - 'A'); + } else if (c == ':') { + break; + } else { + ERR_EXPLAIN("Invalid character in ipv6 address: " + p_string); + ERR_FAIL(); + }; + ret = ret << 4; + ret += n; + }; + + p_dst[0] = ret >> 8; + p_dst[1] = ret & 0xff; +}; + +void IP_Address::_parse_ipv6(const String& p_string) { + + static const int parts_total = 8; + int parts[parts_total] = {0}; + int parts_count = 0; + bool part_found = false; + bool part_skip = false; + bool part_ipv4 = false; + int parts_idx = 0; + + for (int i=0; i= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) { + if (!part_found) { + parts[parts_idx++] = i; + part_found = true; + ++parts_count; + }; + } else { + + ERR_EXPLAIN("Invalid character in IPv6 address: " + p_string); + ERR_FAIL(); + }; + }; + + int parts_extra = 0; + if (part_skip) { + parts_extra = parts_total - parts_count; + }; + + int idx = 0; + for (int i=0; i= 0) { + + _parse_ipv6(p_string); + type = TYPE_IPV6; + } else { + + _parse_ipv4(p_string, 0, &field8[0]); + type = TYPE_IPV4; + }; } -IP_Address::IP_Address(uint8_t p_a,uint8_t p_b,uint8_t p_c,uint8_t p_d) { +_FORCE_INLINE_ static void _32_to_buf(uint8_t* p_dst, uint32_t p_n) { + + p_dst[0] = (p_n >> 24) & 0xff; + p_dst[1] = (p_n >> 16) & 0xff; + p_dst[2] = (p_n >> 8) & 0xff; + p_dst[3] = (p_n >> 0) & 0xff; +}; + +IP_Address::IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, IP_Address::AddrType p_type) { + + type = p_type; + memset(&field8[0], 0, sizeof(field8)); + if (p_type == TYPE_IPV4) { + field8[0]=p_a; + field8[1]=p_b; + field8[2]=p_c; + field8[3]=p_d; + } else if (type == TYPE_IPV6) { + + _32_to_buf(&field8[0], p_a); + _32_to_buf(&field8[4], p_b); + _32_to_buf(&field8[8], p_c); + _32_to_buf(&field8[12], p_d); + } else { + type = TYPE_NONE; + ERR_EXPLAIN("Invalid type specified for IP_Address (use TYPE_IPV4 or TYPE_IPV6"); + ERR_FAIL(); + }; - field[0]=p_a; - field[1]=p_b; - field[2]=p_c; - field[3]=p_d; } diff --git a/core/io/ip_address.h b/core/io/ip_address.h index 12923117297..fe13d70611e 100644 --- a/core/io/ip_address.h +++ b/core/io/ip_address.h @@ -33,22 +33,48 @@ struct IP_Address { - union { - uint8_t field[4]; - uint32_t host; +public: + enum AddrType { + TYPE_NONE = 0, + TYPE_IPV4 = 1, + TYPE_IPV6 = 2, + + TYPE_ANY = 3, }; + AddrType type; + + union { + uint8_t field8[16]; + uint16_t field16[8]; + uint32_t field32[4]; + }; + +protected: + void _parse_ipv6(const String& p_string); + void _parse_ipv4(const String& p_string, int p_start, uint8_t* p_ret); + +public: //operator Variant() const; bool operator==(const IP_Address& p_ip) const { - return host==p_ip.host; + for (int i=0; i<4; i++) + if (field32[i] != p_ip.field32[i]) + return false; + return true; } bool operator!=(const IP_Address& p_ip) const { - return host!=p_ip.host; + for (int i=0; i<4; i++) + if (field32[i] != p_ip.field32[i]) + return true; + return false; } + + void clear(); + operator String() const; IP_Address(const String& p_string); - IP_Address(uint8_t p_a,uint8_t p_b,uint8_t p_c,uint8_t p_d); - IP_Address() { host=0; } + IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, AddrType p_type=TYPE_IPV4); + IP_Address() { clear(); type=TYPE_NONE; } }; diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index efc619e4147..018dc77d916 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -29,14 +29,9 @@ #include "packet_peer_udp.h" #include "io/ip.h" - PacketPeerUDP* (*PacketPeerUDP::_create)()=NULL; -int PacketPeerUDP::_get_packet_address() const { - - IP_Address ip = get_packet_address(); - return ip.host; -} +VARIANT_ENUM_CAST(IP_Address::AddrType); String PacketPeerUDP::_get_packet_ip() const { @@ -65,7 +60,7 @@ void PacketPeerUDP::_bind_methods() { ObjectTypeDB::bind_method(_MD("wait:Error"),&PacketPeerUDP::wait); ObjectTypeDB::bind_method(_MD("is_listening"),&PacketPeerUDP::is_listening); ObjectTypeDB::bind_method(_MD("get_packet_ip"),&PacketPeerUDP::_get_packet_ip); - ObjectTypeDB::bind_method(_MD("get_packet_address"),&PacketPeerUDP::_get_packet_address); + //ObjectTypeDB::bind_method(_MD("get_packet_address"),&PacketPeerUDP::_get_packet_address); ObjectTypeDB::bind_method(_MD("get_packet_port"),&PacketPeerUDP::get_packet_port); ObjectTypeDB::bind_method(_MD("set_send_address","host","port"),&PacketPeerUDP::_set_send_address); diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index 70d92834fc2..c0806a9e6a7 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -40,14 +40,13 @@ protected: static PacketPeerUDP* (*_create)(); static void _bind_methods(); - int _get_packet_address() const; String _get_packet_ip() const; virtual Error _set_send_address(const String& p_address,int p_port); public: - virtual Error listen(int p_port,int p_recv_buffer_size=65536)=0; + virtual Error listen(int p_port, IP_Address::AddrType p_address_type = IP_Address::TYPE_IPV4, int p_recv_buffer_size=65536)=0; virtual void close()=0; virtual Error wait()=0; virtual bool is_listening() const=0; diff --git a/tools/pck/pck_packer.cpp b/core/io/pck_packer.cpp similarity index 100% rename from tools/pck/pck_packer.cpp rename to core/io/pck_packer.cpp diff --git a/tools/pck/pck_packer.h b/core/io/pck_packer.h similarity index 100% rename from tools/pck/pck_packer.h rename to core/io/pck_packer.h diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 274d20a48ae..53d6e900f38 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -30,6 +30,8 @@ TCP_Server* (*TCP_Server::_create)()=NULL; +VARIANT_ENUM_CAST(IP_Address::AddrType); + Ref TCP_Server::create_ref() { if (!_create) @@ -44,19 +46,19 @@ TCP_Server* TCP_Server::create() { return _create(); } -Error TCP_Server::_listen(uint16_t p_port,DVector p_accepted_hosts) { +Error TCP_Server::_listen(uint16_t p_port, IP_Address::AddrType p_type, DVector p_accepted_hosts) { List hosts; for(int i=0;i())); + ObjectTypeDB::bind_method(_MD("listen","port","accepted_hosts"),&TCP_Server::_listen,DEFVAL(IP_Address::TYPE_IPV4), DEFVAL(DVector())); ObjectTypeDB::bind_method(_MD("is_connection_available"),&TCP_Server::is_connection_available); ObjectTypeDB::bind_method(_MD("take_connection"),&TCP_Server::take_connection); ObjectTypeDB::bind_method(_MD("stop"),&TCP_Server::stop); diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index 512a7e640a5..883a3ef2f63 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -41,11 +41,11 @@ protected: static TCP_Server* (*_create)(); //bind helper - Error _listen(uint16_t p_port,DVector p_accepted_hosts=DVector()); + Error _listen(uint16_t p_port, IP_Address::AddrType p_type = IP_Address::TYPE_IPV4 ,DVector p_accepted_hosts=DVector()); static void _bind_methods(); public: - virtual Error listen(uint16_t p_port,const List *p_accepted_hosts=NULL)=0; + virtual Error listen(uint16_t p_port, IP_Address::AddrType p_type = IP_Address::TYPE_IPV4, const List *p_accepted_hosts=NULL)=0; virtual bool is_connection_available() const=0; virtual Ref take_connection()=0; diff --git a/core/math/SCsub b/core/math/SCsub index 7b4a6acbc07..c2731d60e6b 100644 --- a/core/math/SCsub +++ b/core/math/SCsub @@ -1,3 +1,5 @@ +#!/usr/bin/env python + Import('env') env.add_source_files(env.core_sources,"*.cpp") diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index 0e2060008c5..e616f05914f 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -424,7 +424,7 @@ Matrix32 Matrix32::inverse() const { void Matrix32::affine_invert() { - float det = elements[0][0]*elements[1][1] - elements[1][0]*elements[0][1]; + float det = basis_determinant(); ERR_FAIL_COND(det==0); float idet = 1.0 / det; @@ -475,18 +475,18 @@ Matrix32::Matrix32(real_t p_rot, const Vector2& p_pos) { elements[2]=p_pos; } -Vector2 Matrix32::get_scale() const { +Size2 Matrix32::get_scale() const { - return Vector2( elements[0].length(), elements[1].length() ); + return Size2( elements[0].length(), elements[1].length() ); } -void Matrix32::scale(const Vector2& p_scale) { +void Matrix32::scale(const Size2& p_scale) { elements[0]*=p_scale; elements[1]*=p_scale; elements[2]*=p_scale; } -void Matrix32::scale_basis(const Vector2& p_scale) { +void Matrix32::scale_basis(const Size2& p_scale) { elements[0]*=p_scale; elements[1]*=p_scale; @@ -501,7 +501,6 @@ void Matrix32::translate( const Vector2& p_translation ) { elements[2]+=basis_xform(p_translation); } - void Matrix32::orthonormalize() { // Gram-Schmidt Process @@ -550,11 +549,6 @@ void Matrix32::operator*=(const Matrix32& p_transform) { elements[2] = xform(p_transform.elements[2]); float x0,x1,y0,y1; -/* - x0 = p_transform.tdotx(elements[0]); - x1 = p_transform.tdoty(elements[0]); - y0 = p_transform.tdotx(elements[1]); - y1 = p_transform.tdoty(elements[1]);*/ x0 = tdotx(p_transform.elements[0]); x1 = tdoty(p_transform.elements[0]); @@ -576,7 +570,7 @@ Matrix32 Matrix32::operator*(const Matrix32& p_transform) const { } -Matrix32 Matrix32::scaled(const Vector2& p_scale) const { +Matrix32 Matrix32::scaled(const Size2& p_scale) const { Matrix32 copy=*this; copy.scale(p_scale); @@ -584,7 +578,7 @@ Matrix32 Matrix32::scaled(const Vector2& p_scale) const { } -Matrix32 Matrix32::basis_scaled(const Vector2& p_scale) const { +Matrix32 Matrix32::basis_scaled(const Size2& p_scale) const { Matrix32 copy=*this; copy.scale_basis(p_scale); @@ -629,8 +623,8 @@ Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, float p_c) cons real_t r1 = get_rotation(); real_t r2 = p_transform.get_rotation(); - Vector2 s1 = get_scale(); - Vector2 s2 = p_transform.get_scale(); + Size2 s1 = get_scale(); + Size2 s2 = p_transform.get_scale(); //slerp rotation Vector2 v1(Math::cos(r1), Math::sin(r1)); diff --git a/core/math/math_2d.h b/core/math/math_2d.h index 90aae9fe500..38c1ac96560 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -553,10 +553,8 @@ struct Rect2i { struct Matrix32 { - Vector2 elements[3]; - _FORCE_INLINE_ float tdotx(const Vector2& v) const { return elements[0][0] * v.x + elements[1][0] * v.y; } _FORCE_INLINE_ float tdoty(const Vector2& v) const { return elements[0][1] * v.x + elements[1][1] * v.y; } @@ -577,26 +575,25 @@ struct Matrix32 { _FORCE_INLINE_ void set_rotation_and_scale(real_t p_phi,const Size2& p_scale); void rotate(real_t p_phi); - void scale(const Vector2& p_scale); - void scale_basis(const Vector2& p_scale); + void scale(const Size2& p_scale); + void scale_basis(const Size2& p_scale); void translate( real_t p_tx, real_t p_ty); void translate( const Vector2& p_translation ); float basis_determinant() const; - Vector2 get_scale() const; + Size2 get_scale() const; _FORCE_INLINE_ const Vector2& get_origin() const { return elements[2]; } _FORCE_INLINE_ void set_origin(const Vector2& p_origin) { elements[2]=p_origin; } - Matrix32 scaled(const Vector2& p_scale) const; - Matrix32 basis_scaled(const Vector2& p_scale) const; + Matrix32 scaled(const Size2& p_scale) const; + Matrix32 basis_scaled(const Size2& p_scale) const; Matrix32 translated(const Vector2& p_offset) const; Matrix32 rotated(float p_phi) const; Matrix32 untranslated() const; - void orthonormalize(); Matrix32 orthonormalized() const; @@ -615,7 +612,6 @@ struct Matrix32 { _FORCE_INLINE_ Rect2 xform(const Rect2& p_vec) const; _FORCE_INLINE_ Rect2 xform_inv(const Rect2& p_vec) const; - operator String() const; Matrix32(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) { @@ -630,7 +626,6 @@ struct Matrix32 { Matrix32(real_t p_rot, const Vector2& p_pos); Matrix32() { elements[0][0]=1.0; elements[1][1]=1.0; } - }; bool Rect2::intersects_transformed(const Matrix32& p_xform, const Rect2& p_rect) const { diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 64615fe6b4d..46c0218707d 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -41,37 +41,16 @@ static uint32_t Q[4096]; #endif uint32_t Math::rand_from_seed(uint32_t *seed) { - -#if 1 - uint32_t k; - uint32_t s = (*seed); - if (s == 0) - s = 0x12345987; - k = s / 127773; - s = 16807 * (s - k * 127773) - 2836 * k; -// if (s < 0) -// s += 2147483647; - (*seed) = s; - return (s & Math::RANDOM_MAX); -#else - *seed = *seed * 1103515245 + 12345; - return (*seed % ((unsigned int)RANDOM_MAX + 1)); -#endif + // Xorshift31 PRNG + if ( *seed == 0 ) *seed = Math::RANDOM_MAX; + (*seed) ^= (*seed) << 13; + (*seed) ^= (*seed) >> 17; + (*seed) ^= (*seed) << 5; + return (*seed) & Math::RANDOM_MAX; } void Math::seed(uint32_t x) { -#if 0 - int i; - - Q[0] = x; - Q[1] = x + PHI; - Q[2] = x + PHI + PHI; - - for (i = 3; i < 4096; i++) - Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; -#else default_seed=x; -#endif } void Math::randomize() { @@ -82,12 +61,12 @@ void Math::randomize() { uint32_t Math::rand() { - return rand_from_seed(&default_seed)&0x7FFFFFFF; + return rand_from_seed(&default_seed); } double Math::randf() { - return (double)rand() / (double)RANDOM_MAX; + return (double)rand() / (double)Math::RANDOM_MAX; } double Math::sin(double p_x) { diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index b4a13d8f6d7..fae3831dd6d 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -49,13 +49,13 @@ void Vector3::set_axis(int p_axis,real_t p_value) { } real_t Vector3::get_axis(int p_axis) const { - ERR_FAIL_INDEX_V(p_axis,3,0); - return operator[](p_axis); + ERR_FAIL_INDEX_V(p_axis,3,0); + return operator[](p_axis); } int Vector3::min_axis() const { - return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2); + return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2); } int Vector3::max_axis() const { @@ -71,9 +71,9 @@ void Vector3::snap(float p_val) { } Vector3 Vector3::snapped(float p_val) const { - Vector3 v=*this; - v.snap(p_val); - return v; + Vector3 v=*this; + v.snap(p_val); + return v; } diff --git a/core/math/vector3.h b/core/math/vector3.h index 910446023ae..06840be5e73 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -63,77 +63,78 @@ struct Vector3 { return coord[p_axis]; } - void set_axis(int p_axis,real_t p_value); - real_t get_axis(int p_axis) const; + void set_axis(int p_axis,real_t p_value); + real_t get_axis(int p_axis) const; - int min_axis() const; - int max_axis() const; + int min_axis() const; + int max_axis() const; - _FORCE_INLINE_ real_t length() const; - _FORCE_INLINE_ real_t length_squared() const; + _FORCE_INLINE_ real_t length() const; + _FORCE_INLINE_ real_t length_squared() const; - _FORCE_INLINE_ void normalize(); - _FORCE_INLINE_ Vector3 normalized() const; - _FORCE_INLINE_ Vector3 inverse() const; + _FORCE_INLINE_ void normalize(); + _FORCE_INLINE_ Vector3 normalized() const; + _FORCE_INLINE_ Vector3 inverse() const; _FORCE_INLINE_ void zero(); - void snap(float p_val); - Vector3 snapped(float p_val) const; + void snap(float p_val); + Vector3 snapped(float p_val) const; void rotate(const Vector3& p_axis,float p_phi); Vector3 rotated(const Vector3& p_axis,float p_phi) const; - /* Static Methods between 2 vector3s */ + /* Static Methods between 2 vector3s */ - _FORCE_INLINE_ Vector3 linear_interpolate(const Vector3& p_b,float p_t) const; + _FORCE_INLINE_ Vector3 linear_interpolate(const Vector3& p_b,float p_t) const; Vector3 cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const; Vector3 cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const; - _FORCE_INLINE_ Vector3 cross(const Vector3& p_b) const; - _FORCE_INLINE_ real_t dot(const Vector3& p_b) const; + _FORCE_INLINE_ Vector3 cross(const Vector3& p_b) const; + _FORCE_INLINE_ real_t dot(const Vector3& p_b) const; - _FORCE_INLINE_ Vector3 abs() const; - _FORCE_INLINE_ Vector3 floor() const; - _FORCE_INLINE_ Vector3 ceil() const; + _FORCE_INLINE_ Vector3 abs() const; + _FORCE_INLINE_ Vector3 floor() const; + _FORCE_INLINE_ Vector3 ceil() const; - _FORCE_INLINE_ real_t distance_to(const Vector3& p_b) const; - _FORCE_INLINE_ real_t distance_squared_to(const Vector3& p_b) const; + _FORCE_INLINE_ real_t distance_to(const Vector3& p_b) const; + _FORCE_INLINE_ real_t distance_squared_to(const Vector3& p_b) const; + _FORCE_INLINE_ real_t angle_to(const Vector3& p_b) const; _FORCE_INLINE_ Vector3 slide(const Vector3& p_vec) const; _FORCE_INLINE_ Vector3 reflect(const Vector3& p_vec) const; - /* Operators */ + /* Operators */ - _FORCE_INLINE_ Vector3& operator+=(const Vector3& p_v); - _FORCE_INLINE_ Vector3 operator+(const Vector3& p_v) const; - _FORCE_INLINE_ Vector3& operator-=(const Vector3& p_v); - _FORCE_INLINE_ Vector3 operator-(const Vector3& p_v) const; - _FORCE_INLINE_ Vector3& operator*=(const Vector3& p_v); - _FORCE_INLINE_ Vector3 operator*(const Vector3& p_v) const; - _FORCE_INLINE_ Vector3& operator/=(const Vector3& p_v); - _FORCE_INLINE_ Vector3 operator/(const Vector3& p_v) const; + _FORCE_INLINE_ Vector3& operator+=(const Vector3& p_v); + _FORCE_INLINE_ Vector3 operator+(const Vector3& p_v) const; + _FORCE_INLINE_ Vector3& operator-=(const Vector3& p_v); + _FORCE_INLINE_ Vector3 operator-(const Vector3& p_v) const; + _FORCE_INLINE_ Vector3& operator*=(const Vector3& p_v); + _FORCE_INLINE_ Vector3 operator*(const Vector3& p_v) const; + _FORCE_INLINE_ Vector3& operator/=(const Vector3& p_v); + _FORCE_INLINE_ Vector3 operator/(const Vector3& p_v) const; - _FORCE_INLINE_ Vector3& operator*=(real_t p_scalar); - _FORCE_INLINE_ Vector3 operator*(real_t p_scalar) const; - _FORCE_INLINE_ Vector3& operator/=(real_t p_scalar); - _FORCE_INLINE_ Vector3 operator/(real_t p_scalar) const; + _FORCE_INLINE_ Vector3& operator*=(real_t p_scalar); + _FORCE_INLINE_ Vector3 operator*(real_t p_scalar) const; + _FORCE_INLINE_ Vector3& operator/=(real_t p_scalar); + _FORCE_INLINE_ Vector3 operator/(real_t p_scalar) const; - _FORCE_INLINE_ Vector3 operator-() const; + _FORCE_INLINE_ Vector3 operator-() const; - _FORCE_INLINE_ bool operator==(const Vector3& p_v) const; - _FORCE_INLINE_ bool operator!=(const Vector3& p_v) const; - _FORCE_INLINE_ bool operator<(const Vector3& p_v) const; + _FORCE_INLINE_ bool operator==(const Vector3& p_v) const; + _FORCE_INLINE_ bool operator!=(const Vector3& p_v) const; + _FORCE_INLINE_ bool operator<(const Vector3& p_v) const; _FORCE_INLINE_ bool operator<=(const Vector3& p_v) const; operator String() const; - _FORCE_INLINE_ Vector3() { x=y=z=0; } - _FORCE_INLINE_ Vector3(real_t p_x,real_t p_y,real_t p_z) { x=p_x; y=p_y; z=p_z; } + _FORCE_INLINE_ Vector3() { x=y=z=0; } + _FORCE_INLINE_ Vector3(real_t p_x,real_t p_y,real_t p_z) { x=p_x; y=p_y; z=p_z; } }; @@ -151,11 +152,12 @@ Vector3 Vector3::cross(const Vector3& p_b) const { (x * p_b.y) - (y * p_b.x) ); - return ret; + return ret; } + real_t Vector3::dot(const Vector3& p_b) const { - return x*p_b.x + y*p_b.y + z*p_b.z; + return x*p_b.x + y*p_b.y + z*p_b.z; } Vector3 Vector3::abs() const { @@ -180,115 +182,119 @@ Vector3 Vector3::linear_interpolate(const Vector3& p_b,float p_t) const { y+(p_t * (p_b.y-y)), z+(p_t * (p_b.z-z)) ); - } - - real_t Vector3::distance_to(const Vector3& p_b) const { + return (p_b-*this).length(); } + real_t Vector3::distance_squared_to(const Vector3& p_b) const { - return (p_b-*this).length_squared(); + return (p_b-*this).length_squared(); +} + +real_t Vector3::angle_to(const Vector3& p_b) const { + + return Math::acos(this->dot(p_b) / Math::sqrt(this->length_squared() * p_b.length_squared())); } /* Operators */ Vector3& Vector3::operator+=(const Vector3& p_v) { - x+=p_v.x; - y+=p_v.y; - z+=p_v.z; - return *this; + x+=p_v.x; + y+=p_v.y; + z+=p_v.z; + return *this; } + Vector3 Vector3::operator+(const Vector3& p_v) const { - return Vector3(x+p_v.x, y+p_v.y, z+ p_v.z); + return Vector3(x+p_v.x, y+p_v.y, z+ p_v.z); } Vector3& Vector3::operator-=(const Vector3& p_v) { - x-=p_v.x; - y-=p_v.y; - z-=p_v.z; - return *this; + x-=p_v.x; + y-=p_v.y; + z-=p_v.z; + return *this; } Vector3 Vector3::operator-(const Vector3& p_v) const { - return Vector3(x-p_v.x, y-p_v.y, z- p_v.z); + return Vector3(x-p_v.x, y-p_v.y, z- p_v.z); } - - Vector3& Vector3::operator*=(const Vector3& p_v) { - x*=p_v.x; - y*=p_v.y; - z*=p_v.z; - return *this; + x*=p_v.x; + y*=p_v.y; + z*=p_v.z; + return *this; } Vector3 Vector3::operator*(const Vector3& p_v) const { - return Vector3(x*p_v.x, y*p_v.y, z* p_v.z); + return Vector3(x*p_v.x, y*p_v.y, z* p_v.z); } Vector3& Vector3::operator/=(const Vector3& p_v) { - x/=p_v.x; - y/=p_v.y; - z/=p_v.z; - return *this; + x/=p_v.x; + y/=p_v.y; + z/=p_v.z; + return *this; } + Vector3 Vector3::operator/(const Vector3& p_v) const { - return Vector3(x/p_v.x, y/p_v.y, z/ p_v.z); + return Vector3(x/p_v.x, y/p_v.y, z/ p_v.z); } Vector3& Vector3::operator*=(real_t p_scalar) { - x*=p_scalar; - y*=p_scalar; - z*=p_scalar; - return *this; + x*=p_scalar; + y*=p_scalar; + z*=p_scalar; + return *this; } _FORCE_INLINE_ Vector3 operator*(real_t p_scalar, const Vector3& p_vec) { + return p_vec * p_scalar; } Vector3 Vector3::operator*(real_t p_scalar) const { - return Vector3( x*p_scalar, y*p_scalar, z*p_scalar); + return Vector3( x*p_scalar, y*p_scalar, z*p_scalar); } Vector3& Vector3::operator/=(real_t p_scalar) { - x/=p_scalar; - y/=p_scalar; - z/=p_scalar; - return *this; + x/=p_scalar; + y/=p_scalar; + z/=p_scalar; + return *this; } Vector3 Vector3::operator/(real_t p_scalar) const { - return Vector3( x/p_scalar, y/p_scalar, z/p_scalar); + return Vector3( x/p_scalar, y/p_scalar, z/p_scalar); } Vector3 Vector3::operator-() const { - return Vector3( -x, -y, -z ); + return Vector3( -x, -y, -z ); } - bool Vector3::operator==(const Vector3& p_v) const { - return (x==p_v.x && y==p_v.y && z==p_v.z); + return (x==p_v.x && y==p_v.y && z==p_v.z); } bool Vector3::operator!=(const Vector3& p_v) const { - return (x!=p_v.x || y!=p_v.y || z!=p_v.z); + return (x!=p_v.x || y!=p_v.y || z!=p_v.z); } bool Vector3::operator<(const Vector3& p_v) const { @@ -298,9 +304,9 @@ bool Vector3::operator<(const Vector3& p_v) const { return zdot(p_vec); } + Vector3 Vector3::reflect(const Vector3& p_vec) const { return p_vec - *this * this->dot(p_vec) * 2.0; - } #endif diff --git a/core/object.cpp b/core/object.cpp index 8cd4e070977..9a1e9be8d5f 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1215,6 +1215,15 @@ void Object::emit_signal(const StringName& p_name,const Variant** p_args,int p_a Signal *s = signal_map.getptr(p_name); if (!s) { +#ifdef DEBUG_ENABLED + bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_name); + //check in script + if (!signal_is_valid && !script.is_null() && !Ref