diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bind/core_bind.cpp | 11 | ||||
-rw-r--r-- | core/bind/core_bind.h | 2 | ||||
-rw-r--r-- | core/class_db.cpp | 41 | ||||
-rw-r--r-- | core/class_db.h | 2 | ||||
-rw-r--r-- | core/dictionary.cpp | 21 | ||||
-rw-r--r-- | core/io/file_access_network.cpp | 2 | ||||
-rw-r--r-- | core/io/stream_peer.cpp | 2 | ||||
-rw-r--r-- | core/io/stream_peer.h | 2 | ||||
-rw-r--r-- | core/io/stream_peer_ssl.cpp | 1 | ||||
-rw-r--r-- | core/io/stream_peer_ssl.h | 1 | ||||
-rw-r--r-- | core/io/stream_peer_tcp.cpp | 1 | ||||
-rw-r--r-- | core/io/stream_peer_tcp.h | 2 | ||||
-rw-r--r-- | core/make_binders.py | 2 | ||||
-rw-r--r-- | core/math/triangulate.cpp | 2 | ||||
-rw-r--r-- | core/os/file_access.cpp | 3 | ||||
-rw-r--r-- | core/os/input_event.h | 4 | ||||
-rw-r--r-- | core/os/os.cpp | 11 | ||||
-rw-r--r-- | core/os/os.h | 2 | ||||
-rw-r--r-- | core/resource.cpp | 2 | ||||
-rw-r--r-- | core/safe_refcount.cpp | 8 | ||||
-rw-r--r-- | core/script_debugger_local.cpp | 3 | ||||
-rw-r--r-- | core/script_debugger_remote.cpp | 8 | ||||
-rw-r--r-- | core/string_buffer.cpp | 103 | ||||
-rw-r--r-- | core/string_buffer.h | 82 | ||||
-rw-r--r-- | core/string_builder.cpp | 3 | ||||
-rw-r--r-- | core/ustring.cpp | 2 | ||||
-rw-r--r-- | core/variant_call.cpp | 10 | ||||
-rw-r--r-- | core/variant_parser.cpp | 6 |
28 files changed, 198 insertions, 141 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 32b94b9b02..8f1a57e363 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -264,6 +264,10 @@ Size2 _OS::get_window_size() const { return OS::get_singleton()->get_window_size(); } +Size2 _OS::get_real_window_size() const { + return OS::get_singleton()->get_real_window_size(); +} + void _OS::set_window_size(const Size2 &p_size) { OS::get_singleton()->set_window_size(p_size); } @@ -929,6 +933,11 @@ void _OS::request_attention() { OS::get_singleton()->request_attention(); } +void _OS::center_window() { + + OS::get_singleton()->center_window(); +} + bool _OS::is_debug_build() const { #ifdef DEBUG_ENABLED @@ -1017,6 +1026,8 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("set_window_maximized", "enabled"), &_OS::set_window_maximized); ClassDB::bind_method(D_METHOD("is_window_maximized"), &_OS::is_window_maximized); ClassDB::bind_method(D_METHOD("request_attention"), &_OS::request_attention); + ClassDB::bind_method(D_METHOD("get_real_window_size"), &_OS::get_real_window_size); + ClassDB::bind_method(D_METHOD("center_window"), &_OS::center_window); ClassDB::bind_method(D_METHOD("set_borderless_window", "borderless"), &_OS::set_borderless_window); ClassDB::bind_method(D_METHOD("get_borderless_window"), &_OS::get_borderless_window); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 2353b6d09f..6b688a65f8 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -155,6 +155,7 @@ public: virtual Point2 get_window_position() const; virtual void set_window_position(const Point2 &p_position); virtual Size2 get_window_size() const; + virtual Size2 get_real_window_size() const; virtual void set_window_size(const Size2 &p_size); virtual void set_window_fullscreen(bool p_enabled); virtual bool is_window_fullscreen() const; @@ -165,6 +166,7 @@ public: virtual void set_window_maximized(bool p_enabled); virtual bool is_window_maximized() const; virtual void request_attention(); + virtual void center_window(); virtual void set_borderless_window(bool p_borderless); virtual bool get_borderless_window() const; diff --git a/core/class_db.cpp b/core/class_db.cpp index d2cd362792..afcc8de0f2 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -207,6 +207,47 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ return md; } +MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12) { + + MethodDefinition md; + md.name = StaticCString::create(p_name); + md.args.resize(12); + md.args[0] = StaticCString::create(p_arg1); + md.args[1] = StaticCString::create(p_arg2); + md.args[2] = StaticCString::create(p_arg3); + md.args[3] = StaticCString::create(p_arg4); + md.args[4] = StaticCString::create(p_arg5); + md.args[5] = StaticCString::create(p_arg6); + md.args[6] = StaticCString::create(p_arg7); + md.args[7] = StaticCString::create(p_arg8); + md.args[8] = StaticCString::create(p_arg9); + md.args[9] = StaticCString::create(p_arg10); + md.args[10] = StaticCString::create(p_arg11); + md.args[11] = StaticCString::create(p_arg12); + return md; +} + +MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13) { + + MethodDefinition md; + md.name = StaticCString::create(p_name); + md.args.resize(13); + md.args[0] = StaticCString::create(p_arg1); + md.args[1] = StaticCString::create(p_arg2); + md.args[2] = StaticCString::create(p_arg3); + md.args[3] = StaticCString::create(p_arg4); + md.args[4] = StaticCString::create(p_arg5); + md.args[5] = StaticCString::create(p_arg6); + md.args[6] = StaticCString::create(p_arg7); + md.args[7] = StaticCString::create(p_arg8); + md.args[8] = StaticCString::create(p_arg9); + md.args[9] = StaticCString::create(p_arg10); + md.args[10] = StaticCString::create(p_arg11); + md.args[11] = StaticCString::create(p_arg12); + md.args[12] = StaticCString::create(p_arg13); + return md; +} + #endif ClassDB::APIType ClassDB::current_api = API_CORE; diff --git a/core/class_db.h b/core/class_db.h index 14e36e459b..d74317239b 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -68,6 +68,8 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9); MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10); MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11); +MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12); +MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13); #else diff --git a/core/dictionary.cpp b/core/dictionary.cpp index ae1af86b77..e3f4aa5f28 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -34,15 +34,10 @@ #include "safe_refcount.h" #include "variant.h" -struct _DictionaryVariantHash { - - static _FORCE_INLINE_ uint32_t hash(const Variant &p_variant) { return p_variant.hash(); } -}; - struct DictionaryPrivate { SafeRefCount refcount; - OrderedHashMap<Variant, Variant, _DictionaryVariantHash> variant_map; + OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> variant_map; }; void Dictionary::get_key_list(List<Variant> *p_keys) const { @@ -50,7 +45,7 @@ void Dictionary::get_key_list(List<Variant> *p_keys) const { if (_p->variant_map.empty()) return; - for (OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::Element E = _p->variant_map.front(); E; E = E.next()) { + for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) { p_keys->push_back(E.key()); } } @@ -66,7 +61,7 @@ const Variant &Dictionary::operator[](const Variant &p_key) const { } const Variant *Dictionary::getptr(const Variant &p_key) const { - OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::ConstElement E = ((const OrderedHashMap<Variant, Variant, _DictionaryVariantHash> *)&_p->variant_map)->find(p_key); + OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); if (!E) return NULL; @@ -75,7 +70,7 @@ const Variant *Dictionary::getptr(const Variant &p_key) const { Variant *Dictionary::getptr(const Variant &p_key) { - OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::Element E = _p->variant_map.find(p_key); + OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(p_key); if (!E) return NULL; @@ -84,7 +79,7 @@ Variant *Dictionary::getptr(const Variant &p_key) { Variant Dictionary::get_valid(const Variant &p_key) const { - OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::ConstElement E = ((const OrderedHashMap<Variant, Variant, _DictionaryVariantHash> *)&_p->variant_map)->find(p_key); + OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); if (!E) return Variant(); @@ -177,7 +172,7 @@ Array Dictionary::keys() const { return varr; int i = 0; - for (OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::Element E = _p->variant_map.front(); E; E = E.next()) { + for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) { varr[i] = E.key(); i++; } @@ -193,7 +188,7 @@ Array Dictionary::values() const { return varr; int i = 0; - for (OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::Element E = _p->variant_map.front(); E; E = E.next()) { + for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) { varr[i] = E.get(); i++; } @@ -209,7 +204,7 @@ const Variant *Dictionary::next(const Variant *p_key) const { return &_p->variant_map.front().key(); return NULL; } - OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::Element E = _p->variant_map.find(*p_key); + OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(*p_key); if (E && E.next()) return &E.next().key(); diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 7b2bccdfec..ef886cdb3c 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -83,7 +83,7 @@ int64_t FileAccessNetworkClient::get_64() { void FileAccessNetworkClient::_thread_func() { - client->set_nodelay(true); + client->set_no_delay(true); while (!quit) { DEBUG_PRINT("SEM WAIT - " + itos(sem->get())); diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index f6c4948fc3..927b9f6366 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -310,7 +310,7 @@ float StreamPeer::get_float() { return decode_float(buf); } -float StreamPeer::get_double() { +double StreamPeer::get_double() { uint8_t buf[8]; get_data(buf, 8); diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h index ff9ae788ec..605b0a7980 100644 --- a/core/io/stream_peer.h +++ b/core/io/stream_peer.h @@ -83,7 +83,7 @@ public: uint64_t get_u64(); int64_t get_64(); float get_float(); - float get_double(); + double get_double(); String get_string(int p_bytes); String get_utf8_string(int p_bytes); Variant get_var(); diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp index 633b353102..07a01ff99f 100644 --- a/core/io/stream_peer_ssl.cpp +++ b/core/io/stream_peer_ssl.cpp @@ -52,6 +52,7 @@ bool StreamPeerSSL::is_available() { void StreamPeerSSL::_bind_methods() { + ClassDB::bind_method(D_METHOD("poll"), &StreamPeerSSL::poll); ClassDB::bind_method(D_METHOD("accept_stream", "stream"), &StreamPeerSSL::accept_stream); ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "validate_certs", "for_hostname"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String())); ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerSSL::get_status); diff --git a/core/io/stream_peer_ssl.h b/core/io/stream_peer_ssl.h index e4d14ebdfd..f903438c28 100644 --- a/core/io/stream_peer_ssl.h +++ b/core/io/stream_peer_ssl.h @@ -57,6 +57,7 @@ public: STATUS_ERROR_HOSTNAME_MISMATCH }; + virtual void poll() = 0; virtual Error accept_stream(Ref<StreamPeer> p_base) = 0; virtual Error connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs = false, const String &p_for_hostname = String()) = 0; virtual Status get_status() const = 0; diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index 9cfa810034..5d008904ff 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -55,6 +55,7 @@ void StreamPeerTCP::_bind_methods() { ClassDB::bind_method(D_METHOD("get_connected_host"), &StreamPeerTCP::get_connected_host); ClassDB::bind_method(D_METHOD("get_connected_port"), &StreamPeerTCP::get_connected_port); ClassDB::bind_method(D_METHOD("disconnect_from_host"), &StreamPeerTCP::disconnect_from_host); + ClassDB::bind_method(D_METHOD("set_no_delay", "enabled"), &StreamPeerTCP::set_no_delay); BIND_ENUM_CONSTANT(STATUS_NONE); BIND_ENUM_CONSTANT(STATUS_CONNECTING); diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index fc84525c5f..8a16d820f2 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -65,7 +65,7 @@ public: virtual void disconnect_from_host() = 0; virtual IP_Address get_connected_host() const = 0; virtual uint16_t get_connected_port() const = 0; - virtual void set_nodelay(bool p_enabled) = 0; + virtual void set_no_delay(bool p_enabled) = 0; static Ref<StreamPeerTCP> create_ref(); static StreamPeerTCP *create(); diff --git a/core/make_binders.py b/core/make_binders.py index 6f42c6e8eb..1e581f8ce3 100644 --- a/core/make_binders.py +++ b/core/make_binders.py @@ -244,7 +244,7 @@ def make_version(template, nargs, argmax, const, ret): def run(target, source, env): - versions = 11 + versions = 13 versions_ext = 6 text = "" text_ext = "" diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp index 957e16f92c..5bae74ac7e 100644 --- a/core/math/triangulate.cpp +++ b/core/math/triangulate.cpp @@ -74,7 +74,7 @@ bool Triangulate::is_inside_triangle(real_t Ax, real_t Ay, cCROSSap = cx * apy - cy * apx; bCROSScp = bx * cpy - by * cpx; - return ((aCROSSbp >= 0.0) && (bCROSScp >= 0.0) && (cCROSSap >= 0.0)); + return ((aCROSSbp > 0.0) && (bCROSScp > 0.0) && (cCROSSap > 0.0)); }; bool Triangulate::snip(const Vector<Vector2> &p_contour, int u, int v, int w, int n, const Vector<int> &V) { diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 368b4ad09d..033b4b12b9 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -479,6 +479,9 @@ void FileAccess::store_double(double p_dest) { uint64_t FileAccess::get_modified_time(const String &p_file) { + if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) + return 0; + FileAccess *fa = create_for_path(p_file); ERR_FAIL_COND_V(!fa, 0); diff --git a/core/os/input_event.h b/core/os/input_event.h index 72057659d2..ad754d0d1f 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -110,8 +110,8 @@ enum JoystickList { JOY_WII_C = JOY_BUTTON_5, JOY_WII_Z = JOY_BUTTON_6, - JOY_WII_MINUS = JOY_BUTTON_9, - JOY_WII_PLUS = JOY_BUTTON_10, + JOY_WII_MINUS = JOY_BUTTON_10, + JOY_WII_PLUS = JOY_BUTTON_11, // end of history diff --git a/core/os/os.cpp b/core/os/os.cpp index c6e5de703c..422acf95dc 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -616,6 +616,17 @@ bool OS::has_feature(const String &p_feature) { return false; } +void OS::center_window() { + + if (is_window_fullscreen()) return; + + Size2 scr = get_screen_size(get_current_screen()); + Size2 wnd = get_real_window_size(); + int x = scr.width / 2 - wnd.width / 2; + int y = scr.height / 2 - wnd.height / 2; + set_window_position(Vector2(x, y)); +} + OS::OS() { void *volatile stack_bottom; diff --git a/core/os/os.h b/core/os/os.h index 248e1dbefa..1ec488df06 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -182,6 +182,7 @@ public: virtual Point2 get_window_position() const { return Vector2(); } virtual void set_window_position(const Point2 &p_position) {} virtual Size2 get_window_size() const = 0; + virtual Size2 get_real_window_size() const { return get_window_size(); } virtual void set_window_size(const Size2 p_size) {} virtual void set_window_fullscreen(bool p_enabled) {} virtual bool is_window_fullscreen() const { return true; } @@ -192,6 +193,7 @@ public: virtual void set_window_maximized(bool p_enabled) {} virtual bool is_window_maximized() const { return true; } virtual void request_attention() {} + virtual void center_window(); virtual void set_borderless_window(bool p_borderless) {} virtual bool get_borderless_window() { return 0; } diff --git a/core/resource.cpp b/core/resource.cpp index 38f938932c..2eeed50d9d 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -74,7 +74,7 @@ void Resource::set_path(const String &p_path, bool p_take_over) { bool exists = ResourceCache::resources.has(p_path); ResourceCache::lock->read_unlock(); - ERR_EXPLAIN("Another resource is loaded from path: " + p_path); + ERR_EXPLAIN("Another resource is loaded from path: " + p_path + " (possible cyclic resource inclusion)"); ERR_FAIL_COND(exists); } } diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp index ff2f17103c..3b203f6977 100644 --- a/core/safe_refcount.cpp +++ b/core/safe_refcount.cpp @@ -119,8 +119,8 @@ _ALWAYS_INLINE_ uint64_t _atomic_exchange_if_greater_impl(register uint64_t *pw, // The actual advertised functions; they'll call the right implementation -uint32_t atomic_conditional_increment(register uint32_t *counter) { - return _atomic_conditional_increment_impl(counter); +uint32_t atomic_conditional_increment(register uint32_t *pw) { + return _atomic_conditional_increment_impl(pw); } uint32_t atomic_decrement(register uint32_t *pw) { @@ -143,8 +143,8 @@ uint32_t atomic_exchange_if_greater(register uint32_t *pw, register uint32_t val return _atomic_exchange_if_greater_impl(pw, val); } -uint64_t atomic_conditional_increment(register uint64_t *counter) { - return _atomic_conditional_increment_impl(counter); +uint64_t atomic_conditional_increment(register uint64_t *pw) { + return _atomic_conditional_increment_impl(pw); } uint64_t atomic_decrement(register uint64_t *pw) { diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp index 0da377453e..c0e115e300 100644 --- a/core/script_debugger_local.cpp +++ b/core/script_debugger_local.cpp @@ -291,7 +291,8 @@ void ScriptDebuggerLocal::profiling_end() { void ScriptDebuggerLocal::send_message(const String &p_message, const Array &p_args) { - print_line("MESSAGE: '" + p_message + "' - " + String(Variant(p_args))); + // This needs to be cleaned up entirely. + // print_line("MESSAGE: '" + p_message + "' - " + String(Variant(p_args))); } void ScriptDebuggerLocal::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info) { diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index a297bb738f..41071ace5d 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -598,7 +598,13 @@ void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) { Array send_props; for (int i = 0; i < properties.size(); i++) { const PropertyInfo &pi = properties[i].first; - const Variant &var = properties[i].second; + Variant &var = properties[i].second; + + WeakRef *ref = Object::cast_to<WeakRef>(var); + if (ref) { + var = ref->get_ref(); + } + RES res = var; Array prop; diff --git a/core/string_buffer.cpp b/core/string_buffer.cpp deleted file mode 100644 index aac2090378..0000000000 --- a/core/string_buffer.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/*************************************************************************/ -/* string_buffer.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* 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 "string_buffer.h" - -#include <string.h> - -StringBuffer &StringBuffer::append(CharType p_char) { - reserve(string_length + 2); - current_buffer_ptr()[string_length++] = p_char; - return *this; -} - -StringBuffer &StringBuffer::append(const String &p_string) { - return append(p_string.c_str()); -} - -StringBuffer &StringBuffer::append(const char *p_str) { - int len = strlen(p_str); - reserve(string_length + len + 1); - - CharType *buf = current_buffer_ptr(); - for (const char *c_ptr = p_str; *c_ptr; ++c_ptr) { - buf[string_length++] = *c_ptr; - } - return *this; -} - -StringBuffer &StringBuffer::append(const CharType *p_str, int p_clip_to_len) { - int len = 0; - while ((p_clip_to_len < 0 || len < p_clip_to_len) && p_str[len]) { - ++len; - } - reserve(string_length + len + 1); - memcpy(&(current_buffer_ptr()[string_length]), p_str, len * sizeof(CharType)); - string_length += len; - - return *this; -} - -StringBuffer &StringBuffer::reserve(int p_size) { - if (p_size < SHORT_BUFFER_SIZE || p_size < buffer.size()) - return *this; - - bool need_copy = string_length > 0 && buffer.empty(); - buffer.resize(next_power_of_2(p_size)); - if (need_copy) { - memcpy(buffer.ptrw(), short_buffer, string_length * sizeof(CharType)); - } - - return *this; -} - -int StringBuffer::length() const { - return string_length; -} - -String StringBuffer::as_string() { - current_buffer_ptr()[string_length] = '\0'; - if (buffer.empty()) { - return String(short_buffer); - } else { - buffer.resize(string_length + 1); - return buffer; - } -} - -double StringBuffer::as_double() { - current_buffer_ptr()[string_length] = '\0'; - return String::to_double(current_buffer_ptr()); -} - -int64_t StringBuffer::as_int() { - current_buffer_ptr()[string_length] = '\0'; - return String::to_int(current_buffer_ptr()); -} diff --git a/core/string_buffer.h b/core/string_buffer.h index f0ead66bb8..b148e45544 100644 --- a/core/string_buffer.h +++ b/core/string_buffer.h @@ -32,9 +32,10 @@ #define STRING_BUFFER_H #include "ustring.h" +#include <string.h> +template <int SHORT_BUFFER_SIZE = 64> class StringBuffer { - static const int SHORT_BUFFER_SIZE = 64; CharType short_buffer[SHORT_BUFFER_SIZE]; String buffer; @@ -80,4 +81,83 @@ public: } }; +template <int SHORT_BUFFER_SIZE> +StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::append(CharType p_char) { + reserve(string_length + 2); + current_buffer_ptr()[string_length++] = p_char; + return *this; +} + +template <int SHORT_BUFFER_SIZE> +StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::append(const String &p_string) { + return append(p_string.c_str()); +} + +template <int SHORT_BUFFER_SIZE> +StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::append(const char *p_str) { + int len = strlen(p_str); + reserve(string_length + len + 1); + + CharType *buf = current_buffer_ptr(); + for (const char *c_ptr = p_str; *c_ptr; ++c_ptr) { + buf[string_length++] = *c_ptr; + } + return *this; +} + +template <int SHORT_BUFFER_SIZE> +StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::append(const CharType *p_str, int p_clip_to_len) { + int len = 0; + while ((p_clip_to_len < 0 || len < p_clip_to_len) && p_str[len]) { + ++len; + } + reserve(string_length + len + 1); + memcpy(&(current_buffer_ptr()[string_length]), p_str, len * sizeof(CharType)); + string_length += len; + + return *this; +} + +template <int SHORT_BUFFER_SIZE> +StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::reserve(int p_size) { + if (p_size < SHORT_BUFFER_SIZE || p_size < buffer.size()) + return *this; + + bool need_copy = string_length > 0 && buffer.empty(); + buffer.resize(next_power_of_2(p_size)); + if (need_copy) { + memcpy(buffer.ptrw(), short_buffer, string_length * sizeof(CharType)); + } + + return *this; +} + +template <int SHORT_BUFFER_SIZE> +int StringBuffer<SHORT_BUFFER_SIZE>::length() const { + return string_length; +} + +template <int SHORT_BUFFER_SIZE> +String StringBuffer<SHORT_BUFFER_SIZE>::as_string() { + current_buffer_ptr()[string_length] = '\0'; + if (buffer.empty()) { + return String(short_buffer); + } else { + buffer.resize(string_length + 1); + return buffer; + } +} + +template <int SHORT_BUFFER_SIZE> +double StringBuffer<SHORT_BUFFER_SIZE>::as_double() { + current_buffer_ptr()[string_length] = '\0'; + return String::to_double(current_buffer_ptr()); +} + +template <int SHORT_BUFFER_SIZE> +int64_t StringBuffer<SHORT_BUFFER_SIZE>::as_int() { + current_buffer_ptr()[string_length] = '\0'; + return String::to_int(current_buffer_ptr()); +} + #endif diff --git a/core/string_builder.cpp b/core/string_builder.cpp index 4d567cbc03..8ab7e0ea8f 100644 --- a/core/string_builder.cpp +++ b/core/string_builder.cpp @@ -56,6 +56,9 @@ StringBuilder &StringBuilder::append(const char *p_cstring) { String StringBuilder::as_string() const { + if (string_length == 0) + return ""; + CharType *buffer = memnew_arr(CharType, string_length); int current_position = 0; diff --git a/core/ustring.cpp b/core/ustring.cpp index 7aa2b012de..d445e4ed47 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -3167,7 +3167,7 @@ String String::http_unescape() const { if ((ord1 >= '0' && ord1 <= '9') || (ord1 >= 'A' && ord1 <= 'Z')) { CharType ord2 = ord_at(i + 2); if ((ord2 >= '0' && ord2 <= '9') || (ord2 >= 'A' && ord2 <= 'Z')) { - char bytes[2] = { ord1, ord2 }; + char bytes[2] = { (char)ord1, (char)ord2 }; res += (char)strtol(bytes, NULL, 16); i += 2; } diff --git a/core/variant_call.cpp b/core/variant_call.cpp index e9f7af3f63..5607751a27 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -1539,7 +1539,7 @@ void register_variant_methods() { ADDFUNC0R(VECTOR3, BOOL, Vector3, is_normalized, varray()); ADDFUNC0R(VECTOR3, VECTOR3, Vector3, normalized, varray()); ADDFUNC0R(VECTOR3, VECTOR3, Vector3, inverse, varray()); - ADDFUNC1R(VECTOR3, VECTOR3, Vector3, snapped, REAL, "by", varray()); + ADDFUNC1R(VECTOR3, VECTOR3, Vector3, snapped, VECTOR3, "by", varray()); ADDFUNC2R(VECTOR3, VECTOR3, Vector3, rotated, VECTOR3, "axis", REAL, "phi", varray()); ADDFUNC2R(VECTOR3, VECTOR3, Vector3, linear_interpolate, VECTOR3, "b", REAL, "t", varray()); ADDFUNC4R(VECTOR3, VECTOR3, Vector3, cubic_interpolate, VECTOR3, "b", VECTOR3, "pre_a", VECTOR3, "post_b", REAL, "t", varray()); @@ -1748,10 +1748,10 @@ void register_variant_methods() { ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, rotated, REAL, "phi", varray()); ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, scaled, VECTOR2, "scale", varray()); ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, translated, VECTOR2, "offset", varray()); - ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, xform, NIL, "v", varray()); - ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, xform_inv, NIL, "v", varray()); - ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, basis_xform, NIL, "v", varray()); - ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, basis_xform_inv, NIL, "v", varray()); + ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform, NIL, "v", varray()); + ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform_inv, NIL, "v", varray()); + ADDFUNC1R(TRANSFORM2D, VECTOR2, Transform2D, basis_xform, VECTOR2, "v", varray()); + ADDFUNC1R(TRANSFORM2D, VECTOR2, Transform2D, basis_xform_inv, VECTOR2, "v", varray()); ADDFUNC2R(TRANSFORM2D, TRANSFORM2D, Transform2D, interpolate_with, TRANSFORM2D, "transform", REAL, "weight", varray()); ADDFUNC0R(BASIS, BASIS, Basis, inverse, varray()); diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 54edb02347..446aee286d 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -178,7 +178,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri }; case '#': { - StringBuffer color_str; + StringBuffer<> color_str; color_str += '#'; while (true) { CharType ch = p_stream->get_char(); @@ -299,7 +299,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri if (cchar == '-' || (cchar >= '0' && cchar <= '9')) { //a number - StringBuffer num; + StringBuffer<> num; #define READING_SIGN 0 #define READING_INT 1 #define READING_DEC 2 @@ -378,7 +378,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { - StringBuffer id; + StringBuffer<> id; bool first = true; while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) { |