diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bind/core_bind.cpp | 22 | ||||
-rw-r--r-- | core/bind/core_bind.h | 5 | ||||
-rw-r--r-- | core/color.cpp | 2 | ||||
-rw-r--r-- | core/command_queue_mt.h | 4 | ||||
-rw-r--r-- | core/globals.cpp | 10 | ||||
-rw-r--r-- | core/image.cpp | 87 | ||||
-rw-r--r-- | core/image.h | 6 | ||||
-rw-r--r-- | core/io/file_access_memory.cpp | 8 | ||||
-rw-r--r-- | core/io/file_access_memory.h | 1 | ||||
-rw-r--r-- | core/io/file_access_zip.cpp | 21 | ||||
-rw-r--r-- | core/io/packet_peer.cpp | 21 | ||||
-rw-r--r-- | core/io/packet_peer.h | 8 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 1 | ||||
-rw-r--r-- | core/math/math_2d.h | 23 | ||||
-rw-r--r-- | core/message_queue.cpp | 19 | ||||
-rw-r--r-- | core/object.cpp | 35 | ||||
-rw-r--r-- | core/object.h | 2 | ||||
-rw-r--r-- | core/os/main_loop.cpp | 27 | ||||
-rw-r--r-- | core/os/memory.cpp | 7 | ||||
-rw-r--r-- | core/os/memory.h | 17 | ||||
-rw-r--r-- | core/os/os.h | 12 | ||||
-rw-r--r-- | core/reference.h | 3 | ||||
-rw-r--r-- | core/variant.cpp | 8 | ||||
-rw-r--r-- | core/variant_call.cpp | 37 | ||||
-rw-r--r-- | core/vector.h | 4 |
25 files changed, 337 insertions, 53 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 128bc94989..26b1dac6f1 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -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(); @@ -774,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); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 05f54dd64c..74f29c23e8 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -204,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; diff --git a/core/color.cpp b/core/color.cpp index ba4751dc2f..32f3df6d4b 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -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/command_queue_mt.h b/core/command_queue_mt.h index 0985f3cfe7..113199869b 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -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/globals.cpp b/core/globals.cpp index 23d8c16ace..8a7d66b68a 100644 --- a/core/globals.cpp +++ b/core/globals.cpp @@ -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"); @@ -1397,6 +1397,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 +1467,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/image.cpp b/core/image.cpp index 04b3905489..037018519e 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -1124,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;\ @@ -1136,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 || @@ -1746,6 +1823,10 @@ Error Image::_decompress_bc() { return OK; } +bool Image::is_compressed() const { + return format>=FORMAT_BC1; +} + Image Image::decompressed() const { @@ -1998,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; @@ -2167,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; @@ -2175,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 ddb5e88ebf..8ce4f22dc1 100644 --- a/core/image.h +++ b/core/image.h @@ -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 *); @@ -305,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; @@ -335,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(); @@ -349,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/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index 2880c4ebda..83da55fc61 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -74,6 +74,14 @@ bool FileAccessMemory::file_exists(const String& p_name) { } +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) { ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND); diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h index 5a9ec2b3c6..8c58a8a8ce 100644 --- a/core/io/file_access_memory.h +++ b/core/io/file_access_memory.h @@ -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_zip.cpp b/core/io/file_access_zip.cpp index 7a1b6454bd..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/packet_peer.cpp b/core/io/packet_peer.cpp index 7b5ea65a4b..875cace368 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -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 3448ebde1b..76d1eb22b5 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -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_loader.cpp b/core/io/resource_loader.cpp index 03b6c9759b..22d89840ae 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -214,6 +214,7 @@ 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; if (p_path.is_rel_path()) local_path="res://"+p_path; diff --git a/core/math/math_2d.h b/core/math/math_2d.h index ac315fddb7..5e6cefd114 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -226,6 +226,29 @@ struct Rect2 { 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/message_queue.cpp b/core/message_queue.cpp index cfbdb37b88..489939ee65 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -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/object.cpp b/core/object.cpp index 1a51e79a9f..83a6dada80 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -995,12 +995,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; @@ -1319,7 +1351,7 @@ Error Object::connect(const StringName& p_signal, Object *p_to_object, const Str if (!s) { bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal); if (!signal_is_valid) { - ERR_EXPLAIN("Attempt to connect to nonexistent 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(); @@ -1439,6 +1471,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); diff --git a/core/object.h b/core/object.h index fc64b91412..8d1f8ebc5a 100644 --- a/core/object.h +++ b/core/object.h @@ -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, @@ -448,6 +449,7 @@ protected: DVector<String> _get_meta_list_bind() const; Array _get_property_list_bind() const; + Array _get_method_list_bind() const; public: //should be protected, but bug in clang++ static void initialize_type(); diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 83d3155b03..b4c02ddbce 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -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/memory.cpp b/core/os/memory.cpp index 617e40e92a..1d9ac4e302 100644 --- a/core/os/memory.cpp +++ b/core/os/memory.cpp @@ -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 4497fcc200..0a35c93fdb 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -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/os.h b/core/os/os.h index 2f9957c2f8..0230a75ca0 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -244,9 +244,15 @@ 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; diff --git a/core/reference.h b/core/reference.h index 544da41044..65f31f78f3 100644 --- a/core/reference.h +++ b/core/reference.h @@ -294,6 +294,9 @@ public: reference=NULL; } + void instance() { + ref( memnew( T )); + } Ref() { diff --git a/core/variant.cpp b/core/variant.cpp index d7817ac268..034dc2b4fc 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -302,8 +302,8 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) { case COLOR: { static const Type valid[] = { - //STRING, - //INT, + STRING, + INT, NIL, }; @@ -1653,6 +1653,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(); } diff --git a/core/variant_call.cpp b/core/variant_call.cpp index c48336d2ff..2f7e0205dc 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -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); @@ -1215,9 +1245,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()); @@ -1249,6 +1280,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()); diff --git a/core/vector.h b/core/vector.h index 04018b9f78..b93d9a0dea 100644 --- a/core/vector.h +++ b/core/vector.h @@ -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; @@ -221,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) |