summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/class_db.cpp2
-rw-r--r--core/core_string_names.cpp2
-rw-r--r--core/io/resource_format_binary.cpp49
-rw-r--r--core/io/resource_format_binary.h2
-rw-r--r--core/io/resource_import.cpp6
-rw-r--r--core/io/resource_loader.cpp8
-rw-r--r--core/math/geometry.h28
-rw-r--r--core/object.cpp8
8 files changed, 88 insertions, 17 deletions
diff --git a/core/class_db.cpp b/core/class_db.cpp
index 2eff8c07c7..76c2f0633a 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -1256,7 +1256,7 @@ void ClassDB::get_extensions_for_type(const StringName& p_class,List<String> *p_
while((K=resource_base_extensions.next(K))) {
StringName cmp = resource_base_extensions[*K];
- if (is_parent_class(cmp,p_class))
+ if (is_parent_class(p_class,cmp))
p_extensions->push_back(*K);
}
}
diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp
index a173f98602..f8c6f47797 100644
--- a/core/core_string_names.cpp
+++ b/core/core_string_names.cpp
@@ -35,7 +35,7 @@ CoreStringNames::CoreStringNames() {
_free=StaticCString::create("free");
changed=StaticCString::create("changed");
_meta=StaticCString::create("__meta__");
- _script=StaticCString::create("script/script");
+ _script=StaticCString::create("script");
script_changed=StaticCString::create("script_changed");
___pdcdata=StaticCString::create("___pdcdata");
__getvar=StaticCString::create("__getvar");
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index c75e476764..2c02dbcc9b 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -98,6 +98,27 @@ void ResourceInteractiveLoaderBinary::_advance_padding(uint32_t p_len) {
}
+
+StringName ResourceInteractiveLoaderBinary::_get_string() {
+
+ uint32_t id = f->get_32();
+ if (id&0x80000000) {
+ uint32_t len = id&0x7FFFFFFF;
+ if (len>str_buf.size()) {
+ str_buf.resize(len);
+ }
+ if (len==0)
+ return StringName();
+ f->get_buffer((uint8_t*)&str_buf[0],len);
+ String s;
+ s.parse_utf8(&str_buf[0]);
+ return s;
+ }
+
+ return string_map[id];
+
+}
+
Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
@@ -272,8 +293,8 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
Image::Format fmt=Image::Format(format&format_version_mask); //if format changes, we can add a compatibility bit on top
-
uint32_t datalen = f->get_32();
+ print_line("image format: "+String(Image::get_format_name(fmt))+" datalen "+itos(datalen));
PoolVector<uint8_t> imgdata;
imgdata.resize(datalen);
@@ -282,6 +303,14 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
_advance_padding(datalen);
w=PoolVector<uint8_t>::Write();
+#ifdef TOOLS_ENABLED
+//compatibility
+ int correct_size = Image::get_image_data_size(width,height,fmt,mipmaps?-1:0);
+ if (correct_size < datalen) {
+ WARN_PRINT("Image data was too large, shrinking for compatibility")
+ imgdata.resize(correct_size);
+ }
+#endif
r_v=Image(width,height,mipmaps,fmt,imgdata);
} else {
@@ -323,10 +352,10 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
for(int i=0;i<name_count;i++)
- names.push_back(string_map[f->get_32()]);
+ names.push_back(_get_string());
for(uint32_t i=0;i<subname_count;i++)
- subnames.push_back(string_map[f->get_32()]);
- property=string_map[f->get_32()];
+ subnames.push_back(_get_string());
+ property=_get_string();
NodePath np = NodePath(names,subnames,absolute,property);
//print_line("got path: "+String(np));
@@ -641,6 +670,8 @@ Error ResourceInteractiveLoaderBinary::poll(){
if (s<external_resources.size()) {
String path = external_resources[s].path;
+
+ print_line("load external res: "+path);
if (remaps.has(path)) {
path=remaps[path];
}
@@ -711,6 +742,8 @@ Error ResourceInteractiveLoaderBinary::poll(){
String t = get_unicode_string();
+// print_line("loading resource of type "+t+" path is "+path);
+
Object *obj = ClassDB::instance(t);
if (!obj) {
error=ERR_FILE_CORRUPT;
@@ -737,8 +770,8 @@ Error ResourceInteractiveLoaderBinary::poll(){
for(int i=0;i<pc;i++) {
- uint32_t name_idx = f->get_32();
- if (name_idx>=(uint32_t)string_map.size()) {
+ StringName name = _get_string();
+ if (name==StringName()) {
error=ERR_FILE_CORRUPT;
ERR_FAIL_V(ERR_FILE_CORRUPT);
}
@@ -749,7 +782,7 @@ Error ResourceInteractiveLoaderBinary::poll(){
if (error)
return error;
- res->set(string_map[name_idx],value);
+ res->set(name,value);
}
#ifdef TOOLS_ENABLED
res->set_edited(false);
@@ -2143,6 +2176,8 @@ void ResourceFormatSaverBinary::get_recognized_extensions(const RES& p_resource,
String base = p_resource->get_base_extension().to_lower();
p_extensions->push_back(base);
+ if (base!="res")
+ p_extensions->push_back("res");
}
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index 1dac51cc5c..1fab6144d5 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -54,6 +54,8 @@ class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader {
//Map<int,StringName> string_map;
Vector<StringName> string_map;
+ StringName _get_string();
+
struct ExtResoucre {
String path;
String type;
diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp
index 556dff3125..892c2988dc 100644
--- a/core/io/resource_import.cpp
+++ b/core/io/resource_import.cpp
@@ -81,8 +81,10 @@ RES ResourceFormatImporter::load(const String &p_path,const String& p_original_p
RES res = ResourceLoader::load(pat.path,pat.type,false,r_error);
#ifdef TOOLS_ENABLED
- res->set_import_last_modified_time( res->get_last_modified_time() ); //pass this, if used
- res->set_import_path(pat.path);
+ if (res.is_valid()) {
+ res->set_import_last_modified_time( res->get_last_modified_time() ); //pass this, if used
+ res->set_import_path(pat.path);
+ }
#endif
return res;
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 3199f05ff8..b6d28bccfa 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -61,6 +61,7 @@ bool ResourceFormatLoader::recognize_path(const String& p_path,const String& p_f
for (List<String>::Element *E=extensions.front();E;E=E->next()) {
+
if (E->get().nocasecmp_to(extension)==0)
return true;
}
@@ -191,12 +192,15 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
for (int i=0;i<loader_count;i++) {
- if (!loader[i]->recognize_path(local_path,p_type_hint))
+ if (!loader[i]->recognize_path(local_path,p_type_hint)) {
+ print_line("path not recognized");
continue;
+ }
found=true;
RES res = loader[i]->load(local_path,local_path,r_error);
- if (res.is_null())
+ if (res.is_null()) {
continue;
+ }
if (!p_no_cache)
res->set_path(local_path);
#ifdef TOOLS_ENABLED
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 13cbbdce6f..1dd7df038d 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -109,6 +109,7 @@ public:
static void get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2,Vector3& c1, Vector3& c2)
{
+#if 0
//do the function 'd' as defined by pb. I think is is dot product of some sort
#define d_of(m,n,o,p) ( (m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z) )
@@ -123,6 +124,33 @@ public:
if (mub > 1) mub = 1;
c1 = p1.linear_interpolate(p2,mua);
c2 = q1.linear_interpolate(q2,mub);
+#endif
+
+ Vector3 u = p2 - p1;
+ Vector3 v = q2 - q1;
+ Vector3 w = p1 - q1;
+ float a = u.dot(u);
+ float b = u.dot(v);
+ float c = v.dot(v); // always >= 0
+ float d = u.dot(w);
+ float e = v.dot(w);
+ float D = a*c - b*b; // always >= 0
+ float sc, tc;
+
+ // compute the line parameters of the two closest points
+ if (D < CMP_EPSILON) { // the lines are almost parallel
+ sc = 0.0;
+ tc = (b>c ? d/b : e/c); // use the largest denominator
+ }
+ else {
+ sc = (b*e - c*d) / D;
+ tc = (a*e - b*d) / D;
+ }
+
+ c1 = w + sc * u;
+ c2 = w + tc * v;
+ // get the difference of the two closest points
+ //Vector dP = w + (sc * u) - (tc * v); // = L1(sc) - L2(tc)
}
static real_t get_closest_distance_between_segments( const Vector3& p_from_a,const Vector3& p_to_a, const Vector3& p_from_b,const Vector3& p_to_b) {
diff --git a/core/object.cpp b/core/object.cpp
index 730b4209fe..79905a6be6 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -383,7 +383,7 @@ void Object::set(const String& p_name, const Variant& p_value) {
if (p_name=="__meta__") {
metadata=p_value;
- } else if (p_name=="script/script") {
+ } else if (p_name=="script") {
set_script(p_value);
} else if (script_instance) {
script_instance->set(p_name,p_value);
@@ -516,7 +516,7 @@ Variant Object::get(const String& p_name) const {
if (p_name=="__meta__")
return metadata;
- else if (p_name=="script/script")
+ else if (p_name=="script")
return script;
if (script_instance) {
@@ -539,7 +539,7 @@ void Object::get_property_list(List<PropertyInfo> *p_list,bool p_reversed) const
if (!is_class("Script")) // can still be set, but this is for userfriendlyness
- p_list->push_back( PropertyInfo( Variant::OBJECT, "script/script", PROPERTY_HINT_RESOURCE_TYPE, "Script",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_STORE_IF_NONZERO));
+ p_list->push_back( PropertyInfo( Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_STORE_IF_NONZERO));
if (!metadata.empty())
p_list->push_back( PropertyInfo( Variant::DICTIONARY, "__meta__", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_STORE_IF_NONZERO));
if (script_instance && !p_reversed) {
@@ -1041,7 +1041,7 @@ void Object::set_script(const RefPtr& p_script) {
}
- _change_notify("script/script");
+ _change_notify("script");
emit_signal(CoreStringNames::get_singleton()->script_changed);
}