diff options
Diffstat (limited to 'core')
229 files changed, 3040 insertions, 1582 deletions
diff --git a/core/allocators.h b/core/allocators.h index 42eb4effaf..16e516e87b 100644 --- a/core/allocators.h +++ b/core/allocators.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/array.cpp b/core/array.cpp index 728ea5941c..ab9f19d6a0 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/array.h b/core/array.h index 0b8240558f..904309b257 100644 --- a/core/array.h +++ b/core/array.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/balloon_allocator.h b/core/balloon_allocator.h index d99f805f52..177c744669 100644 --- a/core/balloon_allocator.h +++ b/core/balloon_allocator.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 5839467388..95cafdb36d 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -5,7 +5,7 @@ #include "io/base64.h" #include "core/globals.h" #include "io/file_access_encrypted.h" - +#include "os/keyboard.h" _ResourceLoader *_ResourceLoader::singleton=NULL; Ref<ResourceInteractiveLoader> _ResourceLoader::load_interactive(const String& p_path,const String& p_type_hint) { @@ -457,9 +457,9 @@ void _OS::set_icon(const Image& p_icon) { OS::get_singleton()->set_icon(p_icon); } -Dictionary _OS::get_date() const { +Dictionary _OS::get_date(bool utc) const { - OS::Date date = OS::get_singleton()->get_date(); + OS::Date date = OS::get_singleton()->get_date(utc); Dictionary dated; dated["year"]=date.year; dated["month"]=date.month; @@ -470,9 +470,9 @@ Dictionary _OS::get_date() const { } -Dictionary _OS::get_time() const { +Dictionary _OS::get_time(bool utc) const { - OS::Time time = OS::get_singleton()->get_time(); + OS::Time time = OS::get_singleton()->get_time(utc); Dictionary timed; timed["hour"]=time.hour; timed["minute"]=time.min; @@ -480,6 +480,15 @@ Dictionary _OS::get_time() const { return timed; } + +Dictionary _OS::get_time_zone_info() const { + OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info(); + Dictionary infod; + infod["bias"] = info.bias; + infod["name"] = info.name; + return infod; +} + uint64_t _OS::get_unix_time() const { return OS::get_singleton()->get_unix_time(); @@ -500,6 +509,10 @@ uint32_t _OS::get_ticks_msec() const { return OS::get_singleton()->get_ticks_msec(); } +uint32_t _OS::get_splash_tick_msec() const { + + return OS::get_singleton()->get_splash_tick_msec(); +} bool _OS::can_use_threads() const { @@ -690,6 +703,20 @@ String _OS::get_custom_level() const { return OS::get_singleton()->get_custom_level(); } + +String _OS::get_scancode_string(uint32_t p_code) const { + + return keycode_get_string(p_code); +} +bool _OS::is_scancode_unicode(uint32_t p_unicode) const { + + return keycode_has_unicode(p_unicode); +} +int _OS::find_scancode_from_string(const String& p_code) const { + + return find_keycode(p_code); +} + _OS *_OS::singleton=NULL; void _OS::_bind_methods() { @@ -709,13 +736,13 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); ObjectTypeDB::bind_method(_MD("get_current_screen"),&_OS::get_current_screen); - ObjectTypeDB::bind_method(_MD("set_current_screen"),&_OS::set_current_screen); - ObjectTypeDB::bind_method(_MD("get_screen_position"),&_OS::get_screen_position,DEFVAL(0)); - ObjectTypeDB::bind_method(_MD("get_screen_size"),&_OS::get_screen_size,DEFVAL(0)); + ObjectTypeDB::bind_method(_MD("set_current_screen","screen"),&_OS::set_current_screen); + ObjectTypeDB::bind_method(_MD("get_screen_position","screen"),&_OS::get_screen_position,DEFVAL(0)); + ObjectTypeDB::bind_method(_MD("get_screen_size","screen"),&_OS::get_screen_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); - ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); + ObjectTypeDB::bind_method(_MD("set_window_position","position"),&_OS::set_window_position); ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size); - ObjectTypeDB::bind_method(_MD("set_window_size"),&_OS::set_window_size); + ObjectTypeDB::bind_method(_MD("set_window_size","size"),&_OS::set_window_size); ObjectTypeDB::bind_method(_MD("set_window_fullscreen","enabled"),&_OS::set_window_fullscreen); ObjectTypeDB::bind_method(_MD("is_window_fullscreen"),&_OS::is_window_fullscreen); ObjectTypeDB::bind_method(_MD("set_window_resizable","enabled"),&_OS::set_window_resizable); @@ -756,8 +783,9 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_cmdline_args"),&_OS::get_cmdline_args); ObjectTypeDB::bind_method(_MD("get_main_loop"),&_OS::get_main_loop); - ObjectTypeDB::bind_method(_MD("get_date"),&_OS::get_date); - ObjectTypeDB::bind_method(_MD("get_time"),&_OS::get_time); + ObjectTypeDB::bind_method(_MD("get_date","utc"),&_OS::get_date,DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("get_time","utc"),&_OS::get_time,DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("get_time_zone_info"),&_OS::get_time_zone_info); ObjectTypeDB::bind_method(_MD("get_unix_time"),&_OS::get_unix_time); ObjectTypeDB::bind_method(_MD("set_icon"),&_OS::set_icon); @@ -765,6 +793,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("delay_usec","usec"),&_OS::delay_usec); ObjectTypeDB::bind_method(_MD("delay_msec","msec"),&_OS::delay_msec); ObjectTypeDB::bind_method(_MD("get_ticks_msec"),&_OS::get_ticks_msec); + ObjectTypeDB::bind_method(_MD("get_splash_tick_msec"),&_OS::get_splash_tick_msec); ObjectTypeDB::bind_method(_MD("get_locale"),&_OS::get_locale); ObjectTypeDB::bind_method(_MD("get_model_name"),&_OS::get_model_name); @@ -805,6 +834,9 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("native_video_stop"),&_OS::native_video_stop); ObjectTypeDB::bind_method(_MD("native_video_pause"),&_OS::native_video_pause); + ObjectTypeDB::bind_method(_MD("get_scancode_string","code"),&_OS::get_scancode_string); + ObjectTypeDB::bind_method(_MD("is_scancode_unicode","code"),&_OS::is_scancode_unicode); + ObjectTypeDB::bind_method(_MD("find_scancode_from_string","string"),&_OS::find_scancode_from_string); ObjectTypeDB::bind_method(_MD("set_use_file_access_save_and_swap","enabled"),&_OS::set_use_file_access_save_and_swap); @@ -1646,12 +1678,89 @@ Variant _Marshalls::base64_to_variant(const String& p_str) { return v; }; +String _Marshalls::raw_to_base64(const DVector<uint8_t> &p_arr) { + + int len = p_arr.size(); + DVector<uint8_t>::Read r = p_arr.read(); + + int b64len = len / 3 * 4 + 4 + 1; + DVector<uint8_t> b64buff; + b64buff.resize(b64len); + DVector<uint8_t>::Write w64 = b64buff.write(); + + int strlen = base64_encode((char*)(&w64[0]), (char*)(&r[0]), len); + w64[strlen] = 0; + String ret = (char*)&w64[0]; + + return ret; +}; + +DVector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) { + + int strlen = p_str.length(); + CharString cstr = p_str.ascii(); + + int arr_len; + DVector<uint8_t> buf; + { + buf.resize(strlen / 4 * 3 + 1); + DVector<uint8_t>::Write w = buf.write(); + + arr_len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen); + }; + buf.resize(arr_len); + + // conversion from DVector<uint8_t> to raw array? + return buf; +}; + +String _Marshalls::utf8_to_base64(const String& p_str) { + + CharString cstr = p_str.utf8(); + int len = cstr.length(); + + int b64len = len / 3 * 4 + 4 + 1; + DVector<uint8_t> b64buff; + b64buff.resize(b64len); + DVector<uint8_t>::Write w64 = b64buff.write(); + + int strlen = base64_encode((char*)(&w64[0]), (char*)cstr.get_data(), len); + + w64[strlen] = 0; + String ret = (char*)&w64[0]; + + return ret; +}; + +String _Marshalls::base64_to_utf8(const String& p_str) { + + int strlen = p_str.length(); + CharString cstr = p_str.ascii(); + + DVector<uint8_t> buf; + buf.resize(strlen / 4 * 3 + 1 + 1); + DVector<uint8_t>::Write w = buf.write(); + + int len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen); + + w[len] = 0; + String ret = String::utf8((char*)&w[0]); + + return ret; +}; + void _Marshalls::_bind_methods() { ObjectTypeDB::bind_method(_MD("variant_to_base64:String","variant"),&_Marshalls::variant_to_base64); ObjectTypeDB::bind_method(_MD("base64_to_variant:Variant","base64_str"),&_Marshalls::base64_to_variant); + ObjectTypeDB::bind_method(_MD("raw_to_base64:String","array"),&_Marshalls::raw_to_base64); + ObjectTypeDB::bind_method(_MD("base64_to_raw:RawArray","base64_str"),&_Marshalls::base64_to_raw); + + ObjectTypeDB::bind_method(_MD("utf8_to_base64:String","utf8_str"),&_Marshalls::utf8_to_base64); + ObjectTypeDB::bind_method(_MD("base64_to_utf8:String","base64_str"),&_Marshalls::base64_to_utf8); + }; @@ -1735,9 +1844,12 @@ _Mutex::~_Mutex(){ void _Thread::_start_func(void *ud) { - _Thread *t=(_Thread*)ud; + Ref<_Thread>* tud=(Ref<_Thread>*)ud; + Ref<_Thread> t=*tud; + memdelete(tud); Variant::CallError ce; const Variant* arg[1]={&t->userdata}; + t->ret=t->target_instance->call(t->target_method,arg,1,ce); if (ce.error!=Variant::CallError::CALL_OK) { @@ -1762,6 +1874,7 @@ void _Thread::_start_func(void *ud) { default: {} } + ERR_EXPLAIN("Could not call function '"+t->target_method.operator String()+"'' starting thread ID: "+t->get_id()+" Reason: "+reason); ERR_FAIL(); } @@ -1782,9 +1895,11 @@ Error _Thread::start(Object *p_instance,const StringName& p_method,const Variant userdata=p_userdata; active=true; + Ref<_Thread> *ud = memnew( Ref<_Thread>(this) ); + Thread::Settings s; s.priority=(Thread::Priority)p_priority; - thread = Thread::create(_start_func,this,s); + thread = Thread::create(_start_func,ud,s); if (!thread) { active=false; target_method=StringName(); @@ -1845,5 +1960,8 @@ _Thread::_Thread() { _Thread::~_Thread() { + if (active) { + ERR_EXPLAIN("Reference to a Thread object object was lost while the thread is still running.."); + } ERR_FAIL_COND(active==true); } diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index f3601e35fb..83f9e533ea 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -178,6 +178,11 @@ public: String get_unique_ID() const; + String get_scancode_string(uint32_t p_code) const; + bool is_scancode_unicode(uint32_t p_unicode) const; + int find_scancode_from_string(const String& p_code) const; + + /* struct Date { @@ -199,8 +204,9 @@ public: void set_use_file_access_save_and_swap(bool p_enable); void set_icon(const Image& p_icon); - Dictionary get_date() const; - Dictionary get_time() const; + Dictionary get_date(bool utc) const; + Dictionary get_time(bool utc) const; + Dictionary get_time_zone_info() const; uint64_t get_unix_time() const; int get_static_memory_usage() const; @@ -210,6 +216,7 @@ public: void delay_usec(uint32_t p_usec) const; void delay_msec(uint32_t p_msec) const; uint32_t get_ticks_msec() const; + uint32_t get_splash_tick_msec() const; bool can_use_threads() const; @@ -429,6 +436,12 @@ public: String variant_to_base64(const Variant& p_var); Variant base64_to_variant(const String& p_str); + String raw_to_base64(const DVector<uint8_t>& p_arr); + DVector<uint8_t> base64_to_raw(const String& p_str); + + String utf8_to_base64(const String& p_str); + String base64_to_utf8(const String& p_str); + _Marshalls() {}; }; diff --git a/core/color.cpp b/core/color.cpp index 3116c33a31..32f3df6d4b 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -161,7 +161,7 @@ void Color::invert() { r=1.0-r; g=1.0-g; - g=1.0-b; + b=1.0-b; } void Color::contrast() { diff --git a/core/color.h b/core/color.h index 491c72d449..d5d5a4ea09 100644 --- a/core/color.h +++ b/core/color.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index 78151b858f..f28617b33c 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index 8b74b3b561..113199869b 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -34,6 +34,7 @@ #include "os/mutex.h" #include "os/memory.h" #include "simple_type.h" +#include "print_string.h" /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -174,7 +175,7 @@ class CommandQueueMT { R* ret; SyncSemaphore *sync; - virtual void call() { *ret = (instance->*method)(p1); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { *ret = (instance->*method)(p1); sync->sem->post(); print_line("post"); sync->in_use=false; ; } }; template<class T,class M,class P1,class P2,class R> @@ -675,6 +676,7 @@ public: if (sync) sync->post(); ss->sem->wait(); + print_line("wait"); } template<class T, class M, class P1, class P2,class R> diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp index 0c97f459f8..45fd4b5080 100644 --- a/core/compressed_translation.cpp +++ b/core/compressed_translation.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/compressed_translation.h b/core/compressed_translation.h index a0b94116de..c41e2afb53 100644 --- a/core/compressed_translation.h +++ b/core/compressed_translation.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp index 75cb48137b..d0cd19768f 100644 --- a/core/core_string_names.cpp +++ b/core/core_string_names.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -42,6 +42,7 @@ CoreStringNames::CoreStringNames() { _iter_init=StaticCString::create("_iter_init"); _iter_next=StaticCString::create("_iter_next"); _iter_get=StaticCString::create("_iter_get"); + get_rid=StaticCString::create("get_rid"); } diff --git a/core/core_string_names.h b/core/core_string_names.h index e2982acc1a..8bda1f3f79 100644 --- a/core/core_string_names.h +++ b/core/core_string_names.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -56,6 +56,7 @@ public: StringName _iter_init; StringName _iter_next; StringName _iter_get; + StringName get_rid; }; diff --git a/core/dictionary.cpp b/core/dictionary.cpp index 2d503bae50..b2d31f230d 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/dictionary.h b/core/dictionary.h index de5be0fc6b..8cbabfc65d 100644 --- a/core/dictionary.h +++ b/core/dictionary.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/dvector.cpp b/core/dvector.cpp index e0a378a427..60aa2e079f 100644 --- a/core/dvector.cpp +++ b/core/dvector.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/dvector.h b/core/dvector.h index 29be417844..2c75bbf9eb 100644 --- a/core/dvector.h +++ b/core/dvector.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/error_list.h b/core/error_list.h index 2127938769..124027172e 100644 --- a/core/error_list.h +++ b/core/error_list.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/error_macros.cpp b/core/error_macros.cpp index bd08cbb2f5..53bce56626 100644 --- a/core/error_macros.cpp +++ b/core/error_macros.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/error_macros.h b/core/error_macros.h index 6cd38755c0..18b08d8e0e 100644 --- a/core/error_macros.h +++ b/core/error_macros.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/event_queue.cpp b/core/event_queue.cpp index 161fb4fedd..1afd686f86 100644 --- a/core/event_queue.cpp +++ b/core/event_queue.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/event_queue.h b/core/event_queue.h index 0647c02777..51ed7373eb 100644 --- a/core/event_queue.h +++ b/core/event_queue.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/fpstr.cpp b/core/fpstr.cpp index 25784adb15..20b527d88b 100644 --- a/core/fpstr.cpp +++ b/core/fpstr.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/fpstr.h b/core/fpstr.h index d07ae7d5a2..c8ff80806e 100644 --- a/core/fpstr.h +++ b/core/fpstr.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/global_constants.cpp b/core/global_constants.cpp index fc48a105db..b8d113f67c 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/global_constants.h b/core/global_constants.h index cd8304bd45..77cd3724c6 100644 --- a/core/global_constants.h +++ b/core/global_constants.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/globals.cpp b/core/globals.cpp index a39ace7360..731c5b7dff 100644 --- a/core/globals.cpp +++ b/core/globals.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -339,7 +339,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) { //try to load settings in ascending through dirs shape! //tries to open pack, but only first time - if (first_time && _load_resource_pack(current_dir+"/data.pck")) { + if (first_time && (_load_resource_pack(current_dir+"/data.pck") || _load_resource_pack(current_dir+"/data.pcz") )) { if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { _load_settings("res://override.cfg"); @@ -1149,6 +1149,12 @@ Error Globals::_save_settings_text(const String& p_file,const Map<String,List<St return OK; } + +Error Globals::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array? + + return save_custom(p_file); +}; + Error Globals::save_custom(const String& p_path,const CustomMap& p_custom,const Set<String>& p_ignore_masks) { ERR_FAIL_COND_V(p_path=="",ERR_INVALID_PARAMETER); @@ -1321,7 +1327,7 @@ Vector<String> Globals::get_optimizer_presets() const { if (!E->get().name.begins_with("optimizer_presets/")) continue; - names.push_back(E->get().name.get_slice("/",1)); + names.push_back(E->get().name.get_slicec('/',1)); } names.sort(); @@ -1361,6 +1367,9 @@ void Globals::_bind_methods() { ObjectTypeDB::bind_method(_MD("has_singleton"),&Globals::has_singleton); ObjectTypeDB::bind_method(_MD("get_singleton"),&Globals::get_singleton_object); ObjectTypeDB::bind_method(_MD("load_resource_pack"),&Globals::_load_resource_pack); + + ObjectTypeDB::bind_method(_MD("save_custom"),&Globals::_save_custom_bnd); + } Globals::Globals() { @@ -1381,7 +1390,7 @@ Globals::Globals() { set("application/name","" ); set("application/main_scene",""); - custom_prop_info["application/main_scene"]=PropertyInfo(Variant::STRING,"application/main_scene",PROPERTY_HINT_FILE,"xml,res,scn,xscn"); + custom_prop_info["application/main_scene"]=PropertyInfo(Variant::STRING,"application/main_scene",PROPERTY_HINT_FILE,"scn,res,xscn,xml"); set("application/disable_stdout",false); set("application/use_shared_user_dir",true); @@ -1397,6 +1406,13 @@ Globals::Globals() { set("input/ui_accept",va); va=Array(); + key.key.scancode=KEY_SPACE; + va.push_back(key); + joyb.joy_button.button_index=JOY_BUTTON_3; + va.push_back(joyb); + set("input/ui_select",va); + + va=Array(); key.key.scancode=KEY_ESCAPE; va.push_back(key); joyb.joy_button.button_index=JOY_BUTTON_1; @@ -1460,6 +1476,7 @@ Globals::Globals() { custom_prop_info["display/orientation"]=PropertyInfo(Variant::STRING,"display/orientation",PROPERTY_HINT_ENUM,"landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor"); custom_prop_info["render/mipmap_policy"]=PropertyInfo(Variant::INT,"render/mipmap_policy",PROPERTY_HINT_ENUM,"Allow,Allow For Po2,Disallow"); custom_prop_info["render/thread_model"]=PropertyInfo(Variant::INT,"render/thread_model",PROPERTY_HINT_ENUM,"Single-Unsafe,Single-Safe,Multi-Threaded"); + custom_prop_info["physics_2d/thread_model"]=PropertyInfo(Variant::INT,"physics_2d/thread_model",PROPERTY_HINT_ENUM,"Single-Unsafe,Single-Safe,Multi-Threaded"); set("display/emulate_touchscreen",false); using_datapack=false; diff --git a/core/globals.h b/core/globals.h index 580fd0fecd..2ec56966f6 100644 --- a/core/globals.h +++ b/core/globals.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -86,6 +86,7 @@ protected: List<Singleton> singletons; + Error _save_custom_bnd(const String& p_file); bool _load_resource_pack(const String& p_pack); diff --git a/core/hash_map.h b/core/hash_map.h index da8f038490..eea6d1a153 100644 --- a/core/hash_map.h +++ b/core/hash_map.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/hashfuncs.h b/core/hashfuncs.h index 3b6715a4cd..b12950f160 100644 --- a/core/hashfuncs.h +++ b/core/hashfuncs.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/image.cpp b/core/image.cpp index 17ee569b6b..c31fa47847 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -134,6 +134,18 @@ void Image::get_mipmap_offset_and_size(int p_mipmap,int &r_ofs, int &r_size) con } +void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap,int &r_ofs, int &r_size,int &w, int& h) const { + + + int ofs; + _get_mipmap_offset_and_size(p_mipmap,ofs,w,h); + int ofs2,w2,h2; + _get_mipmap_offset_and_size(p_mipmap+1,ofs2,w2,h2); + r_ofs=ofs; + r_size=ofs2-ofs; + +} + void Image::put_pixel(int p_x,int p_y, const Color& p_color,int p_mipmap){ ERR_FAIL_INDEX(p_mipmap,mipmaps+1); @@ -1004,10 +1016,10 @@ void Image::create( const char ** p_xpm ) { String line_str=line_ptr; line_str.replace("\t"," "); - size_width=line_str.get_slice(" ",0).to_int(); - size_height=line_str.get_slice(" ",1).to_int(); - colormap_size=line_str.get_slice(" ",2).to_int(); - pixelchars=line_str.get_slice(" ",3).to_int(); + size_width=line_str.get_slicec(' ',0).to_int(); + size_height=line_str.get_slicec(' ',1).to_int(); + colormap_size=line_str.get_slicec(' ',2).to_int(); + pixelchars=line_str.get_slicec(' ',3).to_int(); ERR_FAIL_COND(colormap_size > 32766); ERR_FAIL_COND(pixelchars > 5); ERR_FAIL_COND(size_width > 32767); @@ -1112,6 +1124,7 @@ void Image::create( const char ** p_xpm ) { } #define DETECT_ALPHA_MAX_TRESHOLD 254 #define DETECT_ALPHA_MIN_TRESHOLD 2 + #define DETECT_ALPHA( m_value )\ { \ uint8_t value=m_value;\ @@ -1124,6 +1137,82 @@ void Image::create( const char ** p_xpm ) { }\ } +#define DETECT_NON_ALPHA( m_value )\ +{ \ + uint8_t value=m_value;\ + if (value>0) {\ + \ + detected=true;\ + break;\ + }\ +} + + +bool Image::is_invisible() const { + + if (format==FORMAT_GRAYSCALE || + format==FORMAT_RGB || + format==FORMAT_INDEXED) + return false; + + int len = data.size(); + + if (len==0) + return true; + + if (format >= FORMAT_YUV_422 && format <= FORMAT_YUV_444) + return false; + + int w,h; + _get_mipmap_offset_and_size(1,len,w,h); + + DVector<uint8_t>::Read r = data.read(); + const unsigned char *data_ptr=r.ptr(); + + bool detected=false; + + switch(format) { + case FORMAT_INTENSITY: { + + for(int i=0;i<len;i++) { + DETECT_NON_ALPHA(data_ptr[i]); + } + } break; + case FORMAT_GRAYSCALE_ALPHA: { + + + for(int i=0;i<(len>>1);i++) { + DETECT_NON_ALPHA(data_ptr[(i<<1)+1]); + } + + } break; + case FORMAT_RGBA: { + + for(int i=0;i<(len>>2);i++) { + DETECT_NON_ALPHA(data_ptr[(i<<2)+3]) + } + + } break; + case FORMAT_INDEXED: { + + return false; + } break; + case FORMAT_INDEXED_ALPHA: { + + return false; + } break; + case FORMAT_PVRTC2_ALPHA: + case FORMAT_PVRTC4_ALPHA: + case FORMAT_BC2: + case FORMAT_BC3: { + detected=true; + } break; + default: {} + } + + return !detected; +} + Image::AlphaMode Image::detect_alpha() const { if (format==FORMAT_GRAYSCALE || @@ -1734,6 +1823,10 @@ Error Image::_decompress_bc() { return OK; } +bool Image::is_compressed() const { + return format>=FORMAT_BC1; +} + Image Image::decompressed() const { @@ -1986,7 +2079,7 @@ void Image::blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2& } -Image (*Image::_png_mem_loader_func)(const uint8_t*)=NULL; +Image (*Image::_png_mem_loader_func)(const uint8_t*,int)=NULL; void (*Image::_image_compress_bc_func)(Image *)=NULL; void (*Image::_image_compress_pvrtc2_func)(Image *)=NULL; void (*Image::_image_compress_pvrtc4_func)(Image *)=NULL; @@ -2155,7 +2248,7 @@ void Image::fix_alpha_edges() { } -Image::Image(const uint8_t* p_png) { +Image::Image(const uint8_t* p_png,int p_len) { width=0; height=0; @@ -2163,7 +2256,7 @@ Image::Image(const uint8_t* p_png) { format=FORMAT_GRAYSCALE; if (_png_mem_loader_func) { - *this = _png_mem_loader_func(p_png); + *this = _png_mem_loader_func(p_png,p_len); } } diff --git a/core/image.h b/core/image.h index f4c96703b9..8ce4f22dc1 100644 --- a/core/image.h +++ b/core/image.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -94,7 +94,7 @@ public: /* INTERPOLATE GAUSS */ }; - static Image (*_png_mem_loader_func)(const uint8_t* p_png); + static Image (*_png_mem_loader_func)(const uint8_t* p_png,int p_size); static void (*_image_compress_bc_func)(Image *); static void (*_image_compress_pvrtc2_func)(Image *); static void (*_image_compress_pvrtc4_func)(Image *); @@ -236,6 +236,7 @@ public: int get_mipmap_offset(int p_mipmap) const; //get where the mipmap begins in data void get_mipmap_offset_and_size(int p_mipmap,int &r_ofs, int &r_size) const; //get where the mipmap begins in data + void get_mipmap_offset_size_and_dimensions(int p_mipmap,int &r_ofs, int &r_size,int &w, int& h) const; //get where the mipmap begins in data /** * Resize the image, using the prefered interpolation method. @@ -304,6 +305,7 @@ public: }; AlphaMode detect_alpha() const; + bool is_invisible() const; void put_indexed_pixel(int p_x, int p_y, uint8_t p_idx,int p_mipmap=0); uint8_t get_indexed_pixel(int p_x, int p_y,int p_mipmap=0) const; @@ -334,6 +336,7 @@ public: Image compressed(int p_mode); /* from the Image::CompressMode enum */ Error decompress(); Image decompressed() const; + bool is_compressed() const; void fix_alpha_edges(); void premultiply_alpha(); @@ -348,7 +351,7 @@ public: Image get_rect(const Rect2& p_area) const; static void set_compress_bc_func(void (*p_compress_func)(Image *)); - Image(const uint8_t* p_mem_png); + Image(const uint8_t* p_mem_png, int p_len=-1); Image(const char **p_xpm); ~Image(); diff --git a/core/image_quantize.cpp b/core/image_quantize.cpp index d728a32861..a14e0ab72e 100644 --- a/core/image_quantize.cpp +++ b/core/image_quantize.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/input_map.cpp b/core/input_map.cpp index 9426b0568e..24151c59c9 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -42,7 +42,7 @@ void InputMap::_bind_methods() { ObjectTypeDB::bind_method(_MD("action_add_event","action","event"),&InputMap::action_add_event); ObjectTypeDB::bind_method(_MD("action_has_event","action","event"),&InputMap::action_has_event); ObjectTypeDB::bind_method(_MD("action_erase_event","action","event"),&InputMap::action_erase_event); - ObjectTypeDB::bind_method(_MD("get_action_list","action"),&InputMap::get_action_list); + ObjectTypeDB::bind_method(_MD("get_action_list","action"),&InputMap::_get_action_list); ObjectTypeDB::bind_method(_MD("event_is_action","event","action"),&InputMap::event_is_action); ObjectTypeDB::bind_method(_MD("load_from_globals"),&InputMap::load_from_globals); @@ -162,6 +162,22 @@ void InputMap::action_erase_event(const StringName& p_action,const InputEvent& p } + +Array InputMap::_get_action_list(const StringName& p_action) { + + Array ret; + const List<InputEvent> *al = get_action_list(p_action); + if (al) { + for(const List<InputEvent>::Element *E=al->front();E;E=E->next()) { + + ret.push_back(E->get());; + } + } + + return ret; + +} + const List<InputEvent> *InputMap::get_action_list(const StringName& p_action) { const Map<StringName, Action>::Element *E=input_map.find(p_action); @@ -176,7 +192,7 @@ bool InputMap::event_is_action(const InputEvent& p_event, const StringName& p_ac Map<StringName,Action >::Element *E=input_map.find(p_action); if(!E) { - ERR_EXPLAIN("Request for unexisting InputMap action: "+String(p_action)); + ERR_EXPLAIN("Request for nonexistent InputMap action: "+String(p_action)); ERR_FAIL_COND_V(!E,false); } diff --git a/core/input_map.h b/core/input_map.h index bf20645b15..c5b21b1457 100644 --- a/core/input_map.h +++ b/core/input_map.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -46,6 +46,8 @@ class InputMap : public Object { List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const; + Array _get_action_list(const StringName& p_action); + protected: static void _bind_methods(); diff --git a/core/int_types.h b/core/int_types.h index 31f05b2d35..231196b808 100644 --- a/core/int_types.h +++ b/core/int_types.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/compression.cpp b/core/io/compression.cpp index ea2f5d2d9c..0bc006b41e 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/compression.h b/core/io/compression.h index 70742d42d6..106a3f0201 100644 --- a/core/io/compression.h +++ b/core/io/compression.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,28 +26,28 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef COMPRESSION_H
-#define COMPRESSION_H
-
-#include "typedefs.h"
-
-class Compression
-{
-public:
-
- enum Mode {
- MODE_FASTLZ,
- MODE_DEFLATE
- };
-
-
- static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,Mode p_mode=MODE_FASTLZ);
- static int get_max_compressed_buffer_size(int p_src_size,Mode p_mode=MODE_FASTLZ);
- static void decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size,Mode p_mode=MODE_FASTLZ);
-
- Compression();
-};
-
-
-
-#endif // COMPRESSION_H
+#ifndef COMPRESSION_H +#define COMPRESSION_H + +#include "typedefs.h" + +class Compression +{ +public: + + enum Mode { + MODE_FASTLZ, + MODE_DEFLATE + }; + + + static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,Mode p_mode=MODE_FASTLZ); + static int get_max_compressed_buffer_size(int p_src_size,Mode p_mode=MODE_FASTLZ); + static void decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size,Mode p_mode=MODE_FASTLZ); + + Compression(); +}; + + + +#endif // COMPRESSION_H diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 17ee72f2eb..75388f514a 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -357,6 +357,7 @@ if (res!=-1 && res < min_pos) {\ } break; case MIN_OPEN: { int level=1; + end++; while(end<close_pos) { if (str[end]=='[') @@ -373,6 +374,7 @@ if (res!=-1 && res < min_pos) {\ } break; case MIN_CURLY_OPEN: { int level=1; + end++; while(end<close_pos) { if (str[end]=='{') diff --git a/core/io/config_file.h b/core/io/config_file.h index e132e46fea..608f143fb1 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp index 6927b3772f..ab17cb8118 100644 --- a/core/io/file_access_buffered.cpp +++ b/core/io/file_access_buffered.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h index 533cc6c7dd..e6de203cda 100644 --- a/core/io/file_access_buffered.h +++ b/core/io/file_access_buffered.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_buffered_fa.h b/core/io/file_access_buffered_fa.h index 5de2f66ace..d36c4843e4 100644 --- a/core/io/file_access_buffered_fa.h +++ b/core/io/file_access_buffered_fa.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index b90a41df54..1d06dc8c4b 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h index 3039b5c8be..69a03fa14f 100644 --- a/core/io/file_access_compressed.h +++ b/core/io/file_access_compressed.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,76 +26,76 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef FILE_ACCESS_COMPRESSED_H
-#define FILE_ACCESS_COMPRESSED_H
-
-#include "io/compression.h"
-#include "os/file_access.h"
-
-class FileAccessCompressed : public FileAccess {
-
- Compression::Mode cmode;
- bool writing;
- int write_pos;
- uint8_t*write_ptr;
- int write_buffer_size;
- int write_max;
- int block_size;
- mutable bool read_eof;
- mutable bool at_end;
-
- struct ReadBlock {
- int csize;
- int offset;
- };
-
- mutable Vector<uint8_t> comp_buffer;
- uint8_t *read_ptr;
- mutable int read_block;
- int read_block_count;
- mutable int read_block_size;
- mutable int read_pos;
- Vector<ReadBlock> read_blocks;
- int read_total;
-
-
-
-
- String magic;
- mutable Vector<uint8_t> buffer;
- FileAccess *f;
-public:
-
- void configure(const String& p_magic, Compression::Mode p_mode=Compression::MODE_FASTLZ, int p_block_size=4096);
-
- Error open_after_magic(FileAccess *p_base);
-
- virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file
- virtual void close(); ///< close a file
- virtual bool is_open() const; ///< true when file is open
-
- virtual void seek(size_t p_position); ///< seek to a given position
- virtual void seek_end(int64_t p_position=0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
- virtual size_t get_len() const; ///< get size of the file
-
- virtual bool eof_reached() const; ///< reading passed EOF
-
- virtual uint8_t get_8() const; ///< get a byte
- virtual int get_buffer(uint8_t *p_dst, int p_length) const;
-
- virtual Error get_error() const; ///< get last error
-
- virtual void store_8(uint8_t p_dest); ///< store a byte
-
- virtual bool file_exists(const String& p_name); ///< return true if a file exists
-
- virtual uint64_t _get_modified_time(const String& p_file);
-
-
- FileAccessCompressed();
- virtual ~FileAccessCompressed();
-
-};
-
-#endif // FILE_ACCESS_COMPRESSED_H
+#ifndef FILE_ACCESS_COMPRESSED_H +#define FILE_ACCESS_COMPRESSED_H + +#include "io/compression.h" +#include "os/file_access.h" + +class FileAccessCompressed : public FileAccess { + + Compression::Mode cmode; + bool writing; + int write_pos; + uint8_t*write_ptr; + int write_buffer_size; + int write_max; + int block_size; + mutable bool read_eof; + mutable bool at_end; + + struct ReadBlock { + int csize; + int offset; + }; + + mutable Vector<uint8_t> comp_buffer; + uint8_t *read_ptr; + mutable int read_block; + int read_block_count; + mutable int read_block_size; + mutable int read_pos; + Vector<ReadBlock> read_blocks; + int read_total; + + + + + String magic; + mutable Vector<uint8_t> buffer; + FileAccess *f; +public: + + void configure(const String& p_magic, Compression::Mode p_mode=Compression::MODE_FASTLZ, int p_block_size=4096); + + Error open_after_magic(FileAccess *p_base); + + virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file + virtual void close(); ///< close a file + virtual bool is_open() const; ///< true when file is open + + virtual void seek(size_t p_position); ///< seek to a given position + virtual void seek_end(int64_t p_position=0); ///< seek from the end of file + virtual size_t get_pos() const; ///< get position in the file + virtual size_t get_len() const; ///< get size of the file + + virtual bool eof_reached() const; ///< reading passed EOF + + virtual uint8_t get_8() const; ///< get a byte + virtual int get_buffer(uint8_t *p_dst, int p_length) const; + + virtual Error get_error() const; ///< get last error + + virtual void store_8(uint8_t p_dest); ///< store a byte + + virtual bool file_exists(const String& p_name); ///< return true if a file exists + + virtual uint64_t _get_modified_time(const String& p_file); + + + FileAccessCompressed(); + virtual ~FileAccessCompressed(); + +}; + +#endif // FILE_ACCESS_COMPRESSED_H diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index 29f27dcbda..65b1ca5207 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -5,10 +5,12 @@ #include "print_string.h" #define COMP_MAGIC 0x43454447 +#include "core/variant.h" +#include <stdio.h> Error FileAccessEncrypted::open_and_parse(FileAccess *p_base,const Vector<uint8_t>& p_key,Mode p_mode) { - print_line("open and parse!"); + //print_line("open and parse!"); ERR_FAIL_COND_V(file!=NULL,ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(p_key.size()!=32,ERR_INVALID_PARAMETER); diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index a1dd2e48bb..83da55fc61 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -39,7 +39,7 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) { if (!files) { files = memnew((Map<String, Vector<uint8_t> >)); - }; + } String name; if (Globals::get_singleton()) @@ -49,7 +49,7 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) { name = DirAccess::normalize_path(name); (*files)[name] = p_data; -}; +} void FileAccessMemory::cleanup() { @@ -57,13 +57,13 @@ void FileAccessMemory::cleanup() { return; memdelete(files); -}; +} FileAccess* FileAccessMemory::create() { return memnew(FileAccessMemory); -}; +} bool FileAccessMemory::file_exists(const String& p_name) { @@ -71,8 +71,16 @@ bool FileAccessMemory::file_exists(const String& p_name) { name = DirAccess::normalize_path(name); return files && (files->find(name) != NULL); -}; +} + +Error FileAccessMemory::open_custom(const uint8_t* p_data, int p_len) { + + data=(uint8_t*)p_data; + length=p_len; + pos=0; + return OK; +} Error FileAccessMemory::_open(const String& p_path, int p_mode_flags) { @@ -89,57 +97,57 @@ Error FileAccessMemory::_open(const String& p_path, int p_mode_flags) { pos = 0; return OK; -}; +} void FileAccessMemory::close() { data = NULL; -}; +} bool FileAccessMemory::is_open() const { return data != NULL; -}; +} void FileAccessMemory::seek(size_t p_position) { ERR_FAIL_COND(!data); pos = p_position; -}; +} void FileAccessMemory::seek_end(int64_t p_position) { ERR_FAIL_COND(!data); pos = length + p_position; -}; +} size_t FileAccessMemory::get_pos() const { ERR_FAIL_COND_V(!data, 0); return pos; -}; +} size_t FileAccessMemory::get_len() const { ERR_FAIL_COND_V(!data, 0); return length; -}; +} bool FileAccessMemory::eof_reached() const { return pos >= length; -}; +} uint8_t FileAccessMemory::get_8() const { - uint8_t ret; + uint8_t ret = 0; if (pos < length) { ret = data[pos]; - }; + } ++pos; return ret; -}; +} int FileAccessMemory::get_buffer(uint8_t *p_dst,int p_length) const { @@ -156,19 +164,19 @@ int FileAccessMemory::get_buffer(uint8_t *p_dst,int p_length) const { pos += p_length; return read; -}; +} Error FileAccessMemory::get_error() const { return pos >= length ? ERR_FILE_EOF : OK; -}; +} void FileAccessMemory::store_8(uint8_t p_byte) { ERR_FAIL_COND(!data); ERR_FAIL_COND(pos >= length); data[pos++] = p_byte; -}; +} void FileAccessMemory::store_buffer(const uint8_t *p_src,int p_length) { @@ -176,11 +184,11 @@ void FileAccessMemory::store_buffer(const uint8_t *p_src,int p_length) { int write = MIN(p_length, left); if (write < p_length) { WARN_PRINT("Writing less data than requested"); - }; + } copymem(&data[pos], p_src, write); pos += p_length; -}; +} FileAccessMemory::FileAccessMemory() { diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h index a02a022a4f..8c58a8a8ce 100644 --- a/core/io/file_access_memory.h +++ b/core/io/file_access_memory.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -44,6 +44,7 @@ public: static void register_file(String p_name, Vector<uint8_t> p_data); static void cleanup(); + virtual Error open_custom(const uint8_t* p_data, int p_len); ///< open a file virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file virtual void close(); ///< close a file virtual bool is_open() const; ///< true when file is open diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 26194040b0..850e055129 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -254,6 +254,7 @@ FileAccessNetworkClient::~FileAccessNetworkClient() { quit=true; sem->post(); Thread::wait_to_finish(thread); + memdelete(thread); } memdelete(blockrequest_mutex); diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h index f338bea43f..2190cdb0ea 100644 --- a/core/io/file_access_network.h +++ b/core/io/file_access_network.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index afbd7e3d46..339a6d0528 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -92,7 +92,9 @@ void PackedData::add_path(const String& pkg_path, const String& path, uint64_t o void PackedData::add_pack_source(PackSource *p_source) { - sources.push_back(p_source); + if (p_source != NULL) { + sources.push_back(p_source); + } }; PackedData *PackedData::singleton=NULL; @@ -107,6 +109,21 @@ PackedData::PackedData() { add_pack_source(memnew(PackedSourcePCK)); } +void PackedData::_free_packed_dirs(PackedDir *p_dir) { + + for (Map<String,PackedDir*>::Element *E=p_dir->subdirs.front();E;E=E->next()) + _free_packed_dirs(E->get()); + memdelete(p_dir); +} + +PackedData::~PackedData() { + + for(int i=0;i<sources.size();i++) { + memdelete(sources[i]); + } + _free_packed_dirs(root); +} + ////////////////////////////////////////////////////////////////// diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index 2d0cf5b32e..5bf5ad012c 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -96,6 +96,8 @@ private: static PackedData *singleton; bool disabled; + void _free_packed_dirs(PackedDir *p_dir); + public: void add_pack_source(PackSource* p_source); @@ -111,6 +113,7 @@ public: _FORCE_INLINE_ bool has_path(const String& p_path); PackedData(); + ~PackedData(); }; class PackSource { @@ -119,6 +122,7 @@ public: virtual bool try_open_pack(const String& p_path)=0; virtual FileAccess* get_file(const String& p_path, PackedData::PackedFile* p_file)=0; + virtual ~PackSource() {} }; class PackedSourcePCK : public PackSource { diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index 55c0dedad9..ab2eb3b3f2 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -31,6 +31,7 @@ #include "file_access_zip.h" #include "core/os/file_access.h" +#include "core/os/copymem.h" ZipArchive* ZipArchive::instance = NULL; @@ -103,9 +104,17 @@ static int godot_testerror(voidpf opaque, voidpf stream) { return f->get_error()!=OK?1:0; }; +static voidpf godot_alloc(voidpf opaque, uInt items, uInt size) { + return memalloc(items * size); }; +static void godot_free(voidpf opaque, voidpf address) { + + memfree(address); +}; + +}; // extern "C" void ZipArchive::close_handle(unzFile p_file) const { @@ -125,6 +134,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const { ERR_FAIL_COND_V(!f, NULL); zlib_filefunc_def io; + zeromem(&io, sizeof(io)); io.opaque = f; io.zopen_file = godot_open; @@ -136,9 +146,13 @@ unzFile ZipArchive::get_file_handle(String p_file) const { io.zclose_file = godot_close; io.zerror_file = godot_testerror; + io.alloc_mem = godot_alloc; + io.free_mem = godot_free; + unzFile pkg = unzOpen2(packages[file.package].filename.utf8().get_data(), &io); ERR_FAIL_COND_V(!pkg, NULL); - unzGoToFilePos(pkg, &file.file_pos); + int unz_err = unzGoToFilePos(pkg, &file.file_pos); + ERR_FAIL_COND_V(unz_err != UNZ_OK, NULL); if (unzOpenCurrentFile(pkg) != UNZ_OK) { unzClose(pkg); @@ -150,7 +164,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const { bool ZipArchive::try_open_pack(const String& p_name) { - printf("opening pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz")); + //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.extension().nocasecmp_to("zip") != 0 && p_name.extension().nocasecmp_to("pcz") != 0) return false; @@ -198,7 +212,8 @@ 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, 0, 0, md5, this); + PackedData::get_singleton()->add_path(p_name, 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) { unzGoToNextFile(zfile); diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index c7906018e9..24012660d2 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -325,7 +325,7 @@ Error HTTPClient::poll(){ if (i==0 && responses[i].begins_with("HTTP")) { - String num = responses[i].get_slice(" ",1); + String num = responses[i].get_slicec(' ',1); response_num=num.to_int(); } else { diff --git a/core/io/http_client.h b/core/io/http_client.h index d0ebaa4596..21281f38c5 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 180df8964b..d3390ae199 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/image_loader.h b/core/io/image_loader.h index 665cc0b460..ff972696ea 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 6ef6b31188..523f9f472b 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -183,7 +183,7 @@ void IP::erase_resolve_item(ResolverID p_id) { GLOBAL_LOCK_FUNCTION; - resolver->queue[p_id].status=IP::RESOLVER_STATUS_DONE; + resolver->queue[p_id].status=IP::RESOLVER_STATUS_NONE; } diff --git a/core/io/ip.h b/core/io/ip.h index 0181dc7d12..6f50a190e6 100644 --- a/core/io/ip.h +++ b/core/io/ip.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index a1400adbb6..ed5a45c9ef 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -47,7 +47,7 @@ IP_Address::IP_Address(const String& p_string) { } for(int i=0;i<4;i++) { - field[i]=p_string.get_slice(".",i).to_int(); + field[i]=p_string.get_slicec('.',i).to_int(); } } diff --git a/core/io/ip_address.h b/core/io/ip_address.h index 3cd8bb7733..e55f45a2d7 100644 --- a/core/io/ip_address.h +++ b/core/io/ip_address.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/json.cpp b/core/io/json.cpp index 88a23eb4cd..14890abd26 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/json.h b/core/io/json.h index d113d0e4ef..78b6303451 100644 --- a/core/io/json.h +++ b/core/io/json.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index c6c15af5e0..b0d24abfe3 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/marshalls.h b/core/io/marshalls.h index bb8d3b336a..df673debf5 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index b566ce4b7b..875cace368 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -36,7 +36,7 @@ PacketPeer::PacketPeer() { - + last_get_error=OK; } Error PacketPeer::get_packet_buffer(DVector<uint8_t> &r_buffer) const { @@ -108,10 +108,29 @@ Variant PacketPeer::_bnd_get_var() const { return var; }; +Error PacketPeer::_put_packet(const DVector<uint8_t> &p_buffer) { + return put_packet_buffer(p_buffer); +} +DVector<uint8_t> PacketPeer::_get_packet() const { + + DVector<uint8_t> raw; + last_get_error=get_packet_buffer(raw); + return raw; +} + +Error PacketPeer::_get_packet_error() const { + + return last_get_error; +} + + void PacketPeer::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_var"),&PacketPeer::_bnd_get_var); ObjectTypeDB::bind_method(_MD("put_var", "var:var"),&PacketPeer::put_var); + ObjectTypeDB::bind_method(_MD("get_packet"),&PacketPeer::_get_packet); + ObjectTypeDB::bind_method(_MD("put_packet:Error", "buffer"),&PacketPeer::_put_packet); + ObjectTypeDB::bind_method(_MD("get_packet_error:Error"),&PacketPeer::_get_packet_error); ObjectTypeDB::bind_method(_MD("get_available_packet_count"),&PacketPeer::get_available_packet_count); }; diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h index e9d6be4fb9..76d1eb22b5 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -41,6 +41,14 @@ class PacketPeer : public Reference { static void _bind_methods(); + + Error _put_packet(const DVector<uint8_t> &p_buffer); + DVector<uint8_t> _get_packet() const; + Error _get_packet_error() const; + + + mutable Error last_get_error; + public: virtual int get_available_packet_count() const=0; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index ead6984650..c6cf631de6 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -390,7 +390,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) { if (path.find("://")==-1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path(res_path.get_base_dir()+"/"+path); + path=Globals::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); } @@ -663,14 +663,18 @@ Error ResourceInteractiveLoaderBinary::poll(){ //maybe it is loaded already String path; + int subindex=0; if (!main) { path=internal_resources[s].path; - if (path.begins_with("local://")) - path=path.replace("local://",res_path+"::"); + if (path.begins_with("local://")) { + path=path.replace_first("local://",""); + subindex = path.to_int(); + path=res_path+"::"+path; + } @@ -709,6 +713,7 @@ Error ResourceInteractiveLoaderBinary::poll(){ RES res = RES( r ); r->set_path(path); + r->set_subindex(subindex); int pc = f->get_32(); @@ -861,7 +866,7 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { print_bl("minor: "+itos(ver_minor)); print_bl("format: "+itos(ver_format)); - if (ver_format<FORMAT_VERSION || ver_major>VERSION_MAJOR || (ver_major==VERSION_MAJOR && ver_minor>VERSION_MINOR)) { + if (ver_format<FORMAT_VERSION || ver_major>VERSION_MAJOR) { f->close(); ERR_EXPLAIN("File Format '"+itos(FORMAT_VERSION)+"."+itos(ver_major)+"."+itos(ver_minor)+"' is too new! Please upgrade to a a new engine version: "+local_path); @@ -968,7 +973,7 @@ String ResourceInteractiveLoaderBinary::recognize(FileAccess *p_f) { uint32_t ver_minor=f->get_32(); uint32_t ver_format=f->get_32(); - if (ver_format<FORMAT_VERSION || ver_major>VERSION_MAJOR || (ver_major==VERSION_MAJOR && ver_minor>VERSION_MINOR)) { + if (ver_format<FORMAT_VERSION || ver_major>VERSION_MAJOR) { f->close(); return ""; @@ -1434,14 +1439,14 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property, save_unicode_string(path); } else { - if (!resource_map.has(res)) { + if (!resource_set.has(res)) { f->store_32(OBJECT_EMPTY); ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?"); ERR_FAIL(); } f->store_32(OBJECT_INTERNAL_RESOURCE); - f->store_32(resource_map[res]); + f->store_32(res->get_subindex()); //internal resource } @@ -1598,7 +1603,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant& p_variant } - if (resource_map.has(res)) + if (resource_set.has(res)) return; List<PropertyInfo> property_list; @@ -1613,7 +1618,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant& p_variant } } - resource_map[ res ] = saved_resources.size(); + resource_set.insert(res); saved_resources.push_back(res); } break; @@ -1814,7 +1819,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_ Property p; p.name_idx=get_string_index(F->get().name); p.value=E->get()->get(F->get().name); - if (F->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && p.value.is_zero()) + if ((F->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && p.value.is_zero())||(F->get().usage&PROPERTY_USAGE_STORE_IF_NONONE && p.value.is_one()) ) continue; p.pi=F->get(); @@ -1846,11 +1851,42 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_ // save internal resource table f->store_32(saved_resources.size()); //amount of internal resources Vector<uint64_t> ofs_pos; + Set<int> used_indices; + + for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) { + + RES r = E->get(); + if (r->get_path()=="" || r->get_path().find("::")!=-1) { + + if (r->get_subindex()!=0) { + if (used_indices.has(r->get_subindex())) { + r->set_subindex(0); //repeated + } else { + used_indices.insert(r->get_subindex()); + } + } + } + + } + + for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) { + RES r = E->get(); if (r->get_path()=="" || r->get_path().find("::")!=-1) { - save_unicode_string("local://"+itos(ofs_pos.size())); + if (r->get_subindex()==0) { + int new_subindex=1; + if (used_indices.size()) { + new_subindex=used_indices.back()->get()+1; + } + + r->set_subindex(new_subindex); + used_indices.insert(new_subindex); + + } + + save_unicode_string("local://"+itos(r->get_subindex())); if (takeover_paths) { r->set_path(p_path+"::"+itos(ofs_pos.size()),true); } diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index cc26357bfb..da415d97a5 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -129,7 +129,7 @@ class ResourceFormatSaverBinaryInstance { int bin_meta_idx; FileAccess *f; String magic; - Map<RES,int> resource_map; + Set<RES> resource_set; Map<StringName,int> string_map; Vector<StringName> strings; diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp index 033b4d5e5a..b744cbf967 100644 --- a/core/io/resource_format_xml.cpp +++ b/core/io/resource_format_xml.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -309,6 +309,7 @@ Error ResourceInteractiveLoaderXML::_parse_array_element(Vector<char> &buff,bool buff_max++; buff.resize(buff_max); + buffptr=buff.ptr(); } @@ -458,7 +459,7 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) path=path.replace("local://",local_path+"::"); else if (path.find("://")==-1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path(local_path.get_base_dir()+"/"+path); + path=Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path)); } @@ -1206,47 +1207,47 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) r_v=Vector3( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double() ); } else if (type=="vector2") { r_v=Vector2( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double() ); } else if (type=="plane") { r_v=Plane( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ); } else if (type=="quaternion") { r_v=Quat( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ); } else if (type=="rect2") { r_v=Rect2( Vector2( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double() ), Vector2( - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ) ); @@ -1255,14 +1256,14 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) r_v=AABB( Vector3( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double() ), Vector3( - data.get_slice(",",3).to_double(), - data.get_slice(",",4).to_double(), - data.get_slice(",",5).to_double() + data.get_slicec(',',3).to_double(), + data.get_slicec(',',4).to_double(), + data.get_slicec(',',5).to_double() ) ); @@ -1271,7 +1272,7 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) Matrix32 m3; for (int i=0;i<3;i++) { for (int j=0;j<2;j++) { - m3.elements[i][j]=data.get_slice(",",i*2+j).to_double(); + m3.elements[i][j]=data.get_slicec(',',i*2+j).to_double(); } } r_v=m3; @@ -1281,7 +1282,7 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) Matrix3 m3; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { - m3.elements[i][j]=data.get_slice(",",i*3+j).to_double(); + m3.elements[i][j]=data.get_slicec(',',i*3+j).to_double(); } } r_v=m3; @@ -1291,24 +1292,24 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) Transform tr; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { - tr.basis.elements[i][j]=data.get_slice(",",i*3+j).to_double(); + tr.basis.elements[i][j]=data.get_slicec(',',i*3+j).to_double(); } } tr.origin=Vector3( - data.get_slice(",",9).to_double(), - data.get_slice(",",10).to_double(), - data.get_slice(",",11).to_double() + data.get_slicec(',',9).to_double(), + data.get_slicec(',',10).to_double(), + data.get_slicec(',',11).to_double() ); r_v=tr; } else if (type=="color") { r_v=Color( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ); } else if (type=="node_path") { @@ -1373,7 +1374,7 @@ Error ResourceInteractiveLoaderXML::poll() { if (res.is_null()) { if (ResourceLoader::get_abort_on_missing_resources()) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": editor exported unexisting resource at: "+path); + ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": editor exported nonexistent resource at: "+path); ERR_FAIL_V(error); } else { ResourceLoader::notify_load_error("Resource Not Found: "+path); @@ -1423,7 +1424,7 @@ Error ResourceInteractiveLoaderXML::poll() { if (path.find("://")==-1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path(local_path.get_base_dir()+"/"+path); + path=Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path)); } @@ -1432,7 +1433,7 @@ Error ResourceInteractiveLoaderXML::poll() { if (res.is_null()) { if (ResourceLoader::get_abort_on_missing_resources()) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> referenced unexisting resource at: "+path); + ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> referenced nonexistent resource at: "+path); ERR_FAIL_V(error); } else { ResourceLoader::notify_load_error("Resource Not Found: "+path); @@ -1465,6 +1466,7 @@ Error ResourceInteractiveLoaderXML::poll() { String type; String path; + int subres=0; if (!main) { //loading resource @@ -1475,11 +1477,15 @@ Error ResourceInteractiveLoaderXML::poll() { ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <resource> missing 'type' field."); ERR_FAIL_COND_V(!tag->args.has("type"),ERR_FILE_CORRUPT); path=tag->args["path"]; + error=OK; if (path.begins_with("local://")) { //built-in resource (but really external) - path=path.replace("local://",local_path+"::"); + + path=path.replace("local://",""); + subres=path.to_int(); + path=local_path+"::"+path; } @@ -1518,6 +1524,7 @@ Error ResourceInteractiveLoaderXML::poll() { res = RES( r ); if (path!="") r->set_path(path); + r->set_subindex(subres); //load properties @@ -1601,7 +1608,7 @@ void ResourceInteractiveLoaderXML::get_dependencies(FileAccess *f,List<String> * if (path.find("://")==-1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path(local_path.get_base_dir()+"/"+path); + path=Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path)); } if (path.ends_with("*")) { @@ -1667,10 +1674,10 @@ void ResourceInteractiveLoaderXML::open(FileAccess *p_f) { ERR_FAIL(); } - int major = version.get_slice(".",0).to_int(); - int minor = version.get_slice(".",1).to_int(); + int major = version.get_slicec('.',0).to_int(); + int minor = version.get_slicec('.',1).to_int(); - if (major>VERSION_MAJOR || (major==VERSION_MAJOR && minor>VERSION_MINOR)) { + if (major>VERSION_MAJOR) { error=ERR_FILE_UNRECOGNIZED; ResourceLoader::notify_load_error(local_path+": File Format '"+version+"' is too new. Please upgrade to a newer engine version."); @@ -1849,7 +1856,7 @@ void ResourceFormatSaverXMLInstance::escape(String& p_str) { p_str=p_str.replace(">","<"); p_str=p_str.replace("'","'"); p_str=p_str.replace("\"","""); - for (int i=1;i<32;i++) { + for (char i=1;i<32;i++) { char chr[2]={i,0}; const char hexn[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; @@ -2028,9 +2035,9 @@ void ResourceFormatSaverXMLInstance::write_property(const String& p_name,const V //internal resource ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?"); - ERR_FAIL_COND(!resource_map.has(res)); + ERR_FAIL_COND(!resource_set.has(res)); - params+=" path=\"local://"+itos(resource_map[res])+"\""; + params+=" path=\"local://"+itos(res->get_subindex())+"\""; } } break; @@ -2243,12 +2250,12 @@ void ResourceFormatSaverXMLInstance::write_property(const String& p_name,const V List<Variant> keys; dict.get_key_list(&keys); + keys.sort(); for(List<Variant>::Element *E=keys.front();E;E=E->next()) { //if (!_check_type(dict[E->get()])) // continue; - bool ok; write_property("",E->get(),&ok); ERR_CONTINUE(!ok); @@ -2438,16 +2445,17 @@ void ResourceFormatSaverXMLInstance::_find_resources(const Variant& p_variant,bo return; if (!p_main && (!bundle_resources ) && res->get_path().length() && res->get_path().find("::") == -1 ) { - external_resources.insert(res); + external_resources.push_back(res); return; } - if (resource_map.has(res)) + if (resource_set.has(res)) return; List<PropertyInfo> property_list; res->get_property_list( &property_list ); + property_list.sort(); List<PropertyInfo>::Element *I=property_list.front(); @@ -2464,7 +2472,7 @@ void ResourceFormatSaverXMLInstance::_find_resources(const Variant& p_variant,bo I=I->next(); } - resource_map[ res ] = resource_map.size(); //saved after, so the childs it needs are available when loaded + resource_set.insert( res ); //saved after, so the childs it needs are available when loaded saved_resources.push_back(res); } break; @@ -2525,7 +2533,7 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res enter_tag("resource_file","type=\""+p_resource->get_type()+"\" subresource_count=\""+itos(saved_resources.size()+external_resources.size())+"\" version=\""+itos(VERSION_MAJOR)+"."+itos(VERSION_MINOR)+"\" version_name=\""+VERSION_FULL_NAME+"\""); write_string("\n",false); - for(Set<RES>::Element *E=external_resources.front();E;E=E->next()) { + for(List<RES>::Element *E=external_resources.front();E;E=E->next()) { write_tabs(); String p = E->get()->get_path(); @@ -2535,12 +2543,27 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res write_string("\n",false); } + Set<int> used_indices; + for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) { + + RES res = E->get(); + if (E->next() && (res->get_path()=="" || res->get_path().find("::") != -1 )) { + + if (res->get_subindex()!=0) { + if (used_indices.has(res->get_subindex())) { + res->set_subindex(0); //repeated + } else { + used_indices.insert(res->get_subindex()); + } + } + } + } for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) { RES res = E->get(); - ERR_CONTINUE(!resource_map.has(res)); + ERR_CONTINUE(!resource_set.has(res)); bool main = (E->next()==NULL); write_tabs(); @@ -2550,7 +2573,18 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res else if (res->get_path().length() && res->get_path().find("::") == -1 ) enter_tag("resource","type=\""+res->get_type()+"\" path=\""+res->get_path()+"\""); //bundled else { - int idx = resource_map[res]; + + if (res->get_subindex()==0) { + int new_subindex=1; + if (used_indices.size()) { + new_subindex=used_indices.back()->get()+1; + } + + res->set_subindex(new_subindex); + used_indices.insert(new_subindex); + } + + int idx = res->get_subindex(); enter_tag("resource","type=\""+res->get_type()+"\" path=\"local://"+itos(idx)+"\""); if (takeover_paths) { res->set_path(p_path+"::"+itos(idx),true); @@ -2562,6 +2596,7 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res List<PropertyInfo> property_list; res->get_property_list(&property_list); +// property_list.sort(); for(List<PropertyInfo>::Element *PE = property_list.front();PE;PE=PE->next()) { @@ -2572,9 +2607,12 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res String name = PE->get().name; Variant value = res->get(name); - if (PE->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero()) + + + if ((PE->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero())||(PE->get().usage&PROPERTY_USAGE_STORE_IF_NONONE && value.is_one()) ) continue; + write_property(name,value); } diff --git a/core/io/resource_format_xml.h b/core/io/resource_format_xml.h index 40aaa01451..d5ba9eb800 100644 --- a/core/io/resource_format_xml.h +++ b/core/io/resource_format_xml.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -123,9 +123,9 @@ class ResourceFormatSaverXMLInstance { bool skip_editor; FileAccess *f; int depth; - Map<RES,int> resource_map; + Set<RES> resource_set; List<RES> saved_resources; - Set<RES> external_resources; + List<RES> external_resources; void enter_tag(const char* p_tag,const String& p_args=String()); void exit_tag(const char* p_tag); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index d2610d5d4f..22d89840ae 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -117,6 +117,7 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const Stri RES ResourceFormatLoader::load(const String &p_path,const String& p_original_path) { + String path=p_path; //or this must be implemented Ref<ResourceInteractiveLoader> ril = load_interactive(p_path); @@ -150,9 +151,13 @@ void ResourceFormatLoader::get_dependencies(const String& p_path,List<String> *p RES ResourceLoader::load(const String &p_path,const String& p_type_hint,bool p_no_cache) { - String local_path = Globals::get_singleton()->localize_path(p_path); + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); - local_path=find_complete_path(p_path,p_type_hint); + local_path=find_complete_path(local_path,p_type_hint); ERR_FAIL_COND_V(local_path=="",RES()); if (!p_no_cache && ResourceCache::has(local_path)) { @@ -209,7 +214,12 @@ RES ResourceLoader::load(const String &p_path,const String& p_type_hint,bool p_n Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p_path) { - String local_path = Globals::get_singleton()->localize_path(p_path); + + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); String extension=p_path.extension(); bool found=false; @@ -283,9 +293,13 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_ - String local_path = Globals::get_singleton()->localize_path(p_path); + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); - local_path=find_complete_path(p_path,p_type_hint); + local_path=find_complete_path(local_path,p_type_hint); ERR_FAIL_COND_V(local_path=="",Ref<ResourceInteractiveLoader>()); @@ -340,7 +354,13 @@ void ResourceLoader::add_resource_format_loader(ResourceFormatLoader *p_format_l void ResourceLoader::get_dependencies(const String& p_path,List<String> *p_dependencies) { - String local_path = Globals::get_singleton()->localize_path(p_path); + + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); + String remapped_path = PathRemap::get_singleton()->get_remap(local_path); String extension=remapped_path.extension(); @@ -359,7 +379,11 @@ void ResourceLoader::get_dependencies(const String& p_path,List<String> *p_depen String ResourceLoader::guess_full_filename(const String &p_path,const String& p_type) { - String local_path = Globals::get_singleton()->localize_path(p_path); + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); return find_complete_path(local_path,p_type); @@ -367,7 +391,12 @@ String ResourceLoader::guess_full_filename(const String &p_path,const String& p_ String ResourceLoader::get_resource_type(const String &p_path) { - String local_path = Globals::get_singleton()->localize_path(p_path); + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); + String remapped_path = PathRemap::get_singleton()->get_remap(local_path); String extension=remapped_path.extension(); diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index ab23158785..d25727f19f 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 598f517d76..fdb9a53f0d 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index e307668721..05cbe7f98e 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index 0eae660373..b00b462eb6 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h index 84552cfd3e..e83fc71b93 100644 --- a/core/io/stream_peer.h +++ b/core/io/stream_peer.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index f83c174084..c2343790ea 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index d447ded78b..0e37303516 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index bce9e19ae3..803df87086 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index fff00e5ce0..b59f3293d7 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index 0d42cebb41..c32b25c407 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/translation_loader_po.h b/core/io/translation_loader_po.h index 7a0c4e10dc..9d8ad97a29 100644 --- a/core/io/translation_loader_po.h +++ b/core/io/translation_loader_po.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index 1d69f8e5e7..1ff458f325 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h index 9debbf9e2f..418a8efa70 100644 --- a/core/io/xml_parser.h +++ b/core/io/xml_parser.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/zip_io.h b/core/io/zip_io.h index 798265cc48..c4b4d6b34d 100644 --- a/core/io/zip_io.h +++ b/core/io/zip_io.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/list.h b/core/list.h index ef30e43d21..6deb150ef6 100644 --- a/core/list.h +++ b/core/list.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/map.h b/core/map.h index 05abdc510e..e45c833bcb 100644 --- a/core/map.h +++ b/core/map.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index 576e4fa928..435df66aab 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/aabb.h b/core/math/aabb.h index 089d5d15f7..4781e5c263 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -110,17 +110,17 @@ public: inline bool AABB::intersects(const AABB& p_aabb) const { - if ( pos.x > (p_aabb.pos.x + p_aabb.size.x) ) + if ( pos.x >= (p_aabb.pos.x + p_aabb.size.x) ) return false; - if ( (pos.x+size.x) < p_aabb.pos.x ) + if ( (pos.x+size.x) <= p_aabb.pos.x ) return false; - if ( pos.y > (p_aabb.pos.y + p_aabb.size.y) ) + if ( pos.y >= (p_aabb.pos.y + p_aabb.size.y) ) return false; - if ( (pos.y+size.y) < p_aabb.pos.y ) + if ( (pos.y+size.y) <= p_aabb.pos.y ) return false; - if ( pos.z > (p_aabb.pos.z + p_aabb.size.z) ) + if ( pos.z >= (p_aabb.pos.z + p_aabb.size.z) ) return false; - if ( (pos.z+size.z) < p_aabb.pos.z ) + if ( (pos.z+size.z) <= p_aabb.pos.z ) return false; return true; diff --git a/core/math/bezier_curve.cpp b/core/math/bezier_curve.cpp index 2676804945..c9467a77e4 100644 --- a/core/math/bezier_curve.cpp +++ b/core/math/bezier_curve.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/bezier_curve.h b/core/math/bezier_curve.h index 6cc4c730db..de14d68987 100644 --- a/core/math/bezier_curve.h +++ b/core/math/bezier_curve.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp index 7f838b1215..d71b7551d9 100644 --- a/core/math/bsp_tree.cpp +++ b/core/math/bsp_tree.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h index 03bfd947cb..b980d9590b 100644 --- a/core/math/bsp_tree.h +++ b/core/math/bsp_tree.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index fbe5f8c741..f1afa33a4b 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h index 767236ea04..52b84f4870 100644 --- a/core/math/camera_matrix.h +++ b/core/math/camera_matrix.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/face3.cpp b/core/math/face3.cpp index 1adc95e4e9..354372df74 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/face3.h b/core/math/face3.h index 5a509299a2..eccbc78122 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index 2d525dd1ce..14adde74e7 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/geometry.h b/core/math/geometry.h index 4ad4db8523..b438b41d61 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index 3aaa539fbb..88717723ce 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -230,6 +230,23 @@ Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, co + Vector2 p0=p_pre_a; + Vector2 p1=*this; + Vector2 p2=p_b; + Vector2 p3=p_post_b; + + float t = p_t; + float t2 = t * t; + float t3 = t2 * t; + + Vector2 out; + out = 0.5f * ( ( p1 * 2.0f) + + ( -p0 + p2 ) * t + + ( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 + + ( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 ); + return out; + +/* float mu = p_t; float mu2 = mu*mu; @@ -239,7 +256,7 @@ Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, co Vector2 a3 = *this; return ( a0*mu*mu2 + a1*mu2 + a2*mu + a3 ); - +*/ /* float t = p_t; real_t t2 = t*t; @@ -605,9 +622,39 @@ float Matrix32::basis_determinant() const { } Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, float p_c) const { + + //extract parameters + Vector2 p1 = get_origin(); + Vector2 p2 = p_transform.get_origin(); + + real_t r1 = get_rotation(); + real_t r2 = p_transform.get_rotation(); + + Vector2 s1 = get_scale(); + Vector2 s2 = p_transform.get_scale(); + + //slerp rotation + Vector2 v1(Math::cos(r1), Math::sin(r1)); + Vector2 v2(Math::cos(r2), Math::sin(r2)); + + real_t dot = v1.dot(v2); + + dot = (dot < -1.0) ? -1.0 : ((dot > 1.0) ? 1.0 : dot); //clamp dot to [-1,1] + + Vector2 v; - - return Matrix32(); + if (dot > 0.9995) { + v = Vector2::linear_interpolate(v1, v2, p_c).normalized(); //linearly interpolate to avoid numerical precision issues + } else { + real_t angle = p_c*Math::acos(dot); + Vector2 v3 = (v2 - v1*dot).normalized(); + v = v1*Math::cos(angle) + v3*Math::sin(angle); + } + + //construct matrix + Matrix32 res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c)); + res.scale_basis(Vector2::linear_interpolate(s1, s2, p_c)); + return res; } Matrix32::operator String() const { diff --git a/core/math/math_2d.h b/core/math/math_2d.h index 5bc1b5f0be..5e6cefd114 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -214,18 +214,41 @@ struct Rect2 { float get_area() const { return size.width*size.height; } inline bool intersects(const Rect2& p_rect) const { - if ( pos.x > (p_rect.pos.x + p_rect.size.width) ) + if ( pos.x >= (p_rect.pos.x + p_rect.size.width) ) return false; - if ( (pos.x+size.width) < p_rect.pos.x ) + if ( (pos.x+size.width) <= p_rect.pos.x ) return false; - if ( pos.y > (p_rect.pos.y + p_rect.size.height) ) + if ( pos.y >= (p_rect.pos.y + p_rect.size.height) ) return false; - if ( (pos.y+size.height) < p_rect.pos.y ) + if ( (pos.y+size.height) <= p_rect.pos.y ) return false; return true; } + inline float distance_to(const Vector2& p_point) const { + + float dist = 1e20; + + if (p_point.x < pos.x) { + dist=MIN(dist,pos.x-p_point.x); + } + if (p_point.y < pos.y) { + dist=MIN(dist,pos.y-p_point.y); + } + if (p_point.x >= (pos.x+size.x) ) { + dist=MIN(p_point.x-(pos.x+size.x),dist); + } + if (p_point.y >= (pos.y+size.y) ) { + dist=MIN(p_point.y-(pos.y+size.y),dist); + } + + if (dist==1e20) + return 0; + else + return dist; + } + _FORCE_INLINE_ bool intersects_transformed(const Matrix32& p_xform, const Rect2& p_rect) const; bool intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos=NULL, Point2* r_normal=NULL) const; diff --git a/core/math/math_defs.cpp b/core/math/math_defs.cpp index ca43bc7ae3..51aaa6800e 100644 --- a/core/math/math_defs.cpp +++ b/core/math/math_defs.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,5 +26,5 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "math_defs.h"
-
+#include "math_defs.h" + diff --git a/core/math/math_defs.h b/core/math/math_defs.h index dd0390240a..7cb6c7f499 100644 --- a/core/math/math_defs.h +++ b/core/math/math_defs.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,35 +26,35 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef MATH_DEFS_H
-#define MATH_DEFS_H
-
-#define CMP_EPSILON 0.00001
-#define CMP_EPSILON2 (CMP_EPSILON*CMP_EPSILON)
-#define CMP_NORMALIZE_TOLERANCE 0.000001
-#define CMP_POINT_IN_PLANE_EPSILON 0.00001
-
-/**
- * "Real" is a type that will be translated to either floats or fixed depending
- * on the compilation setting
- */
-
-enum ClockDirection {
-
- CLOCKWISE,
- COUNTERCLOCKWISE
-};
-
-
-#ifdef REAL_T_IS_DOUBLE
-
-typedef double real_t;
-
-#else
-
-typedef float real_t;
-
-#endif
-
-
-#endif // MATH_DEFS_H
+#ifndef MATH_DEFS_H +#define MATH_DEFS_H + +#define CMP_EPSILON 0.00001 +#define CMP_EPSILON2 (CMP_EPSILON*CMP_EPSILON) +#define CMP_NORMALIZE_TOLERANCE 0.000001 +#define CMP_POINT_IN_PLANE_EPSILON 0.00001 + +/** + * "Real" is a type that will be translated to either floats or fixed depending + * on the compilation setting + */ + +enum ClockDirection { + + CLOCKWISE, + COUNTERCLOCKWISE +}; + + +#ifdef REAL_T_IS_DOUBLE + +typedef double real_t; + +#else + +typedef float real_t; + +#endif + + +#endif // MATH_DEFS_H diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index ad48ceaac0..3c94ac5bc7 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -36,8 +36,9 @@ uint32_t Math::default_seed=1; #define PHI 0x9e3779b9 -static uint32_t Q[4096], c = 362436; - +#if 0 +static uint32_t Q[4096]; +#endif uint32_t Math::rand_from_seed(uint32_t *seed) { @@ -48,8 +49,8 @@ uint32_t Math::rand_from_seed(uint32_t *seed) { s = 0x12345987; k = s / 127773; s = 16807 * (s - k * 127773) - 2836 * k; - if (s < 0) - s += 2147483647; +// if (s < 0) +// s += 2147483647; (*seed) = s; return (s & Math::RANDOM_MAX); #else @@ -269,7 +270,7 @@ bool Math::is_inf(double p_val) { uint32_t Math::larger_prime(uint32_t p_val) { - static const int primes[] = { + static const uint32_t primes[] = { 5, 13, 23, diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 6d43ed8e64..33175ed2fc 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp index ff62e7786b..10f1461fdc 100644 --- a/core/math/matrix3.cpp +++ b/core/math/matrix3.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/matrix3.h b/core/math/matrix3.h index f68703ca23..98feb2dbbd 100644 --- a/core/math/matrix3.h +++ b/core/math/matrix3.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/octree.h b/core/math/octree.h index b64ba381c0..84de388178 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/plane.cpp b/core/math/plane.cpp index 88c7be5f63..f9395a002a 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/plane.h b/core/math/plane.h index 608ec26926..604b880266 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/quat.cpp b/core/math/quat.cpp index 950a4756ad..e0c4b0793c 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/quat.h b/core/math/quat.h index 04901116b8..de4aedaeec 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index a417cdaddf..80ae0f04e1 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h index d7f056d366..cb486a0b6f 100644 --- a/core/math/quick_hull.h +++ b/core/math/quick_hull.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/transform.cpp b/core/math/transform.cpp index bb874facbd..a6f4f626cc 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/transform.h b/core/math/transform.h index b1a0ea1ab8..a992843d70 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 111ceca185..70cb639fc2 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,543 +26,543 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "triangle_mesh.h"
-#include "sort.h"
-
-
-
-int TriangleMesh::_create_bvh(BVH*p_bvh,BVH** p_bb,int p_from,int p_size,int p_depth,int&max_depth,int&max_alloc) {
-
-
- if (p_depth>max_depth) {
- max_depth=p_depth;
- }
-
- if (p_size==1) {
-
-
- return p_bb[p_from]-p_bvh;
- } else if (p_size==0) {
-
- return -1;
- }
-
-
- AABB aabb;
- aabb=p_bb[p_from]->aabb;
- for(int i=1;i<p_size;i++) {
-
- aabb.merge_with(p_bb[p_from+i]->aabb);
- }
-
- int li=aabb.get_longest_axis_index();
-
- switch(li) {
-
- case Vector3::AXIS_X: {
- SortArray<BVH*,BVHCmpX> sort_x;
- sort_x.nth_element(0,p_size,p_size/2,&p_bb[p_from]);
- //sort_x.sort(&p_bb[p_from],p_size);
- } break;
- case Vector3::AXIS_Y: {
- SortArray<BVH*,BVHCmpY> sort_y;
- sort_y.nth_element(0,p_size,p_size/2,&p_bb[p_from]);
- //sort_y.sort(&p_bb[p_from],p_size);
- } break;
- case Vector3::AXIS_Z: {
- SortArray<BVH*,BVHCmpZ> sort_z;
- sort_z.nth_element(0,p_size,p_size/2,&p_bb[p_from]);
- //sort_z.sort(&p_bb[p_from],p_size);
-
- } break;
- }
-
-
- int left = _create_bvh(p_bvh,p_bb,p_from,p_size/2,p_depth+1,max_depth,max_alloc);
- int right = _create_bvh(p_bvh,p_bb,p_from+p_size/2,p_size-p_size/2,p_depth+1,max_depth,max_alloc);
-
- int index=max_alloc++;
- BVH *_new = &p_bvh[index];
- _new->aabb=aabb;
- _new->center=aabb.pos+aabb.size*0.5;
- _new->face_index=-1;
- _new->left=left;
- _new->right=right;
-
- return index;
-
-}
-
-
-void TriangleMesh::create(const DVector<Vector3>& p_faces) {
-
- valid=false;
-
- int fc=p_faces.size();
- ERR_FAIL_COND(!fc || ((fc%3) != 0));
- fc/=3;
- triangles.resize(fc);
-
- bvh.resize(fc*3); //will never be larger than this (todo make better)
- DVector<BVH>::Write bw = bvh.write();
-
- {
-
- //create faces and indices and base bvh
- //except for the Set for repeated triangles, everything
- //goes in-place.
-
- DVector<Vector3>::Read r = p_faces.read();
- DVector<Triangle>::Write w = triangles.write();
- Map<Vector3,int> db;
-
- for(int i=0;i<fc;i++) {
-
- Triangle&f=w[i];
- const Vector3 *v=&r[i*3];
-
- for(int j=0;j<3;j++) {
-
- int vidx=-1;
- Vector3 vs=v[j].snapped(0.0001);
- Map<Vector3,int>::Element *E=db.find(vs);
- if (E) {
- vidx=E->get();
- } else {
- vidx=db.size();
- db[vs]=vidx;
- }
-
- f.indices[j]=vidx;
- if (j==0)
- bw[i].aabb.pos=vs;
- else
- bw[i].aabb.expand_to(vs);
- }
-
- f.normal=Face3(r[i*3+0],r[i*3+1],r[i*3+2]).get_plane().get_normal();
-
- bw[i].left=-1;
- bw[i].right=-1;
- bw[i].face_index=i;
- bw[i].center=bw[i].aabb.pos+bw[i].aabb.size*0.5;
- }
-
- vertices.resize(db.size());
- DVector<Vector3>::Write vw = vertices.write();
- for (Map<Vector3,int>::Element *E=db.front();E;E=E->next()) {
- vw[E->get()]=E->key();
- }
-
- }
-
- DVector<BVH*> bwptrs;
- bwptrs.resize(fc);
- DVector<BVH*>::Write bwp = bwptrs.write();
- for(int i=0;i<fc;i++) {
-
- bwp[i]=&bw[i];
- }
-
- max_depth=0;
- int max_alloc=fc;
- int max=_create_bvh(bw.ptr(),bwp.ptr(),0,fc,1,max_depth,max_alloc);
-
- bw=DVector<BVH>::Write(); //clearup
- bvh.resize(max_alloc); //resize back
-
- valid=true;
-
-}
-
-
-Vector3 TriangleMesh::get_area_normal(const AABB& p_aabb) const {
-
- uint32_t* stack = (uint32_t*)alloca(sizeof(int)*max_depth);
-
- enum {
- TEST_AABB_BIT=0,
- VISIT_LEFT_BIT=1,
- VISIT_RIGHT_BIT=2,
- VISIT_DONE_BIT=3,
- VISITED_BIT_SHIFT=29,
- NODE_IDX_MASK=(1<<VISITED_BIT_SHIFT)-1,
- VISITED_BIT_MASK=~NODE_IDX_MASK,
-
-
- };
-
- int n_count=0;
- Vector3 n;
-
- //for(int i=0;i<max_depth;i++)
- // stack[i]=0;
-
- int level=0;
-
- DVector<Triangle>::Read trianglesr = triangles.read();
- DVector<Vector3>::Read verticesr=vertices.read();
- DVector<BVH>::Read bvhr=bvh.read();
-
- const Triangle *triangleptr=trianglesr.ptr();
- const Vector3 *vertexptr=verticesr.ptr();
- int pos=bvh.size()-1;
- const BVH *bvhptr = bvhr.ptr();
-
- stack[0]=pos;
- while(true) {
-
- uint32_t node = stack[level]&NODE_IDX_MASK;
- const BVH &b = bvhptr[ node ];
- bool done=false;
-
- switch(stack[level]>>VISITED_BIT_SHIFT) {
- case TEST_AABB_BIT: {
-
-
- bool valid = b.aabb.intersects(p_aabb);
- if (!valid) {
-
- stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
-
- } else {
-
- if (b.face_index>=0) {
-
- const Triangle &s=triangleptr[ b.face_index ];
- n+=s.normal;
- n_count++;
-
- stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
-
- } else {
-
- stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node;
- }
- }
-
- } continue;
- case VISIT_LEFT_BIT: {
-
- stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node;
- stack[level+1]=b.left|TEST_AABB_BIT;
- level++;
-
- } continue;
- case VISIT_RIGHT_BIT: {
-
- stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
- stack[level+1]=b.right|TEST_AABB_BIT;
- level++;
- } continue;
- case VISIT_DONE_BIT: {
-
- if (level==0) {
- done=true;
- break;
- } else
- level--;
-
- } continue;
- }
-
-
- if (done)
- break;
- }
-
-
- if (n_count>0)
- n/=n_count;
-
- return n;
-
-}
-
-
-bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_point, Vector3 &r_normal) const {
-
-
- uint32_t* stack = (uint32_t*)alloca(sizeof(int)*max_depth);
-
- enum {
- TEST_AABB_BIT=0,
- VISIT_LEFT_BIT=1,
- VISIT_RIGHT_BIT=2,
- VISIT_DONE_BIT=3,
- VISITED_BIT_SHIFT=29,
- NODE_IDX_MASK=(1<<VISITED_BIT_SHIFT)-1,
- VISITED_BIT_MASK=~NODE_IDX_MASK,
-
-
- };
-
- Vector3 n = (p_end-p_begin).normalized();
- real_t d=1e10;
- bool inters=false;
-
- //for(int i=0;i<max_depth;i++)
- // stack[i]=0;
-
- int level=0;
- //AABB ray_aabb;
- //ray_aabb.pos=p_begin;
- //ray_aabb.expand_to(p_end);
-
-
- DVector<Triangle>::Read trianglesr = triangles.read();
- DVector<Vector3>::Read verticesr=vertices.read();
- DVector<BVH>::Read bvhr=bvh.read();
-
- const Triangle *triangleptr=trianglesr.ptr();
- const Vector3 *vertexptr=verticesr.ptr();
- int pos=bvh.size()-1;
- const BVH *bvhptr = bvhr.ptr();
-
- stack[0]=pos;
- while(true) {
-
- uint32_t node = stack[level]&NODE_IDX_MASK;
- const BVH &b = bvhptr[ node ];
- bool done=false;
-
- switch(stack[level]>>VISITED_BIT_SHIFT) {
- case TEST_AABB_BIT: {
-
-
- bool valid = b.aabb.intersects_segment(p_begin,p_end);
-// bool valid = b.aabb.intersects(ray_aabb);
-
- if (!valid) {
-
- stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
-
- } else {
-
- if (b.face_index>=0) {
-
- const Triangle &s=triangleptr[ b.face_index ];
- Face3 f3(vertexptr[ s.indices[0] ],vertexptr[ s.indices[1] ],vertexptr[ s.indices[2] ]);
-
-
- Vector3 res;
-
- if (f3.intersects_segment(p_begin,p_end,&res)) {
-
-
- float nd = n.dot(res);
- if (nd<d) {
-
- d=nd;
- r_point=res;
- r_normal=f3.get_plane().get_normal();
- inters=true;
- }
-
- }
-
- stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
-
- } else {
-
- stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node;
- }
- }
-
- } continue;
- case VISIT_LEFT_BIT: {
-
- stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node;
- stack[level+1]=b.left|TEST_AABB_BIT;
- level++;
-
- } continue;
- case VISIT_RIGHT_BIT: {
-
- stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
- stack[level+1]=b.right|TEST_AABB_BIT;
- level++;
- } continue;
- case VISIT_DONE_BIT: {
-
- if (level==0) {
- done=true;
- break;
- } else
- level--;
-
- } continue;
- }
-
-
- if (done)
- break;
- }
-
-
- if (inters) {
-
- if (n.dot(r_normal)>0)
- r_normal=-r_normal;
- }
-
- return inters;
-}
-
-
-bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vector3 &r_point, Vector3 &r_normal) const {
-
-
- uint32_t* stack = (uint32_t*)alloca(sizeof(int)*max_depth);
-
- enum {
- TEST_AABB_BIT=0,
- VISIT_LEFT_BIT=1,
- VISIT_RIGHT_BIT=2,
- VISIT_DONE_BIT=3,
- VISITED_BIT_SHIFT=29,
- NODE_IDX_MASK=(1<<VISITED_BIT_SHIFT)-1,
- VISITED_BIT_MASK=~NODE_IDX_MASK,
-
-
- };
-
- Vector3 n = p_dir;
- real_t d=1e20;
- bool inters=false;
-
- //for(int i=0;i<max_depth;i++)
- // stack[i]=0;
-
- int level=0;
-
- DVector<Triangle>::Read trianglesr = triangles.read();
- DVector<Vector3>::Read verticesr=vertices.read();
- DVector<BVH>::Read bvhr=bvh.read();
-
- const Triangle *triangleptr=trianglesr.ptr();
- const Vector3 *vertexptr=verticesr.ptr();
- int pos=bvh.size()-1;
- const BVH *bvhptr = bvhr.ptr();
-
- stack[0]=pos;
- while(true) {
-
- uint32_t node = stack[level]&NODE_IDX_MASK;
- const BVH &b = bvhptr[ node ];
- bool done=false;
-
- switch(stack[level]>>VISITED_BIT_SHIFT) {
- case TEST_AABB_BIT: {
-
-
- bool valid = b.aabb.intersects_ray(p_begin,p_dir);
- if (!valid) {
-
- stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
-
- } else {
-
- if (b.face_index>=0) {
-
- const Triangle &s=triangleptr[ b.face_index ];
- Face3 f3(vertexptr[ s.indices[0] ],vertexptr[ s.indices[1] ],vertexptr[ s.indices[2] ]);
-
-
- Vector3 res;
-
- if (f3.intersects_ray(p_begin,p_dir,&res)) {
-
-
- float nd = n.dot(res);
- if (nd<d) {
-
- d=nd;
- r_point=res;
- r_normal=f3.get_plane().get_normal();
- inters=true;
- }
-
- }
-
- stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
-
- } else {
-
- stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node;
- }
- }
-
- } continue;
- case VISIT_LEFT_BIT: {
-
- stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node;
- stack[level+1]=b.left|TEST_AABB_BIT;
- level++;
-
- } continue;
- case VISIT_RIGHT_BIT: {
-
- stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
- stack[level+1]=b.right|TEST_AABB_BIT;
- level++;
- } continue;
- case VISIT_DONE_BIT: {
-
- if (level==0) {
- done=true;
- break;
- } else
- level--;
-
- } continue;
- }
-
-
- if (done)
- break;
- }
-
-
- if (inters) {
-
- if (n.dot(r_normal)>0)
- r_normal=-r_normal;
- }
-
- return inters;
-}
-
-bool TriangleMesh::is_valid() const {
-
- return valid;
-}
-
-DVector<Face3> TriangleMesh::get_faces() const {
-
- if (!valid)
- return DVector<Face3>();
-
- DVector<Face3> faces;
- int ts = triangles.size();
- faces.resize(triangles.size());
-
- DVector<Face3>::Write w=faces.write();
- DVector<Triangle>::Read r = triangles.read();
- DVector<Vector3>::Read rv = vertices.read();
-
- for(int i=0;i<ts;i++) {
- for(int j=0;j<3;j++) {
- w[i].vertex[j]=rv[r[i].indices[j]];
- }
- }
-
- w = DVector<Face3>::Write();
- return faces;
-}
-
-TriangleMesh::TriangleMesh() {
-
- valid=false;
- max_depth=0;
-}
+#include "triangle_mesh.h" +#include "sort.h" + + + +int TriangleMesh::_create_bvh(BVH*p_bvh,BVH** p_bb,int p_from,int p_size,int p_depth,int&max_depth,int&max_alloc) { + + + if (p_depth>max_depth) { + max_depth=p_depth; + } + + if (p_size==1) { + + + return p_bb[p_from]-p_bvh; + } else if (p_size==0) { + + return -1; + } + + + AABB aabb; + aabb=p_bb[p_from]->aabb; + for(int i=1;i<p_size;i++) { + + aabb.merge_with(p_bb[p_from+i]->aabb); + } + + int li=aabb.get_longest_axis_index(); + + switch(li) { + + case Vector3::AXIS_X: { + SortArray<BVH*,BVHCmpX> sort_x; + sort_x.nth_element(0,p_size,p_size/2,&p_bb[p_from]); + //sort_x.sort(&p_bb[p_from],p_size); + } break; + case Vector3::AXIS_Y: { + SortArray<BVH*,BVHCmpY> sort_y; + sort_y.nth_element(0,p_size,p_size/2,&p_bb[p_from]); + //sort_y.sort(&p_bb[p_from],p_size); + } break; + case Vector3::AXIS_Z: { + SortArray<BVH*,BVHCmpZ> sort_z; + sort_z.nth_element(0,p_size,p_size/2,&p_bb[p_from]); + //sort_z.sort(&p_bb[p_from],p_size); + + } break; + } + + + int left = _create_bvh(p_bvh,p_bb,p_from,p_size/2,p_depth+1,max_depth,max_alloc); + int right = _create_bvh(p_bvh,p_bb,p_from+p_size/2,p_size-p_size/2,p_depth+1,max_depth,max_alloc); + + int index=max_alloc++; + BVH *_new = &p_bvh[index]; + _new->aabb=aabb; + _new->center=aabb.pos+aabb.size*0.5; + _new->face_index=-1; + _new->left=left; + _new->right=right; + + return index; + +} + + +void TriangleMesh::create(const DVector<Vector3>& p_faces) { + + valid=false; + + int fc=p_faces.size(); + ERR_FAIL_COND(!fc || ((fc%3) != 0)); + fc/=3; + triangles.resize(fc); + + bvh.resize(fc*3); //will never be larger than this (todo make better) + DVector<BVH>::Write bw = bvh.write(); + + { + + //create faces and indices and base bvh + //except for the Set for repeated triangles, everything + //goes in-place. + + DVector<Vector3>::Read r = p_faces.read(); + DVector<Triangle>::Write w = triangles.write(); + Map<Vector3,int> db; + + for(int i=0;i<fc;i++) { + + Triangle&f=w[i]; + const Vector3 *v=&r[i*3]; + + for(int j=0;j<3;j++) { + + int vidx=-1; + Vector3 vs=v[j].snapped(0.0001); + Map<Vector3,int>::Element *E=db.find(vs); + if (E) { + vidx=E->get(); + } else { + vidx=db.size(); + db[vs]=vidx; + } + + f.indices[j]=vidx; + if (j==0) + bw[i].aabb.pos=vs; + else + bw[i].aabb.expand_to(vs); + } + + f.normal=Face3(r[i*3+0],r[i*3+1],r[i*3+2]).get_plane().get_normal(); + + bw[i].left=-1; + bw[i].right=-1; + bw[i].face_index=i; + bw[i].center=bw[i].aabb.pos+bw[i].aabb.size*0.5; + } + + vertices.resize(db.size()); + DVector<Vector3>::Write vw = vertices.write(); + for (Map<Vector3,int>::Element *E=db.front();E;E=E->next()) { + vw[E->get()]=E->key(); + } + + } + + DVector<BVH*> bwptrs; + bwptrs.resize(fc); + DVector<BVH*>::Write bwp = bwptrs.write(); + for(int i=0;i<fc;i++) { + + bwp[i]=&bw[i]; + } + + max_depth=0; + int max_alloc=fc; + int max=_create_bvh(bw.ptr(),bwp.ptr(),0,fc,1,max_depth,max_alloc); + + bw=DVector<BVH>::Write(); //clearup + bvh.resize(max_alloc); //resize back + + valid=true; + +} + + +Vector3 TriangleMesh::get_area_normal(const AABB& p_aabb) const { + + uint32_t* stack = (uint32_t*)alloca(sizeof(int)*max_depth); + + enum { + TEST_AABB_BIT=0, + VISIT_LEFT_BIT=1, + VISIT_RIGHT_BIT=2, + VISIT_DONE_BIT=3, + VISITED_BIT_SHIFT=29, + NODE_IDX_MASK=(1<<VISITED_BIT_SHIFT)-1, + VISITED_BIT_MASK=~NODE_IDX_MASK, + + + }; + + int n_count=0; + Vector3 n; + + //for(int i=0;i<max_depth;i++) + // stack[i]=0; + + int level=0; + + DVector<Triangle>::Read trianglesr = triangles.read(); + DVector<Vector3>::Read verticesr=vertices.read(); + DVector<BVH>::Read bvhr=bvh.read(); + + const Triangle *triangleptr=trianglesr.ptr(); + const Vector3 *vertexptr=verticesr.ptr(); + int pos=bvh.size()-1; + const BVH *bvhptr = bvhr.ptr(); + + stack[0]=pos; + while(true) { + + uint32_t node = stack[level]&NODE_IDX_MASK; + const BVH &b = bvhptr[ node ]; + bool done=false; + + switch(stack[level]>>VISITED_BIT_SHIFT) { + case TEST_AABB_BIT: { + + + bool valid = b.aabb.intersects(p_aabb); + if (!valid) { + + stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; + + } else { + + if (b.face_index>=0) { + + const Triangle &s=triangleptr[ b.face_index ]; + n+=s.normal; + n_count++; + + stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; + + } else { + + stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node; + } + } + + } continue; + case VISIT_LEFT_BIT: { + + stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node; + stack[level+1]=b.left|TEST_AABB_BIT; + level++; + + } continue; + case VISIT_RIGHT_BIT: { + + stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; + stack[level+1]=b.right|TEST_AABB_BIT; + level++; + } continue; + case VISIT_DONE_BIT: { + + if (level==0) { + done=true; + break; + } else + level--; + + } continue; + } + + + if (done) + break; + } + + + if (n_count>0) + n/=n_count; + + return n; + +} + + +bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_point, Vector3 &r_normal) const { + + + uint32_t* stack = (uint32_t*)alloca(sizeof(int)*max_depth); + + enum { + TEST_AABB_BIT=0, + VISIT_LEFT_BIT=1, + VISIT_RIGHT_BIT=2, + VISIT_DONE_BIT=3, + VISITED_BIT_SHIFT=29, + NODE_IDX_MASK=(1<<VISITED_BIT_SHIFT)-1, + VISITED_BIT_MASK=~NODE_IDX_MASK, + + + }; + + Vector3 n = (p_end-p_begin).normalized(); + real_t d=1e10; + bool inters=false; + + //for(int i=0;i<max_depth;i++) + // stack[i]=0; + + int level=0; + //AABB ray_aabb; + //ray_aabb.pos=p_begin; + //ray_aabb.expand_to(p_end); + + + DVector<Triangle>::Read trianglesr = triangles.read(); + DVector<Vector3>::Read verticesr=vertices.read(); + DVector<BVH>::Read bvhr=bvh.read(); + + const Triangle *triangleptr=trianglesr.ptr(); + const Vector3 *vertexptr=verticesr.ptr(); + int pos=bvh.size()-1; + const BVH *bvhptr = bvhr.ptr(); + + stack[0]=pos; + while(true) { + + uint32_t node = stack[level]&NODE_IDX_MASK; + const BVH &b = bvhptr[ node ]; + bool done=false; + + switch(stack[level]>>VISITED_BIT_SHIFT) { + case TEST_AABB_BIT: { + + + bool valid = b.aabb.intersects_segment(p_begin,p_end); +// bool valid = b.aabb.intersects(ray_aabb); + + if (!valid) { + + stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; + + } else { + + if (b.face_index>=0) { + + const Triangle &s=triangleptr[ b.face_index ]; + Face3 f3(vertexptr[ s.indices[0] ],vertexptr[ s.indices[1] ],vertexptr[ s.indices[2] ]); + + + Vector3 res; + + if (f3.intersects_segment(p_begin,p_end,&res)) { + + + float nd = n.dot(res); + if (nd<d) { + + d=nd; + r_point=res; + r_normal=f3.get_plane().get_normal(); + inters=true; + } + + } + + stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; + + } else { + + stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node; + } + } + + } continue; + case VISIT_LEFT_BIT: { + + stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node; + stack[level+1]=b.left|TEST_AABB_BIT; + level++; + + } continue; + case VISIT_RIGHT_BIT: { + + stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; + stack[level+1]=b.right|TEST_AABB_BIT; + level++; + } continue; + case VISIT_DONE_BIT: { + + if (level==0) { + done=true; + break; + } else + level--; + + } continue; + } + + + if (done) + break; + } + + + if (inters) { + + if (n.dot(r_normal)>0) + r_normal=-r_normal; + } + + return inters; +} + + +bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vector3 &r_point, Vector3 &r_normal) const { + + + uint32_t* stack = (uint32_t*)alloca(sizeof(int)*max_depth); + + enum { + TEST_AABB_BIT=0, + VISIT_LEFT_BIT=1, + VISIT_RIGHT_BIT=2, + VISIT_DONE_BIT=3, + VISITED_BIT_SHIFT=29, + NODE_IDX_MASK=(1<<VISITED_BIT_SHIFT)-1, + VISITED_BIT_MASK=~NODE_IDX_MASK, + + + }; + + Vector3 n = p_dir; + real_t d=1e20; + bool inters=false; + + //for(int i=0;i<max_depth;i++) + // stack[i]=0; + + int level=0; + + DVector<Triangle>::Read trianglesr = triangles.read(); + DVector<Vector3>::Read verticesr=vertices.read(); + DVector<BVH>::Read bvhr=bvh.read(); + + const Triangle *triangleptr=trianglesr.ptr(); + const Vector3 *vertexptr=verticesr.ptr(); + int pos=bvh.size()-1; + const BVH *bvhptr = bvhr.ptr(); + + stack[0]=pos; + while(true) { + + uint32_t node = stack[level]&NODE_IDX_MASK; + const BVH &b = bvhptr[ node ]; + bool done=false; + + switch(stack[level]>>VISITED_BIT_SHIFT) { + case TEST_AABB_BIT: { + + + bool valid = b.aabb.intersects_ray(p_begin,p_dir); + if (!valid) { + + stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; + + } else { + + if (b.face_index>=0) { + + const Triangle &s=triangleptr[ b.face_index ]; + Face3 f3(vertexptr[ s.indices[0] ],vertexptr[ s.indices[1] ],vertexptr[ s.indices[2] ]); + + + Vector3 res; + + if (f3.intersects_ray(p_begin,p_dir,&res)) { + + + float nd = n.dot(res); + if (nd<d) { + + d=nd; + r_point=res; + r_normal=f3.get_plane().get_normal(); + inters=true; + } + + } + + stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; + + } else { + + stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node; + } + } + + } continue; + case VISIT_LEFT_BIT: { + + stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node; + stack[level+1]=b.left|TEST_AABB_BIT; + level++; + + } continue; + case VISIT_RIGHT_BIT: { + + stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; + stack[level+1]=b.right|TEST_AABB_BIT; + level++; + } continue; + case VISIT_DONE_BIT: { + + if (level==0) { + done=true; + break; + } else + level--; + + } continue; + } + + + if (done) + break; + } + + + if (inters) { + + if (n.dot(r_normal)>0) + r_normal=-r_normal; + } + + return inters; +} + +bool TriangleMesh::is_valid() const { + + return valid; +} + +DVector<Face3> TriangleMesh::get_faces() const { + + if (!valid) + return DVector<Face3>(); + + DVector<Face3> faces; + int ts = triangles.size(); + faces.resize(triangles.size()); + + DVector<Face3>::Write w=faces.write(); + DVector<Triangle>::Read r = triangles.read(); + DVector<Vector3>::Read rv = vertices.read(); + + for(int i=0;i<ts;i++) { + for(int j=0;j<3;j++) { + w[i].vertex[j]=rv[r[i].indices[j]]; + } + } + + w = DVector<Face3>::Write(); + return faces; +} + +TriangleMesh::TriangleMesh() { + + valid=false; + max_depth=0; +} diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h index ab0cb713b1..87d8ce8e6c 100644 --- a/core/math/triangle_mesh.h +++ b/core/math/triangle_mesh.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,74 +26,74 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef TRIANGLE_MESH_H
-#define TRIANGLE_MESH_H
-
-#include "reference.h"
-#include "face3.h"
-class TriangleMesh : public Reference {
-
- OBJ_TYPE( TriangleMesh, Reference);
-
- struct Triangle {
-
- Vector3 normal;
- int indices[3];
- };
-
- DVector<Triangle> triangles;
- DVector<Vector3> vertices;
-
- struct BVH {
-
- AABB aabb;
- Vector3 center; //used for sorting
- int left;
- int right;
-
- int face_index;
- };
-
- struct BVHCmpX {
-
- bool operator()(const BVH* p_left, const BVH* p_right) const {
-
- return p_left->center.x < p_right->center.x;
- }
- };
-
- struct BVHCmpY {
-
- bool operator()(const BVH* p_left, const BVH* p_right) const {
-
- return p_left->center.y < p_right->center.y;
- }
- };
- struct BVHCmpZ {
-
- bool operator()(const BVH* p_left, const BVH* p_right) const {
-
- return p_left->center.z < p_right->center.z;
- }
- };
-
- int _create_bvh(BVH*p_bvh,BVH** p_bb,int p_from,int p_size,int p_depth,int&max_depth,int&max_alloc);
-
- DVector<BVH> bvh;
- int max_depth;
- bool valid;
-
-public:
-
- bool is_valid() const;
- bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_point, Vector3 &r_normal) const;
- bool intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vector3 &r_point, Vector3 &r_normal) const;
- Vector3 get_area_normal(const AABB& p_aabb) const;
- DVector<Face3> get_faces() const;
-
-
- void create(const DVector<Vector3>& p_faces);
- TriangleMesh();
-};
-
-#endif // TRIANGLE_MESH_H
+#ifndef TRIANGLE_MESH_H +#define TRIANGLE_MESH_H + +#include "reference.h" +#include "face3.h" +class TriangleMesh : public Reference { + + OBJ_TYPE( TriangleMesh, Reference); + + struct Triangle { + + Vector3 normal; + int indices[3]; + }; + + DVector<Triangle> triangles; + DVector<Vector3> vertices; + + struct BVH { + + AABB aabb; + Vector3 center; //used for sorting + int left; + int right; + + int face_index; + }; + + struct BVHCmpX { + + bool operator()(const BVH* p_left, const BVH* p_right) const { + + return p_left->center.x < p_right->center.x; + } + }; + + struct BVHCmpY { + + bool operator()(const BVH* p_left, const BVH* p_right) const { + + return p_left->center.y < p_right->center.y; + } + }; + struct BVHCmpZ { + + bool operator()(const BVH* p_left, const BVH* p_right) const { + + return p_left->center.z < p_right->center.z; + } + }; + + int _create_bvh(BVH*p_bvh,BVH** p_bb,int p_from,int p_size,int p_depth,int&max_depth,int&max_alloc); + + DVector<BVH> bvh; + int max_depth; + bool valid; + +public: + + bool is_valid() const; + bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_point, Vector3 &r_normal) const; + bool intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vector3 &r_point, Vector3 &r_normal) const; + Vector3 get_area_normal(const AABB& p_aabb) const; + DVector<Face3> get_faces() const; + + + void create(const DVector<Vector3>& p_faces); + TriangleMesh(); +}; + +#endif // TRIANGLE_MESH_H diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp index 4a870def4b..b13e13c47d 100644 --- a/core/math/triangulate.cpp +++ b/core/math/triangulate.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/triangulate.h b/core/math/triangulate.h index b20b37bd44..927b7efb8d 100644 --- a/core/math/triangulate.h +++ b/core/math/triangulate.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index cf6fd9242e..a3877eb9ff 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -27,27 +27,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "vector3.h" - +#include "matrix3.h" void Vector3::rotate(const Vector3& p_axis,float p_phi) { - Vector3 axis1 = cross(p_axis); - float l = axis1.length(); - if (l==0) - return; - axis1/=l; - Vector3 axis2 = axis1.cross(p_axis).normalized(); - - float _x = axis1.dot(*this); - float _y = axis2.dot(*this); - - float ang = Math::atan2(_x,_y); - - ang+=p_phi; - - *this=((axis1 * Math::cos(ang)) + (axis2 * Math::sin(ang))) * length(); - + *this=Matrix3(p_axis,p_phi).xform(*this); } Vector3 Vector3::rotated(const Vector3& p_axis,float p_phi) const { diff --git a/core/math/vector3.h b/core/math/vector3.h index d2f2408829..d27b611379 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/message_queue.cpp b/core/message_queue.cpp index dbf6217dc2..489939ee65 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -324,6 +324,7 @@ int MessageQueue::get_max_buffer_usage() const { void MessageQueue::flush() { + if (buffer_max_used<buffer_end); { buffer_max_used=buffer_end; //statistics(); @@ -331,9 +332,14 @@ void MessageQueue::flush() { uint32_t read_pos=0; - while (read_pos < buffer_end ) { + //using reverse locking strategy + _THREAD_SAFE_LOCK_ + + while (read_pos<buffer_end) { + + _THREAD_SAFE_UNLOCK_ + //lock on each interation, so a call can re-add itself to the message queue - _THREAD_SAFE_LOCK_ Message *message = (Message*)&buffer[ read_pos ]; @@ -379,16 +385,17 @@ void MessageQueue::flush() { } - read_pos+=sizeof(Message); + uint32_t advance = sizeof(Message); if (message->type!=TYPE_NOTIFICATION) - read_pos+=sizeof(Variant)*message->args; + advance+=sizeof(Variant)*message->args; message->~Message(); - _THREAD_SAFE_UNLOCK_ + _THREAD_SAFE_LOCK_ + read_pos+=advance; } - _THREAD_SAFE_LOCK_ + buffer_end=0; // reset buffer _THREAD_SAFE_UNLOCK_ diff --git a/core/message_queue.h b/core/message_queue.h index 691c289813..5cee21847b 100644 --- a/core/message_queue.h +++ b/core/message_queue.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/method_bind.cpp b/core/method_bind.cpp index 6ee4882571..ce57380434 100644 --- a/core/method_bind.cpp +++ b/core/method_bind.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -40,8 +40,8 @@ PropertyInfo MethodBind::get_argument_info(int p_argument) const { 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_slice(":",1); - pi.name=name.get_slice(":",0); + pi.hint_string=name.get_slicec(':',1); + pi.name=name.get_slicec(':',0); } return pi; diff --git a/core/method_bind.h b/core/method_bind.h index 6ea9340ad5..85c1084f80 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -98,7 +98,7 @@ struct VariantCaster<m_enum> {\ #define CHECK_ARG(m_arg)\ if ((m_arg-1)<p_arg_count) {\ Variant::Type argtype=get_argument_type(m_arg-1);\ - if (!Variant::can_convert(p_args[m_arg-1]->get_type(),argtype)) {\ + if (!Variant::can_convert_strict(p_args[m_arg-1]->get_type(),argtype)) {\ r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;\ r_error.argument=m_arg-1;\ r_error.expected=argtype;\ @@ -298,7 +298,7 @@ MethodBind* create_native_method_bind( Variant (T::*p_method)(const Variant**,in // tale of an amazing hack.. // -// if you declare an unexisting class.. +// if you declare an nonexistent class.. class __UnexistingClass; diff --git a/core/multi_bucket_array.h b/core/multi_bucket_array.h index a24af941f8..d85c9de583 100644 --- a/core/multi_bucket_array.h +++ b/core/multi_bucket_array.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/object.cpp b/core/object.cpp index 2b83f728d1..07ac430d7a 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -33,6 +33,8 @@ #include "message_queue.h" #include "core_string_names.h" #include "translation.h" +#include "os/os.h" +#include "resource.h" #ifdef DEBUG_ENABLED @@ -256,12 +258,15 @@ bool Object::_predelete() { _predelete_ok=1; notification(NOTIFICATION_PREDELETE,true); + if (_predelete_ok) { + _type_ptr=NULL; //must restore so destructors can access type ptr correctly + } return _predelete_ok; } void Object::_postinitialize() { - + _type_ptr=_get_type_namev(); _initialize_typev(); notification(NOTIFICATION_POSTINITIALIZE); @@ -994,12 +999,44 @@ Variant Object::get_meta(const String& p_name) const { return metadata[p_name]; } + Array Object::_get_property_list_bind() const { List<PropertyInfo> lpi; get_property_list(&lpi); return convert_property_list(&lpi); } + +Array Object::_get_method_list_bind() const { + + List<MethodInfo> ml; + get_method_list(&ml); + Array ret; + + for(List<MethodInfo>::Element *E=ml.front();E;E=E->next()) { + + Dictionary d; + d["name"]=E->get().name; + d["args"]=convert_property_list(&E->get().arguments); + Array da; + for(int i=0;i<E->get().default_arguments.size();i++) + da.push_back(E->get().default_arguments[i]); + d["default_args"]=da; + d["flags"]=E->get().flags; + d["id"]=E->get().id; + Dictionary r; + r["type"]=E->get().return_val.type; + r["hint"]=E->get().return_val.hint; + r["hint_string"]=E->get().return_val.hint_string; + d["return_type"]=r; + //va.push_back(d); + ret.push_back(d); + } + + return ret; + +} + DVector<String> Object::_get_meta_list_bind() const { DVector<String> _metaret; @@ -1268,6 +1305,10 @@ Array Object::_get_signal_connection_list(const String& p_signal) const{ void Object::get_signal_list(List<MethodInfo> *p_signals ) const { + if (!script.is_null()) { + Ref<Script>(script)->get_script_signal_list(p_signals); + } + ObjectTypeDB::get_signal_list(get_type_name(),p_signals); //find maybe usersignals? const StringName *S=NULL; @@ -1279,6 +1320,24 @@ void Object::get_signal_list(List<MethodInfo> *p_signals ) const { p_signals->push_back(signal_map[*S].user); } } + +} + + +void Object::get_all_signal_connections(List<Connection> *p_connections) const { + + const StringName *S=NULL; + + while((S=signal_map.next(S))) { + + const Signal *s=&signal_map[*S]; + + for(int i=0;i<s->slot_map.size();i++) { + + p_connections->push_back(s->slot_map.getv(i).conn); + } + } + } void Object::get_signal_connection_list(const StringName& p_signal,List<Connection> *p_connections) const { @@ -1300,8 +1359,12 @@ Error Object::connect(const StringName& p_signal, Object *p_to_object, const Str Signal *s = signal_map.getptr(p_signal); if (!s) { bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal); + //check in script + if (!signal_is_valid && !script.is_null() && Ref<Script>(script)->has_script_signal(p_signal)) + signal_is_valid=true; + if (!signal_is_valid) { - ERR_EXPLAIN("Attempt to connect to unexisting signal: "+p_signal); + ERR_EXPLAIN("Attempt to connect nonexistent signal '"+p_signal+"' to method '"+p_to_method+"'"); ERR_FAIL_COND_V(!signal_is_valid,ERR_INVALID_PARAMETER); } signal_map[p_signal]=Signal(); @@ -1338,7 +1401,7 @@ bool Object::is_connected(const StringName& p_signal, Object *p_to_object, const bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal); if (signal_is_valid) return false; - ERR_EXPLAIN("Unexisting signal: "+p_signal); + ERR_EXPLAIN("Nonexistent signal: "+p_signal); ERR_FAIL_COND_V(!s,false); } @@ -1355,7 +1418,7 @@ void Object::disconnect(const StringName& p_signal, Object *p_to_object, const S ERR_FAIL_NULL(p_to_object); Signal *s = signal_map.getptr(p_signal); if (!s) { - ERR_EXPLAIN("Unexisting signal: "+p_signal); + ERR_EXPLAIN("Nonexistent signal: "+p_signal); ERR_FAIL_COND(!s); } if (s->lock>0) { @@ -1366,7 +1429,7 @@ void Object::disconnect(const StringName& p_signal, Object *p_to_object, const S Signal::Target target(p_to_object->get_instance_ID(),p_to_method); if (!s->slot_map.has(target)) { - ERR_EXPLAIN("Disconnecting unexisting signal '"+p_signal+"', slot: "+itos(target._id)+":"+target.method); + ERR_EXPLAIN("Disconnecting nonexistent signal '"+p_signal+"', slot: "+itos(target._id)+":"+target.method); ERR_FAIL(); } int prev = p_to_object->connections.size(); @@ -1414,6 +1477,63 @@ StringName Object::tr(const StringName& p_message) const { } + +void Object::_clear_internal_resource_paths(const Variant &p_var) { + + switch(p_var.get_type()) { + + case Variant::OBJECT: { + + RES r = p_var; + if (!r.is_valid()) + return; + + if (!r->get_path().begins_with("res://") || r->get_path().find("::")==-1) + return; //not an internal resource + + Object *object=p_var; + if (!object) + return; + + r->set_path(""); + r->clear_internal_resource_paths(); + } break; + case Variant::ARRAY: { + + Array a=p_var; + for(int i=0;i<a.size();i++) { + _clear_internal_resource_paths(a[i]); + } + + } break; + case Variant::DICTIONARY: { + + Dictionary d=p_var; + List<Variant> keys; + d.get_key_list(&keys); + + for (List<Variant>::Element *E=keys.front();E;E=E->next()) { + + _clear_internal_resource_paths(E->get()); + _clear_internal_resource_paths(d[E->get()]); + } + } break; + } + +} + +void Object::clear_internal_resource_paths() { + + List<PropertyInfo> pinfo; + + get_property_list(&pinfo); + + for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { + + _clear_internal_resource_paths(get(E->get().name)); + } +} + void Object::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_type"),&Object::get_type); @@ -1421,6 +1541,7 @@ void Object::_bind_methods() { ObjectTypeDB::bind_method(_MD("set","property","value"),&Object::_set_bind); ObjectTypeDB::bind_method(_MD("get","property"),&Object::_get_bind); ObjectTypeDB::bind_method(_MD("get_property_list"),&Object::_get_property_list_bind); + ObjectTypeDB::bind_method(_MD("get_method_list"),&Object::_get_method_list_bind); ObjectTypeDB::bind_method(_MD("notification","what"),&Object::notification,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("get_instance_ID"),&Object::get_instance_ID); @@ -1503,6 +1624,10 @@ void Object::_bind_methods() { ObjectTypeDB::bind_method(_MD("XL_MESSAGE","message"),&Object::XL_MESSAGE); ObjectTypeDB::bind_method(_MD("tr","message"),&Object::tr); + ObjectTypeDB::bind_method(_MD("is_queued_for_deletion"),&Object::is_queued_for_deletion); + + ObjectTypeDB::add_virtual_method("Object",MethodInfo("free"),false); + ADD_SIGNAL( MethodInfo("script_changed")); BIND_VMETHOD( MethodInfo("_notification",PropertyInfo(Variant::INT,"what")) ); @@ -1566,6 +1691,10 @@ void Object::get_translatable_strings(List<String> *p_strings) const { } +bool Object::is_queued_for_deletion() const { + return _is_queued_for_deletion; +} + #ifdef TOOLS_ENABLED void Object::set_edited(bool p_edited) { @@ -1581,12 +1710,13 @@ bool Object::is_edited() const { Object::Object() { - + _type_ptr=NULL; _block_signals=false; _predelete_ok=0; _instance_ID=0; _instance_ID = ObjectDB::add_instance(this); _can_translate=true; + _is_queued_for_deletion=false; script_instance=NULL; #ifdef TOOLS_ENABLED @@ -1719,8 +1849,20 @@ void ObjectDB::cleanup() { GLOBAL_LOCK_FUNCTION; if (instances.size()) { - + WARN_PRINT("ObjectDB Instances still exist!"); + if (OS::get_singleton()->is_stdout_verbose()) { + const uint32_t *K=NULL; + while((K=instances.next(K))) { + + String node_name; + if (instances[*K]->is_type("Node")) + node_name=" - Node Name: "+String(instances[*K]->call("get_name")); + if (instances[*K]->is_type("Resoucre")) + node_name=" - Resource Name: "+String(instances[*K]->call("get_name"))+" Path: "+String(instances[*K]->call("get_path")); + print_line("Leaked Instance: "+String(instances[*K]->get_type())+":"+itos(*K)+node_name); + } + } } instances.clear(); instance_checks.clear(); diff --git a/core/object.h b/core/object.h index eb885f5d20..eb0e78a8c3 100644 --- a/core/object.h +++ b/core/object.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -54,6 +54,7 @@ enum PropertyHint { PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc" PROPERTY_HINT_EXP_EASING, /// exponential easing funciton (Math::ease) PROPERTY_HINT_LENGTH, ///< hint_text= "length" (as integer) + PROPERTY_HINT_SPRITE_FRAME, PROPERTY_HINT_KEY_ACCEL, ///< hint_text= "length" (as integer) PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags) PROPERTY_HINT_ALL_FLAGS, @@ -81,7 +82,8 @@ enum PropertyUsageFlags { PROPERTY_USAGE_BUNDLE=128, //used for optimized bundles PROPERTY_USAGE_CATEGORY=256, PROPERTY_USAGE_STORE_IF_NONZERO=512, //only store if nonzero - PROPERTY_USAGE_NO_INSTANCE_STATE=1024, + PROPERTY_USAGE_STORE_IF_NONONE=1024, //only store if false + PROPERTY_USAGE_NO_INSTANCE_STATE=2048, PROPERTY_USAGE_DEFAULT=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK, PROPERTY_USAGE_DEFAULT_INTL=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK|PROPERTY_USAGE_INTERNATIONALIZED, @@ -96,6 +98,8 @@ enum PropertyUsageFlags { #define ADD_PROPERTYI( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), m_property, m_setter, m_getter, m_index ) #define ADD_PROPERTYNZ( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter ) #define ADD_PROPERTYINZ( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter, m_index ) +#define ADD_PROPERTYNO( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter ) +#define ADD_PROPERTYINO( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter, m_index ) struct PropertyInfo { @@ -111,6 +115,9 @@ struct PropertyInfo { 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; + } }; @@ -175,10 +182,10 @@ public:\ virtual String get_type() const { \ return String(#m_type);\ }\ -virtual StringName get_type_name() const { \ +virtual const StringName* _get_type_namev() const { \ if (!_type_name)\ _type_name=get_type_static();\ - return _type_name;\ + return &_type_name;\ }\ static _FORCE_INLINE_ void* get_type_ptr_static() { \ static int ptr;\ @@ -384,6 +391,8 @@ friend void postinitialize_handler(Object*); ScriptInstance *script_instance; RefPtr script; Dictionary metadata; + mutable StringName _type_name; + mutable const StringName* _type_ptr; void _add_user_signal(const String& p_name, const Array& p_pargs=Array()); bool _has_user_signal(const StringName& p_name) const; @@ -397,7 +406,6 @@ friend void postinitialize_handler(Object*); protected: - virtual bool _use_builtin_script() const { return false; } virtual void _initialize_typev() { initialize_type(); } virtual bool _setv(const StringName& p_name,const Variant &p_property) { return false; }; @@ -442,10 +450,17 @@ protected: Variant _call_deferred_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error); - + virtual const StringName* _get_type_namev() const { + if (!_type_name) + _type_name=get_type_static(); + return &_type_name; + } DVector<String> _get_meta_list_bind() const; Array _get_property_list_bind() const; + Array _get_method_list_bind() const; + + void _clear_internal_resource_paths(const Variant &p_var); public: //should be protected, but bug in clang++ static void initialize_type(); @@ -517,11 +532,19 @@ public: virtual String get_type() const { return "Object"; } virtual String get_save_type() const { return get_type(); } //type stored when saving - virtual StringName get_type_name() const { return StringName("Object"); } + + + virtual bool is_type(const String& p_type) const { return (p_type=="Object"); } virtual bool is_type_ptr(void *p_ptr) const { return get_type_ptr_static()==p_ptr; } - + _FORCE_INLINE_ const StringName& get_type_name() const { + if (!_type_ptr) { + return *_get_type_namev(); + } else { + return *_type_ptr; + } + } /* IAPI */ // void set(const String& p_name, const Variant& p_value); @@ -572,6 +595,7 @@ public: void emit_signal(const StringName& p_name,VARIANT_ARG_LIST); void get_signal_list(List<MethodInfo> *p_signals ) const; void get_signal_connection_list(const StringName& p_signal,List<Connection> *p_connections) const; + void get_all_signal_connections(List<Connection> *p_connections) const; Error connect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method,const Vector<Variant>& p_binds=Vector<Variant>(),uint32_t p_flags=0); void disconnect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method); @@ -589,8 +613,14 @@ public: StringName XL_MESSAGE(const StringName& p_message) const; //translate message (internationalization) StringName tr(const StringName& p_message) const; //translate message (alternative) + bool _is_queued_for_deletion; // set to true by SceneTree::queue_delete() + bool is_queued_for_deletion() const; + _FORCE_INLINE_ void set_message_translation(bool p_enable) { _can_translate=p_enable; } _FORCE_INLINE_ bool can_translate_messages() const { return _can_translate; } + + void clear_internal_resource_paths(); + Object(); virtual ~Object(); @@ -643,6 +673,8 @@ public: #endif + + }; //needed by macros diff --git a/core/object_type_db.cpp b/core/object_type_db.cpp index 1047d7eba5..c291714573 100644 --- a/core/object_type_db.cpp +++ b/core/object_type_db.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -205,7 +205,7 @@ ObjectTypeDB::TypeInfo::~TypeInfo() { } -bool ObjectTypeDB::is_type(const String &p_type,const String& p_inherits) { +bool ObjectTypeDB::is_type(const StringName &p_type,const StringName& p_inherits) { OBJTYPE_LOCK; @@ -220,7 +220,7 @@ bool ObjectTypeDB::is_type(const String &p_type,const String& p_inherits) { return false; } -void ObjectTypeDB::get_type_list( List<String> *p_types) { +void ObjectTypeDB::get_type_list( List<StringName> *p_types) { OBJTYPE_LOCK; @@ -235,7 +235,7 @@ void ObjectTypeDB::get_type_list( List<String> *p_types) { } -void ObjectTypeDB::get_inheriters_from( const String& p_type,List<String> *p_types) { +void ObjectTypeDB::get_inheriters_from( const StringName& p_type,List<StringName> *p_types) { OBJTYPE_LOCK; @@ -249,7 +249,7 @@ void ObjectTypeDB::get_inheriters_from( const String& p_type,List<String> *p_typ } -String ObjectTypeDB::type_inherits_from(const String& p_type) { +StringName ObjectTypeDB::type_inherits_from(const StringName& p_type) { OBJTYPE_LOCK; @@ -258,7 +258,7 @@ String ObjectTypeDB::type_inherits_from(const String& p_type) { return ti->inherits; } -bool ObjectTypeDB::type_exists(const String &p_type) { +bool ObjectTypeDB::type_exists(const StringName &p_type) { OBJTYPE_LOCK; return types.has(p_type); @@ -269,7 +269,7 @@ void ObjectTypeDB::add_compatibility_type(const StringName& p_type,const StringN compat_types[p_type]=p_fallback; } -Object *ObjectTypeDB::instance(const String &p_type) { +Object *ObjectTypeDB::instance(const StringName &p_type) { TypeInfo *ti; { @@ -287,7 +287,7 @@ Object *ObjectTypeDB::instance(const String &p_type) { return ti->creation_func(); } -bool ObjectTypeDB::can_instance(const String &p_type) { +bool ObjectTypeDB::can_instance(const StringName &p_type) { OBJTYPE_LOCK; @@ -650,7 +650,13 @@ bool ObjectTypeDB::set_property(Object* p_object,const StringName& p_property, c Variant index=psg->index; const Variant* arg[2]={&index,&p_value}; Variant::CallError ce; - p_object->call(psg->setter,arg,2,ce); +// p_object->call(psg->setter,arg,2,ce); + if (psg->_setptr) { + psg->_setptr->call(p_object,arg,2,ce); + } else { + p_object->call(psg->setter,arg,2,ce); + } + } else { const Variant* arg[1]={&p_value}; @@ -804,12 +810,13 @@ else goto set_defvals; } -void ObjectTypeDB::add_virtual_method(const StringName& p_type,const MethodInfo& p_method ) { +void ObjectTypeDB::add_virtual_method(const StringName& p_type, const MethodInfo& p_method , bool p_virtual) { ERR_FAIL_COND(!types.has(p_type)); #ifdef DEBUG_METHODS_ENABLED MethodInfo mi=p_method; - mi.flags|=METHOD_FLAG_VIRTUAL; + if (p_virtual) + mi.flags|=METHOD_FLAG_VIRTUAL; types[p_type].virtual_methods.push_back(mi); #endif diff --git a/core/object_type_db.h b/core/object_type_db.h index 617a0a7c20..caa5baddd5 100644 --- a/core/object_type_db.h +++ b/core/object_type_db.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -228,13 +228,13 @@ public: T::register_custom_data_to_otdb(); } - static void get_type_list( List<String> *p_types); - static void get_inheriters_from( const String& p_type,List<String> *p_types); - static String type_inherits_from(const String& p_type); - static bool type_exists(const String &p_type); - static bool is_type(const String &p_type,const String& p_inherits); - static bool can_instance(const String &p_type); - static Object *instance(const String &p_type); + static void get_type_list( List<StringName> *p_types); + static void get_inheriters_from( const StringName& p_type,List<StringName> *p_types); + static StringName type_inherits_from(const StringName& p_type); + static bool type_exists(const StringName &p_type); + static bool is_type(const StringName &p_type,const StringName& p_inherits); + static bool can_instance(const StringName &p_type); + static Object *instance(const StringName &p_type); #if 0 template<class N, class M> @@ -468,7 +468,7 @@ public: static void get_method_list(StringName p_type,List<MethodInfo> *p_methods,bool p_no_inheritance=false); static MethodBind *get_method(StringName p_type, StringName p_name); - static void add_virtual_method(const StringName& p_type,const MethodInfo& p_method ); + static void add_virtual_method(const StringName& p_type,const MethodInfo& p_method,bool p_virtual=true ); static void get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods,bool p_no_inheritance=false ); static void bind_integer_constant(const StringName& p_type, const StringName &p_name, int p_constant); diff --git a/core/os/copymem.cpp b/core/os/copymem.cpp index 4a36b6f6d1..54baf1e232 100644 --- a/core/os/copymem.cpp +++ b/core/os/copymem.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/copymem.h b/core/os/copymem.h index 09e8c6903e..a5d640edbf 100644 --- a/core/os/copymem.h +++ b/core/os/copymem.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 53fe792c46..d0baae5872 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -56,6 +56,17 @@ String DirAccess::_get_root_string() const { return ""; } +int DirAccess::get_current_drive() { + + String path = get_current_dir().to_lower(); + for(int i=0;i<get_drive_count();i++) { + String d = get_drive(i).to_lower(); + if (path.begins_with(d)) + return i; + } + + return 0; +} static Error _erase_recursive(DirAccess *da) { @@ -399,6 +410,15 @@ Error DirAccess::copy(String p_from,String p_to) { return err; } +bool DirAccess::exists(String p_dir) { + + DirAccess* da = DirAccess::create_for_path(p_dir); + bool valid = da->change_dir(p_dir)==OK; + memdelete(da); + return valid; + +} + DirAccess::DirAccess(){ _access_type=ACCESS_FILESYSTEM; diff --git a/core/os/dir_access.h b/core/os/dir_access.h index dc56f2308e..8bacc96c60 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -84,6 +84,7 @@ public: virtual int get_drive_count()=0; virtual String get_drive(int p_drive)=0; + virtual int get_current_drive(); virtual Error change_dir(String p_dir)=0; ///< can be relative or absolute, return false on success virtual String get_current_dir()=0; ///< return current dir location @@ -93,7 +94,7 @@ public: virtual bool file_exists(String p_file)=0; virtual bool dir_exists(String p_dir)=0; - + static bool exists(String p_dir); virtual size_t get_space_left()=0; virtual Error copy(String p_from,String p_to); diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index ffa0cad8e4..ef7efd27e1 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/file_access.h b/core/os/file_access.h index 793e971a4c..8e34013796 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/input.cpp b/core/os/input.cpp index 5d4b3a834d..2b939ede46 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -56,7 +56,7 @@ void Input::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_joy_axis","device","axis"),&Input::get_joy_axis); ObjectTypeDB::bind_method(_MD("get_joy_name","device"),&Input::get_joy_name); ObjectTypeDB::bind_method(_MD("get_accelerometer"),&Input::get_accelerometer); - ObjectTypeDB::bind_method(_MD("get_mouse_pos"),&Input::get_mouse_pos); + //ObjectTypeDB::bind_method(_MD("get_mouse_pos"),&Input::get_mouse_pos); - this is not the function you want ObjectTypeDB::bind_method(_MD("get_mouse_speed"),&Input::get_mouse_speed); ObjectTypeDB::bind_method(_MD("get_mouse_button_mask"),&Input::get_mouse_button_mask); ObjectTypeDB::bind_method(_MD("set_mouse_mode","mode"),&Input::set_mouse_mode); diff --git a/core/os/input.h b/core/os/input.h index 387a43a35a..ce14c2166e 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 27c7c10aef..2bd62927b0 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -173,6 +173,16 @@ bool InputEvent::is_action(const String& p_action) const { return InputMap::get_singleton()->event_is_action(*this,p_action); } +bool InputEvent::is_action_pressed(const String& p_action) const { + + return is_action(p_action) && is_pressed() && !is_echo(); +} + +bool InputEvent::is_action_released(const String& p_action) const { + + return is_action(p_action) && !is_pressed(); +} + uint32_t InputEventKey::get_scancode_with_modifiers() const { uint32_t sc=scancode; diff --git a/core/os/input_event.h b/core/os/input_event.h index 218ff327d1..4bb122ebc1 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -287,6 +287,8 @@ struct InputEvent { bool is_pressed() const; bool is_action(const String& p_action) const; + bool is_action_pressed(const String& p_action) const; + bool is_action_released(const String& p_action) const; bool is_echo() const; void set_as_action(const String& p_action, bool p_pressed); diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index e2a992ecb9..10e64c3961 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/keyboard.h b/core/os/keyboard.h index b4ec5da26f..eaf656dd4d 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index d01331a256..b4c02ddbce 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -31,7 +31,20 @@ void MainLoop::_bind_methods() { - ObjectTypeDB::bind_method("input_event",&MainLoop::input_event); + ObjectTypeDB::bind_method(_MD("input_event","ev"),&MainLoop::input_event); + ObjectTypeDB::bind_method(_MD("input_text","text"),&MainLoop::input_text); + ObjectTypeDB::bind_method(_MD("init"),&MainLoop::init); + ObjectTypeDB::bind_method(_MD("iteration","delta"),&MainLoop::iteration); + ObjectTypeDB::bind_method(_MD("idle","delta"),&MainLoop::idle); + ObjectTypeDB::bind_method(_MD("finish"),&MainLoop::finish); + + BIND_VMETHOD( MethodInfo("_input_event",PropertyInfo(Variant::INPUT_EVENT,"ev")) ); + BIND_VMETHOD( MethodInfo("_input_text",PropertyInfo(Variant::STRING,"text")) ); + BIND_VMETHOD( MethodInfo("_initialize") ); + BIND_VMETHOD( MethodInfo("_iteration",PropertyInfo(Variant::REAL,"delta")) ); + BIND_VMETHOD( MethodInfo("_idle",PropertyInfo(Variant::REAL,"delta")) ); + BIND_VMETHOD( MethodInfo("_finalize") ); + BIND_CONSTANT(NOTIFICATION_WM_FOCUS_IN); BIND_CONSTANT(NOTIFICATION_WM_FOCUS_OUT); @@ -58,13 +71,15 @@ MainLoop::~MainLoop() void MainLoop::input_text( const String& p_text ) { + if (get_script_instance()) + get_script_instance()->call("_input_text",p_text); } void MainLoop::input_event( const InputEvent& p_event ) { if (get_script_instance()) - get_script_instance()->call("input_event",p_event); + get_script_instance()->call("_input_event",p_event); } @@ -74,13 +89,13 @@ void MainLoop::init() { set_script(init_script.get_ref_ptr()); if (get_script_instance()) - get_script_instance()->call("init"); + get_script_instance()->call("_initialize"); } bool MainLoop::iteration(float p_time) { if (get_script_instance()) - return get_script_instance()->call("iteration",p_time); + return get_script_instance()->call("_iteration",p_time); return false; @@ -88,14 +103,14 @@ bool MainLoop::iteration(float p_time) { bool MainLoop::idle(float p_time) { if (get_script_instance()) - return get_script_instance()->call("idle",p_time); + return get_script_instance()->call("_idle",p_time); return false; } void MainLoop::finish() { if (get_script_instance()) { - get_script_instance()->call("finish"); + get_script_instance()->call("_finalize"); set_script(RefPtr()); //clear script } diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 6eb5881175..bf9fe83a43 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/memory.cpp b/core/os/memory.cpp index ca5bacf9cd..1d9ac4e302 100644 --- a/core/os/memory.cpp +++ b/core/os/memory.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -112,13 +112,6 @@ size_t Memory::get_dynamic_mem_usage() { return MemoryPoolDynamic::get_singleton()->get_total_usage(); } -void * operator new(size_t p_size,void *p_pointer,size_t check, const char *p_description) { - - void *failptr=0; - ERR_FAIL_COND_V( check < p_size , failptr); /** bug, or strange compiler, most likely */ - - return p_pointer; -} diff --git a/core/os/memory.h b/core/os/memory.h index 6fc3d8f3eb..0a35c93fdb 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -236,11 +236,11 @@ void * operator new(size_t p_size,void *p_pointer,size_t check, const char *p_de #endif -_FORCE_INLINE_ void postinitialize_handler(void *) {} +_ALWAYS_INLINE_ void postinitialize_handler(void *) {} template<class T> -_FORCE_INLINE_ T *_post_initialize(T *p_obj) { +_ALWAYS_INLINE_ T *_post_initialize(T *p_obj) { postinitialize_handler(p_obj); return p_obj; @@ -249,19 +249,26 @@ _FORCE_INLINE_ T *_post_initialize(T *p_obj) { #ifdef DEBUG_MEMORY_ENABLED #define memnew(m_class) _post_initialize(new(__FILE__":"__STR(__LINE__)", memnew type: "__STR(m_class)) m_class) -#define memnew_placement(m_placement,m_class) _post_initialize(new(m_placement,sizeof(m_class),__FILE__":"__STR(__LINE__)", type: "__STR(m_class)) m_class) #else #define memnew(m_class) _post_initialize(new("") m_class) -#define memnew_placement(m_placement,m_class) _post_initialize(new(m_placement,sizeof(m_class),"") m_class) #endif +_ALWAYS_INLINE_ void * operator new(size_t p_size,void *p_pointer,size_t check, const char *p_description) { +// void *failptr=0; +// ERR_FAIL_COND_V( check < p_size , failptr); /** bug, or strange compiler, most likely */ + + return p_pointer; +} + + #define memnew_allocator(m_class,m_allocator) _post_initialize(new(m_allocator::alloc) m_class) +#define memnew_placement(m_placement,m_class) _post_initialize(new(m_placement,sizeof(m_class),"") m_class) -_FORCE_INLINE_ bool predelete_handler(void *) { return true; } +_ALWAYS_INLINE_ bool predelete_handler(void *) { return true; } template<class T> void memdelete(T *p_class) { diff --git a/core/os/memory_pool_dynamic.cpp b/core/os/memory_pool_dynamic.cpp index 4df554f18d..d1c41aff84 100644 --- a/core/os/memory_pool_dynamic.cpp +++ b/core/os/memory_pool_dynamic.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/memory_pool_dynamic.h b/core/os/memory_pool_dynamic.h index ca517daf41..00999ee24d 100644 --- a/core/os/memory_pool_dynamic.h +++ b/core/os/memory_pool_dynamic.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/memory_pool_dynamic_prealloc.cpp b/core/os/memory_pool_dynamic_prealloc.cpp index c5823366c1..c7c25f32d1 100644 --- a/core/os/memory_pool_dynamic_prealloc.cpp +++ b/core/os/memory_pool_dynamic_prealloc.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,91 +26,91 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "memory_pool_dynamic_prealloc.h"
-#include "os/memory.h"
-
-#include "print_string.h"
-MemoryPoolDynamicPrealloc::ID MemoryPoolDynamicPrealloc::alloc(size_t p_amount,const char* p_description) {
-
-
-// print_line("dynpool - allocating: "+itos(p_amount));
- ID id = pool_alloc->alloc(p_amount);
-// print_line("dynpool - free: "+itos(pool_alloc->get_free_mem()));
- return id;
-
-}
-
-void MemoryPoolDynamicPrealloc::free(ID p_id) {
-
- pool_alloc->free(p_id);
-}
-
-Error MemoryPoolDynamicPrealloc::realloc(ID p_id, size_t p_amount) {
-
- return pool_alloc->resize(p_id,p_amount);
-}
-
-bool MemoryPoolDynamicPrealloc::is_valid(ID p_id) {
-
- return true;
-}
-
-size_t MemoryPoolDynamicPrealloc::get_size(ID p_id) const {
-
- return pool_alloc->get_size(p_id);
-}
-
-const char* MemoryPoolDynamicPrealloc::get_description(ID p_id) const {
-
- return "";
-}
-
-Error MemoryPoolDynamicPrealloc::lock(ID p_id) {
-
-// print_line("lock: "+itos(p_id));
- return pool_alloc->lock(p_id);
-}
-
-void * MemoryPoolDynamicPrealloc::get(ID p_ID) {
-
-// print_line("get: "+itos(p_ID));
- return pool_alloc->get(p_ID);
-}
-
-Error MemoryPoolDynamicPrealloc::unlock(ID p_id) {
-
-// print_line("unlock: "+itos(p_id));
- pool_alloc->unlock(p_id);
- return OK;
-}
-
-bool MemoryPoolDynamicPrealloc::is_locked(ID p_id) const {
-
- return pool_alloc->is_locked(p_id);
-}
-
-
-size_t MemoryPoolDynamicPrealloc::get_available_mem() const {
-
- return pool_alloc->get_free_mem();
-}
-
-size_t MemoryPoolDynamicPrealloc::get_total_usage() const {
-
- return pool_alloc->get_used_mem();
-}
-
-
-
-MemoryPoolDynamicPrealloc::MemoryPoolDynamicPrealloc(void * p_mem,int p_size, int p_align, int p_max_entries) {
-
- pool_alloc = memnew( PoolAllocator(p_mem,p_size,p_align,true,p_max_entries));
-
-}
-
-MemoryPoolDynamicPrealloc::~MemoryPoolDynamicPrealloc() {
-
-
- memdelete( pool_alloc );
-}
-
+#include "memory_pool_dynamic_prealloc.h" +#include "os/memory.h" + +#include "print_string.h" +MemoryPoolDynamicPrealloc::ID MemoryPoolDynamicPrealloc::alloc(size_t p_amount,const char* p_description) { + + +// print_line("dynpool - allocating: "+itos(p_amount)); + ID id = pool_alloc->alloc(p_amount); +// print_line("dynpool - free: "+itos(pool_alloc->get_free_mem())); + return id; + +} + +void MemoryPoolDynamicPrealloc::free(ID p_id) { + + pool_alloc->free(p_id); +} + +Error MemoryPoolDynamicPrealloc::realloc(ID p_id, size_t p_amount) { + + return pool_alloc->resize(p_id,p_amount); +} + +bool MemoryPoolDynamicPrealloc::is_valid(ID p_id) { + + return true; +} + +size_t MemoryPoolDynamicPrealloc::get_size(ID p_id) const { + + return pool_alloc->get_size(p_id); +} + +const char* MemoryPoolDynamicPrealloc::get_description(ID p_id) const { + + return ""; +} + +Error MemoryPoolDynamicPrealloc::lock(ID p_id) { + +// print_line("lock: "+itos(p_id)); + return pool_alloc->lock(p_id); +} + +void * MemoryPoolDynamicPrealloc::get(ID p_ID) { + +// print_line("get: "+itos(p_ID)); + return pool_alloc->get(p_ID); +} + +Error MemoryPoolDynamicPrealloc::unlock(ID p_id) { + +// print_line("unlock: "+itos(p_id)); + pool_alloc->unlock(p_id); + return OK; +} + +bool MemoryPoolDynamicPrealloc::is_locked(ID p_id) const { + + return pool_alloc->is_locked(p_id); +} + + +size_t MemoryPoolDynamicPrealloc::get_available_mem() const { + + return pool_alloc->get_free_mem(); +} + +size_t MemoryPoolDynamicPrealloc::get_total_usage() const { + + return pool_alloc->get_used_mem(); +} + + + +MemoryPoolDynamicPrealloc::MemoryPoolDynamicPrealloc(void * p_mem,int p_size, int p_align, int p_max_entries) { + + pool_alloc = memnew( PoolAllocator(p_mem,p_size,p_align,true,p_max_entries)); + +} + +MemoryPoolDynamicPrealloc::~MemoryPoolDynamicPrealloc() { + + + memdelete( pool_alloc ); +} + diff --git a/core/os/memory_pool_dynamic_prealloc.h b/core/os/memory_pool_dynamic_prealloc.h index 698885561a..3523079bac 100644 --- a/core/os/memory_pool_dynamic_prealloc.h +++ b/core/os/memory_pool_dynamic_prealloc.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,35 +26,35 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef MEMORY_POOL_DYNAMIC_PREALLOC_H
-#define MEMORY_POOL_DYNAMIC_PREALLOC_H
-
-#include "pool_allocator.h"
-#include "core/os/memory_pool_dynamic.h"
-
-class MemoryPoolDynamicPrealloc : public MemoryPoolDynamic {
-
- PoolAllocator *pool_alloc;
-
-public:
-
- virtual ID alloc(size_t p_amount,const char* p_description);
- virtual void free(ID p_id);
- virtual Error realloc(ID p_id, size_t p_amount);
- virtual bool is_valid(ID p_id);
- virtual size_t get_size(ID p_id) const;
- virtual const char* get_description(ID p_id) const;
-
- virtual Error lock(ID p_id);
- virtual void * get(ID p_ID);
- virtual Error unlock(ID p_id);
- virtual bool is_locked(ID p_id) const;
-
- virtual size_t get_available_mem() const;
- virtual size_t get_total_usage() const;
-
- MemoryPoolDynamicPrealloc(void * p_mem,int p_size, int p_align = 16, int p_max_entries=PoolAllocator::DEFAULT_MAX_ALLOCS);
- ~MemoryPoolDynamicPrealloc();
-};
-
-#endif // MEMORY_POOL_DYNAMIC_PREALLOC_H
+#ifndef MEMORY_POOL_DYNAMIC_PREALLOC_H +#define MEMORY_POOL_DYNAMIC_PREALLOC_H + +#include "pool_allocator.h" +#include "core/os/memory_pool_dynamic.h" + +class MemoryPoolDynamicPrealloc : public MemoryPoolDynamic { + + PoolAllocator *pool_alloc; + +public: + + virtual ID alloc(size_t p_amount,const char* p_description); + virtual void free(ID p_id); + virtual Error realloc(ID p_id, size_t p_amount); + virtual bool is_valid(ID p_id); + virtual size_t get_size(ID p_id) const; + virtual const char* get_description(ID p_id) const; + + virtual Error lock(ID p_id); + virtual void * get(ID p_ID); + virtual Error unlock(ID p_id); + virtual bool is_locked(ID p_id) const; + + virtual size_t get_available_mem() const; + virtual size_t get_total_usage() const; + + MemoryPoolDynamicPrealloc(void * p_mem,int p_size, int p_align = 16, int p_max_entries=PoolAllocator::DEFAULT_MAX_ALLOCS); + ~MemoryPoolDynamicPrealloc(); +}; + +#endif // MEMORY_POOL_DYNAMIC_PREALLOC_H diff --git a/core/os/memory_pool_dynamic_static.cpp b/core/os/memory_pool_dynamic_static.cpp index 93f94d7726..029ef450cd 100644 --- a/core/os/memory_pool_dynamic_static.cpp +++ b/core/os/memory_pool_dynamic_static.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/memory_pool_dynamic_static.h b/core/os/memory_pool_dynamic_static.h index d10cdb3d0a..a870f3070c 100644 --- a/core/os/memory_pool_dynamic_static.h +++ b/core/os/memory_pool_dynamic_static.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/memory_pool_static.cpp b/core/os/memory_pool_static.cpp index 9dd5baf4e4..d3617eac73 100644 --- a/core/os/memory_pool_static.cpp +++ b/core/os/memory_pool_static.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/memory_pool_static.h b/core/os/memory_pool_static.h index f2b372d03b..40bd1aaf0e 100644 --- a/core/os/memory_pool_static.h +++ b/core/os/memory_pool_static.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp index 03d423ae04..be984c080b 100644 --- a/core/os/mutex.cpp +++ b/core/os/mutex.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/mutex.h b/core/os/mutex.h index 241d70e232..ac6d36d635 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/os.cpp b/core/os/os.cpp index 5e0e5eed77..f292456079 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -43,6 +43,9 @@ OS* OS::get_singleton() { uint32_t OS::get_ticks_msec() const { return get_ticks_usec()/1000; } +uint64_t OS::get_splash_tick_msec() const { + return _msec_splash; +} uint64_t OS::get_unix_time() const { return 0; diff --git a/core/os/os.h b/core/os/os.h index d4ac433644..0230a75ca0 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -51,6 +51,7 @@ class OS { String _local_clipboard; uint64_t frames_drawn; uint32_t _frame_delay; + uint64_t _msec_splash; bool _no_window; int _exit_code; int _orientation; @@ -243,14 +244,21 @@ public: int min; int sec; }; - - virtual Date get_date() const=0; - virtual Time get_time() const=0; + + struct TimeZoneInfo { + int bias; + String name; + }; + + virtual Date get_date(bool local=false) const=0; + virtual Time get_time(bool local=false) const=0; + virtual TimeZoneInfo get_time_zone_info() const=0; virtual uint64_t get_unix_time() const; virtual void delay_usec(uint32_t p_usec) const=0; virtual uint64_t get_ticks_usec() const=0; uint32_t get_ticks_msec() const; + uint64_t get_splash_tick_msec() const; void set_frame_delay(uint32_t p_msec); uint32_t get_frame_delay() const; @@ -384,6 +392,8 @@ public: void set_time_scale(float p_scale); float get_time_scale() const; + + OS(); virtual ~OS(); diff --git a/core/os/pc_joystick_map.h b/core/os/pc_joystick_map.h index 171723439b..111dc9b3a8 100644 --- a/core/os/pc_joystick_map.h +++ b/core/os/pc_joystick_map.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/semaphore.cpp b/core/os/semaphore.cpp index 3abab34886..8cb431d2cc 100644 --- a/core/os/semaphore.cpp +++ b/core/os/semaphore.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/semaphore.h b/core/os/semaphore.h index b188f07399..e8ad9d3c3a 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/shell.cpp b/core/os/shell.cpp index 565929eae5..3746dc6804 100644 --- a/core/os/shell.cpp +++ b/core/os/shell.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/shell.h b/core/os/shell.h index 38b29c6eca..7ef5abbdef 100644 --- a/core/os/shell.h +++ b/core/os/shell.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/thread.cpp b/core/os/thread.cpp index d8d9f3e291..96b0f561ca 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/thread.h b/core/os/thread.h index 864fc6db05..590fee1fc6 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/thread_dummy.cpp b/core/os/thread_dummy.cpp index 1974bf615b..4e139f6379 100644 --- a/core/os/thread_dummy.cpp +++ b/core/os/thread_dummy.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/thread_dummy.h b/core/os/thread_dummy.h index b681005fb6..a83e42ff98 100644 --- a/core/os/thread_dummy.h +++ b/core/os/thread_dummy.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/thread_safe.cpp b/core/os/thread_safe.cpp index 9c7648be94..9a20db6a9d 100644 --- a/core/os/thread_safe.cpp +++ b/core/os/thread_safe.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/os/thread_safe.h b/core/os/thread_safe.h index 8b20c31cc9..62d2181279 100644 --- a/core/os/thread_safe.h +++ b/core/os/thread_safe.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp index 65a6433912..fa17e93aa8 100644 --- a/core/packed_data_container.cpp +++ b/core/packed_data_container.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/packed_data_container.h b/core/packed_data_container.h index b223d3bcfe..f4152bbb4d 100644 --- a/core/packed_data_container.h +++ b/core/packed_data_container.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/pair.cpp b/core/pair.cpp index 4b6f350351..17076bb379 100644 --- a/core/pair.cpp +++ b/core/pair.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/pair.h b/core/pair.h index d4cf3630ee..83fc837fff 100644 --- a/core/pair.h +++ b/core/pair.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/path_db.cpp b/core/path_db.cpp index 1027ce7318..d3dc3aceb8 100644 --- a/core/path_db.cpp +++ b/core/path_db.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/path_db.h b/core/path_db.h index 561dc01672..b4f13d50be 100644 --- a/core/path_db.h +++ b/core/path_db.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/path_remap.cpp b/core/path_remap.cpp index 34675c4575..2ef39470a0 100644 --- a/core/path_remap.cpp +++ b/core/path_remap.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,163 +26,163 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "path_remap.h"
-#include "globals.h"
-#include "os/os.h"
-#include "translation.h"
-PathRemap* PathRemap::singleton=NULL;
-
-PathRemap* PathRemap::get_singleton() {
-
- return singleton;
-}
-
-void PathRemap::add_remap(const String& p_from, const String& p_to,const String& p_locale) {
-
- if (!remap.has(p_from)) {
- remap[p_from]=RemapData();
- }
-
- if (p_locale==String())
- remap[p_from].always=p_to;
- else
- remap[p_from].locale[p_locale]=p_to;
-}
-
-
-String PathRemap::get_remap(const String& p_from) const {
-
- const RemapData *ptr=remap.getptr(p_from);
- if (!ptr) {
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap failed: "+p_from);
- return p_from;
- } else {
-
- String locale = TranslationServer::get_singleton()->get_locale();
-
- if (ptr->locale.has(locale)) {
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap found: "+p_from+" -> "+ptr->locale[locale]);
- return ptr->locale[locale];
- }
-
- int p = locale.find("_");
- if (p!=-1) {
- locale=locale.substr(0,p);
- if (ptr->locale.has(locale)) {
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap found: "+p_from+" -> "+ptr->locale[locale]);
- return ptr->locale[locale];
- }
- }
-
- if (ptr->always!=String()) {
- if (OS::get_singleton()->is_stdout_verbose()) {
- print_line("remap found: "+p_from+" -> "+ptr->always);
- }
- return ptr->always;
- }
-
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap failed: "+p_from);
-
- return p_from;
- }
-}
-bool PathRemap::has_remap(const String& p_from) const{
-
- return remap.has(p_from);
-}
-
-void PathRemap::erase_remap(const String& p_from){
-
- ERR_FAIL_COND(!remap.has(p_from));
- remap.erase(p_from);
-}
-
-void PathRemap::clear_remaps() {
-
- remap.clear();
-}
-
-void PathRemap::load_remaps() {
-
- // default remaps first
- DVector<String> remaps = Globals::get_singleton()->get("remap/all");
-
- {
- int rlen = remaps.size();
-
- ERR_FAIL_COND( rlen%2 );
- DVector<String>::Read r = remaps.read();
- for(int i=0;i<rlen/2;i++) {
-
- String from = r[i*2+0];
- String to = r[i*2+1];
- add_remap(from,to);
- }
- }
-
-
- // platform remaps second, so override
- remaps = Globals::get_singleton()->get("remap/"+OS::get_singleton()->get_name());
-// remaps = Globals::get_singleton()->get("remap/PSP");
- {
- int rlen = remaps.size();
-
- ERR_FAIL_COND( rlen%2 );
- DVector<String>::Read r = remaps.read();
- for(int i=0;i<rlen/2;i++) {
-
- String from = r[i*2+0];
- String to = r[i*2+1];
-// print_line("add remap: "+from+" -> "+to);
- add_remap(from,to);
- }
- }
-
-
- //locale based remaps
-
- if (Globals::get_singleton()->has("locale/translation_remaps")) {
-
- Dictionary remaps = Globals::get_singleton()->get("locale/translation_remaps");
- List<Variant> rk;
- remaps.get_key_list(&rk);
- for(List<Variant>::Element *E=rk.front();E;E=E->next()) {
-
- String source = E->get();
- StringArray sa = remaps[E->get()];
- int sas = sa.size();
- StringArray::Read r = sa.read();
-
- for(int i=0;i<sas;i++) {
-
- String s = r[i];
- int qp = s.find_last(":");
- if (qp!=-1) {
- String path = s.substr(0,qp);
- String locale = s.substr(qp+1,s.length());
- add_remap(source,path,locale);
- }
- }
- }
-
- }
-
-}
-
-void PathRemap::_bind_methods() {
-
- ObjectTypeDB::bind_method(_MD("add_remap","from","to","locale"),&PathRemap::add_remap,DEFVAL(String()));
- ObjectTypeDB::bind_method(_MD("has_remap","path"),&PathRemap::has_remap);
- ObjectTypeDB::bind_method(_MD("get_remap","path"),&PathRemap::get_remap);
- ObjectTypeDB::bind_method(_MD("erase_remap","path"),&PathRemap::erase_remap);
- ObjectTypeDB::bind_method(_MD("clear_remaps"),&PathRemap::clear_remaps);
-}
-
-PathRemap::PathRemap() {
-
- singleton=this;
-}
+#include "path_remap.h" +#include "globals.h" +#include "os/os.h" +#include "translation.h" +PathRemap* PathRemap::singleton=NULL; + +PathRemap* PathRemap::get_singleton() { + + return singleton; +} + +void PathRemap::add_remap(const String& p_from, const String& p_to,const String& p_locale) { + + if (!remap.has(p_from)) { + remap[p_from]=RemapData(); + } + + if (p_locale==String()) + remap[p_from].always=p_to; + else + remap[p_from].locale[p_locale]=p_to; +} + + +String PathRemap::get_remap(const String& p_from) const { + + const RemapData *ptr=remap.getptr(p_from); + if (!ptr) { + if (OS::get_singleton()->is_stdout_verbose()) + print_line("remap failed: "+p_from); + return p_from; + } else { + + String locale = TranslationServer::get_singleton()->get_locale(); + + if (ptr->locale.has(locale)) { + if (OS::get_singleton()->is_stdout_verbose()) + print_line("remap found: "+p_from+" -> "+ptr->locale[locale]); + return ptr->locale[locale]; + } + + int p = locale.find("_"); + if (p!=-1) { + locale=locale.substr(0,p); + if (ptr->locale.has(locale)) { + if (OS::get_singleton()->is_stdout_verbose()) + print_line("remap found: "+p_from+" -> "+ptr->locale[locale]); + return ptr->locale[locale]; + } + } + + if (ptr->always!=String()) { + if (OS::get_singleton()->is_stdout_verbose()) { + print_line("remap found: "+p_from+" -> "+ptr->always); + } + return ptr->always; + } + + if (OS::get_singleton()->is_stdout_verbose()) + print_line("remap failed: "+p_from); + + return p_from; + } +} +bool PathRemap::has_remap(const String& p_from) const{ + + return remap.has(p_from); +} + +void PathRemap::erase_remap(const String& p_from){ + + ERR_FAIL_COND(!remap.has(p_from)); + remap.erase(p_from); +} + +void PathRemap::clear_remaps() { + + remap.clear(); +} + +void PathRemap::load_remaps() { + + // default remaps first + DVector<String> remaps = Globals::get_singleton()->get("remap/all"); + + { + int rlen = remaps.size(); + + ERR_FAIL_COND( rlen%2 ); + DVector<String>::Read r = remaps.read(); + for(int i=0;i<rlen/2;i++) { + + String from = r[i*2+0]; + String to = r[i*2+1]; + add_remap(from,to); + } + } + + + // platform remaps second, so override + remaps = Globals::get_singleton()->get("remap/"+OS::get_singleton()->get_name()); +// remaps = Globals::get_singleton()->get("remap/PSP"); + { + int rlen = remaps.size(); + + ERR_FAIL_COND( rlen%2 ); + DVector<String>::Read r = remaps.read(); + for(int i=0;i<rlen/2;i++) { + + String from = r[i*2+0]; + String to = r[i*2+1]; +// print_line("add remap: "+from+" -> "+to); + add_remap(from,to); + } + } + + + //locale based remaps + + if (Globals::get_singleton()->has("locale/translation_remaps")) { + + Dictionary remaps = Globals::get_singleton()->get("locale/translation_remaps"); + List<Variant> rk; + remaps.get_key_list(&rk); + for(List<Variant>::Element *E=rk.front();E;E=E->next()) { + + String source = E->get(); + StringArray sa = remaps[E->get()]; + int sas = sa.size(); + StringArray::Read r = sa.read(); + + for(int i=0;i<sas;i++) { + + String s = r[i]; + int qp = s.find_last(":"); + if (qp!=-1) { + String path = s.substr(0,qp); + String locale = s.substr(qp+1,s.length()); + add_remap(source,path,locale); + } + } + } + + } + +} + +void PathRemap::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("add_remap","from","to","locale"),&PathRemap::add_remap,DEFVAL(String())); + ObjectTypeDB::bind_method(_MD("has_remap","path"),&PathRemap::has_remap); + ObjectTypeDB::bind_method(_MD("get_remap","path"),&PathRemap::get_remap); + ObjectTypeDB::bind_method(_MD("erase_remap","path"),&PathRemap::erase_remap); + ObjectTypeDB::bind_method(_MD("clear_remaps"),&PathRemap::clear_remaps); +} + +PathRemap::PathRemap() { + + singleton=this; +} diff --git a/core/path_remap.h b/core/path_remap.h index a463cf259e..cb2a045668 100644 --- a/core/path_remap.h +++ b/core/path_remap.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,42 +26,42 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef PATH_REMAP_H
-#define PATH_REMAP_H
-
-#include "hash_map.h"
-#include "ustring.h"
-#include "object.h"
-
-
-class PathRemap : public Object {
-
- OBJ_TYPE(PathRemap,Object);
-
- static PathRemap* singleton;
- struct RemapData {
- String always;
- Map<String,String> locale;
- };
-
- HashMap<String,RemapData> remap;
-protected:
-
- static void _bind_methods();
-public:
-
- void add_remap(const String& p_from, const String& p_to,const String& p_locale=String());
- bool has_remap(const String& p_from) const;
- //_FORCE_INLINE_ String get_remap(const String& p_from) const { const String *ptr=remap.getptr(p_from); if (!ptr) return p_from; else return *ptr; }
- String get_remap(const String& p_from) const;
- void erase_remap(const String& p_from);
- void clear_remaps();
-
- void load_remaps();
-
- static PathRemap* get_singleton();
-
- PathRemap();
-};
-
-#endif // PATH_REMAP_H
+#ifndef PATH_REMAP_H +#define PATH_REMAP_H + +#include "hash_map.h" +#include "ustring.h" +#include "object.h" + + +class PathRemap : public Object { + + OBJ_TYPE(PathRemap,Object); + + static PathRemap* singleton; + struct RemapData { + String always; + Map<String,String> locale; + }; + + HashMap<String,RemapData> remap; +protected: + + static void _bind_methods(); +public: + + void add_remap(const String& p_from, const String& p_to,const String& p_locale=String()); + bool has_remap(const String& p_from) const; + //_FORCE_INLINE_ String get_remap(const String& p_from) const { const String *ptr=remap.getptr(p_from); if (!ptr) return p_from; else return *ptr; } + String get_remap(const String& p_from) const; + void erase_remap(const String& p_from); + void clear_remaps(); + + void load_remaps(); + + static PathRemap* get_singleton(); + + PathRemap(); +}; + +#endif // PATH_REMAP_H diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp index 5af168ce82..d7dca45836 100644 --- a/core/pool_allocator.cpp +++ b/core/pool_allocator.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/pool_allocator.h b/core/pool_allocator.h index 4b94ae48d6..4b0f931eb3 100644 --- a/core/pool_allocator.h +++ b/core/pool_allocator.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/print_string.cpp b/core/print_string.cpp index ae15d05a35..42e018f303 100644 --- a/core/print_string.cpp +++ b/core/print_string.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -32,6 +32,7 @@ static PrintHandlerList *print_handler_list=NULL; bool _print_line_enabled=true; +bool _print_error_enabled = true; void add_print_handler(PrintHandlerList *p_handler) { diff --git a/core/print_string.h b/core/print_string.h index c3e91f32fa..4ea389b3a1 100644 --- a/core/print_string.h +++ b/core/print_string.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -52,6 +52,7 @@ void add_print_handler(PrintHandlerList *p_handler); void remove_print_handler(PrintHandlerList *p_handler); extern bool _print_line_enabled; +extern bool _print_error_enabled; extern void print_line(String p_string); #endif diff --git a/core/ref_ptr.cpp b/core/ref_ptr.cpp index f0758f66ce..ddb8054e3b 100644 --- a/core/ref_ptr.cpp +++ b/core/ref_ptr.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/ref_ptr.h b/core/ref_ptr.h index 007977d993..d1ee6a3a7d 100644 --- a/core/ref_ptr.h +++ b/core/ref_ptr.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/reference.cpp b/core/reference.cpp index 2fc941310d..509e132b5a 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -59,6 +59,10 @@ void Reference::_bind_methods() { ObjectTypeDB::bind_method(_MD("unreference"),&Reference::unreference); } +int Reference::reference_get_count() const { + return refcount.get(); +} + void Reference::reference(){ refcount.ref(); diff --git a/core/reference.h b/core/reference.h index 64d7a7acad..65f31f78f3 100644 --- a/core/reference.h +++ b/core/reference.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -53,6 +53,7 @@ public: bool init_ref(); void reference(); bool unreference(); + int reference_get_count() const; Reference(); ~Reference(); @@ -293,6 +294,9 @@ public: reference=NULL; } + void instance() { + ref( memnew( T )); + } Ref() { diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 4935136eeb..8754946bb1 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -205,12 +205,14 @@ void unregister_core_types() { if (ip) memdelete(ip); + + ObjectDB::cleanup(); + unregister_variant_methods(); - CoreStringNames::free(); ObjectTypeDB::cleanup(); ResourceCache::clear(); - ObjectDB::cleanup(); + CoreStringNames::free(); StringName::cleanup(); if (_global_mutex) { diff --git a/core/register_core_types.h b/core/register_core_types.h index 9f89a3ffeb..a84849c969 100644 --- a/core/register_core_types.h +++ b/core/register_core_types.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/res_ptr.cpp b/core/res_ptr.cpp index b9bd931570..fcff285e8f 100644 --- a/core/res_ptr.cpp +++ b/core/res_ptr.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/res_ptr.h b/core/res_ptr.h index 69da69bf52..21f7fb6a2c 100644 --- a/core/res_ptr.h +++ b/core/res_ptr.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/resource.cpp b/core/resource.cpp index 560ca9a1f2..6967599f96 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -195,6 +195,17 @@ String Resource::get_path() const { return path_cache; } +void Resource::set_subindex(int p_sub_index) { + + subindex=p_sub_index; +} + +int Resource::get_subindex() const{ + + return subindex; +} + + void Resource::set_name(const String& p_name) { name=p_name; @@ -326,6 +337,7 @@ Resource::Resource() { last_modified_time=0; #endif + subindex=0; } diff --git a/core/resource.h b/core/resource.h index 8a637e7996..9d9c445e1d 100644 --- a/core/resource.h +++ b/core/resource.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -99,6 +99,7 @@ friend class ResourceCache; String name; String path_cache; + int subindex; virtual bool _use_builtin_script() const { return true; } @@ -132,6 +133,9 @@ public: void set_path(const String& p_path,bool p_take_over=false); String get_path() const; + void set_subindex(int p_sub_index); + int get_subindex() const; + Ref<Resource> duplicate(bool p_subresources=false); void set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata); diff --git a/core/rid.cpp b/core/rid.cpp index 3dc4c6aed4..0870e6ab2d 100644 --- a/core/rid.cpp +++ b/core/rid.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/rid.h b/core/rid.h index 4d4e11c251..e6582757ee 100644 --- a/core/rid.h +++ b/core/rid.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/ring_buffer.h b/core/ring_buffer.h index 71105e7bf1..de33de0c76 100644 --- a/core/ring_buffer.h +++ b/core/ring_buffer.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp index 3d867448e8..afe2a4eb33 100644 --- a/core/safe_refcount.cpp +++ b/core/safe_refcount.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/safe_refcount.h b/core/safe_refcount.h index 4357786732..481b9fa7e9 100644 --- a/core/safe_refcount.h +++ b/core/safe_refcount.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/script_debugger_debugger.cpp b/core/script_debugger_debugger.cpp index 6ff60e6ff4..5c592a130c 100644 --- a/core/script_debugger_debugger.cpp +++ b/core/script_debugger_debugger.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp index 5e153a4912..649bbe89f0 100644 --- a/core/script_debugger_local.cpp +++ b/core/script_debugger_local.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -60,7 +60,7 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) { if (line.get_slice_count(" ")==1) { print_line("*Frame "+itos(current_frame)+" - "+p_script->debug_get_stack_level_source(current_frame)+":"+itos(p_script->debug_get_stack_level_line(current_frame))+" in function '"+p_script->debug_get_stack_level_function(current_frame)+"'"); } else { - int frame = line.get_slice(" ",1).to_int(); + int frame = line.get_slicec(' ',1).to_int(); if (frame<0 || frame >=total_frames) { print_line("Error: Invalid frame."); } else { @@ -108,7 +108,7 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) { print_line("Usage: print <expre>"); } else { - String expr = line.get_slice(" ",2); + String expr = line.get_slicec(' ',2); String res = p_script->debug_parse_stack_level_expression(current_frame,expr); print_line(res); } @@ -130,9 +130,9 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) { } else { - String bppos=line.get_slice(" ",1); - String source=bppos.get_slice(":",0).strip_edges(); - int line=bppos.get_slice(":",1).strip_edges().to_int(); + String bppos=line.get_slicec(' ',1); + String source=bppos.get_slicec(':',0).strip_edges(); + int line=bppos.get_slicec(':',1).strip_edges().to_int(); source = breakpoint_find_source(source); @@ -147,9 +147,9 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) { clear_breakpoints(); } else { - String bppos=line.get_slice(" ",1); - String source=bppos.get_slice(":",0).strip_edges(); - int line=bppos.get_slice(":",1).strip_edges().to_int(); + String bppos=line.get_slicec(' ',1); + String source=bppos.get_slicec(':',0).strip_edges(); + int line=bppos.get_slicec(':',1).strip_edges().to_int(); source = breakpoint_find_source(source); diff --git a/core/script_debugger_local.h b/core/script_debugger_local.h index 159dd15e58..45ff1d4466 100644 --- a/core/script_debugger_local.h +++ b/core/script_debugger_local.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index cd8303b542..33e9dc0fd9 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/script_debugger_remote.h b/core/script_debugger_remote.h index 861bcccff7..89b9947c4b 100644 --- a/core/script_debugger_remote.h +++ b/core/script_debugger_remote.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/script_language.cpp b/core/script_language.cpp index 81a9e2b062..35c50b1022 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -136,6 +136,14 @@ ScriptInstance::~ScriptInstance() { } + +ScriptCodeCompletionCache *ScriptCodeCompletionCache::singleton=NULL; +ScriptCodeCompletionCache::ScriptCodeCompletionCache() { + singleton=this; +} + + + void ScriptLanguage::frame() { diff --git a/core/script_language.h b/core/script_language.h index 802eff190a..7104fe4547 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -94,6 +94,10 @@ public: virtual ScriptLanguage *get_language() const=0; + virtual bool has_script_signal(const StringName& p_signal) const=0; + virtual void get_script_signal_list(List<MethodInfo> *r_signals) const=0; + + virtual void update_exports() {} //editor tool @@ -122,6 +126,19 @@ public: virtual ~ScriptInstance(); }; +class ScriptCodeCompletionCache { + + static ScriptCodeCompletionCache *singleton; +public: + + virtual RES get_cached_resource(const String& p_path)=0; + + static ScriptCodeCompletionCache* get_sigleton() { return singleton; } + + ScriptCodeCompletionCache(); + +}; + class ScriptLanguage { public: diff --git a/core/self_list.h b/core/self_list.h index 729b9fb680..b414baaba6 100644 --- a/core/self_list.h +++ b/core/self_list.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/set.h b/core/set.h index 95f38d7108..91c4e3f9c4 100644 --- a/core/set.h +++ b/core/set.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/simple_type.h b/core/simple_type.h index fac6dceee8..84e08bf0b4 100644 --- a/core/simple_type.h +++ b/core/simple_type.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/sort.h b/core/sort.h index 583437a099..65664d0ed8 100644 --- a/core/sort.h +++ b/core/sort.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/string_db.cpp b/core/string_db.cpp index ffb7dc194b..b48d9f37d4 100644 --- a/core/string_db.cpp +++ b/core/string_db.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -28,7 +28,7 @@ /*************************************************************************/ #include "string_db.h" #include "print_string.h" - +#include "os/os.h" StaticCString StaticCString::create(const char *p_ptr) { StaticCString scs; scs.ptr=p_ptr; return scs; } @@ -55,15 +55,29 @@ void StringName::setup() { void StringName::cleanup() { _global_lock(); + int lost_strings=0; for(int i=0;i<STRING_TABLE_LEN;i++) { while(_table[i]) { _Data*d=_table[i]; - _table[i]=_table[i]->next; + lost_strings++; + if (OS::get_singleton()->is_stdout_verbose()) { + + if (d->cname) { + print_line("Orphan StringName: "+String(d->cname)); + } else { + print_line("Orphan StringName: "+String(d->name)); + } + } + + _table[i]=_table[i]->next; memdelete(d); } } + if (OS::get_singleton()->is_stdout_verbose() && lost_strings) { + print_line("StringName: "+itos(lost_strings)+" unclaimed string names at exit."); + } _global_unlock(); } @@ -144,7 +158,7 @@ void StringName::operator=(const StringName& p_name) { _data = p_name._data; } } - +/* was inlined StringName::operator String() const { if (_data) @@ -152,7 +166,7 @@ StringName::operator String() const { return ""; } - +*/ StringName::StringName(const StringName& p_name) { ERR_FAIL_COND(!configured); diff --git a/core/string_db.h b/core/string_db.h index 45afbbe6fc..3b3249bf5e 100644 --- a/core/string_db.h +++ b/core/string_db.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -114,7 +114,17 @@ public: } bool operator!=(const StringName& p_name) const; - operator String() const; + _FORCE_INLINE_ operator String() const { + + if (_data) { + if (_data->cname ) + return String(_data->cname); + else + return _data->name; + } + + return String(); + } static StringName search(const char *p_name); static StringName search(const CharType *p_name); diff --git a/core/translation.cpp b/core/translation.cpp index 6ad34651b2..8247cd1201 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/translation.h b/core/translation.h index d690320cd0..54118cd3b5 100644 --- a/core/translation.h +++ b/core/translation.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/typedefs.h b/core/typedefs.h index 442ed9ae0b..ae1eb1f5e7 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index 2c4d9e16a8..f565070216 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -234,11 +234,17 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { ERR_FAIL_COND(!obj); } + switch(op.type) { case Operation::TYPE_METHOD: { - obj->call(op.name,VARIANT_ARGS_FROM_ARRAY(op.args)); + obj->call(op.name,VARIANT_ARGS_FROM_ARRAY(op.args)); +#ifdef TOOLS_ENABLED + Resource* res = obj->cast_to<Resource>(); + if (res) + res->set_edited(true); +#endif } break; case Operation::TYPE_PROPERTY: { @@ -276,6 +282,7 @@ void UndoRedo::undo() { return; //nothing to redo _process_operation_list(actions[current_action].undo_ops.front()); current_action--; + version--; } void UndoRedo::clear_history() { @@ -286,7 +293,7 @@ void UndoRedo::clear_history() { while(actions.size()) _pop_history_tail(); - version++; + //version++; } String UndoRedo::get_current_action_name() const { @@ -320,7 +327,7 @@ void UndoRedo::set_commit_notify_callback(CommitNotifyCallback p_callback,void* UndoRedo::UndoRedo() { - version=0; + version=1; action_level=0; current_action=-1; max_steps=-1; @@ -333,3 +340,126 @@ UndoRedo::~UndoRedo() { clear_history(); } + +Variant UndoRedo::_add_do_method(const Variant** p_args, int p_argcount, Variant::CallError& r_error) { + + if (p_argcount<2) { + r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument=0; + return Variant(); + } + + if (p_args[0]->get_type()!=Variant::OBJECT) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::OBJECT; + return Variant(); + } + + if (p_args[1]->get_type()!=Variant::STRING) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=1; + r_error.expected=Variant::STRING; + return Variant(); + } + + r_error.error=Variant::CallError::CALL_OK; + + Object* object = *p_args[0]; + String method = *p_args[1]; + + Variant v[VARIANT_ARG_MAX]; + + + for(int i=0;i<MIN(VARIANT_ARG_MAX,p_argcount-2);++i) { + + v[i]=*p_args[i+2]; + } + + add_do_method(object,method,v[0],v[1],v[2],v[3],v[4]); + return Variant(); +} + +Variant UndoRedo::_add_undo_method(const Variant** p_args, int p_argcount, Variant::CallError& r_error) { + + if (p_argcount<2) { + r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument=0; + return Variant(); + } + + if (p_args[0]->get_type()!=Variant::OBJECT) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::OBJECT; + return Variant(); + } + + if (p_args[1]->get_type()!=Variant::STRING) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=1; + r_error.expected=Variant::STRING; + return Variant(); + } + + r_error.error=Variant::CallError::CALL_OK; + + Object* object = *p_args[0]; + String method = *p_args[1]; + + Variant v[VARIANT_ARG_MAX]; + + + for(int i=0;i<MIN(VARIANT_ARG_MAX,p_argcount-2);++i) { + + v[i]=*p_args[i+2]; + } + + add_undo_method(object,method,v[0],v[1],v[2],v[3],v[4]); + return Variant(); +} + +void UndoRedo::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("create_action","name","mergeable"),&UndoRedo::create_action, DEFVAL(false) ); + ObjectTypeDB::bind_method(_MD("commit_action"),&UndoRedo::commit_action); + + //ObjectTypeDB::bind_method(_MD("add_do_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_do_method); + //ObjectTypeDB::bind_method(_MD("add_undo_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_undo_method); + + { + MethodInfo mi; + mi.name="add_do_method"; + mi.arguments.push_back( PropertyInfo( Variant::OBJECT, "object")); + mi.arguments.push_back( PropertyInfo( Variant::STRING, "method")); + Vector<Variant> defargs; + for(int i=0;i<VARIANT_ARG_MAX;++i) { + mi.arguments.push_back( PropertyInfo( Variant::NIL, "arg"+itos(i))); + defargs.push_back(Variant()); + } + + ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"add_do_method",&UndoRedo::_add_do_method,mi,defargs); + } + + { + MethodInfo mi; + mi.name="add_undo_method"; + mi.arguments.push_back( PropertyInfo( Variant::OBJECT, "object")); + mi.arguments.push_back( PropertyInfo( Variant::STRING, "method")); + Vector<Variant> defargs; + for(int i=0;i<VARIANT_ARG_MAX;++i) { + mi.arguments.push_back( PropertyInfo( Variant::NIL, "arg"+itos(i))); + defargs.push_back(Variant()); + } + + ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"add_undo_method",&UndoRedo::_add_undo_method,mi,defargs); + } + + ObjectTypeDB::bind_method(_MD("add_do_property","object", "property", "value:var"),&UndoRedo::add_do_property); + ObjectTypeDB::bind_method(_MD("add_undo_property","object", "property", "value:var"),&UndoRedo::add_undo_property); + ObjectTypeDB::bind_method(_MD("add_do_reference","object"),&UndoRedo::add_do_reference); + ObjectTypeDB::bind_method(_MD("add_undo_reference","object"),&UndoRedo::add_undo_reference); + ObjectTypeDB::bind_method(_MD("clear_history"),&UndoRedo::clear_history); + ObjectTypeDB::bind_method(_MD("get_current_action_name"),&UndoRedo::get_current_action_name); + ObjectTypeDB::bind_method(_MD("get_version"),&UndoRedo::get_version); +} diff --git a/core/undo_redo.h b/core/undo_redo.h index ff729e1767..a9187534c1 100644 --- a/core/undo_redo.h +++ b/core/undo_redo.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -38,9 +38,12 @@ class UndoRedo : public Object { OBJ_TYPE(UndoRedo,Object); + OBJ_SAVE_TYPE( UndoRedo ); public: typedef void (*CommitNotifyCallback)(void *p_ud,const String& p_name); + Variant _add_do_method(const Variant** p_args, int p_argcount, Variant::CallError& r_error); + Variant _add_undo_method(const Variant** p_args, int p_argcount, Variant::CallError& r_error); private: struct Operation { @@ -81,6 +84,10 @@ private: CommitNotifyCallback callback; void* callback_ud; + +protected: + static void _bind_methods(); + public: void create_action(const String& p_name="",bool p_mergeable=false); diff --git a/core/ustring.cpp b/core/ustring.cpp index 09d3d95b68..3cfc1e4a3c 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -67,11 +67,14 @@ void String::copy_from(const char *p_cstr) { return; } + resize(len+1); // include 0 - for(int i=0;i<len+1;i++) { - - set(i,p_cstr[i]); + CharType *dst = this->ptr(); + + for (int i=0;i<len+1;i++) { + + dst[i]=p_cstr[i]; } } @@ -486,7 +489,7 @@ String String::capitalize() const { String cap; for (int i=0;i<aux.get_slice_count(" ");i++) { - String slice=aux.get_slice(" ",i); + String slice=aux.get_slicec(' ',i); if (slice.length()>0) { slice[0]=_find_upper(slice[0]); @@ -498,6 +501,27 @@ String String::capitalize() const { return cap; } + +String String::camelcase_to_underscore() const { + const CharType * cstr = c_str(); + String newString; + const char A = 'A', Z = 'Z'; + int startIndex = 0; + + for ( int i = 1; i < this->size()-1; i++ ) { + bool isCapital = cstr[i] >= A && cstr[i] <= Z; + + if ( isCapital ) { + newString += "_" + this->substr(startIndex, i-startIndex); + startIndex = i; + } + } + + newString += "_" + this->substr(startIndex, this->size()-startIndex); + + return newString; +} + int String::get_slice_count(String p_splitter) const{ if (empty()) @@ -556,6 +580,41 @@ String String::get_slice(String p_splitter, int p_slice) const { } +String String::get_slicec(CharType p_splitter, int p_slice) const { + + if (empty()) + return String(); + + if (p_slice<0) + return String(); + + const CharType *c=this->ptr(); + int i=0; + int prev=0; + int count=0; + while(true) { + + + if (c[i]==0 || c[i]==p_splitter) { + + if (p_slice==count) { + + return substr(prev,i-prev); + } else { + count++; + prev=i+1; + } + + } + + i++; + + } + + return String(); //no find! + +} + Vector<String> String::split_spaces() const { @@ -3276,8 +3335,11 @@ String String::path_to_file(const String& p_path) const { String src=this->replace("\\","/").get_base_dir(); String dst=p_path.replace("\\","/").get_base_dir(); - - return src.path_to(dst)+p_path.get_file(); + String rel = src.path_to(dst); + if (rel==dst) // failed + return p_path; + else + return rel+p_path.get_file(); } String String::path_to(const String& p_path) const { @@ -3309,10 +3371,12 @@ String String::path_to(const String& p_path) const { //nothing } else { //dos style - String src_begin=src.get_slice("/",0); - String dst_begin=dst.get_slice("/",0); + String src_begin=src.get_slicec('/',0); + String dst_begin=dst.get_slicec('/',0); + + if (src_begin!=dst_begin) + return p_path; //impossible to do this - ERR_FAIL_COND_V(src_begin!=dst_begin,p_path); //return dst absolute path base=src_begin; src=src.substr(src_begin.length(),src.length()); dst=dst.substr(dst_begin.length(),dst.length()); diff --git a/core/ustring.h b/core/ustring.h index d4b854ea76..1000c1cc8a 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -149,9 +149,11 @@ public: static double to_double(const CharType* p_str, const CharType **r_end=NULL); static int64_t to_int(const CharType* p_str,int p_len=-1); String capitalize() const; + String camelcase_to_underscore() const; 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; Vector<String> split(const String &p_splitter,bool p_allow_empty=true) const; Vector<String> split_spaces() const; diff --git a/core/variant.cpp b/core/variant.cpp index 667a7d8648..e0bceb4dd8 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -32,7 +32,7 @@ #include "scene/main/node.h" #include "scene/gui/control.h" #include "io/marshalls.h" - +#include "core_string_names.h" @@ -258,12 +258,12 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) { case MATRIX32: { - static const Type invalid[]={ + static const Type valid[]={ TRANSFORM, NIL }; - invalid_types=invalid; + valid_types=valid; } break; case QUAT: { @@ -445,6 +445,256 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) { } +bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_to) { + + if (p_type_from==p_type_to) + return true; + if (p_type_to==NIL && p_type_from!=NIL) //nil can convert to anything + return true; + + if (p_type_from == NIL) { + return (p_type_to == OBJECT); + }; + + const Type *valid_types=NULL; + const Type *invalid_types=NULL; + + switch(p_type_to) { + case BOOL: { + + static const Type valid[]={ + INT, + REAL, + //STRING, + NIL, + }; + + valid_types=valid; + } break; + case INT: { + + static const Type valid[]={ + BOOL, + REAL, + //STRING, + NIL, + }; + + valid_types=valid; + + } break; + case REAL: { + + static const Type valid[]={ + BOOL, + INT, + //STRING, + NIL, + }; + + valid_types=valid; + + } break; + case STRING: { + + + static const Type valid[]={ + NODE_PATH, + NIL + }; + + valid_types=valid; + } break; + case MATRIX32: { + + + static const Type valid[]={ + TRANSFORM, + NIL + }; + + valid_types=valid; + } break; + case QUAT: { + + static const Type valid[]={ + MATRIX3, + NIL + }; + + valid_types=valid; + + } break; + case MATRIX3: { + + static const Type valid[]={ + QUAT, + NIL + }; + + valid_types=valid; + + + } break; + case TRANSFORM: { + + static const Type valid[]={ + MATRIX32, + QUAT, + MATRIX3, + NIL + }; + + valid_types=valid; + + } break; + + case COLOR: { + + static const Type valid[] = { + STRING, + INT, + NIL, + }; + + valid_types = valid; + + } break; + + case _RID: { + + static const Type valid[]={ + OBJECT, + NIL + }; + + valid_types=valid; + } break; + case OBJECT: { + + static const Type valid[]={ + NIL + }; + + valid_types=valid; + } break; + case NODE_PATH: { + + static const Type valid[]={ + STRING, + NIL + }; + + valid_types=valid; + } break; + case ARRAY: { + + + static const Type valid[]={ + RAW_ARRAY, + INT_ARRAY, + STRING_ARRAY, + REAL_ARRAY, + COLOR_ARRAY, + VECTOR2_ARRAY, + VECTOR3_ARRAY, + NIL + }; + + valid_types=valid; + } break; + // arrays + case RAW_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + + valid_types=valid; + } break; + case INT_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + valid_types=valid; + } break; + case REAL_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + + valid_types=valid; + } break; + case STRING_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + valid_types=valid; + } break; + case VECTOR2_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + valid_types=valid; + + } break; + case VECTOR3_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + valid_types=valid; + + } break; + case COLOR_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + + valid_types=valid; + + } break; + default: {} + } + + + if (valid_types) { + + int i=0; + while(valid_types[i]!=NIL) { + + if (p_type_from==valid_types[i]) + return true; + i++; + } + } else if (invalid_types) { + + + int i=0; + while(invalid_types[i]!=NIL) { + + if (p_type_from==invalid_types[i]) + return false; + i++; + } + } + + return false; + +} + bool Variant::operator==(const Variant& p_variant) const { if (type!=p_variant.type) //evaluation of operator== needs to be more strict @@ -456,6 +706,15 @@ bool Variant::operator==(const Variant& p_variant) const { } +bool Variant::operator<(const Variant& p_variant) const { + if (type!=p_variant.type) //if types differ, then order by type first + return type<p_variant.type; + bool v; + Variant r; + evaluate(OP_LESS,*this,p_variant,r,v); + return r; +} + bool Variant::is_zero() const { switch( type ) { @@ -523,7 +782,7 @@ bool Variant::is_zero() const { } break; case QUAT: { - *reinterpret_cast<const Quat*>(_data._mem)==Quat(); + return *reinterpret_cast<const Quat*>(_data._mem)==Quat(); } break; case MATRIX3: { @@ -619,6 +878,63 @@ bool Variant::is_zero() const { return false; } + +bool Variant::is_one() const { + + switch( type ) { + case NIL: { + + return true; + } break; + + // atomic types + case BOOL: { + + return _data._bool==true; + } break; + case INT: { + + return _data._int==1; + + } break; + case REAL: { + + return _data._real==1; + + } break; + case VECTOR2: { + + return *reinterpret_cast<const Vector2*>(_data._mem)==Vector2(1,1); + + } break; + case RECT2: { + + return *reinterpret_cast<const Rect2*>(_data._mem)==Rect2(1,1,1,1); + + } break; + case VECTOR3: { + + return *reinterpret_cast<const Vector3*>(_data._mem)==Vector3(1,1,1); + + } break; + case PLANE: { + + return *reinterpret_cast<const Plane*>(_data._mem)==Plane(1,1,1,1); + + } break; + case COLOR: { + + return *reinterpret_cast<const Color*>(_data._mem)==Color(1,1,1,1); + + } break; + + default: { return !is_zero(); } + } + + return false; +} + + void Variant::reference(const Variant& p_variant) { @@ -1394,6 +1710,10 @@ Variant::operator Color() const { if (type==COLOR) return *reinterpret_cast<const Color*>(_data._mem); + else if (type==STRING) + return Color::html( operator String() ); + else if (type==INT) + return Color::hex( operator int() ); else return Color(); } @@ -1430,8 +1750,16 @@ Variant::operator RID() const { return *reinterpret_cast<const RID*>(_data._mem); else if (type==OBJECT && !_get_obj().ref.is_null()) { return _get_obj().ref.get_rid(); - } else + } else if (type==OBJECT && _get_obj().obj) { + Variant::CallError ce; + Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->get_rid,NULL,0,ce); + if (ce.error==Variant::CallError::CALL_OK && ret.get_type()==Variant::_RID) { + return ret; + } return RID(); + } else { + return RID(); + } } Variant::operator Object*() const { diff --git a/core/variant.h b/core/variant.h index d5d4792422..8fd9662c36 100644 --- a/core/variant.h +++ b/core/variant.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -165,7 +165,8 @@ public: _FORCE_INLINE_ Type get_type() const { return type; } static String get_type_name(Variant::Type p_type); - static bool can_convert(Type p_type_from,Type p_type_to); + 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); @@ -184,6 +185,7 @@ public: _FORCE_INLINE_ bool is_array() const { return type>=ARRAY; }; bool is_shared() const; bool is_zero() const; + bool is_one() const; operator bool() const; operator signed int() const; @@ -408,7 +410,8 @@ public: //argsVariant call() - bool operator==(const Variant& p_variant) const; + bool operator==(const Variant& p_variant) const; + bool operator<(const Variant& p_variant) const; uint32_t hash() const; bool booleanize(bool &valid) const; diff --git a/core/variant_call.cpp b/core/variant_call.cpp index c6b498ff28..4cca3420a1 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -285,6 +285,36 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM1R(String,pad_decimals); VCALL_LOCALMEM1R(String,pad_zeros); + static void _call_String_to_ascii(Variant& r_ret,Variant& p_self,const Variant** p_args) { + + String *s = reinterpret_cast<String*>(p_self._data._mem); + CharString charstr = s->ascii(); + + ByteArray retval; + size_t len = charstr.length(); + retval.resize(len); + ByteArray::Write w = retval.write(); + copymem(w.ptr(), charstr.ptr(), len); + w = DVector<uint8_t>::Write(); + + r_ret = retval; + } + + static void _call_String_to_utf8(Variant& r_ret,Variant& p_self,const Variant** p_args) { + + String *s = reinterpret_cast<String*>(p_self._data._mem); + CharString charstr = s->utf8(); + + ByteArray retval; + size_t len = charstr.length(); + retval.resize(len); + ByteArray::Write w = retval.write(); + copymem(w.ptr(), charstr.ptr(), len); + w = DVector<uint8_t>::Write(); + + r_ret = retval; + } + VCALL_LOCALMEM0R(Vector2,normalized); VCALL_LOCALMEM0R(Vector2,length); @@ -426,6 +456,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM0(Array,sort); VCALL_LOCALMEM2(Array,sort_custom); VCALL_LOCALMEM0(Array,invert); + VCALL_LOCALMEM0R(Array,is_shared); static void _call_ByteArray_get_string_from_ascii(Variant& r_ret,Variant& p_self,const Variant** p_args) { @@ -684,6 +715,8 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_PTR0R( InputEvent, is_pressed ); VCALL_PTR1R( InputEvent, is_action ); + VCALL_PTR1R( InputEvent, is_action_pressed ); + VCALL_PTR1R( InputEvent, is_action_released ); VCALL_PTR0R( InputEvent, is_echo ); VCALL_PTR2( InputEvent, set_as_action ); @@ -719,6 +752,12 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var r_ret=Rect2(*p_args[0],*p_args[1],*p_args[2],*p_args[3]); } + static void Matrix32_init2(Variant& r_ret,const Variant** p_args) { + + Matrix32 m(*p_args[0], *p_args[1]); + r_ret=m; + } + static void Matrix32_init3(Variant& r_ret,const Variant** p_args) { Matrix32 m; @@ -1031,7 +1070,7 @@ Variant Variant::construct(const Variant::Type p_type,const Variant** p_args,int case STRING_ARRAY: return (StringArray(*p_args[0])); case VECTOR2_ARRAY: return (Vector2Array(*p_args[0])); // 25 case VECTOR3_ARRAY: return (Vector3Array(*p_args[0])); // 25 - case COLOR_ARRAY: return (Color(*p_args[0])); + case COLOR_ARRAY: return (ColorArray(*p_args[0])); default: return Variant(); } } @@ -1111,6 +1150,7 @@ void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_lis const _VariantCall::ConstructData &cd = E->get(); MethodInfo mi; mi.name=Variant::get_type_name(p_type); + mi.return_val.type=p_type; for(int i=0;i<cd.arg_count;i++) { PropertyInfo pi; @@ -1133,6 +1173,7 @@ void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_lis pi.name="from"; pi.type=Variant::Type(i); mi.arguments.push_back(pi); + mi.return_val.type=p_type; p_list->push_back(mi); } } @@ -1212,9 +1253,10 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(STRING,STRING,String,capitalize,varray()); ADDFUNC2(STRING,STRING_ARRAY,String,split,STRING,"divisor",BOOL,"allow_empty",varray(true)); ADDFUNC2(STRING,REAL_ARRAY,String,split_floats,STRING,"divisor",BOOL,"allow_empty",varray(true)); - ADDFUNC0(STRING,STRING,String,to_upper,varray()); + ADDFUNC0(STRING,STRING,String,to_upper,varray()); ADDFUNC0(STRING,STRING,String,to_lower,varray()); + ADDFUNC1(STRING,STRING,String,left,INT,"pos",varray()); ADDFUNC1(STRING,STRING,String,right,INT,"pos",varray()); ADDFUNC0(STRING,STRING,String,strip_edges,varray()); @@ -1246,6 +1288,10 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC1(STRING,STRING,String,pad_decimals,INT,"digits",varray()); ADDFUNC1(STRING,STRING,String,pad_zeros,INT,"digits",varray()); + ADDFUNC0(STRING,STRING,String,to_ascii,varray()); + ADDFUNC0(STRING,STRING,String,to_utf8,varray()); + + ADDFUNC0(VECTOR2,VECTOR2,Vector2,normalized,varray()); ADDFUNC0(VECTOR2,REAL,Vector2,length,varray()); ADDFUNC0(VECTOR2,REAL,Vector2,atan2,varray()); @@ -1378,6 +1424,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(ARRAY,NIL,Array,sort,varray()); ADDFUNC2(ARRAY,NIL,Array,sort_custom,OBJECT,"obj",STRING,"func",varray()); ADDFUNC0(ARRAY,NIL,Array,invert,varray()); + ADDFUNC0(ARRAY,BOOL,Array,is_shared,varray()); ADDFUNC0(RAW_ARRAY,INT,ByteArray,size,varray()); ADDFUNC2(RAW_ARRAY,NIL,ByteArray,set,INT,"idx",INT,"byte",varray()); @@ -1495,6 +1542,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(INPUT_EVENT,BOOL,InputEvent,is_pressed,varray()); ADDFUNC1(INPUT_EVENT,BOOL,InputEvent,is_action,STRING,"action",varray()); + ADDFUNC1(INPUT_EVENT,BOOL,InputEvent,is_action_pressed,STRING,"is_action_pressed",varray()); + ADDFUNC1(INPUT_EVENT,BOOL,InputEvent,is_action_released,STRING,"is_action_released",varray()); ADDFUNC0(INPUT_EVENT,BOOL,InputEvent,is_echo,varray()); ADDFUNC2(INPUT_EVENT,NIL,InputEvent,set_as_action,STRING,"action",BOOL,"pressed",varray()); @@ -1505,6 +1554,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl _VariantCall::add_constructor(_VariantCall::Rect2_init1,Variant::RECT2,"pos",Variant::VECTOR2,"size",Variant::VECTOR2); _VariantCall::add_constructor(_VariantCall::Rect2_init2,Variant::RECT2,"x",Variant::REAL,"y",Variant::REAL,"width",Variant::REAL,"height",Variant::REAL); + _VariantCall::add_constructor(_VariantCall::Matrix32_init2,Variant::MATRIX32,"rot",Variant::REAL,"pos",Variant::VECTOR2); _VariantCall::add_constructor(_VariantCall::Matrix32_init3,Variant::MATRIX32,"x_axis",Variant::VECTOR2,"y_axis",Variant::VECTOR2,"origin",Variant::VECTOR2); _VariantCall::add_constructor(_VariantCall::Vector3_init1,Variant::VECTOR3,"x",Variant::REAL,"y",Variant::REAL,"z",Variant::REAL); diff --git a/core/variant_call_bind.h b/core/variant_call_bind.h index 39fe25e8c7..613669203d 100644 --- a/core/variant_call_bind.h +++ b/core/variant_call_bind.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 87d9738b06..1cdf6d7319 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -165,6 +165,12 @@ r_valid=false;\ return;} #define DEFAULT_OP_ARRAY_EQ(m_name,m_type)\ +DEFAULT_OP_ARRAY_OP(m_name,m_type,!=,!=,true,false,false) + +#define DEFAULT_OP_ARRAY_LT(m_name,m_type)\ +DEFAULT_OP_ARRAY_OP(m_name,m_type,<,!=,false,a_len<array_b.size(),true) + +#define DEFAULT_OP_ARRAY_OP(m_name,m_type,m_opa,m_opb,m_ret_def,m_ret_s,m_ret_f)\ case m_name: { \ if (p_a.type!=p_b.type) {\ r_valid=false;\ @@ -174,19 +180,19 @@ case m_name: { \ const DVector<m_type> &array_b=*reinterpret_cast<const DVector<m_type> *>(p_b._data._mem);\ \ int a_len = array_a.size();\ - if (a_len!=array_b.size()){\ - _RETURN( false);\ + if (a_len m_opa array_b.size()){\ + _RETURN( m_ret_s);\ }else {\ \ DVector<m_type>::Read ra = array_a.read();\ DVector<m_type>::Read rb = array_b.read();\ \ for(int i=0;i<a_len;i++) {\ - if (ra[i]!=rb[i])\ - _RETURN( false);\ + if (ra[i] m_opb rb[i])\ + _RETURN( m_ret_f);\ }\ \ - _RETURN( true);\ + _RETURN( m_ret_def);\ }\ } @@ -290,8 +296,9 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant& if (arr_b->size()!=l) _RETURN( false ); for(int i=0;i<l;i++) { - if (!(arr_a[i]==arr_b[i])) + if (!((*arr_a)[i]==(*arr_b)[i])) { _RETURN( false ); + } } _RETURN( true ); @@ -356,14 +363,33 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant& } break; DEFAULT_OP_FAIL(INPUT_EVENT); DEFAULT_OP_FAIL(DICTIONARY); - DEFAULT_OP_FAIL(ARRAY); - DEFAULT_OP_FAIL(RAW_ARRAY); - DEFAULT_OP_FAIL(INT_ARRAY); - DEFAULT_OP_FAIL(REAL_ARRAY); - DEFAULT_OP_FAIL(STRING_ARRAY); - DEFAULT_OP_FAIL(VECTOR2_ARRAY); - DEFAULT_OP_FAIL(VECTOR3_ARRAY); - DEFAULT_OP_FAIL(COLOR_ARRAY); + case ARRAY: { + + if (p_b.type!=ARRAY) + _RETURN( false ); + + const Array *arr_a=reinterpret_cast<const Array*>(p_a._data._mem); + const Array *arr_b=reinterpret_cast<const Array*>(p_b._data._mem); + + int l = arr_a->size(); + if (arr_b->size()<l) + _RETURN( false ); + for(int i=0;i<l;i++) { + if (!((*arr_a)[i]<(*arr_b)[i])) { + _RETURN( true ); + } + } + + _RETURN( false ); + + } break; + DEFAULT_OP_ARRAY_LT(RAW_ARRAY,uint8_t); + DEFAULT_OP_ARRAY_LT(INT_ARRAY,int); + DEFAULT_OP_ARRAY_LT(REAL_ARRAY,real_t); + DEFAULT_OP_ARRAY_LT(STRING_ARRAY,String); + DEFAULT_OP_ARRAY_LT(VECTOR2_ARRAY,Vector3); + DEFAULT_OP_ARRAY_LT(VECTOR3_ARRAY,Vector3); + DEFAULT_OP_ARRAY_LT(COLOR_ARRAY,Color); case VARIANT_MAX: { r_valid=false; return; @@ -471,7 +497,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant& } const Array &array_a=*reinterpret_cast<const Array *>(p_a._data._mem); const Array &array_b=*reinterpret_cast<const Array *>(p_b._data._mem); - Array sum; + Array sum(array_a.is_shared() || array_b.is_shared()); int asize=array_a.size(); int bsize=array_b.size(); sum.resize(asize+bsize); @@ -2407,7 +2433,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const { } else if (str == "pressed") { valid=true; - ie.action.pressed; + return ie.action.pressed; } } @@ -3362,7 +3388,15 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const { void Variant::interpolate(const Variant& a, const Variant& b, float c,Variant &r_dst) { if (a.type!=b.type) { - r_dst=a; + if (a.is_num() && b.is_num()) { + //not as efficient but.. + real_t va=a; + real_t vb=b; + r_dst=(1.0-c) * va + vb * c; + + } else { + r_dst=a; + } return; } diff --git a/core/vector.h b/core/vector.h index 90a9bf715b..d103400622 100644 --- a/core/vector.h +++ b/core/vector.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -104,7 +104,7 @@ public: template <class T_val> - int find(T_val& p_val) const; + int find(const T_val& p_val) const; void set(int p_index,T p_elem); T get(int p_index) const; @@ -149,7 +149,16 @@ public: sort_custom<_DefaultComparator<T> >(); } + void ordered_insert(const T& p_val) { + int i; + for (i=0; i<size(); i++) { + if (p_val < operator[](i)) { + break; + }; + }; + insert(i, p_val); + } void operator=(const Vector& p_from); Vector(const Vector& p_from); @@ -212,7 +221,7 @@ void Vector<T>::_copy_on_write() { } template<class T> template<class T_val> -int Vector<T>::find(T_val& p_val) const { +int Vector<T>::find(const T_val &p_val) const { int ret = -1; if (size() == 0) @@ -331,12 +340,14 @@ template<class T> void Vector<T>::remove(int p_index) { ERR_FAIL_INDEX(p_index, size()); - for (int i=p_index; i<size()-1; i++) { + T*p=ptr(); + int len=size(); + for (int i=p_index; i<len-1; i++) { - set(i, get(i+1)); + p[i]=p[i+1]; }; - resize(size()-1); + resize(len-1); }; template<class T> diff --git a/core/vmap.cpp b/core/vmap.cpp index 4903a878b1..32481eb9eb 100644 --- a/core/vmap.cpp +++ b/core/vmap.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/vmap.h b/core/vmap.h index 516299280b..5ff8f73978 100644 --- a/core/vmap.h +++ b/core/vmap.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/vset.cpp b/core/vset.cpp index ffdd158996..c849bf3367 100644 --- a/core/vset.cpp +++ b/core/vset.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/vset.h b/core/vset.h index 3764b015b0..e1e02ab435 100644 --- a/core/vset.h +++ b/core/vset.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ |