summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/io/file_access_memory.cpp42
-rw-r--r--core/io/resource_format_xml.cpp3
-rw-r--r--core/io/resource_loader.cpp44
-rw-r--r--core/method_bind.h2
-rw-r--r--core/ustring.cpp11
-rw-r--r--core/variant.cpp256
-rw-r--r--core/variant.h3
7 files changed, 323 insertions, 38 deletions
diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp
index 749f7d1641..2880c4ebda 100644
--- a/core/io/file_access_memory.cpp
+++ b/core/io/file_access_memory.cpp
@@ -39,7 +39,7 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) {
if (!files) {
files = memnew((Map<String, Vector<uint8_t> >));
- };
+ }
String name;
if (Globals::get_singleton())
@@ -49,7 +49,7 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) {
name = DirAccess::normalize_path(name);
(*files)[name] = p_data;
-};
+}
void FileAccessMemory::cleanup() {
@@ -57,13 +57,13 @@ void FileAccessMemory::cleanup() {
return;
memdelete(files);
-};
+}
FileAccess* FileAccessMemory::create() {
return memnew(FileAccessMemory);
-};
+}
bool FileAccessMemory::file_exists(const String& p_name) {
@@ -71,7 +71,7 @@ bool FileAccessMemory::file_exists(const String& p_name) {
name = DirAccess::normalize_path(name);
return files && (files->find(name) != NULL);
-};
+}
Error FileAccessMemory::_open(const String& p_path, int p_mode_flags) {
@@ -89,57 +89,57 @@ Error FileAccessMemory::_open(const String& p_path, int p_mode_flags) {
pos = 0;
return OK;
-};
+}
void FileAccessMemory::close() {
data = NULL;
-};
+}
bool FileAccessMemory::is_open() const {
return data != NULL;
-};
+}
void FileAccessMemory::seek(size_t p_position) {
ERR_FAIL_COND(!data);
pos = p_position;
-};
+}
void FileAccessMemory::seek_end(int64_t p_position) {
ERR_FAIL_COND(!data);
pos = length + p_position;
-};
+}
size_t FileAccessMemory::get_pos() const {
ERR_FAIL_COND_V(!data, 0);
return pos;
-};
+}
size_t FileAccessMemory::get_len() const {
ERR_FAIL_COND_V(!data, 0);
return length;
-};
+}
bool FileAccessMemory::eof_reached() const {
return pos >= length;
-};
+}
uint8_t FileAccessMemory::get_8() const {
- uint8_t ret;
+ uint8_t ret = 0;
if (pos < length) {
ret = data[pos];
- };
+ }
++pos;
return ret;
-};
+}
int FileAccessMemory::get_buffer(uint8_t *p_dst,int p_length) const {
@@ -156,19 +156,19 @@ int FileAccessMemory::get_buffer(uint8_t *p_dst,int p_length) const {
pos += p_length;
return read;
-};
+}
Error FileAccessMemory::get_error() const {
return pos >= length ? ERR_FILE_EOF : OK;
-};
+}
void FileAccessMemory::store_8(uint8_t p_byte) {
ERR_FAIL_COND(!data);
ERR_FAIL_COND(pos >= length);
data[pos++] = p_byte;
-};
+}
void FileAccessMemory::store_buffer(const uint8_t *p_src,int p_length) {
@@ -176,11 +176,11 @@ void FileAccessMemory::store_buffer(const uint8_t *p_src,int p_length) {
int write = MIN(p_length, left);
if (write < p_length) {
WARN_PRINT("Writing less data than requested");
- };
+ }
copymem(&data[pos], p_src, write);
pos += p_length;
-};
+}
FileAccessMemory::FileAccessMemory() {
diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp
index 5922d83907..9de33e7ef3 100644
--- a/core/io/resource_format_xml.cpp
+++ b/core/io/resource_format_xml.cpp
@@ -309,6 +309,7 @@ Error ResourceInteractiveLoaderXML::_parse_array_element(Vector<char> &buff,bool
buff_max++;
buff.resize(buff_max);
+ buffptr=buff.ptr();
}
@@ -2563,7 +2564,7 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res
List<PropertyInfo> property_list;
res->get_property_list(&property_list);
- property_list.sort();
+// property_list.sort();
for(List<PropertyInfo>::Element *PE = property_list.front();PE;PE=PE->next()) {
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 7e441cea1f..03b6c9759b 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -117,6 +117,7 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const Stri
RES ResourceFormatLoader::load(const String &p_path,const String& p_original_path) {
+ String path=p_path;
//or this must be implemented
Ref<ResourceInteractiveLoader> ril = load_interactive(p_path);
@@ -150,9 +151,13 @@ void ResourceFormatLoader::get_dependencies(const String& p_path,List<String> *p
RES ResourceLoader::load(const String &p_path,const String& p_type_hint,bool p_no_cache) {
- String local_path = Globals::get_singleton()->localize_path(p_path);
+ String local_path;
+ if (p_path.is_rel_path())
+ local_path="res://"+p_path;
+ else
+ local_path = Globals::get_singleton()->localize_path(p_path);
- local_path=find_complete_path(p_path,p_type_hint);
+ local_path=find_complete_path(local_path,p_type_hint);
ERR_FAIL_COND_V(local_path=="",RES());
if (!p_no_cache && ResourceCache::has(local_path)) {
@@ -209,7 +214,11 @@ RES ResourceLoader::load(const String &p_path,const String& p_type_hint,bool p_n
Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p_path) {
- String local_path = Globals::get_singleton()->localize_path(p_path);
+ String local_path;
+ if (p_path.is_rel_path())
+ local_path="res://"+p_path;
+ else
+ local_path = Globals::get_singleton()->localize_path(p_path);
String extension=p_path.extension();
bool found=false;
@@ -283,9 +292,13 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
- String local_path = Globals::get_singleton()->localize_path(p_path);
+ String local_path;
+ if (p_path.is_rel_path())
+ local_path="res://"+p_path;
+ else
+ local_path = Globals::get_singleton()->localize_path(p_path);
- local_path=find_complete_path(p_path,p_type_hint);
+ local_path=find_complete_path(local_path,p_type_hint);
ERR_FAIL_COND_V(local_path=="",Ref<ResourceInteractiveLoader>());
@@ -340,7 +353,13 @@ void ResourceLoader::add_resource_format_loader(ResourceFormatLoader *p_format_l
void ResourceLoader::get_dependencies(const String& p_path,List<String> *p_dependencies) {
- String local_path = Globals::get_singleton()->localize_path(p_path);
+
+ String local_path;
+ if (p_path.is_rel_path())
+ local_path="res://"+p_path;
+ else
+ local_path = Globals::get_singleton()->localize_path(p_path);
+
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
String extension=remapped_path.extension();
@@ -359,7 +378,11 @@ void ResourceLoader::get_dependencies(const String& p_path,List<String> *p_depen
String ResourceLoader::guess_full_filename(const String &p_path,const String& p_type) {
- String local_path = Globals::get_singleton()->localize_path(p_path);
+ String local_path;
+ if (p_path.is_rel_path())
+ local_path="res://"+p_path;
+ else
+ local_path = Globals::get_singleton()->localize_path(p_path);
return find_complete_path(local_path,p_type);
@@ -367,7 +390,12 @@ String ResourceLoader::guess_full_filename(const String &p_path,const String& p_
String ResourceLoader::get_resource_type(const String &p_path) {
- String local_path = Globals::get_singleton()->localize_path(p_path);
+ String local_path;
+ if (p_path.is_rel_path())
+ local_path="res://"+p_path;
+ else
+ local_path = Globals::get_singleton()->localize_path(p_path);
+
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
String extension=remapped_path.extension();
diff --git a/core/method_bind.h b/core/method_bind.h
index d32050cc5d..49c64bd11c 100644
--- a/core/method_bind.h
+++ b/core/method_bind.h
@@ -98,7 +98,7 @@ struct VariantCaster<m_enum> {\
#define CHECK_ARG(m_arg)\
if ((m_arg-1)<p_arg_count) {\
Variant::Type argtype=get_argument_type(m_arg-1);\
- if (!Variant::can_convert(p_args[m_arg-1]->get_type(),argtype)) {\
+ if (!Variant::can_convert_strict(p_args[m_arg-1]->get_type(),argtype)) {\
r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;\
r_error.argument=m_arg-1;\
r_error.expected=argtype;\
diff --git a/core/ustring.cpp b/core/ustring.cpp
index ffd22c1f8f..5df95ac4c2 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -3297,8 +3297,11 @@ String String::path_to_file(const String& p_path) const {
String src=this->replace("\\","/").get_base_dir();
String dst=p_path.replace("\\","/").get_base_dir();
-
- return src.path_to(dst)+p_path.get_file();
+ String rel = src.path_to(dst);
+ if (rel==dst) // failed
+ return p_path;
+ else
+ return rel+p_path.get_file();
}
String String::path_to(const String& p_path) const {
@@ -3333,7 +3336,9 @@ String String::path_to(const String& p_path) const {
String src_begin=src.get_slice("/",0);
String dst_begin=dst.get_slice("/",0);
- ERR_FAIL_COND_V(src_begin!=dst_begin,p_path); //return dst absolute path
+ if (src_begin!=dst_begin)
+ return p_path; //impossible to do this
+
base=src_begin;
src=src.substr(src_begin.length(),src.length());
dst=dst.substr(dst_begin.length(),dst.length());
diff --git a/core/variant.cpp b/core/variant.cpp
index fe6a6b3e4f..d7817ac268 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -258,12 +258,12 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
case MATRIX32: {
- static const Type invalid[]={
+ static const Type valid[]={
TRANSFORM,
NIL
};
- invalid_types=invalid;
+ valid_types=valid;
} break;
case QUAT: {
@@ -302,6 +302,256 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
case COLOR: {
static const Type valid[] = {
+ //STRING,
+ //INT,
+ NIL,
+ };
+
+ valid_types = valid;
+
+ } break;
+
+ case _RID: {
+
+ static const Type valid[]={
+ OBJECT,
+ NIL
+ };
+
+ valid_types=valid;
+ } break;
+ case OBJECT: {
+
+ static const Type valid[]={
+ NIL
+ };
+
+ valid_types=valid;
+ } break;
+ case NODE_PATH: {
+
+ static const Type valid[]={
+ STRING,
+ NIL
+ };
+
+ valid_types=valid;
+ } break;
+ case ARRAY: {
+
+
+ static const Type valid[]={
+ RAW_ARRAY,
+ INT_ARRAY,
+ STRING_ARRAY,
+ REAL_ARRAY,
+ COLOR_ARRAY,
+ VECTOR2_ARRAY,
+ VECTOR3_ARRAY,
+ NIL
+ };
+
+ valid_types=valid;
+ } break;
+ // arrays
+ case RAW_ARRAY: {
+
+ static const Type valid[]={
+ ARRAY,
+ NIL
+ };
+
+ valid_types=valid;
+ } break;
+ case INT_ARRAY: {
+
+ static const Type valid[]={
+ ARRAY,
+ NIL
+ };
+ valid_types=valid;
+ } break;
+ case REAL_ARRAY: {
+
+ static const Type valid[]={
+ ARRAY,
+ NIL
+ };
+
+ valid_types=valid;
+ } break;
+ case STRING_ARRAY: {
+
+ static const Type valid[]={
+ ARRAY,
+ NIL
+ };
+ valid_types=valid;
+ } break;
+ case VECTOR2_ARRAY: {
+
+ static const Type valid[]={
+ ARRAY,
+ NIL
+ };
+ valid_types=valid;
+
+ } break;
+ case VECTOR3_ARRAY: {
+
+ static const Type valid[]={
+ ARRAY,
+ NIL
+ };
+ valid_types=valid;
+
+ } break;
+ case COLOR_ARRAY: {
+
+ static const Type valid[]={
+ ARRAY,
+ NIL
+ };
+
+ valid_types=valid;
+
+ } break;
+ default: {}
+ }
+
+
+ if (valid_types) {
+
+ int i=0;
+ while(valid_types[i]!=NIL) {
+
+ if (p_type_from==valid_types[i])
+ return true;
+ i++;
+ }
+ } else if (invalid_types) {
+
+
+ int i=0;
+ while(invalid_types[i]!=NIL) {
+
+ if (p_type_from==invalid_types[i])
+ return false;
+ i++;
+ }
+ }
+
+ return false;
+
+}
+
+bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_to) {
+
+ if (p_type_from==p_type_to)
+ return true;
+ if (p_type_to==NIL && p_type_from!=NIL) //nil can convert to anything
+ return true;
+
+ if (p_type_from == NIL) {
+ return (p_type_to == OBJECT);
+ };
+
+ const Type *valid_types=NULL;
+ const Type *invalid_types=NULL;
+
+ switch(p_type_to) {
+ case BOOL: {
+
+ static const Type valid[]={
+ INT,
+ REAL,
+ //STRING,
+ NIL,
+ };
+
+ valid_types=valid;
+ } break;
+ case INT: {
+
+ static const Type valid[]={
+ BOOL,
+ REAL,
+ //STRING,
+ NIL,
+ };
+
+ valid_types=valid;
+
+ } break;
+ case REAL: {
+
+ static const Type valid[]={
+ BOOL,
+ INT,
+ //STRING,
+ NIL,
+ };
+
+ valid_types=valid;
+
+ } break;
+ case STRING: {
+
+
+ static const Type valid[]={
+ NODE_PATH,
+ NIL
+ };
+
+ valid_types=valid;
+ } break;
+ case MATRIX32: {
+
+
+ static const Type valid[]={
+ TRANSFORM,
+ NIL
+ };
+
+ valid_types=valid;
+ } break;
+ case QUAT: {
+
+ static const Type valid[]={
+ MATRIX3,
+ NIL
+ };
+
+ valid_types=valid;
+
+ } break;
+ case MATRIX3: {
+
+ static const Type valid[]={
+ QUAT,
+ NIL
+ };
+
+ valid_types=valid;
+
+
+ } break;
+ case TRANSFORM: {
+
+ static const Type valid[]={
+ MATRIX32,
+ QUAT,
+ MATRIX3,
+ NIL
+ };
+
+ valid_types=valid;
+
+ } break;
+
+ case COLOR: {
+
+ static const Type valid[] = {
STRING,
INT,
NIL,
@@ -532,7 +782,7 @@ bool Variant::is_zero() const {
} break;
case QUAT: {
- *reinterpret_cast<const Quat*>(_data._mem)==Quat();
+ return *reinterpret_cast<const Quat*>(_data._mem)==Quat();
} break;
case MATRIX3: {
diff --git a/core/variant.h b/core/variant.h
index 85c7b92c0d..5f338ef667 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -165,7 +165,8 @@ public:
_FORCE_INLINE_ Type get_type() const { return type; }
static String get_type_name(Variant::Type p_type);
- static bool can_convert(Type p_type_from,Type p_type_to);
+ static bool can_convert(Type p_type_from, Type p_type_to);
+ static bool can_convert_strict(Type p_type_from, Type p_type_to);