diff options
54 files changed, 542 insertions, 4074 deletions
diff --git a/core/dictionary.cpp b/core/dictionary.cpp index 94bb0b6e8c..d5d29ca0fc 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -29,7 +29,6 @@ #include "dictionary.h" #include "safe_refcount.h" #include "variant.h" -#include "io/json.h" struct _DictionaryVariantHash { @@ -277,22 +276,6 @@ const Variant* Dictionary::next(const Variant* p_key) const { return _p->variant_map.next(p_key); } - -Error Dictionary::parse_json(const String& p_json) { - - String errstr; - int errline=0; - if (p_json != ""){ - Error err = JSON::parse(p_json,*this,errstr,errline); - if (err!=OK) { - ERR_EXPLAIN("Error parsing JSON: "+errstr+" at line: "+itos(errline)); - ERR_FAIL_COND_V(err!=OK,err); - } - } - - return OK; -} - Dictionary Dictionary::copy() const { Dictionary n(is_shared()); @@ -307,11 +290,6 @@ Dictionary Dictionary::copy() const { return n; } -String Dictionary::to_json() const { - - return JSON::print(*this); -} - void Dictionary::operator=(const Dictionary& p_dictionary) { diff --git a/core/dictionary.h b/core/dictionary.h index d074db8588..9fab653470 100644 --- a/core/dictionary.h +++ b/core/dictionary.h @@ -63,9 +63,6 @@ public: void clear(); - Error parse_json(const String& p_json); - String to_json() const; - bool is_shared() const; bool has(const Variant& p_key) const; diff --git a/core/io/json.cpp b/core/io/json.cpp index f42155bc94..3280f94750 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -92,9 +92,9 @@ String JSON::_print_var(const Variant& p_var) { } -String JSON::print(const Dictionary& p_dict) { +String JSON::print(const Variant& p_var) { - return _print_var(p_dict); + return _print_var(p_var); } @@ -450,27 +450,24 @@ Error JSON::_parse_object(Dictionary &object,const CharType *p_str,int &index, i } -Error JSON::parse(const String& p_json,Dictionary& r_ret,String &r_err_str,int &r_err_line) { +Error JSON::parse(const String& p_json, Variant &r_ret, String &r_err_str, int &r_err_line) { const CharType *str = p_json.ptr(); int idx = 0; int len = p_json.length(); Token token; - int line=0; + r_err_line=0; String aux_key; - Error err = _get_token(str,idx,len,token,line,r_err_str); + Error err = _get_token(str,idx,len,token,r_err_line,r_err_str); if (err) return err; - if (token.type!=TK_CURLY_BRACKET_OPEN) { + err = _parse_value(r_ret,token,str,idx,len,r_err_line,r_err_str); - r_err_str="Expected '{'"; - return ERR_PARSE_ERROR; - } - - return _parse_object(r_ret,str,idx,len,r_err_line,r_err_str); + return err; + } diff --git a/core/io/json.h b/core/io/json.h index 52fcac145d..97457d223e 100644 --- a/core/io/json.h +++ b/core/io/json.h @@ -74,8 +74,8 @@ class JSON { static Error _parse_object(Dictionary &object,const CharType *p_str,int &index, int p_len,int &line,String &r_err_str); public: - static String print(const Dictionary& p_dict); - static Error parse(const String& p_json,Dictionary& r_ret,String &r_err_str,int &r_err_line); + static String print(const Variant &p_var); + static Error parse(const String& p_json,Variant& r_ret,String &r_err_str,int &r_err_line); }; #endif // JSON_H diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index b65ca9a696..0765fc86c7 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -31,6 +31,10 @@ #include "os/keyboard.h" #include <stdio.h> + +#define ENCODE_MASK 0xFF +#define ENCODE_FLAG_64 1<<16 + Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *r_len) { const uint8_t * buf=p_buffer; @@ -44,14 +48,14 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * uint32_t type=decode_uint32(buf); - ERR_FAIL_COND_V(type>=Variant::VARIANT_MAX,ERR_INVALID_DATA); + ERR_FAIL_COND_V((type&ENCODE_MASK)>=Variant::VARIANT_MAX,ERR_INVALID_DATA); buf+=4; len-=4; if (r_len) *r_len=4; - switch(type) { + switch(type&ENCODE_MASK) { case Variant::NIL: { @@ -68,19 +72,35 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * case Variant::INT: { ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA); - int val = decode_uint32(buf); - r_variant=val; - if (r_len) - (*r_len)+=4; + if (type&ENCODE_FLAG_64) { + int64_t val = decode_uint64(buf); + r_variant=val; + if (r_len) + (*r_len)+=8; + + } else { + int32_t val = decode_uint32(buf); + r_variant=val; + if (r_len) + (*r_len)+=4; + } } break; case Variant::REAL: { ERR_FAIL_COND_V(len<(int)4,ERR_INVALID_DATA); - float val = decode_float(buf); - r_variant=val; - if (r_len) - (*r_len)+=4; + + if (type&ENCODE_FLAG_64) { + double val = decode_double(buf); + r_variant=val; + if (r_len) + (*r_len)+=8; + } else { + float val = decode_float(buf); + r_variant=val; + if (r_len) + (*r_len)+=4; + } } break; case Variant::STRING: { @@ -796,8 +816,28 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) { r_len=0; + uint32_t flags=0; + + switch(p_variant.get_type()) { + + case Variant::INT: { + int64_t val = p_variant; + if (val>0x7FFFFFFF || val < -0x80000000) { + flags|=ENCODE_FLAG_64; + } + } break; + case Variant::REAL: { + + double d = p_variant; + float f = d; + if (double(f)!=d) { + flags|=ENCODE_FLAG_64; //always encode real as double + } + } break; + } + if (buf) { - encode_uint32(p_variant.get_type(),buf); + encode_uint32(p_variant.get_type()|flags,buf); buf+=4; } r_len+=4; @@ -819,20 +859,42 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) { } break; case Variant::INT: { - if (buf) { - encode_uint32(p_variant.operator int(),buf); - } + int64_t val = p_variant; + if (val>0x7FFFFFFF || val < -0x80000000) { + //64 bits + if (buf) { + encode_uint64(val,buf); + } - r_len+=4; + r_len+=8; + } else { + if (buf) { + encode_uint32(int32_t(val),buf); + } + r_len+=4; + } } break; case Variant::REAL: { - if (buf) { - encode_float(p_variant.operator float(),buf); + double d = p_variant; + float f = d; + if (double(f)!=d) { + if (buf) { + encode_double(p_variant.operator double(),buf); + } + + r_len+=8; + + } else { + + if (buf) { + encode_double(p_variant.operator float(),buf); + } + + r_len+=4; } - r_len+=4; } break; case Variant::NODE_PATH: { diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 2a9089e8e8..16da74fdf1 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -68,6 +68,8 @@ enum { VARIANT_VECTOR3_ARRAY=35, VARIANT_COLOR_ARRAY=36, VARIANT_VECTOR2_ARRAY=37, + VARIANT_INT64=40, + VARIANT_DOUBLE=41, IMAGE_ENCODING_EMPTY=0, IMAGE_ENCODING_RAW=1, @@ -116,10 +118,18 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) { r_v=int(f->get_32()); } break; + case VARIANT_INT64: { + + r_v=int64_t(f->get_64()); + } break; case VARIANT_REAL: { r_v=f->get_real(); } break; + case VARIANT_DOUBLE: { + + r_v=f->get_double(); + } break; case VARIANT_STRING: { r_v=get_unicode_string(); @@ -1416,15 +1426,33 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property, } break; case Variant::INT: { - f->store_32(VARIANT_INT); - int val=p_property; - f->store_32(val); + int64_t val = p_property; + if (val>0x7FFFFFFF || val < -0x80000000) { + f->store_32(VARIANT_INT64); + f->store_64(val); + + } else { + f->store_32(VARIANT_INT); + int val=p_property; + f->store_32(int32_t(val)); + + } + } break; case Variant::REAL: { - f->store_32(VARIANT_REAL); - real_t val=p_property; - f->store_real(val); + + double d = p_property; + float fl = d; + if (double(fl)!=d) { + f->store_32(VARIANT_DOUBLE); + f->store_double(d); + } else { + + f->store_32(VARIANT_REAL); + f->store_real(fl); + + } } break; case Variant::STRING: { diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp deleted file mode 100644 index 34e3f282c1..0000000000 --- a/core/io/resource_format_xml.cpp +++ /dev/null @@ -1,2882 +0,0 @@ -/*************************************************************************/ -/* resource_format_xml.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "resource_format_xml.h" -#include "globals.h" -#include "version.h" -#include "os/dir_access.h" - - -ResourceInteractiveLoaderXML::Tag* ResourceInteractiveLoaderXML::parse_tag(bool *r_exit, bool p_printerr, List<String> *r_order) { - - - while(get_char()!='<' && !f->eof_reached()) {} - if (f->eof_reached()) { - return NULL; - } - - Tag tag; - bool exit=false; - if (r_exit) - *r_exit=false; - - bool complete=false; - while(!f->eof_reached()) { - - CharType c=get_char(); - if (c<33 && tag.name.length() && !exit) { - break; - } else if (c=='>') { - complete=true; - break; - } else if (c=='/') { - exit=true; - } else { - tag.name+=c; - } - } - - if (f->eof_reached()) { - - return NULL; - } - - if (exit) { - if (!tag_stack.size()) { - if (!p_printerr) - return NULL; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Unmatched exit tag </"+tag.name+">"); - ERR_FAIL_COND_V(!tag_stack.size(),NULL); - } - - if (tag_stack.back()->get().name!=tag.name) { - if (!p_printerr) - return NULL; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Mismatched exit tag. Got </"+tag.name+">, expected </"+tag_stack.back()->get().name+">"); - ERR_FAIL_COND_V(tag_stack.back()->get().name!=tag.name,NULL); - } - - if (!complete) { - while(get_char()!='>' && !f->eof_reached()) {} - if (f->eof_reached()) - return NULL; - } - - if (r_exit) - *r_exit=true; - - tag_stack.pop_back(); - return NULL; - - } - - if (!complete) { - String name; - CharString r_value; - bool reading_value=false; - - while(!f->eof_reached()) { - - CharType c=get_char(); - if (c=='>') { - if (r_value.size()) { - - r_value.push_back(0); - String str; - str.parse_utf8(r_value.get_data()); - tag.args[name]=str; - if (r_order) - r_order->push_back(name); - } - break; - - } else if ( ((!reading_value && (c<33)) || c=='=' || c=='"' || c=='\'') && tag.name.length()) { - - if (!reading_value && name.length()) { - - reading_value=true; - } else if (reading_value && r_value.size()) { - - r_value.push_back(0); - String str; - str.parse_utf8(r_value.get_data()); - tag.args[name]=str; - if (r_order) - r_order->push_back(name); - name=""; - r_value.clear(); - reading_value=false; - } - - } else if (reading_value) { - - r_value.push_back(c); - } else { - - name+=c; - } - } - - if (f->eof_reached()) - return NULL; - } - - tag_stack.push_back(tag); - - return &tag_stack.back()->get(); -} - - -Error ResourceInteractiveLoaderXML::close_tag(const String& p_name) { - - int level=0; - bool inside_tag=false; - - while(true) { - - if (f->eof_reached()) { - - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": EOF found while attempting to find </"+p_name+">"); - ERR_FAIL_COND_V( f->eof_reached(), ERR_FILE_CORRUPT ); - } - - uint8_t c = get_char(); - - if (c == '<') { - - if (inside_tag) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Malformed XML. Already inside Tag."); - ERR_FAIL_COND_V(inside_tag,ERR_FILE_CORRUPT); - } - inside_tag=true; - c = get_char(); - if (c == '/') { - - --level; - } else { - - ++level; - }; - } else if (c == '>') { - - if (!inside_tag) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Malformed XML. Already outside Tag"); - ERR_FAIL_COND_V(!inside_tag,ERR_FILE_CORRUPT); - } - inside_tag=false; - if (level == -1) { - tag_stack.pop_back(); - return OK; - }; - }; - } - - return OK; -} - -void ResourceInteractiveLoaderXML::unquote(String& p_str) { - - - p_str=p_str.strip_edges().replace("\"","").xml_unescape(); - - /*p_str=p_str.strip_edges(); - p_str=p_str.replace("\"",""); - p_str=p_str.replace(">","<"); - p_str=p_str.replace("<",">"); - p_str=p_str.replace("'","'"); - p_str=p_str.replace(""","\""); - for (int i=1;i<32;i++) { - - char chr[2]={i,0}; - p_str=p_str.replace("&#"+String::num(i)+";",chr); - } - p_str=p_str.replace("&","&"); -*/ - //p_str.parse_utf8( p_str.ascii(true).get_data() ); - -} - -Error ResourceInteractiveLoaderXML::goto_end_of_tag() { - - uint8_t c; - while(true) { - - c=get_char(); - if (c=='>') //closetag - break; - if (f->eof_reached()) { - - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": EOF found while attempting to find close tag."); - ERR_FAIL_COND_V( f->eof_reached(), ERR_FILE_CORRUPT ); - } - - } - tag_stack.pop_back(); - - return OK; -} - - -Error ResourceInteractiveLoaderXML::parse_property_data(String &r_data) { - - r_data=""; - CharString cs; - while(true) { - - CharType c=get_char(); - if (c=='<') - break; - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - cs.push_back(c); - } - - cs.push_back(0); - - r_data.parse_utf8(cs.get_data()); - - while(get_char()!='>' && !f->eof_reached()) {} - if (f->eof_reached()) { - - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Malformed XML."); - ERR_FAIL_COND_V( f->eof_reached(), ERR_FILE_CORRUPT ); - } - - r_data=r_data.strip_edges(); - tag_stack.pop_back(); - - return OK; -} - - -Error ResourceInteractiveLoaderXML::_parse_array_element(Vector<char> &buff,bool p_number_only,FileAccess *f,bool *end) { - - if (buff.empty()) - buff.resize(32); // optimi - - int buff_max=buff.size(); - int buff_size=0; - *end=false; - char *buffptr=&buff[0]; - bool found=false; - bool quoted=false; - - while(true) { - - char c=get_char(); - - if (c==0) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": File corrupt (zero found)."); - ERR_FAIL_V(ERR_FILE_CORRUPT); - } else if (c=='"') { - quoted=!quoted; - } else if ((!quoted && ((p_number_only && c<33) || c==',')) || c=='<') { - - - if (c=='<') { - *end=true; - break; - } - if (c<32 && f->eof_reached()) { - *end=true; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": File corrupt (unexpected EOF)."); - ERR_FAIL_V(ERR_FILE_CORRUPT); - } - - if (found) - break; - - } else { - - found=true; - if (buff_size>=buff_max) { - - buff_max++; - buff.resize(buff_max); - buffptr=buff.ptr(); - - } - - buffptr[buff_size]=c; - buff_size++; - } - } - - if (buff_size>=buff_max) { - - buff_max++; - buff.resize(buff_max); - - } - - buff[buff_size]=0; - buff_size++; - - return OK; -} - -Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) { - - bool exit; - Tag *tag = parse_tag(&exit); - - if (!tag) { - if (exit) // shouldn't have exited - return ERR_FILE_EOF; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": File corrupt (No Property Tag)."); - ERR_FAIL_V(ERR_FILE_CORRUPT); - } - - r_v=Variant(); - r_name=""; - - - //ERR_FAIL_COND_V(tag->name!="property",ERR_FILE_CORRUPT); - //ERR_FAIL_COND_V(!tag->args.has("name"),ERR_FILE_CORRUPT); -// ERR_FAIL_COND_V(!tag->args.has("type"),ERR_FILE_CORRUPT); - - //String name=tag->args["name"]; - //ERR_FAIL_COND_V(name=="",ERR_FILE_CORRUPT); - String type=tag->name; - String name=tag->args["name"]; - - if (type=="") { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": 'type' field is empty."); - ERR_FAIL_COND_V(type=="",ERR_FILE_CORRUPT); - } - - if (type=="dictionary") { - - Dictionary d( tag->args.has("shared") && (String(tag->args["shared"])=="true" || String(tag->args["shared"])=="1")); - - while(true) { - - Error err; - String tagname; - Variant key; - - int dictline = get_current_line(); - - - err=parse_property(key,tagname); - - if (err && err!=ERR_FILE_EOF) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error parsing dictionary: "+name+" (from line "+itos(dictline)+")"); - ERR_FAIL_COND_V(err && err!=ERR_FILE_EOF,err); - } - //ERR_FAIL_COND_V(tagname!="key",ERR_FILE_CORRUPT); - if (err) - break; - Variant value; - err=parse_property(value,tagname); - if (err) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error parsing dictionary: "+name+" (from line "+itos(dictline)+")"); - } - - ERR_FAIL_COND_V(err,err); - //ERR_FAIL_COND_V(tagname!="value",ERR_FILE_CORRUPT); - - d[key]=value; - } - - - //err=parse_property_data(name); // skip the rest - //ERR_FAIL_COND_V(err,err); - - r_name=name; - r_v=d; - return OK; - - } else if (type=="array") { - - if (!tag->args.has("len")) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name); - ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT); - } - - - int len=tag->args["len"].to_int(); - bool shared = tag->args.has("shared") && (String(tag->args["shared"])=="true" || String(tag->args["shared"])=="1"); - - Array array(shared); - array.resize(len); - - Error err; - Variant v; - String tagname; - int idx=0; - while( (err=parse_property(v,tagname))==OK ) { - - ERR_CONTINUE( idx <0 || idx >=len ); - - array.set(idx,v); - idx++; - } - - if (idx!=len) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array (size mismatch): "+name); - ERR_FAIL_COND_V(idx!=len,err); - } - - if (err!=ERR_FILE_EOF) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array: "+name); - ERR_FAIL_COND_V(err!=ERR_FILE_EOF,err); - } - - //err=parse_property_data(name); // skip the rest - //ERR_FAIL_COND_V(err,err); - - r_name=name; - r_v=array; - return OK; - - } else if (type=="resource") { - - if (tag->args.has("path")) { - - String path=tag->args["path"]; - String hint; - if (tag->args.has("resource_type")) - hint=tag->args["resource_type"]; - - if (path.begins_with("local://")) - 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=GlobalConfig::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path)); - - } - - if (remaps.has(path)) { - path=remaps[path]; - } - - //take advantage of the resource loader cache. The resource is cached on it, even if - RES res=ResourceLoader::load(path,hint); - - - if (res.is_null()) { - - WARN_PRINT(String("Couldn't load resource: "+path).ascii().get_data()); - } - - r_v=res.get_ref_ptr(); - } else if (tag->args.has("external")) { - - int index = tag->args["external"].to_int(); - if (ext_resources.has(index)) { - String path=ext_resources[index].path; - String type=ext_resources[index].type; - - //take advantage of the resource loader cache. The resource is cached on it, even if - RES res=ResourceLoader::load(path,type); - - if (res.is_null()) { - - WARN_PRINT(String("Couldn't load externalresource: "+path).ascii().get_data()); - } - - r_v=res.get_ref_ptr(); - } else { - WARN_PRINT(String("Invalid external resource index: "+itos(index)).ascii().get_data()); - - } - } - - - - - Error err=goto_end_of_tag(); - if (err) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error closing <resource> tag."); - ERR_FAIL_COND_V(err,err); - } - - - r_name=name; - - return OK; - - } else if (type=="image") { - - if (!tag->args.has("encoding")) { - //empty image - r_v=Image(); - String sdfsdfg; - Error err=parse_property_data(sdfsdfg); - return OK; - } - - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'encoding' field."); - ERR_FAIL_COND_V( !tag->args.has("encoding"), ERR_FILE_CORRUPT ); - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'width' field."); - ERR_FAIL_COND_V( !tag->args.has("width"), ERR_FILE_CORRUPT ); - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'height' field."); - ERR_FAIL_COND_V( !tag->args.has("height"), ERR_FILE_CORRUPT ); - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'format' field."); - ERR_FAIL_COND_V( !tag->args.has("format"), ERR_FILE_CORRUPT ); - - String encoding=tag->args["encoding"]; - - if (encoding=="raw") { - String width=tag->args["width"]; - String height=tag->args["height"]; - String format=tag->args["format"]; - int mipmaps=tag->args.has("mipmaps")?int(tag->args["mipmaps"].to_int()):int(0); - int custom_size = tag->args.has("custom_size")?int(tag->args["custom_size"].to_int()):int(0); - - r_name=name; - - Image::Format imgformat; - -/* - if (format=="grayscale") { - imgformat=Image::FORMAT_L8; - } else if (format=="intensity") { - imgformat=Image::FORMAT_INTENSITY; - } else if (format=="grayscale_alpha") { - imgformat=Image::FORMAT_LA8; - } else if (format=="rgb") { - imgformat=Image::FORMAT_RGB8; - } else if (format=="rgba") { - imgformat=Image::FORMAT_RGBA8; - } else if (format=="indexed") { - imgformat=Image::FORMAT_INDEXED; - } else if (format=="indexed_alpha") { - imgformat=Image::FORMAT_INDEXED_ALPHA; - } else if (format=="bc1") { - imgformat=Image::FORMAT_DXT1; - } else if (format=="bc2") { - imgformat=Image::FORMAT_DXT3; - } else if (format=="bc3") { - imgformat=Image::FORMAT_DXT5; - } else if (format=="bc4") { - imgformat=Image::FORMAT_ATI1; - } else if (format=="bc5") { - imgformat=Image::FORMAT_ATI2; - } else if (format=="pvrtc2") { - imgformat=Image::FORMAT_PVRTC2; - } else if (format=="pvrtc2a") { - imgformat=Image::FORMAT_PVRTC2A; - } else if (format=="pvrtc4") { - imgformat=Image::FORMAT_PVRTC4; - } else if (format=="pvrtc4a") { - imgformat=Image::FORMAT_PVRTC4A; - } else if (format=="etc") { - imgformat=Image::FORMAT_ETC; - } else if (format=="atc") { - imgformat=Image::FORMAT_ATC; - } else if (format=="atcai") { - imgformat=Image::FORMAT_ATC_ALPHA_INTERPOLATED; - } else if (format=="atcae") { - imgformat=Image::FORMAT_ATC_ALPHA_EXPLICIT; - } else if (format=="custom") { - imgformat=Image::FORMAT_CUSTOM; - } else { - - ERR_FAIL_V( ERR_FILE_CORRUPT ); - }*/ - - - int datasize; - int w=width.to_int(); - int h=height.to_int(); - - if (w == 0 && h == 0) { - //r_v = Image(w, h, imgformat); - r_v=Image(); - String sdfsdfg; - Error err=parse_property_data(sdfsdfg); - return OK; - }; - - - if (datasize==0) { - //r_v = Image(w, h, imgformat); - r_v=Image(); - String sdfsdfg; - Error err=parse_property_data(sdfsdfg); - return OK; - }; - - PoolVector<uint8_t> pixels; - pixels.resize(datasize); - PoolVector<uint8_t>::Write wb = pixels.write(); - - int idx=0; - uint8_t byte; - while( idx<datasize*2) { - - CharType c=get_char(); - - ERR_FAIL_COND_V(c=='<',ERR_FILE_CORRUPT); - - if ( (c>='0' && c<='9') || (c>='A' && c<='F') || (c>='a' && c<='f') ) { - - if (idx&1) { - - byte|=HEX2CHR(c); - wb[idx>>1]=byte; - } else { - - byte=HEX2CHR(c)<<4; - } - - idx++; - } - - } - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - - wb=PoolVector<uint8_t>::Write(); - - r_v=Image(w,h,mipmaps,imgformat,pixels); - String sdfsdfg; - Error err=parse_property_data(sdfsdfg); - ERR_FAIL_COND_V(err,err); - - return OK; - } - - ERR_FAIL_V(ERR_FILE_CORRUPT); - - } else if (type=="raw_array") { - - if (!tag->args.has("len")) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": RawArray missing 'len' field: "+name); - ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT); - } - int len=tag->args["len"].to_int(); - - PoolVector<uint8_t> bytes; - bytes.resize(len); - PoolVector<uint8_t>::Write w=bytes.write(); - uint8_t *bytesptr=w.ptr(); - int idx=0; - uint8_t byte; - - while( idx<len*2) { - - CharType c=get_char(); - if (c<=32) - continue; - - if (idx&1) { - - byte|=HEX2CHR(c); - bytesptr[idx>>1]=byte; - //printf("%x\n",int(byte)); - } else { - - byte=HEX2CHR(c)<<4; - } - - idx++; - } - - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - - w=PoolVector<uint8_t>::Write(); - r_v=bytes; - String sdfsdfg; - Error err=parse_property_data(sdfsdfg); - ERR_FAIL_COND_V(err,err); - r_name=name; - - return OK; - - } else if (type=="int_array") { - - if (!tag->args.has("len")) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name); - ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT); - } - int len=tag->args["len"].to_int(); - - PoolVector<int> ints; - ints.resize(len); - PoolVector<int>::Write w=ints.write(); - int *intsptr=w.ptr(); - int idx=0; - String str; -#if 0 - while( idx<len ) { - - - CharType c=get_char(); - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - - if (c<33 || c==',' || c=='<') { - - if (str.length()) { - - intsptr[idx]=str.to_int(); - str=""; - idx++; - } - - if (c=='<') { - - while(get_char()!='>' && !f->eof_reached()) {} - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - break; - } - - } else { - - str+=c; - } - } - -#else - - Vector<char> tmpdata; - - while( idx<len ) { - - bool end=false; - Error err = _parse_array_element(tmpdata,true,f,&end); - ERR_FAIL_COND_V(err,err); - - intsptr[idx]=String::to_int(&tmpdata[0]); - idx++; - if (end) - break; - - } - -#endif - w=PoolVector<int>::Write(); - - r_v=ints; - Error err=goto_end_of_tag(); - ERR_FAIL_COND_V(err,err); - r_name=name; - - return OK; - } else if (type=="real_array") { - - if (!tag->args.has("len")) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name); - ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT); - } - int len=tag->args["len"].to_int();; - - PoolVector<real_t> reals; - reals.resize(len); - PoolVector<real_t>::Write w=reals.write(); - real_t *realsptr=w.ptr(); - int idx=0; - String str; - - -#if 0 - while( idx<len ) { - - - CharType c=get_char(); - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - - - if (c<33 || c==',' || c=='<') { - - if (str.length()) { - - realsptr[idx]=str.to_double(); - str=""; - idx++; - } - - if (c=='<') { - - while(get_char()!='>' && !f->eof_reached()) {} - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - break; - } - - } else { - - str+=c; - } - } - -#else - - - - Vector<char> tmpdata; - - while( idx<len ) { - - bool end=false; - Error err = _parse_array_element(tmpdata,true,f,&end); - ERR_FAIL_COND_V(err,err); - - realsptr[idx]=String::to_double(&tmpdata[0]); - idx++; - - if (end) - break; - } - -#endif - - w=PoolVector<real_t>::Write(); - r_v=reals; - - Error err=goto_end_of_tag(); - ERR_FAIL_COND_V(err,err); - r_name=name; - - return OK; - } else if (type=="string_array") { -#if 0 - if (!tag->args.has("len")) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name); - ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT); - } - int len=tag->args["len"].to_int(); - - PoolVector<String> strings; - strings.resize(len); - PoolVector<String>::Write w=strings.write(); - String *stringsptr=w.ptr(); - int idx=0; - String str; - - bool inside_str=false; - CharString cs; - while( idx<len ) { - - - CharType c=get_char(); - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - - - if (c=='"') { - if (inside_str) { - - cs.push_back(0); - String str; - str.parse_utf8(cs.get_data()); - unquote(str); - stringsptr[idx]=str; - cs.clear(); - idx++; - inside_str=false; - } else { - inside_str=true; - } - } else if (c=='<') { - - while(get_char()!='>' && !f->eof_reached()) {} - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - break; - - - } else if (inside_str){ - - cs.push_back(c); - } - } - w=PoolVector<String>::Write(); - r_v=strings; - String sdfsdfg; - Error err=parse_property_data(sdfsdfg); - ERR_FAIL_COND_V(err,err); - - r_name=name; - - return OK; -#endif - if (!tag->args.has("len")) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": String Array missing 'len' field: "+name); - ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT); - } - - - int len=tag->args["len"].to_int(); - - StringArray array; - array.resize(len); - PoolVector<String>::Write w = array.write(); - - Error err; - Variant v; - String tagname; - int idx=0; - - - while( (err=parse_property(v,tagname))==OK ) { - - ERR_CONTINUE( idx <0 || idx >=len ); - String str = v; //convert back to string - w[idx]=str; - idx++; - } - - if (idx!=len) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array (size mismatch): "+name); - ERR_FAIL_COND_V(idx!=len,err); - } - - if (err!=ERR_FILE_EOF) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array: "+name); - ERR_FAIL_COND_V(err!=ERR_FILE_EOF,err); - } - - //err=parse_property_data(name); // skip the rest - //ERR_FAIL_COND_V(err,err); - - r_name=name; - r_v=array; - return OK; - - } else if (type=="vector3_array") { - - if (!tag->args.has("len")) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name); - ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT); - } - int len=tag->args["len"].to_int();; - - PoolVector<Vector3> vectors; - vectors.resize(len); - PoolVector<Vector3>::Write w=vectors.write(); - Vector3 *vectorsptr=w.ptr(); - int idx=0; - int subidx=0; - Vector3 auxvec; - String str; - -// uint64_t tbegin = OS::get_singleton()->get_ticks_usec(); -#if 0 - while( idx<len ) { - - - CharType c=get_char(); - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - - - if (c<33 || c==',' || c=='<') { - - if (str.length()) { - - auxvec[subidx]=str.to_double(); - subidx++; - str=""; - if (subidx==3) { - vectorsptr[idx]=auxvec; - - idx++; - subidx=0; - } - } - - if (c=='<') { - - while(get_char()!='>' && !f->eof_reached()) {} - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - break; - } - - } else { - - str+=c; - } - } -#else - - Vector<char> tmpdata; - - while( idx<len ) { - - bool end=false; - Error err = _parse_array_element(tmpdata,true,f,&end); - ERR_FAIL_COND_V(err,err); - - - auxvec[subidx]=String::to_double(&tmpdata[0]); - subidx++; - if (subidx==3) { - vectorsptr[idx]=auxvec; - - idx++; - subidx=0; - } - - if (end) - break; - } - - - -#endif - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Premature end of vector3 array"); - ERR_FAIL_COND_V(idx<len,ERR_FILE_CORRUPT); -// double time_taken = (OS::get_singleton()->get_ticks_usec() - tbegin)/1000000.0; - - - w=PoolVector<Vector3>::Write(); - r_v=vectors; - String sdfsdfg; - Error err=goto_end_of_tag(); - ERR_FAIL_COND_V(err,err); - r_name=name; - - return OK; - - } else if (type=="vector2_array") { - - if (!tag->args.has("len")) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name); - ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT); - } - int len=tag->args["len"].to_int();; - - PoolVector<Vector2> vectors; - vectors.resize(len); - PoolVector<Vector2>::Write w=vectors.write(); - Vector2 *vectorsptr=w.ptr(); - int idx=0; - int subidx=0; - Vector2 auxvec; - String str; - -// uint64_t tbegin = OS::get_singleton()->get_ticks_usec(); -#if 0 - while( idx<len ) { - - - CharType c=get_char(); - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - - - if (c<22 || c==',' || c=='<') { - - if (str.length()) { - - auxvec[subidx]=str.to_double(); - subidx++; - str=""; - if (subidx==2) { - vectorsptr[idx]=auxvec; - - idx++; - subidx=0; - } - } - - if (c=='<') { - - while(get_char()!='>' && !f->eof_reached()) {} - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - break; - } - - } else { - - str+=c; - } - } -#else - - Vector<char> tmpdata; - - while( idx<len ) { - - bool end=false; - Error err = _parse_array_element(tmpdata,true,f,&end); - ERR_FAIL_COND_V(err,err); - - - auxvec[subidx]=String::to_double(&tmpdata[0]); - subidx++; - if (subidx==2) { - vectorsptr[idx]=auxvec; - - idx++; - subidx=0; - } - - if (end) - break; - } - - - -#endif - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Premature end of vector2 array"); - ERR_FAIL_COND_V(idx<len,ERR_FILE_CORRUPT); -// double time_taken = (OS::get_singleton()->get_ticks_usec() - tbegin)/1000000.0; - - - w=PoolVector<Vector2>::Write(); - r_v=vectors; - String sdfsdfg; - Error err=goto_end_of_tag(); - ERR_FAIL_COND_V(err,err); - r_name=name; - - return OK; - - } else if (type=="color_array") { - - if (!tag->args.has("len")) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name); - ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT); - } - int len=tag->args["len"].to_int();; - - PoolVector<Color> colors; - colors.resize(len); - PoolVector<Color>::Write w=colors.write(); - Color *colorsptr=w.ptr(); - int idx=0; - int subidx=0; - Color auxcol; - String str; - - while( idx<len ) { - - - CharType c=get_char(); - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - - - if (c<33 || c==',' || c=='<') { - - if (str.length()) { - - auxcol[subidx]=str.to_double(); - subidx++; - str=""; - if (subidx==4) { - colorsptr[idx]=auxcol; - idx++; - subidx=0; - } - } - - if (c=='<') { - - while(get_char()!='>' && !f->eof_reached()) {} - ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT); - break; - } - - } else { - - str+=c; - } - } - w=PoolVector<Color>::Write(); - r_v=colors; - String sdfsdfg; - Error err=parse_property_data(sdfsdfg); - ERR_FAIL_COND_V(err,err); - r_name=name; - - return OK; - } - - - String data; - Error err = parse_property_data(data); - ERR_FAIL_COND_V(err!=OK,err); - - if (type=="nil") { - // uh do nothing - - } else if (type=="bool") { - // uh do nothing - if (data.nocasecmp_to("true")==0 || data.to_int()!=0) - r_v=true; - else - r_v=false; - } else if (type=="int") { - - r_v=data.to_int(); - } else if (type=="real") { - - r_v=data.to_double(); - } else if (type=="string") { - - String str=data; - unquote(str); - r_v=str; - } else if (type=="vector3") { - - - r_v=Vector3( - 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_slicec(',',0).to_double(), - data.get_slicec(',',1).to_double() - ); - - } else if (type=="plane") { - - r_v=Plane( - 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_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_slicec(',',0).to_double(), - data.get_slicec(',',1).to_double() - ), - Vector2( - data.get_slicec(',',2).to_double(), - data.get_slicec(',',3).to_double() - ) - ); - - - } else if (type=="aabb") { - - r_v=AABB( - Vector3( - data.get_slicec(',',0).to_double(), - data.get_slicec(',',1).to_double(), - data.get_slicec(',',2).to_double() - ), - Vector3( - data.get_slicec(',',3).to_double(), - data.get_slicec(',',4).to_double(), - data.get_slicec(',',5).to_double() - ) - ); - - } else if (type=="matrix32") { - - Matrix32 m3; - for (int i=0;i<3;i++) { - for (int j=0;j<2;j++) { - m3.elements[i][j]=data.get_slicec(',',i*2+j).to_double(); - } - } - r_v=m3; - - } else if (type=="matrix3") { - - Matrix3 m3; - for (int i=0;i<3;i++) { - for (int j=0;j<3;j++) { - m3.elements[i][j]=data.get_slicec(',',i*3+j).to_double(); - } - } - r_v=m3; - - } else if (type=="transform") { - - Transform tr; - for (int i=0;i<3;i++) { - for (int j=0;j<3;j++) { - tr.basis.elements[i][j]=data.get_slicec(',',i*3+j).to_double(); - } - - } - tr.origin=Vector3( - 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_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") { - - String str=data; - unquote(str); - r_v=NodePath( str ); - } else if (type=="input_event") { - - // ? - } else { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Unrecognized tag in file: "+type); - ERR_FAIL_V(ERR_FILE_CORRUPT); - } - r_name=name; - return OK; -} - - - -int ResourceInteractiveLoaderXML::get_current_line() const { - - return lines; -} - - -uint8_t ResourceInteractiveLoaderXML::get_char() const { - - uint8_t c = f->get_8(); - if (c=='\n') - lines++; - return c; - -} - - - - -/// - -void ResourceInteractiveLoaderXML::set_local_path(const String& p_local_path) { - - res_path=p_local_path; -} - -Ref<Resource> ResourceInteractiveLoaderXML::get_resource() { - - return resource; -} -Error ResourceInteractiveLoaderXML::poll() { - - if (error!=OK) - return error; - - bool exit; - Tag *tag = parse_tag(&exit); - - - if (!tag) { - error=ERR_FILE_CORRUPT; - if (!exit) // shouldn't have exited - ERR_FAIL_V(error); - error=ERR_FILE_EOF; - return error; - } - - RES res; - //Object *obj=NULL; - - bool main; - - if (tag->name=="ext_resource") { - - error=ERR_FILE_CORRUPT; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> missing 'path' field."); - ERR_FAIL_COND_V(!tag->args.has("path"),ERR_FILE_CORRUPT); - - String type="Resource"; - if (tag->args.has("type")) - type=tag->args["type"]; - - String path = tag->args["path"]; - - - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> can't use a local path, this is a bug?."); - ERR_FAIL_COND_V(path.begins_with("local://"),ERR_FILE_CORRUPT); - - if (path.find("://")==-1 && path.is_rel_path()) { - // path is relative to file being loaded, so convert to a resource path - path=GlobalConfig::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path)); - } - - if (remaps.has(path)) { - path=remaps[path]; - } - - RES res = ResourceLoader::load(path,type); - - if (res.is_null()) { - - if (ResourceLoader::get_abort_on_missing_resources()) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> referenced nonexistent resource at: "+path); - ERR_FAIL_V(error); - } else { - ResourceLoader::notify_dependency_error(local_path,path,type); - } - } else { - - resource_cache.push_back(res); - } - - if (tag->args.has("index")) { - ExtResource er; - er.path=path; - er.type=type; - ext_resources[tag->args["index"].to_int()]=er; - } - - - Error err = close_tag("ext_resource"); - if (err) - return error; - - - error=OK; - resource_current++; - return error; - - } else if (tag->name=="resource") { - - main=false; - } else if (tag->name=="main_resource") { - main=true; - } else { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": unexpected main tag: "+tag->name); - error=ERR_FILE_CORRUPT; - ERR_FAIL_V(error); - } - - - String type; - String path; - int subres=0; - - if (!main) { - //loading resource - - error=ERR_FILE_CORRUPT; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <resource> missing 'len' field."); - ERR_FAIL_COND_V(!tag->args.has("path"),ERR_FILE_CORRUPT); - 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://",""); - subres=path.to_int(); - path=local_path+"::"+path; - } - - - if (ResourceCache::has(path)) { - Error err = close_tag(tag->name); - if (err) { - error=ERR_FILE_CORRUPT; - } - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Unable to close <resource> tag."); - ERR_FAIL_COND_V( err, err ); - resource_current++; - error=OK; - return OK; - } - - type = tag->args["type"]; - } else { - type=resource_type; - } - - Object *obj = ClassDB::instance(type); - if (!obj) { - error=ERR_FILE_CORRUPT; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Object of unrecognized type in file: "+type); - } - ERR_FAIL_COND_V(!obj,ERR_FILE_CORRUPT); - - Resource *r = obj->cast_to<Resource>(); - if (!r) { - error=ERR_FILE_CORRUPT; - memdelete(obj); //bye - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Object type in resource field not a resource, type is: "+obj->get_class()); - ERR_FAIL_COND_V(!r,ERR_FILE_CORRUPT); - } - - res = RES( r ); - if (path!="") - r->set_path(path); - r->set_subindex(subres); - - //load properties - - while(true) { - - String name; - Variant v; - Error err; - err = parse_property(v,name); - if (err==ERR_FILE_EOF) //tag closed - break; - if (err!=OK) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": XML Parsing aborted."); - ERR_FAIL_COND_V(err!=OK,ERR_FILE_CORRUPT); - } - - obj->set(name,v); - } -#ifdef TOOLS_ENABLED - res->set_edited(false); -#endif - resource_cache.push_back(res); //keep it in mem until finished loading - resource_current++; - if (main) { - f->close(); - resource=res; - if (!ResourceCache::has(res_path)) { - resource->set_path(res_path); - } - error=ERR_FILE_EOF; - return error; - - } - error=OK; - return OK; -} - -int ResourceInteractiveLoaderXML::get_stage() const { - - return resource_current; -} -int ResourceInteractiveLoaderXML::get_stage_count() const { - - return resources_total;//+ext_resources; -} - -ResourceInteractiveLoaderXML::~ResourceInteractiveLoaderXML() { - - memdelete(f); -} - -void ResourceInteractiveLoaderXML::get_dependencies(FileAccess *f,List<String> *p_dependencies,bool p_add_types) { - - - open(f); - ERR_FAIL_COND(error!=OK); - - while(true) { - bool exit; - Tag *tag = parse_tag(&exit); - - - if (!tag) { - error=ERR_FILE_CORRUPT; - ERR_FAIL_COND(!exit); - error=ERR_FILE_EOF; - return; - } - - if (tag->name!="ext_resource") { - - return; - } - - error=ERR_FILE_CORRUPT; - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> missing 'path' field."); - ERR_FAIL_COND(!tag->args.has("path")); - - String path = tag->args["path"]; - - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> can't use a local path, this is a bug?."); - ERR_FAIL_COND(path.begins_with("local://")); - - if (path.find("://")==-1 && path.is_rel_path()) { - // path is relative to file being loaded, so convert to a resource path - path=GlobalConfig::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path)); - } - - if (path.ends_with("*")) { - ERR_FAIL_COND(!tag->args.has("type")); - String type = tag->args["type"]; - path = ResourceLoader::guess_full_filename(path,type); - } - - if (p_add_types && tag->args.has("type")) { - path+="::"+tag->args["type"]; - } - - p_dependencies->push_back(path); - - Error err = close_tag("ext_resource"); - if (err) - return; - - error=OK; - } - -} - -Error ResourceInteractiveLoaderXML::rename_dependencies(FileAccess *p_f, const String &p_path,const Map<String,String>& p_map) { - - open(p_f); - ERR_FAIL_COND_V(error!=OK,error); - - //FileAccess - - bool old_format=false; - - FileAccess *fw = NULL; - - String base_path=local_path.get_base_dir(); - - while(true) { - bool exit; - List<String> order; - - Tag *tag = parse_tag(&exit,true,&order); - - bool done=false; - - if (!tag) { - if (fw) { - memdelete(fw); - } - error=ERR_FILE_CORRUPT; - ERR_FAIL_COND_V(!exit,error); - error=ERR_FILE_EOF; - - return error; - } - - if (tag->name=="ext_resource") { - - if (!tag->args.has("index") || !tag->args.has("path") || !tag->args.has("type")) { - old_format=true; - break; - } - - if (!fw) { - - fw=FileAccess::open(p_path+".depren",FileAccess::WRITE); - fw->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //no escape - fw->store_line("<resource_file type=\""+resource_type+"\" subresource_count=\""+itos(resources_total)+"\" version=\""+itos(VERSION_MAJOR)+"."+itos(VERSION_MINOR)+"\" version_name=\""+VERSION_FULL_NAME+"\">"); - - } - - String path = tag->args["path"]; - String index = tag->args["index"]; - String type = tag->args["type"]; - - - bool relative=false; - if (!path.begins_with("res://")) { - path=base_path.plus_file(path).simplify_path(); - relative=true; - } - - - if (p_map.has(path)) { - String np=p_map[path]; - path=np; - } - - if (relative) { - //restore relative - path=base_path.path_to_file(path); - } - - tag->args["path"]=path; - tag->args["index"]=index; - tag->args["type"]=type; - - } else { - - done=true; - } - - String tagt="\t<"; - if (exit) - tagt+="/"; - tagt+=tag->name; - - for(List<String>::Element *E=order.front();E;E=E->next()) { - tagt+=" "+E->get()+"=\""+tag->args[E->get()]+"\""; - } - tagt+=">"; - fw->store_line(tagt); - if (done) - break; - close_tag("ext_resource"); - fw->store_line("\t</ext_resource>"); - - } - - - if (old_format) { - if (fw) - memdelete(fw); - - DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - da->remove(p_path+".depren"); - memdelete(da); - //fuck it, use the old approach; - - WARN_PRINT(("This file is old, so it can't refactor dependencies, opening and resaving: "+p_path).utf8().get_data()); - - Error err; - FileAccess *f2 = FileAccess::open(p_path,FileAccess::READ,&err); - if (err!=OK) { - ERR_FAIL_COND_V(err!=OK,ERR_FILE_CANT_OPEN); - } - - Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML ); - ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path); - ria->res_path=ria->local_path; - ria->remaps=p_map; - // ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); - ria->open(f2); - - err = ria->poll(); - - while(err==OK) { - err=ria->poll(); - } - - ERR_FAIL_COND_V(err!=ERR_FILE_EOF,ERR_FILE_CORRUPT); - RES res = ria->get_resource(); - ERR_FAIL_COND_V(!res.is_valid(),ERR_FILE_CORRUPT); - - return ResourceFormatSaverXML::singleton->save(p_path,res); - } - - if (!fw) { - - return OK; //nothing to rename, do nothing - } - - uint8_t c=f->get_8(); - while(!f->eof_reached()) { - fw->store_8(c); - c=f->get_8(); - } - f->close(); - - bool all_ok = fw->get_error()==OK; - - memdelete(fw); - - if (!all_ok) { - return ERR_CANT_CREATE; - } - - DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); - da->remove(p_path); - da->rename(p_path+".depren",p_path); - memdelete(da); - - return OK; - -} - - -void ResourceInteractiveLoaderXML::open(FileAccess *p_f) { - - error=OK; - - lines=1; - f=p_f; - - - ResourceInteractiveLoaderXML::Tag *tag = parse_tag(); - if (!tag || tag->name!="?xml" || !tag->args.has("version") || !tag->args.has("encoding") || tag->args["encoding"]!="UTF-8") { - - error=ERR_FILE_CORRUPT; - ResourceLoader::notify_load_error("XML is invalid (missing header tags)"); - ERR_EXPLAIN("Not a XML:UTF-8 File: "+local_path); - ERR_FAIL(); - } - - tag_stack.clear(); - - tag = parse_tag(); - - - if (!tag || tag->name!="resource_file" || !tag->args.has("type") || !tag->args.has("version")) { - - ResourceLoader::notify_load_error(local_path+": XML is not a valid resource file."); - error=ERR_FILE_CORRUPT; - ERR_EXPLAIN("Unrecognized XML File: "+local_path); - ERR_FAIL(); - } - - - if (tag->args.has("subresource_count")) - resources_total=tag->args["subresource_count"].to_int(); - resource_current=0; - resource_type=tag->args["type"]; - - String version = tag->args["version"]; - if (version.get_slice_count(".")!=2) { - - error=ERR_FILE_CORRUPT; - ResourceLoader::notify_load_error(local_path+":XML version string is invalid: "+version); - ERR_EXPLAIN("Invalid Version String '"+version+"'' in file: "+local_path); - ERR_FAIL(); - } - - int major = version.get_slicec('.',0).to_int(); - 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."); - ERR_EXPLAIN("File Format '"+version+"' is too new! Please upgrade to a a new engine version: "+local_path); - ERR_FAIL(); - - } - - /* - String preload_depts = "deps/"+local_path.md5_text(); - if (Globals::get_singleton()->has(preload_depts)) { - ext_resources.clear(); - //ignore external resources and use these - NodePath depts=Globals::get_singleton()->get(preload_depts); - - for(int i=0;i<depts.get_name_count();i++) { - ext_resources.push_back(depts.get_name(i)); - } - print_line(local_path+" - EXTERNAL RESOURCES: "+itos(ext_resources.size())); - } -*/ - -} - -String ResourceInteractiveLoaderXML::recognize(FileAccess *p_f) { - - error=OK; - - lines=1; - f=p_f; - - ResourceInteractiveLoaderXML::Tag *tag = parse_tag(); - if (!tag || tag->name!="?xml" || !tag->args.has("version") || !tag->args.has("encoding") || tag->args["encoding"]!="UTF-8") { - - - return ""; //unrecognized - } - - tag_stack.clear(); - - tag = parse_tag(); - - if (!tag || tag->name!="resource_file" || !tag->args.has("type") || !tag->args.has("version")) { - - return ""; //unrecognized - } - - return tag->args["type"]; - -} - -///////////////////// - -Ref<ResourceInteractiveLoader> ResourceFormatLoaderXML::load_interactive(const String &p_path, Error *r_error) { - - if (r_error) - *r_error=ERR_CANT_OPEN; - - Error err; - FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err); - - - if (err!=OK) { - - ERR_FAIL_COND_V(err!=OK,Ref<ResourceInteractiveLoader>()); - } - - Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML ); - ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path); - ria->res_path=ria->local_path; -// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); - ria->open(f); - - return ria; -} - -void ResourceFormatLoaderXML::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const { - - if (p_type=="") { - get_recognized_extensions(p_extensions); - return; - } - - List<String> extensions; - ClassDB::get_extensions_for_type(p_type,&extensions); - - extensions.sort(); - - for(List<String>::Element *E=extensions.front();E;E=E->next()) { - String ext = E->get().to_lower(); - if (ext=="res") - continue; - p_extensions->push_back("x"+ext); - } - - p_extensions->push_back("xml"); - - -} -void ResourceFormatLoaderXML::get_recognized_extensions(List<String> *p_extensions) const{ - - List<String> extensions; - ClassDB::get_resource_base_extensions(&extensions); - extensions.sort(); - - for(List<String>::Element *E=extensions.front();E;E=E->next()) { - String ext = E->get().to_lower(); - if (ext=="res") - continue; - p_extensions->push_back("x"+ext); - } - - p_extensions->push_back("xml"); -} - -bool ResourceFormatLoaderXML::handles_type(const String& p_type) const{ - - return true; -} -String ResourceFormatLoaderXML::get_resource_type(const String &p_path) const{ - - - String ext=p_path.extension().to_lower(); - if (!ext.begins_with("x")) //a lie but.. - return ""; - - FileAccess *f = FileAccess::open(p_path,FileAccess::READ); - if (!f) { - - return ""; //could not rwead - } - - Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML ); - ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path); - ria->res_path=ria->local_path; -// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); - String r = ria->recognize(f); - return r; -} - - -void ResourceFormatLoaderXML::get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types) { - - FileAccess *f = FileAccess::open(p_path,FileAccess::READ); - if (!f) { - - ERR_FAIL(); - } - - Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML ); - ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path); - ria->res_path=ria->local_path; -// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); - ria->get_dependencies(f,p_dependencies,p_add_types); - - -} - -Error ResourceFormatLoaderXML::rename_dependencies(const String &p_path,const Map<String,String>& p_map) { - - FileAccess *f = FileAccess::open(p_path,FileAccess::READ); - if (!f) { - - ERR_FAIL_V(ERR_CANT_OPEN); - } - - Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML ); - ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path); - ria->res_path=ria->local_path; -// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); - return ria->rename_dependencies(f,p_path,p_map); -} - - -/****************************************************************************************/ -/****************************************************************************************/ -/****************************************************************************************/ -/****************************************************************************************/ -/****************************************************************************************/ -/****************************************************************************************/ -/****************************************************************************************/ -/****************************************************************************************/ -/****************************************************************************************/ -/****************************************************************************************/ -/****************************************************************************************/ -/****************************************************************************************/ -/****************************************************************************************/ - - - -void ResourceFormatSaverXMLInstance::escape(String& p_str) { - - p_str=p_str.replace("&","&"); - p_str=p_str.replace("<","<"); - p_str=p_str.replace(">",">"); - p_str=p_str.replace("'","'"); - p_str=p_str.replace("\"","""); - 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'}; - const char hex[8]={'&','#','0','0',hexn[i>>4],hexn[i&0xf],';',0}; - - p_str=p_str.replace(chr,hex); - } - - -} -void ResourceFormatSaverXMLInstance::write_tabs(int p_diff) { - - for (int i=0;i<depth+p_diff;i++) { - - f->store_8('\t'); - } -} - -void ResourceFormatSaverXMLInstance::write_string(String p_str,bool p_escape) { - - /* write an UTF8 string */ - if (p_escape) - escape(p_str); - - f->store_string(p_str);; - /* - CharString cs=p_str.utf8(); - const char *data=cs.get_data(); - - while (*data) { - f->store_8(*data); - data++; - }*/ - - -} - -void ResourceFormatSaverXMLInstance::enter_tag(const char* p_tag,const String& p_args) { - - f->store_8('<'); - int cc = 0; - const char *c=p_tag; - while(*c) { - cc++; - c++; - } - f->store_buffer((const uint8_t*)p_tag,cc); - if (p_args.length()) { - f->store_8(' '); - f->store_string(p_args); - } - f->store_8('>'); - depth++; - -} -void ResourceFormatSaverXMLInstance::exit_tag(const char* p_tag) { - - depth--; - f->store_8('<'); - f->store_8('/'); - int cc = 0; - const char *c=p_tag; - while(*c) { - cc++; - c++; - } - f->store_buffer((const uint8_t*)p_tag,cc); - f->store_8('>'); - -} - -/* -static bool _check_type(const Variant& p_property) { - - if (p_property.get_type()==Variant::_RID) - return false; - if (p_property.get_type()==Variant::OBJECT) { - RES res = p_property; - if (res.is_null()) - return false; - } - - return true; -}*/ - -void ResourceFormatSaverXMLInstance::write_property(const String& p_name,const Variant& p_property,bool *r_ok) { - - if (r_ok) - *r_ok=false; - - const char* type; - String params; - bool oneliner=true; - - switch( p_property.get_type() ) { - - case Variant::NIL: type="nil"; break; - case Variant::BOOL: type="bool"; break; - case Variant::INT: type="int"; break; - case Variant::REAL: type="real"; break; - case Variant::STRING: type="string"; break; - case Variant::VECTOR2: type="vector2"; break; - case Variant::RECT2: type="rect2"; break; - case Variant::VECTOR3: type="vector3"; break; - case Variant::PLANE: type="plane"; break; - case Variant::_AABB: type="aabb"; break; - case Variant::QUAT: type="quaternion"; break; - case Variant::MATRIX32: type="matrix32"; break; - case Variant::MATRIX3: type="matrix3"; break; - case Variant::TRANSFORM: type="transform"; break; - case Variant::COLOR: type="color"; break; - case Variant::IMAGE: { - type="image"; - Image img=p_property; - if (img.empty()) { - write_tabs(); - enter_tag(type,"name=\""+p_name+"\""); - exit_tag(type); - if (r_ok) - *r_ok=true; - return; - } - params+="encoding=\"raw\""; - params+=" width=\""+itos(img.get_width())+"\""; - params+=" height=\""+itos(img.get_height())+"\""; - params+=" mipmaps=\""+itos(img.has_mipmaps())+"\""; -/* - switch(img.get_format()) { - - case Image::FORMAT_L8: params+=" format=\"grayscale\""; break; - case Image::FORMAT_INTENSITY: params+=" format=\"intensity\""; break; - case Image::FORMAT_LA8: params+=" format=\"grayscale_alpha\""; break; - case Image::FORMAT_RGB8: params+=" format=\"rgb\""; break; - case Image::FORMAT_RGBA8: params+=" format=\"rgba\""; break; - case Image::FORMAT_INDEXED : params+=" format=\"indexed\""; break; - case Image::FORMAT_INDEXED_ALPHA: params+=" format=\"indexed_alpha\""; break; - case Image::FORMAT_DXT1: params+=" format=\"bc1\""; break; - case Image::FORMAT_DXT3: params+=" format=\"bc2\""; break; - case Image::FORMAT_DXT5: params+=" format=\"bc3\""; break; - case Image::FORMAT_ATI1: params+=" format=\"bc4\""; break; - case Image::FORMAT_ATI2: params+=" format=\"bc5\""; break; - case Image::FORMAT_PVRTC2: params+=" format=\"pvrtc2\""; break; - case Image::FORMAT_PVRTC2A: params+=" format=\"pvrtc2a\""; break; - case Image::FORMAT_PVRTC4: params+=" format=\"pvrtc4\""; break; - case Image::FORMAT_PVRTC4A: params+=" format=\"pvrtc4a\""; break; - case Image::FORMAT_ETC: params+=" format=\"etc\""; break; - case Image::FORMAT_ATC: params+=" format=\"atc\""; break; - case Image::FORMAT_ATC_ALPHA_EXPLICIT: params+=" format=\"atcae\""; break; - case Image::FORMAT_ATC_ALPHA_INTERPOLATED: params+=" format=\"atcai\""; break; - case Image::FORMAT_CUSTOM: params+=" format=\"custom\" custom_size=\""+itos(img.get_data().size())+"\""; break; - default: {} - }*/ - } break; - case Variant::NODE_PATH: type="node_path"; break; - case Variant::OBJECT: { - type="resource"; - RES res = p_property; - if (res.is_null()) { - write_tabs(); - enter_tag(type,"name=\""+p_name+"\""); - exit_tag(type); - if (r_ok) - *r_ok=true; - - return; // don't save it - } - - if (external_resources.has(res)) { - - params="external=\""+itos(external_resources[res])+"\""; - } else { - params="resource_type=\""+res->get_save_class()+"\""; - - - if (res->get_path().length() && res->get_path().find("::")==-1) { - //external resource - String path=relative_paths?local_path.path_to_file(res->get_path()):res->get_path(); - escape(path); - params+=" path=\""+path+"\""; - } else { - - //internal resource - ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?"); - ERR_FAIL_COND(!resource_set.has(res)); - - params+=" path=\"local://"+itos(res->get_subindex())+"\""; - } - } - - } break; - case Variant::INPUT_EVENT: type="input_event"; break; - case Variant::DICTIONARY: type="dictionary"; params="shared=\""+String(p_property.is_shared()?"true":"false")+"\""; oneliner=false; break; - case Variant::ARRAY: type="array"; params="len=\""+itos(p_property.operator Array().size())+"\" shared=\""+String(p_property.is_shared()?"true":"false")+"\""; oneliner=false; break; - - case Variant::RAW_ARRAY: type="raw_array"; params="len=\""+itos(p_property.operator PoolVector < uint8_t >().size())+"\""; break; - case Variant::INT_ARRAY: type="int_array"; params="len=\""+itos(p_property.operator PoolVector < int >().size())+"\""; break; - case Variant::REAL_ARRAY: type="real_array"; params="len=\""+itos(p_property.operator PoolVector < real_t >().size())+"\""; break; - case Variant::STRING_ARRAY: oneliner=false; type="string_array"; params="len=\""+itos(p_property.operator PoolVector < String >().size())+"\""; break; - case Variant::VECTOR2_ARRAY: type="vector2_array"; params="len=\""+itos(p_property.operator PoolVector < Vector2 >().size())+"\""; break; - case Variant::VECTOR3_ARRAY: type="vector3_array"; params="len=\""+itos(p_property.operator PoolVector < Vector3 >().size())+"\""; break; - case Variant::COLOR_ARRAY: type="color_array"; params="len=\""+itos(p_property.operator PoolVector < Color >().size())+"\""; break; - default: { - - ERR_PRINT("Unknown Variant type."); - ERR_FAIL(); - } - - } - - write_tabs(); - - if (p_name!="") { - if (params.length()) - enter_tag(type,"name=\""+p_name+"\" "+params); - else - enter_tag(type,"name=\""+p_name+"\""); - } else { - if (params.length()) - enter_tag(type," "+params); - else - enter_tag(type,String()); - } - - if (!oneliner) - f->store_8('\n'); - else - f->store_8(' '); - - - switch( p_property.get_type() ) { - - case Variant::NIL: { - - } break; - case Variant::BOOL: { - - write_string( p_property.operator bool() ? "True":"False" ); - } break; - case Variant::INT: { - - write_string( itos(p_property.operator int()) ); - } break; - case Variant::REAL: { - - write_string( rtos(p_property.operator real_t()) ); - } break; - case Variant::STRING: { - - String str=p_property; - escape(str); - str="\""+str+"\""; - write_string( str,false ); - } break; - case Variant::VECTOR2: { - - Vector2 v = p_property; - write_string( rtoss(v.x) +", "+rtoss(v.y) ); - } break; - case Variant::RECT2: { - - Rect2 aabb = p_property; - write_string( rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y) ); - - } break; - case Variant::VECTOR3: { - - Vector3 v = p_property; - write_string( rtoss(v.x) +", "+rtoss(v.y)+", "+rtoss(v.z) ); - } break; - case Variant::PLANE: { - - Plane p = p_property; - write_string( rtoss(p.normal.x) +", "+rtoss(p.normal.y)+", "+rtoss(p.normal.z)+", "+rtoss(p.d) ); - - } break; - case Variant::_AABB: { - - AABB aabb = p_property; - write_string( rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.pos.z) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y) +", "+rtoss(aabb.size.z) ); - - } break; - case Variant::QUAT: { - - Quat quat = p_property; - write_string( rtoss(quat.x)+", "+rtoss(quat.y)+", "+rtoss(quat.z)+", "+rtoss(quat.w)+", "); - - } break; - case Variant::MATRIX32: { - - String s; - Matrix32 m3 = p_property; - for (int i=0;i<3;i++) { - for (int j=0;j<2;j++) { - - if (i!=0 || j!=0) - s+=", "; - s+=rtoss( m3.elements[i][j] ); - } - } - - write_string(s); - - } break; - case Variant::MATRIX3: { - - String s; - Matrix3 m3 = p_property; - for (int i=0;i<3;i++) { - for (int j=0;j<3;j++) { - - if (i!=0 || j!=0) - s+=", "; - s+=rtoss( m3.elements[i][j] ); - } - } - - write_string(s); - - } break; - case Variant::TRANSFORM: { - - String s; - Transform t = p_property; - Matrix3 &m3 = t.basis; - for (int i=0;i<3;i++) { - for (int j=0;j<3;j++) { - - if (i!=0 || j!=0) - s+=", "; - s+=rtoss( m3.elements[i][j] ); - } - } - - s=s+", "+rtoss(t.origin.x) +", "+rtoss(t.origin.y)+", "+rtoss(t.origin.z); - - write_string(s); - } break; - - // misc types - case Variant::COLOR: { - - Color c = p_property; - write_string( rtoss(c.r) +", "+rtoss(c.g)+", "+rtoss(c.b)+", "+rtoss(c.a) ); - - } break; - case Variant::IMAGE: { - - String s; - Image img = p_property; - PoolVector<uint8_t> data = img.get_data(); - int len = data.size(); - PoolVector<uint8_t>::Read r = data.read(); - const uint8_t *ptr=r.ptr();; - for (int i=0;i<len;i++) { - - uint8_t byte = ptr[i]; - const char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; - char str[3]={ hex[byte>>4], hex[byte&0xF], 0}; - s+=str; - } - - write_string(s); - } break; - case Variant::NODE_PATH: { - - String str=p_property; - escape(str); - str="\""+str+"\""; - write_string( str,false); - - } break; - - case Variant::OBJECT: { - /* this saver does not save resources in here - RES res = p_property; - - if (!res.is_null()) { - - String path=res->get_path(); - if (!res->is_shared() || !path.length()) { - // if no path, or path is from inside a scene - write_object( *res ); - } - - } - */ - - } break; - case Variant::INPUT_EVENT: { - - write_string( p_property.operator String() ); - } break; - case Variant::DICTIONARY: { - - Dictionary dict = p_property; - - - 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); - - write_property("",dict[E->get()],&ok); - if (!ok) - write_property("",Variant()); //at least make the file consistent.. - } - - - - - } break; - case Variant::ARRAY: { - - Array array = p_property; - int len=array.size(); - for (int i=0;i<len;i++) { - - write_property("",array[i]); - - } - - } break; - - case Variant::RAW_ARRAY: { - - String s; - PoolVector<uint8_t> data = p_property; - int len = data.size(); - PoolVector<uint8_t>::Read r = data.read(); - const uint8_t *ptr=r.ptr();; - for (int i=0;i<len;i++) { - - uint8_t byte = ptr[i]; - const char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; - char str[3]={ hex[byte>>4], hex[byte&0xF], 0}; - s+=str; - } - - write_string(s,false); - - } break; - case Variant::INT_ARRAY: { - - PoolVector<int> data = p_property; - int len = data.size(); - PoolVector<int>::Read r = data.read(); - const int *ptr=r.ptr();; - write_tabs(); - - for (int i=0;i<len;i++) { - - if (i>0) - write_string(", ",false); - - write_string(itos(ptr[i]),false); - } - - - - } break; - case Variant::REAL_ARRAY: { - - PoolVector<real_t> data = p_property; - int len = data.size(); - PoolVector<real_t>::Read r = data.read(); - const real_t *ptr=r.ptr();; - write_tabs(); - String cm=", " ; - - for (int i=0;i<len;i++) { - - if (i>0) - write_string(cm,false); - write_string(rtoss(ptr[i]),false); - } - - - } break; - case Variant::STRING_ARRAY: { - - PoolVector<String> data = p_property; - int len = data.size(); - PoolVector<String>::Read r = data.read(); - const String *ptr=r.ptr();; - String s; - //write_string("\n"); - - - - for (int i=0;i<len;i++) { - - write_tabs(0); - String str=ptr[i]; - escape(str); - write_string("<string> \""+str+"\" </string>\n",false); - } - } break; - case Variant::VECTOR2_ARRAY: { - - PoolVector<Vector2> data = p_property; - int len = data.size(); - PoolVector<Vector2>::Read r = data.read(); - const Vector2 *ptr=r.ptr();; - write_tabs(); - - for (int i=0;i<len;i++) { - - if (i>0) - write_string(", ",false); - write_string(rtoss(ptr[i].x),false); - write_string(", "+rtoss(ptr[i].y),false); - - } - - - } break; - case Variant::VECTOR3_ARRAY: { - - PoolVector<Vector3> data = p_property; - int len = data.size(); - PoolVector<Vector3>::Read r = data.read(); - const Vector3 *ptr=r.ptr();; - write_tabs(); - - for (int i=0;i<len;i++) { - - if (i>0) - write_string(", ",false); - write_string(rtoss(ptr[i].x),false); - write_string(", "+rtoss(ptr[i].y),false); - write_string(", "+rtoss(ptr[i].z),false); - - } - - - } break; - case Variant::COLOR_ARRAY: { - - PoolVector<Color> data = p_property; - int len = data.size(); - PoolVector<Color>::Read r = data.read(); - const Color *ptr=r.ptr();; - write_tabs(); - - for (int i=0;i<len;i++) { - - if (i>0) - write_string(", ",false); - - write_string(rtoss(ptr[i].r),false); - write_string(", "+rtoss(ptr[i].g),false); - write_string(", "+rtoss(ptr[i].b),false); - write_string(", "+rtoss(ptr[i].a),false); - - } - - } break; - default: {} - - } - if (oneliner) - f->store_8(' '); - else - write_tabs(-1); - exit_tag(type); - - f->store_8('\n'); - - if (r_ok) - *r_ok=true; - -} - - -void ResourceFormatSaverXMLInstance::_find_resources(const Variant& p_variant,bool p_main) { - - - switch(p_variant.get_type()) { - case Variant::OBJECT: { - - - RES res = p_variant.operator RefPtr(); - - if (res.is_null() || external_resources.has(res)) - return; - - if (!p_main && (!bundle_resources ) && res->get_path().length() && res->get_path().find("::") == -1 ) { - int index = external_resources.size(); - external_resources[res]=index; - return; - } - - 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(); - - while(I) { - - PropertyInfo pi=I->get(); - - if (pi.usage&PROPERTY_USAGE_STORAGE) { - - Variant v=res->get(I->get().name); - _find_resources(v); - } - - I=I->next(); - } - - resource_set.insert( res ); //saved after, so the childs it needs are available when loaded - saved_resources.push_back(res); - - } break; - case Variant::ARRAY: { - - Array varray=p_variant; - int len=varray.size(); - for(int i=0;i<len;i++) { - - Variant v=varray.get(i); - _find_resources(v); - } - - } break; - case Variant::DICTIONARY: { - - Dictionary d=p_variant; - List<Variant> keys; - d.get_key_list(&keys); - for(List<Variant>::Element *E=keys.front();E;E=E->next()) { - - Variant v = d[E->get()]; - _find_resources(v); - } - } break; - default: {} - } - -} - - - -Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_resource,uint32_t p_flags) { - - Error err; - f = FileAccess::open(p_path, FileAccess::WRITE,&err); - ERR_FAIL_COND_V( err, ERR_CANT_OPEN ); - FileAccessRef _fref(f); - - local_path = GlobalConfig::get_singleton()->localize_path(p_path); - - relative_paths=p_flags&ResourceSaver::FLAG_RELATIVE_PATHS; - skip_editor=p_flags&ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES; - bundle_resources=p_flags&ResourceSaver::FLAG_BUNDLE_RESOURCES; - takeover_paths=p_flags&ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; - if (!p_path.begins_with("res://")) { - takeover_paths=false; - } - depth=0; - - // save resources - _find_resources(p_resource,true); - - ERR_FAIL_COND_V(err!=OK,err); - - write_string("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>",false); //no escape - write_string("\n",false); - enter_tag("resource_file","type=\""+p_resource->get_class()+"\" 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(Map<RES,int>::Element *E=external_resources.front();E;E=E->next()) { - - write_tabs(); - String p = E->key()->get_path(); - - enter_tag("ext_resource","path=\""+p+"\" type=\""+E->key()->get_save_class()+"\" index=\""+itos(E->get())+"\""); //bundled - exit_tag("ext_resource"); //bundled - 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_set.has(res)); - bool main = (E->next()==NULL); - - write_tabs(); - - if (main) - enter_tag("main_resource",""); //bundled - else if (res->get_path().length() && res->get_path().find("::") == -1 ) - enter_tag("resource","type=\""+res->get_class()+"\" path=\""+res->get_path()+"\""); //bundled - else { - - 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_class()+"\" path=\"local://"+itos(idx)+"\""); - if (takeover_paths) { - res->set_path(p_path+"::"+itos(idx),true); - } -#ifdef TOOLS_ENABLED - res->set_edited(false); -#endif - - - } - write_string("\n",false); - - - 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()) { - - - if (skip_editor && PE->get().name.begins_with("__editor")) - continue; - - if (PE->get().usage&PROPERTY_USAGE_STORAGE ) { - - String name = PE->get().name; - Variant value = res->get(name); - - - 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); - } - - - } - - write_string("\n",false); - write_tabs(-1); - if (main) - exit_tag("main_resource"); - else - exit_tag("resource"); - - write_string("\n",false); - } - - exit_tag("resource_file"); - if (f->get_error()!=OK && f->get_error()!=ERR_FILE_EOF) { - f->close(); - return ERR_CANT_CREATE; - } - - f->close(); - //memdelete(f); - - return OK; -} - - - -Error ResourceFormatSaverXML::save(const String &p_path,const RES& p_resource,uint32_t p_flags) { - - ResourceFormatSaverXMLInstance saver; - return saver.save(p_path,p_resource,p_flags); - -} - -bool ResourceFormatSaverXML::recognize(const RES& p_resource) const { - - - return true; // all recognized! -} -void ResourceFormatSaverXML::get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const { - - - //here comes the sun, lalalala - String base = p_resource->get_base_extension().to_lower(); - p_extensions->push_back("xml"); - if (base!="res") { - - p_extensions->push_back("x"+base); - } - -} - -ResourceFormatSaverXML* ResourceFormatSaverXML::singleton=NULL; -ResourceFormatSaverXML::ResourceFormatSaverXML() { - singleton=this; -} diff --git a/core/io/resource_format_xml.h b/core/io/resource_format_xml.h deleted file mode 100644 index 097c2e43f8..0000000000 --- a/core/io/resource_format_xml.h +++ /dev/null @@ -1,170 +0,0 @@ -/*************************************************************************/ -/* resource_format_xml.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef RESOURCE_FORMAT_XML_H -#define RESOURCE_FORMAT_XML_H - -#include "io/resource_loader.h" -#include "io/resource_saver.h" -#include "os/file_access.h" - - - -class ResourceInteractiveLoaderXML : public ResourceInteractiveLoader { - - String local_path; - String res_path; - - FileAccess *f; - - struct Tag { - - String name; - HashMap<String,String> args; - - }; - - _FORCE_INLINE_ Error _parse_array_element(Vector<char> &buff,bool p_number_only,FileAccess *f,bool *end); - - - struct ExtResource { - String path; - String type; - }; - - - Map<String,String> remaps; - - Map<int,ExtResource> ext_resources; - - int resources_total; - int resource_current; - String resource_type; - - mutable int lines; - uint8_t get_char() const; - int get_current_line() const; - -friend class ResourceFormatLoaderXML; - List<Tag> tag_stack; - - List<RES> resource_cache; - Tag* parse_tag(bool* r_exit=NULL,bool p_printerr=true,List<String> *r_order=NULL); - Error close_tag(const String& p_name); - _FORCE_INLINE_ void unquote(String& p_str); - Error goto_end_of_tag(); - Error parse_property_data(String &r_data); - Error parse_property(Variant& r_v, String &r_name); - - Error error; - - RES resource; - -public: - - virtual void set_local_path(const String& p_local_path); - virtual Ref<Resource> get_resource(); - virtual Error poll(); - virtual int get_stage() const; - virtual int get_stage_count() const; - - void open(FileAccess *p_f); - String recognize(FileAccess *p_f); - void get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types); - Error rename_dependencies(FileAccess *p_f, const String &p_path,const Map<String,String>& p_map); - - - ~ResourceInteractiveLoaderXML(); - -}; - -class ResourceFormatLoaderXML : public ResourceFormatLoader { -public: - - virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,Error *r_error=NULL); - virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const; - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String& p_type) const; - virtual String get_resource_type(const String &p_path) const; - virtual void get_dependencies(const String& p_path, List<String> *p_dependencies, bool p_add_types=false); - virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map); - - -}; - - -//////////////////////////////////////////////////////////////////////////////////////////// - - -class ResourceFormatSaverXMLInstance { - - String local_path; - - - - bool takeover_paths; - bool relative_paths; - bool bundle_resources; - bool skip_editor; - FileAccess *f; - int depth; - Set<RES> resource_set; - List<RES> saved_resources; - Map<RES,int> external_resources; - - void enter_tag(const char* p_tag,const String& p_args=String()); - void exit_tag(const char* p_tag); - - void _find_resources(const Variant& p_variant,bool p_main=false); - void write_property(const String& p_name,const Variant& p_property,bool *r_ok=NULL); - - - void escape(String& p_str); - void write_tabs(int p_diff=0); - void write_string(String p_str,bool p_escape=true); - - -public: - - Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0); - - -}; - -class ResourceFormatSaverXML : public ResourceFormatSaver { -public: - static ResourceFormatSaverXML* singleton; - virtual Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0); - virtual bool recognize(const RES& p_resource) const; - virtual void get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const; - - ResourceFormatSaverXML(); -}; - - -#endif // RESOURCE_FORMAT_XML_H diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 7c076d028e..fe88d1d13d 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -44,7 +44,6 @@ #include "translation.h" #include "compressed_translation.h" #include "io/translation_loader_po.h" -#include "io/resource_format_xml.h" #include "io/resource_format_binary.h" #include "io/stream_peer_ssl.h" #include "os/input.h" @@ -56,10 +55,6 @@ #include "input_map.h" #include "undo_redo.h" -#ifdef XML_ENABLED -static ResourceFormatSaverXML *resource_saver_xml=NULL; -static ResourceFormatLoaderXML *resource_loader_xml=NULL; -#endif static ResourceFormatSaverBinary *resource_saver_binary=NULL; static ResourceFormatLoaderBinary *resource_loader_binary=NULL; @@ -109,13 +104,6 @@ void register_core_types() { resource_loader_binary = memnew( ResourceFormatLoaderBinary ); ResourceLoader::add_resource_format_loader(resource_loader_binary); -#ifdef XML_ENABLED - resource_saver_xml = memnew( ResourceFormatSaverXML ); - ResourceSaver::add_resource_format_saver(resource_saver_xml); - resource_loader_xml = memnew( ResourceFormatLoaderXML ); - ResourceLoader::add_resource_format_loader(resource_loader_xml); -#endif - ClassDB::register_class<Object>(); @@ -212,12 +200,6 @@ void unregister_core_types() { memdelete( _marshalls ); memdelete( _geometry ); -#ifdef XML_ENABLED - if (resource_saver_xml) - memdelete(resource_saver_xml); - if (resource_loader_xml) - memdelete(resource_loader_xml); -#endif if (resource_saver_binary) memdelete(resource_saver_binary); diff --git a/core/ustring.cpp b/core/ustring.cpp index 0c26fe90c6..27bb8eac72 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -1547,20 +1547,20 @@ String::String(const StrRange& p_range) { int String::hex_to_int(bool p_with_prefix) const { - int l = length(); + int l = length(); if (p_with_prefix && l<3) return 0; - const CharType *s=ptr(); + const CharType *s=ptr(); - int sign = s[0]=='-' ? -1 : 1; + int sign = s[0]=='-' ? -1 : 1; - if (sign<0) { - s++; - l--; + if (sign<0) { + s++; + l--; if (p_with_prefix && l<2) - return 0; - } + return 0; + } if (p_with_prefix) { if (s[0]!='0' || s[1]!='x') @@ -1569,26 +1569,74 @@ int String::hex_to_int(bool p_with_prefix) const { l-=2; }; - int hex=0; + int hex=0; - while(*s) { + while(*s) { - CharType c = LOWERCASE(*s); - int n; - if (c>='0' && c<='9') { - n=c-'0'; - } else if (c>='a' && c<='f') { - n=(c-'a')+10; - } else { - return 0; - } + CharType c = LOWERCASE(*s); + int n; + if (c>='0' && c<='9') { + n=c-'0'; + } else if (c>='a' && c<='f') { + n=(c-'a')+10; + } else { + return 0; + } - hex*=16; - hex+=n; - s++; - } + hex*=16; + hex+=n; + s++; + } + + return hex*sign; + +} + + +int64_t String::hex_to_int64(bool p_with_prefix) const { + + int l = length(); + if (p_with_prefix && l<3) + return 0; + + const CharType *s=ptr(); + + int64_t sign = s[0]=='-' ? -1 : 1; + + if (sign<0) { + s++; + l--; + if (p_with_prefix && l<2) + return 0; + } + + if (p_with_prefix) { + if (s[0]!='0' || s[1]!='x') + return 0; + s+=2; + l-=2; + }; + + int64_t hex=0; + + while(*s) { + + CharType c = LOWERCASE(*s); + int64_t n; + if (c>='0' && c<='9') { + n=c-'0'; + } else if (c>='a' && c<='f') { + n=(c-'a')+10; + } else { + return 0; + } + + hex*=16; + hex+=n; + s++; + } - return hex*sign; + return hex*sign; } diff --git a/core/ustring.h b/core/ustring.h index 8b008c2ba4..9a145143d0 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -147,6 +147,7 @@ public: int hex_to_int(bool p_with_prefix = true) const; int to_int() const; + int64_t hex_to_int64(bool p_with_prefix = true) const; int64_t to_int64() const; static int to_int(const char* p_str, int p_len=-1); static double to_double(const char* p_str); diff --git a/core/variant.cpp b/core/variant.cpp index 6b50443854..69160fffa7 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -1467,7 +1467,7 @@ Variant::operator double() const { case NIL: return 0; case BOOL: return _data._bool ? 1.0 : 0.0; - case INT: return (float)_data._int; + case INT: return (double)_data._int; case REAL: return _data._real; case STRING: return operator String().to_double(); default: { @@ -1504,8 +1504,8 @@ Variant::operator String() const { case NIL: return "Null"; case BOOL: return _data._bool ? "True" : "False"; - case INT: return String::num(_data._int); - case REAL: return String::num(_data._real); + case INT: return itos(_data._int); + case REAL: return rtos(_data._real); case STRING: return *reinterpret_cast<const String*>(_data._mem); case VECTOR2: return "("+operator Vector2()+")"; case RECT2: return "("+operator Rect2()+")"; diff --git a/core/variant.h b/core/variant.h index a2b9a88b3e..764ba9ae60 100644 --- a/core/variant.h +++ b/core/variant.h @@ -141,7 +141,7 @@ private: union { bool _bool; - int _int; + int64_t _int; double _real; Matrix32 *_matrix32; AABB* _aabb; diff --git a/core/variant_call.cpp b/core/variant_call.cpp index a54737faf8..5c9e8e9248 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -32,6 +32,7 @@ #include "core_string_names.h" #include "script_language.h" + typedef void (*VariantFunc)(Variant& r_ret,Variant& p_self,const Variant** p_args); typedef void (*VariantConstructFunc)(Variant& r_ret,const Variant** p_args); @@ -146,6 +147,15 @@ struct _VariantCall { }; // void addfunc(Variant::Type p_type, const StringName& p_name,VariantFunc p_func); + + static void make_func_return_variant(Variant::Type p_type,const StringName& p_name) { + +#ifdef DEBUG_ENABLED + type_funcs[p_type].functions[p_name].returns=true; +#endif + } + + static void addfunc(Variant::Type p_type, Variant::Type p_return,const StringName& p_name,VariantFunc p_func, const Vector<Variant>& p_defaultarg,const Arg& p_argtype1=Arg(),const Arg& p_argtype2=Arg(),const Arg& p_argtype3=Arg(),const Arg& p_argtype4=Arg(),const Arg& p_argtype5=Arg()) { FuncData funcdata; @@ -455,8 +465,6 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM0R(Dictionary,hash); VCALL_LOCALMEM0R(Dictionary,keys); VCALL_LOCALMEM0R(Dictionary,values); - VCALL_LOCALMEM1R(Dictionary,parse_json); - VCALL_LOCALMEM0R(Dictionary,to_json); VCALL_LOCALMEM2(Array,set); VCALL_LOCALMEM1R(Array,get); @@ -1436,6 +1444,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(STRING,RAW_ARRAY,String,to_utf8,varray()); + ADDFUNC0(VECTOR2,VECTOR2,Vector2,normalized,varray()); ADDFUNC0(VECTOR2,REAL,Vector2,length,varray()); ADDFUNC0(VECTOR2,REAL,Vector2,angle,varray()); @@ -1556,9 +1565,6 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(DICTIONARY,ARRAY,Dictionary,keys,varray()); ADDFUNC0(DICTIONARY,ARRAY,Dictionary,values,varray()); - ADDFUNC1(DICTIONARY,INT,Dictionary,parse_json,STRING,"json",varray()); - ADDFUNC0(DICTIONARY,STRING,Dictionary,to_json,varray()); - ADDFUNC0(ARRAY,INT,Array,size,varray()); ADDFUNC0(ARRAY,BOOL,Array,empty,varray()); ADDFUNC0(ARRAY,NIL,Array,clear,varray()); diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 84edb51c73..00baffdd3b 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -683,7 +683,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant& case INT: { switch(p_b.type) { case BOOL: { - int b = p_b._data._bool; + int64_t b = p_b._data._bool; if (b==0) { r_valid=false; @@ -693,7 +693,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant& } break; case INT: { - int b = p_b._data._int; + int64_t b = p_b._data._int; if (b==0) { r_valid=false; @@ -3358,8 +3358,8 @@ void Variant::blend(const Variant& a, const Variant& b, float c, Variant &r_dst) switch(a.type) { case NIL: { r_dst=Variant(); } return; case INT:{ - int va=a._data._int; - int vb=b._data._int; + int64_t va=a._data._int; + int64_t vb=b._data._int; r_dst=int(va + vb * c + 0.5); } return; case REAL:{ @@ -3423,8 +3423,8 @@ void Variant::interpolate(const Variant& a, const Variant& b, float c,Variant &r case NIL:{ r_dst=Variant(); } return; case BOOL:{ r_dst=a; } return; case INT:{ - int va=a._data._int; - int vb=b._data._int; + int64_t va=a._data._int; + int64_t vb=b._data._int; r_dst=int((1.0-c) * va + vb * c); } return; case REAL:{ diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index 74b804b206..64578e5f5c 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -35,6 +35,7 @@ #include "os/os.h" #include "variant_parser.h" #include "io/marshalls.h" +#include "io/json.h" const char *GDFunctions::get_func_name(Function p_func) { @@ -103,6 +104,9 @@ const char *GDFunctions::get_func_name(Function p_func) { "load", "inst2dict", "dict2inst", + "validate_json", + "parse_json", + "to_json", "hash", "Color8", "print_stack", @@ -846,6 +850,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va if (p_args[0]->get_type()!=Variant::STRING) { r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument=0; + r_error.expected=Variant::STRING; r_ret=Variant(); } else { r_ret=ResourceLoader::load(*p_args[0]); @@ -1024,6 +1029,57 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va } } break; + case VALIDATE_JSON: { + + VALIDATE_ARG_COUNT(1); + + if (p_args[0]->get_type()!=Variant::STRING) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::STRING; + r_ret=Variant(); + return; + } + + String errs; + int errl; + + Error err = JSON::parse(*p_args[0],r_ret,errs,errl); + + if (err!=OK) { + r_ret=itos(errl)+":"+errs; + } else { + r_ret=""; + } + + } break; + case PARSE_JSON: { + + VALIDATE_ARG_COUNT(1); + + if (p_args[0]->get_type()!=Variant::STRING) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::STRING; + r_ret=Variant(); + return; + } + + String errs; + int errl; + + Error err = JSON::parse(*p_args[0],r_ret,errs,errl); + + if (err!=OK) { + r_ret=Variant(); + } + + } break; + case TO_JSON: { + VALIDATE_ARG_COUNT(1); + + r_ret = JSON::print(*p_args[0]); + } break; case HASH: { VALIDATE_ARG_COUNT(1); @@ -1510,6 +1566,24 @@ MethodInfo GDFunctions::get_info(Function p_func) { mi.return_val.type=Variant::OBJECT; return mi; } break; + case VALIDATE_JSON: { + + MethodInfo mi("validate_json:Variant",PropertyInfo(Variant::STRING,"json")); + mi.return_val.type=Variant::STRING; + return mi; + } break; + case PARSE_JSON: { + + MethodInfo mi("parse_json:Variant",PropertyInfo(Variant::STRING,"json")); + mi.return_val.type=Variant::NIL; + return mi; + } break; + case TO_JSON: { + + MethodInfo mi("to_json",PropertyInfo(Variant::NIL,"var:Variant")); + mi.return_val.type=Variant::STRING; + return mi; + } break; case HASH: { MethodInfo mi("hash",PropertyInfo(Variant::NIL,"var:Variant")); diff --git a/modules/gdscript/gd_functions.h b/modules/gdscript/gd_functions.h index fb04527060..ab708e3ebe 100644 --- a/modules/gdscript/gd_functions.h +++ b/modules/gdscript/gd_functions.h @@ -97,6 +97,9 @@ public: RESOURCE_LOAD, INST2DICT, DICT2INST, + VALIDATE_JSON, + PARSE_JSON, + TO_JSON, HASH, COLOR8, PRINT_STACK, diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 865c07f3b2..2b306a92fc 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -731,14 +731,14 @@ void GDTokenizerText::_advance() { INCPOS(str.length()); if (hexa_found) { - int val = str.hex_to_int(); + int64_t val = str.hex_to_int64(); _make_constant(val); } else if (period_found || exponent_found) { - real_t val = str.to_double(); + double val = str.to_double(); //print_line("*%*%*%*% to convert: "+str+" result: "+rtos(val)); _make_constant(val); } else { - int val = str.to_int(); + int64_t val = str.to_int64(); _make_constant(val); } @@ -1060,7 +1060,7 @@ void GDTokenizerText::advance(int p_amount) { ////////////////////////////////////////////////////////////////////////////////////////////////////// -#define BYTECODE_VERSION 11 +#define BYTECODE_VERSION 12 Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> & p_buffer) { diff --git a/modules/mpc/SCsub b/modules/mpc/SCsub deleted file mode 100644 index 76b7cbea7a..0000000000 --- a/modules/mpc/SCsub +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python - -Import('env') -Import('env_modules') - -env_mpc = env_modules.Clone() - -# Thirdparty source files -if (env['builtin_libmpcdec'] != 'no'): - thirdparty_dir = "#thirdparty/libmpcdec/" - thirdparty_sources = [ - "huffman.c", - "mpc_bits_reader.c", - "mpc_decoder.c", - "mpc_demux.c", - "mpc_reader.c", - "requant.c", - "streaminfo.c", - "synth_filter.c", - ] - - thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] - - env_mpc.add_source_files(env.modules_sources, thirdparty_sources) - env_mpc.Append(CPPPATH=[thirdparty_dir]) - -# Godot source files -env_mpc.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/mpc/audio_stream_mpc.cpp b/modules/mpc/audio_stream_mpc.cpp deleted file mode 100644 index bcb7e4c871..0000000000 --- a/modules/mpc/audio_stream_mpc.cpp +++ /dev/null @@ -1,414 +0,0 @@ -/*************************************************************************/ -/* audio_stream_mpc.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "audio_stream_mpc.h" - - -Error AudioStreamPlaybackMPC::_open_file() { - - if (f) { - memdelete(f); - f=NULL; - } - Error err; - //printf("mpc open file %ls\n", file.c_str()); - f=FileAccess::open(file,FileAccess::READ,&err); - - if (err) { - f=NULL; - ERR_FAIL_V(err); - return err; - } - - //printf("file size is %i\n", f->get_len()); - //f->seek_end(0); - streamlen=f->get_len(); - //f->seek(0); - if (streamlen<=0) { - memdelete(f); - f=NULL; - ERR_FAIL_V(ERR_INVALID_DATA); - } - - data_ofs=0; - if (preload) { - - data.resize(streamlen); - PoolVector<uint8_t>::Write w = data.write(); - f->get_buffer(&w[0],streamlen); - memdelete(f); - f=NULL; - - } - - return OK; -} - -void AudioStreamPlaybackMPC::_close_file() { - - if (f) { - memdelete(f); - f=NULL; - } - data.resize(0); - streamlen=0; - data_ofs=0; -} - -int AudioStreamPlaybackMPC::_read_file(void *p_dst,int p_bytes) { - - if (f) - return f->get_buffer((uint8_t*)p_dst,p_bytes); - - PoolVector<uint8_t>::Read r = data.read(); - if (p_bytes+data_ofs > streamlen) { - p_bytes=streamlen-data_ofs; - } - - copymem(p_dst,&r[data_ofs],p_bytes); - //print_line("read file: "+itos(p_bytes)); - data_ofs+=p_bytes; - return p_bytes; -} - -bool AudioStreamPlaybackMPC::_seek_file(int p_pos){ - - if (p_pos<0 || p_pos>streamlen) - return false; - - if (f) { - f->seek(p_pos); - return true; - } - - //print_line("read file to: "+itos(p_pos)); - data_ofs=p_pos; - return true; - -} -int AudioStreamPlaybackMPC::_tell_file() const{ - - if (f) - return f->get_pos(); - - //print_line("tell file, get: "+itos(data_ofs)); - return data_ofs; - -} - -int AudioStreamPlaybackMPC::_sizeof_file() const{ - - //print_line("sizeof file, get: "+itos(streamlen)); - return streamlen; -} - -bool AudioStreamPlaybackMPC::_canseek_file() const{ - - //print_line("canseek file, get true"); - return true; -} - -///////////////////// - -mpc_int32_t AudioStreamPlaybackMPC::_mpc_read(mpc_reader *p_reader,void *p_dst, mpc_int32_t p_bytes) { - - AudioStreamPlaybackMPC *smpc=(AudioStreamPlaybackMPC *)p_reader->data; - return smpc->_read_file(p_dst,p_bytes); -} - -mpc_bool_t AudioStreamPlaybackMPC::_mpc_seek(mpc_reader *p_reader,mpc_int32_t p_offset) { - - AudioStreamPlaybackMPC *smpc=(AudioStreamPlaybackMPC *)p_reader->data; - return smpc->_seek_file(p_offset); - -} -mpc_int32_t AudioStreamPlaybackMPC::_mpc_tell(mpc_reader *p_reader) { - - AudioStreamPlaybackMPC *smpc=(AudioStreamPlaybackMPC *)p_reader->data; - return smpc->_tell_file(); - -} -mpc_int32_t AudioStreamPlaybackMPC::_mpc_get_size(mpc_reader *p_reader) { - - AudioStreamPlaybackMPC *smpc=(AudioStreamPlaybackMPC *)p_reader->data; - return smpc->_sizeof_file(); - - -} -mpc_bool_t AudioStreamPlaybackMPC::_mpc_canseek(mpc_reader *p_reader) { - - AudioStreamPlaybackMPC *smpc=(AudioStreamPlaybackMPC *)p_reader->data; - return smpc->_canseek_file(); -} - - - - -int AudioStreamPlaybackMPC::mix(int16_t* p_bufer,int p_frames) { - - if (!active || paused) - return 0; - - int todo=p_frames; - - while(todo>MPC_DECODER_BUFFER_LENGTH/si.channels) { - - mpc_frame_info frame; - - frame.buffer=sample_buffer; - - mpc_status err = mpc_demux_decode(demux, &frame); - if (frame.bits!=-1) { - - int16_t *dst_buff = p_bufer; - -#ifdef MPC_FIXED_POINT - - for( int i = 0; i < frame.samples * si.channels; i++) { - int tmp = sample_buffer[i] >> MPC_FIXED_POINT_FRACTPART; - if (tmp > ((1 << 15) - 1)) tmp = ((1 << 15) - 1); - if (tmp < -(1 << 15)) tmp = -(1 << 15); - dst_buff[i] = tmp; - } -#else - for( int i = 0; i < frame.samples * si.channels; i++) { - - int tmp = Math::fast_ftoi(sample_buffer[i]*32767.0); - if (tmp > ((1 << 15) - 1)) tmp = ((1 << 15) - 1); - if (tmp < -(1 << 15)) tmp = -(1 << 15); - dst_buff[i] = tmp; - - } - -#endif - - int frames = frame.samples; - p_bufer+=si.channels*frames; - todo-=frames; - } else { - - if (err != MPC_STATUS_OK) { - - stop(); - ERR_PRINT("Error decoding MPC"); - break; - } else { - - //finished - if (!loop) { - stop(); - break; - } else { - - - loops++; - mpc_demux_exit(demux); - _seek_file(0); - demux = mpc_demux_init(&reader); - //do loop somehow - - } - } - } - } - - return p_frames-todo; -} - -Error AudioStreamPlaybackMPC::_reload() { - - ERR_FAIL_COND_V(demux!=NULL, ERR_FILE_ALREADY_IN_USE); - - Error err = _open_file(); - ERR_FAIL_COND_V(err!=OK,ERR_CANT_OPEN); - - demux = mpc_demux_init(&reader); - ERR_FAIL_COND_V(!demux,ERR_CANT_CREATE); - mpc_demux_get_info(demux, &si); - - return OK; -} - -void AudioStreamPlaybackMPC::set_file(const String& p_file) { - - file=p_file; - - Error err = _open_file(); - ERR_FAIL_COND(err!=OK); - demux = mpc_demux_init(&reader); - ERR_FAIL_COND(!demux); - mpc_demux_get_info(demux, &si); - stream_min_size=MPC_DECODER_BUFFER_LENGTH*2/si.channels; - stream_rate=si.sample_freq; - stream_channels=si.channels; - - mpc_demux_exit(demux); - demux=NULL; - _close_file(); - -} - - -String AudioStreamPlaybackMPC::get_file() const { - - return file; -} - - -void AudioStreamPlaybackMPC::play(float p_offset) { - - - if (active) - stop(); - active=false; - - Error err = _open_file(); - ERR_FAIL_COND(err!=OK); - if (_reload()!=OK) - return; - active=true; - loops=0; - -} - -void AudioStreamPlaybackMPC::stop() { - - - if (!active) - return; - if (demux) { - mpc_demux_exit(demux); - demux=NULL; - } - _close_file(); - active=false; - -} -bool AudioStreamPlaybackMPC::is_playing() const { - - return active; -} - - -void AudioStreamPlaybackMPC::set_loop(bool p_enable) { - - loop=p_enable; -} -bool AudioStreamPlaybackMPC::has_loop() const { - - return loop; -} - -float AudioStreamPlaybackMPC::get_length() const { - - return 0; -} - -String AudioStreamPlaybackMPC::get_stream_name() const { - - return ""; -} - -int AudioStreamPlaybackMPC::get_loop_count() const { - - return 0; -} - -float AudioStreamPlaybackMPC::get_pos() const { - - return 0; -} -void AudioStreamPlaybackMPC::seek_pos(float p_time) { - - -} - - -void AudioStreamPlaybackMPC::_bind_methods() { - - ClassDB::bind_method(_MD("set_file","name"),&AudioStreamPlaybackMPC::set_file); - ClassDB::bind_method(_MD("get_file"),&AudioStreamPlaybackMPC::get_file); - - ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"file",PROPERTY_HINT_FILE,"mpc"), _SCS("set_file"), _SCS("get_file")); - -} - -AudioStreamPlaybackMPC::AudioStreamPlaybackMPC() { - - preload=false; - f=NULL; - streamlen=0; - data_ofs=0; - active=false; - paused=false; - loop=false; - demux=NULL; - reader.data=this; - reader.read=_mpc_read; - reader.seek=_mpc_seek; - reader.tell=_mpc_tell; - reader.get_size=_mpc_get_size; - reader.canseek=_mpc_canseek; - loops=0; - -} - -AudioStreamPlaybackMPC::~AudioStreamPlaybackMPC() { - - stop(); - - if (f) - memdelete(f); -} - - - -RES ResourceFormatLoaderAudioStreamMPC::load(const String &p_path, const String& p_original_path, Error *r_error) { - if (r_error) - *r_error=OK; //streamed so it will always work.. - AudioStreamMPC *mpc_stream = memnew(AudioStreamMPC); - mpc_stream->set_file(p_path); - return Ref<AudioStreamMPC>(mpc_stream); -} - -void ResourceFormatLoaderAudioStreamMPC::get_recognized_extensions(List<String> *p_extensions) const { - - p_extensions->push_back("mpc"); -} -bool ResourceFormatLoaderAudioStreamMPC::handles_type(const String& p_type) const { - - return (p_type=="AudioStream") || (p_type=="AudioStreamMPC"); -} - -String ResourceFormatLoaderAudioStreamMPC::get_resource_type(const String &p_path) const { - - if (p_path.extension().to_lower()=="mpc") - return "AudioStreamMPC"; - return ""; -} - diff --git a/modules/mpc/audio_stream_mpc.h b/modules/mpc/audio_stream_mpc.h deleted file mode 100644 index 5330fa055f..0000000000 --- a/modules/mpc/audio_stream_mpc.h +++ /dev/null @@ -1,146 +0,0 @@ -/*************************************************************************/ -/* audio_stream_mpc.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef AUDIO_STREAM_MPC_H -#define AUDIO_STREAM_MPC_H - -#include "io/resource_loader.h" -#include "os/file_access.h" -#include "os/thread_safe.h" -#include "scene/resources/audio_stream.h" - -#include <mpc/mpcdec.h> - -class AudioStreamPlaybackMPC : public AudioStreamPlayback { - - GDCLASS( AudioStreamPlaybackMPC, AudioStreamPlayback ); - - bool preload; - FileAccess *f; - String file; - PoolVector<uint8_t> data; - int data_ofs; - int streamlen; - - - bool active; - bool paused; - bool loop; - int loops; - - // mpc - mpc_reader reader; - mpc_demux* demux; - mpc_streaminfo si; - MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH]; - - static mpc_int32_t _mpc_read(mpc_reader *p_reader,void *p_dst, mpc_int32_t p_bytes); - static mpc_bool_t _mpc_seek(mpc_reader *p_reader,mpc_int32_t p_offset); - static mpc_int32_t _mpc_tell(mpc_reader *p_reader); - static mpc_int32_t _mpc_get_size(mpc_reader *p_reader); - static mpc_bool_t _mpc_canseek(mpc_reader *p_reader); - - int stream_min_size; - int stream_rate; - int stream_channels; - -protected: - Error _open_file(); - void _close_file(); - int _read_file(void *p_dst,int p_bytes); - bool _seek_file(int p_pos); - int _tell_file() const; - int _sizeof_file() const; - bool _canseek_file() const; - - - Error _reload(); - static void _bind_methods(); - -public: - - void set_file(const String& p_file); - String get_file() const; - - virtual void play(float p_offset=0); - virtual void stop(); - virtual bool is_playing() const; - - - virtual void set_loop(bool p_enable); - virtual bool has_loop() const; - - virtual float get_length() const; - - virtual String get_stream_name() const; - - virtual int get_loop_count() const; - - virtual float get_pos() const; - virtual void seek_pos(float p_time); - - virtual int get_channels() const { return stream_channels; } - virtual int get_mix_rate() const { return stream_rate; } - - virtual int get_minimum_buffer_size() const { return stream_min_size; } - virtual int mix(int16_t* p_bufer,int p_frames); - - virtual void set_loop_restart_time(float p_time) { } - - AudioStreamPlaybackMPC(); - ~AudioStreamPlaybackMPC(); -}; - -class AudioStreamMPC : public AudioStream { - - GDCLASS( AudioStreamMPC, AudioStream ); - - String file; -public: - - Ref<AudioStreamPlayback> instance_playback() { - Ref<AudioStreamPlaybackMPC> pb = memnew( AudioStreamPlaybackMPC ); - pb->set_file(file); - return pb; - } - - void set_file(const String& p_file) { file=p_file; } - - -}; - -class ResourceFormatLoaderAudioStreamMPC : public ResourceFormatLoader { -public: - virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String& p_type) const; - virtual String get_resource_type(const String &p_path) const; - -}; - -#endif // AUDIO_STREAM_MPC_H diff --git a/modules/mpc/config.py b/modules/mpc/config.py deleted file mode 100644 index fb920482f5..0000000000 --- a/modules/mpc/config.py +++ /dev/null @@ -1,7 +0,0 @@ - -def can_build(platform): - return True - - -def configure(env): - pass diff --git a/modules/mpc/register_types.cpp b/modules/mpc/register_types.cpp deleted file mode 100644 index df058916bb..0000000000 --- a/modules/mpc/register_types.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "register_types.h" - -#include "audio_stream_mpc.h" - -static ResourceFormatLoaderAudioStreamMPC* mpc_stream_loader = NULL; - -void register_mpc_types() { - - mpc_stream_loader=memnew( ResourceFormatLoaderAudioStreamMPC ); - ResourceLoader::add_resource_format_loader(mpc_stream_loader); - ClassDB::register_class<AudioStreamMPC>(); -} - -void unregister_mpc_types() { - - memdelete( mpc_stream_loader ); -} diff --git a/modules/mpc/register_types.h b/modules/mpc/register_types.h deleted file mode 100644 index d1e692f254..0000000000 --- a/modules/mpc/register_types.h +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -void register_mpc_types(); -void unregister_mpc_types(); diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index 531c3b0a00..f31f51a5cd 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -280,7 +280,8 @@ BoxContainer::AlignMode BoxContainer::get_alignment() const { void BoxContainer::add_spacer(bool p_begin) { Control *c = memnew( Control ); - c->set_stop_mouse(false); + c->set_mouse_filter(MOUSE_FILTER_PASS); //allow spacer to pass mouse events + if (vertical) c->set_v_size_flags(SIZE_EXPAND_FILL); else @@ -296,7 +297,7 @@ BoxContainer::BoxContainer(bool p_vertical) { vertical=p_vertical; align = ALIGN_BEGIN; // set_ignore_mouse(true); - set_stop_mouse(false); + set_mouse_filter(MOUSE_FILTER_PASS); } void BoxContainer::_bind_methods() { diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 9c96adcbf2..a7e08f9f7e 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -242,7 +242,7 @@ Button::Button(const String &p_text) { flat=false; clip_text=false; - set_stop_mouse(true); + set_mouse_filter(MOUSE_FILTER_STOP); set_text(p_text); align=ALIGN_CENTER; } diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 9083bdc128..9c30b333b0 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -501,9 +501,9 @@ ColorPicker::ColorPicker() : - uv_edit->set_ignore_mouse(false); + uv_edit->connect("gui_input", this, "_uv_input"); - uv_edit->set_stop_mouse(false); + uv_edit->set_mouse_filter(MOUSE_FILTER_PASS); uv_edit->set_custom_minimum_size(Size2 (256,256)); Vector<Variant> args=Vector<Variant>(); args.push_back(0); @@ -513,7 +513,7 @@ ColorPicker::ColorPicker() : add_child(hb_edit); w_edit= memnew( Control ); - w_edit->set_ignore_mouse(false); + //w_edit->set_ignore_mouse(false); w_edit->set_custom_minimum_size(Size2(30,256)); w_edit->connect("gui_input", this, "_w_input"); args.clear(); @@ -592,7 +592,7 @@ ColorPicker::ColorPicker() : preset = memnew( TextureFrame ); bbc->add_child(preset); - preset->set_ignore_mouse(false); + //preset->set_ignore_mouse(false); preset->connect("gui_input", this, "_preset_input"); bt_add_preset = memnew ( Button ); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index abfe11dba0..7507ab0952 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -116,30 +116,7 @@ bool Control::_set(const StringName& p_name, const Variant& p_value) { String name= p_name; if (!name.begins_with("custom")) { - if (name.begins_with("margin/")) { - String dname = name.get_slicec('/', 1); - if (dname == "left") { - set_margin(MARGIN_LEFT, p_value); - return true; - } - else if (dname == "top") { - set_margin(MARGIN_TOP, p_value); - return true; - } - else if (dname == "right") { - set_margin(MARGIN_RIGHT, p_value); - return true; - } - else if (dname == "bottom") { - set_margin(MARGIN_BOTTOM, p_value); - return true; - } - else { - return false; - } - } else { - return false; - } + return false; } if (p_value.get_type()==Variant::NIL) { @@ -235,30 +212,8 @@ bool Control::_get(const StringName& p_name,Variant &r_ret) const { String sname=p_name; if (!sname.begins_with("custom")) { - if (sname.begins_with("margin/")) { - String dname = sname.get_slicec('/', 1); - if (dname == "left") { - r_ret = get_margin(MARGIN_LEFT); - return true; - } - else if (dname == "top") { - r_ret = get_margin(MARGIN_TOP); - return true; - } - else if (dname == "right") { - r_ret = get_margin(MARGIN_RIGHT); - return true; - } - else if (dname == "bottom") { - r_ret = get_margin(MARGIN_BOTTOM); - return true; - } - else { - return false; - } - } else { - return false; - } + return false; + } if (sname.begins_with("custom_icons/")) { @@ -295,36 +250,6 @@ bool Control::_get(const StringName& p_name,Variant &r_ret) const { } void Control::_get_property_list( List<PropertyInfo> *p_list) const { - { - if (get_anchor(MARGIN_LEFT) == ANCHOR_RATIO) { - p_list->push_back(PropertyInfo(Variant::REAL, "margin/left", PROPERTY_HINT_RANGE, "-4096,4096,0.001")); - } - else { - p_list->push_back(PropertyInfo(Variant::INT, "margin/left", PROPERTY_HINT_RANGE, "-4096,4096")); - } - - if (get_anchor(MARGIN_TOP) == ANCHOR_RATIO) { - p_list->push_back(PropertyInfo(Variant::REAL, "margin/top", PROPERTY_HINT_RANGE, "-4096,4096,0.001")); - } - else { - p_list->push_back(PropertyInfo(Variant::INT, "margin/top", PROPERTY_HINT_RANGE, "-4096,4096")); - } - - if (get_anchor(MARGIN_RIGHT) == ANCHOR_RATIO) { - p_list->push_back(PropertyInfo(Variant::REAL, "margin/right", PROPERTY_HINT_RANGE, "-4096,4096,0.001")); - } - else { - p_list->push_back(PropertyInfo(Variant::INT, "margin/right", PROPERTY_HINT_RANGE, "-4096,4096")); - } - - if (get_anchor(MARGIN_BOTTOM) == ANCHOR_RATIO) { - p_list->push_back(PropertyInfo(Variant::REAL, "margin/bottom", PROPERTY_HINT_RANGE, "-4096,4096,0.001")); - } - else { - p_list->push_back(PropertyInfo(Variant::INT, "margin/bottom", PROPERTY_HINT_RANGE, "-4096,4096")); - } - } - Ref<Theme> theme; if (data.theme.is_valid()) { @@ -1258,14 +1183,10 @@ void Control::_size_changed() { margin_pos[i]=area-data.margin[i]; } break; - case ANCHOR_RATIO: { + case ANCHOR_CENTER: { - margin_pos[i]=area*data.margin[i]; + margin_pos[i]=(area/2)-data.margin[i]; } break; - case ANCHOR_CENTER: { - - margin_pos[i]=(area/2)-data.margin[i]; - } break; } } @@ -1334,12 +1255,9 @@ float Control::_s2a(float p_val, AnchorType p_anchor,float p_range) const { case ANCHOR_END: { return p_range-p_val; } break; - case ANCHOR_RATIO: { - return p_val/p_range; + case ANCHOR_CENTER: { + return (p_range/2)-p_val; } break; - case ANCHOR_CENTER: { - return (p_range/2)-p_val; - } break; } return 0; @@ -1356,11 +1274,8 @@ float Control::_a2s(float p_val, AnchorType p_anchor,float p_range) const { case ANCHOR_END: { return Math::floor(p_range-p_val); } break; - case ANCHOR_RATIO: { - return Math::floor(p_range*p_val); - } break; case ANCHOR_CENTER: { - return Math::floor((p_range/2)-p_val); + return Math::floor((p_range/2)-p_val); } break; } return 0; @@ -2246,25 +2161,17 @@ int Control::get_v_size_flags() const{ return data.v_size_flags; } -void Control::set_ignore_mouse(bool p_ignore) { +void Control::set_mouse_filter(MouseFilter p_filter) { - data.ignore_mouse=p_ignore; + ERR_FAIL_INDEX(p_filter,3); + data.mouse_filter=p_filter; } -bool Control::is_ignoring_mouse() const { +Control::MouseFilter Control::get_mouse_filter() const{ - return data.ignore_mouse; + return data.mouse_filter; } -void Control::set_stop_mouse(bool p_stop) { - - data.stop_mouse=p_stop; -} - -bool Control::is_stopping_mouse() const { - - return data.stop_mouse; -} Control *Control::get_focus_owner() const { @@ -2535,13 +2442,10 @@ void Control::_bind_methods() { ClassDB::bind_method(_MD("set_focus_neighbour","margin","neighbour"),&Control::set_focus_neighbour); ClassDB::bind_method(_MD("get_focus_neighbour","margin"),&Control::get_focus_neighbour); - ClassDB::bind_method(_MD("set_ignore_mouse","ignore"),&Control::set_ignore_mouse); - ClassDB::bind_method(_MD("is_ignoring_mouse"),&Control::is_ignoring_mouse); - ClassDB::bind_method(_MD("force_drag","data","preview"),&Control::force_drag); - ClassDB::bind_method(_MD("set_stop_mouse","stop"),&Control::set_stop_mouse); - ClassDB::bind_method(_MD("is_stopping_mouse"),&Control::is_stopping_mouse); + ClassDB::bind_method(_MD("set_mouse_filter","stop"),&Control::set_mouse_filter); + ClassDB::bind_method(_MD("get_mouse_filter"),&Control::get_mouse_filter); ClassDB::bind_method(_MD("grab_click_focus"),&Control::grab_click_focus); @@ -2565,10 +2469,16 @@ void Control::_bind_methods() { BIND_VMETHOD(MethodInfo("drop_data",PropertyInfo(Variant::VECTOR2,"pos"),PropertyInfo(Variant::NIL,"data"))); ADD_GROUP("Anchor","anchor_"); - ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor_left", PROPERTY_HINT_ENUM, "Begin,End,Ratio,Center"), _SCS("_set_anchor"),_SCS("get_anchor"), MARGIN_LEFT ); - ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor_top", PROPERTY_HINT_ENUM, "Begin,End,Ratio,Center"), _SCS("_set_anchor"),_SCS("get_anchor"), MARGIN_TOP ); - ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor_right", PROPERTY_HINT_ENUM, "Begin,End,Ratio,Center"), _SCS("_set_anchor"),_SCS("get_anchor"), MARGIN_RIGHT ); - ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor_bottom", PROPERTY_HINT_ENUM, "Begin,End,Ratio,Center"), _SCS("_set_anchor"),_SCS("get_anchor"), MARGIN_BOTTOM ); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor_left", PROPERTY_HINT_ENUM, "Begin,End,Center"), _SCS("_set_anchor"),_SCS("get_anchor"), MARGIN_LEFT ); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor_top", PROPERTY_HINT_ENUM, "Begin,End,Center"), _SCS("_set_anchor"),_SCS("get_anchor"), MARGIN_TOP ); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor_right", PROPERTY_HINT_ENUM, "Begin,End,Center"), _SCS("_set_anchor"),_SCS("get_anchor"), MARGIN_RIGHT ); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"anchor_bottom", PROPERTY_HINT_ENUM, "Begin,End,Center"), _SCS("_set_anchor"),_SCS("get_anchor"), MARGIN_BOTTOM ); + + ADD_GROUP("Margin","margin_"); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"margin_left", PROPERTY_HINT_RANGE, "-4096,4096"), _SCS("set_margin"),_SCS("get_margin"),MARGIN_LEFT ); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"margin_top", PROPERTY_HINT_RANGE, "-4096,4096"), _SCS("set_margin"),_SCS("get_margin"),MARGIN_TOP ); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"margin_right", PROPERTY_HINT_RANGE, "-4096,4096"), _SCS("set_margin"),_SCS("get_margin"),MARGIN_RIGHT ); + ADD_PROPERTYINZ( PropertyInfo(Variant::INT,"margin_bottom", PROPERTY_HINT_RANGE, "-4096,4096"), _SCS("set_margin"),_SCS("get_margin"),MARGIN_BOTTOM ); ADD_GROUP("Rect","rect_"); ADD_PROPERTYNZ( PropertyInfo(Variant::VECTOR2,"rect_pos", PROPERTY_HINT_NONE, "",PROPERTY_USAGE_EDITOR), _SCS("set_pos"),_SCS("get_pos") ); @@ -2577,20 +2487,22 @@ void Control::_bind_methods() { ADD_PROPERTYNZ( PropertyInfo(Variant::REAL,"rect_rotation",PROPERTY_HINT_RANGE,"-1080,1080,0.01"), _SCS("set_rotation_deg"),_SCS("get_rotation_deg") ); ADD_PROPERTYNO( PropertyInfo(Variant::VECTOR2,"rect_scale"), _SCS("set_scale"),_SCS("get_scale") ); + ADD_GROUP("Hint","hint_"); ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"hint_tooltip", PROPERTY_HINT_MULTILINE_TEXT), _SCS("set_tooltip"),_SCS("_get_tooltip") ); ADD_GROUP("Focus","focus_"); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"focus_ignore_mouse"), _SCS("set_ignore_mouse"),_SCS("is_ignoring_mouse") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"focus_stop_mouse"), _SCS("set_stop_mouse"),_SCS("is_stopping_mouse") ); ADD_PROPERTYINZ( PropertyInfo(Variant::NODE_PATH,"focus_neighbour_left" ), _SCS("set_focus_neighbour"),_SCS("get_focus_neighbour"),MARGIN_LEFT ); ADD_PROPERTYINZ( PropertyInfo(Variant::NODE_PATH,"focus_neighbour_top" ), _SCS("set_focus_neighbour"),_SCS("get_focus_neighbour"),MARGIN_TOP ); ADD_PROPERTYINZ( PropertyInfo(Variant::NODE_PATH,"focus_neighbour_right" ), _SCS("set_focus_neighbour"),_SCS("get_focus_neighbour"),MARGIN_RIGHT ); ADD_PROPERTYINZ( PropertyInfo(Variant::NODE_PATH,"focus_neighbour_bottom" ), _SCS("set_focus_neighbour"),_SCS("get_focus_neighbour"),MARGIN_BOTTOM ); + ADD_GROUP("Mouse","mouse_"); + ADD_PROPERTY( PropertyInfo(Variant::INT,"mouse_filter",PROPERTY_HINT_ENUM,"Stop,Pass,Ignore"), _SCS("set_mouse_filter"),_SCS("get_mouse_filter") ); + ADD_GROUP("Size Flags","size_flags_"); - ADD_PROPERTY( PropertyInfo(Variant::INT,"size_flags_horizontal", PROPERTY_HINT_FLAGS, "Expand,Fill"), _SCS("set_h_size_flags"),_SCS("get_h_size_flags") ); - ADD_PROPERTY( PropertyInfo(Variant::INT,"size_flags_vertical", PROPERTY_HINT_FLAGS, "Expand,Fill"), _SCS("set_v_size_flags"),_SCS("get_v_size_flags") ); + ADD_PROPERTYNO( PropertyInfo(Variant::INT,"size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand"), _SCS("set_h_size_flags"),_SCS("get_h_size_flags") ); + ADD_PROPERTYNO( PropertyInfo(Variant::INT,"size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand"), _SCS("set_v_size_flags"),_SCS("get_v_size_flags") ); ADD_PROPERTYNO( PropertyInfo(Variant::INT,"size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "1,128,0.01"), _SCS("set_stretch_ratio"),_SCS("get_stretch_ratio") ); ADD_GROUP("Theme",""); ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), _SCS("set_theme"),_SCS("get_theme") ); @@ -2598,7 +2510,6 @@ void Control::_bind_methods() { BIND_CONSTANT( ANCHOR_BEGIN ); BIND_CONSTANT( ANCHOR_END ); - BIND_CONSTANT( ANCHOR_RATIO ); BIND_CONSTANT( ANCHOR_CENTER ); BIND_CONSTANT( FOCUS_NONE ); BIND_CONSTANT( FOCUS_CLICK ); @@ -2635,6 +2546,10 @@ void Control::_bind_methods() { BIND_CONSTANT( SIZE_FILL ); BIND_CONSTANT( SIZE_EXPAND_FILL ); + BIND_CONSTANT( MOUSE_FILTER_STOP ); + BIND_CONSTANT( MOUSE_FILTER_PASS ); + BIND_CONSTANT( MOUSE_FILTER_IGNORE ); + ADD_SIGNAL( MethodInfo("resized") ); ADD_SIGNAL( MethodInfo("gui_input",PropertyInfo(Variant::INPUT_EVENT,"ev")) ); ADD_SIGNAL( MethodInfo("mouse_enter") ); @@ -2651,9 +2566,7 @@ Control::Control() { data.parent=NULL; - data.ignore_mouse=false; - data.stop_mouse=true; - + data.mouse_filter=MOUSE_FILTER_STOP; data.SI=NULL; data.MI=NULL; diff --git a/scene/gui/control.h b/scene/gui/control.h index 7295c393a5..b67e5980c5 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -54,7 +54,6 @@ public: enum AnchorType { ANCHOR_BEGIN, ANCHOR_END, - ANCHOR_RATIO, ANCHOR_CENTER, }; @@ -66,12 +65,18 @@ public: enum SizeFlags { - SIZE_EXPAND=1, - SIZE_FILL=2, + SIZE_FILL=1, + SIZE_EXPAND=2, SIZE_EXPAND_FILL=SIZE_EXPAND|SIZE_FILL }; + enum MouseFilter { + MOUSE_FILTER_STOP, + MOUSE_FILTER_PASS, + MOUSE_FILTER_IGNORE + }; + enum CursorShape { CURSOR_ARROW, CURSOR_IBEAM, @@ -125,8 +130,7 @@ private: bool pending_min_size_update; Point2 custom_minimum_size; - bool ignore_mouse; - bool stop_mouse; + MouseFilter mouse_filter; bool block_minimum_size_adjust; bool disable_visibility_clip; @@ -338,11 +342,8 @@ public: Control *get_focus_owner() const; - void set_ignore_mouse(bool p_ignore); - bool is_ignoring_mouse() const; - - void set_stop_mouse(bool p_stop); - bool is_stopping_mouse() const; + void set_mouse_filter(MouseFilter p_filter); + MouseFilter get_mouse_filter() const; /* SKINNING */ @@ -418,5 +419,6 @@ VARIANT_ENUM_CAST(Control::AnchorType); VARIANT_ENUM_CAST(Control::FocusMode); VARIANT_ENUM_CAST(Control::SizeFlags); VARIANT_ENUM_CAST(Control::CursorShape); +VARIANT_ENUM_CAST(Control::MouseFilter); #endif diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 25260ec608..d3f2ad7e13 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -256,7 +256,7 @@ void GraphEdit::add_child_notify(Node *p_child) { gn->connect("raise_request",this,"_graph_node_raised",varray(gn)); gn->connect("item_rect_changed",connections_layer,"update"); _graph_node_moved(gn); - gn->set_stop_mouse(false); + gn->set_mouse_filter(MOUSE_FILTER_PASS); } @@ -1262,10 +1262,10 @@ GraphEdit::GraphEdit() { top_layer=NULL; top_layer=memnew(GraphEditFilter(this)); add_child(top_layer); - top_layer->set_stop_mouse(false); + top_layer->set_mouse_filter(MOUSE_FILTER_PASS); top_layer->set_area_as_parent_rect(); top_layer->connect("draw",this,"_top_layer_draw"); - top_layer->set_stop_mouse(false); + top_layer->set_mouse_filter(MOUSE_FILTER_PASS); top_layer->connect("input_event",this,"_top_layer_input"); connections_layer = memnew( Control ); diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 4d658deab4..8b7b84910d 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -787,7 +787,7 @@ GraphNode::GraphNode() { overlay=OVERLAY_DISABLED; show_close=false; connpos_dirty=true; - set_stop_mouse(false); + set_mouse_filter(MOUSE_FILTER_PASS); modulate=Color(1,1,1,1); comment=false; resizeable=false; diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index 13cb972a19..7dffaa2fd5 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -230,6 +230,6 @@ Size2 GridContainer::get_minimum_size() const { GridContainer::GridContainer() { - set_stop_mouse(false); + set_mouse_filter(MOUSE_FILTER_PASS); columns=1; } diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 03a0219e98..3d350b2230 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -699,7 +699,7 @@ Label::Label(const String &p_text) { line_count=0; set_v_size_flags(0); clip=false; - set_ignore_mouse(true); + set_mouse_filter(MOUSE_FILTER_IGNORE); total_char_cache=0; visible_chars=-1; percent_visible=1; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 30c04608ef..e75785b1ff 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1341,7 +1341,7 @@ LineEdit::LineEdit() { set_focus_mode( FOCUS_ALL ); editable=true; set_default_cursor_shape(CURSOR_IBEAM); - set_stop_mouse(true); + set_mouse_filter(MOUSE_FILTER_STOP); draw_caret=true; caret_blink_enabled=false; diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index 68d01ccb6e..c4b7199c3e 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -41,7 +41,7 @@ void Panel::_notification(int p_what) { Panel::Panel() { - set_stop_mouse(true); + set_mouse_filter(MOUSE_FILTER_STOP); } diff --git a/scene/gui/patch_9_frame.cpp b/scene/gui/patch_9_frame.cpp index 5bcc6eb3e9..e32f60a222 100644 --- a/scene/gui/patch_9_frame.cpp +++ b/scene/gui/patch_9_frame.cpp @@ -174,7 +174,7 @@ Patch9Frame::Patch9Frame() { margin[MARGIN_BOTTOM]=0; margin[MARGIN_TOP]=0; - set_ignore_mouse(true); + set_mouse_filter(MOUSE_FILTER_IGNORE); draw_center=true; } diff --git a/scene/gui/texture_frame.cpp b/scene/gui/texture_frame.cpp index b0940df1f6..bfa72ef067 100644 --- a/scene/gui/texture_frame.cpp +++ b/scene/gui/texture_frame.cpp @@ -158,7 +158,7 @@ TextureFrame::TextureFrame() { expand=false; - set_ignore_mouse(true); + set_mouse_filter(MOUSE_FILTER_IGNORE); stretch_mode=STRETCH_SCALE_ON_EXPAND; } diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index ba22320a22..16175e9f4b 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -3711,7 +3711,7 @@ Tree::Tree() { blocked=0; cursor_can_exit_tree=true; - set_stop_mouse(true); + set_mouse_filter(MOUSE_FILTER_STOP); drag_speed=0; drag_touching=false; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 4c7114d093..8d8e41812b 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1615,7 +1615,7 @@ void Viewport::_gui_call_input(Control *p_control,const InputEvent& p_input) { break; if (gui.key_event_accepted) break; - if (!cant_stop_me_now && control->data.stop_mouse && (ev.type==InputEvent::MOUSE_BUTTON || ev.type==InputEvent::MOUSE_MOTION)) + if (!cant_stop_me_now && control->data.mouse_filter==Control::MOUSE_FILTER_STOP && (ev.type==InputEvent::MOUSE_BUTTON || ev.type==InputEvent::MOUSE_MOTION)) break; } @@ -1724,7 +1724,7 @@ Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_g matrix.affine_invert(); //conditions for considering this as a valid control for return - if (!c->data.ignore_mouse && c->has_point(matrix.xform(p_global)) && (!gui.drag_preview || (c!=gui.drag_preview && !gui.drag_preview->is_a_parent_of(c)))) { + if (c->data.mouse_filter!=Control::MOUSE_FILTER_IGNORE && c->has_point(matrix.xform(p_global)) && (!gui.drag_preview || (c!=gui.drag_preview && !gui.drag_preview->is_a_parent_of(c)))) { r_inv_xform=matrix; return c; } else diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 76c6f29bcb..c962e1a671 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -72,6 +72,8 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) { track_set_path(track,p_value); else if (what=="interp") track_set_interpolation_type(track,InterpolationType(p_value.operator int())); + else if (what=="loop_wrap") + track_set_interpolation_loop_wrap(track,p_value); else if (what=="imported") track_set_imported(track,p_value); else if (what == "keys" || what=="key_values") { @@ -291,6 +293,8 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const { r_ret=track_get_path(track); else if (what=="interp") r_ret = track_get_interpolation_type(track); + else if (what=="loop_wrap") + r_ret = track_get_interpolation_loop_wrap(track); else if (what=="imported") r_ret = track_is_imported(track); else if (what=="keys") { @@ -440,6 +444,7 @@ void Animation::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::STRING, "tracks/"+itos(i)+"/type", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::NODE_PATH, "tracks/"+itos(i)+"/path", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::INT, "tracks/"+itos(i)+"/interp", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); + p_list->push_back( PropertyInfo( Variant::BOOL, "tracks/"+itos(i)+"/loop_wrap", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::BOOL, "tracks/"+itos(i)+"/imported", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::ARRAY, "tracks/"+itos(i)+"/keys", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); } @@ -559,6 +564,19 @@ Animation::InterpolationType Animation::track_get_interpolation_type(int p_track return tracks[p_track]->interpolation; } +void Animation::track_set_interpolation_loop_wrap(int p_track,bool p_enable) { + ERR_FAIL_INDEX(p_track, tracks.size()); + tracks[p_track]->loop_wrap=p_enable; + emit_changed(); + +} + +bool Animation::track_get_interpolation_loop_wrap(int p_track) const{ + + ERR_FAIL_INDEX_V(p_track, tracks.size(),INTERPOLATION_NEAREST); + return tracks[p_track]->loop_wrap; + +} // transform /* @@ -1211,7 +1229,7 @@ float Animation::_cubic_interpolate( const float& p_pre_a,const float& p_a, cons } template<class T> -T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, InterpolationType p_interp, bool *p_ok) const { +T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, InterpolationType p_interp, bool p_loop_wrap,bool *p_ok) const { int len=_find( p_keys, length )+1; // try to find last key (there may be more past the end) @@ -1239,7 +1257,7 @@ T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, Inter float c=0; // prepare for all cases of interpolation - if (loop) { + if (loop && p_loop_wrap) { // loop if (idx>=0) { @@ -1363,7 +1381,7 @@ Error Animation::transform_track_interpolate(int p_track, float p_time, Vector3 bool ok; - TransformKey tk = _interpolate( tt->transforms, p_time, tt->interpolation, &ok ); + TransformKey tk = _interpolate( tt->transforms, p_time, tt->interpolation, tt->loop_wrap, &ok ); if (!ok) // ?? return ERR_UNAVAILABLE; @@ -1391,7 +1409,7 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const { bool ok; - Variant res = _interpolate( vt->values, p_time, vt->update_mode==UPDATE_CONTINUOUS?vt->interpolation:INTERPOLATION_NEAREST, &ok ); + Variant res = _interpolate( vt->values, p_time, vt->update_mode==UPDATE_CONTINUOUS?vt->interpolation:INTERPOLATION_NEAREST,vt->loop_wrap, &ok ); if (ok) { @@ -1711,6 +1729,8 @@ void Animation::_bind_methods() { ClassDB::bind_method(_MD("track_set_interpolation_type","idx","interpolation"),&Animation::track_set_interpolation_type); ClassDB::bind_method(_MD("track_get_interpolation_type","idx"),&Animation::track_get_interpolation_type); + ClassDB::bind_method(_MD("track_set_interpolation_loop_wrap","idx","interpolation"),&Animation::track_set_interpolation_loop_wrap); + ClassDB::bind_method(_MD("track_get_interpolation_loop_wrap","idx"),&Animation::track_get_interpolation_loop_wrap); ClassDB::bind_method(_MD("transform_track_interpolate","idx","time_sec"),&Animation::_transform_track_interpolate); diff --git a/scene/resources/animation.h b/scene/resources/animation.h index c236b3ef37..b81ac4f1bf 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -39,12 +39,7 @@ class Animation : public Resource { RES_BASE_EXTENSION("anm"); public: - enum LoopMode { - LOOP_NONE, - LOOP_ENABLED, - LOOP_WRAP - }; enum TrackType { TYPE_VALUE, ///< Set a value in a property, can be interpolated. @@ -71,9 +66,10 @@ private: TrackType type; InterpolationType interpolation; + bool loop_wrap; NodePath path; // path to something bool imported; - Track() { interpolation=INTERPOLATION_LINEAR; imported=false;} + Track() { interpolation=INTERPOLATION_LINEAR; imported=false; loop_wrap=true;} virtual ~Track() {} }; @@ -164,7 +160,7 @@ private: _FORCE_INLINE_ float _cubic_interpolate( const float& p_pre_a,const float& p_a, const float& p_b, const float& p_post_b, float p_c) const; template<class T> - _FORCE_INLINE_ T _interpolate( const Vector< TKey<T> >& p_keys, float p_time, InterpolationType p_interp,bool *p_ok) const; + _FORCE_INLINE_ T _interpolate( const Vector< TKey<T> >& p_keys, float p_time, InterpolationType p_interp,bool p_loop_wrap,bool *p_ok) const; _FORCE_INLINE_ void _value_track_get_key_indices_in_range(const ValueTrack * vt, float from_time, float to_time,List<int> *p_indices) const; _FORCE_INLINE_ void _method_track_get_key_indices_in_range(const MethodTrack * mt, float from_time, float to_time,List<int> *p_indices) const; @@ -260,6 +256,8 @@ public: void track_set_interpolation_type(int p_track,InterpolationType p_interp); InterpolationType track_get_interpolation_type(int p_track) const; + void track_set_interpolation_loop_wrap(int p_track,bool p_enable); + bool track_get_interpolation_loop_wrap(int p_track) const; Error transform_track_interpolate(int p_track, float p_time, Vector3 * r_loc, Quat *r_rot, Vector3 *r_scale) const; diff --git a/tools/editor/animation_editor.cpp b/tools/editor/animation_editor.cpp index 54ef21e681..e08091f7c0 100644 --- a/tools/editor/animation_editor.cpp +++ b/tools/editor/animation_editor.cpp @@ -1157,6 +1157,12 @@ void AnimationKeyEditor::_track_editor_draw() { Ref<Texture> add_key_icon = get_icon("TrackAddKey","EditorIcons"); Ref<Texture> add_key_icon_hl = get_icon("TrackAddKeyHl","EditorIcons"); Ref<Texture> down_icon = get_icon("select_arrow","Tree"); + + Ref<Texture> wrap_icon[2]={ + get_icon("InterpWrapClamp","EditorIcons"), + get_icon("InterpWrapLoop","EditorIcons"), + }; + Ref<Texture> interp_icon[3]={ get_icon("InterpRaw","EditorIcons"), get_icon("InterpLinear","EditorIcons"), @@ -1181,7 +1187,7 @@ void AnimationKeyEditor::_track_editor_draw() { Ref<Texture> type_hover=get_icon("KeyHover","EditorIcons"); Ref<Texture> type_selected=get_icon("KeySelected","EditorIcons"); - int right_separator_ofs = down_icon->get_width() *2 + add_key_icon->get_width() + interp_icon[0]->get_width() + cont_icon[0]->get_width() + hsep*7; + int right_separator_ofs = down_icon->get_width() *3 + add_key_icon->get_width() + interp_icon[0]->get_width() + wrap_icon[0]->get_width() + cont_icon[0]->get_width() + hsep*9; int h = font->get_height()+sep; @@ -1421,6 +1427,20 @@ void AnimationKeyEditor::_track_editor_draw() { icon_ofs.x-=hsep; */ + track_ofs[0]=size.width-icon_ofs.x; + icon_ofs.x-=down_icon->get_width(); + te->draw_texture(down_icon,icon_ofs); + + int wrap_type = animation->track_get_interpolation_loop_wrap(idx)?1:0; + icon_ofs.x-=hsep; + icon_ofs.x-=wrap_icon[wrap_type]->get_width(); + te->draw_texture(wrap_icon[wrap_type],icon_ofs); + + icon_ofs.x-=hsep; + te->draw_line(Point2(icon_ofs.x,ofs.y+y),Point2(icon_ofs.x,ofs.y+y+h),sepcolor); + + track_ofs[1]=size.width-icon_ofs.x; + icon_ofs.x-=down_icon->get_width(); te->draw_texture(down_icon,icon_ofs); @@ -1433,6 +1453,8 @@ void AnimationKeyEditor::_track_editor_draw() { icon_ofs.x-=hsep; te->draw_line(Point2(icon_ofs.x,ofs.y+y),Point2(icon_ofs.x,ofs.y+y+h),sepcolor); + track_ofs[2]=size.width-icon_ofs.x; + if (animation->track_get_type(idx)==Animation::TYPE_VALUE) { @@ -1453,10 +1475,14 @@ void AnimationKeyEditor::_track_editor_draw() { icon_ofs.x-=hsep; te->draw_line(Point2(icon_ofs.x,ofs.y+y),Point2(icon_ofs.x,ofs.y+y+h),sepcolor); + track_ofs[3]=size.width-icon_ofs.x; + icon_ofs.x-=hsep; icon_ofs.x-=add_key_icon->get_width(); te->draw_texture((mouse_over.over==MouseOver::OVER_ADD_KEY && mouse_over.track==idx)?add_key_icon_hl:add_key_icon,icon_ofs); + track_ofs[4]=size.width-icon_ofs.x; + //draw the keys; int tt = animation->track_get_type(idx); float key_vofs = Math::floor((h - type_icon[tt]->get_height())/2); @@ -1621,6 +1647,14 @@ void AnimationKeyEditor::_track_menu_selected(int p_idx) { undo_redo->add_do_method(animation.ptr(),"value_track_set_update_mode",cont_editing,p_idx); undo_redo->add_undo_method(animation.ptr(),"value_track_set_update_mode",cont_editing,animation->value_track_get_update_mode(cont_editing)); undo_redo->commit_action(); + } else if (wrap_editing!=-1) { + + ERR_FAIL_INDEX(wrap_editing,animation->get_track_count()); + + undo_redo->create_action(TTR("Anim Track Change Wrap Mode")); + undo_redo->add_do_method(animation.ptr(),"track_set_interpolation_loop_wrap",wrap_editing,p_idx?true:false); + undo_redo->add_undo_method(animation.ptr(),"track_set_interpolation_loop_wrap",wrap_editing,animation->track_get_interpolation_loop_wrap(wrap_editing)); + undo_redo->commit_action(); } else { switch (p_idx) { @@ -1833,6 +1867,10 @@ void AnimationKeyEditor::_track_editor_gui_input(const InputEvent& p_input) { Ref<Texture> hsize_icon = get_icon("Hsize","EditorIcons"); Ref<Texture> add_key_icon = get_icon("TrackAddKey","EditorIcons"); + Ref<Texture> wrap_icon[2]={ + get_icon("InterpWrapClamp","EditorIcons"), + get_icon("InterpWrapLoop","EditorIcons"), + }; Ref<Texture> interp_icon[3]={ get_icon("InterpRaw","EditorIcons"), get_icon("InterpLinear","EditorIcons"), @@ -1848,7 +1886,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const InputEvent& p_input) { get_icon("KeyXform","EditorIcons"), get_icon("KeyCall","EditorIcons") }; - int right_separator_ofs = down_icon->get_width() *2 + add_key_icon->get_width() + interp_icon[0]->get_width() + cont_icon[0]->get_width() + hsep*7; + int right_separator_ofs = down_icon->get_width() *3 + add_key_icon->get_width() + interp_icon[0]->get_width() + wrap_icon[0]->get_width() + cont_icon[0]->get_width() + hsep*9; int h = font->get_height()+sep; @@ -2054,6 +2092,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const InputEvent& p_input) { interp_editing=-1; cont_editing=-1; + wrap_editing=-1; track_menu->popup(); } @@ -2277,7 +2316,33 @@ void AnimationKeyEditor::_track_editor_gui_input(const InputEvent& p_input) { ofsx-=hsep*3+move_up_icon->get_width(); */ - if (ofsx < down_icon->get_width() + interp_icon[0]->get_width() + hsep*2) { + + if (ofsx < track_ofs[1]) { + + track_menu->clear(); + track_menu->set_size(Point2(1,1)); + static const char *interp_name[2]={"Clamp Loop Interp","Wrap Loop Interp"}; + for(int i=0;i<2;i++) { + track_menu->add_icon_item(wrap_icon[i],interp_name[i]); + } + + int popup_y = ofs.y+((int(mpos.y)/h)+2)*h; + int popup_x = size.width-track_ofs[1]; + + track_menu->set_pos(te->get_global_pos()+Point2(popup_x,popup_y)); + + + wrap_editing=idx; + interp_editing=-1; + cont_editing=-1; + + track_menu->popup(); + + return; + } + + + if (ofsx < track_ofs[2]) { track_menu->clear(); track_menu->set_size(Point2(1,1)); @@ -2286,24 +2351,22 @@ void AnimationKeyEditor::_track_editor_gui_input(const InputEvent& p_input) { track_menu->add_icon_item(interp_icon[i],interp_name[i]); } - int lofs = remove_icon->get_width() + move_up_icon->get_width() + move_down_icon->get_width() + down_icon->get_width() *2 + hsep*7;//interp_icon[0]->get_width() + cont_icon[0]->get_width() ; int popup_y = ofs.y+((int(mpos.y)/h)+2)*h; - int popup_x = ofs.x+size.width-lofs; + int popup_x = size.width-track_ofs[2]; track_menu->set_pos(te->get_global_pos()+Point2(popup_x,popup_y)); interp_editing=idx; cont_editing=-1; + wrap_editing=-1; track_menu->popup(); return; } - ofsx-=hsep*2+interp_icon[0]->get_width()+down_icon->get_width(); - - if (ofsx < down_icon->get_width() + cont_icon[0]->get_width()) { + if (ofsx < track_ofs[3]) { track_menu->clear(); track_menu->set_size(Point2(1,1)); @@ -2312,13 +2375,14 @@ void AnimationKeyEditor::_track_editor_gui_input(const InputEvent& p_input) { track_menu->add_icon_item(cont_icon[i],cont_name[i]); } - int lofs = settings_limit; + int popup_y = ofs.y+((int(mpos.y)/h)+2)*h; - int popup_x = ofs.x+lofs; + int popup_x = size.width-track_ofs[3]; track_menu->set_pos(te->get_global_pos()+Point2(popup_x,popup_y)); interp_editing=-1; + wrap_editing=-1; cont_editing=idx; track_menu->popup(); @@ -2326,9 +2390,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const InputEvent& p_input) { return; } - ofsx-=hsep*3+cont_icon[0]->get_width()+down_icon->get_width(); - - if (ofsx < add_key_icon->get_width()) { + if (ofsx < track_ofs[4]) { Animation::TrackType tt = animation->track_get_type(idx); @@ -2940,7 +3002,15 @@ void AnimationKeyEditor::_track_editor_gui_input(const InputEvent& p_input) { */ - if (ofsx < down_icon->get_width() + interp_icon[0]->get_width() + hsep*2) { + if (ofsx < down_icon->get_width() + wrap_icon[0]->get_width() + hsep*3) { + + mouse_over.over=MouseOver::OVER_WRAP; + return; + } + + ofsx-=hsep*3+wrap_icon[0]->get_width() + down_icon->get_width(); + + if (ofsx < down_icon->get_width() + interp_icon[0]->get_width() + hsep*3) { mouse_over.over=MouseOver::OVER_INTERP; return; @@ -3068,8 +3138,13 @@ void AnimationKeyEditor::_notification(int p_what) { get_icon("TrackTrigger","EditorIcons") }; + Ref<Texture> wrap_icon[2]={ + get_icon("InterpWrapClamp","EditorIcons"), + get_icon("InterpWrapLoop","EditorIcons"), + }; + //right_data_size_cache = remove_icon->get_width() + move_up_icon->get_width() + move_down_icon->get_width() + down_icon->get_width() *2 + interp_icon[0]->get_width() + cont_icon[0]->get_width() + add_key_icon->get_width() + hsep*11; - right_data_size_cache = down_icon->get_width() *2 + add_key_icon->get_width() + interp_icon[0]->get_width() + cont_icon[0]->get_width() + hsep*7; + right_data_size_cache = down_icon->get_width() *3 + add_key_icon->get_width() + interp_icon[0]->get_width() + cont_icon[0]->get_width() + wrap_icon[0]->get_width() + hsep*8; } @@ -4090,7 +4165,7 @@ AnimationKeyEditor::AnimationKeyEditor() { track_pos = memnew( Control ); track_pos->set_area_as_parent_rect(); - track_pos->set_ignore_mouse(true); + track_pos->set_mouse_filter(MOUSE_FILTER_IGNORE); track_editor->add_child(track_pos); track_pos->connect("draw",this,"_track_pos_draw"); diff --git a/tools/editor/animation_editor.h b/tools/editor/animation_editor.h index 10cc1bf611..0c9b0b5ac6 100644 --- a/tools/editor/animation_editor.h +++ b/tools/editor/animation_editor.h @@ -113,6 +113,7 @@ class AnimationKeyEditor : public VBoxContainer { OVER_KEY, OVER_VALUE, OVER_INTERP, + OVER_WRAP, OVER_UP, OVER_DOWN, OVER_REMOVE, @@ -166,7 +167,9 @@ class AnimationKeyEditor : public VBoxContainer { int track_name_editing; int interp_editing; int cont_editing; + int wrap_editing; int selected_track; + int track_ofs[5]; int last_menu_track_opt; LineEdit *track_name; diff --git a/tools/editor/asset_library_editor_plugin.cpp b/tools/editor/asset_library_editor_plugin.cpp index b4f9337d86..aca4a512fd 100644 --- a/tools/editor/asset_library_editor_plugin.cpp +++ b/tools/editor/asset_library_editor_plugin.cpp @@ -29,7 +29,7 @@ #include "asset_library_editor_plugin.h" #include "editor_node.h" #include "editor_settings.h" - +#include "io/json.h" @@ -157,7 +157,7 @@ EditorAssetLibraryItem::EditorAssetLibraryItem() { set_custom_minimum_size(Size2(250,100)); set_h_size_flags(SIZE_EXPAND_FILL); - set_stop_mouse(false); + set_mouse_filter(MOUSE_FILTER_PASS); } ////////////////////////////////////////////////////////////////////////////// @@ -1076,8 +1076,16 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const } print_line("response: "+itos(p_status)+" code: "+itos(p_code)); + Dictionary d; - d.parse_json(str); + { + Variant js; + String errs; + int errl; + JSON::parse(str,js,errs,errl); + d=js; + } + print_line(Variant(d).get_construct_string()); @@ -1446,7 +1454,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { library_scroll->add_child(library_vb_border); library_vb_border->add_style_override("panel",border2); library_vb_border->set_h_size_flags(SIZE_EXPAND_FILL); - library_vb_border->set_stop_mouse(false); + library_vb_border->set_mouse_filter(MOUSE_FILTER_PASS); diff --git a/tools/editor/call_dialog.cpp b/tools/editor/call_dialog.cpp index 7e8ce1a37a..054a5098f0 100644 --- a/tools/editor/call_dialog.cpp +++ b/tools/editor/call_dialog.cpp @@ -28,6 +28,7 @@ /*************************************************************************/ #include "call_dialog.h" +#if 0 #include "scene/gui/label.h" #include "object_type_db.h" #include "print_string.h" @@ -268,7 +269,6 @@ CallDialog::CallDialog() { tree = memnew( Tree ); - tree->set_anchor( MARGIN_RIGHT, ANCHOR_RATIO ); tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); tree->set_begin( Point2( 20,50 ) ); tree->set_margin(MARGIN_BOTTOM, 44 ); @@ -283,7 +283,7 @@ CallDialog::CallDialog() { property_editor->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, 15 ); property_editor->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 50 ); - property_editor->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 ); +// property_editor->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 ); property_editor->set_anchor_and_margin( MARGIN_BOTTOM, ANCHOR_END, 90 ); property_editor->get_scene_tree()->set_hide_root( true ); property_editor->hide_top_label(); @@ -296,21 +296,21 @@ CallDialog::CallDialog() { add_child(method_label); Label *label = memnew( Label ); - label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 ); + //label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 ); label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 25 ); label->set_text(TTR("Arguments:")); add_child(label); return_label = memnew( Label ); - return_label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 ); + //return_label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 ); return_label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, 85 ); return_label->set_text(TTR("Return:")); add_child(return_label); return_value = memnew( LineEdit ); - return_value->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 ); + //return_value->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 ); return_value->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, 15 ); return_value->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, 65 ); @@ -338,3 +338,4 @@ CallDialog::~CallDialog() { memdelete(call_params); } +#endif diff --git a/tools/editor/call_dialog.h b/tools/editor/call_dialog.h index 928ee74567..b0ebe68d86 100644 --- a/tools/editor/call_dialog.h +++ b/tools/editor/call_dialog.h @@ -39,6 +39,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ +#if 0 class CallDialogParams; @@ -81,3 +82,4 @@ public: }; #endif +#endif diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp index c1be2cd940..1804016f47 100644 --- a/tools/editor/editor_import_export.cpp +++ b/tools/editor/editor_import_export.cpp @@ -783,7 +783,7 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func if (atlas_valid) { //compare options - Dictionary options; + /*Dictionary options; options.parse_json(f->get_line()); if (!options.has("lossy_quality") || float(options["lossy_quality"])!=group_lossy_quality) atlas_valid=false; @@ -794,7 +794,7 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func if (!atlas_valid) print_line("JSON INVALID"); - +*/ } @@ -921,7 +921,7 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func options["lossy_quality"]=group_lossy_quality; options["shrink"]=EditorImportExport::get_singleton()->image_export_group_get_shrink(E->get()); options["image_format"]=group_format; - f->store_line(options.to_json()); +// f->store_line(options.to_json()); f->store_line(image_list_md5); } diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 72a8473945..5eb5f42001 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -2638,12 +2638,6 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { _set_editing_top_editors(current); } break; - case OBJECT_CALL_METHOD: { - - editor_data.apply_changes_in_editors();; - call_dialog->set_object(current); - call_dialog->popup_centered_ratio(); - } break; case RUN_PLAY: { _menu_option_confirm(RUN_STOP,true); _call_build(); @@ -5879,7 +5873,7 @@ EditorNode::EditorNode() { play_cc = memnew( CenterContainer ); - play_cc->set_ignore_mouse(true); + play_cc->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); gui_base->add_child( play_cc ); play_cc->set_area_as_parent_rect(); play_cc->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,10); @@ -6346,9 +6340,7 @@ EditorNode::EditorNode() { - call_dialog = memnew( CallDialog ); - call_dialog->hide(); - gui_base->add_child( call_dialog ); + diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h index 90162e0082..fcfd5ca389 100644 --- a/tools/editor/editor_node.h +++ b/tools/editor/editor_node.h @@ -159,7 +159,6 @@ private: OBJECT_COPY_PARAMS, OBJECT_PASTE_PARAMS, OBJECT_UNIQUE_RESOURCES, - OBJECT_CALL_METHOD, OBJECT_REQUEST_HELP, RUN_PLAY, @@ -287,7 +286,7 @@ private: CreateDialog *create_dialog; - CallDialog *call_dialog; +// CallDialog *call_dialog; ConfirmationDialog *confirmation; ConfirmationDialog *import_confirmation; ConfirmationDialog *open_recent_confirmation; diff --git a/tools/editor/editor_profiler.cpp b/tools/editor/editor_profiler.cpp index 54b9de7622..162e1d05f5 100644 --- a/tools/editor/editor_profiler.cpp +++ b/tools/editor/editor_profiler.cpp @@ -710,8 +710,8 @@ EditorProfiler::EditorProfiler() graph = memnew( TextureFrame ); graph->set_expand(true); - graph->set_stop_mouse(true); - graph->set_ignore_mouse(false); + graph->set_mouse_filter(MOUSE_FILTER_STOP); + //graph->set_ignore_mouse(false); graph->connect("draw",this,"_graph_tex_draw"); graph->connect("gui_input",this,"_graph_tex_input"); graph->connect("mouse_exit",this,"_graph_tex_mouse_exit"); diff --git a/tools/editor/icons/icon_interp_wrap_clamp.png b/tools/editor/icons/icon_interp_wrap_clamp.png Binary files differnew file mode 100644 index 0000000000..3026b19d97 --- /dev/null +++ b/tools/editor/icons/icon_interp_wrap_clamp.png diff --git a/tools/editor/icons/icon_interp_wrap_loop.png b/tools/editor/icons/icon_interp_wrap_loop.png Binary files differnew file mode 100644 index 0000000000..64beb6c670 --- /dev/null +++ b/tools/editor/icons/icon_interp_wrap_loop.png diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index fa702fc9bb..3ba405cdbd 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -2320,7 +2320,7 @@ void ShaderGraphView::_create_node(int p_id) { tex->set_custom_minimum_size(Size2(80,80)); tex->set_drag_forwarding(this); gn->add_child(tex); - tex->set_ignore_mouse(false); + tex->set_mouse_filter(MOUSE_FILTER_PASS); tex->set_texture(graph->texture_input_node_get_value(type,p_id)); ToolButton *edit = memnew( ToolButton ); edit->set_text("edit.."); diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index ef2ea13729..2897723f29 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -2963,9 +2963,9 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } viewports[0]->set_area_as_parent_rect(); - viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); + //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); viewports[2]->set_area_as_parent_rect(); - viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), true ); @@ -2987,9 +2987,9 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } viewports[0]->set_area_as_parent_rect(); - viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); + //viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); viewports[2]->set_area_as_parent_rect(); - viewports[2]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); + //viewports[2]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false ); @@ -3009,13 +3009,13 @@ void SpatialEditor::_menu_item_pressed(int p_option) { viewports[i]->show(); } viewports[0]->set_area_as_parent_rect(); - viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); + //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); viewports[2]->set_area_as_parent_rect(); - viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + //viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); + //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); viewports[3]->set_area_as_parent_rect(); - viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); - viewports[3]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); + //viewports[3]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false ); @@ -3035,13 +3035,13 @@ void SpatialEditor::_menu_item_pressed(int p_option) { viewports[i]->show(); } viewports[0]->set_area_as_parent_rect(); - viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); - viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); + //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); + //viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); viewports[2]->set_area_as_parent_rect(); - viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); - viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); + //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + //viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); viewports[3]->set_area_as_parent_rect(); - viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); + //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false ); @@ -3058,17 +3058,17 @@ void SpatialEditor::_menu_item_pressed(int p_option) { viewports[i]->show(); } viewports[0]->set_area_as_parent_rect(); - viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); + //viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); + //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); viewports[1]->set_area_as_parent_rect(); - viewports[1]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); - viewports[1]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); + //viewports[1]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); + //viewports[1]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); viewports[2]->set_area_as_parent_rect(); - viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + //viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); + //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); viewports[3]->set_area_as_parent_rect(); - viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); - viewports[3]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); + //viewports[3]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false ); |