diff options
-rw-r--r-- | core/os/file_access.cpp | 31 | ||||
-rw-r--r-- | core/os/file_access.h | 1 | ||||
-rw-r--r-- | core/string_buffer.cpp | 2 | ||||
-rw-r--r-- | core/string_db.h | 17 | ||||
-rw-r--r-- | core/ustring.cpp | 61 | ||||
-rw-r--r-- | core/ustring.h | 23 | ||||
-rw-r--r-- | doc/classes/TileMap.xml | 3 | ||||
-rw-r--r-- | editor/editor_file_system.cpp | 46 |
8 files changed, 120 insertions, 64 deletions
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 20c1221f2b..133c70b671 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -569,6 +569,37 @@ String FileAccess::get_md5(const String &p_file) { return ret; } +String FileAccess::get_multiple_md5(const Vector<String> &p_file) { + + MD5_CTX md5; + MD5Init(&md5); + + for (int i = 0; i < p_file.size(); i++) { + FileAccess *f = FileAccess::open(p_file[i], READ); + ERR_CONTINUE(!f); + + unsigned char step[32768]; + + while (true) { + + int br = f->get_buffer(step, 32768); + if (br > 0) { + + MD5Update(&md5, step, br); + } + if (br < 4096) + break; + } + memdelete(f); + } + + MD5Final(&md5); + + String ret = String::md5(md5.digest); + + return ret; +} + String FileAccess::get_sha256(const String &p_file) { FileAccess *f = FileAccess::open(p_file, READ); diff --git a/core/os/file_access.h b/core/os/file_access.h index 6fda3d9668..548d7b71f1 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -155,6 +155,7 @@ public: static String get_md5(const String &p_file); static String get_sha256(const String &p_file); + static String get_multiple_md5(const Vector<String> &p_file); static Vector<uint8_t> get_file_as_array(const String &p_path); diff --git a/core/string_buffer.cpp b/core/string_buffer.cpp index 8489df2599..3b47685fc9 100644 --- a/core/string_buffer.cpp +++ b/core/string_buffer.cpp @@ -46,7 +46,7 @@ StringBuffer &StringBuffer::append(const char *p_str) { reserve(string_length + len + 1); CharType *buf = current_buffer_ptr(); - for (const char *c_ptr = p_str; c_ptr; ++c_ptr) { + for (const char *c_ptr = p_str; *c_ptr; ++c_ptr) { buf[string_length++] = *c_ptr; } return *this; diff --git a/core/string_db.h b/core/string_db.h index de91e2abd8..9665198ecd 100644 --- a/core/string_db.h +++ b/core/string_db.h @@ -138,7 +138,22 @@ public: _FORCE_INLINE_ bool operator()(const StringName &l, const StringName &r) const { - return l.operator String() < r.operator String(); + const char *l_cname = l._data ? l._data->cname : ""; + const char *r_cname = r._data ? r._data->cname : ""; + + if (l_cname) { + + if (r_cname) + return is_str_less(l_cname, r_cname); + else + return is_str_less(l_cname, r._data->name.ptr()); + } else { + + if (r_cname) + return is_str_less(l._data->name.ptr(), r_cname); + else + return is_str_less(l._data->name.ptr(), r._data->name.ptr()); + } } }; diff --git a/core/ustring.cpp b/core/ustring.cpp index ceafe209ea..261cc0778c 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -64,26 +64,7 @@ bool CharString::operator<(const CharString &p_right) const { return p_right.length() != 0; } - const char *this_str = get_data(); - const char *that_str = p_right.get_data(); - while (true) { - - if (*that_str == 0 && *this_str == 0) - return false; //this can't be equal, sadly - else if (*this_str == 0) - return true; //if this is empty, and the other one is not, then we're less.. I think? - else if (*that_str == 0) - return false; //otherwise the other one is smaller.. - else if (*this_str < *that_str) //more than - return true; - else if (*this_str > *that_str) //less than - return false; - - this_str++; - that_str++; - } - - return false; //should never reach here anyway + return is_str_less(get_data(), p_right.get_data()); } const char *CharString::get_data() const { @@ -372,25 +353,7 @@ bool String::operator<(const CharType *p_str) const { if (empty()) return true; - const CharType *this_str = c_str(); - while (true) { - - if (*p_str == 0 && *this_str == 0) - return false; //this can't be equal, sadly - else if (*this_str == 0) - return true; //if this is empty, and the other one is not, then we're less.. I think? - else if (*p_str == 0) - return false; //otherwise the other one is smaller.. - else if (*this_str < *p_str) //more than - return true; - else if (*this_str > *p_str) //less than - return false; - - this_str++; - p_str++; - } - - return false; //should never reach here anyway + return is_str_less(c_str(), p_str); } bool String::operator<=(const String &p_str) const { @@ -405,25 +368,7 @@ bool String::operator<(const char *p_str) const { if (empty()) return true; - const CharType *this_str = c_str(); - while (true) { - - if (*p_str == 0 && *this_str == 0) - return false; //this can't be equal, sadly - else if (*this_str == 0) - return true; //if this is empty, and the other one is not, then we're less.. I think? - else if (*p_str == 0) - return false; //otherwise the other one is smaller.. - else if (*this_str < *p_str) //more than - return true; - else if (*this_str > *p_str) //less than - return false; - - this_str++; - p_str++; - } - - return false; //should never reach here anyway + return is_str_less(c_str(), p_str); } bool String::operator<(const String &p_str) const { diff --git a/core/ustring.h b/core/ustring.h index 73537bfd13..1bb4719b85 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -279,6 +279,29 @@ struct NaturalNoCaseComparator { } }; +template <typename L, typename R> +_FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) { + + while (true) { + + if (*l_ptr == 0 && *r_ptr == 0) + return false; + else if (*l_ptr == 0) + return true; + else if (*r_ptr == 0) + return false; + else if (*l_ptr < *r_ptr) + return true; + else if (*l_ptr > *r_ptr) + return false; + + l_ptr++; + r_ptr++; + } + + CRASH_COND(true); // unreachable +} + /* end of namespace */ //tool translate diff --git a/doc/classes/TileMap.xml b/doc/classes/TileMap.xml index 510a215fbc..a09f6b6dc3 100644 --- a/doc/classes/TileMap.xml +++ b/doc/classes/TileMap.xml @@ -188,6 +188,7 @@ <argument index="0" name="arg0" type="Vector2"> </argument> <description> + Applies autotiling rules to the cell (and its adjacent cells) referenced by its grid-based X and Y coordinates. </description> </method> <method name="update_bitmask_region"> @@ -198,6 +199,8 @@ <argument index="1" name="end" type="Vector2" default="Vector2( 0, 0 )"> </argument> <description> + Applies autotiling rules to the cells in the given region (specified by grid-based X and Y coordinates). + Calling with invalid (or missing) parameters applies autotiling rules for the entire TileMap. </description> </method> <method name="world_to_map" qualifiers="const"> diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index d462cce908..27a1248089 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -320,7 +320,10 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo List<String> to_check; + String source_file; String source_md5; + Vector<String> dest_files; + String dest_md5; while (true) { @@ -346,8 +349,16 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo for (int i = 0; i < fa.size(); i++) { to_check.push_back(fa[i]); } - } else if (!p_only_imported_files && assign == "source_md5") { - source_md5 = value; + } else if (!p_only_imported_files) { + if (assign == "source_md5") { + source_md5 = value; + } else if (assign == "source_file") { + source_file = value; + } else if (assign == "dest_md5") { + dest_md5 = value; + } else if (assign == "dest_files") { + dest_files = value; + } } } else if (next_tag.name != "remap" && next_tag.name != "deps") { @@ -366,6 +377,11 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo //check source md5 matching if (!p_only_imported_files) { + + if (source_file != String() && source_file != p_path) { + return true; //file was moved, reimport + } + if (source_md5 == String()) { return true; //lacks md5, so just reimport } @@ -374,6 +390,13 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo if (md5 != source_md5) { return true; } + + if (dest_files.size() && dest_md5 != String()) { + md5 = FileAccess::get_multiple_md5(dest_files); + if (md5 != dest_md5) { + return true; + } + } } return false; //nothing changed @@ -1388,6 +1411,8 @@ void EditorFileSystem::_reimport_file(const String &p_file) { f->store_line("type=\"" + importer->get_resource_type() + "\""); } + Vector<String> dest_paths; + if (err == OK) { if (importer->get_save_extension() == "") { @@ -1399,10 +1424,12 @@ void EditorFileSystem::_reimport_file(const String &p_file) { String path = base_path.c_escape() + "." + E->get() + "." + importer->get_save_extension(); f->store_line("path." + E->get() + "=\"" + path + "\""); + dest_paths.push_back(path); } } else { - - f->store_line("path=\"" + base_path + "." + importer->get_save_extension() + "\""); + String path = base_path + "." + importer->get_save_extension(); + f->store_line("path=\"" + path + "\""); + dest_paths.push_back(path); } } else { @@ -1418,6 +1445,7 @@ void EditorFileSystem::_reimport_file(const String &p_file) { Array genf; for (List<String>::Element *E = gen_files.front(); E; E = E->next()) { genf.push_back(E->get()); + dest_paths.push_back(E->get()); } String value; @@ -1426,8 +1454,18 @@ void EditorFileSystem::_reimport_file(const String &p_file) { f->store_line(""); } + f->store_line("source_file=" + Variant(p_file).get_construct_string()); f->store_line("source_md5=\"" + FileAccess::get_md5(p_file) + "\"\n"); + if (dest_paths.size()) { + Array dp; + for (int i = 0; i < dest_paths.size(); i++) { + dp.push_back(dest_paths[i]); + } + f->store_line("dest_files=" + Variant(dp).get_construct_string()); + f->store_line("dest_md5=\"" + FileAccess::get_multiple_md5(dest_paths) + "\"\n"); + } + f->store_line("[params]"); f->store_line(""); |