summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/array.cpp78
-rw-r--r--core/array.h1
-rw-r--r--core/bind/core_bind.cpp365
-rw-r--r--core/bind/core_bind.h7
-rw-r--r--core/callable.cpp17
-rw-r--r--core/callable.h1
-rw-r--r--core/callable_method_pointer.cpp1
-rw-r--r--core/callable_method_pointer.h8
-rw-r--r--core/class_db.cpp243
-rw-r--r--core/class_db.h18
-rw-r--r--core/color.cpp84
-rw-r--r--core/color.h19
-rw-r--r--core/color_names.inc3
-rw-r--r--core/command_queue_mt.cpp12
-rw-r--r--core/command_queue_mt.h28
-rw-r--r--core/compressed_translation.cpp35
-rw-r--r--core/compressed_translation.h8
-rw-r--r--core/container_type_validate.h2
-rw-r--r--core/core_string_names.h1
-rw-r--r--core/cowdata.h51
-rw-r--r--core/crypto/crypto.cpp32
-rw-r--r--core/crypto/crypto_core.h5
-rw-r--r--core/crypto/hashing_context.cpp4
-rw-r--r--core/debugger/debugger_marshalls.cpp3
-rw-r--r--core/debugger/debugger_marshalls.h1
-rw-r--r--core/debugger/engine_debugger.cpp25
-rw-r--r--core/debugger/local_debugger.cpp55
-rw-r--r--core/debugger/local_debugger.h1
-rw-r--r--core/debugger/remote_debugger.cpp100
-rw-r--r--core/debugger/remote_debugger_peer.cpp18
-rw-r--r--core/debugger/script_debugger.cpp27
-rw-r--r--core/debugger/script_debugger.h1
-rw-r--r--core/dictionary.cpp60
-rw-r--r--core/dictionary.h1
-rw-r--r--core/engine.cpp22
-rw-r--r--core/engine.h1
-rw-r--r--core/error_macros.cpp12
-rw-r--r--core/error_macros.h1
-rw-r--r--core/func_ref.cpp11
-rw-r--r--core/func_ref.h1
-rw-r--r--core/global_constants.cpp7
-rw-r--r--core/hash_map.h109
-rw-r--r--core/hashfuncs.h20
-rw-r--r--core/image.cpp526
-rw-r--r--core/input/input.cpp142
-rw-r--r--core/input/input.h1
-rw-r--r--core/input/input_event.cpp242
-rw-r--r--core/input/input_event.h11
-rw-r--r--core/input/input_map.cpp50
-rw-r--r--core/input/input_map.h1
-rw-r--r--core/io/compression.cpp19
-rw-r--r--core/io/compression.h1
-rw-r--r--core/io/config_file.cpp56
-rw-r--r--core/io/config_file.h1
-rw-r--r--core/io/dtls_server.cpp2
-rw-r--r--core/io/file_access_buffered.cpp18
-rw-r--r--core/io/file_access_buffered.h3
-rw-r--r--core/io/file_access_buffered_fa.h12
-rw-r--r--core/io/file_access_compressed.cpp68
-rw-r--r--core/io/file_access_compressed.h1
-rw-r--r--core/io/file_access_encrypted.cpp59
-rw-r--r--core/io/file_access_memory.cpp26
-rw-r--r--core/io/file_access_memory.h1
-rw-r--r--core/io/file_access_network.cpp61
-rw-r--r--core/io/file_access_network.h3
-rw-r--r--core/io/file_access_pack.cpp91
-rw-r--r--core/io/file_access_pack.h14
-rw-r--r--core/io/file_access_zip.cpp50
-rw-r--r--core/io/file_access_zip.h3
-rw-r--r--core/io/http_client.cpp81
-rw-r--r--core/io/http_client.h1
-rw-r--r--core/io/image_loader.cpp31
-rw-r--r--core/io/image_loader.h1
-rw-r--r--core/io/ip.cpp37
-rw-r--r--core/io/ip_address.cpp31
-rw-r--r--core/io/ip_address.h26
-rw-r--r--core/io/json.cpp87
-rw-r--r--core/io/json.h2
-rw-r--r--core/io/logger.cpp5
-rw-r--r--core/io/logger.h1
-rw-r--r--core/io/marshalls.cpp271
-rw-r--r--core/io/marshalls.h24
-rw-r--r--core/io/multiplayer_api.cpp103
-rw-r--r--core/io/multiplayer_api.h1
-rw-r--r--core/io/net_socket.cpp4
-rw-r--r--core/io/net_socket.h1
-rw-r--r--core/io/networked_multiplayer_peer.cpp1
-rw-r--r--core/io/networked_multiplayer_peer.h1
-rw-r--r--core/io/packet_peer.cpp64
-rw-r--r--core/io/packet_peer.h2
-rw-r--r--core/io/packet_peer_dtls.cpp2
-rw-r--r--core/io/packet_peer_udp.cpp52
-rw-r--r--core/io/pck_packer.cpp22
-rw-r--r--core/io/pck_packer.h2
-rw-r--r--core/io/resource_format_binary.cpp245
-rw-r--r--core/io/resource_format_binary.h3
-rw-r--r--core/io/resource_importer.cpp53
-rw-r--r--core/io/resource_importer.h2
-rw-r--r--core/io/resource_loader.cpp178
-rw-r--r--core/io/resource_loader.h8
-rw-r--r--core/io/resource_saver.cpp44
-rw-r--r--core/io/resource_saver.h1
-rw-r--r--core/io/stream_peer.cpp88
-rw-r--r--core/io/stream_peer.h1
-rw-r--r--core/io/stream_peer_ssl.cpp5
-rw-r--r--core/io/stream_peer_tcp.cpp41
-rw-r--r--core/io/stream_peer_tcp.h1
-rw-r--r--core/io/tcp_server.cpp16
-rw-r--r--core/io/tcp_server.h1
-rw-r--r--core/io/translation_loader_po.cpp46
-rw-r--r--core/io/udp_server.cpp15
-rw-r--r--core/io/xml_parser.cpp127
-rw-r--r--core/io/xml_parser.h1
-rw-r--r--core/io/zip_io.cpp15
-rw-r--r--core/list.h120
-rw-r--r--core/local_vector.h16
-rw-r--r--core/map.h181
-rw-r--r--core/math/a_star.cpp83
-rw-r--r--core/math/a_star.h2
-rw-r--r--core/math/aabb.cpp74
-rw-r--r--core/math/aabb.h113
-rw-r--r--core/math/audio_frame.h2
-rw-r--r--core/math/basis.cpp65
-rw-r--r--core/math/basis.h19
-rw-r--r--core/math/camera_matrix.cpp56
-rw-r--r--core/math/camera_matrix.h3
-rw-r--r--core/math/delaunay_2d.h4
-rw-r--r--core/math/delaunay_3d.h47
-rw-r--r--core/math/disjoint_set.h5
-rw-r--r--core/math/expression.cpp250
-rw-r--r--core/math/expression.h11
-rw-r--r--core/math/face3.cpp73
-rw-r--r--core/math/face3.h30
-rw-r--r--core/math/geometry.cpp231
-rw-r--r--core/math/geometry.h324
-rw-r--r--core/math/math_fieldwise.cpp1
-rw-r--r--core/math/math_funcs.cpp16
-rw-r--r--core/math/math_funcs.h18
-rw-r--r--core/math/octree.h270
-rw-r--r--core/math/plane.cpp21
-rw-r--r--core/math/plane.h12
-rw-r--r--core/math/quat.cpp12
-rw-r--r--core/math/quat.h2
-rw-r--r--core/math/quick_hull.cpp69
-rw-r--r--core/math/quick_hull.h5
-rw-r--r--core/math/random_number_generator.h5
-rw-r--r--core/math/rect2.cpp80
-rw-r--r--core/math/rect2.h111
-rw-r--r--core/math/transform.cpp23
-rw-r--r--core/math/transform.h13
-rw-r--r--core/math/transform_2d.cpp33
-rw-r--r--core/math/transform_2d.h13
-rw-r--r--core/math/triangle_mesh.cpp132
-rw-r--r--core/math/triangle_mesh.h9
-rw-r--r--core/math/triangulate.cpp36
-rw-r--r--core/math/vector2.cpp37
-rw-r--r--core/math/vector2.h24
-rw-r--r--core/math/vector3.cpp21
-rw-r--r--core/math/vector3.h64
-rw-r--r--core/math/vector3i.cpp6
-rw-r--r--core/math/vector3i.h48
-rw-r--r--core/message_queue.cpp60
-rw-r--r--core/message_queue.h2
-rw-r--r--core/method_bind.cpp12
-rw-r--r--core/method_bind.h31
-rw-r--r--core/method_ptrcall.h8
-rw-r--r--core/node_path.cpp120
-rw-r--r--core/node_path.h5
-rw-r--r--core/oa_hash_map.h9
-rw-r--r--core/object.cpp352
-rw-r--r--core/object.h60
-rw-r--r--core/os/dir_access.cpp68
-rw-r--r--core/os/dir_access.h7
-rw-r--r--core/os/file_access.cpp140
-rw-r--r--core/os/file_access.h8
-rw-r--r--core/os/keyboard.cpp11
-rw-r--r--core/os/main_loop.cpp20
-rw-r--r--core/os/main_loop.h1
-rw-r--r--core/os/memory.cpp11
-rw-r--r--core/os/memory.h27
-rw-r--r--core/os/midi_driver.cpp5
-rw-r--r--core/os/midi_driver.h1
-rw-r--r--core/os/mutex.h1
-rw-r--r--core/os/os.cpp87
-rw-r--r--core/os/os.h3
-rw-r--r--core/os/rw_lock.cpp1
-rw-r--r--core/os/rw_lock.h14
-rw-r--r--core/os/semaphore.h3
-rw-r--r--core/os/thread.cpp14
-rw-r--r--core/os/thread.h1
-rw-r--r--core/os/thread_dummy.h2
-rw-r--r--core/os/threaded_array_processor.h6
-rw-r--r--core/packed_data_container.cpp70
-rw-r--r--core/packed_data_container.h1
-rw-r--r--core/pair.h2
-rw-r--r--core/pool_allocator.cpp87
-rw-r--r--core/pool_allocator.h5
-rw-r--r--core/print_string.cpp20
-rw-r--r--core/print_string.h1
-rw-r--r--core/project_settings.cpp180
-rw-r--r--core/project_settings.h1
-rw-r--r--core/reference.cpp17
-rw-r--r--core/reference.h36
-rw-r--r--core/register_core_types.cpp6
-rw-r--r--core/resource.cpp96
-rw-r--r--core/resource.h1
-rw-r--r--core/rid.h5
-rw-r--r--core/rid_owner.h6
-rw-r--r--core/ring_buffer.h14
-rw-r--r--core/safe_refcount.cpp8
-rw-r--r--core/safe_refcount.h32
-rw-r--r--core/script_language.cpp99
-rw-r--r--core/script_language.h6
-rw-r--r--core/self_list.h10
-rw-r--r--core/set.h165
-rw-r--r--core/simple_type.h3
-rw-r--r--core/sort_array.h94
-rw-r--r--core/string_buffer.h4
-rw-r--r--core/string_builder.cpp10
-rw-r--r--core/string_builder.h1
-rw-r--r--core/string_name.cpp72
-rw-r--r--core/string_name.h30
-rw-r--r--core/thread_work_pool.cpp3
-rw-r--r--core/thread_work_pool.h3
-rw-r--r--core/translation.cpp58
-rw-r--r--core/translation.h2
-rw-r--r--core/type_info.h7
-rw-r--r--core/typed_array.h5
-rw-r--r--core/typedefs.h3
-rw-r--r--core/ucaps.h2
-rw-r--r--core/undo_redo.cpp112
-rw-r--r--core/undo_redo.h2
-rw-r--r--core/ustring.cpp1080
-rw-r--r--core/ustring.h29
-rw-r--r--core/variant.cpp833
-rw-r--r--core/variant.h9
-rw-r--r--core/variant_call.cpp183
-rw-r--r--core/variant_op.cpp464
-rw-r--r--core/variant_parser.cpp363
-rw-r--r--core/variant_parser.h6
-rw-r--r--core/vector.h18
-rw-r--r--core/vmap.h32
-rw-r--r--core/vset.h27
243 files changed, 4761 insertions, 8147 deletions
diff --git a/core/array.cpp b/core/array.cpp
index 7c0129ffde..d1c0688e63 100644
--- a/core/array.cpp
+++ b/core/array.cpp
@@ -46,13 +46,13 @@ public:
};
void Array::_ref(const Array &p_from) const {
-
ArrayPrivate *_fp = p_from._p;
ERR_FAIL_COND(!_fp); // should NOT happen.
- if (_fp == _p)
+ if (_fp == _p) {
return; // whatever it is, nothing to do here move along
+ }
bool success = _fp->refcount.ref();
@@ -64,9 +64,9 @@ void Array::_ref(const Array &p_from) const {
}
void Array::_unref() const {
-
- if (!_p)
+ if (!_p) {
return;
+ }
if (_p->refcount.unref()) {
memdelete(_p);
@@ -75,46 +75,39 @@ void Array::_unref() const {
}
Variant &Array::operator[](int p_idx) {
-
return _p->array.write[p_idx];
}
const Variant &Array::operator[](int p_idx) const {
-
return _p->array[p_idx];
}
int Array::size() const {
-
return _p->array.size();
}
-bool Array::empty() const {
+bool Array::empty() const {
return _p->array.empty();
}
-void Array::clear() {
+void Array::clear() {
_p->array.clear();
}
bool Array::operator==(const Array &p_array) const {
-
return _p == p_array._p;
}
uint32_t Array::hash() const {
-
uint32_t h = hash_djb2_one_32(0);
for (int i = 0; i < _p->array.size(); i++) {
-
h = hash_djb2_one_32(_p->array[i].hash(), h);
}
return h;
}
void Array::_assign(const Array &p_array) {
-
if (_p->typed.type != Variant::OBJECT && _p->typed.type == p_array._p->typed.type) {
//same type or untyped, just reference, shuold be fine
_ref(p_array);
@@ -162,25 +155,22 @@ void Array::_assign(const Array &p_array) {
void Array::operator=(const Array &p_array) {
_assign(p_array);
}
-void Array::push_back(const Variant &p_value) {
+void Array::push_back(const Variant &p_value) {
ERR_FAIL_COND(!_p->typed.validate(p_value, "push_back"));
_p->array.push_back(p_value);
}
Error Array::resize(int p_new_size) {
-
return _p->array.resize(p_new_size);
}
void Array::insert(int p_pos, const Variant &p_value) {
-
ERR_FAIL_COND(!_p->typed.validate(p_value, "insert"));
_p->array.insert(p_pos, p_value);
}
void Array::erase(const Variant &p_value) {
-
ERR_FAIL_COND(!_p->typed.validate(p_value, "erase"));
_p->array.erase(p_value);
}
@@ -196,15 +186,14 @@ Variant Array::back() const {
}
int Array::find(const Variant &p_value, int p_from) const {
-
ERR_FAIL_COND_V(!_p->typed.validate(p_value, "find"), -1);
return _p->array.find(p_value, p_from);
}
int Array::rfind(const Variant &p_value, int p_from) const {
-
- if (_p->array.size() == 0)
+ if (_p->array.size() == 0) {
return -1;
+ }
ERR_FAIL_COND_V(!_p->typed.validate(p_value, "rfind"), -1);
if (p_from < 0) {
@@ -217,7 +206,6 @@ int Array::rfind(const Variant &p_value, int p_from) const {
}
for (int i = p_from; i >= 0; i--) {
-
if (_p->array[i] == p_value) {
return i;
}
@@ -227,20 +215,18 @@ int Array::rfind(const Variant &p_value, int p_from) const {
}
int Array::find_last(const Variant &p_value) const {
-
ERR_FAIL_COND_V(!_p->typed.validate(p_value, "find_last"), -1);
return rfind(p_value);
}
int Array::count(const Variant &p_value) const {
-
ERR_FAIL_COND_V(!_p->typed.validate(p_value, "count"), 0);
- if (_p->array.size() == 0)
+ if (_p->array.size() == 0) {
return 0;
+ }
int amount = 0;
for (int i = 0; i < _p->array.size(); i++) {
-
if (_p->array[i] == p_value) {
amount++;
}
@@ -256,24 +242,20 @@ bool Array::has(const Variant &p_value) const {
}
void Array::remove(int p_pos) {
-
_p->array.remove(p_pos);
}
void Array::set(int p_idx, const Variant &p_value) {
-
ERR_FAIL_COND(!_p->typed.validate(p_value, "set"));
operator[](p_idx) = p_value;
}
const Variant &Array::get(int p_idx) const {
-
return operator[](p_idx);
}
Array Array::duplicate(bool p_deep) const {
-
Array new_arr;
int element_count = size();
new_arr.resize(element_count);
@@ -286,7 +268,6 @@ Array Array::duplicate(bool p_deep) const {
}
int Array::_clamp_slice_index(int p_index) const {
-
int arr_size = size();
int fixed_index = CLAMP(p_index, -arr_size, arr_size - 1);
if (fixed_index < 0) {
@@ -301,14 +282,17 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // l
ERR_FAIL_COND_V_MSG(p_step == 0, new_arr, "Array slice step size cannot be zero.");
- if (empty()) // Don't try to slice empty arrays.
+ if (empty()) { // Don't try to slice empty arrays.
return new_arr;
+ }
if (p_step > 0) {
- if (p_begin >= size() || p_end < -size())
+ if (p_begin >= size() || p_end < -size()) {
return new_arr;
+ }
} else { // p_step < 0
- if (p_begin < -size() || p_end >= size())
+ if (p_begin < -size() || p_end >= size()) {
return new_arr;
+ }
}
int begin = _clamp_slice_index(p_begin);
@@ -335,40 +319,37 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // l
}
struct _ArrayVariantSort {
-
_FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const {
bool valid = false;
Variant res;
Variant::evaluate(Variant::OP_LESS, p_l, p_r, res, valid);
- if (!valid)
+ if (!valid) {
res = false;
+ }
return res;
}
};
Array &Array::sort() {
-
_p->array.sort_custom<_ArrayVariantSort>();
return *this;
}
struct _ArrayVariantSortCustom {
-
Object *obj;
StringName func;
_FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const {
-
const Variant *args[2] = { &p_l, &p_r };
Callable::CallError err;
bool res = obj->call(func, args, 2, err);
- if (err.error != Callable::CallError::CALL_OK)
+ if (err.error != Callable::CallError::CALL_OK) {
res = false;
+ }
return res;
}
};
Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {
-
ERR_FAIL_NULL_V(p_obj, *this);
SortArray<Variant, _ArrayVariantSortCustom, true> avs;
@@ -379,10 +360,10 @@ Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {
}
void Array::shuffle() {
-
const int n = _p->array.size();
- if (n < 2)
+ if (n < 2) {
return;
+ }
Variant *data = _p->array.ptrw();
for (int i = n - 1; i >= 1; i--) {
const int j = Math::rand() % (i + 1);
@@ -394,7 +375,6 @@ void Array::shuffle() {
template <typename Less>
_FORCE_INLINE_ int bisect(const Vector<Variant> &p_array, const Variant &p_value, bool p_before, const Less &p_less) {
-
int lo = 0;
int hi = p_array.size();
if (p_before) {
@@ -420,13 +400,11 @@ _FORCE_INLINE_ int bisect(const Vector<Variant> &p_array, const Variant &p_value
}
int Array::bsearch(const Variant &p_value, bool p_before) {
-
ERR_FAIL_COND_V(!_p->typed.validate(p_value, "binary search"), -1);
return bisect(_p->array, p_value, p_before, _ArrayVariantSort());
}
int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringName &p_function, bool p_before) {
-
ERR_FAIL_COND_V(!_p->typed.validate(p_value, "custom binary search"), -1);
ERR_FAIL_NULL_V(p_obj, 0);
@@ -438,19 +416,16 @@ int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringNam
}
Array &Array::invert() {
-
_p->array.invert();
return *this;
}
void Array::push_front(const Variant &p_value) {
-
ERR_FAIL_COND(!_p->typed.validate(p_value, "push_front"));
_p->array.insert(0, p_value);
}
Variant Array::pop_back() {
-
if (!_p->array.empty()) {
int n = _p->array.size() - 1;
Variant ret = _p->array.get(n);
@@ -461,7 +436,6 @@ Variant Array::pop_back() {
}
Variant Array::pop_front() {
-
if (!_p->array.empty()) {
Variant ret = _p->array.get(0);
_p->array.remove(0);
@@ -471,7 +445,6 @@ Variant Array::pop_front() {
}
Variant Array::min() const {
-
Variant minval;
for (int i = 0; i < size(); i++) {
if (i == 0) {
@@ -494,7 +467,6 @@ Variant Array::min() const {
}
Variant Array::max() const {
-
Variant maxval;
for (int i = 0; i < size(); i++) {
if (i == 0) {
@@ -542,17 +514,15 @@ void Array::set_typed(uint32_t p_type, const StringName &p_class_name, const Var
}
Array::Array(const Array &p_from) {
-
_p = nullptr;
_ref(p_from);
}
Array::Array() {
-
_p = memnew(ArrayPrivate);
_p->refcount.init();
}
-Array::~Array() {
+Array::~Array() {
_unref();
}
diff --git a/core/array.h b/core/array.h
index 14db57f15f..d2e0537ad5 100644
--- a/core/array.h
+++ b/core/array.h
@@ -39,7 +39,6 @@ class Object;
class StringName;
class Array {
-
mutable ArrayPrivate *_p;
void _ref(const Array &p_from) const;
void _unref() const;
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index ed0e7b1018..607e17eae4 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -67,9 +67,9 @@ static const unsigned int MONTH_DAYS_TABLE[2][12] = {
_ResourceLoader *_ResourceLoader::singleton = nullptr;
Error _ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads) {
-
return ResourceLoader::load_threaded_request(p_path, p_type_hint, p_use_sub_threads);
}
+
_ResourceLoader::ThreadLoadStatus _ResourceLoader::load_threaded_get_status(const String &p_path, Array r_progress) {
float progress = 0;
ResourceLoader::ThreadLoadStatus tls = ResourceLoader::load_threaded_get_status(p_path, &progress);
@@ -77,6 +77,7 @@ _ResourceLoader::ThreadLoadStatus _ResourceLoader::load_threaded_get_status(cons
r_progress[0] = progress;
return (ThreadLoadStatus)tls;
}
+
RES _ResourceLoader::load_threaded_get(const String &p_path) {
Error error;
RES res = ResourceLoader::load_threaded_get(p_path, &error);
@@ -84,7 +85,6 @@ RES _ResourceLoader::load_threaded_get(const String &p_path) {
}
RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache) {
-
Error err = OK;
RES ret = ResourceLoader::load(p_path, p_type_hint, p_no_cache, &err);
@@ -93,12 +93,10 @@ RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool
}
Vector<String> _ResourceLoader::get_recognized_extensions_for_type(const String &p_type) {
-
List<String> exts;
ResourceLoader::get_recognized_extensions_for_type(p_type, &exts);
Vector<String> ret;
for (List<String>::Element *E = exts.front(); E; E = E->next()) {
-
ret.push_back(E->get());
}
@@ -106,12 +104,10 @@ Vector<String> _ResourceLoader::get_recognized_extensions_for_type(const String
}
void _ResourceLoader::set_abort_on_missing_resources(bool p_abort) {
-
ResourceLoader::set_abort_on_missing_resources(p_abort);
}
PackedStringArray _ResourceLoader::get_dependencies(const String &p_path) {
-
List<String> deps;
ResourceLoader::get_dependencies(p_path, &deps);
@@ -124,7 +120,6 @@ PackedStringArray _ResourceLoader::get_dependencies(const String &p_path) {
};
bool _ResourceLoader::has_cached(const String &p_path) {
-
String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
return ResourceCache::has(local_path);
}
@@ -134,7 +129,6 @@ bool _ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
}
void _ResourceLoader::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("load_threaded_request", "path", "type_hint", "use_sub_threads"), &_ResourceLoader::load_threaded_request, DEFVAL(""), DEFVAL(false));
ClassDB::bind_method(D_METHOD("load_threaded_get_status", "path", "progress"), &_ResourceLoader::load_threaded_get_status, DEFVAL(Array()));
ClassDB::bind_method(D_METHOD("load_threaded_get", "path"), &_ResourceLoader::load_threaded_get);
@@ -160,13 +154,11 @@ Error _ResourceSaver::save(const String &p_path, const RES &p_resource, SaverFla
}
Vector<String> _ResourceSaver::get_recognized_extensions(const RES &p_resource) {
-
ERR_FAIL_COND_V_MSG(p_resource.is_null(), Vector<String>(), "It's not a reference to a valid Resource object.");
List<String> exts;
ResourceSaver::get_recognized_extensions(p_resource, &exts);
Vector<String> ret;
for (List<String>::Element *E = exts.front(); E; E = E->next()) {
-
ret.push_back(E->get());
}
return ret;
@@ -175,7 +167,6 @@ Vector<String> _ResourceSaver::get_recognized_extensions(const RES &p_resource)
_ResourceSaver *_ResourceSaver::singleton = nullptr;
void _ResourceSaver::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &_ResourceSaver::save, DEFVAL(0));
ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &_ResourceSaver::get_recognized_extensions);
@@ -203,36 +194,30 @@ void _OS::close_midi_inputs() {
}
void _OS::set_use_file_access_save_and_swap(bool p_enable) {
-
FileAccess::set_backup_save(p_enable);
}
void _OS::set_low_processor_usage_mode(bool p_enabled) {
-
OS::get_singleton()->set_low_processor_usage_mode(p_enabled);
}
-bool _OS::is_in_low_processor_usage_mode() const {
+bool _OS::is_in_low_processor_usage_mode() const {
return OS::get_singleton()->is_in_low_processor_usage_mode();
}
void _OS::set_low_processor_usage_mode_sleep_usec(int p_usec) {
-
OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(p_usec);
}
int _OS::get_low_processor_usage_mode_sleep_usec() const {
-
return OS::get_singleton()->get_low_processor_usage_mode_sleep_usec();
}
String _OS::get_executable_path() const {
-
return OS::get_singleton()->get_executable_path();
}
Error _OS::shell_open(String p_uri) {
-
if (p_uri.begins_with("res://")) {
WARN_PRINT("Attempting to open an URL with the \"res://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_open()`.");
} else if (p_uri.begins_with("user://")) {
@@ -242,53 +227,49 @@ Error _OS::shell_open(String p_uri) {
};
int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output, bool p_read_stderr) {
-
OS::ProcessID pid = -2;
int exitcode = 0;
List<String> args;
- for (int i = 0; i < p_arguments.size(); i++)
+ for (int i = 0; i < p_arguments.size(); i++) {
args.push_back(p_arguments[i]);
+ }
String pipe;
Error err = OS::get_singleton()->execute(p_path, args, p_blocking, &pid, &pipe, &exitcode, p_read_stderr);
p_output.clear();
p_output.push_back(pipe);
- if (err != OK)
+ if (err != OK) {
return -1;
- else if (p_blocking)
+ } else if (p_blocking) {
return exitcode;
- else
+ } else {
return pid;
+ }
}
Error _OS::kill(int p_pid) {
-
return OS::get_singleton()->kill(p_pid);
}
int _OS::get_process_id() const {
-
return OS::get_singleton()->get_process_id();
};
bool _OS::has_environment(const String &p_var) const {
-
return OS::get_singleton()->has_environment(p_var);
}
-String _OS::get_environment(const String &p_var) const {
+String _OS::get_environment(const String &p_var) const {
return OS::get_singleton()->get_environment(p_var);
}
String _OS::get_name() const {
-
return OS::get_singleton()->get_name();
}
-Vector<String> _OS::get_cmdline_args() {
+Vector<String> _OS::get_cmdline_args() {
List<String> cmdline = OS::get_singleton()->get_cmdline_args();
Vector<String> cmdlinev;
for (List<String>::Element *E = cmdline.front(); E; E = E->next()) {
-
cmdlinev.push_back(E->get());
}
@@ -296,42 +277,34 @@ Vector<String> _OS::get_cmdline_args() {
}
String _OS::get_locale() const {
-
return OS::get_singleton()->get_locale();
}
String _OS::get_model_name() const {
-
return OS::get_singleton()->get_model_name();
}
Error _OS::set_thread_name(const String &p_name) {
-
return Thread::set_name(p_name);
};
bool _OS::has_feature(const String &p_feature) const {
-
return OS::get_singleton()->has_feature(p_feature);
}
uint64_t _OS::get_static_memory_usage() const {
-
return OS::get_singleton()->get_static_memory_usage();
}
uint64_t _OS::get_static_memory_peak_usage() const {
-
return OS::get_singleton()->get_static_memory_peak_usage();
}
int _OS::get_exit_code() const {
-
return OS::get_singleton()->get_exit_code();
}
void _OS::set_exit_code(int p_code) {
-
if (p_code < 0 || p_code > 125) {
WARN_PRINT("For portability reasons, the exit code should be set between 0 and 125 (inclusive).");
}
@@ -344,7 +317,6 @@ void _OS::set_exit_code(int p_code) {
* dst
*/
Dictionary _OS::get_datetime(bool utc) const {
-
Dictionary dated = get_date(utc);
Dictionary timed = get_time(utc);
@@ -359,7 +331,6 @@ Dictionary _OS::get_datetime(bool utc) const {
}
Dictionary _OS::get_date(bool utc) const {
-
OS::Date date = OS::get_singleton()->get_date(utc);
Dictionary dated;
dated[YEAR_KEY] = date.year;
@@ -371,7 +342,6 @@ Dictionary _OS::get_date(bool utc) const {
}
Dictionary _OS::get_time(bool utc) const {
-
OS::Time time = OS::get_singleton()->get_time(utc);
Dictionary timed;
timed[HOUR_KEY] = time.hour;
@@ -393,7 +363,6 @@ Dictionary _OS::get_time(bool utc) const {
* @return epoch calculated
*/
int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const {
-
// Bunch of conversion constants
static const unsigned int SECONDS_PER_MINUTE = 60;
static const unsigned int MINUTES_PER_HOUR = 60;
@@ -466,7 +435,6 @@ int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const {
* @return dictionary of date and time values
*/
Dictionary _OS::get_datetime_from_unix_time(int64_t unix_time_val) const {
-
OS::Date date;
OS::Time time;
@@ -530,7 +498,6 @@ Dictionary _OS::get_time_zone_info() const {
}
uint64_t _OS::get_unix_time() const {
-
return OS::get_singleton()->get_unix_time();
}
@@ -543,57 +510,46 @@ uint64_t _OS::get_system_time_msecs() const {
}
void _OS::delay_usec(uint32_t p_usec) const {
-
OS::get_singleton()->delay_usec(p_usec);
}
void _OS::delay_msec(uint32_t p_msec) const {
-
OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000);
}
uint32_t _OS::get_ticks_msec() const {
-
return OS::get_singleton()->get_ticks_msec();
}
uint64_t _OS::get_ticks_usec() const {
-
return OS::get_singleton()->get_ticks_usec();
}
uint32_t _OS::get_splash_tick_msec() const {
-
return OS::get_singleton()->get_splash_tick_msec();
}
bool _OS::can_use_threads() const {
-
return OS::get_singleton()->can_use_threads();
}
bool _OS::is_userfs_persistent() const {
-
return OS::get_singleton()->is_userfs_persistent();
}
int _OS::get_processor_count() const {
-
return OS::get_singleton()->get_processor_count();
}
bool _OS::is_stdout_verbose() const {
-
return OS::get_singleton()->is_stdout_verbose();
}
void _OS::dump_memory_to_file(const String &p_file) {
-
OS::get_singleton()->dump_memory_to_file(p_file.utf8().get_data());
}
struct _OSCoreBindImg {
-
String path;
Size2 size;
int fmt;
@@ -603,7 +559,6 @@ struct _OSCoreBindImg {
};
void _OS::print_all_textures_by_size() {
-
List<_OSCoreBindImg> imgs;
int total = 0;
{
@@ -611,9 +566,9 @@ void _OS::print_all_textures_by_size() {
ResourceCache::get_cached_resources(&rsrc);
for (List<Ref<Resource>>::Element *E = rsrc.front(); E; E = E->next()) {
-
- if (!E->get()->is_class("ImageTexture"))
+ if (!E->get()->is_class("ImageTexture")) {
continue;
+ }
Size2 size = E->get()->call("get_size");
int fmt = E->get()->call("get_format");
@@ -632,13 +587,11 @@ void _OS::print_all_textures_by_size() {
imgs.sort();
for (List<_OSCoreBindImg>::Element *E = imgs.front(); E; E = E->next()) {
-
total -= E->get().vram;
}
}
void _OS::print_resources_by_type(const Vector<String> &p_types) {
-
Map<String, int> type_count;
List<Ref<Resource>> resources;
@@ -648,17 +601,18 @@ void _OS::print_resources_by_type(const Vector<String> &p_types) {
ResourceCache::get_cached_resources(&rsrc);
for (List<Ref<Resource>>::Element *E = rsrc.front(); E; E = E->next()) {
-
Ref<Resource> r = E->get();
bool found = false;
for (int i = 0; i < p_types.size(); i++) {
- if (r->is_class(p_types[i]))
+ if (r->is_class(p_types[i])) {
found = true;
+ }
}
- if (!found)
+ if (!found) {
continue;
+ }
if (!type_count.has(r->get_class())) {
type_count[r->get_class()] = 0;
@@ -669,27 +623,22 @@ void _OS::print_resources_by_type(const Vector<String> &p_types) {
};
void _OS::print_all_resources(const String &p_to_file) {
-
OS::get_singleton()->print_all_resources(p_to_file);
}
void _OS::print_resources_in_use(bool p_short) {
-
OS::get_singleton()->print_resources_in_use(p_short);
}
void _OS::dump_resources_to_file(const String &p_file) {
-
OS::get_singleton()->dump_resources_to_file(p_file.utf8().get_data());
}
String _OS::get_user_data_dir() const {
-
return OS::get_singleton()->get_user_data_dir();
};
bool _OS::is_debug_build() const {
-
#ifdef DEBUG_ENABLED
return true;
#else
@@ -698,37 +647,30 @@ bool _OS::is_debug_build() const {
}
String _OS::get_system_dir(SystemDir p_dir) const {
-
return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir));
}
String _OS::get_keycode_string(uint32_t p_code) const {
-
return keycode_get_string(p_code);
}
bool _OS::is_keycode_unicode(uint32_t p_unicode) const {
-
return keycode_has_unicode(p_unicode);
}
int _OS::find_keycode_from_string(const String &p_code) const {
-
return find_keycode(p_code);
}
bool _OS::request_permission(const String &p_name) {
-
return OS::get_singleton()->request_permission(p_name);
}
bool _OS::request_permissions() {
-
return OS::get_singleton()->request_permissions();
}
Vector<String> _OS::get_granted_permissions() const {
-
return OS::get_singleton()->get_granted_permissions();
}
@@ -739,7 +681,6 @@ String _OS::get_unique_id() const {
_OS *_OS::singleton = nullptr;
void _OS::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &_OS::get_connected_midi_inputs);
ClassDB::bind_method(D_METHOD("open_midi_inputs"), &_OS::open_midi_inputs);
ClassDB::bind_method(D_METHOD("close_midi_inputs"), &_OS::close_midi_inputs);
@@ -870,39 +811,32 @@ void _OS::_bind_methods() {
_Geometry *_Geometry::singleton = nullptr;
_Geometry *_Geometry::get_singleton() {
-
return singleton;
}
Vector<Plane> _Geometry::build_box_planes(const Vector3 &p_extents) {
-
return Geometry::build_box_planes(p_extents);
}
Vector<Plane> _Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
-
return Geometry::build_cylinder_planes(p_radius, p_height, p_sides, p_axis);
}
-Vector<Plane> _Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
+Vector<Plane> _Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
return Geometry::build_capsule_planes(p_radius, p_height, p_sides, p_lats, p_axis);
}
bool _Geometry::is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) {
-
return Geometry::is_point_in_circle(p_point, p_circle_pos, p_circle_radius);
}
real_t _Geometry::segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) {
-
return Geometry::segment_intersects_circle(p_from, p_to, p_circle_pos, p_circle_radius);
}
Variant _Geometry::segment_intersects_segment_2d(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b) {
-
Vector2 result;
if (Geometry::segment_intersects_segment_2d(p_from_a, p_to_a, p_from_b, p_to_b, &result)) {
-
return result;
} else {
return Variant();
@@ -910,7 +844,6 @@ Variant _Geometry::segment_intersects_segment_2d(const Vector2 &p_from_a, const
};
Variant _Geometry::line_intersects_line_2d(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b) {
-
Vector2 result;
if (Geometry::line_intersects_line_2d(p_from_a, p_dir_a, p_from_b, p_dir_b, result)) {
return result;
@@ -920,7 +853,6 @@ Variant _Geometry::line_intersects_line_2d(const Vector2 &p_from_a, const Vector
}
Vector<Vector2> _Geometry::get_closest_points_between_segments_2d(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2) {
-
Vector2 r1, r2;
Geometry::get_closest_points_between_segments(p1, q1, p2, q2, r1, r2);
Vector<Vector2> r;
@@ -931,7 +863,6 @@ Vector<Vector2> _Geometry::get_closest_points_between_segments_2d(const Vector2
}
Vector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2) {
-
Vector3 r1, r2;
Geometry::get_closest_points_between_segments(p1, p2, q1, q2, r1, r2);
Vector<Vector3> r;
@@ -940,78 +871,81 @@ Vector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3 &p1
r.set(1, r2);
return r;
}
-Vector2 _Geometry::get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
+Vector2 _Geometry::get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
Vector2 s[2] = { p_a, p_b };
return Geometry::get_closest_point_to_segment_2d(p_point, s);
}
-Vector3 _Geometry::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
+Vector3 _Geometry::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
Vector3 s[2] = { p_a, p_b };
return Geometry::get_closest_point_to_segment(p_point, s);
}
-Vector2 _Geometry::get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
+Vector2 _Geometry::get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
Vector2 s[2] = { p_a, p_b };
return Geometry::get_closest_point_to_segment_uncapped_2d(p_point, s);
}
-Vector3 _Geometry::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
+Vector3 _Geometry::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
Vector3 s[2] = { p_a, p_b };
return Geometry::get_closest_point_to_segment_uncapped(p_point, s);
}
-Variant _Geometry::ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
+Variant _Geometry::ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
Vector3 res;
- if (Geometry::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res))
+ if (Geometry::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res)) {
return res;
- else
+ } else {
return Variant();
+ }
}
-Variant _Geometry::segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
+Variant _Geometry::segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
Vector3 res;
- if (Geometry::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res))
+ if (Geometry::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res)) {
return res;
- else
+ } else {
return Variant();
+ }
}
bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
-
return Geometry::is_point_in_triangle(s, a, b, c);
}
Vector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) {
-
Vector<Vector3> r;
Vector3 res, norm;
- if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm))
+ if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm)) {
return r;
+ }
r.resize(2);
r.set(0, res);
r.set(1, norm);
return r;
}
-Vector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
+Vector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
Vector<Vector3> r;
Vector3 res, norm;
- if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm))
+ if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm)) {
return r;
+ }
r.resize(2);
r.set(0, res);
r.set(1, norm);
return r;
}
-Vector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes) {
+Vector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes) {
Vector<Vector3> r;
Vector3 res, norm;
- if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm))
+ if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm)) {
return r;
+ }
r.resize(2);
r.set(0, res);
@@ -1020,37 +954,30 @@ Vector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, cons
}
bool _Geometry::is_polygon_clockwise(const Vector<Vector2> &p_polygon) {
-
return Geometry::is_polygon_clockwise(p_polygon);
}
bool _Geometry::is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon) {
-
return Geometry::is_point_in_polygon(p_point, p_polygon);
}
Vector<int> _Geometry::triangulate_polygon(const Vector<Vector2> &p_polygon) {
-
return Geometry::triangulate_polygon(p_polygon);
}
Vector<int> _Geometry::triangulate_delaunay_2d(const Vector<Vector2> &p_points) {
-
return Geometry::triangulate_delaunay_2d(p_points);
}
Vector<Point2> _Geometry::convex_hull_2d(const Vector<Point2> &p_points) {
-
return Geometry::convex_hull_2d(p_points);
}
Vector<Vector3> _Geometry::clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane) {
-
return Geometry::clip_polygon(p_points, p_plane);
}
Array _Geometry::merge_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
-
Vector<Vector<Point2>> polys = Geometry::merge_polygons_2d(p_polygon_a, p_polygon_b);
Array ret;
@@ -1062,7 +989,6 @@ Array _Geometry::merge_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vec
}
Array _Geometry::clip_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
-
Vector<Vector<Point2>> polys = Geometry::clip_polygons_2d(p_polygon_a, p_polygon_b);
Array ret;
@@ -1074,7 +1000,6 @@ Array _Geometry::clip_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vect
}
Array _Geometry::intersect_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
-
Vector<Vector<Point2>> polys = Geometry::intersect_polygons_2d(p_polygon_a, p_polygon_b);
Array ret;
@@ -1086,7 +1011,6 @@ Array _Geometry::intersect_polygons_2d(const Vector<Vector2> &p_polygon_a, const
}
Array _Geometry::exclude_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
-
Vector<Vector<Point2>> polys = Geometry::exclude_polygons_2d(p_polygon_a, p_polygon_b);
Array ret;
@@ -1098,7 +1022,6 @@ Array _Geometry::exclude_polygons_2d(const Vector<Vector2> &p_polygon_a, const V
}
Array _Geometry::clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
-
Vector<Vector<Point2>> polys = Geometry::clip_polyline_with_polygon_2d(p_polyline, p_polygon);
Array ret;
@@ -1110,7 +1033,6 @@ Array _Geometry::clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline
}
Array _Geometry::intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
-
Vector<Vector<Point2>> polys = Geometry::intersect_polyline_with_polygon_2d(p_polyline, p_polygon);
Array ret;
@@ -1122,7 +1044,6 @@ Array _Geometry::intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_pol
}
Array _Geometry::offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
-
Vector<Vector<Point2>> polys = Geometry::offset_polygon_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type));
Array ret;
@@ -1134,7 +1055,6 @@ Array _Geometry::offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_de
}
Array _Geometry::offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
-
Vector<Vector<Point2>> polys = Geometry::offset_polyline_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type), Geometry::PolyEndType(p_end_type));
Array ret;
@@ -1146,12 +1066,10 @@ Array _Geometry::offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_d
}
Dictionary _Geometry::make_atlas(const Vector<Size2> &p_rects) {
-
Dictionary ret;
Vector<Size2i> rects;
for (int i = 0; i < p_rects.size(); i++) {
-
rects.push_back(p_rects[i]);
};
@@ -1163,7 +1081,6 @@ Dictionary _Geometry::make_atlas(const Vector<Size2> &p_rects) {
Size2 r_size = size;
Vector<Point2> r_result;
for (int i = 0; i < result.size(); i++) {
-
r_result.push_back(result[i]);
};
@@ -1174,12 +1091,10 @@ Dictionary _Geometry::make_atlas(const Vector<Size2> &p_rects) {
};
int _Geometry::get_uv84_normal_bit(const Vector3 &p_vector) {
-
return Geometry::get_uv84_normal_bit(p_vector);
}
void _Geometry::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &_Geometry::build_box_planes);
ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &_Geometry::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &_Geometry::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
@@ -1245,10 +1160,10 @@ void _Geometry::_bind_methods() {
////// _File //////
Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key) {
-
Error err = open(p_path, p_mode_flags);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse(f, p_key, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
@@ -1262,10 +1177,10 @@ Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const
}
Error _File::open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass) {
-
Error err = open(p_path, p_mode_flags);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse_password(f, p_pass, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
@@ -1280,7 +1195,6 @@ Error _File::open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, c
}
Error _File::open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode) {
-
FileAccessCompressed *fac = memnew(FileAccessCompressed);
fac->configure("GCPF", (Compression::Mode)p_compress_mode);
@@ -1297,110 +1211,104 @@ Error _File::open_compressed(const String &p_path, ModeFlags p_mode_flags, Compr
}
Error _File::open(const String &p_path, ModeFlags p_mode_flags) {
-
close();
Error err;
f = FileAccess::open(p_path, p_mode_flags, &err);
- if (f)
+ if (f) {
f->set_endian_swap(eswap);
+ }
return err;
}
void _File::close() {
-
- if (f)
+ if (f) {
memdelete(f);
+ }
f = nullptr;
}
-bool _File::is_open() const {
+bool _File::is_open() const {
return f != nullptr;
}
-String _File::get_path() const {
+String _File::get_path() const {
ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use.");
return f->get_path();
}
String _File::get_path_absolute() const {
-
ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use.");
return f->get_path_absolute();
}
void _File::seek(int64_t p_position) {
-
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->seek(p_position);
}
-void _File::seek_end(int64_t p_position) {
+void _File::seek_end(int64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->seek_end(p_position);
}
-int64_t _File::get_position() const {
+int64_t _File::get_position() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_position();
}
int64_t _File::get_len() const {
-
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_len();
}
bool _File::eof_reached() const {
-
ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use.");
return f->eof_reached();
}
uint8_t _File::get_8() const {
-
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_8();
}
-uint16_t _File::get_16() const {
+uint16_t _File::get_16() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_16();
}
-uint32_t _File::get_32() const {
+uint32_t _File::get_32() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_32();
}
-uint64_t _File::get_64() const {
+uint64_t _File::get_64() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_64();
}
float _File::get_float() const {
-
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_float();
}
-double _File::get_double() const {
+double _File::get_double() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_double();
}
-real_t _File::get_real() const {
+real_t _File::get_real() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_real();
}
Vector<uint8_t> _File::get_buffer(int p_length) const {
-
Vector<uint8_t> data;
ERR_FAIL_COND_V_MSG(!f, data, "File must be opened before use.");
ERR_FAIL_COND_V_MSG(p_length < 0, data, "Length of buffer cannot be smaller than 0.");
- if (p_length == 0)
+ if (p_length == 0) {
return data;
+ }
Error err = data.resize(p_length);
ERR_FAIL_COND_V_MSG(err != OK, data, "Can't resize data to " + itos(p_length) + " elements.");
@@ -1409,14 +1317,14 @@ Vector<uint8_t> _File::get_buffer(int p_length) const {
int len = f->get_buffer(&w[0], p_length);
ERR_FAIL_COND_V(len < 0, Vector<uint8_t>());
- if (len < p_length)
+ if (len < p_length) {
data.resize(p_length);
+ }
return data;
}
String _File::get_as_text() const {
-
ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use.");
String text;
@@ -1436,17 +1344,14 @@ String _File::get_as_text() const {
}
String _File::get_md5(const String &p_path) const {
-
return FileAccess::get_md5(p_path);
}
String _File::get_sha256(const String &p_path) const {
-
return FileAccess::get_sha256(p_path);
}
String _File::get_line() const {
-
ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use.");
return f->get_line();
}
@@ -1462,90 +1367,84 @@ Vector<String> _File::get_csv_line(const String &p_delim) const {
*/
void _File::set_endian_swap(bool p_swap) {
-
eswap = p_swap;
- if (f)
+ if (f) {
f->set_endian_swap(p_swap);
+ }
}
-bool _File::get_endian_swap() {
+bool _File::get_endian_swap() {
return eswap;
}
Error _File::get_error() const {
-
- if (!f)
+ if (!f) {
return ERR_UNCONFIGURED;
+ }
return f->get_error();
}
void _File::store_8(uint8_t p_dest) {
-
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->store_8(p_dest);
}
-void _File::store_16(uint16_t p_dest) {
+void _File::store_16(uint16_t p_dest) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->store_16(p_dest);
}
-void _File::store_32(uint32_t p_dest) {
+void _File::store_32(uint32_t p_dest) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->store_32(p_dest);
}
-void _File::store_64(uint64_t p_dest) {
+void _File::store_64(uint64_t p_dest) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->store_64(p_dest);
}
void _File::store_float(float p_dest) {
-
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->store_float(p_dest);
}
-void _File::store_double(double p_dest) {
+void _File::store_double(double p_dest) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->store_double(p_dest);
}
-void _File::store_real(real_t p_real) {
+void _File::store_real(real_t p_real) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->store_real(p_real);
}
void _File::store_string(const String &p_string) {
-
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->store_string(p_string);
}
void _File::store_pascal_string(const String &p_string) {
-
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->store_pascal_string(p_string);
};
String _File::get_pascal_string() {
-
ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use.");
return f->get_pascal_string();
};
void _File::store_line(const String &p_string) {
-
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
f->store_line(p_string);
}
@@ -1556,12 +1455,12 @@ void _File::store_csv_line(const Vector<String> &p_values, const String &p_delim
}
void _File::store_buffer(const Vector<uint8_t> &p_buffer) {
-
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
int len = p_buffer.size();
- if (len == 0)
+ if (len == 0) {
return;
+ }
const uint8_t *r = p_buffer.ptr();
@@ -1569,12 +1468,10 @@ void _File::store_buffer(const Vector<uint8_t> &p_buffer) {
}
bool _File::file_exists(const String &p_name) const {
-
return FileAccess::exists(p_name);
}
void _File::store_var(const Variant &p_var, bool p_full_objects) {
-
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
int len;
Error err = encode_variant(p_var, nullptr, len, p_full_objects);
@@ -1592,7 +1489,6 @@ void _File::store_var(const Variant &p_var, bool p_full_objects) {
}
Variant _File::get_var(bool p_allow_objects) const {
-
ERR_FAIL_COND_V_MSG(!f, Variant(), "File must be opened before use.");
uint32_t len = get_32();
Vector<uint8_t> buff = get_buffer(len);
@@ -1608,12 +1504,10 @@ Variant _File::get_var(bool p_allow_objects) const {
}
uint64_t _File::get_modified_time(const String &p_file) const {
-
return FileAccess::get_modified_time(p_file);
}
void _File::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("open_encrypted", "path", "mode_flags", "key"), &_File::open_encrypted);
ClassDB::bind_method(D_METHOD("open_encrypted_with_pass", "path", "mode_flags", "pass"), &_File::open_encrypted_pass);
ClassDB::bind_method(D_METHOD("open_compressed", "path", "mode_flags", "compression_mode"), &_File::open_compressed, DEFVAL(0));
@@ -1679,8 +1573,9 @@ void _File::_bind_methods() {
}
_File::~_File() {
- if (f)
+ if (f) {
memdelete(f);
+ }
}
////// _Directory //////
@@ -1689,17 +1584,18 @@ Error _Directory::open(const String &p_path) {
Error err;
DirAccess *alt = DirAccess::open(p_path, &err);
- if (!alt)
+ if (!alt) {
return err;
- if (d)
+ }
+ if (d) {
memdelete(d);
+ }
d = alt;
return OK;
}
Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) {
-
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
_list_skip_navigational = p_skip_navigational;
@@ -1709,55 +1605,51 @@ Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) {
}
String _Directory::get_next() {
-
ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
String next = d->get_next();
while (next != "" && ((_list_skip_navigational && (next == "." || next == "..")) || (_list_skip_hidden && d->current_is_hidden()))) {
-
next = d->get_next();
}
return next;
}
-bool _Directory::current_is_dir() const {
+bool _Directory::current_is_dir() const {
ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
return d->current_is_dir();
}
void _Directory::list_dir_end() {
-
ERR_FAIL_COND_MSG(!d, "Directory must be opened before use.");
d->list_dir_end();
}
int _Directory::get_drive_count() {
-
ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
return d->get_drive_count();
}
-String _Directory::get_drive(int p_drive) {
+String _Directory::get_drive(int p_drive) {
ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
return d->get_drive(p_drive);
}
+
int _Directory::get_current_drive() {
ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
return d->get_current_drive();
}
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() {
ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
return d->get_current_dir();
}
-Error _Directory::make_dir(String p_dir) {
+Error _Directory::make_dir(String p_dir) {
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
if (!p_dir.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_dir);
@@ -1767,8 +1659,8 @@ Error _Directory::make_dir(String p_dir) {
}
return d->make_dir(p_dir);
}
-Error _Directory::make_dir_recursive(String p_dir) {
+Error _Directory::make_dir_recursive(String p_dir) {
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
if (!p_dir.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_dir);
@@ -1780,7 +1672,6 @@ Error _Directory::make_dir_recursive(String p_dir) {
}
bool _Directory::file_exists(String p_file) {
-
ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
if (!p_file.is_rel_path()) {
@@ -1793,7 +1684,6 @@ bool _Directory::file_exists(String p_file) {
bool _Directory::dir_exists(String p_dir) {
ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
if (!p_dir.is_rel_path()) {
-
DirAccess *d = DirAccess::create_for_path(p_dir);
bool exists = d->dir_exists(p_dir);
memdelete(d);
@@ -1805,18 +1695,16 @@ bool _Directory::dir_exists(String p_dir) {
}
int _Directory::get_space_left() {
-
ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
return d->get_space_left() / 1024 * 1024; //return value in megabytes, given binding is int
}
Error _Directory::copy(String p_from, String p_to) {
-
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
return d->copy(p_from, p_to);
}
-Error _Directory::rename(String p_from, String p_to) {
+Error _Directory::rename(String p_from, String p_to) {
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
if (!p_from.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_from);
@@ -1827,8 +1715,8 @@ Error _Directory::rename(String p_from, String p_to) {
return d->rename(p_from, p_to);
}
-Error _Directory::remove(String p_name) {
+Error _Directory::remove(String p_name) {
ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
if (!p_name.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_name);
@@ -1841,7 +1729,6 @@ Error _Directory::remove(String p_name) {
}
void _Directory::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("open", "path"), &_Directory::open);
ClassDB::bind_method(D_METHOD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_next"), &_Directory::get_next);
@@ -1868,8 +1755,9 @@ _Directory::_Directory() {
}
_Directory::~_Directory() {
- if (d)
+ if (d) {
memdelete(d);
+ }
}
////// _Marshalls //////
@@ -1881,7 +1769,6 @@ _Marshalls *_Marshalls::get_singleton() {
}
String _Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) {
-
int len;
Error err = encode_variant(p_var, nullptr, len, p_full_objects);
ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
@@ -1900,7 +1787,6 @@ String _Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects)
};
Variant _Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) {
-
int strlen = p_str.length();
CharString cstr = p_str.ascii();
@@ -1919,14 +1805,12 @@ Variant _Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects)
};
String _Marshalls::raw_to_base64(const Vector<uint8_t> &p_arr) {
-
String ret = CryptoCore::b64_encode_str(p_arr.ptr(), p_arr.size());
ERR_FAIL_COND_V(ret == "", ret);
return ret;
};
Vector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) {
-
int strlen = p_str.length();
CharString cstr = p_str.ascii();
@@ -1944,7 +1828,6 @@ Vector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) {
};
String _Marshalls::utf8_to_base64(const String &p_str) {
-
CharString cstr = p_str.utf8();
String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length());
ERR_FAIL_COND_V(ret == "", ret);
@@ -1952,7 +1835,6 @@ String _Marshalls::utf8_to_base64(const String &p_str) {
};
String _Marshalls::base64_to_utf8(const String &p_str) {
-
int strlen = p_str.length();
CharString cstr = p_str.ascii();
@@ -1970,7 +1852,6 @@ String _Marshalls::base64_to_utf8(const String &p_str) {
};
void _Marshalls::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("variant_to_base64", "variant", "full_objects"), &_Marshalls::variant_to_base64, DEFVAL(false));
ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str", "allow_objects"), &_Marshalls::base64_to_variant, DEFVAL(false));
@@ -1984,22 +1865,18 @@ void _Marshalls::_bind_methods() {
////// _Semaphore //////
void _Semaphore::wait() {
-
semaphore.wait();
}
Error _Semaphore::try_wait() {
-
return semaphore.try_wait() ? OK : ERR_BUSY;
}
void _Semaphore::post() {
-
semaphore.post();
}
void _Semaphore::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("wait"), &_Semaphore::wait);
ClassDB::bind_method(D_METHOD("try_wait"), &_Semaphore::try_wait);
ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post);
@@ -2008,22 +1885,18 @@ void _Semaphore::_bind_methods() {
////// _Mutex //////
void _Mutex::lock() {
-
mutex.lock();
}
Error _Mutex::try_lock() {
-
return mutex.try_lock();
}
void _Mutex::unlock() {
-
mutex.unlock();
}
void _Mutex::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("lock"), &_Mutex::lock);
ClassDB::bind_method(D_METHOD("try_lock"), &_Mutex::try_lock);
ClassDB::bind_method(D_METHOD("unlock"), &_Mutex::unlock);
@@ -2032,7 +1905,6 @@ void _Mutex::_bind_methods() {
////// _Thread //////
void _Thread::_start_func(void *ud) {
-
Ref<_Thread> *tud = (Ref<_Thread> *)ud;
Ref<_Thread> t = *tud;
memdelete(tud);
@@ -2043,23 +1915,18 @@ void _Thread::_start_func(void *ud) {
t->ret = t->target_instance->call(t->target_method, arg, 1, ce);
if (ce.error != Callable::CallError::CALL_OK) {
-
String reason;
switch (ce.error) {
case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: {
-
reason = "Invalid Argument #" + itos(ce.argument);
} break;
case Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: {
-
reason = "Too Many Arguments";
} break;
case Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: {
-
reason = "Too Few Arguments";
} break;
case Callable::CallError::CALL_ERROR_INVALID_METHOD: {
-
reason = "Method Not Found";
} break;
default: {
@@ -2071,7 +1938,6 @@ void _Thread::_start_func(void *ud) {
}
Error _Thread::start(Object *p_instance, const StringName &p_method, const Variant &p_userdata, Priority p_priority) {
-
ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "Thread already started.");
ERR_FAIL_COND_V(!p_instance, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(p_method == StringName(), ERR_INVALID_PARAMETER);
@@ -2100,19 +1966,18 @@ Error _Thread::start(Object *p_instance, const StringName &p_method, const Varia
}
String _Thread::get_id() const {
-
- if (!thread)
+ if (!thread) {
return String();
+ }
return itos(thread->get_id());
}
bool _Thread::is_active() const {
-
return active;
}
-Variant _Thread::wait_to_finish() {
+Variant _Thread::wait_to_finish() {
ERR_FAIL_COND_V_MSG(!thread, Variant(), "Thread must exist to wait for its completion.");
ERR_FAIL_COND_V_MSG(!active, Variant(), "Thread must be active to wait for its completion.");
Thread::wait_to_finish(thread);
@@ -2121,15 +1986,15 @@ Variant _Thread::wait_to_finish() {
target_method = StringName();
target_instance = nullptr;
userdata = Variant();
- if (thread)
+ if (thread) {
memdelete(thread);
+ }
thread = nullptr;
return r;
}
void _Thread::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("start", "instance", "method", "userdata", "priority"), &_Thread::start, DEFVAL(Variant()), DEFVAL(PRIORITY_NORMAL));
ClassDB::bind_method(D_METHOD("get_id"), &_Thread::get_id);
ClassDB::bind_method(D_METHOD("is_active"), &_Thread::is_active);
@@ -2147,7 +2012,6 @@ _Thread::~_Thread() {
////// _ClassDB //////
PackedStringArray _ClassDB::get_class_list() const {
-
List<StringName> classes;
ClassDB::get_class_list(&classes);
@@ -2160,8 +2024,8 @@ PackedStringArray _ClassDB::get_class_list() const {
return ret;
}
-PackedStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class) const {
+PackedStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class) const {
List<StringName> classes;
ClassDB::get_inheriters_from_class(p_class, &classes);
@@ -2174,27 +2038,28 @@ PackedStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class)
return ret;
}
-StringName _ClassDB::get_parent_class(const StringName &p_class) const {
+StringName _ClassDB::get_parent_class(const StringName &p_class) const {
return ClassDB::get_parent_class(p_class);
}
-bool _ClassDB::class_exists(const StringName &p_class) const {
+bool _ClassDB::class_exists(const StringName &p_class) const {
return ClassDB::class_exists(p_class);
}
-bool _ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const {
+bool _ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const {
return ClassDB::is_parent_class(p_class, p_inherits);
}
-bool _ClassDB::can_instance(const StringName &p_class) const {
+bool _ClassDB::can_instance(const StringName &p_class) const {
return ClassDB::can_instance(p_class);
}
-Variant _ClassDB::instance(const StringName &p_class) const {
+Variant _ClassDB::instance(const StringName &p_class) const {
Object *obj = ClassDB::instance(p_class);
- if (!obj)
+ if (!obj) {
return Variant();
+ }
Reference *r = Object::cast_to<Reference>(obj);
if (r) {
@@ -2205,11 +2070,10 @@ Variant _ClassDB::instance(const StringName &p_class) const {
}
bool _ClassDB::has_signal(StringName p_class, StringName p_signal) const {
-
return ClassDB::has_signal(p_class, p_signal);
}
-Dictionary _ClassDB::get_signal(StringName p_class, StringName p_signal) const {
+Dictionary _ClassDB::get_signal(StringName p_class, StringName p_signal) const {
MethodInfo signal;
if (ClassDB::get_signal(p_class, p_signal, &signal)) {
return signal.operator Dictionary();
@@ -2217,8 +2081,8 @@ Dictionary _ClassDB::get_signal(StringName p_class, StringName p_signal) const {
return Dictionary();
}
}
-Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const {
+Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const {
List<MethodInfo> signals;
ClassDB::get_signal_list(p_class, &signals, p_no_inheritance);
Array ret;
@@ -2231,7 +2095,6 @@ Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const
}
Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) const {
-
List<PropertyInfo> plist;
ClassDB::get_property_list(p_class, &plist, p_no_inheritance);
Array ret;
@@ -2260,12 +2123,10 @@ Error _ClassDB::set_property(Object *p_object, const StringName &p_property, con
}
bool _ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) const {
-
return ClassDB::has_method(p_class, p_method, p_no_inheritance);
}
Array _ClassDB::get_method_list(StringName p_class, bool p_no_inheritance) const {
-
List<MethodInfo> methods;
ClassDB::get_method_list(p_class, &methods, p_no_inheritance);
Array ret;
@@ -2284,7 +2145,6 @@ Array _ClassDB::get_method_list(StringName p_class, bool p_no_inheritance) const
}
PackedStringArray _ClassDB::get_integer_constant_list(const StringName &p_class, bool p_no_inheritance) const {
-
List<String> constants;
ClassDB::get_integer_constant_list(p_class, &constants, p_no_inheritance);
@@ -2299,31 +2159,27 @@ PackedStringArray _ClassDB::get_integer_constant_list(const StringName &p_class,
}
bool _ClassDB::has_integer_constant(const StringName &p_class, const StringName &p_name) const {
-
bool success;
ClassDB::get_integer_constant(p_class, p_name, &success);
return success;
}
int _ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name) const {
-
bool found;
int c = ClassDB::get_integer_constant(p_class, p_name, &found);
ERR_FAIL_COND_V(!found, 0);
return c;
}
-StringName _ClassDB::get_category(const StringName &p_node) const {
+StringName _ClassDB::get_category(const StringName &p_node) const {
return ClassDB::get_category(p_node);
}
bool _ClassDB::is_class_enabled(StringName p_class) const {
-
return ClassDB::is_class_enabled(p_class);
}
void _ClassDB::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_class_list"), &_ClassDB::get_class_list);
ClassDB::bind_method(D_METHOD("get_inheriters_from_class", "class"), &_ClassDB::get_inheriters_from_class);
ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &_ClassDB::get_parent_class);
@@ -2356,11 +2212,10 @@ void _ClassDB::_bind_methods() {
////// _Engine //////
void _Engine::set_iterations_per_second(int p_ips) {
-
Engine::get_singleton()->set_iterations_per_second(p_ips);
}
-int _Engine::get_iterations_per_second() const {
+int _Engine::get_iterations_per_second() const {
return Engine::get_singleton()->get_iterations_per_second();
}
@@ -2385,17 +2240,14 @@ int _Engine::get_target_fps() const {
}
float _Engine::get_frames_per_second() const {
-
return Engine::get_singleton()->get_frames_per_second();
}
uint64_t _Engine::get_physics_frames() const {
-
return Engine::get_singleton()->get_physics_frames();
}
uint64_t _Engine::get_idle_frames() const {
-
return Engine::get_singleton()->get_idle_frames();
}
@@ -2404,23 +2256,19 @@ void _Engine::set_time_scale(float p_scale) {
}
float _Engine::get_time_scale() {
-
return Engine::get_singleton()->get_time_scale();
}
int _Engine::get_frames_drawn() {
-
return Engine::get_singleton()->get_frames_drawn();
}
MainLoop *_Engine::get_main_loop() const {
-
//needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
return OS::get_singleton()->get_main_loop();
}
Dictionary _Engine::get_version_info() const {
-
return Engine::get_singleton()->get_version_info();
}
@@ -2449,27 +2297,22 @@ bool _Engine::is_in_physics_frame() const {
}
bool _Engine::has_singleton(const String &p_name) const {
-
return Engine::get_singleton()->has_singleton(p_name);
}
Object *_Engine::get_singleton_object(const String &p_name) const {
-
return Engine::get_singleton()->get_singleton_object(p_name);
}
void _Engine::set_editor_hint(bool p_enabled) {
-
Engine::get_singleton()->set_editor_hint(p_enabled);
}
bool _Engine::is_editor_hint() const {
-
return Engine::get_singleton()->is_editor_hint();
}
void _Engine::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_iterations_per_second", "iterations_per_second"), &_Engine::set_iterations_per_second);
ClassDB::bind_method(D_METHOD("get_iterations_per_second"), &_Engine::get_iterations_per_second);
ClassDB::bind_method(D_METHOD("set_physics_jitter_fix", "physics_jitter_fix"), &_Engine::set_physics_jitter_fix);
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 44e573ccbe..32ddcf2c74 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -254,7 +254,6 @@ VARIANT_ENUM_CAST(_OS::Month);
VARIANT_ENUM_CAST(_OS::SystemDir);
class _Geometry : public Object {
-
GDCLASS(_Geometry, Object);
static _Geometry *singleton;
@@ -437,7 +436,6 @@ VARIANT_ENUM_CAST(_File::ModeFlags);
VARIANT_ENUM_CAST(_File::CompressionMode);
class _Directory : public Reference {
-
GDCLASS(_Directory, Reference);
DirAccess *d;
@@ -481,7 +479,6 @@ private:
};
class _Marshalls : public Object {
-
GDCLASS(_Marshalls, Object);
static _Marshalls *singleton;
@@ -506,7 +503,6 @@ public:
};
class _Mutex : public Reference {
-
GDCLASS(_Mutex, Reference);
Mutex mutex;
@@ -519,7 +515,6 @@ public:
};
class _Semaphore : public Reference {
-
GDCLASS(_Semaphore, Reference);
Semaphore semaphore;
@@ -532,7 +527,6 @@ public:
};
class _Thread : public Reference {
-
GDCLASS(_Thread, Reference);
protected:
@@ -566,7 +560,6 @@ public:
VARIANT_ENUM_CAST(_Thread::Priority);
class _ClassDB : public Object {
-
GDCLASS(_ClassDB, Object);
protected:
diff --git a/core/callable.cpp b/core/callable.cpp
index 447cf78bea..b7bdc715f8 100644
--- a/core/callable.cpp
+++ b/core/callable.cpp
@@ -40,7 +40,6 @@ void Callable::call_deferred(const Variant **p_arguments, int p_argcount) const
}
void Callable::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, CallError &r_call_error) const {
-
if (is_null()) {
r_call_error.error = CallError::CALL_ERROR_INSTANCE_IS_NULL;
r_call_error.argument = 0;
@@ -73,6 +72,7 @@ ObjectID Callable::get_object_id() const {
return ObjectID(object);
}
}
+
StringName Callable::get_method() const {
ERR_FAIL_COND_V_MSG(is_custom(), StringName(),
vformat("Can't get method on CallableCustom \"%s\".", operator String()));
@@ -118,9 +118,11 @@ bool Callable::operator==(const Callable &p_callable) const {
return false;
}
}
+
bool Callable::operator!=(const Callable &p_callable) const {
return !(*this == p_callable);
}
+
bool Callable::operator<(const Callable &p_callable) const {
bool custom_a = is_custom();
bool custom_b = p_callable.is_custom();
@@ -179,7 +181,6 @@ void Callable::operator=(const Callable &p_callable) {
}
Callable::operator String() const {
-
if (is_custom()) {
return custom->get_as_text();
} else {
@@ -192,7 +193,6 @@ Callable::operator String() const {
String class_name = base->get_class();
Ref<Script> script = base->get_script();
if (script.is_valid() && script->get_path().is_resource_file()) {
-
class_name += "(" + script->get_path().get_file() + ")";
}
return class_name + "::" + String(method);
@@ -225,6 +225,7 @@ Callable::Callable(ObjectID p_object, const StringName &p_method) {
object = p_object;
method = p_method;
}
+
Callable::Callable(CallableCustom *p_custom) {
if (p_custom->referenced) {
object = 0;
@@ -234,6 +235,7 @@ Callable::Callable(CallableCustom *p_custom) {
object = 0; //ensure object is all zero, since pointer may be 32 bits
custom = p_custom;
}
+
Callable::Callable(const Callable &p_callable) {
if (p_callable.is_custom()) {
if (!p_callable.custom->ref_count.ref()) {
@@ -265,9 +267,11 @@ CallableCustom::CallableCustom() {
Object *Signal::get_object() const {
return ObjectDB::get_instance(object);
}
+
ObjectID Signal::get_object_id() const {
return object;
}
+
StringName Signal::get_name() const {
return name;
}
@@ -294,7 +298,6 @@ Signal::operator String() const {
String class_name = base->get_class();
Ref<Script> script = base->get_script();
if (script.is_valid() && script->get_path().is_resource_file()) {
-
class_name += "(" + script->get_path().get_file() + ")";
}
return class_name + "::[signal]" + String(name);
@@ -311,18 +314,20 @@ Error Signal::emit(const Variant **p_arguments, int p_argcount) const {
return obj->emit_signal(name, p_arguments, p_argcount);
}
-Error Signal::connect(const Callable &p_callable, const Vector<Variant> &p_binds, uint32_t p_flags) {
+Error Signal::connect(const Callable &p_callable, const Vector<Variant> &p_binds, uint32_t p_flags) {
Object *object = get_object();
ERR_FAIL_COND_V(!object, ERR_UNCONFIGURED);
return object->connect(name, p_callable, p_binds, p_flags);
}
+
void Signal::disconnect(const Callable &p_callable) {
Object *object = get_object();
ERR_FAIL_COND(!object);
object->disconnect(name, p_callable);
}
+
bool Signal::is_connected(const Callable &p_callable) const {
Object *object = get_object();
ERR_FAIL_COND_V(!object, false);
@@ -347,7 +352,6 @@ Array Signal::get_connections() const {
}
Signal::Signal(const Object *p_object, const StringName &p_name) {
-
ERR_FAIL_COND_MSG(p_object == nullptr, "Object argument to Signal constructor must be non-null");
object = p_object->get_instance_id();
@@ -355,7 +359,6 @@ Signal::Signal(const Object *p_object, const StringName &p_name) {
}
Signal::Signal(ObjectID p_object, const StringName &p_name) {
-
object = p_object;
name = p_name;
}
diff --git a/core/callable.h b/core/callable.h
index 1f6ff48d4f..7fd6b54cf7 100644
--- a/core/callable.h
+++ b/core/callable.h
@@ -45,7 +45,6 @@ class CallableCustom;
// but can be optimized or customized.
class Callable {
-
//needs to be max 16 bytes in 64 bits
StringName method;
union {
diff --git a/core/callable_method_pointer.cpp b/core/callable_method_pointer.cpp
index 8774af6add..21a917cbd7 100644
--- a/core/callable_method_pointer.cpp
+++ b/core/callable_method_pointer.cpp
@@ -48,7 +48,6 @@ bool CallableCustomMethodPointerBase::compare_equal(const CallableCustom *p_a, c
}
bool CallableCustomMethodPointerBase::compare_less(const CallableCustom *p_a, const CallableCustom *p_b) {
-
const CallableCustomMethodPointerBase *a = static_cast<const CallableCustomMethodPointerBase *>(p_a);
const CallableCustomMethodPointerBase *b = static_cast<const CallableCustomMethodPointerBase *>(p_b);
diff --git a/core/callable_method_pointer.h b/core/callable_method_pointer.h
index fb809c2b44..3b0503e259 100644
--- a/core/callable_method_pointer.h
+++ b/core/callable_method_pointer.h
@@ -38,7 +38,6 @@
#include "core/simple_type.h"
class CallableCustomMethodPointerBase : public CallableCustom {
-
uint32_t *comp_ptr;
uint32_t comp_size;
uint32_t h;
@@ -74,7 +73,6 @@ public:
template <class T>
struct VariantCasterAndValidate {
-
static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) {
Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE;
if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype)) {
@@ -89,7 +87,6 @@ struct VariantCasterAndValidate {
template <class T>
struct VariantCasterAndValidate<T &> {
-
static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) {
Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE;
if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype)) {
@@ -104,7 +101,6 @@ struct VariantCasterAndValidate<T &> {
template <class T>
struct VariantCasterAndValidate<const T &> {
-
static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) {
Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE;
if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype)) {
@@ -163,7 +159,6 @@ void call_with_variant_args(T *p_instance, void (T::*p_method)(P...), const Vari
template <class T, class... P>
class CallableCustomMethodPointer : public CallableCustomMethodPointerBase {
-
struct Data {
T *instance;
void (T::*method)(P...);
@@ -173,7 +168,6 @@ public:
virtual ObjectID get_object() const { return data.instance->get_instance_id(); }
virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
-
call_with_variant_args(data.instance, data.method, p_arguments, p_argcount, r_call_error);
}
@@ -246,7 +240,6 @@ void call_with_variant_args_ret(T *p_instance, R (T::*p_method)(P...), const Var
template <class T, class R, class... P>
class CallableCustomMethodPointerRet : public CallableCustomMethodPointerBase {
-
struct Data {
T *instance;
R(T::*method)
@@ -257,7 +250,6 @@ public:
virtual ObjectID get_object() const { return data.instance->get_instance_id(); }
virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
-
call_with_variant_args_ret(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error);
}
diff --git a/core/class_db.cpp b/core/class_db.cpp
index dd9fba16d3..eed9ec17cb 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -40,14 +40,12 @@
#ifdef DEBUG_METHODS_ENABLED
MethodDefinition D_METHOD(const char *p_name) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
return md;
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.push_back(StaticCString::create(p_arg1));
@@ -55,7 +53,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) {
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(2);
@@ -65,7 +62,6 @@ 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) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(3);
@@ -76,7 +72,6 @@ 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) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(4);
@@ -88,7 +83,6 @@ 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) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(5);
@@ -101,7 +95,6 @@ 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) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(6);
@@ -115,7 +108,6 @@ 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) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(7);
@@ -130,7 +122,6 @@ 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) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(8);
@@ -146,7 +137,6 @@ 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 md;
md.name = StaticCString::create(p_name);
md.args.resize(9);
@@ -163,7 +153,6 @@ 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, const char *p_arg10) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(10);
@@ -181,7 +170,6 @@ 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, const char *p_arg10, const char *p_arg11) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(11);
@@ -200,7 +188,6 @@ 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, const char *p_arg10, const char *p_arg11, const char *p_arg12) {
-
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(12);
@@ -220,7 +207,6 @@ 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, 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);
@@ -245,12 +231,10 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
ClassDB::APIType ClassDB::current_api = API_CORE;
void ClassDB::set_current_api(APIType p_api) {
-
current_api = p_api;
}
ClassDB::APIType ClassDB::get_current_api() {
-
return current_api;
}
@@ -259,28 +243,26 @@ HashMap<StringName, StringName> ClassDB::resource_base_extensions;
HashMap<StringName, StringName> ClassDB::compat_classes;
bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) {
-
OBJTYPE_RLOCK;
StringName inherits = p_class;
while (inherits.operator String().length()) {
-
- if (inherits == p_inherits)
+ if (inherits == p_inherits) {
return true;
+ }
inherits = get_parent_class(inherits);
}
return false;
}
-void ClassDB::get_class_list(List<StringName> *p_classes) {
+void ClassDB::get_class_list(List<StringName> *p_classes) {
OBJTYPE_RLOCK;
const StringName *k = nullptr;
while ((k = classes.next(k))) {
-
p_classes->push_back(*k);
}
@@ -288,43 +270,40 @@ void ClassDB::get_class_list(List<StringName> *p_classes) {
}
void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
-
OBJTYPE_RLOCK;
const StringName *k = nullptr;
while ((k = classes.next(k))) {
-
- if (*k != p_class && is_parent_class(*k, p_class))
+ if (*k != p_class && is_parent_class(*k, p_class)) {
p_classes->push_back(*k);
+ }
}
}
void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
-
OBJTYPE_RLOCK;
const StringName *k = nullptr;
while ((k = classes.next(k))) {
-
- if (*k != p_class && get_parent_class(*k) == p_class)
+ if (*k != p_class && get_parent_class(*k) == p_class) {
p_classes->push_back(*k);
+ }
}
}
StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
-
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
- if (!ti)
+ if (!ti) {
return StringName();
+ }
return ti->inherits;
}
StringName ClassDB::get_compatibility_remapped_class(const StringName &p_class) {
-
if (classes.has(p_class)) {
return p_class;
}
@@ -337,7 +316,6 @@ StringName ClassDB::get_compatibility_remapped_class(const StringName &p_class)
}
StringName ClassDB::get_parent_class(const StringName &p_class) {
-
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
@@ -346,7 +324,6 @@ StringName ClassDB::get_parent_class(const StringName &p_class) {
}
ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
-
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
@@ -356,7 +333,6 @@ ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
}
uint64_t ClassDB::get_api_hash(APIType p_api) {
-
OBJTYPE_RLOCK;
#ifdef DEBUG_METHODS_ENABLED
@@ -367,18 +343,17 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
const StringName *k = nullptr;
while ((k = classes.next(k))) {
-
names.push_back(*k);
}
//must be alphabetically sorted for hash to compute
names.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
-
ClassInfo *t = classes.getptr(E->get());
ERR_FAIL_COND_V_MSG(!t, 0, "Cannot get class '" + String(E->get()) + "'.");
- if (t->api != p_api || !t->exposed)
+ if (t->api != p_api || !t->exposed) {
continue;
+ }
hash = hash_djb2_one_64(t->name.hash(), hash);
hash = hash_djb2_one_64(t->inherits.hash(), hash);
@@ -389,13 +364,13 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
k = nullptr;
while ((k = t->method_map.next(k))) {
-
String name = k->operator String();
ERR_CONTINUE(name.empty());
- if (name[0] == '_')
+ if (name[0] == '_') {
continue; // Ignore non-virtual methods that start with an underscore
+ }
snames.push_back(*k);
}
@@ -403,7 +378,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
snames.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
-
MethodBind *mb = t->method_map[F->get()];
hash = hash_djb2_one_64(mb->get_name().hash(), hash);
hash = hash_djb2_one_64(mb->get_argument_count(), hash);
@@ -436,14 +410,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
k = nullptr;
while ((k = t->constant_map.next(k))) {
-
snames.push_back(*k);
}
snames.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
-
hash = hash_djb2_one_64(F->get().hash(), hash);
hash = hash_djb2_one_64(t->constant_map[F->get()], hash);
}
@@ -456,14 +428,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
k = nullptr;
while ((k = t->signal_map.next(k))) {
-
snames.push_back(*k);
}
snames.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
-
MethodInfo &mi = t->signal_map[F->get()];
hash = hash_djb2_one_64(F->get().hash(), hash);
for (int i = 0; i < mi.arguments.size(); i++) {
@@ -479,14 +449,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
k = nullptr;
while ((k = t->property_setget.next(k))) {
-
snames.push_back(*k);
}
snames.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
-
PropertySetGet *psg = t->property_setget.getptr(F->get());
ERR_FAIL_COND_V(!psg, 0);
@@ -498,7 +466,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
//property list
for (List<PropertyInfo>::Element *F = t->property_list.front(); F; F = F->next()) {
-
hash = hash_djb2_one_64(F->get().name.hash(), hash);
hash = hash_djb2_one_64(F->get().type, hash);
hash = hash_djb2_one_64(F->get().hint, hash);
@@ -514,19 +481,16 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
}
bool ClassDB::class_exists(const StringName &p_class) {
-
OBJTYPE_RLOCK;
return classes.has(p_class);
}
void ClassDB::add_compatibility_class(const StringName &p_class, const StringName &p_fallback) {
-
OBJTYPE_WLOCK;
compat_classes[p_class] = p_fallback;
}
Object *ClassDB::instance(const StringName &p_class) {
-
ClassInfo *ti;
{
OBJTYPE_RLOCK;
@@ -548,8 +512,8 @@ Object *ClassDB::instance(const StringName &p_class) {
#endif
return ti->creation_func();
}
-bool ClassDB::can_instance(const StringName &p_class) {
+bool ClassDB::can_instance(const StringName &p_class) {
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
@@ -563,7 +527,6 @@ bool ClassDB::can_instance(const StringName &p_class) {
}
void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherits) {
-
OBJTYPE_WLOCK;
const StringName &name = p_class;
@@ -577,7 +540,6 @@ void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherit
ti.api = current_api;
if (ti.inherits) {
-
ERR_FAIL_COND(!classes.has(ti.inherits)); //it MUST be registered.
ti.inherits_ptr = &classes[ti.inherits];
@@ -587,17 +549,15 @@ void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherit
}
void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, bool p_no_inheritance, bool p_exclude_from_properties) {
-
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
-
if (type->disabled) {
-
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
continue;
@@ -606,22 +566,20 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
#ifdef DEBUG_METHODS_ENABLED
for (List<MethodInfo>::Element *E = type->virtual_methods.front(); E; E = E->next()) {
-
p_methods->push_back(E->get());
}
for (List<StringName>::Element *E = type->method_order.front(); E; E = E->next()) {
-
MethodBind *method = type->method_map.get(E->get());
MethodInfo minfo;
minfo.name = E->get();
minfo.id = method->get_method_id();
- if (p_exclude_from_properties && type->methods_in_properties.has(minfo.name))
+ if (p_exclude_from_properties && type->methods_in_properties.has(minfo.name)) {
continue;
+ }
for (int i = 0; i < method->get_argument_count(); i++) {
-
//Variant::Type t=method->get_argument_type(i);
minfo.arguments.push_back(method->get_argument_info(i));
@@ -631,8 +589,9 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
minfo.flags = method->get_hint_flags();
for (int i = 0; i < method->get_argument_count(); i++) {
- if (method->has_default_argument(i))
+ if (method->has_default_argument(i)) {
minfo.default_arguments.push_back(method->get_default_argument(i));
+ }
}
p_methods->push_back(minfo);
@@ -643,7 +602,6 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
const StringName *K = nullptr;
while ((K = type->method_map.next(K))) {
-
MethodBind *m = type->method_map[*K];
MethodInfo mi;
mi.name = m->get_name();
@@ -652,31 +610,30 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
#endif
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
}
}
MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) {
-
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
-
MethodBind **method = type->method_map.getptr(p_name);
- if (method && *method)
+ if (method && *method) {
return *method;
+ }
type = type->inherits_ptr;
}
return nullptr;
}
void ClassDB::bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int p_constant) {
-
OBJTYPE_WLOCK;
ClassInfo *type = classes.getptr(p_class);
@@ -684,7 +641,6 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName
ERR_FAIL_COND(!type);
if (type->constant_map.has(p_name)) {
-
ERR_FAIL();
}
@@ -713,16 +669,15 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName
}
void ClassDB::get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance) {
-
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
-
#ifdef DEBUG_METHODS_ENABLED
- for (List<StringName>::Element *E = type->constant_order.front(); E; E = E->next())
+ for (List<StringName>::Element *E = type->constant_order.front(); E; E = E->next()) {
p_constants->push_back(E->get());
+ }
#else
const StringName *K = nullptr;
@@ -731,57 +686,56 @@ void ClassDB::get_integer_constant_list(const StringName &p_class, List<String>
}
#endif
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
}
}
int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success) {
-
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
-
int *constant = type->constant_map.getptr(p_name);
if (constant) {
-
- if (p_success)
+ if (p_success) {
*p_success = true;
+ }
return *constant;
}
type = type->inherits_ptr;
}
- if (p_success)
+ if (p_success) {
*p_success = false;
+ }
return 0;
}
StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) {
-
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
-
const StringName *k = nullptr;
while ((k = type->enum_map.next(k))) {
-
List<StringName> &constants_list = type->enum_map.get(*k);
const List<StringName>::Element *found = constants_list.find(p_name);
- if (found)
+ if (found) {
return *k;
+ }
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
}
@@ -790,33 +744,30 @@ StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const S
}
void ClassDB::get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance) {
-
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
-
const StringName *k = nullptr;
while ((k = type->enum_map.next(k))) {
p_enums->push_back(*k);
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
}
}
void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance) {
-
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
-
const List<StringName> *constants = type->enum_map.getptr(p_enum);
if (constants) {
@@ -825,15 +776,15 @@ void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_
}
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
}
}
void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) {
-
OBJTYPE_WLOCK;
ClassInfo *type = classes.getptr(p_class);
@@ -853,7 +804,6 @@ void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) {
}
void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, bool p_no_inheritance) {
-
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
@@ -862,28 +812,27 @@ void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, b
ClassInfo *check = type;
while (check) {
-
const StringName *S = nullptr;
while ((S = check->signal_map.next(S))) {
-
p_signals->push_back(check->signal_map[*S]);
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
return;
+ }
check = check->inherits_ptr;
}
}
bool ClassDB::has_signal(StringName p_class, StringName p_signal) {
-
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
- if (check->signal_map.has(p_signal))
+ if (check->signal_map.has(p_signal)) {
return true;
+ }
check = check->inherits_ptr;
}
@@ -891,7 +840,6 @@ bool ClassDB::has_signal(StringName p_class, StringName p_signal) {
}
bool ClassDB::get_signal(StringName p_class, StringName p_signal, MethodInfo *r_signal) {
-
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
@@ -909,7 +857,6 @@ bool ClassDB::get_signal(StringName p_class, StringName p_signal, MethodInfo *r_
}
void ClassDB::add_property_group(StringName p_class, const String &p_name, const String &p_prefix) {
-
OBJTYPE_WLOCK;
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_COND(!type);
@@ -918,7 +865,6 @@ void ClassDB::add_property_group(StringName p_class, const String &p_name, const
}
void ClassDB::add_property_subgroup(StringName p_class, const String &p_name, const String &p_prefix) {
-
OBJTYPE_WLOCK;
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_COND(!type);
@@ -927,7 +873,6 @@ void ClassDB::add_property_subgroup(StringName p_class, const String &p_name, co
}
void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) {
-
lock->read_lock();
ClassInfo *type = classes.getptr(p_class);
lock->read_unlock();
@@ -948,7 +893,6 @@ void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, cons
MethodBind *mb_get = nullptr;
if (p_getter) {
-
mb_get = get_method(p_class, p_getter);
#ifdef DEBUG_METHODS_ENABLED
@@ -993,15 +937,12 @@ void ClassDB::set_property_default_value(StringName p_class, const StringName &p
}
void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) {
-
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
-
for (List<PropertyInfo>::Element *E = check->property_list.front(); E; E = E->next()) {
-
if (p_validator) {
PropertyInfo pi = E->get();
p_validator->_validate_property(pi);
@@ -1011,22 +952,23 @@ void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list,
}
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
return;
+ }
check = check->inherits_ptr;
}
}
-bool ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid) {
+bool ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid) {
ClassInfo *type = classes.getptr(p_object->get_class_name());
ClassInfo *check = type;
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
-
if (!psg->setter) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return true; //return true but do nothing
}
@@ -1051,8 +993,9 @@ bool ClassDB::set_property(Object *p_object, const StringName &p_property, const
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = ce.error == Callable::CallError::CALL_OK;
+ }
return true;
}
@@ -1062,15 +1005,16 @@ bool ClassDB::set_property(Object *p_object, const StringName &p_property, const
return false;
}
-bool ClassDB::get_property(Object *p_object, const StringName &p_property, Variant &r_value) {
+bool ClassDB::get_property(Object *p_object, const StringName &p_property, Variant &r_value) {
ClassInfo *type = classes.getptr(p_object->get_class_name());
ClassInfo *check = type;
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
- if (!psg->getter)
+ if (!psg->getter) {
return true; //return true but do nothing
+ }
if (psg->index >= 0) {
Variant index = psg->index;
@@ -1079,10 +1023,8 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia
r_value = p_object->call(psg->getter, arg, 1, ce);
} else {
-
Callable::CallError ce;
if (psg->_getptr) {
-
r_value = psg->_getptr->call(p_object, nullptr, 0, ce);
} else {
r_value = p_object->call(psg->getter, nullptr, 0, ce);
@@ -1093,7 +1035,6 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia
const int *c = check->constant_map.getptr(p_property); //constants count
if (c) {
-
r_value = *c;
return true;
}
@@ -1115,57 +1056,55 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia
}
int ClassDB::get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
-
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
-
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = true;
+ }
return psg->index;
}
check = check->inherits_ptr;
}
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = false;
+ }
return -1;
}
Variant::Type ClassDB::get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
-
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
-
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = true;
+ }
return psg->type;
}
check = check->inherits_ptr;
}
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = false;
+ }
return Variant::NIL;
}
StringName ClassDB::get_property_setter(StringName p_class, const StringName &p_property) {
-
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
-
return psg->setter;
}
@@ -1176,13 +1115,11 @@ StringName ClassDB::get_property_setter(StringName p_class, const StringName &p_
}
StringName ClassDB::get_property_getter(StringName p_class, const StringName &p_property) {
-
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
-
return psg->getter;
}
@@ -1193,15 +1130,16 @@ StringName ClassDB::get_property_getter(StringName p_class, const StringName &p_
}
bool ClassDB::has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance) {
-
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
- if (check->property_setget.has(p_property))
+ if (check->property_setget.has(p_property)) {
return true;
+ }
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
check = check->inherits_ptr;
}
@@ -1209,7 +1147,6 @@ bool ClassDB::has_property(const StringName &p_class, const StringName &p_proper
}
void ClassDB::set_method_flags(StringName p_class, StringName p_method, int p_flags) {
-
OBJTYPE_WLOCK;
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
@@ -1219,14 +1156,15 @@ void ClassDB::set_method_flags(StringName p_class, StringName p_method, int p_fl
}
bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) {
-
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
- if (check->method_map.has(p_method))
+ if (check->method_map.has(p_method)) {
return true;
- if (p_no_inheritance)
+ }
+ if (p_no_inheritance) {
return false;
+ }
check = check->inherits_ptr;
}
@@ -1282,7 +1220,6 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c
defvals.resize(p_defcount);
for (int i = 0; i < p_defcount; i++) {
-
defvals.write[i] = *p_defs[p_defcount - i - 1];
}
@@ -1298,15 +1235,15 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_
#ifdef DEBUG_METHODS_ENABLED
MethodInfo mi = p_method;
- if (p_virtual)
+ if (p_virtual) {
mi.flags |= METHOD_FLAG_VIRTUAL;
+ }
classes[p_class].virtual_methods.push_back(mi);
#endif
}
void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance) {
-
ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'.");
#ifdef DEBUG_METHODS_ENABLED
@@ -1314,13 +1251,13 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
-
for (List<MethodInfo>::Element *E = check->virtual_methods.front(); E; E = E->next()) {
p_methods->push_back(E->get());
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
return;
+ }
check = check->inherits_ptr;
}
@@ -1328,7 +1265,6 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p
}
void ClassDB::set_class_enabled(StringName p_class, bool p_enable) {
-
OBJTYPE_WLOCK;
ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'.");
@@ -1336,7 +1272,6 @@ void ClassDB::set_class_enabled(StringName p_class, bool p_enable) {
}
bool ClassDB::is_class_enabled(StringName p_class) {
-
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
@@ -1351,7 +1286,6 @@ bool ClassDB::is_class_enabled(StringName p_class) {
}
bool ClassDB::is_class_exposed(StringName p_class) {
-
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
@@ -1360,7 +1294,6 @@ bool ClassDB::is_class_exposed(StringName p_class) {
}
StringName ClassDB::get_category(const StringName &p_node) {
-
ERR_FAIL_COND_V(!classes.has(p_node), StringName());
#ifdef DEBUG_ENABLED
return classes[p_node].category;
@@ -1370,31 +1303,29 @@ StringName ClassDB::get_category(const StringName &p_node) {
}
void ClassDB::add_resource_base_extension(const StringName &p_extension, const StringName &p_class) {
-
- if (resource_base_extensions.has(p_extension))
+ if (resource_base_extensions.has(p_extension)) {
return;
+ }
resource_base_extensions[p_extension] = p_class;
}
void ClassDB::get_resource_base_extensions(List<String> *p_extensions) {
-
const StringName *K = nullptr;
while ((K = resource_base_extensions.next(K))) {
-
p_extensions->push_back(*K);
}
}
void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p_extensions) {
-
const StringName *K = nullptr;
while ((K = resource_base_extensions.next(K))) {
StringName cmp = resource_base_extensions[*K];
- if (is_parent_class(p_class, cmp) || is_parent_class(cmp, p_class))
+ if (is_parent_class(p_class, cmp) || is_parent_class(cmp, p_class)) {
p_extensions->push_back(*K);
+ }
}
}
@@ -1402,9 +1333,7 @@ HashMap<StringName, HashMap<StringName, Variant>> ClassDB::default_values;
Set<StringName> ClassDB::default_values_cached;
Variant ClassDB::class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid) {
-
if (!default_values_cached.has(p_class)) {
-
if (!default_values.has(p_class)) {
default_values[p_class] = HashMap<StringName, Variant>();
}
@@ -1421,12 +1350,10 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con
}
if (c) {
-
List<PropertyInfo> plist;
c->get_property_list(&plist);
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
if (E->get().usage & (PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR)) {
-
if (!default_values[p_class].has(E->get().name)) {
Variant v = c->get(E->get().name);
default_values[p_class][E->get().name] = v;
@@ -1443,48 +1370,46 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con
}
if (!default_values.has(p_class)) {
- if (r_valid != nullptr)
+ if (r_valid != nullptr) {
*r_valid = false;
+ }
return Variant();
}
if (!default_values[p_class].has(p_property)) {
- if (r_valid != nullptr)
+ if (r_valid != nullptr) {
*r_valid = false;
+ }
return Variant();
}
- if (r_valid != nullptr)
+ if (r_valid != nullptr) {
*r_valid = true;
+ }
return default_values[p_class][p_property];
}
RWLock *ClassDB::lock = nullptr;
void ClassDB::init() {
-
lock = RWLock::create();
}
void ClassDB::cleanup_defaults() {
-
default_values.clear();
default_values_cached.clear();
}
void ClassDB::cleanup() {
-
//OBJTYPE_LOCK; hah not here
const StringName *k = nullptr;
while ((k = classes.next(k))) {
-
ClassInfo &ti = classes[*k];
const StringName *m = nullptr;
while ((m = ti.method_map.next(m))) {
-
memdelete(ti.method_map[*m]);
}
}
diff --git a/core/class_db.h b/core/class_db.h
index 32d2148048..eae2a9afd4 100644
--- a/core/class_db.h
+++ b/core/class_db.h
@@ -48,7 +48,6 @@
#ifdef DEBUG_METHODS_ENABLED
struct MethodDefinition {
-
StringName name;
Vector<StringName> args;
MethodDefinition() {}
@@ -103,7 +102,6 @@ public:
public:
struct PropertySetGet {
-
int index;
StringName setter;
StringName getter;
@@ -113,7 +111,6 @@ public:
};
struct ClassInfo {
-
APIType api = API_NONE;
ClassInfo *inherits_ptr = nullptr;
void *class_ptr = nullptr;
@@ -169,13 +166,11 @@ public:
// DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
template <class T>
static void _add_class() {
-
_add_class2(T::get_class_static(), T::get_parent_class_static());
}
template <class T>
static void register_class() {
-
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
@@ -188,7 +183,6 @@ public:
template <class T>
static void register_virtual_class() {
-
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
@@ -200,13 +194,11 @@ public:
template <class T>
static Object *_create_ptr_func() {
-
return T::create();
}
template <class T>
static void register_custom_instance_class() {
-
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
@@ -233,7 +225,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method) {
-
MethodBind *bind = create_method_bind(p_method);
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, nullptr, 0); //use static function, much smaller binary usage
@@ -241,7 +232,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1) {
-
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[1] = { &p_def1 };
@@ -250,7 +240,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2) {
-
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[2] = { &p_def1, &p_def2 };
@@ -259,7 +248,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3) {
-
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[3] = { &p_def1, &p_def2, &p_def3 };
@@ -268,7 +256,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4) {
-
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[4] = { &p_def1, &p_def2, &p_def3, &p_def4 };
@@ -277,7 +264,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5) {
-
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[5] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5 };
@@ -286,7 +272,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6) {
-
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[6] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6 };
@@ -295,7 +280,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7) {
-
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[7] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7 };
@@ -304,7 +288,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7, const Variant &p_def8) {
-
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[8] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7, &p_def8 };
@@ -313,7 +296,6 @@ public:
template <class M>
static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>(), bool p_return_nil_is_variant = true) {
-
GLOBAL_LOCK_FUNCTION;
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
diff --git a/core/color.cpp b/core/color.cpp
index 79b9f70a99..fa3f6475d4 100644
--- a/core/color.cpp
+++ b/core/color.cpp
@@ -36,7 +36,6 @@
#include "core/print_string.h"
uint32_t Color::to_argb32() const {
-
uint32_t c = (uint8_t)Math::round(a * 255);
c <<= 8;
c |= (uint8_t)Math::round(r * 255);
@@ -49,7 +48,6 @@ uint32_t Color::to_argb32() const {
}
uint32_t Color::to_abgr32() const {
-
uint32_t c = (uint8_t)Math::round(a * 255);
c <<= 8;
c |= (uint8_t)Math::round(b * 255);
@@ -62,7 +60,6 @@ uint32_t Color::to_abgr32() const {
}
uint32_t Color::to_rgba32() const {
-
uint32_t c = (uint8_t)Math::round(r * 255);
c <<= 8;
c |= (uint8_t)Math::round(g * 255);
@@ -75,7 +72,6 @@ uint32_t Color::to_rgba32() const {
}
uint64_t Color::to_abgr64() const {
-
uint64_t c = (uint16_t)Math::round(a * 65535);
c <<= 16;
c |= (uint16_t)Math::round(b * 65535);
@@ -88,7 +84,6 @@ uint64_t Color::to_abgr64() const {
}
uint64_t Color::to_argb64() const {
-
uint64_t c = (uint16_t)Math::round(a * 65535);
c <<= 16;
c |= (uint16_t)Math::round(r * 65535);
@@ -101,7 +96,6 @@ uint64_t Color::to_argb64() const {
}
uint64_t Color::to_rgba64() const {
-
uint64_t c = (uint16_t)Math::round(r * 65535);
c <<= 16;
c |= (uint16_t)Math::round(g * 65535);
@@ -114,7 +108,6 @@ uint64_t Color::to_rgba64() const {
}
float Color::get_h() const {
-
float min = MIN(r, g);
min = MIN(min, b);
float max = MAX(r, g);
@@ -122,26 +115,28 @@ float Color::get_h() const {
float delta = max - min;
- if (delta == 0)
+ if (delta == 0) {
return 0;
+ }
float h;
- if (r == max)
+ if (r == max) {
h = (g - b) / delta; // between yellow & magenta
- else if (g == max)
+ } else if (g == max) {
h = 2 + (b - r) / delta; // between cyan & yellow
- else
+ } else {
h = 4 + (r - g) / delta; // between magenta & cyan
+ }
h /= 6.0;
- if (h < 0)
+ if (h < 0) {
h += 1.0;
+ }
return h;
}
float Color::get_s() const {
-
float min = MIN(r, g);
min = MIN(min, b);
float max = MAX(r, g);
@@ -153,14 +148,12 @@ float Color::get_s() const {
}
float Color::get_v() const {
-
float max = MAX(r, g);
max = MAX(max, b);
return max;
}
void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
-
int i;
float f, p, q, t;
a = p_alpha;
@@ -215,25 +208,22 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
}
bool Color::is_equal_approx(const Color &p_color) const {
-
return Math::is_equal_approx(r, p_color.r) && Math::is_equal_approx(g, p_color.g) && Math::is_equal_approx(b, p_color.b) && Math::is_equal_approx(a, p_color.a);
}
void Color::invert() {
-
r = 1.0 - r;
g = 1.0 - g;
b = 1.0 - b;
}
-void Color::contrast() {
+void Color::contrast() {
r = Math::fmod(r + 0.5, 1.0);
g = Math::fmod(g + 0.5, 1.0);
b = Math::fmod(b + 0.5, 1.0);
}
Color Color::hex(uint32_t p_hex) {
-
float a = (p_hex & 0xFF) / 255.0;
p_hex >>= 8;
float b = (p_hex & 0xFF) / 255.0;
@@ -246,7 +236,6 @@ Color Color::hex(uint32_t p_hex) {
}
Color Color::hex64(uint64_t p_hex) {
-
float a = (p_hex & 0xFFFF) / 65535.0;
p_hex >>= 16;
float b = (p_hex & 0xFFFF) / 65535.0;
@@ -259,7 +248,6 @@ Color Color::hex64(uint64_t p_hex) {
}
Color Color::from_rgbe9995(uint32_t p_rgbe) {
-
float r = p_rgbe & 0x1ff;
float g = (p_rgbe >> 9) & 0x1ff;
float b = (p_rgbe >> 18) & 0x1ff;
@@ -274,11 +262,9 @@ Color Color::from_rgbe9995(uint32_t p_rgbe) {
}
static float _parse_col(const String &p_str, int p_ofs) {
-
int ig = 0;
for (int i = 0; i < 2; i++) {
-
int c = p_str[i + p_ofs];
int v = 0;
@@ -294,36 +280,36 @@ static float _parse_col(const String &p_str, int p_ofs) {
return -1;
}
- if (i == 0)
+ if (i == 0) {
ig += v * 16;
- else
+ } else {
ig += v;
+ }
}
return ig;
}
Color Color::inverted() const {
-
Color c = *this;
c.invert();
return c;
}
Color Color::contrasted() const {
-
Color c = *this;
c.contrast();
return c;
}
Color Color::html(const String &p_color) {
-
String color = p_color;
- if (color.length() == 0)
+ if (color.length() == 0) {
return Color();
- if (color[0] == '#')
+ }
+ if (color[0] == '#') {
color = color.substr(1, color.length() - 1);
+ }
if (color.length() == 3 || color.length() == 4) {
String exp_color;
for (int i = 0; i < color.length(); i++) {
@@ -362,13 +348,14 @@ Color Color::html(const String &p_color) {
}
bool Color::html_is_valid(const String &p_color) {
-
String color = p_color;
- if (color.length() == 0)
+ if (color.length() == 0) {
return false;
- if (color[0] == '#')
+ }
+ if (color[0] == '#') {
color = color.substr(1, color.length() - 1);
+ }
bool alpha = false;
@@ -406,8 +393,9 @@ bool Color::html_is_valid(const String &p_color) {
}
Color Color::named(const String &p_name) {
- if (_named_colors.empty())
+ if (_named_colors.empty()) {
_populate_named_colors(); // from color_names.inc
+ }
String name = p_name;
// Normalize name
name = name.replace(" ", "");
@@ -423,19 +411,18 @@ Color Color::named(const String &p_name) {
}
String _to_hex(float p_val) {
-
int v = Math::round(p_val * 255);
v = CLAMP(v, 0, 255);
String ret;
for (int i = 0; i < 2; i++) {
-
CharType c[2] = { 0, 0 };
int lv = v & 0xF;
- if (lv < 10)
+ if (lv < 10) {
c[0] = '0' + lv;
- else
+ } else {
c[0] = 'a' + lv - 10;
+ }
v >>= 4;
String cs = (const CharType *)c;
@@ -446,21 +433,21 @@ String _to_hex(float p_val) {
}
String Color::to_html(bool p_alpha) const {
-
String txt;
txt += _to_hex(r);
txt += _to_hex(g);
txt += _to_hex(b);
- if (p_alpha)
+ if (p_alpha) {
txt = _to_hex(a) + txt;
+ }
return txt;
}
Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const {
-
p_h = Math::fmod(p_h * 360.0f, 360.0f);
- if (p_h < 0.0)
+ if (p_h < 0.0) {
p_h += 360.0f;
+ }
const float h_ = p_h / 60.0f;
const float c = p_v * p_s;
@@ -510,12 +497,10 @@ Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const {
}
Color::operator String() const {
-
return rtos(r) + ", " + rtos(g) + ", " + rtos(b) + ", " + rtos(a);
}
Color Color::operator+(const Color &p_color) const {
-
return Color(
r + p_color.r,
g + p_color.g,
@@ -524,7 +509,6 @@ Color Color::operator+(const Color &p_color) const {
}
Color Color::operator-(const Color &p_color) const {
-
return Color(
r - p_color.r,
g - p_color.g,
@@ -533,7 +517,6 @@ Color Color::operator-(const Color &p_color) const {
}
void Color::operator-=(const Color &p_color) {
-
r = r - p_color.r;
g = g - p_color.g;
b = b - p_color.b;
@@ -541,7 +524,6 @@ void Color::operator-=(const Color &p_color) {
}
Color Color::operator*(const Color &p_color) const {
-
return Color(
r * p_color.r,
g * p_color.g,
@@ -550,7 +532,6 @@ Color Color::operator*(const Color &p_color) const {
}
Color Color::operator*(const real_t &rvalue) const {
-
return Color(
r * rvalue,
g * rvalue,
@@ -559,7 +540,6 @@ Color Color::operator*(const real_t &rvalue) const {
}
void Color::operator*=(const Color &p_color) {
-
r = r * p_color.r;
g = g * p_color.g;
b = b * p_color.b;
@@ -567,7 +547,6 @@ void Color::operator*=(const Color &p_color) {
}
void Color::operator*=(const real_t &rvalue) {
-
r = r * rvalue;
g = g * rvalue;
b = b * rvalue;
@@ -575,7 +554,6 @@ void Color::operator*=(const real_t &rvalue) {
}
Color Color::operator/(const Color &p_color) const {
-
return Color(
r / p_color.r,
g / p_color.g,
@@ -584,7 +562,6 @@ Color Color::operator/(const Color &p_color) const {
}
Color Color::operator/(const real_t &rvalue) const {
-
return Color(
r / rvalue,
g / rvalue,
@@ -593,7 +570,6 @@ Color Color::operator/(const real_t &rvalue) const {
}
void Color::operator/=(const Color &p_color) {
-
r = r / p_color.r;
g = g / p_color.g;
b = b / p_color.b;
@@ -601,7 +577,6 @@ void Color::operator/=(const Color &p_color) {
}
void Color::operator/=(const real_t &rvalue) {
-
if (rvalue == 0) {
r = 1.0;
g = 1.0;
@@ -616,7 +591,6 @@ void Color::operator/=(const real_t &rvalue) {
};
Color Color::operator-() const {
-
return Color(
1.0 - r,
1.0 - g,
diff --git a/core/color.h b/core/color.h
index 066a3f6696..258965fd16 100644
--- a/core/color.h
+++ b/core/color.h
@@ -35,9 +35,7 @@
#include "core/ustring.h"
struct Color {
-
union {
-
struct {
float r;
float g;
@@ -98,7 +96,6 @@ struct Color {
Color contrasted() const;
_FORCE_INLINE_ Color lerp(const Color &p_b, float p_t) const {
-
Color res = *this;
res.r += (p_t * (p_b.r - r));
@@ -110,7 +107,6 @@ struct Color {
}
_FORCE_INLINE_ Color darkened(float p_amount) const {
-
Color res = *this;
res.r = res.r * (1.0f - p_amount);
res.g = res.g * (1.0f - p_amount);
@@ -119,7 +115,6 @@ struct Color {
}
_FORCE_INLINE_ Color lightened(float p_amount) const {
-
Color res = *this;
res.r = res.r + (1.0f - res.r) * p_amount;
res.g = res.g + (1.0f - res.g) * p_amount;
@@ -128,7 +123,6 @@ struct Color {
}
_FORCE_INLINE_ uint32_t to_rgbe9995() const {
-
const float pow2to9 = 512.0f;
const float B = 15.0f;
//const float Emax = 31.0f;
@@ -162,7 +156,6 @@ struct Color {
}
_FORCE_INLINE_ Color blend(const Color &p_over) const {
-
Color res;
float sa = 1.0 - p_over.a;
res.a = a * sa + p_over.a;
@@ -177,7 +170,6 @@ struct Color {
}
_FORCE_INLINE_ Color to_linear() const {
-
return Color(
r < 0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4),
g < 0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4),
@@ -185,7 +177,6 @@ struct Color {
a);
}
_FORCE_INLINE_ Color to_srgb() const {
-
return Color(
r < 0.0031308 ? 12.92 * r : (1.0 + 0.055) * Math::pow(r, 1.0f / 2.4f) - 0.055,
g < 0.0031308 ? 12.92 * g : (1.0 + 0.055) * Math::pow(g, 1.0f / 2.4f) - 0.055,
@@ -228,17 +219,19 @@ struct Color {
};
bool Color::operator<(const Color &p_color) const {
-
if (r == p_color.r) {
if (g == p_color.g) {
if (b == p_color.b) {
return (a < p_color.a);
- } else
+ } else {
return (b < p_color.b);
- } else
+ }
+ } else {
return g < p_color.g;
- } else
+ }
+ } else {
return r < p_color.r;
+ }
}
#endif // COLOR_H
diff --git a/core/color_names.inc b/core/color_names.inc
index f249ee9868..2b50d88b02 100644
--- a/core/color_names.inc
+++ b/core/color_names.inc
@@ -3,8 +3,9 @@
static Map<String, Color> _named_colors;
static void _populate_named_colors() {
- if (!_named_colors.empty())
+ if (!_named_colors.empty()) {
return;
+ }
_named_colors.insert("aliceblue", Color(0.94, 0.97, 1.00));
_named_colors.insert("antiquewhite", Color(0.98, 0.92, 0.84));
_named_colors.insert("aqua", Color(0.00, 1.00, 1.00));
diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp
index 60ab5d133b..ace210ca2c 100644
--- a/core/command_queue_mt.cpp
+++ b/core/command_queue_mt.cpp
@@ -33,30 +33,24 @@
#include "core/os/os.h"
void CommandQueueMT::lock() {
-
mutex.lock();
}
void CommandQueueMT::unlock() {
-
mutex.unlock();
}
void CommandQueueMT::wait_for_flush() {
-
// wait one millisecond for a flush to happen
OS::get_singleton()->delay_usec(1000);
}
CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() {
-
int idx = -1;
while (true) {
-
lock();
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
-
if (!sync_sems[i].in_use) {
sync_sems[i].in_use = true;
idx = i;
@@ -100,12 +94,14 @@ tryagain:
}
CommandQueueMT::CommandQueueMT(bool p_sync) {
- if (p_sync)
+ if (p_sync) {
sync = memnew(Semaphore);
+ }
}
CommandQueueMT::~CommandQueueMT() {
- if (sync)
+ if (sync) {
memdelete(sync);
+ }
memfree(command_mem);
}
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h
index af8bbb24c6..d7a6a5bc43 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -297,22 +297,18 @@
#define MAX_CMD_PARAMS 15
class CommandQueueMT {
-
struct SyncSemaphore {
-
Semaphore sem;
bool in_use = false;
};
struct CommandBase {
-
virtual void call() = 0;
virtual void post() {}
virtual ~CommandBase() {}
};
struct SyncCommand : public CommandBase {
-
SyncSemaphore *sync_sem;
virtual void post() {
@@ -349,7 +345,6 @@ class CommandQueueMT {
template <class T>
T *allocate() {
-
// alloc size is size+T+safeguard
uint32_t alloc_size = ((sizeof(T) + 8 - 1) & ~(8 - 1)) + 8;
@@ -358,7 +353,6 @@ class CommandQueueMT {
if (write_ptr < dealloc_ptr) {
// behind dealloc_ptr, check that there is room
if ((dealloc_ptr - write_ptr) <= alloc_size) {
-
// There is no more room, try to deallocate something
if (dealloc_one()) {
goto tryagain;
@@ -405,12 +399,10 @@ class CommandQueueMT {
template <class T>
T *allocate_and_lock() {
-
lock();
T *ret;
while ((ret = allocate<T>()) == nullptr) {
-
unlock();
// sleep a little until fetch happened and some room is made
wait_for_flush();
@@ -421,14 +413,16 @@ class CommandQueueMT {
}
bool flush_one(bool p_lock = true) {
- if (p_lock)
+ if (p_lock) {
lock();
+ }
tryagain:
// tried to read an empty queue
if (read_ptr == write_ptr) {
- if (p_lock)
+ if (p_lock) {
unlock();
+ }
return false;
}
@@ -447,18 +441,21 @@ class CommandQueueMT {
read_ptr += size;
- if (p_lock)
+ if (p_lock) {
unlock();
+ }
cmd->call();
- if (p_lock)
+ if (p_lock) {
lock();
+ }
cmd->post();
cmd->~CommandBase();
*(uint32_t *)&command_mem[size_ptr] &= ~1;
- if (p_lock)
+ if (p_lock) {
unlock();
+ }
return true;
}
@@ -488,11 +485,10 @@ public:
}
void flush_all() {
-
//ERR_FAIL_COND(sync);
lock();
- while (flush_one(false))
- ;
+ while (flush_one(false)) {
+ }
unlock();
}
diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp
index 9e6ba6cde2..a66997aa52 100644
--- a/core/compressed_translation.cpp
+++ b/core/compressed_translation.cpp
@@ -37,7 +37,6 @@ extern "C" {
}
struct _PHashTranslationCmp {
-
int orig_len;
CharString compressed;
int offset;
@@ -65,7 +64,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
int total_string_size = 0;
for (List<StringName>::Element *E = keys.front(); E; E = E->next()) {
-
//hash string
CharString cs = E->get().operator String().utf8();
uint32_t h = hash(0, cs.get_data());
@@ -108,21 +106,19 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
int bucket_table_size = 0;
for (int i = 0; i < size; i++) {
-
const Vector<Pair<int, CharString>> &b = buckets[i];
Map<uint32_t, int> &t = table.write[i];
- if (b.size() == 0)
+ if (b.size() == 0) {
continue;
+ }
int d = 1;
int item = 0;
while (item < b.size()) {
-
uint32_t slot = hash(d, b[item].second.get_data());
if (t.has(slot)) {
-
item = 0;
d++;
t.clear();
@@ -151,7 +147,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
int collisions = 0;
for (int i = 0; i < size; i++) {
-
const Map<uint32_t, int> &t = table[i];
if (t.size() == 0) {
htw[i] = 0xFFFFFFFF; //nothing
@@ -165,7 +160,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
btw[btindex++] = hfunc_table[i];
for (Map<uint32_t, int>::Element *E = t.front(); E; E = E->next()) {
-
btw[btindex++] = E->key();
btw[btindex++] = compressed[E->get()].offset;
btw[btindex++] = compressed[E->get()].compressed.size();
@@ -187,7 +181,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
}
bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) {
-
String name = p_name.operator String();
if (name == "hash_table") {
hash_table = p_value;
@@ -197,33 +190,34 @@ bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) {
strings = p_value;
} else if (name == "load_from") {
generate(p_value);
- } else
+ } else {
return false;
+ }
return true;
}
bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const {
-
String name = p_name.operator String();
- if (name == "hash_table")
+ if (name == "hash_table") {
r_ret = hash_table;
- else if (name == "bucket_table")
+ } else if (name == "bucket_table") {
r_ret = bucket_table;
- else if (name == "strings")
+ } else if (name == "strings") {
r_ret = strings;
- else
+ } else {
return false;
+ }
return true;
}
StringName PHashTranslation::get_message(const StringName &p_src_text) const {
-
int htsize = hash_table.size();
- if (htsize == 0)
+ if (htsize == 0) {
return StringName();
+ }
CharString str = p_src_text.operator String().utf8();
uint32_t h = hash(0, str.get_data());
@@ -248,9 +242,7 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const {
int idx = -1;
for (int i = 0; i < bucket.size; i++) {
-
if (bucket.elem[i].key == h) {
-
idx = i;
break;
}
@@ -261,13 +253,11 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const {
}
if (bucket.elem[idx].comp_size == bucket.elem[idx].uncomp_size) {
-
String rstr;
rstr.parse_utf8(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].uncomp_size);
return rstr;
} else {
-
CharString uncomp;
uncomp.resize(bucket.elem[idx].uncomp_size + 1);
smaz_decompress(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].comp_size, uncomp.ptrw(), bucket.elem[idx].uncomp_size);
@@ -278,13 +268,12 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const {
}
void PHashTranslation::_get_property_list(List<PropertyInfo> *p_list) const {
-
p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "hash_table"));
p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "bucket_table"));
p_list->push_back(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "strings"));
p_list->push_back(PropertyInfo(Variant::OBJECT, "load_from", PROPERTY_HINT_RESOURCE_TYPE, "Translation", PROPERTY_USAGE_EDITOR));
}
-void PHashTranslation::_bind_methods() {
+void PHashTranslation::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate", "from"), &PHashTranslation::generate);
}
diff --git a/core/compressed_translation.h b/core/compressed_translation.h
index fff4350caa..3c029bdf58 100644
--- a/core/compressed_translation.h
+++ b/core/compressed_translation.h
@@ -34,7 +34,6 @@
#include "core/translation.h"
class PHashTranslation : public Translation {
-
GDCLASS(PHashTranslation, Translation);
//this translation uses a sort of modified perfect hash algorithm
@@ -48,12 +47,10 @@ class PHashTranslation : public Translation {
Vector<uint8_t> strings;
struct Bucket {
-
int size;
uint32_t func;
struct Elem {
-
uint32_t key;
uint32_t str_offset;
uint32_t comp_size;
@@ -64,11 +61,10 @@ class PHashTranslation : public Translation {
};
_FORCE_INLINE_ uint32_t hash(uint32_t d, const char *p_str) const {
-
- if (d == 0)
+ if (d == 0) {
d = 0x1000193;
+ }
while (*p_str) {
-
d = (d * 0x1000193) ^ uint32_t(*p_str);
p_str++;
}
diff --git a/core/container_type_validate.h b/core/container_type_validate.h
index 7809e5f385..f2724e884d 100644
--- a/core/container_type_validate.h
+++ b/core/container_type_validate.h
@@ -35,7 +35,6 @@
#include "core/variant.h"
struct ContainerTypeValidate {
-
Variant::Type type = Variant::NIL;
StringName class_name;
Ref<Script> script;
@@ -76,7 +75,6 @@ struct ContainerTypeValidate {
}
_FORCE_INLINE_ bool validate(const Variant &p_variant, const char *p_operation = "use") {
-
if (type == Variant::NIL) {
return true;
}
diff --git a/core/core_string_names.h b/core/core_string_names.h
index 2ade44f4e0..1a18c84572 100644
--- a/core/core_string_names.h
+++ b/core/core_string_names.h
@@ -34,7 +34,6 @@
#include "core/string_name.h"
class CoreStringNames {
-
friend void register_core_types();
friend void unregister_core_types();
diff --git a/core/cowdata.h b/core/cowdata.h
index b63a407511..3f72362e29 100644
--- a/core/cowdata.h
+++ b/core/cowdata.h
@@ -59,25 +59,25 @@ private:
// internal helpers
_FORCE_INLINE_ uint32_t *_get_refcount() const {
-
- if (!_ptr)
+ if (!_ptr) {
return nullptr;
+ }
return reinterpret_cast<uint32_t *>(_ptr) - 2;
}
_FORCE_INLINE_ uint32_t *_get_size() const {
-
- if (!_ptr)
+ if (!_ptr) {
return nullptr;
+ }
return reinterpret_cast<uint32_t *>(_ptr) - 1;
}
_FORCE_INLINE_ T *_get_data() const {
-
- if (!_ptr)
+ if (!_ptr) {
return nullptr;
+ }
return reinterpret_cast<T *>(_ptr);
}
@@ -125,31 +125,29 @@ public:
_FORCE_INLINE_ int size() const {
uint32_t *size = (uint32_t *)_get_size();
- if (size)
+ if (size) {
return *size;
- else
+ } else {
return 0;
+ }
}
_FORCE_INLINE_ void clear() { resize(0); }
_FORCE_INLINE_ bool empty() const { return _ptr == nullptr; }
_FORCE_INLINE_ void set(int p_index, const T &p_elem) {
-
CRASH_BAD_INDEX(p_index, size());
_copy_on_write();
_get_data()[p_index] = p_elem;
}
_FORCE_INLINE_ T &get_m(int p_index) {
-
CRASH_BAD_INDEX(p_index, size());
_copy_on_write();
return _get_data()[p_index];
}
_FORCE_INLINE_ const T &get(int p_index) const {
-
CRASH_BAD_INDEX(p_index, size());
return _get_data()[p_index];
@@ -158,12 +156,10 @@ public:
Error resize(int p_size);
_FORCE_INLINE_ void remove(int p_index) {
-
ERR_FAIL_INDEX(p_index, size());
T *p = ptrw();
int len = size();
for (int i = p_index; i < len - 1; i++) {
-
p[i] = p[i + 1];
};
@@ -171,11 +167,11 @@ public:
};
Error insert(int p_pos, const T &p_val) {
-
ERR_FAIL_INDEX_V(p_pos, size() + 1, ERR_INVALID_PARAMETER);
resize(size() + 1);
- for (int i = (size() - 1); i > p_pos; i--)
+ for (int i = (size() - 1); i > p_pos; i--) {
set(i, get(i - 1));
+ }
set(p_pos, p_val);
return OK;
@@ -190,14 +186,15 @@ public:
template <class T>
void CowData<T>::_unref(void *p_data) {
-
- if (!p_data)
+ if (!p_data) {
return;
+ }
uint32_t *refc = _get_refcount();
- if (atomic_decrement(refc) > 0)
+ if (atomic_decrement(refc) > 0) {
return; // still in use
+ }
// clean up
if (!__has_trivial_destructor(T)) {
@@ -216,9 +213,9 @@ void CowData<T>::_unref(void *p_data) {
template <class T>
void CowData<T>::_copy_on_write() {
-
- if (!_ptr)
+ if (!_ptr) {
return;
+ }
uint32_t *refc = _get_refcount();
@@ -250,13 +247,13 @@ void CowData<T>::_copy_on_write() {
template <class T>
Error CowData<T>::resize(int p_size) {
-
ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER);
int current_size = size();
- if (p_size == current_size)
+ if (p_size == current_size) {
return OK;
+ }
if (p_size == 0) {
// wants to clean up
@@ -273,7 +270,6 @@ Error CowData<T>::resize(int p_size) {
ERR_FAIL_COND_V(!_get_alloc_size_checked(p_size, &alloc_size), ERR_OUT_OF_MEMORY);
if (p_size > current_size) {
-
if (alloc_size != current_alloc_size) {
if (current_size == 0) {
// alloc from scratch
@@ -304,7 +300,6 @@ Error CowData<T>::resize(int p_size) {
*_get_size() = p_size;
} else if (p_size < current_size) {
-
if (!__has_trivial_destructor(T)) {
// deinitialize no longer needed elements
for (uint32_t i = p_size; i < *_get_size(); i++) {
@@ -351,15 +346,16 @@ void CowData<T>::_ref(const CowData *p_from) {
template <class T>
void CowData<T>::_ref(const CowData &p_from) {
-
- if (_ptr == p_from._ptr)
+ if (_ptr == p_from._ptr) {
return; // self assign, do nothing.
+ }
_unref(_ptr);
_ptr = nullptr;
- if (!p_from._ptr)
+ if (!p_from._ptr) {
return; //nothing to do
+ }
if (atomic_conditional_increment(p_from._get_refcount()) > 0) { // could reference
_ptr = p_from._ptr;
@@ -368,7 +364,6 @@ void CowData<T>::_ref(const CowData &p_from) {
template <class T>
CowData<T>::~CowData() {
-
_unref(_ptr);
}
diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp
index 585731ac9f..eb942c60c9 100644
--- a/core/crypto/crypto.cpp
+++ b/core/crypto/crypto.cpp
@@ -38,8 +38,9 @@
CryptoKey *(*CryptoKey::_create)() = nullptr;
CryptoKey *CryptoKey::create() {
- if (_create)
+ if (_create) {
return _create();
+ }
return nullptr;
}
@@ -50,8 +51,9 @@ void CryptoKey::_bind_methods() {
X509Certificate *(*X509Certificate::_create)() = nullptr;
X509Certificate *X509Certificate::create() {
- if (_create)
+ if (_create) {
return _create();
+ }
return nullptr;
}
@@ -65,15 +67,16 @@ void X509Certificate::_bind_methods() {
void (*Crypto::_load_default_certificates)(String p_path) = nullptr;
Crypto *(*Crypto::_create)() = nullptr;
Crypto *Crypto::create() {
- if (_create)
+ if (_create) {
return _create();
+ }
return memnew(Crypto);
}
void Crypto::load_default_certificates(String p_path) {
-
- if (_load_default_certificates)
+ if (_load_default_certificates) {
_load_default_certificates(p_path);
+ }
}
void Crypto::_bind_methods() {
@@ -97,45 +100,43 @@ Ref<X509Certificate> Crypto::generate_self_signed_certificate(Ref<CryptoKey> p_k
/// Resource loader/saver
RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
-
String el = p_path.get_extension().to_lower();
if (el == "crt") {
X509Certificate *cert = X509Certificate::create();
- if (cert)
+ if (cert) {
cert->load(p_path);
+ }
return cert;
} else if (el == "key") {
CryptoKey *key = CryptoKey::create();
- if (key)
+ if (key) {
key->load(p_path);
+ }
return key;
}
return nullptr;
}
void ResourceFormatLoaderCrypto::get_recognized_extensions(List<String> *p_extensions) const {
-
p_extensions->push_back("crt");
p_extensions->push_back("key");
}
bool ResourceFormatLoaderCrypto::handles_type(const String &p_type) const {
-
return p_type == "X509Certificate" || p_type == "CryptoKey";
}
String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const {
-
String el = p_path.get_extension().to_lower();
- if (el == "crt")
+ if (el == "crt") {
return "X509Certificate";
- else if (el == "key")
+ } else if (el == "key") {
return "CryptoKey";
+ }
return "";
}
Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
-
Error err;
Ref<X509Certificate> cert = p_resource;
Ref<CryptoKey> key = p_resource;
@@ -151,7 +152,6 @@ Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resourc
}
void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
-
const X509Certificate *cert = Object::cast_to<X509Certificate>(*p_resource);
const CryptoKey *key = Object::cast_to<CryptoKey>(*p_resource);
if (cert) {
@@ -161,7 +161,7 @@ void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource,
p_extensions->push_back("key");
}
}
-bool ResourceFormatSaverCrypto::recognize(const RES &p_resource) const {
+bool ResourceFormatSaverCrypto::recognize(const RES &p_resource) const {
return Object::cast_to<X509Certificate>(*p_resource) || Object::cast_to<CryptoKey>(*p_resource);
}
diff --git a/core/crypto/crypto_core.h b/core/crypto/crypto_core.h
index b3be58e8ee..36d8ace723 100644
--- a/core/crypto/crypto_core.h
+++ b/core/crypto/crypto_core.h
@@ -34,10 +34,8 @@
#include "core/reference.h"
class CryptoCore {
-
public:
class MD5Context {
-
private:
void *ctx; // To include, or not to include...
@@ -51,7 +49,6 @@ public:
};
class SHA1Context {
-
private:
void *ctx; // To include, or not to include...
@@ -65,7 +62,6 @@ public:
};
class SHA256Context {
-
private:
void *ctx; // To include, or not to include...
@@ -79,7 +75,6 @@ public:
};
class AESContext {
-
private:
void *ctx; // To include, or not to include...
diff --git a/core/crypto/hashing_context.cpp b/core/crypto/hashing_context.cpp
index 0b21dead74..fb0dadfbab 100644
--- a/core/crypto/hashing_context.cpp
+++ b/core/crypto/hashing_context.cpp
@@ -104,7 +104,6 @@ void HashingContext::_create_ctx(HashType p_type) {
}
void HashingContext::_delete_ctx() {
-
switch (type) {
case HASH_MD5:
memdelete((CryptoCore::MD5Context *)ctx);
@@ -129,6 +128,7 @@ void HashingContext::_bind_methods() {
}
HashingContext::~HashingContext() {
- if (ctx != nullptr)
+ if (ctx != nullptr) {
_delete_ctx();
+ }
}
diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp
index 410c55129d..3f949b0ae1 100644
--- a/core/debugger/debugger_marshalls.cpp
+++ b/core/debugger/debugger_marshalls.cpp
@@ -228,8 +228,9 @@ Array DebuggerMarshalls::ScriptStackVariable::serialize(int max_size) {
int len = 0;
Error err = encode_variant(var, nullptr, len, true);
- if (err != OK)
+ if (err != OK) {
ERR_PRINT("Failed to encode variant.");
+ }
if (len > max_size) {
arr.push_back(Variant());
diff --git a/core/debugger/debugger_marshalls.h b/core/debugger/debugger_marshalls.h
index 9ba316d997..7b7f4ac4b5 100644
--- a/core/debugger/debugger_marshalls.h
+++ b/core/debugger/debugger_marshalls.h
@@ -35,7 +35,6 @@
#include "servers/rendering_server.h"
struct DebuggerMarshalls {
-
// Memory usage
struct ResourceInfo {
String path;
diff --git a/core/debugger/engine_debugger.cpp b/core/debugger/engine_debugger.cpp
index 04eba84b30..5c9fb67de4 100644
--- a/core/debugger/engine_debugger.cpp
+++ b/core/debugger/engine_debugger.cpp
@@ -111,8 +111,9 @@ Error EngineDebugger::capture_parse(const StringName &p_name, const String &p_ms
void EngineDebugger::line_poll() {
// The purpose of this is just processing events every now and then when the script might get too busy otherwise bugs like infinite loops can't be caught
- if (poll_every % 2048 == 0)
+ if (poll_every % 2048 == 0) {
poll_events(false);
+ }
poll_every++;
}
@@ -124,8 +125,9 @@ void EngineDebugger::iteration(uint64_t p_frame_ticks, uint64_t p_idle_ticks, ui
// Notify tick to running profilers
for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) {
Profiler &p = E->get();
- if (!p.active || !p.tick)
+ if (!p.active || !p.tick) {
continue;
+ }
p.tick(p.data, frame_time, idle_time, physics_time, physics_frame_time);
}
singleton->poll_events(true);
@@ -133,8 +135,9 @@ void EngineDebugger::iteration(uint64_t p_frame_ticks, uint64_t p_idle_ticks, ui
void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Vector<String> p_breakpoints) {
register_uri_handler("tcp://", RemoteDebuggerPeerTCP::create); // TCP is the default protocol. Platforms/modules can add more.
- if (p_uri.empty())
+ if (p_uri.empty()) {
return;
+ }
if (p_uri == "local://") {
singleton = memnew(LocalDebugger);
script_debugger = memnew(ScriptDebugger);
@@ -142,11 +145,13 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve
OS::get_singleton()->initialize_debugging();
} else if (p_uri.find("://") >= 0) {
const String proto = p_uri.substr(0, p_uri.find("://") + 3);
- if (!protocols.has(proto))
+ if (!protocols.has(proto)) {
return;
+ }
RemoteDebuggerPeer *peer = protocols[proto](p_uri);
- if (!peer)
+ if (!peer) {
return;
+ }
singleton = memnew(RemoteDebugger(Ref<RemoteDebuggerPeer>(peer)));
script_debugger = memnew(ScriptDebugger);
// Notify editor of our pid (to allow focus stealing).
@@ -154,15 +159,15 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve
msg.push_back(OS::get_singleton()->get_process_id());
singleton->send_message("set_pid", msg);
}
- if (!singleton)
+ if (!singleton) {
return;
+ }
// There is a debugger, parse breakpoints.
ScriptDebugger *singleton_script_debugger = singleton->get_script_debugger();
singleton_script_debugger->set_skip_breakpoints(p_skip_breakpoints);
for (int i = 0; i < p_breakpoints.size(); i++) {
-
String bp = p_breakpoints[i];
int sp = bp.find_last(":");
ERR_CONTINUE_MSG(sp == -1, "Invalid breakpoint: '" + bp + "', expected file:line format.");
@@ -175,8 +180,9 @@ void EngineDebugger::deinitialize() {
if (singleton) {
// Stop all profilers
for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) {
- if (E->get().active)
+ if (E->get().active) {
singleton->profiler_enable(E->key(), false);
+ }
}
// Flush any remaining message
@@ -193,8 +199,9 @@ void EngineDebugger::deinitialize() {
}
EngineDebugger::~EngineDebugger() {
- if (script_debugger)
+ if (script_debugger) {
memdelete(script_debugger);
+ }
script_debugger = nullptr;
singleton = nullptr;
}
diff --git a/core/debugger/local_debugger.cpp b/core/debugger/local_debugger.cpp
index 6d88ceb2c1..876be79418 100644
--- a/core/debugger/local_debugger.cpp
+++ b/core/debugger/local_debugger.cpp
@@ -36,7 +36,6 @@
struct LocalDebugger::ScriptsProfiler {
struct ProfileInfoSort {
-
bool operator()(const ScriptLanguage::ProfilingInfo &A, const ScriptLanguage::ProfilingInfo &B) const {
return A.total_time > B.total_time;
}
@@ -70,17 +69,19 @@ struct LocalDebugger::ScriptsProfiler {
void _print_frame_data(bool p_accumulated) {
uint64_t diff = OS::get_singleton()->get_ticks_usec() - idle_accum;
- if (!p_accumulated && diff < 1000000) //show every one second
+ if (!p_accumulated && diff < 1000000) { //show every one second
return;
+ }
idle_accum = OS::get_singleton()->get_ticks_usec();
int ofs = 0;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- if (p_accumulated)
+ if (p_accumulated) {
ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&pinfo.write[ofs], pinfo.size() - ofs);
- else
+ } else {
ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&pinfo.write[ofs], pinfo.size() - ofs);
+ }
}
SortArray<ScriptLanguage::ProfilingInfo, ProfileInfoSort> sort;
@@ -89,7 +90,6 @@ struct LocalDebugger::ScriptsProfiler {
// compute total script frame time
uint64_t script_time_us = 0;
for (int i = 0; i < ofs; i++) {
-
script_time_us += pinfo[i].self_time;
}
float script_time = USEC_TO_SEC(script_time_us);
@@ -102,7 +102,6 @@ struct LocalDebugger::ScriptsProfiler {
}
for (int i = 0; i < ofs; i++) {
-
print_line(itos(i) + ":" + pinfo[i].signature);
float tt = USEC_TO_SEC(pinfo[i].total_time);
float st = USEC_TO_SEC(pinfo[i].self_time);
@@ -116,7 +115,6 @@ struct LocalDebugger::ScriptsProfiler {
};
void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
-
ScriptLanguage *script_lang = script_debugger->get_break_language();
if (!target_function.empty()) {
@@ -135,7 +133,6 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
int current_frame = 0;
int total_frames = script_lang->debug_get_stack_level_count();
while (true) {
-
OS::get_singleton()->print("debug> ");
String line = OS::get_singleton()->get_stdin_string().strip_edges();
@@ -146,18 +143,15 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
print_line("\nDebugger Break, Reason: '" + script_lang->debug_get_error() + "'");
print_line("*Frame " + itos(current_frame) + " - " + script_lang->debug_get_stack_level_source(current_frame) + ":" + itos(script_lang->debug_get_stack_level_line(current_frame)) + " in function '" + script_lang->debug_get_stack_level_function(current_frame) + "'");
print_line("Enter \"help\" for assistance.");
- } else if (line == "c" || line == "continue")
+ } else if (line == "c" || line == "continue") {
break;
- else if (line == "bt" || line == "breakpoint") {
-
+ } else if (line == "bt" || line == "breakpoint") {
for (int i = 0; i < total_frames; i++) {
-
String cfi = (current_frame == i) ? "*" : " "; //current frame indicator
print_line(cfi + "Frame " + itos(i) + " - " + script_lang->debug_get_stack_level_source(i) + ":" + itos(script_lang->debug_get_stack_level_line(i)) + " in function '" + script_lang->debug_get_stack_level_function(i) + "'");
}
} else if (line.begins_with("fr") || line.begins_with("frame")) {
-
if (line.get_slice_count(" ") == 1) {
print_line("*Frame " + itos(current_frame) + " - " + script_lang->debug_get_stack_level_source(current_frame) + ":" + itos(script_lang->debug_get_stack_level_line(current_frame)) + " in function '" + script_lang->debug_get_stack_level_function(current_frame) + "'");
} else {
@@ -171,9 +165,7 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
}
} else if (line.begins_with("set")) {
-
if (line.get_slice_count(" ") == 1) {
-
for (Map<String, String>::Element *E = options.front(); E; E = E->next()) {
print_line("\t" + E->key() + "=" + E->value());
}
@@ -185,13 +177,11 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
if (value_pos < 0) {
print_line("Error: Invalid set format. Use: set key=value");
} else {
-
String key = key_value.left(value_pos);
if (!options.has(key)) {
print_line("Error: Unknown option " + key);
} else {
-
// Allow explicit tab character
String value = key_value.right(value_pos + 1).replace("\\t", "\t");
@@ -201,49 +191,41 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
}
} else if (line == "lv" || line == "locals") {
-
List<String> locals;
List<Variant> values;
script_lang->debug_get_stack_level_locals(current_frame, &locals, &values);
print_variables(locals, values, variable_prefix);
} else if (line == "gv" || line == "globals") {
-
List<String> globals;
List<Variant> values;
script_lang->debug_get_globals(&globals, &values);
print_variables(globals, values, variable_prefix);
} else if (line == "mv" || line == "members") {
-
List<String> members;
List<Variant> values;
script_lang->debug_get_stack_level_members(current_frame, &members, &values);
print_variables(members, values, variable_prefix);
} else if (line.begins_with("p") || line.begins_with("print")) {
-
if (line.get_slice_count(" ") <= 1) {
print_line("Usage: print <expre>");
} else {
-
String expr = line.get_slicec(' ', 2);
String res = script_lang->debug_parse_stack_level_expression(current_frame, expr);
print_line(res);
}
} else if (line == "s" || line == "step") {
-
script_debugger->set_depth(-1);
script_debugger->set_lines_left(1);
break;
} else if (line == "n" || line == "next") {
-
script_debugger->set_depth(0);
script_debugger->set_lines_left(1);
break;
} else if (line == "fin" || line == "finish") {
-
String current_function = script_lang->debug_get_stack_level_function(0);
for (int i = 0; i < total_frames; i++) {
@@ -259,9 +241,7 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
target_function = "";
} else if (line.begins_with("br") || line.begins_with("break")) {
-
if (line.get_slice_count(" ") <= 1) {
-
const Map<int, Set<StringName>> &breakpoints = script_debugger->get_breakpoints();
if (breakpoints.size() == 0) {
print_line("No Breakpoints.");
@@ -274,14 +254,14 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
}
} else {
-
Pair<String, int> breakpoint = to_breakpoint(line);
String source = breakpoint.first;
int linenr = breakpoint.second;
- if (source.empty())
+ if (source.empty()) {
continue;
+ }
script_debugger->insert_breakpoint(linenr, source);
@@ -289,7 +269,6 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
}
} else if (line == "q" || line == "quit") {
-
// Do not stop again on quit
script_debugger->clear_breakpoints();
script_debugger->set_depth(-1);
@@ -298,18 +277,17 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
SceneTree::get_singleton()->quit();
break;
} else if (line.begins_with("delete")) {
-
if (line.get_slice_count(" ") <= 1) {
script_debugger->clear_breakpoints();
} else {
-
Pair<String, int> breakpoint = to_breakpoint(line);
String source = breakpoint.first;
int linenr = breakpoint.second;
- if (source.empty())
+ if (source.empty()) {
continue;
+ }
script_debugger->remove_breakpoint(linenr, source);
@@ -317,7 +295,6 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
}
} else if (line == "h" || line == "help") {
-
print_line("Built-In Debugger command list:\n");
print_line("\tc,continue\t\t Continue execution.");
print_line("\tbt,backtrace\t\t Show stack trace (frames).");
@@ -340,18 +317,15 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
}
void LocalDebugger::print_variables(const List<String> &names, const List<Variant> &values, const String &variable_prefix) {
-
String value;
Vector<String> value_lines;
const List<Variant>::Element *V = values.front();
for (const List<String>::Element *E = names.front(); E; E = E->next()) {
-
value = String(V->get());
if (variable_prefix.empty()) {
print_line(E->get() + ": " + String(V->get()));
} else {
-
print_line(E->get() + ":");
value_lines = value.split("\n");
for (int i = 0; i < value_lines.size(); ++i) {
@@ -364,7 +338,6 @@ void LocalDebugger::print_variables(const List<String> &names, const List<Varian
}
Pair<String, int> LocalDebugger::to_breakpoint(const String &p_line) {
-
String breakpoint_part = p_line.get_slicec(' ', 1);
Pair<String, int> breakpoint;
@@ -381,18 +354,15 @@ Pair<String, int> LocalDebugger::to_breakpoint(const String &p_line) {
}
void LocalDebugger::send_message(const String &p_message, const Array &p_args) {
-
// This needs to be cleaned up entirely.
// print_line("MESSAGE: '" + p_message + "' - " + String(Variant(p_args)));
}
void LocalDebugger::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type) {
-
print_line("ERROR: '" + (p_descr.empty() ? p_err : p_descr) + "'");
}
LocalDebugger::LocalDebugger() {
-
options["variable_prefix"] = "";
// Bind scripts profiler.
@@ -411,6 +381,7 @@ LocalDebugger::LocalDebugger() {
LocalDebugger::~LocalDebugger() {
unregister_profiler("scripts");
- if (scripts_profiler)
+ if (scripts_profiler) {
memdelete(scripts_profiler);
+ }
}
diff --git a/core/debugger/local_debugger.h b/core/debugger/local_debugger.h
index 2c4302f4da..d342da6d44 100644
--- a/core/debugger/local_debugger.h
+++ b/core/debugger/local_debugger.h
@@ -36,7 +36,6 @@
#include "core/script_language.h"
class LocalDebugger : public EngineDebugger {
-
private:
struct ScriptsProfiler;
diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp
index 18c9602eb2..62f600c5e5 100644
--- a/core/debugger/remote_debugger.cpp
+++ b/core/debugger/remote_debugger.cpp
@@ -57,7 +57,6 @@ void RemoteDebugger::_bind_profiler(const String &p_name, T *p_prof) {
}
struct RemoteDebugger::NetworkProfiler {
-
public:
typedef DebuggerMarshalls::MultiplayerNodeInfo NodeInfo;
struct BandwidthFrame {
@@ -97,8 +96,9 @@ public:
}
void init_node(const ObjectID p_node) {
- if (multiplayer_node_data.has(p_node))
+ if (multiplayer_node_data.has(p_node)) {
return;
+ }
multiplayer_node_data.insert(p_node, DebuggerMarshalls::MultiplayerNodeInfo());
multiplayer_node_data[p_node].node = p_node;
multiplayer_node_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path();
@@ -191,7 +191,6 @@ struct RemoteDebugger::ScriptsProfiler {
typedef DebuggerMarshalls::ScriptFunctionSignature FunctionSignature;
typedef DebuggerMarshalls::ScriptFunctionInfo FunctionInfo;
struct ProfileInfoSort {
-
bool operator()(ScriptLanguage::ProfilingInfo *A, ScriptLanguage::ProfilingInfo *B) const {
return A->total_time < B->total_time;
}
@@ -220,10 +219,11 @@ struct RemoteDebugger::ScriptsProfiler {
void write_frame_data(Vector<FunctionInfo> &r_funcs, uint64_t &r_total, bool p_accumulated) {
int ofs = 0;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- if (p_accumulated)
+ if (p_accumulated) {
ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&info.write[ofs], info.size() - ofs);
- else
+ } else {
ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&info.write[ofs], info.size() - ofs);
+ }
}
for (int i = 0; i < ofs; i++) {
@@ -270,7 +270,6 @@ struct RemoteDebugger::ScriptsProfiler {
};
struct RemoteDebugger::ServersProfiler {
-
bool skip_profile_frame = false;
typedef DebuggerMarshalls::ServerInfo ServerInfo;
typedef DebuggerMarshalls::ServerFunctionInfo ServerFunctionInfo;
@@ -347,7 +346,6 @@ struct RemoteDebugger::ServersProfiler {
};
struct RemoteDebugger::VisualProfiler {
-
typedef DebuggerMarshalls::ServerInfo ServerInfo;
typedef DebuggerMarshalls::ServerFunctionInfo ServerFunctionInfo;
@@ -362,8 +360,9 @@ struct RemoteDebugger::VisualProfiler {
void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
Vector<RS::FrameProfileArea> profile_areas = RS::get_singleton()->get_frame_profile();
DebuggerMarshalls::VisualProfilerFrame frame;
- if (!profile_areas.size())
+ if (!profile_areas.size()) {
return;
+ }
frame.frame_number = RS::get_singleton()->get_frame_profile_frame();
frame.areas.append_array(profile_areas);
@@ -372,19 +371,20 @@ struct RemoteDebugger::VisualProfiler {
};
struct RemoteDebugger::PerformanceProfiler {
-
Object *performance = nullptr;
int last_perf_time = 0;
void toggle(bool p_enable, const Array &p_opts) {}
void add(const Array &p_data) {}
void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
- if (!performance)
+ if (!performance) {
return;
+ }
uint64_t pt = OS::get_singleton()->get_ticks_msec();
- if (pt - last_perf_time < 1000)
+ if (pt - last_perf_time < 1000) {
return;
+ }
last_perf_time = pt;
int max = performance->get("MONITOR_MAX");
Array arr;
@@ -401,14 +401,12 @@ struct RemoteDebugger::PerformanceProfiler {
};
void RemoteDebugger::_send_resource_usage() {
-
DebuggerMarshalls::ResourceUsage usage;
List<RS::TextureInfo> tinfo;
RS::get_singleton()->texture_debug_usage(&tinfo);
for (List<RS::TextureInfo>::Element *E = tinfo.front(); E; E = E->next()) {
-
DebuggerMarshalls::ResourceInfo info;
info.path = E->get().path;
info.vram = E->get().bytes;
@@ -430,26 +428,29 @@ Error RemoteDebugger::_put_msg(String p_message, Array p_data) {
msg.push_back(p_message);
msg.push_back(p_data);
Error err = peer->put_message(msg);
- if (err != OK)
+ if (err != OK) {
n_messages_dropped++;
+ }
return err;
}
void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, ErrorHandlerType p_type) {
-
- if (p_type == ERR_HANDLER_SCRIPT)
+ if (p_type == ERR_HANDLER_SCRIPT) {
return; //ignore script errors, those go through debugger
+ }
RemoteDebugger *rd = (RemoteDebugger *)p_this;
- if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) // Can't handle recursive errors during flush.
+ if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) { // Can't handle recursive errors during flush.
return;
+ }
Vector<ScriptLanguage::StackInfo> si;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
si = ScriptServer::get_language(i)->debug_get_current_stack_info();
- if (si.size())
+ if (si.size()) {
break;
+ }
}
// send_error will lock internally.
@@ -457,17 +458,18 @@ void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char *
}
void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p_error) {
-
RemoteDebugger *rd = (RemoteDebugger *)p_this;
- if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) // Can't handle recursive prints during flush.
+ if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) { // Can't handle recursive prints during flush.
return;
+ }
String s = p_string;
int allowed_chars = MIN(MAX(rd->max_chars_per_second - rd->char_count, 0), s.length());
- if (allowed_chars == 0 && s.length() > 0)
+ if (allowed_chars == 0 && s.length() > 0) {
return;
+ }
if (allowed_chars < s.length()) {
s = s.substr(0, allowed_chars);
@@ -478,8 +480,9 @@ void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p
rd->char_count += allowed_chars;
bool overflowed = rd->char_count >= rd->max_chars_per_second;
if (rd->is_peer_connected()) {
- if (overflowed)
+ if (overflowed) {
s += "[...]";
+ }
OutputString output_string;
output_string.message = s;
@@ -511,17 +514,18 @@ void RemoteDebugger::flush_output() {
flush_thread = Thread::get_caller_id();
flushing = true;
MutexLock lock(mutex);
- if (!is_peer_connected())
+ if (!is_peer_connected()) {
return;
+ }
if (n_messages_dropped > 0) {
ErrorMessage err_msg = _create_overflow_error("TOO_MANY_MESSAGES", "Too many messages! " + String::num_int64(n_messages_dropped) + " messages were dropped. Profiling might misbheave, try raising 'network/limits/debugger/max_queued_messages' in project setting.");
- if (_put_msg("error", err_msg.serialize()) == OK)
+ if (_put_msg("error", err_msg.serialize()) == OK) {
n_messages_dropped = 0;
+ }
}
if (output_strings.size()) {
-
// Join output strings so we generate less messages.
Vector<String> joined_log_strings;
Vector<String> strings;
@@ -574,7 +578,6 @@ void RemoteDebugger::flush_output() {
}
void RemoteDebugger::send_message(const String &p_message, const Array &p_args) {
-
MutexLock lock(mutex);
if (is_peer_connected()) {
_put_msg(p_message, p_args);
@@ -582,7 +585,6 @@ void RemoteDebugger::send_message(const String &p_message, const Array &p_args)
}
void RemoteDebugger::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type) {
-
ErrorMessage oe;
oe.error = p_err;
oe.error_descr = p_descr;
@@ -597,8 +599,9 @@ void RemoteDebugger::send_error(const String &p_func, const String &p_file, int
oe.msec = time % 1000;
oe.callstack.append_array(script_debugger->get_error_stack_info());
- if (flushing && Thread::get_caller_id() == flush_thread) // Can't handle recursive errors during flush.
+ if (flushing && Thread::get_caller_id() == flush_thread) { // Can't handle recursive errors during flush.
return;
+ }
MutexLock lock(mutex);
@@ -609,7 +612,6 @@ void RemoteDebugger::send_error(const String &p_func, const String &p_file, int
}
if (is_peer_connected()) {
-
if (oe.warning) {
if (warn_count > max_warnings_per_second) {
n_warnings_dropped++;
@@ -657,24 +659,26 @@ Error RemoteDebugger::_try_capture(const String &p_msg, const Array &p_data, boo
return OK;
}
const String cap = p_msg.substr(0, idx);
- if (!has_capture(cap))
+ if (!has_capture(cap)) {
return ERR_UNAVAILABLE; // Unknown message...
+ }
const String msg = p_msg.substr(idx + 1);
return capture_parse(cap, msg, p_data, r_captured);
}
void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
-
//this function is called when there is a debugger break (bug on script)
//or when execution is paused from editor
- if (script_debugger->is_skipping_breakpoints() && !p_is_error_breakpoint)
+ if (script_debugger->is_skipping_breakpoints() && !p_is_error_breakpoint) {
return;
+ }
ERR_FAIL_COND_MSG(!is_peer_connected(), "Script Debugger failed to connect, but being used anyway.");
- if (!peer->can_block())
+ if (!peer->can_block()) {
return; // Peer does not support blocking IO. We could at least send the error though.
+ }
ScriptLanguage *script_lang = script_debugger->get_break_language();
const String error_str = script_lang ? script_lang->debug_get_error() : "";
@@ -686,8 +690,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
servers_profiler->skip_profile_frame = true; // Avoid frame time spike in debug.
Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode();
- if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
+ if (mouse_mode != Input::MOUSE_MODE_VISIBLE) {
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
+ }
uint64_t loop_begin_usec = 0;
uint64_t loop_time_sec = 0;
@@ -698,7 +703,6 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
peer->poll();
if (peer->has_message()) {
-
Array cmd = peer->get_message();
ERR_CONTINUE(cmd.size() != 2);
@@ -776,10 +780,11 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
} else if (command == "breakpoint") {
ERR_FAIL_COND(data.size() < 3);
bool set = data[2];
- if (set)
+ if (set) {
script_debugger->insert_breakpoint(data[1], data[0]);
- else
+ } else {
script_debugger->remove_breakpoint(data[1], data[0]);
+ }
} else if (command == "set_skip_breakpoints") {
ERR_FAIL_COND(data.size() < 1);
@@ -787,8 +792,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
} else {
bool captured = false;
ERR_CONTINUE(_try_capture(command, data, captured) != OK);
- if (!captured)
+ if (!captured) {
WARN_PRINT("Unknown message received from debugger: " + command);
+ }
}
} else {
OS::get_singleton()->delay_usec(10000);
@@ -805,18 +811,19 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
send_message("debug_exit", Array());
- if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
+ if (mouse_mode != Input::MOUSE_MODE_VISIBLE) {
Input::get_singleton()->set_mouse_mode(mouse_mode);
+ }
}
void RemoteDebugger::poll_events(bool p_is_idle) {
- if (peer.is_null())
+ if (peer.is_null()) {
return;
+ }
flush_output();
peer->poll();
while (peer->has_message()) {
-
Array arr = peer->get_message();
ERR_CONTINUE(arr.size() != 2);
@@ -832,8 +839,9 @@ void RemoteDebugger::poll_events(bool p_is_idle) {
}
const String cap = cmd.substr(0, idx);
- if (!has_capture(cap))
+ if (!has_capture(cap)) {
continue; // Unknown message...
+ }
const String msg = cmd.substr(idx + 1);
capture_parse(cap, msg, arr[1], parsed);
@@ -856,10 +864,11 @@ Error RemoteDebugger::_core_capture(const String &p_cmd, const Array &p_data, bo
} else if (p_cmd == "breakpoint") {
ERR_FAIL_COND_V(p_data.size() < 3, ERR_INVALID_DATA);
bool set = p_data[2];
- if (set)
+ if (set) {
script_debugger->insert_breakpoint(p_data[1], p_data[0]);
- else
+ } else {
script_debugger->remove_breakpoint(p_data[1], p_data[0]);
+ }
} else if (p_cmd == "set_skip_breakpoints") {
ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA);
@@ -950,6 +959,7 @@ RemoteDebugger::~RemoteDebugger() {
memdelete(servers_profiler);
memdelete(network_profiler);
memdelete(visual_profiler);
- if (performance_profiler)
+ if (performance_profiler) {
memdelete(performance_profiler);
+ }
}
diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp
index 458c46df93..fd1eee0654 100644
--- a/core/debugger/remote_debugger_peer.cpp
+++ b/core/debugger/remote_debugger_peer.cpp
@@ -52,8 +52,9 @@ Array RemoteDebuggerPeerTCP::get_message() {
Error RemoteDebuggerPeerTCP::put_message(const Array &p_arr) {
MutexLock lock(mutex);
- if (out_queue.size() >= max_queued_messages)
+ if (out_queue.size() >= max_queued_messages) {
return ERR_OUT_OF_MEMORY;
+ }
out_queue.push_back(p_arr);
return OK;
@@ -99,8 +100,9 @@ void RemoteDebuggerPeerTCP::_write_out() {
while (tcp_client->poll(NetSocket::POLL_TYPE_OUT) == OK) {
uint8_t *buf = out_buf.ptrw();
if (out_left <= 0) {
- if (out_queue.size() == 0)
+ if (out_queue.size() == 0) {
break; // Nothing left to send
+ }
mutex.lock();
Variant var = out_queue[0];
out_queue.pop_front();
@@ -154,12 +156,12 @@ void RemoteDebuggerPeerTCP::_read_in() {
}
Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_port) {
-
IP_Address ip;
- if (p_host.is_valid_ip_address())
+ if (p_host.is_valid_ip_address()) {
ip = p_host;
- else
+ } else {
ip = IP::get_singleton()->resolve_hostname(p_host);
+ }
int port = p_port;
@@ -169,12 +171,10 @@ Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_po
tcp_client->connect_to_host(ip, port);
for (int i = 0; i < tries; i++) {
-
if (tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED) {
print_verbose("Remote Debugger: Connected!");
break;
} else {
-
const int ms = waits[i];
OS::get_singleton()->delay_usec(ms * 1000);
print_verbose("Remote Debugger: Connection failed with status: '" + String::num(tcp_client->get_status()) + "', retrying in " + String::num(ms) + " msec.");
@@ -182,7 +182,6 @@ Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_po
};
if (tcp_client->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
-
ERR_PRINT("Remote Debugger: Unable to connect. Status: " + String::num(tcp_client->get_status()) + ".");
return FAILED;
};
@@ -198,8 +197,9 @@ void RemoteDebuggerPeerTCP::_thread_func(void *p_ud) {
RemoteDebuggerPeerTCP *peer = (RemoteDebuggerPeerTCP *)p_ud;
while (peer->running && peer->is_peer_connected()) {
peer->_poll();
- if (!peer->is_peer_connected())
+ if (!peer->is_peer_connected()) {
break;
+ }
peer->tcp_client->poll(NetSocket::POLL_TYPE_IN_OUT, 1);
}
}
diff --git a/core/debugger/script_debugger.cpp b/core/debugger/script_debugger.cpp
index 935ad01d80..0cd3238efb 100644
--- a/core/debugger/script_debugger.cpp
+++ b/core/debugger/script_debugger.cpp
@@ -33,69 +33,63 @@
#include "core/debugger/engine_debugger.h"
void ScriptDebugger::set_lines_left(int p_left) {
-
lines_left = p_left;
}
int ScriptDebugger::get_lines_left() const {
-
return lines_left;
}
void ScriptDebugger::set_depth(int p_depth) {
-
depth = p_depth;
}
int ScriptDebugger::get_depth() const {
-
return depth;
}
void ScriptDebugger::insert_breakpoint(int p_line, const StringName &p_source) {
-
- if (!breakpoints.has(p_line))
+ if (!breakpoints.has(p_line)) {
breakpoints[p_line] = Set<StringName>();
+ }
breakpoints[p_line].insert(p_source);
}
void ScriptDebugger::remove_breakpoint(int p_line, const StringName &p_source) {
-
- if (!breakpoints.has(p_line))
+ if (!breakpoints.has(p_line)) {
return;
+ }
breakpoints[p_line].erase(p_source);
- if (breakpoints[p_line].size() == 0)
+ if (breakpoints[p_line].size() == 0) {
breakpoints.erase(p_line);
+ }
}
-bool ScriptDebugger::is_breakpoint(int p_line, const StringName &p_source) const {
- if (!breakpoints.has(p_line))
+bool ScriptDebugger::is_breakpoint(int p_line, const StringName &p_source) const {
+ if (!breakpoints.has(p_line)) {
return false;
+ }
return breakpoints[p_line].has(p_source);
}
-bool ScriptDebugger::is_breakpoint_line(int p_line) const {
+bool ScriptDebugger::is_breakpoint_line(int p_line) const {
return breakpoints.has(p_line);
}
String ScriptDebugger::breakpoint_find_source(const String &p_source) const {
-
return p_source;
}
void ScriptDebugger::clear_breakpoints() {
-
breakpoints.clear();
}
void ScriptDebugger::set_skip_breakpoints(bool p_skip_breakpoints) {
-
skip_breakpoints = p_skip_breakpoints;
}
bool ScriptDebugger::is_skipping_breakpoints() {
-
return skip_breakpoints;
}
@@ -118,6 +112,5 @@ Vector<ScriptLanguage::StackInfo> ScriptDebugger::get_error_stack_info() const {
}
ScriptLanguage *ScriptDebugger::get_break_language() const {
-
return break_lang;
}
diff --git a/core/debugger/script_debugger.h b/core/debugger/script_debugger.h
index e5066273d2..0068691825 100644
--- a/core/debugger/script_debugger.h
+++ b/core/debugger/script_debugger.h
@@ -38,7 +38,6 @@
#include "core/vector.h"
class ScriptDebugger {
-
typedef ScriptLanguage::StackInfo StackInfo;
int lines_left = -1;
diff --git a/core/dictionary.cpp b/core/dictionary.cpp
index bc3b792bd5..052e1bdae1 100644
--- a/core/dictionary.cpp
+++ b/core/dictionary.cpp
@@ -35,15 +35,14 @@
#include "core/variant.h"
struct DictionaryPrivate {
-
SafeRefCount refcount;
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> variant_map;
};
void Dictionary::get_key_list(List<Variant> *p_keys) const {
-
- if (_p->variant_map.empty())
+ if (_p->variant_map.empty()) {
return;
+ }
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
p_keys->push_back(E.key());
@@ -51,7 +50,6 @@ void Dictionary::get_key_list(List<Variant> *p_keys) const {
}
Variant Dictionary::get_key_at_index(int p_index) const {
-
int index = 0;
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
if (index == p_index) {
@@ -64,7 +62,6 @@ Variant Dictionary::get_key_at_index(int p_index) const {
}
Variant Dictionary::get_value_at_index(int p_index) const {
-
int index = 0;
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
if (index == p_index) {
@@ -77,38 +74,37 @@ Variant Dictionary::get_value_at_index(int p_index) const {
}
Variant &Dictionary::operator[](const Variant &p_key) {
-
return _p->variant_map[p_key];
}
const Variant &Dictionary::operator[](const Variant &p_key) const {
-
return _p->variant_map[p_key];
}
-const Variant *Dictionary::getptr(const Variant &p_key) const {
+const Variant *Dictionary::getptr(const Variant &p_key) const {
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key);
- if (!E)
+ if (!E) {
return nullptr;
+ }
return &E.get();
}
Variant *Dictionary::getptr(const Variant &p_key) {
-
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(p_key);
- if (!E)
+ if (!E) {
return nullptr;
+ }
return &E.get();
}
Variant Dictionary::get_valid(const Variant &p_key) const {
-
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key);
- if (!E)
+ if (!E) {
return Variant();
+ }
return E.get();
}
@@ -122,16 +118,14 @@ Variant Dictionary::get(const Variant &p_key, const Variant &p_default) const {
}
int Dictionary::size() const {
-
return _p->variant_map.size();
}
-bool Dictionary::empty() const {
+bool Dictionary::empty() const {
return !_p->variant_map.size();
}
bool Dictionary::has(const Variant &p_key) const {
-
return _p->variant_map.has(p_key);
}
@@ -145,51 +139,47 @@ bool Dictionary::has_all(const Array &p_keys) const {
}
bool Dictionary::erase(const Variant &p_key) {
-
return _p->variant_map.erase(p_key);
}
bool Dictionary::operator==(const Dictionary &p_dictionary) const {
-
return _p == p_dictionary._p;
}
bool Dictionary::operator!=(const Dictionary &p_dictionary) const {
-
return _p != p_dictionary._p;
}
void Dictionary::_ref(const Dictionary &p_from) const {
-
//make a copy first (thread safe)
- if (!p_from._p->refcount.ref())
+ if (!p_from._p->refcount.ref()) {
return; // couldn't copy
+ }
//if this is the same, unreference the other one
if (p_from._p == _p) {
_p->refcount.unref();
return;
}
- if (_p)
+ if (_p) {
_unref();
+ }
_p = p_from._p;
}
void Dictionary::clear() {
-
_p->variant_map.clear();
}
void Dictionary::_unref() const {
-
ERR_FAIL_COND(!_p);
if (_p->refcount.unref()) {
memdelete(_p);
}
_p = nullptr;
}
-uint32_t Dictionary::hash() const {
+uint32_t Dictionary::hash() const {
uint32_t h = hash_djb2_one_32(Variant::DICTIONARY);
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
@@ -201,10 +191,10 @@ uint32_t Dictionary::hash() const {
}
Array Dictionary::keys() const {
-
Array varr;
- if (_p->variant_map.empty())
+ if (_p->variant_map.empty()) {
return varr;
+ }
varr.resize(size());
@@ -218,10 +208,10 @@ Array Dictionary::keys() const {
}
Array Dictionary::values() const {
-
Array varr;
- if (_p->variant_map.empty())
+ if (_p->variant_map.empty()) {
return varr;
+ }
varr.resize(size());
@@ -235,22 +225,22 @@ Array Dictionary::values() const {
}
const Variant *Dictionary::next(const Variant *p_key) const {
-
if (p_key == nullptr) {
// caller wants to get the first element
- if (_p->variant_map.front())
+ if (_p->variant_map.front()) {
return &_p->variant_map.front().key();
+ }
return nullptr;
}
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(*p_key);
- if (E && E.next())
+ if (E && E.next()) {
return &E.next().key();
+ }
return nullptr;
}
Dictionary Dictionary::duplicate(bool p_deep) const {
-
Dictionary n;
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
@@ -261,7 +251,6 @@ Dictionary Dictionary::duplicate(bool p_deep) const {
}
void Dictionary::operator=(const Dictionary &p_dictionary) {
-
_ref(p_dictionary);
}
@@ -275,11 +264,10 @@ Dictionary::Dictionary(const Dictionary &p_from) {
}
Dictionary::Dictionary() {
-
_p = memnew(DictionaryPrivate);
_p->refcount.init();
}
-Dictionary::~Dictionary() {
+Dictionary::~Dictionary() {
_unref();
}
diff --git a/core/dictionary.h b/core/dictionary.h
index c6cbacc144..a01d96ba01 100644
--- a/core/dictionary.h
+++ b/core/dictionary.h
@@ -40,7 +40,6 @@ class Variant;
struct DictionaryPrivate;
class Dictionary {
-
mutable DictionaryPrivate *_p;
void _ref(const Dictionary &p_from) const;
diff --git a/core/engine.cpp b/core/engine.cpp
index 86ce0395b9..43c5766431 100644
--- a/core/engine.cpp
+++ b/core/engine.cpp
@@ -37,18 +37,18 @@
#include "core/version_hash.gen.h"
void Engine::set_iterations_per_second(int p_ips) {
-
ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0.");
ips = p_ips;
}
-int Engine::get_iterations_per_second() const {
+int Engine::get_iterations_per_second() const {
return ips;
}
void Engine::set_physics_jitter_fix(float p_threshold) {
- if (p_threshold < 0)
+ if (p_threshold < 0) {
p_threshold = 0;
+ }
physics_jitter_fix = p_threshold;
}
@@ -65,32 +65,26 @@ int Engine::get_target_fps() const {
}
uint64_t Engine::get_frames_drawn() {
-
return frames_drawn;
}
void Engine::set_frame_delay(uint32_t p_msec) {
-
_frame_delay = p_msec;
}
uint32_t Engine::get_frame_delay() const {
-
return _frame_delay;
}
void Engine::set_time_scale(float p_scale) {
-
_time_scale = p_scale;
}
float Engine::get_time_scale() const {
-
return _time_scale;
}
Dictionary Engine::get_version_info() const {
-
Dictionary dict;
dict["major"] = VERSION_MAJOR;
dict["minor"] = VERSION_MINOR;
@@ -104,8 +98,9 @@ Dictionary Engine::get_version_info() const {
dict["hash"] = hash.length() == 0 ? String("unknown") : hash;
String stringver = String(dict["major"]) + "." + String(dict["minor"]);
- if ((int)dict["patch"] != 0)
+ if ((int)dict["patch"] != 0) {
stringver += "." + String(dict["patch"]);
+ }
stringver += "-" + String(dict["status"]) + " (" + String(dict["build"]) + ")";
dict["string"] = stringver;
@@ -185,27 +180,24 @@ String Engine::get_license_text() const {
}
void Engine::add_singleton(const Singleton &p_singleton) {
-
singletons.push_back(p_singleton);
singleton_ptrs[p_singleton.name] = p_singleton.ptr;
}
Object *Engine::get_singleton_object(const String &p_name) const {
-
const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name);
ERR_FAIL_COND_V_MSG(!E, nullptr, "Failed to retrieve non-existent singleton '" + p_name + "'.");
return E->get();
};
bool Engine::has_singleton(const String &p_name) const {
-
return singleton_ptrs.has(p_name);
};
void Engine::get_singletons(List<Singleton> *p_singletons) {
-
- for (List<Singleton>::Element *E = singletons.front(); E; E = E->next())
+ for (List<Singleton>::Element *E = singletons.front(); E; E = E->next()) {
p_singletons->push_back(E->get());
+ }
}
Engine *Engine::singleton = nullptr;
diff --git a/core/engine.h b/core/engine.h
index aa28b35814..fef330c0c1 100644
--- a/core/engine.h
+++ b/core/engine.h
@@ -37,7 +37,6 @@
#include "core/vector.h"
class Engine {
-
public:
struct Singleton {
StringName name;
diff --git a/core/error_macros.cpp b/core/error_macros.cpp
index 5de070844a..2fae939965 100644
--- a/core/error_macros.cpp
+++ b/core/error_macros.cpp
@@ -37,7 +37,6 @@
static ErrorHandlerList *error_handler_list = nullptr;
void add_error_handler(ErrorHandlerList *p_handler) {
-
_global_lock();
p_handler->next = error_handler_list;
error_handler_list = p_handler;
@@ -45,20 +44,18 @@ void add_error_handler(ErrorHandlerList *p_handler) {
}
void remove_error_handler(ErrorHandlerList *p_handler) {
-
_global_lock();
ErrorHandlerList *prev = nullptr;
ErrorHandlerList *l = error_handler_list;
while (l) {
-
if (l == p_handler) {
-
- if (prev)
+ if (prev) {
prev->next = l->next;
- else
+ } else {
error_handler_list = l->next;
+ }
break;
}
prev = l;
@@ -77,13 +74,11 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
}
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, ErrorHandlerType p_type) {
-
OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, p_message, (Logger::ErrorType)p_type);
_global_lock();
ErrorHandlerList *l = error_handler_list;
while (l) {
-
l->errfunc(l->userdata, p_function, p_file, p_line, p_error, p_message, p_type);
l = l->next;
}
@@ -104,7 +99,6 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
}
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message, bool fatal) {
-
String fstr(fatal ? "FATAL: " : "");
String err(fstr + "Index " + p_index_str + " = " + itos(p_index) + " is out of bounds (" + p_size_str + " = " + itos(p_size) + ").");
_err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message);
diff --git a/core/error_macros.h b/core/error_macros.h
index eb2cc5215d..a592f752d5 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -47,7 +47,6 @@ enum ErrorHandlerType {
typedef void (*ErrorHandlerFunc)(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
struct ErrorHandlerList {
-
ErrorHandlerFunc errfunc = nullptr;
void *userdata = nullptr;
diff --git a/core/func_ref.cpp b/core/func_ref.cpp
index ad29f4488d..4427d94d2a 100644
--- a/core/func_ref.cpp
+++ b/core/func_ref.cpp
@@ -31,7 +31,6 @@
#include "func_ref.h"
Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
-
if (id.is_null()) {
r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
return Variant();
@@ -47,7 +46,6 @@ Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Callable::Cal
}
Variant FuncRef::call_funcv(const Array &p_args) {
-
ERR_FAIL_COND_V(id.is_null(), Variant());
Object *obj = ObjectDB::get_instance(id);
@@ -58,29 +56,28 @@ Variant FuncRef::call_funcv(const Array &p_args) {
}
void FuncRef::set_instance(Object *p_obj) {
-
ERR_FAIL_NULL(p_obj);
id = p_obj->get_instance_id();
}
void FuncRef::set_function(const StringName &p_func) {
-
function = p_func;
}
bool FuncRef::is_valid() const {
- if (id.is_null())
+ if (id.is_null()) {
return false;
+ }
Object *obj = ObjectDB::get_instance(id);
- if (!obj)
+ if (!obj) {
return false;
+ }
return obj->has_method(function);
}
void FuncRef::_bind_methods() {
-
{
MethodInfo mi;
mi.name = "call_func";
diff --git a/core/func_ref.h b/core/func_ref.h
index 07b361db2d..6b0b22bab5 100644
--- a/core/func_ref.h
+++ b/core/func_ref.h
@@ -34,7 +34,6 @@
#include "core/reference.h"
class FuncRef : public Reference {
-
GDCLASS(FuncRef, Reference);
ObjectID id;
StringName function;
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index 4f415a2056..6281e56395 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -36,7 +36,6 @@
#include "core/variant.h"
struct _GlobalConstant {
-
#ifdef DEBUG_METHODS_ENABLED
StringName enum_name;
#endif
@@ -638,33 +637,27 @@ void register_global_constants() {
}
void unregister_global_constants() {
-
_global_constants.clear();
}
int GlobalConstants::get_global_constant_count() {
-
return _global_constants.size();
}
#ifdef DEBUG_METHODS_ENABLED
StringName GlobalConstants::get_global_constant_enum(int p_idx) {
-
return _global_constants[p_idx].enum_name;
}
#else
StringName GlobalConstants::get_global_constant_enum(int p_idx) {
-
return StringName();
}
#endif
const char *GlobalConstants::get_global_constant_name(int p_idx) {
-
return _global_constants[p_idx].name;
}
int GlobalConstants::get_global_constant_value(int p_idx) {
-
return _global_constants[p_idx].value;
}
diff --git a/core/hash_map.h b/core/hash_map.h
index cfc0f87010..78592f8d82 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -59,7 +59,6 @@ template <class TKey, class TData, class Hasher = HashMapHasherDefault, class Co
class HashMap {
public:
struct Pair {
-
TKey key;
TData data;
@@ -99,19 +98,18 @@ private:
uint32_t elements = 0;
void make_hash_table() {
-
ERR_FAIL_COND(hash_table);
hash_table = memnew_arr(Element *, (1 << MIN_HASH_TABLE_POWER));
hash_table_power = MIN_HASH_TABLE_POWER;
elements = 0;
- for (int i = 0; i < (1 << MIN_HASH_TABLE_POWER); i++)
+ for (int i = 0; i < (1 << MIN_HASH_TABLE_POWER); i++) {
hash_table[i] = nullptr;
+ }
}
void erase_hash_table() {
-
ERR_FAIL_COND_MSG(elements, "Cannot erase hash table if there are still elements inside.");
memdelete_arr(hash_table);
@@ -121,7 +119,6 @@ private:
}
void check_hash_table() {
-
int new_hash_table_power = -1;
if ((int)elements > ((1 << hash_table_power) * RELATIONSHIP)) {
@@ -129,40 +126,36 @@ private:
new_hash_table_power = hash_table_power + 1;
while ((int)elements > ((1 << new_hash_table_power) * RELATIONSHIP)) {
-
new_hash_table_power++;
}
} else if ((hash_table_power > (int)MIN_HASH_TABLE_POWER) && ((int)elements < ((1 << (hash_table_power - 1)) * RELATIONSHIP))) {
-
/* rehash down */
new_hash_table_power = hash_table_power - 1;
while ((int)elements < ((1 << (new_hash_table_power - 1)) * RELATIONSHIP)) {
-
new_hash_table_power--;
}
- if (new_hash_table_power < (int)MIN_HASH_TABLE_POWER)
+ if (new_hash_table_power < (int)MIN_HASH_TABLE_POWER) {
new_hash_table_power = MIN_HASH_TABLE_POWER;
+ }
}
- if (new_hash_table_power == -1)
+ if (new_hash_table_power == -1) {
return;
+ }
Element **new_hash_table = memnew_arr(Element *, ((uint64_t)1 << new_hash_table_power));
ERR_FAIL_COND_MSG(!new_hash_table, "Out of memory.");
for (int i = 0; i < (1 << new_hash_table_power); i++) {
-
new_hash_table[i] = nullptr;
}
if (hash_table) {
for (int i = 0; i < (1 << hash_table_power); i++) {
-
while (hash_table[i]) {
-
Element *se = hash_table[i];
hash_table[i] = se->next;
int new_pos = se->hash & ((1 << new_hash_table_power) - 1);
@@ -179,17 +172,14 @@ private:
/* I want to have only one function.. */
_FORCE_INLINE_ const Element *get_element(const TKey &p_key) const {
-
uint32_t hash = Hasher::hash(p_key);
uint32_t index = hash & ((1 << hash_table_power) - 1);
Element *e = hash_table[index];
while (e) {
-
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) {
-
/* the pair exists in this hashtable, so just update data */
return e;
}
@@ -201,7 +191,6 @@ private:
}
Element *create_element(const TKey &p_key) {
-
/* if element doesn't exist, create it */
Element *e = memnew(Element);
ERR_FAIL_COND_V_MSG(!e, nullptr, "Out of memory.");
@@ -219,27 +208,26 @@ private:
}
void copy_from(const HashMap &p_t) {
-
- if (&p_t == this)
+ if (&p_t == this) {
return; /* much less bother with that */
+ }
clear();
- if (!p_t.hash_table || p_t.hash_table_power == 0)
+ if (!p_t.hash_table || p_t.hash_table_power == 0) {
return; /* not copying from empty table */
+ }
hash_table = memnew_arr(Element *, (uint64_t)1 << p_t.hash_table_power);
hash_table_power = p_t.hash_table_power;
elements = p_t.elements;
for (int i = 0; i < (1 << p_t.hash_table_power); i++) {
-
hash_table[i] = nullptr;
const Element *e = p_t.hash_table[i];
while (e) {
-
Element *le = memnew(Element); /* local element */
*le = *e; /* copy data */
@@ -259,20 +247,20 @@ public:
}
Element *set(const Pair &p_pair) {
-
Element *e = nullptr;
- if (!hash_table)
+ if (!hash_table) {
make_hash_table(); // if no table, make one
- else
+ } else {
e = const_cast<Element *>(get_element(p_pair.key));
+ }
/* if we made it up to here, the pair doesn't exist, create and assign */
if (!e) {
-
e = create_element(p_pair.key);
- if (!e)
+ if (!e) {
return nullptr;
+ }
check_hash_table(); // perform mantenience routine
}
@@ -281,7 +269,6 @@ public:
}
bool has(const TKey &p_key) const {
-
return getptr(p_key) != nullptr;
}
@@ -292,14 +279,12 @@ public:
*/
const TData &get(const TKey &p_key) const {
-
const TData *res = getptr(p_key);
ERR_FAIL_COND_V(!res, *res);
return *res;
}
TData &get(const TKey &p_key) {
-
TData *res = getptr(p_key);
ERR_FAIL_COND_V(!res, *res);
return *res;
@@ -311,27 +296,29 @@ public:
*/
_FORCE_INLINE_ TData *getptr(const TKey &p_key) {
-
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return nullptr;
+ }
Element *e = const_cast<Element *>(get_element(p_key));
- if (e)
+ if (e) {
return &e->pair.data;
+ }
return nullptr;
}
_FORCE_INLINE_ const TData *getptr(const TKey &p_key) const {
-
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return nullptr;
+ }
const Element *e = const_cast<Element *>(get_element(p_key));
- if (e)
+ if (e) {
return &e->pair.data;
+ }
return nullptr;
}
@@ -343,9 +330,9 @@ public:
template <class C>
_FORCE_INLINE_ TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) {
-
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return nullptr;
+ }
uint32_t hash = p_custom_hash;
uint32_t index = hash & ((1 << hash_table_power) - 1);
@@ -353,10 +340,8 @@ public:
Element *e = hash_table[index];
while (e) {
-
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) {
-
/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
}
@@ -369,9 +354,9 @@ public:
template <class C>
_FORCE_INLINE_ const TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) const {
-
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return nullptr;
+ }
uint32_t hash = p_custom_hash;
uint32_t index = hash & ((1 << hash_table_power) - 1);
@@ -379,10 +364,8 @@ public:
const Element *e = hash_table[index];
while (e) {
-
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) {
-
/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
}
@@ -398,9 +381,9 @@ public:
*/
bool erase(const TKey &p_key) {
-
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return false;
+ }
uint32_t hash = Hasher::hash(p_key);
uint32_t index = hash & ((1 << hash_table_power) - 1);
@@ -408,12 +391,9 @@ public:
Element *e = hash_table[index];
Element *p = nullptr;
while (e) {
-
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) {
-
if (p) {
-
p->next = e->next;
} else {
//begin of list
@@ -423,10 +403,11 @@ public:
memdelete(e);
elements--;
- if (elements == 0)
+ if (elements == 0) {
erase_hash_table();
- else
+ } else {
check_hash_table();
+ }
return true;
}
@@ -444,14 +425,14 @@ public:
inline TData &operator[](const TKey &p_key) { //assignment
Element *e = nullptr;
- if (!hash_table)
+ if (!hash_table) {
make_hash_table(); // if no table, make one
- else
+ } else {
e = const_cast<Element *>(get_element(p_key));
+ }
/* if we made it up to here, the pair doesn't exist, create */
if (!e) {
-
e = create_element(p_key);
CRASH_COND(!e);
check_hash_table(); // perform mantenience routine
@@ -476,14 +457,13 @@ public:
*
*/
const TKey *next(const TKey *p_key) const {
-
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return nullptr;
+ }
if (!p_key) { /* get the first key */
for (int i = 0; i < (1 << hash_table_power); i++) {
-
if (hash_table[i]) {
return &hash_table[i]->pair.key;
}
@@ -501,7 +481,6 @@ public:
uint32_t index = e->hash & ((1 << hash_table_power) - 1);
index++;
for (int i = index; i < (1 << hash_table_power); i++) {
-
if (hash_table[i]) {
return &hash_table[i]->pair.key;
}
@@ -515,23 +494,18 @@ public:
}
inline unsigned int size() const {
-
return elements;
}
inline bool empty() const {
-
return elements == 0;
}
void clear() {
-
/* clean up */
if (hash_table) {
for (int i = 0; i < (1 << hash_table_power); i++) {
-
while (hash_table[i]) {
-
Element *e = hash_table[i];
hash_table[i] = e->next;
memdelete(e);
@@ -547,15 +521,14 @@ public:
}
void operator=(const HashMap &p_table) {
-
copy_from(p_table);
}
void get_key_value_ptr_array(const Pair **p_pairs) const {
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return;
+ }
for (int i = 0; i < (1 << hash_table_power); i++) {
-
Element *e = hash_table[i];
while (e) {
*p_pairs = &e->pair;
@@ -566,10 +539,10 @@ public:
}
void get_key_list(List<TKey> *p_keys) const {
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return;
+ }
for (int i = 0; i < (1 << hash_table_power); i++) {
-
Element *e = hash_table[i];
while (e) {
p_keys->push_back(e->pair.key);
diff --git a/core/hashfuncs.h b/core/hashfuncs.h
index a41a034843..d984f6c524 100644
--- a/core/hashfuncs.h
+++ b/core/hashfuncs.h
@@ -49,29 +49,28 @@
* @return 32-bits hashcode
*/
static inline uint32_t hash_djb2(const char *p_cstr) {
-
const unsigned char *chr = (const unsigned char *)p_cstr;
uint32_t hash = 5381;
uint32_t c;
- while ((c = *chr++))
+ while ((c = *chr++)) {
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
+ }
return hash;
}
static inline uint32_t hash_djb2_buffer(const uint8_t *p_buff, int p_len, uint32_t p_prev = 5381) {
-
uint32_t hash = p_prev;
- for (int i = 0; i < p_len; i++)
+ for (int i = 0; i < p_len; i++) {
hash = ((hash << 5) + hash) + p_buff[i]; /* hash * 33 + c */
+ }
return hash;
}
static inline uint32_t hash_djb2_one_32(uint32_t p_in, uint32_t p_prev = 5381) {
-
return ((p_prev << 5) + p_prev) + p_in;
}
@@ -93,19 +92,19 @@ static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381)
} u;
// Normalize +/- 0.0 and NaN values so they hash the same.
- if (p_in == 0.0f)
+ if (p_in == 0.0f) {
u.d = 0.0;
- else if (Math::is_nan(p_in))
+ } else if (Math::is_nan(p_in)) {
u.d = Math_NAN;
- else
+ } else {
u.d = p_in;
+ }
return ((p_prev << 5) + p_prev) + hash_one_uint64(u.i);
}
template <class T>
static inline uint32_t make_uint32_t(T p_in) {
-
union {
T t;
uint32_t _u32;
@@ -116,13 +115,11 @@ static inline uint32_t make_uint32_t(T p_in) {
}
static inline uint64_t hash_djb2_one_64(uint64_t p_in, uint64_t p_prev = 5381) {
-
return ((p_prev << 5) + p_prev) + p_in;
}
template <class T>
static inline uint64_t make_uint64_t(T p_in) {
-
union {
T t;
uint64_t _u64;
@@ -134,7 +131,6 @@ static inline uint64_t make_uint64_t(T p_in) {
}
struct HashMapHasherDefault {
-
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }
diff --git a/core/image.cpp b/core/image.cpp
index c88ed7e3cb..29be2ff5eb 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -90,7 +90,6 @@ SaveEXRFunc Image::save_exr_func = nullptr;
SavePNGBufferFunc Image::save_png_buffer_func = nullptr;
void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, const uint8_t *p_pixel) {
-
uint32_t ofs = (p_y * width + p_x) * p_pixelsize;
for (uint32_t i = 0; i < p_pixelsize; i++) {
@@ -99,7 +98,6 @@ void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data,
}
void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_data, uint8_t *p_pixel) {
-
uint32_t ofs = (p_y * width + p_x) * p_pixelsize;
for (uint32_t i = 0; i < p_pixelsize; i++) {
@@ -108,7 +106,6 @@ void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p
}
int Image::get_format_pixel_size(Format p_format) {
-
switch (p_format) {
case FORMAT_L8:
return 1; //luminance
@@ -195,7 +192,6 @@ int Image::get_format_pixel_size(Format p_format) {
}
void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
-
switch (p_format) {
case FORMAT_DXT1: //s3tc bc1
case FORMAT_DXT3: //bc2
@@ -208,25 +204,21 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
} break;
case FORMAT_PVRTC2:
case FORMAT_PVRTC2A: {
-
r_w = 16;
r_h = 8;
} break;
case FORMAT_PVRTC4A:
case FORMAT_PVRTC4: {
-
r_w = 8;
r_h = 8;
} break;
case FORMAT_ETC: {
-
r_w = 4;
r_h = 4;
} break;
case FORMAT_BPTC_RGBA:
case FORMAT_BPTC_RGBF:
case FORMAT_BPTC_RGBFU: {
-
r_w = 4;
r_h = 4;
} break;
@@ -239,7 +231,6 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
case FORMAT_ETC2_RGB8A1:
case FORMAT_ETC2_RA_AS_RG:
case FORMAT_DXT5_RA_AS_RG: {
-
r_w = 4;
r_h = 4;
@@ -253,17 +244,16 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
}
int Image::get_format_pixel_rshift(Format p_format) {
-
- if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1)
+ if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1) {
return 1;
- else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A)
+ } else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A) {
return 2;
- else
+ } else {
return 0;
+ }
}
int Image::get_format_block_size(Format p_format) {
-
switch (p_format) {
case FORMAT_DXT1: //s3tc bc1
case FORMAT_DXT3: //bc2
@@ -275,22 +265,18 @@ int Image::get_format_block_size(Format p_format) {
}
case FORMAT_PVRTC2:
case FORMAT_PVRTC2A: {
-
return 4;
}
case FORMAT_PVRTC4A:
case FORMAT_PVRTC4: {
-
return 4;
}
case FORMAT_ETC: {
-
return 4;
}
case FORMAT_BPTC_RGBA:
case FORMAT_BPTC_RGBF:
case FORMAT_BPTC_RGBFU: {
-
return 4;
}
case FORMAT_ETC2_R11: //etc2
@@ -304,7 +290,6 @@ int Image::get_format_block_size(Format p_format) {
case FORMAT_DXT5_RA_AS_RG: //used to make basis universal happy
{
-
return 4;
}
default: {
@@ -315,7 +300,6 @@ int Image::get_format_block_size(Format p_format) {
}
void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_width, int &r_height) const {
-
int w = width;
int h = height;
int ofs = 0;
@@ -345,7 +329,6 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_widt
}
int Image::get_mipmap_offset(int p_mipmap) const {
-
ERR_FAIL_INDEX_V(p_mipmap, get_mipmap_count() + 1, -1);
int ofs, w, h;
@@ -354,7 +337,6 @@ int Image::get_mipmap_offset(int p_mipmap) const {
}
int Image::get_mipmap_byte_size(int p_mipmap) const {
-
ERR_FAIL_INDEX_V(p_mipmap, get_mipmap_count() + 1, -1);
int ofs, w, h;
@@ -365,7 +347,6 @@ int Image::get_mipmap_byte_size(int p_mipmap) const {
}
void Image::get_mipmap_offset_and_size(int p_mipmap, int &r_ofs, int &r_size) const {
-
int ofs, w, h;
_get_mipmap_offset_and_size(p_mipmap, ofs, w, h);
int ofs2;
@@ -375,7 +356,6 @@ void Image::get_mipmap_offset_and_size(int p_mipmap, int &r_ofs, int &r_size) co
}
void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap, int &r_ofs, int &r_size, int &w, int &h) const {
-
int ofs;
_get_mipmap_offset_and_size(p_mipmap, ofs, w, h);
int ofs2, w2, h2;
@@ -385,42 +365,36 @@ void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap, int &r_ofs, int
}
int Image::get_width() const {
-
return width;
}
int Image::get_height() const {
-
return height;
}
Vector2 Image::get_size() const {
-
return Vector2(width, height);
}
bool Image::has_mipmaps() const {
-
return mipmaps;
}
int Image::get_mipmap_count() const {
-
- if (mipmaps)
+ if (mipmaps) {
return get_image_required_mipmaps(width, height, format);
- else
+ } else {
return 0;
+ }
}
//using template generates perfectly optimized code due to constant expression reduction and unused variable removal present in all compilers
template <uint32_t read_bytes, bool read_alpha, uint32_t write_bytes, bool write_alpha, bool read_gray, bool write_gray>
static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p_dst) {
-
uint32_t max_bytes = MAX(read_bytes, write_bytes);
for (int y = 0; y < p_height; y++) {
for (int x = 0; x < p_width; x++) {
-
const uint8_t *rofs = &p_src[((y * p_width) + x) * (read_bytes + (read_alpha ? 1 : 0))];
uint8_t *wofs = &p_dst[((y * p_width) + x) * (write_bytes + (write_alpha ? 1 : 0))];
@@ -431,9 +405,7 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p
rgba[1] = rofs[0];
rgba[2] = rofs[0];
} else {
-
for (uint32_t i = 0; i < max_bytes; i++) {
-
rgba[i] = (i < read_bytes) ? rofs[i] : 0;
}
}
@@ -447,7 +419,6 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p
wofs[0] = uint8_t((uint16_t(rofs[0]) + uint16_t(rofs[1]) + uint16_t(rofs[2])) / 3);
} else {
for (uint32_t i = 0; i < write_bytes; i++) {
-
wofs[i] = rgba[i];
}
}
@@ -460,25 +431,23 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p
}
void Image::convert(Format p_new_format) {
-
- if (data.size() == 0)
+ if (data.size() == 0) {
return;
+ }
- if (p_new_format == format)
+ if (p_new_format == format) {
return;
+ }
if (format > FORMAT_RGBE9995 || p_new_format > FORMAT_RGBE9995) {
-
ERR_FAIL_MSG("Cannot convert to <-> from compressed formats. Use compress() and decompress() instead.");
} else if (format > FORMAT_RGBA8 || p_new_format > FORMAT_RGBA8) {
-
//use put/set pixel which is slower but works with non byte formats
Image new_img(width, height, false, p_new_format);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
-
new_img.set_pixel(i, j, get_pixel(i, j));
}
}
@@ -500,7 +469,6 @@ void Image::convert(Format p_new_format) {
int conversion_type = format | p_new_format << 8;
switch (conversion_type) {
-
case FORMAT_L8 | (FORMAT_LA8 << 8):
_convert<1, false, 1, true, true, true>(width, height, rptr, wptr);
break;
@@ -597,32 +565,31 @@ void Image::convert(Format p_new_format) {
_copy_internals_from(new_img);
- if (gen_mipmaps)
+ if (gen_mipmaps) {
generate_mipmaps();
+ }
}
Image::Format Image::get_format() const {
-
return format;
}
static double _bicubic_interp_kernel(double x) {
-
x = ABS(x);
double bc = 0;
- if (x <= 1)
+ if (x <= 1) {
bc = (1.5 * x - 2.5) * x * x + 1;
- else if (x < 2)
+ } else if (x < 2) {
bc = ((-0.5 * x + 2.5) * x - 4) * x + 2;
+ }
return bc;
}
template <int CC, class T>
static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
-
// get source image size
int width = p_src_width;
int height = p_src_height;
@@ -663,20 +630,24 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
k1 = _bicubic_interp_kernel(dy - (double)n);
oy2 = oy1 + n;
- if (oy2 < 0)
+ if (oy2 < 0) {
oy2 = 0;
- if (oy2 > ymax)
+ }
+ if (oy2 > ymax) {
oy2 = ymax;
+ }
for (int m = -1; m < 3; m++) {
// get X coefficient
k2 = k1 * _bicubic_interp_kernel((double)m - dx);
ox2 = ox1 + m;
- if (ox2 < 0)
+ if (ox2 < 0) {
ox2 = 0;
- if (ox2 > xmax)
+ }
+ if (ox2 > xmax) {
ox2 = xmax;
+ }
// get pixel of original image
const T *__restrict p = ((T *)p_src) + (oy2 * p_src_width + ox2) * CC;
@@ -706,7 +677,6 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
template <int CC, class T>
static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
-
enum {
FRAC_BITS = 8,
FRAC_LEN = (1 << FRAC_BITS),
@@ -715,14 +685,14 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict
};
for (uint32_t i = 0; i < p_dst_height; i++) {
-
uint32_t src_yofs_up_fp = (i * p_src_height * FRAC_LEN / p_dst_height);
uint32_t src_yofs_frac = src_yofs_up_fp & FRAC_MASK;
uint32_t src_yofs_up = src_yofs_up_fp >> FRAC_BITS;
uint32_t src_yofs_down = (i + 1) * p_src_height / p_dst_height;
- if (src_yofs_down >= p_src_height)
+ if (src_yofs_down >= p_src_height) {
src_yofs_down = p_src_height - 1;
+ }
//src_yofs_up*=CC;
//src_yofs_down*=CC;
@@ -731,19 +701,18 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict
uint32_t y_ofs_down = src_yofs_down * p_src_width * CC;
for (uint32_t j = 0; j < p_dst_width; j++) {
-
uint32_t src_xofs_left_fp = (j * p_src_width * FRAC_LEN / p_dst_width);
uint32_t src_xofs_frac = src_xofs_left_fp & FRAC_MASK;
uint32_t src_xofs_left = src_xofs_left_fp >> FRAC_BITS;
uint32_t src_xofs_right = (j + 1) * p_src_width / p_dst_width;
- if (src_xofs_right >= p_src_width)
+ if (src_xofs_right >= p_src_width) {
src_xofs_right = p_src_width - 1;
+ }
src_xofs_left *= CC;
src_xofs_right *= CC;
for (uint32_t l = 0; l < CC; l++) {
-
if (sizeof(T) == 1) { //uint8
uint32_t p00 = p_src[y_ofs_up + src_xofs_left + l] << FRAC_BITS;
uint32_t p10 = p_src[y_ofs_up + src_xofs_right + l] << FRAC_BITS;
@@ -797,19 +766,15 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict
template <int CC, class T>
static void _scale_nearest(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
-
for (uint32_t i = 0; i < p_dst_height; i++) {
-
uint32_t src_yofs = i * p_src_height / p_dst_height;
uint32_t y_ofs = src_yofs * p_src_width * CC;
for (uint32_t j = 0; j < p_dst_width; j++) {
-
uint32_t src_xofs = j * p_src_width / p_dst_width;
src_xofs *= CC;
for (uint32_t l = 0; l < CC; l++) {
-
const T *src = ((const T *)p_src);
T *dst = ((T *)p_dst);
@@ -828,7 +793,6 @@ static float _lanczos(float p_x) {
template <int CC, class T>
static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
-
int32_t src_width = p_src_width;
int32_t src_height = p_src_height;
int32_t dst_height = p_dst_height;
@@ -847,40 +811,40 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
float *kernel = memnew_arr(float, half_kernel * 2);
for (int32_t buffer_x = 0; buffer_x < dst_width; buffer_x++) {
-
// The corresponding point on the source image
float src_x = (buffer_x + 0.5f) * x_scale; // Offset by 0.5 so it uses the pixel's center
int32_t start_x = MAX(0, int32_t(src_x) - half_kernel + 1);
int32_t end_x = MIN(src_width - 1, int32_t(src_x) + half_kernel);
// Create the kernel used by all the pixels of the column
- for (int32_t target_x = start_x; target_x <= end_x; target_x++)
+ for (int32_t target_x = start_x; target_x <= end_x; target_x++) {
kernel[target_x - start_x] = _lanczos((target_x + 0.5f - src_x) / scale_factor);
+ }
for (int32_t buffer_y = 0; buffer_y < src_height; buffer_y++) {
-
float pixel[CC] = { 0 };
float weight = 0;
for (int32_t target_x = start_x; target_x <= end_x; target_x++) {
-
float lanczos_val = kernel[target_x - start_x];
weight += lanczos_val;
const T *__restrict src_data = ((const T *)p_src) + (buffer_y * src_width + target_x) * CC;
for (uint32_t i = 0; i < CC; i++) {
- if (sizeof(T) == 2) //half float
+ if (sizeof(T) == 2) { //half float
pixel[i] += Math::half_to_float(src_data[i]) * lanczos_val;
- else
+ } else {
pixel[i] += src_data[i] * lanczos_val;
+ }
}
}
float *dst_data = ((float *)buffer) + (buffer_y * dst_width + buffer_x) * CC;
- for (uint32_t i = 0; i < CC; i++)
+ for (uint32_t i = 0; i < CC; i++) {
dst_data[i] = pixel[i] / weight; // Normalize the sum of all the samples
+ }
}
}
@@ -897,28 +861,27 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
float *kernel = memnew_arr(float, half_kernel * 2);
for (int32_t dst_y = 0; dst_y < dst_height; dst_y++) {
-
float buffer_y = (dst_y + 0.5f) * y_scale;
int32_t start_y = MAX(0, int32_t(buffer_y) - half_kernel + 1);
int32_t end_y = MIN(src_height - 1, int32_t(buffer_y) + half_kernel);
- for (int32_t target_y = start_y; target_y <= end_y; target_y++)
+ for (int32_t target_y = start_y; target_y <= end_y; target_y++) {
kernel[target_y - start_y] = _lanczos((target_y + 0.5f - buffer_y) / scale_factor);
+ }
for (int32_t dst_x = 0; dst_x < dst_width; dst_x++) {
-
float pixel[CC] = { 0 };
float weight = 0;
for (int32_t target_y = start_y; target_y <= end_y; target_y++) {
-
float lanczos_val = kernel[target_y - start_y];
weight += lanczos_val;
float *buffer_data = ((float *)buffer) + (target_y * dst_width + dst_x) * CC;
- for (uint32_t i = 0; i < CC; i++)
+ for (uint32_t i = 0; i < CC; i++) {
pixel[i] += buffer_data[i] * lanczos_val;
+ }
}
T *dst_data = ((T *)p_dst) + (dst_y * dst_width + dst_x) * CC;
@@ -926,12 +889,13 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
for (uint32_t i = 0; i < CC; i++) {
pixel[i] /= weight;
- if (sizeof(T) == 1) //byte
+ if (sizeof(T) == 1) { //byte
dst_data[i] = CLAMP(Math::fast_ftoi(pixel[i]), 0, 255);
- else if (sizeof(T) == 2) //half float
+ } else if (sizeof(T) == 2) { //half float
dst_data[i] = Math::make_half_float(pixel[i]);
- else // float
+ } else { // float
dst_data[i] = pixel[i];
+ }
}
}
}
@@ -943,11 +907,9 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
}
static void _overlay(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, float p_alpha, uint32_t p_width, uint32_t p_height, uint32_t p_pixel_size) {
-
uint16_t alpha = MIN((uint16_t)(p_alpha * 256.0f), 256);
for (uint32_t i = 0; i < p_width * p_height * p_pixel_size; i++) {
-
p_dst[i] = (p_dst[i] * (256 - alpha) + p_src[i] * alpha) >> 8;
}
}
@@ -957,7 +919,6 @@ bool Image::is_size_po2() const {
}
void Image::resize_to_po2(bool p_square) {
-
ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in compressed or custom image formats.");
int w = next_power_of_2(width);
@@ -967,16 +928,15 @@ void Image::resize_to_po2(bool p_square) {
}
if (w == width && h == height) {
-
- if (!p_square || w == h)
+ if (!p_square || w == h) {
return; //nothing to do
+ }
}
resize(w, h);
}
void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
-
ERR_FAIL_COND_MSG(data.size() == 0, "Cannot resize image before creating it, use create() or create_from_data() first.");
ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in compressed or custom image formats.");
@@ -988,8 +948,9 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + ".");
ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS));
- if (p_width == width && p_height == height)
+ if (p_width == width && p_height == height) {
return;
+ }
Image dst(p_width, p_height, false, format);
@@ -1027,9 +988,7 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
unsigned char *w_ptr = w;
switch (p_interpolation) {
-
case INTERPOLATE_NEAREST: {
-
if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) {
switch (get_format_pixel_size(format)) {
case 1:
@@ -1081,7 +1040,6 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
} break;
case INTERPOLATE_BILINEAR:
case INTERPOLATE_TRILINEAR: {
-
for (int i = 0; i < 2; ++i) {
int src_width;
int src_height;
@@ -1174,7 +1132,6 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
} break;
case INTERPOLATE_CUBIC: {
-
if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) {
switch (get_format_pixel_size(format)) {
case 1:
@@ -1223,7 +1180,6 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
}
} break;
case INTERPOLATE_LANCZOS: {
-
if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) {
switch (get_format_pixel_size(format)) {
case 1:
@@ -1277,14 +1233,14 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
dst._copy_internals_from(dst2);
}
- if (had_mipmaps)
+ if (had_mipmaps) {
dst.generate_mipmaps();
+ }
_copy_internals_from(dst);
}
void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) {
-
ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot crop in compressed or custom image formats.");
ERR_FAIL_COND_MSG(p_x < 0, "Start x position cannot be smaller than 0.");
@@ -1298,8 +1254,9 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) {
will most likely either not be used much, or in critical areas, for now it won't, because
it's a waste of time. */
- if (p_width == width && p_height == height && p_x == 0 && p_y == 0)
+ if (p_width == width && p_height == height && p_x == 0 && p_y == 0) {
return;
+ }
uint8_t pdata[16]; //largest is 16
uint32_t pixel_size = get_format_pixel_size(format);
@@ -1313,12 +1270,11 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) {
int m_h = p_y + p_height;
int m_w = p_x + p_width;
for (int y = p_y; y < m_h; y++) {
-
for (int x = p_x; x < m_w; x++) {
-
if ((x >= width || y >= height)) {
- for (uint32_t i = 0; i < pixel_size; i++)
+ for (uint32_t i = 0; i < pixel_size; i++) {
pdata[i] = 0;
+ }
} else {
_get_pixelb(x, y, pixel_size, r, pdata);
}
@@ -1328,18 +1284,17 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) {
}
}
- if (has_mipmaps())
+ if (has_mipmaps()) {
dst.generate_mipmaps();
+ }
_copy_internals_from(dst);
}
void Image::crop(int p_width, int p_height) {
-
crop_from_point(0, 0, p_width, p_height);
}
void Image::flip_y() {
-
ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot flip_y in compressed or custom image formats.");
bool used_mipmaps = has_mipmaps();
@@ -1354,9 +1309,7 @@ void Image::flip_y() {
uint32_t pixel_size = get_format_pixel_size(format);
for (int y = 0; y < height / 2; y++) {
-
for (int x = 0; x < width; x++) {
-
_get_pixelb(x, y, pixel_size, w, up);
_get_pixelb(x, height - y - 1, pixel_size, w, down);
@@ -1372,7 +1325,6 @@ void Image::flip_y() {
}
void Image::flip_x() {
-
ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot flip_x in compressed or custom image formats.");
bool used_mipmaps = has_mipmaps();
@@ -1387,9 +1339,7 @@ void Image::flip_x() {
uint32_t pixel_size = get_format_pixel_size(format);
for (int y = 0; y < height; y++) {
-
for (int x = 0; x < width / 2; x++) {
-
_get_pixelb(x, y, pixel_size, w, up);
_get_pixelb(width - x - 1, y, pixel_size, w, down);
@@ -1405,7 +1355,6 @@ void Image::flip_x() {
}
int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps, int *r_mm_width, int *r_mm_height) {
-
int size = 0;
int w = p_width;
int h = p_height;
@@ -1420,7 +1369,6 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &
int minw = 1, minh = 1;
while (true) {
-
int bw = w % block != 0 ? w + (block - w % block) : w;
int bh = h % block != 0 ? h + (block - h % block) : h;
@@ -1438,16 +1386,17 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &
*r_mm_height = bh;
}
- if (p_mipmaps >= 0 && mm == p_mipmaps)
+ if (p_mipmaps >= 0 && mm == p_mipmaps) {
break;
+ }
if (p_mipmaps >= 0) {
-
w = MAX(minw, w >> 1);
h = MAX(minh, h >> 1);
} else {
- if (w == minw && h == minh)
+ if (w == minw && h == minh) {
break;
+ }
w = MAX(minw, w >> 1);
h = MAX(minh, h >> 1);
}
@@ -1459,7 +1408,6 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &
}
bool Image::_can_modify(Format p_format) const {
-
return p_format <= FORMAT_RGBE9995;
}
@@ -1467,7 +1415,6 @@ template <class Component, int CC, bool renormalize,
void (*average_func)(Component &, const Component &, const Component &, const Component &, const Component &),
void (*renormalize_func)(Component *)>
static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint32_t p_width, uint32_t p_height) {
-
//fast power of 2 mipmap generation
uint32_t dst_w = MAX(p_width >> 1, 1);
uint32_t dst_h = MAX(p_height >> 1, 1);
@@ -1476,7 +1423,6 @@ static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint3
int down_step = (p_height == 1) ? 0 : (p_width * CC);
for (uint32_t i = 0; i < dst_h; i++) {
-
const Component *rup_ptr = &p_src[i * 2 * down_step];
const Component *rdown_ptr = rup_ptr + down_step;
Component *dst_ptr = &p_dst[i * dst_w * CC];
@@ -1500,7 +1446,6 @@ static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint3
}
void Image::expand_x2_hq2x() {
-
ERR_FAIL_COND(!_can_modify(format));
bool used_mipmaps = has_mipmaps();
@@ -1510,8 +1455,9 @@ void Image::expand_x2_hq2x() {
Format current = format;
- if (current != FORMAT_RGBA8)
+ if (current != FORMAT_RGBA8) {
convert(FORMAT_RGBA8);
+ }
Vector<uint8_t> dest;
dest.resize(width * 2 * height * 2 * 4);
@@ -1529,8 +1475,9 @@ void Image::expand_x2_hq2x() {
height *= 2;
data = dest;
- if (current != FORMAT_RGBA8)
+ if (current != FORMAT_RGBA8) {
convert(current);
+ }
// FIXME: This is likely meant to use "used_mipmaps" as defined above, but if we do,
// we end up with a regression: GH-22747
@@ -1540,11 +1487,9 @@ void Image::expand_x2_hq2x() {
}
void Image::shrink_x2() {
-
ERR_FAIL_COND(data.size() == 0);
if (mipmaps) {
-
//just use the lower mipmap as base and copy all
Vector<uint8_t> new_img;
@@ -1566,7 +1511,6 @@ void Image::shrink_x2() {
data = new_img;
} else {
-
Vector<uint8_t> new_img;
ERR_FAIL_COND(!_can_modify(format));
@@ -1580,7 +1524,6 @@ void Image::shrink_x2() {
const uint8_t *r = data.ptr();
switch (format) {
-
case FORMAT_L8:
case FORMAT_R8:
_generate_po2_mipmap<uint8_t, 1, false, Image::average_4_uint8, Image::renormalize_uint8>(r, w, width, height);
@@ -1639,16 +1582,13 @@ void Image::shrink_x2() {
}
void Image::normalize() {
-
bool used_mipmaps = has_mipmaps();
if (used_mipmaps) {
clear_mipmaps();
}
for (int y = 0; y < height; y++) {
-
for (int x = 0; x < width; x++) {
-
Color c = get_pixel(x, y);
Vector3 v(c.r * 2.0 - 1.0, c.g * 2.0 - 1.0, c.b * 2.0 - 1.0);
v.normalize();
@@ -1665,7 +1605,6 @@ void Image::normalize() {
}
Error Image::generate_mipmaps(bool p_renormalize) {
-
ERR_FAIL_COND_V_MSG(!_can_modify(format), ERR_UNAVAILABLE, "Cannot generate mipmaps in compressed or custom image formats.");
ERR_FAIL_COND_V_MSG(format == FORMAT_RGBA4444, ERR_UNAVAILABLE, "Cannot generate mipmaps from RGBA4444 format.");
@@ -1685,12 +1624,10 @@ Error Image::generate_mipmaps(bool p_renormalize) {
int prev_w = width;
for (int i = 1; i <= mmcount; i++) {
-
int ofs, w, h;
_get_mipmap_offset_and_size(i, ofs, w, h);
switch (format) {
-
case FORMAT_L8:
case FORMAT_R8:
_generate_po2_mipmap<uint8_t, 1, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h);
@@ -1700,17 +1637,19 @@ Error Image::generate_mipmaps(bool p_renormalize) {
_generate_po2_mipmap<uint8_t, 2, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h);
break;
case FORMAT_RGB8:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<uint8_t, 3, true, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<uint8_t, 3, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h);
+ }
break;
case FORMAT_RGBA8:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<uint8_t, 4, true, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<uint8_t, 4, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h);
+ }
break;
case FORMAT_RF:
_generate_po2_mipmap<float, 1, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
@@ -1719,17 +1658,19 @@ Error Image::generate_mipmaps(bool p_renormalize) {
_generate_po2_mipmap<float, 2, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
break;
case FORMAT_RGBF:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<float, 3, true, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<float, 3, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
+ }
break;
case FORMAT_RGBAF:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<float, 4, true, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<float, 4, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
+ }
break;
case FORMAT_RH:
@@ -1739,24 +1680,27 @@ Error Image::generate_mipmaps(bool p_renormalize) {
_generate_po2_mipmap<uint16_t, 2, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h);
break;
case FORMAT_RGBH:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<uint16_t, 3, true, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<uint16_t, 3, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h);
+ }
break;
case FORMAT_RGBAH:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<uint16_t, 4, true, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<uint16_t, 4, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h);
+ }
break;
case FORMAT_RGBE9995:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<uint32_t, 1, true, Image::average_4_rgbe9995, Image::renormalize_rgbe9995>(reinterpret_cast<const uint32_t *>(&wp[prev_ofs]), reinterpret_cast<uint32_t *>(&wp[ofs]), prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<uint32_t, 1, false, Image::average_4_rgbe9995, Image::renormalize_rgbe9995>(reinterpret_cast<const uint32_t *>(&wp[prev_ofs]), reinterpret_cast<uint32_t *>(&wp[ofs]), prev_w, prev_h);
+ }
break;
default: {
@@ -1774,7 +1718,6 @@ Error Image::generate_mipmaps(bool p_renormalize) {
}
Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, const Ref<Image> &p_normal_map) {
-
Vector<double> normal_sat_vec; //summed area table
double *normal_sat = nullptr; //summed area table for normalmap
int normal_w = 0, normal_h = 0;
@@ -1839,7 +1782,6 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con
uint8_t *base_ptr = data.ptrw();
for (int i = 1; i <= mmcount; i++) {
-
int ofs, w, h;
_get_mipmap_offset_and_size(i, ofs, w, h);
uint8_t *ptr = &base_ptr[ofs];
@@ -1970,12 +1912,13 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con
}
void Image::clear_mipmaps() {
-
- if (!mipmaps)
+ if (!mipmaps) {
return;
+ }
- if (empty())
+ if (empty()) {
return;
+ }
int ofs, w, h;
_get_mipmap_offset_and_size(1, ofs, w, h);
@@ -1985,17 +1928,14 @@ void Image::clear_mipmaps() {
}
bool Image::empty() const {
-
return (data.size() == 0);
}
Vector<uint8_t> Image::get_data() const {
-
return data;
}
void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {
-
ERR_FAIL_INDEX(p_width - 1, MAX_WIDTH);
ERR_FAIL_INDEX(p_height - 1, MAX_HEIGHT);
ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS));
@@ -2016,7 +1956,6 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
}
void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {
-
ERR_FAIL_INDEX(p_width - 1, MAX_WIDTH);
ERR_FAIL_INDEX(p_height - 1, MAX_HEIGHT);
ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS));
@@ -2035,7 +1974,6 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
}
void Image::create(const char **p_xpm) {
-
int size_width = 0;
int size_height = 0;
int pixelchars = 0;
@@ -2058,13 +1996,10 @@ void Image::create(const char **p_xpm) {
uint8_t *w;
while (status != DONE) {
-
const char *line_ptr = p_xpm[line];
switch (status) {
-
case READING_HEADER: {
-
String line_str = line_ptr;
line_str.replace("\t", " ");
@@ -2079,25 +2014,24 @@ void Image::create(const char **p_xpm) {
status = READING_COLORS;
} break;
case READING_COLORS: {
-
String colorstring;
for (int i = 0; i < pixelchars; i++) {
-
colorstring += *line_ptr;
line_ptr++;
}
//skip spaces
while (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == 0) {
- if (*line_ptr == 0)
+ if (*line_ptr == 0) {
break;
+ }
line_ptr++;
}
if (*line_ptr == 'c') {
-
line_ptr++;
while (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == 0) {
- if (*line_ptr == 0)
+ if (*line_ptr == 0) {
break;
+ }
line_ptr++;
}
@@ -2109,17 +2043,17 @@ void Image::create(const char **p_xpm) {
//uint8_t col_a=255;
for (int i = 0; i < 6; i++) {
-
char v = line_ptr[i];
- if (v >= '0' && v <= '9')
+ if (v >= '0' && v <= '9') {
v -= '0';
- else if (v >= 'A' && v <= 'F')
+ } else if (v >= 'A' && v <= 'F') {
v = (v - 'A') + 10;
- else if (v >= 'a' && v <= 'f')
+ } else if (v >= 'a' && v <= 'f') {
v = (v - 'a') + 10;
- else
+ } else {
break;
+ }
switch (i) {
case 0:
@@ -2145,17 +2079,14 @@ void Image::create(const char **p_xpm) {
// magenta mask
if (col_r == 255 && col_g == 0 && col_b == 255) {
-
colormap[colorstring] = Color(0, 0, 0, 0);
has_alpha = true;
} else {
-
colormap[colorstring] = Color(col_r / 255.0, col_g / 255.0, col_b / 255.0, 1.0);
}
}
}
if (line == colormap_size) {
-
status = READING_PIXELS;
create(size_width, size_height, false, has_alpha ? FORMAT_RGBA8 : FORMAT_RGB8);
w = data.ptrw();
@@ -2163,13 +2094,12 @@ void Image::create(const char **p_xpm) {
}
} break;
case READING_PIXELS: {
-
int y = line - colormap_size - 1;
for (int x = 0; x < size_width; x++) {
-
char pixelstr[6] = { 0, 0, 0, 0, 0, 0 };
- for (int i = 0; i < pixelchars; i++)
+ for (int i = 0; i < pixelchars; i++) {
pixelstr[i] = line_ptr[x * pixelchars + i];
+ }
Color *colorptr = colormap.getptr(pixelstr);
ERR_FAIL_COND(!colorptr);
@@ -2180,8 +2110,9 @@ void Image::create(const char **p_xpm) {
_put_pixelb(x, y, pixel_size, w, pixel);
}
- if (y == (size_height - 1))
+ if (y == (size_height - 1)) {
status = DONE;
+ }
} break;
default: {
}
@@ -2199,7 +2130,6 @@ void Image::create(const char **p_xpm) {
if (value < DETECT_ALPHA_MIN_THRESHOLD) \
bit = true; \
else if (value < DETECT_ALPHA_MAX_THRESHOLD) { \
- \
detected = true; \
break; \
} \
@@ -2209,22 +2139,22 @@ void Image::create(const char **p_xpm) {
{ \
uint8_t value = m_value; \
if (value > 0) { \
- \
detected = true; \
break; \
} \
}
bool Image::is_invisible() const {
-
if (format == FORMAT_L8 ||
- format == FORMAT_RGB8 || format == FORMAT_RG8)
+ format == FORMAT_RGB8 || format == FORMAT_RG8) {
return false;
+ }
int len = data.size();
- if (len == 0)
+ if (len == 0) {
return true;
+ }
int w, h;
_get_mipmap_offset_and_size(1, len, w, h);
@@ -2235,16 +2165,13 @@ bool Image::is_invisible() const {
bool detected = false;
switch (format) {
-
case FORMAT_LA8: {
-
for (int i = 0; i < (len >> 1); i++) {
DETECT_NON_ALPHA(data_ptr[(i << 1) + 1]);
}
} break;
case FORMAT_RGBA8: {
-
for (int i = 0; i < (len >> 2); i++) {
DETECT_NON_ALPHA(data_ptr[(i << 2) + 3])
}
@@ -2265,11 +2192,11 @@ bool Image::is_invisible() const {
}
Image::AlphaMode Image::detect_alpha() const {
-
int len = data.size();
- if (len == 0)
+ if (len == 0) {
return ALPHA_NONE;
+ }
int w, h;
_get_mipmap_offset_and_size(1, len, w, h);
@@ -2281,16 +2208,13 @@ Image::AlphaMode Image::detect_alpha() const {
bool detected = false;
switch (format) {
-
case FORMAT_LA8: {
-
for (int i = 0; i < (len >> 1); i++) {
DETECT_ALPHA(data_ptr[(i << 1) + 1]);
}
} break;
case FORMAT_RGBA8: {
-
for (int i = 0; i < (len >> 2); i++) {
DETECT_ALPHA(data_ptr[(i << 2) + 3])
}
@@ -2306,12 +2230,13 @@ Image::AlphaMode Image::detect_alpha() const {
}
}
- if (detected)
+ if (detected) {
return ALPHA_BLEND;
- else if (bit)
+ } else if (bit) {
return ALPHA_BIT;
- else
+ } else {
return ALPHA_NONE;
+ }
}
Error Image::load(const String &p_path) {
@@ -2324,9 +2249,9 @@ Error Image::load(const String &p_path) {
}
Error Image::save_png(const String &p_path) const {
-
- if (save_png_func == nullptr)
+ if (save_png_func == nullptr) {
return ERR_UNAVAILABLE;
+ }
return save_png_func(p_path, Ref<Image>((Image *)this));
}
@@ -2340,21 +2265,19 @@ Vector<uint8_t> Image::save_png_to_buffer() const {
}
Error Image::save_exr(const String &p_path, bool p_grayscale) const {
-
- if (save_exr_func == nullptr)
+ if (save_exr_func == nullptr) {
return ERR_UNAVAILABLE;
+ }
return save_exr_func(p_path, Ref<Image>((Image *)this), p_grayscale);
}
int Image::get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps) {
-
int mm;
return _get_dst_image_size(p_width, p_height, p_format, mm, p_mipmaps ? -1 : 0);
}
int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format) {
-
int mm;
_get_dst_image_size(p_width, p_height, p_format, mm, -1);
return mm;
@@ -2368,7 +2291,6 @@ Size2i Image::get_image_mipmap_size(int p_width, int p_height, Format p_format,
}
int Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap) {
-
if (p_mipmap <= 0) {
return 0;
}
@@ -2377,7 +2299,6 @@ int Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, i
}
int Image::get_image_mipmap_offset_and_dimensions(int p_width, int p_height, Format p_format, int p_mipmap, int &r_w, int &r_h) {
-
if (p_mipmap <= 0) {
r_w = p_width;
r_h = p_height;
@@ -2392,57 +2313,49 @@ bool Image::is_compressed() const {
}
Error Image::decompress() {
-
- if (((format >= FORMAT_DXT1 && format <= FORMAT_RGTC_RG) || (format == FORMAT_DXT5_RA_AS_RG)) && _image_decompress_bc)
+ if (((format >= FORMAT_DXT1 && format <= FORMAT_RGTC_RG) || (format == FORMAT_DXT5_RA_AS_RG)) && _image_decompress_bc) {
_image_decompress_bc(this);
- else if (format >= FORMAT_BPTC_RGBA && format <= FORMAT_BPTC_RGBFU && _image_decompress_bptc)
+ } else if (format >= FORMAT_BPTC_RGBA && format <= FORMAT_BPTC_RGBFU && _image_decompress_bptc) {
_image_decompress_bptc(this);
- else if (format >= FORMAT_PVRTC2 && format <= FORMAT_PVRTC4A && _image_decompress_pvrtc)
+ } else if (format >= FORMAT_PVRTC2 && format <= FORMAT_PVRTC4A && _image_decompress_pvrtc) {
_image_decompress_pvrtc(this);
- else if (format == FORMAT_ETC && _image_decompress_etc1)
+ } else if (format == FORMAT_ETC && _image_decompress_etc1) {
_image_decompress_etc1(this);
- else if (format >= FORMAT_ETC2_R11 && format <= FORMAT_ETC2_RA_AS_RG && _image_decompress_etc2)
+ } else if (format >= FORMAT_ETC2_R11 && format <= FORMAT_ETC2_RA_AS_RG && _image_decompress_etc2) {
_image_decompress_etc2(this);
- else
+ } else {
return ERR_UNAVAILABLE;
+ }
return OK;
}
Error Image::compress(CompressMode p_mode, CompressSource p_source, float p_lossy_quality) {
-
return compress_from_channels(p_mode, detect_used_channels(p_source), p_lossy_quality);
}
-Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels, float p_lossy_quality) {
+Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels, float p_lossy_quality) {
switch (p_mode) {
-
case COMPRESS_S3TC: {
-
ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
_image_compress_bc_func(this, p_lossy_quality, p_channels);
} break;
case COMPRESS_PVRTC2: {
-
ERR_FAIL_COND_V(!_image_compress_pvrtc2_func, ERR_UNAVAILABLE);
_image_compress_pvrtc2_func(this);
} break;
case COMPRESS_PVRTC4: {
-
ERR_FAIL_COND_V(!_image_compress_pvrtc4_func, ERR_UNAVAILABLE);
_image_compress_pvrtc4_func(this);
} break;
case COMPRESS_ETC: {
-
ERR_FAIL_COND_V(!_image_compress_etc1_func, ERR_UNAVAILABLE);
_image_compress_etc1_func(this, p_lossy_quality);
} break;
case COMPRESS_ETC2: {
-
ERR_FAIL_COND_V(!_image_compress_etc2_func, ERR_UNAVAILABLE);
_image_compress_etc2_func(this, p_lossy_quality, p_channels);
} break;
case COMPRESS_BPTC: {
-
ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE);
_image_compress_bptc_func(this, p_lossy_quality, p_channels);
} break;
@@ -2452,7 +2365,6 @@ Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels
}
Image::Image(const char **p_xpm) {
-
width = 0;
height = 0;
mipmaps = false;
@@ -2462,7 +2374,6 @@ Image::Image(const char **p_xpm) {
}
Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {
-
width = 0;
height = 0;
mipmaps = p_use_mipmaps;
@@ -2472,7 +2383,6 @@ Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {
}
Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {
-
width = 0;
height = 0;
mipmaps = p_mipmaps;
@@ -2482,48 +2392,52 @@ Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const V
}
Rect2 Image::get_used_rect() const {
-
- if (format != FORMAT_LA8 && format != FORMAT_RGBA8 && format != FORMAT_RGBAF && format != FORMAT_RGBAH && format != FORMAT_RGBA4444 && format != FORMAT_RGB565)
+ if (format != FORMAT_LA8 && format != FORMAT_RGBA8 && format != FORMAT_RGBAF && format != FORMAT_RGBAH && format != FORMAT_RGBA4444 && format != FORMAT_RGB565) {
return Rect2(Point2(), Size2(width, height));
+ }
int len = data.size();
- if (len == 0)
+ if (len == 0) {
return Rect2();
+ }
int minx = 0xFFFFFF, miny = 0xFFFFFFF;
int maxx = -1, maxy = -1;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
-
- if (!(get_pixel(i, j).a > 0))
+ if (!(get_pixel(i, j).a > 0)) {
continue;
- if (i > maxx)
+ }
+ if (i > maxx) {
maxx = i;
- if (j > maxy)
+ }
+ if (j > maxy) {
maxy = j;
- if (i < minx)
+ }
+ if (i < minx) {
minx = i;
- if (j < miny)
+ }
+ if (j < miny) {
miny = j;
+ }
}
}
- if (maxx == -1)
+ if (maxx == -1) {
return Rect2();
- else
+ } else {
return Rect2(minx, miny, maxx - minx + 1, maxy - miny + 1);
+ }
}
Ref<Image> Image::get_rect(const Rect2 &p_area) const {
-
Ref<Image> img = memnew(Image(p_area.size.x, p_area.size.y, mipmaps, format));
img->blit_rect(Ref<Image>((Image *)this), p_area, Point2(0, 0));
return img;
}
void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest) {
-
ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object.");
int dsize = data.size();
int srcdsize = p_src->data.size();
@@ -2534,13 +2448,16 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po
Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect);
- if (p_dest.x < 0)
+ if (p_dest.x < 0) {
clipped_src_rect.position.x = ABS(p_dest.x);
- if (p_dest.y < 0)
+ }
+ if (p_dest.y < 0) {
clipped_src_rect.position.y = ABS(p_dest.y);
+ }
- if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0)
+ if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) {
return;
+ }
Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y));
Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size));
@@ -2554,9 +2471,7 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po
int pixel_size = get_format_pixel_size(format);
for (int i = 0; i < dest_rect.size.y; i++) {
-
for (int j = 0; j < dest_rect.size.x; j++) {
-
int src_x = clipped_src_rect.position.x + j;
int src_y = clipped_src_rect.position.y + i;
@@ -2574,7 +2489,6 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po
}
void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest) {
-
ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object.");
ERR_FAIL_COND_MSG(p_mask.is_null(), "It's not a reference to a valid Image object.");
int dsize = data.size();
@@ -2589,13 +2503,16 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co
Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect);
- if (p_dest.x < 0)
+ if (p_dest.x < 0) {
clipped_src_rect.position.x = ABS(p_dest.x);
- if (p_dest.y < 0)
+ }
+ if (p_dest.y < 0) {
clipped_src_rect.position.y = ABS(p_dest.y);
+ }
- if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0)
+ if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) {
return;
+ }
Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y));
Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size));
@@ -2611,14 +2528,11 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co
Ref<Image> msk = p_mask;
for (int i = 0; i < dest_rect.size.y; i++) {
-
for (int j = 0; j < dest_rect.size.x; j++) {
-
int src_x = clipped_src_rect.position.x + j;
int src_y = clipped_src_rect.position.y + i;
if (msk->get_pixel(src_x, src_y).a != 0) {
-
int dst_x = dest_rect.position.x + j;
int dst_y = dest_rect.position.y + i;
@@ -2634,7 +2548,6 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co
}
void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest) {
-
ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object.");
int dsize = data.size();
int srcdsize = p_src->data.size();
@@ -2644,13 +2557,16 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const P
Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect);
- if (p_dest.x < 0)
+ if (p_dest.x < 0) {
clipped_src_rect.position.x = ABS(p_dest.x);
- if (p_dest.y < 0)
+ }
+ if (p_dest.y < 0) {
clipped_src_rect.position.y = ABS(p_dest.y);
+ }
- if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0)
+ if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) {
return;
+ }
Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y));
Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size));
@@ -2658,9 +2574,7 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const P
Ref<Image> img = p_src;
for (int i = 0; i < dest_rect.size.y; i++) {
-
for (int j = 0; j < dest_rect.size.x; j++) {
-
int src_x = clipped_src_rect.position.x + j;
int src_y = clipped_src_rect.position.y + i;
@@ -2679,7 +2593,6 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const P
}
void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest) {
-
ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object.");
ERR_FAIL_COND_MSG(p_mask.is_null(), "It's not a reference to a valid Image object.");
int dsize = data.size();
@@ -2694,13 +2607,16 @@ void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, c
Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect);
- if (p_dest.x < 0)
+ if (p_dest.x < 0) {
clipped_src_rect.position.x = ABS(p_dest.x);
- if (p_dest.y < 0)
+ }
+ if (p_dest.y < 0) {
clipped_src_rect.position.y = ABS(p_dest.y);
+ }
- if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0)
+ if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) {
return;
+ }
Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y));
Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size));
@@ -2709,9 +2625,7 @@ void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, c
Ref<Image> msk = p_mask;
for (int i = 0; i < dest_rect.size.y; i++) {
-
for (int j = 0; j < dest_rect.size.x; j++) {
-
int src_x = clipped_src_rect.position.x + j;
int src_y = clipped_src_rect.position.y + i;
@@ -2719,7 +2633,6 @@ void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, c
//Color c = msk->get_pixel(src_x, src_y);
//if (c.a == 0) continue;
if (msk->get_pixel(src_x, src_y).a != 0) {
-
int dst_x = dest_rect.position.x + j;
int dst_y = dest_rect.position.y + i;
@@ -2747,9 +2660,7 @@ void Image::fill(const Color &c) {
set_pixel(0, 0, c);
for (int y = 0; y < height; y++) {
-
for (int x = 0; x < width; x++) {
-
uint8_t *dst = &dst_data_ptr[(y * width + x) * pixel_size];
for (int k = 0; k < pixel_size; k++) {
@@ -2783,7 +2694,6 @@ Vector<uint8_t> (*Image::basis_universal_packer)(const Ref<Image> &, Image::Used
Ref<Image> (*Image::basis_universal_unpacker)(const Vector<uint8_t> &) = nullptr;
void Image::_set_data(const Dictionary &p_data) {
-
ERR_FAIL_COND(!p_data.has("width"));
ERR_FAIL_COND(!p_data.has("height"));
ERR_FAIL_COND(!p_data.has("format"));
@@ -2809,7 +2719,6 @@ void Image::_set_data(const Dictionary &p_data) {
}
Dictionary Image::_get_data() const {
-
Dictionary d;
d["width"] = width;
d["height"] = height;
@@ -2824,7 +2733,6 @@ Color Image::get_pixelv(const Point2 &p_src) const {
}
Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const {
-
switch (format) {
case FORMAT_L8: {
float l = ptr[ofs] / 255.0;
@@ -2836,12 +2744,10 @@ Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const {
return Color(l, l, l, a);
}
case FORMAT_R8: {
-
float r = ptr[ofs] / 255.0;
return Color(r, 0, 0, 1);
}
case FORMAT_RG8: {
-
float r = ptr[ofs * 2 + 0] / 255.0;
float g = ptr[ofs * 2 + 1] / 255.0;
return Color(r, g, 0, 1);
@@ -2868,7 +2774,6 @@ Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const {
return Color(r, g, b, a);
}
case FORMAT_RGB565: {
-
uint16_t u = ((uint16_t *)ptr)[ofs];
float r = (u & 0x1F) / 31.0;
float g = ((u >> 5) & 0x3F) / 63.0;
@@ -2876,25 +2781,21 @@ Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const {
return Color(r, g, b, 1.0);
}
case FORMAT_RF: {
-
float r = ((float *)ptr)[ofs];
return Color(r, 0, 0, 1);
}
case FORMAT_RGF: {
-
float r = ((float *)ptr)[ofs * 2 + 0];
float g = ((float *)ptr)[ofs * 2 + 1];
return Color(r, g, 0, 1);
}
case FORMAT_RGBF: {
-
float r = ((float *)ptr)[ofs * 3 + 0];
float g = ((float *)ptr)[ofs * 3 + 1];
float b = ((float *)ptr)[ofs * 3 + 2];
return Color(r, g, b, 1);
}
case FORMAT_RGBAF: {
-
float r = ((float *)ptr)[ofs * 4 + 0];
float g = ((float *)ptr)[ofs * 4 + 1];
float b = ((float *)ptr)[ofs * 4 + 2];
@@ -2902,25 +2803,21 @@ Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const {
return Color(r, g, b, a);
}
case FORMAT_RH: {
-
uint16_t r = ((uint16_t *)ptr)[ofs];
return Color(Math::half_to_float(r), 0, 0, 1);
}
case FORMAT_RGH: {
-
uint16_t r = ((uint16_t *)ptr)[ofs * 2 + 0];
uint16_t g = ((uint16_t *)ptr)[ofs * 2 + 1];
return Color(Math::half_to_float(r), Math::half_to_float(g), 0, 1);
}
case FORMAT_RGBH: {
-
uint16_t r = ((uint16_t *)ptr)[ofs * 3 + 0];
uint16_t g = ((uint16_t *)ptr)[ofs * 3 + 1];
uint16_t b = ((uint16_t *)ptr)[ofs * 3 + 2];
return Color(Math::half_to_float(r), Math::half_to_float(g), Math::half_to_float(b), 1);
}
case FORMAT_RGBAH: {
-
uint16_t r = ((uint16_t *)ptr)[ofs * 4 + 0];
uint16_t g = ((uint16_t *)ptr)[ofs * 4 + 1];
uint16_t b = ((uint16_t *)ptr)[ofs * 4 + 2];
@@ -2946,11 +2843,9 @@ void Image::_set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color)
ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.a * 255.0, 0, 255));
} break;
case FORMAT_R8: {
-
ptr[ofs] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255));
} break;
case FORMAT_RG8: {
-
ptr[ofs * 2 + 0] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255));
ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.g * 255.0, 0, 255));
} break;
@@ -2967,7 +2862,6 @@ void Image::_set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color)
} break;
case FORMAT_RGBA4444: {
-
uint16_t rgba = 0;
rgba = uint16_t(CLAMP(p_color.r * 15.0, 0, 15)) << 12;
@@ -2979,7 +2873,6 @@ void Image::_set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color)
} break;
case FORMAT_RGB565: {
-
uint16_t rgba = 0;
rgba = uint16_t(CLAMP(p_color.r * 31.0, 0, 31));
@@ -2990,51 +2883,42 @@ void Image::_set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color)
} break;
case FORMAT_RF: {
-
((float *)ptr)[ofs] = p_color.r;
} break;
case FORMAT_RGF: {
-
((float *)ptr)[ofs * 2 + 0] = p_color.r;
((float *)ptr)[ofs * 2 + 1] = p_color.g;
} break;
case FORMAT_RGBF: {
-
((float *)ptr)[ofs * 3 + 0] = p_color.r;
((float *)ptr)[ofs * 3 + 1] = p_color.g;
((float *)ptr)[ofs * 3 + 2] = p_color.b;
} break;
case FORMAT_RGBAF: {
-
((float *)ptr)[ofs * 4 + 0] = p_color.r;
((float *)ptr)[ofs * 4 + 1] = p_color.g;
((float *)ptr)[ofs * 4 + 2] = p_color.b;
((float *)ptr)[ofs * 4 + 3] = p_color.a;
} break;
case FORMAT_RH: {
-
((uint16_t *)ptr)[ofs] = Math::make_half_float(p_color.r);
} break;
case FORMAT_RGH: {
-
((uint16_t *)ptr)[ofs * 2 + 0] = Math::make_half_float(p_color.r);
((uint16_t *)ptr)[ofs * 2 + 1] = Math::make_half_float(p_color.g);
} break;
case FORMAT_RGBH: {
-
((uint16_t *)ptr)[ofs * 3 + 0] = Math::make_half_float(p_color.r);
((uint16_t *)ptr)[ofs * 3 + 1] = Math::make_half_float(p_color.g);
((uint16_t *)ptr)[ofs * 3 + 2] = Math::make_half_float(p_color.b);
} break;
case FORMAT_RGBAH: {
-
((uint16_t *)ptr)[ofs * 4 + 0] = Math::make_half_float(p_color.r);
((uint16_t *)ptr)[ofs * 4 + 1] = Math::make_half_float(p_color.g);
((uint16_t *)ptr)[ofs * 4 + 2] = Math::make_half_float(p_color.b);
((uint16_t *)ptr)[ofs * 4 + 3] = Math::make_half_float(p_color.a);
} break;
case FORMAT_RGBE9995: {
-
((uint32_t *)ptr)[ofs] = p_color.to_rgbe9995();
} break;
@@ -3069,24 +2953,26 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) {
}
Image::UsedChannels Image::detect_used_channels(CompressSource p_source) {
-
ERR_FAIL_COND_V(data.size() == 0, USED_CHANNELS_RGBA);
ERR_FAIL_COND_V(is_compressed(), USED_CHANNELS_RGBA);
bool r = false, g = false, b = false, a = false, c = false;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
-
Color col = get_pixel(i, j);
- if (col.r > 0.001)
+ if (col.r > 0.001) {
r = true;
- if (col.g > 0.001)
+ }
+ if (col.g > 0.001) {
g = true;
- if (col.b > 0.001)
+ }
+ if (col.b > 0.001) {
b = true;
- if (col.a < 0.999)
+ }
+ if (col.a < 0.999) {
a = true;
+ }
if (col.r != col.b || col.r != col.g || col.b != col.g) {
c = true;
@@ -3096,18 +2982,19 @@ Image::UsedChannels Image::detect_used_channels(CompressSource p_source) {
UsedChannels used_channels;
- if (!c && !a)
+ if (!c && !a) {
used_channels = USED_CHANNELS_L;
- else if (!c && a)
+ } else if (!c && a) {
used_channels = USED_CHANNELS_LA;
- else if (r && !g && !b && !a)
+ } else if (r && !g && !b && !a) {
used_channels = USED_CHANNELS_R;
- else if (r && g && !b && !a)
+ } else if (r && g && !b && !a) {
used_channels = USED_CHANNELS_RG;
- else if (r && g && b && !a)
+ } else if (r && g && b && !a) {
used_channels = USED_CHANNELS_RGB;
- else
+ } else {
used_channels = USED_CHANNELS_RGBA;
+ }
if (p_source == COMPRESS_SOURCE_SRGB && (used_channels == USED_CHANNELS_R || used_channels == USED_CHANNELS_RG)) {
//R and RG do not support SRGB
@@ -3146,7 +3033,6 @@ void Image::optimize_channels() {
}
void Image::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_width"), &Image::get_width);
ClassDB::bind_method(D_METHOD("get_height"), &Image::get_height);
ClassDB::bind_method(D_METHOD("get_size"), &Image::get_size);
@@ -3292,17 +3178,14 @@ void Image::_bind_methods() {
}
void Image::set_compress_bc_func(void (*p_compress_func)(Image *, float, UsedChannels)) {
-
_image_compress_bc_func = p_compress_func;
}
void Image::set_compress_bptc_func(void (*p_compress_func)(Image *, float, UsedChannels)) {
-
_image_compress_bptc_func = p_compress_func;
}
void Image::normalmap_to_xy() {
-
convert(Image::FORMAT_RGBA8);
{
@@ -3310,7 +3193,6 @@ void Image::normalmap_to_xy() {
uint8_t *data_ptr = data.ptrw();
for (int i = 0; i < len; i++) {
-
data_ptr[(i << 2) + 3] = data_ptr[(i << 2) + 0]; //x to w
data_ptr[(i << 2) + 0] = data_ptr[(i << 2) + 1]; //y to xz
data_ptr[(i << 2) + 2] = data_ptr[(i << 2) + 1];
@@ -3321,9 +3203,9 @@ void Image::normalmap_to_xy() {
}
Ref<Image> Image::rgbe_to_srgb() {
-
- if (data.size() == 0)
+ if (data.size() == 0) {
return Ref<Image>();
+ }
ERR_FAIL_COND_V(format != FORMAT_RGBE9995, Ref<Image>());
@@ -3345,7 +3227,6 @@ Ref<Image> Image::rgbe_to_srgb() {
}
Ref<Image> Image::get_image_from_mipmap(int p_mipamp) const {
-
int ofs, size, w, h;
get_mipmap_offset_size_and_dimensions(p_mipamp, ofs, size, w, h);
@@ -3387,13 +3268,15 @@ void Image::bumpmap_to_normalmap(float bump_scale) {
for (int ty = 0; ty < height; ty++) {
int py = ty + 1;
- if (py >= height)
+ if (py >= height) {
py -= height;
+ }
for (int tx = 0; tx < width; tx++) {
int px = tx + 1;
- if (px >= width)
+ if (px >= width) {
px -= width;
+ }
float here = read_ptr[ty * width + tx];
float to_right = read_ptr[ty * width + px];
float above = read_ptr[py * width + tx];
@@ -3415,33 +3298,29 @@ void Image::bumpmap_to_normalmap(float bump_scale) {
}
void Image::srgb_to_linear() {
-
- if (data.size() == 0)
+ if (data.size() == 0) {
return;
+ }
static const uint8_t srgb2lin[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116, 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 148, 150, 152, 153, 155, 157, 159, 160, 162, 164, 166, 167, 169, 171, 173, 175, 176, 178, 180, 182, 184, 186, 188, 190, 192, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 235, 237, 239, 241, 243, 245, 248, 250, 252, 255 };
ERR_FAIL_COND(format != FORMAT_RGB8 && format != FORMAT_RGBA8);
if (format == FORMAT_RGBA8) {
-
int len = data.size() / 4;
uint8_t *data_ptr = data.ptrw();
for (int i = 0; i < len; i++) {
-
data_ptr[(i << 2) + 0] = srgb2lin[data_ptr[(i << 2) + 0]];
data_ptr[(i << 2) + 1] = srgb2lin[data_ptr[(i << 2) + 1]];
data_ptr[(i << 2) + 2] = srgb2lin[data_ptr[(i << 2) + 2]];
}
} else if (format == FORMAT_RGB8) {
-
int len = data.size() / 3;
uint8_t *data_ptr = data.ptrw();
for (int i = 0; i < len; i++) {
-
data_ptr[(i * 3) + 0] = srgb2lin[data_ptr[(i * 3) + 0]];
data_ptr[(i * 3) + 1] = srgb2lin[data_ptr[(i * 3) + 1]];
data_ptr[(i * 3) + 2] = srgb2lin[data_ptr[(i * 3) + 2]];
@@ -3450,18 +3329,18 @@ void Image::srgb_to_linear() {
}
void Image::premultiply_alpha() {
-
- if (data.size() == 0)
+ if (data.size() == 0) {
return;
+ }
- if (format != FORMAT_RGBA8)
+ if (format != FORMAT_RGBA8) {
return; //not needed
+ }
uint8_t *data_ptr = data.ptrw();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
-
uint8_t *ptr = &data_ptr[(i * width + j) * 4];
ptr[0] = (uint16_t(ptr[0]) * uint16_t(ptr[3])) >> 8;
@@ -3472,12 +3351,13 @@ void Image::premultiply_alpha() {
}
void Image::fix_alpha_edges() {
-
- if (data.size() == 0)
+ if (data.size() == 0) {
return;
+ }
- if (format != FORMAT_RGBA8)
+ if (format != FORMAT_RGBA8) {
return; //not needed
+ }
Vector<uint8_t> dcopy = data;
const uint8_t *srcptr = dcopy.ptr();
@@ -3490,12 +3370,12 @@ void Image::fix_alpha_edges() {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
-
const uint8_t *rptr = &srcptr[(i * width + j) * 4];
uint8_t *wptr = &data_ptr[(i * width + j) * 4];
- if (rptr[3] >= alpha_threshold)
+ if (rptr[3] >= alpha_threshold) {
continue;
+ }
int closest_dist = max_dist;
uint8_t closest_color[3];
@@ -3507,17 +3387,18 @@ void Image::fix_alpha_edges() {
for (int k = from_y; k <= to_y; k++) {
for (int l = from_x; l <= to_x; l++) {
-
int dy = i - k;
int dx = j - l;
int dist = dy * dy + dx * dx;
- if (dist >= closest_dist)
+ if (dist >= closest_dist) {
continue;
+ }
const uint8_t *rp2 = &srcptr[(k * width + l) << 2];
- if (rp2[3] < alpha_threshold)
+ if (rp2[3] < alpha_threshold) {
continue;
+ }
closest_dist = dist;
closest_color[0] = rp2[0];
@@ -3527,7 +3408,6 @@ void Image::fix_alpha_edges() {
}
if (closest_dist != max_dist) {
-
wptr[0] = closest_color[0];
wptr[1] = closest_color[1];
wptr[2] = closest_color[2];
@@ -3537,7 +3417,6 @@ void Image::fix_alpha_edges() {
}
String Image::get_format_name(Format p_format) {
-
ERR_FAIL_INDEX_V(p_format, FORMAT_MAX, String());
return format_names[p_format];
}
@@ -3566,6 +3445,7 @@ void Image::convert_rg_to_ra_rgba8() {
w[i + 2] = 0;
}
}
+
void Image::convert_ra_rgba8_to_rg() {
ERR_FAIL_COND(format != FORMAT_RGBA8);
ERR_FAIL_COND(!data.size());
@@ -3645,7 +3525,6 @@ void Image::renormalize_rgbe9995(uint32_t *p_rgb) {
}
Image::Image(const uint8_t *p_mem_png_jpg, int p_len) {
-
width = 0;
height = 0;
mipmaps = false;
@@ -3661,7 +3540,6 @@ Image::Image(const uint8_t *p_mem_png_jpg, int p_len) {
}
Ref<Resource> Image::duplicate(bool p_subresources) const {
-
Ref<Image> copy;
copy.instance();
copy->_copy_internals_from(*this);
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 38a71994d8..dc1c207524 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -129,7 +129,6 @@ Input::CursorShape (*Input::get_current_cursor_shape_func)() = nullptr;
void (*Input::set_custom_mouse_cursor_func)(const RES &, Input::CursorShape, const Vector2 &) = nullptr;
Input *Input::get_singleton() {
-
return singleton;
}
@@ -139,12 +138,10 @@ void Input::set_mouse_mode(MouseMode p_mode) {
}
Input::MouseMode Input::get_mouse_mode() const {
-
return get_mouse_mode_func();
}
void Input::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &Input::is_key_pressed);
ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed);
ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed);
@@ -219,15 +216,15 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
String pf = p_function;
if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released" || pf == "get_action_strength")) {
-
List<PropertyInfo> pinfo;
ProjectSettings::get_singleton()->get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
- if (!pi.name.begins_with("input/"))
+ if (!pi.name.begins_with("input/")) {
continue;
+ }
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
r_options->push_back(quote_style + name + quote_style);
@@ -237,7 +234,6 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
}
void Input::SpeedTrack::update(const Vector2 &p_delta_p) {
-
uint64_t tick = OS::get_singleton()->get_ticks_usec();
uint32_t tdiff = tick - last_tick;
float delta_t = tdiff / 1000000.0;
@@ -246,11 +242,11 @@ void Input::SpeedTrack::update(const Vector2 &p_delta_p) {
accum += p_delta_p;
accum_t += delta_t;
- if (accum_t > max_ref_frame * 10)
+ if (accum_t > max_ref_frame * 10) {
accum_t = max_ref_frame * 10;
+ }
while (accum_t >= min_ref_frame) {
-
float slice_t = min_ref_frame / accum_t;
Vector2 slice = accum * slice_t;
accum = accum - slice;
@@ -267,45 +263,39 @@ void Input::SpeedTrack::reset() {
}
Input::SpeedTrack::SpeedTrack() {
-
min_ref_frame = 0.1;
max_ref_frame = 0.3;
reset();
}
bool Input::is_key_pressed(int p_keycode) const {
-
_THREAD_SAFE_METHOD_
return keys_pressed.has(p_keycode);
}
bool Input::is_mouse_button_pressed(int p_button) const {
-
_THREAD_SAFE_METHOD_
return (mouse_button_mask & (1 << (p_button - 1))) != 0;
}
static int _combine_device(int p_value, int p_device) {
-
return p_value | (p_device << 20);
}
bool Input::is_joy_button_pressed(int p_device, int p_button) const {
-
_THREAD_SAFE_METHOD_
return joy_buttons_pressed.has(_combine_device(p_button, p_device));
}
bool Input::is_action_pressed(const StringName &p_action) const {
-
return action_state.has(p_action) && action_state[p_action].pressed;
}
bool Input::is_action_just_pressed(const StringName &p_action) const {
-
const Map<StringName, Action>::Element *E = action_state.find(p_action);
- if (!E)
+ if (!E) {
return false;
+ }
if (Engine::get_singleton()->is_in_physics_frame()) {
return E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames();
@@ -315,10 +305,10 @@ bool Input::is_action_just_pressed(const StringName &p_action) const {
}
bool Input::is_action_just_released(const StringName &p_action) const {
-
const Map<StringName, Action>::Element *E = action_state.find(p_action);
- if (!E)
+ if (!E) {
return false;
+ }
if (Engine::get_singleton()->is_in_physics_frame()) {
return !E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames();
@@ -329,14 +319,14 @@ bool Input::is_action_just_released(const StringName &p_action) const {
float Input::get_action_strength(const StringName &p_action) const {
const Map<StringName, Action>::Element *E = action_state.find(p_action);
- if (!E)
+ if (!E) {
return 0.0f;
+ }
return E->get().strength;
}
float Input::get_joy_axis(int p_device, int p_axis) const {
-
_THREAD_SAFE_METHOD_
int c = _combine_device(p_axis, p_device);
if (_joy_axis.has(c)) {
@@ -347,7 +337,6 @@ float Input::get_joy_axis(int p_device, int p_axis) const {
}
String Input::get_joy_name(int p_idx) {
-
_THREAD_SAFE_METHOD_
return joy_names[p_idx].name;
};
@@ -377,7 +366,6 @@ float Input::get_joy_vibration_duration(int p_device) {
}
static String _hex_str(uint8_t p_byte) {
-
static const char *dict = "0123456789abcdef";
char ret[3];
ret[2] = 0;
@@ -389,14 +377,12 @@ static String _hex_str(uint8_t p_byte) {
};
void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) {
-
_THREAD_SAFE_METHOD_
Joypad js;
js.name = p_connected ? p_name : "";
js.uid = p_connected ? p_guid : "";
if (p_connected) {
-
String uidname = p_guid;
if (p_guid == "") {
int uidlen = MIN(p_name.length(), 16);
@@ -430,36 +416,30 @@ void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, S
};
Vector3 Input::get_gravity() const {
-
_THREAD_SAFE_METHOD_
return gravity;
}
Vector3 Input::get_accelerometer() const {
-
_THREAD_SAFE_METHOD_
return accelerometer;
}
Vector3 Input::get_magnetometer() const {
-
_THREAD_SAFE_METHOD_
return magnetometer;
}
Vector3 Input::get_gyroscope() const {
-
_THREAD_SAFE_METHOD_
return gyroscope;
}
void Input::parse_input_event(const Ref<InputEvent> &p_event) {
-
_parse_input_event_impl(p_event, false);
}
void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated) {
-
// Notes on mouse-touch emulation:
// - Emulated mouse events are parsed, that is, re-routed to this method, so they make the same effects
// as true mouse events. The only difference is the situation is flagged as emulated so they are not
@@ -471,16 +451,16 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
Ref<InputEventKey> k = p_event;
if (k.is_valid() && !k->is_echo() && k->get_keycode() != 0) {
- if (k->is_pressed())
+ if (k->is_pressed()) {
keys_pressed.insert(k->get_keycode());
- else
+ } else {
keys_pressed.erase(k->get_keycode());
+ }
}
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
-
if (mb->is_pressed()) {
mouse_button_mask |= (1 << (mb->get_button_index() - 1));
} else {
@@ -504,7 +484,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
-
Point2 pos = mm->get_global_position();
if (mouse_pos != pos) {
set_mouse_position(pos);
@@ -525,7 +504,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
Ref<InputEventScreenTouch> st = p_event;
if (st.is_valid()) {
-
if (st->is_pressed()) {
SpeedTrack &track = touch_speed_track[st->get_index()];
track.reset();
@@ -536,7 +514,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
}
if (emulate_mouse_from_touch) {
-
bool translate = false;
if (st->is_pressed()) {
if (mouse_from_touch_index == -1) {
@@ -573,13 +550,11 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
Ref<InputEventScreenDrag> sd = p_event;
if (sd.is_valid()) {
-
SpeedTrack &track = touch_speed_track[sd->get_index()];
track.update(sd->get_relative());
sd->set_speed(track.speed);
if (emulate_mouse_from_touch && sd->get_index() == mouse_from_touch_index) {
-
Ref<InputEventMouseMotion> motion_event;
motion_event.instance();
@@ -597,13 +572,13 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
Ref<InputEventJoypadButton> jb = p_event;
if (jb.is_valid()) {
-
int c = _combine_device(jb->get_button_index(), jb->get_device());
- if (jb->is_pressed())
+ if (jb->is_pressed()) {
joy_buttons_pressed.insert(c);
- else
+ } else {
joy_buttons_pressed.erase(c);
+ }
}
Ref<InputEventJoypadMotion> jm = p_event;
@@ -615,7 +590,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
Ref<InputEventGesture> ge = p_event;
if (ge.is_valid()) {
-
if (event_dispatch_function) {
event_dispatch_function(ge);
}
@@ -623,7 +597,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
for (const Map<StringName, InputMap::Action>::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) {
if (InputMap::get_singleton()->event_is_action(p_event, E->key())) {
-
// Save the action's state
if (!p_event->is_echo() && is_action_pressed(E->key()) != p_event->is_action_pressed(E->key())) {
Action action;
@@ -637,12 +610,12 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
}
}
- if (event_dispatch_function)
+ if (event_dispatch_function) {
event_dispatch_function(p_event);
+ }
}
void Input::set_joy_axis(int p_device, int p_axis, float p_value) {
-
_THREAD_SAFE_METHOD_
int c = _combine_device(p_axis, p_device);
_joy_axis[c] = p_value;
@@ -676,50 +649,43 @@ void Input::vibrate_handheld(int p_duration_ms) {
}
void Input::set_gravity(const Vector3 &p_gravity) {
-
_THREAD_SAFE_METHOD_
gravity = p_gravity;
}
void Input::set_accelerometer(const Vector3 &p_accel) {
-
_THREAD_SAFE_METHOD_
accelerometer = p_accel;
}
void Input::set_magnetometer(const Vector3 &p_magnetometer) {
-
_THREAD_SAFE_METHOD_
magnetometer = p_magnetometer;
}
void Input::set_gyroscope(const Vector3 &p_gyroscope) {
-
_THREAD_SAFE_METHOD_
gyroscope = p_gyroscope;
}
void Input::set_mouse_position(const Point2 &p_posf) {
-
mouse_speed_track.update(p_posf - mouse_pos);
mouse_pos = p_posf;
}
Point2 Input::get_mouse_position() const {
-
return mouse_pos;
}
-Point2 Input::get_last_mouse_speed() const {
+Point2 Input::get_last_mouse_speed() const {
return mouse_speed_track.speed;
}
int Input::get_mouse_button_mask() const {
-
return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state();
}
@@ -728,7 +694,6 @@ void Input::warp_mouse_position(const Vector2 &p_to) {
}
Point2i Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) {
-
// The relative distance reported for the next event after a warp is in the boundaries of the
// size of the rect on that axis, but it may be greater, in which case there's not problem as fmod()
// will warp it, but if the pointer has moved in the opposite direction between the pointer relocation
@@ -757,7 +722,6 @@ void Input::iteration(float p_step) {
}
void Input::action_press(const StringName &p_action, float p_strength) {
-
Action action;
action.physics_frame = Engine::get_singleton()->get_physics_frames();
@@ -769,7 +733,6 @@ void Input::action_press(const StringName &p_action, float p_strength) {
}
void Input::action_release(const StringName &p_action) {
-
Action action;
action.physics_frame = Engine::get_singleton()->get_physics_frames();
@@ -781,19 +744,16 @@ void Input::action_release(const StringName &p_action) {
}
void Input::set_emulate_touch_from_mouse(bool p_emulate) {
-
emulate_touch_from_mouse = p_emulate;
}
bool Input::is_emulating_touch_from_mouse() const {
-
return emulate_touch_from_mouse;
}
// Calling this whenever the game window is focused helps unstucking the "touch mouse"
// if the OS or its abstraction class hasn't properly reported that touch pointers raised
void Input::ensure_touch_mouse_raised() {
-
if (mouse_from_touch_index != -1) {
mouse_from_touch_index = -1;
@@ -812,24 +772,21 @@ void Input::ensure_touch_mouse_raised() {
}
void Input::set_emulate_mouse_from_touch(bool p_emulate) {
-
emulate_mouse_from_touch = p_emulate;
}
bool Input::is_emulating_mouse_from_touch() const {
-
return emulate_mouse_from_touch;
}
Input::CursorShape Input::get_default_cursor_shape() const {
-
return default_shape;
}
void Input::set_default_cursor_shape(CursorShape p_shape) {
-
- if (default_shape == p_shape)
+ if (default_shape == p_shape) {
return;
+ }
default_shape = p_shape;
// The default shape is set in Viewport::_gui_input_event. To instantly
@@ -842,13 +799,13 @@ void Input::set_default_cursor_shape(CursorShape p_shape) {
}
Input::CursorShape Input::get_current_cursor_shape() const {
-
return get_current_cursor_shape_func();
}
void Input::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
set_custom_mouse_cursor_func(p_cursor, p_shape, p_hotspot);
}
@@ -866,8 +823,8 @@ void Input::accumulate_input_event(const Ref<InputEvent> &p_event) {
accumulated_events.push_back(p_event);
}
-void Input::flush_accumulated_events() {
+void Input::flush_accumulated_events() {
while (accumulated_events.front()) {
parse_input_event(accumulated_events.front()->get());
accumulated_events.pop_front();
@@ -875,12 +832,10 @@ void Input::flush_accumulated_events() {
}
void Input::set_use_accumulated_input(bool p_enable) {
-
use_accumulated_input = p_enable;
}
void Input::release_pressed_events() {
-
flush_accumulated_events(); // this is needed to release actions strengths
keys_pressed.clear();
@@ -888,8 +843,9 @@ void Input::release_pressed_events() {
_joy_axis.clear();
for (Map<StringName, Input::Action>::Element *E = action_state.front(); E; E = E->next()) {
- if (E->get().pressed)
+ if (E->get().pressed) {
action_release(E->key());
+ }
}
}
@@ -898,7 +854,6 @@ void Input::set_event_dispatch_function(EventDispatchFunc p_function) {
}
void Input::joy_button(int p_device, int p_button, bool p_pressed) {
-
_THREAD_SAFE_METHOD_;
Joypad &joy = joy_names[p_device];
//printf("got button %i, mapping is %i\n", p_button, joy.mapping);
@@ -925,7 +880,6 @@ void Input::joy_button(int p_device, int p_button, bool p_pressed) {
}
void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
-
_THREAD_SAFE_METHOD_;
ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX);
@@ -937,13 +891,10 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
}
if (p_value.value > joy.last_axis[p_axis]) {
-
if (p_value.value < joy.last_axis[p_axis] + joy.filter) {
-
return;
}
} else if (p_value.value > joy.last_axis[p_axis] - joy.filter) {
-
return;
}
@@ -972,7 +923,6 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, p_value);
if (map.type == TYPE_BUTTON) {
-
if (map.index == JOY_BUTTON_DPAD_UP || map.index == JOY_BUTTON_DPAD_DOWN) {
bool pressed = p_value.value != 0.0f;
int button = p_value.value < 0 ? JOY_BUTTON_DPAD_UP : JOY_BUTTON_DPAD_DOWN;
@@ -1023,7 +973,6 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
}
if (map.type == TYPE_AXIS) {
-
_axis_event(p_device, map.index, map.value);
return;
}
@@ -1031,7 +980,6 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
}
void Input::joy_hat(int p_device, int p_val) {
-
_THREAD_SAFE_METHOD_;
const Joypad &joy = joy_names[p_device];
@@ -1077,7 +1025,6 @@ void Input::joy_hat(int p_device, int p_val) {
}
void Input::_button_event(int p_device, int p_index, bool p_pressed) {
-
Ref<InputEventJoypadButton> ievent;
ievent.instance();
ievent->set_device(p_device);
@@ -1088,7 +1035,6 @@ void Input::_button_event(int p_device, int p_index, bool p_pressed) {
}
void Input::_axis_event(int p_device, int p_axis, float p_value) {
-
Ref<InputEventJoypadMotion> ievent;
ievent.instance();
ievent->set_device(p_device);
@@ -1099,7 +1045,6 @@ void Input::_axis_event(int p_device, int p_axis, float p_value) {
};
Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button) {
-
JoyEvent event;
event.type = TYPE_MAX;
@@ -1123,7 +1068,6 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping,
}
Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, const JoyAxis &p_value) {
-
JoyEvent event;
event.type = TYPE_MAX;
@@ -1131,8 +1075,9 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i
const JoyBinding binding = mapping.bindings[i];
if (binding.inputType == TYPE_AXIS && binding.input.axis.axis == p_axis) {
float value = p_value.value;
- if (binding.input.axis.invert)
+ if (binding.input.axis.invert) {
value = -value;
+ }
if (binding.input.axis.range == FULL_AXIS ||
(binding.input.axis.range == POSITIVE_HALF_AXIS && value > 0) ||
(binding.input.axis.range == NEGATIVE_HALF_AXIS && value < 0)) {
@@ -1180,11 +1125,9 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i
}
void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[]) {
-
for (int i = 0; i < mapping.bindings.size(); i++) {
const JoyBinding binding = mapping.bindings[i];
if (binding.inputType == TYPE_HAT && binding.input.hat.hat == p_hat) {
-
int index;
switch (binding.input.hat.hat_mask) {
case HAT_MASK_UP:
@@ -1220,25 +1163,24 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, J
}
JoyButtonList Input::_get_output_button(String output) {
-
for (int i = 0; _joy_buttons[i]; i++) {
- if (output == _joy_buttons[i])
+ if (output == _joy_buttons[i]) {
return JoyButtonList(i);
+ }
}
return JoyButtonList::JOY_INVALID_BUTTON;
}
JoyAxisList Input::_get_output_axis(String output) {
-
for (int i = 0; _joy_axes[i]; i++) {
- if (output == _joy_axes[i])
+ if (output == _joy_axes[i]) {
return JoyAxisList(i);
+ }
}
return JoyAxisList::JOY_INVALID_AXIS;
}
void Input::parse_mapping(String p_mapping) {
-
_THREAD_SAFE_METHOD_;
JoyDeviceMapping mapping;
@@ -1255,26 +1197,28 @@ void Input::parse_mapping(String p_mapping) {
int idx = 1;
while (++idx < entry.size()) {
-
- if (entry[idx] == "")
+ if (entry[idx] == "") {
continue;
+ }
String output = entry[idx].get_slice(":", 0).replace(" ", "");
String input = entry[idx].get_slice(":", 1).replace(" ", "");
ERR_CONTINUE_MSG(output.length() < 1 || input.length() < 2,
String(entry[idx] + "\nInvalid device mapping entry: " + entry[idx]));
- if (output == "platform")
+ if (output == "platform") {
continue;
+ }
JoyAxisRange output_range = FULL_AXIS;
if (output[0] == '+' || output[0] == '-') {
ERR_CONTINUE_MSG(output.length() < 2, String(entry[idx] + "\nInvalid output: " + entry[idx]));
output = output.right(1);
- if (output[0] == '+')
+ if (output[0] == '+') {
output_range = POSITIVE_HALF_AXIS;
- else if (output[0] == '-')
+ } else if (output[0] == '-') {
output_range = NEGATIVE_HALF_AXIS;
+ }
}
JoyAxisRange input_range = FULL_AXIS;
@@ -1286,8 +1230,9 @@ void Input::parse_mapping(String p_mapping) {
input = input.right(1);
}
bool invert_axis = false;
- if (input[input.length() - 1] == '~')
+ if (input[input.length() - 1] == '~') {
invert_axis = true;
+ }
JoyButtonList output_button = _get_output_button(output);
JoyAxisList output_axis = _get_output_axis(output);
@@ -1361,7 +1306,6 @@ void Input::remove_joy_mapping(String p_guid) {
}
void Input::set_fallback_mapping(String p_guid) {
-
for (int i = 0; i < map_db.size(); i++) {
if (map_db[i].uid == p_guid) {
fallback_mapping = i;
@@ -1431,7 +1375,6 @@ int Input::get_joy_axis_index_from_string(String p_axis) {
}
Input::Input() {
-
singleton = this;
// Parse default mappings.
@@ -1447,8 +1390,9 @@ Input::Input() {
if (env_mapping != "") {
Vector<String> entries = env_mapping.split("\n");
for (int i = 0; i < entries.size(); i++) {
- if (entries[i] == "")
+ if (entries[i] == "") {
continue;
+ }
parse_mapping(entries[i]);
}
}
diff --git a/core/input/input.h b/core/input/input.h
index f3150a8127..91e3b83b95 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -128,7 +128,6 @@ private:
int mouse_from_touch_index = -1;
struct SpeedTrack {
-
uint64_t last_tick;
Vector2 speed;
Vector2 accum;
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 9d3f8f9424..6ba082f86f 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -45,26 +45,22 @@ int InputEvent::get_device() const {
}
bool InputEvent::is_action(const StringName &p_action) const {
-
return InputMap::get_singleton()->event_is_action(Ref<InputEvent>((InputEvent *)this), p_action);
}
bool InputEvent::is_action_pressed(const StringName &p_action, bool p_allow_echo) const {
-
bool pressed;
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed);
return valid && pressed && (p_allow_echo || !is_echo());
}
bool InputEvent::is_action_released(const StringName &p_action) const {
-
bool pressed;
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed);
return valid && !pressed;
}
float InputEvent::get_action_strength(const StringName &p_action) const {
-
bool pressed;
float strength;
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed, &strength);
@@ -72,42 +68,34 @@ float InputEvent::get_action_strength(const StringName &p_action) const {
}
bool InputEvent::is_pressed() const {
-
return false;
}
bool InputEvent::is_echo() const {
-
return false;
}
Ref<InputEvent> InputEvent::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
-
return Ref<InputEvent>((InputEvent *)this);
}
String InputEvent::as_text() const {
-
return String();
}
bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
-
return false;
}
bool InputEvent::shortcut_match(const Ref<InputEvent> &p_event) const {
-
return false;
}
bool InputEvent::is_action_type() const {
-
return false;
}
void InputEvent::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device);
ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device);
@@ -135,7 +123,6 @@ void InputEvent::_bind_methods() {
///////////////////////////////////
void InputEventFromWindow::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_window_id", "id"), &InputEventFromWindow::set_window_id);
ClassDB::bind_method(D_METHOD("get_window_id"), &InputEventFromWindow::get_window_id);
ADD_PROPERTY(PropertyInfo(Variant::INT, "window_id"), "set_window_id", "get_window_id");
@@ -144,6 +131,7 @@ void InputEventFromWindow::_bind_methods() {
void InputEventFromWindow::set_window_id(int64_t p_id) {
window_id = p_id;
}
+
int64_t InputEventFromWindow::get_window_id() const {
return window_id;
}
@@ -151,53 +139,46 @@ int64_t InputEventFromWindow::get_window_id() const {
///////////////////////////////////
void InputEventWithModifiers::set_shift(bool p_enabled) {
-
shift = p_enabled;
}
bool InputEventWithModifiers::get_shift() const {
-
return shift;
}
void InputEventWithModifiers::set_alt(bool p_enabled) {
-
alt = p_enabled;
}
-bool InputEventWithModifiers::get_alt() const {
+bool InputEventWithModifiers::get_alt() const {
return alt;
}
void InputEventWithModifiers::set_control(bool p_enabled) {
-
control = p_enabled;
}
-bool InputEventWithModifiers::get_control() const {
+bool InputEventWithModifiers::get_control() const {
return control;
}
void InputEventWithModifiers::set_metakey(bool p_enabled) {
-
meta = p_enabled;
}
-bool InputEventWithModifiers::get_metakey() const {
+bool InputEventWithModifiers::get_metakey() const {
return meta;
}
void InputEventWithModifiers::set_command(bool p_enabled) {
-
command = p_enabled;
}
-bool InputEventWithModifiers::get_command() const {
+bool InputEventWithModifiers::get_command() const {
return command;
}
void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModifiers *event) {
-
set_alt(event->get_alt());
set_shift(event->get_shift());
set_control(event->get_control());
@@ -205,7 +186,6 @@ void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModif
}
void InputEventWithModifiers::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt);
ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt);
@@ -231,90 +211,86 @@ void InputEventWithModifiers::_bind_methods() {
///////////////////////////////////
void InputEventKey::set_pressed(bool p_pressed) {
-
pressed = p_pressed;
}
bool InputEventKey::is_pressed() const {
-
return pressed;
}
void InputEventKey::set_keycode(uint32_t p_keycode) {
-
keycode = p_keycode;
}
uint32_t InputEventKey::get_keycode() const {
-
return keycode;
}
void InputEventKey::set_physical_keycode(uint32_t p_keycode) {
-
physical_keycode = p_keycode;
}
uint32_t InputEventKey::get_physical_keycode() const {
-
return physical_keycode;
}
void InputEventKey::set_unicode(uint32_t p_unicode) {
-
unicode = p_unicode;
}
uint32_t InputEventKey::get_unicode() const {
-
return unicode;
}
void InputEventKey::set_echo(bool p_enable) {
-
echo = p_enable;
}
bool InputEventKey::is_echo() const {
-
return echo;
}
uint32_t InputEventKey::get_keycode_with_modifiers() const {
-
uint32_t sc = keycode;
- if (get_control())
+ if (get_control()) {
sc |= KEY_MASK_CTRL;
- if (get_alt())
+ }
+ if (get_alt()) {
sc |= KEY_MASK_ALT;
- if (get_shift())
+ }
+ if (get_shift()) {
sc |= KEY_MASK_SHIFT;
- if (get_metakey())
+ }
+ if (get_metakey()) {
sc |= KEY_MASK_META;
+ }
return sc;
}
uint32_t InputEventKey::get_physical_keycode_with_modifiers() const {
-
uint32_t sc = physical_keycode;
- if (get_control())
+ if (get_control()) {
sc |= KEY_MASK_CTRL;
- if (get_alt())
+ }
+ if (get_alt()) {
sc |= KEY_MASK_ALT;
- if (get_shift())
+ }
+ if (get_shift()) {
sc |= KEY_MASK_SHIFT;
- if (get_metakey())
+ }
+ if (get_metakey()) {
sc |= KEY_MASK_META;
+ }
return sc;
}
String InputEventKey::as_text() const {
-
String kc = keycode_get_string(keycode);
- if (kc == String())
+ if (kc == String()) {
return kc;
+ }
if (get_metakey()) {
kc = find_keycode_name(KEY_META) + ("+" + kc);
@@ -332,10 +308,10 @@ String InputEventKey::as_text() const {
}
bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
-
Ref<InputEventKey> key = p_event;
- if (key.is_null())
+ if (key.is_null()) {
return false;
+ }
bool match = false;
if (get_keycode() == 0) {
@@ -350,19 +326,21 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed
match = get_keycode() == key->get_keycode() && (!key->is_pressed() || (code & event_code) == code);
}
if (match) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = key->is_pressed();
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ }
}
return match;
}
bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const {
-
Ref<InputEventKey> key = p_event;
- if (key.is_null())
+ if (key.is_null()) {
return false;
+ }
uint32_t code = get_keycode_with_modifiers();
uint32_t event_code = key->get_keycode_with_modifiers();
@@ -371,7 +349,6 @@ bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const {
}
void InputEventKey::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed);
ClassDB::bind_method(D_METHOD("set_keycode", "keycode"), &InputEventKey::set_keycode);
@@ -398,34 +375,30 @@ void InputEventKey::_bind_methods() {
///////////////////////////////////
void InputEventMouse::set_button_mask(int p_mask) {
-
button_mask = p_mask;
}
-int InputEventMouse::get_button_mask() const {
+int InputEventMouse::get_button_mask() const {
return button_mask;
}
void InputEventMouse::set_position(const Vector2 &p_pos) {
-
pos = p_pos;
}
-Vector2 InputEventMouse::get_position() const {
+Vector2 InputEventMouse::get_position() const {
return pos;
}
void InputEventMouse::set_global_position(const Vector2 &p_global_pos) {
-
global_pos = p_global_pos;
}
-Vector2 InputEventMouse::get_global_position() const {
+Vector2 InputEventMouse::get_global_position() const {
return global_pos;
}
void InputEventMouse::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask);
ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask);
@@ -443,44 +416,38 @@ void InputEventMouse::_bind_methods() {
///////////////////////////////////
void InputEventMouseButton::set_factor(float p_factor) {
-
factor = p_factor;
}
float InputEventMouseButton::get_factor() const {
-
return factor;
}
void InputEventMouseButton::set_button_index(int p_index) {
-
button_index = p_index;
}
-int InputEventMouseButton::get_button_index() const {
+int InputEventMouseButton::get_button_index() const {
return button_index;
}
void InputEventMouseButton::set_pressed(bool p_pressed) {
-
pressed = p_pressed;
}
-bool InputEventMouseButton::is_pressed() const {
+bool InputEventMouseButton::is_pressed() const {
return pressed;
}
void InputEventMouseButton::set_doubleclick(bool p_doubleclick) {
-
doubleclick = p_doubleclick;
}
-bool InputEventMouseButton::is_doubleclick() const {
+bool InputEventMouseButton::is_doubleclick() const {
return doubleclick;
}
Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
-
Vector2 g = get_global_position();
Vector2 l = p_xform.xform(get_position() + p_local_ofs);
@@ -504,24 +471,25 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co
}
bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
-
Ref<InputEventMouseButton> mb = p_event;
- if (mb.is_null())
+ if (mb.is_null()) {
return false;
+ }
bool match = mb->button_index == button_index;
if (match) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = mb->is_pressed();
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ }
}
return match;
}
String InputEventMouseButton::as_text() const {
-
String button_index_string = "";
switch (get_button_index()) {
case BUTTON_LEFT:
@@ -559,7 +527,6 @@ String InputEventMouseButton::as_text() const {
}
void InputEventMouseButton::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor);
ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMouseButton::get_factor);
@@ -581,47 +548,38 @@ void InputEventMouseButton::_bind_methods() {
///////////////////////////////////
void InputEventMouseMotion::set_tilt(const Vector2 &p_tilt) {
-
tilt = p_tilt;
}
Vector2 InputEventMouseMotion::get_tilt() const {
-
return tilt;
}
void InputEventMouseMotion::set_pressure(float p_pressure) {
-
pressure = p_pressure;
}
float InputEventMouseMotion::get_pressure() const {
-
return pressure;
}
void InputEventMouseMotion::set_relative(const Vector2 &p_relative) {
-
relative = p_relative;
}
Vector2 InputEventMouseMotion::get_relative() const {
-
return relative;
}
void InputEventMouseMotion::set_speed(const Vector2 &p_speed) {
-
speed = p_speed;
}
Vector2 InputEventMouseMotion::get_speed() const {
-
return speed;
}
Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
-
Vector2 g = get_global_position();
Vector2 l = p_xform.xform(get_position() + p_local_ofs);
Vector2 r = p_xform.basis_xform(get_relative());
@@ -648,7 +606,6 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co
}
String InputEventMouseMotion::as_text() const {
-
String button_mask_string = "";
switch (get_button_mask()) {
case BUTTON_MASK_LEFT:
@@ -674,10 +631,10 @@ String InputEventMouseMotion::as_text() const {
}
bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
-
Ref<InputEventMouseMotion> motion = p_event;
- if (motion.is_null())
+ if (motion.is_null()) {
return false;
+ }
if (get_window_id() != motion->get_window_id()) {
return false;
@@ -716,7 +673,6 @@ bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
}
void InputEventMouseMotion::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_tilt", "tilt"), &InputEventMouseMotion::set_tilt);
ClassDB::bind_method(D_METHOD("get_tilt"), &InputEventMouseMotion::get_tilt);
@@ -738,42 +694,38 @@ void InputEventMouseMotion::_bind_methods() {
///////////////////////////////////
void InputEventJoypadMotion::set_axis(int p_axis) {
-
axis = p_axis;
}
int InputEventJoypadMotion::get_axis() const {
-
return axis;
}
void InputEventJoypadMotion::set_axis_value(float p_value) {
-
axis_value = p_value;
}
float InputEventJoypadMotion::get_axis_value() const {
-
return axis_value;
}
bool InputEventJoypadMotion::is_pressed() const {
-
return Math::abs(axis_value) >= 0.5f;
}
bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
-
Ref<InputEventJoypadMotion> jm = p_event;
- if (jm.is_null())
+ if (jm.is_null()) {
return false;
+ }
bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.
if (match) {
bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false;
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = pressed;
+ }
if (p_strength != nullptr) {
if (pressed) {
if (p_deadzone == 1.0f) {
@@ -790,12 +742,10 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *
}
String InputEventJoypadMotion::as_text() const {
-
return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value));
}
void InputEventJoypadMotion::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis);
ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis);
@@ -809,66 +759,62 @@ void InputEventJoypadMotion::_bind_methods() {
///////////////////////////////////
void InputEventJoypadButton::set_button_index(int p_index) {
-
button_index = p_index;
}
int InputEventJoypadButton::get_button_index() const {
-
return button_index;
}
void InputEventJoypadButton::set_pressed(bool p_pressed) {
-
pressed = p_pressed;
}
-bool InputEventJoypadButton::is_pressed() const {
+bool InputEventJoypadButton::is_pressed() const {
return pressed;
}
void InputEventJoypadButton::set_pressure(float p_pressure) {
-
pressure = p_pressure;
}
-float InputEventJoypadButton::get_pressure() const {
+float InputEventJoypadButton::get_pressure() const {
return pressure;
}
bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
-
Ref<InputEventJoypadButton> jb = p_event;
- if (jb.is_null())
+ if (jb.is_null()) {
return false;
+ }
bool match = button_index == jb->button_index;
if (match) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = jb->is_pressed();
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ }
}
return match;
}
bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const {
-
Ref<InputEventJoypadButton> button = p_event;
- if (button.is_null())
+ if (button.is_null()) {
return false;
+ }
return button_index == button->button_index;
}
String InputEventJoypadButton::as_text() const {
-
return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure));
}
void InputEventJoypadButton::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);
@@ -886,34 +832,30 @@ void InputEventJoypadButton::_bind_methods() {
///////////////////////////////////
void InputEventScreenTouch::set_index(int p_index) {
-
index = p_index;
}
-int InputEventScreenTouch::get_index() const {
+int InputEventScreenTouch::get_index() const {
return index;
}
void InputEventScreenTouch::set_position(const Vector2 &p_pos) {
-
pos = p_pos;
}
-Vector2 InputEventScreenTouch::get_position() const {
+Vector2 InputEventScreenTouch::get_position() const {
return pos;
}
void InputEventScreenTouch::set_pressed(bool p_pressed) {
-
pressed = p_pressed;
}
-bool InputEventScreenTouch::is_pressed() const {
+bool InputEventScreenTouch::is_pressed() const {
return pressed;
}
Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
-
Ref<InputEventScreenTouch> st;
st.instance();
st->set_device(get_device());
@@ -926,12 +868,10 @@ Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co
}
String InputEventScreenTouch::as_text() const {
-
return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")";
}
void InputEventScreenTouch::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index);
@@ -949,44 +889,38 @@ void InputEventScreenTouch::_bind_methods() {
///////////////////////////////////
void InputEventScreenDrag::set_index(int p_index) {
-
index = p_index;
}
int InputEventScreenDrag::get_index() const {
-
return index;
}
void InputEventScreenDrag::set_position(const Vector2 &p_pos) {
-
pos = p_pos;
}
-Vector2 InputEventScreenDrag::get_position() const {
+Vector2 InputEventScreenDrag::get_position() const {
return pos;
}
void InputEventScreenDrag::set_relative(const Vector2 &p_relative) {
-
relative = p_relative;
}
-Vector2 InputEventScreenDrag::get_relative() const {
+Vector2 InputEventScreenDrag::get_relative() const {
return relative;
}
void InputEventScreenDrag::set_speed(const Vector2 &p_speed) {
-
speed = p_speed;
}
-Vector2 InputEventScreenDrag::get_speed() const {
+Vector2 InputEventScreenDrag::get_speed() const {
return speed;
}
Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
-
Ref<InputEventScreenDrag> sd;
sd.instance();
@@ -1003,12 +937,10 @@ Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con
}
String InputEventScreenDrag::as_text() const {
-
return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
}
void InputEventScreenDrag::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
@@ -1030,20 +962,18 @@ void InputEventScreenDrag::_bind_methods() {
///////////////////////////////////
void InputEventAction::set_action(const StringName &p_action) {
-
action = p_action;
}
-StringName InputEventAction::get_action() const {
+StringName InputEventAction::get_action() const {
return action;
}
void InputEventAction::set_pressed(bool p_pressed) {
-
pressed = p_pressed;
}
-bool InputEventAction::is_pressed() const {
+bool InputEventAction::is_pressed() const {
return pressed;
}
@@ -1056,40 +986,40 @@ float InputEventAction::get_strength() const {
}
bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const {
- if (p_event.is_null())
+ if (p_event.is_null()) {
return false;
+ }
return p_event->is_action(action);
}
bool InputEventAction::is_action(const StringName &p_action) const {
-
return action == p_action;
}
bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
-
Ref<InputEventAction> act = p_event;
- if (act.is_null())
+ if (act.is_null()) {
return false;
+ }
bool match = action == act->action;
if (match) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = act->pressed;
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ }
}
return match;
}
String InputEventAction::as_text() const {
-
return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false");
}
void InputEventAction::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);
ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action);
@@ -1109,12 +1039,10 @@ void InputEventAction::_bind_methods() {
///////////////////////////////////
void InputEventGesture::set_position(const Vector2 &p_pos) {
-
pos = p_pos;
}
void InputEventGesture::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventGesture::set_position);
ClassDB::bind_method(D_METHOD("get_position"), &InputEventGesture::get_position);
@@ -1122,24 +1050,20 @@ void InputEventGesture::_bind_methods() {
}
Vector2 InputEventGesture::get_position() const {
-
return pos;
}
///////////////////////////////////
void InputEventMagnifyGesture::set_factor(real_t p_factor) {
-
factor = p_factor;
}
real_t InputEventMagnifyGesture::get_factor() const {
-
return factor;
}
Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
-
Ref<InputEventMagnifyGesture> ev;
ev.instance();
@@ -1155,12 +1079,10 @@ Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform,
}
String InputEventMagnifyGesture::as_text() const {
-
return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")";
}
void InputEventMagnifyGesture::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor);
ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor);
@@ -1170,7 +1092,6 @@ void InputEventMagnifyGesture::_bind_methods() {
///////////////////////////////////
void InputEventPanGesture::set_delta(const Vector2 &p_delta) {
-
delta = p_delta;
}
@@ -1179,7 +1100,6 @@ Vector2 InputEventPanGesture::get_delta() const {
}
Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
-
Ref<InputEventPanGesture> ev;
ev.instance();
@@ -1195,12 +1115,10 @@ Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, con
}
String InputEventPanGesture::as_text() const {
-
return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")";
}
void InputEventPanGesture::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta);
ClassDB::bind_method(D_METHOD("get_delta"), &InputEventPanGesture::get_delta);
@@ -1210,7 +1128,6 @@ void InputEventPanGesture::_bind_methods() {
///////////////////////////////////
void InputEventMIDI::set_channel(const int p_channel) {
-
channel = p_channel;
}
@@ -1219,7 +1136,6 @@ int InputEventMIDI::get_channel() const {
}
void InputEventMIDI::set_message(const int p_message) {
-
message = p_message;
}
@@ -1228,7 +1144,6 @@ int InputEventMIDI::get_message() const {
}
void InputEventMIDI::set_pitch(const int p_pitch) {
-
pitch = p_pitch;
}
@@ -1237,7 +1152,6 @@ int InputEventMIDI::get_pitch() const {
}
void InputEventMIDI::set_velocity(const int p_velocity) {
-
velocity = p_velocity;
}
@@ -1246,7 +1160,6 @@ int InputEventMIDI::get_velocity() const {
}
void InputEventMIDI::set_instrument(const int p_instrument) {
-
instrument = p_instrument;
}
@@ -1255,7 +1168,6 @@ int InputEventMIDI::get_instrument() const {
}
void InputEventMIDI::set_pressure(const int p_pressure) {
-
pressure = p_pressure;
}
@@ -1264,7 +1176,6 @@ int InputEventMIDI::get_pressure() const {
}
void InputEventMIDI::set_controller_number(const int p_controller_number) {
-
controller_number = p_controller_number;
}
@@ -1273,7 +1184,6 @@ int InputEventMIDI::get_controller_number() const {
}
void InputEventMIDI::set_controller_value(const int p_controller_value) {
-
controller_value = p_controller_value;
}
@@ -1282,12 +1192,10 @@ int InputEventMIDI::get_controller_value() const {
}
String InputEventMIDI::as_text() const {
-
return "InputEventMIDI : channel=(" + itos(get_channel()) + "), message=(" + itos(get_message()) + ")";
}
void InputEventMIDI::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_channel", "channel"), &InputEventMIDI::set_channel);
ClassDB::bind_method(D_METHOD("get_channel"), &InputEventMIDI::get_channel);
ClassDB::bind_method(D_METHOD("set_message", "message"), &InputEventMIDI::set_message);
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 18792076f5..dd1cc11982 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -192,7 +192,6 @@ public:
};
class InputEventFromWindow : public InputEvent {
-
GDCLASS(InputEventFromWindow, InputEvent);
int64_t window_id = 0;
@@ -252,7 +251,6 @@ public:
};
class InputEventKey : public InputEventWithModifiers {
-
GDCLASS(InputEventKey, InputEventWithModifiers);
bool pressed = false; /// otherwise release
@@ -296,7 +294,6 @@ public:
};
class InputEventMouse : public InputEventWithModifiers {
-
GDCLASS(InputEventMouse, InputEventWithModifiers);
int button_mask = 0;
@@ -321,7 +318,6 @@ public:
};
class InputEventMouseButton : public InputEventMouse {
-
GDCLASS(InputEventMouseButton, InputEventMouse);
float factor = 1;
@@ -355,7 +351,6 @@ public:
};
class InputEventMouseMotion : public InputEventMouse {
-
GDCLASS(InputEventMouseMotion, InputEventMouse);
Vector2 tilt;
@@ -388,7 +383,6 @@ public:
};
class InputEventJoypadMotion : public InputEvent {
-
GDCLASS(InputEventJoypadMotion, InputEvent);
int axis = 0; ///< Joypad axis
float axis_value = 0; ///< -1 to 1
@@ -467,7 +461,6 @@ public:
};
class InputEventScreenDrag : public InputEventFromWindow {
-
GDCLASS(InputEventScreenDrag, InputEventFromWindow);
int index = 0;
Vector2 pos;
@@ -497,7 +490,6 @@ public:
};
class InputEventAction : public InputEvent {
-
GDCLASS(InputEventAction, InputEvent);
StringName action;
@@ -529,7 +521,6 @@ public:
};
class InputEventGesture : public InputEventWithModifiers {
-
GDCLASS(InputEventGesture, InputEventWithModifiers);
Vector2 pos;
@@ -543,7 +534,6 @@ public:
};
class InputEventMagnifyGesture : public InputEventGesture {
-
GDCLASS(InputEventMagnifyGesture, InputEventGesture);
real_t factor = 1.0;
@@ -561,7 +551,6 @@ public:
};
class InputEventPanGesture : public InputEventGesture {
-
GDCLASS(InputEventPanGesture, InputEventGesture);
Vector2 delta;
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index 6b6acf062d..3cb4b43a26 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -38,7 +38,6 @@ InputMap *InputMap::singleton = nullptr;
int InputMap::ALL_DEVICES = -1;
void InputMap::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions);
ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(0.5f));
@@ -55,7 +54,6 @@ void InputMap::_bind_methods() {
}
void InputMap::add_action(const StringName &p_action, float p_deadzone) {
-
ERR_FAIL_COND_MSG(input_map.has(p_action), "InputMap already has action '" + String(p_action) + "'.");
input_map[p_action] = Action();
static int last_id = 1;
@@ -65,20 +63,18 @@ void InputMap::add_action(const StringName &p_action, float p_deadzone) {
}
void InputMap::erase_action(const StringName &p_action) {
-
ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'.");
input_map.erase(p_action);
}
Array InputMap::_get_actions() {
-
Array ret;
List<StringName> actions = get_actions();
- if (actions.empty())
+ if (actions.empty()) {
return ret;
+ }
for (const List<StringName>::Element *E = actions.front(); E; E = E->next()) {
-
ret.push_back(E->get());
}
@@ -86,7 +82,6 @@ Array InputMap::_get_actions() {
}
List<StringName> InputMap::get_actions() const {
-
List<StringName> actions = List<StringName>();
if (input_map.empty()) {
return actions;
@@ -100,9 +95,7 @@ List<StringName> InputMap::get_actions() const {
}
List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength) const {
-
for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) {
-
const Ref<InputEvent> e = E->get();
//if (e.type != Ref<InputEvent>::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here?
@@ -120,56 +113,50 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re
}
bool InputMap::has_action(const StringName &p_action) const {
-
return input_map.has(p_action);
}
void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) {
-
ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'.");
input_map[p_action].deadzone = p_deadzone;
}
void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
-
ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object.");
ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'.");
- if (_find_event(input_map[p_action], p_event))
+ if (_find_event(input_map[p_action], p_event)) {
return; //already gots
+ }
input_map[p_action].inputs.push_back(p_event);
}
bool InputMap::action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
-
ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, "Request for nonexistent InputMap action '" + String(p_action) + "'.");
return (_find_event(input_map[p_action], p_event) != nullptr);
}
void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
-
ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'.");
List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event);
- if (E)
+ if (E) {
input_map[p_action].inputs.erase(E);
+ }
}
void InputMap::action_erase_events(const StringName &p_action) {
-
ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'.");
input_map[p_action].inputs.clear();
}
Array InputMap::_get_action_list(const StringName &p_action) {
-
Array ret;
const List<Ref<InputEvent>> *al = get_action_list(p_action);
if (al) {
for (const List<Ref<InputEvent>>::Element *E = al->front(); E; E = E->next()) {
-
ret.push_back(E->get());
}
}
@@ -178,10 +165,10 @@ Array InputMap::_get_action_list(const StringName &p_action) {
}
const List<Ref<InputEvent>> *InputMap::get_action_list(const StringName &p_action) {
-
const Map<StringName, Action>::Element *E = input_map.find(p_action);
- if (!E)
+ if (!E) {
return nullptr;
+ }
return &E->get().inputs;
}
@@ -196,10 +183,12 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
Ref<InputEventAction> input_event_action = p_event;
if (input_event_action.is_valid()) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = input_event_action->is_pressed();
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? input_event_action->get_strength() : 0.0f;
+ }
return input_event_action->get_action() == p_action;
}
@@ -207,10 +196,12 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
float strength;
List<Ref<InputEvent>>::Element *event = _find_event(E->get(), p_event, &pressed, &strength);
if (event != nullptr) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = pressed;
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = strength;
+ }
return true;
} else {
return false;
@@ -222,7 +213,6 @@ const Map<StringName, InputMap::Action> &InputMap::get_action_map() const {
}
void InputMap::load_from_globals() {
-
input_map.clear();
List<PropertyInfo> pinfo;
@@ -231,8 +221,9 @@ void InputMap::load_from_globals() {
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
- if (!pi.name.begins_with("input/"))
+ if (!pi.name.begins_with("input/")) {
continue;
+ }
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
@@ -243,15 +234,15 @@ void InputMap::load_from_globals() {
add_action(name, deadzone);
for (int i = 0; i < events.size(); i++) {
Ref<InputEvent> event = events[i];
- if (event.is_null())
+ if (event.is_null()) {
continue;
+ }
action_add_event(name, event);
}
}
}
void InputMap::load_default() {
-
Ref<InputEventKey> key;
add_action("ui_accept");
@@ -332,7 +323,6 @@ void InputMap::load_default() {
}
InputMap::InputMap() {
-
ERR_FAIL_COND_MSG(singleton, "Singleton in InputMap already exist.");
singleton = this;
}
diff --git a/core/input/input_map.h b/core/input/input_map.h
index e03bc5fd4f..3abc224ccf 100644
--- a/core/input/input_map.h
+++ b/core/input/input_map.h
@@ -35,7 +35,6 @@
#include "core/object.h"
class InputMap : public Object {
-
GDCLASS(InputMap, Object);
public:
diff --git a/core/io/compression.cpp b/core/io/compression.cpp
index 20c9fdca6f..99ca8107e4 100644
--- a/core/io/compression.cpp
+++ b/core/io/compression.cpp
@@ -40,10 +40,8 @@
#include <zstd.h>
int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode) {
-
switch (p_mode) {
case MODE_FASTLZ: {
-
if (p_src_size < 16) {
uint8_t src[16];
zeromem(&src[p_src_size], 16 - p_src_size);
@@ -56,7 +54,6 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
-
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
@@ -65,8 +62,9 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
strm.opaque = Z_NULL;
int level = p_mode == MODE_DEFLATE ? zlib_level : gzip_level;
int err = deflateInit2(&strm, level, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY);
- if (err != Z_OK)
+ if (err != Z_OK) {
return -1;
+ }
strm.avail_in = p_src_size;
int aout = deflateBound(&strm, p_src_size);
@@ -97,19 +95,17 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
}
int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
-
switch (p_mode) {
case MODE_FASTLZ: {
-
int ss = p_src_size + p_src_size * 6 / 100;
- if (ss < 66)
+ if (ss < 66) {
ss = 66;
+ }
return ss;
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
-
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
@@ -117,14 +113,14 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
strm.zfree = zipio_free;
strm.opaque = Z_NULL;
int err = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY);
- if (err != Z_OK)
+ if (err != Z_OK) {
return -1;
+ }
int aout = deflateBound(&strm, p_src_size);
deflateEnd(&strm);
return aout;
} break;
case MODE_ZSTD: {
-
return ZSTD_compressBound(p_src_size);
} break;
}
@@ -133,10 +129,8 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
}
int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode) {
-
switch (p_mode) {
case MODE_FASTLZ: {
-
int ret_size = 0;
if (p_dst_max_size < 16) {
@@ -150,7 +144,6 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
-
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
diff --git a/core/io/compression.h b/core/io/compression.h
index 3e7c125d8e..f195f96ba5 100644
--- a/core/io/compression.h
+++ b/core/io/compression.h
@@ -34,7 +34,6 @@
#include "core/typedefs.h"
class Compression {
-
public:
static int zlib_level;
static int gzip_level;
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index 73230e3a3c..1af9142317 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -35,14 +35,12 @@
#include "core/variant_parser.h"
PackedStringArray ConfigFile::_get_sections() const {
-
List<String> s;
get_sections(&s);
PackedStringArray arr;
arr.resize(s.size());
int idx = 0;
for (const List<String>::Element *E = s.front(); E; E = E->next()) {
-
arr.set(idx++, E->get());
}
@@ -50,14 +48,12 @@ PackedStringArray ConfigFile::_get_sections() const {
}
PackedStringArray ConfigFile::_get_section_keys(const String &p_section) const {
-
List<String> s;
get_section_keys(p_section, &s);
PackedStringArray arr;
arr.resize(s.size());
int idx = 0;
for (const List<String>::Element *E = s.front(); E; E = E->next()) {
-
arr.set(idx++, E->get());
}
@@ -65,11 +61,11 @@ PackedStringArray ConfigFile::_get_section_keys(const String &p_section) const {
}
void ConfigFile::set_value(const String &p_section, const String &p_key, const Variant &p_value) {
-
if (p_value.get_type() == Variant::NIL) {
//erase
- if (!values.has(p_section))
+ if (!values.has(p_section)) {
return; // ?
+ }
values[p_section].erase(p_key);
if (values[p_section].empty()) {
values.erase(p_section);
@@ -83,8 +79,8 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V
values[p_section][p_key] = p_value;
}
}
-Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const {
+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(),
vformat("Couldn't find the given section \"%s\" and key \"%s\", and no default was given.", p_section, p_key));
@@ -95,24 +91,23 @@ Variant ConfigFile::get_value(const String &p_section, const String &p_key, Vari
}
bool ConfigFile::has_section(const String &p_section) const {
-
return values.has(p_section);
}
-bool ConfigFile::has_section_key(const String &p_section, const String &p_key) const {
- if (!values.has(p_section))
+bool ConfigFile::has_section_key(const String &p_section, const String &p_key) const {
+ if (!values.has(p_section)) {
return false;
+ }
return values[p_section].has(p_key);
}
void ConfigFile::get_sections(List<String> *r_sections) const {
-
for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::ConstElement E = values.front(); E; E = E.next()) {
r_sections->push_back(E.key());
}
}
-void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) const {
+void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) const {
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()) {
@@ -121,13 +116,11 @@ 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), 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));
@@ -135,13 +128,13 @@ void ConfigFile::erase_section_key(const String &p_section, const String &p_key)
}
Error ConfigFile::save(const String &p_path) {
-
Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
if (err) {
- if (file)
+ if (file) {
memdelete(file);
+ }
return err;
}
@@ -149,12 +142,12 @@ Error ConfigFile::save(const String &p_path) {
}
Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_key) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_WRITE_AES256);
@@ -167,12 +160,12 @@ Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_
}
Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_WRITE_AES256);
@@ -186,15 +179,13 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass
}
Error ConfigFile::_internal_save(FileAccess *file) {
-
for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::Element E = values.front(); E; E = E.next()) {
-
- if (E != values.front())
+ if (E != values.front()) {
file->store_string("\n");
+ }
file->store_string("[" + E.key() + "]\n\n");
for (OrderedHashMap<String, Variant>::Element F = E.get().front(); F; F = F.next()) {
-
String vstr;
VariantWriter::write_to_string(F.get(), vstr);
file->store_string(F.key() + "=" + vstr + "\n");
@@ -207,23 +198,23 @@ Error ConfigFile::_internal_save(FileAccess *file) {
}
Error ConfigFile::load(const String &p_path) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
- if (!f)
+ if (!f) {
return err;
+ }
return _internal_load(p_path, f);
}
Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_key) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_READ);
@@ -236,12 +227,12 @@ Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_
}
Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_READ);
@@ -255,7 +246,6 @@ Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass
}
Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) {
-
VariantParser::StreamFile stream;
stream.f = f;
@@ -267,14 +257,12 @@ Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) {
}
Error ConfigFile::parse(const String &p_data) {
-
VariantParser::StreamString stream;
stream.s = p_data;
return _parse("<string>", &stream);
}
Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) {
-
String assign;
Variant value;
VariantParser::Tag next_tag;
@@ -285,7 +273,6 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
String section;
while (true) {
-
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();
@@ -309,7 +296,6 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
}
void ConfigFile::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_value", "section", "key", "value"), &ConfigFile::set_value);
ClassDB::bind_method(D_METHOD("get_value", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant()));
diff --git a/core/io/config_file.h b/core/io/config_file.h
index 39fc2ab412..ae06960f02 100644
--- a/core/io/config_file.h
+++ b/core/io/config_file.h
@@ -37,7 +37,6 @@
#include "core/variant_parser.h"
class ConfigFile : public Reference {
-
GDCLASS(ConfigFile, Reference);
OrderedHashMap<String, OrderedHashMap<String, Variant>> values;
diff --git a/core/io/dtls_server.cpp b/core/io/dtls_server.cpp
index 7cbf5c618e..0278027c50 100644
--- a/core/io/dtls_server.cpp
+++ b/core/io/dtls_server.cpp
@@ -37,7 +37,6 @@ DTLSServer *(*DTLSServer::_create)() = nullptr;
bool DTLSServer::available = false;
DTLSServer *DTLSServer::create() {
-
return _create();
}
@@ -46,7 +45,6 @@ bool DTLSServer::is_available() {
}
void DTLSServer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("setup", "key", "certificate", "chain"), &DTLSServer::setup, DEFVAL(Ref<X509Certificate>()));
ClassDB::bind_method(D_METHOD("take_connection", "udp_peer"), &DTLSServer::take_connection);
}
diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp
index 2df91a4dd8..6208f3a4d1 100644
--- a/core/io/file_access_buffered.cpp
+++ b/core/io/file_access_buffered.cpp
@@ -33,28 +33,23 @@
#include "core/error_macros.h"
Error FileAccessBuffered::set_error(Error p_error) const {
-
return (last_error = p_error);
}
void FileAccessBuffered::set_cache_size(int p_size) {
-
cache_size = p_size;
}
int FileAccessBuffered::get_cache_size() {
-
return cache_size;
}
int FileAccessBuffered::cache_data_left() const {
-
if (file.offset >= file.size) {
return 0;
}
if (cache.offset == -1 || file.offset < cache.offset || file.offset >= cache.offset + cache.buffer.size()) {
-
return read_data_block(file.offset, cache_size);
}
@@ -62,37 +57,30 @@ int FileAccessBuffered::cache_data_left() const {
}
void FileAccessBuffered::seek(size_t p_position) {
-
file.offset = p_position;
}
void FileAccessBuffered::seek_end(int64_t p_position) {
-
file.offset = file.size + p_position;
}
size_t FileAccessBuffered::get_position() const {
-
return file.offset;
}
size_t FileAccessBuffered::get_len() const {
-
return file.size;
}
bool FileAccessBuffered::eof_reached() const {
-
return file.offset > file.size;
}
uint8_t FileAccessBuffered::get_8() const {
-
ERR_FAIL_COND_V_MSG(!file.open, 0, "Can't get data, when file is not opened.");
uint8_t byte = 0;
if (cache_data_left() >= 1) {
-
byte = cache.buffer[file.offset - cache.offset];
}
@@ -102,15 +90,12 @@ uint8_t FileAccessBuffered::get_8() const {
}
int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const {
-
ERR_FAIL_COND_V_MSG(!file.open, -1, "Can't get buffer, when file is not opened.");
if (p_length > cache_size) {
-
int total_read = 0;
if (!(cache.offset == -1 || file.offset < cache.offset || file.offset >= cache.offset + cache.buffer.size())) {
-
int size = (cache.buffer.size() - (file.offset - cache.offset));
size = size - (size % 4);
//const uint8_t* read = cache.buffer.ptr();
@@ -134,7 +119,6 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const {
int to_read = p_length;
int total_read = 0;
while (to_read > 0) {
-
int left = cache_data_left();
if (left == 0) {
file.offset += to_read;
@@ -158,11 +142,9 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const {
}
bool FileAccessBuffered::is_open() const {
-
return file.open;
}
Error FileAccessBuffered::get_error() const {
-
return last_error;
}
diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h
index f473886330..61c0fa7489 100644
--- a/core/io/file_access_buffered.h
+++ b/core/io/file_access_buffered.h
@@ -36,7 +36,6 @@
#include "core/ustring.h"
class FileAccessBuffered : public FileAccess {
-
public:
enum {
DEFAULT_CACHE_SIZE = 128 * 1024,
@@ -52,7 +51,6 @@ protected:
Error set_error(Error p_error) const;
mutable struct File {
-
bool open;
int size;
int offset;
@@ -61,7 +59,6 @@ protected:
} file;
mutable struct Cache {
-
Vector<uint8_t> buffer;
int offset;
} cache;
diff --git a/core/io/file_access_buffered_fa.h b/core/io/file_access_buffered_fa.h
index edb4ff9a9f..3ea98584a4 100644
--- a/core/io/file_access_buffered_fa.h
+++ b/core/io/file_access_buffered_fa.h
@@ -35,22 +35,18 @@
template <class T>
class FileAccessBufferedFA : public FileAccessBuffered {
-
T f;
int read_data_block(int p_offset, int p_size, uint8_t *p_dest = 0) const {
-
ERR_FAIL_COND_V_MSG(!f.is_open(), -1, "Can't read data block when file is not opened.");
((T *)&f)->seek(p_offset);
if (p_dest) {
-
f.get_buffer(p_dest, p_size);
return p_size;
} else {
-
cache.offset = p_offset;
cache.buffer.resize(p_size);
@@ -66,7 +62,6 @@ class FileAccessBufferedFA : public FileAccessBuffered {
};
static FileAccess *create() {
-
return memnew(FileAccessBufferedFA<T>());
};
@@ -78,27 +73,22 @@ protected:
public:
void flush() {
-
f.flush();
};
void store_8(uint8_t p_dest) {
-
f.store_8(p_dest);
};
void store_buffer(const uint8_t *p_src, int p_length) {
-
f.store_buffer(p_src, p_length);
};
bool file_exists(const String &p_name) {
-
return f.file_exists(p_name);
};
Error _open(const String &p_path, int p_mode_flags) {
-
close();
Error ret = f._open(p_path, p_mode_flags);
@@ -119,7 +109,6 @@ public:
};
void close() {
-
f.close();
file.offset = 0;
@@ -133,7 +122,6 @@ public:
};
virtual uint64_t _get_modified_time(const String &p_file) {
-
return f._get_modified_time(p_file);
}
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index f2827b519e..7817ccb773 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -33,13 +33,13 @@
#include "core/print_string.h"
void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, int p_block_size) {
-
magic = p_magic.ascii().get_data();
- if (magic.length() > 4)
+ if (magic.length() > 4) {
magic = magic.substr(0, 4);
- else {
- while (magic.length() < 4)
+ } else {
+ while (magic.length() < 4) {
magic += " ";
+ }
}
cmode = p_mode;
@@ -59,7 +59,6 @@ void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_
}
Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
-
f = p_base;
cmode = (Compression::Mode)f->get_32();
block_size = f->get_32();
@@ -72,7 +71,6 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
int acc_ofs = f->get_position() + bc * 4;
int max_bs = 0;
for (int i = 0; i < bc; i++) {
-
ReadBlock rb;
rb.offset = acc_ofs;
rb.csize = f->get_32();
@@ -98,11 +96,11 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
}
Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
-
ERR_FAIL_COND_V(p_mode_flags == READ_WRITE, ERR_UNAVAILABLE);
- if (f)
+ if (f) {
close();
+ }
Error err;
f = FileAccess::open(p_path, p_mode_flags, &err);
@@ -114,7 +112,6 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
}
if (p_mode_flags & WRITE) {
-
buffer.clear();
writing = true;
write_pos = 0;
@@ -125,7 +122,6 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
//don't store anything else unless it's done saving!
} else {
-
char rmagic[5];
f->get_buffer((uint8_t *)rmagic, 4);
rmagic[4] = 0;
@@ -138,10 +134,11 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
return OK;
}
-void FileAccessCompressed::close() {
- if (!f)
+void FileAccessCompressed::close() {
+ if (!f) {
return;
+ }
if (writing) {
//save block table and all compressed blocks
@@ -159,7 +156,6 @@ void FileAccessCompressed::close() {
Vector<int> block_sizes;
for (int i = 0; i < bc; i++) {
-
int bl = i == (bc - 1) ? write_max % block_size : block_size;
uint8_t *bp = &write_ptr[i * block_size];
@@ -172,15 +168,15 @@ void FileAccessCompressed::close() {
}
f->seek(16); //ok write block sizes
- for (int i = 0; i < bc; i++)
+ for (int i = 0; i < bc; i++) {
f->store_32(block_sizes[i]);
+ }
f->seek_end();
f->store_buffer((const uint8_t *)mgc.get_data(), mgc.length()); //magic at the end too
buffer.clear();
} else {
-
comp_buffer.clear();
buffer.clear();
read_blocks.clear();
@@ -191,21 +187,17 @@ void FileAccessCompressed::close() {
}
bool FileAccessCompressed::is_open() const {
-
return f != nullptr;
}
void FileAccessCompressed::seek(size_t p_position) {
-
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
if (writing) {
-
ERR_FAIL_COND(p_position > write_max);
write_pos = p_position;
} else {
-
ERR_FAIL_COND(p_position > read_total);
if (p_position == read_total) {
at_end = true;
@@ -214,7 +206,6 @@ void FileAccessCompressed::seek(size_t p_position) {
read_eof = false;
int block_idx = p_position / block_size;
if (block_idx != read_block) {
-
read_block = block_idx;
f->seek(read_blocks[read_block].offset);
f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
@@ -228,32 +219,26 @@ void FileAccessCompressed::seek(size_t p_position) {
}
void FileAccessCompressed::seek_end(int64_t p_position) {
-
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
if (writing) {
-
seek(write_max + p_position);
} else {
-
seek(read_total + p_position);
}
}
-size_t FileAccessCompressed::get_position() const {
+size_t FileAccessCompressed::get_position() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
if (writing) {
-
return write_pos;
} else {
-
return read_block * block_size + read_pos;
}
}
-size_t FileAccessCompressed::get_len() const {
+size_t FileAccessCompressed::get_len() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
if (writing) {
-
return write_max;
} else {
return read_total;
@@ -261,7 +246,6 @@ size_t FileAccessCompressed::get_len() const {
}
bool FileAccessCompressed::eof_reached() const {
-
ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use.");
if (writing) {
return false;
@@ -271,7 +255,6 @@ bool FileAccessCompressed::eof_reached() const {
}
uint8_t FileAccessCompressed::get_8() const {
-
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
@@ -301,8 +284,8 @@ uint8_t FileAccessCompressed::get_8() const {
return ret;
}
-int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
+int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
@@ -312,7 +295,6 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
}
for (int i = 0; i < p_length; i++) {
-
p_dst[i] = read_ptr[read_pos];
read_pos++;
if (read_pos >= read_block_size) {
@@ -328,8 +310,9 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
} else {
read_block--;
at_end = true;
- if (i < p_length - 1)
+ if (i < p_length - 1) {
read_eof = true;
+ }
return i;
}
}
@@ -339,7 +322,6 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
}
Error FileAccessCompressed::get_error() const {
-
return read_eof ? ERR_FILE_EOF : OK;
}
@@ -351,7 +333,6 @@ void FileAccessCompressed::flush() {
}
void FileAccessCompressed::store_8(uint8_t p_dest) {
-
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode.");
@@ -360,25 +341,26 @@ void FileAccessCompressed::store_8(uint8_t p_dest) {
}
bool FileAccessCompressed::file_exists(const String &p_name) {
-
FileAccess *fa = FileAccess::open(p_name, FileAccess::READ);
- if (!fa)
+ if (!fa) {
return false;
+ }
memdelete(fa);
return true;
}
uint64_t FileAccessCompressed::_get_modified_time(const String &p_file) {
-
- if (f)
+ if (f) {
return f->get_modified_time(p_file);
- else
+ } else {
return 0;
+ }
}
uint32_t FileAccessCompressed::_get_unix_permissions(const String &p_file) {
- if (f)
+ if (f) {
return f->_get_unix_permissions(p_file);
+ }
return 0;
}
@@ -390,7 +372,7 @@ Error FileAccessCompressed::_set_unix_permissions(const String &p_file, uint32_t
}
FileAccessCompressed::~FileAccessCompressed() {
-
- if (f)
+ if (f) {
close();
+ }
}
diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h
index f192be0883..52284b347e 100644
--- a/core/io/file_access_compressed.h
+++ b/core/io/file_access_compressed.h
@@ -35,7 +35,6 @@
#include "core/os/file_access.h"
class FileAccessCompressed : public FileAccess {
-
Compression::Mode cmode = Compression::MODE_ZSTD;
bool writing = false;
uint32_t write_pos = 0;
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index 271c34ec4a..5938914cb0 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -40,7 +40,6 @@
#define COMP_MAGIC 0x43454447
Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8_t> &p_key, Mode p_mode) {
-
ERR_FAIL_COND_V_MSG(file != nullptr, ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open.");
ERR_FAIL_COND_V(p_key.size() != 32, ERR_INVALID_PARAMETER);
@@ -48,7 +47,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
eofed = false;
if (p_mode == MODE_WRITE_AES256) {
-
data.clear();
writing = true;
file = p_base;
@@ -56,7 +54,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
key = p_key;
} else if (p_mode == MODE_READ) {
-
writing = false;
key = p_key;
uint32_t magic = p_base->get_32();
@@ -85,7 +82,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
ctx.set_decode_key(key.ptrw(), 256);
for (size_t i = 0; i < ds; i += 16) {
-
ctx.decrypt_ecb(&data.write[i], &data.write[i]);
}
@@ -103,13 +99,11 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
}
Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const String &p_key, Mode p_mode) {
-
String cs = p_key.md5_text();
ERR_FAIL_COND_V(cs.length() != 32, ERR_INVALID_PARAMETER);
Vector<uint8_t> key;
key.resize(32);
for (int i = 0; i < 32; i++) {
-
key.write[i] = cs[i];
}
@@ -117,16 +111,15 @@ Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const Str
}
Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) {
-
return OK;
}
-void FileAccessEncrypted::close() {
- if (!file)
+void FileAccessEncrypted::close() {
+ if (!file) {
return;
+ }
if (writing) {
-
Vector<uint8_t> compressed;
size_t len = data.size();
if (len % 16) {
@@ -146,7 +139,6 @@ void FileAccessEncrypted::close() {
ctx.set_encode_key(key.ptrw(), 256);
for (size_t i = 0; i < len; i += 16) {
-
ctx.encrypt_ecb(&compressed.write[i], &compressed.write[i]);
}
@@ -163,7 +155,6 @@ void FileAccessEncrypted::close() {
data.clear();
} else {
-
file->close();
memdelete(file);
data.clear();
@@ -172,55 +163,51 @@ void FileAccessEncrypted::close() {
}
bool FileAccessEncrypted::is_open() const {
-
return file != nullptr;
}
String FileAccessEncrypted::get_path() const {
-
- if (file)
+ if (file) {
return file->get_path();
- else
+ } else {
return "";
+ }
}
String FileAccessEncrypted::get_path_absolute() const {
-
- if (file)
+ if (file) {
return file->get_path_absolute();
- else
+ } else {
return "";
+ }
}
void FileAccessEncrypted::seek(size_t p_position) {
-
- if (p_position > (size_t)data.size())
+ if (p_position > (size_t)data.size()) {
p_position = data.size();
+ }
pos = p_position;
eofed = false;
}
void FileAccessEncrypted::seek_end(int64_t p_position) {
-
seek(data.size() + p_position);
}
-size_t FileAccessEncrypted::get_position() const {
+size_t FileAccessEncrypted::get_position() const {
return pos;
}
-size_t FileAccessEncrypted::get_len() const {
+size_t FileAccessEncrypted::get_len() const {
return data.size();
}
bool FileAccessEncrypted::eof_reached() const {
-
return eofed;
}
uint8_t FileAccessEncrypted::get_8() const {
-
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
if (pos >= data.size()) {
eofed = true;
@@ -231,13 +218,12 @@ uint8_t FileAccessEncrypted::get_8() const {
pos++;
return b;
}
-int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
+int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
int to_copy = MIN(p_length, data.size() - pos);
for (int i = 0; i < to_copy; i++) {
-
p_dst[i] = data[pos++];
}
@@ -249,25 +235,19 @@ int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
}
Error FileAccessEncrypted::get_error() const {
-
return eofed ? ERR_FILE_EOF : OK;
}
void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) {
-
ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode.");
if (pos < data.size()) {
-
for (int i = 0; i < p_length; i++) {
-
store_8(p_src[i]);
}
} else if (pos == data.size()) {
-
data.resize(pos + p_length);
for (int i = 0; i < p_length; i++) {
-
data.write[pos + i] = p_src[i];
}
pos += p_length;
@@ -281,7 +261,6 @@ void FileAccessEncrypted::flush() {
}
void FileAccessEncrypted::store_8(uint8_t p_dest) {
-
ERR_FAIL_COND_MSG(!writing, "File has not been opened in read mode.");
if (pos < data.size()) {
@@ -294,21 +273,19 @@ void FileAccessEncrypted::store_8(uint8_t p_dest) {
}
bool FileAccessEncrypted::file_exists(const String &p_name) {
-
FileAccess *fa = FileAccess::open(p_name, FileAccess::READ);
- if (!fa)
+ if (!fa) {
return false;
+ }
memdelete(fa);
return true;
}
uint64_t FileAccessEncrypted::_get_modified_time(const String &p_file) {
-
return 0;
}
uint32_t FileAccessEncrypted::_get_unix_permissions(const String &p_file) {
-
return 0;
}
@@ -318,7 +295,7 @@ Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t
}
FileAccessEncrypted::~FileAccessEncrypted() {
-
- if (file)
+ if (file) {
close();
+ }
}
diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp
index a3e04a4538..3c5f846941 100644
--- a/core/io/file_access_memory.cpp
+++ b/core/io/file_access_memory.cpp
@@ -38,36 +38,34 @@
static Map<String, Vector<uint8_t>> *files = nullptr;
void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) {
-
if (!files) {
files = memnew((Map<String, Vector<uint8_t>>));
}
String name;
- if (ProjectSettings::get_singleton())
+ if (ProjectSettings::get_singleton()) {
name = ProjectSettings::get_singleton()->globalize_path(p_name);
- else
+ } else {
name = p_name;
+ }
//name = DirAccess::normalize_path(name);
(*files)[name] = p_data;
}
void FileAccessMemory::cleanup() {
-
- if (!files)
+ if (!files) {
return;
+ }
memdelete(files);
}
FileAccess *FileAccessMemory::create() {
-
return memnew(FileAccessMemory);
}
bool FileAccessMemory::file_exists(const String &p_name) {
-
String name = fix_path(p_name);
//name = DirAccess::normalize_path(name);
@@ -75,7 +73,6 @@ bool FileAccessMemory::file_exists(const String &p_name) {
}
Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) {
-
data = (uint8_t *)p_data;
length = p_len;
pos = 0;
@@ -83,7 +80,6 @@ Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) {
}
Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) {
-
ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND);
String name = fix_path(p_path);
@@ -100,46 +96,38 @@ Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessMemory::close() {
-
data = nullptr;
}
bool FileAccessMemory::is_open() const {
-
return data != nullptr;
}
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_position() 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 = 0;
if (pos < length) {
ret = data[pos];
@@ -150,7 +138,6 @@ uint8_t FileAccessMemory::get_8() const {
}
int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const {
-
ERR_FAIL_COND_V(!data, -1);
int left = length - pos;
@@ -167,7 +154,6 @@ int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const {
}
Error FileAccessMemory::get_error() const {
-
return pos >= length ? ERR_FILE_EOF : OK;
}
@@ -176,14 +162,12 @@ void FileAccessMemory::flush() {
}
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) {
-
int left = length - pos;
int write = MIN(p_length, left);
if (write < p_length) {
diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h
index d8be989b20..1a9bd3fbbb 100644
--- a/core/io/file_access_memory.h
+++ b/core/io/file_access_memory.h
@@ -34,7 +34,6 @@
#include "core/os/file_access.h"
class FileAccessMemory : public FileAccess {
-
uint8_t *data = nullptr;
int length;
mutable int pos;
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index 00f504c391..6890740d90 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -41,19 +41,16 @@
#define DEBUG_TIME(m_what)
void FileAccessNetworkClient::lock_mutex() {
-
mutex.lock();
lockcount++;
}
void FileAccessNetworkClient::unlock_mutex() {
-
lockcount--;
mutex.unlock();
}
void FileAccessNetworkClient::put_32(int p_32) {
-
uint8_t buf[4];
encode_uint32(p_32, buf);
client->put_data(buf, 4);
@@ -61,7 +58,6 @@ void FileAccessNetworkClient::put_32(int p_32) {
}
void FileAccessNetworkClient::put_64(int64_t p_64) {
-
uint8_t buf[8];
encode_uint64(p_64, buf);
client->put_data(buf, 8);
@@ -69,24 +65,20 @@ void FileAccessNetworkClient::put_64(int64_t p_64) {
}
int FileAccessNetworkClient::get_32() {
-
uint8_t buf[4];
client->get_data(buf, 4);
return decode_uint32(buf);
}
int64_t FileAccessNetworkClient::get_64() {
-
uint8_t buf[8];
client->get_data(buf, 8);
return decode_uint64(buf);
}
void FileAccessNetworkClient::_thread_func() {
-
client->set_no_delay(true);
while (!quit) {
-
DEBUG_PRINT("SEM WAIT - " + itos(sem->get()));
sem.wait();
DEBUG_TIME("sem_unlock");
@@ -123,13 +115,12 @@ void FileAccessNetworkClient::_thread_func() {
}
}
- if (accesses.has(id))
+ if (accesses.has(id)) {
fa = accesses[id];
+ }
switch (response) {
-
case FileAccessNetwork::RESPONSE_OPEN: {
-
DEBUG_TIME("sem_open");
int status = get_32();
if (status != OK) {
@@ -143,7 +134,6 @@ void FileAccessNetworkClient::_thread_func() {
} break;
case FileAccessNetwork::RESPONSE_DATA: {
-
int64_t offset = get_64();
uint32_t len = get_32();
@@ -151,19 +141,18 @@ void FileAccessNetworkClient::_thread_func() {
block.resize(len);
client->get_data(block.ptrw(), len);
- if (fa) //may have been queued
+ if (fa) { //may have been queued
fa->_set_block(offset, block);
+ }
} break;
case FileAccessNetwork::RESPONSE_FILE_EXISTS: {
-
int status = get_32();
fa->exists_modtime = status != 0;
fa->sem.post();
} break;
case FileAccessNetwork::RESPONSE_GET_MODTIME: {
-
uint64_t status = get_64();
fa->exists_modtime = status;
fa->sem.post();
@@ -176,14 +165,12 @@ void FileAccessNetworkClient::_thread_func() {
}
void FileAccessNetworkClient::_thread_func(void *s) {
-
FileAccessNetworkClient *self = (FileAccessNetworkClient *)s;
self->_thread_func();
}
Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const String &p_password) {
-
IP_Address ip;
if (p_host.is_valid_ip_address()) {
@@ -236,7 +223,6 @@ FileAccessNetworkClient::~FileAccessNetworkClient() {
}
void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) {
-
int page = p_offset / page_size;
ERR_FAIL_INDEX(page, pages.size());
if (page < pages.size() - 1) {
@@ -258,11 +244,11 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block)
}
void FileAccessNetwork::_respond(size_t p_len, Error p_status) {
-
DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status));
response = p_status;
- if (response != OK)
+ if (response != OK) {
return;
+ }
opened = true;
total_size = p_len;
int pc = ((total_size - 1) / page_size) + 1;
@@ -270,10 +256,10 @@ void FileAccessNetwork::_respond(size_t p_len, Error p_status) {
}
Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
-
ERR_FAIL_COND_V(p_mode_flags != READ, ERR_UNAVAILABLE);
- if (opened)
+ if (opened) {
close();
+ }
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
DEBUG_PRINT("open: " + p_path);
@@ -305,9 +291,9 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessNetwork::close() {
-
- if (!opened)
+ if (!opened) {
return;
+ }
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
@@ -319,13 +305,12 @@ void FileAccessNetwork::close() {
opened = false;
nc->unlock_mutex();
}
-bool FileAccessNetwork::is_open() const {
+bool FileAccessNetwork::is_open() const {
return opened;
}
void FileAccessNetwork::seek(size_t p_position) {
-
ERR_FAIL_COND_MSG(!opened, "File must be opened before use.");
eof_flag = p_position > total_size;
@@ -337,39 +322,35 @@ void FileAccessNetwork::seek(size_t p_position) {
}
void FileAccessNetwork::seek_end(int64_t p_position) {
-
seek(total_size + p_position);
}
-size_t FileAccessNetwork::get_position() const {
+size_t FileAccessNetwork::get_position() const {
ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use.");
return pos;
}
-size_t FileAccessNetwork::get_len() const {
+size_t FileAccessNetwork::get_len() const {
ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use.");
return total_size;
}
bool FileAccessNetwork::eof_reached() const {
-
ERR_FAIL_COND_V_MSG(!opened, false, "File must be opened before use.");
return eof_flag;
}
uint8_t FileAccessNetwork::get_8() const {
-
uint8_t v;
get_buffer(&v, 1);
return v;
}
void FileAccessNetwork::_queue_page(int p_page) const {
-
- if (p_page >= pages.size())
+ if (p_page >= pages.size()) {
return;
+ }
if (pages[p_page].buffer.empty() && !pages[p_page].queued) {
-
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
{
MutexLock lock(nc->blockrequest_mutex);
@@ -388,7 +369,6 @@ void FileAccessNetwork::_queue_page(int p_page) const {
}
int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
-
//bool eof=false;
if (pos + p_length > total_size) {
eof_flag = true;
@@ -402,7 +382,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
uint8_t *buff = last_page_buff;
for (int i = 0; i < p_length; i++) {
-
int page = pos / page_size;
if (page != last_page) {
@@ -410,7 +389,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
if (pages[page].buffer.empty()) {
waiting_on_page = page;
for (int j = 0; j < read_ahead; j++) {
-
_queue_page(page + j);
}
buffer_mutex.unlock();
@@ -418,9 +396,7 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
page_sem.wait();
DEBUG_PRINT("done");
} else {
-
for (int j = 0; j < read_ahead; j++) {
-
_queue_page(page + j);
}
//queue pages
@@ -440,7 +416,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
}
Error FileAccessNetwork::get_error() const {
-
return pos == total_size ? ERR_FILE_EOF : OK;
}
@@ -449,12 +424,10 @@ void FileAccessNetwork::flush() {
}
void FileAccessNetwork::store_8(uint8_t p_dest) {
-
ERR_FAIL();
}
bool FileAccessNetwork::file_exists(const String &p_path) {
-
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->lock_mutex();
nc->put_32(id);
@@ -471,7 +444,6 @@ bool FileAccessNetwork::file_exists(const String &p_path) {
}
uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) {
-
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->lock_mutex();
nc->put_32(id);
@@ -498,7 +470,6 @@ Error FileAccessNetwork::_set_unix_permissions(const String &p_file, uint32_t p_
}
void FileAccessNetwork::configure() {
-
GLOBAL_DEF("network/remote_fs/page_size", 65536);
ProjectSettings::get_singleton()->set_custom_property_info("network/remote_fs/page_size", PropertyInfo(Variant::INT, "network/remote_fs/page_size", PROPERTY_HINT_RANGE, "1,65536,1,or_greater")); //is used as denominator and can't be zero
GLOBAL_DEF("network/remote_fs/page_read_ahead", 4);
@@ -506,7 +477,6 @@ void FileAccessNetwork::configure() {
}
FileAccessNetwork::FileAccessNetwork() {
-
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->lock_mutex();
id = nc->last_id++;
@@ -517,7 +487,6 @@ FileAccessNetwork::FileAccessNetwork() {
}
FileAccessNetwork::~FileAccessNetwork() {
-
close();
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h
index 6cdd6af0b4..dc5ce1e883 100644
--- a/core/io/file_access_network.h
+++ b/core/io/file_access_network.h
@@ -39,9 +39,7 @@
class FileAccessNetwork;
class FileAccessNetworkClient {
-
struct BlockRequest {
-
int id;
uint64_t offset;
int size;
@@ -84,7 +82,6 @@ public:
};
class FileAccessNetwork : public FileAccess {
-
Semaphore sem;
Semaphore page_sem;
Mutex buffer_mutex;
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index d70f2ba445..00c4e76efe 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -35,11 +35,8 @@
#include <stdio.h>
Error PackedData::add_pack(const String &p_path, bool p_replace_files) {
-
for (int i = 0; i < sources.size(); i++) {
-
if (sources[i]->try_open_pack(p_path, p_replace_files)) {
-
return OK;
};
};
@@ -48,7 +45,6 @@ Error PackedData::add_pack(const String &p_path, bool p_replace_files) {
};
void PackedData::add_path(const String &pkg_path, const String &path, uint64_t ofs, uint64_t size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files) {
-
PathMD5 pmd5(path.md5_buffer());
//printf("adding path %ls, %lli, %lli\n", path.c_str(), pmd5.a, pmd5.b);
@@ -58,12 +54,14 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
pf.pack = pkg_path;
pf.offset = ofs;
pf.size = size;
- for (int i = 0; i < 16; i++)
+ for (int i = 0; i < 16; i++) {
pf.md5[i] = p_md5[i];
+ }
pf.src = p_src;
- if (!exists || p_replace_files)
+ if (!exists || p_replace_files) {
files[pmd5] = pf;
+ }
if (!exists) {
//search for dir
@@ -75,9 +73,7 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
Vector<String> ds = p.get_base_dir().split("/");
for (int j = 0; j < ds.size(); j++) {
-
if (!cd->subdirs.has(ds[j])) {
-
PackedDir *pd = memnew(PackedDir);
pd->name = ds[j];
pd->parent = cd;
@@ -97,7 +93,6 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
}
void PackedData::add_pack_source(PackSource *p_source) {
-
if (p_source != nullptr) {
sources.push_back(p_source);
}
@@ -106,7 +101,6 @@ void PackedData::add_pack_source(PackSource *p_source) {
PackedData *PackedData::singleton = nullptr;
PackedData::PackedData() {
-
singleton = this;
root = memnew(PackedDir);
@@ -114,14 +108,13 @@ PackedData::PackedData() {
}
void PackedData::_free_packed_dirs(PackedDir *p_dir) {
-
- for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next())
+ for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next()) {
_free_packed_dirs(E->get());
+ }
memdelete(p_dir);
}
PackedData::~PackedData() {
-
for (int i = 0; i < sources.size(); i++) {
memdelete(sources[i]);
}
@@ -131,10 +124,10 @@ PackedData::~PackedData() {
//////////////////////////////////////////////////////////////////
bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) {
-
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
- if (!f)
+ if (!f) {
return false;
+ }
uint32_t magic = f->get_32();
@@ -144,7 +137,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files)
f->seek(f->get_position() - 4);
magic = f->get_32();
if (magic != PACK_HEADER_MAGIC) {
-
f->close();
memdelete(f);
return false;
@@ -156,7 +148,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files)
magic = f->get_32();
if (magic != PACK_HEADER_MAGIC) {
-
f->close();
memdelete(f);
return false;
@@ -187,7 +178,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files)
int file_count = f->get_32();
for (int i = 0; i < file_count; i++) {
-
uint32_t sl = f->get_32();
CharString cs;
cs.resize(sl + 1);
@@ -210,30 +200,25 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files)
};
FileAccess *PackedSourcePCK::get_file(const String &p_path, PackedData::PackedFile *p_file) {
-
return memnew(FileAccessPack(p_path, *p_file));
};
//////////////////////////////////////////////////////////////////
Error FileAccessPack::_open(const String &p_path, int p_mode_flags) {
-
ERR_FAIL_V(ERR_UNAVAILABLE);
return ERR_UNAVAILABLE;
}
void FileAccessPack::close() {
-
f->close();
}
bool FileAccessPack::is_open() const {
-
return f->is_open();
}
void FileAccessPack::seek(size_t p_position) {
-
if (p_position > pf.size) {
eof = true;
} else {
@@ -243,26 +228,24 @@ void FileAccessPack::seek(size_t p_position) {
f->seek(pf.offset + p_position);
pos = p_position;
}
-void FileAccessPack::seek_end(int64_t p_position) {
+void FileAccessPack::seek_end(int64_t p_position) {
seek(pf.size + p_position);
}
-size_t FileAccessPack::get_position() const {
+size_t FileAccessPack::get_position() const {
return pos;
}
-size_t FileAccessPack::get_len() const {
+size_t FileAccessPack::get_len() const {
return pf.size;
}
bool FileAccessPack::eof_reached() const {
-
return eof;
}
uint8_t FileAccessPack::get_8() const {
-
if (pos >= pf.size) {
eof = true;
return 0;
@@ -273,9 +256,9 @@ uint8_t FileAccessPack::get_8() const {
}
int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const {
-
- if (eof)
+ if (eof) {
return 0;
+ }
uint64_t to_read = p_length;
if (to_read + pos > pf.size) {
@@ -285,8 +268,9 @@ int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const {
pos += p_length;
- if (to_read <= 0)
+ if (to_read <= 0) {
return 0;
+ }
f->get_buffer(p_dst, to_read);
return to_read;
@@ -298,36 +282,31 @@ void FileAccessPack::set_endian_swap(bool p_swap) {
}
Error FileAccessPack::get_error() const {
-
- if (eof)
+ if (eof) {
return ERR_FILE_EOF;
+ }
return OK;
}
void FileAccessPack::flush() {
-
ERR_FAIL();
}
void FileAccessPack::store_8(uint8_t p_dest) {
-
ERR_FAIL();
}
void FileAccessPack::store_buffer(const uint8_t *p_src, int p_length) {
-
ERR_FAIL();
}
bool FileAccessPack::file_exists(const String &p_name) {
-
return false;
}
FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file) :
pf(p_file),
f(FileAccess::open(pf.pack, FileAccess::READ)) {
-
ERR_FAIL_COND_MSG(!f, "Can't open pack-referenced file '" + String(pf.pack) + "'.");
f->seek(pf.offset);
@@ -336,8 +315,9 @@ FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFil
}
FileAccessPack::~FileAccessPack() {
- if (f)
+ if (f) {
memdelete(f);
+ }
}
//////////////////////////////////////////////////////////////////////////////////
@@ -345,17 +325,14 @@ FileAccessPack::~FileAccessPack() {
//////////////////////////////////////////////////////////////////////////////////
Error DirAccessPack::list_dir_begin() {
-
list_dirs.clear();
list_files.clear();
for (Map<String, PackedData::PackedDir *>::Element *E = current->subdirs.front(); E; E = E->next()) {
-
list_dirs.push_back(E->key());
}
for (Set<String>::Element *E = current->files.front(); E; E = E->next()) {
-
list_files.push_back(E->get());
}
@@ -363,7 +340,6 @@ Error DirAccessPack::list_dir_begin() {
}
String DirAccessPack::get_next() {
-
if (list_dirs.size()) {
cdir = true;
String d = list_dirs.front()->get();
@@ -378,31 +354,29 @@ String DirAccessPack::get_next() {
return String();
}
}
-bool DirAccessPack::current_is_dir() const {
+bool DirAccessPack::current_is_dir() const {
return cdir;
}
-bool DirAccessPack::current_is_hidden() const {
+bool DirAccessPack::current_is_hidden() const {
return false;
}
-void DirAccessPack::list_dir_end() {
+void DirAccessPack::list_dir_end() {
list_dirs.clear();
list_files.clear();
}
int DirAccessPack::get_drive_count() {
-
return 0;
}
-String DirAccessPack::get_drive(int p_drive) {
+String DirAccessPack::get_drive(int p_drive) {
return "";
}
Error DirAccessPack::change_dir(String p_dir) {
-
String nd = p_dir.replace("\\", "/");
bool absolute = false;
if (nd.begins_with("res://")) {
@@ -412,8 +386,9 @@ Error DirAccessPack::change_dir(String p_dir) {
nd = nd.simplify_path();
- if (nd == "")
+ if (nd == "") {
nd = ".";
+ }
if (nd.begins_with("/")) {
nd = nd.replace_first("/", "");
@@ -424,13 +399,13 @@ Error DirAccessPack::change_dir(String p_dir) {
PackedData::PackedDir *pd;
- if (absolute)
+ if (absolute) {
pd = PackedData::get_singleton()->root;
- else
+ } else {
pd = current;
+ }
for (int i = 0; i < paths.size(); i++) {
-
String p = paths[i];
if (p == ".") {
continue;
@@ -439,11 +414,9 @@ Error DirAccessPack::change_dir(String p_dir) {
pd = pd->parent;
}
} else if (pd->subdirs.has(p)) {
-
pd = pd->subdirs[p];
} else {
-
return ERR_INVALID_PARAMETER;
}
}
@@ -454,7 +427,6 @@ Error DirAccessPack::change_dir(String p_dir) {
}
String DirAccessPack::get_current_dir(bool p_include_drive) {
-
PackedData::PackedDir *pd = current;
String p = current->name;
@@ -467,35 +439,30 @@ String DirAccessPack::get_current_dir(bool p_include_drive) {
}
bool DirAccessPack::file_exists(String p_file) {
-
p_file = fix_path(p_file);
return current->files.has(p_file);
}
bool DirAccessPack::dir_exists(String p_dir) {
-
p_dir = fix_path(p_dir);
return current->subdirs.has(p_dir);
}
Error DirAccessPack::make_dir(String p_dir) {
-
return ERR_UNAVAILABLE;
}
Error DirAccessPack::rename(String p_from, String p_to) {
-
return ERR_UNAVAILABLE;
}
-Error DirAccessPack::remove(String p_name) {
+Error DirAccessPack::remove(String p_name) {
return ERR_UNAVAILABLE;
}
size_t DirAccessPack::get_space_left() {
-
return 0;
}
diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h
index aa3a14272b..320a6cb216 100644
--- a/core/io/file_access_pack.h
+++ b/core/io/file_access_pack.h
@@ -51,7 +51,6 @@ class PackedData {
public:
struct PackedFile {
-
String pack;
uint64_t offset; //if offset is ZERO, the file was ERASED
uint64_t size;
@@ -71,7 +70,6 @@ private:
uint64_t a = 0;
uint64_t b = 0;
bool operator<(const PathMD5 &p_md5) const {
-
if (p_md5.a == a) {
return b < p_md5.b;
} else {
@@ -120,7 +118,6 @@ public:
};
class PackSource {
-
public:
virtual bool try_open_pack(const String &p_path, bool p_replace_files) = 0;
virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file) = 0;
@@ -128,14 +125,12 @@ public:
};
class PackedSourcePCK : public PackSource {
-
public:
virtual bool try_open_pack(const String &p_path, bool p_replace_files);
virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file);
};
class FileAccessPack : public FileAccess {
-
PackedData::PackedFile pf;
mutable size_t pos;
@@ -178,24 +173,23 @@ public:
};
FileAccess *PackedData::try_open_path(const String &p_path) {
-
PathMD5 pmd5(p_path.md5_buffer());
Map<PathMD5, PackedFile>::Element *E = files.find(pmd5);
- if (!E)
+ if (!E) {
return nullptr; //not found
- if (E->get().offset == 0)
+ }
+ if (E->get().offset == 0) {
return nullptr; //was erased
+ }
return E->get().src->get_file(p_path, &E->get());
}
bool PackedData::has_path(const String &p_path) {
-
return files.has(PathMD5(p_path.md5_buffer()));
}
class DirAccessPack : public DirAccess {
-
PackedData::PackedDir *current;
List<String> list_dirs;
diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp
index 9d068fe809..c3a62706c7 100644
--- a/core/io/file_access_zip.cpp
+++ b/core/io/file_access_zip.cpp
@@ -40,7 +40,6 @@ ZipArchive *ZipArchive::instance = nullptr;
extern "C" {
static void *godot_open(void *data, const char *p_fname, int mode) {
-
if (mode & ZLIB_FILEFUNC_MODE_WRITE) {
return nullptr;
}
@@ -52,30 +51,25 @@ static void *godot_open(void *data, const char *p_fname, int mode) {
}
static uLong godot_read(void *data, void *fdata, void *buf, uLong size) {
-
FileAccess *f = (FileAccess *)data;
f->get_buffer((uint8_t *)buf, size);
return size;
}
static uLong godot_write(voidpf opaque, voidpf stream, const void *buf, uLong size) {
-
return 0;
}
static long godot_tell(voidpf opaque, voidpf stream) {
-
FileAccess *f = (FileAccess *)opaque;
return f->get_position();
}
static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
-
FileAccess *f = (FileAccess *)opaque;
int pos = offset;
switch (origin) {
-
case ZLIB_FILEFUNC_SEEK_CUR:
pos = f->get_position() + offset;
break;
@@ -91,32 +85,27 @@ static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
}
static int godot_close(voidpf opaque, voidpf stream) {
-
FileAccess *f = (FileAccess *)opaque;
f->close();
return 0;
}
static int godot_testerror(voidpf opaque, voidpf stream) {
-
FileAccess *f = (FileAccess *)opaque;
return f->get_error() != OK ? 1 : 0;
}
static voidpf godot_alloc(voidpf opaque, uInt items, uInt size) {
-
return memalloc(items * size);
}
static void godot_free(voidpf opaque, voidpf address) {
-
memfree(address);
}
} // extern "C"
void ZipArchive::close_handle(unzFile p_file) const {
-
ERR_FAIL_COND_MSG(!p_file, "Cannot close a file if none is open.");
FileAccess *f = (FileAccess *)unzGetOpaque(p_file);
unzCloseCurrentFile(p_file);
@@ -125,7 +114,6 @@ void ZipArchive::close_handle(unzFile p_file) const {
}
unzFile ZipArchive::get_file_handle(String p_file) const {
-
ERR_FAIL_COND_V_MSG(!file_exists(p_file), nullptr, "File '" + p_file + " doesn't exist.");
File file = files[p_file];
@@ -152,7 +140,6 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
ERR_FAIL_COND_V(!pkg, nullptr);
int unz_err = unzGoToFilePos(pkg, &file.file_pos);
if (unz_err != UNZ_OK || unzOpenCurrentFile(pkg) != UNZ_OK) {
-
unzClose(pkg);
ERR_FAIL_V(nullptr);
}
@@ -161,16 +148,17 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
}
bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) {
-
//printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
- if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0)
+ if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0) {
return false;
+ }
zlib_filefunc_def io;
FileAccess *fa = FileAccess::open(p_path, FileAccess::READ);
- if (!fa)
+ if (!fa) {
return false;
+ }
io.opaque = fa;
io.zopen_file = godot_open;
io.zread_file = godot_read;
@@ -195,7 +183,6 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) {
int pkg_num = packages.size() - 1;
for (uint64_t i = 0; i < gi.number_entry; i++) {
-
char filename_inzip[256];
unz_file_info64 file_info;
@@ -222,17 +209,14 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) {
}
bool ZipArchive::file_exists(String p_name) const {
-
return files.has(p_name);
}
FileAccess *ZipArchive::get_file(const String &p_path, PackedData::PackedFile *p_file) {
-
return memnew(FileAccessZip(p_path, *p_file));
}
ZipArchive *ZipArchive::get_singleton() {
-
if (instance == nullptr) {
instance = memnew(ZipArchive);
}
@@ -245,9 +229,7 @@ ZipArchive::ZipArchive() {
}
ZipArchive::~ZipArchive() {
-
for (int i = 0; i < packages.size(); i++) {
-
FileAccess *f = (FileAccess *)unzGetOpaque(packages[i].zfile);
unzClose(packages[i].zfile);
memdelete(f);
@@ -257,7 +239,6 @@ ZipArchive::~ZipArchive() {
}
Error FileAccessZip::_open(const String &p_path, int p_mode_flags) {
-
close();
ERR_FAIL_COND_V(p_mode_flags & FileAccess::WRITE, FAILED);
@@ -273,9 +254,9 @@ Error FileAccessZip::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessZip::close() {
-
- if (!zfile)
+ if (!zfile) {
return;
+ }
ZipArchive *arch = ZipArchive::get_singleton();
ERR_FAIL_COND(!arch);
@@ -284,65 +265,57 @@ void FileAccessZip::close() {
}
bool FileAccessZip::is_open() const {
-
return zfile != nullptr;
}
void FileAccessZip::seek(size_t p_position) {
-
ERR_FAIL_COND(!zfile);
unzSeekCurrentFile(zfile, p_position);
}
void FileAccessZip::seek_end(int64_t p_position) {
-
ERR_FAIL_COND(!zfile);
unzSeekCurrentFile(zfile, get_len() + p_position);
}
size_t FileAccessZip::get_position() const {
-
ERR_FAIL_COND_V(!zfile, 0);
return unztell(zfile);
}
size_t FileAccessZip::get_len() const {
-
ERR_FAIL_COND_V(!zfile, 0);
return file_info.uncompressed_size;
}
bool FileAccessZip::eof_reached() const {
-
ERR_FAIL_COND_V(!zfile, true);
return at_eof;
}
uint8_t FileAccessZip::get_8() const {
-
uint8_t ret = 0;
get_buffer(&ret, 1);
return ret;
}
int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const {
-
ERR_FAIL_COND_V(!zfile, -1);
at_eof = unzeof(zfile);
- if (at_eof)
+ if (at_eof) {
return 0;
+ }
int read = unzReadCurrentFile(zfile, p_dst, p_length);
ERR_FAIL_COND_V(read < 0, read);
- if (read < p_length)
+ if (read < p_length) {
at_eof = true;
+ }
return read;
}
Error FileAccessZip::get_error() const {
-
if (!zfile) {
-
return ERR_UNCONFIGURED;
}
if (eof_reached()) {
@@ -353,17 +326,14 @@ Error FileAccessZip::get_error() const {
}
void FileAccessZip::flush() {
-
ERR_FAIL();
}
void FileAccessZip::store_8(uint8_t p_dest) {
-
ERR_FAIL();
}
bool FileAccessZip::file_exists(const String &p_name) {
-
return false;
}
diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h
index 17a3d085b6..776e830f36 100644
--- a/core/io/file_access_zip.h
+++ b/core/io/file_access_zip.h
@@ -41,10 +41,8 @@
#include <stdlib.h>
class ZipArchive : public PackSource {
-
public:
struct File {
-
int package = -1;
unz_file_pos file_pos;
File() {}
@@ -81,7 +79,6 @@ public:
};
class FileAccessZip : public FileAccess {
-
unzFile zfile;
unz_file_info64 file_info;
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 940bac0009..40debae9e5 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -47,7 +47,6 @@ const char *HTTPClient::_methods[METHOD_MAX] = {
#ifndef JAVASCRIPT_ENABLED
Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) {
-
close();
conn_port = p_port;
@@ -58,10 +57,8 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl,
String host_lower = conn_host.to_lower();
if (host_lower.begins_with("http://")) {
-
conn_host = conn_host.substr(7, conn_host.length() - 7);
} else if (host_lower.begins_with("https://")) {
-
ssl = true;
conn_host = conn_host.substr(8, conn_host.length() - 8);
}
@@ -97,7 +94,6 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl,
}
void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) {
-
ERR_FAIL_COND_MSG(p_connection.is_null(), "Connection is not a reference to a valid StreamPeer object.");
close();
@@ -106,12 +102,10 @@ void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) {
}
Ref<StreamPeer> HTTPClient::get_connection() const {
-
return connection;
}
Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const Vector<uint8_t> &p_body) {
-
ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(!p_url.begins_with("/"), ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER);
@@ -179,7 +173,6 @@ Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector
}
Error HTTPClient::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body) {
-
ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(!p_url.begins_with("/"), ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER);
@@ -235,27 +228,23 @@ Error HTTPClient::request(Method p_method, const String &p_url, const Vector<Str
}
bool HTTPClient::has_response() const {
-
return response_headers.size() != 0;
}
bool HTTPClient::is_response_chunked() const {
-
return chunked;
}
int HTTPClient::get_response_code() const {
-
return response_num;
}
Error HTTPClient::get_response_headers(List<String> *r_response) {
-
- if (!response_headers.size())
+ if (!response_headers.size()) {
return ERR_INVALID_PARAMETER;
+ }
for (int i = 0; i < response_headers.size(); i++) {
-
r_response->push_back(response_headers[i]);
}
@@ -265,15 +254,14 @@ Error HTTPClient::get_response_headers(List<String> *r_response) {
}
void HTTPClient::close() {
-
- if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE)
+ if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE) {
tcp_connection->disconnect_from_host();
+ }
connection.unref();
status = STATUS_DISCONNECTED;
head_request = false;
if (resolving != IP::RESOLVER_INVALID_ID) {
-
IP::get_singleton()->erase_resolve_item(resolving);
resolving = IP::RESOLVER_INVALID_ID;
}
@@ -290,9 +278,7 @@ void HTTPClient::close() {
}
Error HTTPClient::poll() {
-
switch (status) {
-
case STATUS_RESOLVING: {
ERR_FAIL_COND_V(resolving == IP::RESOLVER_INVALID_ID, ERR_BUG);
@@ -302,7 +288,6 @@ Error HTTPClient::poll() {
return OK; // Still resolving
case IP::RESOLVER_STATUS_DONE: {
-
IP_Address host = IP::get_singleton()->get_resolve_item_address(resolving);
Error err = tcp_connection->connect_to_host(host, conn_port);
IP::get_singleton()->erase_resolve_item(resolving);
@@ -316,7 +301,6 @@ Error HTTPClient::poll() {
} break;
case IP::RESOLVER_STATUS_NONE:
case IP::RESOLVER_STATUS_ERROR: {
-
IP::get_singleton()->erase_resolve_item(resolving);
resolving = IP::RESOLVER_INVALID_ID;
close();
@@ -326,10 +310,8 @@ Error HTTPClient::poll() {
}
} break;
case STATUS_CONNECTING: {
-
StreamPeerTCP::Status s = tcp_connection->get_status();
switch (s) {
-
case StreamPeerTCP::STATUS_CONNECTING: {
return OK;
} break;
@@ -379,7 +361,6 @@ Error HTTPClient::poll() {
} break;
case StreamPeerTCP::STATUS_ERROR:
case StreamPeerTCP::STATUS_NONE: {
-
close();
status = STATUS_CANT_CONNECT;
return ERR_CANT_CONNECT;
@@ -404,7 +385,6 @@ Error HTTPClient::poll() {
return OK;
} break;
case STATUS_REQUESTING: {
-
while (true) {
uint8_t byte;
int rec = 0;
@@ -415,15 +395,15 @@ Error HTTPClient::poll() {
return ERR_CONNECTION_ERROR;
}
- if (rec == 0)
+ if (rec == 0) {
return OK; // Still requesting, keep trying!
+ }
response_str.push_back(byte);
int rs = response_str.size();
if (
(rs >= 2 && response_str[rs - 2] == '\n' && response_str[rs - 1] == '\n') ||
(rs >= 4 && response_str[rs - 4] == '\r' && response_str[rs - 3] == '\n' && response_str[rs - 2] == '\r' && response_str[rs - 1] == '\n')) {
-
// End of response, parse.
response_str.push_back(0);
String response;
@@ -445,11 +425,11 @@ Error HTTPClient::poll() {
bool keep_alive = true;
for (int i = 0; i < responses.size(); i++) {
-
String header = responses[i].strip_edges();
String s = header.to_lower();
- if (s.length() == 0)
+ if (s.length() == 0) {
continue;
+ }
if (s.begins_with("content-length:")) {
body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int();
body_left = body_size;
@@ -464,11 +444,9 @@ Error HTTPClient::poll() {
}
if (i == 0 && responses[i].begins_with("HTTP")) {
-
String num = responses[i].get_slicec(' ', 1);
response_num = num.to_int();
} else {
-
response_headers.push_back(header);
}
}
@@ -480,14 +458,11 @@ Error HTTPClient::poll() {
}
if (body_size != -1 || chunked) {
-
status = STATUS_BODY;
} else if (!keep_alive) {
-
read_until_eof = true;
status = STATUS_BODY;
} else {
-
status = STATUS_CONNECTED;
}
return OK;
@@ -513,29 +488,26 @@ Error HTTPClient::poll() {
}
int HTTPClient::get_response_body_length() const {
-
return body_size;
}
PackedByteArray HTTPClient::read_response_body_chunk() {
-
ERR_FAIL_COND_V(status != STATUS_BODY, PackedByteArray());
PackedByteArray ret;
Error err = OK;
if (chunked) {
-
while (true) {
-
if (chunk_trailer_part) {
// We need to consume the trailer part too or keep-alive will break
uint8_t b;
int rec = 0;
err = _get_http_data(&b, 1, rec);
- if (rec == 0)
+ if (rec == 0) {
break;
+ }
chunk.push_back(b);
int cs = chunk.size();
@@ -557,8 +529,9 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
int rec = 0;
err = _get_http_data(&b, 1, rec);
- if (rec == 0)
+ if (rec == 0) {
break;
+ }
chunk.push_back(b);
@@ -569,18 +542,17 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
}
if (chunk.size() > 2 && chunk[chunk.size() - 2] == '\r' && chunk[chunk.size() - 1] == '\n') {
-
int len = 0;
for (int i = 0; i < chunk.size() - 2; i++) {
char c = chunk[i];
int v = 0;
- if (c >= '0' && c <= '9')
+ if (c >= '0' && c <= '9') {
v = c - '0';
- else if (c >= 'a' && c <= 'f')
+ } else if (c >= 'a' && c <= 'f') {
v = c - 'a' + 10;
- else if (c >= 'A' && c <= 'F')
+ } else if (c >= 'A' && c <= 'F') {
v = c - 'A' + 10;
- else {
+ } else {
ERR_PRINT("HTTP Chunk len not in hex!!");
status = STATUS_CONNECTION_ERROR;
break;
@@ -605,7 +577,6 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
chunk.resize(chunk_left);
}
} else {
-
int rec = 0;
err = _get_http_data(&chunk.write[chunk.size() - chunk_left], chunk_left, rec);
if (rec == 0) {
@@ -614,7 +585,6 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
chunk_left -= rec;
if (chunk_left == 0) {
-
if (chunk[chunk.size() - 2] != '\r' || chunk[chunk.size() - 1] != '\n') {
ERR_PRINT("HTTP Invalid chunk terminator (not \\r\\n)");
status = STATUS_CONNECTION_ERROR;
@@ -632,7 +602,6 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
}
} else {
-
int to_read = !read_until_eof ? MIN(body_left, read_chunk_size) : read_chunk_size;
ret.resize(to_read);
int _offset = 0;
@@ -652,24 +621,21 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
body_left -= rec;
}
}
- if (err != OK)
+ if (err != OK) {
break;
+ }
}
}
if (err != OK) {
-
close();
if (err == ERR_FILE_EOF) {
-
status = STATUS_DISCONNECTED; // Server disconnected
} else {
-
status = STATUS_CONNECTION_ERROR;
}
} else if (body_left == 0 && !chunked && !read_until_eof) {
-
status = STATUS_CONNECTED;
}
@@ -677,24 +643,19 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
}
HTTPClient::Status HTTPClient::get_status() const {
-
return status;
}
void HTTPClient::set_blocking_mode(bool p_enable) {
-
blocking = p_enable;
}
bool HTTPClient::is_blocking_mode_enabled() const {
-
return blocking;
}
Error HTTPClient::_get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
-
if (blocking) {
-
// We can't use StreamPeer.get_data, since when reaching EOF we will get an
// error without knowing how many bytes we received.
Error err = ERR_FILE_EOF;
@@ -767,15 +728,15 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) {
}
Dictionary HTTPClient::_get_response_headers_as_dictionary() {
-
List<String> rh;
get_response_headers(&rh);
Dictionary ret;
for (const List<String>::Element *E = rh.front(); E; E = E->next()) {
const String &s = E->get();
int sp = s.find(":");
- if (sp == -1)
+ if (sp == -1) {
continue;
+ }
String key = s.substr(0, sp).strip_edges();
String value = s.substr(sp + 1, s.length()).strip_edges();
ret[key] = value;
@@ -785,7 +746,6 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() {
}
PackedStringArray HTTPClient::_get_response_headers() {
-
List<String> rh;
get_response_headers(&rh);
PackedStringArray ret;
@@ -799,7 +759,6 @@ PackedStringArray HTTPClient::_get_response_headers() {
}
void HTTPClient::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port", "use_ssl", "verify_host"), &HTTPClient::connect_to_host, DEFVAL(-1), DEFVAL(false), DEFVAL(true));
ClassDB::bind_method(D_METHOD("set_connection", "connection"), &HTTPClient::set_connection);
ClassDB::bind_method(D_METHOD("get_connection"), &HTTPClient::get_connection);
diff --git a/core/io/http_client.h b/core/io/http_client.h
index 05690534ae..1dc1f3d76a 100644
--- a/core/io/http_client.h
+++ b/core/io/http_client.h
@@ -37,7 +37,6 @@
#include "core/reference.h"
class HTTPClient : public Reference {
-
GDCLASS(HTTPClient, Reference);
public:
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index 01e6bb5618..b1e92eb87f 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -33,13 +33,12 @@
#include "core/print_string.h"
bool ImageFormatLoader::recognize(const String &p_extension) const {
-
List<String> extensions;
get_recognized_extensions(&extensions);
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
-
- if (E->get().nocasecmp_to(p_extension) == 0)
+ if (E->get().nocasecmp_to(p_extension) == 0) {
return true;
+ }
}
return false;
@@ -61,43 +60,41 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c
String extension = p_file.get_extension();
for (int i = 0; i < loader.size(); i++) {
-
- if (!loader[i]->recognize(extension))
+ if (!loader[i]->recognize(extension)) {
continue;
+ }
Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale);
if (err != OK) {
ERR_PRINT("Error loading image: " + p_file);
}
if (err != ERR_FILE_UNRECOGNIZED) {
-
- if (!p_custom)
+ if (!p_custom) {
memdelete(f);
+ }
return err;
}
}
- if (!p_custom)
+ if (!p_custom) {
memdelete(f);
+ }
return ERR_FILE_UNRECOGNIZED;
}
void ImageLoader::get_recognized_extensions(List<String> *p_extensions) {
-
for (int i = 0; i < loader.size(); i++) {
-
loader[i]->get_recognized_extensions(p_extensions);
}
}
ImageFormatLoader *ImageLoader::recognize(const String &p_extension) {
-
for (int i = 0; i < loader.size(); i++) {
-
- if (loader[i]->recognize(p_extension))
+ if (loader[i]->recognize(p_extension)) {
return loader[i];
+ }
}
return nullptr;
@@ -106,22 +103,18 @@ ImageFormatLoader *ImageLoader::recognize(const String &p_extension) {
Vector<ImageFormatLoader *> ImageLoader::loader;
void ImageLoader::add_image_format_loader(ImageFormatLoader *p_loader) {
-
loader.push_back(p_loader);
}
void ImageLoader::remove_image_format_loader(ImageFormatLoader *p_loader) {
-
loader.erase(p_loader);
}
const Vector<ImageFormatLoader *> &ImageLoader::get_image_format_loaders() {
-
return loader;
}
void ImageLoader::cleanup() {
-
while (loader.size()) {
remove_image_format_loader(loader[0]);
}
@@ -130,7 +123,6 @@ void ImageLoader::cleanup() {
/////////////////
RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
-
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
if (r_error) {
@@ -192,16 +184,13 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_origin
}
void ResourceFormatLoaderImage::get_recognized_extensions(List<String> *p_extensions) const {
-
p_extensions->push_back("image");
}
bool ResourceFormatLoaderImage::handles_type(const String &p_type) const {
-
return p_type == "Image";
}
String ResourceFormatLoaderImage::get_resource_type(const String &p_path) const {
-
return p_path.get_extension().to_lower() == "image" ? "Image" : String();
}
diff --git a/core/io/image_loader.h b/core/io/image_loader.h
index 15ce6031d7..9682f144c7 100644
--- a/core/io/image_loader.h
+++ b/core/io/image_loader.h
@@ -53,7 +53,6 @@ public:
};
class ImageLoader {
-
static Vector<ImageFormatLoader *> loader;
friend class ResourceFormatLoaderImage;
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index 5de7fb7186..653959b393 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -39,9 +39,7 @@ VARIANT_ENUM_CAST(IP::ResolverStatus);
/************* RESOLVER ******************/
struct _IP_ResolverPrivate {
-
struct QueueItem {
-
volatile IP::ResolverStatus status;
IP_Address response;
String hostname;
@@ -62,10 +60,10 @@ struct _IP_ResolverPrivate {
QueueItem queue[IP::RESOLVER_MAX_QUERIES];
IP::ResolverID find_empty_id() const {
-
for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) {
- if (queue[i].status == IP::RESOLVER_STATUS_NONE)
+ if (queue[i].status == IP::RESOLVER_STATUS_NONE) {
return i;
+ }
}
return IP::RESOLVER_INVALID_ID;
}
@@ -78,26 +76,24 @@ struct _IP_ResolverPrivate {
bool thread_abort;
void resolve_queues() {
-
for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) {
-
- if (queue[i].status != IP::RESOLVER_STATUS_WAITING)
+ if (queue[i].status != IP::RESOLVER_STATUS_WAITING) {
continue;
+ }
queue[i].response = IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type);
- if (!queue[i].response.is_valid())
+ if (!queue[i].response.is_valid()) {
queue[i].status = IP::RESOLVER_STATUS_ERROR;
- else
+ } else {
queue[i].status = IP::RESOLVER_STATUS_DONE;
+ }
}
}
static void _thread_function(void *self) {
-
_IP_ResolverPrivate *ipr = (_IP_ResolverPrivate *)self;
while (!ipr->thread_abort) {
-
ipr->sem.wait();
MutexLock lock(ipr->mutex);
@@ -113,7 +109,6 @@ struct _IP_ResolverPrivate {
};
IP_Address IP::resolve_hostname(const String &p_hostname, IP::Type p_type) {
-
MutexLock lock(resolver->mutex);
String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type);
@@ -128,7 +123,6 @@ IP_Address IP::resolve_hostname(const String &p_hostname, IP::Type p_type) {
}
IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Type p_type) {
-
MutexLock lock(resolver->mutex);
ResolverID id = resolver->find_empty_id();
@@ -147,17 +141,17 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ
} else {
resolver->queue[id].response = IP_Address();
resolver->queue[id].status = IP::RESOLVER_STATUS_WAITING;
- if (resolver->thread)
+ if (resolver->thread) {
resolver->sem.post();
- else
+ } else {
resolver->resolve_queues();
+ }
}
return id;
}
IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const {
-
ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP::RESOLVER_STATUS_NONE);
MutexLock lock(resolver->mutex);
@@ -171,7 +165,6 @@ IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const {
}
IP_Address IP::get_resolve_item_address(ResolverID p_id) const {
-
ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP_Address());
MutexLock lock(resolver->mutex);
@@ -186,7 +179,6 @@ IP_Address IP::get_resolve_item_address(ResolverID p_id) const {
}
void IP::erase_resolve_item(ResolverID p_id) {
-
ERR_FAIL_INDEX(p_id, IP::RESOLVER_MAX_QUERIES);
MutexLock lock(resolver->mutex);
@@ -195,7 +187,6 @@ void IP::erase_resolve_item(ResolverID p_id) {
}
void IP::clear_cache(const String &p_hostname) {
-
MutexLock lock(resolver->mutex);
if (p_hostname.empty()) {
@@ -209,7 +200,6 @@ void IP::clear_cache(const String &p_hostname) {
}
Array IP::_get_local_addresses() const {
-
Array addresses;
List<IP_Address> ip_addresses;
get_local_addresses(&ip_addresses);
@@ -221,7 +211,6 @@ Array IP::_get_local_addresses() const {
}
Array IP::_get_local_interfaces() const {
-
Array results;
Map<String, Interface_Info> interfaces;
get_local_interfaces(&interfaces);
@@ -245,7 +234,6 @@ Array IP::_get_local_interfaces() const {
}
void IP::get_local_addresses(List<IP_Address> *r_addresses) const {
-
Map<String, Interface_Info> interfaces;
get_local_interfaces(&interfaces);
for (Map<String, Interface_Info>::Element *E = interfaces.front(); E; E = E->next()) {
@@ -256,7 +244,6 @@ void IP::get_local_addresses(List<IP_Address> *r_addresses) const {
}
void IP::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("resolve_hostname", "host", "ip_type"), &IP::resolve_hostname, DEFVAL(IP::TYPE_ANY));
ClassDB::bind_method(D_METHOD("resolve_hostname_queue_item", "host", "ip_type"), &IP::resolve_hostname_queue_item, DEFVAL(IP::TYPE_ANY));
ClassDB::bind_method(D_METHOD("get_resolve_item_status", "id"), &IP::get_resolve_item_status);
@@ -283,21 +270,18 @@ void IP::_bind_methods() {
IP *IP::singleton = nullptr;
IP *IP::get_singleton() {
-
return singleton;
}
IP *(*IP::_create)() = nullptr;
IP *IP::create() {
-
ERR_FAIL_COND_V_MSG(singleton, nullptr, "IP singleton already exist.");
ERR_FAIL_COND_V(!_create, nullptr);
return _create();
}
IP::IP() {
-
singleton = this;
resolver = memnew(_IP_ResolverPrivate);
@@ -312,7 +296,6 @@ IP::IP() {
}
IP::~IP() {
-
#ifndef NO_THREADS
if (resolver->thread) {
resolver->thread_abort = true;
diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp
index f5fd8ae205..89b317bf93 100644
--- a/core/io/ip_address.cpp
+++ b/core/io/ip_address.cpp
@@ -39,20 +39,23 @@ IP_Address::operator Variant() const {
#include <string.h>
IP_Address::operator String() const {
-
- if (wildcard)
+ if (wildcard) {
return "*";
+ }
- if (!valid)
+ if (!valid) {
return "";
+ }
- if (is_ipv4())
+ if (is_ipv4()) {
// IPv4 address mapped to IPv6
return itos(field8[12]) + "." + itos(field8[13]) + "." + itos(field8[14]) + "." + itos(field8[15]);
+ }
String ret;
for (int i = 0; i < 8; i++) {
- if (i > 0)
+ if (i > 0) {
ret = ret + ":";
+ }
uint16_t num = (field8[i * 2] << 8) + field8[i * 2 + 1];
ret = ret + String::num_int64(num, 16);
};
@@ -61,10 +64,8 @@ IP_Address::operator String() const {
}
static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) {
-
uint16_t ret = 0;
for (int i = p_start; i < p_start + 4; i++) {
-
if (i >= p_string.length()) {
break;
};
@@ -72,7 +73,6 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) {
int n = 0;
CharType c = p_string[i];
if (c >= '0' && c <= '9') {
-
n = c - '0';
} else if (c >= 'a' && c <= 'f') {
n = 10 + (c - 'a');
@@ -92,7 +92,6 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) {
};
void IP_Address::_parse_ipv6(const String &p_string) {
-
static const int parts_total = 8;
int parts[parts_total] = { 0 };
int parts_count = 0;
@@ -102,10 +101,8 @@ void IP_Address::_parse_ipv6(const String &p_string) {
int parts_idx = 0;
for (int i = 0; i < p_string.length(); i++) {
-
CharType c = p_string[i];
if (c == ':') {
-
if (i == 0) {
continue; // next must be a ":"
};
@@ -115,7 +112,6 @@ void IP_Address::_parse_ipv6(const String &p_string) {
};
part_found = false;
} else if (c == '.') {
-
part_ipv4 = true;
} else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
@@ -136,9 +132,7 @@ void IP_Address::_parse_ipv6(const String &p_string) {
int idx = 0;
for (int i = 0; i < parts_idx; i++) {
-
if (parts[i] == -1) {
-
for (int j = 0; j < parts_extra; j++) {
field16[idx++] = 0;
};
@@ -154,7 +148,6 @@ void IP_Address::_parse_ipv6(const String &p_string) {
};
void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) {
-
String ip;
if (p_start != 0) {
ip = p_string.substr(p_start, p_string.length() - p_start);
@@ -170,7 +163,6 @@ void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret
};
void IP_Address::clear() {
-
memset(&field8[0], 0, sizeof(field8));
valid = false;
wildcard = false;
@@ -199,12 +191,12 @@ const uint8_t *IP_Address::get_ipv6() const {
void IP_Address::set_ipv6(const uint8_t *p_buf) {
clear();
valid = true;
- for (int i = 0; i < 16; i++)
+ for (int i = 0; i < 16; i++) {
field8[i] = p_buf[i];
+ }
}
IP_Address::IP_Address(const String &p_string) {
-
clear();
if (p_string == "*") {
@@ -228,7 +220,6 @@ IP_Address::IP_Address(const String &p_string) {
}
_FORCE_INLINE_ static void _32_to_buf(uint8_t *p_dst, uint32_t p_n) {
-
p_dst[0] = (p_n >> 24) & 0xff;
p_dst[1] = (p_n >> 16) & 0xff;
p_dst[2] = (p_n >> 8) & 0xff;
@@ -236,7 +227,6 @@ _FORCE_INLINE_ static void _32_to_buf(uint8_t *p_dst, uint32_t p_n) {
};
IP_Address::IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6) {
-
clear();
valid = true;
if (!is_v6) {
@@ -247,7 +237,6 @@ IP_Address::IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, b
field8[14] = p_c;
field8[15] = p_d;
} else {
-
_32_to_buf(&field8[0], p_a);
_32_to_buf(&field8[4], p_b);
_32_to_buf(&field8[8], p_c);
diff --git a/core/io/ip_address.h b/core/io/ip_address.h
index a59178063d..2f8f83503e 100644
--- a/core/io/ip_address.h
+++ b/core/io/ip_address.h
@@ -34,7 +34,6 @@
#include "core/ustring.h"
struct IP_Address {
-
private:
union {
uint8_t field8[16];
@@ -52,23 +51,32 @@ protected:
public:
//operator Variant() const;
bool operator==(const IP_Address &p_ip) const {
- if (p_ip.valid != valid)
+ if (p_ip.valid != valid) {
return false;
- if (!valid)
+ }
+ if (!valid) {
return false;
- for (int i = 0; i < 4; i++)
- if (field32[i] != p_ip.field32[i])
+ }
+ for (int i = 0; i < 4; i++) {
+ if (field32[i] != p_ip.field32[i]) {
return false;
+ }
+ }
return true;
}
+
bool operator!=(const IP_Address &p_ip) const {
- if (p_ip.valid != valid)
+ if (p_ip.valid != valid) {
return true;
- if (!valid)
+ }
+ if (!valid) {
return true;
- for (int i = 0; i < 4; i++)
- if (field32[i] != p_ip.field32[i])
+ }
+ for (int i = 0; i < 4; i++) {
+ if (field32[i] != p_ip.field32[i]) {
return true;
+ }
+ }
return false;
}
diff --git a/core/io/json.cpp b/core/io/json.cpp
index 0186547dd2..03f4e65220 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -46,17 +46,16 @@ const char *JSON::tk_name[TK_MAX] = {
};
static String _make_indent(const String &p_indent, int p_size) {
-
String indent_text = "";
if (!p_indent.empty()) {
- for (int i = 0; i < p_size; i++)
+ for (int i = 0; i < p_size; i++) {
indent_text += p_indent;
+ }
}
return indent_text;
}
String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys) {
-
String colon = ":";
String end_statement = "";
@@ -66,7 +65,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
}
switch (p_var.get_type()) {
-
case Variant::NIL:
return "null";
case Variant::BOOL:
@@ -81,7 +79,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
case Variant::PACKED_FLOAT64_ARRAY:
case Variant::PACKED_STRING_ARRAY:
case Variant::ARRAY: {
-
String s = "[";
s += end_statement;
Array a = p_var;
@@ -96,18 +93,17 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
return s;
};
case Variant::DICTIONARY: {
-
String s = "{";
s += end_statement;
Dictionary d = p_var;
List<Variant> keys;
d.get_key_list(&keys);
- if (p_sort_keys)
+ if (p_sort_keys) {
keys.sort();
+ }
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
if (E != keys.front()) {
s += ",";
s += end_statement;
@@ -126,17 +122,13 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
}
String JSON::print(const Variant &p_var, const String &p_indent, bool p_sort_keys) {
-
return _print_var(p_var, p_indent, 0, p_sort_keys);
}
Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) {
-
while (p_len > 0) {
switch (p_str[index]) {
-
case '\n': {
-
line++;
index++;
break;
@@ -146,43 +138,36 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
return OK;
} break;
case '{': {
-
r_token.type = TK_CURLY_BRACKET_OPEN;
index++;
return OK;
};
case '}': {
-
r_token.type = TK_CURLY_BRACKET_CLOSE;
index++;
return OK;
};
case '[': {
-
r_token.type = TK_BRACKET_OPEN;
index++;
return OK;
};
case ']': {
-
r_token.type = TK_BRACKET_CLOSE;
index++;
return OK;
};
case ':': {
-
r_token.type = TK_COLON;
index++;
return OK;
};
case ',': {
-
r_token.type = TK_COMMA;
index++;
return OK;
};
case '"': {
-
index++;
String str;
while (true) {
@@ -203,7 +188,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
CharType res = 0;
switch (next) {
-
case 'b':
res = 8;
break;
@@ -228,7 +212,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
return ERR_PARSE_ERROR;
}
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
-
r_err_str = "Malformed hex constant in string";
return ERR_PARSE_ERROR;
}
@@ -260,8 +243,9 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
str += res;
} else {
- if (p_str[index] == '\n')
+ if (p_str[index] == '\n') {
line++;
+ }
str += p_str[index];
}
index++;
@@ -273,7 +257,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
} break;
default: {
-
if (p_str[index] <= 32) {
index++;
break;
@@ -289,11 +272,9 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
return OK;
} else if ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) {
-
String id;
while ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) {
-
id += p_str[index];
index++;
}
@@ -313,45 +294,41 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
}
Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
-
if (token.type == TK_CURLY_BRACKET_OPEN) {
-
Dictionary d;
Error err = _parse_object(d, p_str, index, p_len, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
value = d;
return OK;
} else if (token.type == TK_BRACKET_OPEN) {
-
Array a;
Error err = _parse_array(a, p_str, index, p_len, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
value = a;
return OK;
} else if (token.type == TK_IDENTIFIER) {
-
String id = token.value;
- if (id == "true")
+ if (id == "true") {
value = true;
- else if (id == "false")
+ } else if (id == "false") {
value = false;
- else if (id == "null")
+ } else if (id == "null") {
value = Variant();
- else {
+ } else {
r_err_str = "Expected 'true','false' or 'null', got '" + id + "'.";
return ERR_PARSE_ERROR;
}
return OK;
} else if (token.type == TK_NUMBER) {
-
value = token.value;
return OK;
} else if (token.type == TK_STRING) {
-
value = token.value;
return OK;
} else {
@@ -361,25 +338,21 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in
}
Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
-
Token token;
bool need_comma = false;
while (index < p_len) {
-
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type == TK_BRACKET_CLOSE) {
-
return OK;
}
if (need_comma) {
-
if (token.type != TK_COMMA) {
-
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
} else {
@@ -390,8 +363,9 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_
Variant v;
err = _parse_value(v, token, p_str, index, p_len, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
array.push_back(v);
need_comma = true;
@@ -401,29 +375,24 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_
}
Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
-
bool at_key = true;
String key;
Token token;
bool need_comma = false;
while (index < p_len) {
-
if (at_key) {
-
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type == TK_CURLY_BRACKET_CLOSE) {
-
return OK;
}
if (need_comma) {
-
if (token.type != TK_COMMA) {
-
r_err_str = "Expected '}' or ','";
return ERR_PARSE_ERROR;
} else {
@@ -433,31 +402,31 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index,
}
if (token.type != TK_STRING) {
-
r_err_str = "Expected key";
return ERR_PARSE_ERROR;
}
key = token.value;
err = _get_token(p_str, index, p_len, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type != TK_COLON) {
-
r_err_str = "Expected ':'";
return ERR_PARSE_ERROR;
}
at_key = false;
} else {
-
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
Variant v;
err = _parse_value(v, token, p_str, index, p_len, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
object[key] = v;
need_comma = true;
at_key = true;
@@ -468,7 +437,6 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index,
}
Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {
-
const CharType *str = p_json.ptr();
int idx = 0;
int len = p_json.length();
@@ -477,8 +445,9 @@ Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &
String aux_key;
Error err = _get_token(str, idx, len, token, r_err_line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
err = _parse_value(r_ret, token, str, idx, len, r_err_line, r_err_str);
diff --git a/core/io/json.h b/core/io/json.h
index 2e851afcf4..4fc5630a93 100644
--- a/core/io/json.h
+++ b/core/io/json.h
@@ -34,7 +34,6 @@
#include "core/variant.h"
class JSON {
-
enum TokenType {
TK_CURLY_BRACKET_OPEN,
TK_CURLY_BRACKET_CLOSE,
@@ -58,7 +57,6 @@ class JSON {
};
struct Token {
-
TokenType type;
Variant value;
};
diff --git a/core/io/logger.cpp b/core/io/logger.cpp
index 23165b575e..ef78b1194e 100644
--- a/core/io/logger.cpp
+++ b/core/io/logger.cpp
@@ -67,10 +67,11 @@ void Logger::log_error(const char *p_function, const char *p_file, int p_line, c
}
const char *err_details;
- if (p_rationale && *p_rationale)
+ if (p_rationale && *p_rationale) {
err_details = p_rationale;
- else
+ } else {
err_details = p_code;
+ }
logf_error("%s: %s\n", err_type, err_details);
logf_error(" at: %s (%s:%i) - %s\n", p_function, p_file, p_line, p_code);
diff --git a/core/io/logger.h b/core/io/logger.h
index 54f1a42da9..277be9ed35 100644
--- a/core/io/logger.h
+++ b/core/io/logger.h
@@ -62,7 +62,6 @@ public:
* Writes messages to stdout/stderr.
*/
class StdLogger : public Logger {
-
public:
virtual void logv(const char *p_format, va_list p_list, bool p_err) _PRINTF_FORMAT_ATTRIBUTE_2_0;
virtual ~StdLogger() {}
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index abf27954b8..eb39b1433f 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -49,7 +49,6 @@ void EncodedObjectAsID::set_object_id(ObjectID p_id) {
}
ObjectID EncodedObjectAsID::get_object_id() const {
-
return id;
}
@@ -97,7 +96,6 @@ static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r
}
Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects) {
-
const uint8_t *buf = p_buffer;
int len = p_len;
@@ -109,95 +107,95 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
buf += 4;
len -= 4;
- if (r_len)
+ if (r_len) {
*r_len = 4;
+ }
switch (type & ENCODE_MASK) {
-
case Variant::NIL: {
-
r_variant = Variant();
} break;
case Variant::BOOL: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
bool val = decode_uint32(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
} break;
case Variant::INT: {
-
if (type & ENCODE_FLAG_64) {
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
int64_t val = decode_uint64(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 8;
+ }
} else {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t val = decode_uint32(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
}
} break;
case Variant::FLOAT: {
-
if (type & ENCODE_FLAG_64) {
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
double val = decode_double(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 8;
+ }
} else {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
float val = decode_float(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
}
} break;
case Variant::STRING: {
-
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
r_variant = str;
} break;
// math types
case Variant::VECTOR2: {
-
ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA);
Vector2 val;
val.x = decode_float(&buf[0]);
val.y = decode_float(&buf[4]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 2;
+ }
} break;
case Variant::VECTOR2I: {
-
ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA);
Vector2i val;
val.x = decode_uint32(&buf[0]);
val.y = decode_uint32(&buf[4]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 2;
+ }
} break;
case Variant::RECT2: {
-
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Rect2 val;
val.position.x = decode_float(&buf[0]);
@@ -206,12 +204,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.size.y = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::RECT2I: {
-
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Rect2i val;
val.position.x = decode_uint32(&buf[0]);
@@ -220,12 +218,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.size.y = decode_uint32(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::VECTOR3: {
-
ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA);
Vector3 val;
val.x = decode_float(&buf[0]);
@@ -233,12 +231,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.z = decode_float(&buf[8]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 3;
+ }
} break;
case Variant::VECTOR3I: {
-
ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA);
Vector3i val;
val.x = decode_uint32(&buf[0]);
@@ -246,29 +244,28 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.z = decode_uint32(&buf[8]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 3;
+ }
} break;
case Variant::TRANSFORM2D: {
-
ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA);
Transform2D val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
-
val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]);
}
}
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 6;
+ }
} break;
case Variant::PLANE: {
-
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Plane val;
val.normal.x = decode_float(&buf[0]);
@@ -277,12 +274,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.d = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::QUAT: {
-
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Quat val;
val.x = decode_float(&buf[0]);
@@ -291,12 +288,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.w = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::AABB: {
-
ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA);
AABB val;
val.position.x = decode_float(&buf[0]);
@@ -307,34 +304,32 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.size.z = decode_float(&buf[20]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 6;
+ }
} break;
case Variant::BASIS: {
-
ERR_FAIL_COND_V(len < 4 * 9, ERR_INVALID_DATA);
Basis val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
-
val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
}
}
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 9;
+ }
} break;
case Variant::TRANSFORM: {
-
ERR_FAIL_COND_V(len < 4 * 12, ERR_INVALID_DATA);
Transform val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
-
val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
}
}
@@ -344,14 +339,14 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 12;
+ }
} break;
// misc types
case Variant::COLOR: {
-
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Color val;
val.r = decode_float(&buf[0]);
@@ -360,22 +355,22 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.a = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::STRING_NAME: {
-
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
r_variant = StringName(str);
} break;
case Variant::NODE_PATH: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t strlen = decode_uint32(buf);
@@ -392,25 +387,28 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
len -= 12;
buf += 12;
- if (flags & 2) // Obsolete format with property separate from subpath
+ if (flags & 2) { // Obsolete format with property separate from subpath
subnamecount++;
+ }
uint32_t total = namecount + subnamecount;
- if (r_len)
+ if (r_len) {
(*r_len) += 12;
+ }
for (uint32_t i = 0; i < total; i++) {
-
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
- if (i < namecount)
+ if (i < namecount) {
names.push_back(str);
- else
+ } else {
subnames.push_back(str);
+ }
}
r_variant = NodePath(names, subnames, flags & 1);
@@ -423,17 +421,16 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::_RID: {
-
r_variant = RID();
} break;
case Variant::OBJECT: {
-
if (type & ENCODE_FLAG_OBJECT_AS_ID) {
//this _is_ allowed
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
ObjectID val = ObjectID(decode_uint64(buf));
- if (r_len)
+ if (r_len) {
(*r_len) += 8;
+ }
if (val.is_null()) {
r_variant = (Object *)nullptr;
@@ -450,13 +447,13 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
if (str == String()) {
r_variant = (Object *)nullptr;
} else {
-
Object *obj = ClassDB::instance(str);
ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE);
@@ -470,17 +467,18 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
}
for (int i = 0; i < count; i++) {
-
str = String();
err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
Variant value;
int used;
err = decode_variant(value, buf, len, &used, p_allow_objects);
- if (err)
+ if (err) {
return err;
+ }
buf += used;
len -= used;
@@ -502,16 +500,13 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::CALLABLE: {
-
r_variant = Callable();
} break;
case Variant::SIGNAL: {
-
r_variant = Signal();
} break;
case Variant::DICTIONARY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
// bool shared = count&0x80000000;
@@ -527,7 +522,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Dictionary d;
for (int i = 0; i < count; i++) {
-
Variant key, value;
int used;
@@ -556,7 +550,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
// bool shared = count&0x80000000;
@@ -572,7 +565,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Array varr;
for (int i = 0; i < count; i++) {
-
int used = 0;
Variant v;
Error err = decode_variant(v, buf, len, &used, p_allow_objects);
@@ -591,7 +583,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
// arrays
case Variant::PACKED_BYTE_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -604,7 +595,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
uint8_t *w = data.ptrw();
for (int32_t i = 0; i < count; i++) {
-
w[i] = buf[i];
}
}
@@ -612,14 +602,14 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = data;
if (r_len) {
- if (count % 4)
+ if (count % 4) {
(*r_len) += 4 - count % 4;
+ }
(*r_len) += 4 + count;
}
} break;
case Variant::PACKED_INT32_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -634,7 +624,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
int32_t *w = data.ptrw();
for (int32_t i = 0; i < count; i++) {
-
w[i] = decode_uint32(&buf[i * 4]);
}
}
@@ -645,7 +634,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::PACKED_INT64_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int64_t count = decode_uint64(buf);
buf += 4;
@@ -660,7 +648,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
int64_t *w = data.ptrw();
for (int64_t i = 0; i < count; i++) {
-
w[i] = decode_uint64(&buf[i * 8]);
}
}
@@ -671,7 +658,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::PACKED_FLOAT32_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -686,7 +672,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
float *w = data.ptrw();
for (int32_t i = 0; i < count; i++) {
-
w[i] = decode_float(&buf[i * 4]);
}
}
@@ -698,7 +683,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::PACKED_FLOAT64_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int64_t count = decode_uint64(buf);
buf += 4;
@@ -713,7 +697,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
double *w = data.ptrw();
for (int64_t i = 0; i < count; i++) {
-
w[i] = decode_double(&buf[i * 8]);
}
}
@@ -725,7 +708,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::PACKED_STRING_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
@@ -733,16 +715,17 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
buf += 4;
len -= 4;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
//printf("string count: %i\n",count);
for (int32_t i = 0; i < count; i++) {
-
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
strings.push_back(str);
}
@@ -751,7 +734,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::PACKED_VECTOR2_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -770,22 +752,21 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Vector2 *w = varray.ptrw();
for (int32_t i = 0; i < count; i++) {
-
w[i].x = decode_float(buf + i * 4 * 2 + 4 * 0);
w[i].y = decode_float(buf + i * 4 * 2 + 4 * 1);
}
int adv = 4 * 2 * count;
- if (r_len)
+ if (r_len) {
(*r_len) += adv;
+ }
}
r_variant = varray;
} break;
case Variant::PACKED_VECTOR3_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -805,7 +786,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Vector3 *w = varray.ptrw();
for (int32_t i = 0; i < count; i++) {
-
w[i].x = decode_float(buf + i * 4 * 3 + 4 * 0);
w[i].y = decode_float(buf + i * 4 * 3 + 4 * 1);
w[i].z = decode_float(buf + i * 4 * 3 + 4 * 2);
@@ -813,15 +793,15 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
int adv = 4 * 3 * count;
- if (r_len)
+ if (r_len) {
(*r_len) += adv;
+ }
}
r_variant = varray;
} break;
case Variant::PACKED_COLOR_ARRAY: {
-
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@@ -841,7 +821,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Color *w = carray.ptrw();
for (int32_t i = 0; i < count; i++) {
-
w[i].r = decode_float(buf + i * 4 * 4 + 4 * 0);
w[i].g = decode_float(buf + i * 4 * 4 + 4 * 1);
w[i].b = decode_float(buf + i * 4 * 4 + 4 * 2);
@@ -850,8 +829,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
int adv = 4 * 4 * count;
- if (r_len)
+ if (r_len) {
(*r_len) += adv;
+ }
}
r_variant = carray;
@@ -866,7 +846,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
}
static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) {
-
CharString utf8 = p_string.utf8();
if (buf) {
@@ -886,7 +865,6 @@ static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) {
}
Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects) {
-
uint8_t *buf = r_buffer;
r_len = 0;
@@ -894,7 +872,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
uint32_t flags = 0;
switch (p_variant.get_type()) {
-
case Variant::INT: {
int64_t val = p_variant;
if (val > (int64_t)INT_MAX || val < (int64_t)INT_MIN) {
@@ -902,7 +879,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
}
} break;
case Variant::FLOAT: {
-
double d = p_variant;
float f = d;
if (double(f) != d) {
@@ -910,7 +886,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
}
} break;
case Variant::OBJECT: {
-
// Test for potential wrong values sent by the debugger when it breaks.
Object *obj = p_variant.get_validated_object();
if (!obj) {
@@ -937,13 +912,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
switch (p_variant.get_type()) {
-
case Variant::NIL: {
-
//nothing to do
} break;
case Variant::BOOL: {
-
if (buf) {
encode_uint32(p_variant.operator bool(), buf);
}
@@ -952,7 +924,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::INT: {
-
if (flags & ENCODE_FLAG_64) {
//64 bits
if (buf) {
@@ -969,7 +940,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
}
} break;
case Variant::FLOAT: {
-
if (flags & ENCODE_FLAG_64) {
if (buf) {
encode_double(p_variant.operator double(), buf);
@@ -978,7 +948,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 8;
} else {
-
if (buf) {
encode_float(p_variant.operator float(), buf);
}
@@ -988,14 +957,14 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::NODE_PATH: {
-
NodePath np = p_variant;
if (buf) {
encode_uint32(uint32_t(np.get_name_count()) | 0x80000000, buf); //for compatibility with the old format
encode_uint32(np.get_subname_count(), buf + 4);
uint32_t np_flags = 0;
- if (np.is_absolute())
+ if (np.is_absolute()) {
np_flags |= 1;
+ }
encode_uint32(np_flags, buf + 8);
@@ -1007,20 +976,21 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
int total = np.get_name_count() + np.get_subname_count();
for (int i = 0; i < total; i++) {
-
String str;
- if (i < np.get_name_count())
+ if (i < np.get_name_count()) {
str = np.get_name(i);
- else
+ } else {
str = np.get_subname(i - np.get_name_count());
+ }
CharString utf8 = str.utf8();
int pad = 0;
- if (utf8.length() % 4)
+ if (utf8.length() % 4) {
pad = 4 - utf8.length() % 4;
+ }
if (buf) {
encode_uint32(utf8.length(), buf);
@@ -1034,19 +1004,16 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::STRING: {
-
_encode_string(p_variant, buf, r_len);
} break;
case Variant::STRING_NAME: {
-
_encode_string(p_variant, buf, r_len);
} break;
// math types
case Variant::VECTOR2: {
-
if (buf) {
Vector2 v2 = p_variant;
encode_float(v2.x, &buf[0]);
@@ -1057,7 +1024,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::VECTOR2I: {
-
if (buf) {
Vector2i v2 = p_variant;
encode_uint32(v2.x, &buf[0]);
@@ -1068,7 +1034,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::RECT2: {
-
if (buf) {
Rect2 r2 = p_variant;
encode_float(r2.position.x, &buf[0]);
@@ -1080,7 +1045,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::RECT2I: {
-
if (buf) {
Rect2i r2 = p_variant;
encode_uint32(r2.position.x, &buf[0]);
@@ -1092,7 +1056,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::VECTOR3: {
-
if (buf) {
Vector3 v3 = p_variant;
encode_float(v3.x, &buf[0]);
@@ -1104,7 +1067,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::VECTOR3I: {
-
if (buf) {
Vector3i v3 = p_variant;
encode_uint32(v3.x, &buf[0]);
@@ -1116,12 +1078,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::TRANSFORM2D: {
-
if (buf) {
Transform2D val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
-
copymem(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float));
}
}
@@ -1131,7 +1091,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::PLANE: {
-
if (buf) {
Plane p = p_variant;
encode_float(p.normal.x, &buf[0]);
@@ -1144,7 +1103,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::QUAT: {
-
if (buf) {
Quat q = p_variant;
encode_float(q.x, &buf[0]);
@@ -1157,7 +1115,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::AABB: {
-
if (buf) {
AABB aabb = p_variant;
encode_float(aabb.position.x, &buf[0]);
@@ -1172,12 +1129,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::BASIS: {
-
if (buf) {
Basis val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
-
copymem(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float));
}
}
@@ -1187,12 +1142,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::TRANSFORM: {
-
if (buf) {
Transform val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
-
copymem(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float));
}
}
@@ -1208,7 +1161,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
// misc types
case Variant::COLOR: {
-
if (buf) {
Color c = p_variant;
encode_float(c.r, &buf[0]);
@@ -1221,18 +1173,13 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::_RID: {
-
} break;
case Variant::CALLABLE: {
-
} break;
case Variant::SIGNAL: {
-
} break;
case Variant::OBJECT: {
-
if (p_full_objects) {
-
Object *obj = p_variant;
if (!obj) {
if (buf) {
@@ -1248,9 +1195,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
int pc = 0;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
-
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
pc++;
}
@@ -1262,25 +1209,26 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
-
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
_encode_string(E->get().name, buf, r_len);
int len;
Error err = encode_variant(obj->get(E->get().name), buf, len, p_full_objects);
- if (err)
+ if (err) {
return err;
+ }
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
}
}
} else {
if (buf) {
-
Object *obj = p_variant.get_validated_object();
ObjectID id;
if (obj) {
@@ -1295,7 +1243,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::DICTIONARY: {
-
Dictionary d = p_variant;
if (buf) {
@@ -1308,7 +1255,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
d.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
/*
CharString utf8 = E->->utf8();
@@ -1326,20 +1272,21 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_variant(E->get(), buf, len, p_full_objects);
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
Variant *v = d.getptr(E->get());
ERR_FAIL_COND_V(!v, ERR_BUG);
encode_variant(*v, buf, len, p_full_objects);
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
}
} break;
case Variant::ARRAY: {
-
Array v = p_variant;
if (buf) {
@@ -1350,19 +1297,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
for (int i = 0; i < v.size(); i++) {
-
int len;
encode_variant(v.get(i), buf, len, p_full_objects);
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
}
} break;
// arrays
case Variant::PACKED_BYTE_ARRAY: {
-
Vector<uint8_t> data = p_variant;
int datalen = data.size();
int datasize = sizeof(uint8_t);
@@ -1378,13 +1324,13 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4 + datalen * datasize;
while (r_len % 4) {
r_len++;
- if (buf)
+ if (buf) {
*(buf++) = 0;
+ }
}
} break;
case Variant::PACKED_INT32_ARRAY: {
-
Vector<int32_t> data = p_variant;
int datalen = data.size();
int datasize = sizeof(int32_t);
@@ -1393,15 +1339,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint32(datalen, buf);
buf += 4;
const int32_t *r = data.ptr();
- for (int32_t i = 0; i < datalen; i++)
+ for (int32_t i = 0; i < datalen; i++) {
encode_uint32(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
} break;
case Variant::PACKED_INT64_ARRAY: {
-
Vector<int64_t> data = p_variant;
int datalen = data.size();
int datasize = sizeof(int64_t);
@@ -1410,15 +1356,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint64(datalen, buf);
buf += 4;
const int64_t *r = data.ptr();
- for (int64_t i = 0; i < datalen; i++)
+ for (int64_t i = 0; i < datalen; i++) {
encode_uint64(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
} break;
case Variant::PACKED_FLOAT32_ARRAY: {
-
Vector<float> data = p_variant;
int datalen = data.size();
int datasize = sizeof(float);
@@ -1427,15 +1373,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint32(datalen, buf);
buf += 4;
const float *r = data.ptr();
- for (int i = 0; i < datalen; i++)
+ for (int i = 0; i < datalen; i++) {
encode_float(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
} break;
case Variant::PACKED_FLOAT64_ARRAY: {
-
Vector<double> data = p_variant;
int datalen = data.size();
int datasize = sizeof(double);
@@ -1444,15 +1390,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint32(datalen, buf);
buf += 4;
const double *r = data.ptr();
- for (int i = 0; i < datalen; i++)
+ for (int i = 0; i < datalen; i++) {
encode_double(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
} break;
case Variant::PACKED_STRING_ARRAY: {
-
Vector<String> data = p_variant;
int len = data.size();
@@ -1464,7 +1410,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
for (int i = 0; i < len; i++) {
-
CharString utf8 = data.get(i).utf8();
if (buf) {
@@ -1477,14 +1422,14 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4 + utf8.length() + 1;
while (r_len % 4) {
r_len++; //pad
- if (buf)
+ if (buf) {
*(buf++) = 0;
+ }
}
}
} break;
case Variant::PACKED_VECTOR2_ARRAY: {
-
Vector<Vector2> data = p_variant;
int len = data.size();
@@ -1496,9 +1441,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
if (buf) {
-
for (int i = 0; i < len; i++) {
-
Vector2 v = data.get(i);
encode_float(v.x, &buf[0]);
@@ -1511,7 +1454,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::PACKED_VECTOR3_ARRAY: {
-
Vector<Vector3> data = p_variant;
int len = data.size();
@@ -1523,9 +1465,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
if (buf) {
-
for (int i = 0; i < len; i++) {
-
Vector3 v = data.get(i);
encode_float(v.x, &buf[0]);
@@ -1539,7 +1479,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::PACKED_COLOR_ARRAY: {
-
Vector<Color> data = p_variant;
int len = data.size();
@@ -1551,9 +1490,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
if (buf) {
-
for (int i = 0; i < len; i++) {
-
Color c = data.get(i);
encode_float(c.r, &buf[0]);
diff --git a/core/io/marshalls.h b/core/io/marshalls.h
index 1ba786d5d9..c21a97ac8a 100644
--- a/core/io/marshalls.h
+++ b/core/io/marshalls.h
@@ -41,21 +41,17 @@
*/
union MarshallFloat {
-
uint32_t i; ///< int
float f; ///< float
};
union MarshallDouble {
-
uint64_t l; ///< long long
double d; ///< double
};
static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) {
-
for (int i = 0; i < 2; i++) {
-
*p_arr = p_uint & 0xFF;
p_arr++;
p_uint >>= 8;
@@ -65,9 +61,7 @@ static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) {
}
static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) {
-
for (int i = 0; i < 4; i++) {
-
*p_arr = p_uint & 0xFF;
p_arr++;
p_uint >>= 8;
@@ -77,7 +71,6 @@ static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) {
}
static inline unsigned int encode_float(float p_float, uint8_t *p_arr) {
-
MarshallFloat mf;
mf.f = p_float;
encode_uint32(mf.i, p_arr);
@@ -86,9 +79,7 @@ static inline unsigned int encode_float(float p_float, uint8_t *p_arr) {
}
static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) {
-
for (int i = 0; i < 8; i++) {
-
*p_arr = p_uint & 0xFF;
p_arr++;
p_uint >>= 8;
@@ -98,7 +89,6 @@ static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) {
}
static inline unsigned int encode_double(double p_double, uint8_t *p_arr) {
-
MarshallDouble md;
md.d = p_double;
encode_uint64(md.l, p_arr);
@@ -107,13 +97,10 @@ static inline unsigned int encode_double(double p_double, uint8_t *p_arr) {
}
static inline int encode_cstring(const char *p_string, uint8_t *p_data) {
-
int len = 0;
while (*p_string) {
-
if (p_data) {
-
*p_data = (uint8_t)*p_string;
p_data++;
}
@@ -121,17 +108,16 @@ static inline int encode_cstring(const char *p_string, uint8_t *p_data) {
len++;
};
- if (p_data)
+ if (p_data) {
*p_data = 0;
+ }
return len + 1;
}
static inline uint16_t decode_uint16(const uint8_t *p_arr) {
-
uint16_t u = 0;
for (int i = 0; i < 2; i++) {
-
uint16_t b = *p_arr;
b <<= (i * 8);
u |= b;
@@ -142,11 +128,9 @@ static inline uint16_t decode_uint16(const uint8_t *p_arr) {
}
static inline uint32_t decode_uint32(const uint8_t *p_arr) {
-
uint32_t u = 0;
for (int i = 0; i < 4; i++) {
-
uint32_t b = *p_arr;
b <<= (i * 8);
u |= b;
@@ -157,18 +141,15 @@ static inline uint32_t decode_uint32(const uint8_t *p_arr) {
}
static inline float decode_float(const uint8_t *p_arr) {
-
MarshallFloat mf;
mf.i = decode_uint32(p_arr);
return mf.f;
}
static inline uint64_t decode_uint64(const uint8_t *p_arr) {
-
uint64_t u = 0;
for (int i = 0; i < 8; i++) {
-
uint64_t b = (*p_arr) & 0xFF;
b <<= (i * 8);
u |= b;
@@ -179,7 +160,6 @@ static inline uint64_t decode_uint64(const uint8_t *p_arr) {
}
static inline double decode_double(const uint8_t *p_arr) {
-
MarshallDouble md;
md.l = decode_uint64(p_arr);
return md.d;
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 998bcfd3f3..2f17d9e746 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -45,9 +45,7 @@
#endif
_FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_master, bool &r_skip_rpc) {
-
switch (mode) {
-
case MultiplayerAPI::RPC_MODE_DISABLED: {
// Do nothing.
} break;
@@ -55,8 +53,9 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas
// Do nothing also. Remote cannot produce a local call.
} break;
case MultiplayerAPI::RPC_MODE_MASTERSYNC: {
- if (is_master)
+ if (is_master) {
r_skip_rpc = true; // I am the master, so skip remote call.
+ }
[[fallthrough]];
}
case MultiplayerAPI::RPC_MODE_REMOTESYNC:
@@ -65,8 +64,9 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas
return true;
} break;
case MultiplayerAPI::RPC_MODE_MASTER: {
- if (is_master)
+ if (is_master) {
r_skip_rpc = true; // I am the master, so skip remote call.
+ }
return is_master;
} break;
case MultiplayerAPI::RPC_MODE_PUPPET: {
@@ -78,7 +78,6 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas
_FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, int p_remote_id) {
switch (mode) {
-
case MultiplayerAPI::RPC_MODE_DISABLED: {
return false;
} break;
@@ -100,17 +99,17 @@ _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, i
}
void MultiplayerAPI::poll() {
-
- if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED)
+ if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) {
return;
+ }
network_peer->poll();
- if (!network_peer.is_valid()) // It's possible that polling might have resulted in a disconnection, so check here.
+ if (!network_peer.is_valid()) { // It's possible that polling might have resulted in a disconnection, so check here.
return;
+ }
while (network_peer->get_available_packet_count()) {
-
int sender = network_peer->get_packet_peer();
const uint8_t *packet;
int len;
@@ -144,9 +143,9 @@ void MultiplayerAPI::set_root_node(Node *p_node) {
}
void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer) {
-
- if (p_peer == network_peer)
+ if (p_peer == network_peer) {
return; // Nothing to do
+ }
ERR_FAIL_COND_MSG(p_peer.is_valid() && p_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED,
"Supplied NetworkedMultiplayerPeer must be connecting or connected.");
@@ -185,6 +184,7 @@ void _profile_node_data(const String &p_what, ObjectID p_id) {
EngineDebugger::profiler_add_frame_data("multiplayer", values);
}
}
+
void _profile_bandwidth_data(const String &p_inout, int p_size) {
if (EngineDebugger::is_profiling("multiplayer")) {
Array values;
@@ -208,7 +208,6 @@ int get_packet_len(uint32_t p_node_target, int p_packet_len) {
}
void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) {
-
ERR_FAIL_COND_MSG(root_node == nullptr, "Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it.");
ERR_FAIL_COND_MSG(p_packet_len < 1, "Invalid packet received. Size too small.");
@@ -220,20 +219,16 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
uint8_t packet_type = p_packet[0] & 7;
switch (packet_type) {
-
case NETWORK_COMMAND_SIMPLIFY_PATH: {
-
_process_simplify_path(p_from, p_packet, p_packet_len);
} break;
case NETWORK_COMMAND_CONFIRM_PATH: {
-
_process_confirm_path(p_from, p_packet, p_packet_len);
} break;
case NETWORK_COMMAND_REMOTE_CALL:
case NETWORK_COMMAND_REMOTE_SET: {
-
// Extract packet meta
int packet_min_size = 1;
int name_id_offset = 1;
@@ -304,25 +299,21 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
const int packet_len = get_packet_len(node_target, p_packet_len);
if (packet_type == NETWORK_COMMAND_REMOTE_CALL) {
-
_process_rpc(node, name_id, p_from, p_packet, packet_len, packet_min_size);
} else {
-
_process_rset(node, name_id, p_from, p_packet, packet_len, packet_min_size);
}
} break;
case NETWORK_COMMAND_RAW: {
-
_process_raw(p_from, p_packet, p_packet_len);
} break;
}
}
Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len) {
-
Node *node = nullptr;
if (p_node_target & 0x80000000) {
@@ -339,8 +330,9 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uin
node = root_node->get_node(np);
- if (!node)
+ if (!node) {
ERR_PRINT("Failed to get path from RPC: " + String(np) + ".");
+ }
} else {
// Use cached path.
int id = p_node_target;
@@ -355,14 +347,14 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uin
// Do proper caching later.
node = root_node->get_node(ni->path);
- if (!node)
+ if (!node) {
ERR_PRINT("Failed to get cached path from RPC: " + String(ni->path) + ".");
+ }
}
return node;
}
void MultiplayerAPI::_process_rpc(Node *p_node, const uint16_t p_rpc_method_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
-
ERR_FAIL_COND_MSG(p_offset > p_packet_len, "Invalid packet received. Size too small.");
// Check that remote can call the RPC on this node.
@@ -415,7 +407,6 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const uint16_t p_rpc_method_id,
p_offset += len;
} else {
for (int i = 0; i < argc; i++) {
-
ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
int vlen;
@@ -438,7 +429,6 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const uint16_t p_rpc_method_id,
}
void MultiplayerAPI::_process_rset(Node *p_node, const uint16_t p_rpc_property_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
-
ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
// Check that remote can call the RSET on this node.
@@ -472,7 +462,6 @@ void MultiplayerAPI::_process_rset(Node *p_node, const uint16_t p_rpc_property_i
}
void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
-
ERR_FAIL_COND_MSG(p_packet_len < 38, "Invalid packet received. Size too small.");
int ofs = 1;
@@ -521,7 +510,6 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet,
}
void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
-
ERR_FAIL_COND_MSG(p_packet_len < 3, "Invalid packet received. Size too small.");
const bool valid_rpc_checksum = p_packet[1];
@@ -548,12 +536,13 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC
List<int> peers_to_add; // If one is missing, take note to add it.
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
-
- if (p_target < 0 && E->get() == -p_target)
+ if (p_target < 0 && E->get() == -p_target) {
continue; // Continue, excluded.
+ }
- if (p_target > 0 && E->get() != p_target)
+ if (p_target > 0 && E->get() != p_target) {
continue; // Continue, not for this peer.
+ }
Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
@@ -569,7 +558,6 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC
}
if (peers_to_add.size() > 0) {
-
// Those that need to be added, send a message for this.
// Encode function name.
@@ -594,7 +582,6 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC
ofs += encode_cstring(path.get_data(), &packet.write[ofs]);
for (List<int>::Element *E = peers_to_add.front(); E; E = E->next()) {
-
network_peer->set_target_peer(E->get()); // To all of you.
network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
network_peer->put_packet(packet.ptr(), packet.size());
@@ -619,7 +606,6 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC
#define ENCODE_32 2 << 5
#define ENCODE_64 3 << 5
Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) {
-
// Unreachable because `VARIANT_MAX` == 27 and `ENCODE_VARIANT_MASK` == 31
CRASH_COND(p_variant.get_type() > VARIANT_META_TYPE_MASK);
@@ -681,8 +667,9 @@ Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uin
default:
// Any other case is not yet compressed.
Error err = encode_variant(p_variant, r_buffer, r_len, allow_object_decoding);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (r_buffer) {
// The first byte is not used by the marshaling, so store the type
// so we know how to decompress and decode this variant.
@@ -692,8 +679,8 @@ Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uin
return OK;
}
-Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len) {
+Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len) {
const uint8_t *buf = p_buffer;
int len = p_len;
@@ -707,55 +694,61 @@ Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const u
case Variant::BOOL: {
bool val = (buf[0] & VARIANT_META_BOOL_MASK) > 0;
r_variant = val;
- if (r_len)
+ if (r_len) {
*r_len = 1;
+ }
} break;
case Variant::INT: {
buf += 1;
len -= 1;
- if (r_len)
+ if (r_len) {
*r_len = 1;
+ }
if (encode_mode == ENCODE_8) {
// 8 bits.
ERR_FAIL_COND_V(len < 1, ERR_INVALID_DATA);
int8_t val = buf[0];
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 1;
+ }
} else if (encode_mode == ENCODE_16) {
// 16 bits.
ERR_FAIL_COND_V(len < 2, ERR_INVALID_DATA);
int16_t val = decode_uint16(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 2;
+ }
} else if (encode_mode == ENCODE_32) {
// 32 bits.
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t val = decode_uint32(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
} else {
// 64 bits.
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
int64_t val = decode_uint64(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 8;
+ }
}
} break;
default:
Error err = decode_variant(r_variant, p_buffer, p_len, r_len, allow_object_decoding);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
}
return OK;
}
void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount) {
-
ERR_FAIL_COND_MSG(network_peer.is_null(), "Attempt to remote call/set when networking is not active in SceneTree.");
ERR_FAIL_COND_MSG(network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_CONNECTING, "Attempt to remote call/set when networking is not connected yet in SceneTree.");
@@ -841,7 +834,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
}
if (p_set) {
-
// Take the rpc property ID
uint16_t property_id = p_from->get_node_rset_property_id(p_name);
if (property_id == UINT16_MAX && p_from->get_script_instance()) {
@@ -934,7 +926,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
network_peer->set_transfer_mode(p_unreliable ? NetworkedMultiplayerPeer::TRANSFER_MODE_UNRELIABLE : NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
if (has_all_peers) {
-
// They all have verified paths, so send fast.
network_peer->set_target_peer(p_to); // To all of you.
network_peer->put_packet(packet_cache.ptr(), ofs); // A message with love.
@@ -951,12 +942,13 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
encode_cstring(pname.get_data(), &(packet_cache.write[ofs]));
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
-
- if (p_to < 0 && E->get() == -p_to)
+ if (p_to < 0 && E->get() == -p_to) {
continue; // Continue, excluded.
+ }
- if (p_to > 0 && E->get() != p_to)
+ if (p_to > 0 && E->get() != p_to) {
continue; // Continue, not for this peer.
+ }
Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
ERR_CONTINUE(!F); // Should never happen.
@@ -998,22 +990,18 @@ void MultiplayerAPI::_del_peer(int p_id) {
}
void MultiplayerAPI::_connected_to_server() {
-
emit_signal("connected_to_server");
}
void MultiplayerAPI::_connection_failed() {
-
emit_signal("connection_failed");
}
void MultiplayerAPI::_server_disconnected() {
-
emit_signal("server_disconnected");
}
void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) {
-
ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to call an RPC while no network peer is active.");
ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to call an RPC on a node which is not inside SceneTree.");
ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to call an RPC via a network peer which is not connected.");
@@ -1040,7 +1028,6 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
if (!skip_rpc) {
-
#ifdef DEBUG_ENABLED
_profile_node_data("out_rpc", p_node->get_instance_id());
#endif
@@ -1081,7 +1068,6 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value) {
-
ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to RSET while no network peer is active.");
ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to RSET on a node which is not inside SceneTree.");
ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to send an RSET via a network peer which is not connected.");
@@ -1146,7 +1132,6 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
Error MultiplayerAPI::send_bytes(Vector<uint8_t> p_data, int p_to, NetworkedMultiplayerPeer::TransferMode p_mode) {
-
ERR_FAIL_COND_V_MSG(p_data.size() < 1, ERR_INVALID_DATA, "Trying to send an empty raw packet.");
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), ERR_UNCONFIGURED, "Trying to send a raw packet while no network peer is active.");
ERR_FAIL_COND_V_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED, "Trying to send a raw packet via a network peer which is not connected.");
@@ -1163,7 +1148,6 @@ Error MultiplayerAPI::send_bytes(Vector<uint8_t> p_data, int p_to, NetworkedMult
}
void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_packet_len) {
-
ERR_FAIL_COND_MSG(p_packet_len < 2, "Invalid packet received. Size too small.");
Vector<uint8_t> out;
@@ -1177,32 +1161,27 @@ void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_pac
}
int MultiplayerAPI::get_network_unique_id() const {
-
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), 0, "No network peer is assigned. Unable to get unique network ID.");
return network_peer->get_unique_id();
}
bool MultiplayerAPI::is_network_server() const {
-
// XXX Maybe fail silently? Maybe should actually return true to make development of both local and online multiplayer easier?
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. I can't be a server.");
return network_peer->is_server();
}
void MultiplayerAPI::set_refuse_new_network_connections(bool p_refuse) {
-
ERR_FAIL_COND_MSG(!network_peer.is_valid(), "No network peer is assigned. Unable to set 'refuse_new_connections'.");
network_peer->set_refuse_new_connections(p_refuse);
}
bool MultiplayerAPI::is_refusing_new_network_connections() const {
-
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. Unable to get 'refuse_new_connections'.");
return network_peer->is_refusing_new_connections();
}
Vector<int> MultiplayerAPI::get_network_connected_peers() const {
-
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), Vector<int>(), "No network peer is assigned. Assume no peers are connected.");
Vector<int> ret;
@@ -1214,12 +1193,10 @@ Vector<int> MultiplayerAPI::get_network_connected_peers() const {
}
void MultiplayerAPI::set_allow_object_decoding(bool p_enable) {
-
allow_object_decoding = p_enable;
}
bool MultiplayerAPI::is_object_decoding_allowed() const {
-
return allow_object_decoding;
}
diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h
index 2603fb1e27..06eab7796c 100644
--- a/core/io/multiplayer_api.h
+++ b/core/io/multiplayer_api.h
@@ -35,7 +35,6 @@
#include "core/reference.h"
class MultiplayerAPI : public Reference {
-
GDCLASS(MultiplayerAPI, Reference);
private:
diff --git a/core/io/net_socket.cpp b/core/io/net_socket.cpp
index 838c674cec..130a2e245e 100644
--- a/core/io/net_socket.cpp
+++ b/core/io/net_socket.cpp
@@ -33,9 +33,9 @@
NetSocket *(*NetSocket::_create)() = nullptr;
NetSocket *NetSocket::create() {
-
- if (_create)
+ if (_create) {
return _create();
+ }
ERR_PRINT("Unable to create network socket, platform not supported");
return nullptr;
diff --git a/core/io/net_socket.h b/core/io/net_socket.h
index 376fd87a27..746945eced 100644
--- a/core/io/net_socket.h
+++ b/core/io/net_socket.h
@@ -35,7 +35,6 @@
#include "core/reference.h"
class NetSocket : public Reference {
-
protected:
static NetSocket *(*_create)();
diff --git a/core/io/networked_multiplayer_peer.cpp b/core/io/networked_multiplayer_peer.cpp
index 332beb4c8c..f521f2bb79 100644
--- a/core/io/networked_multiplayer_peer.cpp
+++ b/core/io/networked_multiplayer_peer.cpp
@@ -31,7 +31,6 @@
#include "networked_multiplayer_peer.h"
void NetworkedMultiplayerPeer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_transfer_mode", "mode"), &NetworkedMultiplayerPeer::set_transfer_mode);
ClassDB::bind_method(D_METHOD("get_transfer_mode"), &NetworkedMultiplayerPeer::get_transfer_mode);
ClassDB::bind_method(D_METHOD("set_target_peer", "id"), &NetworkedMultiplayerPeer::set_target_peer);
diff --git a/core/io/networked_multiplayer_peer.h b/core/io/networked_multiplayer_peer.h
index 8792886ff3..dc76237f45 100644
--- a/core/io/networked_multiplayer_peer.h
+++ b/core/io/networked_multiplayer_peer.h
@@ -34,7 +34,6 @@
#include "core/io/packet_peer.h"
class NetworkedMultiplayerPeer : public PacketPeer {
-
GDCLASS(NetworkedMultiplayerPeer, PacketPeer);
protected:
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index 6d3e1341a7..6d37d95994 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -36,7 +36,6 @@
/* helpers / binders */
void PacketPeer::set_encode_buffer_max_size(int p_max_size) {
-
ERR_FAIL_COND_MSG(p_max_size < 1024, "Max encode buffer must be at least 1024 bytes");
ERR_FAIL_COND_MSG(p_max_size > 256 * 1024 * 1024, "Max encode buffer cannot exceed 256 MiB");
encode_buffer_max_size = next_power_of_2(p_max_size);
@@ -44,59 +43,61 @@ void PacketPeer::set_encode_buffer_max_size(int p_max_size) {
}
int PacketPeer::get_encode_buffer_max_size() const {
-
return encode_buffer_max_size;
}
Error PacketPeer::get_packet_buffer(Vector<uint8_t> &r_buffer) {
-
const uint8_t *buffer;
int buffer_size;
Error err = get_packet(&buffer, buffer_size);
- if (err)
+ if (err) {
return err;
+ }
r_buffer.resize(buffer_size);
- if (buffer_size == 0)
+ if (buffer_size == 0) {
return OK;
+ }
uint8_t *w = r_buffer.ptrw();
- for (int i = 0; i < buffer_size; i++)
+ for (int i = 0; i < buffer_size; i++) {
w[i] = buffer[i];
+ }
return OK;
}
Error PacketPeer::put_packet_buffer(const Vector<uint8_t> &p_buffer) {
-
int len = p_buffer.size();
- if (len == 0)
+ if (len == 0) {
return OK;
+ }
const uint8_t *r = p_buffer.ptr();
return put_packet(&r[0], len);
}
Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) {
-
const uint8_t *buffer;
int buffer_size;
Error err = get_packet(&buffer, buffer_size);
- if (err)
+ if (err) {
return err;
+ }
return decode_variant(r_variant, buffer, buffer_size, nullptr, p_allow_objects);
}
Error PacketPeer::put_var(const Variant &p_packet, bool p_full_objects) {
-
int len;
Error err = encode_variant(p_packet, nullptr, len, p_full_objects); // compute len first
- if (err)
+ if (err) {
return err;
+ }
- if (len == 0)
+ if (len == 0) {
return OK;
+ }
ERR_FAIL_COND_V_MSG(len > encode_buffer_max_size, ERR_OUT_OF_MEMORY, "Failed to encode variant, encode size is bigger then encode_buffer_max_size. Consider raising it via 'set_encode_buffer_max_size'.");
@@ -123,20 +124,18 @@ Variant PacketPeer::_bnd_get_var(bool p_allow_objects) {
Error PacketPeer::_put_packet(const Vector<uint8_t> &p_buffer) {
return put_packet_buffer(p_buffer);
}
-Vector<uint8_t> PacketPeer::_get_packet() {
+Vector<uint8_t> PacketPeer::_get_packet() {
Vector<uint8_t> raw;
last_get_error = get_packet_buffer(raw);
return raw;
}
Error PacketPeer::_get_packet_error() const {
-
return last_get_error;
}
void PacketPeer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_var", "allow_objects"), &PacketPeer::_bnd_get_var, DEFVAL(false));
ClassDB::bind_method(D_METHOD("put_var", "var", "full_objects"), &PacketPeer::put_var, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_packet"), &PacketPeer::_get_packet);
@@ -153,13 +152,11 @@ void PacketPeer::_bind_methods() {
/***************/
void PacketPeerStream::_set_stream_peer(REF p_peer) {
-
ERR_FAIL_COND_MSG(p_peer.is_null(), "It's not a reference to a valid Resource object.");
set_stream_peer(p_peer);
}
void PacketPeerStream::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_stream_peer", "peer"), &PacketPeerStream::set_stream_peer);
ClassDB::bind_method(D_METHOD("get_stream_peer"), &PacketPeerStream::get_stream_peer);
ClassDB::bind_method(D_METHOD("set_input_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_input_buffer_max_size);
@@ -173,16 +170,17 @@ void PacketPeerStream::_bind_methods() {
}
Error PacketPeerStream::_poll_buffer() const {
-
ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED);
int read = 0;
ERR_FAIL_COND_V(input_buffer.size() < ring_buffer.space_left(), ERR_UNAVAILABLE);
Error err = peer->get_partial_data(input_buffer.ptrw(), ring_buffer.space_left(), read);
- if (err)
+ if (err) {
return err;
- if (read == 0)
+ }
+ if (read == 0) {
return OK;
+ }
int w = ring_buffer.write(&input_buffer[0], read);
ERR_FAIL_COND_V(w != read, ERR_BUG);
@@ -191,7 +189,6 @@ Error PacketPeerStream::_poll_buffer() const {
}
int PacketPeerStream::get_available_packet_count() const {
-
_poll_buffer();
uint32_t remaining = ring_buffer.data_left();
@@ -200,14 +197,14 @@ int PacketPeerStream::get_available_packet_count() const {
int count = 0;
while (remaining >= 4) {
-
uint8_t lbuf[4];
ring_buffer.copy(lbuf, ofs, 4);
uint32_t len = decode_uint32(lbuf);
remaining -= 4;
ofs += 4;
- if (len > remaining)
+ if (len > remaining) {
break;
+ }
remaining -= len;
ofs += len;
count++;
@@ -217,7 +214,6 @@ int PacketPeerStream::get_available_packet_count() const {
}
Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
-
ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED);
_poll_buffer();
@@ -239,34 +235,34 @@ Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size)
}
Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
-
ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED);
Error err = _poll_buffer(); //won't hurt to poll here too
- if (err)
+ if (err) {
return err;
+ }
- if (p_buffer_size == 0)
+ if (p_buffer_size == 0) {
return OK;
+ }
ERR_FAIL_COND_V(p_buffer_size < 0, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(p_buffer_size + 4 > output_buffer.size(), ERR_INVALID_PARAMETER);
encode_uint32(p_buffer_size, output_buffer.ptrw());
uint8_t *dst = &output_buffer.write[4];
- for (int i = 0; i < p_buffer_size; i++)
+ for (int i = 0; i < p_buffer_size; i++) {
dst[i] = p_buffer[i];
+ }
return peer->put_data(&output_buffer[0], p_buffer_size + 4);
}
int PacketPeerStream::get_max_packet_size() const {
-
return output_buffer.size();
}
void PacketPeerStream::set_stream_peer(const Ref<StreamPeer> &p_peer) {
-
//ERR_FAIL_COND(p_peer.is_null());
if (p_peer.ptr() != peer.ptr()) {
@@ -277,12 +273,10 @@ void PacketPeerStream::set_stream_peer(const Ref<StreamPeer> &p_peer) {
}
Ref<StreamPeer> PacketPeerStream::get_stream_peer() const {
-
return peer;
}
void PacketPeerStream::set_input_buffer_max_size(int p_max_size) {
-
ERR_FAIL_COND_MSG(p_max_size < 0, "Max size of input buffer size cannot be smaller than 0.");
//warning may lose packets
ERR_FAIL_COND_MSG(ring_buffer.data_left(), "Buffer in use, resizing would cause loss of data.");
@@ -291,22 +285,18 @@ void PacketPeerStream::set_input_buffer_max_size(int p_max_size) {
}
int PacketPeerStream::get_input_buffer_max_size() const {
-
return input_buffer.size() - 4;
}
void PacketPeerStream::set_output_buffer_max_size(int p_max_size) {
-
output_buffer.resize(next_power_of_2(p_max_size + 4));
}
int PacketPeerStream::get_output_buffer_max_size() const {
-
return output_buffer.size() - 4;
}
PacketPeerStream::PacketPeerStream() {
-
int rbsize = GLOBAL_GET("network/limits/packet_peer_stream/max_buffer_po2");
ring_buffer.resize(rbsize);
diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h
index b69efa531f..f0ba50087f 100644
--- a/core/io/packet_peer.h
+++ b/core/io/packet_peer.h
@@ -36,7 +36,6 @@
#include "core/ring_buffer.h"
class PacketPeer : public Reference {
-
GDCLASS(PacketPeer, Reference);
Variant _bnd_get_var(bool p_allow_objects = false);
@@ -75,7 +74,6 @@ public:
};
class PacketPeerStream : public PacketPeer {
-
GDCLASS(PacketPeerStream, PacketPeer);
//the way the buffers work sucks, will change later
diff --git a/core/io/packet_peer_dtls.cpp b/core/io/packet_peer_dtls.cpp
index ada3cb10a2..67579c339a 100644
--- a/core/io/packet_peer_dtls.cpp
+++ b/core/io/packet_peer_dtls.cpp
@@ -36,7 +36,6 @@ PacketPeerDTLS *(*PacketPeerDTLS::_create)() = nullptr;
bool PacketPeerDTLS::available = false;
PacketPeerDTLS *PacketPeerDTLS::create() {
-
return _create();
}
@@ -45,7 +44,6 @@ bool PacketPeerDTLS::is_available() {
}
void PacketPeerDTLS::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("poll"), &PacketPeerDTLS::poll);
ClassDB::bind_method(D_METHOD("connect_to_peer", "packet_peer", "validate_certs", "for_hostname", "valid_certificate"), &PacketPeerDTLS::connect_to_peer, DEFVAL(true), DEFVAL(String()), DEFVAL(Ref<X509Certificate>()));
ClassDB::bind_method(D_METHOD("get_status"), &PacketPeerDTLS::get_status);
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp
index 8b6bd7ef90..862fca96fc 100644
--- a/core/io/packet_peer_udp.cpp
+++ b/core/io/packet_peer_udp.cpp
@@ -33,18 +33,17 @@
#include "core/io/ip.h"
void PacketPeerUDP::set_blocking_mode(bool p_enable) {
-
blocking = p_enable;
}
void PacketPeerUDP::set_broadcast_enabled(bool p_enabled) {
broadcast = p_enabled;
- if (_sock.is_valid() && _sock->is_open())
+ if (_sock.is_valid() && _sock->is_open()) {
_sock->set_broadcasting_enabled(p_enabled);
+ }
}
Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_if_name) {
-
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(!p_multi_address.is_valid(), ERR_INVALID_PARAMETER);
@@ -59,26 +58,24 @@ Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_i
}
Error PacketPeerUDP::leave_multicast_group(IP_Address p_multi_address, String p_if_name) {
-
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(!_sock->is_open(), ERR_UNCONFIGURED);
return _sock->leave_multicast_group(p_multi_address, p_if_name);
}
String PacketPeerUDP::_get_packet_ip() const {
-
return get_packet_address();
}
Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) {
-
IP_Address ip;
if (p_address.is_valid_ip_address()) {
ip = p_address;
} else {
ip = IP::get_singleton()->resolve_hostname(p_address);
- if (!ip.is_valid())
+ if (!ip.is_valid()) {
return ERR_CANT_RESOLVE;
+ }
}
set_dest_address(ip, p_port);
@@ -86,22 +83,23 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) {
}
int PacketPeerUDP::get_available_packet_count() const {
-
// TODO we should deprecate this, and expose poll instead!
Error err = const_cast<PacketPeerUDP *>(this)->_poll();
- if (err != OK)
+ if (err != OK) {
return -1;
+ }
return queue_count;
}
Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
-
Error err = _poll();
- if (err != OK)
+ if (err != OK) {
return err;
- if (queue_count == 0)
+ }
+ if (queue_count == 0) {
return ERR_UNAVAILABLE;
+ }
uint32_t size = 0;
uint8_t ipv6[16];
@@ -117,7 +115,6 @@ Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
}
Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
-
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(!peer_addr.is_valid(), ERR_UNCONFIGURED);
@@ -139,10 +136,11 @@ Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
err = _sock->sendto(p_buffer, p_buffer_size, sent, peer_addr, peer_port);
}
if (err != OK) {
- if (err != ERR_BUSY)
+ if (err != ERR_BUSY) {
return FAILED;
- else if (!blocking)
+ } else if (!blocking) {
return ERR_BUSY;
+ }
// Keep trying to send full packet
continue;
}
@@ -154,12 +152,10 @@ Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
}
int PacketPeerUDP::get_max_packet_size() const {
-
return 512; // uhm maybe not
}
Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) {
-
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
@@ -167,13 +163,15 @@ Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_
Error err;
IP::Type ip_type = IP::TYPE_ANY;
- if (p_bind_address.is_valid())
+ if (p_bind_address.is_valid()) {
ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
+ }
err = _sock->open(NetSocket::TYPE_UDP, ip_type);
- if (err != OK)
+ if (err != OK) {
return ERR_CANT_CREATE;
+ }
_sock->set_blocking_enabled(false);
_sock->set_reuse_address_enabled(true);
@@ -245,22 +243,20 @@ bool PacketPeerUDP::is_connected_to_host() const {
}
void PacketPeerUDP::close() {
-
- if (_sock.is_valid())
+ if (_sock.is_valid()) {
_sock->close();
+ }
rb.resize(16);
queue_count = 0;
connected = false;
}
Error PacketPeerUDP::wait() {
-
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
return _sock->poll(NetSocket::POLL_TYPE_IN, -1);
}
Error PacketPeerUDP::_poll() {
-
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
if (!_sock->is_open()) {
@@ -282,8 +278,9 @@ Error PacketPeerUDP::_poll() {
}
if (err != OK) {
- if (err == ERR_BUSY)
+ if (err == ERR_BUSY) {
break;
+ }
return FAILED;
}
@@ -304,30 +301,26 @@ Error PacketPeerUDP::_poll() {
return OK;
}
-bool PacketPeerUDP::is_listening() const {
+bool PacketPeerUDP::is_listening() const {
return _sock.is_valid() && _sock->is_open();
}
IP_Address PacketPeerUDP::get_packet_address() const {
-
return packet_ip;
}
int PacketPeerUDP::get_packet_port() const {
-
return packet_port;
}
void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) {
-
ERR_FAIL_COND_MSG(connected, "Destination address cannot be set for connected sockets");
peer_addr = p_address;
peer_port = p_port;
}
void PacketPeerUDP::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("listen", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536));
ClassDB::bind_method(D_METHOD("close"), &PacketPeerUDP::close);
ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait);
@@ -348,6 +341,5 @@ PacketPeerUDP::PacketPeerUDP() :
}
PacketPeerUDP::~PacketPeerUDP() {
-
close();
}
diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp
index 124ac30b88..06d22ce897 100644
--- a/core/io/pck_packer.cpp
+++ b/core/io/pck_packer.cpp
@@ -35,34 +35,31 @@
#include "core/version.h"
static uint64_t _align(uint64_t p_n, int p_alignment) {
-
- if (p_alignment == 0)
+ if (p_alignment == 0) {
return p_n;
+ }
uint64_t rest = p_n % p_alignment;
- if (rest == 0)
+ if (rest == 0) {
return p_n;
- else
+ } else {
return p_n + (p_alignment - rest);
+ }
};
static void _pad(FileAccess *p_file, int p_bytes) {
-
for (int i = 0; i < p_bytes; i++) {
-
p_file->store_8(0);
};
};
void PCKPacker::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("pck_start", "pck_name", "alignment"), &PCKPacker::pck_start, DEFVAL(0));
ClassDB::bind_method(D_METHOD("add_file", "pck_path", "source_path"), &PCKPacker::add_file);
ClassDB::bind_method(D_METHOD("flush", "verbose"), &PCKPacker::flush, DEFVAL(false));
};
Error PCKPacker::pck_start(const String &p_file, int p_alignment) {
-
if (file != nullptr) {
memdelete(file);
}
@@ -80,7 +77,6 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment) {
file->store_32(VERSION_PATCH);
for (int i = 0; i < 16; i++) {
-
file->store_32(0); // reserved
};
@@ -90,7 +86,6 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment) {
};
Error PCKPacker::add_file(const String &p_file, const String &p_src) {
-
FileAccess *f = FileAccess::open(p_src, FileAccess::READ);
if (!f) {
return ERR_FILE_CANT_OPEN;
@@ -111,7 +106,6 @@ Error PCKPacker::add_file(const String &p_file, const String &p_src) {
};
Error PCKPacker::flush(bool p_verbose) {
-
ERR_FAIL_COND_V_MSG(!file, ERR_INVALID_PARAMETER, "File must be opened before use.");
// write the index
@@ -119,7 +113,6 @@ Error PCKPacker::flush(bool p_verbose) {
file->store_32(files.size());
for (int i = 0; i < files.size(); i++) {
-
file->store_pascal_string(files[i].path);
files.write[i].offset_offset = file->get_position();
file->store_64(0); // offset
@@ -142,11 +135,9 @@ Error PCKPacker::flush(bool p_verbose) {
int count = 0;
for (int i = 0; i < files.size(); i++) {
-
FileAccess *src = FileAccess::open(files[i].src_path, FileAccess::READ);
uint64_t to_write = files[i].size;
while (to_write > 0) {
-
int read = src->get_buffer(buf, MIN(to_write, buf_max));
file->store_buffer(buf, read);
to_write -= read;
@@ -171,8 +162,9 @@ Error PCKPacker::flush(bool p_verbose) {
};
};
- if (p_verbose)
+ if (p_verbose) {
printf("\n");
+ }
file->close();
memdelete_arr(buf);
diff --git a/core/io/pck_packer.h b/core/io/pck_packer.h
index 2848ac3a65..2929967a68 100644
--- a/core/io/pck_packer.h
+++ b/core/io/pck_packer.h
@@ -36,7 +36,6 @@
class FileAccess;
class PCKPacker : public Reference {
-
GDCLASS(PCKPacker, Reference);
FileAccess *file = nullptr;
@@ -45,7 +44,6 @@ class PCKPacker : public Reference {
static void _bind_methods();
struct File {
-
String path;
String src_path;
int size;
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 8ce17bcfbe..5097f6d98b 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -94,24 +94,24 @@ enum {
};
void ResourceLoaderBinary::_advance_padding(uint32_t p_len) {
-
uint32_t extra = 4 - (p_len % 4);
if (extra < 4) {
- for (uint32_t i = 0; i < extra; i++)
+ for (uint32_t i = 0; i < extra; i++) {
f->get_8(); //pad to 32
+ }
}
}
StringName ResourceLoaderBinary::_get_string() {
-
uint32_t id = f->get_32();
if (id & 0x80000000) {
uint32_t len = id & 0x7FFFFFFF;
if ((int)len > str_buf.size()) {
str_buf.resize(len);
}
- if (len == 0)
+ if (len == 0) {
return StringName();
+ }
f->get_buffer((uint8_t *)&str_buf[0], len);
String s;
s.parse_utf8(&str_buf[0]);
@@ -122,42 +122,32 @@ StringName ResourceLoaderBinary::_get_string() {
}
Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
-
uint32_t type = f->get_32();
print_bl("find property of type: " + itos(type));
switch (type) {
-
case VARIANT_NIL: {
-
r_v = Variant();
} break;
case VARIANT_BOOL: {
-
r_v = bool(f->get_32());
} break;
case VARIANT_INT: {
-
r_v = int(f->get_32());
} break;
case VARIANT_INT64: {
-
r_v = int64_t(f->get_64());
} break;
case VARIANT_FLOAT: {
-
r_v = f->get_real();
} break;
case VARIANT_DOUBLE: {
-
r_v = f->get_double();
} break;
case VARIANT_STRING: {
-
r_v = get_unicode_string();
} break;
case VARIANT_VECTOR2: {
-
Vector2 v;
v.x = f->get_real();
v.y = f->get_real();
@@ -165,7 +155,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_VECTOR2I: {
-
Vector2i v;
v.x = f->get_32();
v.y = f->get_32();
@@ -173,7 +162,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_RECT2: {
-
Rect2 v;
v.position.x = f->get_real();
v.position.y = f->get_real();
@@ -183,7 +171,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_RECT2I: {
-
Rect2i v;
v.position.x = f->get_32();
v.position.y = f->get_32();
@@ -193,7 +180,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_VECTOR3: {
-
Vector3 v;
v.x = f->get_real();
v.y = f->get_real();
@@ -201,7 +187,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
r_v = v;
} break;
case VARIANT_VECTOR3I: {
-
Vector3i v;
v.x = f->get_32();
v.y = f->get_32();
@@ -209,7 +194,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
r_v = v;
} break;
case VARIANT_PLANE: {
-
Plane v;
v.normal.x = f->get_real();
v.normal.y = f->get_real();
@@ -227,7 +211,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_AABB: {
-
AABB v;
v.position.x = f->get_real();
v.position.y = f->get_real();
@@ -239,7 +222,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_MATRIX32: {
-
Transform2D v;
v.elements[0].x = f->get_real();
v.elements[0].y = f->get_real();
@@ -251,7 +233,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_MATRIX3: {
-
Basis v;
v.elements[0].x = f->get_real();
v.elements[0].y = f->get_real();
@@ -266,7 +247,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_TRANSFORM: {
-
Transform v;
v.basis.elements[0].x = f->get_real();
v.basis.elements[0].y = f->get_real();
@@ -283,7 +263,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
r_v = v;
} break;
case VARIANT_COLOR: {
-
Color v;
v.r = f->get_real();
v.g = f->get_real();
@@ -293,12 +272,10 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_STRING_NAME: {
-
r_v = StringName(get_unicode_string());
} break;
case VARIANT_NODE_PATH: {
-
Vector<StringName> names;
Vector<StringName> subnames;
bool absolute;
@@ -311,10 +288,12 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
subname_count += 1; // has a property field, so we should count it as well
}
- for (int i = 0; i < name_count; i++)
+ for (int i = 0; i < name_count; i++) {
names.push_back(_get_string());
- for (uint32_t i = 0; i < subname_count; i++)
+ }
+ for (uint32_t i = 0; i < subname_count; i++) {
subnames.push_back(_get_string());
+ }
NodePath np = NodePath(names, subnames, absolute);
@@ -322,15 +301,12 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_RID: {
-
r_v = f->get_32();
} break;
case VARIANT_OBJECT: {
-
uint32_t objtype = f->get_32();
switch (objtype) {
-
case OBJECT_EMPTY: {
//do none
@@ -384,7 +360,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
WARN_PRINT("Broken external resource! (index out of size)");
r_v = Variant();
} else {
-
if (external_resources[erindex].cache.is_null()) {
//cache not here yet, wait for it?
if (use_sub_threads) {
@@ -393,10 +368,8 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
if (err != OK || external_resources[erindex].cache.is_null()) {
if (!ResourceLoader::get_abort_on_missing_resources()) {
-
ResourceLoader::notify_dependency_error(local_path, external_resources[erindex].path, external_resources[erindex].type);
} else {
-
error = ERR_FILE_MISSING_DEPENDENCIES;
ERR_FAIL_V_MSG(error, "Can't load dependency: " + external_resources[erindex].path + ".");
}
@@ -409,23 +382,19 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
default: {
-
ERR_FAIL_V(ERR_FILE_CORRUPT);
} break;
}
} break;
case VARIANT_CALLABLE: {
-
r_v = Callable();
} break;
case VARIANT_SIGNAL: {
-
r_v = Signal();
} break;
case VARIANT_DICTIONARY: {
-
uint32_t len = f->get_32();
Dictionary d; //last bit means shared
len &= 0x7FFFFFFF;
@@ -441,7 +410,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
r_v = d;
} break;
case VARIANT_ARRAY: {
-
uint32_t len = f->get_32();
Array a; //last bit means shared
len &= 0x7FFFFFFF;
@@ -456,7 +424,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_RAW_ARRAY: {
-
uint32_t len = f->get_32();
Vector<uint8_t> array;
@@ -469,7 +436,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_INT32_ARRAY: {
-
uint32_t len = f->get_32();
Vector<int32_t> array;
@@ -480,7 +446,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
{
uint32_t *ptr = (uint32_t *)w.ptr();
for (int i = 0; i < len; i++) {
-
ptr[i] = BSWAP32(ptr[i]);
}
}
@@ -490,7 +455,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
r_v = array;
} break;
case VARIANT_INT64_ARRAY: {
-
uint32_t len = f->get_32();
Vector<int64_t> array;
@@ -501,7 +465,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
{
uint64_t *ptr = (uint64_t *)w.ptr();
for (int i = 0; i < len; i++) {
-
ptr[i] = BSWAP64(ptr[i]);
}
}
@@ -511,7 +474,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
r_v = array;
} break;
case VARIANT_FLOAT32_ARRAY: {
-
uint32_t len = f->get_32();
Vector<float> array;
@@ -522,7 +484,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
{
uint32_t *ptr = (uint32_t *)w.ptr();
for (int i = 0; i < len; i++) {
-
ptr[i] = BSWAP32(ptr[i]);
}
}
@@ -532,7 +493,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
r_v = array;
} break;
case VARIANT_FLOAT64_ARRAY: {
-
uint32_t len = f->get_32();
Vector<double> array;
@@ -543,7 +503,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
{
uint64_t *ptr = (uint64_t *)w.ptr();
for (int i = 0; i < len; i++) {
-
ptr[i] = BSWAP64(ptr[i]);
}
}
@@ -553,19 +512,18 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
r_v = array;
} break;
case VARIANT_STRING_ARRAY: {
-
uint32_t len = f->get_32();
Vector<String> array;
array.resize(len);
String *w = array.ptrw();
- for (uint32_t i = 0; i < len; i++)
+ for (uint32_t i = 0; i < len; i++) {
w[i] = get_unicode_string();
+ }
r_v = array;
} break;
case VARIANT_VECTOR2_ARRAY: {
-
uint32_t len = f->get_32();
Vector<Vector2> array;
@@ -577,7 +535,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
{
uint32_t *ptr = (uint32_t *)w.ptr();
for (int i = 0; i < len * 2; i++) {
-
ptr[i] = BSWAP32(ptr[i]);
}
}
@@ -592,7 +549,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_VECTOR3_ARRAY: {
-
uint32_t len = f->get_32();
Vector<Vector3> array;
@@ -604,7 +560,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
{
uint32_t *ptr = (uint32_t *)w.ptr();
for (int i = 0; i < len * 3; i++) {
-
ptr[i] = BSWAP32(ptr[i]);
}
}
@@ -619,7 +574,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_COLOR_ARRAY: {
-
uint32_t len = f->get_32();
Vector<Color> array;
@@ -631,7 +585,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
{
uint32_t *ptr = (uint32_t *)w.ptr();
for (int i = 0; i < len * 4; i++) {
-
ptr[i] = BSWAP32(ptr[i]);
}
}
@@ -653,23 +606,21 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
}
void ResourceLoaderBinary::set_local_path(const String &p_local_path) {
-
res_path = p_local_path;
}
Ref<Resource> ResourceLoaderBinary::get_resource() {
-
return resource;
}
-Error ResourceLoaderBinary::load() {
- if (error != OK)
+Error ResourceLoaderBinary::load() {
+ if (error != OK) {
return error;
+ }
int stage = 0;
for (int i = 0; i < external_resources.size(); i++) {
-
String path = external_resources[i].path;
if (remaps.has(path)) {
@@ -688,10 +639,8 @@ Error ResourceLoaderBinary::load() {
if (external_resources[i].cache.is_null()) {
if (!ResourceLoader::get_abort_on_missing_resources()) {
-
ResourceLoader::notify_dependency_error(local_path, path, external_resources[i].type);
} else {
-
error = ERR_FILE_MISSING_DEPENDENCIES;
ERR_FAIL_V_MSG(error, "Can't load dependency: " + path + ".");
}
@@ -701,10 +650,8 @@ Error ResourceLoaderBinary::load() {
Error err = ResourceLoader::load_threaded_request(path, external_resources[i].type, use_sub_threads, local_path);
if (err != OK) {
if (!ResourceLoader::get_abort_on_missing_resources()) {
-
ResourceLoader::notify_dependency_error(local_path, path, external_resources[i].type);
} else {
-
error = ERR_FILE_MISSING_DEPENDENCIES;
ERR_FAIL_V_MSG(error, "Can't load dependency: " + path + ".");
}
@@ -715,7 +662,6 @@ Error ResourceLoaderBinary::load() {
}
for (int i = 0; i < internal_resources.size(); i++) {
-
bool main = i == (internal_resources.size() - 1);
//maybe it is loaded already
@@ -723,7 +669,6 @@ Error ResourceLoaderBinary::load() {
int subindex = 0;
if (!main) {
-
path = internal_resources[i].path;
if (path.begins_with("local://")) {
@@ -733,7 +678,6 @@ Error ResourceLoaderBinary::load() {
}
if (!use_nocache) {
-
if (ResourceCache::has(path)) {
//already loaded, don't do anything
stage++;
@@ -742,9 +686,9 @@ Error ResourceLoaderBinary::load() {
}
}
} else {
-
- if (!use_nocache && !ResourceCache::has(res_path))
+ if (!use_nocache && !ResourceCache::has(res_path)) {
path = res_path;
+ }
}
uint64_t offset = internal_resources[i].offset;
@@ -783,7 +727,6 @@ Error ResourceLoaderBinary::load() {
//set properties
for (int j = 0; j < pc; j++) {
-
StringName name = _get_string();
if (name == StringName()) {
@@ -794,8 +737,9 @@ Error ResourceLoaderBinary::load() {
Variant value;
error = parse_variant(value);
- if (error)
+ if (error) {
return error;
+ }
res->set(name, value);
}
@@ -811,7 +755,6 @@ Error ResourceLoaderBinary::load() {
resource_cache.push_back(res);
if (main) {
-
f->close();
resource = res;
resource->set_as_translation_remapped(translation_remapped);
@@ -824,19 +767,16 @@ Error ResourceLoaderBinary::load() {
}
void ResourceLoaderBinary::set_translation_remapped(bool p_remapped) {
-
translation_remapped = p_remapped;
}
static void save_ustring(FileAccess *f, const String &p_string) {
-
CharString utf8 = p_string.utf8();
f->store_32(utf8.length() + 1);
f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length() + 1);
}
static String get_ustring(FileAccess *f) {
-
int len = f->get_32();
Vector<char> str_buf;
str_buf.resize(len);
@@ -847,13 +787,13 @@ static String get_ustring(FileAccess *f) {
}
String ResourceLoaderBinary::get_unicode_string() {
-
int len = f->get_32();
if (len > str_buf.size()) {
str_buf.resize(len);
}
- if (len == 0)
+ if (len == 0) {
return String();
+ }
f->get_buffer((uint8_t *)&str_buf[0], len);
String s;
s.parse_utf8(&str_buf[0]);
@@ -861,13 +801,12 @@ String ResourceLoaderBinary::get_unicode_string() {
}
void ResourceLoaderBinary::get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types) {
-
open(p_f);
- if (error)
+ if (error) {
return;
+ }
for (int i = 0; i < external_resources.size(); i++) {
-
String dep = external_resources[i].path;
if (p_add_types && external_resources[i].type != String()) {
@@ -879,7 +818,6 @@ void ResourceLoaderBinary::get_dependencies(FileAccess *p_f, List<String> *p_dep
}
void ResourceLoaderBinary::open(FileAccess *p_f) {
-
error = OK;
f = p_f;
@@ -924,7 +862,6 @@ void ResourceLoaderBinary::open(FileAccess *p_f) {
print_bl("format: " + itos(ver_format));
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
-
f->close();
ERR_FAIL_MSG("File format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a new engine version: " + local_path + ".");
}
@@ -934,13 +871,13 @@ void ResourceLoaderBinary::open(FileAccess *p_f) {
print_bl("type: " + type);
importmd_ofs = f->get_64();
- for (int i = 0; i < 14; i++)
+ for (int i = 0; i < 14; i++) {
f->get_32(); //skip a few reserved fields
+ }
uint32_t string_table_size = f->get_32();
string_map.resize(string_table_size);
for (uint32_t i = 0; i < string_table_size; i++) {
-
StringName s = get_unicode_string();
string_map.write[i] = s;
}
@@ -949,7 +886,6 @@ void ResourceLoaderBinary::open(FileAccess *p_f) {
uint32_t ext_resources_size = f->get_32();
for (uint32_t i = 0; i < ext_resources_size; i++) {
-
ExtResource er;
er.type = get_unicode_string();
@@ -962,7 +898,6 @@ void ResourceLoaderBinary::open(FileAccess *p_f) {
uint32_t int_resources_size = f->get_32();
for (uint32_t i = 0; i < int_resources_size; i++) {
-
IntResource ir;
ir.path = get_unicode_string();
ir.offset = f->get_64();
@@ -972,7 +907,6 @@ void ResourceLoaderBinary::open(FileAccess *p_f) {
print_bl("int resources: " + itos(int_resources_size));
if (f->eof_reached()) {
-
error = ERR_FILE_CORRUPT;
f->close();
ERR_FAIL_MSG("Premature end of file (EOF): " + local_path + ".");
@@ -980,7 +914,6 @@ void ResourceLoaderBinary::open(FileAccess *p_f) {
}
String ResourceLoaderBinary::recognize(FileAccess *p_f) {
-
error = OK;
f = p_f;
@@ -1014,7 +947,6 @@ String ResourceLoaderBinary::recognize(FileAccess *p_f) {
uint32_t ver_format = f->get_32();
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
-
f->close();
return "";
}
@@ -1025,15 +957,15 @@ String ResourceLoaderBinary::recognize(FileAccess *p_f) {
}
ResourceLoaderBinary::~ResourceLoaderBinary() {
-
- if (f)
+ if (f) {
memdelete(f);
+ }
}
RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
-
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CANT_OPEN;
+ }
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
@@ -1063,7 +995,6 @@ RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_origi
}
void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
-
if (p_type == "") {
get_recognized_extensions(p_extensions);
return;
@@ -1079,8 +1010,8 @@ void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String
p_extensions->push_back(ext);
}
}
-void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_extensions) const {
+void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_extensions) const {
List<String> extensions;
ClassDB::get_resource_base_extensions(&extensions);
extensions.sort();
@@ -1092,12 +1023,10 @@ void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_exten
}
bool ResourceFormatLoaderBinary::handles_type(const String &p_type) const {
-
return true; //handles all
}
void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
-
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_MSG(!f, "Cannot open file '" + p_path + "'.");
@@ -1109,7 +1038,6 @@ void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List<Str
}
Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
-
//Error error=OK;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
@@ -1175,7 +1103,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
uint32_t ver_format = f->get_32();
if (ver_format < FORMAT_VERSION_CAN_RENAME_DEPS) {
-
memdelete(f);
memdelete(fw);
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
@@ -1207,7 +1134,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
}
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
-
memdelete(f);
memdelete(fw);
ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "File format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a new engine version: " + local_path + ".");
@@ -1236,7 +1162,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
fw->store_32(string_table_size);
for (uint32_t i = 0; i < string_table_size; i++) {
-
String s = get_ustring(f);
save_ustring(fw, s);
}
@@ -1245,7 +1170,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
uint32_t ext_resources_size = f->get_32();
fw->store_32(ext_resources_size);
for (uint32_t i = 0; i < ext_resources_size; i++) {
-
String type = get_ustring(f);
String path = get_ustring(f);
@@ -1276,7 +1200,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
fw->store_32(int_resources_size);
for (uint32_t i = 0; i < int_resources_size; i++) {
-
String path = get_ustring(f);
uint64_t offset = f->get_64();
save_ustring(fw, path);
@@ -1310,7 +1233,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
}
String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const {
-
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
return ""; //could not rwead
@@ -1329,36 +1251,30 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const
///////////////////////////////////////////////////////////
void ResourceFormatSaverBinaryInstance::_pad_buffer(FileAccess *f, int p_bytes) {
-
int extra = 4 - (p_bytes % 4);
if (extra < 4) {
- for (int i = 0; i < extra; i++)
+ for (int i = 0; i < extra; i++) {
f->store_8(0); //pad to 32
+ }
}
}
void ResourceFormatSaverBinaryInstance::_write_variant(const Variant &p_property, const PropertyInfo &p_hint) {
-
write_variant(f, p_property, resource_set, external_resources, string_map, p_hint);
}
void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Variant &p_property, Set<RES> &resource_set, Map<RES, int> &external_resources, Map<StringName, int> &string_map, const PropertyInfo &p_hint) {
-
switch (p_property.get_type()) {
-
case Variant::NIL: {
-
f->store_32(VARIANT_NIL);
// don't store anything
} break;
case Variant::BOOL: {
-
f->store_32(VARIANT_BOOL);
bool val = p_property;
f->store_32(val);
} break;
case Variant::INT: {
-
int64_t val = p_property;
if (val > 0x7FFFFFFF || val < -(int64_t)0x80000000) {
f->store_32(VARIANT_INT64);
@@ -1371,28 +1287,24 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::FLOAT: {
-
double d = p_property;
float fl = d;
if (double(fl) != d) {
f->store_32(VARIANT_DOUBLE);
f->store_double(d);
} else {
-
f->store_32(VARIANT_FLOAT);
f->store_real(fl);
}
} break;
case Variant::STRING: {
-
f->store_32(VARIANT_STRING);
String val = p_property;
save_unicode_string(f, val);
} break;
case Variant::VECTOR2: {
-
f->store_32(VARIANT_VECTOR2);
Vector2 val = p_property;
f->store_real(val.x);
@@ -1400,7 +1312,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::VECTOR2I: {
-
f->store_32(VARIANT_VECTOR2I);
Vector2i val = p_property;
f->store_32(val.x);
@@ -1408,7 +1319,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::RECT2: {
-
f->store_32(VARIANT_RECT2);
Rect2 val = p_property;
f->store_real(val.position.x);
@@ -1418,7 +1328,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::RECT2I: {
-
f->store_32(VARIANT_RECT2I);
Rect2i val = p_property;
f->store_32(val.position.x);
@@ -1428,7 +1337,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::VECTOR3: {
-
f->store_32(VARIANT_VECTOR3);
Vector3 val = p_property;
f->store_real(val.x);
@@ -1437,7 +1345,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::VECTOR3I: {
-
f->store_32(VARIANT_VECTOR3I);
Vector3i val = p_property;
f->store_32(val.x);
@@ -1446,7 +1353,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::PLANE: {
-
f->store_32(VARIANT_PLANE);
Plane val = p_property;
f->store_real(val.normal.x);
@@ -1456,7 +1362,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::QUAT: {
-
f->store_32(VARIANT_QUAT);
Quat val = p_property;
f->store_real(val.x);
@@ -1466,7 +1371,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::AABB: {
-
f->store_32(VARIANT_AABB);
AABB val = p_property;
f->store_real(val.position.x);
@@ -1478,7 +1382,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::TRANSFORM2D: {
-
f->store_32(VARIANT_MATRIX32);
Transform2D val = p_property;
f->store_real(val.elements[0].x);
@@ -1490,7 +1393,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::BASIS: {
-
f->store_32(VARIANT_MATRIX3);
Basis val = p_property;
f->store_real(val.elements[0].x);
@@ -1505,7 +1407,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::TRANSFORM: {
-
f->store_32(VARIANT_TRANSFORM);
Transform val = p_property;
f->store_real(val.basis.elements[0].x);
@@ -1523,7 +1424,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::COLOR: {
-
f->store_32(VARIANT_COLOR);
Color val = p_property;
f->store_real(val.r);
@@ -1533,7 +1433,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::STRING_NAME: {
-
f->store_32(VARIANT_STRING_NAME);
String val = p_property;
save_unicode_string(f, val);
@@ -1545,8 +1444,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
NodePath np = p_property;
f->store_16(np.get_name_count());
uint16_t snc = np.get_subname_count();
- if (np.is_absolute())
+ if (np.is_absolute()) {
snc |= 0x8000;
+ }
f->store_16(snc);
for (int i = 0; i < np.get_name_count(); i++) {
if (string_map.has(np.get_name(i))) {
@@ -1565,14 +1465,12 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::_RID: {
-
f->store_32(VARIANT_RID);
WARN_PRINT("Can't save RIDs.");
RID val = p_property;
f->store_32(val.get_id());
} break;
case Variant::OBJECT: {
-
f->store_32(VARIANT_OBJECT);
RES res = p_property;
if (res.is_null()) {
@@ -1584,7 +1482,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
f->store_32(OBJECT_EXTERNAL_RESOURCE_INDEX);
f->store_32(external_resources[res]);
} else {
-
if (!resource_set.has(res)) {
f->store_32(OBJECT_EMPTY);
ERR_FAIL_MSG("Resource was not pre cached for the resource section, most likely due to circular reference.");
@@ -1597,18 +1494,15 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::CALLABLE: {
-
f->store_32(VARIANT_CALLABLE);
WARN_PRINT("Can't save Callables.");
} break;
case Variant::SIGNAL: {
-
f->store_32(VARIANT_SIGNAL);
WARN_PRINT("Can't save Signals.");
} break;
case Variant::DICTIONARY: {
-
f->store_32(VARIANT_DICTIONARY);
Dictionary d = p_property;
f->store_32(uint32_t(d.size()));
@@ -1617,7 +1511,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
d.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
/*
if (!_check_type(dict[E->get()]))
continue;
@@ -1629,18 +1522,15 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::ARRAY: {
-
f->store_32(VARIANT_ARRAY);
Array a = p_property;
f->store_32(uint32_t(a.size()));
for (int i = 0; i < a.size(); i++) {
-
write_variant(f, a[i], resource_set, external_resources, string_map);
}
} break;
case Variant::PACKED_BYTE_ARRAY: {
-
f->store_32(VARIANT_RAW_ARRAY);
Vector<uint8_t> arr = p_property;
int len = arr.size();
@@ -1651,29 +1541,28 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::PACKED_INT32_ARRAY: {
-
f->store_32(VARIANT_INT32_ARRAY);
Vector<int32_t> arr = p_property;
int len = arr.size();
f->store_32(len);
const int32_t *r = arr.ptr();
- for (int i = 0; i < len; i++)
+ for (int i = 0; i < len; i++) {
f->store_32(r[i]);
+ }
} break;
case Variant::PACKED_INT64_ARRAY: {
-
f->store_32(VARIANT_INT64_ARRAY);
Vector<int64_t> arr = p_property;
int len = arr.size();
f->store_32(len);
const int64_t *r = arr.ptr();
- for (int i = 0; i < len; i++)
+ for (int i = 0; i < len; i++) {
f->store_64(r[i]);
+ }
} break;
case Variant::PACKED_FLOAT32_ARRAY: {
-
f->store_32(VARIANT_FLOAT32_ARRAY);
Vector<float> arr = p_property;
int len = arr.size();
@@ -1685,7 +1574,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::PACKED_FLOAT64_ARRAY: {
-
f->store_32(VARIANT_FLOAT64_ARRAY);
Vector<double> arr = p_property;
int len = arr.size();
@@ -1697,7 +1585,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::PACKED_STRING_ARRAY: {
-
f->store_32(VARIANT_STRING_ARRAY);
Vector<String> arr = p_property;
int len = arr.size();
@@ -1709,7 +1596,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::PACKED_VECTOR3_ARRAY: {
-
f->store_32(VARIANT_VECTOR3_ARRAY);
Vector<Vector3> arr = p_property;
int len = arr.size();
@@ -1723,7 +1609,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::PACKED_VECTOR2_ARRAY: {
-
f->store_32(VARIANT_VECTOR2_ARRAY);
Vector<Vector2> arr = p_property;
int len = arr.size();
@@ -1736,7 +1621,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::PACKED_COLOR_ARRAY: {
-
f->store_32(VARIANT_COLOR_ARRAY);
Vector<Color> arr = p_property;
int len = arr.size();
@@ -1751,21 +1635,19 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
default: {
-
ERR_FAIL_MSG("Invalid variant.");
}
}
}
void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant, bool p_main) {
-
switch (p_variant.get_type()) {
case Variant::OBJECT: {
-
RES res = p_variant;
- if (res.is_null() || external_resources.has(res))
+ if (res.is_null() || external_resources.has(res)) {
return;
+ }
if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) {
if (res->get_path() == path) {
@@ -1777,17 +1659,16 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
return;
}
- if (resource_set.has(res))
+ if (resource_set.has(res)) {
return;
+ }
List<PropertyInfo> property_list;
res->get_property_list(&property_list);
for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) {
-
if (E->get().usage & PROPERTY_USAGE_STORAGE) {
-
Variant value = res->get(E->get().name);
if (E->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) {
RES sres = value;
@@ -1811,11 +1692,9 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
} break;
case Variant::ARRAY: {
-
Array varray = p_variant;
int len = varray.size();
for (int i = 0; i < len; i++) {
-
const Variant &v = varray.get(i);
_find_resources(v);
}
@@ -1823,12 +1702,10 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
} break;
case Variant::DICTIONARY: {
-
Dictionary d = p_variant;
List<Variant> keys;
d.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
_find_resources(E->get());
Variant v = d[E->get()];
_find_resources(v);
@@ -1837,10 +1714,12 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
case Variant::NODE_PATH: {
//take the chance and save node path strings
NodePath np = p_variant;
- for (int i = 0; i < np.get_name_count(); i++)
+ for (int i = 0; i < np.get_name_count(); i++) {
get_string_index(np.get_name(i));
- for (int i = 0; i < np.get_subname_count(); i++)
+ }
+ for (int i = 0; i < np.get_subname_count(); i++) {
get_string_index(np.get_subname(i));
+ }
} break;
default: {
@@ -1849,7 +1728,6 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
}
void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const String &p_string, bool p_bit_on_len) {
-
CharString utf8 = p_string.utf8();
if (p_bit_on_len) {
f->store_32((utf8.length() + 1) | 0x80000000);
@@ -1860,10 +1738,10 @@ void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const
}
int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string) {
-
StringName s = p_string;
- if (string_map.has(s))
+ if (string_map.has(s)) {
return string_map[s];
+ }
string_map[s] = strings.size();
strings.push_back(s);
@@ -1871,15 +1749,15 @@ int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string)
}
Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
-
Error err;
if (p_flags & ResourceSaver::FLAG_COMPRESS) {
FileAccessCompressed *fac = memnew(FileAccessCompressed);
fac->configure("RSCC");
f = fac;
err = fac->_open(p_path, FileAccess::WRITE);
- if (err)
+ if (err) {
memdelete(f);
+ }
} else {
f = FileAccess::open(p_path, FileAccess::WRITE, &err);
@@ -1893,8 +1771,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
big_endian = p_flags & ResourceSaver::FLAG_SAVE_BIG_ENDIAN;
takeover_paths = p_flags & ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
- if (!p_path.begins_with("res://"))
+ if (!p_path.begins_with("res://")) {
takeover_paths = false;
+ }
local_path = p_path.get_base_dir();
path = ProjectSettings::get_singleton()->localize_path(p_path);
@@ -1910,8 +1789,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
if (big_endian) {
f->store_32(1);
f->set_endian_swap(true);
- } else
+ } else {
f->store_32(0);
+ }
f->store_32(0); //64 bits file, false for now
f->store_32(VERSION_MAJOR);
@@ -1926,15 +1806,14 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
save_unicode_string(f, p_resource->get_class());
f->store_64(0); //offset to import metadata
- for (int i = 0; i < 14; i++)
+ for (int i = 0; i < 14; i++) {
f->store_32(0); // reserved
+ }
List<ResourceData> resources;
{
-
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
-
ResourceData &rd = resources.push_back(ResourceData())->get();
rd.type = E->get()->get_class();
@@ -1942,9 +1821,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
E->get()->get_property_list(&property_list);
for (List<PropertyInfo>::Element *F = property_list.front(); F; F = F->next()) {
-
- if (skip_editor && F->get().name.begins_with("__editor"))
+ if (skip_editor && F->get().name.begins_with("__editor")) {
continue;
+ }
if ((F->get().usage & PROPERTY_USAGE_STORAGE)) {
Property p;
p.name_idx = get_string_index(F->get().name);
@@ -1989,7 +1868,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
}
for (int i = 0; i < save_order.size(); i++) {
-
save_unicode_string(f, save_order[i]->get_save_class());
String path = save_order[i]->get_path();
path = relative_paths ? local_path.path_to_file(path) : path;
@@ -2001,10 +1879,8 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
Set<int> used_indices;
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
-
RES r = E->get();
if (r->get_path() == "" || r->get_path().find("::") != -1) {
-
if (r->get_subindex() != 0) {
if (used_indices.has(r->get_subindex())) {
r->set_subindex(0); //repeated
@@ -2016,7 +1892,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
}
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
-
RES r = E->get();
if (r->get_path() == "" || r->get_path().find("::") != -1) {
if (r->get_subindex() == 0) {
@@ -2047,7 +1922,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
//now actually save the resources
for (List<ResourceData>::Element *E = resources.front(); E; E = E->next()) {
-
ResourceData &rd = E->get();
ofs_table.push_back(f->get_position());
@@ -2055,7 +1929,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
f->store_32(rd.properties.size());
for (List<Property>::Element *F = rd.properties.front(); F; F = F->next()) {
-
Property &p = F->get();
f->store_32(p.name_idx);
_write_variant(p.value, F->get().pi);
@@ -2084,23 +1957,21 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
}
Error ResourceFormatSaverBinary::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
-
String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
ResourceFormatSaverBinaryInstance saver;
return saver.save(local_path, p_resource, p_flags);
}
bool ResourceFormatSaverBinary::recognize(const RES &p_resource) const {
-
return true; //all recognized
}
void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
-
String base = p_resource->get_base_extension().to_lower();
p_extensions->push_back(base);
- if (base != "res")
+ if (base != "res") {
p_extensions->push_back("res");
+ }
}
ResourceFormatSaverBinary *ResourceFormatSaverBinary::singleton = nullptr;
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index 57aa086022..54cddca49e 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -36,7 +36,6 @@
#include "core/os/file_access.h"
class ResourceLoaderBinary {
-
bool translation_remapped = false;
String local_path;
String res_path;
@@ -114,7 +113,6 @@ public:
};
class ResourceFormatSaverBinaryInstance {
-
String local_path;
String path;
@@ -147,7 +145,6 @@ class ResourceFormatSaverBinaryInstance {
};
struct ResourceData {
-
String type;
List<Property> properties;
};
diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp
index 9e22bdced7..9ed159bd20 100644
--- a/core/io/resource_importer.cpp
+++ b/core/io/resource_importer.cpp
@@ -38,7 +38,6 @@ bool ResourceFormatImporter::SortImporterByName::operator()(const Ref<ResourceIm
}
Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid) const {
-
Error err;
FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err);
@@ -64,7 +63,6 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy
String error_text;
bool path_found = false; //first match must have priority
while (true) {
-
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();
@@ -118,14 +116,13 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy
}
RES ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
-
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
if (err != OK) {
-
- if (r_error)
+ if (r_error) {
*r_error = err;
+ }
return RES();
}
@@ -143,7 +140,6 @@ RES ResourceFormatImporter::load(const String &p_path, const String &p_original_
}
void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const {
-
Set<String> found;
for (int i = 0; i < importers.size(); i++) {
@@ -159,7 +155,6 @@ void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extension
}
void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
-
if (p_type == "") {
get_recognized_extensions(p_extensions);
return;
@@ -169,11 +164,13 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_
for (int i = 0; i < importers.size(); i++) {
String res_type = importers[i]->get_resource_type();
- if (res_type == String())
+ if (res_type == String()) {
continue;
+ }
- if (!ClassDB::is_parent_class(res_type, p_type))
+ if (!ClassDB::is_parent_class(res_type, p_type)) {
continue;
+ }
List<String> local_exts;
importers[i]->get_recognized_extensions(&local_exts);
@@ -187,26 +184,21 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_
}
bool ResourceFormatImporter::exists(const String &p_path) const {
-
return FileAccess::exists(p_path + ".import");
}
bool ResourceFormatImporter::recognize_path(const String &p_path, const String &p_for_type) const {
-
return FileAccess::exists(p_path + ".import");
}
bool ResourceFormatImporter::can_be_imported(const String &p_path) const {
-
return ResourceFormatLoader::recognize_path(p_path);
}
int ResourceFormatImporter::get_import_order(const String &p_path) const {
-
Ref<ResourceImporter> importer;
if (FileAccess::exists(p_path + ".import")) {
-
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
@@ -214,37 +206,35 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const {
importer = get_importer_by_name(pat.importer);
}
} else {
-
importer = get_importer_by_extension(p_path.get_extension().to_lower());
}
- if (importer.is_valid())
+ if (importer.is_valid()) {
return importer->get_import_order();
+ }
return 0;
}
bool ResourceFormatImporter::handles_type(const String &p_type) const {
-
for (int i = 0; i < importers.size(); i++) {
-
String res_type = importers[i]->get_resource_type();
- if (res_type == String())
+ if (res_type == String()) {
continue;
- if (ClassDB::is_parent_class(res_type, p_type))
+ }
+ if (ClassDB::is_parent_class(res_type, p_type)) {
return true;
+ }
}
return true;
}
String ResourceFormatImporter::get_internal_resource_path(const String &p_path) const {
-
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
if (err != OK) {
-
return String();
}
@@ -252,12 +242,12 @@ String ResourceFormatImporter::get_internal_resource_path(const String &p_path)
}
void ResourceFormatImporter::get_internal_resource_path_list(const String &p_path, List<String> *r_paths) {
-
Error err;
FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err);
- if (!f)
+ if (!f) {
return;
+ }
VariantParser::StreamFile stream;
stream.f = f;
@@ -269,7 +259,6 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat
int lines = 0;
String error_text;
while (true) {
-
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();
@@ -298,7 +287,6 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat
}
String ResourceFormatImporter::get_import_group_file(const String &p_path) const {
-
bool valid = true;
PathAndType pat;
_get_path_and_type(p_path, pat, &valid);
@@ -306,7 +294,6 @@ String ResourceFormatImporter::get_import_group_file(const String &p_path) const
}
bool ResourceFormatImporter::is_import_valid(const String &p_path) const {
-
bool valid = true;
PathAndType pat;
_get_path_and_type(p_path, pat, &valid);
@@ -314,12 +301,10 @@ bool ResourceFormatImporter::is_import_valid(const String &p_path) const {
}
String ResourceFormatImporter::get_resource_type(const String &p_path) const {
-
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
if (err != OK) {
-
return "";
}
@@ -331,7 +316,6 @@ Variant ResourceFormatImporter::get_resource_metadata(const String &p_path) cons
Error err = _get_path_and_type(p_path, pat);
if (err != OK) {
-
return Variant();
}
@@ -339,12 +323,10 @@ Variant ResourceFormatImporter::get_resource_metadata(const String &p_path) cons
}
void ResourceFormatImporter::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
-
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
if (err != OK) {
-
return;
}
@@ -352,7 +334,6 @@ void ResourceFormatImporter::get_dependencies(const String &p_path, List<String>
}
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String &p_name) const {
-
for (int i = 0; i < importers.size(); i++) {
if (importers[i]->get_importer_name() == p_name) {
return importers[i];
@@ -363,7 +344,6 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String
}
void ResourceFormatImporter::get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter>> *r_importers) {
-
for (int i = 0; i < importers.size(); i++) {
List<String> local_exts;
importers[i]->get_recognized_extensions(&local_exts);
@@ -376,12 +356,10 @@ void ResourceFormatImporter::get_importers_for_extension(const String &p_extensi
}
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) const {
-
Ref<ResourceImporter> importer;
float priority = 0;
for (int i = 0; i < importers.size(); i++) {
-
List<String> local_exts;
importers[i]->get_recognized_extensions(&local_exts);
for (List<String>::Element *F = local_exts.front(); F; F = F->next()) {
@@ -396,12 +374,10 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const St
}
String ResourceFormatImporter::get_import_base_path(const String &p_for_file) const {
-
return "res://.import/" + p_for_file.get_file() + "-" + p_for_file.md5_text();
}
bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) const {
-
bool valid = true;
PathAndType pat;
_get_path_and_type(p_path, pat, &valid);
@@ -422,7 +398,6 @@ bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) con
}
String ResourceFormatImporter::get_import_settings_hash() const {
-
Vector<Ref<ResourceImporter>> sorted_importers = importers;
sorted_importers.sort_custom<SortImporterByName>();
diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h
index 6b76912494..d31a9a0194 100644
--- a/core/io/resource_importer.h
+++ b/core/io/resource_importer.h
@@ -36,7 +36,6 @@
class ResourceImporter;
class ResourceFormatImporter : public ResourceFormatLoader {
-
struct PathAndType {
String path;
String type;
@@ -93,7 +92,6 @@ public:
};
class ResourceImporter : public Reference {
-
GDCLASS(ResourceImporter, Reference);
public:
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index dc44be4e0b..f9d2c9067c 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -49,7 +49,6 @@ Ref<ResourceFormatLoader> ResourceLoader::loader[ResourceLoader::MAX_LOADERS];
int ResourceLoader::loader_count = 0;
bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_for_type) const {
-
String extension = p_path.get_extension();
List<String> extensions;
@@ -60,16 +59,15 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_
}
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
-
- if (E->get().nocasecmp_to(extension) == 0)
+ if (E->get().nocasecmp_to(extension) == 0) {
return true;
+ }
}
return false;
}
bool ResourceFormatLoader::handles_type(const String &p_type) const {
-
if (get_script_instance() && get_script_instance()->has_method("handles_type")) {
// I guess custom loaders for custom resources should use "Resource"
return get_script_instance()->call("handles_type", p_type);
@@ -79,7 +77,6 @@ bool ResourceFormatLoader::handles_type(const String &p_type) const {
}
String ResourceFormatLoader::get_resource_type(const String &p_path) const {
-
if (get_script_instance() && get_script_instance()->has_method("get_resource_type")) {
return get_script_instance()->call("get_resource_type", p_path);
}
@@ -88,13 +85,12 @@ String ResourceFormatLoader::get_resource_type(const String &p_path) const {
}
void ResourceFormatLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
-
- if (p_type == "" || handles_type(p_type))
+ if (p_type == "" || handles_type(p_type)) {
get_recognized_extensions(p_extensions);
+ }
}
void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) {
-
for (int i = 0; i < loader_count; i++) {
loader[i]->get_recognized_extensions_for_type(p_type, p_extensions);
}
@@ -105,7 +101,6 @@ bool ResourceFormatLoader::exists(const String &p_path) const {
}
void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) const {
-
if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) {
PackedStringArray exts = get_script_instance()->call("get_recognized_extensions");
@@ -119,19 +114,18 @@ void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions)
}
RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
-
if (get_script_instance() && get_script_instance()->has_method("load")) {
Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads);
if (res.get_type() == Variant::INT) {
-
- if (r_error)
+ if (r_error) {
*r_error = (Error)res.operator int64_t();
+ }
} else {
-
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return res;
}
@@ -142,7 +136,6 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa
}
void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
-
if (get_script_instance() && get_script_instance()->has_method("get_dependencies")) {
PackedStringArray deps = get_script_instance()->call("get_dependencies", p_path, p_add_types);
@@ -156,9 +149,7 @@ void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *
}
Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
-
if (get_script_instance() && get_script_instance()->has_method("rename_dependencies")) {
-
Dictionary deps_dict;
for (Map<String, String>::Element *E = p_map.front(); E; E = E->next()) {
deps_dict[E->key()] = E->value();
@@ -172,7 +163,6 @@ Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map<
}
void ResourceFormatLoader::_bind_methods() {
-
{
MethodInfo info = MethodInfo(Variant::NIL, "load", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "original_path"));
info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
@@ -189,12 +179,10 @@ void ResourceFormatLoader::_bind_methods() {
///////////////////////////////////
RES ResourceLoader::_load(const String &p_path, const String &p_original_path, const String &p_type_hint, bool p_no_cache, Error *r_error, bool p_use_sub_threads, float *r_progress) {
-
bool found = false;
// Try all loaders and pick the first match for the type hint
for (int i = 0; i < loader_count; i++) {
-
if (!loader[i]->recognize_path(p_path, p_type_hint)) {
continue;
}
@@ -218,7 +206,6 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c
}
void ResourceLoader::_thread_load_function(void *p_userdata) {
-
ThreadLoadTask &load_task = *(ThreadLoadTask *)p_userdata;
load_task.loader_id = Thread::get_caller_id();
@@ -237,7 +224,6 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
load_task.status = THREAD_LOAD_LOADED;
}
if (load_task.semaphore) {
-
if (load_task.start_next && thread_waiting_count > 0) {
thread_waiting_count--;
//thread loading count remains constant, this ends but another one begins
@@ -258,8 +244,9 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
if (load_task.resource.is_valid()) {
load_task.resource->set_path(load_task.local_path);
- if (load_task.xl_remapped)
+ if (load_task.xl_remapped) {
load_task.resource->set_as_translation_remapped(true);
+ }
#ifdef TOOLS_ENABLED
@@ -278,13 +265,14 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
thread_load_mutex->unlock();
}
-Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, const String &p_source_resource) {
+Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, const String &p_source_resource) {
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
thread_load_mutex->lock();
@@ -387,7 +375,6 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String &
}
float ResourceLoader::_dependency_get_progress(const String &p_path) {
-
if (thread_load_tasks.has(p_path)) {
ThreadLoadTask &load_task = thread_load_tasks[p_path];
int dep_count = load_task.sub_tasks.size();
@@ -410,12 +397,12 @@ float ResourceLoader::_dependency_get_progress(const String &p_path) {
}
ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, float *r_progress) {
-
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
thread_load_mutex->lock();
if (!thread_load_tasks.has(local_path)) {
@@ -433,13 +420,14 @@ ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const
return status;
}
-RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) {
+RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) {
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
thread_load_mutex->lock();
if (!thread_load_tasks.has(local_path)) {
@@ -516,18 +504,18 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) {
}
RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
-
- if (r_error)
+ if (r_error) {
*r_error = ERR_CANT_OPEN;
+ }
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
if (!p_no_cache) {
-
thread_load_mutex->lock();
//Is it already being loaded? poll until done
@@ -592,7 +580,6 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
return load_threaded_get(p_path, r_error);
} else {
-
bool xl_remapped = false;
String path = _path_remap(local_path, &xl_remapped);
@@ -609,8 +596,9 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
return RES();
}
- if (xl_remapped)
+ if (xl_remapped) {
res->set_as_translation_remapped(true);
+ }
#ifdef TOOLS_ENABLED
@@ -627,15 +615,14 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
}
bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
-
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
if (ResourceCache::has(local_path)) {
-
return true; // If cached, it probably exists
}
@@ -644,20 +631,19 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
// Try all loaders and pick the first match for the type hint
for (int i = 0; i < loader_count; i++) {
-
if (!loader[i]->recognize_path(path, p_type_hint)) {
continue;
}
- if (loader[i]->exists(path))
+ if (loader[i]->exists(path)) {
return true;
+ }
}
return false;
}
void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader, bool p_at_front) {
-
ERR_FAIL_COND(p_format_loader.is_null());
ERR_FAIL_COND(loader_count >= MAX_LOADERS);
@@ -673,14 +659,14 @@ void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_form
}
void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader) {
-
ERR_FAIL_COND(p_format_loader.is_null());
// Find loader
int i = 0;
for (; i < loader_count; ++i) {
- if (loader[i] == p_format_loader)
+ if (loader[i] == p_format_loader) {
break;
+ }
}
ERR_FAIL_COND(i >= loader_count); // Not found
@@ -694,19 +680,19 @@ void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_f
}
int ResourceLoader::get_import_order(const String &p_path) {
-
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
-
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -722,15 +708,16 @@ String ResourceLoader::get_import_group_file(const String &p_path) {
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
-
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -743,19 +730,19 @@ String ResourceLoader::get_import_group_file(const String &p_path) {
}
bool ResourceLoader::is_import_valid(const String &p_path) {
-
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
-
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -768,19 +755,19 @@ bool ResourceLoader::is_import_valid(const String &p_path) {
}
bool ResourceLoader::is_imported(const String &p_path) {
-
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
-
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -793,19 +780,19 @@ bool ResourceLoader::is_imported(const String &p_path) {
}
void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
-
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
-
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -816,19 +803,19 @@ void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_depe
}
Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
-
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
-
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -841,15 +828,14 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String
}
String ResourceLoader::get_resource_type(const String &p_path) {
-
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
for (int i = 0; i < loader_count; i++) {
-
String result = loader[i]->get_resource_type(local_path);
if (result != "") {
return result;
@@ -860,7 +846,6 @@ String ResourceLoader::get_resource_type(const String &p_path) {
}
String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_remapped) {
-
String new_path = p_path;
if (translation_remaps.has(p_path)) {
@@ -919,7 +904,6 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
FileAccess *f = FileAccess::open(p_path + ".remap", FileAccess::READ, &err);
if (f) {
-
VariantParser::StreamFile stream;
stream.f = f;
@@ -930,7 +914,6 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
int lines = 0;
String error_text;
while (true) {
-
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();
@@ -959,9 +942,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
}
String ResourceLoader::import_remap(const String &p_path) {
-
if (ResourceFormatImporter::get_singleton()->recognize_path(p_path)) {
-
return ResourceFormatImporter::get_singleton()->get_internal_resource_path(p_path);
}
@@ -973,7 +954,6 @@ String ResourceLoader::path_remap(const String &p_path) {
}
void ResourceLoader::reload_translation_remaps() {
-
if (ResourceCache::lock) {
ResourceCache::lock->read_lock();
}
@@ -998,15 +978,14 @@ void ResourceLoader::reload_translation_remaps() {
}
void ResourceLoader::load_translation_remaps() {
-
- if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
+ if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
return;
+ }
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
List<Variant> keys;
remaps.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
Array langs = remaps[E->get()];
Vector<String> lang_remaps;
lang_remaps.resize(langs.size());
@@ -1023,9 +1002,9 @@ void ResourceLoader::clear_translation_remaps() {
}
void ResourceLoader::load_path_remaps() {
-
- if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths"))
+ if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) {
return;
+ }
Vector<String> remaps = ProjectSettings::get_singleton()->get("path_remap/remapped_paths");
int rc = remaps.size();
@@ -1033,13 +1012,11 @@ void ResourceLoader::load_path_remaps() {
const String *r = remaps.ptr();
for (int i = 0; i < rc; i += 2) {
-
path_remaps[r[i]] = r[i + 1];
}
}
void ResourceLoader::clear_path_remaps() {
-
path_remaps.clear();
}
@@ -1059,9 +1036,9 @@ Ref<ResourceFormatLoader> ResourceLoader::_find_custom_resource_format_loader(St
}
bool ResourceLoader::add_custom_resource_format_loader(String script_path) {
-
- if (_find_custom_resource_format_loader(script_path).is_valid())
+ if (_find_custom_resource_format_loader(script_path).is_valid()) {
return false;
+ }
Ref<Resource> res = ResourceLoader::load(script_path);
ERR_FAIL_COND_V(res.is_null(), false);
@@ -1084,10 +1061,10 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) {
}
void ResourceLoader::remove_custom_resource_format_loader(String script_path) {
-
Ref<ResourceFormatLoader> custom_loader = _find_custom_resource_format_loader(script_path);
- if (custom_loader.is_valid())
+ if (custom_loader.is_valid()) {
remove_resource_format_loader(custom_loader);
+ }
}
void ResourceLoader::add_custom_loaders() {
@@ -1099,7 +1076,6 @@ void ResourceLoader::add_custom_loaders() {
ScriptServer::get_global_class_list(&global_classes);
for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
-
StringName class_name = E->get();
StringName base_class = ScriptServer::get_global_class_native_base(class_name);
@@ -1111,7 +1087,6 @@ void ResourceLoader::add_custom_loaders() {
}
void ResourceLoader::remove_custom_loaders() {
-
Vector<Ref<ResourceFormatLoader>> custom_loaders;
for (int i = 0; i < loader_count; ++i) {
if (loader[i]->get_script_instance()) {
@@ -1134,7 +1109,6 @@ void ResourceLoader::initialize() {
}
void ResourceLoader::finalize() {
-
memdelete(thread_load_mutex);
memdelete(thread_load_semaphore);
}
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index b10c08d693..9322b5273a 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -36,7 +36,6 @@
#include "core/resource.h"
class ResourceFormatLoader : public Reference {
-
GDCLASS(ResourceFormatLoader, Reference);
protected:
@@ -67,7 +66,6 @@ typedef Error (*ResourceLoaderImport)(const String &p_path);
typedef void (*ResourceLoadedCallback)(RES p_resource, const String &p_path);
class ResourceLoader {
-
enum {
MAX_LOADERS = 64
};
@@ -160,8 +158,9 @@ public:
static bool get_timestamp_on_load() { return timestamp_on_load; }
static void notify_load_error(const String &p_err) {
- if (err_notify)
+ if (err_notify) {
err_notify(err_notify_ud, p_err);
+ }
}
static void set_error_notify_func(void *p_ud, ResourceLoadErrorNotify p_err_notify) {
err_notify = p_err_notify;
@@ -169,8 +168,9 @@ public:
}
static void notify_dependency_error(const String &p_path, const String &p_dependency, const String &p_type) {
- if (dep_err_notify)
+ if (dep_err_notify) {
dep_err_notify(dep_err_notify_ud, p_path, p_dependency, p_type);
+ }
}
static void set_dependency_error_notify_func(void *p_ud, DependencyErrorNotify p_err_notify) {
dep_err_notify = p_err_notify;
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index 09128adb50..a8da215b61 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -41,7 +41,6 @@ bool ResourceSaver::timestamp_on_save = false;
ResourceSavedCallback ResourceSaver::save_callback = nullptr;
Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
-
if (get_script_instance() && get_script_instance()->has_method("save")) {
return (Error)get_script_instance()->call("save", p_path, p_resource, p_flags).operator int64_t();
}
@@ -50,7 +49,6 @@ Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uin
}
bool ResourceFormatSaver::recognize(const RES &p_resource) const {
-
if (get_script_instance() && get_script_instance()->has_method("recognize")) {
return get_script_instance()->call("recognize", p_resource);
}
@@ -59,7 +57,6 @@ bool ResourceFormatSaver::recognize(const RES &p_resource) const {
}
void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
-
if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) {
PackedStringArray exts = get_script_instance()->call("get_recognized_extensions", p_resource);
@@ -73,7 +70,6 @@ void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<
}
void ResourceFormatSaver::_bind_methods() {
-
{
PropertyInfo arg0 = PropertyInfo(Variant::STRING, "path");
PropertyInfo arg1 = PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource");
@@ -86,40 +82,40 @@ void ResourceFormatSaver::_bind_methods() {
}
Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
-
String extension = p_path.get_extension();
Error err = ERR_FILE_UNRECOGNIZED;
for (int i = 0; i < saver_count; i++) {
-
- if (!saver[i]->recognize(p_resource))
+ if (!saver[i]->recognize(p_resource)) {
continue;
+ }
List<String> extensions;
bool recognized = false;
saver[i]->get_recognized_extensions(p_resource, &extensions);
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
-
- if (E->get().nocasecmp_to(extension) == 0)
+ if (E->get().nocasecmp_to(extension) == 0) {
recognized = true;
+ }
}
- if (!recognized)
+ if (!recognized) {
continue;
+ }
String old_path = p_resource->get_path();
String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
RES rwcopy = p_resource;
- if (p_flags & FLAG_CHANGE_PATH)
+ if (p_flags & FLAG_CHANGE_PATH) {
rwcopy->set_path(local_path);
+ }
err = saver[i]->save(p_path, p_resource, p_flags);
if (err == OK) {
-
#ifdef TOOLS_ENABLED
((Resource *)p_resource.ptr())->set_edited(false);
@@ -130,11 +126,13 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t
}
#endif
- if (p_flags & FLAG_CHANGE_PATH)
+ if (p_flags & FLAG_CHANGE_PATH) {
rwcopy->set_path(old_path);
+ }
- if (save_callback && p_path.begins_with("res://"))
+ if (save_callback && p_path.begins_with("res://")) {
save_callback(p_resource, p_path);
+ }
return OK;
}
@@ -144,20 +142,16 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t
}
void ResourceSaver::set_save_callback(ResourceSavedCallback p_callback) {
-
save_callback = p_callback;
}
void ResourceSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) {
-
for (int i = 0; i < saver_count; i++) {
-
saver[i]->get_recognized_extensions(p_resource, p_extensions);
}
}
void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front) {
-
ERR_FAIL_COND_MSG(p_format_saver.is_null(), "It's not a reference to a valid ResourceFormatSaver object.");
ERR_FAIL_COND(saver_count >= MAX_SAVERS);
@@ -173,14 +167,14 @@ void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_
}
void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver) {
-
ERR_FAIL_COND_MSG(p_format_saver.is_null(), "It's not a reference to a valid ResourceFormatSaver object.");
// Find saver
int i = 0;
for (; i < saver_count; ++i) {
- if (saver[i] == p_format_saver)
+ if (saver[i] == p_format_saver) {
break;
+ }
}
ERR_FAIL_COND(i >= saver_count); // Not found
@@ -203,9 +197,9 @@ Ref<ResourceFormatSaver> ResourceSaver::_find_custom_resource_format_saver(Strin
}
bool ResourceSaver::add_custom_resource_format_saver(String script_path) {
-
- if (_find_custom_resource_format_saver(script_path).is_valid())
+ if (_find_custom_resource_format_saver(script_path).is_valid()) {
return false;
+ }
Ref<Resource> res = ResourceLoader::load(script_path);
ERR_FAIL_COND_V(res.is_null(), false);
@@ -228,10 +222,10 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) {
}
void ResourceSaver::remove_custom_resource_format_saver(String script_path) {
-
Ref<ResourceFormatSaver> custom_saver = _find_custom_resource_format_saver(script_path);
- if (custom_saver.is_valid())
+ if (custom_saver.is_valid()) {
remove_resource_format_saver(custom_saver);
+ }
}
void ResourceSaver::add_custom_savers() {
@@ -243,7 +237,6 @@ void ResourceSaver::add_custom_savers() {
ScriptServer::get_global_class_list(&global_classes);
for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
-
StringName class_name = E->get();
StringName base_class = ScriptServer::get_global_class_native_base(class_name);
@@ -255,7 +248,6 @@ void ResourceSaver::add_custom_savers() {
}
void ResourceSaver::remove_custom_savers() {
-
Vector<Ref<ResourceFormatSaver>> custom_savers;
for (int i = 0; i < saver_count; ++i) {
if (saver[i]->get_script_instance()) {
diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h
index 2ddebf0581..8b4cdd86f8 100644
--- a/core/io/resource_saver.h
+++ b/core/io/resource_saver.h
@@ -50,7 +50,6 @@ public:
typedef void (*ResourceSavedCallback)(Ref<Resource> p_resource, const String &p_path);
class ResourceSaver {
-
enum {
MAX_SAVERS = 64
};
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index 9bbe92096d..403f61bb24 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -33,16 +33,15 @@
#include "core/io/marshalls.h"
Error StreamPeer::_put_data(const Vector<uint8_t> &p_data) {
-
int len = p_data.size();
- if (len == 0)
+ if (len == 0) {
return OK;
+ }
const uint8_t *r = p_data.ptr();
return put_data(&r[0], len);
}
Array StreamPeer::_put_partial_data(const Vector<uint8_t> &p_data) {
-
Array ret;
int len = p_data.size();
@@ -65,13 +64,11 @@ Array StreamPeer::_put_partial_data(const Vector<uint8_t> &p_data) {
}
Array StreamPeer::_get_data(int p_bytes) {
-
Array ret;
Vector<uint8_t> data;
data.resize(p_bytes);
if (data.size() != p_bytes) {
-
ret.push_back(ERR_OUT_OF_MEMORY);
ret.push_back(Vector<uint8_t>());
return ret;
@@ -86,13 +83,11 @@ Array StreamPeer::_get_data(int p_bytes) {
}
Array StreamPeer::_get_partial_data(int p_bytes) {
-
Array ret;
Vector<uint8_t> data;
data.resize(p_bytes);
if (data.size() != p_bytes) {
-
ret.push_back(ERR_OUT_OF_MEMORY);
ret.push_back(Vector<uint8_t>());
return ret;
@@ -105,7 +100,6 @@ Array StreamPeer::_get_partial_data(int p_bytes) {
if (err != OK) {
data.resize(0);
} else if (received != data.size()) {
-
data.resize(received);
}
@@ -115,12 +109,10 @@ Array StreamPeer::_get_partial_data(int p_bytes) {
}
void StreamPeer::set_big_endian(bool p_enable) {
-
big_endian = p_enable;
}
bool StreamPeer::is_big_endian_enabled() const {
-
return big_endian;
}
@@ -129,11 +121,10 @@ void StreamPeer::put_u8(uint8_t p_val) {
}
void StreamPeer::put_8(int8_t p_val) {
-
put_data((const uint8_t *)&p_val, 1);
}
-void StreamPeer::put_u16(uint16_t p_val) {
+void StreamPeer::put_u16(uint16_t p_val) {
if (big_endian) {
p_val = BSWAP16(p_val);
}
@@ -141,8 +132,8 @@ void StreamPeer::put_u16(uint16_t p_val) {
encode_uint16(p_val, buf);
put_data(buf, 2);
}
-void StreamPeer::put_16(int16_t p_val) {
+void StreamPeer::put_16(int16_t p_val) {
if (big_endian) {
p_val = BSWAP16(p_val);
}
@@ -150,8 +141,8 @@ void StreamPeer::put_16(int16_t p_val) {
encode_uint16(p_val, buf);
put_data(buf, 2);
}
-void StreamPeer::put_u32(uint32_t p_val) {
+void StreamPeer::put_u32(uint32_t p_val) {
if (big_endian) {
p_val = BSWAP32(p_val);
}
@@ -159,8 +150,8 @@ void StreamPeer::put_u32(uint32_t p_val) {
encode_uint32(p_val, buf);
put_data(buf, 4);
}
-void StreamPeer::put_32(int32_t p_val) {
+void StreamPeer::put_32(int32_t p_val) {
if (big_endian) {
p_val = BSWAP32(p_val);
}
@@ -168,8 +159,8 @@ void StreamPeer::put_32(int32_t p_val) {
encode_uint32(p_val, buf);
put_data(buf, 4);
}
-void StreamPeer::put_u64(uint64_t p_val) {
+void StreamPeer::put_u64(uint64_t p_val) {
if (big_endian) {
p_val = BSWAP64(p_val);
}
@@ -177,8 +168,8 @@ void StreamPeer::put_u64(uint64_t p_val) {
encode_uint64(p_val, buf);
put_data(buf, 8);
}
-void StreamPeer::put_64(int64_t p_val) {
+void StreamPeer::put_64(int64_t p_val) {
if (big_endian) {
p_val = BSWAP64(p_val);
}
@@ -186,8 +177,8 @@ void StreamPeer::put_64(int64_t p_val) {
encode_uint64(p_val, buf);
put_data(buf, 8);
}
-void StreamPeer::put_float(float p_val) {
+void StreamPeer::put_float(float p_val) {
uint8_t buf[4];
encode_float(p_val, buf);
@@ -198,8 +189,8 @@ void StreamPeer::put_float(float p_val) {
put_data(buf, 4);
}
-void StreamPeer::put_double(double p_val) {
+void StreamPeer::put_double(double p_val) {
uint8_t buf[8];
encode_double(p_val, buf);
if (big_endian) {
@@ -208,20 +199,20 @@ void StreamPeer::put_double(double p_val) {
}
put_data(buf, 8);
}
-void StreamPeer::put_string(const String &p_string) {
+void StreamPeer::put_string(const String &p_string) {
CharString cs = p_string.ascii();
put_u32(cs.length());
put_data((const uint8_t *)cs.get_data(), cs.length());
}
-void StreamPeer::put_utf8_string(const String &p_string) {
+void StreamPeer::put_utf8_string(const String &p_string) {
CharString cs = p_string.utf8();
put_u32(cs.length());
put_data((const uint8_t *)cs.get_data(), cs.length());
}
-void StreamPeer::put_var(const Variant &p_variant, bool p_full_objects) {
+void StreamPeer::put_var(const Variant &p_variant, bool p_full_objects) {
int len = 0;
Vector<uint8_t> buf;
encode_variant(p_variant, nullptr, len, p_full_objects);
@@ -232,19 +223,18 @@ void StreamPeer::put_var(const Variant &p_variant, bool p_full_objects) {
}
uint8_t StreamPeer::get_u8() {
-
uint8_t buf[1];
get_data(buf, 1);
return buf[0];
}
-int8_t StreamPeer::get_8() {
+int8_t StreamPeer::get_8() {
uint8_t buf[1];
get_data(buf, 1);
return buf[0];
}
-uint16_t StreamPeer::get_u16() {
+uint16_t StreamPeer::get_u16() {
uint8_t buf[2];
get_data(buf, 2);
uint16_t r = decode_uint16(buf);
@@ -253,8 +243,8 @@ uint16_t StreamPeer::get_u16() {
}
return r;
}
-int16_t StreamPeer::get_16() {
+int16_t StreamPeer::get_16() {
uint8_t buf[2];
get_data(buf, 2);
uint16_t r = decode_uint16(buf);
@@ -263,8 +253,8 @@ int16_t StreamPeer::get_16() {
}
return r;
}
-uint32_t StreamPeer::get_u32() {
+uint32_t StreamPeer::get_u32() {
uint8_t buf[4];
get_data(buf, 4);
uint32_t r = decode_uint32(buf);
@@ -273,8 +263,8 @@ uint32_t StreamPeer::get_u32() {
}
return r;
}
-int32_t StreamPeer::get_32() {
+int32_t StreamPeer::get_32() {
uint8_t buf[4];
get_data(buf, 4);
uint32_t r = decode_uint32(buf);
@@ -283,8 +273,8 @@ int32_t StreamPeer::get_32() {
}
return r;
}
-uint64_t StreamPeer::get_u64() {
+uint64_t StreamPeer::get_u64() {
uint8_t buf[8];
get_data(buf, 8);
uint64_t r = decode_uint64(buf);
@@ -293,8 +283,8 @@ uint64_t StreamPeer::get_u64() {
}
return r;
}
-int64_t StreamPeer::get_64() {
+int64_t StreamPeer::get_64() {
uint8_t buf[8];
get_data(buf, 8);
uint64_t r = decode_uint64(buf);
@@ -303,8 +293,8 @@ int64_t StreamPeer::get_64() {
}
return r;
}
-float StreamPeer::get_float() {
+float StreamPeer::get_float() {
uint8_t buf[4];
get_data(buf, 4);
@@ -317,7 +307,6 @@ float StreamPeer::get_float() {
}
double StreamPeer::get_double() {
-
uint8_t buf[8];
get_data(buf, 8);
@@ -328,10 +317,11 @@ double StreamPeer::get_double() {
return decode_double(buf);
}
-String StreamPeer::get_string(int p_bytes) {
- if (p_bytes < 0)
+String StreamPeer::get_string(int p_bytes) {
+ if (p_bytes < 0) {
p_bytes = get_u32();
+ }
ERR_FAIL_COND_V(p_bytes < 0, String());
Vector<char> buf;
@@ -342,10 +332,11 @@ String StreamPeer::get_string(int p_bytes) {
buf.write[p_bytes] = 0;
return buf.ptr();
}
-String StreamPeer::get_utf8_string(int p_bytes) {
- if (p_bytes < 0)
+String StreamPeer::get_utf8_string(int p_bytes) {
+ if (p_bytes < 0) {
p_bytes = get_u32();
+ }
ERR_FAIL_COND_V(p_bytes < 0, String());
Vector<uint8_t> buf;
@@ -358,8 +349,8 @@ String StreamPeer::get_utf8_string(int p_bytes) {
ret.parse_utf8((const char *)buf.ptr(), buf.size());
return ret;
}
-Variant StreamPeer::get_var(bool p_allow_objects) {
+Variant StreamPeer::get_var(bool p_allow_objects) {
int len = get_32();
Vector<uint8_t> var;
Error err = var.resize(len);
@@ -375,7 +366,6 @@ Variant StreamPeer::get_var(bool p_allow_objects) {
}
void StreamPeer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("put_data", "data"), &StreamPeer::_put_data);
ClassDB::bind_method(D_METHOD("put_partial_data", "data"), &StreamPeer::_put_partial_data);
@@ -417,10 +407,10 @@ void StreamPeer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "big_endian"), "set_big_endian", "is_big_endian_enabled");
}
+
////////////////////////////////
void StreamPeerBuffer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("seek", "position"), &StreamPeerBuffer::seek);
ClassDB::bind_method(D_METHOD("get_size"), &StreamPeerBuffer::get_size);
ClassDB::bind_method(D_METHOD("get_position"), &StreamPeerBuffer::get_position);
@@ -434,9 +424,9 @@ void StreamPeerBuffer::_bind_methods() {
}
Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) {
-
- if (p_bytes <= 0)
+ if (p_bytes <= 0) {
return OK;
+ }
if (pointer + p_bytes > data.size()) {
data.resize(pointer + p_bytes);
@@ -450,23 +440,21 @@ Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) {
}
Error StreamPeerBuffer::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) {
-
r_sent = p_bytes;
return put_data(p_data, p_bytes);
}
Error StreamPeerBuffer::get_data(uint8_t *p_buffer, int p_bytes) {
-
int recv;
get_partial_data(p_buffer, p_bytes, recv);
- if (recv != p_bytes)
+ if (recv != p_bytes) {
return ERR_INVALID_PARAMETER;
+ }
return OK;
}
Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
-
if (pointer + p_bytes > data.size()) {
r_received = data.size() - pointer;
if (r_received <= 0) {
@@ -487,50 +475,42 @@ Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_
}
int StreamPeerBuffer::get_available_bytes() const {
-
return data.size() - pointer;
}
void StreamPeerBuffer::seek(int p_pos) {
-
ERR_FAIL_COND(p_pos < 0);
ERR_FAIL_COND(p_pos > data.size());
pointer = p_pos;
}
-int StreamPeerBuffer::get_size() const {
+int StreamPeerBuffer::get_size() const {
return data.size();
}
int StreamPeerBuffer::get_position() const {
-
return pointer;
}
void StreamPeerBuffer::resize(int p_size) {
-
data.resize(p_size);
}
void StreamPeerBuffer::set_data_array(const Vector<uint8_t> &p_data) {
-
data = p_data;
pointer = 0;
}
Vector<uint8_t> StreamPeerBuffer::get_data_array() const {
-
return data;
}
void StreamPeerBuffer::clear() {
-
data.resize(0);
pointer = 0;
}
Ref<StreamPeerBuffer> StreamPeerBuffer::duplicate() const {
-
Ref<StreamPeerBuffer> spb;
spb.instance();
spb->data = data;
diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h
index a390fdc325..ec0b989ed8 100644
--- a/core/io/stream_peer.h
+++ b/core/io/stream_peer.h
@@ -93,7 +93,6 @@ public:
};
class StreamPeerBuffer : public StreamPeer {
-
GDCLASS(StreamPeerBuffer, StreamPeer);
Vector<uint8_t> data;
diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp
index 1d86c35578..3dc31c6769 100644
--- a/core/io/stream_peer_ssl.cpp
+++ b/core/io/stream_peer_ssl.cpp
@@ -35,9 +35,9 @@
StreamPeerSSL *(*StreamPeerSSL::_create)() = nullptr;
StreamPeerSSL *StreamPeerSSL::create() {
-
- if (_create)
+ if (_create) {
return _create();
+ }
return nullptr;
}
@@ -56,7 +56,6 @@ bool StreamPeerSSL::is_blocking_handshake_enabled() const {
}
void StreamPeerSSL::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("poll"), &StreamPeerSSL::poll);
ClassDB::bind_method(D_METHOD("accept_stream", "stream", "private_key", "certificate", "chain"), &StreamPeerSSL::accept_stream, DEFVAL(Ref<X509Certificate>()));
ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "validate_certs", "for_hostname", "valid_certificate"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String()), DEFVAL(Ref<X509Certificate>()));
diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp
index 6218b98758..cce728c30a 100644
--- a/core/io/stream_peer_tcp.cpp
+++ b/core/io/stream_peer_tcp.cpp
@@ -33,7 +33,6 @@
#include "core/project_settings.h"
Error StreamPeerTCP::_poll_connection() {
-
ERR_FAIL_COND_V(status != STATUS_CONNECTING || !_sock.is_valid() || !_sock->is_open(), FAILED);
Error err = _sock->connect_to_host(peer_host, peer_port);
@@ -58,7 +57,6 @@ Error StreamPeerTCP::_poll_connection() {
}
void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port) {
-
_sock = p_sock;
_sock->set_blocking_enabled(false);
@@ -70,7 +68,6 @@ void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint
}
Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port) {
-
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER);
@@ -103,18 +100,14 @@ Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port)
}
Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block) {
-
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
if (status == STATUS_NONE || status == STATUS_ERROR) {
-
return FAILED;
}
if (status != STATUS_CONNECTED) {
-
if (_poll_connection() != OK) {
-
return FAILED;
}
@@ -124,8 +117,9 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool
}
}
- if (!_sock->is_open())
+ if (!_sock->is_open()) {
return FAILED;
+ }
Error err;
int data_to_send = p_bytes;
@@ -133,12 +127,10 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool
int total_sent = 0;
while (data_to_send) {
-
int sent_amount = 0;
err = _sock->send(offset, data_to_send, sent_amount);
if (err != OK) {
-
if (err != ERR_BUSY) {
disconnect_from_host();
return FAILED;
@@ -156,7 +148,6 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool
return FAILED;
}
} else {
-
data_to_send -= sent_amount;
offset += sent_amount;
total_sent += sent_amount;
@@ -169,16 +160,12 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool
}
Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) {
-
if (!is_connected_to_host()) {
-
return FAILED;
}
if (status == STATUS_CONNECTING) {
-
if (_poll_connection() != OK) {
-
return FAILED;
}
@@ -194,12 +181,10 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool
r_received = 0;
while (to_read) {
-
int read = 0;
err = _sock->recv(p_buffer + total_read, to_read, read);
if (err != OK) {
-
if (err != ERR_BUSY) {
disconnect_from_host();
return FAILED;
@@ -218,13 +203,11 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool
}
} else if (read == 0) {
-
disconnect_from_host();
r_received = total_read;
return ERR_FILE_EOF;
} else {
-
to_read -= read;
total_read += read;
@@ -241,18 +224,15 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool
}
void StreamPeerTCP::set_no_delay(bool p_enabled) {
-
ERR_FAIL_COND(!is_connected_to_host());
_sock->set_tcp_no_delay_enabled(p_enabled);
}
bool StreamPeerTCP::is_connected_to_host() const {
-
return _sock.is_valid() && _sock->is_open() && (status == STATUS_CONNECTED || status == STATUS_CONNECTING);
}
StreamPeerTCP::Status StreamPeerTCP::get_status() {
-
if (status == STATUS_CONNECTING) {
_poll_connection();
} else if (status == STATUS_CONNECTED) {
@@ -278,9 +258,9 @@ StreamPeerTCP::Status StreamPeerTCP::get_status() {
}
void StreamPeerTCP::disconnect_from_host() {
-
- if (_sock.is_valid() && _sock->is_open())
+ if (_sock.is_valid() && _sock->is_open()) {
_sock->close();
+ }
timeout = 0;
status = STATUS_NONE;
@@ -294,59 +274,51 @@ Error StreamPeerTCP::poll(NetSocket::PollType p_type, int timeout) {
}
Error StreamPeerTCP::put_data(const uint8_t *p_data, int p_bytes) {
-
int total;
return write(p_data, p_bytes, total, true);
}
Error StreamPeerTCP::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) {
-
return write(p_data, p_bytes, r_sent, false);
}
Error StreamPeerTCP::get_data(uint8_t *p_buffer, int p_bytes) {
-
int total;
return read(p_buffer, p_bytes, total, true);
}
Error StreamPeerTCP::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
-
return read(p_buffer, p_bytes, r_received, false);
}
int StreamPeerTCP::get_available_bytes() const {
-
ERR_FAIL_COND_V(!_sock.is_valid(), -1);
return _sock->get_available_bytes();
}
IP_Address StreamPeerTCP::get_connected_host() const {
-
return peer_host;
}
uint16_t StreamPeerTCP::get_connected_port() const {
-
return peer_port;
}
Error StreamPeerTCP::_connect(const String &p_address, int p_port) {
-
IP_Address ip;
if (p_address.is_valid_ip_address()) {
ip = p_address;
} else {
ip = IP::get_singleton()->resolve_hostname(p_address);
- if (!ip.is_valid())
+ if (!ip.is_valid()) {
return ERR_CANT_RESOLVE;
+ }
}
return connect_to_host(ip, p_port);
}
void StreamPeerTCP::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port"), &StreamPeerTCP::_connect);
ClassDB::bind_method(D_METHOD("is_connected_to_host"), &StreamPeerTCP::is_connected_to_host);
ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerTCP::get_status);
@@ -366,6 +338,5 @@ StreamPeerTCP::StreamPeerTCP() :
}
StreamPeerTCP::~StreamPeerTCP() {
-
disconnect_from_host();
}
diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h
index 571f6b7c54..ab98d494d6 100644
--- a/core/io/stream_peer_tcp.h
+++ b/core/io/stream_peer_tcp.h
@@ -37,7 +37,6 @@
#include "core/io/stream_peer.h"
class StreamPeerTCP : public StreamPeer {
-
GDCLASS(StreamPeerTCP, StreamPeer);
OBJ_CATEGORY("Networking");
diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp
index 69c2ba7943..d7061b6bf4 100644
--- a/core/io/tcp_server.cpp
+++ b/core/io/tcp_server.cpp
@@ -31,7 +31,6 @@
#include "tcp_server.h"
void TCP_Server::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCP_Server::listen, DEFVAL("*"));
ClassDB::bind_method(D_METHOD("is_connection_available"), &TCP_Server::is_connection_available);
ClassDB::bind_method(D_METHOD("is_listening"), &TCP_Server::is_listening);
@@ -40,7 +39,6 @@ void TCP_Server::_bind_methods() {
}
Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) {
-
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
@@ -49,8 +47,9 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) {
IP::Type ip_type = IP::TYPE_ANY;
// If the bind address is valid use its type as the socket type
- if (p_bind_address.is_valid())
+ if (p_bind_address.is_valid()) {
ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
+ }
err = _sock->open(NetSocket::TYPE_TCP, ip_type);
@@ -62,7 +61,6 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) {
err = _sock->bind(p_bind_address, p_port);
if (err != OK) {
-
_sock->close();
return ERR_ALREADY_IN_USE;
}
@@ -83,18 +81,17 @@ bool TCP_Server::is_listening() const {
}
bool TCP_Server::is_connection_available() const {
-
ERR_FAIL_COND_V(!_sock.is_valid(), false);
- if (!_sock->is_open())
+ if (!_sock->is_open()) {
return false;
+ }
Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0);
return (err == OK);
}
Ref<StreamPeerTCP> TCP_Server::take_connection() {
-
Ref<StreamPeerTCP> conn;
if (!is_connection_available()) {
return conn;
@@ -104,8 +101,9 @@ Ref<StreamPeerTCP> TCP_Server::take_connection() {
IP_Address ip;
uint16_t port = 0;
ns = _sock->accept(ip, port);
- if (!ns.is_valid())
+ if (!ns.is_valid()) {
return conn;
+ }
conn = Ref<StreamPeerTCP>(memnew(StreamPeerTCP));
conn->accept_socket(ns, ip, port);
@@ -113,7 +111,6 @@ Ref<StreamPeerTCP> TCP_Server::take_connection() {
}
void TCP_Server::stop() {
-
if (_sock.is_valid()) {
_sock->close();
}
@@ -124,6 +121,5 @@ TCP_Server::TCP_Server() :
}
TCP_Server::~TCP_Server() {
-
stop();
}
diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h
index ca52b13ba1..eb715a745c 100644
--- a/core/io/tcp_server.h
+++ b/core/io/tcp_server.h
@@ -37,7 +37,6 @@
#include "core/io/stream_peer_tcp.h"
class TCP_Server : public Reference {
-
GDCLASS(TCP_Server, Reference);
protected:
diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp
index 6f79e2554b..0e0a948953 100644
--- a/core/io/translation_loader_po.cpp
+++ b/core/io/translation_loader_po.cpp
@@ -34,7 +34,6 @@
#include "core/translation.h"
RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
-
enum Status {
STATUS_NONE,
@@ -48,8 +47,9 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
String msg_str;
String config;
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CORRUPT;
+ }
Ref<Translation> translation = Ref<Translation>(memnew(Translation));
int line = 1;
@@ -58,13 +58,11 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
bool is_eof = false;
while (!is_eof) {
-
String l = f->get_line().strip_edges();
is_eof = f->eof_reached();
// If we reached last line and it's not a content line, break, otherwise let processing that last loop
if (is_eof && l.empty()) {
-
if (status == STATUS_READING_ID) {
memdelete(f);
ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected EOF while reading 'msgid' at file: ");
@@ -74,18 +72,18 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
}
if (l.begins_with("msgid")) {
-
if (status == STATUS_READING_ID) {
-
memdelete(f);
ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected 'msgid', was expecting 'msgstr' while parsing: ");
}
if (msg_id != "") {
- if (!skip_this)
+ if (!skip_this) {
translation->add_message(msg_id, msg_str);
- } else if (config == "")
+ }
+ } else if (config == "") {
config = msg_str;
+ }
l = l.substr(5, l.length()).strip_edges();
status = STATUS_READING_ID;
@@ -96,9 +94,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
}
if (l.begins_with("msgstr")) {
-
if (status != STATUS_READING_ID) {
-
memdelete(f);
ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected 'msgstr', was expecting 'msgid' while parsing: ");
}
@@ -142,10 +138,11 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
l = l.substr(0, end_pos);
l = l.c_unescape();
- if (status == STATUS_READING_ID)
+ if (status == STATUS_READING_ID) {
msg_id += l;
- else
+ } else {
msg_str += l;
+ }
line++;
}
@@ -154,23 +151,24 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
memdelete(f);
if (status == STATUS_READING_STRING) {
-
if (msg_id != "") {
- if (!skip_this)
+ if (!skip_this) {
translation->add_message(msg_id, msg_str);
- } else if (config == "")
+ }
+ } else if (config == "") {
config = msg_str;
+ }
}
ERR_FAIL_COND_V_MSG(config == "", RES(), "No config found in file: " + f->get_path() + ".");
Vector<String> configs = config.split("\n");
for (int i = 0; i < configs.size(); i++) {
-
String c = configs[i].strip_edges();
int p = c.find(":");
- if (p == -1)
+ if (p == -1) {
continue;
+ }
String prop = c.substr(0, p).strip_edges();
String value = c.substr(p + 1, c.length()).strip_edges();
@@ -179,16 +177,17 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
}
}
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return translation;
}
RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
-
- if (r_error)
+ if (r_error) {
*r_error = ERR_CANT_OPEN;
+ }
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_V_MSG(!f, RES(), "Cannot open file '" + p_path + "'.");
@@ -197,18 +196,17 @@ RES TranslationLoaderPO::load(const String &p_path, const String &p_original_pat
}
void TranslationLoaderPO::get_recognized_extensions(List<String> *p_extensions) const {
-
p_extensions->push_back("po");
//p_extensions->push_back("mo"); //mo in the future...
}
-bool TranslationLoaderPO::handles_type(const String &p_type) const {
+bool TranslationLoaderPO::handles_type(const String &p_type) const {
return (p_type == "Translation");
}
String TranslationLoaderPO::get_resource_type(const String &p_path) const {
-
- if (p_path.get_extension().to_lower() == "po")
+ if (p_path.get_extension().to_lower() == "po") {
return "Translation";
+ }
return "";
}
diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp
index 16b7863cdd..1d329daf8b 100644
--- a/core/io/udp_server.cpp
+++ b/core/io/udp_server.cpp
@@ -31,7 +31,6 @@
#include "udp_server.h"
void UDPServer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &UDPServer::listen, DEFVAL("*"));
ClassDB::bind_method(D_METHOD("is_connection_available"), &UDPServer::is_connection_available);
ClassDB::bind_method(D_METHOD("is_listening"), &UDPServer::is_listening);
@@ -40,7 +39,6 @@ void UDPServer::_bind_methods() {
}
Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) {
-
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
@@ -48,13 +46,15 @@ Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) {
Error err;
IP::Type ip_type = IP::TYPE_ANY;
- if (p_bind_address.is_valid())
+ if (p_bind_address.is_valid()) {
ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
+ }
err = _sock->open(NetSocket::TYPE_UDP, ip_type);
- if (err != OK)
+ if (err != OK) {
return ERR_CANT_CREATE;
+ }
_sock->set_blocking_enabled(false);
_sock->set_reuse_address_enabled(true);
@@ -76,18 +76,17 @@ bool UDPServer::is_listening() const {
}
bool UDPServer::is_connection_available() const {
-
ERR_FAIL_COND_V(!_sock.is_valid(), false);
- if (!_sock->is_open())
+ if (!_sock->is_open()) {
return false;
+ }
Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0);
return (err == OK);
}
Ref<PacketPeerUDP> UDPServer::take_connection() {
-
Ref<PacketPeerUDP> conn;
if (!is_connection_available()) {
return conn;
@@ -101,7 +100,6 @@ Ref<PacketPeerUDP> UDPServer::take_connection() {
}
void UDPServer::stop() {
-
if (_sock.is_valid()) {
_sock->close();
}
@@ -114,6 +112,5 @@ UDPServer::UDPServer() :
}
UDPServer::~UDPServer() {
-
stop();
}
diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp
index a4b64bf17c..11f82fef9d 100644
--- a/core/io/xml_parser.cpp
+++ b/core/io/xml_parser.cpp
@@ -38,9 +38,11 @@ VARIANT_ENUM_CAST(XMLParser::NodeType);
static bool _equalsn(const CharType *str1, const CharType *str2, int len) {
int i;
- for (i = 0; i < len && str1[i] && str2[i]; ++i)
- if (str1[i] != str2[i])
+ for (i = 0; i < len && str1[i] && str2[i]; ++i) {
+ if (str1[i] != str2[i]) {
return false;
+ }
+ }
// if one (or both) of the strings was smaller then they
// are only equal if they have the same length
@@ -48,12 +50,12 @@ static bool _equalsn(const CharType *str1, const CharType *str2, int len) {
}
String XMLParser::_replace_special_characters(const String &origstr) {
-
int pos = origstr.find("&");
int oldPos = 0;
- if (pos == -1)
+ if (pos == -1) {
return origstr;
+ }
String newstr;
@@ -84,8 +86,9 @@ String XMLParser::_replace_special_characters(const String &origstr) {
pos = origstr.find("&", pos);
}
- if (oldPos < origstr.length() - 1)
+ if (oldPos < origstr.length() - 1) {
newstr += (origstr.substr(oldPos, origstr.length() - oldPos));
+ }
return newstr;
}
@@ -100,12 +103,15 @@ bool XMLParser::_set_text(char *start, char *end) {
// only white space, so that this text won't be reported
if (end - start < 3) {
char *p = start;
- for (; p != end; ++p)
- if (!_is_white_space(*p))
+ for (; p != end; ++p) {
+ if (!_is_white_space(*p)) {
break;
+ }
+ }
- if (p == end)
+ if (p == end) {
return false;
+ }
}
// set current text to the parsed text, and replace xml special characters
@@ -126,8 +132,9 @@ void XMLParser::_parse_closing_xml_element() {
++P;
const char *pBeginClose = P;
- while (*P != '>')
+ while (*P != '>') {
++P;
+ }
node_name = String::utf8(pBeginClose, (int)(P - pBeginClose));
#ifdef DEBUG_XML
@@ -141,16 +148,17 @@ void XMLParser::_ignore_definition() {
char *F = P;
// move until end marked with '>' reached
- while (*P != '>')
+ while (*P != '>') {
++P;
+ }
node_name.parse_utf8(F, P - F);
++P;
}
bool XMLParser::_parse_cdata() {
-
- if (*(P + 1) != '[')
+ if (*(P + 1) != '[') {
return false;
+ }
node_type = NODE_CDATA;
@@ -161,8 +169,9 @@ bool XMLParser::_parse_cdata() {
++count;
}
- if (!*P)
+ if (!*P) {
return true;
+ }
char *cDataBegin = P;
char *cDataEnd = nullptr;
@@ -178,10 +187,11 @@ bool XMLParser::_parse_cdata() {
++P;
}
- if (cDataEnd)
+ if (cDataEnd) {
node_name = String::utf8(cDataBegin, (int)(cDataEnd - cDataBegin));
- else
+ } else {
node_name = "";
+ }
#ifdef DEBUG_XML
print_line("XML CDATA: " + node_name);
#endif
@@ -190,7 +200,6 @@ bool XMLParser::_parse_cdata() {
}
void XMLParser::_parse_comment() {
-
node_type = NODE_COMMENT;
P += 1;
@@ -200,10 +209,11 @@ void XMLParser::_parse_comment() {
// move until end of comment reached
while (count) {
- if (*P == '>')
+ if (*P == '>') {
--count;
- else if (*P == '<')
+ } else if (*P == '<') {
++count;
+ }
++P;
}
@@ -217,7 +227,6 @@ void XMLParser::_parse_comment() {
}
void XMLParser::_parse_opening_xml_element() {
-
node_type = NODE_ELEMENT;
node_empty = false;
attributes.clear();
@@ -226,46 +235,52 @@ void XMLParser::_parse_opening_xml_element() {
const char *startName = P;
// find end of element
- while (*P != '>' && !_is_white_space(*P))
+ while (*P != '>' && !_is_white_space(*P)) {
++P;
+ }
const char *endName = P;
// find attributes
while (*P != '>') {
- if (_is_white_space(*P))
+ if (_is_white_space(*P)) {
++P;
- else {
+ } else {
if (*P != '/') {
// we've got an attribute
// read the attribute names
const char *attributeNameBegin = P;
- while (!_is_white_space(*P) && *P != '=')
+ while (!_is_white_space(*P) && *P != '=') {
++P;
+ }
const char *attributeNameEnd = P;
++P;
// read the attribute value
// check for quotes and single quotes, thx to murphy
- while ((*P != '\"') && (*P != '\'') && *P)
+ while ((*P != '\"') && (*P != '\'') && *P) {
++P;
+ }
- if (!*P) // malformatted xml file
+ if (!*P) { // malformatted xml file
return;
+ }
const char attributeQuoteChar = *P;
++P;
const char *attributeValueBegin = P;
- while (*P != attributeQuoteChar && *P)
+ while (*P != attributeQuoteChar && *P) {
++P;
+ }
- if (!*P) // malformatted xml file
+ if (!*P) { // malformatted xml file
return;
+ }
const char *attributeValueEnd = P;
++P;
@@ -304,21 +319,23 @@ void XMLParser::_parse_opening_xml_element() {
}
void XMLParser::_parse_current_node() {
-
char *start = P;
node_offset = P - data;
// more forward until '<' found
- while (*P != '<' && *P)
+ while (*P != '<' && *P) {
++P;
+ }
- if (!*P)
+ if (!*P) {
return;
+ }
if (P - start > 0) {
// we found some text, store it
- if (_set_text(start, P))
+ if (_set_text(start, P)) {
return;
+ }
}
++P;
@@ -332,8 +349,9 @@ void XMLParser::_parse_current_node() {
_ignore_definition();
break;
case '!':
- if (!_parse_cdata())
+ if (!_parse_cdata()) {
_parse_comment();
+ }
break;
default:
_parse_opening_xml_element();
@@ -342,12 +360,10 @@ void XMLParser::_parse_current_node() {
}
uint64_t XMLParser::get_node_offset() const {
-
return node_offset;
};
Error XMLParser::seek(uint64_t p_pos) {
-
ERR_FAIL_COND_V(!data, ERR_FILE_EOF);
ERR_FAIL_COND_V(p_pos >= length, ERR_FILE_EOF);
@@ -357,7 +373,6 @@ Error XMLParser::seek(uint64_t p_pos) {
};
void XMLParser::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("read"), &XMLParser::read);
ClassDB::bind_method(D_METHOD("get_node_type"), &XMLParser::get_node_type);
ClassDB::bind_method(D_METHOD("get_node_name"), &XMLParser::get_node_name);
@@ -386,7 +401,6 @@ void XMLParser::_bind_methods() {
};
Error XMLParser::read() {
-
// if not end reached, parse the node
if (P && (P - data) < (int64_t)length - 1 && *P != 0) {
_parse_current_node();
@@ -397,11 +411,10 @@ Error XMLParser::read() {
}
XMLParser::NodeType XMLParser::get_node_type() {
-
return node_type;
}
-String XMLParser::get_node_data() const {
+String XMLParser::get_node_data() const {
ERR_FAIL_COND_V(node_type != NODE_TEXT, "");
return node_name;
}
@@ -410,31 +423,32 @@ String XMLParser::get_node_name() const {
ERR_FAIL_COND_V(node_type == NODE_TEXT, "");
return node_name;
}
-int XMLParser::get_attribute_count() const {
+int XMLParser::get_attribute_count() const {
return attributes.size();
}
-String XMLParser::get_attribute_name(int p_idx) const {
+String XMLParser::get_attribute_name(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, attributes.size(), "");
return attributes[p_idx].name;
}
-String XMLParser::get_attribute_value(int p_idx) const {
+String XMLParser::get_attribute_value(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, attributes.size(), "");
return attributes[p_idx].value;
}
-bool XMLParser::has_attribute(const String &p_name) const {
+bool XMLParser::has_attribute(const String &p_name) const {
for (int i = 0; i < attributes.size(); i++) {
- if (attributes[i].name == p_name)
+ if (attributes[i].name == p_name) {
return true;
+ }
}
return false;
}
-String XMLParser::get_attribute_value(const String &p_name) const {
+String XMLParser::get_attribute_value(const String &p_name) const {
int idx = -1;
for (int i = 0; i < attributes.size(); i++) {
if (attributes[i].name == p_name) {
@@ -449,7 +463,6 @@ String XMLParser::get_attribute_value(const String &p_name) const {
}
String XMLParser::get_attribute_value_safe(const String &p_name) const {
-
int idx = -1;
for (int i = 0; i < attributes.size(); i++) {
if (attributes[i].name == p_name) {
@@ -458,17 +471,17 @@ String XMLParser::get_attribute_value_safe(const String &p_name) const {
}
}
- if (idx < 0)
+ if (idx < 0) {
return "";
+ }
return attributes[idx].value;
}
-bool XMLParser::is_empty() const {
+bool XMLParser::is_empty() const {
return node_empty;
}
Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) {
-
ERR_FAIL_COND_V(p_buffer.size() == 0, ERR_INVALID_DATA);
if (data) {
@@ -484,7 +497,6 @@ Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) {
}
Error XMLParser::open(const String &p_path) {
-
Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::READ, &err);
@@ -508,10 +520,10 @@ Error XMLParser::open(const String &p_path) {
}
void XMLParser::skip_section() {
-
// skip if this element is empty anyway.
- if (is_empty())
+ if (is_empty()) {
return;
+ }
// read until we've reached the last element in this section
int tagcount = 1;
@@ -520,15 +532,16 @@ void XMLParser::skip_section() {
if (get_node_type() == XMLParser::NODE_ELEMENT &&
!is_empty()) {
++tagcount;
- } else if (get_node_type() == XMLParser::NODE_ELEMENT_END)
+ } else if (get_node_type() == XMLParser::NODE_ELEMENT_END) {
--tagcount;
+ }
}
}
void XMLParser::close() {
-
- if (data)
+ if (data) {
memdelete_arr(data);
+ }
data = nullptr;
length = 0;
P = nullptr;
@@ -538,7 +551,6 @@ void XMLParser::close() {
}
int XMLParser::get_current_line() const {
-
return 0;
}
@@ -549,8 +561,9 @@ XMLParser::XMLParser() {
special_characters.push_back("\"quot;");
special_characters.push_back("'apos;");
}
-XMLParser::~XMLParser() {
- if (data)
+XMLParser::~XMLParser() {
+ if (data) {
memdelete_arr(data);
+ }
}
diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h
index 42b7d6e0d4..ee2174d52c 100644
--- a/core/io/xml_parser.h
+++ b/core/io/xml_parser.h
@@ -41,7 +41,6 @@
*/
class XMLParser : public Reference {
-
GDCLASS(XMLParser, Reference);
public:
diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp
index 3a2a207d22..1979e91b8c 100644
--- a/core/io/zip_io.cpp
+++ b/core/io/zip_io.cpp
@@ -33,7 +33,6 @@
#include "core/os/copymem.h"
void *zipio_open(void *data, const char *p_fname, int mode) {
-
FileAccess *&f = *(FileAccess **)data;
String fname;
@@ -42,42 +41,37 @@ void *zipio_open(void *data, const char *p_fname, int mode) {
if (mode & ZLIB_FILEFUNC_MODE_WRITE) {
f = FileAccess::open(fname, FileAccess::WRITE);
} else {
-
f = FileAccess::open(fname, FileAccess::READ);
}
- if (!f)
+ if (!f) {
return nullptr;
+ }
return data;
}
uLong zipio_read(void *data, void *fdata, void *buf, uLong size) {
-
FileAccess *f = *(FileAccess **)data;
return f->get_buffer((uint8_t *)buf, size);
}
uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size) {
-
FileAccess *f = *(FileAccess **)opaque;
f->store_buffer((uint8_t *)buf, size);
return size;
}
long zipio_tell(voidpf opaque, voidpf stream) {
-
FileAccess *f = *(FileAccess **)opaque;
return f->get_position();
}
long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
-
FileAccess *f = *(FileAccess **)opaque;
int pos = offset;
switch (origin) {
-
case ZLIB_FILEFUNC_SEEK_CUR:
pos = f->get_position() + offset;
break;
@@ -93,7 +87,6 @@ long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
}
int zipio_close(voidpf opaque, voidpf stream) {
-
FileAccess *&f = *(FileAccess **)opaque;
if (f) {
f->close();
@@ -104,25 +97,21 @@ int zipio_close(voidpf opaque, voidpf stream) {
}
int zipio_testerror(voidpf opaque, voidpf stream) {
-
FileAccess *f = *(FileAccess **)opaque;
return (f && f->get_error() != OK) ? 1 : 0;
}
voidpf zipio_alloc(voidpf opaque, uInt items, uInt size) {
-
voidpf ptr = memalloc(items * size);
zeromem(ptr, items * size);
return ptr;
}
void zipio_free(voidpf opaque, voidpf address) {
-
memfree(address);
}
zlib_filefunc_def zipio_create_io_from_file(FileAccess **p_file) {
-
zlib_filefunc_def io;
io.opaque = p_file;
io.zopen_file = zipio_open;
diff --git a/core/list.h b/core/list.h
index 7fbf3e50fc..86e4a45036 100644
--- a/core/list.h
+++ b/core/list.h
@@ -49,7 +49,6 @@ class List {
public:
class Element {
-
private:
friend class List<T, A>;
@@ -63,14 +62,12 @@ public:
* Get NEXT Element iterator, for constant lists.
*/
_FORCE_INLINE_ const Element *next() const {
-
return next_ptr;
};
/**
* Get NEXT Element iterator,
*/
_FORCE_INLINE_ Element *next() {
-
return next_ptr;
};
@@ -78,14 +75,12 @@ public:
* Get PREV Element iterator, for constant lists.
*/
_FORCE_INLINE_ const Element *prev() const {
-
return prev_ptr;
};
/**
* Get PREV Element iterator,
*/
_FORCE_INLINE_ Element *prev() {
-
return prev_ptr;
};
@@ -99,7 +94,6 @@ public:
* operator->, for using as iterator->, when iterators are defined on stack, for constant lists.
*/
_FORCE_INLINE_ const T *operator->() const {
-
return &value;
};
/**
@@ -135,7 +129,6 @@ public:
};
void erase() {
-
data->erase(this);
}
@@ -144,13 +137,11 @@ public:
private:
struct _Data {
-
Element *first;
Element *last;
int size_cache;
bool erase(const Element *p_I) {
-
ERR_FAIL_COND_V(!p_I, false);
ERR_FAIL_COND_V(p_I->data != this, false);
@@ -158,14 +149,17 @@ private:
first = p_I->next_ptr;
};
- if (last == p_I)
+ if (last == p_I) {
last = p_I->prev_ptr;
+ }
- if (p_I->prev_ptr)
+ if (p_I->prev_ptr) {
p_I->prev_ptr->next_ptr = p_I->next_ptr;
+ }
- if (p_I->next_ptr)
+ if (p_I->next_ptr) {
p_I->next_ptr->prev_ptr = p_I->prev_ptr;
+ }
memdelete_allocator<Element, A>(const_cast<Element *>(p_I));
size_cache--;
@@ -181,7 +175,6 @@ public:
* return a const iterator to the beginning of the list.
*/
_FORCE_INLINE_ const Element *front() const {
-
return _data ? _data->first : nullptr;
};
@@ -196,7 +189,6 @@ public:
* return a const iterator to the last member of the list.
*/
_FORCE_INLINE_ const Element *back() const {
-
return _data ? _data->last : nullptr;
};
@@ -204,7 +196,6 @@ public:
* return an iterator to the last member of the list.
*/
_FORCE_INLINE_ Element *back() {
-
return _data ? _data->last : nullptr;
};
@@ -212,9 +203,7 @@ public:
* store a new element at the end of the list
*/
Element *push_back(const T &value) {
-
if (!_data) {
-
_data = memnew_allocator(_Data, A);
_data->first = nullptr;
_data->last = nullptr;
@@ -229,14 +218,14 @@ public:
n->data = _data;
if (_data->last) {
-
_data->last->next_ptr = n;
}
_data->last = n;
- if (!_data->first)
+ if (!_data->first) {
_data->first = n;
+ }
_data->size_cache++;
@@ -244,18 +233,16 @@ public:
};
void pop_back() {
-
- if (_data && _data->last)
+ if (_data && _data->last) {
erase(_data->last);
+ }
}
/**
* store a new element at the beginning of the list
*/
Element *push_front(const T &value) {
-
if (!_data) {
-
_data = memnew_allocator(_Data, A);
_data->first = nullptr;
_data->last = nullptr;
@@ -269,14 +256,14 @@ public:
n->data = _data;
if (_data->first) {
-
_data->first->prev_ptr = n;
}
_data->first = n;
- if (!_data->last)
+ if (!_data->last) {
_data->last = n;
+ }
_data->size_cache++;
@@ -284,9 +271,9 @@ public:
};
void pop_front() {
-
- if (_data && _data->first)
+ if (_data && _data->first) {
erase(_data->first);
+ }
}
Element *insert_after(Element *p_element, const T &p_value) {
@@ -346,11 +333,11 @@ public:
*/
template <class T_v>
Element *find(const T_v &p_val) {
-
Element *it = front();
while (it) {
- if (it->value == p_val)
+ if (it->value == p_val) {
return it;
+ }
it = it->next();
};
@@ -361,7 +348,6 @@ public:
* erase an element in the list, by iterator pointing to it. Return true if it was found/erased.
*/
bool erase(const Element *p_I) {
-
if (_data) {
bool ret = _data->erase(p_I);
@@ -380,7 +366,6 @@ public:
* erase the first element in the list, that contains value
*/
bool erase(const T &value) {
-
Element *I = find(value);
return erase(I);
};
@@ -389,7 +374,6 @@ public:
* return whether the list is empty
*/
_FORCE_INLINE_ bool empty() const {
-
return (!_data || !_data->size_cache);
}
@@ -397,19 +381,16 @@ public:
* clear the list
*/
void clear() {
-
while (front()) {
erase(front());
};
};
_FORCE_INLINE_ int size() const {
-
return _data ? _data->size_cache : 0;
}
void swap(Element *p_A, Element *p_B) {
-
ERR_FAIL_COND(!p_A || !p_B);
ERR_FAIL_COND(p_A->data != _data);
ERR_FAIL_COND(p_B->data != _data);
@@ -423,32 +404,33 @@ public:
p_B->next_ptr = A_next;
p_B->prev_ptr = A_prev;
- if (p_A->prev_ptr)
+ if (p_A->prev_ptr) {
p_A->prev_ptr->next_ptr = p_A;
- if (p_A->next_ptr)
+ }
+ if (p_A->next_ptr) {
p_A->next_ptr->prev_ptr = p_A;
+ }
- if (p_B->prev_ptr)
+ if (p_B->prev_ptr) {
p_B->prev_ptr->next_ptr = p_B;
- if (p_B->next_ptr)
+ }
+ if (p_B->next_ptr) {
p_B->next_ptr->prev_ptr = p_B;
+ }
}
/**
* copy the list
*/
void operator=(const List &p_list) {
-
clear();
const Element *it = p_list.front();
while (it) {
-
push_back(it->get());
it = it->next();
}
}
T &operator[](int p_index) {
-
CRASH_BAD_INDEX(p_index, size());
Element *I = front();
@@ -462,7 +444,6 @@ public:
}
const T &operator[](int p_index) const {
-
CRASH_BAD_INDEX(p_index, size());
const Element *I = front();
@@ -476,20 +457,22 @@ public:
}
void move_to_back(Element *p_I) {
-
ERR_FAIL_COND(p_I->data != _data);
- if (!p_I->next_ptr)
+ if (!p_I->next_ptr) {
return;
+ }
if (_data->first == p_I) {
_data->first = p_I->next_ptr;
};
- if (_data->last == p_I)
+ if (_data->last == p_I) {
_data->last = p_I->prev_ptr;
+ }
- if (p_I->prev_ptr)
+ if (p_I->prev_ptr) {
p_I->prev_ptr->next_ptr = p_I->next_ptr;
+ }
p_I->next_ptr->prev_ptr = p_I->prev_ptr;
@@ -500,12 +483,10 @@ public:
}
void invert() {
-
int s = size() / 2;
Element *F = front();
Element *B = back();
for (int i = 0; i < s; i++) {
-
SWAP(F->value, B->value);
F = F->next();
B = B->prev();
@@ -513,22 +494,24 @@ public:
}
void move_to_front(Element *p_I) {
-
ERR_FAIL_COND(p_I->data != _data);
- if (!p_I->prev_ptr)
+ if (!p_I->prev_ptr) {
return;
+ }
if (_data->first == p_I) {
_data->first = p_I->next_ptr;
};
- if (_data->last == p_I)
+ if (_data->last == p_I) {
_data->last = p_I->prev_ptr;
+ }
p_I->prev_ptr->next_ptr = p_I->next_ptr;
- if (p_I->next_ptr)
+ if (p_I->next_ptr) {
p_I->next_ptr->prev_ptr = p_I->prev_ptr;
+ }
_data->first->prev_ptr = p_I;
p_I->next_ptr = _data->first;
@@ -537,7 +520,6 @@ public:
}
void move_before(Element *value, Element *where) {
-
if (value->prev_ptr) {
value->prev_ptr->next_ptr = value->next_ptr;
} else {
@@ -572,49 +554,46 @@ public:
*/
void sort() {
-
sort_custom<Comparator<T>>();
}
template <class C>
void sort_custom_inplace() {
-
- if (size() < 2)
+ if (size() < 2) {
return;
+ }
Element *from = front();
Element *current = from;
Element *to = from;
while (current) {
-
Element *next = current->next_ptr;
if (from != current) {
-
current->prev_ptr = nullptr;
current->next_ptr = from;
Element *find = from;
C less;
while (find && less(find->value, current->value)) {
-
current->prev_ptr = find;
current->next_ptr = find->next_ptr;
find = find->next_ptr;
}
- if (current->prev_ptr)
+ if (current->prev_ptr) {
current->prev_ptr->next_ptr = current;
- else
+ } else {
from = current;
+ }
- if (current->next_ptr)
+ if (current->next_ptr) {
current->next_ptr->prev_ptr = current;
- else
+ } else {
to = current;
+ }
} else {
-
current->prev_ptr = nullptr;
current->next_ptr = nullptr;
}
@@ -627,29 +606,26 @@ public:
template <class C>
struct AuxiliaryComparator {
-
C compare;
_FORCE_INLINE_ bool operator()(const Element *a, const Element *b) const {
-
return compare(a->value, b->value);
}
};
template <class C>
void sort_custom() {
-
//this version uses auxiliary memory for speed.
//if you don't want to use auxiliary memory, use the in_place version
int s = size();
- if (s < 2)
+ if (s < 2) {
return;
+ }
Element **aux_buffer = memnew_arr(Element *, s);
int idx = 0;
for (Element *E = front(); E; E = E->next_ptr) {
-
aux_buffer[idx] = E;
idx++;
}
@@ -666,7 +642,6 @@ public:
aux_buffer[s - 1]->next_ptr = nullptr;
for (int i = 1; i < s - 1; i++) {
-
aux_buffer[i]->prev_ptr = aux_buffer[i - 1];
aux_buffer[i]->next_ptr = aux_buffer[i + 1];
}
@@ -682,10 +657,8 @@ public:
* copy constructor for the list
*/
List(const List &p_list) {
-
const Element *it = p_list.front();
while (it) {
-
push_back(it->get());
it = it->next();
}
@@ -696,7 +669,6 @@ public:
~List() {
clear();
if (_data) {
-
ERR_FAIL_COND(_data->size_cache);
memdelete_allocator<_Data, A>(_data);
}
diff --git a/core/local_vector.h b/core/local_vector.h
index 0b0ef6dfdc..c8abb32bf5 100644
--- a/core/local_vector.h
+++ b/core/local_vector.h
@@ -76,12 +76,12 @@ public:
void erase(const T &p_val) {
U idx = find(p_val);
- if (idx >= 0)
+ if (idx >= 0) {
remove(idx);
+ }
}
void invert() {
-
for (U i = 0; i < count / 2; i++) {
SWAP(data[i], data[count - i - 1]);
}
@@ -108,9 +108,7 @@ public:
_FORCE_INLINE_ U size() const { return count; }
void resize(U p_size) {
-
if (p_size < count) {
-
if (!__has_trivial_destructor(T) && !force_trivial) {
for (U i = p_size; i < count; i++) {
data[i].~T();
@@ -118,7 +116,6 @@ public:
}
count = p_size;
} else if (p_size > count) {
-
if (unlikely(p_size > capacity)) {
if (capacity == 0) {
capacity = 1;
@@ -160,7 +157,6 @@ public:
}
int64_t find(const T &p_val, U p_from = 0) const {
-
for (U i = 0; i < count; i++) {
if (data[i] == p_val) {
return int64_t(i);
@@ -171,25 +167,22 @@ public:
template <class C>
void sort_custom() {
-
U len = count;
- if (len == 0)
+ if (len == 0) {
return;
+ }
SortArray<T, C> sorter;
sorter.sort(data, len);
}
void sort() {
-
sort_custom<_DefaultComparator<T>>();
}
void ordered_insert(T p_val) {
-
U i;
for (i = 0; i < count; i++) {
-
if (p_val < data[i]) {
break;
};
@@ -236,7 +229,6 @@ public:
}
_FORCE_INLINE_ ~LocalVector() {
-
if (data) {
reset();
}
diff --git a/core/map.h b/core/map.h
index 621b6c2842..4861d6a026 100644
--- a/core/map.h
+++ b/core/map.h
@@ -39,7 +39,6 @@
template <class K, class V, class C = Comparator<K>, class A = DefaultAllocator>
class Map {
-
enum Color {
RED,
BLACK
@@ -48,7 +47,6 @@ class Map {
public:
class Element {
-
private:
friend class Map<K, V, C, A>;
int color = RED;
@@ -63,19 +61,15 @@ public:
public:
const Element *next() const {
-
return _next;
}
Element *next() {
-
return _next;
}
const Element *prev() const {
-
return _prev;
}
Element *prev() {
-
return _prev;
}
const K &key() const {
@@ -98,7 +92,6 @@ public:
private:
struct _Data {
-
Element *_root = nullptr;
Element *_nil;
int size_cache = 0;
@@ -114,14 +107,12 @@ private:
}
void _create_root() {
-
_root = memnew_allocator(Element, A);
_root->parent = _root->left = _root->right = _nil;
_root->color = BLACK;
}
void _free_root() {
-
if (_root) {
memdelete_allocator<Element, A>(_root);
_root = nullptr;
@@ -129,7 +120,6 @@ private:
}
~_Data() {
-
_free_root();
#ifdef GLOBALNIL_DISABLED
@@ -141,62 +131,61 @@ private:
_Data _data;
inline void _set_color(Element *p_node, int p_color) {
-
ERR_FAIL_COND(p_node == _data._nil && p_color == RED);
p_node->color = p_color;
}
inline void _rotate_left(Element *p_node) {
-
Element *r = p_node->right;
p_node->right = r->left;
- if (r->left != _data._nil)
+ if (r->left != _data._nil) {
r->left->parent = p_node;
+ }
r->parent = p_node->parent;
- if (p_node == p_node->parent->left)
+ if (p_node == p_node->parent->left) {
p_node->parent->left = r;
- else
+ } else {
p_node->parent->right = r;
+ }
r->left = p_node;
p_node->parent = r;
}
inline void _rotate_right(Element *p_node) {
-
Element *l = p_node->left;
p_node->left = l->right;
- if (l->right != _data._nil)
+ if (l->right != _data._nil) {
l->right->parent = p_node;
+ }
l->parent = p_node->parent;
- if (p_node == p_node->parent->right)
+ if (p_node == p_node->parent->right) {
p_node->parent->right = l;
- else
+ } else {
p_node->parent->left = l;
+ }
l->right = p_node;
p_node->parent = l;
}
inline Element *_successor(Element *p_node) const {
-
Element *node = p_node;
if (node->right != _data._nil) {
-
node = node->right;
while (node->left != _data._nil) { /* returns the minimum of the right subtree of node */
node = node->left;
}
return node;
} else {
-
while (node == node->parent->right) {
node = node->parent;
}
- if (node->parent == _data._root)
+ if (node->parent == _data._root) {
return nullptr; // No successor, as p_node = last node
+ }
return node->parent;
}
}
@@ -205,43 +194,41 @@ private:
Element *node = p_node;
if (node->left != _data._nil) {
-
node = node->left;
while (node->right != _data._nil) { /* returns the minimum of the left subtree of node */
node = node->right;
}
return node;
} else {
-
while (node == node->parent->left) {
node = node->parent;
}
- if (node == _data._root)
+ if (node == _data._root) {
return nullptr; // No predecessor, as p_node = first node
+ }
return node->parent;
}
}
Element *_find(const K &p_key) const {
-
Element *node = _data._root->left;
C less;
while (node != _data._nil) {
- if (less(p_key, node->_key))
+ if (less(p_key, node->_key)) {
node = node->left;
- else if (less(node->_key, p_key))
+ } else if (less(node->_key, p_key)) {
node = node->right;
- else
+ } else {
return node; // found
+ }
}
return nullptr;
}
Element *_find_closest(const K &p_key) const {
-
Element *node = _data._root->left;
Element *prev = nullptr;
C less;
@@ -249,25 +236,27 @@ private:
while (node != _data._nil) {
prev = node;
- if (less(p_key, node->_key))
+ if (less(p_key, node->_key)) {
node = node->left;
- else if (less(node->_key, p_key))
+ } else if (less(node->_key, p_key)) {
node = node->right;
- else
+ } else {
return node; // found
+ }
}
- if (prev == nullptr)
+ if (prev == nullptr) {
return nullptr; // tree empty
+ }
- if (less(p_key, prev->_key))
+ if (less(p_key, prev->_key)) {
prev = prev->_prev;
+ }
return prev;
}
void _insert_rb_fix(Element *p_new_node) {
-
Element *node = p_new_node;
Element *nparent = node->parent;
Element *ngrand_parent;
@@ -316,20 +305,18 @@ private:
}
Element *_insert(const K &p_key, const V &p_value) {
-
Element *new_parent = _data._root;
Element *node = _data._root->left;
C less;
while (node != _data._nil) {
-
new_parent = node;
- if (less(p_key, node->_key))
+ if (less(p_key, node->_key)) {
node = node->left;
- else if (less(node->_key, p_key))
+ } else if (less(node->_key, p_key)) {
node = node->right;
- else {
+ } else {
node->_value = p_value;
return node; // Return existing node with new value
}
@@ -351,10 +338,12 @@ private:
new_node->_next = _successor(new_node);
new_node->_prev = _predecessor(new_node);
- if (new_node->_next)
+ if (new_node->_next) {
new_node->_next->_prev = new_node;
- if (new_node->_prev)
+ }
+ if (new_node->_prev) {
new_node->_prev->_next = new_node;
+ }
_data.size_cache++;
_insert_rb_fix(new_node);
@@ -362,7 +351,6 @@ private:
}
void _erase_fix_rb(Element *p_node) {
-
Element *root = _data._root->left;
Element *node = _data._nil;
Element *sibling = p_node;
@@ -424,7 +412,6 @@ private:
}
void _erase(Element *p_node) {
-
Element *rp = ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : p_node->_next;
Element *node = (rp->left == _data._nil) ? rp->right : rp->left;
@@ -445,17 +432,18 @@ private:
}
if (rp != p_node) {
-
ERR_FAIL_COND(rp == _data._nil);
rp->left = p_node->left;
rp->right = p_node->right;
rp->parent = p_node->parent;
rp->color = p_node->color;
- if (p_node->left != _data._nil)
+ if (p_node->left != _data._nil) {
p_node->left->parent = rp;
- if (p_node->right != _data._nil)
+ }
+ if (p_node->right != _data._nil) {
p_node->right->parent = rp;
+ }
if (p_node == p_node->parent->left) {
p_node->parent->left = rp;
@@ -464,10 +452,12 @@ private:
}
}
- if (p_node->_next)
+ if (p_node->_next) {
p_node->_next->_prev = p_node->_prev;
- if (p_node->_prev)
+ }
+ if (p_node->_prev) {
p_node->_prev->_next = p_node->_next;
+ }
memdelete_allocator<Element, A>(p_node);
_data.size_cache--;
@@ -475,21 +465,22 @@ private:
}
void _calculate_depth(Element *p_element, int &max_d, int d) const {
-
- if (p_element == _data._nil)
+ if (p_element == _data._nil) {
return;
+ }
_calculate_depth(p_element->left, max_d, d + 1);
_calculate_depth(p_element->right, max_d, d + 1);
- if (d > max_d)
+ if (d > max_d) {
max_d = d;
+ }
}
void _cleanup_tree(Element *p_element) {
-
- if (p_element == _data._nil)
+ if (p_element == _data._nil) {
return;
+ }
_cleanup_tree(p_element->left);
_cleanup_tree(p_element->right);
@@ -497,91 +488,90 @@ private:
}
void _copy_from(const Map &p_map) {
-
clear();
// not the fastest way, but safeset to write.
for (Element *I = p_map.front(); I; I = I->next()) {
-
insert(I->key(), I->value());
}
}
public:
const Element *find(const K &p_key) const {
-
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
const Element *res = _find(p_key);
return res;
}
Element *find(const K &p_key) {
-
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *res = _find(p_key);
return res;
}
const Element *find_closest(const K &p_key) const {
-
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
const Element *res = _find_closest(p_key);
return res;
}
Element *find_closest(const K &p_key) {
-
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *res = _find_closest(p_key);
return res;
}
bool has(const K &p_key) const {
-
return find(p_key) != nullptr;
}
Element *insert(const K &p_key, const V &p_value) {
-
- if (!_data._root)
+ if (!_data._root) {
_data._create_root();
+ }
return _insert(p_key, p_value);
}
void erase(Element *p_element) {
-
- if (!_data._root || !p_element)
+ if (!_data._root || !p_element) {
return;
+ }
_erase(p_element);
- if (_data.size_cache == 0 && _data._root)
+ if (_data.size_cache == 0 && _data._root) {
_data._free_root();
+ }
}
bool erase(const K &p_key) {
-
- if (!_data._root)
+ if (!_data._root) {
return false;
+ }
Element *e = find(p_key);
- if (!e)
+ if (!e) {
return false;
+ }
_erase(e);
- if (_data.size_cache == 0 && _data._root)
+ if (_data.size_cache == 0 && _data._root) {
_data._free_root();
+ }
return true;
}
const V &operator[](const K &p_key) const {
-
CRASH_COND(!_data._root);
const Element *e = find(p_key);
CRASH_COND(!e);
@@ -589,43 +579,48 @@ public:
}
V &operator[](const K &p_key) {
-
- if (!_data._root)
+ if (!_data._root) {
_data._create_root();
+ }
Element *e = find(p_key);
- if (!e)
+ if (!e) {
e = insert(p_key, V());
+ }
return e->_value;
}
Element *front() const {
-
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *e = _data._root->left;
- if (e == _data._nil)
+ if (e == _data._nil) {
return nullptr;
+ }
- while (e->left != _data._nil)
+ while (e->left != _data._nil) {
e = e->left;
+ }
return e;
}
Element *back() const {
-
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *e = _data._root->left;
- if (e == _data._nil)
+ if (e == _data._nil) {
return nullptr;
+ }
- while (e->right != _data._nil)
+ while (e->right != _data._nil) {
e = e->right;
+ }
return e;
}
@@ -635,8 +630,9 @@ public:
int calculate_depth() const {
// used for debug mostly
- if (!_data._root)
+ if (!_data._root) {
return 0;
+ }
int max_d = 0;
_calculate_depth(_data._root->left, max_d, 0);
@@ -644,9 +640,9 @@ public:
}
void clear() {
-
- if (!_data._root)
+ if (!_data._root) {
return;
+ }
_cleanup_tree(_data._root->left);
_data._root->left = _data._nil;
@@ -655,19 +651,16 @@ public:
}
void operator=(const Map &p_map) {
-
_copy_from(p_map);
}
Map(const Map &p_map) {
-
_copy_from(p_map);
}
_FORCE_INLINE_ Map() {}
~Map() {
-
clear();
}
};
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index d6d6101402..45c4a207c3 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -35,7 +35,6 @@
#include "scene/scene_string_names.h"
int AStar::get_available_point_id() const {
-
if (points.empty()) {
return 1;
}
@@ -54,7 +53,6 @@ int AStar::get_available_point_id() const {
}
void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
-
ERR_FAIL_COND(p_id < 0);
ERR_FAIL_COND(p_weight_scale < 1);
@@ -78,7 +76,6 @@ void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
}
Vector3 AStar::get_point_position(int p_id) const {
-
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, Vector3());
@@ -87,7 +84,6 @@ Vector3 AStar::get_point_position(int p_id) const {
}
void AStar::set_point_position(int p_id, const Vector3 &p_pos) {
-
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
@@ -96,7 +92,6 @@ void AStar::set_point_position(int p_id, const Vector3 &p_pos) {
}
real_t AStar::get_point_weight_scale(int p_id) const {
-
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, 0);
@@ -105,7 +100,6 @@ real_t AStar::get_point_weight_scale(int p_id) const {
}
void AStar::set_point_weight_scale(int p_id, real_t p_weight_scale) {
-
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
@@ -115,13 +109,11 @@ void AStar::set_point_weight_scale(int p_id, real_t p_weight_scale) {
}
void AStar::remove_point(int p_id) {
-
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
for (OAHashMap<int, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
-
Segment s(p_id, (*it.key));
segments.erase(s);
@@ -130,7 +122,6 @@ void AStar::remove_point(int p_id) {
}
for (OAHashMap<int, Point *>::Iterator it = p->unlinked_neighbours.iter(); it.valid; it = p->unlinked_neighbours.next_iter(it)) {
-
Segment s(p_id, (*it.key));
segments.erase(s);
@@ -144,7 +135,6 @@ void AStar::remove_point(int p_id) {
}
void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
-
ERR_FAIL_COND(p_id == p_with_id);
Point *a;
@@ -164,8 +154,9 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
}
Segment s(p_id, p_with_id);
- if (bidirectional)
+ if (bidirectional) {
s.direction = Segment::BIDIRECTIONAL;
+ }
Set<Segment>::Element *element = segments.find(s);
if (element != nullptr) {
@@ -182,7 +173,6 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
}
void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) {
-
Point *a;
bool a_exists = points.lookup(p_id, a);
ERR_FAIL_COND(!a_exists);
@@ -208,25 +198,25 @@ void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) {
b->unlinked_neighbours.remove(a->id);
}
} else {
- if (s.direction == Segment::NONE)
+ if (s.direction == Segment::NONE) {
b->unlinked_neighbours.remove(a->id);
- else
+ } else {
a->unlinked_neighbours.set(b->id, b);
+ }
}
segments.erase(element);
- if (s.direction != Segment::NONE)
+ if (s.direction != Segment::NONE) {
segments.insert(s);
+ }
}
}
bool AStar::has_point(int p_id) const {
-
return points.has(p_id);
}
Array AStar::get_points() {
-
Array point_list;
for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) {
@@ -237,7 +227,6 @@ Array AStar::get_points() {
}
Vector<int> AStar::get_point_connections(int p_id) {
-
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, Vector<int>());
@@ -252,7 +241,6 @@ Vector<int> AStar::get_point_connections(int p_id) {
}
bool AStar::are_points_connected(int p_id, int p_with_id, bool bidirectional) const {
-
Segment s(p_id, p_with_id);
const Set<Segment>::Element *element = segments.find(s);
@@ -261,7 +249,6 @@ bool AStar::are_points_connected(int p_id, int p_with_id, bool bidirectional) co
}
void AStar::clear() {
-
last_free_id = 0;
for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) {
memdelete(*(it.value));
@@ -285,14 +272,13 @@ void AStar::reserve_space(int p_num_nodes) {
}
int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) const {
-
int closest_id = -1;
real_t closest_dist = 1e20;
for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) {
-
- if (!p_include_disabled && !(*it.value)->enabled)
+ if (!p_include_disabled && !(*it.value)->enabled) {
continue; // Disabled points should not be considered.
+ }
real_t d = p_point.distance_squared_to((*it.value)->pos);
if (closest_id < 0 || d < closest_dist) {
@@ -305,13 +291,11 @@ int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) co
}
Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const {
-
bool found = false;
real_t closest_dist = 1e20;
Vector3 closest_point;
for (const Set<Segment>::Element *E = segments.front(); E; E = E->next()) {
-
Point *from_point = nullptr, *to_point = nullptr;
points.lookup(E->get().u, from_point);
points.lookup(E->get().v, to_point);
@@ -328,7 +312,6 @@ Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const {
Vector3 p = Geometry::get_closest_point_to_segment(p_point, segment);
real_t d = p_point.distance_squared_to(p);
if (!found || d < closest_dist) {
-
closest_point = p;
closest_dist = d;
found = true;
@@ -339,11 +322,11 @@ Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const {
}
bool AStar::_solve(Point *begin_point, Point *end_point) {
-
pass++;
- if (!end_point->enabled)
+ if (!end_point->enabled) {
return false;
+ }
bool found_route = false;
@@ -355,7 +338,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
open_list.push_back(begin_point);
while (!open_list.empty()) {
-
Point *p = open_list[0]; // The currently processed point
if (p == end_point) {
@@ -368,7 +350,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
p->closed_pass = pass; // Mark the point as closed
for (OAHashMap<int, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
-
Point *e = *(it.value); // The neighbour point
if (!e->enabled || e->closed_pass == pass) {
@@ -403,9 +384,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
}
real_t AStar::_estimate_cost(int p_from_id, int p_to_id) {
-
- if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost))
+ if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) {
return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id);
+ }
Point *from_point;
bool from_exists = points.lookup(p_from_id, from_point);
@@ -419,9 +400,9 @@ real_t AStar::_estimate_cost(int p_from_id, int p_to_id) {
}
real_t AStar::_compute_cost(int p_from_id, int p_to_id) {
-
- if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost))
+ if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) {
return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id);
+ }
Point *from_point;
bool from_exists = points.lookup(p_from_id, from_point);
@@ -435,7 +416,6 @@ real_t AStar::_compute_cost(int p_from_id, int p_to_id) {
}
Vector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
-
Point *a;
bool from_exists = points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, Vector<Vector3>());
@@ -454,8 +434,9 @@ Vector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
Point *end_point = b;
bool found_route = _solve(begin_point, end_point);
- if (!found_route)
+ if (!found_route) {
return Vector<Vector3>();
+ }
Point *p = end_point;
int pc = 1; // Begin point
@@ -484,7 +465,6 @@ Vector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
}
Vector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
-
Point *a;
bool from_exists = points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, Vector<int>());
@@ -503,8 +483,9 @@ Vector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
Point *end_point = b;
bool found_route = _solve(begin_point, end_point);
- if (!found_route)
+ if (!found_route) {
return Vector<int>();
+ }
Point *p = end_point;
int pc = 1; // Begin point
@@ -533,7 +514,6 @@ Vector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
}
void AStar::set_point_disabled(int p_id, bool p_disabled) {
-
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
@@ -542,7 +522,6 @@ void AStar::set_point_disabled(int p_id, bool p_disabled) {
}
bool AStar::is_point_disabled(int p_id) const {
-
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, false);
@@ -551,7 +530,6 @@ bool AStar::is_point_disabled(int p_id) const {
}
void AStar::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_available_point_id"), &AStar::get_available_point_id);
ClassDB::bind_method(D_METHOD("add_point", "id", "position", "weight_scale"), &AStar::add_point, DEFVAL(1.0));
ClassDB::bind_method(D_METHOD("get_point_position", "id"), &AStar::get_point_position);
@@ -678,9 +656,9 @@ Vector2 AStar2D::get_closest_position_in_segment(const Vector2 &p_point) const {
}
real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) {
-
- if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost))
+ if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) {
return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id);
+ }
AStar::Point *from_point;
bool from_exists = astar.points.lookup(p_from_id, from_point);
@@ -694,9 +672,9 @@ real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) {
}
real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) {
-
- if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost))
+ if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) {
return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id);
+ }
AStar::Point *from_point;
bool from_exists = astar.points.lookup(p_from_id, from_point);
@@ -710,7 +688,6 @@ real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) {
}
Vector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) {
-
AStar::Point *a;
bool from_exists = astar.points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, Vector<Vector2>());
@@ -729,8 +706,9 @@ Vector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) {
AStar::Point *end_point = b;
bool found_route = _solve(begin_point, end_point);
- if (!found_route)
+ if (!found_route) {
return Vector<Vector2>();
+ }
AStar::Point *p = end_point;
int pc = 1; // Begin point
@@ -759,7 +737,6 @@ Vector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) {
}
Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) {
-
AStar::Point *a;
bool from_exists = astar.points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, Vector<int>());
@@ -778,8 +755,9 @@ Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) {
AStar::Point *end_point = b;
bool found_route = _solve(begin_point, end_point);
- if (!found_route)
+ if (!found_route) {
return Vector<int>();
+ }
AStar::Point *p = end_point;
int pc = 1; // Begin point
@@ -808,11 +786,11 @@ Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) {
}
bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) {
-
astar.pass++;
- if (!end_point->enabled)
+ if (!end_point->enabled) {
return false;
+ }
bool found_route = false;
@@ -824,7 +802,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) {
open_list.push_back(begin_point);
while (!open_list.empty()) {
-
AStar::Point *p = open_list[0]; // The currently processed point
if (p == end_point) {
@@ -837,7 +814,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) {
p->closed_pass = astar.pass; // Mark the point as closed
for (OAHashMap<int, AStar::Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
-
AStar::Point *e = *(it.value); // The neighbour point
if (!e->enabled || e->closed_pass == astar.pass) {
@@ -872,7 +848,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) {
}
void AStar2D::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_available_point_id"), &AStar2D::get_available_point_id);
ClassDB::bind_method(D_METHOD("add_point", "id", "position", "weight_scale"), &AStar2D::add_point, DEFVAL(1.0));
ClassDB::bind_method(D_METHOD("get_point_position", "id"), &AStar2D::get_point_position);
diff --git a/core/math/a_star.h b/core/math/a_star.h
index ffb437ee04..ba1c3033b8 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -41,12 +41,10 @@
*/
class AStar : public Reference {
-
GDCLASS(AStar, Reference);
friend class AStar2D;
struct Point {
-
Point() {}
int id;
diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp
index 19d60fea72..f5c667dab0 100644
--- a/core/math/aabb.cpp
+++ b/core/math/aabb.cpp
@@ -33,21 +33,18 @@
#include "core/print_string.h"
real_t AABB::get_area() const {
-
return size.x * size.y * size.z;
}
bool AABB::operator==(const AABB &p_rval) const {
-
return ((position == p_rval.position) && (size == p_rval.size));
}
-bool AABB::operator!=(const AABB &p_rval) const {
+bool AABB::operator!=(const AABB &p_rval) const {
return ((position != p_rval.position) || (size != p_rval.size));
}
void AABB::merge_with(const AABB &p_aabb) {
-
Vector3 beg_1, beg_2;
Vector3 end_1, end_2;
Vector3 min, max;
@@ -70,12 +67,10 @@ void AABB::merge_with(const AABB &p_aabb) {
}
bool AABB::is_equal_approx(const AABB &p_aabb) const {
-
return position.is_equal_approx(p_aabb.position) && size.is_equal_approx(p_aabb.size);
}
AABB AABB::intersection(const AABB &p_aabb) const {
-
Vector3 src_min = position;
Vector3 src_max = position + size;
Vector3 dst_min = p_aabb.position;
@@ -83,26 +78,23 @@ AABB AABB::intersection(const AABB &p_aabb) const {
Vector3 min, max;
- if (src_min.x > dst_max.x || src_max.x < dst_min.x)
+ if (src_min.x > dst_max.x || src_max.x < dst_min.x) {
return AABB();
- else {
-
+ } else {
min.x = (src_min.x > dst_min.x) ? src_min.x : dst_min.x;
max.x = (src_max.x < dst_max.x) ? src_max.x : dst_max.x;
}
- if (src_min.y > dst_max.y || src_max.y < dst_min.y)
+ if (src_min.y > dst_max.y || src_max.y < dst_min.y) {
return AABB();
- else {
-
+ } else {
min.y = (src_min.y > dst_min.y) ? src_min.y : dst_min.y;
max.y = (src_max.y < dst_max.y) ? src_max.y : dst_max.y;
}
- if (src_min.z > dst_max.z || src_max.z < dst_min.z)
+ if (src_min.z > dst_max.z || src_max.z < dst_min.z) {
return AABB();
- else {
-
+ } else {
min.z = (src_min.z > dst_min.z) ? src_min.z : dst_min.z;
max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z;
}
@@ -111,7 +103,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
}
bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip, Vector3 *r_normal) const {
-
Vector3 c1, c2;
Vector3 end = position + size;
real_t near = -1e20;
@@ -143,8 +134,9 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *
}
}
- if (r_clip)
+ if (r_clip) {
*r_clip = c1;
+ }
if (r_normal) {
*r_normal = Vector3();
(*r_normal)[axis] = p_dir[axis] ? -1 : 1;
@@ -154,7 +146,6 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *
}
bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip, Vector3 *r_normal) const {
-
real_t min = 0, max = 1;
int axis = 0;
real_t sign = 0;
@@ -168,18 +159,18 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
real_t csign;
if (seg_from < seg_to) {
-
- if (seg_from > box_end || seg_to < box_begin)
+ if (seg_from > box_end || seg_to < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0;
cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1;
csign = -1.0;
} else {
-
- if (seg_to > box_end || seg_from < box_begin)
+ if (seg_to > box_end || seg_from < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0;
cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1;
@@ -191,10 +182,12 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
axis = i;
sign = csign;
}
- if (cmax < max)
+ if (cmax < max) {
max = cmax;
- if (max < min)
+ }
+ if (max < min) {
return false;
+ }
}
Vector3 rel = p_to - p_from;
@@ -205,14 +198,14 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
*r_normal = normal;
}
- if (r_clip)
+ if (r_clip) {
*r_clip = p_from + rel * min;
+ }
return true;
}
bool AABB::intersects_plane(const Plane &p_plane) const {
-
Vector3 points[8] = {
Vector3(position.x, position.y, position.z),
Vector3(position.x, position.y, position.z + size.z),
@@ -228,18 +221,17 @@ bool AABB::intersects_plane(const Plane &p_plane) const {
bool under = false;
for (int i = 0; i < 8; i++) {
-
- if (p_plane.distance_to(points[i]) > 0)
+ if (p_plane.distance_to(points[i]) > 0) {
over = true;
- else
+ } else {
under = true;
+ }
}
return under && over;
}
Vector3 AABB::get_longest_axis() const {
-
Vector3 axis(1, 0, 0);
real_t max_size = size.x;
@@ -254,8 +246,8 @@ Vector3 AABB::get_longest_axis() const {
return axis;
}
-int AABB::get_longest_axis_index() const {
+int AABB::get_longest_axis_index() const {
int axis = 0;
real_t max_size = size.x;
@@ -272,7 +264,6 @@ int AABB::get_longest_axis_index() const {
}
Vector3 AABB::get_shortest_axis() const {
-
Vector3 axis(1, 0, 0);
real_t max_size = size.x;
@@ -287,8 +278,8 @@ Vector3 AABB::get_shortest_axis() const {
return axis;
}
-int AABB::get_shortest_axis_index() const {
+int AABB::get_shortest_axis_index() const {
int axis = 0;
real_t max_size = size.x;
@@ -305,35 +296,31 @@ int AABB::get_shortest_axis_index() const {
}
AABB AABB::merge(const AABB &p_with) const {
-
AABB aabb = *this;
aabb.merge_with(p_with);
return aabb;
}
+
AABB AABB::expand(const Vector3 &p_vector) const {
AABB aabb = *this;
aabb.expand_to(p_vector);
return aabb;
}
-AABB AABB::grow(real_t p_by) const {
+AABB AABB::grow(real_t p_by) const {
AABB aabb = *this;
aabb.grow_by(p_by);
return aabb;
}
void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
-
ERR_FAIL_INDEX(p_edge, 12);
switch (p_edge) {
-
case 0: {
-
r_from = Vector3(position.x + size.x, position.y, position.z);
r_to = Vector3(position.x, position.y, position.z);
} break;
case 1: {
-
r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
r_to = Vector3(position.x + size.x, position.y, position.z);
} break;
@@ -343,18 +330,15 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
} break;
case 3: {
-
r_from = Vector3(position.x, position.y, position.z);
r_to = Vector3(position.x, position.y, position.z + size.z);
} break;
case 4: {
-
r_from = Vector3(position.x, position.y + size.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
} break;
case 5: {
-
r_from = Vector3(position.x + size.x, position.y + size.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
} break;
@@ -364,31 +348,26 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
} break;
case 7: {
-
r_from = Vector3(position.x, position.y + size.y, position.z + size.z);
r_to = Vector3(position.x, position.y + size.y, position.z);
} break;
case 8: {
-
r_from = Vector3(position.x, position.y, position.z + size.z);
r_to = Vector3(position.x, position.y + size.y, position.z + size.z);
} break;
case 9: {
-
r_from = Vector3(position.x, position.y, position.z);
r_to = Vector3(position.x, position.y + size.y, position.z);
} break;
case 10: {
-
r_from = Vector3(position.x + size.x, position.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
} break;
case 11: {
-
r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
@@ -397,6 +376,5 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
}
AABB::operator String() const {
-
return String() + position + " - " + size;
}
diff --git a/core/math/aabb.h b/core/math/aabb.h
index f87fced12d..9bbedfe59c 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -47,12 +47,10 @@ public:
real_t get_area() const; /// get area
_FORCE_INLINE_ bool has_no_area() const {
-
return (size.x <= 0 || size.y <= 0 || size.z <= 0);
}
_FORCE_INLINE_ bool has_no_surface() const {
-
return (size.x <= 0 && size.y <= 0 && size.z <= 0);
}
@@ -111,43 +109,52 @@ public:
};
inline bool AABB::intersects(const AABB &p_aabb) const {
-
- if (position.x >= (p_aabb.position.x + p_aabb.size.x))
+ if (position.x >= (p_aabb.position.x + p_aabb.size.x)) {
return false;
- if ((position.x + size.x) <= p_aabb.position.x)
+ }
+ if ((position.x + size.x) <= p_aabb.position.x) {
return false;
- if (position.y >= (p_aabb.position.y + p_aabb.size.y))
+ }
+ if (position.y >= (p_aabb.position.y + p_aabb.size.y)) {
return false;
- if ((position.y + size.y) <= p_aabb.position.y)
+ }
+ if ((position.y + size.y) <= p_aabb.position.y) {
return false;
- if (position.z >= (p_aabb.position.z + p_aabb.size.z))
+ }
+ if (position.z >= (p_aabb.position.z + p_aabb.size.z)) {
return false;
- if ((position.z + size.z) <= p_aabb.position.z)
+ }
+ if ((position.z + size.z) <= p_aabb.position.z) {
return false;
+ }
return true;
}
inline bool AABB::intersects_inclusive(const AABB &p_aabb) const {
-
- if (position.x > (p_aabb.position.x + p_aabb.size.x))
+ if (position.x > (p_aabb.position.x + p_aabb.size.x)) {
return false;
- if ((position.x + size.x) < p_aabb.position.x)
+ }
+ if ((position.x + size.x) < p_aabb.position.x) {
return false;
- if (position.y > (p_aabb.position.y + p_aabb.size.y))
+ }
+ if (position.y > (p_aabb.position.y + p_aabb.size.y)) {
return false;
- if ((position.y + size.y) < p_aabb.position.y)
+ }
+ if ((position.y + size.y) < p_aabb.position.y) {
return false;
- if (position.z > (p_aabb.position.z + p_aabb.size.z))
+ }
+ if (position.z > (p_aabb.position.z + p_aabb.size.z)) {
return false;
- if ((position.z + size.z) < p_aabb.position.z)
+ }
+ if ((position.z + size.z) < p_aabb.position.z) {
return false;
+ }
return true;
}
inline bool AABB::encloses(const AABB &p_aabb) const {
-
Vector3 src_min = position;
Vector3 src_max = position + size;
Vector3 dst_min = p_aabb.position;
@@ -163,7 +170,6 @@ inline bool AABB::encloses(const AABB &p_aabb) const {
}
Vector3 AABB::get_support(const Vector3 &p_normal) const {
-
Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents;
@@ -175,7 +181,6 @@ Vector3 AABB::get_support(const Vector3 &p_normal) const {
}
Vector3 AABB::get_endpoint(int p_point) const {
-
switch (p_point) {
case 0:
return Vector3(position.x, position.y, position.z);
@@ -199,7 +204,6 @@ Vector3 AABB::get_endpoint(int p_point) const {
}
bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const {
-
Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents;
@@ -210,8 +214,9 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con
(p.normal.y > 0) ? -half_extents.y : half_extents.y,
(p.normal.z > 0) ? -half_extents.z : half_extents.z);
point += ofs;
- if (p.is_point_over(point))
+ if (p.is_point_over(point)) {
return false;
+ }
}
// Make sure all points in the shape aren't fully separated from the AABB on
@@ -220,7 +225,6 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con
int bad_point_counts_negative[3] = { 0 };
for (int k = 0; k < 3; k++) {
-
for (int i = 0; i < p_point_count; i++) {
if (p_points[i].coord[k] > ofs.coord[k] + half_extents.coord[k]) {
bad_point_counts_positive[k]++;
@@ -242,7 +246,6 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con
}
bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const {
-
Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents;
@@ -253,56 +256,66 @@ bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const {
(p.normal.y < 0) ? -half_extents.y : half_extents.y,
(p.normal.z < 0) ? -half_extents.z : half_extents.z);
point += ofs;
- if (p.is_point_over(point))
+ if (p.is_point_over(point)) {
return false;
+ }
}
return true;
}
bool AABB::has_point(const Vector3 &p_point) const {
-
- if (p_point.x < position.x)
+ if (p_point.x < position.x) {
return false;
- if (p_point.y < position.y)
+ }
+ if (p_point.y < position.y) {
return false;
- if (p_point.z < position.z)
+ }
+ if (p_point.z < position.z) {
return false;
- if (p_point.x > position.x + size.x)
+ }
+ if (p_point.x > position.x + size.x) {
return false;
- if (p_point.y > position.y + size.y)
+ }
+ if (p_point.y > position.y + size.y) {
return false;
- if (p_point.z > position.z + size.z)
+ }
+ if (p_point.z > position.z + size.z) {
return false;
+ }
return true;
}
inline void AABB::expand_to(const Vector3 &p_vector) {
-
Vector3 begin = position;
Vector3 end = position + size;
- if (p_vector.x < begin.x)
+ if (p_vector.x < begin.x) {
begin.x = p_vector.x;
- if (p_vector.y < begin.y)
+ }
+ if (p_vector.y < begin.y) {
begin.y = p_vector.y;
- if (p_vector.z < begin.z)
+ }
+ if (p_vector.z < begin.z) {
begin.z = p_vector.z;
+ }
- if (p_vector.x > end.x)
+ if (p_vector.x > end.x) {
end.x = p_vector.x;
- if (p_vector.y > end.y)
+ }
+ if (p_vector.y > end.y) {
end.y = p_vector.y;
- if (p_vector.z > end.z)
+ }
+ if (p_vector.z > end.z) {
end.z = p_vector.z;
+ }
position = begin;
size = end - begin;
}
void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const {
-
Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5);
Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z);
@@ -313,7 +326,6 @@ void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r
}
inline real_t AABB::get_longest_axis_size() const {
-
real_t max_size = size.x;
if (size.y > max_size) {
@@ -328,7 +340,6 @@ inline real_t AABB::get_longest_axis_size() const {
}
inline real_t AABB::get_shortest_axis_size() const {
-
real_t max_size = size.x;
if (size.y < max_size) {
@@ -343,7 +354,6 @@ inline real_t AABB::get_shortest_axis_size() const {
}
bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const {
-
real_t divx = 1.0 / p_dir.x;
real_t divy = 1.0 / p_dir.y;
real_t divz = 1.0 / p_dir.z;
@@ -364,12 +374,15 @@ bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real
tymin = (upbound.y - p_from.y) * divy;
tymax = (position.y - p_from.y) * divy;
}
- if ((tmin > tymax) || (tymin > tmax))
+ if ((tmin > tymax) || (tymin > tmax)) {
return false;
- if (tymin > tmin)
+ }
+ if (tymin > tmin) {
tmin = tymin;
- if (tymax < tmax)
+ }
+ if (tymax < tmax) {
tmax = tymax;
+ }
if (p_dir.z >= 0) {
tzmin = (position.z - p_from.z) * divz;
tzmax = (upbound.z - p_from.z) * divz;
@@ -377,17 +390,19 @@ bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real
tzmin = (upbound.z - p_from.z) * divz;
tzmax = (position.z - p_from.z) * divz;
}
- if ((tmin > tzmax) || (tzmin > tmax))
+ if ((tmin > tzmax) || (tzmin > tmax)) {
return false;
- if (tzmin > tmin)
+ }
+ if (tzmin > tmin) {
tmin = tzmin;
- if (tzmax < tmax)
+ }
+ if (tzmax < tmax) {
tmax = tzmax;
+ }
return ((tmin < t1) && (tmax > t0));
}
void AABB::grow_by(real_t p_amount) {
-
position.x -= p_amount;
position.y -= p_amount;
position.z -= p_amount;
diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h
index 4665311059..91f533eafb 100644
--- a/core/math/audio_frame.h
+++ b/core/math/audio_frame.h
@@ -48,7 +48,6 @@ static inline float undenormalise(volatile float f) {
}
struct AudioFrame {
-
//left and right samples
float l, r;
@@ -105,7 +104,6 @@ struct AudioFrame {
}
_FORCE_INLINE_ AudioFrame lerp(const AudioFrame &p_b, float p_t) const {
-
AudioFrame res = *this;
res.l += (p_t * (p_b.l - l));
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index 6218b7e248..cbfd09810c 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -38,16 +38,13 @@
(elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1])
void Basis::from_z(const Vector3 &p_z) {
-
if (Math::abs(p_z.z) > Math_SQRT12) {
-
// choose p in y-z plane
real_t a = p_z[1] * p_z[1] + p_z[2] * p_z[2];
real_t k = 1.0 / Math::sqrt(a);
elements[0] = Vector3(0, -p_z[2] * k, p_z[1] * k);
elements[1] = Vector3(a * k, -p_z[0] * elements[0][2], p_z[0] * elements[0][1]);
} else {
-
// choose p in x-y plane
real_t a = p_z.x * p_z.x + p_z.y * p_z.y;
real_t k = 1.0 / Math::sqrt(a);
@@ -58,7 +55,6 @@ void Basis::from_z(const Vector3 &p_z) {
}
void Basis::invert() {
-
real_t co[3] = {
cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1)
};
@@ -76,7 +72,6 @@ void Basis::invert() {
}
void Basis::orthonormalize() {
-
// Gram-Schmidt Process
Vector3 x = get_axis(0);
@@ -95,7 +90,6 @@ void Basis::orthonormalize() {
}
Basis Basis::orthonormalized() const {
-
Basis c = *this;
c.orthonormalize();
return c;
@@ -120,19 +114,20 @@ bool Basis::is_rotation() const {
}
bool Basis::is_symmetric() const {
-
- if (!Math::is_equal_approx_ratio(elements[0][1], elements[1][0], UNIT_EPSILON))
+ if (!Math::is_equal_approx_ratio(elements[0][1], elements[1][0], UNIT_EPSILON)) {
return false;
- if (!Math::is_equal_approx_ratio(elements[0][2], elements[2][0], UNIT_EPSILON))
+ }
+ if (!Math::is_equal_approx_ratio(elements[0][2], elements[2][0], UNIT_EPSILON)) {
return false;
- if (!Math::is_equal_approx_ratio(elements[1][2], elements[2][1], UNIT_EPSILON))
+ }
+ if (!Math::is_equal_approx_ratio(elements[1][2], elements[2][1], UNIT_EPSILON)) {
return false;
+ }
return true;
}
Basis Basis::diagonalize() {
-
//NOTE: only implemented for symmetric matrices
//with the Jacobi iterative method method
#ifdef MATH_CHECKS
@@ -193,21 +188,18 @@ Basis Basis::diagonalize() {
}
Basis Basis::inverse() const {
-
Basis inv = *this;
inv.invert();
return inv;
}
void Basis::transpose() {
-
SWAP(elements[0][1], elements[1][0]);
SWAP(elements[0][2], elements[2][0]);
SWAP(elements[1][2], elements[2][1]);
}
Basis Basis::transposed() const {
-
Basis tr = *this;
tr.transpose();
return tr;
@@ -216,7 +208,6 @@ Basis Basis::transposed() const {
// Multiplies the matrix from left by the scaling matrix: M -> S.M
// See the comment for Basis::rotated for further explanation.
void Basis::scale(const Vector3 &p_scale) {
-
elements[0][0] *= p_scale.x;
elements[0][1] *= p_scale.x;
elements[0][2] *= p_scale.x;
@@ -260,7 +251,6 @@ Basis Basis::scaled_local(const Vector3 &p_scale) const {
}
Vector3 Basis::get_scale_abs() const {
-
return Vector3(
Vector3(elements[0][0], elements[1][0], elements[2][0]).length(),
Vector3(elements[0][1], elements[1][1], elements[2][1]).length(),
@@ -340,8 +330,8 @@ void Basis::rotate_local(const Vector3 &p_axis, real_t p_phi) {
// M -> (M.R.Minv).M = M.R.
*this = rotated_local(p_axis, p_phi);
}
-Basis Basis::rotated_local(const Vector3 &p_axis, real_t p_phi) const {
+Basis Basis::rotated_local(const Vector3 &p_axis, real_t p_phi) const {
return (*this) * Basis(p_axis, p_phi);
}
@@ -430,7 +420,6 @@ void Basis::get_rotation_axis_angle_local(Vector3 &p_axis, real_t &p_angle) cons
// the angles in the decomposition R = X(a1).Y(a2).Z(a3) where Z(a) rotates
// around the z-axis by a and so on.
Vector3 Basis::get_euler_xyz() const {
-
// Euler angles in XYZ convention.
// See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
//
@@ -474,7 +463,6 @@ Vector3 Basis::get_euler_xyz() const {
// and similar for other axes.
// The current implementation uses XYZ convention (Z is the first rotation).
void Basis::set_euler_xyz(const Vector3 &p_euler) {
-
real_t c, s;
c = Math::cos(p_euler.x);
@@ -497,7 +485,6 @@ void Basis::set_euler_xyz(const Vector3 &p_euler) {
// as in first-Z, then-X, last-Y. The angles for X, Y, and Z rotations are returned
// as the x, y, and z components of a Vector3 respectively.
Vector3 Basis::get_euler_yxz() const {
-
/* checking this is a bad idea, because obtaining from scaled transform is a valid use case
#ifdef MATH_CHECKS
ERR_FAIL_COND(!is_rotation());
@@ -546,7 +533,6 @@ Vector3 Basis::get_euler_yxz() const {
// and similar for other axes.
// The current implementation uses YXZ convention (Z is the first rotation).
void Basis::set_euler_yxz(const Vector3 &p_euler) {
-
real_t c, s;
c = Math::cos(p_euler.x);
@@ -566,16 +552,15 @@ void Basis::set_euler_yxz(const Vector3 &p_euler) {
}
bool Basis::is_equal_approx(const Basis &p_basis) const {
-
return elements[0].is_equal_approx(p_basis.elements[0]) && elements[1].is_equal_approx(p_basis.elements[1]) && elements[2].is_equal_approx(p_basis.elements[2]);
}
bool Basis::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsilon) const {
-
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (!Math::is_equal_approx_ratio(a.elements[i][j], b.elements[i][j], p_epsilon))
+ if (!Math::is_equal_approx_ratio(a.elements[i][j], b.elements[i][j], p_epsilon)) {
return false;
+ }
}
}
@@ -583,11 +568,11 @@ bool Basis::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsil
}
bool Basis::operator==(const Basis &p_matrix) const {
-
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (elements[i][j] != p_matrix.elements[i][j])
+ if (elements[i][j] != p_matrix.elements[i][j]) {
return false;
+ }
}
}
@@ -595,19 +580,16 @@ bool Basis::operator==(const Basis &p_matrix) const {
}
bool Basis::operator!=(const Basis &p_matrix) const {
-
return (!(*this == p_matrix));
}
Basis::operator String() const {
-
String mtx;
for (int i = 0; i < 3; i++) {
-
for (int j = 0; j < 3; j++) {
-
- if (i != 0 || j != 0)
+ if (i != 0 || j != 0) {
mtx += ", ";
+ }
mtx += rtos(elements[i][j]);
}
@@ -617,7 +599,6 @@ Basis::operator String() const {
}
Quat Basis::get_quat() const {
-
#ifdef MATH_CHECKS
ERR_FAIL_COND_V_MSG(!is_rotation(), Quat(), "Basis must be normalized in order to be casted to a Quaternion. Use get_rotation_quat() or call orthonormalized() instead.");
#endif
@@ -681,35 +662,33 @@ static const Basis _ortho_bases[24] = {
};
int Basis::get_orthogonal_index() const {
-
//could be sped up if i come up with a way
Basis orth = *this;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
-
real_t v = orth[i][j];
- if (v > 0.5)
+ if (v > 0.5) {
v = 1.0;
- else if (v < -0.5)
+ } else if (v < -0.5) {
v = -1.0;
- else
+ } else {
v = 0;
+ }
orth[i][j] = v;
}
}
for (int i = 0; i < 24; i++) {
-
- if (_ortho_bases[i] == orth)
+ if (_ortho_bases[i] == orth) {
return i;
+ }
}
return 0;
}
void Basis::set_orthogonal_index(int p_index) {
-
//there only exist 24 orthogonal bases in r3
ERR_FAIL_INDEX(p_index, 24);
@@ -783,8 +762,9 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
real_t s = Math::sqrt((elements[1][2] - elements[2][1]) * (elements[1][2] - elements[2][1]) + (elements[2][0] - elements[0][2]) * (elements[2][0] - elements[0][2]) + (elements[0][1] - elements[1][0]) * (elements[0][1] - elements[1][0])); // s=|axis||sin(angle)|, used to normalise
angle = Math::acos((elements[0][0] + elements[1][1] + elements[2][2] - 1) / 2);
- if (angle < 0)
+ if (angle < 0) {
s = -s;
+ }
x = (elements[2][1] - elements[1][2]) / s;
y = (elements[0][2] - elements[2][0]) / s;
z = (elements[1][0] - elements[0][1]) / s;
@@ -794,7 +774,6 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
}
void Basis::set_quat(const Quat &p_quat) {
-
real_t d = p_quat.length_squared();
real_t s = 2.0 / d;
real_t xs = p_quat.x * s, ys = p_quat.y * s, zs = p_quat.z * s;
@@ -866,7 +845,6 @@ void Basis::set_diagonal(const Vector3 &p_diag) {
}
Basis Basis::slerp(const Basis &target, const real_t &t) const {
-
//consider scale
Quat from(*this);
Quat to(target);
@@ -880,7 +858,6 @@ Basis Basis::slerp(const Basis &target, const real_t &t) const {
}
void Basis::rotate_sh(real_t *p_values) {
-
// code by John Hable
// http://filmicworlds.com/blog/simple-and-fast-spherical-harmonic-rotation/
// this code is Public Domain
diff --git a/core/math/basis.h b/core/math/basis.h
index 2924a0ddbd..d870a6b099 100644
--- a/core/math/basis.h
+++ b/core/math/basis.h
@@ -39,11 +39,9 @@ public:
Vector3 elements[3];
_FORCE_INLINE_ const Vector3 &operator[](int axis) const {
-
return elements[axis];
}
_FORCE_INLINE_ Vector3 &operator[](int axis) {
-
return elements[axis];
}
@@ -166,7 +164,6 @@ public:
/* create / set */
_FORCE_INLINE_ void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
-
elements[0][0] = xx;
elements[0][1] = xy;
elements[0][2] = xz;
@@ -178,18 +175,15 @@ public:
elements[2][2] = zz;
}
_FORCE_INLINE_ void set(const Vector3 &p_x, const Vector3 &p_y, const Vector3 &p_z) {
-
set_axis(0, p_x);
set_axis(1, p_y);
set_axis(2, p_z);
}
_FORCE_INLINE_ Vector3 get_column(int i) const {
-
return Vector3(elements[0][i], elements[1][i], elements[2][i]);
}
_FORCE_INLINE_ Vector3 get_row(int i) const {
-
return Vector3(elements[i][0], elements[i][1], elements[i][2]);
}
_FORCE_INLINE_ Vector3 get_main_diagonal() const {
@@ -221,7 +215,6 @@ public:
elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z);
}
Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
-
set(xx, xy, xz, yx, yy, yz, zx, zy, zz);
}
@@ -249,7 +242,6 @@ public:
}
_FORCE_INLINE_ Basis() {
-
elements[0][0] = 1;
elements[0][1] = 0;
elements[0][2] = 0;
@@ -263,7 +255,6 @@ public:
};
_FORCE_INLINE_ void Basis::operator*=(const Basis &p_matrix) {
-
set(
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]),
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]),
@@ -271,7 +262,6 @@ _FORCE_INLINE_ void Basis::operator*=(const Basis &p_matrix) {
}
_FORCE_INLINE_ Basis Basis::operator*(const Basis &p_matrix) const {
-
return Basis(
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]),
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]),
@@ -279,49 +269,42 @@ _FORCE_INLINE_ Basis Basis::operator*(const Basis &p_matrix) const {
}
_FORCE_INLINE_ void Basis::operator+=(const Basis &p_matrix) {
-
elements[0] += p_matrix.elements[0];
elements[1] += p_matrix.elements[1];
elements[2] += p_matrix.elements[2];
}
_FORCE_INLINE_ Basis Basis::operator+(const Basis &p_matrix) const {
-
Basis ret(*this);
ret += p_matrix;
return ret;
}
_FORCE_INLINE_ void Basis::operator-=(const Basis &p_matrix) {
-
elements[0] -= p_matrix.elements[0];
elements[1] -= p_matrix.elements[1];
elements[2] -= p_matrix.elements[2];
}
_FORCE_INLINE_ Basis Basis::operator-(const Basis &p_matrix) const {
-
Basis ret(*this);
ret -= p_matrix;
return ret;
}
_FORCE_INLINE_ void Basis::operator*=(real_t p_val) {
-
elements[0] *= p_val;
elements[1] *= p_val;
elements[2] *= p_val;
}
_FORCE_INLINE_ Basis Basis::operator*(real_t p_val) const {
-
Basis ret(*this);
ret *= p_val;
return ret;
}
Vector3 Basis::xform(const Vector3 &p_vector) const {
-
return Vector3(
elements[0].dot(p_vector),
elements[1].dot(p_vector),
@@ -329,7 +312,6 @@ Vector3 Basis::xform(const Vector3 &p_vector) const {
}
Vector3 Basis::xform_inv(const Vector3 &p_vector) const {
-
return Vector3(
(elements[0][0] * p_vector.x) + (elements[1][0] * p_vector.y) + (elements[2][0] * p_vector.z),
(elements[0][1] * p_vector.x) + (elements[1][1] * p_vector.y) + (elements[2][1] * p_vector.z),
@@ -337,7 +319,6 @@ Vector3 Basis::xform_inv(const Vector3 &p_vector) const {
}
real_t Basis::determinant() const {
-
return elements[0][0] * (elements[1][1] * elements[2][2] - elements[2][1] * elements[1][2]) -
elements[1][0] * (elements[0][1] * elements[2][2] - elements[2][1] * elements[0][2]) +
elements[2][0] * (elements[0][1] * elements[1][2] - elements[1][1] * elements[0][2]);
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 5d3ebc9f6d..81c602d8fe 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -34,7 +34,6 @@
#include "core/print_string.h"
float CameraMatrix::determinant() const {
-
return matrix[0][3] * matrix[1][2] * matrix[2][1] * matrix[3][0] - matrix[0][2] * matrix[1][3] * matrix[2][1] * matrix[3][0] -
matrix[0][3] * matrix[1][1] * matrix[2][2] * matrix[3][0] + matrix[0][1] * matrix[1][3] * matrix[2][2] * matrix[3][0] +
matrix[0][2] * matrix[1][1] * matrix[2][3] * matrix[3][0] - matrix[0][1] * matrix[1][2] * matrix[2][3] * matrix[3][0] -
@@ -50,29 +49,22 @@ float CameraMatrix::determinant() const {
}
void CameraMatrix::set_identity() {
-
for (int i = 0; i < 4; i++) {
-
for (int j = 0; j < 4; j++) {
-
matrix[i][j] = (i == j) ? 1 : 0;
}
}
}
void CameraMatrix::set_zero() {
-
for (int i = 0; i < 4; i++) {
-
for (int j = 0; j < 4; j++) {
-
matrix[i][j] = 0;
}
}
}
Plane CameraMatrix::xform4(const Plane &p_vec4) const {
-
Plane ret;
ret.normal.x = matrix[0][0] * p_vec4.normal.x + matrix[1][0] * p_vec4.normal.y + matrix[2][0] * p_vec4.normal.z + matrix[3][0] * p_vec4.d;
@@ -83,7 +75,6 @@ Plane CameraMatrix::xform4(const Plane &p_vec4) const {
}
void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov) {
-
if (p_flip_fov) {
p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect);
}
@@ -176,7 +167,6 @@ void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_
};
void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
-
set_identity();
matrix[0][0] = 2.0 / (p_right - p_left);
@@ -189,7 +179,6 @@ void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom
}
void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) {
-
if (!p_flip_fov) {
p_size *= p_aspect;
}
@@ -198,7 +187,6 @@ void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear
}
void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) {
-
ERR_FAIL_COND(p_right <= p_left);
ERR_FAIL_COND(p_top <= p_bottom);
ERR_FAIL_COND(p_far <= p_near);
@@ -239,7 +227,6 @@ void CameraMatrix::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset,
}
real_t CameraMatrix::get_z_far() const {
-
const real_t *matrix = (const real_t *)this->matrix;
Plane new_plane = Plane(matrix[3] - matrix[2],
matrix[7] - matrix[6],
@@ -251,8 +238,8 @@ real_t CameraMatrix::get_z_far() const {
return new_plane.d;
}
-real_t CameraMatrix::get_z_near() const {
+real_t CameraMatrix::get_z_near() const {
const real_t *matrix = (const real_t *)this->matrix;
Plane new_plane = Plane(matrix[3] + matrix[2],
matrix[7] + matrix[6],
@@ -264,7 +251,6 @@ real_t CameraMatrix::get_z_near() const {
}
Vector2 CameraMatrix::get_viewport_half_extents() const {
-
const real_t *matrix = (const real_t *)this->matrix;
///////--- Near Plane ---///////
Plane near_plane = Plane(matrix[3] + matrix[2],
@@ -293,7 +279,6 @@ Vector2 CameraMatrix::get_viewport_half_extents() const {
}
void CameraMatrix::get_far_plane_size(real_t &r_width, real_t &r_height) const {
-
const real_t *matrix = (const real_t *)this->matrix;
///////--- Far Plane ---///////
Plane far_plane = Plane(matrix[3] - matrix[2],
@@ -323,7 +308,6 @@ void CameraMatrix::get_far_plane_size(real_t &r_width, real_t &r_height) const {
}
bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8points) const {
-
Vector<Plane> planes = get_projection_planes(Transform());
const Planes intersections[8][3] = {
{ PLANE_FAR, PLANE_LEFT, PLANE_TOP },
@@ -337,7 +321,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point
};
for (int i = 0; i < 8; i++) {
-
Vector3 point;
bool res = planes[intersections[i][0]].intersect_3(planes[intersections[i][1]], planes[intersections[i][2]], &point);
ERR_FAIL_COND_V(!res, false);
@@ -348,7 +331,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point
}
Vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transform) const {
-
/** Fast Plane Extraction from combined modelview/projection matrices.
* References:
* https://web.archive.org/web/20011221205252/http://www.markmorley.com/opengl/frustumculling.html
@@ -431,14 +413,12 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transform)
}
CameraMatrix CameraMatrix::inverse() const {
-
CameraMatrix cm = *this;
cm.invert();
return cm;
}
void CameraMatrix::invert() {
-
int i, j, k;
int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */
real_t pvt_val; /* Value of current pivot element */
@@ -489,23 +469,26 @@ void CameraMatrix::invert() {
/** Divide column by minus pivot value **/
for (i = 0; i < 4; i++) {
- if (i != k)
+ if (i != k) {
matrix[i][k] /= (-pvt_val);
+ }
}
/** Reduce the matrix **/
for (i = 0; i < 4; i++) {
hold = matrix[i][k];
for (j = 0; j < 4; j++) {
- if (i != k && j != k)
+ if (i != k && j != k) {
matrix[i][j] += hold * matrix[k][j];
+ }
}
}
/** Divide row by pivot **/
for (j = 0; j < 4; j++) {
- if (j != k)
+ if (j != k) {
matrix[k][j] /= pvt_val;
+ }
}
/** Replace pivot by reciprocal (at last we can touch it). **/
@@ -525,12 +508,13 @@ void CameraMatrix::invert() {
}
j = pvt_i[k]; /* Columns to swap correspond to pivot ROW */
- if (j != k) /* If columns are different */
+ if (j != k) { /* If columns are different */
for (i = 0; i < 4; i++) {
hold = matrix[i][k];
matrix[i][k] = -matrix[i][j];
matrix[i][j] = hold;
}
+ }
}
}
@@ -541,19 +525,18 @@ void CameraMatrix::flip_y() {
}
CameraMatrix::CameraMatrix() {
-
set_identity();
}
CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const {
-
CameraMatrix new_matrix;
for (int j = 0; j < 4; j++) {
for (int i = 0; i < 4; i++) {
real_t ab = 0;
- for (int k = 0; k < 4; k++)
+ for (int k = 0; k < 4; k++) {
ab += matrix[k][i] * p_matrix.matrix[j][k];
+ }
new_matrix.matrix[j][i] = ab;
}
}
@@ -562,7 +545,6 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const {
}
void CameraMatrix::set_depth_correction(bool p_flip_y) {
-
real_t *m = &matrix[0][0];
m[0] = 1;
@@ -584,7 +566,6 @@ void CameraMatrix::set_depth_correction(bool p_flip_y) {
}
void CameraMatrix::set_light_bias() {
-
real_t *m = &matrix[0][0];
m[0] = 0.5;
@@ -606,7 +587,6 @@ void CameraMatrix::set_light_bias() {
}
void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) {
-
real_t *m = &matrix[0][0];
m[0] = p_rect.size.width;
@@ -628,30 +608,28 @@ void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) {
}
CameraMatrix::operator String() const {
-
String str;
- for (int i = 0; i < 4; i++)
- for (int j = 0; j < 4; j++)
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
str += String((j > 0) ? ", " : "\n") + rtos(matrix[i][j]);
+ }
+ }
return str;
}
real_t CameraMatrix::get_aspect() const {
-
Vector2 vp_he = get_viewport_half_extents();
return vp_he.x / vp_he.y;
}
int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const {
-
Vector3 result = xform(Vector3(1, 0, -1));
return int((result.x * 0.5 + 0.5) * p_for_pixel_width);
}
bool CameraMatrix::is_orthogonal() const {
-
return matrix[3][3] == 1.0;
}
@@ -679,7 +657,6 @@ real_t CameraMatrix::get_fov() const {
}
void CameraMatrix::make_scale(const Vector3 &p_scale) {
-
set_identity();
matrix[0][0] = p_scale.x;
matrix[1][1] = p_scale.y;
@@ -687,7 +664,6 @@ void CameraMatrix::make_scale(const Vector3 &p_scale) {
}
void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) {
-
Vector3 min = p_aabb.position;
Vector3 max = p_aabb.position + p_aabb.size;
@@ -713,7 +689,6 @@ void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) {
}
CameraMatrix::operator Transform() const {
-
Transform tr;
const real_t *m = &matrix[0][0];
@@ -737,7 +712,6 @@ CameraMatrix::operator Transform() const {
}
CameraMatrix::CameraMatrix(const Transform &p_transform) {
-
const Transform &tr = p_transform;
real_t *m = &matrix[0][0];
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index 5420fa2984..49fdecae02 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -35,7 +35,6 @@
#include "core/math/transform.h"
struct CameraMatrix {
-
enum Planes {
PLANE_NEAR,
PLANE_FAR,
@@ -62,7 +61,6 @@ struct CameraMatrix {
void set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov = false);
static real_t get_fovy(real_t p_fovx, real_t p_aspect) {
-
return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5)) * 2.0);
}
@@ -116,7 +114,6 @@ struct CameraMatrix {
};
Vector3 CameraMatrix::xform(const Vector3 &p_vec3) const {
-
Vector3 ret;
ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0];
ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1];
diff --git a/core/math/delaunay_2d.h b/core/math/delaunay_2d.h
index 66b2f8f573..d637671686 100644
--- a/core/math/delaunay_2d.h
+++ b/core/math/delaunay_2d.h
@@ -57,7 +57,6 @@ public:
};
static bool circum_circle_contains(const Vector<Vector2> &p_vertices, const Triangle &p_triangle, int p_vertex) {
-
Vector2 p1 = p_vertices[p_triangle.points[0]];
Vector2 p2 = p_vertices[p_triangle.points[1]];
Vector2 p3 = p_vertices[p_triangle.points[2]];
@@ -89,7 +88,6 @@ public:
}
static Vector<Triangle> triangulate(const Vector<Vector2> &p_points) {
-
Vector<Vector2> points = p_points;
Vector<Triangle> triangles;
@@ -112,7 +110,6 @@ public:
triangles.push_back(Triangle(p_points.size() + 0, p_points.size() + 1, p_points.size() + 2));
for (int i = 0; i < p_points.size(); i++) {
-
Vector<Edge> polygon;
for (int j = 0; j < triangles.size(); j++) {
@@ -141,7 +138,6 @@ public:
}
for (int j = 0; j < polygon.size(); j++) {
-
if (polygon[j].bad) {
continue;
}
diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h
index ab0993abc9..014b4c4621 100644
--- a/core/math/delaunay_3d.h
+++ b/core/math/delaunay_3d.h
@@ -1,3 +1,33 @@
+/*************************************************************************/
+/* delaunay_3d.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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. */
+/*************************************************************************/
+
#ifndef DELAUNAY_3D_H
#define DELAUNAY_3D_H
@@ -25,7 +55,6 @@ class Delaunay3D {
};
struct Simplex {
-
uint32_t points[4];
R128 circum_center_x;
R128 circum_center_y;
@@ -52,12 +81,15 @@ class Delaunay3D {
_FORCE_INLINE_ Triangle() {}
_FORCE_INLINE_ Triangle(uint32_t p_a, uint32_t p_b, uint32_t p_c) {
- if (p_a > p_b)
+ if (p_a > p_b) {
SWAP(p_a, p_b);
- if (p_b > p_c)
+ }
+ if (p_b > p_c) {
SWAP(p_b, p_c);
- if (p_a > p_b)
+ }
+ if (p_a > p_b) {
SWAP(p_a, p_b);
+ }
triangle[0] = p_a;
triangle[1] = p_b;
@@ -74,7 +106,6 @@ class Delaunay3D {
};
_FORCE_INLINE_ static void circum_sphere_compute(const Vector3 *p_points, Simplex *p_simplex) {
-
// the only part in the algorithm where there may be precision errors is this one, so ensure that
// we do it as maximum precision as possible
@@ -134,7 +165,6 @@ class Delaunay3D {
}
_FORCE_INLINE_ static bool simplex_contains(const Vector3 *p_points, const Simplex &p_simplex, uint32_t p_vertex) {
-
R128 v_x = p_points[p_vertex].x;
R128 v_y = p_points[p_vertex].y;
R128 v_z = p_points[p_vertex].z;
@@ -149,7 +179,6 @@ class Delaunay3D {
}
static bool simplex_is_coplanar(const Vector3 *p_points, const Simplex &p_simplex) {
-
Plane p(p_points[p_simplex.points[0]], p_points[p_simplex.points[1]], p_points[p_simplex.points[2]]);
if (ABS(p.distance_to(p_points[p_simplex.points[3]])) < CMP_EPSILON) {
return true;
@@ -186,7 +215,6 @@ public:
};
static Vector<OutputSimplex> tetrahedralize(const Vector<Vector3> &p_points) {
-
uint32_t point_count = p_points.size();
Vector3 *points = (Vector3 *)memalloc(sizeof(Vector3) * (point_count + 4));
@@ -243,7 +271,6 @@ public:
LocalVector<Triangle> triangles;
for (uint32_t i = 0; i < point_count; i++) {
-
bool unique = true;
for (uint32_t j = i + 1; j < point_count; j++) {
if (points[i].is_equal_approx(points[j])) {
@@ -266,7 +293,6 @@ public:
Simplex *simplex = E->get();
if (simplex_contains(points, *simplex, i)) {
-
static const uint32_t triangle_order[4][3] = {
{ 0, 1, 2 },
{ 0, 1, 3 },
@@ -299,7 +325,6 @@ public:
uint32_t good_triangles = 0;
for (uint32_t j = 0; j < triangles.size(); j++) {
-
if (triangles[j].bad) {
continue;
}
diff --git a/core/math/disjoint_set.h b/core/math/disjoint_set.h
index 32b9875e4c..198f46e111 100644
--- a/core/math/disjoint_set.h
+++ b/core/math/disjoint_set.h
@@ -41,7 +41,6 @@
/* This DisjointSet class uses Find with path compression and Union by rank */
template <typename T, class C = Comparator<T>, class AL = DefaultAllocator>
class DisjointSet {
-
struct Element {
T object;
Element *parent = nullptr;
@@ -103,7 +102,6 @@ typename DisjointSet<T, C, AL>::Element *DisjointSet<T, C, AL>::insert_or_get(T
template <typename T, class C, class AL>
void DisjointSet<T, C, AL>::create_union(T a, T b) {
-
Element *x = insert_or_get(a);
Element *y = insert_or_get(b);
@@ -111,8 +109,9 @@ void DisjointSet<T, C, AL>::create_union(T a, T b) {
Element *y_root = get_parent(y);
// Already in the same set
- if (x_root == y_root)
+ if (x_root == y_root) {
return;
+ }
// Not in the same set, merge
if (x_root->rank < y_root->rank) {
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index c43831ddee..81c1e7f564 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -110,25 +110,22 @@ const char *Expression::func_name[Expression::FUNC_MAX] = {
};
Expression::BuiltinFunc Expression::find_function(const String &p_string) {
-
for (int i = 0; i < FUNC_MAX; i++) {
- if (p_string == func_name[i])
+ if (p_string == func_name[i]) {
return BuiltinFunc(i);
+ }
}
return FUNC_MAX;
}
String Expression::get_func_name(BuiltinFunc p_func) {
-
ERR_FAIL_INDEX_V(p_func, FUNC_MAX, String());
return func_name[p_func];
}
int Expression::get_func_argument_count(BuiltinFunc p_func) {
-
switch (p_func) {
-
case MATH_RANDOMIZE:
case MATH_RAND:
case MATH_RANDF:
@@ -220,194 +217,157 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
r_error.error = Callable::CallError::CALL_OK;
switch (p_func) {
case MATH_SIN: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::sin((double)*p_inputs[0]);
} break;
case MATH_COS: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::cos((double)*p_inputs[0]);
} break;
case MATH_TAN: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::tan((double)*p_inputs[0]);
} break;
case MATH_SINH: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::sinh((double)*p_inputs[0]);
} break;
case MATH_COSH: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::cosh((double)*p_inputs[0]);
} break;
case MATH_TANH: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::tanh((double)*p_inputs[0]);
} break;
case MATH_ASIN: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::asin((double)*p_inputs[0]);
} break;
case MATH_ACOS: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::acos((double)*p_inputs[0]);
} break;
case MATH_ATAN: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::atan((double)*p_inputs[0]);
} break;
case MATH_ATAN2: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return = Math::atan2((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case MATH_SQRT: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::sqrt((double)*p_inputs[0]);
} break;
case MATH_FMOD: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return = Math::fmod((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case MATH_FPOSMOD: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return = Math::fposmod((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case MATH_POSMOD: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return = Math::posmod((int)*p_inputs[0], (int)*p_inputs[1]);
} break;
case MATH_FLOOR: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::floor((double)*p_inputs[0]);
} break;
case MATH_CEIL: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::ceil((double)*p_inputs[0]);
} break;
case MATH_ROUND: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::round((double)*p_inputs[0]);
} break;
case MATH_ABS: {
-
if (p_inputs[0]->get_type() == Variant::INT) {
-
int64_t i = *p_inputs[0];
*r_return = ABS(i);
} else if (p_inputs[0]->get_type() == Variant::FLOAT) {
-
real_t r = *p_inputs[0];
*r_return = Math::abs(r);
} else {
-
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::FLOAT;
}
} break;
case MATH_SIGN: {
-
if (p_inputs[0]->get_type() == Variant::INT) {
-
int64_t i = *p_inputs[0];
*r_return = i < 0 ? -1 : (i > 0 ? +1 : 0);
} else if (p_inputs[0]->get_type() == Variant::FLOAT) {
-
real_t r = *p_inputs[0];
*r_return = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0);
} else {
-
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::FLOAT;
}
} break;
case MATH_POW: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return = Math::pow((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case MATH_LOG: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::log((double)*p_inputs[0]);
} break;
case MATH_EXP: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::exp((double)*p_inputs[0]);
} break;
case MATH_ISNAN: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::is_nan((double)*p_inputs[0]);
} break;
case MATH_ISINF: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::is_inf((double)*p_inputs[0]);
} break;
case MATH_EASE: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return = Math::ease((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case MATH_STEP_DECIMALS: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::step_decimals((double)*p_inputs[0]);
} break;
case MATH_STEPIFY: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return = Math::stepify((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case MATH_LERP: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
*r_return = Math::lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
} break;
case MATH_LERP_ANGLE: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
*r_return = Math::lerp_angle((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
} break;
case MATH_INVERSE_LERP: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
*r_return = Math::inverse_lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
} break;
case MATH_RANGE_LERP: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
@@ -422,14 +382,12 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
*r_return = Math::smoothstep((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
} break;
case MATH_MOVE_TOWARD: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
*r_return = Math::move_toward((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
} break;
case MATH_DECTIME: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
@@ -446,20 +404,17 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
*r_return = Math::randf();
} break;
case MATH_RANDOM: {
-
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return = Math::random((double)*p_inputs[0], (double)*p_inputs[1]);
} break;
case MATH_SEED: {
-
VALIDATE_ARG_NUM(0);
uint64_t seed = *p_inputs[0];
Math::seed(seed);
} break;
case MATH_RANDSEED: {
-
VALIDATE_ARG_NUM(0);
uint64_t seed = *p_inputs[0];
int ret = Math::rand_from_seed(&seed);
@@ -470,22 +425,18 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
} break;
case MATH_DEG2RAD: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::deg2rad((double)*p_inputs[0]);
} break;
case MATH_RAD2DEG: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::rad2deg((double)*p_inputs[0]);
} break;
case MATH_LINEAR2DB: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::linear2db((double)*p_inputs[0]);
} break;
case MATH_DB2LINEAR: {
-
VALIDATE_ARG_NUM(0);
*r_return = Math::db2linear((double)*p_inputs[0]);
} break;
@@ -516,9 +467,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
*r_return = Math::wrapf((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
} break;
case LOGIC_MAX: {
-
if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) {
-
int64_t a = *p_inputs[0];
int64_t b = *p_inputs[1];
*r_return = MAX(a, b);
@@ -534,9 +483,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
} break;
case LOGIC_MIN: {
-
if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) {
-
int64_t a = *p_inputs[0];
int64_t b = *p_inputs[1];
*r_return = MIN(a, b);
@@ -551,9 +498,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
}
} break;
case LOGIC_CLAMP: {
-
if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT && p_inputs[2]->get_type() == Variant::INT) {
-
int64_t a = *p_inputs[0];
int64_t b = *p_inputs[1];
int64_t c = *p_inputs[2];
@@ -571,15 +516,12 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
}
} break;
case LOGIC_NEAREST_PO2: {
-
VALIDATE_ARG_NUM(0);
int64_t num = *p_inputs[0];
*r_return = next_power_of_2(num);
} break;
case OBJ_WEAKREF: {
-
if (p_inputs[0]->get_type() != Variant::OBJECT) {
-
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::OBJECT;
@@ -588,10 +530,8 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
}
if (p_inputs[0]->is_ref()) {
-
REF r = *p_inputs[0];
if (!r.is_valid()) {
-
return;
}
@@ -601,7 +541,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
} else {
Object *obj = *p_inputs[0];
if (!obj) {
-
return;
}
Ref<WeakRef> wref = memnew(WeakRef);
@@ -611,9 +550,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
} break;
case FUNC_FUNCREF: {
-
if (p_inputs[0]->get_type() != Variant::OBJECT) {
-
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::OBJECT;
@@ -621,7 +558,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
return;
}
if (p_inputs[1]->get_type() != Variant::STRING && p_inputs[1]->get_type() != Variant::NODE_PATH) {
-
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 1;
r_error.expected = Variant::STRING;
@@ -638,11 +574,9 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
} break;
case TYPE_CONVERT: {
-
VALIDATE_ARG_NUM(1);
int type = *p_inputs[1];
if (type < 0 || type >= Variant::VARIANT_MAX) {
-
r_error_str = RTR("Invalid type argument to convert(), use TYPE_* constants.");
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
@@ -650,31 +584,25 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
return;
} else {
-
*r_return = Variant::construct(Variant::Type(type), p_inputs, 1, r_error);
}
} break;
case TYPE_OF: {
-
*r_return = p_inputs[0]->get_type();
} break;
case TYPE_EXISTS: {
-
*r_return = ClassDB::class_exists(*p_inputs[0]);
} break;
case TEXT_CHAR: {
-
CharType result[2] = { *p_inputs[0], 0 };
*r_return = String(result);
} break;
case TEXT_ORD: {
-
if (p_inputs[0]->get_type() != Variant::STRING) {
-
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::STRING;
@@ -685,7 +613,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
String str = *p_inputs[0];
if (str.length() != 1) {
-
r_error_str = RTR("Expected a string of length 1 (a character).");
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
@@ -698,39 +625,33 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
} break;
case TEXT_STR: {
-
String str = *p_inputs[0];
*r_return = str;
} break;
case TEXT_PRINT: {
-
String str = *p_inputs[0];
print_line(str);
} break;
case TEXT_PRINTERR: {
-
String str = *p_inputs[0];
print_error(str);
} break;
case TEXT_PRINTRAW: {
-
String str = *p_inputs[0];
OS::get_singleton()->print("%s", str.utf8().get_data());
} break;
case VAR_TO_STR: {
-
String vars;
VariantWriter::write_to_string(*p_inputs[0], vars);
*r_return = vars;
} break;
case STR_TO_VAR: {
-
if (p_inputs[0]->get_type() != Variant::STRING) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
@@ -756,7 +677,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
} break;
case VAR_TO_BYTES: {
-
PackedByteArray barr;
bool full_objects = *p_inputs[1];
int len;
@@ -777,7 +697,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
*r_return = barr;
} break;
case BYTES_TO_VAR: {
-
if (p_inputs[0]->get_type() != Variant::PACKED_BYTE_ARRAY) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
@@ -805,7 +724,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
} break;
case COLORN: {
-
VALIDATE_ARG_NUM(1);
Color color = Color::named(*p_inputs[0]);
@@ -826,60 +744,49 @@ static bool _is_number(CharType c) {
}
Error Expression::_get_token(Token &r_token) {
-
while (true) {
#define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++])
CharType cchar = GET_CHAR();
switch (cchar) {
-
case 0: {
r_token.type = TK_EOF;
return OK;
};
case '{': {
-
r_token.type = TK_CURLY_BRACKET_OPEN;
return OK;
};
case '}': {
-
r_token.type = TK_CURLY_BRACKET_CLOSE;
return OK;
};
case '[': {
-
r_token.type = TK_BRACKET_OPEN;
return OK;
};
case ']': {
-
r_token.type = TK_BRACKET_CLOSE;
return OK;
};
case '(': {
-
r_token.type = TK_PARENTHESIS_OPEN;
return OK;
};
case ')': {
-
r_token.type = TK_PARENTHESIS_CLOSE;
return OK;
};
case ',': {
-
r_token.type = TK_COMMA;
return OK;
};
case ':': {
-
r_token.type = TK_COLON;
return OK;
};
case '$': {
-
r_token.type = TK_INPUT;
int index = 0;
do {
@@ -898,7 +805,6 @@ Error Expression::_get_token(Token &r_token) {
return OK;
};
case '=': {
-
cchar = GET_CHAR();
if (cchar == '=') {
r_token.type = TK_OP_EQUAL;
@@ -910,7 +816,6 @@ Error Expression::_get_token(Token &r_token) {
return OK;
};
case '!': {
-
if (expression[str_ofs] == '=') {
r_token.type = TK_OP_NOT_EQUAL;
str_ofs++;
@@ -920,7 +825,6 @@ Error Expression::_get_token(Token &r_token) {
return OK;
};
case '>': {
-
if (expression[str_ofs] == '=') {
r_token.type = TK_OP_GREATER_EQUAL;
str_ofs++;
@@ -933,7 +837,6 @@ Error Expression::_get_token(Token &r_token) {
return OK;
};
case '<': {
-
if (expression[str_ofs] == '=') {
r_token.type = TK_OP_LESS_EQUAL;
str_ofs++;
@@ -966,7 +869,6 @@ Error Expression::_get_token(Token &r_token) {
return OK;
};
case '&': {
-
if (expression[str_ofs] == '&') {
r_token.type = TK_OP_AND;
str_ofs++;
@@ -976,7 +878,6 @@ Error Expression::_get_token(Token &r_token) {
return OK;
};
case '|': {
-
if (expression[str_ofs] == '|') {
r_token.type = TK_OP_OR;
str_ofs++;
@@ -986,22 +887,18 @@ Error Expression::_get_token(Token &r_token) {
return OK;
};
case '^': {
-
r_token.type = TK_OP_BIT_XOR;
return OK;
};
case '~': {
-
r_token.type = TK_OP_BIT_INVERT;
return OK;
};
case '"': {
-
String str;
while (true) {
-
CharType ch = GET_CHAR();
if (ch == 0) {
@@ -1022,7 +919,6 @@ Error Expression::_get_token(Token &r_token) {
CharType res = 0;
switch (next) {
-
case 'b':
res = 8;
break;
@@ -1049,7 +945,6 @@ Error Expression::_get_token(Token &r_token) {
return ERR_PARSE_ERROR;
}
if (!(_is_number(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
-
_set_error("Malformed hex constant in string");
r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
@@ -1091,7 +986,6 @@ Error Expression::_get_token(Token &r_token) {
} break;
default: {
-
if (cchar <= 32) {
break;
}
@@ -1114,10 +1008,8 @@ Error Expression::_get_token(Token &r_token) {
bool is_float = false;
while (true) {
-
switch (reading) {
case READING_INT: {
-
if (_is_number(c)) {
//pass
} else if (c == '.') {
@@ -1131,9 +1023,7 @@ Error Expression::_get_token(Token &r_token) {
} break;
case READING_DEC: {
-
if (_is_number(c)) {
-
} else if (c == 'e') {
reading = READING_EXP;
@@ -1143,13 +1033,13 @@ Error Expression::_get_token(Token &r_token) {
} break;
case READING_EXP: {
-
if (_is_number(c)) {
exp_beg = true;
} else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) {
- if (c == '-')
+ if (c == '-') {
is_float = true;
+ }
exp_sign = true;
} else {
@@ -1158,8 +1048,9 @@ Error Expression::_get_token(Token &r_token) {
} break;
}
- if (reading == READING_DONE)
+ if (reading == READING_DONE) {
break;
+ }
num += String::chr(c);
c = GET_CHAR();
}
@@ -1168,19 +1059,18 @@ Error Expression::_get_token(Token &r_token) {
r_token.type = TK_CONSTANT;
- if (is_float)
+ if (is_float) {
r_token.value = num.to_double();
- else
+ } else {
r_token.value = num.to_int64();
+ }
return OK;
} else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') {
-
String id;
bool first = true;
while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && _is_number(cchar))) {
-
id += String::chr(cchar);
cchar = GET_CHAR();
first = false;
@@ -1220,7 +1110,6 @@ Error Expression::_get_token(Token &r_token) {
} else if (id == "self") {
r_token.type = TK_SELF;
} else {
-
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
if (id == Variant::get_type_name(Variant::Type(i))) {
r_token.type = TK_BASIC_TYPE;
@@ -1303,7 +1192,6 @@ const char *Expression::token_name[TK_MAX] = {
};
Expression::ENode *Expression::_parse_expression() {
-
Vector<ExpressionNode> expression;
while (true) {
@@ -1312,8 +1200,9 @@ Expression::ENode *Expression::_parse_expression() {
Token tk;
_get_token(tk);
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
switch (tk.type) {
case TK_CURLY_BRACKET_OPEN: {
@@ -1321,7 +1210,6 @@ Expression::ENode *Expression::_parse_expression() {
DictionaryNode *dn = alloc_node<DictionaryNode>();
while (true) {
-
int cofs = str_ofs;
_get_token(tk);
if (tk.type == TK_CURLY_BRACKET_CLOSE) {
@@ -1330,8 +1218,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
dn->dict.push_back(subexpr);
_get_token(tk);
@@ -1341,8 +1230,9 @@ Expression::ENode *Expression::_parse_expression() {
}
subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
dn->dict.push_back(subexpr);
@@ -1365,7 +1255,6 @@ Expression::ENode *Expression::_parse_expression() {
ArrayNode *an = alloc_node<ArrayNode>();
while (true) {
-
int cofs = str_ofs;
_get_token(tk);
if (tk.type == TK_BRACKET_CLOSE) {
@@ -1374,8 +1263,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
an->array.push_back(subexpr);
cofs = str_ofs;
@@ -1394,8 +1284,9 @@ Expression::ENode *Expression::_parse_expression() {
case TK_PARENTHESIS_OPEN: {
//a suexpression
ENode *e = _parse_expression();
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
_get_token(tk);
if (tk.type != TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')'");
@@ -1406,7 +1297,6 @@ Expression::ENode *Expression::_parse_expression() {
} break;
case TK_IDENTIFIER: {
-
String identifier = tk.value;
int cofs = str_ofs;
@@ -1419,7 +1309,6 @@ Expression::ENode *Expression::_parse_expression() {
func_call->base = self_node;
while (true) {
-
int cofs2 = str_ofs;
_get_token(tk);
if (tk.type == TK_PARENTHESIS_CLOSE) {
@@ -1428,8 +1317,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs2; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
func_call->arguments.push_back(subexpr);
@@ -1462,7 +1352,6 @@ Expression::ENode *Expression::_parse_expression() {
input->index = input_index;
expr = input;
} else {
-
NamedIndexNode *index = alloc_node<NamedIndexNode>();
SelfNode *self_node = alloc_node<SelfNode>();
index->base = self_node;
@@ -1472,13 +1361,11 @@ Expression::ENode *Expression::_parse_expression() {
}
} break;
case TK_INPUT: {
-
InputNode *input = alloc_node<InputNode>();
input->index = tk.value;
expr = input;
} break;
case TK_SELF: {
-
SelfNode *self = alloc_node<SelfNode>();
expr = self;
} break;
@@ -1501,7 +1388,6 @@ Expression::ENode *Expression::_parse_expression() {
constructor->data_type = bt;
while (true) {
-
int cofs = str_ofs;
_get_token(tk);
if (tk.type == TK_PARENTHESIS_CLOSE) {
@@ -1510,8 +1396,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
constructor->arguments.push_back(subexpr);
@@ -1542,7 +1429,6 @@ Expression::ENode *Expression::_parse_expression() {
bifunc->func = BuiltinFunc(int(tk.value));
while (true) {
-
int cofs = str_ofs;
_get_token(tk);
if (tk.type == TK_PARENTHESIS_CLOSE) {
@@ -1551,8 +1437,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
bifunc->arguments.push_back(subexpr);
@@ -1576,7 +1463,6 @@ Expression::ENode *Expression::_parse_expression() {
} break;
case TK_OP_SUB: {
-
ExpressionNode e;
e.is_op = true;
e.op = Variant::OP_NEGATE;
@@ -1584,7 +1470,6 @@ Expression::ENode *Expression::_parse_expression() {
continue;
} break;
case TK_OP_NOT: {
-
ExpressionNode e;
e.is_op = true;
e.op = Variant::OP_NOT;
@@ -1603,8 +1488,9 @@ Expression::ENode *Expression::_parse_expression() {
while (true) {
int cofs2 = str_ofs;
_get_token(tk);
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
bool done = false;
@@ -1616,8 +1502,9 @@ Expression::ENode *Expression::_parse_expression() {
index->base = expr;
ENode *what = _parse_expression();
- if (!what)
+ if (!what) {
return nullptr;
+ }
index->index = what;
@@ -1648,7 +1535,6 @@ Expression::ENode *Expression::_parse_expression() {
func_call->base = expr;
while (true) {
-
int cofs3 = str_ofs;
_get_token(tk);
if (tk.type == TK_PARENTHESIS_CLOSE) {
@@ -1657,8 +1543,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs3; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
func_call->arguments.push_back(subexpr);
@@ -1691,8 +1578,9 @@ Expression::ENode *Expression::_parse_expression() {
} break;
}
- if (done)
+ if (done) {
break;
+ }
}
//push expression
@@ -1707,8 +1595,9 @@ Expression::ENode *Expression::_parse_expression() {
int cofs = str_ofs;
_get_token(tk);
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
Variant::Operator op = Variant::OP_MAX;
@@ -1797,15 +1686,12 @@ Expression::ENode *Expression::_parse_expression() {
/* Reduce the set set of expressions and place them in an operator tree, respecting precedence */
while (expression.size() > 1) {
-
int next_op = -1;
int min_priority = 0xFFFFF;
bool is_unary = false;
for (int i = 0; i < expression.size(); i++) {
-
if (!expression[i].is_op) {
-
continue;
}
@@ -1814,7 +1700,6 @@ Expression::ENode *Expression::_parse_expression() {
bool unary = false;
switch (expression[i].op) {
-
case Variant::OP_BIT_NEGATE:
priority = 0;
unary = true;
@@ -1910,17 +1795,14 @@ Expression::ENode *Expression::_parse_expression() {
}
if (next_op == -1) {
-
_set_error("Yet another parser bug....");
ERR_FAIL_V(nullptr);
}
// OK! create operator..
if (is_unary) {
-
int expr_pos = next_op;
while (expression[expr_pos].is_op) {
-
expr_pos++;
if (expr_pos == expression.size()) {
//can happen..
@@ -1931,7 +1813,6 @@ Expression::ENode *Expression::_parse_expression() {
//consecutively do unary operators
for (int i = expr_pos - 1; i >= next_op; i--) {
-
OperatorNode *op = alloc_node<OperatorNode>();
op->op = expression[i].op;
op->nodes[0] = expression[i + 1].node;
@@ -1942,7 +1823,6 @@ Expression::ENode *Expression::_parse_expression() {
}
} else {
-
if (next_op < 1 || next_op >= (expression.size() - 1)) {
_set_error("Parser bug...");
ERR_FAIL_V(nullptr);
@@ -1952,7 +1832,6 @@ Expression::ENode *Expression::_parse_expression() {
op->op = expression[next_op].op;
if (expression[next_op - 1].is_op) {
-
_set_error("Parser bug...");
ERR_FAIL_V(nullptr);
}
@@ -1981,9 +1860,9 @@ Expression::ENode *Expression::_parse_expression() {
}
bool Expression::_compile_expression() {
-
- if (!expression_dirty)
+ if (!expression_dirty) {
return error_set;
+ }
if (nodes) {
memdelete(nodes);
@@ -2011,10 +1890,8 @@ bool Expression::_compile_expression() {
}
bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression::ENode *p_node, Variant &r_ret, String &r_error_str) {
-
switch (p_node->type) {
case Expression::ENode::TYPE_INPUT: {
-
const Expression::InputNode *in = static_cast<const Expression::InputNode *>(p_node);
if (in->index < 0 || in->index >= p_inputs.size()) {
r_error_str = vformat(RTR("Invalid input %i (not passed) in expression"), in->index);
@@ -2023,13 +1900,11 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
r_ret = p_inputs[in->index];
} break;
case Expression::ENode::TYPE_CONSTANT: {
-
const Expression::ConstantNode *c = static_cast<const Expression::ConstantNode *>(p_node);
r_ret = c->value;
} break;
case Expression::ENode::TYPE_SELF: {
-
if (!p_instance) {
r_error_str = RTR("self can't be used because instance is null (not passed)");
return true;
@@ -2037,20 +1912,21 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
r_ret = p_instance;
} break;
case Expression::ENode::TYPE_OPERATOR: {
-
const Expression::OperatorNode *op = static_cast<const Expression::OperatorNode *>(p_node);
Variant a;
bool ret = _execute(p_inputs, p_instance, op->nodes[0], a, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
Variant b;
if (op->nodes[1]) {
ret = _execute(p_inputs, p_instance, op->nodes[1], b, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
}
bool valid = true;
@@ -2062,19 +1938,20 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
} break;
case Expression::ENode::TYPE_INDEX: {
-
const Expression::IndexNode *index = static_cast<const Expression::IndexNode *>(p_node);
Variant base;
bool ret = _execute(p_inputs, p_instance, index->base, base, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
Variant idx;
ret = _execute(p_inputs, p_instance, index->index, idx, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
bool valid;
r_ret = base.get(idx, &valid);
@@ -2085,13 +1962,13 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
} break;
case Expression::ENode::TYPE_NAMED_INDEX: {
-
const Expression::NamedIndexNode *index = static_cast<const Expression::NamedIndexNode *>(p_node);
Variant base;
bool ret = _execute(p_inputs, p_instance, index->base, base, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
bool valid;
r_ret = base.get_named(index->name, &valid);
@@ -2107,12 +1984,12 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
Array arr;
arr.resize(array->array.size());
for (int i = 0; i < array->array.size(); i++) {
-
Variant value;
bool ret = _execute(p_inputs, p_instance, array->array[i], value, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
arr[i] = value;
}
@@ -2124,17 +2001,18 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
Dictionary d;
for (int i = 0; i < dictionary->dict.size(); i += 2) {
-
Variant key;
bool ret = _execute(p_inputs, p_instance, dictionary->dict[i + 0], key, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
Variant value;
ret = _execute(p_inputs, p_instance, dictionary->dict[i + 1], value, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
d[key] = value;
}
@@ -2142,7 +2020,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
r_ret = d;
} break;
case Expression::ENode::TYPE_CONSTRUCTOR: {
-
const Expression::ConstructorNode *constructor = static_cast<const Expression::ConstructorNode *>(p_node);
Vector<Variant> arr;
@@ -2151,12 +2028,12 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
argp.resize(constructor->arguments.size());
for (int i = 0; i < constructor->arguments.size(); i++) {
-
Variant value;
bool ret = _execute(p_inputs, p_instance, constructor->arguments[i], value, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
arr.write[i] = value;
argp.write[i] = &arr[i];
}
@@ -2171,7 +2048,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
} break;
case Expression::ENode::TYPE_BUILTIN_FUNC: {
-
const Expression::BuiltinFuncNode *bifunc = static_cast<const Expression::BuiltinFuncNode *>(p_node);
Vector<Variant> arr;
@@ -2180,11 +2056,11 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
argp.resize(bifunc->arguments.size());
for (int i = 0; i < bifunc->arguments.size(); i++) {
-
Variant value;
bool ret = _execute(p_inputs, p_instance, bifunc->arguments[i], value, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
arr.write[i] = value;
argp.write[i] = &arr[i];
}
@@ -2199,14 +2075,14 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
} break;
case Expression::ENode::TYPE_CALL: {
-
const Expression::CallNode *call = static_cast<const Expression::CallNode *>(p_node);
Variant base;
bool ret = _execute(p_inputs, p_instance, call->base, base, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
Vector<Variant> arr;
Vector<const Variant *> argp;
@@ -2214,12 +2090,12 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
argp.resize(call->arguments.size());
for (int i = 0; i < call->arguments.size(); i++) {
-
Variant value;
ret = _execute(p_inputs, p_instance, call->arguments[i], value, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
arr.write[i] = value;
argp.write[i] = &arr[i];
}
@@ -2238,7 +2114,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
}
Error Expression::parse(const String &p_expression, const Vector<String> &p_input_names) {
-
if (nodes) {
memdelete(nodes);
nodes = nullptr;
@@ -2266,7 +2141,6 @@ Error Expression::parse(const String &p_expression, const Vector<String> &p_inpu
}
Variant Expression::execute(Array p_inputs, Object *p_base, bool p_show_error) {
-
ERR_FAIL_COND_V_MSG(error_set, Variant(), "There was previously a parse error: " + error_str + ".");
execution_error = false;
@@ -2291,7 +2165,6 @@ String Expression::get_error_text() const {
}
void Expression::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("parse", "expression", "input_names"), &Expression::parse, DEFVAL(Vector<String>()));
ClassDB::bind_method(D_METHOD("execute", "inputs", "base_instance", "show_error"), &Expression::execute, DEFVAL(Array()), DEFVAL(Variant()), DEFVAL(true));
ClassDB::bind_method(D_METHOD("has_execute_failed"), &Expression::has_execute_failed);
@@ -2299,7 +2172,6 @@ void Expression::_bind_methods() {
}
Expression::~Expression() {
-
if (nodes) {
memdelete(nodes);
}
diff --git a/core/math/expression.h b/core/math/expression.h
index bf710ecdd5..59a9a2f4ed 100644
--- a/core/math/expression.h
+++ b/core/math/expression.h
@@ -118,7 +118,6 @@ private:
static const char *func_name[FUNC_MAX];
struct Input {
-
Variant::Type type = Variant::NIL;
String name;
@@ -180,14 +179,14 @@ private:
static const char *token_name[TK_MAX];
struct Token {
-
TokenType type;
Variant value;
};
void _set_error(const String &p_err) {
- if (error_set)
+ if (error_set) {
return;
+ }
error_str = p_err;
error_set = true;
}
@@ -198,7 +197,6 @@ private:
bool error_set = true;
struct ENode {
-
enum Type {
TYPE_INPUT,
TYPE_CONSTANT,
@@ -226,7 +224,6 @@ private:
};
struct ExpressionNode {
-
bool is_op;
union {
Variant::Operator op;
@@ -237,7 +234,6 @@ private:
ENode *_parse_expression();
struct InputNode : public ENode {
-
int index;
InputNode() {
type = TYPE_INPUT;
@@ -245,7 +241,6 @@ private:
};
struct ConstantNode : public ENode {
-
Variant value;
ConstantNode() {
type = TYPE_CONSTANT;
@@ -253,7 +248,6 @@ private:
};
struct OperatorNode : public ENode {
-
Variant::Operator op;
ENode *nodes[2];
@@ -264,7 +258,6 @@ private:
};
struct SelfNode : public ENode {
-
SelfNode() {
type = TYPE_SELF;
}
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index 74331b391f..6d76e116be 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -33,7 +33,6 @@
#include "core/math/geometry.h"
int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_over[3]) const {
-
ERR_FAIL_COND_V(is_degenerate(), 0);
Vector3 above[4];
@@ -43,7 +42,6 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_
int below_count = 0;
for (int i = 0; i < 3; i++) {
-
if (p_plane.has_point(vertex[i], CMP_EPSILON)) { // point is in plane
ERR_FAIL_COND_V(above_count >= 4, 0);
@@ -52,7 +50,6 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_
below[below_count++] = vertex[i];
} else {
-
if (p_plane.is_point_over(vertex[i])) {
//Point is over
ERR_FAIL_COND_V(above_count >= 4, 0);
@@ -67,8 +64,9 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_
/* Check for Intersection between this and the next vertex*/
Vector3 inters;
- if (!p_plane.intersects_segment(vertex[i], vertex[(i + 1) % 3], &inters))
+ if (!p_plane.intersects_segment(vertex[i], vertex[(i + 1) % 3], &inters)) {
continue;
+ }
/* Intersection goes to both */
ERR_FAIL_COND_V(above_count >= 4, 0);
@@ -83,13 +81,11 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_
ERR_FAIL_COND_V(above_count >= 4 && below_count >= 4, 0); //bug in the algo
if (above_count >= 3) {
-
p_res[polygons_created] = Face3(above[0], above[1], above[2]);
p_is_point_over[polygons_created] = true;
polygons_created++;
if (above_count == 4) {
-
p_res[polygons_created] = Face3(above[2], above[3], above[0]);
p_is_point_over[polygons_created] = true;
polygons_created++;
@@ -97,13 +93,11 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_
}
if (below_count >= 3) {
-
p_res[polygons_created] = Face3(below[0], below[1], below[2]);
p_is_point_over[polygons_created] = false;
polygons_created++;
if (below_count == 4) {
-
p_res[polygons_created] = Face3(below[2], below[3], below[0]);
p_is_point_over[polygons_created] = false;
polygons_created++;
@@ -114,52 +108,49 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_
}
bool Face3::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const {
-
return Geometry::ray_intersects_triangle(p_from, p_dir, vertex[0], vertex[1], vertex[2], p_intersection);
}
bool Face3::intersects_segment(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const {
-
return Geometry::segment_intersects_triangle(p_from, p_dir, vertex[0], vertex[1], vertex[2], p_intersection);
}
bool Face3::is_degenerate() const {
-
Vector3 normal = vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]);
return (normal.length_squared() < CMP_EPSILON2);
}
Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir) const {
-
int over = 0, under = 0;
Plane plane = get_plane(p_clock_dir);
for (int i = 0; i < 3; i++) {
-
const Vector3 &v = p_face.vertex[i];
- if (plane.has_point(v)) //coplanar, don't bother
+ if (plane.has_point(v)) { //coplanar, don't bother
continue;
+ }
- if (plane.is_point_over(v))
+ if (plane.is_point_over(v)) {
over++;
- else
+ } else {
under++;
+ }
}
- if (over > 0 && under == 0)
+ if (over > 0 && under == 0) {
return SIDE_OVER;
- else if (under > 0 && over == 0)
+ } else if (under > 0 && over == 0) {
return SIDE_UNDER;
- else if (under == 0 && over == 0)
+ } else if (under == 0 && over == 0) {
return SIDE_COPLANAR;
- else
+ } else {
return SIDE_SPANNING;
+ }
}
Vector3 Face3::get_random_point_inside() const {
-
real_t a = Math::random(0, 1);
real_t b = Math::random(0, 1);
if (a > b) {
@@ -170,32 +161,28 @@ Vector3 Face3::get_random_point_inside() const {
}
Plane Face3::get_plane(ClockDirection p_dir) const {
-
return Plane(vertex[0], vertex[1], vertex[2], p_dir);
}
Vector3 Face3::get_median_point() const {
-
return (vertex[0] + vertex[1] + vertex[2]) / 3.0;
}
real_t Face3::get_area() const {
-
return vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]).length();
}
ClockDirection Face3::get_clock_dir() const {
-
Vector3 normal = vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]);
//printf("normal is %g,%g,%g x %g,%g,%g- wtfu is %g\n",tofloat(normal.x),tofloat(normal.y),tofloat(normal.z),tofloat(vertex[0].x),tofloat(vertex[0].y),tofloat(vertex[0].z),tofloat( normal.dot( vertex[0] ) ) );
return (normal.dot(vertex[0]) >= 0) ? CLOCKWISE : COUNTERCLOCKWISE;
}
bool Face3::intersects_aabb(const AABB &p_aabb) const {
-
/** TEST PLANE **/
- if (!p_aabb.intersects_plane(get_plane()))
+ if (!p_aabb.intersects_plane(get_plane())) {
return false;
+ }
#define TEST_AXIS(m_ax) \
/** TEST FACE AXIS */ \
@@ -228,7 +215,6 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const {
};
for (int i = 0; i < 12; i++) {
-
Vector3 from, to;
p_aabb.get_edge(i, from, to);
Vector3 e1 = from - to;
@@ -237,58 +223,57 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const {
Vector3 axis = vec3_cross(e1, e2);
- if (axis.length_squared() < 0.0001)
+ if (axis.length_squared() < 0.0001) {
continue; // coplanar
+ }
axis.normalize();
real_t minA, maxA, minB, maxB;
p_aabb.project_range_in_plane(Plane(axis, 0), minA, maxA);
project_range(axis, Transform(), minB, maxB);
- if (maxA < minB || maxB < minA)
+ if (maxA < minB || maxB < minA) {
return false;
+ }
}
}
return true;
}
Face3::operator String() const {
-
return String() + vertex[0] + ", " + vertex[1] + ", " + vertex[2];
}
void Face3::project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const {
-
for (int i = 0; i < 3; i++) {
-
Vector3 v = p_transform.xform(vertex[i]);
real_t d = p_normal.dot(v);
- if (i == 0 || d > r_max)
+ if (i == 0 || d > r_max) {
r_max = d;
+ }
- if (i == 0 || d < r_min)
+ if (i == 0 || d < r_min) {
r_min = d;
+ }
}
}
void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, Vector3 *p_vertices, int *p_count, int p_max) const {
-
#define _FACE_IS_VALID_SUPPORT_THRESHOLD 0.98
#define _EDGE_IS_VALID_SUPPORT_THRESHOLD 0.05
- if (p_max <= 0)
+ if (p_max <= 0) {
return;
+ }
Vector3 n = p_transform.basis.xform_inv(p_normal);
/** TEST FACE AS SUPPORT **/
if (get_plane().normal.dot(n) > _FACE_IS_VALID_SUPPORT_THRESHOLD) {
-
*p_count = MIN(3, p_max);
for (int i = 0; i < *p_count; i++) {
-
p_vertices[i] = p_transform.xform(vertex[i]);
}
@@ -301,7 +286,6 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V
real_t support_max = 0;
for (int i = 0; i < 3; i++) {
-
real_t d = n.dot(vertex[i]);
if (i == 0 || d > support_max) {
@@ -313,19 +297,19 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V
/** TEST EDGES AS SUPPORT **/
for (int i = 0; i < 3; i++) {
-
- if (i != vert_support_idx && i + 1 != vert_support_idx)
+ if (i != vert_support_idx && i + 1 != vert_support_idx) {
continue;
+ }
// check if edge is valid as a support
real_t dot = (vertex[i] - vertex[(i + 1) % 3]).normalized().dot(n);
dot = ABS(dot);
if (dot < _EDGE_IS_VALID_SUPPORT_THRESHOLD) {
-
*p_count = MIN(2, p_max);
- for (int j = 0; j < *p_count; j++)
+ for (int j = 0; j < *p_count; j++) {
p_vertices[j] = p_transform.xform(vertex[(j + i) % 3]);
+ }
return;
}
@@ -336,7 +320,6 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V
}
Vector3 Face3::get_closest_point_to(const Vector3 &p_point) const {
-
Vector3 edge0 = vertex[1] - vertex[0];
Vector3 edge1 = vertex[2] - vertex[0];
Vector3 v0 = vertex[0] - p_point;
diff --git a/core/math/face3.h b/core/math/face3.h
index da269028f5..fb40e8ab9e 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -78,7 +78,6 @@ public:
void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const;
AABB get_aabb() const {
-
AABB aabb(vertex[0], Vector3());
aabb.expand_to(vertex[1]);
aabb.expand_to(vertex[2]);
@@ -98,7 +97,6 @@ public:
};
bool Face3::intersects_aabb2(const AABB &p_aabb) const {
-
Vector3 perp = (vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]);
Vector3 half_extents = p_aabb.size * 0.5;
@@ -113,8 +111,9 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const {
real_t dist_a = perp.dot(ofs + sup) - d;
real_t dist_b = perp.dot(ofs - sup) - d;
- if (dist_a * dist_b > 0)
+ if (dist_a * dist_b > 0) {
return false; //does not intersect the plane
+ }
#define TEST_AXIS(m_ax) \
{ \
@@ -145,17 +144,13 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const {
};
for (int i = 0; i < 12; i++) {
-
Vector3 from, to;
switch (i) {
-
case 0: {
-
from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z);
to = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z);
} break;
case 1: {
-
from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z);
to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z);
} break;
@@ -165,18 +160,15 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const {
} break;
case 3: {
-
from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z);
to = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z);
} break;
case 4: {
-
from = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
} break;
case 5: {
-
from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z);
} break;
@@ -186,31 +178,26 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const {
} break;
case 7: {
-
from = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z);
to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
} break;
case 8: {
-
from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z);
to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z);
} break;
case 9: {
-
from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z);
to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
} break;
case 10: {
-
from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z);
to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
} break;
case 11: {
-
from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z);
to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z);
@@ -223,8 +210,9 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const {
Vector3 axis = vec3_cross(e1, e2);
- if (axis.length_squared() < 0.0001)
+ if (axis.length_squared() < 0.0001) {
continue; // coplanar
+ }
//axis.normalize();
Vector3 sup2 = Vector3(
@@ -240,18 +228,20 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const {
real_t minT = 1e20, maxT = -1e20;
for (int k = 0; k < 3; k++) {
-
real_t vert_d = axis.dot(vertex[k]);
- if (vert_d > maxT)
+ if (vert_d > maxT) {
maxT = vert_d;
+ }
- if (vert_d < minT)
+ if (vert_d < minT) {
minT = vert_d;
+ }
}
- if (maxB < minT || maxT < minB)
+ if (maxB < minT || maxT < minB) {
return false;
+ }
}
}
return true;
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index f923b62542..f6f22e1db2 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -51,16 +51,14 @@ bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2>
}
return false;
}
+
*/
void Geometry::MeshData::optimize_vertices() {
-
Map<int, int> vtx_remap;
for (int i = 0; i < faces.size(); i++) {
-
for (int j = 0; j < faces[i].indices.size(); j++) {
-
int idx = faces[i].indices[j];
if (!vtx_remap.has(idx)) {
int ni = vtx_remap.size();
@@ -72,7 +70,6 @@ void Geometry::MeshData::optimize_vertices() {
}
for (int i = 0; i < edges.size(); i++) {
-
int a = edges[i].a;
int b = edges[i].b;
@@ -93,17 +90,15 @@ void Geometry::MeshData::optimize_vertices() {
new_vertices.resize(vtx_remap.size());
for (int i = 0; i < vertices.size(); i++) {
-
- if (vtx_remap.has(i))
+ if (vtx_remap.has(i)) {
new_vertices.write[vtx_remap[i]] = vertices[i];
+ }
}
vertices = new_vertices;
}
struct _FaceClassify {
-
struct _Link {
-
int face = -1;
int edge = -1;
void clear() {
@@ -126,42 +121,36 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) {
bool error = false;
for (int i = 0; i < len; i++) {
-
for (int j = 0; j < 3; j++) {
-
p_faces[i].links[j].clear();
}
}
for (int i = 0; i < len; i++) {
-
- if (p_faces[i].group != p_group)
+ if (p_faces[i].group != p_group) {
continue;
+ }
for (int j = i + 1; j < len; j++) {
-
- if (p_faces[j].group != p_group)
+ if (p_faces[j].group != p_group) {
continue;
+ }
for (int k = 0; k < 3; k++) {
-
Vector3 vi1 = p_faces[i].face.vertex[k];
Vector3 vi2 = p_faces[i].face.vertex[(k + 1) % 3];
for (int l = 0; l < 3; l++) {
-
Vector3 vj2 = p_faces[j].face.vertex[l];
Vector3 vj1 = p_faces[j].face.vertex[(l + 1) % 3];
if (vi1.distance_to(vj1) < 0.00001 &&
vi2.distance_to(vj2) < 0.00001) {
if (p_faces[i].links[k].face != -1) {
-
ERR_PRINT("already linked\n");
error = true;
break;
}
if (p_faces[j].links[l].face != -1) {
-
ERR_PRINT("already linked\n");
error = true;
break;
@@ -173,37 +162,38 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) {
p_faces[j].links[l].edge = k;
}
}
- if (error)
+ if (error) {
break;
+ }
}
- if (error)
+ if (error) {
break;
+ }
}
- if (error)
+ if (error) {
break;
+ }
}
for (int i = 0; i < len; i++) {
-
p_faces[i].valid = true;
for (int j = 0; j < 3; j++) {
-
- if (p_faces[i].links[j].face == -1)
+ if (p_faces[i].links[j].face == -1) {
p_faces[i].valid = false;
+ }
}
}
return error;
}
static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_group) {
-
- if (p_faces[p_index].group >= 0)
+ if (p_faces[p_index].group >= 0) {
return false;
+ }
p_faces[p_index].group = p_group;
for (int i = 0; i < 3; i++) {
-
ERR_FAIL_INDEX_V(p_faces[p_index].links[i].face, len, true);
_group_face(p_faces, len, p_faces[p_index].links[i].face, p_group);
}
@@ -212,7 +202,6 @@ static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_grou
}
Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) {
-
Vector<Vector<Face3>> objects;
int len = p_array.size();
@@ -226,7 +215,6 @@ Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) {
_FaceClassify *_fcptr = fc.ptrw();
for (int i = 0; i < len; i++) {
-
_fcptr[i].face = arrayptr[i];
}
@@ -238,9 +226,9 @@ Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) {
int group = 0;
for (int i = 0; i < len; i++) {
-
- if (!_fcptr[i].valid)
+ if (!_fcptr[i].valid) {
continue;
+ }
if (_group_face(_fcptr, len, i, group)) {
group++;
}
@@ -249,20 +237,18 @@ Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) {
// Group connected faces in separate objects.
for (int i = 0; i < len; i++) {
-
_fcptr[i].face = arrayptr[i];
}
if (group >= 0) {
-
objects.resize(group);
Vector<Face3> *group_faces = objects.ptrw();
for (int i = 0; i < len; i++) {
- if (!_fcptr[i].valid)
+ if (!_fcptr[i].valid) {
continue;
+ }
if (_fcptr[i].group >= 0 && _fcptr[i].group < group) {
-
group_faces[_fcptr[i].group].push_back(_fcptr[i].face);
}
}
@@ -299,16 +285,15 @@ enum _CellFlags {
};
static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z, const Vector3 &voxelsize, const Face3 &p_face) {
-
AABB aabb(Vector3(x, y, z), Vector3(len_x, len_y, len_z));
aabb.position = aabb.position * voxelsize;
aabb.size = aabb.size * voxelsize;
- if (!p_face.intersects_aabb(aabb))
+ if (!p_face.intersects_aabb(aabb)) {
return;
+ }
if (len_x == 1 && len_y == 1 && len_z == 1) {
-
p_cell_status[x][y][z] = _CELL_SOLID;
return;
}
@@ -337,15 +322,12 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int
int new_len_z;
for (int i = 0; i < div_x; i++) {
-
_SPLIT(i, div_x, x, len_x, new_x, new_len_x);
for (int j = 0; j < div_y; j++) {
-
_SPLIT(j, div_y, y, len_y, new_y, new_len_y);
for (int k = 0; k < div_z; k++) {
-
_SPLIT(k, div_z, z, len_z, new_z, new_len_z);
_plot_face(p_cell_status, new_x, new_y, new_z, new_len_x, new_len_y, new_len_z, voxelsize, p_face);
@@ -355,14 +337,13 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int
}
static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z) {
-
- if (p_cell_status[x][y][z] & 3)
+ if (p_cell_status[x][y][z] & 3) {
return; // Nothing to do, already used and/or visited.
+ }
p_cell_status[x][y][z] = _CELL_PREV_FIRST;
while (true) {
-
uint8_t &c = p_cell_status[x][y][z];
if ((c & _CELL_STEP_MASK) == _CELL_STEP_NONE) {
@@ -416,9 +397,7 @@ static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z,
uint8_t prev = 0;
switch (c & _CELL_STEP_MASK) {
-
case _CELL_STEP_Y_POS: {
-
next_y++;
prev = _CELL_PREV_Y_NEG;
} break;
@@ -446,15 +425,19 @@ static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z,
ERR_FAIL();
}
- if (next_x < 0 || next_x >= len_x)
+ if (next_x < 0 || next_x >= len_x) {
continue;
- if (next_y < 0 || next_y >= len_y)
+ }
+ if (next_y < 0 || next_y >= len_y) {
continue;
- if (next_z < 0 || next_z >= len_z)
+ }
+ if (next_z < 0 || next_z >= len_z) {
continue;
+ }
- if (p_cell_status[next_x][next_y][next_z] & 3)
+ if (p_cell_status[next_x][next_y][next_z] & 3) {
continue;
+ }
x = next_x;
y = next_y;
@@ -464,13 +447,13 @@ static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z,
}
static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z, Vector<Face3> &p_faces) {
-
ERR_FAIL_INDEX(x, len_x);
ERR_FAIL_INDEX(y, len_y);
ERR_FAIL_INDEX(z, len_z);
- if (p_cell_status[x][y][z] & _CELL_EXTERIOR)
+ if (p_cell_status[x][y][z] & _CELL_EXTERIOR) {
return;
+ }
#define vert(m_idx) Vector3(((m_idx)&4) >> 2, ((m_idx)&2) >> 1, (m_idx)&1)
@@ -485,7 +468,6 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i
};
for (int i = 0; i < 6; i++) {
-
Vector3 face_points[4];
int disp_x = x + ((i % 3) == 0 ? ((i < 3) ? 1 : -1) : 0);
int disp_y = y + (((i - 1) % 3) == 0 ? ((i < 3) ? 1 : -1) : 0);
@@ -493,21 +475,27 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i
bool plot = false;
- if (disp_x < 0 || disp_x >= len_x)
+ if (disp_x < 0 || disp_x >= len_x) {
plot = true;
- if (disp_y < 0 || disp_y >= len_y)
+ }
+ if (disp_y < 0 || disp_y >= len_y) {
plot = true;
- if (disp_z < 0 || disp_z >= len_z)
+ }
+ if (disp_z < 0 || disp_z >= len_z) {
plot = true;
+ }
- if (!plot && (p_cell_status[disp_x][disp_y][disp_z] & _CELL_EXTERIOR))
+ if (!plot && (p_cell_status[disp_x][disp_y][disp_z] & _CELL_EXTERIOR)) {
plot = true;
+ }
- if (!plot)
+ if (!plot) {
continue;
+ }
- for (int j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++) {
face_points[j] = vert(indices[i][j]) + Vector3(x, y, z);
+ }
p_faces.push_back(
Face3(
@@ -524,7 +512,6 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i
}
Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
-
#define _MIN_SIZE 1.0
#define _MAX_LENGTH 20
@@ -534,12 +521,9 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
AABB global_aabb;
for (int i = 0; i < face_count; i++) {
-
if (i == 0) {
-
global_aabb = faces[i].get_aabb();
} else {
-
global_aabb.merge_with(faces[i].get_aabb());
}
}
@@ -549,20 +533,23 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
// Determine amount of cells in grid axis.
int div_x, div_y, div_z;
- if (global_aabb.size.x / _MIN_SIZE < _MAX_LENGTH)
+ if (global_aabb.size.x / _MIN_SIZE < _MAX_LENGTH) {
div_x = (int)(global_aabb.size.x / _MIN_SIZE) + 1;
- else
+ } else {
div_x = _MAX_LENGTH;
+ }
- if (global_aabb.size.y / _MIN_SIZE < _MAX_LENGTH)
+ if (global_aabb.size.y / _MIN_SIZE < _MAX_LENGTH) {
div_y = (int)(global_aabb.size.y / _MIN_SIZE) + 1;
- else
+ } else {
div_y = _MAX_LENGTH;
+ }
- if (global_aabb.size.z / _MIN_SIZE < _MAX_LENGTH)
+ if (global_aabb.size.z / _MIN_SIZE < _MAX_LENGTH) {
div_z = (int)(global_aabb.size.z / _MIN_SIZE) + 1;
- else
+ } else {
div_z = _MAX_LENGTH;
+ }
Vector3 voxelsize = global_aabb.size;
voxelsize.x /= div_x;
@@ -573,15 +560,12 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
uint8_t ***cell_status = memnew_arr(uint8_t **, div_x);
for (int i = 0; i < div_x; i++) {
-
cell_status[i] = memnew_arr(uint8_t *, div_y);
for (int j = 0; j < div_y; j++) {
-
cell_status[i][j] = memnew_arr(uint8_t, div_z);
for (int k = 0; k < div_z; k++) {
-
cell_status[i][j][k] = 0;
}
}
@@ -590,10 +574,8 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
// Plot faces into cells.
for (int i = 0; i < face_count; i++) {
-
Face3 f = faces[i];
for (int j = 0; j < 3; j++) {
-
f.vertex[j] -= global_aabb.position;
}
_plot_face(cell_status, 0, 0, 0, div_x, div_y, div_z, voxelsize, f);
@@ -602,27 +584,21 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
// Determine which cells connect to the outside by traversing the outside and recursively flood-fill marking.
for (int i = 0; i < div_x; i++) {
-
for (int j = 0; j < div_y; j++) {
-
_mark_outside(cell_status, i, j, 0, div_x, div_y, div_z);
_mark_outside(cell_status, i, j, div_z - 1, div_x, div_y, div_z);
}
}
for (int i = 0; i < div_z; i++) {
-
for (int j = 0; j < div_y; j++) {
-
_mark_outside(cell_status, 0, j, i, div_x, div_y, div_z);
_mark_outside(cell_status, div_x - 1, j, i, div_x, div_y, div_z);
}
}
for (int i = 0; i < div_x; i++) {
-
for (int j = 0; j < div_z; j++) {
-
_mark_outside(cell_status, i, 0, j, div_x, div_y, div_z);
_mark_outside(cell_status, i, div_y - 1, j, div_x, div_y, div_z);
}
@@ -633,11 +609,8 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
Vector<Face3> wrapped_faces;
for (int i = 0; i < div_x; i++) {
-
for (int j = 0; j < div_y; j++) {
-
for (int k = 0; k < div_z; k++) {
-
_build_faces(cell_status, i, j, k, div_x, div_y, div_z, wrapped_faces);
}
}
@@ -649,9 +622,7 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
Face3 *wrapped_faces_ptr = wrapped_faces.ptrw();
for (int i = 0; i < wrapped_faces_count; i++) {
-
for (int j = 0; j < 3; j++) {
-
Vector3 &v = wrapped_faces_ptr[i].vertex[j];
v = v * voxelsize;
v += global_aabb.position;
@@ -661,9 +632,7 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
// clean up grid
for (int i = 0; i < div_x; i++) {
-
for (int j = 0; j < div_y; j++) {
-
memdelete_arr(cell_status[i][j]);
}
@@ -671,8 +640,9 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
}
memdelete_arr(cell_status);
- if (p_error)
+ if (p_error) {
*p_error = voxelsize.length();
+ }
return wrapped_faces;
}
@@ -712,20 +682,19 @@ Vector<Vector<Vector2>> Geometry::decompose_polygon_in_convex(Vector<Point2> pol
}
Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
-
MeshData mesh;
#define SUBPLANE_SIZE 1024.0
real_t subplane_size = 1024.0; // Should compute this from the actual plane.
for (int i = 0; i < p_planes.size(); i++) {
-
Plane p = p_planes[i];
Vector3 ref = Vector3(0.0, 1.0, 0.0);
- if (ABS(p.normal.dot(ref)) > 0.95)
+ if (ABS(p.normal.dot(ref)) > 0.95) {
ref = Vector3(0.0, 0.0, 1.0); // Change axis.
+ }
Vector3 right = p.normal.cross(ref).normalized();
Vector3 up = p.normal.cross(right).normalized();
@@ -740,21 +709,22 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
vertices.push_back(center + up * subplane_size + right * subplane_size);
for (int j = 0; j < p_planes.size(); j++) {
-
- if (j == i)
+ if (j == i) {
continue;
+ }
Vector<Vector3> new_vertices;
Plane clip = p_planes[j];
- if (clip.normal.dot(p.normal) > 0.95)
+ if (clip.normal.dot(p.normal) > 0.95) {
continue;
+ }
- if (vertices.size() < 3)
+ if (vertices.size() < 3) {
break;
+ }
for (int k = 0; k < vertices.size(); k++) {
-
int k_n = (k + 1) % vertices.size();
Vector3 edge0_A = vertices[k];
@@ -770,13 +740,13 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
// Check for different sides and non coplanar.
if ((dist0 * dist1) < 0) {
-
// Calculate intersection.
Vector3 rel = edge1_A - edge0_A;
real_t den = clip.normal.dot(rel);
- if (Math::is_zero_approx(den))
+ if (Math::is_zero_approx(den)) {
continue; // Point too short.
+ }
real_t dist = -(clip.normal.dot(edge0_A) - clip.d) / den;
Vector3 inters = edge0_A + rel * dist;
@@ -787,8 +757,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
vertices = new_vertices;
}
- if (vertices.size() < 3)
+ if (vertices.size() < 3) {
continue;
+ }
// Result is a clockwise face.
@@ -796,19 +767,15 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
// Add face indices.
for (int j = 0; j < vertices.size(); j++) {
-
int idx = -1;
for (int k = 0; k < mesh.vertices.size(); k++) {
-
if (mesh.vertices[k].distance_to(vertices[j]) < 0.001) {
-
idx = k;
break;
}
}
if (idx == -1) {
-
idx = mesh.vertices.size();
mesh.vertices.push_back(vertices[j]);
}
@@ -821,13 +788,11 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
// Add edge.
for (int j = 0; j < face.indices.size(); j++) {
-
int a = face.indices[j];
int b = face.indices[(j + 1) % face.indices.size()];
bool found = false;
for (int k = 0; k < mesh.edges.size(); k++) {
-
if (mesh.edges[k].a == a && mesh.edges[k].b == b) {
found = true;
break;
@@ -838,8 +803,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
}
}
- if (found)
+ if (found) {
continue;
+ }
MeshData::Edge edge;
edge.a = a;
edge.b = b;
@@ -851,7 +817,6 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
}
Vector<Plane> Geometry::build_box_planes(const Vector3 &p_extents) {
-
Vector<Plane> planes;
planes.push_back(Plane(Vector3(1, 0, 0), p_extents.x));
@@ -865,11 +830,9 @@ Vector<Plane> Geometry::build_box_planes(const Vector3 &p_extents) {
}
Vector<Plane> Geometry::build_cylinder_planes(real_t p_radius, real_t p_height, int p_sides, Vector3::Axis p_axis) {
-
Vector<Plane> planes;
for (int i = 0; i < p_sides; i++) {
-
Vector3 normal;
normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_sides);
normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_sides);
@@ -887,7 +850,6 @@ Vector<Plane> Geometry::build_cylinder_planes(real_t p_radius, real_t p_height,
}
Vector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats, int p_lons, Vector3::Axis p_axis) {
-
Vector<Plane> planes;
Vector3 axis;
@@ -899,7 +861,6 @@ Vector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats, int p_l
axis_neg[p_axis] = -1.0;
for (int i = 0; i < p_lons; i++) {
-
Vector3 normal;
normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_lons);
normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_lons);
@@ -907,7 +868,6 @@ Vector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats, int p_l
planes.push_back(Plane(normal, p_radius));
for (int j = 1; j <= p_lats; j++) {
-
// FIXME: This is stupid.
Vector3 angle = normal.lerp(axis, j / (real_t)p_lats).normalized();
Vector3 pos = angle * p_radius;
@@ -920,7 +880,6 @@ Vector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats, int p_l
}
Vector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
-
Vector<Plane> planes;
Vector3 axis;
@@ -932,7 +891,6 @@ Vector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, i
axis_neg[p_axis] = -1.0;
for (int i = 0; i < p_sides; i++) {
-
Vector3 normal;
normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_sides);
normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_sides);
@@ -940,7 +898,6 @@ Vector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, i
planes.push_back(Plane(normal, p_radius));
for (int j = 1; j <= p_lats; j++) {
-
Vector3 angle = normal.lerp(axis, j / (real_t)p_lats).normalized();
Vector3 pos = axis * p_height * 0.5 + angle * p_radius;
planes.push_back(Plane(pos, angle));
@@ -952,7 +909,6 @@ Vector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, i
}
struct _AtlasWorkRect {
-
Size2i s;
Point2i p;
int idx;
@@ -960,14 +916,12 @@ struct _AtlasWorkRect {
};
struct _AtlasWorkRectResult {
-
Vector<_AtlasWorkRect> result;
int max_w;
int max_h;
};
void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size) {
-
// Super simple, almost brute force scanline stacking fitter.
// It's pretty basic for now, but it tries to make sure that the aspect ratio of the
// resulting atlas is somehow square. This is necessary because video cards have limits.
@@ -990,55 +944,57 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
Vector<_AtlasWorkRectResult> results;
for (int i = 0; i <= 12; i++) {
-
int w = 1 << i;
int max_h = 0;
int max_w = 0;
- if (w < widest)
+ if (w < widest) {
continue;
+ }
Vector<int> hmax;
hmax.resize(w);
- for (int j = 0; j < w; j++)
+ for (int j = 0; j < w; j++) {
hmax.write[j] = 0;
+ }
// Place them.
int ofs = 0;
int limit_h = 0;
for (int j = 0; j < wrects.size(); j++) {
-
if (ofs + wrects[j].s.width > w) {
-
ofs = 0;
}
int from_y = 0;
for (int k = 0; k < wrects[j].s.width; k++) {
-
- if (hmax[ofs + k] > from_y)
+ if (hmax[ofs + k] > from_y) {
from_y = hmax[ofs + k];
+ }
}
wrects.write[j].p.x = ofs;
wrects.write[j].p.y = from_y;
int end_h = from_y + wrects[j].s.height;
int end_w = ofs + wrects[j].s.width;
- if (ofs == 0)
+ if (ofs == 0) {
limit_h = end_h;
+ }
for (int k = 0; k < wrects[j].s.width; k++) {
-
hmax.write[ofs + k] = end_h;
}
- if (end_h > max_h)
+ if (end_h > max_h) {
max_h = end_h;
+ }
- if (end_w > max_w)
+ if (end_w > max_w) {
max_w = end_w;
+ }
- if (ofs == 0 || end_h > limit_h) // While h limit not reached, keep stacking.
+ if (ofs == 0 || end_h > limit_h) { // While h limit not reached, keep stacking.
ofs += wrects[j].s.width;
+ }
}
_AtlasWorkRectResult result;
@@ -1054,7 +1010,6 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
real_t best_aspect = 1e20;
for (int i = 0; i < results.size(); i++) {
-
real_t h = next_power_of_2(results[i].max_h);
real_t w = next_power_of_2(results[i].max_w);
real_t aspect = h > w ? h / w : w / h;
@@ -1067,7 +1022,6 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
r_result.resize(p_rects.size());
for (int i = 0; i < p_rects.size(); i++) {
-
r_result.write[results[best].result[i].idx] = results[best].result[i].p;
}
@@ -1075,7 +1029,6 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
}
Vector<Vector<Point2>> Geometry::_polypaths_do_operation(PolyBooleanOperation p_op, const Vector<Point2> &p_polypath_a, const Vector<Point2> &p_polypath_b, bool is_a_open) {
-
using namespace ClipperLib;
ClipType op = ctUnion;
@@ -1135,7 +1088,6 @@ Vector<Vector<Point2>> Geometry::_polypaths_do_operation(PolyBooleanOperation p_
}
Vector<Vector<Point2>> Geometry::_polypath_offset(const Vector<Point2> &p_polypath, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
-
using namespace ClipperLib;
JoinType jt = jtSquare;
@@ -1202,19 +1154,16 @@ Vector<Vector<Point2>> Geometry::_polypath_offset(const Vector<Point2> &p_polypa
}
Vector<Vector3> Geometry::compute_convex_mesh_points(const Plane *p_planes, int p_plane_count) {
-
Vector<Vector3> points;
// Iterate through every unique combination of any three planes.
for (int i = p_plane_count - 1; i >= 0; i--) {
for (int j = i - 1; j >= 0; j--) {
for (int k = j - 1; k >= 0; k--) {
-
// Find the point where these planes all cross over (if they
// do at all).
Vector3 convex_shape_point;
if (p_planes[i].intersect_3(p_planes[j], p_planes[k], &convex_shape_point)) {
-
// See if any *other* plane excludes this point because it's
// on the wrong side.
bool excluded = false;
@@ -1241,7 +1190,6 @@ Vector<Vector3> Geometry::compute_convex_mesh_points(const Plane *p_planes, int
}
Vector<Point2i> Geometry::pack_rects(const Vector<Size2i> &p_sizes, const Size2i &p_atlas_size) {
-
Vector<stbrp_node> nodes;
nodes.resize(p_atlas_size.width);
@@ -1277,7 +1225,6 @@ Vector<Point2i> Geometry::pack_rects(const Vector<Size2i> &p_sizes, const Size2i
}
Vector<Vector3i> Geometry::partial_pack_rects(const Vector<Vector2i> &p_sizes, const Size2i &p_atlas_size) {
-
Vector<stbrp_node> nodes;
nodes.resize(p_atlas_size.width);
zeromem(nodes.ptrw(), sizeof(stbrp_node) * nodes.size());
@@ -1314,7 +1261,6 @@ Vector<Vector3i> Geometry::partial_pack_rects(const Vector<Vector2i> &p_sizes, c
/* dt of 1d function using squared distance */
static void edt(float *f, int stride, int n) {
-
float *d = (float *)alloca(sizeof(float) * n + sizeof(int) * n + sizeof(float) * (n + 1));
int *v = (int *)&(d[n]);
float *z = (float *)&v[n];
@@ -1338,8 +1284,9 @@ static void edt(float *f, int stride, int n) {
k = 0;
for (int q = 0; q <= n - 1; q++) {
- while (z[k + 1] < q)
+ while (z[k + 1] < q) {
k++;
+ }
d[q] = square(q - v[k]) + f[v[k] * stride];
}
@@ -1351,7 +1298,6 @@ static void edt(float *f, int stride, int n) {
#undef square
Vector<uint32_t> Geometry::generate_edf(const Vector<bool> &p_voxels, const Vector3i &p_size, bool p_negative) {
-
uint32_t float_count = p_size.x * p_size.y * p_size.z;
ERR_FAIL_COND_V((uint32_t)p_voxels.size() != float_count, Vector<uint32_t>());
@@ -1368,7 +1314,6 @@ Vector<uint32_t> Geometry::generate_edf(const Vector<bool> &p_voxels, const Vect
{
const bool *voxr = p_voxels.ptr();
for (uint32_t i = 0; i < float_count; i++) {
-
bool plot = voxr[i];
if (p_negative) {
plot = !plot;
diff --git a/core/math/geometry.h b/core/math/geometry.h
index b90cae3786..a61bf20c4c 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -45,7 +45,6 @@ class Geometry {
public:
static real_t get_closest_points_between_segments(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2, Vector2 &c1, Vector2 &c2) {
-
Vector2 d1 = q1 - p1; // Direction vector of segment S1.
Vector2 d2 = q2 - p2; // Direction vector of segment S2.
Vector2 r = p1 - p2;
@@ -79,8 +78,9 @@ public:
// clamp to segment S1. Else pick arbitrary s (here 0).
if (denom != 0.0) {
s = CLAMP((b * f - c * e) / denom, 0.0, 1.0);
- } else
+ } else {
s = 0.0;
+ }
// Compute point on L2 closest to S1(s) using
// t = Dot((P1 + D1*s) - P2,D2) / Dot(D2,D2) = (b*s + f) / e
t = (b * s + f) / e;
@@ -103,7 +103,6 @@ public:
}
static void get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2, Vector3 &c1, Vector3 &c2) {
-
// 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))
@@ -112,14 +111,18 @@ public:
real_t mub = (d_of(p1, q1, q2, q1) + mua * d_of(q2, q1, p2, p1)) / d_of(q2, q1, q2, q1);
// Clip the value between [0..1] constraining the solution to lie on the original curves.
- if (mua < 0)
+ if (mua < 0) {
mua = 0;
- if (mub < 0)
+ }
+ if (mub < 0) {
mub = 0;
- if (mua > 1)
+ }
+ if (mua > 1) {
mua = 1;
- if (mub > 1)
+ }
+ if (mub > 1) {
mub = 1;
+ }
c1 = p1.lerp(p2, mua);
c2 = q1.lerp(q2, mub);
}
@@ -160,22 +163,22 @@ public:
if (tN < 0.0) { // tc < 0 => the t=0 edge is visible.
tN = 0.0;
// Recompute sc for this edge.
- if (-d < 0.0)
+ if (-d < 0.0) {
sN = 0.0;
- else if (-d > a)
+ } else if (-d > a) {
sN = sD;
- else {
+ } else {
sN = -d;
sD = a;
}
} else if (tN > tD) { // tc > 1 => the t=1 edge is visible.
tN = tD;
// Recompute sc for this edge.
- if ((-d + b) < 0.0)
+ if ((-d + b) < 0.0) {
sN = 0;
- else if ((-d + b) > a)
+ } else if ((-d + b) > a) {
sN = sD;
- else {
+ } else {
sN = (-d + b);
sD = a;
}
@@ -195,115 +198,129 @@ public:
Vector3 e2 = p_v2 - p_v0;
Vector3 h = p_dir.cross(e2);
real_t a = e1.dot(h);
- if (Math::is_zero_approx(a)) // Parallel test.
+ if (Math::is_zero_approx(a)) { // Parallel test.
return false;
+ }
real_t f = 1.0 / a;
Vector3 s = p_from - p_v0;
real_t u = f * s.dot(h);
- if (u < 0.0 || u > 1.0)
+ if (u < 0.0 || u > 1.0) {
return false;
+ }
Vector3 q = s.cross(e1);
real_t v = f * p_dir.dot(q);
- if (v < 0.0 || u + v > 1.0)
+ if (v < 0.0 || u + v > 1.0) {
return false;
+ }
// At this stage we can compute t to find out where
// the intersection point is on the line.
real_t t = f * e2.dot(q);
if (t > 0.00001) { // ray intersection
- if (r_res)
+ if (r_res) {
*r_res = p_from + p_dir * t;
+ }
return true;
- } else // This means that there is a line intersection but not a ray intersection.
+ } else { // This means that there is a line intersection but not a ray intersection.
return false;
+ }
}
static inline bool segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2, Vector3 *r_res = nullptr) {
-
Vector3 rel = p_to - p_from;
Vector3 e1 = p_v1 - p_v0;
Vector3 e2 = p_v2 - p_v0;
Vector3 h = rel.cross(e2);
real_t a = e1.dot(h);
- if (Math::is_zero_approx(a)) // Parallel test.
+ if (Math::is_zero_approx(a)) { // Parallel test.
return false;
+ }
real_t f = 1.0 / a;
Vector3 s = p_from - p_v0;
real_t u = f * s.dot(h);
- if (u < 0.0 || u > 1.0)
+ if (u < 0.0 || u > 1.0) {
return false;
+ }
Vector3 q = s.cross(e1);
real_t v = f * rel.dot(q);
- if (v < 0.0 || u + v > 1.0)
+ if (v < 0.0 || u + v > 1.0) {
return false;
+ }
// At this stage we can compute t to find out where
// the intersection point is on the line.
real_t t = f * e2.dot(q);
if (t > CMP_EPSILON && t <= 1.0) { // Ray intersection.
- if (r_res)
+ if (r_res) {
*r_res = p_from + rel * t;
+ }
return true;
- } else // This means that there is a line intersection but not a ray intersection.
+ } else { // This means that there is a line intersection but not a ray intersection.
return false;
+ }
}
static inline bool segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 *r_res = nullptr, Vector3 *r_norm = nullptr) {
-
Vector3 sphere_pos = p_sphere_pos - p_from;
Vector3 rel = (p_to - p_from);
real_t rel_l = rel.length();
- if (rel_l < CMP_EPSILON)
+ if (rel_l < CMP_EPSILON) {
return false; // Both points are the same.
+ }
Vector3 normal = rel / rel_l;
real_t sphere_d = normal.dot(sphere_pos);
real_t ray_distance = sphere_pos.distance_to(normal * sphere_d);
- if (ray_distance >= p_sphere_radius)
+ if (ray_distance >= p_sphere_radius) {
return false;
+ }
real_t inters_d2 = p_sphere_radius * p_sphere_radius - ray_distance * ray_distance;
real_t inters_d = sphere_d;
- if (inters_d2 >= CMP_EPSILON)
+ if (inters_d2 >= CMP_EPSILON) {
inters_d -= Math::sqrt(inters_d2);
+ }
// Check in segment.
- if (inters_d < 0 || inters_d > rel_l)
+ if (inters_d < 0 || inters_d > rel_l) {
return false;
+ }
Vector3 result = p_from + normal * inters_d;
- if (r_res)
+ if (r_res) {
*r_res = result;
- if (r_norm)
+ }
+ if (r_norm) {
*r_norm = (result - p_sphere_pos).normalized();
+ }
return true;
}
static inline bool segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, real_t p_height, real_t p_radius, Vector3 *r_res = nullptr, Vector3 *r_norm = nullptr) {
-
Vector3 rel = (p_to - p_from);
real_t rel_l = rel.length();
- if (rel_l < CMP_EPSILON)
+ if (rel_l < CMP_EPSILON) {
return false; // Both points are the same.
+ }
// First check if they are parallel.
Vector3 normal = (rel / rel_l);
@@ -320,13 +337,15 @@ public:
real_t dist = z_dir.dot(p_from);
- if (dist >= p_radius)
+ if (dist >= p_radius) {
return false; // Too far away.
+ }
// Convert to 2D.
real_t w2 = p_radius * p_radius - dist * dist;
- if (w2 < CMP_EPSILON)
+ if (w2 < CMP_EPSILON) {
return false; // Avoid numerical error.
+ }
Size2 size(Math::sqrt(w2), p_height * 0.5);
Vector3 x_dir = z_dir.cross(Vector3(0, 0, 1)).normalized();
@@ -339,7 +358,6 @@ public:
int axis = -1;
for (int i = 0; i < 2; i++) {
-
real_t seg_from = from2D[i];
real_t seg_to = to2D[i];
real_t box_begin = -size[i];
@@ -347,17 +365,17 @@ public:
real_t cmin, cmax;
if (seg_from < seg_to) {
-
- if (seg_from > box_end || seg_to < box_begin)
+ if (seg_from > box_end || seg_to < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0;
cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1;
} else {
-
- if (seg_to > box_end || seg_from < box_begin)
+ if (seg_to > box_end || seg_from < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0;
cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1;
@@ -367,10 +385,12 @@ public:
min = cmin;
axis = i;
}
- if (cmax < max)
+ if (cmax < max) {
max = cmax;
- if (max < min)
+ }
+ if (max < min) {
return false;
+ }
}
// Convert to 3D again.
@@ -386,45 +406,47 @@ public:
res_normal.normalize();
- if (r_res)
+ if (r_res) {
*r_res = result;
- if (r_norm)
+ }
+ if (r_norm) {
*r_norm = res_normal;
+ }
return true;
}
static bool segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Plane *p_planes, int p_plane_count, Vector3 *p_res, Vector3 *p_norm) {
-
real_t min = -1e20, max = 1e20;
Vector3 rel = p_to - p_from;
real_t rel_l = rel.length();
- if (rel_l < CMP_EPSILON)
+ if (rel_l < CMP_EPSILON) {
return false;
+ }
Vector3 dir = rel / rel_l;
int min_index = -1;
for (int i = 0; i < p_plane_count; i++) {
-
const Plane &p = p_planes[i];
real_t den = p.normal.dot(dir);
- if (Math::abs(den) <= CMP_EPSILON)
+ if (Math::abs(den) <= CMP_EPSILON) {
continue; // Ignore parallel plane.
+ }
real_t dist = -p.distance_to(p_from) / den;
if (den > 0) {
// Backwards facing plane.
- if (dist < max)
+ if (dist < max) {
max = dist;
+ }
} else {
-
// Front facing plane.
if (dist > min) {
min = dist;
@@ -433,42 +455,46 @@ public:
}
}
- if (max <= min || min < 0 || min > rel_l || min_index == -1) // Exit conditions.
+ if (max <= min || min < 0 || min > rel_l || min_index == -1) { // Exit conditions.
return false; // No intersection.
+ }
- if (p_res)
+ if (p_res) {
*p_res = p_from + dir * min;
- if (p_norm)
+ }
+ if (p_norm) {
*p_norm = p_planes[min_index].normal;
+ }
return true;
}
static Vector3 get_closest_point_to_segment(const Vector3 &p_point, const Vector3 *p_segment) {
-
Vector3 p = p_point - p_segment[0];
Vector3 n = p_segment[1] - p_segment[0];
real_t l2 = n.length_squared();
- if (l2 < 1e-20)
+ if (l2 < 1e-20) {
return p_segment[0]; // Both points are the same, just give any.
+ }
real_t d = n.dot(p) / l2;
- if (d <= 0.0)
+ if (d <= 0.0) {
return p_segment[0]; // Before first point.
- else if (d >= 1.0)
+ } else if (d >= 1.0) {
return p_segment[1]; // After first point.
- else
+ } else {
return p_segment[0] + n * d; // Inside.
+ }
}
static Vector3 get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 *p_segment) {
-
Vector3 p = p_point - p_segment[0];
Vector3 n = p_segment[1] - p_segment[0];
real_t l2 = n.length_squared();
- if (l2 < 1e-20)
+ if (l2 < 1e-20) {
return p_segment[0]; // Both points are the same, just give any.
+ }
real_t d = n.dot(p) / l2;
@@ -476,21 +502,22 @@ public:
}
static Vector2 get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 *p_segment) {
-
Vector2 p = p_point - p_segment[0];
Vector2 n = p_segment[1] - p_segment[0];
real_t l2 = n.length_squared();
- if (l2 < 1e-20)
+ if (l2 < 1e-20) {
return p_segment[0]; // Both points are the same, just give any.
+ }
real_t d = n.dot(p) / l2;
- if (d <= 0.0)
+ if (d <= 0.0) {
return p_segment[0]; // Before first point.
- else if (d >= 1.0)
+ } else if (d >= 1.0) {
return p_segment[1]; // After first point.
- else
+ } else {
return p_segment[0] + n * d; // Inside.
+ }
}
static bool is_point_in_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) {
@@ -500,19 +527,20 @@ public:
bool orientation = an.cross(bn) > 0;
- if ((bn.cross(cn) > 0) != orientation)
+ if ((bn.cross(cn) > 0) != orientation) {
return false;
+ }
return (cn.cross(an) > 0) == orientation;
}
static Vector2 get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 *p_segment) {
-
Vector2 p = p_point - p_segment[0];
Vector2 n = p_segment[1] - p_segment[0];
real_t l2 = n.length_squared();
- if (l2 < 1e-20)
+ if (l2 < 1e-20) {
return p_segment[0]; // Both points are the same, just give any.
+ }
real_t d = n.dot(p) / l2;
@@ -520,7 +548,6 @@ public:
}
static bool line_intersects_line_2d(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b, Vector2 &r_result) {
-
// See http://paulbourke.net/geometry/pointlineplane/
const real_t denom = p_dir_b.y * p_dir_a.x - p_dir_b.x * p_dir_a.y;
@@ -535,62 +562,68 @@ public:
}
static bool segment_intersects_segment_2d(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b, Vector2 *r_result) {
-
Vector2 B = p_to_a - p_from_a;
Vector2 C = p_from_b - p_from_a;
Vector2 D = p_to_b - p_from_a;
real_t ABlen = B.dot(B);
- if (ABlen <= 0)
+ if (ABlen <= 0) {
return false;
+ }
Vector2 Bn = B / ABlen;
C = Vector2(C.x * Bn.x + C.y * Bn.y, C.y * Bn.x - C.x * Bn.y);
D = Vector2(D.x * Bn.x + D.y * Bn.y, D.y * Bn.x - D.x * Bn.y);
- if ((C.y < 0 && D.y < 0) || (C.y >= 0 && D.y >= 0))
+ if ((C.y < 0 && D.y < 0) || (C.y >= 0 && D.y >= 0)) {
return false;
+ }
real_t ABpos = D.x + (C.x - D.x) * D.y / (D.y - C.y);
// Fail if segment C-D crosses line A-B outside of segment A-B.
- if (ABpos < 0 || ABpos > 1.0)
+ if (ABpos < 0 || ABpos > 1.0) {
return false;
+ }
// (4) Apply the discovered position to line A-B in the original coordinate system.
- if (r_result)
+ if (r_result) {
*r_result = p_from_a + B * ABpos;
+ }
return true;
}
static inline bool point_in_projected_triangle(const Vector3 &p_point, const Vector3 &p_v1, const Vector3 &p_v2, const Vector3 &p_v3) {
-
Vector3 face_n = (p_v1 - p_v3).cross(p_v1 - p_v2);
Vector3 n1 = (p_point - p_v3).cross(p_point - p_v2);
- if (face_n.dot(n1) < 0)
+ if (face_n.dot(n1) < 0) {
return false;
+ }
Vector3 n2 = (p_v1 - p_v3).cross(p_v1 - p_point);
- if (face_n.dot(n2) < 0)
+ if (face_n.dot(n2) < 0) {
return false;
+ }
Vector3 n3 = (p_v1 - p_point).cross(p_v1 - p_v2);
- if (face_n.dot(n3) < 0)
+ if (face_n.dot(n3) < 0) {
return false;
+ }
return true;
}
static inline bool triangle_sphere_intersection_test(const Vector3 *p_triangle, const Vector3 &p_normal, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 &r_triangle_contact, Vector3 &r_sphere_contact) {
-
real_t d = p_normal.dot(p_sphere_pos) - p_normal.dot(p_triangle[0]);
- if (d > p_sphere_radius || d < -p_sphere_radius) // Not touching the plane of the face, return.
+ if (d > p_sphere_radius || d < -p_sphere_radius) {
+ // Not touching the plane of the face, return.
return false;
+ }
Vector3 contact = p_sphere_pos - (p_normal * d);
@@ -608,7 +641,6 @@ public:
const Vector3 verts[4] = { p_triangle[0], p_triangle[1], p_triangle[2], p_triangle[0] }; // for() friendly
for (int i = 0; i < 3; i++) {
-
// Check edge cylinder.
Vector3 n1 = verts[i] - verts[i + 1];
@@ -633,7 +665,6 @@ public:
real_t sphere_at = n1.dot(n2);
if (sphere_at >= 0 && sphere_at < n1.dot(n1)) {
-
r_triangle_contact = p_sphere_pos - axis * (axis.dot(n2));
r_sphere_contact = p_sphere_pos - axis * p_sphere_radius;
// Point inside here.
@@ -643,7 +674,6 @@ public:
real_t r2 = p_sphere_radius * p_sphere_radius;
if (n2.length_squared() < r2) {
-
Vector3 n = (p_sphere_pos - verts[i + 1]).normalized();
r_triangle_contact = verts[i + 1];
@@ -666,12 +696,10 @@ public:
}
static inline bool is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) {
-
return p_point.distance_squared_to(p_circle_pos) <= p_circle_radius * p_circle_radius;
}
static real_t segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) {
-
Vector2 line_vec = p_to - p_from;
Vector2 vec_to_line = p_from - p_circle_pos;
@@ -687,8 +715,9 @@ public:
// If the term we intend to square root is less than 0 then the answer won't be real,
// so it definitely won't be t in the range 0 to 1.
- if (sqrtterm < 0)
+ if (sqrtterm < 0) {
return -1;
+ }
// If we can assume that the line segment starts outside the circle (e.g. for continuous time collision detection)
// then the following can be skipped and we can just return the equivalent of res1.
@@ -696,23 +725,25 @@ public:
real_t res1 = (-b - sqrtterm) / (2 * a);
real_t res2 = (-b + sqrtterm) / (2 * a);
- if (res1 >= 0 && res1 <= 1)
+ if (res1 >= 0 && res1 <= 1) {
return res1;
- if (res2 >= 0 && res2 <= 1)
+ }
+ if (res2 >= 0 && res2 <= 1) {
return res2;
+ }
return -1;
}
static inline Vector<Vector3> clip_polygon(const Vector<Vector3> &polygon, const Plane &p_plane) {
-
enum LocationCache {
LOC_INSIDE = 1,
LOC_BOUNDARY = 0,
LOC_OUTSIDE = -1
};
- if (polygon.size() == 0)
+ if (polygon.size() == 0) {
return polygon;
+ }
int *location_cache = (int *)alloca(sizeof(int) * polygon.size());
int inside_count = 0;
@@ -734,11 +765,8 @@ public:
}
if (outside_count == 0) {
-
return polygon; // No changes.
-
} else if (inside_count == 0) {
-
return Vector<Vector3>(); // Empty.
}
@@ -798,49 +826,40 @@ public:
};
static Vector<Vector<Point2>> merge_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) {
-
return _polypaths_do_operation(OPERATION_UNION, p_polygon_a, p_polygon_b);
}
static Vector<Vector<Point2>> clip_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) {
-
return _polypaths_do_operation(OPERATION_DIFFERENCE, p_polygon_a, p_polygon_b);
}
static Vector<Vector<Point2>> intersect_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) {
-
return _polypaths_do_operation(OPERATION_INTERSECTION, p_polygon_a, p_polygon_b);
}
static Vector<Vector<Point2>> exclude_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) {
-
return _polypaths_do_operation(OPERATION_XOR, p_polygon_a, p_polygon_b);
}
static Vector<Vector<Point2>> clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
-
return _polypaths_do_operation(OPERATION_DIFFERENCE, p_polyline, p_polygon, true);
}
static Vector<Vector<Point2>> intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
-
return _polypaths_do_operation(OPERATION_INTERSECTION, p_polyline, p_polygon, true);
}
static Vector<Vector<Point2>> offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
-
return _polypath_offset(p_polygon, p_delta, p_join_type, END_POLYGON);
}
static Vector<Vector<Point2>> offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
-
ERR_FAIL_COND_V_MSG(p_end_type == END_POLYGON, Vector<Vector<Point2>>(), "Attempt to offset a polyline like a polygon (use offset_polygon_2d instead).");
return _polypath_offset(p_polygon, p_delta, p_join_type, p_end_type);
}
static Vector<int> triangulate_delaunay_2d(const Vector<Vector2> &p_points) {
-
Vector<Delaunay2D::Triangle> tr = Delaunay2D::triangulate(p_points);
Vector<int> triangles;
@@ -853,17 +872,18 @@ public:
}
static Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon) {
-
Vector<int> triangles;
- if (!Triangulate::triangulate(p_polygon, triangles))
+ if (!Triangulate::triangulate(p_polygon, triangles)) {
return Vector<int>(); //fail
+ }
return triangles;
}
static bool is_polygon_clockwise(const Vector<Vector2> &p_polygon) {
int c = p_polygon.size();
- if (c < 3)
+ if (c < 3) {
return false;
+ }
const Vector2 *p = p_polygon.ptr();
real_t sum = 0;
for (int i = 0; i < c; i++) {
@@ -878,8 +898,9 @@ public:
// Alternate implementation that should be faster.
static bool is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon) {
int c = p_polygon.size();
- if (c < 3)
+ if (c < 3) {
return false;
+ }
const Vector2 *p = p_polygon.ptr();
Vector2 further_away(-1e20, -1e20);
Vector2 further_away_opposite(1e20, 1e20);
@@ -912,7 +933,6 @@ public:
static Vector<Face3> wrap_geometry(Vector<Face3> p_array, real_t *p_error = nullptr);
struct MeshData {
-
struct Face {
Plane plane;
Vector<int> indices;
@@ -921,7 +941,6 @@ public:
Vector<Face> faces;
struct Edge {
-
int a, b;
};
@@ -933,7 +952,6 @@ public:
};
_FORCE_INLINE_ static int get_uv84_normal_bit(const Vector3 &p_vector) {
-
int lat = Math::fast_ftoi(Math::floor(Math::acos(p_vector.dot(Vector3(0, 1, 0))) * 4.0 / Math_PI + 0.5));
if (lat == 0) {
@@ -948,33 +966,35 @@ public:
}
_FORCE_INLINE_ static int get_uv84_normal_bit_neighbors(int p_idx) {
-
if (p_idx == 24) {
return 1 | 2 | 4 | 8;
} else if (p_idx == 25) {
return (1 << 23) | (1 << 22) | (1 << 21) | (1 << 20);
} else {
-
int ret = 0;
- if ((p_idx % 8) == 0)
+ if ((p_idx % 8) == 0) {
ret |= (1 << (p_idx + 7));
- else
+ } else {
ret |= (1 << (p_idx - 1));
- if ((p_idx % 8) == 7)
+ }
+ if ((p_idx % 8) == 7) {
ret |= (1 << (p_idx - 7));
- else
+ } else {
ret |= (1 << (p_idx + 1));
+ }
int mask = ret | (1 << p_idx);
- if (p_idx < 8)
+ if (p_idx < 8) {
ret |= 24;
- else
+ } else {
ret |= mask >> 8;
+ }
- if (p_idx >= 16)
+ if (p_idx >= 16) {
ret |= 25;
- else
+ } else {
ret |= mask << 8;
+ }
return ret;
}
@@ -996,15 +1016,17 @@ public:
// Build lower hull.
for (int i = 0; i < n; ++i) {
- while (k >= 2 && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0)
+ while (k >= 2 && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0) {
k--;
+ }
H.write[k++] = P[i];
}
// Build upper hull.
for (int i = n - 2, t = k + 1; i >= 0; i--) {
- while (k >= t && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0)
+ while (k >= t && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0) {
k--;
+ }
H.write[k++] = P[i];
}
@@ -1025,14 +1047,18 @@ public:
#define FINDMINMAX(x0, x1, x2, min, max) \
min = max = x0; \
- if (x1 < min) \
+ if (x1 < min) { \
min = x1; \
- if (x1 > max) \
+ } \
+ if (x1 > max) { \
max = x1; \
- if (x2 < min) \
+ } \
+ if (x2 < min) { \
min = x2; \
- if (x2 > max) \
- max = x2;
+ } \
+ if (x2 > max) { \
+ max = x2; \
+ }
_FORCE_INLINE_ static bool planeBoxOverlap(Vector3 normal, float d, Vector3 maxbox) {
int q;
@@ -1046,10 +1072,12 @@ public:
vmax[q] = -maxbox[q];
}
}
- if (normal.dot(vmin) + d > 0.0f)
+ if (normal.dot(vmin) + d > 0.0f) {
return false;
- if (normal.dot(vmax) + d >= 0.0f)
+ }
+ if (normal.dot(vmax) + d >= 0.0f) {
return true;
+ }
return false;
}
@@ -1066,8 +1094,9 @@ public:
max = p0; \
} \
rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
#define AXISTEST_X2(a, b, fa, fb) \
p0 = a * v0.y - b * v0.z; \
@@ -1080,8 +1109,9 @@ public:
max = p0; \
} \
rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
/*======================== Y-tests ========================*/
#define AXISTEST_Y02(a, b, fa, fb) \
@@ -1095,8 +1125,9 @@ public:
max = p0; \
} \
rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
#define AXISTEST_Y1(a, b, fa, fb) \
p0 = -a * v0.x + b * v0.z; \
@@ -1109,8 +1140,9 @@ public:
max = p0; \
} \
rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
/*======================== Z-tests ========================*/
@@ -1125,8 +1157,9 @@ public:
max = p2; \
} \
rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
#define AXISTEST_Z0(a, b, fa, fb) \
p0 = a * v0.x - b * v0.y; \
@@ -1139,11 +1172,11 @@ public:
max = p0; \
} \
rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
_FORCE_INLINE_ static bool triangle_box_overlap(const Vector3 &boxcenter, const Vector3 boxhalfsize, const Vector3 *triverts) {
-
/* use separating axis theorem to test overlap between triangle and box */
/* need to test for overlap in these directions: */
/* 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle */
@@ -1198,18 +1231,21 @@ public:
/* test in X-direction */
FINDMINMAX(v0.x, v1.x, v2.x, min, max);
- if (min > boxhalfsize.x || max < -boxhalfsize.x)
+ if (min > boxhalfsize.x || max < -boxhalfsize.x) {
return false;
+ }
/* test in Y-direction */
FINDMINMAX(v0.y, v1.y, v2.y, min, max);
- if (min > boxhalfsize.y || max < -boxhalfsize.y)
+ if (min > boxhalfsize.y || max < -boxhalfsize.y) {
return false;
+ }
/* test in Z-direction */
FINDMINMAX(v0.z, v1.z, v2.z, min, max);
- if (min > boxhalfsize.z || max < -boxhalfsize.z)
+ if (min > boxhalfsize.z || max < -boxhalfsize.z) {
return false;
+ }
/* Bullet 2: */
/* test if the box intersects the plane of the triangle */
diff --git a/core/math/math_fieldwise.cpp b/core/math/math_fieldwise.cpp
index a47d4ef7ad..ef2a0c5339 100644
--- a/core/math/math_fieldwise.cpp
+++ b/core/math/math_fieldwise.cpp
@@ -41,7 +41,6 @@
}
Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const String &p_field) {
-
ERR_FAIL_COND_V(p_target.get_type() != p_source.get_type(), p_target);
/* clang-format makes a mess of this macro usage */
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 7417e64ac1..1585c96b38 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -94,16 +94,18 @@ double Math::dectime(double p_value, double p_amount, double p_step) {
double sgn = p_value < 0 ? -1.0 : 1.0;
double val = Math::abs(p_value);
val -= p_amount * p_step;
- if (val < 0.0)
+ if (val < 0.0) {
val = 0.0;
+ }
return val * sgn;
}
double Math::ease(double p_x, double p_c) {
- if (p_x < 0)
+ if (p_x < 0) {
p_x = 0;
- else if (p_x > 1.0)
+ } else if (p_x > 1.0) {
p_x = 1.0;
+ }
if (p_c > 0) {
if (p_c < 1.0) {
return 1.0 - Math::pow(1.0 - p_x, 1.0 / p_c);
@@ -118,8 +120,9 @@ double Math::ease(double p_x, double p_c) {
} else {
return (1.0 - Math::pow(1.0 - (p_x - 0.5) * 2.0, -p_c)) * 0.5 + 0.5;
}
- } else
+ } else {
return 0; // no ease (raw)
+ }
}
double Math::stepify(double p_value, double p_step) {
@@ -130,7 +133,6 @@ double Math::stepify(double p_value, double p_step) {
}
uint32_t Math::larger_prime(uint32_t p_val) {
-
static const uint32_t primes[] = {
5,
13,
@@ -166,10 +168,10 @@ uint32_t Math::larger_prime(uint32_t p_val) {
int idx = 0;
while (true) {
-
ERR_FAIL_COND_V(primes[idx] == 0, 0);
- if (primes[idx] > p_val)
+ if (primes[idx] > p_val) {
return primes[idx];
+ }
idx++;
}
}
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index bd13c82894..7a9fd60e23 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -41,7 +41,6 @@
#include <math.h>
class Math {
-
static RandomPCG default_rand;
public:
@@ -233,14 +232,16 @@ public:
static _ALWAYS_INLINE_ float range_lerp(float p_value, float p_istart, float p_istop, float p_ostart, float p_ostop) { return Math::lerp(p_ostart, p_ostop, Math::inverse_lerp(p_istart, p_istop, p_value)); }
static _ALWAYS_INLINE_ double smoothstep(double p_from, double p_to, double p_weight) {
- if (is_equal_approx(p_from, p_to))
+ if (is_equal_approx(p_from, p_to)) {
return p_from;
+ }
double x = CLAMP((p_weight - p_from) / (p_to - p_from), 0.0, 1.0);
return x * x * (3.0 - 2.0 * x);
}
static _ALWAYS_INLINE_ float smoothstep(float p_from, float p_to, float p_weight) {
- if (is_equal_approx(p_from, p_to))
+ if (is_equal_approx(p_from, p_to)) {
return p_from;
+ }
float x = CLAMP((p_weight - p_from) / (p_to - p_from), 0.0f, 1.0f);
return x * x * (3.0f - 2.0f * x);
}
@@ -328,7 +329,6 @@ public:
}
static _ALWAYS_INLINE_ float absf(float g) {
-
union {
float f;
uint32_t i;
@@ -340,7 +340,6 @@ public:
}
static _ALWAYS_INLINE_ double absd(double g) {
-
union {
double d;
uint64_t i;
@@ -352,7 +351,6 @@ public:
//this function should be as fast as possible and rounding mode should not matter
static _ALWAYS_INLINE_ int fast_ftoi(float a) {
-
static int b;
#if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603) || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // windows 8 phone?
@@ -407,7 +405,6 @@ public:
}
static _ALWAYS_INLINE_ float halfptr_to_float(const uint16_t *h) {
-
union {
uint32_t u32;
float f32;
@@ -422,7 +419,6 @@ public:
}
static _ALWAYS_INLINE_ uint16_t make_half_float(float f) {
-
union {
float fv;
uint32_t ui;
@@ -453,7 +449,6 @@ public:
}
// check if exponent is <= -15
else if (exp <= 0x38000000) {
-
/*// store a denorm half-float value or zero
exp = (0x38000000 - exp) >> 23;
mantissa >>= (14 + exp);
@@ -478,10 +473,11 @@ public:
if (p_step != 0) {
float a = Math::stepify(p_target - p_offset, p_step + p_separation) + p_offset;
float b = a;
- if (p_target >= 0)
+ if (p_target >= 0) {
b -= p_separation;
- else
+ } else {
b += p_step;
+ }
return (Math::abs(p_target - a) < Math::abs(p_target - b)) ? a : b;
}
return p_target;
diff --git a/core/math/octree.h b/core/math/octree.h
index 7d89c50f69..c05fc4e9ed 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -68,7 +68,6 @@ private:
};
struct PairKey {
-
union {
struct {
OctreeElementID A;
@@ -78,18 +77,14 @@ private:
};
_FORCE_INLINE_ bool operator<(const PairKey &p_pair) const {
-
return key < p_pair.key;
}
_FORCE_INLINE_ PairKey(OctreeElementID p_A, OctreeElementID p_B) {
-
if (p_A < p_B) {
-
A = p_A;
B = p_B;
} else {
-
B = p_A;
A = p_B;
}
@@ -101,7 +96,6 @@ private:
struct Element;
struct Octant {
-
// cached for FAST plane check
AABB aabb;
@@ -122,7 +116,6 @@ private:
struct PairData;
struct Element {
-
Octree *octree = nullptr;
T *userdata = nullptr;
@@ -141,7 +134,6 @@ private:
List<PairData *, AL> pair_list;
struct OctantOwner {
-
Octant *octant;
typename List<Element *, AL>::Element *E;
}; // an element can be in max 8 octants
@@ -152,7 +144,6 @@ private:
};
struct PairData {
-
int refcount;
bool intersect;
Element *A, *B;
@@ -179,19 +170,15 @@ private:
int pair_count;
_FORCE_INLINE_ void _pair_check(PairData *p_pair) {
-
bool intersect = p_pair->A->aabb.intersects_inclusive(p_pair->B->aabb);
if (intersect != p_pair->intersect) {
-
if (intersect) {
-
if (pair_callback) {
p_pair->ud = pair_callback(pair_callback_userdata, p_pair->A->_id, p_pair->A->userdata, p_pair->A->subindex, p_pair->B->_id, p_pair->B->userdata, p_pair->B->subindex);
}
pair_count++;
} else {
-
if (unpair_callback) {
unpair_callback(pair_callback_userdata, p_pair->A->_id, p_pair->A->userdata, p_pair->A->subindex, p_pair->B->_id, p_pair->B->userdata, p_pair->B->subindex, p_pair->ud);
}
@@ -203,19 +190,19 @@ private:
}
_FORCE_INLINE_ void _pair_reference(Element *p_A, Element *p_B) {
-
- if (p_A == p_B || (p_A->userdata == p_B->userdata && p_A->userdata))
+ if (p_A == p_B || (p_A->userdata == p_B->userdata && p_A->userdata)) {
return;
+ }
if (!(p_A->pairable_type & p_B->pairable_mask) &&
- !(p_B->pairable_type & p_A->pairable_mask))
+ !(p_B->pairable_type & p_A->pairable_mask)) {
return; // none can pair with none
+ }
PairKey key(p_A->_id, p_B->_id);
typename PairMap::Element *E = pair_map.find(key);
if (!E) {
-
PairData pdata;
pdata.refcount = 1;
pdata.A = p_A;
@@ -230,15 +217,14 @@ private:
pair_callback(pair_callback_userdata,p_A->userdata,p_B->userdata);
*/
} else {
-
E->get().refcount++;
}
}
_FORCE_INLINE_ void _pair_unreference(Element *p_A, Element *p_B) {
-
- if (p_A == p_B)
+ if (p_A == p_B) {
return;
+ }
PairKey key(p_A->_id, p_B->_id);
typename PairMap::Element *E = pair_map.find(key);
@@ -271,24 +257,18 @@ private:
}
_FORCE_INLINE_ void _element_check_pairs(Element *p_element) {
-
typename List<PairData *, AL>::Element *E = p_element->pair_list.front();
while (E) {
-
_pair_check(E->get());
E = E->next();
}
}
_FORCE_INLINE_ void _optimize() {
-
while (root && root->children_count < 2 && !root->elements.size() && !(use_pairs && root->pairable_elements.size())) {
-
Octant *new_root = nullptr;
if (root->children_count == 1) {
-
for (int i = 0; i < 8; i++) {
-
if (root->children[i]) {
new_root = root->children[i];
root->children[i] = nullptr;
@@ -314,7 +294,6 @@ private:
void _unpair_element(Element *p_element, Octant *p_octant);
struct _CullConvexData {
-
const Plane *planes;
int plane_count;
const Vector3 *points;
@@ -331,14 +310,14 @@ private:
void _cull_point(Octant *p_octant, const Vector3 &p_point, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask);
void _remove_tree(Octant *p_octant) {
-
- if (!p_octant)
+ if (!p_octant) {
return;
+ }
for (int i = 0; i < 8; i++) {
-
- if (p_octant->children[i])
+ if (p_octant->children[i]) {
_remove_tree(p_octant->children[i]);
+ }
}
memdelete_allocator<Octant, AL>(p_octant);
@@ -380,7 +359,6 @@ T *Octree<T, use_pairs, AL>::get(OctreeElementID p_id) const {
template <class T, bool use_pairs, class AL>
bool Octree<T, use_pairs, AL>::is_pairable(OctreeElementID p_id) const {
-
const typename ElementMap::Element *E = element_map.find(p_id);
ERR_FAIL_COND_V(!E, false);
return E->get().pairable;
@@ -388,7 +366,6 @@ bool Octree<T, use_pairs, AL>::is_pairable(OctreeElementID p_id) const {
template <class T, bool use_pairs, class AL>
int Octree<T, use_pairs, AL>::get_subindex(OctreeElementID p_id) const {
-
const typename ElementMap::Element *E = element_map.find(p_id);
ERR_FAIL_COND_V(!E, -1);
return E->get().subindex;
@@ -398,7 +375,6 @@ int Octree<T, use_pairs, AL>::get_subindex(OctreeElementID p_id) const {
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_octant) {
-
real_t element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues
if (p_octant->aabb.size.x / OCTREE_DIVISOR < element_size) {
@@ -409,11 +385,9 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct
owner.octant = p_octant;
if (use_pairs && p_element->pairable) {
-
p_octant->pairable_elements.push_back(p_element);
owner.E = p_octant->pairable_elements.back();
} else {
-
p_octant->elements.push_back(p_element);
owner.E = p_octant->elements.back();
}
@@ -428,11 +402,9 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct
}
if (use_pairs && p_octant->children_count > 0) {
-
pass++; //elements below this only get ONE reference added
for (int i = 0; i < 8; i++) {
-
if (p_octant->children[i]) {
_pair_element(p_element, p_octant->children[i]);
}
@@ -444,7 +416,6 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct
bool candidate = p_element->common_parent == nullptr;
for (int i = 0; i < 8; i++) {
-
if (p_octant->children[i]) {
/* element exists, go straight to it */
if (p_octant->children[i]->aabb.intersects_inclusive(p_element->aabb)) {
@@ -457,12 +428,15 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct
AABB aabb = p_octant->aabb;
aabb.size *= 0.5;
- if (i & 1)
+ if (i & 1) {
aabb.position.x += aabb.size.x;
- if (i & 2)
+ }
+ if (i & 2) {
aabb.position.y += aabb.size.y;
- if (i & 4)
+ }
+ if (i & 4) {
aabb.position.z += aabb.size.z;
+ }
if (aabb.intersects_inclusive(p_element->aabb)) {
/* if actually intersects, create the child */
@@ -484,13 +458,11 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct
}
if (candidate && splits > 1) {
-
p_element->common_parent = p_octant;
}
}
if (use_pairs) {
-
typename List<Element *, AL>::Element *E = p_octant->pairable_elements.front();
while (E) {
@@ -511,14 +483,12 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_ensure_valid_root(const AABB &p_aabb) {
-
if (!root) {
// octre is empty
AABB base(Vector3(), Vector3(1.0, 1.0, 1.0) * unit_size);
while (!base.encloses(p_aabb)) {
-
if (ABS(base.position.x + base.size.x) <= ABS(base.position.x)) {
/* grow towards positive */
base.size *= 2.0;
@@ -537,11 +507,9 @@ void Octree<T, use_pairs, AL>::_ensure_valid_root(const AABB &p_aabb) {
octant_count++;
} else {
-
AABB base = root->aabb;
while (!base.encloses(p_aabb)) {
-
ERR_FAIL_COND_MSG(base.size.x > OCTREE_SIZE_LIMIT, "Octree upper size limit reached, does the AABB supplied contain NAN?");
Octant *gp = memnew_allocator(Octant, AL);
@@ -570,15 +538,14 @@ void Octree<T, use_pairs, AL>::_ensure_valid_root(const AABB &p_aabb) {
template <class T, bool use_pairs, class AL>
bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, Octant *p_octant, Octant *p_limit) {
-
bool octant_removed = false;
while (true) {
-
// check all exit conditions
- if (p_octant == p_limit) // reached limit, nothing to erase, exit
+ if (p_octant == p_limit) { // reached limit, nothing to erase, exit
return octant_removed;
+ }
bool unpaired = false;
@@ -607,7 +574,6 @@ bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, O
Octant *parent = p_octant->parent;
if (p_octant->children_count == 0 && p_octant->elements.empty() && p_octant->pairable_elements.empty()) {
-
// erase octant
if (p_octant == root) { // won't have a parent, just erase
@@ -626,8 +592,9 @@ bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, O
octant_removed = true;
}
- if (!removed && !unpaired)
+ if (!removed && !unpaired) {
return octant_removed; // no reason to keep going up anymore! was already visited and was not removed
+ }
p_octant = parent;
}
@@ -637,7 +604,6 @@ bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, O
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_unpair_element(Element *p_element, Octant *p_octant) {
-
// always test pairable
typename List<Element *, AL>::Element *E = p_octant->pairable_elements.front();
while (E) {
@@ -662,25 +628,24 @@ void Octree<T, use_pairs, AL>::_unpair_element(Element *p_element, Octant *p_oct
p_octant->last_pass = pass;
- if (p_octant->children_count == 0)
+ if (p_octant->children_count == 0) {
return; // small optimization for leafs
+ }
for (int i = 0; i < 8; i++) {
-
- if (p_octant->children[i])
+ if (p_octant->children[i]) {
_unpair_element(p_element, p_octant->children[i]);
+ }
}
}
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_pair_element(Element *p_element, Octant *p_octant) {
-
// always test pairable
typename List<Element *, AL>::Element *E = p_octant->pairable_elements.front();
while (E) {
-
if (E->get()->last_pass != pass) { // only get ONE reference
_pair_reference(p_element, E->get());
E->get()->last_pass = pass;
@@ -701,30 +666,30 @@ void Octree<T, use_pairs, AL>::_pair_element(Element *p_element, Octant *p_octan
}
p_octant->last_pass = pass;
- if (p_octant->children_count == 0)
+ if (p_octant->children_count == 0) {
return; // small optimization for leafs
+ }
for (int i = 0; i < 8; i++) {
-
- if (p_octant->children[i])
+ if (p_octant->children[i]) {
_pair_element(p_element, p_octant->children[i]);
+ }
}
}
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_remove_element(Element *p_element) {
-
pass++; // will do a new pass for this
typename List<typename Element::OctantOwner, AL>::Element *I = p_element->octant_owners.front();
/* FIRST remove going up normally */
for (; I; I = I->next()) {
-
Octant *o = I->get().octant;
- if (!use_pairs) // small speedup
+ if (!use_pairs) { // small speedup
o->elements.erase(I->get().E);
+ }
_remove_element_from_octant(p_element, o);
}
@@ -734,30 +699,28 @@ void Octree<T, use_pairs, AL>::_remove_element(Element *p_element) {
I = p_element->octant_owners.front();
if (use_pairs) {
-
for (; I; I = I->next()) {
-
Octant *o = I->get().octant;
// erase children pairs, they are erased ONCE even if repeated
pass++;
for (int i = 0; i < 8; i++) {
-
- if (o->children[i])
+ if (o->children[i]) {
_unpair_element(p_element, o->children[i]);
+ }
}
- if (p_element->pairable)
+ if (p_element->pairable) {
o->pairable_elements.erase(I->get().E);
- else
+ } else {
o->elements.erase(I->get().E);
+ }
}
}
p_element->octant_owners.clear();
if (use_pairs) {
-
int remaining = p_element->pair_list.size();
//p_element->pair_list.clear();
ERR_FAIL_COND(remaining);
@@ -766,7 +729,6 @@ void Octree<T, use_pairs, AL>::_remove_element(Element *p_element) {
template <class T, bool use_pairs, class AL>
OctreeElementID Octree<T, use_pairs, AL>::create(T *p_userdata, const AABB &p_aabb, int p_subindex, bool p_pairable, uint32_t p_pairable_type, uint32_t p_pairable_mask) {
-
// check for AABB validity
#ifdef DEBUG_ENABLED
ERR_FAIL_COND_V(p_aabb.position.x > 1e15 || p_aabb.position.x < -1e15, 0);
@@ -797,8 +759,9 @@ OctreeElementID Octree<T, use_pairs, AL>::create(T *p_userdata, const AABB &p_aa
if (!e.aabb.has_no_surface()) {
_ensure_valid_root(p_aabb);
_insert_element(&e, root);
- if (use_pairs)
+ if (use_pairs) {
_element_check_pairs(&e);
+ }
}
return last_element_id - 1;
@@ -806,7 +769,6 @@ OctreeElementID Octree<T, use_pairs, AL>::create(T *p_userdata, const AABB &p_aa
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
-
#ifdef DEBUG_ENABLED
// check for AABB validity
ERR_FAIL_COND(p_aabb.position.x > 1e15 || p_aabb.position.x < -1e15);
@@ -827,7 +789,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
bool new_has_surf = !p_aabb.has_no_surface();
if (old_has_surf != new_has_surf) {
-
if (old_has_surf) {
_remove_element(&e); // removing
e.common_parent = nullptr;
@@ -838,22 +799,24 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
e.common_parent = nullptr;
e.aabb = p_aabb;
_insert_element(&e, root);
- if (use_pairs)
+ if (use_pairs) {
_element_check_pairs(&e);
+ }
}
return;
}
- if (!old_has_surf) // doing nothing
+ if (!old_has_surf) { // doing nothing
return;
+ }
// it still is enclosed in the same AABB it was assigned to
if (e.container_aabb.encloses(p_aabb)) {
-
e.aabb = p_aabb;
- if (use_pairs)
+ if (use_pairs) {
_element_check_pairs(&e); // must check pairs anyway
+ }
return;
}
@@ -873,8 +836,9 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
//src is now the place towards where insertion is going to happen
pass++;
- while (common_parent && !common_parent->aabb.encloses(p_aabb))
+ while (common_parent && !common_parent->aabb.encloses(p_aabb)) {
common_parent = common_parent->parent;
+ }
ERR_FAIL_COND(!common_parent);
@@ -888,7 +852,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
pass++;
for (typename List<typename Element::OctantOwner, AL>::Element *F = owners.front(); F;) {
-
Octant *o = F->get().octant;
typename List<typename Element::OctantOwner, AL>::Element *N = F->next();
@@ -897,13 +860,13 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
o->elements.erase( F->get().E );
*/
- if (use_pairs && e.pairable)
+ if (use_pairs && e.pairable) {
o->pairable_elements.erase(F->get().E);
- else
+ } else {
o->elements.erase(F->get().E);
+ }
if (_remove_element_from_octant(&e, o, common_parent->parent)) {
-
owners.erase(F);
}
@@ -913,15 +876,14 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
if (use_pairs) {
//unpair child elements in anything that survived
for (typename List<typename Element::OctantOwner, AL>::Element *F = owners.front(); F; F = F->next()) {
-
Octant *o = F->get().octant;
// erase children pairs, unref ONCE
pass++;
for (int i = 0; i < 8; i++) {
-
- if (o->children[i])
+ if (o->children[i]) {
_unpair_element(&e, o->children[i]);
+ }
}
}
@@ -933,14 +895,14 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::set_pairable(OctreeElementID p_id, bool p_pairable, uint32_t p_pairable_type, uint32_t p_pairable_mask) {
-
typename ElementMap::Element *E = element_map.find(p_id);
ERR_FAIL_COND(!E);
Element &e = E->get();
- if (p_pairable == e.pairable && e.pairable_type == p_pairable_type && e.pairable_mask == p_pairable_mask)
+ if (p_pairable == e.pairable && e.pairable_type == p_pairable_type && e.pairable_mask == p_pairable_mask) {
return; // no changes, return
+ }
if (!e.aabb.has_no_surface()) {
_remove_element(&e);
@@ -954,21 +916,20 @@ void Octree<T, use_pairs, AL>::set_pairable(OctreeElementID p_id, bool p_pairabl
if (!e.aabb.has_no_surface()) {
_ensure_valid_root(e.aabb);
_insert_element(&e, root);
- if (use_pairs)
+ if (use_pairs) {
_element_check_pairs(&e);
+ }
}
}
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::erase(OctreeElementID p_id) {
-
typename ElementMap::Element *E = element_map.find(p_id);
ERR_FAIL_COND(!E);
Element &e = E->get();
if (!e.aabb.has_no_surface()) {
-
_remove_element(&e);
}
@@ -978,21 +939,20 @@ void Octree<T, use_pairs, AL>::erase(OctreeElementID p_id) {
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) {
-
- if (*p_cull->result_idx == p_cull->result_max)
+ if (*p_cull->result_idx == p_cull->result_max) {
return; //pointless
+ }
if (!p_octant->elements.empty()) {
-
typename List<Element *, AL>::Element *I;
I = p_octant->elements.front();
for (; I; I = I->next()) {
-
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) {
@@ -1000,7 +960,6 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p
p_cull->result_array[*p_cull->result_idx] = e->userdata;
(*p_cull->result_idx)++;
} else {
-
return; // pointless to continue
}
}
@@ -1008,26 +967,22 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p
}
if (use_pairs && !p_octant->pairable_elements.empty()) {
-
typename List<Element *, AL>::Element *I;
I = p_octant->pairable_elements.front();
for (; I; I = I->next()) {
-
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) {
-
if (*p_cull->result_idx < p_cull->result_max) {
-
p_cull->result_array[*p_cull->result_idx] = e->userdata;
(*p_cull->result_idx)++;
} else {
-
return; // pointless to continue
}
}
@@ -1035,7 +990,6 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p
}
for (int i = 0; i < 8; i++) {
-
if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) {
_cull_convex(p_octant->children[i], p_cull);
}
@@ -1044,33 +998,30 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
-
- if (*p_result_idx == p_result_max)
+ if (*p_result_idx == p_result_max) {
return; //pointless
+ }
if (!p_octant->elements.empty()) {
-
typename List<Element *, AL>::Element *I;
I = p_octant->elements.front();
for (; I; I = I->next()) {
-
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (p_aabb.intersects_inclusive(e->aabb)) {
-
if (*p_result_idx < p_result_max) {
-
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
} else {
-
return; // pointless to continue
}
}
@@ -1078,27 +1029,24 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb,
}
if (use_pairs && !p_octant->pairable_elements.empty()) {
-
typename List<Element *, AL>::Element *I;
I = p_octant->pairable_elements.front();
for (; I; I = I->next()) {
-
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (p_aabb.intersects_inclusive(e->aabb)) {
-
if (*p_result_idx < p_result_max) {
-
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
} else {
-
return; // pointless to continue
}
}
@@ -1106,7 +1054,6 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb,
}
for (int i = 0; i < 8; i++) {
-
if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_inclusive(p_aabb)) {
_cull_aabb(p_octant->children[i], p_aabb, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask);
}
@@ -1115,33 +1062,30 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb,
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
-
- if (*p_result_idx == p_result_max)
+ if (*p_result_idx == p_result_max) {
return; //pointless
+ }
if (!p_octant->elements.empty()) {
-
typename List<Element *, AL>::Element *I;
I = p_octant->elements.front();
for (; I; I = I->next()) {
-
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.intersects_segment(p_from, p_to)) {
-
if (*p_result_idx < p_result_max) {
-
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
} else {
-
return; // pointless to continue
}
}
@@ -1149,30 +1093,27 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_
}
if (use_pairs && !p_octant->pairable_elements.empty()) {
-
typename List<Element *, AL>::Element *I;
I = p_octant->pairable_elements.front();
for (; I; I = I->next()) {
-
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.intersects_segment(p_from, p_to)) {
-
if (*p_result_idx < p_result_max) {
-
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
} else {
-
return; // pointless to continue
}
}
@@ -1180,7 +1121,6 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_
}
for (int i = 0; i < 8; i++) {
-
if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_segment(p_from, p_to)) {
_cull_segment(p_octant->children[i], p_from, p_to, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask);
}
@@ -1189,33 +1129,30 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
-
- if (*p_result_idx == p_result_max)
+ if (*p_result_idx == p_result_max) {
return; //pointless
+ }
if (!p_octant->elements.empty()) {
-
typename List<Element *, AL>::Element *I;
I = p_octant->elements.front();
for (; I; I = I->next()) {
-
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.has_point(p_point)) {
-
if (*p_result_idx < p_result_max) {
-
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
} else {
-
return; // pointless to continue
}
}
@@ -1223,30 +1160,27 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po
}
if (use_pairs && !p_octant->pairable_elements.empty()) {
-
typename List<Element *, AL>::Element *I;
I = p_octant->pairable_elements.front();
for (; I; I = I->next()) {
-
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.has_point(p_point)) {
-
if (*p_result_idx < p_result_max) {
-
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
} else {
-
return; // pointless to continue
}
}
@@ -1254,7 +1188,6 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po
}
for (int i = 0; i < 8; i++) {
-
//could be optimized..
if (p_octant->children[i] && p_octant->children[i]->aabb.has_point(p_point)) {
_cull_point(p_octant->children[i], p_point, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask);
@@ -1264,13 +1197,14 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po
template <class T, bool use_pairs, class AL>
int Octree<T, use_pairs, AL>::cull_convex(const Vector<Plane> &p_convex, T **p_result_array, int p_result_max, uint32_t p_mask) {
-
- if (!root || p_convex.size() == 0)
+ if (!root || p_convex.size() == 0) {
return 0;
+ }
Vector<Vector3> convex_points = Geometry::compute_convex_mesh_points(&p_convex[0], p_convex.size());
- if (convex_points.size() == 0)
+ if (convex_points.size() == 0) {
return 0;
+ }
int result_count = 0;
pass++;
@@ -1291,9 +1225,9 @@ int Octree<T, use_pairs, AL>::cull_convex(const Vector<Plane> &p_convex, T **p_r
template <class T, bool use_pairs, class AL>
int Octree<T, use_pairs, AL>::cull_aabb(const AABB &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
-
- if (!root)
+ if (!root) {
return 0;
+ }
int result_count = 0;
pass++;
@@ -1304,9 +1238,9 @@ int Octree<T, use_pairs, AL>::cull_aabb(const AABB &p_aabb, T **p_result_array,
template <class T, bool use_pairs, class AL>
int Octree<T, use_pairs, AL>::cull_segment(const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
-
- if (!root)
+ if (!root) {
return 0;
+ }
int result_count = 0;
pass++;
@@ -1317,9 +1251,9 @@ int Octree<T, use_pairs, AL>::cull_segment(const Vector3 &p_from, const Vector3
template <class T, bool use_pairs, class AL>
int Octree<T, use_pairs, AL>::cull_point(const Vector3 &p_point, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
-
- if (!root)
+ if (!root) {
return 0;
+ }
int result_count = 0;
pass++;
@@ -1330,20 +1264,18 @@ int Octree<T, use_pairs, AL>::cull_point(const Vector3 &p_point, T **p_result_ar
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::set_pair_callback(PairCallback p_callback, void *p_userdata) {
-
pair_callback = p_callback;
pair_callback_userdata = p_userdata;
}
+
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::set_unpair_callback(UnpairCallback p_callback, void *p_userdata) {
-
unpair_callback = p_callback;
unpair_callback_userdata = p_userdata;
}
template <class T, bool use_pairs, class AL>
Octree<T, use_pairs, AL>::Octree(real_t p_unit_size) {
-
last_element_id = 1;
pass = 1;
unit_size = p_unit_size;
diff --git a/core/math/plane.cpp b/core/math/plane.cpp
index 26ac0aac47..df37ceb0e5 100644
--- a/core/math/plane.cpp
+++ b/core/math/plane.cpp
@@ -33,12 +33,10 @@
#include "core/math/math_funcs.h"
void Plane::set_normal(const Vector3 &p_normal) {
-
normal = p_normal;
}
void Plane::normalize() {
-
real_t l = normal.length();
if (l == 0) {
*this = Plane(0, 0, 0, 0);
@@ -49,27 +47,25 @@ void Plane::normalize() {
}
Plane Plane::normalized() const {
-
Plane p = *this;
p.normalize();
return p;
}
Vector3 Plane::get_any_point() const {
-
return get_normal() * d;
}
Vector3 Plane::get_any_perpendicular_normal() const {
-
static const Vector3 p1 = Vector3(1, 0, 0);
static const Vector3 p2 = Vector3(0, 1, 0);
Vector3 p;
- if (ABS(normal.dot(p1)) > 0.99) // if too similar to p1
+ if (ABS(normal.dot(p1)) > 0.99) { // if too similar to p1
p = p2; // use p2
- else
+ } else {
p = p1; // use p1
+ }
p -= normal * normal.dot(p);
p.normalize();
@@ -80,7 +76,6 @@ Vector3 Plane::get_any_perpendicular_normal() const {
/* intersections */
bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result) const {
-
const Plane &p_plane0 = *this;
Vector3 normal0 = p_plane0.normal;
Vector3 normal1 = p_plane1.normal;
@@ -88,8 +83,9 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r
real_t denom = vec3_cross(normal0, normal1).dot(normal2);
- if (Math::is_zero_approx(denom))
+ if (Math::is_zero_approx(denom)) {
return false;
+ }
if (r_result) {
*r_result = ((vec3_cross(normal1, normal2) * p_plane0.d) +
@@ -102,13 +98,11 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r
}
bool Plane::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const {
-
Vector3 segment = p_dir;
real_t den = normal.dot(segment);
//printf("den is %i\n",den);
if (Math::is_zero_approx(den)) {
-
return false;
}
@@ -127,13 +121,11 @@ bool Plane::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3
}
bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const {
-
Vector3 segment = p_begin - p_end;
real_t den = normal.dot(segment);
//printf("den is %i\n",den);
if (Math::is_zero_approx(den)) {
-
return false;
}
@@ -141,7 +133,6 @@ bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vec
//printf("dist is %i\n",dist);
if (dist < -CMP_EPSILON || dist > (1.0 + CMP_EPSILON)) {
-
return false;
}
@@ -158,11 +149,9 @@ bool Plane::is_equal_approx_any_side(const Plane &p_plane) const {
}
bool Plane::is_equal_approx(const Plane &p_plane) const {
-
return normal.is_equal_approx(p_plane.normal) && Math::is_equal_approx(d, p_plane.d);
}
Plane::operator String() const {
-
return normal.operator String() + ", " + rtos(d);
}
diff --git a/core/math/plane.h b/core/math/plane.h
index f4f205465f..9a3e5a485f 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -61,7 +61,6 @@ public:
bool intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const;
_FORCE_INLINE_ Vector3 project(const Vector3 &p_point) const {
-
return p_point - normal * distance_to(p_point);
}
@@ -86,17 +85,14 @@ public:
};
bool Plane::is_point_over(const Vector3 &p_point) const {
-
return (normal.dot(p_point) > d);
}
real_t Plane::distance_to(const Vector3 &p_point) const {
-
return (normal.dot(p_point) - d);
}
bool Plane::has_point(const Vector3 &p_point, real_t _epsilon) const {
-
real_t dist = normal.dot(p_point) - d;
dist = ABS(dist);
return (dist <= _epsilon);
@@ -113,23 +109,21 @@ Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal) :
}
Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir) {
-
- if (p_dir == CLOCKWISE)
+ if (p_dir == CLOCKWISE) {
normal = (p_point1 - p_point3).cross(p_point1 - p_point2);
- else
+ } else {
normal = (p_point1 - p_point2).cross(p_point1 - p_point3);
+ }
normal.normalize();
d = normal.dot(p_point1);
}
bool Plane::operator==(const Plane &p_plane) const {
-
return normal == p_plane.normal && d == p_plane.d;
}
bool Plane::operator!=(const Plane &p_plane) const {
-
return normal != p_plane.normal || d != p_plane.d;
}
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index 6fbea70279..c10f5da494 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -107,7 +107,6 @@ Vector3 Quat::get_euler_yxz() const {
}
void Quat::operator*=(const Quat &q) {
-
set(w * q.x + x * q.w + y * q.z - z * q.y,
w * q.y + y * q.w + z * q.x - x * q.z,
w * q.z + z * q.w + x * q.y - y * q.x,
@@ -115,19 +114,16 @@ void Quat::operator*=(const Quat &q) {
}
Quat Quat::operator*(const Quat &q) const {
-
Quat r = *this;
r *= q;
return r;
}
bool Quat::is_equal_approx(const Quat &p_quat) const {
-
return Math::is_equal_approx(x, p_quat.x) && Math::is_equal_approx(y, p_quat.y) && Math::is_equal_approx(z, p_quat.z) && Math::is_equal_approx(w, p_quat.w);
}
real_t Quat::length() const {
-
return Math::sqrt(length_squared());
}
@@ -206,8 +202,9 @@ Quat Quat::slerpni(const Quat &q, const real_t &t) const {
real_t dot = from.dot(q);
- if (Math::absf(dot) > 0.9999)
+ if (Math::absf(dot) > 0.9999) {
return from;
+ }
real_t theta = Math::acos(dot),
sinT = 1.0 / Math::sin(theta),
@@ -233,7 +230,6 @@ Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const
}
Quat::operator String() const {
-
return String::num(x) + ", " + String::num(y) + ", " + String::num(z) + ", " + String::num(w);
}
@@ -242,9 +238,9 @@ void Quat::set_axis_angle(const Vector3 &axis, const real_t &angle) {
ERR_FAIL_COND_MSG(!axis.is_normalized(), "The axis Vector3 must be normalized.");
#endif
real_t d = axis.length();
- if (d == 0)
+ if (d == 0) {
set(0, 0, 0, 0);
- else {
+ } else {
real_t sin_angle = Math::sin(angle * 0.5);
real_t cos_angle = Math::cos(angle * 0.5);
real_t s = sin_angle / d;
diff --git a/core/math/quat.h b/core/math/quat.h
index 1ca6fe7ce3..64d0f00912 100644
--- a/core/math/quat.h
+++ b/core/math/quat.h
@@ -149,7 +149,6 @@ public:
z = 0;
w = 0;
} else {
-
real_t s = Math::sqrt((1.0 + d) * 2.0);
real_t rs = 1.0 / s;
@@ -191,7 +190,6 @@ void Quat::operator*=(const real_t &s) {
}
void Quat::operator/=(const real_t &s) {
-
*this *= 1.0 / s;
}
diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp
index 7fbb26c377..fe16904448 100644
--- a/core/math/quick_hull.cpp
+++ b/core/math/quick_hull.cpp
@@ -35,12 +35,10 @@
uint32_t QuickHull::debug_stop_after = 0xFFFFFFFF;
Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_mesh) {
-
/* CREATE AABB VOLUME */
AABB aabb;
for (int i = 0; i < p_points.size(); i++) {
-
if (i == 0) {
aabb.position = p_points[i];
} else {
@@ -57,7 +55,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Set<Vector3> valid_cache;
for (int i = 0; i < p_points.size(); i++) {
-
Vector3 sp = p_points[i].snapped(Vector3(0.0001, 0.0001, 0.0001));
if (valid_cache.has(sp)) {
valid_points.write[i] = false;
@@ -78,12 +75,11 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
real_t max = 0, min = 0;
for (int i = 0; i < p_points.size(); i++) {
-
- if (!valid_points[i])
+ if (!valid_points[i]) {
continue;
+ }
real_t d = p_points[i][longest_axis];
if (i == 0 || d < min) {
-
simplex[0] = i;
min = d;
}
@@ -102,15 +98,14 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Vector3 rel12 = p_points[simplex[0]] - p_points[simplex[1]];
for (int i = 0; i < p_points.size(); i++) {
-
- if (!valid_points[i])
+ if (!valid_points[i]) {
continue;
+ }
Vector3 n = rel12.cross(p_points[simplex[0]] - p_points[i]).cross(rel12).normalized();
real_t d = Math::abs(n.dot(p_points[simplex[0]]) - n.dot(p_points[i]));
if (i == 0 || d > maxd) {
-
maxd = d;
simplex[2] = i;
}
@@ -124,14 +119,13 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Plane p(p_points[simplex[0]], p_points[simplex[1]], p_points[simplex[2]]);
for (int i = 0; i < p_points.size(); i++) {
-
- if (!valid_points[i])
+ if (!valid_points[i]) {
continue;
+ }
real_t d = Math::abs(p.distance_to(p_points[i]));
if (i == 0 || d > maxd) {
-
maxd = d;
simplex[3] = i;
}
@@ -152,7 +146,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
List<Face> faces;
for (int i = 0; i < 4; i++) {
-
static const int face_order[4][3] = {
{ 0, 1, 2 },
{ 0, 1, 3 },
@@ -183,22 +176,24 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
/* COMPUTE AVAILABLE VERTICES */
for (int i = 0; i < p_points.size(); i++) {
-
- if (i == simplex[0])
+ if (i == simplex[0]) {
continue;
- if (i == simplex[1])
+ }
+ if (i == simplex[1]) {
continue;
- if (i == simplex[2])
+ }
+ if (i == simplex[2]) {
continue;
- if (i == simplex[3])
+ }
+ if (i == simplex[3]) {
continue;
- if (!valid_points[i])
+ }
+ if (!valid_points[i]) {
continue;
+ }
for (List<Face>::Element *E = faces.front(); E; E = E->next()) {
-
if (E->get().plane.distance_to(p_points[i]) > over_tolerance) {
-
E->get().points_over.push_back(i);
break;
}
@@ -219,7 +214,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
uint32_t debug_stop = debug_stop_after;
while (debug_stop > 0 && faces.back()->get().points_over.size()) {
-
debug_stop--;
Face &f = faces.back()->get();
@@ -228,7 +222,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
real_t next_d = 0;
for (int i = 0; i < f.points_over.size(); i++) {
-
real_t d = f.plane.distance_to(p_points[f.points_over[i]]);
if (d > next_d) {
@@ -247,9 +240,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Map<Edge, FaceConnect> lit_edges; //create this on the flight, should not be that bad for performance and simplifies code a lot
for (List<Face>::Element *E = faces.front(); E; E = E->next()) {
-
if (E->get().plane.distance_to(v) > 0) {
-
lit_faces.push_back(E);
for (int i = 0; i < 3; i++) {
@@ -265,7 +256,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
//left
F->get().left = E;
} else {
-
F->get().right = E;
}
}
@@ -276,7 +266,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
List<List<Face>::Element *> new_faces; //new faces
for (Map<Edge, FaceConnect>::Element *E = lit_edges.front(); E; E = E->next()) {
-
FaceConnect &fc = E->get();
if (fc.left && fc.right) {
continue; //edge is uninteresting, not on horizont
@@ -304,17 +293,15 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
//distribute points into new faces
for (List<List<Face>::Element *>::Element *F = lit_faces.front(); F; F = F->next()) {
-
Face &lf = F->get()->get();
for (int i = 0; i < lf.points_over.size(); i++) {
-
- if (lf.points_over[i] == f.points_over[next]) //do not add current one
+ if (lf.points_over[i] == f.points_over[next]) { //do not add current one
continue;
+ }
Vector3 p = p_points[lf.points_over[i]];
for (List<List<Face>::Element *>::Element *E = new_faces.front(); E; E = E->next()) {
-
Face &f2 = E->get()->get();
if (f2.plane.distance_to(p) > over_tolerance) {
f2.points_over.push_back(lf.points_over[i]);
@@ -327,7 +314,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
//erase lit faces
while (lit_faces.size()) {
-
faces.erase(lit_faces.front()->get());
lit_faces.pop_front();
}
@@ -335,7 +321,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
//put faces that contain no points on the front
for (List<List<Face>::Element *>::Element *E = new_faces.front(); E; E = E->next()) {
-
Face &f2 = E->get()->get();
if (f2.points_over.size() == 0) {
faces.move_to_front(E->get());
@@ -352,7 +337,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
List<Geometry::MeshData::Face> ret_faces;
for (List<Face>::Element *E = faces.front(); E; E = E->next()) {
-
Geometry::MeshData::Face f;
f.plane = E->get().plane;
@@ -363,7 +347,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
List<Geometry::MeshData::Face>::Element *F = ret_faces.push_back(f);
for (int i = 0; i < 3; i++) {
-
uint32_t a = E->get().vertices[i];
uint32_t b = E->get().vertices[(i + 1) % 3];
Edge e(a, b);
@@ -376,7 +359,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
//left
G->get().left = F;
} else {
-
G->get().right = F;
}
}
@@ -385,11 +367,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
//fill faces
for (List<Geometry::MeshData::Face>::Element *E = ret_faces.front(); E; E = E->next()) {
-
Geometry::MeshData::Face &f = E->get();
for (int i = 0; i < f.indices.size(); i++) {
-
int a = E->get().indices[i];
int b = E->get().indices[(i + 1) % f.indices.size()];
Edge e(a, b);
@@ -411,7 +391,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
if (O->get().indices[j] == a) {
//append the rest
for (int k = 0; k < ois; k++) {
-
int idx = O->get().indices[(k + j) % ois];
int idxn = O->get().indices[(k + j + 1) % ois];
if (idx == b && idxn == a) { //already have b!
@@ -427,10 +406,11 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Map<Edge, RetFaceConnect>::Element *F2 = ret_edges.find(e2);
ERR_CONTINUE(!F2);
//change faceconnect, point to this face instead
- if (F2->get().left == O)
+ if (F2->get().left == O) {
F2->get().left = E;
- else if (F2->get().right == O)
+ } else if (F2->get().right == O) {
F2->get().right = E;
+ }
}
break;
@@ -439,11 +419,13 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
// remove all edge connections to this face
for (Map<Edge, RetFaceConnect>::Element *G = ret_edges.front(); G; G = G->next()) {
- if (G->get().left == O)
+ if (G->get().left == O) {
G->get().left = nullptr;
+ }
- if (G->get().right == O)
+ if (G->get().right == O) {
G->get().right = nullptr;
+ }
}
ret_edges.erase(F); //remove the edge
@@ -463,7 +445,6 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
r_mesh.edges.resize(ret_edges.size());
idx = 0;
for (Map<Edge, RetFaceConnect>::Element *E = ret_edges.front(); E; E = E->next()) {
-
Geometry::MeshData::Edge e;
e.a = E->key().vertices[0];
e.b = E->key().vertices[1];
diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h
index 89061ab415..29f709febe 100644
--- a/core/math/quick_hull.h
+++ b/core/math/quick_hull.h
@@ -37,10 +37,8 @@
#include "core/set.h"
class QuickHull {
-
public:
struct Edge {
-
union {
uint32_t vertices[2];
uint64_t id;
@@ -51,7 +49,6 @@ public:
}
Edge(int p_vtx_a = 0, int p_vtx_b = 0) {
-
if (p_vtx_a > p_vtx_b) {
SWAP(p_vtx_a, p_vtx_b);
}
@@ -62,13 +59,11 @@ public:
};
struct Face {
-
Plane plane;
uint32_t vertices[3];
Vector<int> points_over;
bool operator<(const Face &p_face) const {
-
return points_over.size() < p_face.points_over.size();
}
};
diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h
index 2b125433b3..920308e597 100644
--- a/core/math/random_number_generator.h
+++ b/core/math/random_number_generator.h
@@ -59,10 +59,11 @@ public:
_FORCE_INLINE_ int randi_range(int from, int to) {
unsigned int ret = randbase.rand();
- if (to < from)
+ if (to < from) {
return ret % (from - to + 1) + to;
- else
+ } else {
return ret % (to - from + 1) + from;
+ }
}
RandomNumberGenerator() {}
diff --git a/core/math/rect2.cpp b/core/math/rect2.cpp
index 12b9904c88..0cc3c4ca0f 100644
--- a/core/math/rect2.cpp
+++ b/core/math/rect2.cpp
@@ -31,12 +31,10 @@
#include "core/math/transform_2d.h" // Includes rect2.h but Rect2 needs Transform2D
bool Rect2::is_equal_approx(const Rect2 &p_rect) const {
-
return position.is_equal_approx(p_rect.position) && size.is_equal_approx(p_rect.size);
}
bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos, Point2 *r_normal) const {
-
real_t min = 0, max = 1;
int axis = 0;
real_t sign = 0;
@@ -50,18 +48,18 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
real_t csign;
if (seg_from < seg_to) {
-
- if (seg_from > box_end || seg_to < box_begin)
+ if (seg_from > box_end || seg_to < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0;
cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1;
csign = -1.0;
} else {
-
- if (seg_to > box_end || seg_from < box_begin)
+ if (seg_to > box_end || seg_from < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0;
cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1;
@@ -73,10 +71,12 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
axis = i;
sign = csign;
}
- if (cmax < max)
+ if (cmax < max) {
max = cmax;
- if (max < min)
+ }
+ if (max < min) {
return false;
+ }
}
Vector2 rel = p_to - p_from;
@@ -87,14 +87,14 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
*r_normal = normal;
}
- if (r_pos)
+ if (r_pos) {
*r_pos = p_from + rel * min;
+ }
return true;
}
bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const {
-
//SAT intersection between local and transformed rect2
Vector2 xf_points[4] = {
@@ -108,14 +108,18 @@ bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_re
//base rect2 first (faster)
- if (xf_points[0].y > position.y)
+ if (xf_points[0].y > position.y) {
goto next1;
- if (xf_points[1].y > position.y)
+ }
+ if (xf_points[1].y > position.y) {
goto next1;
- if (xf_points[2].y > position.y)
+ }
+ if (xf_points[2].y > position.y) {
goto next1;
- if (xf_points[3].y > position.y)
+ }
+ if (xf_points[3].y > position.y) {
goto next1;
+ }
return false;
@@ -123,27 +127,35 @@ next1:
low_limit = position.y + size.y;
- if (xf_points[0].y < low_limit)
+ if (xf_points[0].y < low_limit) {
goto next2;
- if (xf_points[1].y < low_limit)
+ }
+ if (xf_points[1].y < low_limit) {
goto next2;
- if (xf_points[2].y < low_limit)
+ }
+ if (xf_points[2].y < low_limit) {
goto next2;
- if (xf_points[3].y < low_limit)
+ }
+ if (xf_points[3].y < low_limit) {
goto next2;
+ }
return false;
next2:
- if (xf_points[0].x > position.x)
+ if (xf_points[0].x > position.x) {
goto next3;
- if (xf_points[1].x > position.x)
+ }
+ if (xf_points[1].x > position.x) {
goto next3;
- if (xf_points[2].x > position.x)
+ }
+ if (xf_points[2].x > position.x) {
goto next3;
- if (xf_points[3].x > position.x)
+ }
+ if (xf_points[3].x > position.x) {
goto next3;
+ }
return false;
@@ -151,14 +163,18 @@ next3:
low_limit = position.x + size.x;
- if (xf_points[0].x < low_limit)
+ if (xf_points[0].x < low_limit) {
goto next4;
- if (xf_points[1].x < low_limit)
+ }
+ if (xf_points[1].x < low_limit) {
goto next4;
- if (xf_points[2].x < low_limit)
+ }
+ if (xf_points[2].x < low_limit) {
goto next4;
- if (xf_points[3].x < low_limit)
+ }
+ if (xf_points[3].x < low_limit) {
goto next4;
+ }
return false;
@@ -201,10 +217,12 @@ next4:
maxb = MAX(dp, maxb);
minb = MIN(dp, minb);
- if (mina > maxb)
+ if (mina > maxb) {
return false;
- if (minb > maxa)
+ }
+ if (minb > maxa) {
return false;
+ }
maxa = p_xform.elements[1].dot(xf_points2[0]);
mina = maxa;
@@ -236,10 +254,12 @@ next4:
maxb = MAX(dp, maxb);
minb = MIN(dp, minb);
- if (mina > maxb)
+ if (mina > maxb) {
return false;
- if (minb > maxa)
+ }
+ if (minb > maxa) {
return false;
+ }
return true;
}
diff --git a/core/math/rect2.h b/core/math/rect2.h
index a3f3634bfb..1b86dbd49a 100644
--- a/core/math/rect2.h
+++ b/core/math/rect2.h
@@ -36,7 +36,6 @@
struct Transform2D;
struct Rect2 {
-
Point2 position;
Size2 size;
@@ -49,30 +48,37 @@ struct Rect2 {
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))
+ if (position.x > (p_rect.position.x + p_rect.size.width)) {
return false;
- if ((position.x + size.width) < p_rect.position.x)
+ }
+ if ((position.x + size.width) < p_rect.position.x) {
return false;
- if (position.y > (p_rect.position.y + p_rect.size.height))
+ }
+ if (position.y > (p_rect.position.y + p_rect.size.height)) {
return false;
- if ((position.y + size.height) < p_rect.position.y)
+ }
+ if ((position.y + size.height) < p_rect.position.y) {
return false;
+ }
} else {
- if (position.x >= (p_rect.position.x + p_rect.size.width))
+ if (position.x >= (p_rect.position.x + p_rect.size.width)) {
return false;
- if ((position.x + size.width) <= p_rect.position.x)
+ }
+ if ((position.x + size.width) <= p_rect.position.x) {
return false;
- if (position.y >= (p_rect.position.y + p_rect.size.height))
+ }
+ if (position.y >= (p_rect.position.y + p_rect.size.height)) {
return false;
- if ((position.y + size.height) <= p_rect.position.y)
+ }
+ if ((position.y + size.height) <= p_rect.position.y) {
return false;
+ }
}
return true;
}
inline real_t distance_to(const Vector2 &p_point) const {
-
real_t dist = 0.0;
bool inside = true;
@@ -97,10 +103,11 @@ struct Rect2 {
inside = false;
}
- if (inside)
+ if (inside) {
return 0;
- else
+ } else {
return dist;
+ }
}
bool intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const;
@@ -108,22 +115,21 @@ struct Rect2 {
bool intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos = nullptr, Point2 *r_normal = nullptr) const;
inline bool encloses(const Rect2 &p_rect) const {
-
return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) &&
((p_rect.position.x + p_rect.size.x) <= (position.x + size.x)) &&
((p_rect.position.y + p_rect.size.y) <= (position.y + size.y));
}
_FORCE_INLINE_ bool has_no_area() const {
-
return (size.x <= 0 || size.y <= 0);
}
inline Rect2 clip(const Rect2 &p_rect) const { /// return a clipped rect
Rect2 new_rect = p_rect;
- if (!intersects(new_rect))
+ if (!intersects(new_rect)) {
return Rect2();
+ }
new_rect.position.x = MAX(p_rect.position.x, position.x);
new_rect.position.y = MAX(p_rect.position.y, position.y);
@@ -152,15 +158,19 @@ struct Rect2 {
return new_rect;
};
inline bool has_point(const Point2 &p_point) const {
- if (p_point.x < position.x)
+ if (p_point.x < position.x) {
return false;
- if (p_point.y < position.y)
+ }
+ if (p_point.y < position.y) {
return false;
+ }
- if (p_point.x >= (position.x + size.x))
+ if (p_point.x >= (position.x + size.x)) {
return false;
- if (p_point.y >= (position.y + size.y))
+ }
+ if (p_point.y >= (position.y + size.y)) {
return false;
+ }
return true;
}
@@ -170,7 +180,6 @@ struct Rect2 {
bool operator!=(const Rect2 &p_rect) const { return position != p_rect.position || size != p_rect.size; }
inline Rect2 grow(real_t p_by) const {
-
Rect2 g = *this;
g.position.x -= p_by;
g.position.y -= p_by;
@@ -189,7 +198,6 @@ struct Rect2 {
}
inline Rect2 grow_individual(real_t p_left, real_t p_top, real_t p_right, real_t p_bottom) const {
-
Rect2 g = *this;
g.position.x -= p_left;
g.position.y -= p_top;
@@ -200,7 +208,6 @@ struct Rect2 {
}
_FORCE_INLINE_ Rect2 expand(const Vector2 &p_vector) const {
-
Rect2 r = *this;
r.expand_to(p_vector);
return r;
@@ -211,22 +218,25 @@ struct Rect2 {
Vector2 begin = position;
Vector2 end = position + size;
- if (p_vector.x < begin.x)
+ if (p_vector.x < begin.x) {
begin.x = p_vector.x;
- if (p_vector.y < begin.y)
+ }
+ if (p_vector.y < begin.y) {
begin.y = p_vector.y;
+ }
- if (p_vector.x > end.x)
+ if (p_vector.x > end.x) {
end.x = p_vector.x;
- if (p_vector.y > end.y)
+ }
+ if (p_vector.y > end.y) {
end.y = p_vector.y;
+ }
position = begin;
size = end - begin;
}
_FORCE_INLINE_ Rect2 abs() const {
-
return Rect2(Point2(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs());
}
@@ -244,7 +254,6 @@ struct Rect2 {
};
struct Rect2i {
-
Point2i position;
Size2i size;
@@ -256,35 +265,38 @@ struct Rect2i {
int get_area() const { return size.width * size.height; }
inline bool intersects(const Rect2i &p_rect) const {
- if (position.x > (p_rect.position.x + p_rect.size.width))
+ if (position.x > (p_rect.position.x + p_rect.size.width)) {
return false;
- if ((position.x + size.width) < p_rect.position.x)
+ }
+ if ((position.x + size.width) < p_rect.position.x) {
return false;
- if (position.y > (p_rect.position.y + p_rect.size.height))
+ }
+ if (position.y > (p_rect.position.y + p_rect.size.height)) {
return false;
- if ((position.y + size.height) < p_rect.position.y)
+ }
+ if ((position.y + size.height) < p_rect.position.y) {
return false;
+ }
return true;
}
inline bool encloses(const Rect2i &p_rect) const {
-
return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) &&
((p_rect.position.x + p_rect.size.x) < (position.x + size.x)) &&
((p_rect.position.y + p_rect.size.y) < (position.y + size.y));
}
_FORCE_INLINE_ bool has_no_area() const {
-
return (size.x <= 0 || size.y <= 0);
}
inline Rect2i clip(const Rect2i &p_rect) const { /// return a clipped rect
Rect2i new_rect = p_rect;
- if (!intersects(new_rect))
+ if (!intersects(new_rect)) {
return Rect2i();
+ }
new_rect.position.x = MAX(p_rect.position.x, position.x);
new_rect.position.y = MAX(p_rect.position.y, position.y);
@@ -313,15 +325,19 @@ struct Rect2i {
return new_rect;
};
bool has_point(const Point2 &p_point) const {
- if (p_point.x < position.x)
+ if (p_point.x < position.x) {
return false;
- if (p_point.y < position.y)
+ }
+ if (p_point.y < position.y) {
return false;
+ }
- if (p_point.x >= (position.x + size.x))
+ if (p_point.x >= (position.x + size.x)) {
return false;
- if (p_point.y >= (position.y + size.y))
+ }
+ if (p_point.y >= (position.y + size.y)) {
return false;
+ }
return true;
}
@@ -330,7 +346,6 @@ struct Rect2i {
bool operator!=(const Rect2i &p_rect) const { return position != p_rect.position || size != p_rect.size; }
Rect2i grow(int p_by) const {
-
Rect2i g = *this;
g.position.x -= p_by;
g.position.y -= p_by;
@@ -349,7 +364,6 @@ struct Rect2i {
}
inline Rect2i grow_individual(int p_left, int p_top, int p_right, int p_bottom) const {
-
Rect2i g = *this;
g.position.x -= p_left;
g.position.y -= p_top;
@@ -360,33 +374,34 @@ struct Rect2i {
}
_FORCE_INLINE_ Rect2i expand(const Vector2i &p_vector) const {
-
Rect2i r = *this;
r.expand_to(p_vector);
return r;
}
inline void expand_to(const Point2i &p_vector) {
-
Point2i begin = position;
Point2i end = position + size;
- if (p_vector.x < begin.x)
+ if (p_vector.x < begin.x) {
begin.x = p_vector.x;
- if (p_vector.y < begin.y)
+ }
+ if (p_vector.y < begin.y) {
begin.y = p_vector.y;
+ }
- if (p_vector.x > end.x)
+ if (p_vector.x > end.x) {
end.x = p_vector.x;
- if (p_vector.y > end.y)
+ }
+ if (p_vector.y > end.y) {
end.y = p_vector.y;
+ }
position = begin;
size = end - begin;
}
_FORCE_INLINE_ Rect2i abs() const {
-
return Rect2i(Point2i(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs());
}
diff --git a/core/math/transform.cpp b/core/math/transform.cpp
index 82e4005d3e..0274dd18af 100644
--- a/core/math/transform.cpp
+++ b/core/math/transform.cpp
@@ -35,20 +35,17 @@
#include "core/print_string.h"
void Transform::affine_invert() {
-
basis.invert();
origin = basis.xform(-origin);
}
Transform Transform::affine_inverse() const {
-
Transform ret = *this;
ret.affine_invert();
return ret;
}
void Transform::invert() {
-
basis.transpose();
origin = basis.xform(-origin);
}
@@ -62,22 +59,18 @@ Transform Transform::inverse() const {
}
void Transform::rotate(const Vector3 &p_axis, real_t p_phi) {
-
*this = rotated(p_axis, p_phi);
}
Transform Transform::rotated(const Vector3 &p_axis, real_t p_phi) const {
-
return Transform(Basis(p_axis, p_phi), Vector3()) * (*this);
}
void Transform::rotate_basis(const Vector3 &p_axis, real_t p_phi) {
-
basis.rotate(p_axis, p_phi);
}
Transform Transform::looking_at(const Vector3 &p_target, const Vector3 &p_up) const {
-
Transform t = *this;
t.set_look_at(origin, p_target, p_up);
return t;
@@ -117,7 +110,6 @@ void Transform::set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const
}
Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c) const {
-
/* not sure if very "efficient" but good enough? */
Vector3 src_scale = basis.get_scale();
@@ -136,81 +128,70 @@ Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c)
}
void Transform::scale(const Vector3 &p_scale) {
-
basis.scale(p_scale);
origin *= p_scale;
}
Transform Transform::scaled(const Vector3 &p_scale) const {
-
Transform t = *this;
t.scale(p_scale);
return t;
}
void Transform::scale_basis(const Vector3 &p_scale) {
-
basis.scale(p_scale);
}
void Transform::translate(real_t p_tx, real_t p_ty, real_t p_tz) {
translate(Vector3(p_tx, p_ty, p_tz));
}
-void Transform::translate(const Vector3 &p_translation) {
+void Transform::translate(const Vector3 &p_translation) {
for (int i = 0; i < 3; i++) {
origin[i] += basis[i].dot(p_translation);
}
}
Transform Transform::translated(const Vector3 &p_translation) const {
-
Transform t = *this;
t.translate(p_translation);
return t;
}
void Transform::orthonormalize() {
-
basis.orthonormalize();
}
Transform Transform::orthonormalized() const {
-
Transform _copy = *this;
_copy.orthonormalize();
return _copy;
}
bool Transform::is_equal_approx(const Transform &p_transform) const {
-
return basis.is_equal_approx(p_transform.basis) && origin.is_equal_approx(p_transform.origin);
}
bool Transform::operator==(const Transform &p_transform) const {
-
return (basis == p_transform.basis && origin == p_transform.origin);
}
-bool Transform::operator!=(const Transform &p_transform) const {
+bool Transform::operator!=(const Transform &p_transform) const {
return (basis != p_transform.basis || origin != p_transform.origin);
}
void Transform::operator*=(const Transform &p_transform) {
-
origin = xform(p_transform.origin);
basis *= p_transform.basis;
}
Transform Transform::operator*(const Transform &p_transform) const {
-
Transform t = *this;
t *= p_transform;
return t;
}
Transform::operator String() const {
-
return basis.operator String() + " - " + origin.operator String();
}
diff --git a/core/math/transform.h b/core/math/transform.h
index c6e3be4c70..71847d36ac 100644
--- a/core/math/transform.h
+++ b/core/math/transform.h
@@ -92,14 +92,12 @@ public:
Transform interpolate_with(const Transform &p_transform, real_t p_c) const;
_FORCE_INLINE_ Transform inverse_xform(const Transform &t) const {
-
Vector3 v = t.origin - origin;
return Transform(basis.transpose_xform(t.basis),
basis.xform(v));
}
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz) {
-
basis.set(xx, xy, xz, yx, yy, yz, zx, zy, zz);
origin.x = tx;
origin.y = ty;
@@ -114,14 +112,13 @@ public:
};
_FORCE_INLINE_ Vector3 Transform::xform(const Vector3 &p_vector) const {
-
return Vector3(
basis[0].dot(p_vector) + origin.x,
basis[1].dot(p_vector) + origin.y,
basis[2].dot(p_vector) + origin.z);
}
-_FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3 &p_vector) const {
+_FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3 &p_vector) const {
Vector3 v = p_vector - origin;
return Vector3(
@@ -131,7 +128,6 @@ _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3 &p_vector) const {
}
_FORCE_INLINE_ Plane Transform::xform(const Plane &p_plane) const {
-
Vector3 point = p_plane.normal * p_plane.d;
Vector3 point_dir = point + p_plane.normal;
point = xform(point);
@@ -143,8 +139,8 @@ _FORCE_INLINE_ Plane Transform::xform(const Plane &p_plane) const {
return Plane(normal, d);
}
-_FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const {
+_FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const {
Vector3 point = p_plane.normal * p_plane.d;
Vector3 point_dir = point + p_plane.normal;
xform_inv(point);
@@ -158,7 +154,6 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const {
}
_FORCE_INLINE_ AABB Transform::xform(const AABB &p_aabb) const {
-
/* http://dev.theomader.com/transform-bounding-boxes/ */
Vector3 min = p_aabb.position;
Vector3 max = p_aabb.position + p_aabb.size;
@@ -184,7 +179,6 @@ _FORCE_INLINE_ AABB Transform::xform(const AABB &p_aabb) const {
}
_FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const {
-
/* define vertices */
Vector3 vertices[8] = {
Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z),
@@ -202,7 +196,6 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const {
ret.position = xform_inv(vertices[0]);
for (int i = 1; i < 8; i++) {
-
ret.expand_to(xform_inv(vertices[i]));
}
@@ -210,7 +203,6 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const {
}
Vector<Vector3> Transform::xform(const Vector<Vector3> &p_array) const {
-
Vector<Vector3> array;
array.resize(p_array.size());
@@ -224,7 +216,6 @@ Vector<Vector3> Transform::xform(const Vector<Vector3> &p_array) const {
}
Vector<Vector3> Transform::xform_inv(const Vector<Vector3> &p_array) const {
-
Vector<Vector3> array;
array.resize(p_array.size());
diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp
index ed95baa233..dee1b3b23e 100644
--- a/core/math/transform_2d.cpp
+++ b/core/math/transform_2d.cpp
@@ -38,14 +38,12 @@ void Transform2D::invert() {
}
Transform2D Transform2D::inverse() const {
-
Transform2D inv = *this;
inv.invert();
return inv;
}
void Transform2D::affine_invert() {
-
real_t det = basis_determinant();
#ifdef MATH_CHECKS
ERR_FAIL_COND(det == 0);
@@ -60,7 +58,6 @@ void Transform2D::affine_invert() {
}
Transform2D Transform2D::affine_inverse() const {
-
Transform2D inv = *this;
inv.affine_invert();
return inv;
@@ -71,13 +68,11 @@ void Transform2D::rotate(real_t p_phi) {
}
real_t Transform2D::get_skew() const {
-
real_t det = basis_determinant();
return Math::acos(elements[0].normalized().dot(SGN(det) * elements[1].normalized())) - Math_PI * 0.5;
}
void Transform2D::set_skew(float p_angle) {
-
real_t det = basis_determinant();
elements[1] = SGN(det) * elements[0].rotated((Math_PI * 0.5 + p_angle)).normalized() * elements[1].length();
}
@@ -103,7 +98,6 @@ void Transform2D::set_rotation(real_t p_rot) {
}
Transform2D::Transform2D(real_t p_rot, const Vector2 &p_pos) {
-
real_t cr = Math::cos(p_rot);
real_t sr = Math::sin(p_rot);
elements[0][0] = cr;
@@ -129,24 +123,23 @@ void Transform2D::scale(const Size2 &p_scale) {
scale_basis(p_scale);
elements[2] *= p_scale;
}
-void Transform2D::scale_basis(const Size2 &p_scale) {
+void Transform2D::scale_basis(const Size2 &p_scale) {
elements[0][0] *= p_scale.x;
elements[0][1] *= p_scale.y;
elements[1][0] *= p_scale.x;
elements[1][1] *= p_scale.y;
}
-void Transform2D::translate(real_t p_tx, real_t p_ty) {
+void Transform2D::translate(real_t p_tx, real_t p_ty) {
translate(Vector2(p_tx, p_ty));
}
-void Transform2D::translate(const Vector2 &p_translation) {
+void Transform2D::translate(const Vector2 &p_translation) {
elements[2] += basis_xform(p_translation);
}
void Transform2D::orthonormalize() {
-
// Gram-Schmidt Process
Vector2 x = elements[0];
@@ -161,39 +154,36 @@ void Transform2D::orthonormalize() {
}
Transform2D Transform2D::orthonormalized() const {
-
Transform2D on = *this;
on.orthonormalize();
return on;
}
bool Transform2D::is_equal_approx(const Transform2D &p_transform) const {
-
return elements[0].is_equal_approx(p_transform.elements[0]) && elements[1].is_equal_approx(p_transform.elements[1]) && elements[2].is_equal_approx(p_transform.elements[2]);
}
bool Transform2D::operator==(const Transform2D &p_transform) const {
-
for (int i = 0; i < 3; i++) {
- if (elements[i] != p_transform.elements[i])
+ if (elements[i] != p_transform.elements[i]) {
return false;
+ }
}
return true;
}
bool Transform2D::operator!=(const Transform2D &p_transform) const {
-
for (int i = 0; i < 3; i++) {
- if (elements[i] != p_transform.elements[i])
+ if (elements[i] != p_transform.elements[i]) {
return true;
+ }
}
return false;
}
void Transform2D::operator*=(const Transform2D &p_transform) {
-
elements[2] = xform(p_transform.elements[2]);
real_t x0, x1, y0, y1;
@@ -210,54 +200,46 @@ void Transform2D::operator*=(const Transform2D &p_transform) {
}
Transform2D Transform2D::operator*(const Transform2D &p_transform) const {
-
Transform2D t = *this;
t *= p_transform;
return t;
}
Transform2D Transform2D::scaled(const Size2 &p_scale) const {
-
Transform2D copy = *this;
copy.scale(p_scale);
return copy;
}
Transform2D Transform2D::basis_scaled(const Size2 &p_scale) const {
-
Transform2D copy = *this;
copy.scale_basis(p_scale);
return copy;
}
Transform2D Transform2D::untranslated() const {
-
Transform2D copy = *this;
copy.elements[2] = Vector2();
return copy;
}
Transform2D Transform2D::translated(const Vector2 &p_offset) const {
-
Transform2D copy = *this;
copy.translate(p_offset);
return copy;
}
Transform2D Transform2D::rotated(real_t p_phi) const {
-
Transform2D copy = *this;
copy.rotate(p_phi);
return copy;
}
real_t Transform2D::basis_determinant() const {
-
return elements[0].x * elements[1].y - elements[0].y * elements[1].x;
}
Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t p_c) const {
-
//extract parameters
Vector2 p1 = get_origin();
Vector2 p2 = p_transform.get_origin();
@@ -293,6 +275,5 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t
}
Transform2D::operator String() const {
-
return String(String() + elements[0] + ", " + elements[1] + ", " + elements[2]);
}
diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h
index 459ceed7a9..46e97abaa7 100644
--- a/core/math/transform_2d.h
+++ b/core/math/transform_2d.h
@@ -120,7 +120,6 @@ struct Transform2D {
operator String() const;
Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) {
-
elements[0][0] = xx;
elements[0][1] = xy;
elements[1][0] = yx;
@@ -137,36 +136,33 @@ struct Transform2D {
};
Vector2 Transform2D::basis_xform(const Vector2 &p_vec) const {
-
return Vector2(
tdotx(p_vec),
tdoty(p_vec));
}
Vector2 Transform2D::basis_xform_inv(const Vector2 &p_vec) const {
-
return Vector2(
elements[0].dot(p_vec),
elements[1].dot(p_vec));
}
Vector2 Transform2D::xform(const Vector2 &p_vec) const {
-
return Vector2(
tdotx(p_vec),
tdoty(p_vec)) +
elements[2];
}
-Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const {
+Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const {
Vector2 v = p_vec - elements[2];
return Vector2(
elements[0].dot(v),
elements[1].dot(v));
}
-Rect2 Transform2D::xform(const Rect2 &p_rect) const {
+Rect2 Transform2D::xform(const Rect2 &p_rect) const {
Vector2 x = elements[0] * p_rect.size.x;
Vector2 y = elements[1] * p_rect.size.y;
Vector2 pos = xform(p_rect.position);
@@ -180,7 +176,6 @@ Rect2 Transform2D::xform(const Rect2 &p_rect) const {
}
void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) {
-
elements[0][0] = Math::cos(p_rot) * p_scale.x;
elements[1][1] = Math::cos(p_rot) * p_scale.y;
elements[1][0] = -Math::sin(p_rot) * p_scale.y;
@@ -188,7 +183,6 @@ void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) {
}
void Transform2D::set_rotation_scale_and_skew(real_t p_rot, const Size2 &p_scale, float p_skew) {
-
elements[0][0] = Math::cos(p_rot) * p_scale.x;
elements[1][1] = Math::cos(p_rot + p_skew) * p_scale.y;
elements[1][0] = -Math::sin(p_rot + p_skew) * p_scale.y;
@@ -196,7 +190,6 @@ void Transform2D::set_rotation_scale_and_skew(real_t p_rot, const Size2 &p_scale
}
Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const {
-
Vector2 ends[4] = {
xform_inv(p_rect.position),
xform_inv(Vector2(p_rect.position.x, p_rect.position.y + p_rect.size.y)),
@@ -214,7 +207,6 @@ Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const {
}
Vector<Vector2> Transform2D::xform(const Vector<Vector2> &p_array) const {
-
Vector<Vector2> array;
array.resize(p_array.size());
@@ -228,7 +220,6 @@ Vector<Vector2> Transform2D::xform(const Vector<Vector2> &p_array) const {
}
Vector<Vector2> Transform2D::xform_inv(const Vector<Vector2> &p_array) const {
-
Vector<Vector2> array;
array.resize(p_array.size());
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index 0f7350a260..c9a546e385 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -33,30 +33,25 @@
#include "core/sort_array.h"
int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, int p_depth, int &max_depth, int &max_alloc) {
-
if (p_depth > max_depth) {
max_depth = p_depth;
}
if (p_size == 1) {
-
return p_bb[p_from] - p_bvh;
} else if (p_size == 0) {
-
return -1;
}
AABB aabb;
aabb = p_bb[p_from]->aabb;
for (int i = 1; i < p_size; i++) {
-
aabb.merge_with(p_bb[p_from + i]->aabb);
}
int li = aabb.get_longest_axis_index();
switch (li) {
-
case Vector3::AXIS_X: {
SortArray<BVH *, BVHCmpX> sort_x;
sort_x.nth_element(0, p_size, p_size / 2, &p_bb[p_from]);
@@ -90,9 +85,9 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in
}
void TriangleMesh::get_indices(Vector<int> *r_triangles_indices) const {
-
- if (!valid)
+ if (!valid) {
return;
+ }
const int triangles_num = triangles.size();
@@ -110,7 +105,6 @@ void TriangleMesh::get_indices(Vector<int> *r_triangles_indices) const {
}
void TriangleMesh::create(const Vector<Vector3> &p_faces) {
-
valid = false;
int fc = p_faces.size();
@@ -122,7 +116,6 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) {
BVH *bw = bvh.ptrw();
{
-
//create faces and indices and base bvh
//except for the Set for repeated triangles, everything
//goes in-place.
@@ -132,12 +125,10 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) {
Map<Vector3, int> db;
for (int i = 0; i < fc; i++) {
-
Triangle &f = w[i];
const Vector3 *v = &r[i * 3];
for (int j = 0; j < 3; j++) {
-
int vidx = -1;
Vector3 vs = v[j].snapped(Vector3(0.0001, 0.0001, 0.0001));
Map<Vector3, int>::Element *E = db.find(vs);
@@ -149,10 +140,11 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) {
}
f.indices[j] = vidx;
- if (j == 0)
+ if (j == 0) {
bw[i].aabb.position = vs;
- else
+ } else {
bw[i].aabb.expand_to(vs);
+ }
}
f.normal = Face3(r[i * 3 + 0], r[i * 3 + 1], r[i * 3 + 2]).get_plane().get_normal();
@@ -174,7 +166,6 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) {
bwptrs.resize(fc);
BVH **bwp = bwptrs.ptrw();
for (int i = 0; i < fc; i++) {
-
bwp[i] = &bw[i];
}
@@ -188,7 +179,6 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) {
}
Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const {
-
uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth);
enum {
@@ -215,23 +205,18 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const {
stack[0] = pos;
while (true) {
-
uint32_t node = stack[level] & NODE_IDX_MASK;
const BVH &b = bvhptr[node];
bool done = false;
switch (stack[level] >> VISITED_BIT_SHIFT) {
case TEST_AABB_BIT: {
-
bool valid = b.aabb.intersects(p_aabb);
if (!valid) {
-
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
-
if (b.face_index >= 0) {
-
const Triangle &s = triangleptr[b.face_index];
n += s.normal;
n_count++;
@@ -239,49 +224,47 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
-
stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
}
}
continue;
}
case VISIT_LEFT_BIT: {
-
stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.left | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_RIGHT_BIT: {
-
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.right | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_DONE_BIT: {
-
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
continue;
}
}
- if (done)
+ if (done) {
break;
+ }
}
- if (n_count > 0)
+ if (n_count > 0) {
n /= n_count;
+ }
return n;
}
bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const {
-
uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth);
enum {
@@ -309,35 +292,28 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en
stack[0] = pos;
while (true) {
-
uint32_t node = stack[level] & NODE_IDX_MASK;
const BVH &b = bvhptr[node];
bool done = false;
switch (stack[level] >> VISITED_BIT_SHIFT) {
case TEST_AABB_BIT: {
-
bool valid = b.aabb.intersects_segment(p_begin, p_end);
//bool valid = b.aabb.intersects(ray_aabb);
if (!valid) {
-
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
-
if (b.face_index >= 0) {
-
const Triangle &s = triangleptr[b.face_index];
Face3 f3(vertexptr[s.indices[0]], vertexptr[s.indices[1]], vertexptr[s.indices[2]]);
Vector3 res;
if (f3.intersects_segment(p_begin, p_end, &res)) {
-
real_t nd = n.dot(res);
if (nd < d) {
-
d = nd;
r_point = res;
r_normal = f3.get_plane().get_normal();
@@ -348,52 +324,49 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
-
stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
}
}
continue;
}
case VISIT_LEFT_BIT: {
-
stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.left | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_RIGHT_BIT: {
-
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.right | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_DONE_BIT: {
-
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
continue;
}
}
- if (done)
+ if (done) {
break;
+ }
}
if (inters) {
-
- if (n.dot(r_normal) > 0)
+ if (n.dot(r_normal) > 0) {
r_normal = -r_normal;
+ }
}
return inters;
}
bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, Vector3 &r_point, Vector3 &r_normal) const {
-
uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth);
enum {
@@ -421,33 +394,26 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V
stack[0] = pos;
while (true) {
-
uint32_t node = stack[level] & NODE_IDX_MASK;
const BVH &b = bvhptr[node];
bool done = false;
switch (stack[level] >> VISITED_BIT_SHIFT) {
case TEST_AABB_BIT: {
-
bool valid = b.aabb.intersects_ray(p_begin, p_dir);
if (!valid) {
-
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
-
if (b.face_index >= 0) {
-
const Triangle &s = triangleptr[b.face_index];
Face3 f3(vertexptr[s.indices[0]], vertexptr[s.indices[1]], vertexptr[s.indices[2]]);
Vector3 res;
if (f3.intersects_ray(p_begin, p_dir, &res)) {
-
real_t nd = n.dot(res);
if (nd < d) {
-
d = nd;
r_point = res;
r_normal = f3.get_plane().get_normal();
@@ -458,45 +424,43 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
-
stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
}
}
continue;
}
case VISIT_LEFT_BIT: {
-
stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.left | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_RIGHT_BIT: {
-
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.right | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_DONE_BIT: {
-
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
continue;
}
}
- if (done)
+ if (done) {
break;
+ }
}
if (inters) {
-
- if (n.dot(r_normal) > 0)
+ if (n.dot(r_normal) > 0) {
r_normal = -r_normal;
+ }
}
return inters;
@@ -528,23 +492,18 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou
stack[0] = pos;
while (true) {
-
uint32_t node = stack[level] & NODE_IDX_MASK;
const BVH &b = bvhptr[node];
bool done = false;
switch (stack[level] >> VISITED_BIT_SHIFT) {
case TEST_AABB_BIT: {
-
bool valid = b.aabb.intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count);
if (!valid) {
-
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
-
if (b.face_index >= 0) {
-
const Triangle &s = triangleptr[b.face_index];
for (int j = 0; j < 3; ++j) {
@@ -558,16 +517,18 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou
if (p.intersects_segment(point, next_point, &res)) {
bool inisde = true;
for (int k = 0; k < p_plane_count; k++) {
- if (k == i)
+ if (k == i) {
continue;
+ }
const Plane &pp = p_planes[k];
if (pp.is_point_over(res)) {
inisde = false;
break;
}
}
- if (inisde)
+ if (inisde) {
return true;
+ }
}
if (p.is_point_over(point)) {
@@ -575,46 +536,45 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou
break;
}
}
- if (over)
+ if (over) {
return true;
+ }
}
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
-
stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
}
}
continue;
}
case VISIT_LEFT_BIT: {
-
stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.left | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_RIGHT_BIT: {
-
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.right | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_DONE_BIT: {
-
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
continue;
}
}
- if (done)
+ if (done) {
break;
+ }
}
return false;
@@ -646,86 +606,81 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count,
stack[0] = pos;
while (true) {
-
uint32_t node = stack[level] & NODE_IDX_MASK;
const BVH &b = bvhptr[node];
bool done = false;
switch (stack[level] >> VISITED_BIT_SHIFT) {
case TEST_AABB_BIT: {
-
bool intersects = scale.xform(b.aabb).intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count);
- if (!intersects)
+ if (!intersects) {
return false;
+ }
bool inside = scale.xform(b.aabb).inside_convex_shape(p_planes, p_plane_count);
if (inside) {
-
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
-
if (b.face_index >= 0) {
const Triangle &s = triangleptr[b.face_index];
for (int j = 0; j < 3; ++j) {
Vector3 point = scale.xform(vertexptr[s.indices[j]]);
for (int i = 0; i < p_plane_count; i++) {
const Plane &p = p_planes[i];
- if (p.is_point_over(point))
+ if (p.is_point_over(point)) {
return false;
+ }
}
}
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
} else {
-
stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
}
}
continue;
}
case VISIT_LEFT_BIT: {
-
stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.left | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_RIGHT_BIT: {
-
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
stack[level + 1] = b.right | TEST_AABB_BIT;
level++;
continue;
}
case VISIT_DONE_BIT: {
-
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
continue;
}
}
- if (done)
+ if (done) {
break;
+ }
}
return true;
}
bool TriangleMesh::is_valid() const {
-
return valid;
}
Vector<Face3> TriangleMesh::get_faces() const {
-
- if (!valid)
+ if (!valid) {
return Vector<Face3>();
+ }
Vector<Face3> faces;
int ts = triangles.size();
@@ -745,7 +700,6 @@ Vector<Face3> TriangleMesh::get_faces() const {
}
TriangleMesh::TriangleMesh() {
-
valid = false;
max_depth = 0;
}
diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h
index 64704477cc..86412cf725 100644
--- a/core/math/triangle_mesh.h
+++ b/core/math/triangle_mesh.h
@@ -35,11 +35,9 @@
#include "core/reference.h"
class TriangleMesh : public Reference {
-
GDCLASS(TriangleMesh, Reference);
struct Triangle {
-
Vector3 normal;
int indices[3];
};
@@ -48,7 +46,6 @@ class TriangleMesh : public Reference {
Vector<Vector3> vertices;
struct BVH {
-
AABB aabb;
Vector3 center; //used for sorting
int left;
@@ -58,24 +55,18 @@ class TriangleMesh : public Reference {
};
struct BVHCmpX {
-
bool operator()(const BVH *p_left, const BVH *p_right) const {
-
return p_left->center.x < p_right->center.x;
}
};
struct BVHCmpY {
-
bool operator()(const BVH *p_left, const BVH *p_right) const {
-
return p_left->center.y < p_right->center.y;
}
};
struct BVHCmpZ {
-
bool operator()(const BVH *p_left, const BVH *p_right) const {
-
return p_left->center.z < p_right->center.z;
}
};
diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp
index ae278b034d..7fab36ff50 100644
--- a/core/math/triangulate.cpp
+++ b/core/math/triangulate.cpp
@@ -31,7 +31,6 @@
#include "triangulate.h"
real_t Triangulate::get_area(const Vector<Vector2> &contour) {
-
int n = contour.size();
const Vector2 *c = &contour[0];
@@ -103,16 +102,19 @@ bool Triangulate::snip(const Vector<Vector2> &p_contour, int u, int v, int w, in
// To avoid that we allow zero-area triangles if all else failed.
float threshold = relaxed ? -CMP_EPSILON : CMP_EPSILON;
- if (threshold > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax))))
+ if (threshold > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) {
return false;
+ }
for (p = 0; p < n; p++) {
- if ((p == u) || (p == v) || (p == w))
+ if ((p == u) || (p == v) || (p == w)) {
continue;
+ }
Px = contour[V[p]].x;
Py = contour[V[p]].y;
- if (is_inside_triangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py, relaxed))
+ if (is_inside_triangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py, relaxed)) {
return false;
+ }
}
return true;
@@ -122,20 +124,24 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
/* allocate and initialize list of Vertices in polygon */
int n = contour.size();
- if (n < 3)
+ if (n < 3) {
return false;
+ }
Vector<int> V;
V.resize(n);
/* we want a counter-clockwise polygon in V */
- if (0.0 < get_area(contour))
- for (int v = 0; v < n; v++)
+ if (0.0 < get_area(contour)) {
+ for (int v = 0; v < n; v++) {
V.write[v] = v;
- else
- for (int v = 0; v < n; v++)
+ }
+ } else {
+ for (int v = 0; v < n; v++) {
V.write[v] = (n - 1) - v;
+ }
+ }
bool relaxed = false;
@@ -165,14 +171,17 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
/* three consecutive vertices in current polygon, <u,v,w> */
int u = v;
- if (nv <= u)
+ if (nv <= u) {
u = 0; /* previous */
+ }
v = u + 1;
- if (nv <= v)
+ if (nv <= v) {
v = 0; /* new v */
+ }
int w = v + 1;
- if (nv <= w)
+ if (nv <= w) {
w = 0; /* next */
+ }
if (snip(contour, u, v, w, nv, V, relaxed)) {
int a, b, c, s, t;
@@ -188,8 +197,9 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
result.push_back(c);
/* remove v from remaining polygon */
- for (s = v, t = v + 1; t < nv; s++, t++)
+ for (s = v, t = v + 1; t < nv; s++, t++) {
V.write[s] = V[t];
+ }
nv--;
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp
index f46badd19e..7f264ce119 100644
--- a/core/math/vector2.cpp
+++ b/core/math/vector2.cpp
@@ -31,25 +31,20 @@
#include "vector2.h"
real_t Vector2::angle() const {
-
return Math::atan2(y, x);
}
real_t Vector2::length() const {
-
return Math::sqrt(x * x + y * y);
}
real_t Vector2::length_squared() const {
-
return x * x + y * y;
}
void Vector2::normalize() {
-
real_t l = x * x + y * y;
if (l != 0) {
-
l = Math::sqrt(l);
x /= l;
y /= l;
@@ -57,7 +52,6 @@ void Vector2::normalize() {
}
Vector2 Vector2::normalized() const {
-
Vector2 v = *this;
v.normalize();
return v;
@@ -69,52 +63,42 @@ bool Vector2::is_normalized() const {
}
real_t Vector2::distance_to(const Vector2 &p_vector2) const {
-
return Math::sqrt((x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y));
}
real_t Vector2::distance_squared_to(const Vector2 &p_vector2) const {
-
return (x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y);
}
real_t Vector2::angle_to(const Vector2 &p_vector2) const {
-
return Math::atan2(cross(p_vector2), dot(p_vector2));
}
real_t Vector2::angle_to_point(const Vector2 &p_vector2) const {
-
return Math::atan2(y - p_vector2.y, x - p_vector2.x);
}
real_t Vector2::dot(const Vector2 &p_other) const {
-
return x * p_other.x + y * p_other.y;
}
real_t Vector2::cross(const Vector2 &p_other) const {
-
return x * p_other.y - y * p_other.x;
}
Vector2 Vector2::sign() const {
-
return Vector2(SGN(x), SGN(y));
}
Vector2 Vector2::floor() const {
-
return Vector2(Math::floor(x), Math::floor(y));
}
Vector2 Vector2::ceil() const {
-
return Vector2(Math::ceil(x), Math::ceil(y));
}
Vector2 Vector2::round() const {
-
return Vector2(Math::round(x), Math::round(y));
}
@@ -139,18 +123,15 @@ Vector2 Vector2::project(const Vector2 &p_b) const {
}
Vector2 Vector2::snapped(const Vector2 &p_by) const {
-
return Vector2(
Math::stepify(x, p_by.x),
Math::stepify(y, p_by.y));
}
Vector2 Vector2::clamped(real_t p_len) const {
-
real_t l = length();
Vector2 v = *this;
if (l > 0 && p_len < l) {
-
v /= l;
v *= p_len;
}
@@ -159,7 +140,6 @@ Vector2 Vector2::clamped(real_t p_len) const {
}
Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const {
-
Vector2 p0 = p_pre_a;
Vector2 p1 = *this;
Vector2 p2 = p_b;
@@ -210,65 +190,56 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const {
/* Vector2i */
Vector2i Vector2i::operator+(const Vector2i &p_v) const {
-
return Vector2i(x + p_v.x, y + p_v.y);
}
-void Vector2i::operator+=(const Vector2i &p_v) {
+void Vector2i::operator+=(const Vector2i &p_v) {
x += p_v.x;
y += p_v.y;
}
-Vector2i Vector2i::operator-(const Vector2i &p_v) const {
+Vector2i Vector2i::operator-(const Vector2i &p_v) const {
return Vector2i(x - p_v.x, y - p_v.y);
}
-void Vector2i::operator-=(const Vector2i &p_v) {
+void Vector2i::operator-=(const Vector2i &p_v) {
x -= p_v.x;
y -= p_v.y;
}
Vector2i Vector2i::operator*(const Vector2i &p_v1) const {
-
return Vector2i(x * p_v1.x, y * p_v1.y);
};
Vector2i Vector2i::operator*(const int &rvalue) const {
-
return Vector2i(x * rvalue, y * rvalue);
};
void Vector2i::operator*=(const int &rvalue) {
-
x *= rvalue;
y *= rvalue;
};
Vector2i Vector2i::operator/(const Vector2i &p_v1) const {
-
return Vector2i(x / p_v1.x, y / p_v1.y);
};
Vector2i Vector2i::operator/(const int &rvalue) const {
-
return Vector2i(x / rvalue, y / rvalue);
};
void Vector2i::operator/=(const int &rvalue) {
-
x /= rvalue;
y /= rvalue;
};
Vector2i Vector2i::operator-() const {
-
return Vector2i(-x, -y);
}
bool Vector2i::operator==(const Vector2i &p_vec2) const {
-
return x == p_vec2.x && y == p_vec2.y;
}
-bool Vector2i::operator!=(const Vector2i &p_vec2) const {
+bool Vector2i::operator!=(const Vector2i &p_vec2) const {
return x != p_vec2.x || y != p_vec2.y;
}
diff --git a/core/math/vector2.h b/core/math/vector2.h
index 5a3e6a0660..e5774f1d55 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -37,7 +37,6 @@
struct Vector2i;
struct Vector2 {
-
enum Axis {
AXIS_X,
AXIS_Y,
@@ -123,13 +122,11 @@ struct Vector2 {
real_t angle() const;
_FORCE_INLINE_ Vector2 abs() const {
-
return Vector2(Math::abs(x), Math::abs(y));
}
Vector2 rotated(real_t p_by) const;
Vector2 tangent() const {
-
return Vector2(y, -x);
}
@@ -150,81 +147,69 @@ struct Vector2 {
};
_FORCE_INLINE_ Vector2 Vector2::plane_project(real_t p_d, const Vector2 &p_vec) const {
-
return p_vec - *this * (dot(p_vec) - p_d);
}
_FORCE_INLINE_ Vector2 operator*(real_t p_scalar, const Vector2 &p_vec) {
-
return p_vec * p_scalar;
}
_FORCE_INLINE_ Vector2 Vector2::operator+(const Vector2 &p_v) const {
-
return Vector2(x + p_v.x, y + p_v.y);
}
-_FORCE_INLINE_ void Vector2::operator+=(const Vector2 &p_v) {
+_FORCE_INLINE_ void Vector2::operator+=(const Vector2 &p_v) {
x += p_v.x;
y += p_v.y;
}
-_FORCE_INLINE_ Vector2 Vector2::operator-(const Vector2 &p_v) const {
+_FORCE_INLINE_ Vector2 Vector2::operator-(const Vector2 &p_v) const {
return Vector2(x - p_v.x, y - p_v.y);
}
-_FORCE_INLINE_ void Vector2::operator-=(const Vector2 &p_v) {
+_FORCE_INLINE_ void Vector2::operator-=(const Vector2 &p_v) {
x -= p_v.x;
y -= p_v.y;
}
_FORCE_INLINE_ Vector2 Vector2::operator*(const Vector2 &p_v1) const {
-
return Vector2(x * p_v1.x, y * p_v1.y);
};
_FORCE_INLINE_ Vector2 Vector2::operator*(const real_t &rvalue) const {
-
return Vector2(x * rvalue, y * rvalue);
};
_FORCE_INLINE_ void Vector2::operator*=(const real_t &rvalue) {
-
x *= rvalue;
y *= rvalue;
};
_FORCE_INLINE_ Vector2 Vector2::operator/(const Vector2 &p_v1) const {
-
return Vector2(x / p_v1.x, y / p_v1.y);
};
_FORCE_INLINE_ Vector2 Vector2::operator/(const real_t &rvalue) const {
-
return Vector2(x / rvalue, y / rvalue);
};
_FORCE_INLINE_ void Vector2::operator/=(const real_t &rvalue) {
-
x /= rvalue;
y /= rvalue;
};
_FORCE_INLINE_ Vector2 Vector2::operator-() const {
-
return Vector2(-x, -y);
}
_FORCE_INLINE_ bool Vector2::operator==(const Vector2 &p_vec2) const {
-
return x == p_vec2.x && y == p_vec2.y;
}
-_FORCE_INLINE_ bool Vector2::operator!=(const Vector2 &p_vec2) const {
+_FORCE_INLINE_ bool Vector2::operator!=(const Vector2 &p_vec2) const {
return x != p_vec2.x || y != p_vec2.y;
}
Vector2 Vector2::lerp(const Vector2 &p_b, real_t p_t) const {
-
Vector2 res = *this;
res.x += (p_t * (p_b.x - x));
@@ -253,7 +238,6 @@ typedef Vector2 Point2;
/* INTEGER STUFF */
struct Vector2i {
-
enum Axis {
AXIS_X,
AXIS_Y,
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index 353b2acd16..568df48c62 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -33,12 +33,10 @@
#include "core/math/basis.h"
void Vector3::rotate(const Vector3 &p_axis, real_t p_phi) {
-
*this = Basis(p_axis, p_phi).xform(*this);
}
Vector3 Vector3::rotated(const Vector3 &p_axis, real_t p_phi) const {
-
Vector3 r = *this;
r.rotate(p_axis, p_phi);
return r;
@@ -48,36 +46,33 @@ void Vector3::set_axis(int p_axis, real_t p_value) {
ERR_FAIL_INDEX(p_axis, 3);
coord[p_axis] = p_value;
}
-real_t Vector3::get_axis(int p_axis) const {
+real_t Vector3::get_axis(int p_axis) const {
ERR_FAIL_INDEX_V(p_axis, 3, 0);
return operator[](p_axis);
}
int Vector3::min_axis() const {
-
return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2);
}
-int Vector3::max_axis() const {
+int Vector3::max_axis() const {
return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0);
}
void Vector3::snap(Vector3 p_val) {
-
x = Math::stepify(x, p_val.x);
y = Math::stepify(y, p_val.y);
z = Math::stepify(z, p_val.z);
}
-Vector3 Vector3::snapped(Vector3 p_val) const {
+Vector3 Vector3::snapped(Vector3 p_val) const {
Vector3 v = *this;
v.snap(p_val);
return v;
}
Vector3 Vector3::cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const {
-
Vector3 p0 = p_pre_a;
Vector3 p1 = *this;
Vector3 p2 = p_b;
@@ -90,10 +85,12 @@ Vector3 Vector3::cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a,
real_t bc = p1.distance_to(p2);
real_t cd = p2.distance_to(p3);
- if (ab > 0)
+ if (ab > 0) {
p0 = p1 + (p0 - p1) * (bc / ab);
- if (cd > 0)
+ }
+ if (cd > 0) {
p3 = p2 + (p3 - p2) * (bc / cd);
+ }
}
real_t t = p_t;
@@ -109,7 +106,6 @@ Vector3 Vector3::cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a,
}
Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const {
-
Vector3 p0 = p_pre_a;
Vector3 p1 = *this;
Vector3 p2 = p_b;
@@ -135,7 +131,6 @@ Vector3 Vector3::move_toward(const Vector3 &p_to, const real_t p_delta) const {
}
Basis Vector3::outer(const Vector3 &p_b) const {
-
Vector3 row0(x * p_b.x, x * p_b.y, x * p_b.z);
Vector3 row1(y * p_b.x, y * p_b.y, y * p_b.z);
Vector3 row2(z * p_b.x, z * p_b.y, z * p_b.z);
@@ -150,11 +145,9 @@ Basis Vector3::to_diagonal_matrix() const {
}
bool Vector3::is_equal_approx(const Vector3 &p_v) const {
-
return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y) && Math::is_equal_approx(z, p_v.z);
}
Vector3::operator String() const {
-
return (rtos(x) + ", " + rtos(y) + ", " + rtos(z));
}
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 7131063e04..0bc1a467f2 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -38,7 +38,6 @@
class Basis;
struct Vector3 {
-
enum Axis {
AXIS_X,
AXIS_Y,
@@ -56,12 +55,10 @@ struct Vector3 {
};
_FORCE_INLINE_ const real_t &operator[](int p_axis) const {
-
return coord[p_axis];
}
_FORCE_INLINE_ real_t &operator[](int p_axis) {
-
return coord[p_axis];
}
@@ -166,7 +163,6 @@ struct Vector3 {
};
Vector3 Vector3::cross(const Vector3 &p_b) const {
-
Vector3 ret(
(y * p_b.z) - (z * p_b.y),
(z * p_b.x) - (x * p_b.z),
@@ -176,37 +172,30 @@ Vector3 Vector3::cross(const Vector3 &p_b) const {
}
real_t Vector3::dot(const Vector3 &p_b) const {
-
return x * p_b.x + y * p_b.y + z * p_b.z;
}
Vector3 Vector3::abs() const {
-
return Vector3(Math::abs(x), Math::abs(y), Math::abs(z));
}
Vector3 Vector3::sign() const {
-
return Vector3(SGN(x), SGN(y), SGN(z));
}
Vector3 Vector3::floor() const {
-
return Vector3(Math::floor(x), Math::floor(y), Math::floor(z));
}
Vector3 Vector3::ceil() const {
-
return Vector3(Math::ceil(x), Math::ceil(y), Math::ceil(z));
}
Vector3 Vector3::round() const {
-
return Vector3(Math::round(x), Math::round(y), Math::round(z));
}
Vector3 Vector3::lerp(const Vector3 &p_b, real_t p_t) const {
-
return Vector3(
x + (p_t * (p_b.x - x)),
y + (p_t * (p_b.y - y)),
@@ -219,12 +208,10 @@ Vector3 Vector3::slerp(const Vector3 &p_b, real_t p_t) const {
}
real_t Vector3::distance_to(const Vector3 &p_b) const {
-
return (p_b - *this).length();
}
real_t Vector3::distance_squared_to(const Vector3 &p_b) const {
-
return (p_b - *this).length_squared();
}
@@ -241,7 +228,6 @@ Vector3 Vector3::project(const Vector3 &p_b) const {
}
real_t Vector3::angle_to(const Vector3 &p_b) const {
-
return Math::atan2(cross(p_b).length(), dot(p_b));
}
@@ -254,7 +240,6 @@ Vector3 Vector3::direction_to(const Vector3 &p_b) const {
/* Operators */
Vector3 &Vector3::operator+=(const Vector3 &p_v) {
-
x += p_v.x;
y += p_v.y;
z += p_v.z;
@@ -262,36 +247,32 @@ Vector3 &Vector3::operator+=(const Vector3 &p_v) {
}
Vector3 Vector3::operator+(const Vector3 &p_v) const {
-
return Vector3(x + p_v.x, y + p_v.y, z + p_v.z);
}
Vector3 &Vector3::operator-=(const Vector3 &p_v) {
-
x -= p_v.x;
y -= p_v.y;
z -= p_v.z;
return *this;
}
-Vector3 Vector3::operator-(const Vector3 &p_v) const {
+Vector3 Vector3::operator-(const Vector3 &p_v) const {
return Vector3(x - p_v.x, y - p_v.y, z - p_v.z);
}
Vector3 &Vector3::operator*=(const Vector3 &p_v) {
-
x *= p_v.x;
y *= p_v.y;
z *= p_v.z;
return *this;
}
-Vector3 Vector3::operator*(const Vector3 &p_v) const {
+Vector3 Vector3::operator*(const Vector3 &p_v) const {
return Vector3(x * p_v.x, y * p_v.y, z * p_v.z);
}
Vector3 &Vector3::operator/=(const Vector3 &p_v) {
-
x /= p_v.x;
y /= p_v.y;
z /= p_v.z;
@@ -299,12 +280,10 @@ Vector3 &Vector3::operator/=(const Vector3 &p_v) {
}
Vector3 Vector3::operator/(const Vector3 &p_v) const {
-
return Vector3(x / p_v.x, y / p_v.y, z / p_v.z);
}
Vector3 &Vector3::operator*=(real_t p_scalar) {
-
x *= p_scalar;
y *= p_scalar;
z *= p_scalar;
@@ -312,17 +291,14 @@ Vector3 &Vector3::operator*=(real_t p_scalar) {
}
_FORCE_INLINE_ Vector3 operator*(real_t p_scalar, const Vector3 &p_vec) {
-
return p_vec * p_scalar;
}
Vector3 Vector3::operator*(real_t p_scalar) const {
-
return Vector3(x * p_scalar, y * p_scalar, z * p_scalar);
}
Vector3 &Vector3::operator/=(real_t p_scalar) {
-
x /= p_scalar;
y /= p_scalar;
z /= p_scalar;
@@ -330,85 +306,78 @@ Vector3 &Vector3::operator/=(real_t p_scalar) {
}
Vector3 Vector3::operator/(real_t p_scalar) const {
-
return Vector3(x / p_scalar, y / p_scalar, z / p_scalar);
}
Vector3 Vector3::operator-() const {
-
return Vector3(-x, -y, -z);
}
bool Vector3::operator==(const Vector3 &p_v) const {
-
return x == p_v.x && y == p_v.y && z == p_v.z;
}
bool Vector3::operator!=(const Vector3 &p_v) const {
-
return x != p_v.x || y != p_v.y || z != p_v.z;
}
bool Vector3::operator<(const Vector3 &p_v) const {
-
if (Math::is_equal_approx(x, p_v.x)) {
- if (Math::is_equal_approx(y, p_v.y))
+ if (Math::is_equal_approx(y, p_v.y)) {
return z < p_v.z;
- else
+ } else {
return y < p_v.y;
+ }
} else {
return x < p_v.x;
}
}
bool Vector3::operator>(const Vector3 &p_v) const {
-
if (Math::is_equal_approx(x, p_v.x)) {
- if (Math::is_equal_approx(y, p_v.y))
+ if (Math::is_equal_approx(y, p_v.y)) {
return z > p_v.z;
- else
+ } else {
return y > p_v.y;
+ }
} else {
return x > p_v.x;
}
}
bool Vector3::operator<=(const Vector3 &p_v) const {
-
if (Math::is_equal_approx(x, p_v.x)) {
- if (Math::is_equal_approx(y, p_v.y))
+ if (Math::is_equal_approx(y, p_v.y)) {
return z <= p_v.z;
- else
+ } else {
return y < p_v.y;
+ }
} else {
return x < p_v.x;
}
}
bool Vector3::operator>=(const Vector3 &p_v) const {
-
if (Math::is_equal_approx(x, p_v.x)) {
- if (Math::is_equal_approx(y, p_v.y))
+ if (Math::is_equal_approx(y, p_v.y)) {
return z >= p_v.z;
- else
+ } else {
return y > p_v.y;
+ }
} else {
return x > p_v.x;
}
}
_FORCE_INLINE_ Vector3 vec3_cross(const Vector3 &p_a, const Vector3 &p_b) {
-
return p_a.cross(p_b);
}
_FORCE_INLINE_ real_t vec3_dot(const Vector3 &p_a, const Vector3 &p_b) {
-
return p_a.dot(p_b);
}
real_t Vector3::length() const {
-
real_t x2 = x * x;
real_t y2 = y * y;
real_t z2 = z * z;
@@ -417,7 +386,6 @@ real_t Vector3::length() const {
}
real_t Vector3::length_squared() const {
-
real_t x2 = x * x;
real_t y2 = y * y;
real_t z2 = z * z;
@@ -426,7 +394,6 @@ real_t Vector3::length_squared() const {
}
void Vector3::normalize() {
-
real_t lengthsq = length_squared();
if (lengthsq == 0) {
x = y = z = 0;
@@ -439,7 +406,6 @@ void Vector3::normalize() {
}
Vector3 Vector3::normalized() const {
-
Vector3 v = *this;
v.normalize();
return v;
@@ -451,12 +417,10 @@ bool Vector3::is_normalized() const {
}
Vector3 Vector3::inverse() const {
-
return Vector3(1.0 / x, 1.0 / y, 1.0 / z);
}
void Vector3::zero() {
-
x = y = z = 0;
}
diff --git a/core/math/vector3i.cpp b/core/math/vector3i.cpp
index 8a4ddf03b9..718a1553a0 100644
--- a/core/math/vector3i.cpp
+++ b/core/math/vector3i.cpp
@@ -34,22 +34,20 @@ void Vector3i::set_axis(int p_axis, int32_t p_value) {
ERR_FAIL_INDEX(p_axis, 3);
coord[p_axis] = p_value;
}
-int32_t Vector3i::get_axis(int p_axis) const {
+int32_t Vector3i::get_axis(int p_axis) const {
ERR_FAIL_INDEX_V(p_axis, 3, 0);
return operator[](p_axis);
}
int Vector3i::min_axis() const {
-
return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2);
}
-int Vector3i::max_axis() const {
+int Vector3i::max_axis() const {
return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0);
}
Vector3i::operator String() const {
-
return (itos(x) + ", " + itos(y) + ", " + itos(z));
}
diff --git a/core/math/vector3i.h b/core/math/vector3i.h
index 60e5b94c12..08729ad056 100644
--- a/core/math/vector3i.h
+++ b/core/math/vector3i.h
@@ -35,7 +35,6 @@
#include "core/ustring.h"
struct Vector3i {
-
enum Axis {
AXIS_X,
AXIS_Y,
@@ -53,12 +52,10 @@ struct Vector3i {
};
_FORCE_INLINE_ const int32_t &operator[](int p_axis) const {
-
return coord[p_axis];
}
_FORCE_INLINE_ int32_t &operator[](int p_axis) {
-
return coord[p_axis];
}
@@ -109,19 +106,16 @@ struct Vector3i {
};
Vector3i Vector3i::abs() const {
-
return Vector3i(ABS(x), ABS(y), ABS(z));
}
Vector3i Vector3i::sign() const {
-
return Vector3i(SGN(x), SGN(y), SGN(z));
}
/* Operators */
Vector3i &Vector3i::operator+=(const Vector3i &p_v) {
-
x += p_v.x;
y += p_v.y;
z += p_v.z;
@@ -129,36 +123,32 @@ Vector3i &Vector3i::operator+=(const Vector3i &p_v) {
}
Vector3i Vector3i::operator+(const Vector3i &p_v) const {
-
return Vector3i(x + p_v.x, y + p_v.y, z + p_v.z);
}
Vector3i &Vector3i::operator-=(const Vector3i &p_v) {
-
x -= p_v.x;
y -= p_v.y;
z -= p_v.z;
return *this;
}
-Vector3i Vector3i::operator-(const Vector3i &p_v) const {
+Vector3i Vector3i::operator-(const Vector3i &p_v) const {
return Vector3i(x - p_v.x, y - p_v.y, z - p_v.z);
}
Vector3i &Vector3i::operator*=(const Vector3i &p_v) {
-
x *= p_v.x;
y *= p_v.y;
z *= p_v.z;
return *this;
}
-Vector3i Vector3i::operator*(const Vector3i &p_v) const {
+Vector3i Vector3i::operator*(const Vector3i &p_v) const {
return Vector3i(x * p_v.x, y * p_v.y, z * p_v.z);
}
Vector3i &Vector3i::operator/=(const Vector3i &p_v) {
-
x /= p_v.x;
y /= p_v.y;
z /= p_v.z;
@@ -166,12 +156,10 @@ Vector3i &Vector3i::operator/=(const Vector3i &p_v) {
}
Vector3i Vector3i::operator/(const Vector3i &p_v) const {
-
return Vector3i(x / p_v.x, y / p_v.y, z / p_v.z);
}
Vector3i &Vector3i::operator*=(int32_t p_scalar) {
-
x *= p_scalar;
y *= p_scalar;
z *= p_scalar;
@@ -179,17 +167,14 @@ Vector3i &Vector3i::operator*=(int32_t p_scalar) {
}
_FORCE_INLINE_ Vector3i operator*(int32_t p_scalar, const Vector3i &p_vec) {
-
return p_vec * p_scalar;
}
Vector3i Vector3i::operator*(int32_t p_scalar) const {
-
return Vector3i(x * p_scalar, y * p_scalar, z * p_scalar);
}
Vector3i &Vector3i::operator/=(int32_t p_scalar) {
-
x /= p_scalar;
y /= p_scalar;
z /= p_scalar;
@@ -197,75 +182,70 @@ Vector3i &Vector3i::operator/=(int32_t p_scalar) {
}
Vector3i Vector3i::operator/(int32_t p_scalar) const {
-
return Vector3i(x / p_scalar, y / p_scalar, z / p_scalar);
}
Vector3i Vector3i::operator-() const {
-
return Vector3i(-x, -y, -z);
}
bool Vector3i::operator==(const Vector3i &p_v) const {
-
return (x == p_v.x && y == p_v.y && z == p_v.z);
}
bool Vector3i::operator!=(const Vector3i &p_v) const {
-
return (x != p_v.x || y != p_v.y || z != p_v.z);
}
bool Vector3i::operator<(const Vector3i &p_v) const {
-
if (x == p_v.x) {
- if (y == p_v.y)
+ if (y == p_v.y) {
return z < p_v.z;
- else
+ } else {
return y < p_v.y;
+ }
} else {
return x < p_v.x;
}
}
bool Vector3i::operator>(const Vector3i &p_v) const {
-
if (x == p_v.x) {
- if (y == p_v.y)
+ if (y == p_v.y) {
return z > p_v.z;
- else
+ } else {
return y > p_v.y;
+ }
} else {
return x > p_v.x;
}
}
bool Vector3i::operator<=(const Vector3i &p_v) const {
-
if (x == p_v.x) {
- if (y == p_v.y)
+ if (y == p_v.y) {
return z <= p_v.z;
- else
+ } else {
return y < p_v.y;
+ }
} else {
return x < p_v.x;
}
}
bool Vector3i::operator>=(const Vector3i &p_v) const {
-
if (x == p_v.x) {
- if (y == p_v.y)
+ if (y == p_v.y) {
return z >= p_v.z;
- else
+ } else {
return y > p_v.y;
+ }
} else {
return x > p_v.x;
}
}
void Vector3i::zero() {
-
x = y = z = 0;
}
diff --git a/core/message_queue.cpp b/core/message_queue.cpp
index ad4211f3da..8c71f760b2 100644
--- a/core/message_queue.cpp
+++ b/core/message_queue.cpp
@@ -37,24 +37,22 @@
MessageQueue *MessageQueue::singleton = nullptr;
MessageQueue *MessageQueue::get_singleton() {
-
return singleton;
}
Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error) {
-
return push_callable(Callable(p_id, p_method), p_args, p_argcount, p_show_error);
}
Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, VARIANT_ARG_DECLARE) {
-
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -62,15 +60,15 @@ Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, VARIANT
}
Error MessageQueue::push_set(ObjectID p_id, const StringName &p_prop, const Variant &p_value) {
-
_THREAD_SAFE_METHOD_
uint8_t room_needed = sizeof(Message) + sizeof(Variant);
if ((buffer_end + room_needed) >= buffer_size) {
String type;
- if (ObjectDB::get_instance(p_id))
+ if (ObjectDB::get_instance(p_id)) {
type = ObjectDB::get_instance(p_id)->get_class();
+ }
print_line("Failed set: " + type + ":" + p_prop + " target ID: " + itos(p_id));
statistics();
ERR_FAIL_V_MSG(ERR_OUT_OF_MEMORY, "Message queue out of memory. Try increasing 'memory/limits/message_queue/max_size_kb' in project settings.");
@@ -91,7 +89,6 @@ Error MessageQueue::push_set(ObjectID p_id, const StringName &p_prop, const Vari
}
Error MessageQueue::push_notification(ObjectID p_id, int p_notification) {
-
_THREAD_SAFE_METHOD_
ERR_FAIL_COND_V(p_notification < 0, ERR_INVALID_PARAMETER);
@@ -117,21 +114,18 @@ Error MessageQueue::push_notification(ObjectID p_id, int p_notification) {
}
Error MessageQueue::push_call(Object *p_object, const StringName &p_method, VARIANT_ARG_DECLARE) {
-
return push_call(p_object->get_instance_id(), p_method, VARIANT_ARG_PASS);
}
Error MessageQueue::push_notification(Object *p_object, int p_notification) {
-
return push_notification(p_object->get_instance_id(), p_notification);
}
-Error MessageQueue::push_set(Object *p_object, const StringName &p_prop, const Variant &p_value) {
+Error MessageQueue::push_set(Object *p_object, const StringName &p_prop, const Variant &p_value) {
return push_set(p_object->get_instance_id(), p_prop, p_value);
}
Error MessageQueue::push_callable(const Callable &p_callable, const Variant **p_args, int p_argcount, bool p_show_error) {
-
_THREAD_SAFE_METHOD_
int room_needed = sizeof(Message) + sizeof(Variant) * p_argcount;
@@ -146,13 +140,13 @@ Error MessageQueue::push_callable(const Callable &p_callable, const Variant **p_
msg->args = p_argcount;
msg->callable = p_callable;
msg->type = TYPE_CALL;
- if (p_show_error)
+ if (p_show_error) {
msg->type |= FLAG_SHOW_ERROR;
+ }
buffer_end += sizeof(Message);
for (int i = 0; i < p_argcount; i++) {
-
Variant *v = memnew_placement(&buffer[buffer_end], Variant);
buffer_end += sizeof(Variant);
*v = *p_args[i];
@@ -162,7 +156,6 @@ Error MessageQueue::push_callable(const Callable &p_callable, const Variant **p_
}
void MessageQueue::statistics() {
-
Map<StringName, int> set_count;
Map<int, int> notify_count;
Map<Callable, int> call_count;
@@ -175,30 +168,28 @@ void MessageQueue::statistics() {
Object *target = message->callable.get_object();
if (target != nullptr) {
-
switch (message->type & FLAG_MASK) {
-
case TYPE_CALL: {
-
- if (!call_count.has(message->callable))
+ if (!call_count.has(message->callable)) {
call_count[message->callable] = 0;
+ }
call_count[message->callable]++;
} break;
case TYPE_NOTIFICATION: {
-
- if (!notify_count.has(message->notification))
+ if (!notify_count.has(message->notification)) {
notify_count[message->notification] = 0;
+ }
notify_count[message->notification]++;
} break;
case TYPE_SET: {
-
StringName t = message->callable.get_method();
- if (!set_count.has(t))
+ if (!set_count.has(t)) {
set_count[t] = 0;
+ }
set_count[t]++;
@@ -213,8 +204,9 @@ void MessageQueue::statistics() {
}
read_pos += sizeof(Message);
- if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION)
+ if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) {
read_pos += sizeof(Variant) * message->args;
+ }
}
print_line("TOTAL BYTES: " + itos(buffer_end));
@@ -234,12 +226,10 @@ void MessageQueue::statistics() {
}
int MessageQueue::get_max_buffer_usage() const {
-
return buffer_max_used;
}
void MessageQueue::_call_function(const Callable &p_callable, const Variant *p_args, int p_argcount, bool p_show_error) {
-
const Variant **argptrs = nullptr;
if (p_argcount) {
argptrs = (const Variant **)alloca(sizeof(Variant *) * p_argcount);
@@ -252,13 +242,11 @@ void MessageQueue::_call_function(const Callable &p_callable, const Variant *p_a
Variant ret;
p_callable.call(argptrs, p_argcount, ret, ce);
if (p_show_error && ce.error != Callable::CallError::CALL_OK) {
-
ERR_PRINT("Error calling deferred method: " + Variant::get_callable_error_text(p_callable, argptrs, p_argcount, ce) + ".");
}
}
void MessageQueue::flush() {
-
if (buffer_end > buffer_max_used) {
buffer_max_used = buffer_end;
}
@@ -275,14 +263,14 @@ void MessageQueue::flush() {
flushing = true;
while (read_pos < buffer_end) {
-
//lock on each iteration, so a call can re-add itself to the message queue
Message *message = (Message *)&buffer[read_pos];
uint32_t advance = sizeof(Message);
- if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION)
+ if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) {
advance += sizeof(Variant) * message->args;
+ }
//pre-advance so this function is reentrant
read_pos += advance;
@@ -292,10 +280,8 @@ void MessageQueue::flush() {
Object *target = message->callable.get_object();
if (target != nullptr) {
-
switch (message->type & FLAG_MASK) {
case TYPE_CALL: {
-
Variant *args = (Variant *)(message + 1);
// messages don't expect a return value
@@ -304,13 +290,11 @@ void MessageQueue::flush() {
} break;
case TYPE_NOTIFICATION: {
-
// messages don't expect a return value
target->notification(message->notification);
} break;
case TYPE_SET: {
-
Variant *arg = (Variant *)(message + 1);
// messages don't expect a return value
target->set(message->callable.get_method(), *arg);
@@ -337,12 +321,10 @@ void MessageQueue::flush() {
}
bool MessageQueue::is_flushing() const {
-
return flushing;
}
MessageQueue::MessageQueue() {
-
ERR_FAIL_COND_MSG(singleton != nullptr, "A MessageQueue singleton already exists.");
singleton = this;
@@ -353,23 +335,23 @@ MessageQueue::MessageQueue() {
}
MessageQueue::~MessageQueue() {
-
uint32_t read_pos = 0;
while (read_pos < buffer_end) {
-
Message *message = (Message *)&buffer[read_pos];
Variant *args = (Variant *)(message + 1);
int argc = message->args;
if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) {
- for (int i = 0; i < argc; i++)
+ for (int i = 0; i < argc; i++) {
args[i].~Variant();
+ }
}
message->~Message();
read_pos += sizeof(Message);
- if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION)
+ if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) {
read_pos += sizeof(Variant) * message->args;
+ }
}
singleton = nullptr;
diff --git a/core/message_queue.h b/core/message_queue.h
index 180e0ce362..8e50f1b2b7 100644
--- a/core/message_queue.h
+++ b/core/message_queue.h
@@ -35,7 +35,6 @@
#include "core/os/thread_safe.h"
class MessageQueue {
-
_THREAD_SAFE_CLASS_
enum {
@@ -53,7 +52,6 @@ class MessageQueue {
};
struct Message {
-
Callable callable;
int16_t type;
union {
diff --git a/core/method_bind.cpp b/core/method_bind.cpp
index 854e19cf8a..3244c63292 100644
--- a/core/method_bind.cpp
+++ b/core/method_bind.cpp
@@ -36,7 +36,6 @@
#ifdef DEBUG_METHODS_ENABLED
PropertyInfo MethodBind::get_argument_info(int p_argument) const {
-
ERR_FAIL_INDEX_V(p_argument, get_argument_count(), PropertyInfo());
PropertyInfo info = _gen_argument_type_info(p_argument);
@@ -45,35 +44,32 @@ PropertyInfo MethodBind::get_argument_info(int p_argument) const {
}
PropertyInfo MethodBind::get_return_info() const {
-
return _gen_argument_type_info(-1);
}
#endif
void MethodBind::_set_const(bool p_const) {
-
_const = p_const;
}
void MethodBind::_set_returns(bool p_returns) {
-
_returns = p_returns;
}
StringName MethodBind::get_name() const {
return name;
}
+
void MethodBind::set_name(const StringName &p_name) {
name = p_name;
}
#ifdef DEBUG_METHODS_ENABLED
void MethodBind::set_argument_names(const Vector<StringName> &p_names) {
-
arg_names = p_names;
}
-Vector<StringName> MethodBind::get_argument_names() const {
+Vector<StringName> MethodBind::get_argument_names() const {
return arg_names;
}
@@ -86,7 +82,6 @@ void MethodBind::set_default_arguments(const Vector<Variant> &p_defargs) {
#ifdef DEBUG_METHODS_ENABLED
void MethodBind::_generate_argument_types(int p_count) {
-
set_argument_count(p_count);
Variant::Type *argt = memnew_arr(Variant::Type, p_count + 1);
@@ -108,7 +103,8 @@ MethodBind::MethodBind() {
MethodBind::~MethodBind() {
#ifdef DEBUG_METHODS_ENABLED
- if (argument_types)
+ if (argument_types) {
memdelete_arr(argument_types);
+ }
#endif
}
diff --git a/core/method_bind.h b/core/method_bind.h
index 0092527a25..ff2c771f81 100644
--- a/core/method_bind.h
+++ b/core/method_bind.h
@@ -59,27 +59,21 @@ enum MethodFlags {
template <class T>
struct VariantCaster {
-
static _FORCE_INLINE_ T cast(const Variant &p_variant) {
-
return p_variant;
}
};
template <class T>
struct VariantCaster<T &> {
-
static _FORCE_INLINE_ T cast(const Variant &p_variant) {
-
return p_variant;
}
};
template <class T>
struct VariantCaster<const T &> {
-
static _FORCE_INLINE_ T cast(const Variant &p_variant) {
-
return p_variant;
}
};
@@ -93,7 +87,6 @@ struct VariantCaster<const T &> {
MAKE_ENUM_TYPE_INFO(m_enum) \
template <> \
struct VariantCaster<m_enum> { \
- \
static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \
return (m_enum)p_variant.operator int(); \
} \
@@ -114,7 +107,6 @@ struct VariantCaster<const T &> {
MAKE_ENUM_TYPE_INFO(m_enum) \
template <> \
struct VariantCaster<m_enum> { \
- \
static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \
return (m_enum)p_variant.operator int(); \
} \
@@ -165,8 +157,9 @@ struct VariantObjectClassChecker<Control *> {
#define CHECK_NOARG(m_arg) \
{ \
if (p_arg##m_arg.get_type() != Variant::NIL) { \
- if (r_argerror) \
+ if (r_argerror) { \
*r_argerror = (m_arg - 1); \
+ } \
return CALL_ERROR_EXTRA_ARGUMENT; \
} \
}
@@ -206,7 +199,6 @@ struct PtrToArg<wchar_t> {
#endif
class MethodBind {
-
int method_id;
uint32_t hint_flags = METHOD_FLAGS_DEFAULT;
StringName name;
@@ -237,29 +229,28 @@ public:
_FORCE_INLINE_ int get_default_argument_count() const { return default_argument_count; }
_FORCE_INLINE_ Variant has_default_argument(int p_arg) const {
-
int idx = argument_count - p_arg - 1;
- if (idx < 0 || idx >= default_arguments.size())
+ if (idx < 0 || idx >= default_arguments.size()) {
return false;
- else
+ } else {
return true;
+ }
}
_FORCE_INLINE_ Variant get_default_argument(int p_arg) const {
-
int idx = argument_count - p_arg - 1;
- if (idx < 0 || idx >= default_arguments.size())
+ if (idx < 0 || idx >= default_arguments.size()) {
return Variant();
- else
+ } else {
return default_arguments[idx];
+ }
}
#ifdef DEBUG_METHODS_ENABLED
_FORCE_INLINE_ Variant::Type get_argument_type(int p_argument) const {
-
ERR_FAIL_COND_V(p_argument < -1 || p_argument > argument_count, Variant::NIL);
return argument_types[p_argument + 1];
}
@@ -313,7 +304,6 @@ public:
#ifdef DEBUG_METHODS_ENABLED
virtual PropertyInfo _gen_argument_type_info(int p_arg) const {
-
if (p_arg < 0) {
return arguments.return_val;
} else if (p_arg < arguments.arguments.size()) {
@@ -339,23 +329,19 @@ public:
#endif
virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
-
T *instance = static_cast<T *>(p_object);
return (instance->*call_method)(p_args, p_arg_count, r_error);
}
void set_method_info(const MethodInfo &p_info, bool p_return_nil_is_variant) {
-
set_argument_count(p_info.arguments.size());
#ifdef DEBUG_METHODS_ENABLED
Variant::Type *at = memnew_arr(Variant::Type, p_info.arguments.size() + 1);
at[0] = p_info.return_val.type;
if (p_info.arguments.size()) {
-
Vector<StringName> names;
names.resize(p_info.arguments.size());
for (int i = 0; i < p_info.arguments.size(); i++) {
-
at[i + 1] = p_info.arguments[i].type;
names.write[i] = p_info.arguments[i].name;
}
@@ -389,7 +375,6 @@ public:
template <class T>
MethodBind *create_vararg_method_bind(Variant (T::*p_method)(const Variant **, int, Callable::CallError &), const MethodInfo &p_info, bool p_return_nil_is_variant) {
-
MethodBindVarArg<T> *a = memnew((MethodBindVarArg<T>));
a->set_method(p_method);
a->set_method_info(p_info, p_return_nil_is_variant);
diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h
index 7ae0a788bd..022ed2a5d6 100644
--- a/core/method_ptrcall.h
+++ b/core/method_ptrcall.h
@@ -150,28 +150,22 @@ MAKE_PTRARG_BY_REFERENCE(Variant);
template <class T>
struct PtrToArg<T *> {
-
_FORCE_INLINE_ static T *convert(const void *p_ptr) {
-
return const_cast<T *>(reinterpret_cast<const T *>(p_ptr));
}
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
-
*((T **)p_ptr) = p_var;
}
};
template <class T>
struct PtrToArg<const T *> {
-
_FORCE_INLINE_ static const T *convert(const void *p_ptr) {
-
return reinterpret_cast<const T *>(p_ptr);
}
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
-
*((T **)p_ptr) = p_var;
}
};
@@ -181,12 +175,10 @@ struct PtrToArg<const T *> {
template <>
struct PtrToArg<ObjectID> {
_FORCE_INLINE_ static const ObjectID convert(const void *p_ptr) {
-
return ObjectID(*reinterpret_cast<const uint64_t *>(p_ptr));
}
_FORCE_INLINE_ static void encode(const ObjectID &p_val, void *p_ptr) {
-
*((uint64_t *)p_ptr) = p_val;
}
};
diff --git a/core/node_path.cpp b/core/node_path.cpp
index f8001a354a..2a51dca74a 100644
--- a/core/node_path.cpp
+++ b/core/node_path.cpp
@@ -33,7 +33,6 @@
#include "core/print_string.h"
void NodePath::_update_hash_cache() const {
-
uint32_t h = data->absolute ? 1 : 0;
int pc = data->path.size();
const StringName *sn = data->path.ptr();
@@ -51,7 +50,6 @@ void NodePath::_update_hash_cache() const {
}
void NodePath::prepend_period() {
-
if (data->path.size() && data->path[0].operator String() != ".") {
data->path.insert(0, ".");
data->hash_cache_valid = false;
@@ -59,59 +57,60 @@ void NodePath::prepend_period() {
}
bool NodePath::is_absolute() const {
-
- if (!data)
+ if (!data) {
return false;
+ }
return data->absolute;
}
-int NodePath::get_name_count() const {
- if (!data)
+int NodePath::get_name_count() const {
+ if (!data) {
return 0;
+ }
return data->path.size();
}
-StringName NodePath::get_name(int p_idx) const {
+StringName NodePath::get_name(int p_idx) const {
ERR_FAIL_COND_V(!data, StringName());
ERR_FAIL_INDEX_V(p_idx, data->path.size(), StringName());
return data->path[p_idx];
}
int NodePath::get_subname_count() const {
-
- if (!data)
+ if (!data) {
return 0;
+ }
return data->subpath.size();
}
-StringName NodePath::get_subname(int p_idx) const {
+StringName NodePath::get_subname(int p_idx) const {
ERR_FAIL_COND_V(!data, StringName());
ERR_FAIL_INDEX_V(p_idx, data->subpath.size(), StringName());
return data->subpath[p_idx];
}
void NodePath::unref() {
-
if (data && data->refcount.unref()) {
-
memdelete(data);
}
data = nullptr;
}
bool NodePath::operator==(const NodePath &p_path) const {
-
- if (data == p_path.data)
+ if (data == p_path.data) {
return true;
+ }
- if (!data || !p_path.data)
+ if (!data || !p_path.data) {
return false;
+ }
- if (data->absolute != p_path.data->absolute)
+ if (data->absolute != p_path.data->absolute) {
return false;
+ }
int path_size = data->path.size();
@@ -129,58 +128,57 @@ bool NodePath::operator==(const NodePath &p_path) const {
const StringName *r_path_ptr = p_path.data->path.ptr();
for (int i = 0; i < path_size; i++) {
-
- if (l_path_ptr[i] != r_path_ptr[i])
+ if (l_path_ptr[i] != r_path_ptr[i]) {
return false;
+ }
}
const StringName *l_subpath_ptr = data->subpath.ptr();
const StringName *r_subpath_ptr = p_path.data->subpath.ptr();
for (int i = 0; i < subpath_size; i++) {
-
- if (l_subpath_ptr[i] != r_subpath_ptr[i])
+ if (l_subpath_ptr[i] != r_subpath_ptr[i]) {
return false;
+ }
}
return true;
}
-bool NodePath::operator!=(const NodePath &p_path) const {
+bool NodePath::operator!=(const NodePath &p_path) const {
return (!(*this == p_path));
}
void NodePath::operator=(const NodePath &p_path) {
-
- if (this == &p_path)
+ if (this == &p_path) {
return;
+ }
unref();
if (p_path.data && p_path.data->refcount.ref()) {
-
data = p_path.data;
}
}
NodePath::operator String() const {
-
- if (!data)
+ if (!data) {
return String();
+ }
String ret;
- if (data->absolute)
+ if (data->absolute) {
ret = "/";
+ }
for (int i = 0; i < data->path.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
ret += "/";
+ }
ret += data->path[i].operator String();
}
for (int i = 0; i < data->subpath.size(); i++) {
-
ret += ":" + data->subpath[i].operator String();
}
@@ -188,16 +186,16 @@ NodePath::operator String() const {
}
Vector<StringName> NodePath::get_names() const {
-
- if (data)
+ if (data) {
return data->path;
+ }
return Vector<StringName>();
}
Vector<StringName> NodePath::get_subnames() const {
-
- if (data)
+ if (data) {
return data->subpath;
+ }
return Vector<StringName>();
}
@@ -217,7 +215,6 @@ StringName NodePath::get_concatenated_subnames() const {
}
NodePath NodePath::rel_path_to(const NodePath &p_np) const {
-
ERR_FAIL_COND_V(!is_absolute(), NodePath());
ERR_FAIL_COND_V(!p_np.is_absolute(), NodePath());
@@ -228,12 +225,15 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const {
int common_parent = 0;
while (true) {
- if (src_dirs.size() == common_parent)
+ if (src_dirs.size() == common_parent) {
break;
- if (dst_dirs.size() == common_parent)
+ }
+ if (dst_dirs.size() == common_parent) {
break;
- if (src_dirs[common_parent] != dst_dirs[common_parent])
+ }
+ if (src_dirs[common_parent] != dst_dirs[common_parent]) {
break;
+ }
common_parent++;
}
@@ -242,23 +242,21 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const {
Vector<StringName> relpath;
for (int i = src_dirs.size() - 1; i > common_parent; i--) {
-
relpath.push_back("..");
}
for (int i = common_parent + 1; i < dst_dirs.size(); i++) {
-
relpath.push_back(dst_dirs[i]);
}
- if (relpath.size() == 0)
+ if (relpath.size() == 0) {
relpath.push_back(".");
+ }
return NodePath(relpath, p_np.get_subnames(), false);
}
NodePath NodePath::get_as_property_path() const {
-
if (!data || !data->path.size()) {
return *this;
} else {
@@ -280,12 +278,13 @@ bool NodePath::is_empty() const {
}
void NodePath::simplify() {
-
- if (!data)
+ if (!data) {
return;
+ }
for (int i = 0; i < data->path.size(); i++) {
- if (data->path.size() == 1)
+ if (data->path.size() == 1) {
break;
+ }
if (data->path[i].operator String() == ".") {
data->path.remove(i);
i--;
@@ -304,15 +303,15 @@ void NodePath::simplify() {
}
NodePath NodePath::simplified() const {
-
NodePath np = *this;
np.simplify();
return np;
}
NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) {
- if (p_path.size() == 0)
+ if (p_path.size() == 0) {
return;
+ }
data = memnew(Data);
data->refcount.init();
@@ -323,8 +322,9 @@ NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) {
}
NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p_subpath, bool p_absolute) {
- if (p_path.size() == 0 && p_subpath.size() == 0)
+ if (p_path.size() == 0 && p_subpath.size() == 0) {
return;
+ }
data = memnew(Data);
data->refcount.init();
@@ -342,8 +342,9 @@ NodePath::NodePath(const NodePath &p_path) {
}
NodePath::NodePath(const String &p_path) {
- if (p_path.length() == 0)
+ if (p_path.length() == 0) {
return;
+ }
String path = p_path;
Vector<StringName> subpath;
@@ -355,17 +356,15 @@ NodePath::NodePath(const String &p_path) {
int subpath_pos = path.find(":");
if (subpath_pos != -1) {
-
int from = subpath_pos + 1;
for (int i = from; i <= path.length(); i++) {
-
if (path[i] == ':' || path[i] == 0) {
-
String str = path.substr(from, i - from);
if (str == "") {
- if (path[i] == 0)
+ if (path[i] == 0) {
continue; // Allow end-of-path :
+ }
ERR_FAIL_MSG("Invalid NodePath '" + p_path + "'.");
}
@@ -379,22 +378,21 @@ NodePath::NodePath(const String &p_path) {
}
for (int i = (int)absolute; i < path.length(); i++) {
-
if (path[i] == '/') {
-
last_is_slash = true;
has_slashes = true;
} else {
-
- if (last_is_slash)
+ if (last_is_slash) {
slices++;
+ }
last_is_slash = false;
}
}
- if (slices == 0 && !absolute && !subpath.size())
+ if (slices == 0 && !absolute && !subpath.size()) {
return;
+ }
data = memnew(Data);
data->refcount.init();
@@ -403,19 +401,17 @@ NodePath::NodePath(const String &p_path) {
data->subpath = subpath;
data->hash_cache_valid = false;
- if (slices == 0)
+ if (slices == 0) {
return;
+ }
data->path.resize(slices);
last_is_slash = true;
int from = (int)absolute;
int slice = 0;
for (int i = (int)absolute; i < path.length() + 1; i++) {
-
if (path[i] == '/' || path[i] == 0) {
-
if (!last_is_slash) {
-
String name = path.substr(from, i - from);
ERR_FAIL_INDEX(slice, data->path.size());
data->path.write[slice++] = name;
diff --git a/core/node_path.h b/core/node_path.h
index fb15d017bf..7c06bf01ce 100644
--- a/core/node_path.h
+++ b/core/node_path.h
@@ -35,9 +35,7 @@
#include "core/ustring.h"
class NodePath {
-
struct Data {
-
SafeRefCount refcount;
Vector<StringName> path;
Vector<StringName> subpath;
@@ -71,8 +69,9 @@ public:
NodePath get_parent() const;
_FORCE_INLINE_ uint32_t hash() const {
- if (!data)
+ if (!data) {
return 0;
+ }
if (!data->hash_cache_valid) {
_update_hash_cache();
}
diff --git a/core/oa_hash_map.h b/core/oa_hash_map.h
index b4d9ce4d51..e411ced044 100644
--- a/core/oa_hash_map.h
+++ b/core/oa_hash_map.h
@@ -50,7 +50,6 @@ template <class TKey, class TValue,
class Hasher = HashMapHasherDefault,
class Comparator = HashMapComparatorDefault<TKey>>
class OAHashMap {
-
private:
TValue *values;
TKey *keys;
@@ -110,7 +109,6 @@ private:
}
void _insert_with_hash(uint32_t p_hash, const TKey &p_key, const TValue &p_value) {
-
uint32_t hash = p_hash;
uint32_t distance = 0;
uint32_t pos = hash % capacity;
@@ -140,7 +138,6 @@ private:
}
void _resize_and_rehash(uint32_t p_new_capacity) {
-
uint32_t old_capacity = capacity;
capacity = p_new_capacity;
@@ -183,9 +180,7 @@ public:
}
void clear() {
-
for (uint32_t i = 0; i < capacity; i++) {
-
if (hashes[i] == EMPTY_HASH) {
continue;
}
@@ -199,7 +194,6 @@ public:
}
void insert(const TKey &p_key, const TValue &p_value) {
-
if (num_elements + 1 > 0.9 * capacity) {
_resize_and_rehash();
}
@@ -317,7 +311,6 @@ public:
}
Iterator next_iter(const Iterator &p_iter) const {
-
if (!p_iter.valid) {
return p_iter;
}
@@ -348,7 +341,6 @@ public:
OAHashMap &operator=(const OAHashMap &) = delete; // Same for assignment operator.
OAHashMap(uint32_t p_initial_capacity = 64) {
-
capacity = p_initial_capacity;
keys = memnew_arr(TKey, p_initial_capacity);
@@ -361,7 +353,6 @@ public:
}
~OAHashMap() {
-
memdelete_arr(keys);
memdelete_arr(values);
memdelete_arr(hashes);
diff --git a/core/object.cpp b/core/object.cpp
index 9ae2d2dcde..0a4e8a5890 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -42,7 +42,6 @@
#ifdef DEBUG_ENABLED
struct _ObjectDebugLock {
-
Object *obj;
_ObjectDebugLock(Object *p_obj) {
@@ -63,7 +62,6 @@ struct _ObjectDebugLock {
#endif
PropertyInfo::operator Dictionary() const {
-
Dictionary d;
d["name"] = name;
d["class_name"] = class_name;
@@ -75,36 +73,38 @@ PropertyInfo::operator Dictionary() const {
}
PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) {
-
PropertyInfo pi;
- if (p_dict.has("type"))
+ if (p_dict.has("type")) {
pi.type = Variant::Type(int(p_dict["type"]));
+ }
- if (p_dict.has("name"))
+ if (p_dict.has("name")) {
pi.name = p_dict["name"];
+ }
- if (p_dict.has("class_name"))
+ if (p_dict.has("class_name")) {
pi.class_name = p_dict["class_name"];
+ }
- if (p_dict.has("hint"))
+ if (p_dict.has("hint")) {
pi.hint = PropertyHint(int(p_dict["hint"]));
+ }
- if (p_dict.has("hint_string"))
-
+ if (p_dict.has("hint_string")) {
pi.hint_string = p_dict["hint_string"];
+ }
- if (p_dict.has("usage"))
+ if (p_dict.has("usage")) {
pi.usage = p_dict["usage"];
+ }
return pi;
}
Array convert_property_list(const List<PropertyInfo> *p_list) {
-
Array va;
for (const List<PropertyInfo>::Element *E = p_list->front(); E; E = E->next()) {
-
va.push_back(Dictionary(E->get()));
}
@@ -112,13 +112,13 @@ Array convert_property_list(const List<PropertyInfo> *p_list) {
}
MethodInfo::operator Dictionary() const {
-
Dictionary d;
d["name"] = name;
d["args"] = convert_property_list(&arguments);
Array da;
- for (int i = 0; i < default_arguments.size(); i++)
+ for (int i = 0; i < default_arguments.size(); i++) {
da.push_back(default_arguments[i]);
+ }
d["default_args"] = da;
d["flags"] = flags;
d["id"] = id;
@@ -128,11 +128,11 @@ MethodInfo::operator Dictionary() const {
}
MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) {
-
MethodInfo mi;
- if (p_dict.has("name"))
+ if (p_dict.has("name")) {
mi.name = p_dict["name"];
+ }
Array args;
if (p_dict.has("args")) {
args = p_dict["args"];
@@ -154,8 +154,9 @@ MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) {
mi.return_val = PropertyInfo::from_dict(p_dict["return"]);
}
- if (p_dict.has("flags"))
+ if (p_dict.has("flags")) {
mi.flags = p_dict["flags"];
+ }
return mi;
}
@@ -167,11 +168,13 @@ MethodInfo::MethodInfo(const String &p_name) :
name(p_name),
flags(METHOD_FLAG_NORMAL) {
}
+
MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1) :
name(p_name),
flags(METHOD_FLAG_NORMAL) {
arguments.push_back(p_param1);
}
+
MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2) :
name(p_name),
flags(METHOD_FLAG_NORMAL) {
@@ -216,12 +219,14 @@ MethodInfo::MethodInfo(Variant::Type ret, const String &p_name) :
flags(METHOD_FLAG_NORMAL) {
return_val.type = ret;
}
+
MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1) :
name(p_name),
flags(METHOD_FLAG_NORMAL) {
return_val.type = ret;
arguments.push_back(p_param1);
}
+
MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2) :
name(p_name),
flags(METHOD_FLAG_NORMAL) {
@@ -312,7 +317,6 @@ MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const Pr
}
Object::Connection::operator Variant() const {
-
Dictionary d;
d["signal"] = signal;
d["callable"] = callable;
@@ -322,28 +326,30 @@ Object::Connection::operator Variant() const {
}
bool Object::Connection::operator<(const Connection &p_conn) const {
-
if (signal == p_conn.signal) {
return callable < p_conn.callable;
} else {
return signal < p_conn.signal;
}
}
-Object::Connection::Connection(const Variant &p_variant) {
+Object::Connection::Connection(const Variant &p_variant) {
Dictionary d = p_variant;
- if (d.has("signal"))
+ if (d.has("signal")) {
signal = d["signal"];
- if (d.has("callable"))
+ }
+ if (d.has("callable")) {
callable = d["callable"];
- if (d.has("flags"))
+ }
+ if (d.has("flags")) {
flags = d["flags"];
- if (d.has("binds"))
+ }
+ if (d.has("binds")) {
binds = d["binds"];
+ }
}
bool Object::_predelete() {
-
_predelete_ok = 1;
notification(NOTIFICATION_PREDELETE, true);
if (_predelete_ok) {
@@ -360,21 +366,21 @@ void Object::_postinitialize() {
void Object::get_valid_parents_static(List<String> *p_parents) {
}
+
void Object::_get_valid_parents_static(List<String> *p_parents) {
}
void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid) {
-
#ifdef TOOLS_ENABLED
_edited = true;
#endif
if (script_instance) {
-
if (script_instance->set(p_name, p_value)) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
}
}
@@ -392,23 +398,26 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid
if (p_name == CoreStringNames::get_singleton()->_script) {
set_script(p_value);
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
} else if (p_name == CoreStringNames::get_singleton()->_meta) {
//set_meta(p_name,p_value);
metadata = p_value.duplicate();
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
}
//something inside the object... :|
bool success = _setv(p_name, p_value);
if (success) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
}
@@ -416,8 +425,9 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid
bool valid;
setvar(p_name, p_value, &valid);
if (valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
}
}
@@ -427,26 +437,27 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid
bool valid;
script_instance->property_set_fallback(p_name, p_value, &valid);
if (valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
}
}
#endif
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
}
Variant Object::get(const StringName &p_name, bool *r_valid) const {
-
Variant ret;
if (script_instance) {
-
if (script_instance->get(p_name, ret)) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
}
}
@@ -454,30 +465,34 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
//try built-in setgetter
{
if (ClassDB::get_property(const_cast<Object *>(this), p_name, ret)) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
}
}
if (p_name == CoreStringNames::get_singleton()->_script) {
ret = get_script();
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
} else if (p_name == CoreStringNames::get_singleton()->_meta) {
ret = metadata;
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
} else {
//something inside the object... :|
bool success = _getv(p_name, ret);
if (success) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
}
@@ -486,8 +501,9 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
bool valid;
ret = getvar(p_name, &valid);
if (valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
}
}
@@ -497,23 +513,26 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
bool valid;
ret = script_instance->property_get_fallback(p_name, &valid);
if (valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
}
}
#endif
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant();
}
}
void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_value, bool *r_valid) {
if (p_names.empty()) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return;
}
if (p_names.size() == 1) {
@@ -522,8 +541,9 @@ void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_val
}
bool valid = false;
- if (!r_valid)
+ if (!r_valid) {
r_valid = &valid;
+ }
List<Variant> value_stack;
@@ -546,7 +566,6 @@ void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_val
value_stack.push_back(p_value); // p_names[p_names.size() - 1]
for (int i = p_names.size() - 1; i > 0; i--) {
-
value_stack.back()->prev()->get().set_named(p_names[i], value_stack.back()->get(), r_valid);
value_stack.pop_back();
@@ -564,8 +583,9 @@ void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_val
Variant Object::get_indexed(const Vector<StringName> &p_names, bool *r_valid) const {
if (p_names.empty()) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant();
}
bool valid = false;
@@ -574,17 +594,18 @@ Variant Object::get_indexed(const Vector<StringName> &p_names, bool *r_valid) co
for (int i = 1; i < p_names.size(); i++) {
current_value = current_value.get_named(p_names[i], &valid);
- if (!valid)
+ if (!valid) {
break;
+ }
}
- if (r_valid)
+ if (r_valid) {
*r_valid = valid;
+ }
return current_value;
}
void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) const {
-
if (script_instance && p_reversed) {
p_list->push_back(PropertyInfo(Variant::NIL, "Script Variables", PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY));
script_instance->get_property_list(p_list);
@@ -611,7 +632,6 @@ void Object::_validate_property(PropertyInfo &property) const {
}
void Object::get_method_list(List<MethodInfo> *p_list) const {
-
ClassDB::get_method_list(get_class_name(), p_list);
if (script_instance) {
script_instance->get_method_list(p_list);
@@ -619,7 +639,6 @@ void Object::get_method_list(List<MethodInfo> *p_list) const {
}
Variant Object::_call_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
-
if (p_argcount < 1) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument = 0;
@@ -639,7 +658,6 @@ Variant Object::_call_bind(const Variant **p_args, int p_argcount, Callable::Cal
}
Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
-
if (p_argcount < 1) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument = 0;
@@ -664,24 +682,19 @@ Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Call
#ifdef DEBUG_ENABLED
static void _test_call_error(const StringName &p_func, const Callable::CallError &error) {
-
switch (error.error) {
-
case Callable::CallError::CALL_OK:
case Callable::CallError::CALL_ERROR_INVALID_METHOD:
break;
case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: {
-
ERR_FAIL_MSG("Error calling function: " + String(p_func) + " - Invalid type for argument " + itos(error.argument) + ", expected " + Variant::get_type_name(Variant::Type(error.expected)) + ".");
break;
}
case Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: {
-
ERR_FAIL_MSG("Error calling function: " + String(p_func) + " - Too many arguments, expected " + itos(error.argument) + ".");
break;
}
case Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: {
-
ERR_FAIL_MSG("Error calling function: " + String(p_func) + " - Too few arguments, expected " + itos(error.argument) + ".");
break;
}
@@ -696,7 +709,6 @@ static void _test_call_error(const StringName &p_func, const Callable::CallError
#endif
void Object::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) {
-
if (p_method == CoreStringNames::get_singleton()->_free) {
#ifdef DEBUG_ENABLED
ERR_FAIL_COND_MSG(Object::cast_to<Reference>(this), "Can't 'free' a reference.");
@@ -722,21 +734,18 @@ void Object::call_multilevel(const StringName &p_method, const Variant **p_args,
MethodBind *method = ClassDB::get_method(get_class_name(), p_method);
if (method) {
-
method->call(this, p_args, p_argcount, error);
_test_call_error(p_method, error);
}
}
void Object::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) {
-
MethodBind *method = ClassDB::get_method(get_class_name(), p_method);
Callable::CallError error;
OBJ_DEBUG_LOCK
if (method) {
-
method->call(this, p_args, p_argcount, error);
_test_call_error(p_method, error);
}
@@ -750,7 +759,6 @@ void Object::call_multilevel_reversed(const StringName &p_method, const Variant
}
bool Object::has_method(const StringName &p_method) const {
-
if (p_method == CoreStringNames::get_singleton()->_free) {
return true;
}
@@ -765,15 +773,16 @@ bool Object::has_method(const StringName &p_method) const {
}
Variant Object::getvar(const Variant &p_key, bool *r_valid) const {
-
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant();
}
-void Object::setvar(const Variant &p_key, const Variant &p_value, bool *r_valid) {
- if (r_valid)
+void Object::setvar(const Variant &p_key, const Variant &p_value, bool *r_valid) {
+ if (r_valid) {
*r_valid = false;
+ }
}
Variant Object::callv(const StringName &p_method, const Array &p_args) {
@@ -795,13 +804,13 @@ Variant Object::callv(const StringName &p_method, const Array &p_args) {
}
Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) {
-
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -812,13 +821,13 @@ Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) {
}
void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) {
-
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -827,7 +836,6 @@ void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) {
}
Variant Object::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
-
r_error.error = Callable::CallError::CALL_OK;
if (p_method == CoreStringNames::get_singleton()->_free) {
@@ -863,7 +871,6 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a
ret = script_instance->call(p_method, p_args, p_argcount, r_error);
//force jumptable
switch (r_error.error) {
-
case Callable::CallError::CALL_OK:
return ret;
case Callable::CallError::CALL_ERROR_INVALID_METHOD:
@@ -889,7 +896,6 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a
}
void Object::notification(int p_notification, bool p_reversed) {
-
_notificationv(p_notification, p_reversed);
if (script_instance) {
@@ -901,8 +907,9 @@ String Object::to_string() {
if (script_instance) {
bool valid;
String ret = script_instance->to_string(&valid);
- if (valid)
+ if (valid) {
return ret;
+ }
}
return "[" + get_class() + ":" + itos(get_instance_id()) + "]";
}
@@ -911,27 +918,22 @@ void Object::_changed_callback(Object *p_changed, const char *p_prop) {
}
void Object::add_change_receptor(Object *p_receptor) {
-
change_receptors.insert(p_receptor);
}
void Object::remove_change_receptor(Object *p_receptor) {
-
change_receptors.erase(p_receptor);
}
void Object::property_list_changed_notify() {
-
_change_notify();
}
void Object::cancel_delete() {
-
_predelete_ok = true;
}
void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_instance) {
-
//this function is not meant to be used in any of these ways
ERR_FAIL_COND(p_script.is_null());
ERR_FAIL_COND(!p_instance);
@@ -942,9 +944,9 @@ void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_
}
void Object::set_script(const Variant &p_script) {
-
- if (script == p_script)
+ if (script == p_script) {
return;
+ }
if (script_instance) {
memdelete(script_instance);
@@ -969,33 +971,32 @@ void Object::set_script(const Variant &p_script) {
}
void Object::set_script_instance(ScriptInstance *p_instance) {
-
- if (script_instance == p_instance)
+ if (script_instance == p_instance) {
return;
+ }
- if (script_instance)
+ if (script_instance) {
memdelete(script_instance);
+ }
script_instance = p_instance;
- if (p_instance)
+ if (p_instance) {
script = p_instance->get_script();
- else
+ } else {
script = Variant();
+ }
}
Variant Object::get_script() const {
-
return script;
}
bool Object::has_meta(const String &p_name) const {
-
return metadata.has(p_name);
}
void Object::set_meta(const String &p_name, const Variant &p_value) {
-
if (p_value.get_type() == Variant::NIL) {
metadata.erase(p_name);
return;
@@ -1005,7 +1006,6 @@ void Object::set_meta(const String &p_name, const Variant &p_value) {
}
Variant Object::get_meta(const String &p_name) const {
-
ERR_FAIL_COND_V(!metadata.has(p_name), Variant());
return metadata[p_name];
}
@@ -1015,20 +1015,17 @@ void Object::remove_meta(const String &p_name) {
}
Array Object::_get_property_list_bind() const {
-
List<PropertyInfo> lpi;
get_property_list(&lpi);
return convert_property_list(&lpi);
}
Array Object::_get_method_list_bind() const {
-
List<MethodInfo> ml;
get_method_list(&ml);
Array ret;
for (List<MethodInfo>::Element *E = ml.front(); E; E = E->next()) {
-
Dictionary d = E->get();
//va.push_back(d);
ret.push_back(d);
@@ -1038,30 +1035,26 @@ Array Object::_get_method_list_bind() const {
}
Vector<String> Object::_get_meta_list_bind() const {
-
Vector<String> _metaret;
List<Variant> keys;
metadata.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
_metaret.push_back(E->get());
}
return _metaret;
}
-void Object::get_meta_list(List<String> *p_list) const {
+void Object::get_meta_list(List<String> *p_list) const {
List<Variant> keys;
metadata.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
p_list->push_back(E->get());
}
}
void Object::add_user_signal(const MethodInfo &p_signal) {
-
ERR_FAIL_COND_MSG(p_signal.name == "", "Signal name cannot be empty.");
ERR_FAIL_COND_MSG(ClassDB::has_signal(get_class_name(), p_signal.name), "User signal's name conflicts with a built-in signal of '" + get_class_name() + "'.");
ERR_FAIL_COND_MSG(signal_map.has(p_signal.name), "Trying to add already existing signal '" + p_signal.name + "'.");
@@ -1071,20 +1064,18 @@ void Object::add_user_signal(const MethodInfo &p_signal) {
}
bool Object::_has_user_signal(const StringName &p_name) const {
-
- if (!signal_map.has(p_name))
+ if (!signal_map.has(p_name)) {
return false;
+ }
return signal_map[p_name].user.name.length() > 0;
}
struct _ObjectSignalDisconnectData {
-
StringName signal;
Callable callable;
};
Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
-
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
ERR_FAIL_COND_V(p_argcount < 1, Variant());
@@ -1112,9 +1103,9 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::C
}
Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) {
-
- if (_block_signals)
+ if (_block_signals) {
return ERR_CANT_ACQUIRE_RESOURCE; //no emit, signals blocked
+ }
SignalData *s = signal_map.getptr(p_name);
if (!s) {
@@ -1143,7 +1134,6 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int
Error err = OK;
for (int i = 0; i < ssize; i++) {
-
const Connection &c = slot_map.getv(i).conn;
Object *target = c.callable.get_object();
@@ -1181,8 +1171,9 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int
if (ce.error != Callable::CallError::CALL_OK) {
#ifdef DEBUG_ENABLED
- if (c.flags & CONNECT_PERSIST && Engine::get_singleton()->is_editor_hint() && (script.is_null() || !Ref<Script>(script)->is_tool()))
+ if (c.flags & CONNECT_PERSIST && Engine::get_singleton()->is_editor_hint() && (script.is_null() || !Ref<Script>(script)->is_tool())) {
continue;
+ }
#endif
if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD && !ClassDB::class_exists(target->get_class_name())) {
//most likely object is not initialized yet, do not throw error.
@@ -1201,7 +1192,6 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int
}
#endif
if (disconnect) {
-
_ObjectSignalDisconnectData dd;
dd.signal = p_name;
dd.callable = c.callable;
@@ -1210,7 +1200,6 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int
}
while (!disconnect_data.empty()) {
-
const _ObjectSignalDisconnectData &dd = disconnect_data.front()->get();
_disconnect(dd.signal, dd.callable);
@@ -1221,15 +1210,14 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int
}
Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) {
-
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
-
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -1237,7 +1225,6 @@ Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) {
}
void Object::_add_user_signal(const String &p_name, const Array &p_args) {
-
// this version of add_user_signal is meant to be used from scripts or external apis
// without access to ADD_SIGNAL in bind_methods
// added events are per instance, as opposed to the other ones, which are global
@@ -1246,14 +1233,15 @@ void Object::_add_user_signal(const String &p_name, const Array &p_args) {
mi.name = p_name;
for (int i = 0; i < p_args.size(); i++) {
-
Dictionary d = p_args[i];
PropertyInfo param;
- if (d.has("name"))
+ if (d.has("name")) {
param.name = d["name"];
- if (d.has("type"))
+ }
+ if (d.has("type")) {
param.type = (Variant::Type)(int)d["type"];
+ }
mi.arguments.push_back(param);
}
@@ -1262,13 +1250,11 @@ void Object::_add_user_signal(const String &p_name, const Array &p_args) {
}
Array Object::_get_signal_list() const {
-
List<MethodInfo> signal_list;
get_signal_list(&signal_list);
Array ret;
for (List<MethodInfo>::Element *E = signal_list.front(); E; E = E->next()) {
-
ret.push_back(Dictionary(E->get()));
}
@@ -1276,14 +1262,12 @@ Array Object::_get_signal_list() const {
}
Array Object::_get_signal_connection_list(const String &p_signal) const {
-
List<Connection> conns;
get_all_signal_connections(&conns);
Array ret;
for (List<Connection>::Element *E = conns.front(); E; E = E->next()) {
-
Connection &c = E->get();
if (c.signal.get_name() == p_signal) {
ret.push_back(c);
@@ -1294,7 +1278,6 @@ Array Object::_get_signal_connection_list(const String &p_signal) const {
}
Array Object::_get_incoming_connections() const {
-
Array ret;
int connections_amount = connections.size();
for (int idx_conn = 0; idx_conn < connections_amount; idx_conn++) {
@@ -1324,7 +1307,6 @@ bool Object::has_signal(const StringName &p_name) const {
}
void Object::get_signal_list(List<MethodInfo> *p_signals) const {
-
if (!script.is_null()) {
Ref<Script> scr = script;
if (scr.is_valid()) {
@@ -1337,7 +1319,6 @@ void Object::get_signal_list(List<MethodInfo> *p_signals) const {
const StringName *S = nullptr;
while ((S = signal_map.next(S))) {
-
if (signal_map[*S].user.name != "") {
//user signal
p_signals->push_back(signal_map[*S].user);
@@ -1346,37 +1327,33 @@ void Object::get_signal_list(List<MethodInfo> *p_signals) const {
}
void Object::get_all_signal_connections(List<Connection> *p_connections) const {
-
const StringName *S = nullptr;
while ((S = signal_map.next(S))) {
-
const SignalData *s = &signal_map[*S];
for (int i = 0; i < s->slot_map.size(); i++) {
-
p_connections->push_back(s->slot_map.getv(i).conn);
}
}
}
void Object::get_signal_connection_list(const StringName &p_signal, List<Connection> *p_connections) const {
-
const SignalData *s = signal_map.getptr(p_signal);
- if (!s)
+ if (!s) {
return; //nothing
+ }
- for (int i = 0; i < s->slot_map.size(); i++)
+ for (int i = 0; i < s->slot_map.size(); i++) {
p_connections->push_back(s->slot_map.getv(i).conn);
+ }
}
int Object::get_persistent_signal_connection_count() const {
-
int count = 0;
const StringName *S = nullptr;
while ((S = signal_map.next(S))) {
-
const SignalData *s = &signal_map[*S];
for (int i = 0; i < s->slot_map.size(); i++) {
@@ -1390,18 +1367,16 @@ int Object::get_persistent_signal_connection_count() const {
}
void Object::get_signals_connected_to_this(List<Connection> *p_connections) const {
-
for (const List<Connection>::Element *E = connections.front(); E; E = E->next()) {
p_connections->push_back(E->get());
}
}
Error Object::connect_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method, const Vector<Variant> &p_binds, uint32_t p_flags) {
-
return connect(p_signal, Callable(p_to_object, p_to_method), p_binds, p_flags);
}
-Error Object::connect(const StringName &p_signal, const Callable &p_callable, const Vector<Variant> &p_binds, uint32_t p_flags) {
+Error Object::connect(const StringName &p_signal, const Callable &p_callable, const Vector<Variant> &p_binds, uint32_t p_flags) {
ERR_FAIL_COND_V(p_callable.is_null(), ERR_INVALID_PARAMETER);
Object *target_object = p_callable.get_object();
@@ -1412,7 +1387,6 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co
bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal);
//check in script
if (!signal_is_valid && !script.is_null()) {
-
if (Ref<Script>(script)->has_script_signal(p_signal)) {
signal_is_valid = true;
}
@@ -1462,21 +1436,21 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co
}
bool Object::is_connected_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method) const {
-
return is_connected(p_signal, Callable(p_to_object, p_to_method));
}
bool Object::is_connected(const StringName &p_signal, const Callable &p_callable) const {
-
ERR_FAIL_COND_V(p_callable.is_null(), false);
const SignalData *s = signal_map.getptr(p_signal);
if (!s) {
bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal);
- if (signal_is_valid)
+ if (signal_is_valid) {
return false;
+ }
- if (!script.is_null() && Ref<Script>(script)->has_script_signal(p_signal))
+ if (!script.is_null() && Ref<Script>(script)->has_script_signal(p_signal)) {
return false;
+ }
ERR_FAIL_V_MSG(false, "Nonexistent signal: " + p_signal + ".");
}
@@ -1489,7 +1463,6 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable
}
void Object::disconnect_compat(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method) {
-
_disconnect(p_signal, Callable(p_to_object, p_to_method));
}
@@ -1498,7 +1471,6 @@ void Object::disconnect(const StringName &p_signal, const Callable &p_callable)
}
void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force) {
-
ERR_FAIL_COND(p_callable.is_null());
Object *target_object = p_callable.get_object();
@@ -1528,65 +1500,60 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable,
}
void Object::_set_bind(const String &p_set, const Variant &p_value) {
-
set(p_set, p_value);
}
Variant Object::_get_bind(const String &p_name) const {
-
return get(p_name);
}
void Object::_set_indexed_bind(const NodePath &p_name, const Variant &p_value) {
-
set_indexed(p_name.get_as_property_path().get_subnames(), p_value);
}
Variant Object::_get_indexed_bind(const NodePath &p_name) const {
-
return get_indexed(p_name.get_as_property_path().get_subnames());
}
void Object::initialize_class() {
-
static bool initialized = false;
- if (initialized)
+ if (initialized) {
return;
+ }
ClassDB::_add_class<Object>();
_bind_methods();
initialized = true;
}
StringName Object::tr(const StringName &p_message) const {
-
- if (!_can_translate || !TranslationServer::get_singleton())
+ if (!_can_translate || !TranslationServer::get_singleton()) {
return p_message;
+ }
return TranslationServer::get_singleton()->translate(p_message);
}
void Object::_clear_internal_resource_paths(const Variant &p_var) {
-
switch (p_var.get_type()) {
-
case Variant::OBJECT: {
-
RES r = p_var;
- if (!r.is_valid())
+ if (!r.is_valid()) {
return;
+ }
- if (!r->get_path().begins_with("res://") || r->get_path().find("::") == -1)
+ if (!r->get_path().begins_with("res://") || r->get_path().find("::") == -1) {
return; //not an internal resource
+ }
Object *object = p_var;
- if (!object)
+ if (!object) {
return;
+ }
r->set_path("");
r->clear_internal_resource_paths();
} break;
case Variant::ARRAY: {
-
Array a = p_var;
for (int i = 0; i < a.size(); i++) {
_clear_internal_resource_paths(a[i]);
@@ -1594,13 +1561,11 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) {
} break;
case Variant::DICTIONARY: {
-
Dictionary d = p_var;
List<Variant> keys;
d.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
_clear_internal_resource_paths(E->get());
_clear_internal_resource_paths(d[E->get()]);
}
@@ -1612,35 +1577,31 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) {
#ifdef TOOLS_ENABLED
void Object::editor_set_section_unfold(const String &p_section, bool p_unfolded) {
-
set_edited(true);
- if (p_unfolded)
+ if (p_unfolded) {
editor_section_folding.insert(p_section);
- else
+ } else {
editor_section_folding.erase(p_section);
+ }
}
bool Object::editor_is_section_unfolded(const String &p_section) {
-
return editor_section_folding.has(p_section);
}
#endif
void Object::clear_internal_resource_paths() {
-
List<PropertyInfo> pinfo;
get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
-
_clear_internal_resource_paths(get(E->get().name));
}
}
void Object::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_class"), &Object::get_class);
ClassDB::bind_method(D_METHOD("is_class", "class"), &Object::is_class);
ClassDB::bind_method(D_METHOD("set", "property", "value"), &Object::_set_bind);
@@ -1745,7 +1706,6 @@ void Object::_bind_methods() {
}
void Object::call_deferred(const StringName &p_method, VARIANT_ARG_DECLARE) {
-
MessageQueue::get_singleton()->push_call(this, p_method, VARIANT_ARG_PASS);
}
@@ -1754,58 +1714,57 @@ void Object::set_deferred(const StringName &p_property, const Variant &p_value)
}
void Object::set_block_signals(bool p_block) {
-
_block_signals = p_block;
}
bool Object::is_blocking_signals() const {
-
return _block_signals;
}
void Object::get_translatable_strings(List<String> *p_strings) const {
-
List<PropertyInfo> plist;
get_property_list(&plist);
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
-
- if (!(E->get().usage & PROPERTY_USAGE_INTERNATIONALIZED))
+ if (!(E->get().usage & PROPERTY_USAGE_INTERNATIONALIZED)) {
continue;
+ }
String text = get(E->get().name);
- if (text == "")
+ if (text == "") {
continue;
+ }
p_strings->push_back(text);
}
}
Variant::Type Object::get_static_property_type(const StringName &p_property, bool *r_valid) const {
-
bool valid;
Variant::Type t = ClassDB::get_property_type(get_class_name(), p_property, &valid);
if (valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return t;
}
if (get_script_instance()) {
return get_script_instance()->get_property_type(p_property, r_valid);
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant::NIL;
}
Variant::Type Object::get_static_property_type_indexed(const Vector<StringName> &p_path, bool *r_valid) const {
-
if (p_path.size() == 0) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant::NIL;
}
@@ -1813,8 +1772,9 @@ Variant::Type Object::get_static_property_type_indexed(const Vector<StringName>
bool valid = false;
Variant::Type t = get_static_property_type(p_path[0], &valid);
if (!valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant::NIL;
}
@@ -1825,22 +1785,25 @@ Variant::Type Object::get_static_property_type_indexed(const Vector<StringName>
for (int i = 1; i < p_path.size(); i++) {
if (check.get_type() == Variant::OBJECT || check.get_type() == Variant::DICTIONARY || check.get_type() == Variant::ARRAY) {
// We cannot be sure about the type of properties this types can have
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant::NIL;
}
check = check.get_named(p_path[i], &valid);
if (!valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant::NIL;
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return check.get_type();
}
@@ -1851,18 +1814,15 @@ bool Object::is_queued_for_deletion() const {
#ifdef TOOLS_ENABLED
void Object::set_edited(bool p_edited) {
-
_edited = p_edited;
_edited_version++;
}
bool Object::is_edited() const {
-
return _edited;
}
uint32_t Object::get_edited_version() const {
-
return _edited_version;
}
#endif
@@ -1889,7 +1849,6 @@ void *Object::get_script_instance_binding(int p_script_language_index) {
}
bool Object::has_script_instance_binding(int p_script_language_index) {
-
return _script_instance_bindings[p_script_language_index] != nullptr;
}
@@ -1919,9 +1878,9 @@ Object::Object() {
}
Object::~Object() {
-
- if (script_instance)
+ if (script_instance) {
memdelete(script_instance);
+ }
script_instance = nullptr;
const StringName *S = nullptr;
@@ -1932,7 +1891,6 @@ Object::~Object() {
}
while ((S = signal_map.next(nullptr))) {
-
SignalData *s = &signal_map[*S];
//brute force disconnect for performance
@@ -1940,7 +1898,6 @@ Object::~Object() {
const VMap<Callable, SignalData::Slot>::Pair *slot_list = s->slot_map.get_array();
for (int i = 0; i < slot_count; i++) {
-
slot_list[i].value.conn.callable.get_object()->connections.erase(slot_list[i].value.cE);
}
@@ -1949,7 +1906,6 @@ Object::~Object() {
//signals from nodes that connect to this node
while (connections.size()) {
-
Connection c = connections.front()->get();
c.signal.get_object()->_disconnect(c.signal.get_name(), c.callable, true);
}
@@ -1968,17 +1924,14 @@ Object::~Object() {
}
bool predelete_handler(Object *p_object) {
-
return p_object->_predelete();
}
void postinitialize_handler(Object *p_object) {
-
p_object->_postinitialize();
}
void ObjectDB::debug_objects(DebugFunc p_func) {
-
spin_lock.lock();
for (uint32_t i = 0; i < slot_count; i++) {
uint32_t slot = object_slots[i].next_free;
@@ -1997,15 +1950,12 @@ ObjectDB::ObjectSlot *ObjectDB::object_slots = nullptr;
uint64_t ObjectDB::validator_counter = 0;
int ObjectDB::get_object_count() {
-
return slot_count;
}
ObjectID ObjectDB::add_instance(Object *p_object) {
-
spin_lock.lock();
if (unlikely(slot_count == slot_max)) {
-
CRASH_COND(slot_count == (1 << OBJECTDB_SLOT_MAX_COUNT_BITS));
uint32_t new_slot_max = slot_max > 0 ? slot_max * 2 : 1;
@@ -2081,12 +2031,10 @@ void ObjectDB::remove_instance(Object *p_object) {
}
void ObjectDB::setup() {
-
//nothing to do now
}
void ObjectDB::cleanup() {
-
if (slot_count > 0) {
spin_lock.lock();
@@ -2097,10 +2045,12 @@ void ObjectDB::cleanup() {
Object *obj = object_slots[slot].object;
String node_name;
- if (obj->is_class("Node"))
+ if (obj->is_class("Node")) {
node_name = " - Node name: " + String(obj->call("get_name"));
- if (obj->is_class("Resource"))
+ }
+ if (obj->is_class("Resource")) {
node_name = " - Resource name: " + String(obj->call("get_name")) + " Path: " + String(obj->call("get_path"));
+ }
uint64_t id = uint64_t(slot) | (uint64_t(object_slots[slot].validator) << OBJECTDB_VALIDATOR_BITS) | (object_slots[slot].is_reference ? OBJECTDB_REFERENCE_BIT : 0);
print_line("Leaked instance: " + String(obj->get_class()) + ":" + itos(id) + node_name);
diff --git a/core/object.h b/core/object.h
index 20defae095..95662f6208 100644
--- a/core/object.h
+++ b/core/object.h
@@ -138,7 +138,6 @@ enum PropertyUsageFlags {
#define ADD_SUBGROUP(m_name, m_prefix) ClassDB::add_property_subgroup(get_class_static(), m_name, m_prefix)
struct PropertyInfo {
-
Variant::Type type = Variant::NIL;
String name;
StringName class_name; //for classes
@@ -164,7 +163,6 @@ struct PropertyInfo {
hint(p_hint),
hint_string(p_hint_string),
usage(p_usage) {
-
if (hint == PROPERTY_HINT_RESOURCE_TYPE) {
class_name = hint_string;
} else {
@@ -193,7 +191,6 @@ struct PropertyInfo {
Array convert_property_list(const List<PropertyInfo> *p_list);
struct MethodInfo {
-
String name;
PropertyInfo return_val;
uint32_t flags; // NOLINT - prevent clang-tidy to assign method_bind.h constant here, it should stay in .cpp.
@@ -263,8 +260,9 @@ public:
return String(#m_class); \
} \
virtual const StringName *_get_class_namev() const { \
- if (!_class_name) \
+ if (!_class_name) { \
_class_name = get_class_static(); \
+ } \
return &_class_name; \
} \
static _FORCE_INLINE_ void *get_class_ptr_static() { \
@@ -284,8 +282,9 @@ public:
static String get_category_static() { \
String category = m_inherits::get_category_static(); \
if (_get_category != m_inherits::_get_category) { \
- if (category != "") \
+ if (category != "") { \
category += "/"; \
+ } \
category += _get_category(); \
} \
return category; \
@@ -297,7 +296,6 @@ public:
virtual bool is_class_ptr(void *p_ptr) const { return (p_ptr == get_class_ptr_static()) ? true : m_inherits::is_class_ptr(p_ptr); } \
\
static void get_valid_parents_static(List<String> *p_parents) { \
- \
if (m_class::_get_valid_parents_static != m_inherits::_get_valid_parents_static) { \
m_class::_get_valid_parents_static(p_parents); \
} \
@@ -313,12 +311,14 @@ protected:
public: \
static void initialize_class() { \
static bool initialized = false; \
- if (initialized) \
+ if (initialized) { \
return; \
+ } \
m_inherits::initialize_class(); \
ClassDB::_add_class<m_class>(); \
- if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) \
+ if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \
_bind_methods(); \
+ } \
initialized = true; \
} \
\
@@ -331,8 +331,9 @@ protected:
} \
virtual bool _getv(const StringName &p_name, Variant &r_ret) const { \
if (m_class::_get_get() != m_inherits::_get_get()) { \
- if (_get(p_name, r_ret)) \
+ if (_get(p_name, r_ret)) { \
return true; \
+ } \
} \
return m_inherits::_getv(p_name, r_ret); \
} \
@@ -340,8 +341,9 @@ protected:
return (bool (Object::*)(const StringName &, const Variant &)) & m_class::_set; \
} \
virtual bool _setv(const StringName &p_name, const Variant &p_property) { \
- if (m_inherits::_setv(p_name, p_property)) \
+ if (m_inherits::_setv(p_name, p_property)) { \
return true; \
+ } \
if (m_class::_get_set() != m_inherits::_get_set()) { \
return _set(p_name, p_property); \
} \
@@ -355,13 +357,15 @@ protected:
m_inherits::_get_property_listv(p_list, p_reversed); \
} \
p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); \
- if (!_is_gpl_reversed()) \
+ if (!_is_gpl_reversed()) { \
ClassDB::get_property_list(#m_class, p_list, true, this); \
+ } \
if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) { \
_get_property_list(p_list); \
} \
- if (_is_gpl_reversed()) \
+ if (_is_gpl_reversed()) { \
ClassDB::get_property_list(#m_class, p_list, true, this); \
+ } \
if (p_reversed) { \
m_inherits::_get_property_listv(p_list, p_reversed); \
} \
@@ -370,13 +374,15 @@ protected:
return (void (Object::*)(int)) & m_class::_notification; \
} \
virtual void _notificationv(int p_notification, bool p_reversed) { \
- if (!p_reversed) \
+ if (!p_reversed) { \
m_inherits::_notificationv(p_notification, p_reversed); \
+ } \
if (m_class::_get_notification() != m_inherits::_get_notification()) { \
_notification(p_notification); \
} \
- if (p_reversed) \
+ if (p_reversed) { \
m_inherits::_notificationv(p_notification, p_reversed); \
+ } \
} \
\
private:
@@ -406,7 +412,6 @@ public:
};
struct Connection {
-
::Signal signal;
Callable callable;
@@ -432,7 +437,6 @@ private:
friend void postinitialize_handler(Object *);
struct SignalData {
-
struct Slot {
int reference_count = 0;
Connection conn;
@@ -532,8 +536,9 @@ protected:
Variant _call_deferred_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
virtual const StringName *_get_class_namev() const {
- if (!_class_name)
+ if (!_class_name) {
_class_name = get_class_static();
+ }
return &_class_name;
}
@@ -556,8 +561,9 @@ public:
#ifdef TOOLS_ENABLED
_FORCE_INLINE_ void _change_notify(const char *p_property = "") {
_edited = true;
- for (Set<Object *>::Element *E = change_receptors.front(); E; E = E->next())
+ for (Set<Object *>::Element *E = change_receptors.front(); E; E = E->next()) {
((Object *)(E->get()))->_changed_callback(this, p_property);
+ }
}
#else
_FORCE_INLINE_ void _change_notify(const char *p_what = "") {}
@@ -580,12 +586,14 @@ public:
#ifndef NO_SAFE_CAST
return dynamic_cast<T *>(p_object);
#else
- if (!p_object)
+ if (!p_object) {
return nullptr;
- if (p_object->is_class_ptr(T::get_class_ptr_static()))
+ }
+ if (p_object->is_class_ptr(T::get_class_ptr_static())) {
return static_cast<T *>(p_object);
- else
+ } else {
return nullptr;
+ }
#endif
}
@@ -594,12 +602,14 @@ public:
#ifndef NO_SAFE_CAST
return dynamic_cast<const T *>(p_object);
#else
- if (!p_object)
+ if (!p_object) {
return nullptr;
- if (p_object->is_class_ptr(T::get_class_ptr_static()))
+ }
+ if (p_object->is_class_ptr(T::get_class_ptr_static())) {
return static_cast<const T *>(p_object);
- else
+ } else {
return nullptr;
+ }
#endif
}
@@ -744,7 +754,6 @@ bool predelete_handler(Object *p_object);
void postinitialize_handler(Object *p_object);
class ObjectDB {
-
//this needs to add up to 63, 1 bit is for reference
#define OBJECTDB_VALIDATOR_BITS 39
#define OBJECTDB_VALIDATOR_MASK ((uint64_t(1) << OBJECTDB_VALIDATOR_BITS) - 1)
@@ -779,7 +788,6 @@ public:
typedef void (*DebugFunc)(Object *p_obj);
_ALWAYS_INLINE_ static Object *get_instance(ObjectID p_instance_id) {
-
uint64_t id = p_instance_id;
uint32_t slot = id & OBJECTDB_SLOT_MAX_COUNT_MASK;
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 53b959a580..9f2672e038 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -36,9 +36,7 @@
#include "core/project_settings.h"
String DirAccess::_get_root_path() const {
-
switch (_access_type) {
-
case ACCESS_RESOURCES:
return ProjectSettings::get_singleton()->get_resource_path();
case ACCESS_USERDATA:
@@ -47,10 +45,9 @@ String DirAccess::_get_root_path() const {
return "";
}
}
-String DirAccess::_get_root_string() const {
+String DirAccess::_get_root_string() const {
switch (_access_type) {
-
case ACCESS_RESOURCES:
return "res://";
case ACCESS_USERDATA:
@@ -61,37 +58,34 @@ String DirAccess::_get_root_string() const {
}
int DirAccess::get_current_drive() {
-
String path = get_current_dir().to_lower();
for (int i = 0; i < get_drive_count(); i++) {
String d = get_drive(i).to_lower();
- if (path.begins_with(d))
+ if (path.begins_with(d)) {
return i;
+ }
}
return 0;
}
bool DirAccess::drives_are_shortcuts() {
-
return false;
}
static Error _erase_recursive(DirAccess *da) {
-
List<String> dirs;
List<String> files;
da->list_dir_begin();
String n = da->get_next();
while (n != String()) {
-
if (n != "." && n != "..") {
-
- if (da->current_is_dir())
+ if (da->current_is_dir()) {
dirs.push_back(n);
- else
+ } else {
files.push_back(n);
+ }
}
n = da->get_next();
@@ -100,10 +94,8 @@ static Error _erase_recursive(DirAccess *da) {
da->list_dir_end();
for (List<String>::Element *E = dirs.front(); E; E = E->next()) {
-
Error err = da->change_dir(E->get());
if (err == OK) {
-
err = _erase_recursive(da);
if (err) {
da->change_dir("..");
@@ -123,7 +115,6 @@ static Error _erase_recursive(DirAccess *da) {
}
for (List<String>::Element *E = files.front(); E; E = E->next()) {
-
Error err = da->remove(da->get_current_dir().plus_file(E->get()));
if (err) {
return err;
@@ -134,12 +125,10 @@ static Error _erase_recursive(DirAccess *da) {
}
Error DirAccess::erase_contents_recursive() {
-
return _erase_recursive(this);
}
Error DirAccess::make_dir_recursive(String p_dir) {
-
if (p_dir.length() < 1) {
return OK;
};
@@ -160,13 +149,13 @@ Error DirAccess::make_dir_recursive(String p_dir) {
String base;
- if (full_dir.begins_with("res://"))
+ if (full_dir.begins_with("res://")) {
base = "res://";
- else if (full_dir.begins_with("user://"))
+ } else if (full_dir.begins_with("user://")) {
base = "user://";
- else if (full_dir.begins_with("/"))
+ } else if (full_dir.begins_with("/")) {
base = "/";
- else if (full_dir.find(":/") != -1) {
+ } else if (full_dir.find(":/") != -1) {
base = full_dir.substr(0, full_dir.find(":/") + 2);
} else {
ERR_FAIL_V(ERR_INVALID_PARAMETER);
@@ -178,11 +167,9 @@ Error DirAccess::make_dir_recursive(String p_dir) {
String curpath = base;
for (int i = 0; i < subdirs.size(); i++) {
-
curpath = curpath.plus_file(subdirs[i]);
Error err = make_dir(curpath);
if (err != OK && err != ERR_ALREADY_EXISTS) {
-
ERR_FAIL_V(err);
}
}
@@ -191,17 +178,12 @@ Error DirAccess::make_dir_recursive(String p_dir) {
}
String DirAccess::fix_path(String p_path) const {
-
switch (_access_type) {
-
case ACCESS_RESOURCES: {
-
if (ProjectSettings::get_singleton()) {
if (p_path.begins_with("res://")) {
-
String resource_path = ProjectSettings::get_singleton()->get_resource_path();
if (resource_path != "") {
-
return p_path.replace_first("res:/", resource_path);
};
return p_path.replace_first("res://", "");
@@ -210,12 +192,9 @@ String DirAccess::fix_path(String p_path) const {
} break;
case ACCESS_USERDATA: {
-
if (p_path.begins_with("user://")) {
-
String data_dir = OS::get_singleton()->get_user_data_dir();
if (data_dir != "") {
-
return p_path.replace_first("user:/", data_dir);
};
return p_path.replace_first("user://", "");
@@ -223,7 +202,6 @@ String DirAccess::fix_path(String p_path) const {
} break;
case ACCESS_FILESYSTEM: {
-
return p_path;
} break;
case ACCESS_MAX:
@@ -236,16 +214,12 @@ String DirAccess::fix_path(String p_path) const {
DirAccess::CreateFunc DirAccess::create_func[ACCESS_MAX] = { nullptr, nullptr, nullptr };
DirAccess *DirAccess::create_for_path(const String &p_path) {
-
DirAccess *da = nullptr;
if (p_path.begins_with("res://")) {
-
da = create(ACCESS_RESOURCES);
} else if (p_path.begins_with("user://")) {
-
da = create(ACCESS_USERDATA);
} else {
-
da = create(ACCESS_FILESYSTEM);
}
@@ -253,13 +227,13 @@ DirAccess *DirAccess::create_for_path(const String &p_path) {
}
DirAccess *DirAccess::open(const String &p_path, Error *r_error) {
-
DirAccess *da = create_for_path(p_path);
ERR_FAIL_COND_V_MSG(!da, nullptr, "Cannot create DirAccess for path '" + p_path + "'.");
Error err = da->change_dir(p_path);
- if (r_error)
+ if (r_error) {
*r_error = err;
+ }
if (err != OK) {
memdelete(da);
return nullptr;
@@ -269,7 +243,6 @@ DirAccess *DirAccess::open(const String &p_path, Error *r_error) {
}
DirAccess *DirAccess::create(AccessType p_access) {
-
DirAccess *da = create_func[p_access] ? create_func[p_access]() : nullptr;
if (da) {
da->_access_type = p_access;
@@ -279,10 +252,10 @@ DirAccess *DirAccess::create(AccessType p_access) {
};
String DirAccess::get_full_path(const String &p_path, AccessType p_access) {
-
DirAccess *d = DirAccess::create(p_access);
- if (!d)
+ if (!d) {
return p_path;
+ }
d->change_dir(p_path);
String full = d->get_current_dir();
@@ -291,7 +264,6 @@ String DirAccess::get_full_path(const String &p_path, AccessType p_access) {
}
Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
-
//printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data());
Error err;
FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ, &err);
@@ -303,7 +275,6 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
FileAccess *fdst = FileAccess::open(p_to, FileAccess::WRITE, &err);
if (err) {
-
fsrc->close();
memdelete(fsrc);
ERR_PRINT("Failed to open " + p_to);
@@ -315,7 +286,6 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
fsrc->seek(0);
err = OK;
while (size--) {
-
if (fsrc->get_error() != OK) {
err = fsrc->get_error();
break;
@@ -332,8 +302,9 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
fdst->close();
err = FileAccess::set_unix_permissions(p_to, p_chmod_flags);
// If running on a platform with no chmod support (i.e., Windows), don't fail
- if (err == ERR_UNAVAILABLE)
+ if (err == ERR_UNAVAILABLE) {
err = OK;
+ }
}
memdelete(fsrc);
@@ -367,12 +338,10 @@ Error DirAccess::_copy_dir(DirAccess *p_target_da, String p_to, int p_chmod_flag
list_dir_begin();
String n = get_next();
while (n != String()) {
-
if (n != "." && n != "..") {
-
- if (current_is_dir())
+ if (current_is_dir()) {
dirs.push_back(n);
- else {
+ } else {
const String &rel_path = n;
if (!n.is_rel_path()) {
list_dir_end();
@@ -440,7 +409,6 @@ Error DirAccess::copy_dir(String p_from, String p_to, int p_chmod_flags) {
}
bool DirAccess::exists(String p_dir) {
-
DirAccess *da = DirAccess::create_for_path(p_dir);
bool valid = da->change_dir(p_dir) == OK;
memdelete(da);
diff --git a/core/os/dir_access.h b/core/os/dir_access.h
index cac0d0ec7c..6bce9a4c12 100644
--- a/core/os/dir_access.h
+++ b/core/os/dir_access.h
@@ -61,7 +61,6 @@ protected:
template <class T>
static DirAccess *_create_builtin() {
-
return memnew(T);
}
@@ -114,7 +113,6 @@ public:
template <class T>
static void make_default(AccessType p_access) {
-
create_func[p_access] = _create_builtin<T>;
}
@@ -125,9 +123,7 @@ public:
};
struct DirAccessRef {
-
_FORCE_INLINE_ DirAccess *operator->() {
-
return f;
}
@@ -137,8 +133,9 @@ struct DirAccessRef {
DirAccessRef(DirAccess *fa) { f = fa; }
~DirAccessRef() {
- if (f)
+ if (f) {
memdelete(f);
+ }
}
};
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index cb8705f706..f9ba8ff2d2 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -43,7 +43,6 @@ FileAccess::FileCloseFailNotify FileAccess::close_fail_notify = nullptr;
bool FileAccess::backup_save = false;
FileAccess *FileAccess::create(AccessType p_access) {
-
ERR_FAIL_INDEX_V(p_access, ACCESS_MAX, nullptr);
FileAccess *ret = create_func[p_access]();
@@ -52,34 +51,30 @@ FileAccess *FileAccess::create(AccessType p_access) {
}
bool FileAccess::exists(const String &p_name) {
-
- if (PackedData::get_singleton() && PackedData::get_singleton()->has_path(p_name))
+ if (PackedData::get_singleton() && PackedData::get_singleton()->has_path(p_name)) {
return true;
+ }
FileAccess *f = open(p_name, READ);
- if (!f)
+ if (!f) {
return false;
+ }
memdelete(f);
return true;
}
void FileAccess::_set_access_type(AccessType p_access) {
-
_access_type = p_access;
};
FileAccess *FileAccess::create_for_path(const String &p_path) {
-
FileAccess *ret = nullptr;
if (p_path.begins_with("res://")) {
-
ret = create(ACCESS_RESOURCES);
} else if (p_path.begins_with("user://")) {
-
ret = create(ACCESS_USERDATA);
} else {
-
ret = create(ACCESS_FILESYSTEM);
}
@@ -87,20 +82,19 @@ FileAccess *FileAccess::create_for_path(const String &p_path) {
}
Error FileAccess::reopen(const String &p_path, int p_mode_flags) {
-
return _open(p_path, p_mode_flags);
};
FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_error) {
-
//try packed data first
FileAccess *ret = nullptr;
if (!(p_mode_flags & WRITE) && PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled()) {
ret = PackedData::get_singleton()->try_open_path(p_path);
if (ret) {
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return ret;
}
}
@@ -108,10 +102,10 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er
ret = create_for_path(p_path);
Error err = ret->_open(p_path, p_mode_flags);
- if (r_error)
+ if (r_error) {
*r_error = err;
+ }
if (err != OK) {
-
memdelete(ret);
ret = nullptr;
}
@@ -120,7 +114,6 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er
}
FileAccess::CreateFunc FileAccess::get_create_func(AccessType p_access) {
-
return create_func[p_access];
};
@@ -130,15 +123,11 @@ String FileAccess::fix_path(const String &p_path) const {
String r_path = p_path.replace("\\", "/");
switch (_access_type) {
-
case ACCESS_RESOURCES: {
-
if (ProjectSettings::get_singleton()) {
if (r_path.begins_with("res://")) {
-
String resource_path = ProjectSettings::get_singleton()->get_resource_path();
if (resource_path != "") {
-
return r_path.replace("res:/", resource_path);
};
return r_path.replace("res://", "");
@@ -147,12 +136,9 @@ String FileAccess::fix_path(const String &p_path) const {
} break;
case ACCESS_USERDATA: {
-
if (r_path.begins_with("user://")) {
-
String data_dir = OS::get_singleton()->get_user_data_dir();
if (data_dir != "") {
-
return r_path.replace("user:/", data_dir);
};
return r_path.replace("user://", "");
@@ -160,7 +146,6 @@ String FileAccess::fix_path(const String &p_path) const {
} break;
case ACCESS_FILESYSTEM: {
-
return r_path;
} break;
case ACCESS_MAX:
@@ -173,7 +158,6 @@ String FileAccess::fix_path(const String &p_path) const {
/* these are all implemented for ease of porting, then can later be optimized */
uint16_t FileAccess::get_16() const {
-
uint16_t res;
uint8_t a, b;
@@ -181,7 +165,6 @@ uint16_t FileAccess::get_16() const {
b = get_8();
if (endian_swap) {
-
SWAP(a, b);
}
@@ -191,8 +174,8 @@ uint16_t FileAccess::get_16() const {
return res;
}
-uint32_t FileAccess::get_32() const {
+uint32_t FileAccess::get_32() const {
uint32_t res;
uint16_t a, b;
@@ -200,7 +183,6 @@ uint32_t FileAccess::get_32() const {
b = get_16();
if (endian_swap) {
-
SWAP(a, b);
}
@@ -210,8 +192,8 @@ uint32_t FileAccess::get_32() const {
return res;
}
-uint64_t FileAccess::get_64() const {
+uint64_t FileAccess::get_64() const {
uint64_t res;
uint32_t a, b;
@@ -219,7 +201,6 @@ uint64_t FileAccess::get_64() const {
b = get_32();
if (endian_swap) {
-
SWAP(a, b);
}
@@ -231,38 +212,35 @@ uint64_t FileAccess::get_64() const {
}
float FileAccess::get_float() const {
-
MarshallFloat m;
m.i = get_32();
return m.f;
};
real_t FileAccess::get_real() const {
-
- if (real_is_double)
+ if (real_is_double) {
return get_double();
- else
+ } else {
return get_float();
+ }
}
double FileAccess::get_double() const {
-
MarshallDouble m;
m.l = get_64();
return m.d;
};
String FileAccess::get_token() const {
-
CharString token;
CharType c = get_8();
while (!eof_reached()) {
-
if (c <= ' ') {
- if (token.length())
+ if (token.length()) {
break;
+ }
} else {
token += c;
}
@@ -281,16 +259,13 @@ class CharBuffer {
int written = 0;
bool grow() {
-
if (vector.resize(next_power_of_2(1 + written)) != OK) {
-
return false;
}
if (buffer == stack_buffer) { // first chunk?
for (int i = 0; i < written; i++) {
-
vector.write[i] = stack_buffer[i];
}
}
@@ -309,9 +284,7 @@ public:
}
_FORCE_INLINE_ void push_back(char c) {
-
if (written >= capacity) {
-
ERR_FAIL_COND(!grow());
}
@@ -319,24 +292,22 @@ public:
}
_FORCE_INLINE_ const char *get_data() const {
-
return buffer;
}
};
String FileAccess::get_line() const {
-
CharBuffer line;
CharType c = get_8();
while (!eof_reached()) {
-
if (c == '\n' || c == '\0') {
line.push_back(0);
return String::utf8(line.get_data());
- } else if (c != '\r')
+ } else if (c != '\r') {
line.push_back(c);
+ }
c = get_8();
}
@@ -345,21 +316,21 @@ String FileAccess::get_line() const {
}
Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
-
ERR_FAIL_COND_V(p_delim.length() != 1, Vector<String>());
String l;
int qc = 0;
do {
- if (eof_reached())
+ if (eof_reached()) {
break;
+ }
l += get_line() + "\n";
qc = 0;
for (int i = 0; i < l.length(); i++) {
-
- if (l[i] == '"')
+ if (l[i] == '"') {
qc++;
+ }
}
} while (qc % 2);
@@ -371,7 +342,6 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
bool in_quote = false;
String current;
for (int i = 0; i < l.length(); i++) {
-
CharType c = l[i];
CharType s[2] = { 0, 0 };
@@ -384,7 +354,6 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
current += s;
i++;
} else {
-
in_quote = !in_quote;
}
} else {
@@ -399,10 +368,10 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
}
int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const {
-
int i = 0;
- for (i = 0; i < p_length && !eof_reached(); i++)
+ for (i = 0; i < p_length && !eof_reached(); i++) {
p_dst[i] = get_8();
+ }
return i;
}
@@ -425,44 +394,40 @@ String FileAccess::get_as_utf8_string() const {
}
void FileAccess::store_16(uint16_t p_dest) {
-
uint8_t a, b;
a = p_dest & 0xFF;
b = p_dest >> 8;
if (endian_swap) {
-
SWAP(a, b);
}
store_8(a);
store_8(b);
}
-void FileAccess::store_32(uint32_t p_dest) {
+void FileAccess::store_32(uint32_t p_dest) {
uint16_t a, b;
a = p_dest & 0xFFFF;
b = p_dest >> 16;
if (endian_swap) {
-
SWAP(a, b);
}
store_16(a);
store_16(b);
}
-void FileAccess::store_64(uint64_t p_dest) {
+void FileAccess::store_64(uint64_t p_dest) {
uint32_t a, b;
a = p_dest & 0xFFFFFFFF;
b = p_dest >> 32;
if (endian_swap) {
-
SWAP(a, b);
}
@@ -471,31 +436,29 @@ void FileAccess::store_64(uint64_t p_dest) {
}
void FileAccess::store_real(real_t p_real) {
-
- if (sizeof(real_t) == 4)
+ if (sizeof(real_t) == 4) {
store_float(p_real);
- else
+ } else {
store_double(p_real);
+ }
}
void FileAccess::store_float(float p_dest) {
-
MarshallFloat m;
m.f = p_dest;
store_32(m.i);
};
void FileAccess::store_double(double p_dest) {
-
MarshallDouble m;
m.d = p_dest;
store_64(m.l);
};
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))
+ 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_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'.");
@@ -506,9 +469,9 @@ uint64_t FileAccess::get_modified_time(const String &p_file) {
}
uint32_t FileAccess::get_unix_permissions(const String &p_file) {
-
- if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(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_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'.");
@@ -519,7 +482,6 @@ uint32_t FileAccess::get_unix_permissions(const String &p_file) {
}
Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissions) {
-
FileAccess *fa = create_for_path(p_file);
ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create FileAccess for path '" + p_file + "'.");
@@ -529,23 +491,21 @@ Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissi
}
void FileAccess::store_string(const String &p_string) {
-
- if (p_string.length() == 0)
+ if (p_string.length() == 0) {
return;
+ }
CharString cs = p_string.utf8();
store_buffer((uint8_t *)&cs[0], cs.length());
}
void FileAccess::store_pascal_string(const String &p_string) {
-
CharString cs = p_string.utf8();
store_32(cs.length());
store_buffer((uint8_t *)&cs[0], cs.length());
};
String FileAccess::get_pascal_string() {
-
uint32_t sl = get_32();
CharString cs;
cs.resize(sl + 1);
@@ -559,13 +519,11 @@ String FileAccess::get_pascal_string() {
};
void FileAccess::store_line(const String &p_line) {
-
store_string(p_line);
store_8('\n');
}
void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_delim) {
-
ERR_FAIL_COND(p_delim.length() != 1);
String line = "";
@@ -587,13 +545,12 @@ void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_
}
void FileAccess::store_buffer(const uint8_t *p_src, int p_length) {
-
- for (int i = 0; i < p_length; i++)
+ for (int i = 0; i < p_length; i++) {
store_8(p_src[i]);
+ }
}
Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_error) {
-
FileAccess *f = FileAccess::open(p_path, READ, r_error);
if (!f) {
if (r_error) { // if error requested, do not throw error
@@ -609,7 +566,6 @@ Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_err
}
String FileAccess::get_file_as_string(const String &p_path, Error *r_error) {
-
Error err;
Vector<uint8_t> array = get_file_as_array(p_path, &err);
if (r_error) {
@@ -628,10 +584,10 @@ String FileAccess::get_file_as_string(const String &p_path, Error *r_error) {
}
String FileAccess::get_md5(const String &p_file) {
-
FileAccess *f = FileAccess::open(p_file, READ);
- if (!f)
+ if (!f) {
return String();
+ }
CryptoCore::MD5Context ctx;
ctx.start();
@@ -639,14 +595,13 @@ String FileAccess::get_md5(const String &p_file) {
unsigned char step[32768];
while (true) {
-
int br = f->get_buffer(step, 32768);
if (br > 0) {
-
ctx.update(step, br);
}
- if (br < 4096)
+ if (br < 4096) {
break;
+ }
}
unsigned char hash[16];
@@ -658,7 +613,6 @@ String FileAccess::get_md5(const String &p_file) {
}
String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
-
CryptoCore::MD5Context ctx;
ctx.start();
@@ -669,14 +623,13 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
unsigned char step[32768];
while (true) {
-
int br = f->get_buffer(step, 32768);
if (br > 0) {
-
ctx.update(step, br);
}
- if (br < 4096)
+ if (br < 4096) {
break;
+ }
}
memdelete(f);
}
@@ -688,10 +641,10 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
}
String FileAccess::get_sha256(const String &p_file) {
-
FileAccess *f = FileAccess::open(p_file, READ);
- if (!f)
+ if (!f) {
return String();
+ }
CryptoCore::SHA256Context ctx;
ctx.start();
@@ -699,14 +652,13 @@ String FileAccess::get_sha256(const String &p_file) {
unsigned char step[32768];
while (true) {
-
int br = f->get_buffer(step, 32768);
if (br > 0) {
-
ctx.update(step, br);
}
- if (br < 4096)
+ if (br < 4096) {
break;
+ }
}
unsigned char hash[32];
diff --git a/core/os/file_access.h b/core/os/file_access.h
index 0ee29abbc9..48b9ee4269 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -41,7 +41,6 @@
*/
class FileAccess {
-
public:
enum AccessType {
ACCESS_RESOURCES,
@@ -73,7 +72,6 @@ private:
static CreateFunc create_func[ACCESS_MAX]; /** default file access creation function for a platform */
template <class T>
static FileAccess *_create_builtin() {
-
return memnew(T);
}
@@ -172,7 +170,6 @@ public:
template <class T>
static void make_default(AccessType p_access) {
-
create_func[p_access] = _create_builtin<T>;
}
@@ -181,9 +178,7 @@ public:
};
struct FileAccessRef {
-
_FORCE_INLINE_ FileAccess *operator->() {
-
return f;
}
@@ -195,8 +190,9 @@ struct FileAccessRef {
FileAccessRef(FileAccess *fa) { f = fa; }
~FileAccessRef() {
- if (f)
+ if (f) {
memdelete(f);
+ }
}
};
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index c65d3fefc2..d088151a6d 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -293,9 +293,7 @@ static const _KeyCodeText _keycodes[] = {
};
bool keycode_has_unicode(uint32_t p_keycode) {
-
switch (p_keycode) {
-
case KEY_ESCAPE:
case KEY_TAB:
case KEY_BACKTAB:
@@ -394,7 +392,6 @@ bool keycode_has_unicode(uint32_t p_keycode) {
}
String keycode_get_string(uint32_t p_code) {
-
String codestr;
if (p_code & KEY_MASK_SHIFT) {
codestr += find_keycode_name(KEY_SHIFT);
@@ -418,9 +415,7 @@ String keycode_get_string(uint32_t p_code) {
const _KeyCodeText *kct = &_keycodes[0];
while (kct->text) {
-
if (kct->code == (int)p_code) {
-
codestr += kct->text;
return codestr;
}
@@ -433,11 +428,9 @@ String keycode_get_string(uint32_t p_code) {
}
int find_keycode(const String &p_code) {
-
const _KeyCodeText *kct = &_keycodes[0];
while (kct->text) {
-
if (p_code.nocasecmp_to(kct->text) == 0) {
return kct->code;
}
@@ -448,11 +441,9 @@ int find_keycode(const String &p_code) {
}
const char *find_keycode_name(int p_keycode) {
-
const _KeyCodeText *kct = &_keycodes[0];
while (kct->text) {
-
if (kct->code == p_keycode) {
return kct->text;
}
@@ -463,12 +454,10 @@ const char *find_keycode_name(int p_keycode) {
}
int keycode_get_count() {
-
const _KeyCodeText *kct = &_keycodes[0];
int count = 0;
while (kct->text) {
-
count++;
kct++;
}
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index b29e3f6142..dc68c2a9f9 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -33,7 +33,6 @@
#include "core/script_language.h"
void MainLoop::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("init"), &MainLoop::init);
ClassDB::bind_method(D_METHOD("iteration", "delta"), &MainLoop::iteration);
ClassDB::bind_method(D_METHOD("idle", "delta"), &MainLoop::idle);
@@ -56,35 +55,36 @@ void MainLoop::_bind_methods() {
};
void MainLoop::set_init_script(const Ref<Script> &p_init_script) {
-
init_script = p_init_script;
}
void MainLoop::init() {
-
- if (init_script.is_valid())
+ if (init_script.is_valid()) {
set_script(init_script);
+ }
- if (get_script_instance())
+ if (get_script_instance()) {
get_script_instance()->call("_initialize");
+ }
}
-bool MainLoop::iteration(float p_time) {
- if (get_script_instance())
+bool MainLoop::iteration(float p_time) {
+ if (get_script_instance()) {
return get_script_instance()->call("_iteration", p_time);
+ }
return false;
}
-bool MainLoop::idle(float p_time) {
- if (get_script_instance())
+bool MainLoop::idle(float p_time) {
+ if (get_script_instance()) {
return get_script_instance()->call("_idle", p_time);
+ }
return false;
}
void MainLoop::finish() {
-
if (get_script_instance()) {
get_script_instance()->call("_finalize");
set_script(Variant()); //clear script
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index c7cc8f01e0..90790a45a1 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -36,7 +36,6 @@
#include "core/script_language.h"
class MainLoop : public Object {
-
GDCLASS(MainLoop, Object);
OBJ_CATEGORY("Main Loop");
diff --git a/core/os/memory.cpp b/core/os/memory.cpp
index 0e48592cc1..8457c52092 100644
--- a/core/os/memory.cpp
+++ b/core/os/memory.cpp
@@ -38,28 +38,23 @@
#include <stdlib.h>
void *operator new(size_t p_size, const char *p_description) {
-
return Memory::alloc_static(p_size, false);
}
void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)) {
-
return p_allocfunc(p_size);
}
#ifdef _MSC_VER
void operator delete(void *p_mem, const char *p_description) {
-
CRASH_NOW_MSG("Call to placement delete should not happen.");
}
void operator delete(void *p_mem, void *(*p_allocfunc)(size_t p_size)) {
-
CRASH_NOW_MSG("Call to placement delete should not happen.");
}
void operator delete(void *p_mem, void *p_pointer, size_t check, const char *p_description) {
-
CRASH_NOW_MSG("Call to placement delete should not happen.");
}
#endif
@@ -72,7 +67,6 @@ uint64_t Memory::max_usage = 0;
uint64_t Memory::alloc_count = 0;
void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
-
#ifdef DEBUG_ENABLED
bool prepad = true;
#else
@@ -102,7 +96,6 @@ void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
}
void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
-
if (p_memory == nullptr) {
return alloc_static(p_bytes, p_pad_align);
}
@@ -144,7 +137,6 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
return mem + PAD_ALIGN;
}
} else {
-
mem = (uint8_t *)realloc(mem, p_bytes);
ERR_FAIL_COND_V(mem == nullptr && p_bytes > 0, nullptr);
@@ -154,7 +146,6 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
}
void Memory::free_static(void *p_ptr, bool p_pad_align) {
-
ERR_FAIL_COND(p_ptr == nullptr);
uint8_t *mem = (uint8_t *)p_ptr;
@@ -177,13 +168,11 @@ void Memory::free_static(void *p_ptr, bool p_pad_align) {
free(mem);
} else {
-
free(mem);
}
}
uint64_t Memory::get_mem_available() {
-
return -1; // 0xFFFF...
}
diff --git a/core/os/memory.h b/core/os/memory.h
index 03c6a80e89..46ffb4124b 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -41,7 +41,6 @@
#endif
class Memory {
-
Memory();
#ifdef DEBUG_ENABLED
static uint64_t mem_usage;
@@ -87,7 +86,6 @@ _ALWAYS_INLINE_ void postinitialize_handler(void *) {}
template <class T>
_ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
-
postinitialize_handler(p_obj);
return p_obj;
}
@@ -110,39 +108,42 @@ _ALWAYS_INLINE_ bool predelete_handler(void *) {
template <class T>
void memdelete(T *p_class) {
-
- if (!predelete_handler(p_class))
+ if (!predelete_handler(p_class)) {
return; // doesn't want to be deleted
- if (!__has_trivial_destructor(T))
+ }
+ if (!__has_trivial_destructor(T)) {
p_class->~T();
+ }
Memory::free_static(p_class, false);
}
template <class T, class A>
void memdelete_allocator(T *p_class) {
-
- if (!predelete_handler(p_class))
+ if (!predelete_handler(p_class)) {
return; // doesn't want to be deleted
- if (!__has_trivial_destructor(T))
+ }
+ if (!__has_trivial_destructor(T)) {
p_class->~T();
+ }
A::free(p_class);
}
#define memdelete_notnull(m_v) \
{ \
- if (m_v) \
+ if (m_v) { \
memdelete(m_v); \
+ } \
}
#define memnew_arr(m_class, m_count) memnew_arr_template<m_class>(m_count)
template <typename T>
T *memnew_arr_template(size_t p_elements, const char *p_descr = "") {
-
- if (p_elements == 0)
+ if (p_elements == 0) {
return nullptr;
+ }
/** overloading operator new[] cannot be done , because it may not return the real allocated address (it may pad the 'element count' before the actual array). Because of that, it must be done by hand. This is the
same strategy used by std::vector, and the Vector class, so it should be safe.*/
@@ -171,14 +172,12 @@ T *memnew_arr_template(size_t p_elements, const char *p_descr = "") {
template <typename T>
size_t memarr_len(const T *p_class) {
-
uint64_t *ptr = (uint64_t *)p_class;
return *(ptr - 1);
}
template <typename T>
void memdelete_arr(T *p_class) {
-
uint64_t *ptr = (uint64_t *)p_class;
if (!__has_trivial_destructor(T)) {
@@ -193,7 +192,6 @@ void memdelete_arr(T *p_class) {
}
struct _GlobalNil {
-
int color = 1;
_GlobalNil *right;
_GlobalNil *left;
@@ -203,7 +201,6 @@ struct _GlobalNil {
};
struct _GlobalNilClass {
-
static _GlobalNil _nil;
};
diff --git a/core/os/midi_driver.cpp b/core/os/midi_driver.cpp
index efd87d3ab6..e9919aeb86 100644
--- a/core/os/midi_driver.cpp
+++ b/core/os/midi_driver.cpp
@@ -36,17 +36,14 @@
uint8_t MIDIDriver::last_received_message = 0x00;
MIDIDriver *MIDIDriver::singleton = nullptr;
MIDIDriver *MIDIDriver::get_singleton() {
-
return singleton;
}
void MIDIDriver::set_singleton() {
-
singleton = this;
}
void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_t length) {
-
Ref<InputEventMIDI> event;
event.instance();
uint32_t param_position = 1;
@@ -122,12 +119,10 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_
}
PackedStringArray MIDIDriver::get_connected_inputs() {
-
PackedStringArray list;
return list;
}
MIDIDriver::MIDIDriver() {
-
set_singleton();
}
diff --git a/core/os/midi_driver.h b/core/os/midi_driver.h
index b7377a8a40..bc922e1fcf 100644
--- a/core/os/midi_driver.h
+++ b/core/os/midi_driver.h
@@ -39,7 +39,6 @@
*/
class MIDIDriver {
-
static MIDIDriver *singleton;
static uint8_t last_received_message;
diff --git a/core/os/mutex.h b/core/os/mutex.h
index 69a15f96de..d42cbed821 100644
--- a/core/os/mutex.h
+++ b/core/os/mutex.h
@@ -82,7 +82,6 @@ extern template class MutexLock<MutexImpl<std::mutex>>;
#else
class FakeMutex {
-
FakeMutex() {}
};
diff --git a/core/os/os.cpp b/core/os/os.cpp
index cdc9f1e0ff..da9dabd401 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -43,7 +43,6 @@
OS *OS::singleton = nullptr;
OS *OS::get_singleton() {
-
return singleton;
}
@@ -83,16 +82,18 @@ String OS::get_iso_date_time(bool local) const {
uint64_t OS::get_splash_tick_msec() const {
return _msec_splash;
}
-uint64_t OS::get_unix_time() const {
+uint64_t OS::get_unix_time() const {
return 0;
};
uint64_t OS::get_system_time_secs() const {
return 0;
}
+
uint64_t OS::get_system_time_msecs() const {
return 0;
}
+
void OS::debug_break(){
// something
@@ -116,12 +117,10 @@ void OS::add_logger(Logger *p_logger) {
}
void OS::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type) {
-
_logger->log_error(p_function, p_file, p_line, p_code, p_rationale, p_type);
}
void OS::print(const char *p_format, ...) {
-
va_list argp;
va_start(argp, p_format);
@@ -140,70 +139,60 @@ void OS::printerr(const char *p_format, ...) {
};
void OS::set_low_processor_usage_mode(bool p_enabled) {
-
low_processor_usage_mode = p_enabled;
}
bool OS::is_in_low_processor_usage_mode() const {
-
return low_processor_usage_mode;
}
void OS::set_low_processor_usage_mode_sleep_usec(int p_usec) {
-
low_processor_usage_mode_sleep_usec = p_usec;
}
int OS::get_low_processor_usage_mode_sleep_usec() const {
-
return low_processor_usage_mode_sleep_usec;
}
String OS::get_executable_path() const {
-
return _execpath;
}
int OS::get_process_id() const {
-
return -1;
};
void OS::vibrate_handheld(int p_duration_ms) {
-
WARN_PRINT("vibrate_handheld() only works with Android and iOS");
}
bool OS::is_stdout_verbose() const {
-
return _verbose_stdout;
}
void OS::dump_memory_to_file(const char *p_file) {
-
//Memory::dump_static_mem_to_file(p_file);
}
static FileAccess *_OSPRF = nullptr;
static void _OS_printres(Object *p_obj) {
-
Resource *res = Object::cast_to<Resource>(p_obj);
- if (!res)
+ if (!res) {
return;
+ }
String str = itos(res->get_instance_id()) + String(res->get_class()) + ":" + String(res->get_name()) + " - " + res->get_path();
- if (_OSPRF)
+ if (_OSPRF) {
_OSPRF->store_line(str);
- else
+ } else {
print_line(str);
+ }
}
void OS::print_all_resources(String p_to_file) {
-
ERR_FAIL_COND(p_to_file != "" && _OSPRF);
if (p_to_file != "") {
-
Error err;
_OSPRF = FileAccess::open(p_to_file, FileAccess::WRITE, &err);
if (err != OK) {
@@ -215,50 +204,43 @@ void OS::print_all_resources(String p_to_file) {
ObjectDB::debug_objects(_OS_printres);
if (p_to_file != "") {
-
- if (_OSPRF)
+ if (_OSPRF) {
memdelete(_OSPRF);
+ }
_OSPRF = nullptr;
}
}
void OS::print_resources_in_use(bool p_short) {
-
ResourceCache::dump(nullptr, p_short);
}
void OS::dump_resources_to_file(const char *p_file) {
-
ResourceCache::dump(p_file);
}
void OS::set_no_window_mode(bool p_enable) {
-
_no_window = p_enable;
}
bool OS::is_no_window_mode_enabled() const {
-
return _no_window;
}
int OS::get_exit_code() const {
-
return _exit_code;
}
-void OS::set_exit_code(int p_code) {
+void OS::set_exit_code(int p_code) {
_exit_code = p_code;
}
String OS::get_locale() const {
-
return "en";
}
// Helper function to ensure that a dir name/path will be valid on the OS
String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator) const {
-
Vector<String> invalid_chars = String(": * ? \" < > |").split(" ");
if (p_allow_dir_separator) {
// Dir separators are allowed, but disallow ".." to avoid going up the filesystem
@@ -278,50 +260,42 @@ String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separato
// Get properly capitalized engine name for system paths
String OS::get_godot_dir_name() const {
-
// Default to lowercase, so only override when different case is needed
return String(VERSION_SHORT_NAME).to_lower();
}
// OS equivalent of XDG_DATA_HOME
String OS::get_data_path() const {
-
return ".";
}
// OS equivalent of XDG_CONFIG_HOME
String OS::get_config_path() const {
-
return ".";
}
// OS equivalent of XDG_CACHE_HOME
String OS::get_cache_path() const {
-
return ".";
}
// Path to macOS .app bundle resources
String OS::get_bundle_resource_dir() const {
-
return ".";
};
// OS specific path for user://
String OS::get_user_data_dir() const {
-
return ".";
};
// Absolute path to res://
String OS::get_resource_dir() const {
-
return ProjectSettings::get_singleton()->get_resource_path();
}
// Access system-specific dirs like Documents, Downloads, etc.
String OS::get_system_dir(SystemDir p_dir) const {
-
return ".";
}
@@ -332,22 +306,18 @@ Error OS::shell_open(String p_uri) {
// implement these with the canvas?
uint64_t OS::get_static_memory_usage() const {
-
return Memory::get_mem_usage();
}
uint64_t OS::get_static_memory_peak_usage() const {
-
return Memory::get_mem_max_usage();
}
Error OS::set_cwd(const String &p_cwd) {
-
return ERR_CANT_OPEN;
}
uint64_t OS::get_free_static_memory() const {
-
return Memory::get_mem_available();
}
@@ -355,7 +325,6 @@ void OS::yield() {
}
void OS::ensure_user_data_dir() {
-
String dd = get_user_data_dir();
DirAccess *da = DirAccess::open(dd);
if (da) {
@@ -371,28 +340,23 @@ void OS::ensure_user_data_dir() {
}
String OS::get_model_name() const {
-
return "GenericDevice";
}
void OS::set_cmdline(const char *p_execpath, const List<String> &p_args) {
-
_execpath = p_execpath;
_cmdline = p_args;
};
String OS::get_unique_id() const {
-
ERR_FAIL_V("");
}
int OS::get_processor_count() const {
-
return 1;
}
bool OS::can_use_threads() const {
-
#ifdef NO_THREADS
return false;
#else
@@ -401,24 +365,25 @@ bool OS::can_use_threads() const {
}
void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) {
-
has_server_feature_callback = p_callback;
}
bool OS::has_feature(const String &p_feature) {
-
- if (p_feature == get_name())
+ if (p_feature == get_name()) {
return true;
+ }
#ifdef DEBUG_ENABLED
- if (p_feature == "debug")
+ if (p_feature == "debug") {
return true;
+ }
#else
if (p_feature == "release")
return true;
#endif
#ifdef TOOLS_ENABLED
- if (p_feature == "editor")
+ if (p_feature == "editor") {
return true;
+ }
#else
if (p_feature == "standalone")
return true;
@@ -458,15 +423,17 @@ bool OS::has_feature(const String &p_feature) {
}
#endif
- if (_check_internal_feature_support(p_feature))
+ if (_check_internal_feature_support(p_feature)) {
return true;
+ }
if (has_server_feature_callback && has_server_feature_callback(p_feature)) {
return true;
}
- if (ProjectSettings::get_singleton()->has_custom_feature(p_feature))
+ if (ProjectSettings::get_singleton()->has_custom_feature(p_feature)) {
return true;
+ }
return false;
}
@@ -485,24 +452,24 @@ List<String> OS::get_restart_on_exit_arguments() const {
}
PackedStringArray OS::get_connected_midi_inputs() {
-
- if (MIDIDriver::get_singleton())
+ if (MIDIDriver::get_singleton()) {
return MIDIDriver::get_singleton()->get_connected_inputs();
+ }
PackedStringArray list;
return list;
}
void OS::open_midi_inputs() {
-
- if (MIDIDriver::get_singleton())
+ if (MIDIDriver::get_singleton()) {
MIDIDriver::get_singleton()->open();
+ }
}
void OS::close_midi_inputs() {
-
- if (MIDIDriver::get_singleton())
+ if (MIDIDriver::get_singleton()) {
MIDIDriver::get_singleton()->close();
+ }
}
OS::OS() {
diff --git a/core/os/os.h b/core/os/os.h
index 4340823cf4..9296e17bb2 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -42,7 +42,6 @@
#include <stdarg.h>
class OS {
-
static OS *singleton;
String _execpath;
List<String> _cmdline;
@@ -185,7 +184,6 @@ public:
};
struct Date {
-
int year;
Month month;
int day;
@@ -194,7 +192,6 @@ public:
};
struct Time {
-
int hour;
int min;
int sec;
diff --git a/core/os/rw_lock.cpp b/core/os/rw_lock.cpp
index 81df7f7ea6..a668fe2b4c 100644
--- a/core/os/rw_lock.cpp
+++ b/core/os/rw_lock.cpp
@@ -37,7 +37,6 @@
RWLock *(*RWLock::create_func)() = nullptr;
RWLock *RWLock::create() {
-
ERR_FAIL_COND_V(!create_func, nullptr);
return create_func();
diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h
index 8dca8a230a..1035072cce 100644
--- a/core/os/rw_lock.h
+++ b/core/os/rw_lock.h
@@ -52,34 +52,36 @@ public:
};
class RWLockRead {
-
RWLock *lock;
public:
RWLockRead(const RWLock *p_lock) {
lock = const_cast<RWLock *>(p_lock);
- if (lock)
+ if (lock) {
lock->read_lock();
+ }
}
~RWLockRead() {
- if (lock)
+ if (lock) {
lock->read_unlock();
+ }
}
};
class RWLockWrite {
-
RWLock *lock;
public:
RWLockWrite(RWLock *p_lock) {
lock = p_lock;
- if (lock)
+ if (lock) {
lock->write_lock();
+ }
}
~RWLockWrite() {
- if (lock)
+ if (lock) {
lock->write_unlock();
+ }
}
};
diff --git a/core/os/semaphore.h b/core/os/semaphore.h
index 3d9d1ab984..077e04704b 100644
--- a/core/os/semaphore.h
+++ b/core/os/semaphore.h
@@ -54,8 +54,9 @@ public:
_ALWAYS_INLINE_ void wait() const {
std::unique_lock<decltype(mutex_)> lock(mutex_);
- while (!count_) // Handle spurious wake-ups.
+ while (!count_) { // Handle spurious wake-ups.
condition_.wait(lock);
+ }
--count_;
}
diff --git a/core/os/thread.cpp b/core/os/thread.cpp
index a8eb0b2a9f..70f960ed2a 100644
--- a/core/os/thread.cpp
+++ b/core/os/thread.cpp
@@ -38,31 +38,29 @@ Error (*Thread::set_name_func)(const String &) = nullptr;
Thread::ID Thread::_main_thread_id = 0;
Thread::ID Thread::get_caller_id() {
-
- if (get_thread_id_func)
+ if (get_thread_id_func) {
return get_thread_id_func();
+ }
return 0;
}
Thread *Thread::create(ThreadCreateCallback p_callback, void *p_user, const Settings &p_settings) {
-
if (create_func) {
-
return create_func(p_callback, p_user, p_settings);
}
return nullptr;
}
void Thread::wait_to_finish(Thread *p_thread) {
-
- if (wait_to_finish_func)
+ if (wait_to_finish_func) {
wait_to_finish_func(p_thread);
+ }
}
Error Thread::set_name(const String &p_name) {
-
- if (set_name_func)
+ if (set_name_func) {
return set_name_func(p_name);
+ }
return ERR_UNAVAILABLE;
};
diff --git a/core/os/thread.h b/core/os/thread.h
index 005217dca7..f761d4ca43 100644
--- a/core/os/thread.h
+++ b/core/os/thread.h
@@ -46,7 +46,6 @@ public:
};
struct Settings {
-
Priority priority;
Settings() { priority = PRIORITY_NORMAL; }
};
diff --git a/core/os/thread_dummy.h b/core/os/thread_dummy.h
index 066ee498ac..37d9ee0846 100644
--- a/core/os/thread_dummy.h
+++ b/core/os/thread_dummy.h
@@ -36,7 +36,6 @@
#include "core/os/thread.h"
class ThreadDummy : public Thread {
-
static Thread *create(ThreadCreateCallback p_callback, void *p_user, const Settings &p_settings = Settings());
public:
@@ -46,7 +45,6 @@ public:
};
class RWLockDummy : public RWLock {
-
static RWLock *create();
public:
diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h
index 00dc53286e..d27399e4cc 100644
--- a/core/os/threaded_array_processor.h
+++ b/core/os/threaded_array_processor.h
@@ -54,19 +54,18 @@ struct ThreadArrayProcessData {
template <class T>
void process_array_thread(void *ud) {
-
T &data = *(T *)ud;
while (true) {
uint32_t index = atomic_increment(&data.index);
- if (index >= data.elements)
+ if (index >= data.elements) {
break;
+ }
data.process(index);
}
}
template <class C, class M, class U>
void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
-
ThreadArrayProcessData<C, U> data;
data.method = p_method;
data.instance = p_instance;
@@ -93,7 +92,6 @@ void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_us
template <class C, class M, class U>
void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
-
ThreadArrayProcessData<C, U> data;
data.method = p_method;
data.instance = p_instance;
diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp
index 17b5905a93..b5aefd6f2c 100644
--- a/core/packed_data_container.cpp
+++ b/core/packed_data_container.cpp
@@ -34,51 +34,50 @@
#include "core/io/marshalls.h"
Variant PackedDataContainer::getvar(const Variant &p_key, bool *r_valid) const {
-
bool err = false;
Variant ret = _key_at_ofs(0, p_key, err);
- if (r_valid)
+ if (r_valid) {
*r_valid = !err;
+ }
return ret;
}
int PackedDataContainer::size() const {
-
return _size(0);
};
Variant PackedDataContainer::_iter_init_ofs(const Array &p_iter, uint32_t p_offset) {
-
Array ref = p_iter;
uint32_t size = _size(p_offset);
- if (size == 0 || ref.size() != 1)
+ if (size == 0 || ref.size() != 1) {
return false;
- else {
+ } else {
ref[0] = 0;
return true;
}
}
Variant PackedDataContainer::_iter_next_ofs(const Array &p_iter, uint32_t p_offset) {
-
Array ref = p_iter;
int size = _size(p_offset);
- if (ref.size() != 1)
+ if (ref.size() != 1) {
return false;
+ }
int pos = ref[0];
- if (pos < 0 || pos >= size)
+ if (pos < 0 || pos >= size) {
return false;
+ }
pos += 1;
ref[0] = pos;
return pos != size;
}
Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_offset) {
-
int size = _size(p_offset);
int pos = p_iter;
- if (pos < 0 || pos >= size)
+ if (pos < 0 || pos >= size) {
return Variant();
+ }
const uint8_t *rd = data.ptr();
const uint8_t *r = &rd[p_offset];
@@ -86,12 +85,10 @@ Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_off
bool err = false;
if (type == TYPE_ARRAY) {
-
uint32_t vpos = decode_uint32(rd + p_offset + 8 + pos * 4);
return _get_at_ofs(vpos, rd, err);
} else if (type == TYPE_DICT) {
-
uint32_t vpos = decode_uint32(rd + p_offset + 8 + pos * 12 + 4);
return _get_at_ofs(vpos, rd, err);
} else {
@@ -100,11 +97,9 @@ Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_off
}
Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, bool &err) const {
-
uint32_t type = decode_uint32(p_buf + p_ofs);
if (type == TYPE_ARRAY || type == TYPE_DICT) {
-
Ref<PackedDataContainerRef> pdcr = memnew(PackedDataContainerRef);
Ref<PackedDataContainer> pdc = Ref<PackedDataContainer>((PackedDataContainer *)this);
@@ -112,12 +107,10 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b
pdcr->offset = p_ofs;
return pdcr;
} else {
-
Variant v;
Error rerr = decode_variant(v, p_buf + p_ofs, datalen - p_ofs, nullptr, false);
if (rerr != OK) {
-
err = true;
ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant.");
}
@@ -126,7 +119,6 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b
}
uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
-
const uint8_t *rd = data.ptr();
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);
@@ -135,19 +127,16 @@ uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
};
int PackedDataContainer::_size(uint32_t p_ofs) const {
-
const uint8_t *rd = data.ptr();
ERR_FAIL_COND_V(!rd, 0);
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);
if (type == TYPE_ARRAY) {
-
uint32_t len = decode_uint32(r + 4);
return len;
} else if (type == TYPE_DICT) {
-
uint32_t len = decode_uint32(r + 4);
return len;
};
@@ -156,15 +145,12 @@ int PackedDataContainer::_size(uint32_t p_ofs) const {
};
Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, bool &err) const {
-
const uint8_t *rd = data.ptr();
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);
if (type == TYPE_ARRAY) {
-
if (p_key.is_num()) {
-
int idx = p_key;
int len = decode_uint32(r + 4);
if (idx < 0 || idx >= len) {
@@ -180,7 +166,6 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b
}
} else if (type == TYPE_DICT) {
-
uint32_t hash = p_key.hash();
uint32_t len = decode_uint32(r + 4);
@@ -189,16 +174,18 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b
uint32_t khash = decode_uint32(r + 8 + i * 12 + 0);
if (khash == hash) {
Variant key = _get_at_ofs(decode_uint32(r + 8 + i * 12 + 4), rd, err);
- if (err)
+ if (err) {
return Variant();
+ }
if (key == p_key) {
//key matches, return value
return _get_at_ofs(decode_uint32(r + 8 + i * 12 + 8), rd, err);
}
found = true;
} else {
- if (found)
+ if (found) {
break;
+ }
}
}
@@ -206,18 +193,14 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b
return Variant();
} else {
-
err = true;
return Variant();
}
}
uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpdata, Map<String, uint32_t> &string_cache) {
-
switch (p_data.get_type()) {
-
case Variant::STRING: {
-
String s = p_data;
if (string_cache.has(s)) {
return string_cache[s];
@@ -251,7 +234,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
case Variant::PACKED_COLOR_ARRAY:
case Variant::STRING_NAME:
case Variant::NODE_PATH: {
-
uint32_t pos = tmpdata.size();
int len;
encode_variant(p_data, nullptr, len, false);
@@ -263,11 +245,9 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
// misc types
case Variant::_RID:
case Variant::OBJECT: {
-
return _pack(Variant(), tmpdata, string_cache);
} break;
case Variant::DICTIONARY: {
-
Dictionary d = p_data;
//size is known, use sort
uint32_t pos = tmpdata.size();
@@ -281,7 +261,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
List<DictKey> sortk;
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
DictKey dk;
dk.hash = E->get().hash();
dk.key = E->get();
@@ -292,7 +271,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
int idx = 0;
for (List<DictKey>::Element *E = sortk.front(); E; E = E->next()) {
-
encode_uint32(E->get().hash, &tmpdata.write[pos + 8 + idx * 12 + 0]);
uint32_t ofs = _pack(E->get().key, tmpdata, string_cache);
encode_uint32(ofs, &tmpdata.write[pos + 8 + idx * 12 + 4]);
@@ -305,7 +283,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
} break;
case Variant::ARRAY: {
-
Array a = p_data;
//size is known, use sort
uint32_t pos = tmpdata.size();
@@ -315,7 +292,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
encode_uint32(len, &tmpdata.write[pos + 4]);
for (int i = 0; i < len; i++) {
-
uint32_t ofs = _pack(a[i], tmpdata, string_cache);
encode_uint32(ofs, &tmpdata.write[pos + 8 + i * 4]);
}
@@ -332,7 +308,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
}
Error PackedDataContainer::pack(const Variant &p_data) {
-
Vector<uint8_t> tmpdata;
Map<String, uint32_t> string_cache;
_pack(p_data, tmpdata, string_cache);
@@ -345,7 +320,6 @@ Error PackedDataContainer::pack(const Variant &p_data) {
}
void PackedDataContainer::_set_data(const Vector<uint8_t> &p_data) {
-
data = p_data;
datalen = data.size();
}
@@ -355,21 +329,18 @@ Vector<uint8_t> PackedDataContainer::_get_data() const {
}
Variant PackedDataContainer::_iter_init(const Array &p_iter) {
-
return _iter_init_ofs(p_iter, 0);
}
Variant PackedDataContainer::_iter_next(const Array &p_iter) {
-
return _iter_next_ofs(p_iter, 0);
}
-Variant PackedDataContainer::_iter_get(const Variant &p_iter) {
+Variant PackedDataContainer::_iter_get(const Variant &p_iter) {
return _iter_get_ofs(p_iter, 0);
}
void PackedDataContainer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_set_data"), &PackedDataContainer::_set_data);
ClassDB::bind_method(D_METHOD("_get_data"), &PackedDataContainer::_get_data);
ClassDB::bind_method(D_METHOD("_iter_init"), &PackedDataContainer::_iter_init);
@@ -384,26 +355,22 @@ void PackedDataContainer::_bind_methods() {
//////////////////
Variant PackedDataContainerRef::_iter_init(const Array &p_iter) {
-
return from->_iter_init_ofs(p_iter, offset);
}
Variant PackedDataContainerRef::_iter_next(const Array &p_iter) {
-
return from->_iter_next_ofs(p_iter, offset);
}
-Variant PackedDataContainerRef::_iter_get(const Variant &p_iter) {
+Variant PackedDataContainerRef::_iter_get(const Variant &p_iter) {
return from->_iter_get_ofs(p_iter, offset);
}
bool PackedDataContainerRef::_is_dictionary() const {
-
return from->_type_at_ofs(offset) == PackedDataContainer::TYPE_DICT;
};
void PackedDataContainerRef::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("size"), &PackedDataContainerRef::size);
ClassDB::bind_method(D_METHOD("_iter_init"), &PackedDataContainerRef::_iter_init);
ClassDB::bind_method(D_METHOD("_iter_get"), &PackedDataContainerRef::_iter_get);
@@ -412,15 +379,14 @@ void PackedDataContainerRef::_bind_methods() {
}
Variant PackedDataContainerRef::getvar(const Variant &p_key, bool *r_valid) const {
-
bool err = false;
Variant ret = from->_key_at_ofs(offset, p_key, err);
- if (r_valid)
+ if (r_valid) {
*r_valid = !err;
+ }
return ret;
}
int PackedDataContainerRef::size() const {
-
return from->_size(offset);
};
diff --git a/core/packed_data_container.h b/core/packed_data_container.h
index 00ec4248ee..b41e9aaefc 100644
--- a/core/packed_data_container.h
+++ b/core/packed_data_container.h
@@ -34,7 +34,6 @@
#include "core/resource.h"
class PackedDataContainer : public Resource {
-
GDCLASS(PackedDataContainer, Resource);
enum {
diff --git a/core/pair.h b/core/pair.h
index 26a317e9d4..89ea2b9fd9 100644
--- a/core/pair.h
+++ b/core/pair.h
@@ -33,7 +33,6 @@
template <class F, class S>
struct Pair {
-
F first;
S second;
@@ -60,7 +59,6 @@ bool operator!=(const Pair<F, S> &pair, const Pair<F, S> &other) {
template <class F, class S>
struct PairSort {
-
bool operator()(const Pair<F, S> &A, const Pair<F, S> &B) const {
return A.first < B.first;
}
diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp
index 8fd67a47d2..1dd215a787 100644
--- a/core/pool_allocator.cpp
+++ b/core/pool_allocator.cpp
@@ -53,12 +53,11 @@ void PoolAllocator::mt_unlock() const {
}
bool PoolAllocator::get_free_entry(EntryArrayPos *p_pos) {
-
- if (entry_count == entry_max)
+ if (entry_count == entry_max) {
return false;
+ }
for (int i = 0; i < entry_max; i++) {
-
if (entry_array[i].len == 0) {
*p_pos = i;
return true;
@@ -77,13 +76,11 @@ bool PoolAllocator::get_free_entry(EntryArrayPos *p_pos) {
* @return false if hole found, true if no hole found
*/
bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) {
-
/* position where previous entry ends. Defaults to zero (begin of pool) */
int prev_entry_end_pos = 0;
for (int i = 0; i < entry_count; i++) {
-
Entry &entry = entry_array[entry_indices[i]];
/* determine hole size to previous entry */
@@ -111,13 +108,12 @@ bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) {
}
void PoolAllocator::compact(int p_up_to) {
-
uint32_t prev_entry_end_pos = 0;
- if (p_up_to < 0)
+ if (p_up_to < 0) {
p_up_to = entry_count;
+ }
for (int i = 0; i < p_up_to; i++) {
-
Entry &entry = entry_array[entry_indices[i]];
/* determine hole size to previous entry */
@@ -126,7 +122,6 @@ void PoolAllocator::compact(int p_up_to) {
/* if we can compact, do it */
if (hole_size > 0 && !entry.lock) {
-
COMPACT_CHUNK(entry, prev_entry_end_pos);
}
@@ -136,11 +131,9 @@ void PoolAllocator::compact(int p_up_to) {
}
void PoolAllocator::compact_up(int p_from) {
-
uint32_t next_entry_end_pos = pool_size; // - static_area_size;
for (int i = entry_count - 1; i >= p_from; i--) {
-
Entry &entry = entry_array[entry_indices[i]];
/* determine hole size to nextious entry */
@@ -149,7 +142,6 @@ void PoolAllocator::compact_up(int p_from) {
/* if we can compact, do it */
if (hole_size > 0 && !entry.lock) {
-
COMPACT_CHUNK(entry, (next_entry_end_pos - aligned(entry.len)));
}
@@ -159,31 +151,29 @@ void PoolAllocator::compact_up(int p_from) {
}
bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry) {
-
EntryArrayPos entry_pos = entry_max;
for (int i = 0; i < entry_count; i++) {
-
if (&entry_array[entry_indices[i]] == p_entry) {
-
entry_pos = i;
break;
}
}
- if (entry_pos == entry_max)
+ if (entry_pos == entry_max) {
return false;
+ }
*p_map_pos = entry_pos;
return true;
}
PoolAllocator::ID PoolAllocator::alloc(int p_size) {
-
ERR_FAIL_COND_V(p_size < 1, POOL_ALLOCATOR_INVALID_ID);
#ifdef DEBUG_ENABLED
- if (p_size > free_mem)
+ if (p_size > free_mem) {
OS::get_singleton()->debug_break();
+ }
#endif
ERR_FAIL_COND_V(p_size > free_mem, POOL_ALLOCATOR_INVALID_ID);
@@ -221,7 +211,6 @@ PoolAllocator::ID PoolAllocator::alloc(int p_size) {
/* move all entry indices up, make room for this one */
for (int i = entry_count; i > new_entry_indices_pos; i--) {
-
entry_indices[i] = entry_indices[i - 1];
}
@@ -236,8 +225,9 @@ PoolAllocator::ID PoolAllocator::alloc(int p_size) {
entry.lock = 0;
entry.check = (check_count++) & CHECK_MASK;
free_mem -= size_to_alloc;
- if (free_mem < free_mem_peak)
+ if (free_mem < free_mem_peak) {
free_mem_peak = free_mem;
+ }
ID retval = (entry_indices[new_entry_indices_pos] << CHECK_BITS) | entry.check;
mt_unlock();
@@ -248,7 +238,6 @@ PoolAllocator::ID PoolAllocator::alloc(int p_size) {
}
PoolAllocator::Entry *PoolAllocator::get_entry(ID p_mem) {
-
unsigned int check = p_mem & CHECK_MASK;
int entry = p_mem >> CHECK_BITS;
ERR_FAIL_INDEX_V(entry, entry_max, nullptr);
@@ -259,7 +248,6 @@ PoolAllocator::Entry *PoolAllocator::get_entry(ID p_mem) {
}
const PoolAllocator::Entry *PoolAllocator::get_entry(ID p_mem) const {
-
unsigned int check = p_mem & CHECK_MASK;
int entry = p_mem >> CHECK_BITS;
ERR_FAIL_INDEX_V(entry, entry_max, nullptr);
@@ -270,7 +258,6 @@ const PoolAllocator::Entry *PoolAllocator::get_entry(ID p_mem) const {
}
void PoolAllocator::free(ID p_mem) {
-
mt_lock();
Entry *e = get_entry(p_mem);
if (!e) {
@@ -288,13 +275,11 @@ void PoolAllocator::free(ID p_mem) {
bool index_found = find_entry_index(&entry_indices_pos, e);
if (!index_found) {
-
mt_unlock();
ERR_FAIL_COND(!index_found);
}
for (int i = entry_indices_pos; i < (entry_count - 1); i++) {
-
entry_indices[i] = entry_indices[i + 1];
}
@@ -305,13 +290,11 @@ void PoolAllocator::free(ID p_mem) {
}
int PoolAllocator::get_size(ID p_mem) const {
-
int size;
mt_lock();
const Entry *e = get_entry(p_mem);
if (!e) {
-
mt_unlock();
ERR_PRINT("!e");
return 0;
@@ -325,7 +308,6 @@ int PoolAllocator::get_size(ID p_mem) const {
}
Error PoolAllocator::resize(ID p_mem, int p_new_size) {
-
mt_lock();
Entry *e = get_entry(p_mem);
@@ -342,12 +324,10 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) {
uint32_t alloc_size = aligned(p_new_size);
if ((uint32_t)aligned(e->len) == alloc_size) {
-
e->len = p_new_size;
mt_unlock();
return OK;
} else if (e->len > (uint32_t)p_new_size) {
-
free_mem += aligned(e->len);
free_mem -= alloc_size;
e->len = p_new_size;
@@ -368,7 +348,6 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) {
bool index_found = find_entry_index(&entry_indices_pos, e);
if (!index_found) {
-
mt_unlock();
ERR_FAIL_COND_V(!index_found, ERR_BUG);
}
@@ -398,8 +377,9 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) {
e->len = p_new_size;
free_mem -= alloc_size;
mt_unlock();
- if (free_mem < free_mem_peak)
+ if (free_mem < free_mem_peak) {
free_mem_peak = free_mem;
+ }
return OK;
}
@@ -413,8 +393,9 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) {
e->len = p_new_size;
free_mem -= alloc_size;
mt_unlock();
- if (free_mem < free_mem_peak)
+ if (free_mem < free_mem_peak) {
free_mem_peak = free_mem;
+ }
return OK;
}
@@ -423,13 +404,12 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) {
}
Error PoolAllocator::lock(ID p_mem) {
-
- if (!needs_locking)
+ if (!needs_locking) {
return OK;
+ }
mt_lock();
Entry *e = get_entry(p_mem);
if (!e) {
-
mt_unlock();
ERR_PRINT("!e");
return ERR_INVALID_PARAMETER;
@@ -440,14 +420,13 @@ Error PoolAllocator::lock(ID p_mem) {
}
bool PoolAllocator::is_locked(ID p_mem) const {
-
- if (!needs_locking)
+ if (!needs_locking) {
return false;
+ }
mt_lock();
const Entry *e = ((PoolAllocator *)(this))->get_entry(p_mem);
if (!e) {
-
mt_unlock();
ERR_PRINT("!e");
return false;
@@ -458,9 +437,7 @@ bool PoolAllocator::is_locked(ID p_mem) const {
}
const void *PoolAllocator::get(ID p_mem) const {
-
if (!needs_locking) {
-
const Entry *e = get_entry(p_mem);
ERR_FAIL_COND_V(!e, nullptr);
return &pool[e->pos];
@@ -470,19 +447,16 @@ const void *PoolAllocator::get(ID p_mem) const {
const Entry *e = get_entry(p_mem);
if (!e) {
-
mt_unlock();
ERR_FAIL_COND_V(!e, nullptr);
}
if (e->lock == 0) {
-
mt_unlock();
ERR_PRINT("e->lock == 0");
return nullptr;
}
if ((int)e->pos >= pool_size) {
-
mt_unlock();
ERR_PRINT("e->pos<0 || e->pos>=pool_size");
return nullptr;
@@ -495,9 +469,7 @@ const void *PoolAllocator::get(ID p_mem) const {
}
void *PoolAllocator::get(ID p_mem) {
-
if (!needs_locking) {
-
Entry *e = get_entry(p_mem);
ERR_FAIL_COND_V(!e, nullptr);
return &pool[e->pos];
@@ -507,12 +479,10 @@ void *PoolAllocator::get(ID p_mem) {
Entry *e = get_entry(p_mem);
if (!e) {
-
mt_unlock();
ERR_FAIL_COND_V(!e, nullptr);
}
if (e->lock == 0) {
-
//assert(0);
mt_unlock();
ERR_PRINT("e->lock == 0");
@@ -520,7 +490,6 @@ void *PoolAllocator::get(ID p_mem) {
}
if ((int)e->pos >= pool_size) {
-
mt_unlock();
ERR_PRINT("e->pos<0 || e->pos>=pool_size");
return nullptr;
@@ -531,10 +500,11 @@ void *PoolAllocator::get(ID p_mem) {
return ptr;
}
-void PoolAllocator::unlock(ID p_mem) {
- if (!needs_locking)
+void PoolAllocator::unlock(ID p_mem) {
+ if (!needs_locking) {
return;
+ }
mt_lock();
Entry *e = get_entry(p_mem);
if (!e) {
@@ -551,22 +521,18 @@ void PoolAllocator::unlock(ID p_mem) {
}
int PoolAllocator::get_used_mem() const {
-
return pool_size - free_mem;
}
int PoolAllocator::get_free_peak() {
-
return free_mem_peak;
}
int PoolAllocator::get_free_mem() {
-
return free_mem;
}
void PoolAllocator::create_pool(void *p_mem, int p_size, int p_max_entries) {
-
pool = (uint8_t *)p_mem;
pool_size = p_size;
@@ -582,7 +548,6 @@ void PoolAllocator::create_pool(void *p_mem, int p_size, int p_max_entries) {
}
PoolAllocator::PoolAllocator(int p_size, bool p_needs_locking, int p_max_entries) {
-
mem_ptr = memalloc(p_size);
ERR_FAIL_COND(!mem_ptr);
align = 1;
@@ -591,9 +556,7 @@ PoolAllocator::PoolAllocator(int p_size, bool p_needs_locking, int p_max_entries
}
PoolAllocator::PoolAllocator(void *p_mem, int p_size, int p_align, bool p_needs_locking, int p_max_entries) {
-
if (p_align > 1) {
-
uint8_t *mem8 = (uint8_t *)p_mem;
uint64_t ofs = (uint64_t)mem8;
if (ofs % p_align) {
@@ -611,22 +574,22 @@ PoolAllocator::PoolAllocator(void *p_mem, int p_size, int p_align, bool p_needs_
}
PoolAllocator::PoolAllocator(int p_align, int p_size, bool p_needs_locking, int p_max_entries) {
-
ERR_FAIL_COND(p_align < 1);
mem_ptr = Memory::alloc_static(p_size + p_align, true);
uint8_t *mem8 = (uint8_t *)mem_ptr;
uint64_t ofs = (uint64_t)mem8;
- if (ofs % p_align)
+ if (ofs % p_align) {
mem8 += p_align - (ofs % p_align);
+ }
create_pool(mem8, p_size, p_max_entries);
needs_locking = p_needs_locking;
align = p_align;
}
PoolAllocator::~PoolAllocator() {
-
- if (mem_ptr)
+ if (mem_ptr) {
memfree(mem_ptr);
+ }
memdelete_arr(entry_array);
memdelete_arr(entry_indices);
diff --git a/core/pool_allocator.h b/core/pool_allocator.h
index 1cc21afb21..7d77af6266 100644
--- a/core/pool_allocator.h
+++ b/core/pool_allocator.h
@@ -60,7 +60,6 @@ private:
};
struct Entry {
-
unsigned int pos = 0;
unsigned int len = 0;
unsigned int lock = 0;
@@ -99,10 +98,10 @@ private:
return p_entry.pos + aligned(p_entry.len);
}
inline int aligned(int p_size) const {
-
int rem = p_size % align;
- if (rem)
+ if (rem) {
p_size += align - rem;
+ }
return p_size;
}
diff --git a/core/print_string.cpp b/core/print_string.cpp
index 8eb1d9e86a..54de229471 100644
--- a/core/print_string.cpp
+++ b/core/print_string.cpp
@@ -39,7 +39,6 @@ bool _print_line_enabled = true;
bool _print_error_enabled = true;
void add_print_handler(PrintHandlerList *p_handler) {
-
_global_lock();
p_handler->next = print_handler_list;
print_handler_list = p_handler;
@@ -47,20 +46,18 @@ void add_print_handler(PrintHandlerList *p_handler) {
}
void remove_print_handler(PrintHandlerList *p_handler) {
-
_global_lock();
PrintHandlerList *prev = nullptr;
PrintHandlerList *l = print_handler_list;
while (l) {
-
if (l == p_handler) {
-
- if (prev)
+ if (prev) {
prev->next = l->next;
- else
+ } else {
print_handler_list = l->next;
+ }
break;
}
prev = l;
@@ -73,16 +70,15 @@ void remove_print_handler(PrintHandlerList *p_handler) {
}
void print_line(String p_string) {
-
- if (!_print_line_enabled)
+ if (!_print_line_enabled) {
return;
+ }
OS::get_singleton()->print("%s\n", p_string.utf8().get_data());
_global_lock();
PrintHandlerList *l = print_handler_list;
while (l) {
-
l->printfunc(l->userdata, p_string, false);
l = l->next;
}
@@ -91,16 +87,15 @@ void print_line(String p_string) {
}
void print_error(String p_string) {
-
- if (!_print_error_enabled)
+ if (!_print_error_enabled) {
return;
+ }
OS::get_singleton()->printerr("%s\n", p_string.utf8().get_data());
_global_lock();
PrintHandlerList *l = print_handler_list;
while (l) {
-
l->printfunc(l->userdata, p_string, true);
l = l->next;
}
@@ -109,7 +104,6 @@ void print_error(String p_string) {
}
void print_verbose(String p_string) {
-
if (OS::get_singleton()->is_stdout_verbose()) {
print_line(p_string);
}
diff --git a/core/print_string.h b/core/print_string.h
index 3e9125bddc..4d03f4a6de 100644
--- a/core/print_string.h
+++ b/core/print_string.h
@@ -38,7 +38,6 @@ extern void (*_print_func)(String);
typedef void (*PrintHandlerFunc)(void *, const String &p_string, bool p_error);
struct PrintHandlerList {
-
PrintHandlerFunc printfunc = nullptr;
void *userdata = nullptr;
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index e141e54e61..cedc7f731f 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -46,30 +46,28 @@
ProjectSettings *ProjectSettings::singleton = nullptr;
ProjectSettings *ProjectSettings::get_singleton() {
-
return singleton;
}
String ProjectSettings::get_resource_path() const {
-
return resource_path;
};
String ProjectSettings::localize_path(const String &p_path) const {
-
- if (resource_path == "")
+ if (resource_path == "") {
return p_path; //not initialized yet
+ }
if (p_path.begins_with("res://") || p_path.begins_with("user://") ||
- (p_path.is_abs_path() && !p_path.begins_with(resource_path)))
+ (p_path.is_abs_path() && !p_path.begins_with(resource_path))) {
return p_path.simplify_path();
+ }
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
String path = p_path.replace("\\", "/").simplify_path();
if (dir->change_dir(path) == OK) {
-
String cwd = dir->get_current_dir();
cwd = cwd.replace("\\", "/");
@@ -93,7 +91,6 @@ String ProjectSettings::localize_path(const String &p_path) const {
return cwd.replace_first(res_path, "res://");
} else {
-
memdelete(dir);
int sep = path.find_last("/");
@@ -116,30 +113,24 @@ String ProjectSettings::localize_path(const String &p_path) const {
}
void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) {
-
ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
props[p_name].initial = p_value;
}
-void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) {
+void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) {
ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
props[p_name].restart_if_changed = p_restart;
}
String ProjectSettings::globalize_path(const String &p_path) const {
-
if (p_path.begins_with("res://")) {
-
if (resource_path != "") {
-
return p_path.replace("res:/", resource_path);
};
return p_path.replace("res://", "");
} else if (p_path.begins_with("user://")) {
-
String data_dir = OS::get_singleton()->get_user_data_dir();
if (data_dir != "") {
-
return p_path.replace("user:/", data_dir);
};
return p_path.replace("user://", "");
@@ -149,17 +140,14 @@ String ProjectSettings::globalize_path(const String &p_path) const {
}
bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
-
_THREAD_SAFE_METHOD_
- if (p_value.get_type() == Variant::NIL)
+ if (p_value.get_type() == Variant::NIL) {
props.erase(p_name);
- else {
-
+ } else {
if (p_name == CoreStringNames::get_singleton()->_custom_features) {
Vector<String> custom_feature_array = String(p_value).split(",");
for (int i = 0; i < custom_feature_array.size(); i++) {
-
custom_features.insert(custom_feature_array[i]);
}
return true;
@@ -180,15 +168,15 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
}
if (override_valid) {
-
feature_overrides[s[0]] = p_name;
}
}
}
if (props.has(p_name)) {
- if (!props[p_name].overridden)
+ if (!props[p_name].overridden) {
props[p_name].variant = p_value;
+ }
} else {
props[p_name] = VariantContainer(p_value, last_order++);
@@ -197,8 +185,8 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
return true;
}
-bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
+bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
_THREAD_SAFE_METHOD_
StringName name = p_name;
@@ -214,7 +202,6 @@ bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
}
struct _VCSort {
-
String name;
Variant::Type type;
int order;
@@ -224,26 +211,26 @@ struct _VCSort {
};
void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
-
_THREAD_SAFE_METHOD_
Set<_VCSort> vclist;
for (Map<StringName, VariantContainer>::Element *E = props.front(); E; E = E->next()) {
-
const VariantContainer *v = &E->get();
- if (v->hide_from_editor)
+ if (v->hide_from_editor) {
continue;
+ }
_VCSort vc;
vc.name = E->key();
vc.order = v->order;
vc.type = v->variant.get_type();
- if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload"))
+ if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload")) {
vc.flags = PROPERTY_USAGE_STORAGE;
- else
+ } else {
vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
+ }
if (v->restart_if_changed) {
vc.flags |= PROPERTY_USAGE_RESTART_IF_CHANGED;
@@ -252,31 +239,33 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
}
for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
-
String prop_info_name = E->get().name;
int dot = prop_info_name.find(".");
- if (dot != -1)
+ if (dot != -1) {
prop_info_name = prop_info_name.substr(0, dot);
+ }
if (custom_prop_info.has(prop_info_name)) {
PropertyInfo pi = custom_prop_info[prop_info_name];
pi.name = E->get().name;
pi.usage = E->get().flags;
p_list->push_back(pi);
- } else
+ } else {
p_list->push_back(PropertyInfo(E->get().type, E->get().name, PROPERTY_HINT_NONE, "", E->get().flags));
+ }
}
}
bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files) {
-
- if (PackedData::get_singleton()->is_disabled())
+ if (PackedData::get_singleton()->is_disabled()) {
return false;
+ }
bool ok = PackedData::get_singleton()->add_pack(p_pack, p_replace_files) == OK;
- if (!ok)
+ if (!ok) {
return false;
+ }
//if data.pck is found, all directory access will be from here
DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
@@ -286,7 +275,6 @@ bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_f
}
void ProjectSettings::_convert_to_last_version(int p_from_version) {
-
if (p_from_version <= 3) {
// Converts the actions from array to dictionary (array of events to dictionary with deadzone + events)
for (Map<StringName, ProjectSettings::VariantContainer>::Element *E = props.front(); E; E = E->next()) {
@@ -322,11 +310,9 @@ void ProjectSettings::_convert_to_last_version(int p_from_version) {
* If nothing was found, error out.
*/
Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, bool p_upwards) {
-
// If looking for files in a network client, use it directly
if (FileAccessNetworkClient::get_singleton()) {
-
Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
if (err == OK) {
// Optional, we don't mind if it fails
@@ -338,7 +324,6 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
// Attempt with a user-defined main pack first
if (p_main_pack != "") {
-
bool ok = _load_resource_pack(p_main_pack);
ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, "Cannot open resource pack '" + p_main_pack + "'.");
@@ -443,8 +428,9 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
if (p_upwards) {
// Try to load settings ascending through parent directories
d->change_dir("..");
- if (d->get_current_dir() == current_dir)
+ if (d->get_current_dir() == current_dir) {
break; // not doing anything useful
+ }
current_dir = d->get_current_dir();
} else {
break;
@@ -455,11 +441,13 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
resource_path = resource_path.replace("\\", "/"); // windows path to unix path just in case
memdelete(d);
- if (!found)
+ if (!found) {
return err;
+ }
- if (resource_path.length() && resource_path[resource_path.length() - 1] == '/')
+ if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') {
resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end
+ }
return OK;
}
@@ -477,19 +465,16 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
}
bool ProjectSettings::has_setting(String p_var) const {
-
_THREAD_SAFE_METHOD_
return props.has(p_var);
}
void ProjectSettings::set_registering_order(bool p_enable) {
-
registering_order = p_enable;
}
Error ProjectSettings::_load_settings_binary(const String &p_path) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
if (err != OK) {
@@ -499,7 +484,6 @@ Error ProjectSettings::_load_settings_binary(const String &p_path) {
uint8_t hdr[4];
f->get_buffer(hdr, 4);
if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') {
-
memdelete(f);
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
}
@@ -507,7 +491,6 @@ Error ProjectSettings::_load_settings_binary(const String &p_path) {
uint32_t count = f->get_32();
for (uint32_t i = 0; i < count; i++) {
-
uint32_t slen = f->get_32();
CharString cs;
cs.resize(slen + 1);
@@ -532,7 +515,6 @@ Error ProjectSettings::_load_settings_binary(const String &p_path) {
}
Error ProjectSettings::_load_settings_text(const String &p_path) {
-
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
@@ -555,7 +537,6 @@ Error ProjectSettings::_load_settings_text(const String &p_path) {
int config_version = 0;
while (true) {
-
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();
@@ -594,7 +575,6 @@ Error ProjectSettings::_load_settings_text(const String &p_path) {
}
Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) {
-
// Attempt first to load the text-based project.godot file
Error err_text = _load_settings_text(p_text_path);
if (err_text == OK) {
@@ -611,19 +591,16 @@ Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path,
}
int ProjectSettings::get_order(const String &p_name) const {
-
ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, "Request for nonexistent project setting: " + p_name + ".");
return props[p_name].order;
}
void ProjectSettings::set_order(const String &p_name, int p_order) {
-
ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
props[p_name].order = p_order;
}
void ProjectSettings::set_builtin_order(const String &p_name) {
-
ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) {
props[p_name].order = last_builtin_order++;
@@ -631,18 +608,15 @@ void ProjectSettings::set_builtin_order(const String &p_name) {
}
void ProjectSettings::clear(const String &p_name) {
-
ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
props.erase(p_name);
}
Error ProjectSettings::save() {
-
return save_custom(get_resource_path().plus_file("project.godot"));
}
Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
-
Error err;
FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.binary at " + p_file + ".");
@@ -653,9 +627,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
int count = 0;
for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
-
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
-
count++;
}
}
@@ -690,33 +662,35 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
}
for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
-
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
-
String key = F->get();
- if (E->key() != "")
+ if (E->key() != "") {
key = E->key() + "/" + key;
+ }
Variant value;
- if (p_custom.has(key))
+ if (p_custom.has(key)) {
value = p_custom[key];
- else
+ } else {
value = get(key);
+ }
file->store_32(key.length());
file->store_string(key);
int len;
err = encode_variant(value, nullptr, len, true);
- if (err != OK)
+ if (err != OK) {
memdelete(file);
+ }
ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
Vector<uint8_t> buff;
buff.resize(len);
err = encode_variant(value, buff.ptrw(), len, true);
- if (err != OK)
+ if (err != OK) {
memdelete(file);
+ }
ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
file->store_32(len);
file->store_buffer(buff.ptr(), buff.size());
@@ -730,7 +704,6 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
}
Error ProjectSettings::_save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
-
Error err;
FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
@@ -746,27 +719,30 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin
file->store_line("");
file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
- if (p_custom_features != String())
+ if (p_custom_features != String()) {
file->store_string("custom_features=\"" + p_custom_features + "\"\n");
+ }
file->store_string("\n");
for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
-
- if (E != props.front())
+ if (E != props.front()) {
file->store_string("\n");
+ }
- if (E->key() != "")
+ if (E->key() != "") {
file->store_string("[" + E->key() + "]\n\n");
+ }
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
-
String key = F->get();
- if (E->key() != "")
+ if (E->key() != "") {
key = E->key() + "/" + key;
+ }
Variant value;
- if (p_custom.has(key))
+ if (p_custom.has(key)) {
value = p_custom[key];
- else
+ } else {
value = get(key);
+ }
String vstr;
VariantWriter::write_to_string(value, vstr);
@@ -786,36 +762,36 @@ Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other par
};
Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
-
ERR_FAIL_COND_V_MSG(p_path == "", ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
Set<_VCSort> vclist;
if (p_merge_with_current) {
for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
-
const VariantContainer *v = &G->get();
- if (v->hide_from_editor)
+ if (v->hide_from_editor) {
continue;
+ }
- if (p_custom.has(G->key()))
+ if (p_custom.has(G->key())) {
continue;
+ }
_VCSort vc;
vc.name = G->key(); //*k;
vc.order = v->order;
vc.type = v->variant.get_type();
vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
- if (v->variant == v->initial)
+ if (v->variant == v->initial) {
continue;
+ }
vclist.insert(vc);
}
}
for (const Map<String, Variant>::Element *E = p_custom.front(); E; E = E->next()) {
-
// Lookup global prop to store in the same order
Map<StringName, VariantContainer>::Element *global_prop = props.find(E->key());
@@ -830,16 +806,14 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
Map<String, List<String>> props;
for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
-
String category = E->get().name;
String name = E->get().name;
int div = category.find("/");
- if (div < 0)
+ if (div < 0) {
category = "";
- else {
-
+ } else {
category = category.substr(0, div);
name = name.substr(div + 1, name.size());
}
@@ -849,25 +823,24 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
String custom_features;
for (int i = 0; i < p_custom_features.size(); i++) {
- if (i > 0)
+ if (i > 0) {
custom_features += ",";
+ }
String f = p_custom_features[i].strip_edges().replace("\"", "");
custom_features += f;
}
- if (p_path.ends_with(".godot"))
+ if (p_path.ends_with(".godot")) {
return _save_settings_text(p_path, props, p_custom, custom_features);
- else if (p_path.ends_with(".binary"))
+ } else if (p_path.ends_with(".binary")) {
return _save_settings_binary(p_path, props, p_custom, custom_features);
- else {
-
+ } else {
ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + ".");
}
}
Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed) {
-
Variant ret;
if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
ProjectSettings::get_singleton()->set(p_var, p_default);
@@ -881,15 +854,14 @@ Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restar
}
Vector<String> ProjectSettings::get_optimizer_presets() const {
-
List<PropertyInfo> pi;
ProjectSettings::get_singleton()->get_property_list(&pi);
Vector<String> names;
for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
-
- if (!E->get().name.begins_with("optimizer_presets/"))
+ if (!E->get().name.begins_with("optimizer_presets/")) {
continue;
+ }
names.push_back(E->get().name.get_slicec('/', 1));
}
@@ -899,7 +871,6 @@ Vector<String> ProjectSettings::get_optimizer_presets() const {
}
void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
-
ERR_FAIL_COND(!p_info.has("name"));
ERR_FAIL_COND(!p_info.has("type"));
@@ -909,16 +880,17 @@ void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
pinfo.type = Variant::Type(p_info["type"].operator int());
ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
- if (p_info.has("hint"))
+ if (p_info.has("hint")) {
pinfo.hint = PropertyHint(p_info["hint"].operator int());
- if (p_info.has("hint_string"))
+ }
+ if (p_info.has("hint_string")) {
pinfo.hint_string = p_info["hint_string"];
+ }
set_custom_property_info(pinfo.name, pinfo);
}
void ProjectSettings::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) {
-
ERR_FAIL_COND(!props.has(p_prop));
custom_prop_info[p_prop] = p_info;
custom_prop_info[p_prop].name = p_prop;
@@ -929,27 +901,25 @@ const Map<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info()
}
void ProjectSettings::set_disable_feature_overrides(bool p_disable) {
-
disable_feature_overrides = p_disable;
}
bool ProjectSettings::is_using_datapack() const {
-
return using_datapack;
}
bool ProjectSettings::property_can_revert(const String &p_name) {
-
- if (!props.has(p_name))
+ if (!props.has(p_name)) {
return false;
+ }
return props[p_name].initial != props[p_name].variant;
}
Variant ProjectSettings::property_get_revert(const String &p_name) {
-
- if (!props.has(p_name))
+ if (!props.has(p_name)) {
return Variant();
+ }
return props[p_name].initial;
}
@@ -967,7 +937,6 @@ bool ProjectSettings::has_custom_feature(const String &p_feature) const {
}
void ProjectSettings::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
ClassDB::bind_method(D_METHOD("get_setting", "name"), &ProjectSettings::get_setting);
@@ -987,7 +956,6 @@ void ProjectSettings::_bind_methods() {
}
ProjectSettings::ProjectSettings() {
-
singleton = this;
Array events;
@@ -1010,8 +978,9 @@ ProjectSettings::ProjectSettings() {
PackedStringArray extensions = PackedStringArray();
extensions.push_back("gd");
- if (Engine::get_singleton()->has_singleton("GodotSharp"))
+ if (Engine::get_singleton()->has_singleton("GodotSharp")) {
extensions.push_back("cs");
+ }
extensions.push_back("shader");
GLOBAL_DEF("editor/search_in_file_extensions", extensions);
@@ -1202,6 +1171,5 @@ ProjectSettings::ProjectSettings() {
}
ProjectSettings::~ProjectSettings() {
-
singleton = nullptr;
}
diff --git a/core/project_settings.h b/core/project_settings.h
index 87f2a8273f..3ed80738a1 100644
--- a/core/project_settings.h
+++ b/core/project_settings.h
@@ -36,7 +36,6 @@
#include "core/set.h"
class ProjectSettings : public Object {
-
GDCLASS(ProjectSettings, Object);
_THREAD_SAFE_CLASS_
diff --git a/core/reference.cpp b/core/reference.cpp
index 57b72dcaad..d1dba0d9bf 100644
--- a/core/reference.cpp
+++ b/core/reference.cpp
@@ -33,22 +33,18 @@
#include "core/script_language.h"
bool Reference::init_ref() {
-
if (reference()) {
-
if (!is_referenced() && refcount_init.unref()) {
unreference(); // first referencing is already 1, so compensate for the ref above
}
return true;
} else {
-
return false;
}
}
void Reference::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("init_ref"), &Reference::init_ref);
ClassDB::bind_method(D_METHOD("reference"), &Reference::reference);
ClassDB::bind_method(D_METHOD("unreference"), &Reference::unreference);
@@ -59,7 +55,6 @@ int Reference::reference_get_count() const {
}
bool Reference::reference() {
-
uint32_t rc_val = refcount.refval();
bool success = rc_val != 0;
@@ -80,7 +75,6 @@ bool Reference::reference() {
}
bool Reference::unreference() {
-
uint32_t rc_val = refcount.unrefval();
bool die = rc_val == 0;
@@ -104,22 +98,21 @@ bool Reference::unreference() {
Reference::Reference() :
Object(true) {
-
refcount.init();
refcount_init.init();
}
Variant WeakRef::get_ref() const {
-
- if (ref.is_null())
+ if (ref.is_null()) {
return Variant();
+ }
Object *obj = ObjectDB::get_instance(ref);
- if (!obj)
+ if (!obj) {
return Variant();
+ }
Reference *r = cast_to<Reference>(obj);
if (r) {
-
return REF(r);
}
@@ -131,11 +124,9 @@ void WeakRef::set_obj(Object *p_object) {
}
void WeakRef::set_ref(const REF &p_ref) {
-
ref = p_ref.is_valid() ? p_ref->get_instance_id() : ObjectID();
}
void WeakRef::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_ref"), &WeakRef::get_ref);
}
diff --git a/core/reference.h b/core/reference.h
index 5190f6ab11..f5794b0b67 100644
--- a/core/reference.h
+++ b/core/reference.h
@@ -36,7 +36,6 @@
#include "core/safe_refcount.h"
class Reference : public Object {
-
GDCLASS(Reference, Object);
SafeRefCount refcount;
SafeRefCount refcount_init;
@@ -57,27 +56,27 @@ public:
template <class T>
class Ref {
-
T *reference = nullptr;
void ref(const Ref &p_from) {
-
- if (p_from.reference == reference)
+ if (p_from.reference == reference) {
return;
+ }
unref();
reference = p_from.reference;
- if (reference)
+ if (reference) {
reference->reference();
+ }
}
void ref_pointer(T *p_ref) {
-
ERR_FAIL_COND(!p_ref);
- if (p_ref->init_ref())
+ if (p_ref->init_ref()) {
reference = p_ref;
+ }
}
//virtual Reference * get_reference() const { return reference; }
@@ -90,60 +89,48 @@ public:
}
_FORCE_INLINE_ bool operator<(const Ref<T> &p_r) const {
-
return reference < p_r.reference;
}
_FORCE_INLINE_ bool operator==(const Ref<T> &p_r) const {
-
return reference == p_r.reference;
}
_FORCE_INLINE_ bool operator!=(const Ref<T> &p_r) const {
-
return reference != p_r.reference;
}
_FORCE_INLINE_ T *operator->() {
-
return reference;
}
_FORCE_INLINE_ T *operator*() {
-
return reference;
}
_FORCE_INLINE_ const T *operator->() const {
-
return reference;
}
_FORCE_INLINE_ const T *ptr() const {
-
return reference;
}
_FORCE_INLINE_ T *ptr() {
-
return reference;
}
_FORCE_INLINE_ const T *operator*() const {
-
return reference;
}
operator Variant() const {
-
return Variant(reference);
}
void operator=(const Ref &p_from) {
-
ref(p_from);
}
template <class T_Other>
void operator=(const Ref<T_Other> &p_from) {
-
Reference *refb = const_cast<Reference *>(static_cast<const Reference *>(p_from.ptr()));
if (!refb) {
unref();
@@ -156,7 +143,6 @@ public:
}
void operator=(const Variant &p_variant) {
-
Object *object = p_variant.get_validated_object();
if (object == reference) {
@@ -206,8 +192,9 @@ public:
}
Ref(T *p_reference) {
- if (p_reference)
+ if (p_reference) {
ref_pointer(p_reference);
+ }
}
Ref(const Variant &p_variant) {
@@ -232,7 +219,6 @@ public:
// mutexes will avoid more crashes?
if (reference && reference->unreference()) {
-
memdelete(reference);
}
reference = nullptr;
@@ -252,7 +238,6 @@ public:
typedef Ref<Reference> REF;
class WeakRef : public Reference {
-
GDCLASS(WeakRef, Reference);
ObjectID ref;
@@ -272,23 +257,18 @@ public:
template <class T>
struct PtrToArg<Ref<T>> {
-
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
-
return Ref<T>(const_cast<T *>(reinterpret_cast<const T *>(p_ptr)));
}
_FORCE_INLINE_ static void encode(Ref<T> p_val, const void *p_ptr) {
-
*(Ref<Reference> *)p_ptr = p_val;
}
};
template <class T>
struct PtrToArg<const Ref<T> &> {
-
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
-
return Ref<T>((T *)p_ptr);
}
};
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index f24397be5b..3870141ecf 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -97,7 +97,6 @@ extern void register_variant_methods();
extern void unregister_variant_methods();
void register_core_types() {
-
//consistency check
static_assert(sizeof(Callable) <= 16);
@@ -237,7 +236,6 @@ void register_core_settings() {
}
void register_core_singletons() {
-
ClassDB::register_class<ProjectSettings>();
ClassDB::register_virtual_class<IP>();
ClassDB::register_class<_Geometry>();
@@ -269,7 +267,6 @@ void register_core_singletons() {
}
void unregister_core_types() {
-
memdelete(_resource_loader);
memdelete(_resource_saver);
memdelete(_os);
@@ -300,8 +297,9 @@ void unregister_core_types() {
ResourceLoader::remove_resource_format_loader(resource_format_loader_crypto);
resource_format_loader_crypto.unref();
- if (ip)
+ if (ip) {
memdelete(ip);
+ }
ResourceLoader::finalize();
diff --git a/core/resource.cpp b/core/resource.cpp
index f8948e9a59..0af8c9c2b3 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -39,7 +39,6 @@
#include <stdio.h>
void Resource::emit_changed() {
-
emit_signal(CoreStringNames::get_singleton()->changed);
}
@@ -47,12 +46,11 @@ void Resource::_resource_path_changed() {
}
void Resource::set_path(const String &p_path, bool p_take_over) {
-
- if (path_cache == p_path)
+ if (path_cache == p_path) {
return;
+ }
if (path_cache != "") {
-
ResourceCache::lock->write_lock();
ResourceCache::resources.erase(path_cache);
ResourceCache::lock->write_unlock();
@@ -66,7 +64,6 @@ void Resource::set_path(const String &p_path, bool p_take_over) {
if (has_path) {
if (p_take_over) {
-
ResourceCache::lock->write_lock();
Resource **res = ResourceCache::resources.getptr(p_path);
if (res) {
@@ -84,7 +81,6 @@ void Resource::set_path(const String &p_path, bool p_take_over) {
path_cache = p_path;
if (path_cache != "") {
-
ResourceCache::lock->write_lock();
ResourceCache::resources[path_cache] = this;
ResourceCache::lock->write_unlock();
@@ -95,62 +91,58 @@ void Resource::set_path(const String &p_path, bool p_take_over) {
}
String Resource::get_path() const {
-
return path_cache;
}
void Resource::set_subindex(int p_sub_index) {
-
subindex = p_sub_index;
}
int Resource::get_subindex() const {
-
return subindex;
}
void Resource::set_name(const String &p_name) {
-
name = p_name;
_change_notify("resource_name");
}
-String Resource::get_name() const {
+String Resource::get_name() const {
return name;
}
bool Resource::editor_can_reload_from_file() {
-
return true; //by default yes
}
void Resource::reload_from_file() {
-
String path = get_path();
- if (!path.is_resource_file())
+ if (!path.is_resource_file()) {
return;
+ }
Ref<Resource> s = ResourceLoader::load(ResourceLoader::path_remap(path), get_class(), true);
- if (!s.is_valid())
+ if (!s.is_valid()) {
return;
+ }
List<PropertyInfo> pi;
s->get_property_list(&pi);
for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
-
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
- if (E->get().name == "resource_path")
+ }
+ if (E->get().name == "resource_path") {
continue; //do not change path
+ }
set(E->get().name, s->get(E->get().name));
}
}
Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource>> &remap_cache) {
-
List<PropertyInfo> plist;
get_property_list(&plist);
@@ -160,20 +152,17 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res
r->local_scene = p_for_scene;
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
-
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
Variant p = get(E->get().name);
if (p.get_type() == Variant::OBJECT) {
-
RES sr = p;
if (sr.is_valid()) {
-
if (sr->is_local_to_scene()) {
if (remap_cache.has(sr)) {
p = remap_cache[sr];
} else {
-
RES dupe = sr->duplicate_for_local_scene(p_for_scene, remap_cache);
p = dupe;
remap_cache[sr] = dupe;
@@ -191,22 +180,19 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res
}
void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource>> &remap_cache) {
-
List<PropertyInfo> plist;
get_property_list(&plist);
local_scene = p_for_scene;
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
-
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
Variant p = get(E->get().name);
if (p.get_type() == Variant::OBJECT) {
-
RES sr = p;
if (sr.is_valid()) {
-
if (sr->is_local_to_scene()) {
if (!remap_cache.has(sr)) {
sr->configure_for_local_scene(p_for_scene, remap_cache);
@@ -219,7 +205,6 @@ void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, R
}
Ref<Resource> Resource::duplicate(bool p_subresources) const {
-
List<PropertyInfo> plist;
get_property_list(&plist);
@@ -227,21 +212,19 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
ERR_FAIL_COND_V(!r, Ref<Resource>());
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
-
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
Variant p = get(E->get().name);
if ((p.get_type() == Variant::DICTIONARY || p.get_type() == Variant::ARRAY)) {
r->set(E->get().name, p.duplicate(p_subresources));
} else if (p.get_type() == Variant::OBJECT && (p_subresources || (E->get().usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE))) {
-
RES sr = p;
if (sr.is_valid()) {
r->set(E->get().name, sr->duplicate(p_subresources));
}
} else {
-
r->set(E->get().name, p);
}
}
@@ -250,34 +233,27 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
}
void Resource::_set_path(const String &p_path) {
-
set_path(p_path, false);
}
void Resource::_take_over_path(const String &p_path) {
-
set_path(p_path, true);
}
RID Resource::get_rid() const {
-
return RID();
}
void Resource::register_owner(Object *p_owner) {
-
owners.insert(p_owner->get_instance_id());
}
void Resource::unregister_owner(Object *p_owner) {
-
owners.erase(p_owner->get_instance_id());
}
void Resource::notify_change_to_owners() {
-
for (Set<ObjectID>::Element *E = owners.front(); E; E = E->next()) {
-
Object *obj = ObjectDB::get_instance(E->get());
ERR_CONTINUE_MSG(!obj, "Object was deleted, while still owning a resource."); //wtf
//TODO store string
@@ -288,14 +264,12 @@ void Resource::notify_change_to_owners() {
#ifdef TOOLS_ENABLED
uint32_t Resource::hash_edited_version() const {
-
uint32_t hash = hash_djb2_one_32(get_edited_version());
List<PropertyInfo> plist;
get_property_list(&plist);
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
-
if (E->get().usage & PROPERTY_USAGE_STORAGE && E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE) {
RES res = get(E->get().name);
if (res.is_valid()) {
@@ -310,19 +284,17 @@ uint32_t Resource::hash_edited_version() const {
#endif
void Resource::set_local_to_scene(bool p_enable) {
-
local_to_scene = p_enable;
}
bool Resource::is_local_to_scene() const {
-
return local_to_scene;
}
Node *Resource::get_local_scene() const {
-
- if (local_scene)
+ if (local_scene) {
return local_scene;
+ }
if (_get_local_scene_func) {
return _get_local_scene_func();
@@ -332,17 +304,17 @@ Node *Resource::get_local_scene() const {
}
void Resource::setup_local_to_scene() {
-
- if (get_script_instance())
+ if (get_script_instance()) {
get_script_instance()->call("_setup_local_to_scene");
+ }
}
Node *(*Resource::_get_local_scene_func)() = nullptr;
void Resource::set_as_translation_remapped(bool p_remapped) {
-
- if (remapped_list.in_list() == p_remapped)
+ if (remapped_list.in_list() == p_remapped) {
return;
+ }
if (ResourceCache::lock) {
ResourceCache::lock->write_lock();
@@ -360,7 +332,6 @@ void Resource::set_as_translation_remapped(bool p_remapped) {
}
bool Resource::is_translation_remapped() const {
-
return remapped_list.in_list();
}
@@ -406,7 +377,6 @@ int Resource::get_id_for_path(const String &p_path) const {
#endif
void Resource::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_path", "path"), &Resource::_set_path);
ClassDB::bind_method(D_METHOD("take_over_path", "path"), &Resource::_take_over_path);
ClassDB::bind_method(D_METHOD("get_path"), &Resource::get_path);
@@ -432,7 +402,6 @@ Resource::Resource() :
remapped_list(this) {}
Resource::~Resource() {
-
if (path_cache != "") {
ResourceCache::lock->write_lock();
ResourceCache::resources.erase(path_cache);
@@ -454,7 +423,6 @@ RWLock *ResourceCache::path_cache_lock = nullptr;
#endif
void ResourceCache::setup() {
-
lock = RWLock::create();
#ifdef TOOLS_ENABLED
path_cache_lock = RWLock::create();
@@ -462,8 +430,9 @@ void ResourceCache::setup() {
}
void ResourceCache::clear() {
- if (resources.size())
+ if (resources.size()) {
ERR_PRINT("Resources Still in use at Exit!");
+ }
resources.clear();
memdelete(lock);
@@ -473,7 +442,6 @@ void ResourceCache::clear() {
}
void ResourceCache::reload_externals() {
-
/*
const String *K=nullptr;
while ((K=resources.next(K))) {
@@ -483,15 +451,14 @@ void ResourceCache::reload_externals() {
}
bool ResourceCache::has(const String &p_path) {
-
lock->read_lock();
bool b = resources.has(p_path);
lock->read_unlock();
return b;
}
-Resource *ResourceCache::get(const String &p_path) {
+Resource *ResourceCache::get(const String &p_path) {
lock->read_lock();
Resource **res = resources.getptr(p_path);
@@ -506,11 +473,9 @@ Resource *ResourceCache::get(const String &p_path) {
}
void ResourceCache::get_cached_resources(List<Ref<Resource>> *p_resources) {
-
lock->read_lock();
const String *K = nullptr;
while ((K = resources.next(K))) {
-
Resource *r = resources[*K];
p_resources->push_back(Ref<Resource>(r));
}
@@ -518,7 +483,6 @@ void ResourceCache::get_cached_resources(List<Ref<Resource>> *p_resources) {
}
int ResourceCache::get_cached_resource_count() {
-
lock->read_lock();
int rc = resources.size();
lock->read_unlock();
@@ -540,7 +504,6 @@ void ResourceCache::dump(const char *p_file, bool p_short) {
const String *K = nullptr;
while ((K = resources.next(K))) {
-
Resource *r = resources[*K];
if (!type_count.has(r->get_class())) {
@@ -550,15 +513,16 @@ void ResourceCache::dump(const char *p_file, bool p_short) {
type_count[r->get_class()]++;
if (!p_short) {
- if (f)
+ if (f) {
f->store_line(r->get_class() + ": " + r->get_path());
+ }
}
}
for (Map<String, int>::Element *E = type_count.front(); E; E = E->next()) {
-
- if (f)
+ if (f) {
f->store_line(E->key() + " count: " + itos(E->get()));
+ }
}
if (f) {
f->close();
diff --git a/core/resource.h b/core/resource.h
index 7d92b843dc..ad2f3ce913 100644
--- a/core/resource.h
+++ b/core/resource.h
@@ -45,7 +45,6 @@ public:
private:
class Resource : public Reference {
-
GDCLASS(Resource, Reference);
OBJ_CATEGORY("Resources");
RES_BASE_EXTENSION("res");
diff --git a/core/rid.h b/core/rid.h
index ac07eacd08..4b65f3fb6a 100644
--- a/core/rid.h
+++ b/core/rid.h
@@ -41,23 +41,18 @@ class RID {
public:
_FORCE_INLINE_ bool operator==(const RID &p_rid) const {
-
return _id == p_rid._id;
}
_FORCE_INLINE_ bool operator<(const RID &p_rid) const {
-
return _id < p_rid._id;
}
_FORCE_INLINE_ bool operator<=(const RID &p_rid) const {
-
return _id <= p_rid._id;
}
_FORCE_INLINE_ bool operator>(const RID &p_rid) const {
-
return _id > p_rid._id;
}
_FORCE_INLINE_ bool operator!=(const RID &p_rid) const {
-
return _id != p_rid._id;
}
_FORCE_INLINE_ bool is_valid() const { return _id != 0; }
diff --git a/core/rid_owner.h b/core/rid_owner.h
index 77bbc3c83c..2489475c68 100644
--- a/core/rid_owner.h
+++ b/core/rid_owner.h
@@ -44,7 +44,6 @@
#include <typeinfo>
class RID_AllocBase {
-
static volatile uint64_t base_id;
protected:
@@ -68,7 +67,6 @@ public:
template <class T, bool THREAD_SAFE = false>
class RID_Alloc : public RID_AllocBase {
-
T **chunks = nullptr;
uint32_t **free_list_chunks = nullptr;
uint32_t **validator_chunks = nullptr;
@@ -83,7 +81,6 @@ class RID_Alloc : public RID_AllocBase {
public:
RID make_rid(const T &p_value) {
-
if (THREAD_SAFE) {
spin_lock.lock();
}
@@ -137,7 +134,6 @@ public:
}
_FORCE_INLINE_ T *getornull(const RID &p_rid) {
-
if (THREAD_SAFE) {
spin_lock.lock();
}
@@ -172,7 +168,6 @@ public:
}
_FORCE_INLINE_ bool owns(const RID &p_rid) {
-
if (THREAD_SAFE) {
spin_lock.lock();
}
@@ -201,7 +196,6 @@ public:
}
_FORCE_INLINE_ void free(const RID &p_rid) {
-
if (THREAD_SAFE) {
spin_lock.lock();
}
diff --git a/core/ring_buffer.h b/core/ring_buffer.h
index 8ef9b1a15c..2fd622b86f 100644
--- a/core/ring_buffer.h
+++ b/core/ring_buffer.h
@@ -35,7 +35,6 @@
template <typename T>
class RingBuffer {
-
Vector<T> data;
int read_pos = 0;
int write_pos = 0;
@@ -78,12 +77,12 @@ public:
};
int copy(T *p_buf, int p_offset, int p_size) const {
-
int left = data_left();
if ((p_offset + p_size) > left) {
p_size -= left - p_offset;
- if (p_size <= 0)
+ if (p_size <= 0) {
return 0;
+ }
}
p_size = MIN(left, p_size);
int pos = read_pos;
@@ -104,12 +103,12 @@ public:
};
int find(const T &t, int p_offset, int p_max_size) const {
-
int left = data_left();
if ((p_offset + p_max_size) > left) {
p_max_size -= left - p_offset;
- if (p_max_size <= 0)
+ if (p_max_size <= 0) {
return 0;
+ }
}
p_max_size = MIN(left, p_max_size);
int pos = read_pos;
@@ -120,8 +119,9 @@ public:
end = MIN(end, size());
int total = end - pos;
for (int i = 0; i < total; i++) {
- if (data[pos + i] == t)
+ if (data[pos + i] == t) {
return i + (p_max_size - to_read);
+ }
};
to_read -= total;
pos = 0;
@@ -148,7 +148,6 @@ public:
};
int write(const T *p_buf, int p_size) {
-
int left = space_left();
p_size = MIN(left, p_size);
@@ -156,7 +155,6 @@ public:
int to_write = p_size;
int src = 0;
while (to_write) {
-
int end = pos + to_write;
end = MIN(end, size());
int total = end - pos;
diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp
index e4604faa09..22b9ff9741 100644
--- a/core/safe_refcount.cpp
+++ b/core/safe_refcount.cpp
@@ -63,22 +63,18 @@ _ALWAYS_INLINE_ uint32_t _atomic_conditional_increment_impl(volatile uint32_t *p
}
_ALWAYS_INLINE_ uint32_t _atomic_decrement_impl(volatile uint32_t *pw) {
-
return InterlockedDecrement((LONG volatile *)pw);
}
_ALWAYS_INLINE_ uint32_t _atomic_increment_impl(volatile uint32_t *pw) {
-
return InterlockedIncrement((LONG volatile *)pw);
}
_ALWAYS_INLINE_ uint32_t _atomic_sub_impl(volatile uint32_t *pw, volatile uint32_t val) {
-
return InterlockedExchangeAdd((LONG volatile *)pw, -(int32_t)val) - val;
}
_ALWAYS_INLINE_ uint32_t _atomic_add_impl(volatile uint32_t *pw, volatile uint32_t val) {
-
return InterlockedAdd((LONG volatile *)pw, val);
}
@@ -93,22 +89,18 @@ _ALWAYS_INLINE_ uint64_t _atomic_conditional_increment_impl(volatile uint64_t *p
}
_ALWAYS_INLINE_ uint64_t _atomic_decrement_impl(volatile uint64_t *pw) {
-
return InterlockedDecrement64((LONGLONG volatile *)pw);
}
_ALWAYS_INLINE_ uint64_t _atomic_increment_impl(volatile uint64_t *pw) {
-
return InterlockedIncrement64((LONGLONG volatile *)pw);
}
_ALWAYS_INLINE_ uint64_t _atomic_sub_impl(volatile uint64_t *pw, volatile uint64_t val) {
-
return InterlockedExchangeAdd64((LONGLONG volatile *)pw, -(int64_t)val) - val;
}
_ALWAYS_INLINE_ uint64_t _atomic_add_impl(volatile uint64_t *pw, volatile uint64_t val) {
-
return InterlockedAdd64((LONGLONG volatile *)pw, val);
}
diff --git a/core/safe_refcount.h b/core/safe_refcount.h
index 953a877397..dc4e62354a 100644
--- a/core/safe_refcount.h
+++ b/core/safe_refcount.h
@@ -43,9 +43,9 @@
template <class T>
static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) {
-
- if (*pw == 0)
+ if (*pw == 0) {
return 0;
+ }
(*pw)++;
@@ -54,7 +54,6 @@ static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) {
template <class T>
static _ALWAYS_INLINE_ T atomic_decrement(volatile T *pw) {
-
(*pw)--;
return *pw;
@@ -62,7 +61,6 @@ static _ALWAYS_INLINE_ T atomic_decrement(volatile T *pw) {
template <class T>
static _ALWAYS_INLINE_ T atomic_increment(volatile T *pw) {
-
(*pw)++;
return *pw;
@@ -70,7 +68,6 @@ static _ALWAYS_INLINE_ T atomic_increment(volatile T *pw) {
template <class T, class V>
static _ALWAYS_INLINE_ T atomic_sub(volatile T *pw, volatile V val) {
-
(*pw) -= val;
return *pw;
@@ -78,7 +75,6 @@ static _ALWAYS_INLINE_ T atomic_sub(volatile T *pw, volatile V val) {
template <class T, class V>
static _ALWAYS_INLINE_ T atomic_add(volatile T *pw, volatile V val) {
-
(*pw) += val;
return *pw;
@@ -86,9 +82,9 @@ static _ALWAYS_INLINE_ T atomic_add(volatile T *pw, volatile V val) {
template <class T, class V>
static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V val) {
-
- if (val > *pw)
+ if (val > *pw) {
*pw = val;
+ }
return *pw;
}
@@ -102,49 +98,47 @@ static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V v
template <class T>
static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) {
-
while (true) {
T tmp = static_cast<T const volatile &>(*pw);
- if (tmp == 0)
+ if (tmp == 0) {
return 0; // if zero, can't add to it anymore
- if (__sync_val_compare_and_swap(pw, tmp, tmp + 1) == tmp)
+ }
+ if (__sync_val_compare_and_swap(pw, tmp, tmp + 1) == tmp) {
return tmp + 1;
+ }
}
}
template <class T>
static _ALWAYS_INLINE_ T atomic_decrement(volatile T *pw) {
-
return __sync_sub_and_fetch(pw, 1);
}
template <class T>
static _ALWAYS_INLINE_ T atomic_increment(volatile T *pw) {
-
return __sync_add_and_fetch(pw, 1);
}
template <class T, class V>
static _ALWAYS_INLINE_ T atomic_sub(volatile T *pw, volatile V val) {
-
return __sync_sub_and_fetch(pw, val);
}
template <class T, class V>
static _ALWAYS_INLINE_ T atomic_add(volatile T *pw, volatile V val) {
-
return __sync_add_and_fetch(pw, val);
}
template <class T, class V>
static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V val) {
-
while (true) {
T tmp = static_cast<T const volatile &>(*pw);
- if (tmp >= val)
+ if (tmp >= val) {
return tmp; // already greater, or equal
- if (__sync_val_compare_and_swap(pw, tmp, val) == tmp)
+ }
+ if (__sync_val_compare_and_swap(pw, tmp, val) == tmp) {
return val;
+ }
}
}
@@ -171,7 +165,6 @@ uint64_t atomic_exchange_if_greater(volatile uint64_t *pw, volatile uint64_t val
#endif
struct SafeRefCount {
-
uint32_t count;
public:
@@ -203,7 +196,6 @@ public:
}
_ALWAYS_INLINE_ void init(uint32_t p_value = 1) {
-
count = p_value;
}
};
diff --git a/core/script_language.cpp b/core/script_language.cpp
index 603b4dc13d..38a970f3c6 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -46,11 +46,10 @@ bool ScriptServer::languages_finished = false;
ScriptEditRequestFunction ScriptServer::edit_request_func = nullptr;
void Script::_notification(int p_what) {
-
if (p_what == NOTIFICATION_POSTINITIALIZE) {
-
- if (EngineDebugger::is_active())
+ if (EngineDebugger::is_active()) {
EngineDebugger::get_script_debugger()->set_break_language(get_language());
+ }
}
}
@@ -101,7 +100,6 @@ Dictionary Script::_get_script_constant_map() {
}
void Script::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("can_instance"), &Script::can_instance);
//ClassDB::bind_method(D_METHOD("instance_create","base_object"),&Script::instance_create);
ClassDB::bind_method(D_METHOD("instance_has", "base_object"), &Script::instance_has);
@@ -126,30 +124,25 @@ void Script::_bind_methods() {
}
void ScriptServer::set_scripting_enabled(bool p_enabled) {
-
scripting_enabled = p_enabled;
}
bool ScriptServer::is_scripting_enabled() {
-
return scripting_enabled;
}
ScriptLanguage *ScriptServer::get_language(int p_idx) {
-
ERR_FAIL_INDEX_V(p_idx, _language_count, nullptr);
return _languages[p_idx];
}
void ScriptServer::register_language(ScriptLanguage *p_language) {
-
ERR_FAIL_COND(_language_count >= MAX_LANGUAGES);
_languages[_language_count++] = p_language;
}
void ScriptServer::unregister_language(ScriptLanguage *p_language) {
-
for (int i = 0; i < _language_count; i++) {
if (_languages[i] == p_language) {
_language_count--;
@@ -162,7 +155,6 @@ void ScriptServer::unregister_language(ScriptLanguage *p_language) {
}
void ScriptServer::init_languages() {
-
{ //load global classes
global_classes_clear();
if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) {
@@ -170,8 +162,9 @@ void ScriptServer::init_languages() {
for (int i = 0; i < script_classes.size(); i++) {
Dictionary c = script_classes[i];
- if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base"))
+ if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) {
continue;
+ }
add_global_class(c["class"], c["base"], c["language"], c["path"]);
}
}
@@ -183,7 +176,6 @@ void ScriptServer::init_languages() {
}
void ScriptServer::finish_languages() {
-
for (int i = 0; i < _language_count; i++) {
_languages[i]->finish();
}
@@ -192,24 +184,20 @@ void ScriptServer::finish_languages() {
}
void ScriptServer::set_reload_scripts_on_save(bool p_enable) {
-
reload_scripts_on_save = p_enable;
}
bool ScriptServer::is_reload_scripts_on_save_enabled() {
-
return reload_scripts_on_save;
}
void ScriptServer::thread_enter() {
-
for (int i = 0; i < _language_count; i++) {
_languages[i]->thread_enter();
}
}
void ScriptServer::thread_exit() {
-
for (int i = 0; i < _language_count; i++) {
_languages[i]->thread_exit();
}
@@ -229,16 +217,20 @@ void ScriptServer::add_global_class(const StringName &p_class, const StringName
g.base = p_base;
global_classes[p_class] = g;
}
+
void ScriptServer::remove_global_class(const StringName &p_class) {
global_classes.erase(p_class);
}
+
bool ScriptServer::is_global_class(const StringName &p_class) {
return global_classes.has(p_class);
}
+
StringName ScriptServer::get_global_class_language(const StringName &p_class) {
ERR_FAIL_COND_V(!global_classes.has(p_class), StringName());
return global_classes[p_class].language;
}
+
String ScriptServer::get_global_class_path(const String &p_class) {
ERR_FAIL_COND_V(!global_classes.has(p_class), String());
return global_classes[p_class].path;
@@ -248,6 +240,7 @@ StringName ScriptServer::get_global_class_base(const String &p_class) {
ERR_FAIL_COND_V(!global_classes.has(p_class), String());
return global_classes[p_class].base;
}
+
StringName ScriptServer::get_global_class_native_base(const String &p_class) {
ERR_FAIL_COND_V(!global_classes.has(p_class), String());
String base = global_classes[p_class].base;
@@ -256,6 +249,7 @@ StringName ScriptServer::get_global_class_native_base(const String &p_class) {
}
return base;
}
+
void ScriptServer::get_global_class_list(List<StringName> *r_global_classes) {
const StringName *K = nullptr;
List<StringName> classes;
@@ -267,6 +261,7 @@ void ScriptServer::get_global_class_list(List<StringName> *r_global_classes) {
r_global_classes->push_back(E->get());
}
}
+
void ScriptServer::save_global_classes() {
List<StringName> gc;
get_global_class_list(&gc);
@@ -286,27 +281,26 @@ void ScriptServer::save_global_classes() {
////////////////////
void ScriptInstance::get_property_state(List<Pair<StringName, Variant>> &state) {
-
List<PropertyInfo> pinfo;
get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
-
if (E->get().usage & PROPERTY_USAGE_STORAGE) {
Pair<StringName, Variant> p;
p.first = E->get().name;
- if (get(p.first, p.second))
+ if (get(p.first, p.second)) {
state.push_back(p);
+ }
}
}
}
Variant ScriptInstance::call(const StringName &p_method, VARIANT_ARG_DECLARE) {
-
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -325,23 +319,25 @@ void ScriptInstance::call_multilevel_reversed(const StringName &p_method, const
}
void ScriptInstance::property_set_fallback(const StringName &, const Variant &, bool *r_valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
}
Variant ScriptInstance::property_get_fallback(const StringName &, bool *r_valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant();
}
void ScriptInstance::call_multilevel(const StringName &p_method, VARIANT_ARG_DECLARE) {
-
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -360,9 +356,9 @@ void ScriptLanguage::frame() {
}
bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) {
-
- if (script->is_placeholder_fallback_enabled())
+ if (script->is_placeholder_fallback_enabled()) {
return false;
+ }
if (values.has(p_name)) {
Variant defval;
@@ -385,8 +381,8 @@ bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_v
}
return false;
}
-bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
+bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
if (values.has(p_name)) {
r_ret = values[p_name];
return true;
@@ -409,7 +405,6 @@ bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) co
}
void PlaceHolderScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
-
if (script->is_placeholder_fallback_enabled()) {
for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
p_properties->push_back(E->get());
@@ -426,38 +421,41 @@ void PlaceHolderScriptInstance::get_property_list(List<PropertyInfo> *p_properti
}
Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const {
-
if (values.has(p_name)) {
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = true;
+ }
return values[p_name].get_type();
}
if (constants.has(p_name)) {
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = true;
+ }
return constants[p_name].get_type();
}
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = false;
+ }
return Variant::NIL;
}
void PlaceHolderScriptInstance::get_method_list(List<MethodInfo> *p_list) const {
-
- if (script->is_placeholder_fallback_enabled())
+ if (script->is_placeholder_fallback_enabled()) {
return;
+ }
if (script.is_valid()) {
script->get_script_method_list(p_list);
}
}
-bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const {
- if (script->is_placeholder_fallback_enabled())
+bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const {
+ if (script->is_placeholder_fallback_enabled()) {
return false;
+ }
if (script.is_valid()) {
return script->has_method(p_method);
@@ -466,17 +464,15 @@ bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const {
}
void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, const Map<StringName, Variant> &p_values) {
-
Set<StringName> new_values;
for (const List<PropertyInfo>::Element *E = p_properties.front(); E; E = E->next()) {
-
StringName n = E->get().name;
new_values.insert(n);
if (!values.has(n) || values[n].get_type() != E->get().type) {
-
- if (p_values.has(n))
+ if (p_values.has(n)) {
values[n] = p_values[n];
+ }
}
}
@@ -484,9 +480,9 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
List<StringName> to_remove;
for (Map<StringName, Variant>::Element *E = values.front(); E; E = E->next()) {
-
- if (!new_values.has(E->key()))
+ if (!new_values.has(E->key())) {
to_remove.push_back(E->key());
+ }
Variant defval;
if (script->get_property_default_value(E->key(), defval)) {
@@ -498,13 +494,11 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
}
while (to_remove.size()) {
-
values.erase(to_remove.front()->get());
to_remove.pop_front();
}
if (owner && owner->get_script_instance() == this) {
-
owner->_change_notify();
}
//change notify
@@ -514,7 +508,6 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
}
void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid) {
-
if (script->is_placeholder_fallback_enabled()) {
Map<StringName, Variant>::Element *E = values.find(p_name);
@@ -536,31 +529,34 @@ void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name,
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false; // Cannot change the value in either case
+ }
}
Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_name, bool *r_valid) {
-
if (script->is_placeholder_fallback_enabled()) {
const Map<StringName, Variant>::Element *E = values.find(p_name);
if (E) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return E->value();
}
E = constants.find(p_name);
if (E) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return E->value();
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant();
}
@@ -580,7 +576,6 @@ PlaceHolderScriptInstance::PlaceHolderScriptInstance(ScriptLanguage *p_language,
}
PlaceHolderScriptInstance::~PlaceHolderScriptInstance() {
-
if (script.is_valid()) {
script->_placeholder_erased(this);
}
diff --git a/core/script_language.h b/core/script_language.h
index 544de26d81..b6c2a47245 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -112,7 +112,6 @@ class ScriptInstance;
class PlaceHolderScriptInstance;
class Script : public Resource {
-
GDCLASS(Script, Resource);
OBJ_SAVE_TYPE(Script);
@@ -205,8 +204,9 @@ public:
virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount);
virtual void notification(int p_notification) = 0;
virtual String to_string(bool *r_valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return String();
}
@@ -268,7 +268,6 @@ struct ScriptCodeCompletionOption {
};
class ScriptCodeCompletionCache {
-
static ScriptCodeCompletionCache *singleton;
public:
@@ -406,7 +405,6 @@ public:
extern uint8_t script_encryption_key[32];
class PlaceHolderScriptInstance : public ScriptInstance {
-
Object *owner;
List<PropertyInfo> properties;
Map<StringName, Variant> values;
diff --git a/core/self_list.h b/core/self_list.h
index 74c585e60e..3104bcb714 100644
--- a/core/self_list.h
+++ b/core/self_list.h
@@ -38,13 +38,11 @@ template <class T>
class SelfList {
public:
class List {
-
SelfList<T> *_first = nullptr;
SelfList<T> *_last = nullptr;
public:
void add(SelfList<T> *p_elem) {
-
ERR_FAIL_COND(p_elem->_root);
p_elem->_root = this;
@@ -62,7 +60,6 @@ public:
}
void add_last(SelfList<T> *p_elem) {
-
ERR_FAIL_COND(p_elem->_root);
p_elem->_root = this;
@@ -80,7 +77,6 @@ public:
}
void remove(SelfList<T> *p_elem) {
-
ERR_FAIL_COND(p_elem->_root != this);
if (p_elem->_next) {
p_elem->_next->_prev = p_elem->_prev;
@@ -119,8 +115,9 @@ private:
public:
_FORCE_INLINE_ bool in_list() const { return _root; }
_FORCE_INLINE_ void remove_from_list() {
- if (_root)
+ if (_root) {
_root->remove(this);
+ }
}
_FORCE_INLINE_ SelfList<T> *next() { return _next; }
_FORCE_INLINE_ SelfList<T> *prev() { return _prev; }
@@ -133,8 +130,9 @@ public:
}
_FORCE_INLINE_ ~SelfList() {
- if (_root)
+ if (_root) {
_root->remove(this);
+ }
}
};
diff --git a/core/set.h b/core/set.h
index 851a33b43a..1bc0a3f41e 100644
--- a/core/set.h
+++ b/core/set.h
@@ -39,7 +39,6 @@
template <class T, class C = Comparator<T>, class A = DefaultAllocator>
class Set {
-
enum Color {
RED,
BLACK
@@ -48,7 +47,6 @@ class Set {
public:
class Element {
-
private:
friend class Set<T, C, A>;
int color = RED;
@@ -62,19 +60,15 @@ public:
public:
const Element *next() const {
-
return _next;
}
Element *next() {
-
return _next;
}
const Element *prev() const {
-
return _prev;
}
Element *prev() {
-
return _prev;
}
const T &get() const {
@@ -85,7 +79,6 @@ public:
private:
struct _Data {
-
Element *_root = nullptr;
Element *_nil;
int size_cache = 0;
@@ -101,14 +94,12 @@ private:
}
void _create_root() {
-
_root = memnew_allocator(Element, A);
_root->parent = _root->left = _root->right = _nil;
_root->color = BLACK;
}
void _free_root() {
-
if (_root) {
memdelete_allocator<Element, A>(_root);
_root = nullptr;
@@ -116,7 +107,6 @@ private:
}
~_Data() {
-
_free_root();
#ifdef GLOBALNIL_DISABLED
@@ -128,62 +118,61 @@ private:
_Data _data;
inline void _set_color(Element *p_node, int p_color) {
-
ERR_FAIL_COND(p_node == _data._nil && p_color == RED);
p_node->color = p_color;
}
inline void _rotate_left(Element *p_node) {
-
Element *r = p_node->right;
p_node->right = r->left;
- if (r->left != _data._nil)
+ if (r->left != _data._nil) {
r->left->parent = p_node;
+ }
r->parent = p_node->parent;
- if (p_node == p_node->parent->left)
+ if (p_node == p_node->parent->left) {
p_node->parent->left = r;
- else
+ } else {
p_node->parent->right = r;
+ }
r->left = p_node;
p_node->parent = r;
}
inline void _rotate_right(Element *p_node) {
-
Element *l = p_node->left;
p_node->left = l->right;
- if (l->right != _data._nil)
+ if (l->right != _data._nil) {
l->right->parent = p_node;
+ }
l->parent = p_node->parent;
- if (p_node == p_node->parent->right)
+ if (p_node == p_node->parent->right) {
p_node->parent->right = l;
- else
+ } else {
p_node->parent->left = l;
+ }
l->right = p_node;
p_node->parent = l;
}
inline Element *_successor(Element *p_node) const {
-
Element *node = p_node;
if (node->right != _data._nil) {
-
node = node->right;
while (node->left != _data._nil) { /* returns the minimum of the right subtree of node */
node = node->left;
}
return node;
} else {
-
while (node == node->parent->right) {
node = node->parent;
}
- if (node->parent == _data._root)
+ if (node->parent == _data._root) {
return nullptr; // No successor, as p_node = last node
+ }
return node->parent;
}
}
@@ -192,43 +181,41 @@ private:
Element *node = p_node;
if (node->left != _data._nil) {
-
node = node->left;
while (node->right != _data._nil) { /* returns the minimum of the left subtree of node */
node = node->right;
}
return node;
} else {
-
while (node == node->parent->left) {
node = node->parent;
}
- if (node == _data._root)
+ if (node == _data._root) {
return nullptr; // No predecessor, as p_node = first node.
+ }
return node->parent;
}
}
Element *_find(const T &p_value) const {
-
Element *node = _data._root->left;
C less;
while (node != _data._nil) {
- if (less(p_value, node->value))
+ if (less(p_value, node->value)) {
node = node->left;
- else if (less(node->value, p_value))
+ } else if (less(node->value, p_value)) {
node = node->right;
- else
+ } else {
return node; // found
+ }
}
return nullptr;
}
Element *_lower_bound(const T &p_value) const {
-
Element *node = _data._root->left;
Element *prev = nullptr;
C less;
@@ -236,25 +223,27 @@ private:
while (node != _data._nil) {
prev = node;
- if (less(p_value, node->value))
+ if (less(p_value, node->value)) {
node = node->left;
- else if (less(node->value, p_value))
+ } else if (less(node->value, p_value)) {
node = node->right;
- else
+ } else {
return node; // found
+ }
}
- if (prev == nullptr)
+ if (prev == nullptr) {
return nullptr; // tree empty
+ }
- if (less(prev->value, p_value))
+ if (less(prev->value, p_value)) {
prev = prev->_next;
+ }
return prev;
}
void _insert_rb_fix(Element *p_new_node) {
-
Element *node = p_new_node;
Element *nparent = node->parent;
Element *ngrand_parent;
@@ -303,20 +292,18 @@ private:
}
Element *_insert(const T &p_value) {
-
Element *new_parent = _data._root;
Element *node = _data._root->left;
C less;
while (node != _data._nil) {
-
new_parent = node;
- if (less(p_value, node->value))
+ if (less(p_value, node->value)) {
node = node->left;
- else if (less(node->value, p_value))
+ } else if (less(node->value, p_value)) {
node = node->right;
- else {
+ } else {
return node; // Return existing node
}
}
@@ -336,10 +323,12 @@ private:
new_node->_next = _successor(new_node);
new_node->_prev = _predecessor(new_node);
- if (new_node->_next)
+ if (new_node->_next) {
new_node->_next->_prev = new_node;
- if (new_node->_prev)
+ }
+ if (new_node->_prev) {
new_node->_prev->_next = new_node;
+ }
_data.size_cache++;
_insert_rb_fix(new_node);
@@ -347,7 +336,6 @@ private:
}
void _erase_fix_rb(Element *p_node) {
-
Element *root = _data._root->left;
Element *node = _data._nil;
Element *sibling = p_node;
@@ -409,7 +397,6 @@ private:
}
void _erase(Element *p_node) {
-
Element *rp = ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : p_node->_next;
Element *node = (rp->left == _data._nil) ? rp->right : rp->left;
@@ -430,17 +417,18 @@ private:
}
if (rp != p_node) {
-
ERR_FAIL_COND(rp == _data._nil);
rp->left = p_node->left;
rp->right = p_node->right;
rp->parent = p_node->parent;
rp->color = p_node->color;
- if (p_node->left != _data._nil)
+ if (p_node->left != _data._nil) {
p_node->left->parent = rp;
- if (p_node->right != _data._nil)
+ }
+ if (p_node->right != _data._nil) {
p_node->right->parent = rp;
+ }
if (p_node == p_node->parent->left) {
p_node->parent->left = rp;
@@ -449,10 +437,12 @@ private:
}
}
- if (p_node->_next)
+ if (p_node->_next) {
p_node->_next->_prev = p_node->_prev;
- if (p_node->_prev)
+ }
+ if (p_node->_prev) {
p_node->_prev->_next = p_node->_next;
+ }
memdelete_allocator<Element, A>(p_node);
_data.size_cache--;
@@ -460,21 +450,22 @@ private:
}
void _calculate_depth(Element *p_element, int &max_d, int d) const {
-
- if (p_element == _data._nil)
+ if (p_element == _data._nil) {
return;
+ }
_calculate_depth(p_element->left, max_d, d + 1);
_calculate_depth(p_element->right, max_d, d + 1);
- if (d > max_d)
+ if (d > max_d) {
max_d = d;
+ }
}
void _cleanup_tree(Element *p_element) {
-
- if (p_element == _data._nil)
+ if (p_element == _data._nil) {
return;
+ }
_cleanup_tree(p_element->left);
_cleanup_tree(p_element->right);
@@ -482,102 +473,105 @@ private:
}
void _copy_from(const Set &p_set) {
-
clear();
// not the fastest way, but safeset to write.
for (Element *I = p_set.front(); I; I = I->next()) {
-
insert(I->get());
}
}
public:
const Element *find(const T &p_value) const {
-
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
const Element *res = _find(p_value);
return res;
}
Element *find(const T &p_value) {
-
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *res = _find(p_value);
return res;
}
Element *lower_bound(const T &p_value) const {
-
return _lower_bound(p_value);
}
bool has(const T &p_value) const {
-
return find(p_value) != nullptr;
}
Element *insert(const T &p_value) {
-
- if (!_data._root)
+ if (!_data._root) {
_data._create_root();
+ }
return _insert(p_value);
}
void erase(Element *p_element) {
-
- if (!_data._root || !p_element)
+ if (!_data._root || !p_element) {
return;
+ }
_erase(p_element);
- if (_data.size_cache == 0 && _data._root)
+ if (_data.size_cache == 0 && _data._root) {
_data._free_root();
+ }
}
bool erase(const T &p_value) {
-
- if (!_data._root)
+ if (!_data._root) {
return false;
+ }
Element *e = find(p_value);
- if (!e)
+ if (!e) {
return false;
+ }
_erase(e);
- if (_data.size_cache == 0 && _data._root)
+ if (_data.size_cache == 0 && _data._root) {
_data._free_root();
+ }
return true;
}
Element *front() const {
-
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *e = _data._root->left;
- if (e == _data._nil)
+ if (e == _data._nil) {
return nullptr;
+ }
- while (e->left != _data._nil)
+ while (e->left != _data._nil) {
e = e->left;
+ }
return e;
}
Element *back() const {
-
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *e = _data._root->left;
- if (e == _data._nil)
+ if (e == _data._nil) {
return nullptr;
+ }
- while (e->right != _data._nil)
+ while (e->right != _data._nil) {
e = e->right;
+ }
return e;
}
@@ -587,8 +581,9 @@ public:
int calculate_depth() const {
// used for debug mostly
- if (!_data._root)
+ if (!_data._root) {
return 0;
+ }
int max_d = 0;
_calculate_depth(_data._root->left, max_d, 0);
@@ -596,9 +591,9 @@ public:
}
void clear() {
-
- if (!_data._root)
+ if (!_data._root) {
return;
+ }
_cleanup_tree(_data._root->left);
_data._root->left = _data._nil;
@@ -607,12 +602,10 @@ public:
}
void operator=(const Set &p_set) {
-
_copy_from(p_set);
}
Set(const Set &p_set) {
-
_copy_from(p_set);
}
diff --git a/core/simple_type.h b/core/simple_type.h
index da031854c6..10dc36cbd4 100644
--- a/core/simple_type.h
+++ b/core/simple_type.h
@@ -35,19 +35,16 @@
template <class T>
struct GetSimpleTypeT {
-
typedef T type_t;
};
template <class T>
struct GetSimpleTypeT<T &> {
-
typedef T type_t;
};
template <class T>
struct GetSimpleTypeT<T const> {
-
typedef T type_t;
};
diff --git a/core/sort_array.h b/core/sort_array.h
index 8aff0fb502..93cc6f727d 100644
--- a/core/sort_array.h
+++ b/core/sort_array.h
@@ -42,7 +42,6 @@
template <class T>
struct _DefaultComparator {
-
_FORCE_INLINE_ bool operator()(const T &a, const T &b) const { return (a < b); }
};
@@ -54,7 +53,6 @@ struct _DefaultComparator {
template <class T, class Comparator = _DefaultComparator<T>, bool Validate = SORT_ARRAY_VALIDATE_ENABLED>
class SortArray {
-
enum {
INTROSORT_THRESHOLD = 16
@@ -64,36 +62,36 @@ public:
Comparator compare;
inline const T &median_of_3(const T &a, const T &b, const T &c) const {
-
- if (compare(a, b))
- if (compare(b, c))
+ if (compare(a, b)) {
+ if (compare(b, c)) {
return b;
- else if (compare(a, c))
+ } else if (compare(a, c)) {
return c;
- else
+ } else {
return a;
- else if (compare(a, c))
+ }
+ } else if (compare(a, c)) {
return a;
- else if (compare(b, c))
+ } else if (compare(b, c)) {
return c;
- else
+ } else {
return b;
+ }
}
inline int bitlog(int n) const {
int k;
- for (k = 0; n != 1; n >>= 1)
+ for (k = 0; n != 1; n >>= 1) {
++k;
+ }
return k;
}
/* Heap / Heapsort functions */
inline void push_heap(int p_first, int p_hole_idx, int p_top_index, T p_value, T *p_array) const {
-
int parent = (p_hole_idx - 1) / 2;
while (p_hole_idx > p_top_index && compare(p_array[p_first + parent], p_value)) {
-
p_array[p_first + p_hole_idx] = p_array[p_first + parent];
p_hole_idx = parent;
parent = (p_hole_idx - 1) / 2;
@@ -102,24 +100,21 @@ public:
}
inline void pop_heap(int p_first, int p_last, int p_result, T p_value, T *p_array) const {
-
p_array[p_result] = p_array[p_first];
adjust_heap(p_first, 0, p_last - p_first, p_value, p_array);
}
inline void pop_heap(int p_first, int p_last, T *p_array) const {
-
pop_heap(p_first, p_last - 1, p_last - 1, p_array[p_last - 1], p_array);
}
inline void adjust_heap(int p_first, int p_hole_idx, int p_len, T p_value, T *p_array) const {
-
int top_index = p_hole_idx;
int second_child = 2 * p_hole_idx + 2;
while (second_child < p_len) {
-
- if (compare(p_array[p_first + second_child], p_array[p_first + (second_child - 1)]))
+ if (compare(p_array[p_first + second_child], p_array[p_first + (second_child - 1)])) {
second_child--;
+ }
p_array[p_first + p_hole_idx] = p_array[p_first + second_child];
p_hole_idx = second_child;
@@ -134,46 +129,47 @@ public:
}
inline void sort_heap(int p_first, int p_last, T *p_array) const {
-
while (p_last - p_first > 1) {
-
pop_heap(p_first, p_last--, p_array);
}
}
inline void make_heap(int p_first, int p_last, T *p_array) const {
- if (p_last - p_first < 2)
+ if (p_last - p_first < 2) {
return;
+ }
int len = p_last - p_first;
int parent = (len - 2) / 2;
while (true) {
adjust_heap(p_first, parent, len, p_array[p_first + parent], p_array);
- if (parent == 0)
+ if (parent == 0) {
return;
+ }
parent--;
}
}
inline void partial_sort(int p_first, int p_last, int p_middle, T *p_array) const {
-
make_heap(p_first, p_middle, p_array);
- for (int i = p_middle; i < p_last; i++)
- if (compare(p_array[i], p_array[p_first]))
+ for (int i = p_middle; i < p_last; i++) {
+ if (compare(p_array[i], p_array[p_first])) {
pop_heap(p_first, p_middle, i, p_array[i], p_array);
+ }
+ }
sort_heap(p_first, p_middle, p_array);
}
inline void partial_select(int p_first, int p_last, int p_middle, T *p_array) const {
-
make_heap(p_first, p_middle, p_array);
- for (int i = p_middle; i < p_last; i++)
- if (compare(p_array[i], p_array[p_first]))
+ for (int i = p_middle; i < p_last; i++) {
+ if (compare(p_array[i], p_array[p_first])) {
pop_heap(p_first, p_middle, i, p_array[i], p_array);
+ }
+ }
}
inline int partitioner(int p_first, int p_last, T p_pivot, T *p_array) const {
-
const int unmodified_first = p_first;
const int unmodified_last = p_last;
@@ -192,8 +188,9 @@ public:
p_last--;
}
- if (!(p_first < p_last))
+ if (!(p_first < p_last)) {
return p_first;
+ }
SWAP(p_array[p_first], p_array[p_last]);
p_first++;
@@ -201,9 +198,7 @@ public:
}
inline void introsort(int p_first, int p_last, T *p_array, int p_max_depth) const {
-
while (p_last - p_first > INTROSORT_THRESHOLD) {
-
if (p_max_depth == 0) {
partial_sort(p_first, p_last, p_last, p_array);
return;
@@ -226,9 +221,7 @@ public:
}
inline void introselect(int p_first, int p_nth, int p_last, T *p_array, int p_max_depth) const {
-
while (p_last - p_first > 3) {
-
if (p_max_depth == 0) {
partial_select(p_first, p_nth + 1, p_last, p_array);
SWAP(p_first, p_nth);
@@ -246,17 +239,17 @@ public:
p_array[p_last - 1]),
p_array);
- if (cut <= p_nth)
+ if (cut <= p_nth) {
p_first = cut;
- else
+ } else {
p_last = cut;
+ }
}
insertion_sort(p_first, p_last, p_array);
}
inline void unguarded_linear_insert(int p_last, T p_value, T *p_array) const {
-
int next = p_last - 1;
while (compare(p_value, p_array[next])) {
if (Validate) {
@@ -270,45 +263,43 @@ public:
}
inline void linear_insert(int p_first, int p_last, T *p_array) const {
-
T val = p_array[p_last];
if (compare(val, p_array[p_first])) {
-
- for (int i = p_last; i > p_first; i--)
+ for (int i = p_last; i > p_first; i--) {
p_array[i] = p_array[i - 1];
+ }
p_array[p_first] = val;
- } else
+ } else {
unguarded_linear_insert(p_last, val, p_array);
+ }
}
inline void insertion_sort(int p_first, int p_last, T *p_array) const {
-
- if (p_first == p_last)
+ if (p_first == p_last) {
return;
- for (int i = p_first + 1; i != p_last; i++)
+ }
+ for (int i = p_first + 1; i != p_last; i++) {
linear_insert(p_first, i, p_array);
+ }
}
inline void unguarded_insertion_sort(int p_first, int p_last, T *p_array) const {
-
- for (int i = p_first; i != p_last; i++)
+ for (int i = p_first; i != p_last; i++) {
unguarded_linear_insert(i, p_array[i], p_array);
+ }
}
inline void final_insertion_sort(int p_first, int p_last, T *p_array) const {
-
if (p_last - p_first > INTROSORT_THRESHOLD) {
insertion_sort(p_first, p_first + INTROSORT_THRESHOLD, p_array);
unguarded_insertion_sort(p_first + INTROSORT_THRESHOLD, p_last, p_array);
} else {
-
insertion_sort(p_first, p_last, p_array);
}
}
inline void sort_range(int p_first, int p_last, T *p_array) const {
-
if (p_first != p_last) {
introsort(p_first, p_last, p_array, bitlog(p_last - p_first) * 2);
final_insertion_sort(p_first, p_last, p_array);
@@ -316,14 +307,13 @@ public:
}
inline void sort(T *p_array, int p_len) const {
-
sort_range(0, p_len, p_array);
}
inline void nth_element(int p_first, int p_last, int p_nth, T *p_array) const {
-
- if (p_first == p_last || p_nth == p_last)
+ if (p_first == p_last || p_nth == p_last) {
return;
+ }
introselect(p_first, p_nth, p_last, p_array, bitlog(p_last - p_first) * 2);
}
};
diff --git a/core/string_buffer.h b/core/string_buffer.h
index cfe7cdabfe..956a6333d9 100644
--- a/core/string_buffer.h
+++ b/core/string_buffer.h
@@ -35,7 +35,6 @@
template <int SHORT_BUFFER_SIZE = 64>
class StringBuffer {
-
CharType short_buffer[SHORT_BUFFER_SIZE];
String buffer;
int string_length = 0;
@@ -119,8 +118,9 @@ StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::append(const C
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())
+ 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));
diff --git a/core/string_builder.cpp b/core/string_builder.cpp
index 46c7e1c53f..c8d6498f27 100644
--- a/core/string_builder.cpp
+++ b/core/string_builder.cpp
@@ -33,9 +33,9 @@
#include <string.h>
StringBuilder &StringBuilder::append(const String &p_string) {
-
- if (p_string == String())
+ if (p_string == String()) {
return *this;
+ }
strings.push_back(p_string);
appended_strings.push_back(-1);
@@ -46,7 +46,6 @@ StringBuilder &StringBuilder::append(const String &p_string) {
}
StringBuilder &StringBuilder::append(const char *p_cstring) {
-
int32_t len = strlen(p_cstring);
c_strings.push_back(p_cstring);
@@ -58,9 +57,9 @@ StringBuilder &StringBuilder::append(const char *p_cstring) {
}
String StringBuilder::as_string() const {
-
- if (string_length == 0)
+ if (string_length == 0) {
return "";
+ }
CharType *buffer = memnew_arr(CharType, string_length);
@@ -80,7 +79,6 @@ String StringBuilder::as_string() const {
godot_string_elem++;
} else {
-
const char *s = c_strings[c_string_elem];
for (int32_t j = 0; j < appended_strings[i]; j++) {
diff --git a/core/string_builder.h b/core/string_builder.h
index 8fcd6669bd..2a37d14218 100644
--- a/core/string_builder.h
+++ b/core/string_builder.h
@@ -35,7 +35,6 @@
#include "core/vector.h"
class StringBuilder {
-
uint32_t string_length = 0;
Vector<String> strings;
diff --git a/core/string_name.cpp b/core/string_name.cpp
index bfc10d96e4..cbf6009681 100644
--- a/core/string_name.cpp
+++ b/core/string_name.cpp
@@ -42,7 +42,6 @@ StaticCString StaticCString::create(const char *p_ptr) {
StringName::_Data *StringName::_table[STRING_TABLE_LEN];
StringName _scs_create(const char *p_chr) {
-
return (p_chr[0] ? StringName(StaticCString::create(p_chr)) : StringName());
}
@@ -50,24 +49,19 @@ bool StringName::configured = false;
Mutex StringName::mutex;
void StringName::setup() {
-
ERR_FAIL_COND(configured);
for (int i = 0; i < STRING_TABLE_LEN; i++) {
-
_table[i] = nullptr;
}
configured = true;
}
void StringName::cleanup() {
-
MutexLock lock(mutex);
int lost_strings = 0;
for (int i = 0; i < STRING_TABLE_LEN; i++) {
-
while (_table[i]) {
-
_Data *d = _table[i];
lost_strings++;
if (OS::get_singleton()->is_stdout_verbose()) {
@@ -88,11 +82,9 @@ void StringName::cleanup() {
}
void StringName::unref() {
-
ERR_FAIL_COND(!configured);
if (_data && _data->refcount.unref()) {
-
MutexLock lock(mutex);
if (_data->prev) {
@@ -114,9 +106,7 @@ void StringName::unref() {
}
bool StringName::operator==(const String &p_name) const {
-
if (!_data) {
-
return (p_name.length() == 0);
}
@@ -124,9 +114,7 @@ bool StringName::operator==(const String &p_name) const {
}
bool StringName::operator==(const char *p_name) const {
-
if (!_data) {
-
return (p_name[0] == 0);
}
@@ -134,32 +122,28 @@ bool StringName::operator==(const char *p_name) const {
}
bool StringName::operator!=(const String &p_name) const {
-
return !(operator==(p_name));
}
bool StringName::operator!=(const StringName &p_name) const {
-
// the real magic of all this mess happens here.
// this is why path comparisons are very fast
return _data != p_name._data;
}
void StringName::operator=(const StringName &p_name) {
-
- if (this == &p_name)
+ if (this == &p_name) {
return;
+ }
unref();
if (p_name._data && p_name._data->refcount.ref()) {
-
_data = p_name._data;
}
}
StringName::StringName(const StringName &p_name) {
-
_data = nullptr;
ERR_FAIL_COND(!configured);
@@ -170,13 +154,13 @@ StringName::StringName(const StringName &p_name) {
}
StringName::StringName(const char *p_name) {
-
_data = nullptr;
ERR_FAIL_COND(!configured);
- if (!p_name || p_name[0] == 0)
+ if (!p_name || p_name[0] == 0) {
return; //empty, ignore
+ }
MutexLock lock(mutex);
@@ -187,10 +171,10 @@ StringName::StringName(const char *p_name) {
_data = _table[idx];
while (_data) {
-
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -209,13 +193,13 @@ StringName::StringName(const char *p_name) {
_data->cname = nullptr;
_data->next = _table[idx];
_data->prev = nullptr;
- if (_table[idx])
+ if (_table[idx]) {
_table[idx]->prev = _data;
+ }
_table[idx] = _data;
}
StringName::StringName(const StaticCString &p_static_string) {
-
_data = nullptr;
ERR_FAIL_COND(!configured);
@@ -231,10 +215,10 @@ StringName::StringName(const StaticCString &p_static_string) {
_data = _table[idx];
while (_data) {
-
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_static_string.ptr)
+ if (_data->hash == hash && _data->get_name() == p_static_string.ptr) {
break;
+ }
_data = _data->next;
}
@@ -253,19 +237,20 @@ StringName::StringName(const StaticCString &p_static_string) {
_data->cname = p_static_string.ptr;
_data->next = _table[idx];
_data->prev = nullptr;
- if (_table[idx])
+ if (_table[idx]) {
_table[idx]->prev = _data;
+ }
_table[idx] = _data;
}
StringName::StringName(const String &p_name) {
-
_data = nullptr;
ERR_FAIL_COND(!configured);
- if (p_name == String())
+ if (p_name == String()) {
return;
+ }
MutexLock lock(mutex);
@@ -275,9 +260,9 @@ StringName::StringName(const String &p_name) {
_data = _table[idx];
while (_data) {
-
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -296,18 +281,19 @@ StringName::StringName(const String &p_name) {
_data->cname = nullptr;
_data->next = _table[idx];
_data->prev = nullptr;
- if (_table[idx])
+ if (_table[idx]) {
_table[idx]->prev = _data;
+ }
_table[idx] = _data;
}
StringName StringName::search(const char *p_name) {
-
ERR_FAIL_COND_V(!configured, StringName());
ERR_FAIL_COND_V(!p_name, StringName());
- if (!p_name[0])
+ if (!p_name[0]) {
return StringName();
+ }
MutexLock lock(mutex);
@@ -317,10 +303,10 @@ StringName StringName::search(const char *p_name) {
_Data *_data = _table[idx];
while (_data) {
-
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -332,12 +318,12 @@ StringName StringName::search(const char *p_name) {
}
StringName StringName::search(const CharType *p_name) {
-
ERR_FAIL_COND_V(!configured, StringName());
ERR_FAIL_COND_V(!p_name, StringName());
- if (!p_name[0])
+ if (!p_name[0]) {
return StringName();
+ }
MutexLock lock(mutex);
@@ -348,10 +334,10 @@ StringName StringName::search(const CharType *p_name) {
_Data *_data = _table[idx];
while (_data) {
-
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -361,8 +347,8 @@ StringName StringName::search(const CharType *p_name) {
return StringName(); //does not exist
}
-StringName StringName::search(const String &p_name) {
+StringName StringName::search(const String &p_name) {
ERR_FAIL_COND_V(p_name == "", StringName());
MutexLock lock(mutex);
@@ -374,10 +360,10 @@ StringName StringName::search(const String &p_name) {
_Data *_data = _table[idx];
while (_data) {
-
// compare hash first
- if (_data->hash == hash && p_name == _data->get_name())
+ if (_data->hash == hash && p_name == _data->get_name()) {
break;
+ }
_data = _data->next;
}
diff --git a/core/string_name.h b/core/string_name.h
index 762eb43610..df6b458581 100644
--- a/core/string_name.h
+++ b/core/string_name.h
@@ -36,13 +36,11 @@
#include "core/ustring.h"
struct StaticCString {
-
const char *ptr;
static StaticCString create(const char *p_ptr);
};
class StringName {
-
enum {
STRING_TABLE_BITS = 12,
@@ -68,7 +66,6 @@ class StringName {
_Data *_data = nullptr;
union _HashUnion {
-
_Data *ptr;
uint32_t hash;
};
@@ -91,7 +88,6 @@ public:
bool operator==(const char *p_name) const;
bool operator!=(const String &p_name) const;
_FORCE_INLINE_ bool operator<(const StringName &p_name) const {
-
return _data < p_name._data;
}
_FORCE_INLINE_ bool operator==(const StringName &p_name) const {
@@ -100,11 +96,11 @@ public:
return _data == p_name._data;
}
_FORCE_INLINE_ uint32_t hash() const {
-
- if (_data)
+ if (_data) {
return _data->hash;
- else
+ } else {
return 0;
+ }
}
_FORCE_INLINE_ const void *data_unique_pointer() const {
return (void *)_data;
@@ -112,12 +108,12 @@ public:
bool operator!=(const StringName &p_name) const;
_FORCE_INLINE_ operator String() const {
-
if (_data) {
- if (_data->cname)
+ if (_data->cname) {
return String(_data->cname);
- else
+ } else {
return _data->name;
+ }
}
return String();
@@ -128,24 +124,22 @@ public:
static StringName search(const String &p_name);
struct AlphCompare {
-
_FORCE_INLINE_ bool operator()(const StringName &l, const StringName &r) const {
-
const char *l_cname = l._data ? l._data->cname : "";
const char *r_cname = r._data ? r._data->cname : "";
if (l_cname) {
-
- if (r_cname)
+ if (r_cname) {
return is_str_less(l_cname, r_cname);
- else
+ } else {
return is_str_less(l_cname, r._data->name.ptr());
+ }
} else {
-
- if (r_cname)
+ if (r_cname) {
return is_str_less(l._data->name.ptr(), r_cname);
- else
+ } else {
return is_str_less(l._data->name.ptr(), r._data->name.ptr());
+ }
}
}
};
diff --git a/core/thread_work_pool.cpp b/core/thread_work_pool.cpp
index 28e933ac4d..3a95e83ffc 100644
--- a/core/thread_work_pool.cpp
+++ b/core/thread_work_pool.cpp
@@ -33,7 +33,6 @@
#include "core/os/os.h"
void ThreadWorkPool::_thread_function(ThreadData *p_thread) {
-
while (true) {
p_thread->start.wait();
if (p_thread->exit.load()) {
@@ -60,7 +59,6 @@ void ThreadWorkPool::init(int p_thread_count) {
}
void ThreadWorkPool::finish() {
-
if (threads == nullptr) {
return;
}
@@ -79,6 +77,5 @@ void ThreadWorkPool::finish() {
}
ThreadWorkPool::~ThreadWorkPool() {
-
finish();
}
diff --git a/core/thread_work_pool.h b/core/thread_work_pool.h
index 8005bf80b8..e21d3974ee 100644
--- a/core/thread_work_pool.h
+++ b/core/thread_work_pool.h
@@ -38,7 +38,6 @@
#include <thread>
class ThreadWorkPool {
-
std::atomic<uint32_t> index;
struct BaseWork {
@@ -54,7 +53,6 @@ class ThreadWorkPool {
M method;
U userdata;
virtual void work() {
-
while (true) {
uint32_t work_index = index->fetch_add(1, std::memory_order_relaxed);
if (work_index >= max_elements) {
@@ -81,7 +79,6 @@ class ThreadWorkPool {
public:
template <class C, class M, class U>
void do_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
-
ERR_FAIL_COND(!threads); //never initialized
index.store(0);
diff --git a/core/translation.cpp b/core/translation.cpp
index 191349e953..f3c1489ce4 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -795,12 +795,10 @@ static const char *locale_renames[][2] = {
///////////////////////////////////////////////
Vector<String> Translation::_get_messages() const {
-
Vector<String> msgs;
msgs.resize(translation_map.size() * 2);
int idx = 0;
for (const Map<StringName, StringName>::Element *E = translation_map.front(); E; E = E->next()) {
-
msgs.set(idx + 0, E->key());
msgs.set(idx + 1, E->get());
idx += 2;
@@ -810,12 +808,10 @@ Vector<String> Translation::_get_messages() const {
}
Vector<String> Translation::_get_message_list() const {
-
Vector<String> msgs;
msgs.resize(translation_map.size());
int idx = 0;
for (const Map<StringName, StringName>::Element *E = translation_map.front(); E; E = E->next()) {
-
msgs.set(idx, E->key());
idx += 1;
}
@@ -824,20 +820,17 @@ Vector<String> Translation::_get_message_list() const {
}
void Translation::_set_messages(const Vector<String> &p_messages) {
-
int msg_count = p_messages.size();
ERR_FAIL_COND(msg_count % 2);
const String *r = p_messages.ptr();
for (int i = 0; i < msg_count; i += 2) {
-
add_message(r[i + 0], r[i + 1]);
}
}
void Translation::set_locale(const String &p_locale) {
-
String univ_locale = TranslationServer::standardize_locale(p_locale);
if (!TranslationServer::is_locale_valid(univ_locale)) {
@@ -856,38 +849,33 @@ void Translation::set_locale(const String &p_locale) {
}
void Translation::add_message(const StringName &p_src_text, const StringName &p_xlated_text) {
-
translation_map[p_src_text] = p_xlated_text;
}
-StringName Translation::get_message(const StringName &p_src_text) const {
+StringName Translation::get_message(const StringName &p_src_text) const {
const Map<StringName, StringName>::Element *E = translation_map.find(p_src_text);
- if (!E)
+ if (!E) {
return StringName();
+ }
return E->get();
}
void Translation::erase_message(const StringName &p_src_text) {
-
translation_map.erase(p_src_text);
}
void Translation::get_message_list(List<StringName> *r_messages) const {
-
for (const Map<StringName, StringName>::Element *E = translation_map.front(); E; E = E->next()) {
-
r_messages->push_back(E->key());
}
}
int Translation::get_message_count() const {
-
return translation_map.size();
};
void Translation::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_locale", "locale"), &Translation::set_locale);
ClassDB::bind_method(D_METHOD("get_locale"), &Translation::get_locale);
ClassDB::bind_method(D_METHOD("add_message", "src_message", "xlated_message"), &Translation::add_message);
@@ -905,13 +893,12 @@ void Translation::_bind_methods() {
///////////////////////////////////////////////
bool TranslationServer::is_locale_valid(const String &p_locale) {
-
const char **ptr = locale_list;
while (*ptr) {
-
- if (*ptr == p_locale)
+ if (*ptr == p_locale) {
return true;
+ }
ptr++;
}
@@ -919,7 +906,6 @@ bool TranslationServer::is_locale_valid(const String &p_locale) {
}
String TranslationServer::standardize_locale(const String &p_locale) {
-
// Replaces '-' with '_' for macOS Sierra-style locales
String univ_locale = p_locale.replace("-", "_");
@@ -937,7 +923,6 @@ String TranslationServer::standardize_locale(const String &p_locale) {
}
String TranslationServer::get_language_code(const String &p_locale) {
-
ERR_FAIL_COND_V_MSG(p_locale.length() < 2, p_locale, "Invalid locale '" + p_locale + "'.");
// Most language codes are two letters, but some are three,
// so we have to look for a regional code separator ('_' or '-')
@@ -954,7 +939,6 @@ String TranslationServer::get_language_code(const String &p_locale) {
}
void TranslationServer::set_locale(const String &p_locale) {
-
String univ_locale = standardize_locale(p_locale);
if (!is_locale_valid(univ_locale)) {
@@ -979,21 +963,19 @@ void TranslationServer::set_locale(const String &p_locale) {
}
String TranslationServer::get_locale() const {
-
return locale;
}
String TranslationServer::get_locale_name(const String &p_locale) const {
-
- if (!locale_name_map.has(p_locale))
+ if (!locale_name_map.has(p_locale)) {
return String();
+ }
return locale_name_map[p_locale];
}
Array TranslationServer::get_loaded_locales() const {
Array locales;
for (const Set<Ref<Translation>>::Element *E = translations.front(); E; E = E->next()) {
-
const Ref<Translation> &t = E->get();
ERR_FAIL_COND_V(t.is_null(), Array());
String l = t->get_locale();
@@ -1005,7 +987,6 @@ Array TranslationServer::get_loaded_locales() const {
}
Vector<String> TranslationServer::get_all_locales() {
-
Vector<String> locales;
const char **ptr = locale_list;
@@ -1019,7 +1000,6 @@ Vector<String> TranslationServer::get_all_locales() {
}
Vector<String> TranslationServer::get_all_locale_names() {
-
Vector<String> locales;
const char **ptr = locale_names;
@@ -1033,25 +1013,23 @@ Vector<String> TranslationServer::get_all_locale_names() {
}
void TranslationServer::add_translation(const Ref<Translation> &p_translation) {
-
translations.insert(p_translation);
}
-void TranslationServer::remove_translation(const Ref<Translation> &p_translation) {
+void TranslationServer::remove_translation(const Ref<Translation> &p_translation) {
translations.erase(p_translation);
}
void TranslationServer::clear() {
-
translations.clear();
};
StringName TranslationServer::translate(const StringName &p_message) const {
-
// Match given message against the translation catalog for the project locale.
- if (!enabled)
+ if (!enabled) {
return p_message;
+ }
ERR_FAIL_COND_V_MSG(locale.length() < 2, p_message, "Could not translate message as configured locale '" + locale + "' is invalid.");
@@ -1141,7 +1119,6 @@ StringName TranslationServer::translate(const StringName &p_message) const {
TranslationServer *TranslationServer::singleton = nullptr;
bool TranslationServer::_load_translations(const String &p_from) {
-
if (ProjectSettings::get_singleton()->has_setting(p_from)) {
Vector<String> translations = ProjectSettings::get_singleton()->get(p_from);
@@ -1151,10 +1128,10 @@ bool TranslationServer::_load_translations(const String &p_from) {
const String *r = translations.ptr();
for (int i = 0; i < tcount; i++) {
-
Ref<Translation> tr = ResourceLoader::load(r[i]);
- if (tr.is_valid())
+ if (tr.is_valid()) {
add_translation(tr);
+ }
}
}
return true;
@@ -1164,21 +1141,22 @@ bool TranslationServer::_load_translations(const String &p_from) {
}
void TranslationServer::setup() {
-
String test = GLOBAL_DEF("locale/test", "");
test = test.strip_edges();
- if (test != "")
+ if (test != "") {
set_locale(test);
- else
+ } else {
set_locale(OS::get_singleton()->get_locale());
+ }
fallback = GLOBAL_DEF("locale/fallback", "en");
#ifdef TOOLS_ENABLED
{
String options = "";
int idx = 0;
while (locale_list[idx]) {
- if (idx > 0)
+ if (idx > 0) {
options += ",";
+ }
options += locale_list[idx];
idx++;
}
@@ -1216,7 +1194,6 @@ StringName TranslationServer::doc_translate(const StringName &p_message) const {
}
void TranslationServer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_locale", "locale"), &TranslationServer::set_locale);
ClassDB::bind_method(D_METHOD("get_locale"), &TranslationServer::get_locale);
@@ -1233,7 +1210,6 @@ void TranslationServer::_bind_methods() {
}
void TranslationServer::load_translations() {
-
String locale = get_locale();
_load_translations("locale/translations"); //all
_load_translations("locale/translations_" + locale.substr(0, 2));
diff --git a/core/translation.h b/core/translation.h
index 423b3166b1..4f50a1a4bc 100644
--- a/core/translation.h
+++ b/core/translation.h
@@ -34,7 +34,6 @@
#include "core/resource.h"
class Translation : public Resource {
-
GDCLASS(Translation, Resource);
OBJ_SAVE_TYPE(Translation);
RES_BASE_EXTENSION("translation");
@@ -65,7 +64,6 @@ public:
};
class TranslationServer : public Object {
-
GDCLASS(TranslationServer, Object);
String locale = "en";
diff --git a/core/type_info.h b/core/type_info.h
index 816d0d9381..e3d2b5bd53 100644
--- a/core/type_info.h
+++ b/core/type_info.h
@@ -35,7 +35,6 @@
template <bool C, typename T = void>
struct EnableIf {
-
typedef T type;
};
@@ -45,19 +44,16 @@ struct EnableIf<false, T> {
template <typename, typename>
struct TypesAreSame {
-
static bool const value = false;
};
template <typename A>
struct TypesAreSame<A, A> {
-
static bool const value = true;
};
template <typename B, typename D>
struct TypeInherits {
-
static D *get_d();
static char (&test(B *))[1];
@@ -262,8 +258,9 @@ struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>:
template <typename T>
inline StringName __constant_get_enum_name(T param, const String &p_constant) {
- if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL)
+ if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL) {
ERR_PRINT("Missing VARIANT_ENUM_CAST for constant's enum: " + p_constant);
+ }
return GetTypeInfo<T>::get_class_info().class_name;
}
diff --git a/core/typed_array.h b/core/typed_array.h
index 2c7b7e0384..86f26d7550 100644
--- a/core/typed_array.h
+++ b/core/typed_array.h
@@ -124,23 +124,18 @@ MAKE_TYPED_ARRAY(Vector<Color>, Variant::PACKED_COLOR_ARRAY)
template <class T>
struct PtrToArg<TypedArray<T>> {
-
_FORCE_INLINE_ static TypedArray<T> convert(const void *p_ptr) {
-
return TypedArray<T>(*reinterpret_cast<const Array *>(p_ptr));
}
_FORCE_INLINE_ static void encode(TypedArray<T> p_val, void *p_ptr) {
-
*(Array *)p_ptr = p_val;
}
};
template <class T>
struct PtrToArg<const TypedArray<T> &> {
-
_FORCE_INLINE_ static TypedArray<T> convert(const void *p_ptr) {
-
return TypedArray<T>(*reinterpret_cast<const Array *>(p_ptr));
}
};
diff --git a/core/typedefs.h b/core/typedefs.h
index bafbffcded..4bfa5debac 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -185,8 +185,9 @@ static _FORCE_INLINE_ T nearest_power_of_2_templated(T x) {
// Function to find the nearest (bigger) power of 2 to an integer.
static inline unsigned int nearest_shift(unsigned int p_number) {
for (int i = 30; i >= 0; i--) {
- if (p_number & (1 << i))
+ if (p_number & (1 << i)) {
return i + 1;
+ }
}
return 0;
diff --git a/core/ucaps.h b/core/ucaps.h
index ad71731617..79b346acba 100644
--- a/core/ucaps.h
+++ b/core/ucaps.h
@@ -1373,7 +1373,6 @@ static const int reverse_caps_table[CAPS_LEN - 1][2] = {
};
static int _find_upper(int ch) {
-
int low = 0;
int high = CAPS_LEN - 1;
int middle;
@@ -1394,7 +1393,6 @@ static int _find_upper(int ch) {
}
static int _find_lower(int ch) {
-
int low = 0;
int high = CAPS_LEN - 2;
int middle;
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index 9324dfb573..90750f2c6e 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -33,19 +33,17 @@
#include "core/os/os.h"
void UndoRedo::_discard_redo() {
-
- if (current_action == actions.size() - 1)
+ if (current_action == actions.size() - 1) {
return;
+ }
for (int i = current_action + 1; i < actions.size(); i++) {
-
for (List<Operation>::Element *E = actions.write[i].do_ops.front(); E; E = E->next()) {
-
if (E->get().type == Operation::TYPE_REFERENCE) {
-
Object *obj = ObjectDB::get_instance(E->get().object);
- if (obj)
+ if (obj) {
memdelete(obj);
+ }
}
}
//ERASE do data
@@ -55,31 +53,26 @@ void UndoRedo::_discard_redo() {
}
void UndoRedo::create_action(const String &p_name, MergeMode p_mode) {
-
uint32_t ticks = OS::get_singleton()->get_ticks_msec();
if (action_level == 0) {
-
_discard_redo();
// Check if the merge operation is valid
if (p_mode != MERGE_DISABLE && actions.size() && actions[actions.size() - 1].name == p_name && actions[actions.size() - 1].last_tick + 800 > ticks) {
-
current_action = actions.size() - 2;
if (p_mode == MERGE_ENDS) {
-
// Clear all do ops from last action, and delete all object references
List<Operation>::Element *E = actions.write[current_action + 1].do_ops.front();
while (E) {
-
if (E->get().type == Operation::TYPE_REFERENCE) {
-
Object *obj = ObjectDB::get_instance(E->get().object);
- if (obj)
+ if (obj) {
memdelete(obj);
+ }
}
E = E->next();
@@ -92,7 +85,6 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) {
merge_mode = p_mode;
merging = true;
} else {
-
Action new_action;
new_action.name = p_name;
new_action.last_tick = ticks;
@@ -106,15 +98,15 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) {
}
void UndoRedo::add_do_method(Object *p_object, const StringName &p_method, VARIANT_ARG_DECLARE) {
-
VARIANT_ARGPTRS
ERR_FAIL_COND(p_object == nullptr);
ERR_FAIL_COND(action_level <= 0);
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
do_op.type = Operation::TYPE_METHOD;
do_op.name = p_method;
@@ -126,20 +118,21 @@ void UndoRedo::add_do_method(Object *p_object, const StringName &p_method, VARIA
}
void UndoRedo::add_undo_method(Object *p_object, const StringName &p_method, VARIANT_ARG_DECLARE) {
-
VARIANT_ARGPTRS
ERR_FAIL_COND(p_object == nullptr);
ERR_FAIL_COND(action_level <= 0);
ERR_FAIL_COND((current_action + 1) >= actions.size());
// No undo if the merge mode is MERGE_ENDS
- if (merge_mode == MERGE_ENDS)
+ if (merge_mode == MERGE_ENDS) {
return;
+ }
Operation undo_op;
undo_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
undo_op.type = Operation::TYPE_METHOD;
undo_op.name = p_method;
@@ -149,87 +142,92 @@ void UndoRedo::add_undo_method(Object *p_object, const StringName &p_method, VAR
}
actions.write[current_action + 1].undo_ops.push_back(undo_op);
}
-void UndoRedo::add_do_property(Object *p_object, const StringName &p_property, const Variant &p_value) {
+void UndoRedo::add_do_property(Object *p_object, const StringName &p_property, const Variant &p_value) {
ERR_FAIL_COND(p_object == nullptr);
ERR_FAIL_COND(action_level <= 0);
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
do_op.type = Operation::TYPE_PROPERTY;
do_op.name = p_property;
do_op.args[0] = p_value;
actions.write[current_action + 1].do_ops.push_back(do_op);
}
-void UndoRedo::add_undo_property(Object *p_object, const StringName &p_property, const Variant &p_value) {
+void UndoRedo::add_undo_property(Object *p_object, const StringName &p_property, const Variant &p_value) {
ERR_FAIL_COND(p_object == nullptr);
ERR_FAIL_COND(action_level <= 0);
ERR_FAIL_COND((current_action + 1) >= actions.size());
// No undo if the merge mode is MERGE_ENDS
- if (merge_mode == MERGE_ENDS)
+ if (merge_mode == MERGE_ENDS) {
return;
+ }
Operation undo_op;
undo_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
undo_op.type = Operation::TYPE_PROPERTY;
undo_op.name = p_property;
undo_op.args[0] = p_value;
actions.write[current_action + 1].undo_ops.push_back(undo_op);
}
-void UndoRedo::add_do_reference(Object *p_object) {
+void UndoRedo::add_do_reference(Object *p_object) {
ERR_FAIL_COND(p_object == nullptr);
ERR_FAIL_COND(action_level <= 0);
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
do_op.type = Operation::TYPE_REFERENCE;
actions.write[current_action + 1].do_ops.push_back(do_op);
}
-void UndoRedo::add_undo_reference(Object *p_object) {
+void UndoRedo::add_undo_reference(Object *p_object) {
ERR_FAIL_COND(p_object == nullptr);
ERR_FAIL_COND(action_level <= 0);
ERR_FAIL_COND((current_action + 1) >= actions.size());
// No undo if the merge mode is MERGE_ENDS
- if (merge_mode == MERGE_ENDS)
+ if (merge_mode == MERGE_ENDS) {
return;
+ }
Operation undo_op;
undo_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
undo_op.type = Operation::TYPE_REFERENCE;
actions.write[current_action + 1].undo_ops.push_back(undo_op);
}
void UndoRedo::_pop_history_tail() {
-
_discard_redo();
- if (!actions.size())
+ if (!actions.size()) {
return;
+ }
for (List<Operation>::Element *E = actions.write[0].undo_ops.front(); E; E = E->next()) {
-
if (E->get().type == Operation::TYPE_REFERENCE) {
-
Object *obj = ObjectDB::get_instance(E->get().object);
- if (obj)
+ if (obj) {
memdelete(obj);
+ }
}
}
@@ -244,11 +242,11 @@ bool UndoRedo::is_committing_action() const {
}
void UndoRedo::commit_action() {
-
ERR_FAIL_COND(action_level <= 0);
action_level--;
- if (action_level > 0)
+ if (action_level > 0) {
return; //still nested
+ }
if (merging) {
version--;
@@ -264,19 +262,16 @@ void UndoRedo::commit_action() {
}
void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
-
for (; E; E = E->next()) {
-
Operation &op = E->get();
Object *obj = ObjectDB::get_instance(op.object);
- if (!obj) //may have been deleted and this is fine
+ if (!obj) { //may have been deleted and this is fine
continue;
+ }
switch (op.type) {
-
case Operation::TYPE_METHOD: {
-
Vector<const Variant *> argptrs;
argptrs.resize(VARIANT_ARG_MAX);
int argc = 0;
@@ -297,8 +292,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
}
#ifdef TOOLS_ENABLED
Resource *res = Object::cast_to<Resource>(obj);
- if (res)
+ if (res) {
res->set_edited(true);
+ }
#endif
@@ -307,12 +303,12 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
}
} break;
case Operation::TYPE_PROPERTY: {
-
obj->set(op.name, op.args[0]);
#ifdef TOOLS_ENABLED
Resource *res = Object::cast_to<Resource>(obj);
- if (res)
+ if (res) {
res->set_edited(true);
+ }
#endif
if (property_callback) {
property_callback(prop_callback_ud, obj, op.name, op.args[0]);
@@ -326,11 +322,11 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
}
bool UndoRedo::redo() {
-
ERR_FAIL_COND_V(action_level > 0, false);
- if ((current_action + 1) >= actions.size())
+ if ((current_action + 1) >= actions.size()) {
return false; //nothing to redo
+ }
current_action++;
@@ -342,10 +338,10 @@ bool UndoRedo::redo() {
}
bool UndoRedo::undo() {
-
ERR_FAIL_COND_V(action_level > 0, false);
- if (current_action < 0)
+ if (current_action < 0) {
return false; //nothing to redo
+ }
_process_operation_list(actions.write[current_action].undo_ops.front());
current_action--;
version--;
@@ -355,12 +351,12 @@ bool UndoRedo::undo() {
}
void UndoRedo::clear_history(bool p_increase_version) {
-
ERR_FAIL_COND(action_level > 0);
_discard_redo();
- while (actions.size())
+ while (actions.size()) {
_pop_history_tail();
+ }
if (p_increase_version) {
version++;
@@ -369,53 +365,45 @@ void UndoRedo::clear_history(bool p_increase_version) {
}
String UndoRedo::get_current_action_name() const {
-
ERR_FAIL_COND_V(action_level > 0, "");
- if (current_action < 0)
+ if (current_action < 0) {
return "";
+ }
return actions[current_action].name;
}
bool UndoRedo::has_undo() {
-
return current_action >= 0;
}
bool UndoRedo::has_redo() {
-
return (current_action + 1) < actions.size();
}
uint64_t UndoRedo::get_version() const {
-
return version;
}
void UndoRedo::set_commit_notify_callback(CommitNotifyCallback p_callback, void *p_ud) {
-
callback = p_callback;
callback_ud = p_ud;
}
void UndoRedo::set_method_notify_callback(MethodNotifyCallback p_method_callback, void *p_ud) {
-
method_callback = p_method_callback;
method_callbck_ud = p_ud;
}
void UndoRedo::set_property_notify_callback(PropertyNotifyCallback p_property_callback, void *p_ud) {
-
property_callback = p_property_callback;
prop_callback_ud = p_ud;
}
UndoRedo::~UndoRedo() {
-
clear_history();
}
Variant UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
-
if (p_argcount < 2) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument = 0;
@@ -444,7 +432,6 @@ Variant UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Callabl
Variant v[VARIANT_ARG_MAX];
for (int i = 0; i < MIN(VARIANT_ARG_MAX, p_argcount - 2); ++i) {
-
v[i] = *p_args[i + 2];
}
@@ -453,7 +440,6 @@ Variant UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Callabl
}
Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
-
if (p_argcount < 2) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument = 0;
@@ -482,7 +468,6 @@ Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Calla
Variant v[VARIANT_ARG_MAX];
for (int i = 0; i < MIN(VARIANT_ARG_MAX, p_argcount - 2); ++i) {
-
v[i] = *p_args[i + 2];
}
@@ -491,7 +476,6 @@ Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Calla
}
void UndoRedo::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("create_action", "name", "merge_mode"), &UndoRedo::create_action, DEFVAL(MERGE_DISABLE));
ClassDB::bind_method(D_METHOD("commit_action"), &UndoRedo::commit_action);
ClassDB::bind_method(D_METHOD("is_committing_action"), &UndoRedo::is_committing_action);
diff --git a/core/undo_redo.h b/core/undo_redo.h
index 5b74ffcbb8..b46f7ff867 100644
--- a/core/undo_redo.h
+++ b/core/undo_redo.h
@@ -35,7 +35,6 @@
#include "core/resource.h"
class UndoRedo : public Object {
-
GDCLASS(UndoRedo, Object);
OBJ_SAVE_TYPE(UndoRedo);
@@ -55,7 +54,6 @@ public:
private:
struct Operation {
-
enum Type {
TYPE_METHOD,
TYPE_PROPERTY,
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 992424f057..ed096bd475 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -69,13 +69,11 @@ bool is_symbol(CharType c) {
}
bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) {
-
const String &s = p_s;
int beg = CLAMP(p_col, 0, s.length());
int end = beg;
if (s[beg] > 32 || beg == s.length()) {
-
bool symbol = beg < s.length() && is_symbol(s[beg]);
while (beg > 0 && s[beg - 1] > 32 && (symbol == is_symbol(s[beg - 1]))) {
@@ -85,15 +83,15 @@ bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) {
end++;
}
- if (end < s.length())
+ if (end < s.length()) {
end += 1;
+ }
r_beg = beg;
r_end = end;
return true;
} else {
-
return false;
}
}
@@ -101,7 +99,6 @@ bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) {
/** STRING **/
bool CharString::operator<(const CharString &p_right) const {
-
if (length() == 0) {
return p_right.length() != 0;
}
@@ -110,7 +107,6 @@ bool CharString::operator<(const CharString &p_right) const {
}
CharString &CharString::operator+=(char p_char) {
-
resize(size() ? size() + 1 : 2);
set(length(), 0);
set(length() - 1, p_char);
@@ -119,21 +115,19 @@ CharString &CharString::operator+=(char p_char) {
}
const char *CharString::get_data() const {
-
- if (size())
+ if (size()) {
return &operator[](0);
- else
+ } else {
return "";
+ }
}
CharString &CharString::operator=(const char *p_cstr) {
-
copy_from(p_cstr);
return *this;
}
void CharString::copy_from(const char *p_cstr) {
-
if (!p_cstr) {
resize(0);
return;
@@ -154,20 +148,18 @@ void CharString::copy_from(const char *p_cstr) {
}
void String::copy_from(const char *p_cstr) {
-
if (!p_cstr) {
-
resize(0);
return;
}
int len = 0;
const char *ptr = p_cstr;
- while (*(ptr++) != 0)
+ while (*(ptr++) != 0) {
len++;
+ }
if (len == 0) {
-
resize(0);
return;
}
@@ -177,26 +169,23 @@ void String::copy_from(const char *p_cstr) {
CharType *dst = this->ptrw();
for (int i = 0; i < len + 1; i++) {
-
dst[i] = p_cstr[i];
}
}
void String::copy_from(const CharType *p_cstr, const int p_clip_to) {
-
if (!p_cstr) {
-
resize(0);
return;
}
int len = 0;
const CharType *ptr = p_cstr;
- while ((p_clip_to < 0 || len < p_clip_to) && *(ptr++) != 0)
+ while ((p_clip_to < 0 || len < p_clip_to) && *(ptr++) != 0) {
len++;
+ }
if (len == 0) {
-
resize(0);
return;
}
@@ -220,18 +209,18 @@ void String::copy_from_unchecked(const CharType *p_char, const int p_length) {
}
void String::copy_from(const CharType &p_char) {
-
resize(2);
set(0, p_char);
set(1, 0);
}
bool String::operator==(const String &p_str) const {
-
- if (length() != p_str.length())
+ if (length() != p_str.length()) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
int l = length();
@@ -240,21 +229,19 @@ bool String::operator==(const String &p_str) const {
/* Compare char by char */
for (int i = 0; i < l; i++) {
-
- if (src[i] != dst[i])
+ if (src[i] != dst[i]) {
return false;
+ }
}
return true;
}
bool String::operator!=(const String &p_str) const {
-
return !(*this == p_str);
}
String String::operator+(const String &p_str) const {
-
String res = *this;
res += p_str;
return res;
@@ -267,16 +254,17 @@ String String::operator+(CharType p_chr) const {
res+=p_chr;
return res;
}
+
*/
String &String::operator+=(const String &p_str) {
-
if (empty()) {
*this = p_str;
return *this;
}
- if (p_str.empty())
+ if (p_str.empty()) {
return *this;
+ }
int from = length();
@@ -287,20 +275,19 @@ String &String::operator+=(const String &p_str) {
set(length(), 0);
- for (int i = 0; i < p_str.length(); i++)
+ for (int i = 0; i < p_str.length(); i++) {
dst[from + i] = src[i];
+ }
return *this;
}
String &String::operator+=(const CharType *p_str) {
-
*this += String(p_str);
return *this;
}
String &String::operator+=(CharType p_char) {
-
resize(size() ? size() + 1 : 2);
set(length(), 0);
set(length() - 1, p_char);
@@ -309,14 +296,15 @@ String &String::operator+=(CharType p_char) {
}
String &String::operator+=(const char *p_str) {
-
- if (!p_str || p_str[0] == 0)
+ if (!p_str || p_str[0] == 0) {
return *this;
+ }
int src_len = 0;
const char *ptr = p_str;
- while (*(ptr++) != 0)
+ while (*(ptr++) != 0) {
src_len++;
+ }
int from = length();
@@ -326,56 +314,58 @@ String &String::operator+=(const char *p_str) {
set(length(), 0);
- for (int i = 0; i < src_len; i++)
+ for (int i = 0; i < src_len; i++) {
dst[from + i] = p_str[i];
+ }
return *this;
}
void String::operator=(const char *p_str) {
-
copy_from(p_str);
}
void String::operator=(const CharType *p_str) {
-
copy_from(p_str);
}
bool String::operator==(const StrRange &p_str_range) const {
-
int len = p_str_range.len;
- if (length() != len)
+ if (length() != len) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
const CharType *c_str = p_str_range.c_str;
const CharType *dst = &operator[](0);
/* Compare char by char */
for (int i = 0; i < len; i++) {
-
- if (c_str[i] != dst[i])
+ if (c_str[i] != dst[i]) {
return false;
+ }
}
return true;
}
bool String::operator==(const char *p_str) const {
-
int len = 0;
const char *aux = p_str;
- while (*(aux++) != 0)
+ while (*(aux++) != 0) {
len++;
+ }
- if (length() != len)
+ if (length() != len) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
int l = length();
@@ -383,26 +373,28 @@ bool String::operator==(const char *p_str) const {
/* Compare char by char */
for (int i = 0; i < l; i++) {
-
- if (p_str[i] != dst[i])
+ if (p_str[i] != dst[i]) {
return false;
+ }
}
return true;
}
bool String::operator==(const CharType *p_str) const {
-
int len = 0;
const CharType *aux = p_str;
- while (*(aux++) != 0)
+ while (*(aux++) != 0) {
len++;
+ }
- if (length() != len)
+ if (length() != len) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
int l = length();
@@ -410,78 +402,78 @@ bool String::operator==(const CharType *p_str) const {
/* Compare char by char */
for (int i = 0; i < l; i++) {
-
- if (p_str[i] != dst[i])
+ if (p_str[i] != dst[i]) {
return false;
+ }
}
return true;
}
bool String::operator!=(const char *p_str) const {
-
return (!(*this == p_str));
}
bool String::operator!=(const CharType *p_str) const {
-
return (!(*this == p_str));
}
bool String::operator<(const CharType *p_str) const {
-
- if (empty() && p_str[0] == 0)
+ if (empty() && p_str[0] == 0) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
return is_str_less(c_str(), p_str);
}
bool String::operator<=(const String &p_str) const {
-
return (*this < p_str) || (*this == p_str);
}
bool String::operator<(const char *p_str) const {
-
- if (empty() && p_str[0] == 0)
+ if (empty() && p_str[0] == 0) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
return is_str_less(c_str(), p_str);
}
bool String::operator<(const String &p_str) const {
-
return operator<(p_str.c_str());
}
signed char String::nocasecmp_to(const String &p_str) const {
-
- if (empty() && p_str.empty())
+ if (empty() && p_str.empty()) {
return 0;
- if (empty())
+ }
+ if (empty()) {
return -1;
- if (p_str.empty())
+ }
+ if (p_str.empty()) {
return 1;
+ }
const CharType *that_str = p_str.c_str();
const CharType *this_str = c_str();
while (true) {
-
- if (*that_str == 0 && *this_str == 0)
+ if (*that_str == 0 && *this_str == 0) {
return 0; //we're equal
- else if (*this_str == 0)
+ } else if (*this_str == 0) {
return -1; //if this is empty, and the other one is not, then we're less.. I think?
- else if (*that_str == 0)
+ } else if (*that_str == 0) {
return 1; //otherwise the other one is smaller..
- else if (_find_upper(*this_str) < _find_upper(*that_str)) //more than
+ } else if (_find_upper(*this_str) < _find_upper(*that_str)) { //more than
return -1;
- else if (_find_upper(*this_str) > _find_upper(*that_str)) //less than
+ } else if (_find_upper(*this_str) > _find_upper(*that_str)) { //less than
return 1;
+ }
this_str++;
that_str++;
@@ -489,29 +481,31 @@ signed char String::nocasecmp_to(const String &p_str) const {
}
signed char String::casecmp_to(const String &p_str) const {
-
- if (empty() && p_str.empty())
+ if (empty() && p_str.empty()) {
return 0;
- if (empty())
+ }
+ if (empty()) {
return -1;
- if (p_str.empty())
+ }
+ if (p_str.empty()) {
return 1;
+ }
const CharType *that_str = p_str.c_str();
const CharType *this_str = c_str();
while (true) {
-
- if (*that_str == 0 && *this_str == 0)
+ if (*that_str == 0 && *this_str == 0) {
return 0; //we're equal
- else if (*this_str == 0)
+ } else if (*this_str == 0) {
return -1; //if this is empty, and the other one is not, then we're less.. I think?
- else if (*that_str == 0)
+ } else if (*that_str == 0) {
return 1; //otherwise the other one is smaller..
- else if (*this_str < *that_str) //more than
+ } else if (*this_str < *that_str) { //more than
return -1;
- else if (*this_str > *that_str) //less than
+ } else if (*this_str > *that_str) { //less than
return 1;
+ }
this_str++;
that_str++;
@@ -519,84 +513,87 @@ signed char String::casecmp_to(const String &p_str) const {
}
signed char String::naturalnocasecmp_to(const String &p_str) const {
-
const CharType *this_str = c_str();
const CharType *that_str = p_str.c_str();
if (this_str && that_str) {
-
while (*this_str == '.' || *that_str == '.') {
- if (*this_str++ != '.')
+ if (*this_str++ != '.') {
return 1;
- if (*that_str++ != '.')
+ }
+ if (*that_str++ != '.') {
return -1;
- if (!*that_str)
+ }
+ if (!*that_str) {
return 1;
- if (!*this_str)
+ }
+ if (!*this_str) {
return -1;
+ }
}
while (*this_str) {
-
- if (!*that_str)
+ if (!*that_str) {
return 1;
- else if (IS_DIGIT(*this_str)) {
-
+ } else if (IS_DIGIT(*this_str)) {
int64_t this_int, that_int;
- if (!IS_DIGIT(*that_str))
+ if (!IS_DIGIT(*that_str)) {
return -1;
+ }
/* Compare the numbers */
this_int = to_int(this_str, -1, true);
that_int = to_int(that_str, -1, true);
- if (this_int < that_int)
+ if (this_int < that_int) {
return -1;
- else if (this_int > that_int)
+ } else if (this_int > that_int) {
return 1;
+ }
/* Skip */
- while (IS_DIGIT(*this_str))
+ while (IS_DIGIT(*this_str)) {
this_str++;
- while (IS_DIGIT(*that_str))
+ }
+ while (IS_DIGIT(*that_str)) {
that_str++;
- } else if (IS_DIGIT(*that_str))
+ }
+ } else if (IS_DIGIT(*that_str)) {
return 1;
- else {
- if (_find_upper(*this_str) < _find_upper(*that_str)) //more than
+ } else {
+ if (_find_upper(*this_str) < _find_upper(*that_str)) { //more than
return -1;
- else if (_find_upper(*this_str) > _find_upper(*that_str)) //less than
+ } else if (_find_upper(*this_str) > _find_upper(*that_str)) { //less than
return 1;
+ }
this_str++;
that_str++;
}
}
- if (*that_str)
+ if (*that_str) {
return -1;
+ }
}
return 0;
}
void String::erase(int p_pos, int p_chars) {
-
*this = left(p_pos) + substr(p_pos + p_chars, length() - ((p_pos + p_chars)));
}
String String::capitalize() const {
-
String aux = this->camelcase_to_underscore(true).replace("_", " ").strip_edges();
String cap;
for (int i = 0; i < aux.get_slice_count(" "); i++) {
-
String slice = aux.get_slicec(' ', i);
if (slice.length() > 0) {
-
slice[0] = _find_upper(slice[0]);
- if (i > 0)
+ if (i > 0) {
cap += " ";
+ }
cap += slice;
}
}
@@ -657,18 +654,19 @@ String String::get_with_code_lines() const {
}
return ret;
}
-int String::get_slice_count(String p_splitter) const {
- if (empty())
+int String::get_slice_count(String p_splitter) const {
+ if (empty()) {
return 0;
- if (p_splitter.empty())
+ }
+ if (p_splitter.empty()) {
return 0;
+ }
int pos = 0;
int slices = 1;
while ((pos = find(p_splitter, pos)) >= 0) {
-
slices++;
pos += p_splitter.length();
}
@@ -677,35 +675,37 @@ int String::get_slice_count(String p_splitter) const {
}
String String::get_slice(String p_splitter, int p_slice) const {
-
- if (empty() || p_splitter.empty())
+ if (empty() || p_splitter.empty()) {
return "";
+ }
int pos = 0;
int prev_pos = 0;
//int slices=1;
- if (p_slice < 0)
+ if (p_slice < 0) {
return "";
- if (find(p_splitter) == -1)
+ }
+ if (find(p_splitter) == -1) {
return *this;
+ }
int i = 0;
while (true) {
-
pos = find(p_splitter, pos);
- if (pos == -1)
+ if (pos == -1) {
pos = length(); //reached end
+ }
int from = prev_pos;
//int to=pos;
if (p_slice == i) {
-
return substr(from, pos - from);
}
- if (pos == length()) //reached end and no find
+ if (pos == length()) { //reached end and no find
break;
+ }
pos += p_splitter.length();
prev_pos = pos;
i++;
@@ -715,23 +715,21 @@ String String::get_slice(String p_splitter, int p_slice) const {
}
String String::get_slicec(CharType p_splitter, int p_slice) const {
-
- if (empty())
+ if (empty()) {
return String();
+ }
- if (p_slice < 0)
+ if (p_slice < 0) {
return String();
+ }
const CharType *c = this->ptr();
int i = 0;
int prev = 0;
int count = 0;
while (true) {
-
if (c[i] == 0 || c[i] == p_splitter) {
-
if (p_slice == count) {
-
return substr(prev, i - prev);
} else if (c[i] == 0) {
return String();
@@ -746,22 +744,22 @@ String String::get_slicec(CharType p_splitter, int p_slice) const {
}
Vector<String> String::split_spaces() const {
-
Vector<String> ret;
int from = 0;
int i = 0;
int len = length();
- if (len == 0)
+ if (len == 0) {
return ret;
+ }
bool inside = false;
while (true) {
-
bool empty = operator[](i) < 33;
- if (i == 0)
+ if (i == 0) {
inside = !empty;
+ }
if (!empty && !inside) {
inside = true;
@@ -769,13 +767,13 @@ Vector<String> String::split_spaces() const {
}
if (empty && inside) {
-
ret.push_back(substr(from, i - from));
inside = false;
}
- if (i == len)
+ if (i == len) {
break;
+ }
i++;
}
@@ -783,21 +781,19 @@ Vector<String> String::split_spaces() const {
}
Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p_maxsplit) const {
-
Vector<String> ret;
int from = 0;
int len = length();
while (true) {
-
int end = find(p_splitter, from);
- if (end < 0)
+ if (end < 0) {
end = len;
+ }
if (p_allow_empty || (end > from)) {
- if (p_maxsplit <= 0)
+ if (p_maxsplit <= 0) {
ret.push_back(substr(from, end - from));
- else {
-
+ } else {
// Put rest of the string and leave cycle.
if (p_maxsplit == ret.size()) {
ret.push_back(substr(from, len));
@@ -809,8 +805,9 @@ Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p
}
}
- if (end == len)
+ if (end == len) {
break;
+ }
from = end + p_splitter.length();
}
@@ -819,13 +816,11 @@ Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p
}
Vector<String> String::rsplit(const String &p_splitter, bool p_allow_empty, int p_maxsplit) const {
-
Vector<String> ret;
const int len = length();
int remaining_len = len;
while (true) {
-
if (remaining_len < p_splitter.length() || (p_maxsplit > 0 && p_maxsplit == ret.size())) {
// no room for another splitter or hit max splits, push what's left and we're done
if (p_allow_empty || remaining_len > 0) {
@@ -855,21 +850,22 @@ Vector<String> String::rsplit(const String &p_splitter, bool p_allow_empty, int
}
Vector<float> String::split_floats(const String &p_splitter, bool p_allow_empty) const {
-
Vector<float> ret;
int from = 0;
int len = length();
while (true) {
-
int end = find(p_splitter, from);
- if (end < 0)
+ if (end < 0) {
end = len;
- if (p_allow_empty || (end > from))
+ }
+ if (p_allow_empty || (end > from)) {
ret.push_back(String::to_double(&c_str()[from]));
+ }
- if (end == len)
+ if (end == len) {
break;
+ }
from = end + p_splitter.length();
}
@@ -878,13 +874,11 @@ Vector<float> String::split_floats(const String &p_splitter, bool p_allow_empty)
}
Vector<float> String::split_floats_mk(const Vector<String> &p_splitters, bool p_allow_empty) const {
-
Vector<float> ret;
int from = 0;
int len = length();
while (true) {
-
int idx;
int end = findmk(p_splitters, from, &idx);
int spl_len = 1;
@@ -898,8 +892,9 @@ Vector<float> String::split_floats_mk(const Vector<String> &p_splitters, bool p_
ret.push_back(String::to_double(&c_str()[from]));
}
- if (end == len)
+ if (end == len) {
break;
+ }
from = end + spl_len;
}
@@ -908,21 +903,22 @@ Vector<float> String::split_floats_mk(const Vector<String> &p_splitters, bool p_
}
Vector<int> String::split_ints(const String &p_splitter, bool p_allow_empty) const {
-
Vector<int> ret;
int from = 0;
int len = length();
while (true) {
-
int end = find(p_splitter, from);
- if (end < 0)
+ if (end < 0) {
end = len;
- if (p_allow_empty || (end > from))
+ }
+ if (p_allow_empty || (end > from)) {
ret.push_back(String::to_int(&c_str()[from], end - from));
+ }
- if (end == len)
+ if (end == len) {
break;
+ }
from = end + p_splitter.length();
}
@@ -931,13 +927,11 @@ Vector<int> String::split_ints(const String &p_splitter, bool p_allow_empty) con
}
Vector<int> String::split_ints_mk(const Vector<String> &p_splitters, bool p_allow_empty) const {
-
Vector<int> ret;
int from = 0;
int len = length();
while (true) {
-
int idx;
int end = findmk(p_splitters, from, &idx);
int spl_len = 1;
@@ -947,11 +941,13 @@ Vector<int> String::split_ints_mk(const Vector<String> &p_splitters, bool p_allo
spl_len = p_splitters[idx].length();
}
- if (p_allow_empty || (end > from))
+ if (p_allow_empty || (end > from)) {
ret.push_back(String::to_int(&c_str()[from], end - from));
+ }
- if (end == len)
+ if (end == len) {
break;
+ }
from = end + spl_len;
}
@@ -971,47 +967,42 @@ String String::join(Vector<String> parts) {
}
CharType String::char_uppercase(CharType p_char) {
-
return _find_upper(p_char);
}
CharType String::char_lowercase(CharType p_char) {
-
return _find_lower(p_char);
}
String String::to_upper() const {
-
String upper = *this;
for (int i = 0; i < upper.size(); i++) {
-
const CharType s = upper[i];
const CharType t = _find_upper(s);
- if (s != t) // avoid copy on write
+ if (s != t) { // avoid copy on write
upper[i] = t;
+ }
}
return upper;
}
String String::to_lower() const {
-
String lower = *this;
for (int i = 0; i < lower.size(); i++) {
-
const CharType s = lower[i];
const CharType t = _find_lower(s);
- if (s != t) // avoid copy on write
+ if (s != t) { // avoid copy on write
lower[i] = t;
+ }
}
return lower;
}
const CharType *String::c_str() const {
-
static const CharType zero = 0;
return size() ? &operator[](0) : &zero;
@@ -1038,23 +1029,22 @@ String String::hex_encode_buffer(const uint8_t *p_buffer, int p_len) {
}
String String::chr(CharType p_char) {
-
CharType c[2] = { p_char, 0 };
return String(c);
}
-String String::num(double p_num, int p_decimals) {
+String String::num(double p_num, int p_decimals) {
#ifndef NO_USE_STDLIB
- if (p_decimals > 16)
+ if (p_decimals > 16) {
p_decimals = 16;
+ }
char fmt[7];
fmt[0] = '%';
fmt[1] = '.';
if (p_decimals < 0) {
-
fmt[1] = 'l';
fmt[2] = 'f';
fmt[3] = 0;
@@ -1082,28 +1072,24 @@ String String::num(double p_num, int p_decimals) {
buf[255] = 0;
//destroy trailing zeroes
{
-
bool period = false;
int z = 0;
while (buf[z]) {
- if (buf[z] == '.')
+ if (buf[z] == '.') {
period = true;
+ }
z++;
}
if (period) {
z--;
while (z > 0) {
-
if (buf[z] == '0') {
-
buf[z] = 0;
} else if (buf[z] == '.') {
-
buf[z] = 0;
break;
} else {
-
break;
}
@@ -1126,7 +1112,6 @@ String String::num(double p_num, int p_decimals) {
/* decimal part */
if (p_decimals > 0 || (p_decimals == -1 && (int)p_num != p_num)) {
-
double dec = p_num - (float)((int)p_num);
int digit = 0;
@@ -1137,14 +1122,12 @@ String String::num(double p_num, int p_decimals) {
int dec_max = 0;
while (true) {
-
dec *= 10.0;
dec_int = dec_int * 10 + (int)dec % 10;
dec_max = dec_max * 10 + 9;
digit++;
if (p_decimals == -1) {
-
if (digit == MAX_DIGITS) //no point in going to infinite
break;
@@ -1160,18 +1143,15 @@ String String::num(double p_num, int p_decimals) {
if (last > 5) {
if (dec_int == dec_max) {
-
dec_int = 0;
intn++;
} else {
-
dec_int++;
}
}
String decimal;
for (int i = 0; i < digit; i++) {
-
char num[2] = { 0, 0 };
num[0] = '0' + dec_int % 10;
decimal = num + decimal;
@@ -1185,7 +1165,6 @@ String String::num(double p_num, int p_decimals) {
s = "0";
else {
while (intn) {
-
CharType num = '0' + (intn % 10);
intn /= 10;
s = num + s;
@@ -1200,7 +1179,6 @@ String String::num(double p_num, int p_decimals) {
}
String String::num_int64(int64_t p_num, int base, bool capitalize_hex) {
-
bool sign = p_num < 0;
int64_t n = p_num;
@@ -1211,8 +1189,9 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) {
chars++;
} while (n);
- if (sign)
+ if (sign) {
chars++;
+ }
String s;
s.resize(chars + 1);
CharType *c = s.ptrw();
@@ -1230,14 +1209,14 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) {
n /= base;
} while (n);
- if (sign)
+ if (sign) {
c[0] = '-';
+ }
return s;
}
String String::num_uint64(uint64_t p_num, int base, bool capitalize_hex) {
-
uint64_t n = p_num;
int chars = 0;
@@ -1267,7 +1246,6 @@ String String::num_uint64(uint64_t p_num, int base, bool capitalize_hex) {
}
String String::num_real(double p_num) {
-
String s;
String sd;
/* integer part */
@@ -1279,7 +1257,6 @@ String String::num_real(double p_num) {
/* decimal part */
if ((int)p_num != p_num) {
-
double dec = p_num - (float)((int)p_num);
int digit = 0;
@@ -1289,17 +1266,18 @@ String String::num_real(double p_num) {
int dec_max = 0;
while (true) {
-
dec *= 10.0;
dec_int = dec_int * 10 + (int)dec % 10;
dec_max = dec_max * 10 + 9;
digit++;
- if ((dec - (float)((int)dec)) < 1e-6)
+ if ((dec - (float)((int)dec)) < 1e-6) {
break;
+ }
- if (digit == decimals)
+ if (digit == decimals) {
break;
+ }
}
dec *= 10;
@@ -1307,18 +1285,15 @@ String String::num_real(double p_num) {
if (last > 5) {
if (dec_int == dec_max) {
-
dec_int = 0;
intn++;
} else {
-
dec_int++;
}
}
String decimal;
for (int i = 0; i < digit; i++) {
-
char num[2] = { 0, 0 };
num[0] = '0' + dec_int % 10;
decimal = num + decimal;
@@ -1329,12 +1304,10 @@ String String::num_real(double p_num) {
sd = ".0";
}
- if (intn == 0)
-
+ if (intn == 0) {
s = "0";
- else {
+ } else {
while (intn) {
-
CharType num = '0' + (intn % 10);
intn /= 10;
s = num + s;
@@ -1342,13 +1315,13 @@ String String::num_real(double p_num) {
}
s = s + sd;
- if (neg)
+ if (neg) {
s = "-" + s;
+ }
return s;
}
String String::num_scientific(double p_num) {
-
#ifndef NO_USE_STDLIB
char buf[256];
@@ -1379,21 +1352,21 @@ String String::num_scientific(double p_num) {
}
CharString String::ascii(bool p_allow_extended) const {
-
- if (!length())
+ if (!length()) {
return CharString();
+ }
CharString cs;
cs.resize(size());
- for (int i = 0; i < size(); i++)
+ for (int i = 0; i < size(); i++) {
cs[i] = operator[](i);
+ }
return cs;
}
String String::utf8(const char *p_utf8, int p_len) {
-
String ret;
ret.parse_utf8(p_utf8, p_len);
@@ -1401,11 +1374,11 @@ String String::utf8(const char *p_utf8, int p_len) {
};
bool String::parse_utf8(const char *p_utf8, int p_len) {
-
#define _UNICERROR(m_err) print_line("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-8?");
- if (!p_utf8)
+ if (!p_utf8) {
return true;
+ }
String aux;
@@ -1414,13 +1387,12 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
/* HANDLE BOM (Byte Order Mark) */
if (p_len < 0 || p_len >= 3) {
-
bool has_bom = uint8_t(p_utf8[0]) == 0xEF && uint8_t(p_utf8[1]) == 0xBB && uint8_t(p_utf8[2]) == 0xBF;
if (has_bom) {
-
//just skip it
- if (p_len >= 0)
+ if (p_len >= 0) {
p_len -= 3;
+ }
p_utf8 += 3;
}
}
@@ -1430,25 +1402,23 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
const char *ptrtmp_limit = &p_utf8[p_len];
int skip = 0;
while (ptrtmp != ptrtmp_limit && *ptrtmp) {
-
if (skip == 0) {
-
uint8_t c = *ptrtmp >= 0 ? *ptrtmp : uint8_t(256 + *ptrtmp);
/* Determine the number of characters in sequence */
- if ((c & 0x80) == 0)
+ if ((c & 0x80) == 0) {
skip = 0;
- else if ((c & 0xE0) == 0xC0)
+ } else if ((c & 0xE0) == 0xC0) {
skip = 1;
- else if ((c & 0xF0) == 0xE0)
+ } else if ((c & 0xF0) == 0xE0) {
skip = 2;
- else if ((c & 0xF8) == 0xF0)
+ } else if ((c & 0xF8) == 0xF0) {
skip = 3;
- else if ((c & 0xFC) == 0xF8)
+ } else if ((c & 0xFC) == 0xF8) {
skip = 4;
- else if ((c & 0xFE) == 0xFC)
+ } else if ((c & 0xFE) == 0xFC) {
skip = 5;
- else {
+ } else {
_UNICERROR("invalid skip");
return true; //invalid utf8
}
@@ -1462,7 +1432,6 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
str_size++;
} else {
-
--skip;
}
@@ -1486,23 +1455,22 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
dst[str_size] = 0;
while (cstr_size) {
-
int len = 0;
/* Determine the number of characters in sequence */
- if ((*p_utf8 & 0x80) == 0)
+ if ((*p_utf8 & 0x80) == 0) {
len = 1;
- else if ((*p_utf8 & 0xE0) == 0xC0)
+ } else if ((*p_utf8 & 0xE0) == 0xC0) {
len = 2;
- else if ((*p_utf8 & 0xF0) == 0xE0)
+ } else if ((*p_utf8 & 0xF0) == 0xE0) {
len = 3;
- else if ((*p_utf8 & 0xF8) == 0xF0)
+ } else if ((*p_utf8 & 0xF8) == 0xF0) {
len = 4;
- else if ((*p_utf8 & 0xFC) == 0xF8)
+ } else if ((*p_utf8 & 0xFC) == 0xF8) {
len = 5;
- else if ((*p_utf8 & 0xFE) == 0xFC)
+ } else if ((*p_utf8 & 0xFE) == 0xFC) {
len = 6;
- else {
+ } else {
_UNICERROR("invalid len");
return true; //invalid UTF8
@@ -1523,14 +1491,12 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
uint32_t unichar = 0;
- if (len == 1)
+ if (len == 1) {
unichar = *p_utf8;
- else {
-
+ } else {
unichar = (0xFF >> (len + 1)) & *p_utf8;
for (int i = 1; i < len; i++) {
-
if ((p_utf8[i] & 0xC0) != 0x80) {
_UNICERROR("invalid utf8");
return true; //invalid utf8
@@ -1557,19 +1523,18 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
}
CharString String::utf8() const {
-
int l = length();
- if (!l)
+ if (!l) {
return CharString();
+ }
const CharType *d = &operator[](0);
int fl = 0;
for (int i = 0; i < l; i++) {
-
uint32_t c = d[i];
- if (c <= 0x7f) // 7 bits.
+ if (c <= 0x7f) { // 7 bits.
fl += 1;
- else if (c <= 0x7ff) { // 11 bits
+ } else if (c <= 0x7ff) { // 11 bits
fl += 2;
} else if (c <= 0xffff) { // 16 bits
fl += 3;
@@ -1594,12 +1559,11 @@ CharString String::utf8() const {
#define APPEND_CHAR(m_c) *(cdst++) = m_c
for (int i = 0; i < l; i++) {
-
uint32_t c = d[i];
- if (c <= 0x7f) // 7 bits.
+ if (c <= 0x7f) { // 7 bits.
APPEND_CHAR(c);
- else if (c <= 0x7ff) { // 11 bits
+ } else if (c <= 0x7ff) { // 11 bits
APPEND_CHAR(uint32_t(0xc0 | ((c >> 6) & 0x1f))); // Top 5 bits.
APPEND_CHAR(uint32_t(0x80 | (c & 0x3f))); // Bottom 6 bits.
@@ -1643,30 +1607,29 @@ String::String(CharType p_char) {
shared=nullptr;
copy_from(p_char);
}
+
*/
String::String(const char *p_str) {
-
copy_from(p_str);
}
String::String(const CharType *p_str, int p_clip_to_len) {
-
copy_from(p_str, p_clip_to_len);
}
String::String(const StrRange &p_range) {
-
- if (!p_range.c_str)
+ if (!p_range.c_str) {
return;
+ }
copy_from(p_range.c_str, p_range.len);
}
int String::hex_to_int(bool p_with_prefix) const {
-
- if (p_with_prefix && length() < 3)
+ if (p_with_prefix && length() < 3) {
return 0;
+ }
const CharType *s = ptr();
@@ -1677,15 +1640,15 @@ int String::hex_to_int(bool p_with_prefix) const {
}
if (p_with_prefix) {
- if (s[0] != '0' || s[1] != 'x')
+ if (s[0] != '0' || s[1] != 'x') {
return 0;
+ }
s += 2;
}
int hex = 0;
while (*s) {
-
CharType c = LOWERCASE(*s);
int n;
if (c >= '0' && c <= '9') {
@@ -1706,9 +1669,9 @@ int String::hex_to_int(bool p_with_prefix) const {
}
int64_t String::hex_to_int64(bool p_with_prefix) const {
-
- if (p_with_prefix && length() < 3)
+ if (p_with_prefix && length() < 3) {
return 0;
+ }
const CharType *s = ptr();
@@ -1719,15 +1682,15 @@ int64_t String::hex_to_int64(bool p_with_prefix) const {
}
if (p_with_prefix) {
- if (s[0] != '0' || s[1] != 'x')
+ if (s[0] != '0' || s[1] != 'x') {
return 0;
+ }
s += 2;
}
int64_t hex = 0;
while (*s) {
-
CharType c = LOWERCASE(*s);
int64_t n;
if (c >= '0' && c <= '9') {
@@ -1748,9 +1711,9 @@ int64_t String::hex_to_int64(bool p_with_prefix) const {
}
int64_t String::bin_to_int64(bool p_with_prefix) const {
-
- if (p_with_prefix && length() < 3)
+ if (p_with_prefix && length() < 3) {
return 0;
+ }
const CharType *s = ptr();
@@ -1761,15 +1724,15 @@ int64_t String::bin_to_int64(bool p_with_prefix) const {
}
if (p_with_prefix) {
- if (s[0] != '0' || s[1] != 'b')
+ if (s[0] != '0' || s[1] != 'b') {
return 0;
+ }
s += 2;
}
int64_t binary = 0;
while (*s) {
-
CharType c = LOWERCASE(*s);
int64_t n;
if (c == '0' || c == '1') {
@@ -1788,9 +1751,9 @@ int64_t String::bin_to_int64(bool p_with_prefix) const {
}
int String::to_int() const {
-
- if (length() == 0)
+ if (length() == 0) {
return 0;
+ }
int to = (find(".") >= 0) ? find(".") : length();
@@ -1798,16 +1761,13 @@ int String::to_int() const {
int sign = 1;
for (int i = 0; i < to; i++) {
-
CharType c = operator[](i);
if (c >= '0' && c <= '9') {
-
ERR_FAIL_COND_V_MSG(integer > INT32_MAX / 10, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + *this + " as integer, provided value is " + (sign == 1 ? "too big." : "too small."));
integer *= 10;
integer += c - '0';
} else if (integer == 0 && c == '-') {
-
sign = -sign;
}
}
@@ -1816,9 +1776,9 @@ int String::to_int() const {
}
int64_t String::to_int64() const {
-
- if (length() == 0)
+ if (length() == 0) {
return 0;
+ }
int to = (find(".") >= 0) ? find(".") : length();
@@ -1826,16 +1786,13 @@ int64_t String::to_int64() const {
int64_t sign = 1;
for (int i = 0; i < to; i++) {
-
CharType c = operator[](i);
if (c >= '0' && c <= '9') {
-
ERR_FAIL_COND_V_MSG(integer > INT64_MAX / 10, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as 64-bit integer, provided value is " + (sign == 1 ? "too big." : "too small."));
integer *= 10;
integer += c - '0';
} else if (integer == 0 && c == '-') {
-
sign = -sign;
}
}
@@ -1844,49 +1801,46 @@ int64_t String::to_int64() const {
}
int String::to_int(const char *p_str, int p_len) {
-
int to = 0;
- if (p_len >= 0)
+ if (p_len >= 0) {
to = p_len;
- else {
- while (p_str[to] != 0 && p_str[to] != '.')
+ } else {
+ while (p_str[to] != 0 && p_str[to] != '.') {
to++;
+ }
}
int integer = 0;
int sign = 1;
for (int i = 0; i < to; i++) {
-
char c = p_str[i];
if (c >= '0' && c <= '9') {
-
ERR_FAIL_COND_V_MSG(integer > INT32_MAX / 10, sign == 1 ? INT32_MAX : INT32_MIN, "Cannot represent " + String(p_str).substr(0, to) + " as integer, provided value is " + (sign == 1 ? "too big." : "too small."));
integer *= 10;
integer += c - '0';
} else if (c == '-' && integer == 0) {
-
sign = -sign;
- } else if (c != ' ')
+ } else if (c != ' ') {
break;
+ }
}
return integer * sign;
}
bool String::is_numeric() const {
-
if (length() == 0) {
return false;
};
int s = 0;
- if (operator[](0) == '-')
+ if (operator[](0) == '-') {
++s;
+ }
bool dot = false;
for (int i = s; i < length(); i++) {
-
CharType c = operator[](i);
if (c == '.') {
if (dot) {
@@ -1917,7 +1871,6 @@ static double built_in_strtod(const C *string, /* A decimal ASCII floating-point
C **endPtr = nullptr) /* If non-nullptr, store terminating Cacter's
* address here. */
{
-
static const int maxExponent = 511; /* Largest possible base 10 exponent. Any
* exponent larger than this will already
* produce underflow or overflow, so there's
@@ -2119,7 +2072,6 @@ done:
#define READING_DONE 4
double String::to_double(const char *p_str) {
-
#ifndef NO_USE_STDLIB
return built_in_strtod<char>(p_str);
//return atof(p_str); DOES NOT WORK ON ANDROID(??)
@@ -2129,19 +2081,17 @@ double String::to_double(const char *p_str) {
}
float String::to_float() const {
-
return to_double();
}
double String::to_double(const CharType *p_str, const CharType **r_end) {
-
return built_in_strtod<CharType>(p_str, (CharType **)r_end);
}
int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) {
-
- if (p_len == 0 || !p_str[0])
+ if (p_len == 0 || !p_str[0]) {
return 0;
+ }
///@todo make more exact so saving and loading does not lose precision
int64_t integer = 0;
@@ -2152,7 +2102,6 @@ int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) {
const CharType *limit = &p_str[p_len];
while (*str && reading != READING_DONE && str != limit) {
-
CharType c = *(str++);
switch (reading) {
case READING_SIGN: {
@@ -2173,9 +2122,7 @@ int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) {
[[fallthrough]];
}
case READING_INT: {
-
if (c >= '0' && c <= '9') {
-
if (integer > INT64_MAX / 10) {
String number("");
str = p_str;
@@ -2206,9 +2153,9 @@ int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) {
}
double String::to_double() const {
-
- if (empty())
+ if (empty()) {
return 0;
+ }
#ifndef NO_USE_STDLIB
return built_in_strtod<CharType>(c_str());
//return wcstod(c_str(),nullptr ); DOES NOT WORK ON ANDROID :(
@@ -2218,91 +2165,88 @@ double String::to_double() const {
}
bool operator==(const char *p_chr, const String &p_str) {
-
return p_str == p_chr;
}
String operator+(const char *p_chr, const String &p_str) {
-
String tmp = p_chr;
tmp += p_str;
return tmp;
}
-String operator+(CharType p_chr, const String &p_str) {
+String operator+(CharType p_chr, const String &p_str) {
return (String::chr(p_chr) + p_str);
}
uint32_t String::hash(const char *p_cstr) {
-
uint32_t hashv = 5381;
uint32_t c;
- while ((c = *p_cstr++))
+ while ((c = *p_cstr++)) {
hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */
+ }
return hashv;
}
uint32_t String::hash(const char *p_cstr, int p_len) {
-
uint32_t hashv = 5381;
- for (int i = 0; i < p_len; i++)
+ for (int i = 0; i < p_len; i++) {
hashv = ((hashv << 5) + hashv) + p_cstr[i]; /* hash * 33 + c */
+ }
return hashv;
}
uint32_t String::hash(const CharType *p_cstr, int p_len) {
-
uint32_t hashv = 5381;
- for (int i = 0; i < p_len; i++)
+ for (int i = 0; i < p_len; i++) {
hashv = ((hashv << 5) + hashv) + p_cstr[i]; /* hash * 33 + c */
+ }
return hashv;
}
uint32_t String::hash(const CharType *p_cstr) {
-
uint32_t hashv = 5381;
uint32_t c;
- while ((c = *p_cstr++))
+ while ((c = *p_cstr++)) {
hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */
+ }
return hashv;
}
uint32_t String::hash() const {
-
/* simple djb2 hashing */
const CharType *chr = c_str();
uint32_t hashv = 5381;
uint32_t c;
- while ((c = *chr++))
+ while ((c = *chr++)) {
hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */
+ }
return hashv;
}
uint64_t String::hash64() const {
-
/* simple djb2 hashing */
const CharType *chr = c_str();
uint64_t hashv = 5381;
uint64_t c;
- while ((c = *chr++))
+ while ((c = *chr++)) {
hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */
+ }
return hashv;
}
String String::md5_text() const {
-
CharString cs = utf8();
unsigned char hash[16];
CryptoCore::md5((unsigned char *)cs.ptr(), cs.length(), hash);
@@ -2324,7 +2268,6 @@ String String::sha256_text() const {
}
Vector<uint8_t> String::md5_buffer() const {
-
CharString cs = utf8();
unsigned char hash[16];
CryptoCore::md5((unsigned char *)cs.ptr(), cs.length(), hash);
@@ -2365,38 +2308,41 @@ Vector<uint8_t> String::sha256_buffer() const {
}
String String::insert(int p_at_pos, const String &p_string) const {
-
- if (p_at_pos < 0)
+ if (p_at_pos < 0) {
return *this;
+ }
- if (p_at_pos > length())
+ if (p_at_pos > length()) {
p_at_pos = length();
+ }
String pre;
- if (p_at_pos > 0)
+ if (p_at_pos > 0) {
pre = substr(0, p_at_pos);
+ }
String post;
- if (p_at_pos < length())
+ if (p_at_pos < length()) {
post = substr(p_at_pos, length() - p_at_pos);
+ }
return pre + p_string + post;
}
-String String::substr(int p_from, int p_chars) const {
- if (p_chars == -1)
+String String::substr(int p_from, int p_chars) const {
+ if (p_chars == -1) {
p_chars = length() - p_from;
+ }
- if (empty() || p_from < 0 || p_from >= length() || p_chars <= 0)
+ if (empty() || p_from < 0 || p_from >= length() || p_chars <= 0) {
return "";
+ }
if ((p_from + p_chars) > length()) {
-
p_chars = length() - p_from;
}
if (p_from == 0 && p_chars >= length()) {
-
return String(*this);
}
@@ -2406,12 +2352,10 @@ String String::substr(int p_from, int p_chars) const {
}
int String::find_last(const String &p_str) const {
-
int pos = -1;
int findfrom = 0;
int findres = -1;
while ((findres = find(p_str, findfrom)) != -1) {
-
pos = findres;
findfrom = pos + 1;
}
@@ -2420,29 +2364,27 @@ int String::find_last(const String &p_str) const {
}
int String::find(const String &p_str, int p_from) const {
-
- if (p_from < 0)
+ if (p_from < 0) {
return -1;
+ }
const int src_len = p_str.length();
const int len = length();
- if (src_len == 0 || len == 0)
+ if (src_len == 0 || len == 0) {
return -1; // won't find anything!
+ }
const CharType *src = c_str();
const CharType *str = p_str.c_str();
for (int i = p_from; i <= (len - src_len); i++) {
-
bool found = true;
for (int j = 0; j < src_len; j++) {
-
int read_pos = i + j;
if (read_pos >= len) {
-
ERR_PRINT("read_pos>=len");
return -1;
};
@@ -2453,51 +2395,48 @@ int String::find(const String &p_str, int p_from) const {
}
}
- if (found)
+ if (found) {
return i;
+ }
}
return -1;
}
int String::find(const char *p_str, int p_from) const {
-
- if (p_from < 0)
+ if (p_from < 0) {
return -1;
+ }
const int len = length();
- if (len == 0)
+ if (len == 0) {
return -1; // won't find anything!
+ }
const CharType *src = c_str();
int src_len = 0;
- while (p_str[src_len] != '\0')
+ while (p_str[src_len] != '\0') {
src_len++;
+ }
if (src_len == 1) {
-
const char needle = p_str[0];
for (int i = p_from; i < len; i++) {
-
if (src[i] == needle) {
return i;
}
}
} else {
-
for (int i = p_from; i <= (len - src_len); i++) {
-
bool found = true;
for (int j = 0; j < src_len; j++) {
-
int read_pos = i + j;
if (read_pos >= len) {
-
ERR_PRINT("read_pos>=len");
return -1;
};
@@ -2508,8 +2447,9 @@ int String::find(const char *p_str, int p_from) const {
}
}
- if (found)
+ if (found) {
return i;
+ }
}
}
@@ -2521,39 +2461,38 @@ int String::find_char(const CharType &p_char, int p_from) const {
}
int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const {
-
- if (p_from < 0)
+ if (p_from < 0) {
return -1;
- if (p_keys.size() == 0)
+ }
+ if (p_keys.size() == 0) {
return -1;
+ }
//int src_len=p_str.length();
const String *keys = &p_keys[0];
int key_count = p_keys.size();
int len = length();
- if (len == 0)
+ if (len == 0) {
return -1; // won't find anything!
+ }
const CharType *src = c_str();
for (int i = p_from; i < len; i++) {
-
bool found = true;
for (int k = 0; k < key_count; k++) {
-
found = true;
- if (r_key)
+ if (r_key) {
*r_key = k;
+ }
const CharType *cmp = keys[k].c_str();
int l = keys[k].length();
for (int j = 0; j < l; j++) {
-
int read_pos = i + j;
if (read_pos >= len) {
-
found = false;
break;
};
@@ -2563,38 +2502,38 @@ int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const {
break;
}
}
- if (found)
+ if (found) {
break;
+ }
}
- if (found)
+ if (found) {
return i;
+ }
}
return -1;
}
int String::findn(const String &p_str, int p_from) const {
-
- if (p_from < 0)
+ if (p_from < 0) {
return -1;
+ }
int src_len = p_str.length();
- if (src_len == 0 || length() == 0)
+ if (src_len == 0 || length() == 0) {
return -1; // won't find anything!
+ }
const CharType *srcd = c_str();
for (int i = p_from; i <= (length() - src_len); i++) {
-
bool found = true;
for (int j = 0; j < src_len; j++) {
-
int read_pos = i + j;
if (read_pos >= length()) {
-
ERR_PRINT("read_pos>=length()");
return -1;
};
@@ -2608,43 +2547,43 @@ int String::findn(const String &p_str, int p_from) const {
}
}
- if (found)
+ if (found) {
return i;
+ }
}
return -1;
}
int String::rfind(const String &p_str, int p_from) const {
-
// establish a limit
int limit = length() - p_str.length();
- if (limit < 0)
+ if (limit < 0) {
return -1;
+ }
// establish a starting point
- if (p_from < 0)
+ if (p_from < 0) {
p_from = limit;
- else if (p_from > limit)
+ } else if (p_from > limit) {
p_from = limit;
+ }
int src_len = p_str.length();
int len = length();
- if (src_len == 0 || len == 0)
+ if (src_len == 0 || len == 0) {
return -1; // won't find anything!
+ }
const CharType *src = c_str();
for (int i = p_from; i >= 0; i--) {
-
bool found = true;
for (int j = 0; j < src_len; j++) {
-
int read_pos = i + j;
if (read_pos >= len) {
-
ERR_PRINT("read_pos>=len");
return -1;
};
@@ -2655,42 +2594,43 @@ int String::rfind(const String &p_str, int p_from) const {
}
}
- if (found)
+ if (found) {
return i;
+ }
}
return -1;
}
-int String::rfindn(const String &p_str, int p_from) const {
+int String::rfindn(const String &p_str, int p_from) const {
// establish a limit
int limit = length() - p_str.length();
- if (limit < 0)
+ if (limit < 0) {
return -1;
+ }
// establish a starting point
- if (p_from < 0)
+ if (p_from < 0) {
p_from = limit;
- else if (p_from > limit)
+ } else if (p_from > limit) {
p_from = limit;
+ }
int src_len = p_str.length();
int len = length();
- if (src_len == 0 || len == 0)
+ if (src_len == 0 || len == 0) {
return -1; // won't find anything!
+ }
const CharType *src = c_str();
for (int i = p_from; i >= 0; i--) {
-
bool found = true;
for (int j = 0; j < src_len; j++) {
-
int read_pos = i + j;
if (read_pos >= len) {
-
ERR_PRINT("read_pos>=len");
return -1;
};
@@ -2704,56 +2644,59 @@ int String::rfindn(const String &p_str, int p_from) const {
}
}
- if (found)
+ if (found) {
return i;
+ }
}
return -1;
}
bool String::ends_with(const String &p_string) const {
-
int pos = find_last(p_string);
- if (pos == -1)
+ if (pos == -1) {
return false;
+ }
return pos + p_string.length() == length();
}
bool String::begins_with(const String &p_string) const {
-
- if (p_string.length() > length())
+ if (p_string.length() > length()) {
return false;
+ }
int l = p_string.length();
- if (l == 0)
+ if (l == 0) {
return true;
+ }
const CharType *src = &p_string[0];
const CharType *str = &operator[](0);
int i = 0;
for (; i < l; i++) {
-
- if (src[i] != str[i])
+ if (src[i] != str[i]) {
return false;
+ }
}
// only if i == l the p_string matches the beginning
return i == l;
}
-bool String::begins_with(const char *p_string) const {
+bool String::begins_with(const char *p_string) const {
int l = length();
- if (l == 0 || !p_string)
+ if (l == 0 || !p_string) {
return false;
+ }
const CharType *str = &operator[](0);
int i = 0;
while (*p_string && i < l) {
-
- if (*p_string != str[i])
+ if (*p_string != str[i]) {
return false;
+ }
i++;
p_string++;
}
@@ -2762,22 +2705,18 @@ bool String::begins_with(const char *p_string) const {
}
bool String::is_enclosed_in(const String &p_string) const {
-
return begins_with(p_string) && ends_with(p_string);
}
bool String::is_subsequence_of(const String &p_string) const {
-
return _base_is_subsequence_of(p_string, false);
}
bool String::is_subsequence_ofi(const String &p_string) const {
-
return _base_is_subsequence_of(p_string, true);
}
bool String::is_quoted() const {
-
return is_enclosed_in("\"") || is_enclosed_in("'");
}
@@ -2827,7 +2766,6 @@ int String::countn(const String &p_string, int p_from, int p_to) const {
}
bool String::_base_is_subsequence_of(const String &p_string, bool case_insensitive) const {
-
int len = length();
if (len == 0) {
// Technically an empty string is subsequence of any string
@@ -2920,22 +2858,21 @@ static bool _wildcard_match(const CharType *p_pattern, const CharType *p_string,
}
bool String::match(const String &p_wildcard) const {
-
- if (!p_wildcard.length() || !length())
+ if (!p_wildcard.length() || !length()) {
return false;
+ }
return _wildcard_match(p_wildcard.c_str(), c_str(), true);
}
bool String::matchn(const String &p_wildcard) const {
-
- if (!p_wildcard.length() || !length())
+ if (!p_wildcard.length() || !length()) {
return false;
+ }
return _wildcard_match(p_wildcard.c_str(), c_str(), false);
}
String String::format(const Variant &values, String placeholder) const {
-
String new_string = String(this->ptr());
if (values.get_type() == Variant::ARRAY) {
@@ -3007,20 +2944,17 @@ String String::format(const Variant &values, String placeholder) const {
}
String String::replace(const String &p_key, const String &p_with) const {
-
String new_string;
int search_from = 0;
int result = 0;
while ((result = find(p_key, search_from)) >= 0) {
-
new_string += substr(search_from, result - search_from);
new_string += p_with;
search_from = result + p_key.length();
}
if (search_from == 0) {
-
return *this;
}
@@ -3030,23 +2964,21 @@ String String::replace(const String &p_key, const String &p_with) const {
}
String String::replace(const char *p_key, const char *p_with) const {
-
String new_string;
int search_from = 0;
int result = 0;
while ((result = find(p_key, search_from)) >= 0) {
-
new_string += substr(search_from, result - search_from);
new_string += p_with;
int k = 0;
- while (p_key[k] != '\0')
+ while (p_key[k] != '\0') {
k++;
+ }
search_from = result + k;
}
if (search_from == 0) {
-
return *this;
}
@@ -3056,7 +2988,6 @@ String String::replace(const char *p_key, const char *p_with) const {
}
String String::replace_first(const String &p_key, const String &p_with) const {
-
int pos = find(p_key);
if (pos >= 0) {
return substr(0, pos) + p_with + substr(pos + p_key.length(), length());
@@ -3064,21 +2995,19 @@ String String::replace_first(const String &p_key, const String &p_with) const {
return *this;
}
-String String::replacen(const String &p_key, const String &p_with) const {
+String String::replacen(const String &p_key, const String &p_with) const {
String new_string;
int search_from = 0;
int result = 0;
while ((result = findn(p_key, search_from)) >= 0) {
-
new_string += substr(search_from, result - search_from);
new_string += p_with;
search_from = result + p_key.length();
}
if (search_from == 0) {
-
return *this;
}
@@ -3087,7 +3016,6 @@ String String::replacen(const String &p_key, const String &p_with) const {
}
String String::repeat(int p_count) const {
-
ERR_FAIL_COND_V_MSG(p_count < 0, "", "Parameter count should be a positive number.");
String new_string;
@@ -3095,43 +3023,45 @@ String String::repeat(int p_count) const {
new_string.resize(length() * p_count + 1);
- for (int i = 0; i < p_count; i++)
- for (int j = 0; j < length(); j++)
+ for (int i = 0; i < p_count; i++) {
+ for (int j = 0; j < length(); j++) {
new_string[i * length() + j] = src[j];
+ }
+ }
return new_string;
}
String String::left(int p_pos) const {
-
- if (p_pos <= 0)
+ if (p_pos <= 0) {
return "";
+ }
- if (p_pos >= length())
+ if (p_pos >= length()) {
return *this;
+ }
return substr(0, p_pos);
}
String String::right(int p_pos) const {
-
- if (p_pos >= length())
+ if (p_pos >= length()) {
return "";
+ }
- if (p_pos <= 0)
+ if (p_pos <= 0) {
return *this;
+ }
return substr(p_pos, (length() - p_pos));
}
CharType String::ord_at(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, length(), 0);
return operator[](p_idx);
}
String String::dedent() const {
-
String new_string;
String indent;
bool has_indent = false;
@@ -3140,11 +3070,11 @@ String String::dedent() const {
int indent_stop = -1;
for (int i = 0; i < length(); i++) {
-
CharType c = operator[](i);
if (c == '\n') {
- if (has_text)
+ if (has_text) {
new_string += substr(indent_stop, i - indent_stop);
+ }
new_string += "\n";
has_text = false;
line_start = i + 1;
@@ -3160,57 +3090,58 @@ String String::dedent() const {
}
if (has_indent && indent_stop < 0) {
int j = i - line_start;
- if (j >= indent.length() || c != indent[j])
+ if (j >= indent.length() || c != indent[j]) {
indent_stop = i;
+ }
}
}
}
- if (has_text)
+ if (has_text) {
new_string += substr(indent_stop, length() - indent_stop);
+ }
return new_string;
}
String String::strip_edges(bool left, bool right) const {
-
int len = length();
int beg = 0, end = len;
if (left) {
for (int i = 0; i < len; i++) {
-
- if (operator[](i) <= 32)
+ if (operator[](i) <= 32) {
beg++;
- else
+ } else {
break;
+ }
}
}
if (right) {
for (int i = (int)(len - 1); i >= 0; i--) {
-
- if (operator[](i) <= 32)
+ if (operator[](i) <= 32) {
end--;
- else
+ } else {
break;
+ }
}
}
- if (beg == 0 && end == len)
+ if (beg == 0 && end == len) {
return *this;
+ }
return substr(beg, end - beg);
}
String String::strip_escapes() const {
-
String new_string;
for (int i = 0; i < length(); i++) {
-
// Escape characters on first page of the ASCII table, before 32 (Space).
- if (operator[](i) < 32)
+ if (operator[](i) < 32) {
continue;
+ }
new_string += operator[](i);
}
@@ -3218,65 +3149,60 @@ String String::strip_escapes() const {
}
String String::lstrip(const String &p_chars) const {
-
int len = length();
int beg;
for (beg = 0; beg < len; beg++) {
-
- if (p_chars.find_char(get(beg)) == -1)
+ if (p_chars.find_char(get(beg)) == -1) {
break;
+ }
}
- if (beg == 0)
+ if (beg == 0) {
return *this;
+ }
return substr(beg, len - beg);
}
String String::rstrip(const String &p_chars) const {
-
int len = length();
int end;
for (end = len - 1; end >= 0; end--) {
-
- if (p_chars.find_char(get(end)) == -1)
+ if (p_chars.find_char(get(end)) == -1) {
break;
+ }
}
- if (end == len - 1)
+ if (end == len - 1) {
return *this;
+ }
return substr(0, end + 1);
}
String String::simplify_path() const {
-
String s = *this;
String drive;
if (s.begins_with("local://")) {
drive = "local://";
s = s.substr(8, s.length());
} else if (s.begins_with("res://")) {
-
drive = "res://";
s = s.substr(6, s.length());
} else if (s.begins_with("user://")) {
-
drive = "user://";
s = s.substr(7, s.length());
} else if (s.begins_with("/") || s.begins_with("\\")) {
-
drive = s.substr(0, 1);
s = s.substr(1, s.length() - 1);
} else {
-
int p = s.find(":/");
- if (p == -1)
+ if (p == -1) {
p = s.find(":\\");
+ }
if (p != -1 && p < s.find("/")) {
-
drive = s.substr(0, p + 2);
s = s.substr(p + 2, s.length());
}
@@ -3285,21 +3211,20 @@ String String::simplify_path() const {
s = s.replace("\\", "/");
while (true) { // in case of using 2 or more slash
String compare = s.replace("//", "/");
- if (s == compare)
+ if (s == compare) {
break;
- else
+ } else {
s = compare;
+ }
}
Vector<String> dirs = s.split("/", false);
for (int i = 0; i < dirs.size(); i++) {
-
String d = dirs[i];
if (d == ".") {
dirs.remove(i);
i--;
} else if (d == "..") {
-
if (i == 0) {
dirs.remove(i);
i--;
@@ -3314,9 +3239,9 @@ String String::simplify_path() const {
s = "";
for (int i = 0; i < dirs.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
s += "/";
+ }
s += dirs[i];
}
@@ -3324,17 +3249,16 @@ String String::simplify_path() const {
}
static int _humanize_digits(int p_num) {
-
- if (p_num < 100)
+ if (p_num < 100) {
return 2;
- else if (p_num < 1024)
+ } else if (p_num < 1024) {
return 1;
- else
+ } else {
return 0;
+ }
}
String String::humanize_size(uint64_t p_size) {
-
uint64_t _div = 1;
Vector<String> prefixes;
prefixes.push_back(RTR("B"));
@@ -3357,36 +3281,38 @@ String String::humanize_size(uint64_t p_size) {
return String::num(p_size / divisor).pad_decimals(digits) + " " + prefixes[prefix_idx];
}
-bool String::is_abs_path() const {
- if (length() > 1)
+bool String::is_abs_path() const {
+ if (length() > 1) {
return (operator[](0) == '/' || operator[](0) == '\\' || find(":/") != -1 || find(":\\") != -1);
- else if ((length()) == 1)
+ } else if ((length()) == 1) {
return (operator[](0) == '/' || operator[](0) == '\\');
- else
+ } else {
return false;
+ }
}
bool String::is_valid_identifier() const {
-
int len = length();
- if (len == 0)
+ if (len == 0) {
return false;
+ }
const wchar_t *str = &operator[](0);
for (int i = 0; i < len; i++) {
-
if (i == 0) {
- if (str[0] >= '0' && str[0] <= '9')
+ if (str[0] >= '0' && str[0] <= '9') {
return false; // no start with number plz
+ }
}
bool valid_char = (str[i] >= '0' && str[i] <= '9') || (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || str[i] == '_';
- if (!valid_char)
+ if (!valid_char) {
return false;
+ }
}
return true;
@@ -3395,7 +3321,6 @@ bool String::is_valid_identifier() const {
//kind of poor should be rewritten properly
String String::word_wrap(int p_chars_per_line) const {
-
int from = 0;
int last_space = 0;
String ret;
@@ -3472,7 +3397,6 @@ String String::http_unescape() const {
}
String String::c_unescape() const {
-
String escaped = *this;
escaped = escaped.replace("\\a", "\a");
escaped = escaped.replace("\\b", "\b");
@@ -3490,7 +3414,6 @@ String String::c_unescape() const {
}
String String::c_escape() const {
-
String escaped = *this;
escaped = escaped.replace("\\", "\\\\");
escaped = escaped.replace("\a", "\\a");
@@ -3508,7 +3431,6 @@ String String::c_escape() const {
}
String String::c_escape_multiline() const {
-
String escaped = *this;
escaped = escaped.replace("\\", "\\\\");
escaped = escaped.replace("\"", "\\\"");
@@ -3517,7 +3439,6 @@ String String::c_escape_multiline() const {
}
String String::json_escape() const {
-
String escaped = *this;
escaped = escaped.replace("\\", "\\\\");
escaped = escaped.replace("\b", "\\b");
@@ -3532,7 +3453,6 @@ String String::json_escape() const {
}
String String::xml_escape(bool p_escape_quotes) const {
-
String str = *this;
str = str.replace("&", "&amp;");
str = str.replace("<", "&lt;");
@@ -3542,29 +3462,24 @@ String String::xml_escape(bool p_escape_quotes) const {
str = str.replace("\"", "&quot;");
}
/*
- for (int i=1;i<32;i++) {
+for (int i=1;i<32;i++) {
- char chr[2]={i,0};
- str=str.replace(chr,"&#"+String::num(i)+";");
- }*/
+ char chr[2]={i,0};
+ str=str.replace(chr,"&#"+String::num(i)+";");
+}*/
return str;
}
static _FORCE_INLINE_ int _xml_unescape(const CharType *p_src, int p_src_len, CharType *p_dst) {
-
int len = 0;
while (p_src_len) {
-
if (*p_src == '&') {
-
int eat = 0;
if (p_src_len >= 4 && p_src[1] == '#') {
-
CharType c = 0;
for (int i = 2; i < p_src_len; i++) {
-
eat = i + 1;
CharType ct = p_src[i];
if (ct == ';') {
@@ -3582,49 +3497,50 @@ static _FORCE_INLINE_ int _xml_unescape(const CharType *p_src, int p_src_len, Ch
c |= ct;
}
- if (p_dst)
+ if (p_dst) {
*p_dst = c;
+ }
} else if (p_src_len >= 4 && p_src[1] == 'g' && p_src[2] == 't' && p_src[3] == ';') {
-
- if (p_dst)
+ if (p_dst) {
*p_dst = '>';
+ }
eat = 4;
} else if (p_src_len >= 4 && p_src[1] == 'l' && p_src[2] == 't' && p_src[3] == ';') {
-
- if (p_dst)
+ if (p_dst) {
*p_dst = '<';
+ }
eat = 4;
} else if (p_src_len >= 5 && p_src[1] == 'a' && p_src[2] == 'm' && p_src[3] == 'p' && p_src[4] == ';') {
-
- if (p_dst)
+ if (p_dst) {
*p_dst = '&';
+ }
eat = 5;
} else if (p_src_len >= 6 && p_src[1] == 'q' && p_src[2] == 'u' && p_src[3] == 'o' && p_src[4] == 't' && p_src[5] == ';') {
-
- if (p_dst)
+ if (p_dst) {
*p_dst = '"';
+ }
eat = 6;
} else if (p_src_len >= 6 && p_src[1] == 'a' && p_src[2] == 'p' && p_src[3] == 'o' && p_src[4] == 's' && p_src[5] == ';') {
-
- if (p_dst)
+ if (p_dst) {
*p_dst = '\'';
+ }
eat = 6;
} else {
-
- if (p_dst)
+ if (p_dst) {
*p_dst = *p_src;
+ }
eat = 1;
}
- if (p_dst)
+ if (p_dst) {
p_dst++;
+ }
len++;
p_src += eat;
p_src_len -= eat;
} else {
-
if (p_dst) {
*p_dst = *p_src;
p_dst++;
@@ -3639,12 +3555,12 @@ static _FORCE_INLINE_ int _xml_unescape(const CharType *p_src, int p_src_len, Ch
}
String String::xml_unescape() const {
-
String str;
int l = length();
int len = _xml_unescape(c_str(), l, nullptr);
- if (len == 0)
+ if (len == 0) {
return String();
+ }
str.resize(len + 1);
_xml_unescape(c_str(), l, str.ptrw());
str[len] = 0;
@@ -3652,7 +3568,6 @@ String String::xml_unescape() const {
}
String String::pad_decimals(int p_digits) const {
-
String s = *this;
int c = s.find(".");
@@ -3679,7 +3594,6 @@ String String::pad_decimals(int p_digits) const {
}
String String::pad_zeros(int p_digits) const {
-
String s = *this;
int end = s.find(".");
@@ -3687,8 +3601,9 @@ String String::pad_zeros(int p_digits) const {
end = s.length();
}
- if (end == 0)
+ if (end == 0) {
return s;
+ }
int begin = 0;
@@ -3696,11 +3611,11 @@ String String::pad_zeros(int p_digits) const {
begin++;
}
- if (begin >= end)
+ if (begin >= end) {
return s;
+ }
while (end - begin < p_digits) {
-
s = s.insert(begin, "0");
end++;
}
@@ -3709,7 +3624,6 @@ String String::pad_zeros(int p_digits) const {
}
String String::trim_prefix(const String &p_prefix) const {
-
String s = *this;
if (s.begins_with(p_prefix)) {
return s.substr(p_prefix.length(), s.length() - p_prefix.length());
@@ -3718,7 +3632,6 @@ String String::trim_prefix(const String &p_prefix) const {
}
String String::trim_suffix(const String &p_suffix) const {
-
String s = *this;
if (s.ends_with(p_suffix)) {
return s.substr(0, s.length() - p_suffix.length());
@@ -3727,40 +3640,42 @@ String String::trim_suffix(const String &p_suffix) const {
}
bool String::is_valid_integer() const {
-
int len = length();
- if (len == 0)
+ if (len == 0) {
return false;
+ }
int from = 0;
- if (len != 1 && (operator[](0) == '+' || operator[](0) == '-'))
+ if (len != 1 && (operator[](0) == '+' || operator[](0) == '-')) {
from++;
+ }
for (int i = from; i < len; i++) {
-
- if (operator[](i) < '0' || operator[](i) > '9')
+ if (operator[](i) < '0' || operator[](i) > '9') {
return false; // no start with number plz
+ }
}
return true;
}
bool String::is_valid_hex_number(bool p_with_prefix) const {
-
int len = length();
- if (len == 0)
+ if (len == 0) {
return false;
+ }
int from = 0;
- if (len != 1 && (operator[](0) == '+' || operator[](0) == '-'))
+ if (len != 1 && (operator[](0) == '+' || operator[](0) == '-')) {
from++;
+ }
if (p_with_prefix) {
-
- if (len < 3)
+ if (len < 3) {
return false;
+ }
if (operator[](from) != '0' || operator[](from + 1) != 'x') {
return false;
}
@@ -3768,10 +3683,10 @@ bool String::is_valid_hex_number(bool p_with_prefix) const {
}
for (int i = from; i < len; i++) {
-
CharType c = operator[](i);
- if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
+ if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
continue;
+ }
return false;
}
@@ -3779,11 +3694,11 @@ bool String::is_valid_hex_number(bool p_with_prefix) const {
};
bool String::is_valid_float() const {
-
int len = length();
- if (len == 0)
+ if (len == 0) {
return false;
+ }
int from = 0;
if (operator[](0) == '+' || operator[](0) == '-') {
@@ -3797,71 +3712,70 @@ bool String::is_valid_float() const {
bool numbers_found = false;
for (int i = from; i < len; i++) {
-
if (operator[](i) >= '0' && operator[](i) <= '9') {
-
- if (exponent_found)
+ if (exponent_found) {
exponent_values_found = true;
- else
+ } else {
numbers_found = true;
+ }
} else if (numbers_found && !exponent_found && operator[](i) == 'e') {
exponent_found = true;
} else if (!period_found && !exponent_found && operator[](i) == '.') {
period_found = true;
} else if ((operator[](i) == '-' || operator[](i) == '+') && exponent_found && !exponent_values_found && !sign_found) {
sign_found = true;
- } else
+ } else {
return false; // no start with number plz
+ }
}
return numbers_found;
}
String String::path_to_file(const String &p_path) const {
-
// Don't get base dir for src, this is expected to be a dir already.
String src = this->replace("\\", "/");
String dst = p_path.replace("\\", "/").get_base_dir();
String rel = src.path_to(dst);
- if (rel == dst) // failed
+ if (rel == dst) { // failed
return p_path;
- else
+ } else {
return rel + p_path.get_file();
+ }
}
String String::path_to(const String &p_path) const {
-
String src = this->replace("\\", "/");
String dst = p_path.replace("\\", "/");
- if (!src.ends_with("/"))
+ if (!src.ends_with("/")) {
src += "/";
- if (!dst.ends_with("/"))
+ }
+ if (!dst.ends_with("/")) {
dst += "/";
+ }
String base;
if (src.begins_with("res://") && dst.begins_with("res://")) {
-
base = "res:/";
src = src.replace("res://", "/");
dst = dst.replace("res://", "/");
} else if (src.begins_with("user://") && dst.begins_with("user://")) {
-
base = "user:/";
src = src.replace("user://", "/");
dst = dst.replace("user://", "/");
} else if (src.begins_with("/") && dst.begins_with("/")) {
-
//nothing
} else {
//dos style
String src_begin = src.get_slicec('/', 0);
String dst_begin = dst.get_slicec('/', 0);
- if (src_begin != dst_begin)
+ if (src_begin != dst_begin) {
return p_path; //impossible to do this
+ }
base = src_begin;
src = src.substr(src_begin.length(), src.length());
@@ -3876,12 +3790,15 @@ String String::path_to(const String &p_path) const {
int common_parent = 0;
while (true) {
- if (src_dirs.size() == common_parent)
+ if (src_dirs.size() == common_parent) {
break;
- if (dst_dirs.size() == common_parent)
+ }
+ if (dst_dirs.size() == common_parent) {
break;
- if (src_dirs[common_parent] != dst_dirs[common_parent])
+ }
+ if (src_dirs[common_parent] != dst_dirs[common_parent]) {
break;
+ }
common_parent++;
}
@@ -3890,27 +3807,24 @@ String String::path_to(const String &p_path) const {
String dir;
for (int i = src_dirs.size() - 1; i > common_parent; i--) {
-
dir += "../";
}
for (int i = common_parent + 1; i < dst_dirs.size(); i++) {
-
dir += dst_dirs[i] + "/";
}
- if (dir.length() == 0)
+ if (dir.length() == 0) {
dir = "./";
+ }
return dir;
}
bool String::is_valid_html_color() const {
-
return Color::html_is_valid(*this);
}
bool String::is_valid_filename() const {
-
String stripped = strip_edges();
if (*this != stripped) {
return false;
@@ -3924,37 +3838,39 @@ bool String::is_valid_filename() const {
}
bool String::is_valid_ip_address() const {
-
if (find(":") >= 0) {
-
Vector<String> ip = split(":");
for (int i = 0; i < ip.size(); i++) {
-
String n = ip[i];
- if (n.empty())
+ if (n.empty()) {
continue;
+ }
if (n.is_valid_hex_number(false)) {
int nint = n.hex_to_int(false);
- if (nint < 0 || nint > 0xffff)
+ if (nint < 0 || nint > 0xffff) {
return false;
+ }
continue;
};
- if (!n.is_valid_ip_address())
+ if (!n.is_valid_ip_address()) {
return false;
+ }
};
} else {
Vector<String> ip = split(".");
- if (ip.size() != 4)
+ if (ip.size() != 4) {
return false;
+ }
for (int i = 0; i < ip.size(); i++) {
-
String n = ip[i];
- if (!n.is_valid_integer())
+ if (!n.is_valid_integer()) {
return false;
+ }
int val = n.to_int();
- if (val < 0 || val > 255)
+ if (val < 0 || val > 255) {
return false;
+ }
}
};
@@ -3962,17 +3878,14 @@ bool String::is_valid_ip_address() const {
}
bool String::is_resource_file() const {
-
return begins_with("res://") && find("::") == -1;
}
bool String::is_rel_path() const {
-
return !is_abs_path();
}
String String::get_base_dir() const {
-
int basepos = find("://");
String rs;
String base;
@@ -3985,52 +3898,52 @@ String String::get_base_dir() const {
rs = substr(1, length());
base = "/";
} else {
-
rs = *this;
}
}
int sep = MAX(rs.find_last("/"), rs.find_last("\\"));
- if (sep == -1)
+ if (sep == -1) {
return base;
+ }
return base + rs.substr(0, sep);
}
String String::get_file() const {
-
int sep = MAX(find_last("/"), find_last("\\"));
- if (sep == -1)
+ if (sep == -1) {
return *this;
+ }
return substr(sep + 1, length());
}
String String::get_extension() const {
-
int pos = find_last(".");
- if (pos < 0 || pos < MAX(find_last("/"), find_last("\\")))
+ if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) {
return "";
+ }
return substr(pos + 1, length());
}
String String::plus_file(const String &p_file) const {
- if (empty())
+ if (empty()) {
return p_file;
- if (operator[](length() - 1) == '/' || (p_file.size() > 0 && p_file.operator[](0) == '/'))
+ }
+ if (operator[](length() - 1) == '/' || (p_file.size() > 0 && p_file.operator[](0) == '/')) {
return *this + p_file;
+ }
return *this + "/" + p_file;
}
String String::percent_encode() const {
-
CharString cs = utf8();
String encoded;
for (int i = 0; i < cs.length(); i++) {
uint8_t c = cs[i];
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '~' || c == '.') {
-
char p[2] = { (char)c, 0 };
encoded += p;
} else {
@@ -4045,34 +3958,34 @@ String String::percent_encode() const {
return encoded;
}
-String String::percent_decode() const {
+String String::percent_decode() const {
CharString pe;
CharString cs = utf8();
for (int i = 0; i < cs.length(); i++) {
-
uint8_t c = cs[i];
if (c == '%' && i < length() - 2) {
-
uint8_t a = LOWERCASE(cs[i + 1]);
uint8_t b = LOWERCASE(cs[i + 2]);
- if (a >= '0' && a <= '9')
+ if (a >= '0' && a <= '9') {
c = (a - '0') << 4;
- else if (a >= 'a' && a <= 'f')
+ } else if (a >= 'a' && a <= 'f') {
c = (a - 'a' + 10) << 4;
- else
+ } else {
continue;
+ }
uint8_t d = 0;
- if (b >= '0' && b <= '9')
+ if (b >= '0' && b <= '9') {
d = (b - '0');
- else if (b >= 'a' && b <= 'f')
+ } else if (b >= 'a' && b <= 'f') {
d = (b - 'a' + 10);
- else
+ } else {
continue;
+ }
c += d;
i += 2;
}
@@ -4096,31 +4009,27 @@ String String::property_name_encode() const {
}
String String::get_basename() const {
-
int pos = find_last(".");
- if (pos < 0 || pos < MAX(find_last("/"), find_last("\\")))
+ if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) {
return *this;
+ }
return substr(0, pos);
}
String itos(int64_t p_val) {
-
return String::num_int64(p_val);
}
String uitos(uint64_t p_val) {
-
return String::num_uint64(p_val);
}
String rtos(double p_val) {
-
return String::num(p_val);
}
String rtoss(double p_val) {
-
return String::num_scientific(p_val);
}
@@ -4129,19 +4038,22 @@ String String::rpad(int min_length, const String &character) const {
String s = *this;
int padding = min_length - s.length();
if (padding > 0) {
- for (int i = 0; i < padding; i++)
+ for (int i = 0; i < padding; i++) {
s = s + character;
+ }
}
return s;
}
+
// Left-pad with a character.
String String::lpad(int min_length, const String &character) const {
String s = *this;
int padding = min_length - s.length();
if (padding > 0) {
- for (int i = 0; i < padding; i++)
+ for (int i = 0; i < padding; i++) {
s = character + s;
+ }
}
return s;
diff --git a/core/ustring.h b/core/ustring.h
index 15bc2b323c..5b13a1c704 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -51,8 +51,9 @@ class CharProxy {
public:
_FORCE_INLINE_ operator T() const {
- if (unlikely(_index == _cowdata.size()))
+ if (unlikely(_index == _cowdata.size())) {
return _null;
+ }
return _cowdata.get(_index);
}
@@ -71,7 +72,6 @@ public:
};
class CharString {
-
CowData<char> _cowdata;
static const char _null;
@@ -84,8 +84,9 @@ public:
_FORCE_INLINE_ char get(int p_index) const { return _cowdata.get(p_index); }
_FORCE_INLINE_ void set(int p_index, const char &p_elem) { _cowdata.set(p_index, p_elem); }
_FORCE_INLINE_ const char &operator[](int p_index) const {
- if (unlikely(p_index == _cowdata.size()))
+ if (unlikely(p_index == _cowdata.size())) {
return _null;
+ }
return _cowdata.get(p_index);
}
@@ -113,7 +114,6 @@ protected:
typedef wchar_t CharType;
struct StrRange {
-
const CharType *c_str;
int len;
@@ -124,7 +124,6 @@ struct StrRange {
};
class String {
-
CowData<CharType> _cowdata;
static const CharType _null;
@@ -154,8 +153,9 @@ public:
Error resize(int p_size) { return _cowdata.resize(p_size); }
_FORCE_INLINE_ const CharType &operator[](int p_index) const {
- if (unlikely(p_index == _cowdata.size()))
+ if (unlikely(p_index == _cowdata.size())) {
return _null;
+ }
return _cowdata.get(p_index);
}
@@ -377,36 +377,31 @@ String rtos(double p_val);
String rtoss(double p_val); //scientific version
struct NoCaseComparator {
-
bool operator()(const String &p_a, const String &p_b) const {
-
return p_a.nocasecmp_to(p_b) < 0;
}
};
struct NaturalNoCaseComparator {
-
bool operator()(const String &p_a, const String &p_b) const {
-
return p_a.naturalnocasecmp_to(p_b) < 0;
}
};
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)
+ if (*l_ptr == 0 && *r_ptr == 0) {
return false;
- else if (*l_ptr == 0)
+ } else if (*l_ptr == 0) {
return true;
- else if (*r_ptr == 0)
+ } else if (*r_ptr == 0) {
return false;
- else if (*l_ptr < *r_ptr)
+ } else if (*l_ptr < *r_ptr) {
return true;
- else if (*l_ptr > *r_ptr)
+ } else if (*l_ptr > *r_ptr) {
return false;
+ }
l_ptr++;
r_ptr++;
diff --git a/core/variant.cpp b/core/variant.cpp
index 162d409026..62d710e493 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -41,172 +41,136 @@
#include "scene/main/node.h"
String Variant::get_type_name(Variant::Type p_type) {
-
switch (p_type) {
case NIL: {
-
return "Nil";
} break;
// atomic types
case BOOL: {
-
return "bool";
} break;
case INT: {
-
return "int";
} break;
case FLOAT: {
-
return "float";
} break;
case STRING: {
-
return "String";
} break;
// math types
case VECTOR2: {
-
return "Vector2";
} break;
case VECTOR2I: {
-
return "Vector2i";
} break;
case RECT2: {
-
return "Rect2";
} break;
case RECT2I: {
-
return "Rect2i";
} break;
case TRANSFORM2D: {
-
return "Transform2D";
} break;
case VECTOR3: {
-
return "Vector3";
} break;
case VECTOR3I: {
-
return "Vector3i";
} break;
case PLANE: {
-
return "Plane";
} break;
case AABB: {
-
return "AABB";
} break;
case QUAT: {
-
return "Quat";
} break;
case BASIS: {
-
return "Basis";
} break;
case TRANSFORM: {
-
return "Transform";
} break;
// misc types
case COLOR: {
-
return "Color";
} break;
case _RID: {
-
return "RID";
} break;
case OBJECT: {
-
return "Object";
} break;
case CALLABLE: {
-
return "Callable";
} break;
case SIGNAL: {
-
return "Signal";
} break;
case STRING_NAME: {
-
return "StringName";
} break;
case NODE_PATH: {
-
return "NodePath";
} break;
case DICTIONARY: {
-
return "Dictionary";
} break;
case ARRAY: {
-
return "Array";
} break;
// arrays
case PACKED_BYTE_ARRAY: {
-
return "PackedByteArray";
} break;
case PACKED_INT32_ARRAY: {
-
return "PackedInt32Array";
} break;
case PACKED_INT64_ARRAY: {
-
return "PackedInt64Array";
} break;
case PACKED_FLOAT32_ARRAY: {
-
return "PackedFloat32Array";
} break;
case PACKED_FLOAT64_ARRAY: {
-
return "PackedFloat64Array";
} break;
case PACKED_STRING_ARRAY: {
-
return "PackedStringArray";
} break;
case PACKED_VECTOR2_ARRAY: {
-
return "PackedVector2Array";
} break;
case PACKED_VECTOR3_ARRAY: {
-
return "PackedVector3Array";
} break;
case PACKED_COLOR_ARRAY: {
-
return "PackedColorArray";
} break;
@@ -218,11 +182,12 @@ String Variant::get_type_name(Variant::Type p_type) {
}
bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
-
- if (p_type_from == 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
+ }
+ 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);
@@ -233,7 +198,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
switch (p_type_to) {
case BOOL: {
-
static const Type valid[] = {
INT,
FLOAT,
@@ -244,7 +208,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case INT: {
-
static const Type valid[] = {
BOOL,
FLOAT,
@@ -256,7 +219,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case FLOAT: {
-
static const Type valid[] = {
BOOL,
INT,
@@ -268,7 +230,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case STRING: {
-
static const Type invalid[] = {
OBJECT,
NIL
@@ -277,7 +238,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
invalid_types = invalid;
} break;
case VECTOR2: {
-
static const Type valid[] = {
VECTOR2I,
NIL,
@@ -287,7 +247,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case VECTOR2I: {
-
static const Type valid[] = {
VECTOR2,
NIL,
@@ -297,7 +256,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case RECT2: {
-
static const Type valid[] = {
RECT2I,
NIL,
@@ -307,7 +265,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case RECT2I: {
-
static const Type valid[] = {
RECT2,
NIL,
@@ -317,7 +274,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case TRANSFORM2D: {
-
static const Type valid[] = {
TRANSFORM,
NIL
@@ -326,7 +282,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case VECTOR3: {
-
static const Type valid[] = {
VECTOR3I,
NIL,
@@ -336,7 +291,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case VECTOR3I: {
-
static const Type valid[] = {
VECTOR3,
NIL,
@@ -347,7 +301,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case QUAT: {
-
static const Type valid[] = {
BASIS,
NIL
@@ -357,7 +310,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case BASIS: {
-
static const Type valid[] = {
QUAT,
VECTOR3,
@@ -368,7 +320,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case TRANSFORM: {
-
static const Type valid[] = {
TRANSFORM2D,
QUAT,
@@ -381,7 +332,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case COLOR: {
-
static const Type valid[] = {
STRING,
INT,
@@ -393,7 +343,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case _RID: {
-
static const Type valid[] = {
OBJECT,
NIL
@@ -402,7 +351,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case OBJECT: {
-
static const Type valid[] = {
NIL
};
@@ -410,7 +358,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case STRING_NAME: {
-
static const Type valid[] = {
STRING,
NIL
@@ -419,7 +366,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case NODE_PATH: {
-
static const Type valid[] = {
STRING,
NIL
@@ -428,7 +374,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case ARRAY: {
-
static const Type valid[] = {
PACKED_BYTE_ARRAY,
PACKED_INT32_ARRAY,
@@ -446,7 +391,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
// arrays
case PACKED_BYTE_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -455,7 +399,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case PACKED_INT32_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -463,7 +406,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case PACKED_INT64_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -471,7 +413,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case PACKED_FLOAT32_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -480,7 +421,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case PACKED_FLOAT64_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -489,7 +429,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case PACKED_STRING_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -497,7 +436,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
case PACKED_VECTOR2_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -506,7 +444,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case PACKED_VECTOR3_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -515,7 +452,6 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
} break;
case PACKED_COLOR_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -529,22 +465,20 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
}
if (valid_types) {
-
int i = 0;
while (valid_types[i] != NIL) {
-
- if (p_type_from == valid_types[i])
+ 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])
+ if (p_type_from == invalid_types[i]) {
return false;
+ }
i++;
}
@@ -555,11 +489,12 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
}
bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type_to) {
-
- if (p_type_from == 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
+ }
+ 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);
@@ -569,7 +504,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
switch (p_type_to) {
case BOOL: {
-
static const Type valid[] = {
INT,
FLOAT,
@@ -580,7 +514,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case INT: {
-
static const Type valid[] = {
BOOL,
FLOAT,
@@ -592,7 +525,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case FLOAT: {
-
static const Type valid[] = {
BOOL,
INT,
@@ -604,7 +536,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case STRING: {
-
static const Type valid[] = {
NODE_PATH,
STRING_NAME,
@@ -614,7 +545,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case VECTOR2: {
-
static const Type valid[] = {
VECTOR2I,
NIL,
@@ -624,7 +554,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case VECTOR2I: {
-
static const Type valid[] = {
VECTOR2,
NIL,
@@ -634,7 +563,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case RECT2: {
-
static const Type valid[] = {
RECT2I,
NIL,
@@ -644,7 +572,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case RECT2I: {
-
static const Type valid[] = {
RECT2,
NIL,
@@ -654,7 +581,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case TRANSFORM2D: {
-
static const Type valid[] = {
TRANSFORM,
NIL
@@ -663,7 +589,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case VECTOR3: {
-
static const Type valid[] = {
VECTOR3I,
NIL,
@@ -673,7 +598,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case VECTOR3I: {
-
static const Type valid[] = {
VECTOR3,
NIL,
@@ -684,7 +608,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case QUAT: {
-
static const Type valid[] = {
BASIS,
NIL
@@ -694,7 +617,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case BASIS: {
-
static const Type valid[] = {
QUAT,
VECTOR3,
@@ -705,7 +627,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case TRANSFORM: {
-
static const Type valid[] = {
TRANSFORM2D,
QUAT,
@@ -718,7 +639,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case COLOR: {
-
static const Type valid[] = {
STRING,
INT,
@@ -730,7 +650,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case _RID: {
-
static const Type valid[] = {
OBJECT,
NIL
@@ -739,7 +658,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case OBJECT: {
-
static const Type valid[] = {
NIL
};
@@ -747,7 +665,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case STRING_NAME: {
-
static const Type valid[] = {
STRING,
NIL
@@ -756,7 +673,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case NODE_PATH: {
-
static const Type valid[] = {
STRING,
NIL
@@ -765,7 +681,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case ARRAY: {
-
static const Type valid[] = {
PACKED_BYTE_ARRAY,
PACKED_INT32_ARRAY,
@@ -783,7 +698,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
// arrays
case PACKED_BYTE_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -792,7 +706,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case PACKED_INT32_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -800,7 +713,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case PACKED_INT64_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -808,7 +720,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case PACKED_FLOAT32_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -817,7 +728,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case PACKED_FLOAT64_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -826,7 +736,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case PACKED_STRING_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -834,7 +743,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case PACKED_VECTOR2_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -843,7 +751,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case PACKED_VECTOR3_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -852,7 +759,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
} break;
case PACKED_COLOR_ARRAY: {
-
static const Type valid[] = {
ARRAY,
NIL
@@ -866,12 +772,11 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
}
if (valid_types) {
-
int i = 0;
while (valid_types[i] != NIL) {
-
- if (p_type_from == valid_types[i])
+ if (p_type_from == valid_types[i]) {
return true;
+ }
i++;
}
}
@@ -880,9 +785,9 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
}
bool Variant::operator==(const Variant &p_variant) const {
-
- if (type != p_variant.type) //evaluation of operator== needs to be more strict
+ if (type != p_variant.type) { //evaluation of operator== needs to be more strict
return false;
+ }
bool v;
Variant r;
evaluate(OP_EQUAL, *this, p_variant, r, v);
@@ -890,9 +795,9 @@ bool Variant::operator==(const Variant &p_variant) const {
}
bool Variant::operator!=(const Variant &p_variant) const {
-
- if (type != p_variant.type) //evaluation of operator== needs to be more strict
+ if (type != p_variant.type) { //evaluation of operator== needs to be more strict
return true;
+ }
bool v;
Variant r;
evaluate(OP_NOT_EQUAL, *this, p_variant, r, v);
@@ -900,8 +805,9 @@ bool Variant::operator!=(const Variant &p_variant) const {
}
bool Variant::operator<(const Variant &p_variant) const {
- if (type != p_variant.type) //if types differ, then order by type first
+ if (type != p_variant.type) { //if types differ, then order by type first
return type < p_variant.type;
+ }
bool v;
Variant r;
evaluate(OP_LESS, *this, p_variant, r, v);
@@ -909,72 +815,58 @@ bool Variant::operator<(const Variant &p_variant) const {
}
bool Variant::is_zero() const {
-
switch (type) {
case NIL: {
-
return true;
} break;
// atomic types
case BOOL: {
-
return !(_data._bool);
} break;
case INT: {
-
return _data._int == 0;
} break;
case FLOAT: {
-
return _data._float == 0;
} break;
case STRING: {
-
return *reinterpret_cast<const String *>(_data._mem) == String();
} break;
// math types
case VECTOR2: {
-
return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2();
} break;
case VECTOR2I: {
-
return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i();
} break;
case RECT2: {
-
return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2();
} break;
case RECT2I: {
-
return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i();
} break;
case TRANSFORM2D: {
-
return *_data._transform2d == Transform2D();
} break;
case VECTOR3: {
-
return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3();
} break;
case VECTOR3I: {
-
return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i();
} break;
case PLANE: {
-
return *reinterpret_cast<const Plane *>(_data._mem) == Plane();
} break;
@@ -984,111 +876,89 @@ bool Variant::is_zero() const {
} break;*/
case AABB: {
-
return *_data._aabb == ::AABB();
} break;
case QUAT: {
-
return *reinterpret_cast<const Quat *>(_data._mem) == Quat();
} break;
case BASIS: {
-
return *_data._basis == Basis();
} break;
case TRANSFORM: {
-
return *_data._transform == Transform();
} break;
// misc types
case COLOR: {
-
return *reinterpret_cast<const Color *>(_data._mem) == Color();
} break;
case _RID: {
-
return *reinterpret_cast<const RID *>(_data._mem) == RID();
} break;
case OBJECT: {
-
return _get_obj().obj == nullptr;
} break;
case CALLABLE: {
-
return reinterpret_cast<const Callable *>(_data._mem)->is_null();
} break;
case SIGNAL: {
-
return reinterpret_cast<const Signal *>(_data._mem)->is_null();
} break;
case STRING_NAME: {
-
return *reinterpret_cast<const StringName *>(_data._mem) != StringName();
} break;
case NODE_PATH: {
-
return reinterpret_cast<const NodePath *>(_data._mem)->is_empty();
} break;
case DICTIONARY: {
-
return reinterpret_cast<const Dictionary *>(_data._mem)->empty();
} break;
case ARRAY: {
-
return reinterpret_cast<const Array *>(_data._mem)->empty();
} break;
// arrays
case PACKED_BYTE_ARRAY: {
-
return PackedArrayRef<uint8_t>::get_array(_data.packed_array).size() == 0;
} break;
case PACKED_INT32_ARRAY: {
-
return PackedArrayRef<int32_t>::get_array(_data.packed_array).size() == 0;
} break;
case PACKED_INT64_ARRAY: {
-
return PackedArrayRef<int64_t>::get_array(_data.packed_array).size() == 0;
} break;
case PACKED_FLOAT32_ARRAY: {
-
return PackedArrayRef<float>::get_array(_data.packed_array).size() == 0;
} break;
case PACKED_FLOAT64_ARRAY: {
-
return PackedArrayRef<double>::get_array(_data.packed_array).size() == 0;
} break;
case PACKED_STRING_ARRAY: {
-
return PackedArrayRef<String>::get_array(_data.packed_array).size() == 0;
} break;
case PACKED_VECTOR2_ARRAY: {
-
return PackedArrayRef<Vector2>::get_array(_data.packed_array).size() == 0;
} break;
case PACKED_VECTOR3_ARRAY: {
-
return PackedArrayRef<Vector3>::get_array(_data.packed_array).size() == 0;
} break;
case PACKED_COLOR_ARRAY: {
-
return PackedArrayRef<Color>::get_array(_data.packed_array).size() == 0;
} break;
@@ -1100,65 +970,52 @@ bool Variant::is_zero() const {
}
bool Variant::is_one() const {
-
switch (type) {
case NIL: {
-
return true;
} break;
// atomic types
case BOOL: {
-
return _data._bool;
} break;
case INT: {
-
return _data._int == 1;
} break;
case FLOAT: {
-
return _data._float == 1;
} break;
case VECTOR2: {
-
return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2(1, 1);
} break;
case VECTOR2I: {
-
return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i(1, 1);
} break;
case RECT2: {
-
return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2(1, 1, 1, 1);
} break;
case RECT2I: {
-
return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i(1, 1, 1, 1);
} break;
case VECTOR3: {
-
return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3(1, 1, 1);
} break;
case VECTOR3I: {
-
return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i(1, 1, 1);
} break;
case PLANE: {
-
return *reinterpret_cast<const Plane *>(_data._mem) == Plane(1, 1, 1, 1);
} break;
case COLOR: {
-
return *reinterpret_cast<const Color *>(_data._mem) == Color(1, 1, 1, 1);
} break;
@@ -1180,7 +1037,6 @@ bool Variant::is_null() const {
}
void Variant::reference(const Variant &p_variant) {
-
switch (type) {
case NIL:
case BOOL:
@@ -1195,93 +1051,73 @@ void Variant::reference(const Variant &p_variant) {
switch (p_variant.type) {
case NIL: {
-
// none
} break;
// atomic types
case BOOL: {
-
_data._bool = p_variant._data._bool;
} break;
case INT: {
-
_data._int = p_variant._data._int;
} break;
case FLOAT: {
-
_data._float = p_variant._data._float;
} break;
case STRING: {
-
memnew_placement(_data._mem, String(*reinterpret_cast<const String *>(p_variant._data._mem)));
} break;
// math types
case VECTOR2: {
-
memnew_placement(_data._mem, Vector2(*reinterpret_cast<const Vector2 *>(p_variant._data._mem)));
} break;
case VECTOR2I: {
-
memnew_placement(_data._mem, Vector2i(*reinterpret_cast<const Vector2i *>(p_variant._data._mem)));
} break;
case RECT2: {
-
memnew_placement(_data._mem, Rect2(*reinterpret_cast<const Rect2 *>(p_variant._data._mem)));
} break;
case RECT2I: {
-
memnew_placement(_data._mem, Rect2i(*reinterpret_cast<const Rect2i *>(p_variant._data._mem)));
} break;
case TRANSFORM2D: {
-
_data._transform2d = memnew(Transform2D(*p_variant._data._transform2d));
} break;
case VECTOR3: {
-
memnew_placement(_data._mem, Vector3(*reinterpret_cast<const Vector3 *>(p_variant._data._mem)));
} break;
case VECTOR3I: {
-
memnew_placement(_data._mem, Vector3i(*reinterpret_cast<const Vector3i *>(p_variant._data._mem)));
} break;
case PLANE: {
-
memnew_placement(_data._mem, Plane(*reinterpret_cast<const Plane *>(p_variant._data._mem)));
} break;
case AABB: {
-
_data._aabb = memnew(::AABB(*p_variant._data._aabb));
} break;
case QUAT: {
-
memnew_placement(_data._mem, Quat(*reinterpret_cast<const Quat *>(p_variant._data._mem)));
} break;
case BASIS: {
-
_data._basis = memnew(Basis(*p_variant._data._basis));
} break;
case TRANSFORM: {
-
_data._transform = memnew(Transform(*p_variant._data._transform));
} break;
// misc types
case COLOR: {
-
memnew_placement(_data._mem, Color(*reinterpret_cast<const Color *>(p_variant._data._mem)));
} break;
case _RID: {
-
memnew_placement(_data._mem, RID(*reinterpret_cast<const RID *>(p_variant._data._mem)));
} break;
case OBJECT: {
-
memnew_placement(_data._mem, ObjData);
if (p_variant._get_obj().obj && p_variant._get_obj().id.is_reference()) {
@@ -1298,37 +1134,30 @@ void Variant::reference(const Variant &p_variant) {
} break;
case CALLABLE: {
-
memnew_placement(_data._mem, Callable(*reinterpret_cast<const Callable *>(p_variant._data._mem)));
} break;
case SIGNAL: {
-
memnew_placement(_data._mem, Signal(*reinterpret_cast<const Signal *>(p_variant._data._mem)));
} break;
case STRING_NAME: {
-
memnew_placement(_data._mem, StringName(*reinterpret_cast<const StringName *>(p_variant._data._mem)));
} break;
case NODE_PATH: {
-
memnew_placement(_data._mem, NodePath(*reinterpret_cast<const NodePath *>(p_variant._data._mem)));
} break;
case DICTIONARY: {
-
memnew_placement(_data._mem, Dictionary(*reinterpret_cast<const Dictionary *>(p_variant._data._mem)));
} break;
case ARRAY: {
-
memnew_placement(_data._mem, Array(*reinterpret_cast<const Array *>(p_variant._data._mem)));
} break;
// arrays
case PACKED_BYTE_ARRAY: {
-
_data.packed_array = static_cast<PackedArrayRef<uint8_t> *>(p_variant._data.packed_array)->reference();
if (!_data.packed_array) {
_data.packed_array = PackedArrayRef<uint8_t>::create();
@@ -1336,7 +1165,6 @@ void Variant::reference(const Variant &p_variant) {
} break;
case PACKED_INT32_ARRAY: {
-
_data.packed_array = static_cast<PackedArrayRef<int32_t> *>(p_variant._data.packed_array)->reference();
if (!_data.packed_array) {
_data.packed_array = PackedArrayRef<int32_t>::create();
@@ -1344,7 +1172,6 @@ void Variant::reference(const Variant &p_variant) {
} break;
case PACKED_INT64_ARRAY: {
-
_data.packed_array = static_cast<PackedArrayRef<int64_t> *>(p_variant._data.packed_array)->reference();
if (!_data.packed_array) {
_data.packed_array = PackedArrayRef<int64_t>::create();
@@ -1352,7 +1179,6 @@ void Variant::reference(const Variant &p_variant) {
} break;
case PACKED_FLOAT32_ARRAY: {
-
_data.packed_array = static_cast<PackedArrayRef<float> *>(p_variant._data.packed_array)->reference();
if (!_data.packed_array) {
_data.packed_array = PackedArrayRef<float>::create();
@@ -1360,7 +1186,6 @@ void Variant::reference(const Variant &p_variant) {
} break;
case PACKED_FLOAT64_ARRAY: {
-
_data.packed_array = static_cast<PackedArrayRef<double> *>(p_variant._data.packed_array)->reference();
if (!_data.packed_array) {
_data.packed_array = PackedArrayRef<double>::create();
@@ -1368,7 +1193,6 @@ void Variant::reference(const Variant &p_variant) {
} break;
case PACKED_STRING_ARRAY: {
-
_data.packed_array = static_cast<PackedArrayRef<String> *>(p_variant._data.packed_array)->reference();
if (!_data.packed_array) {
_data.packed_array = PackedArrayRef<String>::create();
@@ -1376,7 +1200,6 @@ void Variant::reference(const Variant &p_variant) {
} break;
case PACKED_VECTOR2_ARRAY: {
-
_data.packed_array = static_cast<PackedArrayRef<Vector2> *>(p_variant._data.packed_array)->reference();
if (!_data.packed_array) {
_data.packed_array = PackedArrayRef<Vector2>::create();
@@ -1384,7 +1207,6 @@ void Variant::reference(const Variant &p_variant) {
} break;
case PACKED_VECTOR3_ARRAY: {
-
_data.packed_array = static_cast<PackedArrayRef<Vector3> *>(p_variant._data.packed_array)->reference();
if (!_data.packed_array) {
_data.packed_array = PackedArrayRef<Vector3>::create();
@@ -1392,7 +1214,6 @@ void Variant::reference(const Variant &p_variant) {
} break;
case PACKED_COLOR_ARRAY: {
-
_data.packed_array = static_cast<PackedArrayRef<Color> *>(p_variant._data.packed_array)->reference();
if (!_data.packed_array) {
_data.packed_array = PackedArrayRef<Color>::create();
@@ -1451,10 +1272,8 @@ void Variant::zero() {
}
void Variant::clear() {
-
switch (type) {
case STRING: {
-
reinterpret_cast<String *>(_data._mem)->~String();
} break;
/*
@@ -1467,33 +1286,26 @@ void Variant::clear() {
RECT2
*/
case TRANSFORM2D: {
-
memdelete(_data._transform2d);
} break;
case AABB: {
-
memdelete(_data._aabb);
} break;
case BASIS: {
-
memdelete(_data._basis);
} break;
case TRANSFORM: {
-
memdelete(_data._transform);
} break;
// misc types
case STRING_NAME: {
-
reinterpret_cast<StringName *>(_data._mem)->~StringName();
} break;
case NODE_PATH: {
-
reinterpret_cast<NodePath *>(_data._mem)->~NodePath();
} break;
case OBJECT: {
-
if (_get_obj().id.is_reference()) {
//we are safe that there is a reference here
Reference *reference = static_cast<Reference *>(_get_obj().obj);
@@ -1509,56 +1321,43 @@ void Variant::clear() {
reinterpret_cast<RID *>(_data._mem)->~RID();
} break;
case CALLABLE: {
-
reinterpret_cast<Callable *>(_data._mem)->~Callable();
} break;
case SIGNAL: {
-
reinterpret_cast<Signal *>(_data._mem)->~Signal();
} break;
case DICTIONARY: {
-
reinterpret_cast<Dictionary *>(_data._mem)->~Dictionary();
} break;
case ARRAY: {
-
reinterpret_cast<Array *>(_data._mem)->~Array();
} break;
// arrays
case PACKED_BYTE_ARRAY: {
-
PackedArrayRefBase::destroy(_data.packed_array);
} break;
case PACKED_INT32_ARRAY: {
-
PackedArrayRefBase::destroy(_data.packed_array);
} break;
case PACKED_INT64_ARRAY: {
-
PackedArrayRefBase::destroy(_data.packed_array);
} break;
case PACKED_FLOAT32_ARRAY: {
-
PackedArrayRefBase::destroy(_data.packed_array);
} break;
case PACKED_FLOAT64_ARRAY: {
-
PackedArrayRefBase::destroy(_data.packed_array);
} break;
case PACKED_STRING_ARRAY: {
-
PackedArrayRefBase::destroy(_data.packed_array);
} break;
case PACKED_VECTOR2_ARRAY: {
-
PackedArrayRefBase::destroy(_data.packed_array);
} break;
case PACKED_VECTOR3_ARRAY: {
-
PackedArrayRefBase::destroy(_data.packed_array);
} break;
case PACKED_COLOR_ARRAY: {
-
PackedArrayRefBase::destroy(_data.packed_array);
} break;
default: {
@@ -1569,9 +1368,7 @@ void Variant::clear() {
}
Variant::operator signed int() const {
-
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1583,15 +1380,13 @@ Variant::operator signed int() const {
case STRING:
return operator String().to_int();
default: {
-
return 0;
}
}
}
-Variant::operator unsigned int() const {
+Variant::operator unsigned int() const {
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1603,16 +1398,13 @@ Variant::operator unsigned int() const {
case STRING:
return operator String().to_int();
default: {
-
return 0;
}
}
}
Variant::operator int64_t() const {
-
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1624,7 +1416,6 @@ Variant::operator int64_t() const {
case STRING:
return operator String().to_int64();
default: {
-
return 0;
}
}
@@ -1651,9 +1442,7 @@ Variant::operator long unsigned int() const {
*/
Variant::operator uint64_t() const {
-
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1665,7 +1454,6 @@ Variant::operator uint64_t() const {
case STRING:
return operator String().to_int();
default: {
-
return 0;
}
}
@@ -1683,9 +1471,7 @@ Variant::operator ObjectID() const {
#ifdef NEED_LONG_INT
Variant::operator signed long() const {
-
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1697,7 +1483,6 @@ Variant::operator signed long() const {
case STRING:
return operator String().to_int();
default: {
-
return 0;
}
}
@@ -1706,9 +1491,7 @@ Variant::operator signed long() const {
};
Variant::operator unsigned long() const {
-
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1720,7 +1503,6 @@ Variant::operator unsigned long() const {
case STRING:
return operator String().to_int();
default: {
-
return 0;
}
}
@@ -1730,9 +1512,7 @@ Variant::operator unsigned long() const {
#endif
Variant::operator signed short() const {
-
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1744,15 +1524,13 @@ Variant::operator signed short() const {
case STRING:
return operator String().to_int();
default: {
-
return 0;
}
}
}
-Variant::operator unsigned short() const {
+Variant::operator unsigned short() const {
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1764,15 +1542,13 @@ Variant::operator unsigned short() const {
case STRING:
return operator String().to_int();
default: {
-
return 0;
}
}
}
-Variant::operator signed char() const {
+Variant::operator signed char() const {
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1784,15 +1560,13 @@ Variant::operator signed char() const {
case STRING:
return operator String().to_int();
default: {
-
return 0;
}
}
}
-Variant::operator unsigned char() const {
+Variant::operator unsigned char() const {
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1804,21 +1578,17 @@ Variant::operator unsigned char() const {
case STRING:
return operator String().to_int();
default: {
-
return 0;
}
}
}
Variant::operator CharType() const {
-
return operator unsigned int();
}
Variant::operator float() const {
-
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1830,15 +1600,13 @@ Variant::operator float() const {
case STRING:
return operator String().to_double();
default: {
-
return 0;
}
}
}
-Variant::operator double() const {
+Variant::operator double() const {
switch (type) {
-
case NIL:
return 0;
case BOOL:
@@ -1850,14 +1618,12 @@ Variant::operator double() const {
case STRING:
return operator String().to_double();
default: {
-
return 0;
}
}
}
Variant::operator StringName() const {
-
if (type == STRING_NAME) {
return *reinterpret_cast<const StringName *>(_data._mem);
} else if (type == STRING) {
@@ -1868,12 +1634,10 @@ Variant::operator StringName() const {
}
struct _VariantStrPair {
-
String key;
String value;
bool operator<(const _VariantStrPair &p) const {
-
return key < p.key;
}
};
@@ -1886,7 +1650,6 @@ Variant::operator String() const {
String Variant::stringify(List<const void *> &stack) const {
switch (type) {
-
case NIL:
return "Null";
case BOOL:
@@ -1906,7 +1669,6 @@ String Variant::stringify(List<const void *> &stack) const {
case RECT2I:
return "(" + operator Rect2i() + ")";
case TRANSFORM2D: {
-
Transform2D mat32 = operator Transform2D();
return "(" + Variant(mat32.elements[0]).operator String() + ", " + Variant(mat32.elements[1]).operator String() + ", " + Variant(mat32.elements[2]).operator String() + ")";
} break;
@@ -1922,21 +1684,20 @@ String Variant::stringify(List<const void *> &stack) const {
case QUAT:
return "(" + operator Quat() + ")";
case BASIS: {
-
Basis mat3 = operator Basis();
String mtx("(");
for (int i = 0; i < 3; i++) {
-
- if (i != 0)
+ if (i != 0) {
mtx += ", ";
+ }
mtx += "(";
for (int j = 0; j < 3; j++) {
-
- if (j != 0)
+ if (j != 0) {
mtx += ", ";
+ }
mtx += Variant(mat3.elements[i][j]).operator String();
}
@@ -1955,7 +1716,6 @@ String Variant::stringify(List<const void *> &stack) const {
case COLOR:
return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a);
case DICTIONARY: {
-
const Dictionary &d = *reinterpret_cast<const Dictionary *>(_data._mem);
if (stack.find(d.id())) {
return "{...}";
@@ -1971,7 +1731,6 @@ String Variant::stringify(List<const void *> &stack) const {
Vector<_VariantStrPair> pairs;
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
_VariantStrPair sp;
sp.key = E->get().stringify(stack);
sp.value = d[E->get()].stringify(stack);
@@ -1982,8 +1741,9 @@ String Variant::stringify(List<const void *> &stack) const {
pairs.sort();
for (int i = 0; i < pairs.size(); i++) {
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str += pairs[i].key + ":" + pairs[i].value;
}
str += "}";
@@ -1991,98 +1751,90 @@ String Variant::stringify(List<const void *> &stack) const {
return str;
} break;
case PACKED_VECTOR2_ARRAY: {
-
Vector<Vector2> vec = operator Vector<Vector2>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + Variant(vec[i]);
}
str += "]";
return str;
} break;
case PACKED_VECTOR3_ARRAY: {
-
Vector<Vector3> vec = operator Vector<Vector3>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + Variant(vec[i]);
}
str += "]";
return str;
} break;
case PACKED_STRING_ARRAY: {
-
Vector<String> vec = operator Vector<String>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + vec[i];
}
str += "]";
return str;
} break;
case PACKED_INT32_ARRAY: {
-
Vector<int32_t> vec = operator Vector<int32_t>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + itos(vec[i]);
}
str += "]";
return str;
} break;
case PACKED_INT64_ARRAY: {
-
Vector<int64_t> vec = operator Vector<int64_t>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + itos(vec[i]);
}
str += "]";
return str;
} break;
case PACKED_FLOAT32_ARRAY: {
-
Vector<float> vec = operator Vector<float>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + rtos(vec[i]);
}
str += "]";
return str;
} break;
case PACKED_FLOAT64_ARRAY: {
-
Vector<double> vec = operator Vector<double>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + rtos(vec[i]);
}
str += "]";
return str;
} break;
case ARRAY: {
-
Array arr = operator Array();
if (stack.find(arr.id())) {
return "[...]";
@@ -2091,8 +1843,9 @@ String Variant::stringify(List<const void *> &stack) const {
String str("[");
for (int i = 0; i < arr.size(); i++) {
- if (i)
+ if (i) {
str += ", ";
+ }
str += arr[i].stringify(stack);
}
@@ -2102,16 +1855,15 @@ String Variant::stringify(List<const void *> &stack) const {
} break;
case OBJECT: {
-
if (_get_obj().obj) {
-
if (!_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
return "[Freed Object]";
};
return _get_obj().obj->to_string();
- } else
+ } else {
return "[Object:null]";
+ }
} break;
case CALLABLE: {
@@ -2135,131 +1887,131 @@ String Variant::stringify(List<const void *> &stack) const {
}
Variant::operator Vector2() const {
-
- if (type == VECTOR2)
+ if (type == VECTOR2) {
return *reinterpret_cast<const Vector2 *>(_data._mem);
- else if (type == VECTOR2I)
+ } else if (type == VECTOR2I) {
return *reinterpret_cast<const Vector2i *>(_data._mem);
- else if (type == VECTOR3)
+ } else if (type == VECTOR3) {
return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y);
- else if (type == VECTOR3I)
+ } else if (type == VECTOR3I) {
return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y);
- else
+ } else {
return Vector2();
+ }
}
Variant::operator Vector2i() const {
-
- if (type == VECTOR2I)
+ if (type == VECTOR2I) {
return *reinterpret_cast<const Vector2i *>(_data._mem);
- else if (type == VECTOR2)
+ } else if (type == VECTOR2) {
return *reinterpret_cast<const Vector2 *>(_data._mem);
- else if (type == VECTOR3)
+ } else if (type == VECTOR3) {
return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y);
- else if (type == VECTOR3I)
+ } else if (type == VECTOR3I) {
return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y);
- else
+ } else {
return Vector2i();
+ }
}
Variant::operator Rect2() const {
-
- if (type == RECT2)
+ if (type == RECT2) {
return *reinterpret_cast<const Rect2 *>(_data._mem);
- else if (type == RECT2I)
+ } else if (type == RECT2I) {
return *reinterpret_cast<const Rect2i *>(_data._mem);
- else
+ } else {
return Rect2();
+ }
}
Variant::operator Rect2i() const {
-
- if (type == RECT2I)
+ if (type == RECT2I) {
return *reinterpret_cast<const Rect2i *>(_data._mem);
- else if (type == RECT2)
+ } else if (type == RECT2) {
return *reinterpret_cast<const Rect2 *>(_data._mem);
- else
+ } else {
return Rect2i();
+ }
}
Variant::operator Vector3() const {
-
- if (type == VECTOR3)
+ if (type == VECTOR3) {
return *reinterpret_cast<const Vector3 *>(_data._mem);
- else if (type == VECTOR3I)
+ } else if (type == VECTOR3I) {
return *reinterpret_cast<const Vector3i *>(_data._mem);
- else if (type == VECTOR2)
+ } else if (type == VECTOR2) {
return Vector3(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
- else if (type == VECTOR2I)
+ } else if (type == VECTOR2I) {
return Vector3(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0);
- else
+ } else {
return Vector3();
+ }
}
Variant::operator Vector3i() const {
-
- if (type == VECTOR3I)
+ if (type == VECTOR3I) {
return *reinterpret_cast<const Vector3i *>(_data._mem);
- else if (type == VECTOR3)
+ } else if (type == VECTOR3) {
return *reinterpret_cast<const Vector3 *>(_data._mem);
- else if (type == VECTOR2)
+ } else if (type == VECTOR2) {
return Vector3i(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
- else if (type == VECTOR2I)
+ } else if (type == VECTOR2I) {
return Vector3i(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0);
- else
+ } else {
return Vector3i();
+ }
}
Variant::operator Plane() const {
-
- if (type == PLANE)
+ if (type == PLANE) {
return *reinterpret_cast<const Plane *>(_data._mem);
- else
+ } else {
return Plane();
+ }
}
-Variant::operator ::AABB() const {
- if (type == AABB)
+Variant::operator ::AABB() const {
+ if (type == AABB) {
return *_data._aabb;
- else
+ } else {
return ::AABB();
+ }
}
Variant::operator Basis() const {
-
- if (type == BASIS)
+ if (type == BASIS) {
return *_data._basis;
- else if (type == QUAT)
+ } else if (type == QUAT) {
return *reinterpret_cast<const Quat *>(_data._mem);
- else if (type == VECTOR3) {
+ } else if (type == VECTOR3) {
return Basis(*reinterpret_cast<const Vector3 *>(_data._mem));
- } else if (type == TRANSFORM) // unexposed in Variant::can_convert?
+ } else if (type == TRANSFORM) { // unexposed in Variant::can_convert?
return _data._transform->basis;
- else
+ } else {
return Basis();
+ }
}
Variant::operator Quat() const {
-
- if (type == QUAT)
+ if (type == QUAT) {
return *reinterpret_cast<const Quat *>(_data._mem);
- else if (type == BASIS)
+ } else if (type == BASIS) {
return *_data._basis;
- else if (type == TRANSFORM)
+ } else if (type == TRANSFORM) {
return _data._transform->basis;
- else
+ } else {
return Quat();
+ }
}
Variant::operator Transform() const {
-
- if (type == TRANSFORM)
+ if (type == TRANSFORM) {
return *_data._transform;
- else if (type == BASIS)
+ } else if (type == BASIS) {
return Transform(*_data._basis, Vector3());
- else if (type == QUAT)
+ } else if (type == QUAT) {
return Transform(Basis(*reinterpret_cast<const Quat *>(_data._mem)), Vector3());
- else if (type == TRANSFORM2D) {
+ } else if (type == TRANSFORM2D) {
const Transform2D &t = *_data._transform2d;
Transform m;
m.basis.elements[0][0] = t.elements[0][0];
@@ -2269,12 +2021,12 @@ Variant::operator Transform() const {
m.origin[0] = t.elements[2][0];
m.origin[1] = t.elements[2][1];
return m;
- } else
+ } else {
return Transform();
+ }
}
Variant::operator Transform2D() const {
-
if (type == TRANSFORM2D) {
return *_data._transform2d;
} else if (type == TRANSFORM) {
@@ -2287,37 +2039,37 @@ Variant::operator Transform2D() const {
m.elements[2][0] = t.origin[0];
m.elements[2][1] = t.origin[1];
return m;
- } else
+ } else {
return Transform2D();
+ }
}
Variant::operator Color() const {
-
- if (type == COLOR)
+ if (type == COLOR) {
return *reinterpret_cast<const Color *>(_data._mem);
- else if (type == STRING)
+ } else if (type == STRING) {
return Color::html(operator String());
- else if (type == INT)
+ } else if (type == INT) {
return Color::hex(operator int());
- else
+ } else {
return Color();
+ }
}
Variant::operator NodePath() const {
-
- if (type == NODE_PATH)
+ if (type == NODE_PATH) {
return *reinterpret_cast<const NodePath *>(_data._mem);
- else if (type == STRING)
+ } else if (type == STRING) {
return NodePath(operator String());
- else
+ } else {
return NodePath();
+ }
}
Variant::operator RID() const {
-
- if (type == _RID)
+ if (type == _RID) {
return *reinterpret_cast<const RID *>(_data._mem);
- else if (type == OBJECT && _get_obj().obj == nullptr) {
+ } else if (type == OBJECT && _get_obj().obj == nullptr) {
return RID();
} else if (type == OBJECT && _get_obj().obj) {
#ifdef DEBUG_ENABLED
@@ -2337,11 +2089,11 @@ Variant::operator RID() const {
}
Variant::operator Object *() const {
-
- if (type == OBJECT)
+ if (type == OBJECT) {
return _get_obj().obj;
- else
+ } else {
return nullptr;
+ }
}
Object *Variant::get_validated_object_with_check(bool &r_previously_freed) const {
@@ -2356,59 +2108,59 @@ Object *Variant::get_validated_object_with_check(bool &r_previously_freed) const
}
Object *Variant::get_validated_object() const {
- if (type == OBJECT)
+ if (type == OBJECT) {
return ObjectDB::get_instance(_get_obj().id);
- else
+ } else {
return nullptr;
+ }
}
Variant::operator Node *() const {
-
- if (type == OBJECT)
+ if (type == OBJECT) {
return Object::cast_to<Node>(_get_obj().obj);
- else
+ } else {
return nullptr;
+ }
}
-Variant::operator Control *() const {
- if (type == OBJECT)
+Variant::operator Control *() const {
+ if (type == OBJECT) {
return Object::cast_to<Control>(_get_obj().obj);
- else
+ } else {
return nullptr;
+ }
}
Variant::operator Dictionary() const {
-
- if (type == DICTIONARY)
+ if (type == DICTIONARY) {
return *reinterpret_cast<const Dictionary *>(_data._mem);
- else
+ } else {
return Dictionary();
+ }
}
Variant::operator Callable() const {
-
- if (type == CALLABLE)
+ if (type == CALLABLE) {
return *reinterpret_cast<const Callable *>(_data._mem);
- else
+ } else {
return Callable();
+ }
}
Variant::operator Signal() const {
-
- if (type == SIGNAL)
+ if (type == SIGNAL) {
return *reinterpret_cast<const Signal *>(_data._mem);
- else
+ } else {
return Signal();
+ }
}
template <class DA, class SA>
inline DA _convert_array(const SA &p_array) {
-
DA da;
da.resize(p_array.size());
for (int i = 0; i < p_array.size(); i++) {
-
da.set(i, Variant(p_array.get(i)));
}
@@ -2417,9 +2169,7 @@ inline DA _convert_array(const SA &p_array) {
template <class DA>
inline DA _convert_array_from_variant(const Variant &p_variant) {
-
switch (p_variant.get_type()) {
-
case Variant::ARRAY: {
return _convert_array<DA, Array>(p_variant.operator Array());
}
@@ -2457,169 +2207,172 @@ inline DA _convert_array_from_variant(const Variant &p_variant) {
}
Variant::operator Array() const {
-
- if (type == ARRAY)
+ if (type == ARRAY) {
return *reinterpret_cast<const Array *>(_data._mem);
- else
+ } else {
return _convert_array_from_variant<Array>(*this);
+ }
}
Variant::operator Vector<uint8_t>() const {
-
- if (type == PACKED_BYTE_ARRAY)
+ if (type == PACKED_BYTE_ARRAY) {
return static_cast<PackedArrayRef<uint8_t> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<uint8_t>>(*this);
+ }
}
-Variant::operator Vector<int32_t>() const {
- if (type == PACKED_INT32_ARRAY)
+Variant::operator Vector<int32_t>() const {
+ if (type == PACKED_INT32_ARRAY) {
return static_cast<PackedArrayRef<int32_t> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<int>>(*this);
+ }
}
-Variant::operator Vector<int64_t>() const {
- if (type == PACKED_INT64_ARRAY)
+Variant::operator Vector<int64_t>() const {
+ if (type == PACKED_INT64_ARRAY) {
return static_cast<PackedArrayRef<int64_t> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<int64_t>>(*this);
+ }
}
Variant::operator Vector<float>() const {
-
- if (type == PACKED_FLOAT32_ARRAY)
+ if (type == PACKED_FLOAT32_ARRAY) {
return static_cast<PackedArrayRef<float> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<float>>(*this);
+ }
}
Variant::operator Vector<double>() const {
-
- if (type == PACKED_FLOAT64_ARRAY)
+ if (type == PACKED_FLOAT64_ARRAY) {
return static_cast<PackedArrayRef<double> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<double>>(*this);
+ }
}
Variant::operator Vector<String>() const {
-
- if (type == PACKED_STRING_ARRAY)
+ if (type == PACKED_STRING_ARRAY) {
return static_cast<PackedArrayRef<String> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<String>>(*this);
+ }
}
-Variant::operator Vector<Vector3>() const {
- if (type == PACKED_VECTOR3_ARRAY)
+Variant::operator Vector<Vector3>() const {
+ if (type == PACKED_VECTOR3_ARRAY) {
return static_cast<PackedArrayRef<Vector3> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<Vector3>>(*this);
+ }
}
-Variant::operator Vector<Vector2>() const {
- if (type == PACKED_VECTOR2_ARRAY)
+Variant::operator Vector<Vector2>() const {
+ if (type == PACKED_VECTOR2_ARRAY) {
return static_cast<PackedArrayRef<Vector2> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<Vector2>>(*this);
+ }
}
Variant::operator Vector<Color>() const {
-
- if (type == PACKED_COLOR_ARRAY)
+ if (type == PACKED_COLOR_ARRAY) {
return static_cast<PackedArrayRef<Color> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<Color>>(*this);
+ }
}
/* helpers */
Variant::operator Vector<RID>() const {
-
Array va = operator Array();
Vector<RID> rids;
rids.resize(va.size());
- for (int i = 0; i < rids.size(); i++)
+ for (int i = 0; i < rids.size(); i++) {
rids.write[i] = va[i];
+ }
return rids;
}
Variant::operator Vector<Plane>() const {
-
Array va = operator Array();
Vector<Plane> planes;
int va_size = va.size();
- if (va_size == 0)
+ if (va_size == 0) {
return planes;
+ }
planes.resize(va_size);
Plane *w = planes.ptrw();
- for (int i = 0; i < va_size; i++)
+ for (int i = 0; i < va_size; i++) {
w[i] = va[i];
+ }
return planes;
}
Variant::operator Vector<Face3>() const {
-
Vector<Vector3> va = operator Vector<Vector3>();
Vector<Face3> faces;
int va_size = va.size();
- if (va_size == 0)
+ if (va_size == 0) {
return faces;
+ }
faces.resize(va_size / 3);
Face3 *w = faces.ptrw();
const Vector3 *r = va.ptr();
- for (int i = 0; i < va_size; i++)
+ for (int i = 0; i < va_size; i++) {
w[i / 3].vertex[i % 3] = r[i];
+ }
return faces;
}
Variant::operator Vector<Variant>() const {
-
Array va = operator Array();
Vector<Variant> variants;
int va_size = va.size();
- if (va_size == 0)
+ if (va_size == 0) {
return variants;
+ }
variants.resize(va_size);
Variant *w = variants.ptrw();
- for (int i = 0; i < va_size; i++)
+ for (int i = 0; i < va_size; i++) {
w[i] = va[i];
+ }
return variants;
}
-Variant::operator Vector<StringName>() const {
+Variant::operator Vector<StringName>() const {
Vector<String> from = operator Vector<String>();
Vector<StringName> to;
int len = from.size();
to.resize(len);
for (int i = 0; i < len; i++) {
-
to.write[i] = from[i];
}
return to;
}
Variant::operator Margin() const {
-
return (Margin) operator int();
}
-Variant::operator Orientation() const {
+Variant::operator Orientation() const {
return (Orientation) operator int();
}
Variant::operator IP_Address() const {
-
if (type == PACKED_FLOAT32_ARRAY || type == PACKED_INT32_ARRAY || type == PACKED_FLOAT64_ARRAY || type == PACKED_INT64_ARRAY || type == PACKED_BYTE_ARRAY) {
-
Vector<int> addr = operator Vector<int>();
if (addr.size() == 4) {
return IP_Address(addr.get(0), addr.get(1), addr.get(2), addr.get(3));
@@ -2630,7 +2383,6 @@ Variant::operator IP_Address() const {
}
Variant::Variant(bool p_bool) {
-
type = BOOL;
_data._bool = p_bool;
}
@@ -2644,12 +2396,11 @@ Variant::Variant(long unsigned int p_long) {
*/
Variant::Variant(signed int p_int) {
-
type = INT;
_data._int = p_int;
}
-Variant::Variant(unsigned int p_int) {
+Variant::Variant(unsigned int p_int) {
type = INT;
_data._int = p_int;
}
@@ -2657,56 +2408,52 @@ Variant::Variant(unsigned int p_int) {
#ifdef NEED_LONG_INT
Variant::Variant(signed long p_int) {
-
type = INT;
_data._int = p_int;
}
-Variant::Variant(unsigned long p_int) {
+Variant::Variant(unsigned long p_int) {
type = INT;
_data._int = p_int;
}
#endif
Variant::Variant(int64_t p_int) {
-
type = INT;
_data._int = p_int;
}
Variant::Variant(uint64_t p_int) {
-
type = INT;
_data._int = p_int;
}
Variant::Variant(signed short p_short) {
-
type = INT;
_data._int = p_short;
}
-Variant::Variant(unsigned short p_short) {
+Variant::Variant(unsigned short p_short) {
type = INT;
_data._int = p_short;
}
-Variant::Variant(signed char p_char) {
+Variant::Variant(signed char p_char) {
type = INT;
_data._int = p_char;
}
-Variant::Variant(unsigned char p_char) {
+Variant::Variant(unsigned char p_char) {
type = INT;
_data._int = p_char;
}
-Variant::Variant(float p_float) {
+Variant::Variant(float p_float) {
type = FLOAT;
_data._float = p_float;
}
-Variant::Variant(double p_double) {
+Variant::Variant(double p_double) {
type = FLOAT;
_data._float = p_double;
}
@@ -2717,121 +2464,106 @@ Variant::Variant(const ObjectID &p_id) {
}
Variant::Variant(const StringName &p_string) {
-
type = STRING_NAME;
memnew_placement(_data._mem, StringName(p_string));
}
-Variant::Variant(const String &p_string) {
+Variant::Variant(const String &p_string) {
type = STRING;
memnew_placement(_data._mem, String(p_string));
}
Variant::Variant(const char *const p_cstring) {
-
type = STRING;
memnew_placement(_data._mem, String((const char *)p_cstring));
}
Variant::Variant(const CharType *p_wstring) {
-
type = STRING;
memnew_placement(_data._mem, String(p_wstring));
}
-Variant::Variant(const Vector3 &p_vector3) {
+Variant::Variant(const Vector3 &p_vector3) {
type = VECTOR3;
memnew_placement(_data._mem, Vector3(p_vector3));
}
-Variant::Variant(const Vector3i &p_vector3i) {
+Variant::Variant(const Vector3i &p_vector3i) {
type = VECTOR3I;
memnew_placement(_data._mem, Vector3i(p_vector3i));
}
Variant::Variant(const Vector2 &p_vector2) {
-
type = VECTOR2;
memnew_placement(_data._mem, Vector2(p_vector2));
}
Variant::Variant(const Vector2i &p_vector2i) {
-
type = VECTOR2I;
memnew_placement(_data._mem, Vector2i(p_vector2i));
}
Variant::Variant(const Rect2 &p_rect2) {
-
type = RECT2;
memnew_placement(_data._mem, Rect2(p_rect2));
}
Variant::Variant(const Rect2i &p_rect2i) {
-
type = RECT2I;
memnew_placement(_data._mem, Rect2i(p_rect2i));
}
Variant::Variant(const Plane &p_plane) {
-
type = PLANE;
memnew_placement(_data._mem, Plane(p_plane));
}
-Variant::Variant(const ::AABB &p_aabb) {
+Variant::Variant(const ::AABB &p_aabb) {
type = AABB;
_data._aabb = memnew(::AABB(p_aabb));
}
Variant::Variant(const Basis &p_matrix) {
-
type = BASIS;
_data._basis = memnew(Basis(p_matrix));
}
Variant::Variant(const Quat &p_quat) {
-
type = QUAT;
memnew_placement(_data._mem, Quat(p_quat));
}
-Variant::Variant(const Transform &p_transform) {
+Variant::Variant(const Transform &p_transform) {
type = TRANSFORM;
_data._transform = memnew(Transform(p_transform));
}
Variant::Variant(const Transform2D &p_transform) {
-
type = TRANSFORM2D;
_data._transform2d = memnew(Transform2D(p_transform));
}
-Variant::Variant(const Color &p_color) {
+Variant::Variant(const Color &p_color) {
type = COLOR;
memnew_placement(_data._mem, Color(p_color));
}
Variant::Variant(const NodePath &p_node_path) {
-
type = NODE_PATH;
memnew_placement(_data._mem, NodePath(p_node_path));
}
Variant::Variant(const RID &p_rid) {
-
type = _RID;
memnew_placement(_data._mem, RID(p_rid));
}
Variant::Variant(const Object *p_object) {
-
type = OBJECT;
memnew_placement(_data._mem, ObjData);
if (p_object) {
-
if (p_object->is_reference()) {
Reference *reference = const_cast<Reference *>(static_cast<const Reference *>(p_object));
if (!reference->init_ref()) {
@@ -2850,30 +2582,26 @@ Variant::Variant(const Object *p_object) {
}
Variant::Variant(const Callable &p_callable) {
-
type = CALLABLE;
memnew_placement(_data._mem, Callable(p_callable));
}
-Variant::Variant(const Signal &p_callable) {
+Variant::Variant(const Signal &p_callable) {
type = SIGNAL;
memnew_placement(_data._mem, Signal(p_callable));
}
Variant::Variant(const Dictionary &p_dictionary) {
-
type = DICTIONARY;
memnew_placement(_data._mem, Dictionary(p_dictionary));
}
Variant::Variant(const Array &p_array) {
-
type = ARRAY;
memnew_placement(_data._mem, Array(p_array));
}
Variant::Variant(const Vector<Plane> &p_array) {
-
type = ARRAY;
Array *plane_array = memnew_placement(_data._mem, Array);
@@ -2881,13 +2609,11 @@ Variant::Variant(const Vector<Plane> &p_array) {
plane_array->resize(p_array.size());
for (int i = 0; i < p_array.size(); i++) {
-
plane_array->operator[](i) = Variant(p_array[i]);
}
}
Variant::Variant(const Vector<RID> &p_array) {
-
type = ARRAY;
Array *rid_array = memnew_placement(_data._mem, Array);
@@ -2895,65 +2621,57 @@ Variant::Variant(const Vector<RID> &p_array) {
rid_array->resize(p_array.size());
for (int i = 0; i < p_array.size(); i++) {
-
rid_array->set(i, Variant(p_array[i]));
}
}
Variant::Variant(const Vector<uint8_t> &p_byte_array) {
-
type = PACKED_BYTE_ARRAY;
_data.packed_array = PackedArrayRef<uint8_t>::create(p_byte_array);
}
-Variant::Variant(const Vector<int32_t> &p_int32_array) {
+Variant::Variant(const Vector<int32_t> &p_int32_array) {
type = PACKED_INT32_ARRAY;
_data.packed_array = PackedArrayRef<int32_t>::create(p_int32_array);
}
Variant::Variant(const Vector<int64_t> &p_int64_array) {
-
type = PACKED_INT64_ARRAY;
_data.packed_array = PackedArrayRef<int64_t>::create(p_int64_array);
}
Variant::Variant(const Vector<float> &p_float32_array) {
-
type = PACKED_FLOAT32_ARRAY;
_data.packed_array = PackedArrayRef<float>::create(p_float32_array);
}
Variant::Variant(const Vector<double> &p_float64_array) {
-
type = PACKED_FLOAT64_ARRAY;
_data.packed_array = PackedArrayRef<double>::create(p_float64_array);
}
Variant::Variant(const Vector<String> &p_string_array) {
-
type = PACKED_STRING_ARRAY;
_data.packed_array = PackedArrayRef<String>::create(p_string_array);
}
-Variant::Variant(const Vector<Vector3> &p_vector3_array) {
+Variant::Variant(const Vector<Vector3> &p_vector3_array) {
type = PACKED_VECTOR3_ARRAY;
_data.packed_array = PackedArrayRef<Vector3>::create(p_vector3_array);
}
Variant::Variant(const Vector<Vector2> &p_vector2_array) {
-
type = PACKED_VECTOR2_ARRAY;
_data.packed_array = PackedArrayRef<Vector2>::create(p_vector2_array);
}
-Variant::Variant(const Vector<Color> &p_color_array) {
+Variant::Variant(const Vector<Color> &p_color_array) {
type = PACKED_COLOR_ARRAY;
_data.packed_array = PackedArrayRef<Color>::create(p_color_array);
}
Variant::Variant(const Vector<Face3> &p_face_array) {
-
Vector<Vector3> vertices;
int face_count = p_face_array.size();
vertices.resize(face_count * 3);
@@ -2963,9 +2681,9 @@ Variant::Variant(const Vector<Face3> &p_face_array) {
Vector3 *w = vertices.ptrw();
for (int i = 0; i < face_count; i++) {
-
- for (int j = 0; j < 3; j++)
+ for (int j = 0; j < 3; j++) {
w[i * 3 + j] = r[i].vertex[j];
+ }
}
}
@@ -2986,20 +2704,20 @@ Variant::Variant(const Vector<Variant> &p_array) {
}
Variant::Variant(const Vector<StringName> &p_array) {
-
type = NIL;
Vector<String> v;
int len = p_array.size();
v.resize(len);
- for (int i = 0; i < len; i++)
+ for (int i = 0; i < len; i++) {
v.set(i, p_array[i]);
+ }
*this = v;
}
void Variant::operator=(const Variant &p_variant) {
-
- if (unlikely(this == &p_variant))
+ if (unlikely(this == &p_variant)) {
return;
+ }
if (unlikely(type != p_variant.type)) {
reference(p_variant);
@@ -3008,90 +2726,70 @@ void Variant::operator=(const Variant &p_variant) {
switch (p_variant.type) {
case NIL: {
-
// none
} break;
// atomic types
case BOOL: {
-
_data._bool = p_variant._data._bool;
} break;
case INT: {
-
_data._int = p_variant._data._int;
} break;
case FLOAT: {
-
_data._float = p_variant._data._float;
} break;
case STRING: {
-
*reinterpret_cast<String *>(_data._mem) = *reinterpret_cast<const String *>(p_variant._data._mem);
} break;
// math types
case VECTOR2: {
-
*reinterpret_cast<Vector2 *>(_data._mem) = *reinterpret_cast<const Vector2 *>(p_variant._data._mem);
} break;
case VECTOR2I: {
-
*reinterpret_cast<Vector2i *>(_data._mem) = *reinterpret_cast<const Vector2i *>(p_variant._data._mem);
} break;
case RECT2: {
-
*reinterpret_cast<Rect2 *>(_data._mem) = *reinterpret_cast<const Rect2 *>(p_variant._data._mem);
} break;
case RECT2I: {
-
*reinterpret_cast<Rect2i *>(_data._mem) = *reinterpret_cast<const Rect2i *>(p_variant._data._mem);
} break;
case TRANSFORM2D: {
-
*_data._transform2d = *(p_variant._data._transform2d);
} break;
case VECTOR3: {
-
*reinterpret_cast<Vector3 *>(_data._mem) = *reinterpret_cast<const Vector3 *>(p_variant._data._mem);
} break;
case VECTOR3I: {
-
*reinterpret_cast<Vector3i *>(_data._mem) = *reinterpret_cast<const Vector3i *>(p_variant._data._mem);
} break;
case PLANE: {
-
*reinterpret_cast<Plane *>(_data._mem) = *reinterpret_cast<const Plane *>(p_variant._data._mem);
} break;
case AABB: {
-
*_data._aabb = *(p_variant._data._aabb);
} break;
case QUAT: {
-
*reinterpret_cast<Quat *>(_data._mem) = *reinterpret_cast<const Quat *>(p_variant._data._mem);
} break;
case BASIS: {
-
*_data._basis = *(p_variant._data._basis);
} break;
case TRANSFORM: {
-
*_data._transform = *(p_variant._data._transform);
} break;
// misc types
case COLOR: {
-
*reinterpret_cast<Color *>(_data._mem) = *reinterpret_cast<const Color *>(p_variant._data._mem);
} break;
case _RID: {
-
*reinterpret_cast<RID *>(_data._mem) = *reinterpret_cast<const RID *>(p_variant._data._mem);
} break;
case OBJECT: {
-
if (_get_obj().id.is_reference()) {
//we are safe that there is a reference here
Reference *reference = static_cast<Reference *>(_get_obj().obj);
@@ -3114,66 +2812,51 @@ void Variant::operator=(const Variant &p_variant) {
} break;
case CALLABLE: {
-
*reinterpret_cast<Callable *>(_data._mem) = *reinterpret_cast<const Callable *>(p_variant._data._mem);
} break;
case SIGNAL: {
-
*reinterpret_cast<Signal *>(_data._mem) = *reinterpret_cast<const Signal *>(p_variant._data._mem);
} break;
case STRING_NAME: {
-
*reinterpret_cast<StringName *>(_data._mem) = *reinterpret_cast<const StringName *>(p_variant._data._mem);
} break;
case NODE_PATH: {
-
*reinterpret_cast<NodePath *>(_data._mem) = *reinterpret_cast<const NodePath *>(p_variant._data._mem);
} break;
case DICTIONARY: {
-
*reinterpret_cast<Dictionary *>(_data._mem) = *reinterpret_cast<const Dictionary *>(p_variant._data._mem);
} break;
case ARRAY: {
-
*reinterpret_cast<Array *>(_data._mem) = *reinterpret_cast<const Array *>(p_variant._data._mem);
} break;
// arrays
case PACKED_BYTE_ARRAY: {
-
_data.packed_array = PackedArrayRef<uint8_t>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
case PACKED_INT32_ARRAY: {
-
_data.packed_array = PackedArrayRef<int32_t>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
case PACKED_INT64_ARRAY: {
-
_data.packed_array = PackedArrayRef<int64_t>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
case PACKED_FLOAT32_ARRAY: {
-
_data.packed_array = PackedArrayRef<float>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
case PACKED_FLOAT64_ARRAY: {
-
_data.packed_array = PackedArrayRef<double>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
case PACKED_STRING_ARRAY: {
-
_data.packed_array = PackedArrayRef<String>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
case PACKED_VECTOR2_ARRAY: {
-
_data.packed_array = PackedArrayRef<Vector2>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
case PACKED_VECTOR3_ARRAY: {
-
_data.packed_array = PackedArrayRef<Vector3>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
case PACKED_COLOR_ARRAY: {
-
_data.packed_array = PackedArrayRef<Color>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
default: {
@@ -3182,70 +2865,56 @@ void Variant::operator=(const Variant &p_variant) {
}
Variant::Variant(const IP_Address &p_address) {
-
type = STRING;
memnew_placement(_data._mem, String(p_address));
}
Variant::Variant(const Variant &p_variant) {
-
reference(p_variant);
}
uint32_t Variant::hash() const {
-
switch (type) {
case NIL: {
-
return 0;
} break;
case BOOL: {
-
return _data._bool ? 1 : 0;
} break;
case INT: {
-
return _data._int;
} break;
case FLOAT: {
-
return hash_djb2_one_float(_data._float);
} break;
case STRING: {
-
return reinterpret_cast<const String *>(_data._mem)->hash();
} break;
// math types
case VECTOR2: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->x);
return hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->y, hash);
} break;
case VECTOR2I: {
-
uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Vector2i *>(_data._mem)->x);
return hash_djb2_one_32(reinterpret_cast<const Vector2i *>(_data._mem)->y, hash);
} break;
case RECT2: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.x);
hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.y, hash);
hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.x, hash);
return hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.y, hash);
} break;
case RECT2I: {
-
uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->position.x);
hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->position.y, hash);
hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->size.x, hash);
return hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->size.y, hash);
} break;
case TRANSFORM2D: {
-
uint32_t hash = 5831;
for (int i = 0; i < 3; i++) {
-
for (int j = 0; j < 2; j++) {
hash = hash_djb2_one_float(_data._transform2d->elements[i][j], hash);
}
@@ -3254,19 +2923,16 @@ uint32_t Variant::hash() const {
return hash;
} break;
case VECTOR3: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->x);
hash = hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->y, hash);
return hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->z, hash);
} break;
case VECTOR3I: {
-
uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->x);
hash = hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->y, hash);
return hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->z, hash);
} break;
case PLANE: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.x);
hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.y, hash);
hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.z, hash);
@@ -3279,10 +2945,8 @@ uint32_t Variant::hash() const {
} break;*/
case AABB: {
-
uint32_t hash = 5831;
for (int i = 0; i < 3; i++) {
-
hash = hash_djb2_one_float(_data._aabb->position[i], hash);
hash = hash_djb2_one_float(_data._aabb->size[i], hash);
}
@@ -3291,7 +2955,6 @@ uint32_t Variant::hash() const {
} break;
case QUAT: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Quat *>(_data._mem)->x);
hash = hash_djb2_one_float(reinterpret_cast<const Quat *>(_data._mem)->y, hash);
hash = hash_djb2_one_float(reinterpret_cast<const Quat *>(_data._mem)->z, hash);
@@ -3299,10 +2962,8 @@ uint32_t Variant::hash() const {
} break;
case BASIS: {
-
uint32_t hash = 5831;
for (int i = 0; i < 3; i++) {
-
for (int j = 0; j < 3; j++) {
hash = hash_djb2_one_float(_data._basis->elements[i][j], hash);
}
@@ -3312,10 +2973,8 @@ uint32_t Variant::hash() const {
} break;
case TRANSFORM: {
-
uint32_t hash = 5831;
for (int i = 0; i < 3; i++) {
-
for (int j = 0; j < 3; j++) {
hash = hash_djb2_one_float(_data._transform->basis.elements[i][j], hash);
}
@@ -3328,7 +2987,6 @@ uint32_t Variant::hash() const {
// misc types
case COLOR: {
-
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Color *>(_data._mem)->r);
hash = hash_djb2_one_float(reinterpret_cast<const Color *>(_data._mem)->g, hash);
hash = hash_djb2_one_float(reinterpret_cast<const Color *>(_data._mem)->b, hash);
@@ -3336,45 +2994,36 @@ uint32_t Variant::hash() const {
} break;
case _RID: {
-
return hash_djb2_one_64(reinterpret_cast<const RID *>(_data._mem)->get_id());
} break;
case OBJECT: {
-
return hash_djb2_one_64(make_uint64_t(_get_obj().obj));
} break;
case STRING_NAME: {
-
return reinterpret_cast<const StringName *>(_data._mem)->hash();
} break;
case NODE_PATH: {
-
return reinterpret_cast<const NodePath *>(_data._mem)->hash();
} break;
case DICTIONARY: {
-
return reinterpret_cast<const Dictionary *>(_data._mem)->hash();
} break;
case CALLABLE: {
-
return reinterpret_cast<const Callable *>(_data._mem)->hash();
} break;
case SIGNAL: {
-
const Signal &s = *reinterpret_cast<const Signal *>(_data._mem);
uint32_t hash = s.get_name().hash();
return hash_djb2_one_64(s.get_object_id(), hash);
} break;
case ARRAY: {
-
const Array &arr = *reinterpret_cast<const Array *>(_data._mem);
return arr.hash();
} break;
case PACKED_BYTE_ARRAY: {
-
const Vector<uint8_t> &arr = PackedArrayRef<uint8_t>::get_array(_data.packed_array);
int len = arr.size();
if (likely(len)) {
@@ -3386,7 +3035,6 @@ uint32_t Variant::hash() const {
} break;
case PACKED_INT32_ARRAY: {
-
const Vector<int32_t> &arr = PackedArrayRef<int32_t>::get_array(_data.packed_array);
int len = arr.size();
if (likely(len)) {
@@ -3398,7 +3046,6 @@ uint32_t Variant::hash() const {
} break;
case PACKED_INT64_ARRAY: {
-
const Vector<int64_t> &arr = PackedArrayRef<int64_t>::get_array(_data.packed_array);
int len = arr.size();
if (likely(len)) {
@@ -3410,7 +3057,6 @@ uint32_t Variant::hash() const {
} break;
case PACKED_FLOAT32_ARRAY: {
-
const Vector<float> &arr = PackedArrayRef<float>::get_array(_data.packed_array);
int len = arr.size();
@@ -3423,7 +3069,6 @@ uint32_t Variant::hash() const {
} break;
case PACKED_FLOAT64_ARRAY: {
-
const Vector<double> &arr = PackedArrayRef<double>::get_array(_data.packed_array);
int len = arr.size();
@@ -3436,7 +3081,6 @@ uint32_t Variant::hash() const {
} break;
case PACKED_STRING_ARRAY: {
-
uint32_t hash = 5831;
const Vector<String> &arr = PackedArrayRef<String>::get_array(_data.packed_array);
int len = arr.size();
@@ -3452,7 +3096,6 @@ uint32_t Variant::hash() const {
return hash;
} break;
case PACKED_VECTOR2_ARRAY: {
-
uint32_t hash = 5831;
const Vector<Vector2> &arr = PackedArrayRef<Vector2>::get_array(_data.packed_array);
int len = arr.size();
@@ -3469,7 +3112,6 @@ uint32_t Variant::hash() const {
return hash;
} break;
case PACKED_VECTOR3_ARRAY: {
-
uint32_t hash = 5831;
const Vector<Vector3> &arr = PackedArrayRef<Vector3>::get_array(_data.packed_array);
int len = arr.size();
@@ -3487,7 +3129,6 @@ uint32_t Variant::hash() const {
return hash;
} break;
case PACKED_COLOR_ARRAY: {
-
uint32_t hash = 5831;
const Vector<Color> &arr = PackedArrayRef<Color>::get_array(_data.packed_array);
int len = arr.size();
@@ -3554,8 +3195,9 @@ uint32_t Variant::hash() const {
return true
bool Variant::hash_compare(const Variant &p_variant) const {
- if (type != p_variant.type)
+ if (type != p_variant.type) {
return false;
+ }
switch (type) {
case FLOAT: {
@@ -3593,8 +3235,9 @@ bool Variant::hash_compare(const Variant &p_variant) const {
Transform2D *r = p_variant._data._transform2d;
for (int i = 0; i < 3; i++) {
- if (!(hash_compare_vector2(l->elements[i], r->elements[i])))
+ if (!(hash_compare_vector2(l->elements[i], r->elements[i]))) {
return false;
+ }
}
return true;
@@ -3642,8 +3285,9 @@ bool Variant::hash_compare(const Variant &p_variant) const {
const Basis *r = p_variant._data._basis;
for (int i = 0; i < 3; i++) {
- if (!(hash_compare_vector3(l->elements[i], r->elements[i])))
+ if (!(hash_compare_vector3(l->elements[i], r->elements[i]))) {
return false;
+ }
}
return true;
@@ -3654,8 +3298,9 @@ bool Variant::hash_compare(const Variant &p_variant) const {
const Transform *r = p_variant._data._transform;
for (int i = 0; i < 3; i++) {
- if (!(hash_compare_vector3(l->basis.elements[i], r->basis.elements[i])))
+ if (!(hash_compare_vector3(l->basis.elements[i], r->basis.elements[i]))) {
return false;
+ }
}
return hash_compare_vector3(l->origin, r->origin);
@@ -3672,12 +3317,14 @@ bool Variant::hash_compare(const Variant &p_variant) const {
const Array &l = *(reinterpret_cast<const Array *>(_data._mem));
const Array &r = *(reinterpret_cast<const Array *>(p_variant._data._mem));
- if (l.size() != r.size())
+ if (l.size() != r.size()) {
return false;
+ }
for (int i = 0; i < l.size(); ++i) {
- if (!l[i].hash_compare(r[i]))
+ if (!l[i].hash_compare(r[i])) {
return false;
+ }
}
return true;
@@ -3715,38 +3362,35 @@ bool Variant::hash_compare(const Variant &p_variant) const {
}
bool Variant::is_ref() const {
-
return type == OBJECT && _get_obj().id.is_reference();
}
Vector<Variant> varray() {
-
return Vector<Variant>();
}
Vector<Variant> varray(const Variant &p_arg1) {
-
Vector<Variant> v;
v.push_back(p_arg1);
return v;
}
-Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2) {
+Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2) {
Vector<Variant> v;
v.push_back(p_arg1);
v.push_back(p_arg2);
return v;
}
-Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3) {
+Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3) {
Vector<Variant> v;
v.push_back(p_arg1);
v.push_back(p_arg2);
v.push_back(p_arg3);
return v;
}
-Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4) {
+Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4) {
Vector<Variant> v;
v.push_back(p_arg1);
v.push_back(p_arg2);
@@ -3756,7 +3400,6 @@ Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Varia
}
Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5) {
-
Vector<Variant> v;
v.push_back(p_arg1);
v.push_back(p_arg2);
@@ -3770,9 +3413,7 @@ void Variant::static_assign(const Variant &p_variant) {
}
bool Variant::is_shared() const {
-
switch (type) {
-
case OBJECT:
return true;
case ARRAY:
@@ -3790,8 +3431,9 @@ Variant Variant::call(const StringName &p_method, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -3800,20 +3442,16 @@ Variant Variant::call(const StringName &p_method, VARIANT_ARG_DECLARE) {
Variant ret = call(p_method, argptr, argc, error);
switch (error.error) {
-
case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: {
-
String err = "Invalid type for argument #" + itos(error.argument) + ", expected '" + Variant::get_type_name(Variant::Type(error.expected)) + "'.";
ERR_PRINT(err.utf8().get_data());
} break;
case Callable::CallError::CALL_ERROR_INVALID_METHOD: {
-
String err = "Invalid method '" + p_method + "' for type '" + Variant::get_type_name(type) + "'.";
ERR_PRINT(err.utf8().get_data());
} break;
case Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: {
-
String err = "Too many arguments for method '" + p_method + "'";
ERR_PRINT(err.utf8().get_data());
} break;
@@ -3825,12 +3463,10 @@ Variant Variant::call(const StringName &p_method, VARIANT_ARG_DECLARE) {
}
void Variant::construct_from_string(const String &p_string, Variant &r_value, ObjectConstruct p_obj_construct, void *p_construct_ud) {
-
r_value = Variant();
}
String Variant::get_construct_string() const {
-
String vars;
VariantWriter::write_to_string(*this, vars);
@@ -3838,7 +3474,6 @@ String Variant::get_construct_string() const {
}
String Variant::get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) {
-
String err_text;
if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) {
@@ -3863,14 +3498,12 @@ String Variant::get_call_error_text(Object *p_base, const StringName &p_method,
String class_name = p_base->get_class();
Ref<Script> script = p_base->get_script();
if (script.is_valid() && script->get_path().is_resource_file()) {
-
class_name += "(" + script->get_path().get_file() + ")";
}
return "'" + class_name + "::" + String(p_method) + "': " + err_text;
}
String Variant::get_callable_error_text(const Callable &p_callable, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) {
-
String err_text;
if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) {
@@ -3896,26 +3529,20 @@ String Variant::get_callable_error_text(const Callable &p_callable, const Varian
}
String vformat(const String &p_text, const Variant &p1, const Variant &p2, const Variant &p3, const Variant &p4, const Variant &p5) {
-
Array args;
if (p1.get_type() != Variant::NIL) {
-
args.push_back(p1);
if (p2.get_type() != Variant::NIL) {
-
args.push_back(p2);
if (p3.get_type() != Variant::NIL) {
-
args.push_back(p3);
if (p4.get_type() != Variant::NIL) {
-
args.push_back(p4);
if (p5.get_type() != Variant::NIL) {
-
args.push_back(p5);
}
}
diff --git a/core/variant.h b/core/variant.h
index 0498e93825..b24cf968de 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -126,7 +126,6 @@ private:
Type type = NIL;
struct ObjData {
-
ObjectID id;
Object *obj;
};
@@ -403,7 +402,6 @@ public:
static String get_operator_name(Operator p_op);
static void evaluate(const Operator &p_op, const Variant &p_a, const Variant &p_b, Variant &r_ret, bool &r_valid);
static _FORCE_INLINE_ Variant evaluate(const Operator &p_op, const Variant &p_a, const Variant &p_b) {
-
bool valid = true;
Variant res;
evaluate(p_op, p_a, p_b, res, valid);
@@ -473,8 +471,9 @@ public:
Variant(const Variant &p_variant);
_FORCE_INLINE_ Variant() {}
_FORCE_INLINE_ ~Variant() {
- if (type != Variant::NIL)
+ if (type != Variant::NIL) {
clear();
+ }
}
};
@@ -489,22 +488,18 @@ Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Varia
Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5);
struct VariantHasher {
-
static _FORCE_INLINE_ uint32_t hash(const Variant &p_variant) { return p_variant.hash(); }
};
struct VariantComparator {
-
static _FORCE_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); }
};
Variant::ObjData &Variant::_get_obj() {
-
return *reinterpret_cast<ObjData *>(&_data._mem[0]);
}
const Variant::ObjData &Variant::_get_obj() const {
-
return *reinterpret_cast<const ObjData *>(&_data._mem[0]);
}
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 416a1a5fb8..82b1f29805 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -42,14 +42,11 @@ typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_a
typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args);
struct _VariantCall {
-
static void Vector3_dot(Variant &r_ret, Variant &p_self, const Variant **p_args) {
-
r_ret = reinterpret_cast<Vector3 *>(p_self._data._mem)->dot(*reinterpret_cast<const Vector3 *>(p_args[0]->_data._mem));
}
struct FuncData {
-
int arg_count;
Vector<Variant> default_args;
Vector<Variant::Type> arg_types;
@@ -62,16 +59,16 @@ struct _VariantCall {
VariantFunc func;
_FORCE_INLINE_ bool verify_arguments(const Variant **p_args, Callable::CallError &r_error) {
-
- if (arg_count == 0)
+ if (arg_count == 0) {
return true;
+ }
const Variant::Type *tptr = &arg_types[0];
for (int i = 0; i < arg_count; i++) {
-
- if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type)
+ if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type) {
continue; // all good
+ }
if (!Variant::can_convert(p_args[i]->type, tptr[i])) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = i;
@@ -102,21 +99,25 @@ struct _VariantCall {
#endif
ERR_FAIL_COND(p_argcount > VARIANT_ARG_MAX);
const Variant *newargs[VARIANT_ARG_MAX];
- for (int i = 0; i < p_argcount; i++)
+ for (int i = 0; i < p_argcount; i++) {
newargs[i] = p_args[i];
+ }
// fill in any remaining parameters with defaults
int first_default_arg = arg_count - def_argcount;
- for (int i = p_argcount; i < arg_count; i++)
+ for (int i = p_argcount; i < arg_count; i++) {
newargs[i] = &default_args[i - first_default_arg];
+ }
#ifdef DEBUG_ENABLED
- if (!verify_arguments(newargs, r_error))
+ if (!verify_arguments(newargs, r_error)) {
return;
+ }
#endif
func(r_ret, p_self, newargs);
} else {
#ifdef DEBUG_ENABLED
- if (!verify_arguments(p_args, r_error))
+ if (!verify_arguments(p_args, r_error)) {
return;
+ }
#endif
func(r_ret, p_self, p_args);
}
@@ -124,7 +125,6 @@ struct _VariantCall {
};
struct TypeFunc {
-
Map<StringName, FuncData> functions;
};
@@ -143,14 +143,12 @@ struct _VariantCall {
//void addfunc(Variant::Type p_type, const StringName& p_name,VariantFunc p_func);
static void make_func_return_variant(Variant::Type p_type, const StringName &p_name) {
-
#ifdef DEBUG_ENABLED
type_funcs[p_type].functions[p_name].returns = true;
#endif
}
static void addfunc(bool p_const, Variant::Type p_type, Variant::Type p_return, bool p_has_return, const StringName &p_name, VariantFunc p_func, const Vector<Variant> &p_defaultarg, const Arg &p_argtype1 = Arg(), const Arg &p_argtype2 = Arg(), const Arg &p_argtype3 = Arg(), const Arg &p_argtype4 = Arg(), const Arg &p_argtype5 = Arg()) {
-
FuncData funcdata;
funcdata.func = p_func;
funcdata.default_args = p_defaultarg;
@@ -164,8 +162,9 @@ struct _VariantCall {
funcdata.arg_names.push_back(p_argtype1.name);
#endif
- } else
+ } else {
goto end;
+ }
if (p_argtype2.name) {
funcdata.arg_types.push_back(p_argtype2.type);
@@ -173,8 +172,9 @@ struct _VariantCall {
funcdata.arg_names.push_back(p_argtype2.name);
#endif
- } else
+ } else {
goto end;
+ }
if (p_argtype3.name) {
funcdata.arg_types.push_back(p_argtype3.type);
@@ -182,24 +182,27 @@ struct _VariantCall {
funcdata.arg_names.push_back(p_argtype3.name);
#endif
- } else
+ } else {
goto end;
+ }
if (p_argtype4.name) {
funcdata.arg_types.push_back(p_argtype4.type);
#ifdef DEBUG_ENABLED
funcdata.arg_names.push_back(p_argtype4.name);
#endif
- } else
+ } else {
goto end;
+ }
if (p_argtype5.name) {
funcdata.arg_types.push_back(p_argtype5.type);
#ifdef DEBUG_ENABLED
funcdata.arg_names.push_back(p_argtype5.name);
#endif
- } else
+ } else {
goto end;
+ }
end:
@@ -315,7 +318,6 @@ struct _VariantCall {
VCALL_LOCALMEM1R(String, trim_suffix);
static void _call_String_to_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) {
-
String *s = reinterpret_cast<String *>(p_self._data._mem);
if (s->empty()) {
r_ret = PackedByteArray();
@@ -333,7 +335,6 @@ struct _VariantCall {
}
static void _call_String_to_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) {
-
String *s = reinterpret_cast<String *>(p_self._data._mem);
if (s->empty()) {
r_ret = PackedByteArray();
@@ -465,26 +466,29 @@ struct _VariantCall {
//return vector3 if intersected, nil if not
static void _call_Plane_intersect_3(Variant &r_ret, Variant &p_self, const Variant **p_args) {
Vector3 result;
- if (reinterpret_cast<Plane *>(p_self._data._mem)->intersect_3(*p_args[0], *p_args[1], &result))
+ if (reinterpret_cast<Plane *>(p_self._data._mem)->intersect_3(*p_args[0], *p_args[1], &result)) {
r_ret = result;
- else
+ } else {
r_ret = Variant();
+ }
}
static void _call_Plane_intersects_ray(Variant &r_ret, Variant &p_self, const Variant **p_args) {
Vector3 result;
- if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_ray(*p_args[0], *p_args[1], &result))
+ if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_ray(*p_args[0], *p_args[1], &result)) {
r_ret = result;
- else
+ } else {
r_ret = Variant();
+ }
}
static void _call_Plane_intersects_segment(Variant &r_ret, Variant &p_self, const Variant **p_args) {
Vector3 result;
- if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_segment(*p_args[0], *p_args[1], &result))
+ if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_segment(*p_args[0], *p_args[1], &result)) {
r_ret = result;
- else
+ } else {
r_ret = Variant();
+ }
}
VCALL_LOCALMEM0R(Quat, length);
@@ -592,7 +596,6 @@ struct _VariantCall {
VCALL_LOCALMEM0R(Array, min);
static void _call_PackedByteArray_get_string_from_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) {
-
PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem);
String s;
if (ba->size() > 0) {
@@ -608,7 +611,6 @@ struct _VariantCall {
}
static void _call_PackedByteArray_get_string_from_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) {
-
PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem);
String s;
if (ba->size() > 0) {
@@ -619,7 +621,6 @@ struct _VariantCall {
}
static void _call_PackedByteArray_compress(Variant &r_ret, Variant &p_self, const Variant **p_args) {
-
PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem);
PackedByteArray compressed;
if (ba->size() > 0) {
@@ -635,7 +636,6 @@ struct _VariantCall {
}
static void _call_PackedByteArray_decompress(Variant &r_ret, Variant &p_self, const Variant **p_args) {
-
PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem);
PackedByteArray decompressed;
Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]);
@@ -985,7 +985,6 @@ struct _VariantCall {
}
struct ConstructData {
-
int arg_count;
Vector<Variant::Type> arg_types;
Vector<String> arg_names;
@@ -993,50 +992,41 @@ struct _VariantCall {
};
struct ConstructFunc {
-
List<ConstructData> constructors;
};
static ConstructFunc *construct_funcs;
static void Vector2_init1(Variant &r_ret, const Variant **p_args) {
-
r_ret = Vector2(*p_args[0], *p_args[1]);
}
static void Vector2i_init1(Variant &r_ret, const Variant **p_args) {
-
r_ret = Vector2i(*p_args[0], *p_args[1]);
}
static void Rect2_init1(Variant &r_ret, const Variant **p_args) {
-
r_ret = Rect2(*p_args[0], *p_args[1]);
}
static void Rect2_init2(Variant &r_ret, const Variant **p_args) {
-
r_ret = Rect2(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
}
static void Rect2i_init1(Variant &r_ret, const Variant **p_args) {
-
r_ret = Rect2i(*p_args[0], *p_args[1]);
}
static void Rect2i_init2(Variant &r_ret, const Variant **p_args) {
-
r_ret = Rect2i(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
}
static void Transform2D_init2(Variant &r_ret, const Variant **p_args) {
-
Transform2D m(*p_args[0], *p_args[1]);
r_ret = m;
}
static void Transform2D_init3(Variant &r_ret, const Variant **p_args) {
-
Transform2D m;
m[0] = *p_args[0];
m[1] = *p_args[1];
@@ -1045,81 +1035,65 @@ struct _VariantCall {
}
static void Vector3_init1(Variant &r_ret, const Variant **p_args) {
-
r_ret = Vector3(*p_args[0], *p_args[1], *p_args[2]);
}
static void Vector3i_init1(Variant &r_ret, const Variant **p_args) {
-
r_ret = Vector3i(*p_args[0], *p_args[1], *p_args[2]);
}
static void Plane_init1(Variant &r_ret, const Variant **p_args) {
-
r_ret = Plane(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
}
static void Plane_init2(Variant &r_ret, const Variant **p_args) {
-
r_ret = Plane(*p_args[0], *p_args[1], *p_args[2]);
}
static void Plane_init3(Variant &r_ret, const Variant **p_args) {
-
r_ret = Plane(p_args[0]->operator Vector3(), p_args[1]->operator real_t());
}
static void Plane_init4(Variant &r_ret, const Variant **p_args) {
-
r_ret = Plane(p_args[0]->operator Vector3(), p_args[1]->operator Vector3());
}
static void Quat_init1(Variant &r_ret, const Variant **p_args) {
-
r_ret = Quat(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
}
static void Quat_init2(Variant &r_ret, const Variant **p_args) {
-
r_ret = Quat(((Vector3)(*p_args[0])), ((real_t)(*p_args[1])));
}
static void Quat_init3(Variant &r_ret, const Variant **p_args) {
-
r_ret = Quat(((Vector3)(*p_args[0])));
}
static void Color_init1(Variant &r_ret, const Variant **p_args) {
-
r_ret = Color(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
}
static void Color_init2(Variant &r_ret, const Variant **p_args) {
-
r_ret = Color(*p_args[0], *p_args[1], *p_args[2]);
}
static void Color_init3(Variant &r_ret, const Variant **p_args) {
-
r_ret = Color::html(*p_args[0]);
}
static void Color_init4(Variant &r_ret, const Variant **p_args) {
-
r_ret = Color::hex(*p_args[0]);
}
static void Color_init5(Variant &r_ret, const Variant **p_args) {
-
r_ret = Color(((Color)(*p_args[0])), *p_args[1]);
}
static void AABB_init1(Variant &r_ret, const Variant **p_args) {
-
r_ret = ::AABB(*p_args[0], *p_args[1]);
}
static void Basis_init1(Variant &r_ret, const Variant **p_args) {
-
Basis m;
m.set_axis(0, *p_args[0]);
m.set_axis(1, *p_args[1]);
@@ -1128,12 +1102,10 @@ struct _VariantCall {
}
static void Basis_init2(Variant &r_ret, const Variant **p_args) {
-
r_ret = Basis(p_args[0]->operator Vector3(), p_args[1]->operator real_t());
}
static void Transform_init1(Variant &r_ret, const Variant **p_args) {
-
Transform t;
t.basis.set_axis(0, *p_args[0]);
t.basis.set_axis(1, *p_args[1]);
@@ -1143,17 +1115,14 @@ struct _VariantCall {
}
static void Transform_init2(Variant &r_ret, const Variant **p_args) {
-
r_ret = Transform(p_args[0]->operator Basis(), p_args[1]->operator Vector3());
}
static void Callable_init2(Variant &r_ret, const Variant **p_args) {
-
r_ret = Callable(p_args[0]->operator ObjectID(), p_args[1]->operator String());
}
static void Signal_init2(Variant &r_ret, const Variant **p_args) {
-
r_ret = Signal(p_args[0]->operator ObjectID(), p_args[1]->operator String());
}
@@ -1162,31 +1131,34 @@ struct _VariantCall {
const String &p_name2 = "", const Variant::Type p_type2 = Variant::NIL,
const String &p_name3 = "", const Variant::Type p_type3 = Variant::NIL,
const String &p_name4 = "", const Variant::Type p_type4 = Variant::NIL) {
-
ConstructData cd;
cd.func = p_func;
cd.arg_count = 0;
- if (p_name1 == "")
+ if (p_name1 == "") {
goto end;
+ }
cd.arg_count++;
cd.arg_names.push_back(p_name1);
cd.arg_types.push_back(p_type1);
- if (p_name2 == "")
+ if (p_name2 == "") {
goto end;
+ }
cd.arg_count++;
cd.arg_names.push_back(p_name2);
cd.arg_types.push_back(p_type2);
- if (p_name3 == "")
+ if (p_name3 == "") {
goto end;
+ }
cd.arg_count++;
cd.arg_names.push_back(p_name3);
cd.arg_types.push_back(p_type3);
- if (p_name4 == "")
+ if (p_name4 == "") {
goto end;
+ }
cd.arg_count++;
cd.arg_names.push_back(p_name4);
cd.arg_types.push_back(p_type4);
@@ -1197,7 +1169,6 @@ struct _VariantCall {
}
struct ConstantData {
-
Map<StringName, int> value;
#ifdef DEBUG_ENABLED
List<StringName> value_ordered;
@@ -1208,7 +1179,6 @@ struct _VariantCall {
static ConstantData *constant_data;
static void add_constant(int p_type, StringName p_constant_name, int p_constant_value) {
-
constant_data[p_type].value[p_constant_name] = p_constant_value;
#ifdef DEBUG_ENABLED
constant_data[p_type].value_ordered.push_back(p_constant_name);
@@ -1216,7 +1186,6 @@ struct _VariantCall {
}
static void add_variant_constant(int p_type, StringName p_constant_name, const Variant &p_constant_value) {
-
constant_data[p_type].variant_value[p_constant_name] = p_constant_value;
}
};
@@ -1226,7 +1195,6 @@ _VariantCall::ConstructFunc *_VariantCall::construct_funcs = nullptr;
_VariantCall::ConstantData *_VariantCall::constant_data = nullptr;
Variant Variant::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
-
Variant ret;
call_ptr(p_method, p_args, p_argcount, &ret, r_error);
return ret;
@@ -1254,13 +1222,11 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p
//else if (type==Variant::METHOD) {
} else {
-
r_error.error = Callable::CallError::CALL_OK;
Map<StringName, _VariantCall::FuncData>::Element *E = _VariantCall::type_funcs[type].functions.find(p_method);
if (E) {
-
_VariantCall::FuncData &funcdata = E->get();
funcdata.call(ret, *this, p_args, p_argcount, r_error);
@@ -1269,7 +1235,6 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p
bool valid = false;
if (type == CALLABLE) {
if (p_method == CoreStringNames::get_singleton()->call) {
-
reinterpret_cast<const Callable *>(_data._mem)->call(p_args, p_argcount, ret, r_error);
valid = true;
}
@@ -1294,14 +1259,14 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p
}
}
- if (r_error.error == Callable::CallError::CALL_OK && r_ret)
+ if (r_error.error == Callable::CallError::CALL_OK && r_ret) {
*r_ret = ret;
+ }
}
#define VCALL(m_type, m_method) _VariantCall::_call_##m_type##_##m_method
Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, int p_argcount, Callable::CallError &r_error, bool p_strict) {
-
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
ERR_FAIL_INDEX_V(p_type, VARIANT_MAX, Variant());
@@ -1390,7 +1355,6 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
switch (p_type) {
case NIL: {
-
return Variant();
} break;
case BOOL: {
@@ -1475,14 +1439,14 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
return Variant();
}
} else if (p_argcount >= 1) {
-
_VariantCall::ConstructFunc &c = _VariantCall::construct_funcs[p_type];
for (List<_VariantCall::ConstructData>::Element *E = c.constructors.front(); E; E = E->next()) {
const _VariantCall::ConstructData &cd = E->get();
- if (cd.arg_count != p_argcount)
+ if (cd.arg_count != p_argcount) {
continue;
+ }
//validate parameters
for (int i = 0; i < cd.arg_count; i++) {
@@ -1504,11 +1468,11 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
}
bool Variant::has_method(const StringName &p_method) const {
-
if (type == OBJECT) {
Object *obj = get_validated_object();
- if (!obj)
+ if (!obj) {
return false;
+ }
return obj->has_method(p_method);
}
@@ -1518,69 +1482,68 @@ bool Variant::has_method(const StringName &p_method) const {
}
Vector<Variant::Type> Variant::get_method_argument_types(Variant::Type p_type, const StringName &p_method) {
-
const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E)
+ if (!E) {
return Vector<Variant::Type>();
+ }
return E->get().arg_types;
}
bool Variant::is_method_const(Variant::Type p_type, const StringName &p_method) {
-
const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E)
+ if (!E) {
return false;
+ }
return E->get()._const;
}
Vector<StringName> Variant::get_method_argument_names(Variant::Type p_type, const StringName &p_method) {
-
const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E)
+ if (!E) {
return Vector<StringName>();
+ }
return E->get().arg_names;
}
Variant::Type Variant::get_method_return_type(Variant::Type p_type, const StringName &p_method, bool *r_has_return) {
-
const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E)
+ if (!E) {
return Variant::NIL;
+ }
- if (r_has_return)
+ if (r_has_return) {
*r_has_return = E->get().returns;
+ }
return E->get().return_type;
}
Vector<Variant> Variant::get_method_default_arguments(Variant::Type p_type, const StringName &p_method) {
-
const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E)
+ if (!E) {
return Vector<Variant>();
+ }
return E->get().default_args;
}
void Variant::get_method_list(List<MethodInfo> *p_list) const {
-
const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[type];
for (const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.front(); E; E = E->next()) {
-
const _VariantCall::FuncData &fd = E->get();
MethodInfo mi;
@@ -1591,7 +1554,6 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const {
}
for (int i = 0; i < fd.arg_types.size(); i++) {
-
PropertyInfo pi;
pi.type = fd.arg_types[i];
#ifdef DEBUG_ENABLED
@@ -1606,8 +1568,9 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const {
ret.type = fd.return_type;
if (fd.returns) {
ret.name = "ret";
- if (fd.return_type == Variant::NIL)
+ if (fd.return_type == Variant::NIL) {
ret.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
+ }
}
mi.return_val = ret;
#endif
@@ -1616,7 +1579,6 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const {
}
if (type == CALLABLE) {
-
MethodInfo mi;
mi.name = "call";
mi.return_val.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
@@ -1631,7 +1593,6 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const {
}
if (type == SIGNAL) {
-
MethodInfo mi;
mi.name = "emit";
mi.flags |= METHOD_FLAG_VARARG;
@@ -1641,18 +1602,15 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const {
}
void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_list) {
-
ERR_FAIL_INDEX(p_type, VARIANT_MAX);
//custom constructors
for (const List<_VariantCall::ConstructData>::Element *E = _VariantCall::construct_funcs[p_type].constructors.front(); E; E = E->next()) {
-
const _VariantCall::ConstructData &cd = E->get();
MethodInfo mi;
mi.name = Variant::get_type_name(p_type);
mi.return_val.type = p_type;
for (int i = 0; i < cd.arg_count; i++) {
-
PropertyInfo pi;
pi.name = cd.arg_names[i];
pi.type = cd.arg_types[i];
@@ -1662,10 +1620,12 @@ void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_lis
}
//default constructors
for (int i = 0; i < VARIANT_MAX; i++) {
- if (i == p_type)
+ if (i == p_type) {
continue;
- if (!Variant::can_convert(Variant::Type(i), p_type))
+ }
+ if (!Variant::can_convert(Variant::Type(i), p_type)) {
continue;
+ }
MethodInfo mi;
mi.name = Variant::get_type_name(p_type);
@@ -1679,39 +1639,34 @@ void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_lis
}
void Variant::get_constants_for_type(Variant::Type p_type, List<StringName> *p_constants) {
-
ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX);
_VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
#ifdef DEBUG_ENABLED
for (List<StringName>::Element *E = cd.value_ordered.front(); E; E = E->next()) {
-
p_constants->push_back(E->get());
#else
for (Map<StringName, int>::Element *E = cd.value.front(); E; E = E->next()) {
-
p_constants->push_back(E->key());
#endif
}
for (Map<StringName, Variant>::Element *E = cd.variant_value.front(); E; E = E->next()) {
-
p_constants->push_back(E->key());
}
}
bool Variant::has_constant(Variant::Type p_type, const StringName &p_value) {
-
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
_VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
return cd.value.has(p_value) || cd.variant_value.has(p_value);
}
Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_value, bool *r_valid) {
-
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
_VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
@@ -1720,21 +1675,22 @@ Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_va
if (!E) {
Map<StringName, Variant>::Element *F = cd.variant_value.find(p_value);
if (F) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return F->get();
} else {
return -1;
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return E->get();
}
void register_variant_methods() {
-
_VariantCall::type_funcs = memnew_arr(_VariantCall::TypeFunc, Variant::VARIANT_MAX);
_VariantCall::construct_funcs = memnew_arr(_VariantCall::ConstructFunc, Variant::VARIANT_MAX);
@@ -2395,7 +2351,6 @@ void register_variant_methods() {
}
void unregister_variant_methods() {
-
memdelete_arr(_VariantCall::type_funcs);
memdelete_arr(_VariantCall::construct_funcs);
memdelete_arr(_VariantCall::constant_data);
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index 4c9848f26a..8641187f97 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -115,6 +115,7 @@
TYPE(PREFIX, OP, PACKED_VECTOR3_ARRAY), \
TYPE(PREFIX, OP, PACKED_COLOR_ARRAY), \
}
+
/* clang-format on */
#define CASES(PREFIX) static const void *switch_table_##PREFIX[25][Variant::VARIANT_MAX] = { \
@@ -159,7 +160,6 @@
#endif
Variant::operator bool() const {
-
return booleanize();
}
@@ -435,7 +435,6 @@ bool Variant::booleanize() const {
if (a_len m_opa array_b.size()) { \
_RETURN(m_ret_s); \
} else { \
- \
const m_type *ra = array_a.ptr(); \
const m_type *rb = array_b.ptr(); \
\
@@ -461,7 +460,6 @@ bool Variant::booleanize() const {
void Variant::evaluate(const Operator &p_op, const Variant &p_a,
const Variant &p_b, Variant &r_ret, bool &r_valid) {
-
CASES(math);
r_valid = true;
@@ -918,10 +916,12 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
int asize = array_a.size();
int bsize = array_b.size();
sum.resize(asize + bsize);
- for (int i = 0; i < asize; i++)
+ for (int i = 0; i < asize; i++) {
sum[i] = array_a[i];
- for (int i = 0; i < bsize; i++)
+ }
+ for (int i = 0; i < bsize; i++) {
sum[i + asize] = array_b[i];
+ }
_RETURN(sum);
}
@@ -1418,7 +1418,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
}
void Variant::set_named(const StringName &p_index, const Variant &p_value, bool *r_valid) {
-
bool valid = false;
switch (type) {
case VECTOR2: {
@@ -1466,7 +1465,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
} break;
case RECT2: {
-
if (p_value.type == Variant::VECTOR2) {
Rect2 *v = reinterpret_cast<Rect2 *>(_data._mem);
//scalar name
@@ -1483,7 +1481,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
}
} break;
case RECT2I: {
-
if (p_value.type == Variant::VECTOR2I) {
Rect2i *v = reinterpret_cast<Rect2i *>(_data._mem);
//scalar name
@@ -1500,7 +1497,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
}
} break;
case TRANSFORM2D: {
-
if (p_value.type == Variant::VECTOR2) {
Transform2D *v = _data._transform2d;
if (p_index == CoreStringNames::singleton->x) {
@@ -1517,7 +1513,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
} break;
case VECTOR3: {
-
if (p_value.type == Variant::INT) {
Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
if (p_index == CoreStringNames::singleton->x) {
@@ -1546,7 +1541,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
} break;
case VECTOR3I: {
-
if (p_value.type == Variant::INT) {
Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem);
if (p_index == CoreStringNames::singleton->x) {
@@ -1575,7 +1569,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
} break;
case PLANE: {
-
if (p_value.type == Variant::INT) {
Plane *v = reinterpret_cast<Plane *>(_data._mem);
if (p_index == CoreStringNames::singleton->x) {
@@ -1617,7 +1610,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
} break;
case QUAT: {
-
if (p_value.type == Variant::INT) {
Quat *v = reinterpret_cast<Quat *>(_data._mem);
if (p_index == CoreStringNames::singleton->x) {
@@ -1652,7 +1644,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
} break;
case AABB: {
-
if (p_value.type == Variant::VECTOR3) {
::AABB *v = _data._aabb;
//scalar name
@@ -1669,7 +1660,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
}
} break;
case BASIS: {
-
if (p_value.type == Variant::VECTOR3) {
Basis *v = _data._basis;
//scalar name
@@ -1686,7 +1676,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
}
} break;
case TRANSFORM: {
-
if (p_value.type == Variant::BASIS && p_index == CoreStringNames::singleton->basis) {
_data._transform->basis = *p_value._data._basis;
valid = true;
@@ -1697,7 +1686,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
} break;
case COLOR: {
-
if (p_value.type == Variant::INT) {
Color *v = reinterpret_cast<Color *>(_data._mem);
if (p_index == CoreStringNames::singleton->r) {
@@ -1773,7 +1761,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
}
} break;
case OBJECT: {
-
#ifdef DEBUG_ENABLED
if (!_get_obj().obj) {
break;
@@ -1796,7 +1783,6 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool
}
Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
-
if (r_valid) {
*r_valid = true;
}
@@ -1820,7 +1806,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
} break;
case RECT2: {
-
const Rect2 *v = reinterpret_cast<const Rect2 *>(_data._mem);
//scalar name
if (p_index == CoreStringNames::singleton->position) {
@@ -1832,7 +1817,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
}
} break;
case RECT2I: {
-
const Rect2i *v = reinterpret_cast<const Rect2i *>(_data._mem);
//scalar name
if (p_index == CoreStringNames::singleton->position) {
@@ -1844,7 +1828,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
}
} break;
case TRANSFORM2D: {
-
const Transform2D *v = _data._transform2d;
if (p_index == CoreStringNames::singleton->x) {
return v->elements[0];
@@ -1856,7 +1839,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
} break;
case VECTOR3: {
-
const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
if (p_index == CoreStringNames::singleton->x) {
return v->x;
@@ -1868,7 +1850,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
} break;
case VECTOR3I: {
-
const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem);
if (p_index == CoreStringNames::singleton->x) {
return v->x;
@@ -1880,7 +1861,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
} break;
case PLANE: {
-
const Plane *v = reinterpret_cast<const Plane *>(_data._mem);
if (p_index == CoreStringNames::singleton->x) {
return v->normal.x;
@@ -1896,7 +1876,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
} break;
case QUAT: {
-
const Quat *v = reinterpret_cast<const Quat *>(_data._mem);
if (p_index == CoreStringNames::singleton->x) {
return v->x;
@@ -1910,7 +1889,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
} break;
case AABB: {
-
const ::AABB *v = _data._aabb;
//scalar name
if (p_index == CoreStringNames::singleton->position) {
@@ -1922,7 +1900,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
}
} break;
case BASIS: {
-
const Basis *v = _data._basis;
//scalar name
if (p_index == CoreStringNames::singleton->x) {
@@ -1935,7 +1912,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
} break;
case TRANSFORM: {
-
if (p_index == CoreStringNames::singleton->basis) {
return _data._transform->basis;
} else if (p_index == CoreStringNames::singleton->origin) {
@@ -1944,7 +1920,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
} break;
case COLOR: {
-
const Color *v = reinterpret_cast<const Color *>(_data._mem);
if (p_index == CoreStringNames::singleton->r) {
return v->r;
@@ -1971,17 +1946,17 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
}
} break;
case OBJECT: {
-
#ifdef DEBUG_ENABLED
if (!_get_obj().obj) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return "Instance base is null.";
} else {
-
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return "Attempted use of stray pointer object.";
}
}
@@ -2039,7 +2014,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
#define DEFAULT_OP_DVECTOR_GET(m_name, m_type) \
case m_name: { \
- \
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { \
int index = p_index; \
const Vector<m_type> *arr = &PackedArrayRef<m_type>::get_array(_data.packed_array); \
@@ -2054,7 +2028,6 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
} break;
void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) {
-
static bool _dummy = false;
bool &valid = r_valid ? *r_valid : _dummy;
@@ -2074,24 +2047,24 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
return;
} break;
case STRING: {
-
- if (p_index.type != Variant::INT && p_index.type != Variant::FLOAT)
+ if (p_index.type != Variant::INT && p_index.type != Variant::FLOAT) {
return;
+ }
int idx = p_index;
String *str = reinterpret_cast<String *>(_data._mem);
int len = str->length();
- if (idx < 0)
+ if (idx < 0) {
idx += len;
- if (idx < 0 || idx >= len)
+ }
+ if (idx < 0 || idx >= len) {
return;
+ }
String chr;
if (p_value.type == Variant::INT || p_value.type == Variant::FLOAT) {
-
chr = String::chr(p_value);
} else if (p_value.type == Variant::STRING) {
-
chr = p_value;
} else {
return;
@@ -2103,18 +2076,18 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case VECTOR2: {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
// scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 2;
+ }
if (idx >= 0 && idx < 2) {
-
Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
valid = true;
(*v)[idx] = p_value;
@@ -2138,18 +2111,18 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case VECTOR2I: {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
// scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 2;
+ }
if (idx >= 0 && idx < 2) {
-
Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem);
valid = true;
(*v)[idx] = p_value;
@@ -2173,9 +2146,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case RECT2: {
-
- if (p_value.type != Variant::VECTOR2)
+ if (p_value.type != Variant::VECTOR2) {
return;
+ }
if (p_index.get_type() == Variant::STRING) {
//scalar name
@@ -2198,9 +2171,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
}
} break;
case RECT2I: {
-
- if (p_value.type != Variant::VECTOR2I)
+ if (p_value.type != Variant::VECTOR2I) {
return;
+ }
if (p_index.get_type() == Variant::STRING) {
//scalar name
@@ -2223,16 +2196,16 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
}
} break;
case TRANSFORM2D: {
-
- if (p_value.type != Variant::VECTOR2)
+ if (p_value.type != Variant::VECTOR2) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
-
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 3;
+ }
if (index >= 0 && index < 3) {
Transform2D *v = _data._transform2d;
@@ -2241,7 +2214,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
return;
}
} else if (p_index.get_type() == Variant::STRING && p_value.get_type() == Variant::VECTOR2) {
-
//scalar name
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
Transform2D *v = _data._transform2d;
@@ -2262,24 +2234,23 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case VECTOR3: {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
//scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 3;
+ }
if (idx >= 0 && idx < 3) {
-
Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
valid = true;
(*v)[idx] = p_value;
return;
}
} else if (p_index.get_type() == Variant::STRING) {
-
//scalar name
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
@@ -2300,24 +2271,23 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case VECTOR3I: {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
//scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 3;
+ }
if (idx >= 0 && idx < 3) {
-
Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem);
valid = true;
(*v)[idx] = p_value;
return;
}
} else if (p_index.get_type() == Variant::STRING) {
-
//scalar name
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem);
@@ -2338,35 +2308,38 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case PLANE: {
-
if (p_index.get_type() == Variant::STRING) {
//scalar name
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
Plane *v = reinterpret_cast<Plane *>(_data._mem);
if (*str == "x") {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
valid = true;
v->normal.x = p_value;
return;
} else if (*str == "y") {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
valid = true;
v->normal.y = p_value;
return;
} else if (*str == "z") {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
valid = true;
v->normal.z = p_value;
return;
} else if (*str == "normal") {
- if (p_value.type != Variant::VECTOR3)
+ if (p_value.type != Variant::VECTOR3) {
return;
+ }
valid = true;
v->normal = p_value;
@@ -2380,12 +2353,11 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case QUAT: {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::STRING) {
-
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
Quat *v = reinterpret_cast<Quat *>(_data._mem);
if (*str == "x") {
@@ -2409,9 +2381,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case AABB: {
-
- if (p_value.type != Variant::VECTOR3)
+ if (p_value.type != Variant::VECTOR3) {
return;
+ }
if (p_index.get_type() == Variant::STRING) {
//scalar name
@@ -2434,16 +2406,16 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
}
} break;
case BASIS: {
-
- if (p_value.type != Variant::VECTOR3)
+ if (p_value.type != Variant::VECTOR3) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
-
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 3;
+ }
if (index >= 0 && index < 3) {
Basis *v = _data._basis;
@@ -2452,7 +2424,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
return;
}
} else if (p_index.get_type() == Variant::STRING) {
-
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
Basis *v = _data._basis;
@@ -2473,41 +2444,42 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case TRANSFORM: {
-
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
-
- if (p_value.type != Variant::VECTOR3)
+ if (p_value.type != Variant::VECTOR3) {
return;
+ }
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 4;
+ }
if (index >= 0 && index < 4) {
Transform *v = _data._transform;
valid = true;
- if (index == 3)
+ if (index == 3) {
v->origin = p_value;
- else
+ } else {
v->basis.set_axis(index, p_value);
+ }
return;
}
} else if (p_index.get_type() == Variant::STRING) {
-
Transform *v = _data._transform;
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
if (*str == "basis") {
-
- if (p_value.type != Variant::BASIS)
+ if (p_value.type != Variant::BASIS) {
return;
+ }
valid = true;
v->basis = p_value;
return;
}
if (*str == "origin") {
- if (p_value.type != Variant::VECTOR3)
+ if (p_value.type != Variant::VECTOR3) {
return;
+ }
valid = true;
v->origin = p_value;
return;
@@ -2516,12 +2488,11 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case COLOR: {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::STRING) {
-
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
Color *v = reinterpret_cast<Color *>(_data._mem);
if (*str == "r") {
@@ -2570,10 +2541,10 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
return;
}
} else if (p_index.get_type() == Variant::INT) {
-
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 4;
+ }
if (idx >= 0 && idx < 4) {
Color *v = reinterpret_cast<Color *>(_data._mem);
(*v)[idx] = p_value;
@@ -2589,14 +2560,12 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
case _RID: {
} break;
case OBJECT: {
-
Object *obj = _get_obj().obj;
//only if debugging!
if (obj) {
#ifdef DEBUG_ENABLED
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
-
WARN_PRINT("Attempted use of previously freed pointer object.");
valid = false;
return;
@@ -2613,7 +2582,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
}
} break;
case DICTIONARY: {
-
Dictionary *dic = reinterpret_cast<Dictionary *>(_data._mem);
dic->operator[](p_index) = p_value;
valid = true; //always valid, i guess? should this really be ok?
@@ -2635,7 +2603,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
}
Variant Variant::get(const Variant &p_index, bool *r_valid) const {
-
static bool _dummy = false;
bool &valid = r_valid ? *r_valid : _dummy;
@@ -2656,16 +2623,15 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
return Variant();
} break;
case STRING: {
-
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
//string index
int idx = p_index;
const String *str = reinterpret_cast<const String *>(_data._mem);
- if (idx < 0)
+ if (idx < 0) {
idx += str->length();
+ }
if (idx >= 0 && idx < str->length()) {
-
valid = true;
return str->substr(idx, 1);
}
@@ -2673,14 +2639,13 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
} break;
case VECTOR2: {
-
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
// scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 2;
+ }
if (idx >= 0 && idx < 2) {
-
const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem);
valid = true;
return (*v)[idx];
@@ -2701,14 +2666,13 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
} break;
case VECTOR2I: {
-
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
// scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 2;
+ }
if (idx >= 0 && idx < 2) {
-
const Vector2i *v = reinterpret_cast<const Vector2i *>(_data._mem);
valid = true;
return (*v)[idx];
@@ -2729,7 +2693,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
} break;
case RECT2: {
-
if (p_index.get_type() == Variant::STRING) {
//scalar name
@@ -2748,7 +2711,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
}
} break;
case RECT2I: {
-
if (p_index.get_type() == Variant::STRING) {
//scalar name
@@ -2767,20 +2729,18 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
}
} break;
case VECTOR3: {
-
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
//scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 3;
+ }
if (idx >= 0 && idx < 3) {
-
const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
valid = true;
return (*v)[idx];
}
} else if (p_index.get_type() == Variant::STRING) {
-
//scalar name
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
@@ -2798,20 +2758,18 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
} break;
case VECTOR3I: {
-
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
//scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 3;
+ }
if (idx >= 0 && idx < 3) {
-
const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem);
valid = true;
return (*v)[idx];
}
} else if (p_index.get_type() == Variant::STRING) {
-
//scalar name
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem);
@@ -2829,13 +2787,12 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
} break;
case TRANSFORM2D: {
-
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
-
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 3;
+ }
if (index >= 0 && index < 3) {
const Transform2D *v = _data._transform2d;
@@ -2843,7 +2800,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
return v->elements[index];
}
} else if (p_index.get_type() == Variant::STRING) {
-
//scalar name
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
const Transform2D *v = _data._transform2d;
@@ -2861,7 +2817,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
} break;
case PLANE: {
-
if (p_index.get_type() == Variant::STRING) {
//scalar name
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
@@ -2886,9 +2841,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
} break;
case QUAT: {
-
if (p_index.get_type() == Variant::STRING) {
-
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
const Quat *v = reinterpret_cast<const Quat *>(_data._mem);
if (*str == "x") {
@@ -2908,7 +2861,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
} break;
case AABB: {
-
if (p_index.get_type() == Variant::STRING) {
//scalar name
@@ -2927,12 +2879,11 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
}
} break;
case BASIS: {
-
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
-
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 3;
+ }
if (index >= 0 && index < 3) {
const Basis *v = _data._basis;
@@ -2940,7 +2891,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
return v->get_axis(index);
}
} else if (p_index.get_type() == Variant::STRING) {
-
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
const Basis *v = _data._basis;
@@ -2958,19 +2908,17 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
} break;
case TRANSFORM: {
-
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
-
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 4;
+ }
if (index >= 0 && index < 4) {
const Transform *v = _data._transform;
valid = true;
return index == 3 ? v->origin : v->basis.get_axis(index);
}
} else if (p_index.get_type() == Variant::STRING) {
-
const Transform *v = _data._transform;
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
@@ -2986,9 +2934,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
} break;
case COLOR: {
-
if (p_index.get_type() == Variant::STRING) {
-
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
const Color *v = reinterpret_cast<const Color *>(_data._mem);
if (*str == "r") {
@@ -3026,10 +2972,10 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
return (int)Math::round(v->a * 255.0);
}
} else if (p_index.get_type() == Variant::INT) {
-
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 4;
+ }
if (idx >= 0 && idx < 4) {
const Color *v = reinterpret_cast<const Color *>(_data._mem);
valid = true;
@@ -3047,7 +2993,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
case OBJECT: {
Object *obj = _get_obj().obj;
if (obj) {
-
#ifdef DEBUG_ENABLED
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
@@ -3065,7 +3010,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
} break;
case DICTIONARY: {
-
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
const Variant *res = dic->getptr(p_index);
if (res) {
@@ -3091,14 +3035,12 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
}
bool Variant::in(const Variant &p_index, bool *r_valid) const {
-
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
switch (type) {
-
case STRING: {
-
if (p_index.get_type() == Variant::STRING) {
//string index
String idx = p_index;
@@ -3111,7 +3053,6 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
case OBJECT: {
Object *obj = _get_obj().obj;
if (obj) {
-
bool valid = false;
#ifdef DEBUG_ENABLED
@@ -3132,26 +3073,25 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
return valid;
} else {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
}
return false;
} break;
case DICTIONARY: {
-
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
return dic->has(p_index);
} break;
case ARRAY: {
-
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
int l = arr->size();
if (l) {
for (int i = 0; i < l; i++) {
-
- if (evaluate(OP_EQUAL, (*arr)[i], p_index))
+ if (evaluate(OP_EQUAL, (*arr)[i], p_index)) {
return true;
+ }
}
}
@@ -3160,15 +3100,15 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
} break;
case PACKED_BYTE_ARRAY: {
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
-
int index = p_index;
const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array);
int l = arr->size();
if (l) {
const uint8_t *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3178,15 +3118,15 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
} break;
case PACKED_INT32_ARRAY: {
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
-
int32_t index = p_index;
const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array);
int32_t l = arr->size();
if (l) {
const int32_t *r = arr->ptr();
for (int32_t i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3195,15 +3135,15 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
} break;
case PACKED_INT64_ARRAY: {
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
-
int64_t index = p_index;
const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array);
int64_t l = arr->size();
if (l) {
const int64_t *r = arr->ptr();
for (int64_t i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3211,17 +3151,16 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
}
} break;
case PACKED_FLOAT32_ARRAY: {
-
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
-
real_t index = p_index;
const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array);
int l = arr->size();
if (l) {
const float *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3230,17 +3169,16 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
} break;
case PACKED_FLOAT64_ARRAY: {
-
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
-
real_t index = p_index;
const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array);
int l = arr->size();
if (l) {
const double *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3250,7 +3188,6 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
} break;
case PACKED_STRING_ARRAY: {
if (p_index.get_type() == Variant::STRING) {
-
String index = p_index;
const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array);
@@ -3258,8 +3195,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const String *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3269,7 +3207,6 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
} break; //25
case PACKED_VECTOR2_ARRAY: {
if (p_index.get_type() == Variant::VECTOR2) {
-
Vector2 index = p_index;
const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array);
@@ -3277,8 +3214,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const Vector2 *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3288,7 +3226,6 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
} break;
case PACKED_VECTOR3_ARRAY: {
if (p_index.get_type() == Variant::VECTOR3) {
-
Vector3 index = p_index;
const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array);
@@ -3296,8 +3233,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const Vector3 *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3306,9 +3244,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
} break;
case PACKED_COLOR_ARRAY: {
-
if (p_index.get_type() == Variant::COLOR) {
-
Color index = p_index;
const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array);
@@ -3316,8 +3252,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const Color *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3328,63 +3265,55 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return false;
}
void Variant::get_property_list(List<PropertyInfo> *p_list) const {
-
switch (type) {
case VECTOR2: {
-
p_list->push_back(PropertyInfo(Variant::FLOAT, "x"));
p_list->push_back(PropertyInfo(Variant::FLOAT, "y"));
} break;
case VECTOR2I: {
-
p_list->push_back(PropertyInfo(Variant::INT, "x"));
p_list->push_back(PropertyInfo(Variant::INT, "y"));
} break;
case RECT2: {
-
p_list->push_back(PropertyInfo(Variant::VECTOR2, "position"));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "size"));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "end"));
} break;
case RECT2I: {
-
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "position"));
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "size"));
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "end"));
} break;
case VECTOR3: {
-
p_list->push_back(PropertyInfo(Variant::FLOAT, "x"));
p_list->push_back(PropertyInfo(Variant::FLOAT, "y"));
p_list->push_back(PropertyInfo(Variant::FLOAT, "z"));
} break;
case VECTOR3I: {
-
p_list->push_back(PropertyInfo(Variant::INT, "x"));
p_list->push_back(PropertyInfo(Variant::INT, "y"));
p_list->push_back(PropertyInfo(Variant::INT, "z"));
} break;
case TRANSFORM2D: {
-
p_list->push_back(PropertyInfo(Variant::VECTOR2, "x"));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "y"));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "origin"));
} break;
case PLANE: {
-
p_list->push_back(PropertyInfo(Variant::VECTOR3, "normal"));
p_list->push_back(PropertyInfo(Variant::FLOAT, "x"));
p_list->push_back(PropertyInfo(Variant::FLOAT, "y"));
@@ -3393,7 +3322,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
} break;
case QUAT: {
-
p_list->push_back(PropertyInfo(Variant::FLOAT, "x"));
p_list->push_back(PropertyInfo(Variant::FLOAT, "y"));
p_list->push_back(PropertyInfo(Variant::FLOAT, "z"));
@@ -3406,14 +3334,12 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::VECTOR3, "end"));
} break;
case BASIS: {
-
p_list->push_back(PropertyInfo(Variant::VECTOR3, "x"));
p_list->push_back(PropertyInfo(Variant::VECTOR3, "y"));
p_list->push_back(PropertyInfo(Variant::VECTOR3, "z"));
} break;
case TRANSFORM: {
-
p_list->push_back(PropertyInfo(Variant::BASIS, "basis"));
p_list->push_back(PropertyInfo(Variant::VECTOR3, "origin"));
@@ -3439,7 +3365,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
case _RID: {
} break;
case OBJECT: {
-
Object *obj = _get_obj().obj;
if (obj) {
#ifdef DEBUG_ENABLED
@@ -3456,7 +3381,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
} break;
case DICTIONARY: {
-
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
List<Variant> keys;
dic->get_key_list(&keys);
@@ -3476,7 +3400,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
case PACKED_VECTOR2_ARRAY:
case PACKED_VECTOR3_ARRAY:
case PACKED_COLOR_ARRAY: {
-
//nothing
} break;
default: {
@@ -3485,7 +3408,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
}
bool Variant::iter_init(Variant &r_iter, bool &valid) const {
-
valid = true;
switch (type) {
case INT: {
@@ -3541,7 +3463,6 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const {
return step < 0;
} break;
case OBJECT: {
-
if (!_get_obj().obj) {
valid = false;
return false;
@@ -3573,18 +3494,18 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const {
} break;
case STRING: {
-
const String *str = reinterpret_cast<const String *>(_data._mem);
- if (str->empty())
+ if (str->empty()) {
return false;
+ }
r_iter = 0;
return true;
} break;
case DICTIONARY: {
-
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
- if (dic->empty())
+ if (dic->empty()) {
return false;
+ }
const Variant *next = dic->next(nullptr);
r_iter = *next;
@@ -3592,81 +3513,87 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const {
} break;
case ARRAY: {
-
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
- if (arr->empty())
+ if (arr->empty()) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_BYTE_ARRAY: {
const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_INT32_ARRAY: {
const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_INT64_ARRAY: {
const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_FLOAT32_ARRAY: {
const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_FLOAT64_ARRAY: {
const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_STRING_ARRAY: {
const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_VECTOR2_ARRAY: {
-
const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_VECTOR3_ARRAY: {
-
const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_COLOR_ARRAY: {
-
const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
@@ -3678,23 +3605,25 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const {
valid = false;
return false;
}
-bool Variant::iter_next(Variant &r_iter, bool &valid) const {
+bool Variant::iter_next(Variant &r_iter, bool &valid) const {
valid = true;
switch (type) {
case INT: {
int64_t idx = r_iter;
idx++;
- if (idx >= _data._int)
+ if (idx >= _data._int) {
return false;
+ }
r_iter = idx;
return true;
} break;
case FLOAT: {
int64_t idx = r_iter;
idx++;
- if (idx >= _data._float)
+ if (idx >= _data._float) {
return false;
+ }
r_iter = idx;
return true;
} break;
@@ -3704,8 +3633,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
double idx = r_iter;
idx++;
- if (idx >= to)
+ if (idx >= to) {
return false;
+ }
r_iter = idx;
return true;
@@ -3716,8 +3646,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
int64_t idx = r_iter;
idx++;
- if (idx >= to)
+ if (idx >= to) {
return false;
+ }
r_iter = idx;
return true;
@@ -3729,11 +3660,13 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
double idx = r_iter;
idx += step;
- if (step < 0 && idx <= to)
+ if (step < 0 && idx <= to) {
return false;
+ }
- if (step > 0 && idx >= to)
+ if (step > 0 && idx >= to) {
return false;
+ }
r_iter = idx;
return true;
@@ -3745,17 +3678,18 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
int64_t idx = r_iter;
idx += step;
- if (step < 0 && idx <= to)
+ if (step < 0 && idx <= to) {
return false;
+ }
- if (step > 0 && idx >= to)
+ if (step > 0 && idx >= to) {
return false;
+ }
r_iter = idx;
return true;
} break;
case OBJECT: {
-
if (!_get_obj().obj) {
valid = false;
return false;
@@ -3788,33 +3722,33 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
} break;
case STRING: {
-
const String *str = reinterpret_cast<const String *>(_data._mem);
int idx = r_iter;
idx++;
- if (idx >= str->length())
+ if (idx >= str->length()) {
return false;
+ }
r_iter = idx;
return true;
} break;
case DICTIONARY: {
-
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
const Variant *next = dic->next(&r_iter);
- if (!next)
+ if (!next) {
return false;
+ }
r_iter = *next;
return true;
} break;
case ARRAY: {
-
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
} break;
@@ -3822,8 +3756,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
@@ -3832,8 +3767,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array);
int32_t idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
@@ -3842,8 +3778,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array);
int64_t idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
@@ -3852,8 +3789,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
@@ -3862,8 +3800,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
@@ -3872,38 +3811,39 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
} break;
case PACKED_VECTOR2_ARRAY: {
-
const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
} break;
case PACKED_VECTOR3_ARRAY: {
-
const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
} break;
case PACKED_COLOR_ARRAY: {
-
const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
} break;
@@ -3916,35 +3856,27 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
}
Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const {
-
r_valid = true;
switch (type) {
case INT: {
-
return r_iter;
} break;
case FLOAT: {
-
return r_iter;
} break;
case VECTOR2: {
-
return r_iter;
} break;
case VECTOR2I: {
-
return r_iter;
} break;
case VECTOR3: {
-
return r_iter;
} break;
case VECTOR3I: {
-
return r_iter;
} break;
case OBJECT: {
-
if (!_get_obj().obj) {
r_valid = false;
return Variant();
@@ -3972,17 +3904,14 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const {
} break;
case STRING: {
-
const String *str = reinterpret_cast<const String *>(_data._mem);
return str->substr(r_iter, 1);
} break;
case DICTIONARY: {
-
return r_iter; //iterator is the same as the key
} break;
case ARRAY: {
-
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
int idx = r_iter;
#ifdef DEBUG_ENABLED
@@ -4060,7 +3989,6 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const {
return arr->get(idx);
} break;
case PACKED_VECTOR2_ARRAY: {
-
const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array);
int idx = r_iter;
#ifdef DEBUG_ENABLED
@@ -4072,7 +4000,6 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const {
return arr->get(idx);
} break;
case PACKED_VECTOR3_ARRAY: {
-
const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array);
int idx = r_iter;
#ifdef DEBUG_ENABLED
@@ -4084,7 +4011,6 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const {
return arr->get(idx);
} break;
case PACKED_COLOR_ARRAY: {
-
const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array);
int idx = r_iter;
#ifdef DEBUG_ENABLED
@@ -4237,7 +4163,6 @@ void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst)
}
void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst) {
-
if (a.type != b.type) {
if (a.is_num() && b.is_num()) {
//not as efficient but..
@@ -4252,7 +4177,6 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
}
switch (a.type) {
-
case NIL: {
r_dst = Variant();
}
@@ -4290,22 +4214,21 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
int split = csize / 2;
for (int i = 0; i < csize; i++) {
-
CharType chr = ' ';
if (i < split) {
-
- if (i < sa.length())
+ if (i < sa.length()) {
chr = sa[i];
- else if (i < sb.length())
+ } else if (i < sb.length()) {
chr = sb[i];
+ }
} else {
-
- if (i < sb.length())
+ if (i < sb.length()) {
chr = sb[i];
- else if (i < sa.length())
+ } else if (i < sa.length()) {
chr = sa[i];
+ }
}
dst[i] = chr;
@@ -4423,10 +4346,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
const Vector<int32_t> *arr_b = &PackedArrayRef<int32_t>::get_array(b._data.packed_array);
int32_t sz = arr_a->size();
if (sz == 0 || arr_b->size() != sz) {
-
r_dst = a;
} else {
-
Vector<int32_t> v;
v.resize(sz);
{
@@ -4449,10 +4370,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
const Vector<int64_t> *arr_b = &PackedArrayRef<int64_t>::get_array(b._data.packed_array);
int64_t sz = arr_a->size();
if (sz == 0 || arr_b->size() != sz) {
-
r_dst = a;
} else {
-
Vector<int64_t> v;
v.resize(sz);
{
@@ -4475,10 +4394,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
const Vector<float> *arr_b = &PackedArrayRef<float>::get_array(b._data.packed_array);
int sz = arr_a->size();
if (sz == 0 || arr_b->size() != sz) {
-
r_dst = a;
} else {
-
Vector<float> v;
v.resize(sz);
{
@@ -4501,10 +4418,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
const Vector<double> *arr_b = &PackedArrayRef<double>::get_array(b._data.packed_array);
int sz = arr_a->size();
if (sz == 0 || arr_b->size() != sz) {
-
r_dst = a;
} else {
-
Vector<double> v;
v.resize(sz);
{
@@ -4531,10 +4446,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
const Vector<Vector2> *arr_b = &PackedArrayRef<Vector2>::get_array(b._data.packed_array);
int sz = arr_a->size();
if (sz == 0 || arr_b->size() != sz) {
-
r_dst = a;
} else {
-
Vector<Vector2> v;
v.resize(sz);
{
@@ -4551,15 +4464,12 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
}
return;
case PACKED_VECTOR3_ARRAY: {
-
const Vector<Vector3> *arr_a = &PackedArrayRef<Vector3>::get_array(a._data.packed_array);
const Vector<Vector3> *arr_b = &PackedArrayRef<Vector3>::get_array(b._data.packed_array);
int sz = arr_a->size();
if (sz == 0 || arr_b->size() != sz) {
-
r_dst = a;
} else {
-
Vector<Vector3> v;
v.resize(sz);
{
@@ -4580,10 +4490,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
const Vector<Color> *arr_b = &PackedArrayRef<Color>::get_array(b._data.packed_array);
int sz = arr_a->size();
if (sz == 0 || arr_b->size() != sz) {
-
r_dst = a;
} else {
-
Vector<Color> v;
v.resize(sz);
{
@@ -4600,7 +4508,6 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
}
return;
default: {
-
r_dst = a;
}
}
@@ -4636,7 +4543,6 @@ static const char *_op_names[Variant::OP_MAX] = {
};
String Variant::get_operator_name(Operator p_op) {
-
ERR_FAIL_INDEX_V(p_op, OP_MAX, "");
return _op_names[p_op];
}
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index c9678c9933..9fe98265dd 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -36,21 +36,18 @@
#include "core/string_buffer.h"
CharType VariantParser::StreamFile::get_char() {
-
return f->get_8();
}
bool VariantParser::StreamFile::is_utf8() const {
-
return true;
}
-bool VariantParser::StreamFile::is_eof() const {
+bool VariantParser::StreamFile::is_eof() const {
return f->eof_reached();
}
CharType VariantParser::StreamString::get_char() {
-
if (pos > s.length()) {
return 0;
} else if (pos == s.length()) {
@@ -66,6 +63,7 @@ CharType VariantParser::StreamString::get_char() {
bool VariantParser::StreamString::is_utf8() const {
return false;
}
+
bool VariantParser::StreamString::is_eof() const {
return pos > s.length();
}
@@ -93,11 +91,9 @@ const char *VariantParser::tk_name[TK_MAX] = {
};
Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, String &r_err_str) {
-
bool string_name = false;
while (true) {
-
CharType cchar;
if (p_stream->saved) {
cchar = p_stream->saved;
@@ -111,9 +107,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
}
switch (cchar) {
-
case '\n': {
-
line++;
break;
};
@@ -122,71 +116,60 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
return OK;
} break;
case '{': {
-
r_token.type = TK_CURLY_BRACKET_OPEN;
return OK;
};
case '}': {
-
r_token.type = TK_CURLY_BRACKET_CLOSE;
return OK;
};
case '[': {
-
r_token.type = TK_BRACKET_OPEN;
return OK;
};
case ']': {
-
r_token.type = TK_BRACKET_CLOSE;
return OK;
};
case '(': {
-
r_token.type = TK_PARENTHESIS_OPEN;
return OK;
};
case ')': {
-
r_token.type = TK_PARENTHESIS_CLOSE;
return OK;
};
case ':': {
-
r_token.type = TK_COLON;
return OK;
};
case ';': {
-
while (true) {
CharType ch = p_stream->get_char();
if (p_stream->is_eof()) {
r_token.type = TK_EOF;
return OK;
}
- if (ch == '\n')
+ if (ch == '\n') {
break;
+ }
}
break;
};
case ',': {
-
r_token.type = TK_COMMA;
return OK;
};
case '.': {
-
r_token.type = TK_PERIOD;
return OK;
};
case '=': {
-
r_token.type = TK_EQUAL;
return OK;
};
case '#': {
-
StringBuffer<> color_str;
color_str += '#';
while (true) {
@@ -219,10 +202,8 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
[[fallthrough]];
}
case '"': {
-
String str;
while (true) {
-
CharType ch = p_stream->get_char();
if (ch == 0) {
@@ -242,7 +223,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
CharType res = 0;
switch (next) {
-
case 'b':
res = 8;
break;
@@ -268,7 +248,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
return ERR_PARSE_ERROR;
}
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
-
r_err_str = "Malformed hex constant in string";
r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
@@ -300,8 +279,9 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
str += res;
} else {
- if (ch == '\n')
+ if (ch == '\n') {
line++;
+ }
str += ch;
}
}
@@ -321,7 +301,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
} break;
default: {
-
if (cchar <= 32) {
break;
}
@@ -348,10 +327,8 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
bool is_float = false;
while (true) {
-
switch (reading) {
case READING_INT: {
-
if (c >= '0' && c <= '9') {
//pass
} else if (c == '.') {
@@ -366,9 +343,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
} break;
case READING_DEC: {
-
if (c >= '0' && c <= '9') {
-
} else if (c == 'e') {
reading = READING_EXP;
} else {
@@ -377,7 +352,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
} break;
case READING_EXP: {
-
if (c >= '0' && c <= '9') {
exp_beg = true;
@@ -390,8 +364,9 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
} break;
}
- if (reading == READING_DONE)
+ if (reading == READING_DONE) {
break;
+ }
num += c;
c = p_stream->get_char();
}
@@ -400,19 +375,18 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
r_token.type = TK_NUMBER;
- if (is_float)
+ if (is_float) {
r_token.value = num.as_double();
- else
+ } else {
r_token.value = num.as_int();
+ }
return OK;
} else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') {
-
StringBuffer<> id;
bool first = true;
while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) {
-
id += cchar;
cchar = p_stream->get_char();
first = false;
@@ -437,7 +411,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
}
Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String> &strings, int &line, String &r_err_str) {
-
Token token;
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
@@ -448,7 +421,6 @@ Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String> &strings,
String accum;
while (true) {
-
CharType c = p_stream->get_char();
if (p_stream->is_eof()) {
@@ -470,7 +442,6 @@ Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String> &strings,
template <class T>
Error VariantParser::_parse_construct(Stream *p_stream, Vector<T> &r_construct, int &line, String &r_err_str) {
-
Token token;
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
@@ -480,7 +451,6 @@ Error VariantParser::_parse_construct(Stream *p_stream, Vector<T> &r_construct,
bool first = true;
while (true) {
-
if (!first) {
get_token(p_stream, token, line, r_err_str);
if (token.type == TK_COMMA) {
@@ -509,7 +479,6 @@ Error VariantParser::_parse_construct(Stream *p_stream, Vector<T> &r_construct,
}
Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser) {
-
/* {
Error err = get_token(p_stream,token,line,r_err_str);
if (err)
@@ -517,41 +486,40 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}*/
if (token.type == TK_CURLY_BRACKET_OPEN) {
-
Dictionary d;
Error err = _parse_dictionary(d, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
value = d;
return OK;
} else if (token.type == TK_BRACKET_OPEN) {
-
Array a;
Error err = _parse_array(a, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
value = a;
return OK;
} else if (token.type == TK_IDENTIFIER) {
-
String id = token.value;
- if (id == "true")
+ if (id == "true") {
value = true;
- else if (id == "false")
+ } else if (id == "false") {
value = false;
- else if (id == "null" || id == "nil")
+ } else if (id == "null" || id == "nil") {
value = Variant();
- else if (id == "inf")
+ } else if (id == "inf") {
value = Math_INF;
- else if (id == "nan")
+ } else if (id == "nan") {
value = Math_NAN;
- else if (id == "Vector2") {
-
+ } else if (id == "Vector2") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 2) {
r_err_str = "Expected 2 arguments for constructor";
@@ -560,11 +528,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = Vector2(args[0], args[1]);
return OK;
} else if (id == "Vector2i") {
-
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 2) {
r_err_str = "Expected 2 arguments for constructor";
@@ -573,11 +541,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = Vector2i(args[0], args[1]);
return OK;
} else if (id == "Rect2") {
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
@@ -586,11 +554,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = Rect2(args[0], args[1], args[2], args[3]);
return OK;
} else if (id == "Rect2i") {
-
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
@@ -599,11 +567,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = Rect2i(args[0], args[1], args[2], args[3]);
return OK;
} else if (id == "Vector3") {
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 3) {
r_err_str = "Expected 3 arguments for constructor";
@@ -612,11 +580,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = Vector3(args[0], args[1], args[2]);
return OK;
} else if (id == "Vector3i") {
-
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 3) {
r_err_str = "Expected 3 arguments for constructor";
@@ -628,8 +596,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 6) {
r_err_str = "Expected 6 arguments for constructor";
@@ -641,11 +610,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = m;
return OK;
} else if (id == "Plane") {
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
@@ -654,11 +623,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = Plane(args[0], args[1], args[2], args[3]);
return OK;
} else if (id == "Quat") {
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
@@ -668,11 +637,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "AABB" || id == "Rect3") {
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 6) {
r_err_str = "Expected 6 arguments for constructor";
@@ -685,8 +654,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 9) {
r_err_str = "Expected 9 arguments for constructor";
@@ -695,11 +665,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = Basis(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]);
return OK;
} else if (id == "Transform") {
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 12) {
r_err_str = "Expected 12 arguments for constructor";
@@ -709,11 +679,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "Color") {
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
@@ -723,7 +693,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "NodePath") {
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
r_err_str = "Expected '('";
@@ -745,7 +714,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
} else if (id == "RID") {
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
r_err_str = "Expected '('";
@@ -768,7 +736,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "Object") {
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
r_err_str = "Expected '('";
@@ -803,17 +770,16 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
bool need_comma = false;
while (true) {
-
if (p_stream->is_eof()) {
r_err_str = "Unexpected End of File while parsing Object()";
return ERR_FILE_CORRUPT;
}
if (at_key) {
-
Error err = get_token(p_stream, token2, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token2.type == TK_PARENTHESIS_CLOSE) {
Reference *reference = Object::cast_to<Reference>(obj);
@@ -826,9 +792,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
if (need_comma) {
-
if (token2.type != TK_COMMA) {
-
r_err_str = "Expected '}' or ','";
return ERR_PARSE_ERROR;
} else {
@@ -846,24 +810,25 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
err = get_token(p_stream, token2, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token2.type != TK_COLON) {
-
r_err_str = "Expected ':'";
return ERR_PARSE_ERROR;
}
at_key = false;
} else {
-
Error err = get_token(p_stream, token2, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
Variant v;
err = parse_value(token2, v, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
obj->set(key, v);
need_comma = true;
at_key = true;
@@ -871,7 +836,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
} else if (id == "Resource" || id == "SubResource" || id == "ExtResource") {
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
r_err_str = "Expected '('";
@@ -879,37 +843,36 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
if (p_res_parser && id == "Resource" && p_res_parser->func) {
-
RES res;
Error err = p_res_parser->func(p_res_parser->userdata, p_stream, res, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
value = res;
return OK;
} else if (p_res_parser && id == "ExtResource" && p_res_parser->ext_func) {
-
RES res;
Error err = p_res_parser->ext_func(p_res_parser->userdata, p_stream, res, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
value = res;
return OK;
} else if (p_res_parser && id == "SubResource" && p_res_parser->sub_func) {
-
RES res;
Error err = p_res_parser->sub_func(p_res_parser->userdata, p_stream, res, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
value = res;
return OK;
} else {
-
get_token(p_stream, token, line, r_err_str);
if (token.type == TK_STRING) {
String path = token.value;
@@ -935,11 +898,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
} else if (id == "PackedByteArray" || id == "PoolByteArray" || id == "ByteArray") {
-
Vector<uint8_t> args;
Error err = _parse_construct<uint8_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<uint8_t> arr;
{
@@ -956,11 +919,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "PackedInt32Array" || id == "PackedIntArray" || id == "PoolIntArray" || id == "IntArray") {
-
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<int32_t> arr;
{
@@ -977,11 +940,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "PackedInt64Array") {
-
Vector<int64_t> args;
Error err = _parse_construct<int64_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<int64_t> arr;
{
@@ -998,11 +961,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "PackedFloat32Array" || id == "PackedRealArray" || id == "PoolRealArray" || id == "FloatArray") {
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<float> arr;
{
@@ -1018,11 +981,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "PackedFloat64Array") {
-
Vector<double> args;
Error err = _parse_construct<double>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<double> arr;
{
@@ -1038,7 +1001,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "PackedStringArray" || id == "PoolStringArray" || id == "StringArray") {
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
r_err_str = "Expected '('";
@@ -1049,7 +1011,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
bool first = true;
while (true) {
-
if (!first) {
get_token(p_stream, token, line, r_err_str);
if (token.type == TK_COMMA) {
@@ -1089,11 +1050,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "PackedVector2Array" || id == "PoolVector2Array" || id == "Vector2Array") {
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<Vector2> arr;
{
@@ -1110,11 +1071,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "PackedVector3Array" || id == "PoolVector3Array" || id == "Vector3Array") {
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<Vector3> arr;
{
@@ -1131,11 +1092,11 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (id == "PackedColorArray" || id == "PoolColorArray" || id == "ColorArray") {
-
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<Color> arr;
{
@@ -1158,19 +1119,15 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return OK;
} else if (token.type == TK_NUMBER) {
-
value = token.value;
return OK;
} else if (token.type == TK_STRING) {
-
value = token.value;
return OK;
} else if (token.type == TK_STRING_NAME) {
-
value = token.value;
return OK;
} else if (token.type == TK_COLOR) {
-
value = token.value;
return OK;
} else {
@@ -1180,30 +1137,26 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
Error VariantParser::_parse_array(Array &array, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser) {
-
Token token;
bool need_comma = false;
while (true) {
-
if (p_stream->is_eof()) {
r_err_str = "Unexpected End of File while parsing array";
return ERR_FILE_CORRUPT;
}
Error err = get_token(p_stream, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type == TK_BRACKET_CLOSE) {
-
return OK;
}
if (need_comma) {
-
if (token.type != TK_COMMA) {
-
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
} else {
@@ -1214,8 +1167,9 @@ Error VariantParser::_parse_array(Array &array, Stream *p_stream, int &line, Str
Variant v;
err = parse_value(token, v, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
array.push_back(v);
need_comma = true;
@@ -1223,34 +1177,29 @@ Error VariantParser::_parse_array(Array &array, Stream *p_stream, int &line, Str
}
Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser) {
-
bool at_key = true;
Variant key;
Token token;
bool need_comma = false;
while (true) {
-
if (p_stream->is_eof()) {
r_err_str = "Unexpected End of File while parsing dictionary";
return ERR_FILE_CORRUPT;
}
if (at_key) {
-
Error err = get_token(p_stream, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type == TK_CURLY_BRACKET_CLOSE) {
-
return OK;
}
if (need_comma) {
-
if (token.type != TK_COMMA) {
-
r_err_str = "Expected '}' or ','";
return ERR_PARSE_ERROR;
} else {
@@ -1261,29 +1210,31 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int
err = parse_value(token, key, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
err = get_token(p_stream, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type != TK_COLON) {
-
r_err_str = "Expected ':'";
return ERR_PARSE_ERROR;
}
at_key = false;
} else {
-
Error err = get_token(p_stream, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
Variant v;
err = parse_value(token, v, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
object[key] = v;
need_comma = true;
at_key = true;
@@ -1292,7 +1243,6 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int
}
Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, ResourceParser *p_res_parser, bool p_simple_tag) {
-
r_tag.fields.clear();
if (token.type != TK_BRACKET_OPEN) {
@@ -1301,19 +1251,18 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
}
if (p_simple_tag) {
-
r_tag.name = "";
r_tag.fields.clear();
while (true) {
-
CharType c = p_stream->get_char();
if (p_stream->is_eof()) {
r_err_str = "Unexpected EOF while parsing simple tag";
return ERR_PARSE_ERROR;
}
- if (c == ']')
+ if (c == ']') {
break;
+ }
r_tag.name += String::chr(c);
}
@@ -1333,15 +1282,15 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
bool parsing_tag = true;
while (true) {
-
if (p_stream->is_eof()) {
r_err_str = "Unexpected End of File while parsing tag: " + r_tag.name;
return ERR_FILE_CORRUPT;
}
get_token(p_stream, token, line, r_err_str);
- if (token.type == TK_BRACKET_CLOSE)
+ if (token.type == TK_BRACKET_CLOSE) {
break;
+ }
if (parsing_tag && token.type == TK_PERIOD) {
r_tag.name += "."; //support tags such as [someprop.Android] for specific platforms
@@ -1373,8 +1322,9 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
get_token(p_stream, token, line, r_err_str);
Variant value;
Error err = parse_value(token, value, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
r_tag.fields[id] = value;
}
@@ -1383,7 +1333,6 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
}
Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, ResourceParser *p_res_parser, bool p_simple_tag) {
-
Token token;
get_token(p_stream, token, line, r_err_str);
@@ -1400,13 +1349,11 @@ Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, T
}
Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, String &r_assign, Variant &r_value, ResourceParser *p_res_parser, bool p_simple_tag) {
-
//assign..
r_assign = "";
String what;
while (true) {
-
CharType c;
if (p_stream->saved) {
c = p_stream->saved;
@@ -1416,8 +1363,9 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r
c = p_stream->get_char();
}
- if (p_stream->is_eof())
+ if (p_stream->is_eof()) {
return ERR_FILE_EOF;
+ }
if (c == ';') { //comment
while (true) {
@@ -1425,8 +1373,9 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r
if (p_stream->is_eof()) {
return ERR_FILE_EOF;
}
- if (ch == '\n')
+ if (ch == '\n') {
break;
+ }
}
continue;
}
@@ -1445,8 +1394,9 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r
p_stream->saved = '"';
Token tk;
Error err = get_token(p_stream, tk, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (tk.type != TK_STRING) {
r_err_str = "Error reading quoted string";
return ERR_INVALID_DATA;
@@ -1470,11 +1420,11 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r
}
Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str, int &r_err_line, ResourceParser *p_res_parser) {
-
Token token;
Error err = get_token(p_stream, token, r_err_line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (token.type == TK_EOF) {
return ERR_FILE_EOF;
@@ -1488,103 +1438,88 @@ Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str,
////////////////////////////////////////////////////////////////////////////////
static String rtosfix(double p_value) {
-
- if (p_value == 0.0)
+ if (p_value == 0.0) {
return "0"; //avoid negative zero (-0) being written, which may annoy git, svn, etc. for changes when they don't exist.
- else
+ } else {
return rtoss(p_value);
+ }
}
Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_string_func, void *p_store_string_ud, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud) {
-
switch (p_variant.get_type()) {
-
case Variant::NIL: {
p_store_string_func(p_store_string_ud, "null");
} break;
case Variant::BOOL: {
-
p_store_string_func(p_store_string_ud, p_variant.operator bool() ? "true" : "false");
} break;
case Variant::INT: {
-
p_store_string_func(p_store_string_ud, itos(p_variant.operator int64_t()));
} break;
case Variant::FLOAT: {
-
String s = rtosfix(p_variant.operator real_t());
if (s != "inf" && s != "nan") {
- if (s.find(".") == -1 && s.find("e") == -1)
+ if (s.find(".") == -1 && s.find("e") == -1) {
s += ".0";
+ }
}
p_store_string_func(p_store_string_ud, s);
} break;
case Variant::STRING: {
-
String str = p_variant;
str = "\"" + str.c_escape_multiline() + "\"";
p_store_string_func(p_store_string_ud, str);
} break;
case Variant::VECTOR2: {
-
Vector2 v = p_variant;
p_store_string_func(p_store_string_ud, "Vector2( " + rtosfix(v.x) + ", " + rtosfix(v.y) + " )");
} break;
case Variant::VECTOR2I: {
-
Vector2i v = p_variant;
p_store_string_func(p_store_string_ud, "Vector2i( " + itos(v.x) + ", " + itos(v.y) + " )");
} break;
case Variant::RECT2: {
-
Rect2 aabb = p_variant;
p_store_string_func(p_store_string_ud, "Rect2( " + rtosfix(aabb.position.x) + ", " + rtosfix(aabb.position.y) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + " )");
} break;
case Variant::RECT2I: {
-
Rect2i aabb = p_variant;
p_store_string_func(p_store_string_ud, "Rect2i( " + itos(aabb.position.x) + ", " + itos(aabb.position.y) + ", " + itos(aabb.size.x) + ", " + itos(aabb.size.y) + " )");
} break;
case Variant::VECTOR3: {
-
Vector3 v = p_variant;
p_store_string_func(p_store_string_ud, "Vector3( " + rtosfix(v.x) + ", " + rtosfix(v.y) + ", " + rtosfix(v.z) + " )");
} break;
case Variant::VECTOR3I: {
-
Vector3i v = p_variant;
p_store_string_func(p_store_string_ud, "Vector3i( " + itos(v.x) + ", " + itos(v.y) + ", " + itos(v.z) + " )");
} break;
case Variant::PLANE: {
-
Plane p = p_variant;
p_store_string_func(p_store_string_ud, "Plane( " + rtosfix(p.normal.x) + ", " + rtosfix(p.normal.y) + ", " + rtosfix(p.normal.z) + ", " + rtosfix(p.d) + " )");
} break;
case Variant::AABB: {
-
AABB aabb = p_variant;
p_store_string_func(p_store_string_ud, "AABB( " + rtosfix(aabb.position.x) + ", " + rtosfix(aabb.position.y) + ", " + rtosfix(aabb.position.z) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + ", " + rtosfix(aabb.size.z) + " )");
} break;
case Variant::QUAT: {
-
Quat quat = p_variant;
p_store_string_func(p_store_string_ud, "Quat( " + rtosfix(quat.x) + ", " + rtosfix(quat.y) + ", " + rtosfix(quat.z) + ", " + rtosfix(quat.w) + " )");
} break;
case Variant::TRANSFORM2D: {
-
String s = "Transform2D( ";
Transform2D m3 = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
-
- if (i != 0 || j != 0)
+ if (i != 0 || j != 0) {
s += ", ";
+ }
s += rtosfix(m3.elements[i][j]);
}
}
@@ -1593,14 +1528,13 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::BASIS: {
-
String s = "Basis( ";
Basis m3 = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
-
- if (i != 0 || j != 0)
+ if (i != 0 || j != 0) {
s += ", ";
+ }
s += rtosfix(m3.elements[i][j]);
}
}
@@ -1609,15 +1543,14 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::TRANSFORM: {
-
String s = "Transform( ";
Transform t = p_variant;
Basis &m3 = t.basis;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
-
- if (i != 0 || j != 0)
+ if (i != 0 || j != 0) {
s += ", ";
+ }
s += rtosfix(m3.elements[i][j]);
}
}
@@ -1629,13 +1562,11 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
// misc types
case Variant::COLOR: {
-
Color c = p_variant;
p_store_string_func(p_store_string_ud, "Color( " + rtosfix(c.r) + ", " + rtosfix(c.g) + ", " + rtosfix(c.b) + ", " + rtosfix(c.a) + " )");
} break;
case Variant::STRING_NAME: {
-
String str = p_variant;
str = "@\"" + str.c_escape() + "\"";
@@ -1643,7 +1574,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::NODE_PATH: {
-
String str = p_variant;
str = "NodePath(\"" + str.c_escape() + "\")";
@@ -1652,7 +1582,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::OBJECT: {
-
Object *obj = p_variant;
if (!obj) {
@@ -1667,13 +1596,11 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
//try external function
if (p_encode_res_func) {
-
res_text = p_encode_res_func(p_encode_res_ud, res);
}
//try path because it's a file
if (res_text == String() && res->get_path().is_resource_file()) {
-
//external resource
String path = res->get_path();
res_text = "Resource( \"" + path + "\")";
@@ -1694,7 +1621,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
obj->get_property_list(&props);
bool first = true;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
-
if (E->get().usage & PROPERTY_USAGE_STORAGE || E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE) {
//must be serialized
@@ -1714,7 +1640,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::DICTIONARY: {
-
Dictionary dict = p_variant;
List<Variant> keys;
@@ -1723,7 +1648,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud, "{\n");
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
-
/*
if (!_check_type(dict[E->get()]))
continue;
@@ -1731,22 +1655,22 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
write(E->get(), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud);
p_store_string_func(p_store_string_ud, ": ");
write(dict[E->get()], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud);
- if (E->next())
+ if (E->next()) {
p_store_string_func(p_store_string_ud, ",\n");
+ }
}
p_store_string_func(p_store_string_ud, "\n}");
} break;
case Variant::ARRAY: {
-
p_store_string_func(p_store_string_ud, "[ ");
Array array = p_variant;
int len = array.size();
for (int i = 0; i < len; i++) {
-
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
write(array[i], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud);
}
p_store_string_func(p_store_string_ud, " ]");
@@ -1754,7 +1678,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::PACKED_BYTE_ARRAY: {
-
p_store_string_func(p_store_string_ud, "PackedByteArray( ");
String s;
Vector<uint8_t> data = p_variant;
@@ -1762,9 +1685,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
const uint8_t *ptr = data.ptr();
for (int i = 0; i < len; i++) {
-
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, itos(ptr[i]));
}
@@ -1773,16 +1696,15 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::PACKED_INT32_ARRAY: {
-
p_store_string_func(p_store_string_ud, "PackedInt32Array( ");
Vector<int32_t> data = p_variant;
int32_t len = data.size();
const int32_t *ptr = data.ptr();
for (int32_t i = 0; i < len; i++) {
-
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, itos(ptr[i]));
}
@@ -1791,16 +1713,15 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::PACKED_INT64_ARRAY: {
-
p_store_string_func(p_store_string_ud, "PackedInt64Array( ");
Vector<int64_t> data = p_variant;
int64_t len = data.size();
const int64_t *ptr = data.ptr();
for (int64_t i = 0; i < len; i++) {
-
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, itos(ptr[i]));
}
@@ -1809,16 +1730,15 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::PACKED_FLOAT32_ARRAY: {
-
p_store_string_func(p_store_string_ud, "PackedFloat32Array( ");
Vector<float> data = p_variant;
int len = data.size();
const float *ptr = data.ptr();
for (int i = 0; i < len; i++) {
-
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, rtosfix(ptr[i]));
}
@@ -1826,16 +1746,15 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::PACKED_FLOAT64_ARRAY: {
-
p_store_string_func(p_store_string_ud, "PackedFloat64Array( ");
Vector<double> data = p_variant;
int len = data.size();
const double *ptr = data.ptr();
for (int i = 0; i < len; i++) {
-
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, rtosfix(ptr[i]));
}
@@ -1843,7 +1762,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::PACKED_STRING_ARRAY: {
-
p_store_string_func(p_store_string_ud, "PackedStringArray( ");
Vector<String> data = p_variant;
int len = data.size();
@@ -1853,9 +1771,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
//write_string("\n");
for (int i = 0; i < len; i++) {
-
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
String str = ptr[i];
p_store_string_func(p_store_string_ud, "\"" + str.c_escape() + "\"");
}
@@ -1864,16 +1782,15 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::PACKED_VECTOR2_ARRAY: {
-
p_store_string_func(p_store_string_ud, "PackedVector2Array( ");
Vector<Vector2> data = p_variant;
int len = data.size();
const Vector2 *ptr = data.ptr();
for (int i = 0; i < len; i++) {
-
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y));
}
@@ -1881,16 +1798,15 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::PACKED_VECTOR3_ARRAY: {
-
p_store_string_func(p_store_string_ud, "PackedVector3Array( ");
Vector<Vector3> data = p_variant;
int len = data.size();
const Vector3 *ptr = data.ptr();
for (int i = 0; i < len; i++) {
-
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y) + ", " + rtosfix(ptr[i].z));
}
@@ -1898,7 +1814,6 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::PACKED_COLOR_ARRAY: {
-
p_store_string_func(p_store_string_ud, "PackedColorArray( ");
Vector<Color> data = p_variant;
@@ -1906,9 +1821,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
const Color *ptr = data.ptr();
for (int i = 0; i < len; i++) {
-
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, rtosfix(ptr[i].r) + ", " + rtosfix(ptr[i].g) + ", " + rtosfix(ptr[i].b) + ", " + rtosfix(ptr[i].a));
}
@@ -1923,14 +1838,12 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
}
static Error _write_to_str(void *ud, const String &p_string) {
-
String *str = (String *)ud;
(*str) += p_string;
return OK;
}
Error VariantWriter::write_to_string(const Variant &p_variant, String &r_string, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud) {
-
r_string = String();
return write(p_variant, _write_to_str, &r_string, p_encode_res_func, p_encode_res_ud);
diff --git a/core/variant_parser.h b/core/variant_parser.h
index af7d55d1b8..b55d7b2df0 100644
--- a/core/variant_parser.h
+++ b/core/variant_parser.h
@@ -38,7 +38,6 @@
class VariantParser {
public:
struct Stream {
-
virtual CharType get_char() = 0;
virtual bool is_utf8() const = 0;
virtual bool is_eof() const = 0;
@@ -50,7 +49,6 @@ public:
};
struct StreamFile : public Stream {
-
FileAccess *f = nullptr;
virtual CharType get_char();
@@ -61,7 +59,6 @@ public:
};
struct StreamString : public Stream {
-
String s;
int pos = 0;
@@ -75,7 +72,6 @@ public:
typedef Error (*ParseResourceFunc)(void *p_self, Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str);
struct ResourceParser {
-
void *userdata = nullptr;
ParseResourceFunc func;
ParseResourceFunc ext_func;
@@ -112,13 +108,11 @@ public:
};
struct Token {
-
TokenType type;
Variant value;
};
struct Tag {
-
String name;
Map<String, Variant> fields;
};
diff --git a/core/vector.h b/core/vector.h
index 7ab464fe11..696984ac28 100644
--- a/core/vector.h
+++ b/core/vector.h
@@ -70,8 +70,9 @@ public:
void remove(int p_index) { _cowdata.remove(p_index); }
void erase(const T &p_val) {
int idx = find(p_val);
- if (idx >= 0)
+ if (idx >= 0) {
remove(idx);
+ }
}
void invert();
@@ -93,10 +94,10 @@ public:
template <class C>
void sort_custom() {
-
int len = _cowdata.size();
- if (len == 0)
+ if (len == 0) {
return;
+ }
T *data = ptrw();
SortArray<T, C> sorter;
@@ -104,14 +105,12 @@ public:
}
void sort() {
-
sort_custom<_DefaultComparator<T>>();
}
void ordered_insert(const T &p_val) {
int i;
for (i = 0; i < _cowdata.size(); i++) {
-
if (p_val < operator[](i)) {
break;
};
@@ -132,7 +131,6 @@ public:
}
Vector<T> subarray(int p_from, int p_to) const {
-
if (p_from < 0) {
p_from = size() + p_from;
}
@@ -163,7 +161,6 @@ public:
template <class T>
void Vector<T>::invert() {
-
for (int i = 0; i < size() / 2; i++) {
T *p = ptrw();
SWAP(p[i], p[size() - i - 1]);
@@ -173,17 +170,18 @@ void Vector<T>::invert() {
template <class T>
void Vector<T>::append_array(Vector<T> p_other) {
const int ds = p_other.size();
- if (ds == 0)
+ if (ds == 0) {
return;
+ }
const int bs = size();
resize(bs + ds);
- for (int i = 0; i < ds; ++i)
+ for (int i = 0; i < ds; ++i) {
ptrw()[bs + i] = p_other[i];
+ }
}
template <class T>
bool Vector<T>::push_back(T p_elem) {
-
Error err = resize(size() + 1);
ERR_FAIL_COND_V(err, true);
set(size() - 1, p_elem);
diff --git a/core/vmap.h b/core/vmap.h
index 848b5055fa..c91ea9b3c9 100644
--- a/core/vmap.h
+++ b/core/vmap.h
@@ -38,14 +38,12 @@ template <class T, class V>
class VMap {
public:
struct Pair {
-
T key;
V value;
_FORCE_INLINE_ Pair() {}
_FORCE_INLINE_ Pair(const T &p_key, const V &p_value) {
-
key = p_key;
value = p_value;
}
@@ -55,10 +53,10 @@ private:
CowData<Pair> _cowdata;
_FORCE_INLINE_ int _find(const T &p_val, bool &r_exact) const {
-
r_exact = false;
- if (_cowdata.empty())
+ if (_cowdata.empty()) {
return 0;
+ }
int low = 0;
int high = _cowdata.size() - 1;
@@ -66,8 +64,9 @@ private:
int middle = 0;
#ifdef DEBUG_ENABLED
- if (low > high)
+ if (low > high) {
ERR_PRINT("low > high, this may be a bug");
+ }
#endif
while (low <= high) {
middle = (low + high) / 2;
@@ -83,15 +82,16 @@ private:
}
//return the position where this would be inserted
- if (a[middle].key < p_val)
+ if (a[middle].key < p_val) {
middle++;
+ }
return middle;
}
_FORCE_INLINE_ int _find_exact(const T &p_val) const {
-
- if (_cowdata.empty())
+ if (_cowdata.empty()) {
return -1;
+ }
int low = 0;
int high = _cowdata.size() - 1;
@@ -115,7 +115,6 @@ private:
public:
int insert(const T &p_key, const V &p_val) {
-
bool exact;
int pos = _find(p_key, exact);
if (exact) {
@@ -127,25 +126,22 @@ public:
}
bool has(const T &p_val) const {
-
return _find_exact(p_val) != -1;
}
void erase(const T &p_val) {
-
int pos = _find_exact(p_val);
- if (pos < 0)
+ if (pos < 0) {
return;
+ }
_cowdata.remove(pos);
}
int find(const T &p_val) const {
-
return _find_exact(p_val);
}
int find_nearest(const T &p_val) const {
-
bool exact;
return _find(p_val, exact);
}
@@ -154,37 +150,30 @@ public:
_FORCE_INLINE_ bool empty() const { return _cowdata.empty(); }
const Pair *get_array() const {
-
return _cowdata.ptr();
}
Pair *get_array() {
-
return _cowdata.ptrw();
}
const V &getv(int p_index) const {
-
return _cowdata.get(p_index).value;
}
V &getv(int p_index) {
-
return _cowdata.get_m(p_index).value;
}
const T &getk(int p_index) const {
-
return _cowdata.get(p_index).key;
}
T &getk(int p_index) {
-
return _cowdata.get_m(p_index).key;
}
inline const V &operator[](const T &p_key) const {
-
int pos = _find_exact(p_key);
CRASH_COND(pos < 0);
@@ -193,7 +182,6 @@ public:
}
inline V &operator[](const T &p_key) {
-
int pos = _find_exact(p_key);
if (pos < 0) {
pos = insert(p_key, V());
diff --git a/core/vset.h b/core/vset.h
index b96a115d21..034b8fe851 100644
--- a/core/vset.h
+++ b/core/vset.h
@@ -36,14 +36,13 @@
template <class T>
class VSet {
-
Vector<T> _data;
_FORCE_INLINE_ int _find(const T &p_val, bool &r_exact) const {
-
r_exact = false;
- if (_data.empty())
+ if (_data.empty()) {
return 0;
+ }
int low = 0;
int high = _data.size() - 1;
@@ -51,8 +50,9 @@ class VSet {
int middle = 0;
#ifdef DEBUG_ENABLED
- if (low > high)
+ if (low > high) {
ERR_PRINT("low > high, this may be a bug");
+ }
#endif
while (low <= high) {
@@ -69,15 +69,16 @@ class VSet {
}
//return the position where this would be inserted
- if (a[middle] < p_val)
+ if (a[middle] < p_val) {
middle++;
+ }
return middle;
}
_FORCE_INLINE_ int _find_exact(const T &p_val) const {
-
- if (_data.empty())
+ if (_data.empty()) {
return -1;
+ }
int low = 0;
int high = _data.size() - 1;
@@ -101,29 +102,27 @@ class VSet {
public:
void insert(const T &p_val) {
-
bool exact;
int pos = _find(p_val, exact);
- if (exact)
+ if (exact) {
return;
+ }
_data.insert(pos, p_val);
}
bool has(const T &p_val) const {
-
return _find_exact(p_val) != -1;
}
void erase(const T &p_val) {
-
int pos = _find_exact(p_val);
- if (pos < 0)
+ if (pos < 0) {
return;
+ }
_data.remove(pos);
}
int find(const T &p_val) const {
-
return _find_exact(p_val);
}
@@ -132,12 +131,10 @@ public:
_FORCE_INLINE_ int size() const { return _data.size(); }
inline T &operator[](int p_index) {
-
return _data.write[p_index];
}
inline const T &operator[](int p_index) const {
-
return _data[p_index];
}
};