diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bind/core_bind.cpp | 6 | ||||
-rw-r--r-- | core/bind/core_bind.h | 2 | ||||
-rw-r--r-- | core/error_macros.h | 20 | ||||
-rw-r--r-- | core/io/config_file.cpp | 18 | ||||
-rw-r--r-- | core/io/config_file.h | 2 | ||||
-rw-r--r-- | core/io/file_access_pack.cpp | 2 | ||||
-rw-r--r-- | core/io/file_access_pack.h | 2 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 2 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 1 | ||||
-rw-r--r-- | core/io/resource_loader.h | 2 | ||||
-rw-r--r-- | core/math/rect2.h | 42 | ||||
-rw-r--r-- | core/message_queue.cpp | 5 | ||||
-rw-r--r-- | core/os/dir_access.cpp | 5 | ||||
-rw-r--r-- | core/os/dir_access.h | 3 | ||||
-rw-r--r-- | core/register_core_types.cpp | 2 | ||||
-rw-r--r-- | core/rid_owner.h | 4 | ||||
-rw-r--r-- | core/variant_call.cpp | 4 | ||||
-rw-r--r-- | core/variant_parser.cpp | 10 | ||||
-rw-r--r-- | core/variant_parser.h | 2 |
19 files changed, 76 insertions, 58 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index b798d732d6..264d8d415c 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -2344,10 +2344,10 @@ Error _Directory::change_dir(String p_dir) { ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); return d->change_dir(p_dir); } -String _Directory::get_current_dir() { +String _Directory::get_current_dir(bool p_include_drive) { ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use."); - return d->get_current_dir(); + return d->get_current_dir(p_include_drive); } Error _Directory::make_dir(String p_dir) { @@ -2444,7 +2444,7 @@ void _Directory::_bind_methods() { ClassDB::bind_method(D_METHOD("get_drive", "idx"), &_Directory::get_drive); ClassDB::bind_method(D_METHOD("get_current_drive"), &_Directory::get_current_drive); ClassDB::bind_method(D_METHOD("change_dir", "todir"), &_Directory::change_dir); - ClassDB::bind_method(D_METHOD("get_current_dir"), &_Directory::get_current_dir); + ClassDB::bind_method(D_METHOD("get_current_dir", "include_drive"), &_Directory::get_current_dir, DEFVAL(true)); ClassDB::bind_method(D_METHOD("make_dir", "path"), &_Directory::make_dir); ClassDB::bind_method(D_METHOD("make_dir_recursive", "path"), &_Directory::make_dir_recursive); ClassDB::bind_method(D_METHOD("file_exists", "path"), &_Directory::file_exists); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index ae7c3d02fd..e7850de744 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -572,7 +572,7 @@ public: int get_current_drive(); Error change_dir(String p_dir); // Can be relative or absolute, return false on success. - String get_current_dir(); // Return current dir location. + String get_current_dir(bool p_include_drive = true); // Return current dir location. Error make_dir(String p_dir); Error make_dir_recursive(String p_dir); diff --git a/core/error_macros.h b/core/error_macros.h index 4a3ea28957..e4d7609e04 100644 --- a/core/error_macros.h +++ b/core/error_macros.h @@ -502,11 +502,11 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li * * The current function returns `m_retval`. */ -#define ERR_FAIL_V(m_retval) \ - if (1) { \ - _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value)); \ - return m_retval; \ - } else \ +#define ERR_FAIL_V(m_retval) \ + if (1) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_retval)); \ + return m_retval; \ + } else \ ((void)0) /** @@ -515,11 +515,11 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li * * Prints `m_msg`, and the current function returns `m_retval`. */ -#define ERR_FAIL_V_MSG(m_retval, m_msg) \ - if (1) { \ - _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value), DEBUG_STR(m_msg)); \ - return m_retval; \ - } else \ +#define ERR_FAIL_V_MSG(m_retval, m_msg) \ + if (1) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_retval), DEBUG_STR(m_msg)); \ + return m_retval; \ + } else \ ((void)0) /** diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index b44ac16a87..531467ecd6 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -86,7 +86,8 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const { if (!values.has(p_section) || !values[p_section].has(p_key)) { - ERR_FAIL_COND_V_MSG(p_default.get_type() == Variant::NIL, Variant(), "Couldn't find the given section '" + p_section + "', key '" + p_key + "' and no default was given."); + ERR_FAIL_COND_V_MSG(p_default.get_type() == Variant::NIL, Variant(), + vformat("Couldn't find the given section \"%s\" and key \"%s\", and no default was given.", p_section, p_key)); return p_default; } @@ -112,7 +113,7 @@ void ConfigFile::get_sections(List<String> *r_sections) const { } void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) const { - ERR_FAIL_COND_MSG(!values.has(p_section), "Cannont get keys from nonexistent section '" + p_section + "'."); + ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot get keys from nonexistent section \"%s\".", p_section)); for (OrderedHashMap<String, Variant>::ConstElement E = values[p_section].front(); E; E = E.next()) { r_keys->push_back(E.key()); @@ -121,12 +122,14 @@ void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) void ConfigFile::erase_section(const String &p_section) { + ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase nonexistent section \"%s\".", p_section)); values.erase(p_section); } void ConfigFile::erase_section_key(const String &p_section, const String &p_key) { - ERR_FAIL_COND_MSG(!values.has(p_section), "Cannot erase key from nonexistent section '" + p_section + "'."); + ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase key \"%s\" from nonexistent section \"%s\".", p_key, p_section)); + ERR_FAIL_COND_MSG(!values[p_section].has(p_key), vformat("Cannot erase nonexistent key \"%s\" from section \"%s\".", p_key, p_section)); values[p_section].erase(p_key); } @@ -291,7 +294,7 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) if (err == ERR_FILE_EOF) { return OK; } else if (err != OK) { - ERR_PRINT("ConfgFile - " + p_path + ":" + itos(lines) + " error: " + error_text + "."); + ERR_PRINT(vformat("ConfigFile parse error at %s:%d: %s.", p_path, lines, error_text)); return err; } @@ -324,11 +327,8 @@ void ConfigFile::_bind_methods() { ClassDB::bind_method(D_METHOD("save", "path"), &ConfigFile::save); ClassDB::bind_method(D_METHOD("load_encrypted", "path", "key"), &ConfigFile::load_encrypted); - ClassDB::bind_method(D_METHOD("load_encrypted_pass", "path", "pass"), &ConfigFile::load_encrypted_pass); + ClassDB::bind_method(D_METHOD("load_encrypted_pass", "path", "password"), &ConfigFile::load_encrypted_pass); ClassDB::bind_method(D_METHOD("save_encrypted", "path", "key"), &ConfigFile::save_encrypted); - ClassDB::bind_method(D_METHOD("save_encrypted_pass", "path", "pass"), &ConfigFile::save_encrypted_pass); -} - -ConfigFile::ConfigFile() { + ClassDB::bind_method(D_METHOD("save_encrypted_pass", "path", "password"), &ConfigFile::save_encrypted_pass); } diff --git a/core/io/config_file.h b/core/io/config_file.h index 150fd24693..7efcb5a04c 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -74,8 +74,6 @@ public: Error save_encrypted(const String &p_path, const Vector<uint8_t> &p_key); Error save_encrypted_pass(const String &p_path, const String &p_pass); - - ConfigFile(); }; #endif // CONFIG_FILE_H diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index 83ce03418a..055ce816ad 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -454,7 +454,7 @@ Error DirAccessPack::change_dir(String p_dir) { return OK; } -String DirAccessPack::get_current_dir() { +String DirAccessPack::get_current_dir(bool p_include_drive) { PackedData::PackedDir *pd = current; String p = current->name; diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index b6ea9c158f..e1f35aabdd 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -216,7 +216,7 @@ public: virtual String get_drive(int p_drive); virtual Error change_dir(String p_dir); - virtual String get_current_dir(); + virtual String get_current_dir(bool p_include_drive = true); virtual bool file_exists(String p_file); virtual bool dir_exists(String p_dir); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 54b75cc29d..efd452191a 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1008,7 +1008,9 @@ String ResourceLoaderBinary::recognize(FileAccess *p_f) { ResourceLoaderBinary::ResourceLoaderBinary() : translation_remapped(false), + ver_format(0), f(NULL), + importmd_ofs(0), error(OK) { progress = nullptr; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 504dbe2d63..5dca8b3b89 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -538,6 +538,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p if (r_error) { *r_error = err; } + thread_load_mutex->unlock(); return RES(); } thread_load_mutex->unlock(); diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 3b7a27f551..ea89917a5f 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -116,7 +116,7 @@ private: String type_hint; float progress = 0.0; ThreadLoadStatus status = THREAD_LOAD_IN_PROGRESS; - Error error; + Error error = OK; RES resource; bool xl_remapped = false; bool use_sub_threads = false; diff --git a/core/math/rect2.h b/core/math/rect2.h index e4ea615c22..3b9660e2f0 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -47,28 +47,26 @@ struct Rect2 { real_t get_area() const { return size.width * size.height; } - inline bool intersects(const Rect2 &p_rect) const { - if (position.x >= (p_rect.position.x + p_rect.size.width)) - return false; - if ((position.x + size.width) <= p_rect.position.x) - return false; - if (position.y >= (p_rect.position.y + p_rect.size.height)) - return false; - if ((position.y + size.height) <= p_rect.position.y) - return false; - - return true; - } - - inline bool intersects_touch(const Rect2 &p_rect) const { - if (position.x > (p_rect.position.x + p_rect.size.width)) - return false; - if ((position.x + size.width) < p_rect.position.x) - return false; - if (position.y > (p_rect.position.y + p_rect.size.height)) - return false; - if ((position.y + size.height) < p_rect.position.y) - return false; + inline bool intersects(const Rect2 &p_rect, const bool p_include_borders = false) const { + if (p_include_borders) { + if (position.x > (p_rect.position.x + p_rect.size.width)) + return false; + if ((position.x + size.width) < p_rect.position.x) + return false; + if (position.y > (p_rect.position.y + p_rect.size.height)) + return false; + if ((position.y + size.height) < p_rect.position.y) + return false; + } else { + if (position.x >= (p_rect.position.x + p_rect.size.width)) + return false; + if ((position.x + size.width) <= p_rect.position.x) + return false; + if (position.y >= (p_rect.position.y + p_rect.size.height)) + return false; + if ((position.y + size.height) <= p_rect.position.y) + return false; + } return true; } diff --git a/core/message_queue.cpp b/core/message_queue.cpp index 235003627e..37207483fe 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -268,7 +268,10 @@ void MessageQueue::flush() { //using reverse locking strategy _THREAD_SAFE_LOCK_ - ERR_FAIL_COND(flushing); //already flushing, you did something odd + if (flushing) { + _THREAD_SAFE_UNLOCK_ + ERR_FAIL_COND(flushing); //already flushing, you did something odd + } flushing = true; while (read_pos < buffer_end) { diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index f65fc00077..642c86be2f 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -66,6 +66,11 @@ int DirAccess::get_current_drive() { return 0; } +bool DirAccess::drives_are_shortcuts() { + + return false; +} + static Error _erase_recursive(DirAccess *da) { List<String> dirs; diff --git a/core/os/dir_access.h b/core/os/dir_access.h index 55a6d53f72..aac6c67f0a 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -76,9 +76,10 @@ public: virtual int get_drive_count() = 0; virtual String get_drive(int p_drive) = 0; virtual int get_current_drive(); + virtual bool drives_are_shortcuts(); virtual Error change_dir(String p_dir) = 0; ///< can be relative or absolute, return false on success - virtual String get_current_dir() = 0; ///< return current dir location + virtual String get_current_dir(bool p_include_drive = true) = 0; ///< return current dir location virtual Error make_dir(String p_dir) = 0; virtual Error make_dir_recursive(String p_dir); virtual Error erase_contents_recursive(); //super dangerous, use with care! diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 07a252ad31..b0ba8ed194 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -100,7 +100,7 @@ extern void unregister_variant_methods(); void register_core_types() { //consistency check - ERR_FAIL_COND(sizeof(Callable) > 16); + static_assert(sizeof(Callable) <= 16); ObjectDB::setup(); ResourceCache::setup(); diff --git a/core/rid_owner.h b/core/rid_owner.h index bd01eba17d..5c8c48a4cb 100644 --- a/core/rid_owner.h +++ b/core/rid_owner.h @@ -298,7 +298,11 @@ public: if (description) { print_error("ERROR: " + itos(alloc_count) + " RID allocations of type '" + description + "' were leaked at exit."); } else { +#ifdef NO_SAFE_CAST + print_error("ERROR: " + itos(alloc_count) + " RID allocations of type 'unknown' were leaked at exit."); +#else print_error("ERROR: " + itos(alloc_count) + " RID allocations of type '" + typeid(T).name() + "' were leaked at exit."); +#endif } for (size_t i = 0; i < max_alloc; i++) { diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 9cc08b54e6..99cfc7ed3c 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -391,7 +391,7 @@ struct _VariantCall { VCALL_LOCALMEM0R(Rect2, has_no_area); VCALL_LOCALMEM1R(Rect2, has_point); VCALL_LOCALMEM1R(Rect2, is_equal_approx); - VCALL_LOCALMEM1R(Rect2, intersects); + VCALL_LOCALMEM2R(Rect2, intersects); VCALL_LOCALMEM1R(Rect2, encloses); VCALL_LOCALMEM1R(Rect2, clip); VCALL_LOCALMEM1R(Rect2, merge); @@ -1834,7 +1834,7 @@ void register_variant_methods() { ADDFUNC0R(RECT2, BOOL, Rect2, has_no_area, varray()); ADDFUNC1R(RECT2, BOOL, Rect2, has_point, VECTOR2, "point", varray()); ADDFUNC1R(RECT2, BOOL, Rect2, is_equal_approx, RECT2, "rect", varray()); - ADDFUNC1R(RECT2, BOOL, Rect2, intersects, RECT2, "b", varray()); + ADDFUNC2R(RECT2, BOOL, Rect2, intersects, RECT2, "b", BOOL, "include_borders", varray(false)); ADDFUNC1R(RECT2, BOOL, Rect2, encloses, RECT2, "b", varray()); ADDFUNC1R(RECT2, RECT2, Rect2, clip, RECT2, "b", varray()); ADDFUNC1R(RECT2, RECT2, Rect2, merge, RECT2, "b", varray()); diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 12fd9976bd..d2ee0b71c9 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -532,6 +532,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = false; else if (id == "null" || id == "nil") value = Variant(); + else if (id == "inf") + value = Math_INF; + else if (id == "nan") + value = Math_NAN; else if (id == "Vector2") { Vector<float> args; @@ -1499,8 +1503,10 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str case Variant::FLOAT: { String s = rtosfix(p_variant.operator real_t()); - if (s.find(".") == -1 && s.find("e") == -1) - s += ".0"; + if (s != "inf" && s != "nan") { + if (s.find(".") == -1 && s.find("e") == -1) + s += ".0"; + } p_store_string_func(p_store_string_ud, s); } break; case Variant::STRING: { diff --git a/core/variant_parser.h b/core/variant_parser.h index ad0a4d6682..d50842145c 100644 --- a/core/variant_parser.h +++ b/core/variant_parser.h @@ -77,7 +77,7 @@ public: struct ResourceParser { - void *userdata; + void *userdata = nullptr; ParseResourceFunc func; ParseResourceFunc ext_func; ParseResourceFunc sub_func; |