summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/input/input.cpp5
-rw-r--r--core/input/input_event.cpp20
-rw-r--r--core/input/input_map.cpp5
-rw-r--r--core/math/basis.cpp12
-rw-r--r--core/math/basis.h2
-rw-r--r--core/math/vector2.cpp4
-rw-r--r--core/math/vector2.h30
-rw-r--r--core/math/vector3.cpp14
-rw-r--r--core/math/vector3.h60
-rw-r--r--core/math/vector3i.cpp4
-rw-r--r--core/math/vector3i.h50
-rw-r--r--core/object/object.cpp15
-rw-r--r--core/object/object.h1
-rw-r--r--core/templates/paged_allocator.h5
14 files changed, 143 insertions, 84 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 8ba8b892ac..72563cc40a 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -163,8 +163,7 @@ void Input::_bind_methods() {
void Input::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
#ifdef TOOLS_ENABLED
-
- const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
+ const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
String pf = p_function;
if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" ||
@@ -180,7 +179,7 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
}
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
- r_options->push_back(quote_style + name + quote_style);
+ r_options->push_back(name.quote(quote_style));
}
}
#endif
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 16bb92d94b..325cdf2127 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -431,10 +431,11 @@ 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) {
+ bool pressed = key->is_pressed();
if (p_pressed != nullptr) {
- *p_pressed = key->is_pressed();
+ *p_pressed = pressed;
}
- float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ float strength = pressed ? 1.0f : 0.0f;
if (p_strength != nullptr) {
*p_strength = strength;
}
@@ -587,10 +588,11 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p
bool match = mb->button_index == button_index;
if (match) {
+ bool pressed = mb->is_pressed();
if (p_pressed != nullptr) {
- *p_pressed = mb->is_pressed();
+ *p_pressed = pressed;
}
- float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ float strength = pressed ? 1.0f : 0.0f;
if (p_strength != nullptr) {
*p_strength = strength;
}
@@ -998,10 +1000,11 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *
bool match = button_index == jb->button_index;
if (match) {
+ bool pressed = jb->is_pressed();
if (p_pressed != nullptr) {
- *p_pressed = jb->is_pressed();
+ *p_pressed = pressed;
}
- float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ float strength = pressed ? 1.0f : 0.0f;
if (p_strength != nullptr) {
*p_strength = strength;
}
@@ -1291,10 +1294,11 @@ bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pres
bool match = action == act->action;
if (match) {
+ bool pressed = act->pressed;
if (p_pressed != nullptr) {
- *p_pressed = act->pressed;
+ *p_pressed = pressed;
}
- float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ float strength = pressed ? 1.0f : 0.0f;
if (p_strength != nullptr) {
*p_strength = strength;
}
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index 15be0f1e36..83ec70757e 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -222,11 +222,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()) {
+ bool pressed = input_event_action->is_pressed();
if (p_pressed != nullptr) {
- *p_pressed = input_event_action->is_pressed();
+ *p_pressed = pressed;
}
if (p_strength != nullptr) {
- *p_strength = (p_pressed != nullptr && *p_pressed) ? input_event_action->get_strength() : 0.0f;
+ *p_strength = pressed ? input_event_action->get_strength() : 0.0f;
}
return input_event_action->get_action() == p_action;
}
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index b5e25fb837..5c42213e61 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -381,6 +381,18 @@ Quaternion Basis::get_rotation_quaternion() const {
return m.get_quaternion();
}
+void Basis::rotate_to_align(Vector3 p_start_direction, Vector3 p_end_direction) {
+ // Takes two vectors and rotates the basis from the first vector to the second vector.
+ // Adopted from: https://gist.github.com/kevinmoran/b45980723e53edeb8a5a43c49f134724
+ const Vector3 axis = p_start_direction.cross(p_end_direction).normalized();
+ if (axis.length_squared() != 0) {
+ real_t dot = p_start_direction.dot(p_end_direction);
+ dot = CLAMP(dot, -1.0, 1.0);
+ const real_t angle_rads = Math::acos(dot);
+ set_axis_angle(axis, angle_rads);
+ }
+}
+
void Basis::get_rotation_axis_angle(Vector3 &p_axis, real_t &p_angle) const {
// Assumes that the matrix can be decomposed into a proper rotation and scaling matrix as M = R.S,
// and returns the Euler angles corresponding to the rotation part, complementing get_scale().
diff --git a/core/math/basis.h b/core/math/basis.h
index 3db2227b70..9d8ed16e29 100644
--- a/core/math/basis.h
+++ b/core/math/basis.h
@@ -88,6 +88,8 @@ public:
Quaternion get_rotation_quaternion() const;
Vector3 get_rotation() const { return get_rotation_euler(); };
+ void rotate_to_align(Vector3 p_start_direction, Vector3 p_end_direction);
+
Vector3 rotref_posscale_decomposition(Basis &rotref) const;
Vector3 get_euler_xyz() const;
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp
index eb3301f5d0..54abc1b7f2 100644
--- a/core/math/vector2.cpp
+++ b/core/math/vector2.cpp
@@ -102,7 +102,7 @@ Vector2 Vector2::round() const {
return Vector2(Math::round(x), Math::round(y));
}
-Vector2 Vector2::rotated(real_t p_by) const {
+Vector2 Vector2::rotated(const real_t p_by) const {
real_t sine = Math::sin(p_by);
real_t cosi = Math::cos(p_by);
return Vector2(
@@ -145,7 +145,7 @@ Vector2 Vector2::limit_length(const real_t p_len) const {
return v;
}
-Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_weight) const {
+Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, const real_t p_weight) const {
Vector2 p0 = p_pre_a;
Vector2 p1 = *this;
Vector2 p2 = p_b;
diff --git a/core/math/vector2.h b/core/math/vector2.h
index 4d9f3126e9..330b4741b1 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -66,7 +66,7 @@ struct Vector2 {
return p_idx ? y : x;
}
- _FORCE_INLINE_ void set_all(real_t p_value) {
+ _FORCE_INLINE_ void set_all(const real_t p_value) {
x = y = p_value;
}
@@ -106,11 +106,11 @@ struct Vector2 {
Vector2 posmodv(const Vector2 &p_modv) const;
Vector2 project(const Vector2 &p_to) const;
- Vector2 plane_project(real_t p_d, const Vector2 &p_vec) const;
+ Vector2 plane_project(const real_t p_d, const Vector2 &p_vec) const;
- _FORCE_INLINE_ Vector2 lerp(const Vector2 &p_to, real_t p_weight) const;
- _FORCE_INLINE_ Vector2 slerp(const Vector2 &p_to, real_t p_weight) const;
- Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_weight) const;
+ _FORCE_INLINE_ Vector2 lerp(const Vector2 &p_to, const real_t p_weight) const;
+ _FORCE_INLINE_ Vector2 slerp(const Vector2 &p_to, const real_t p_weight) const;
+ Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, const real_t p_weight) const;
Vector2 move_toward(const Vector2 &p_to, const real_t p_delta) const;
Vector2 slide(const Vector2 &p_normal) const;
@@ -152,7 +152,7 @@ struct Vector2 {
return Vector2(Math::abs(x), Math::abs(y));
}
- Vector2 rotated(real_t p_by) const;
+ Vector2 rotated(const real_t p_by) const;
Vector2 orthogonal() const {
return Vector2(y, -x);
}
@@ -168,29 +168,29 @@ struct Vector2 {
operator String() const;
_FORCE_INLINE_ Vector2() {}
- _FORCE_INLINE_ Vector2(real_t p_x, real_t p_y) {
+ _FORCE_INLINE_ Vector2(const real_t p_x, const real_t p_y) {
x = p_x;
y = p_y;
}
};
-_FORCE_INLINE_ Vector2 Vector2::plane_project(real_t p_d, const Vector2 &p_vec) const {
+_FORCE_INLINE_ Vector2 Vector2::plane_project(const real_t p_d, const Vector2 &p_vec) const {
return p_vec - *this * (dot(p_vec) - p_d);
}
-_FORCE_INLINE_ Vector2 operator*(float p_scalar, const Vector2 &p_vec) {
+_FORCE_INLINE_ Vector2 operator*(const float p_scalar, const Vector2 &p_vec) {
return p_vec * p_scalar;
}
-_FORCE_INLINE_ Vector2 operator*(double p_scalar, const Vector2 &p_vec) {
+_FORCE_INLINE_ Vector2 operator*(const double p_scalar, const Vector2 &p_vec) {
return p_vec * p_scalar;
}
-_FORCE_INLINE_ Vector2 operator*(int32_t p_scalar, const Vector2 &p_vec) {
+_FORCE_INLINE_ Vector2 operator*(const int32_t p_scalar, const Vector2 &p_vec) {
return p_vec * p_scalar;
}
-_FORCE_INLINE_ Vector2 operator*(int64_t p_scalar, const Vector2 &p_vec) {
+_FORCE_INLINE_ Vector2 operator*(const int64_t p_scalar, const Vector2 &p_vec) {
return p_vec * p_scalar;
}
@@ -250,7 +250,7 @@ _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_to, real_t p_weight) const {
+Vector2 Vector2::lerp(const Vector2 &p_to, const real_t p_weight) const {
Vector2 res = *this;
res.x += (p_weight * (p_to.x - x));
@@ -259,7 +259,7 @@ Vector2 Vector2::lerp(const Vector2 &p_to, real_t p_weight) const {
return res;
}
-Vector2 Vector2::slerp(const Vector2 &p_to, real_t p_weight) const {
+Vector2 Vector2::slerp(const Vector2 &p_to, const real_t p_weight) const {
#ifdef MATH_CHECKS
ERR_FAIL_COND_V_MSG(!is_normalized(), Vector2(), "The start Vector2 must be normalized.");
#endif
@@ -357,7 +357,7 @@ struct Vector2i {
x = (int32_t)p_vec2.x;
y = (int32_t)p_vec2.y;
}
- inline Vector2i(int32_t p_x, int32_t p_y) {
+ inline Vector2i(const int32_t p_x, const int32_t p_y) {
x = p_x;
y = p_y;
}
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index 3d59064af6..401c3ccd9c 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -32,22 +32,22 @@
#include "core/math/basis.h"
-void Vector3::rotate(const Vector3 &p_axis, real_t p_phi) {
+void Vector3::rotate(const Vector3 &p_axis, const 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 Vector3::rotated(const Vector3 &p_axis, const real_t p_phi) const {
Vector3 r = *this;
r.rotate(p_axis, p_phi);
return r;
}
-void Vector3::set_axis(int p_axis, real_t p_value) {
+void Vector3::set_axis(const int p_axis, const 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(const int p_axis) const {
ERR_FAIL_INDEX_V(p_axis, 3, 0);
return operator[](p_axis);
}
@@ -59,13 +59,13 @@ Vector3 Vector3::clamp(const Vector3 &p_min, const Vector3 &p_max) const {
CLAMP(z, p_min.z, p_max.z));
}
-void Vector3::snap(Vector3 p_step) {
+void Vector3::snap(const Vector3 p_step) {
x = Math::snapped(x, p_step.x);
y = Math::snapped(y, p_step.y);
z = Math::snapped(z, p_step.z);
}
-Vector3 Vector3::snapped(Vector3 p_step) const {
+Vector3 Vector3::snapped(const Vector3 p_step) const {
Vector3 v = *this;
v.snap(p_step);
return v;
@@ -82,7 +82,7 @@ Vector3 Vector3::limit_length(const real_t p_len) const {
return v;
}
-Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_weight) const {
+Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, const real_t p_weight) const {
Vector3 p0 = p_pre_a;
Vector3 p1 = *this;
Vector3 p2 = p_b;
diff --git a/core/math/vector3.h b/core/math/vector3.h
index d8d3cd3cc0..6a4c42f41b 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -56,18 +56,18 @@ struct Vector3 {
real_t coord[3] = { 0 };
};
- _FORCE_INLINE_ const real_t &operator[](int p_axis) const {
+ _FORCE_INLINE_ const real_t &operator[](const int p_axis) const {
return coord[p_axis];
}
- _FORCE_INLINE_ real_t &operator[](int p_axis) {
+ _FORCE_INLINE_ real_t &operator[](const int p_axis) {
return coord[p_axis];
}
- void set_axis(int p_axis, real_t p_value);
- real_t get_axis(int p_axis) const;
+ void set_axis(const int p_axis, const real_t p_value);
+ real_t get_axis(const int p_axis) const;
- _FORCE_INLINE_ void set_all(real_t p_value) {
+ _FORCE_INLINE_ void set_all(const real_t p_value) {
x = y = z = p_value;
}
@@ -90,17 +90,17 @@ struct Vector3 {
_FORCE_INLINE_ void zero();
- void snap(Vector3 p_val);
- Vector3 snapped(Vector3 p_val) const;
+ void snap(const Vector3 p_val);
+ Vector3 snapped(const Vector3 p_val) const;
- void rotate(const Vector3 &p_axis, real_t p_phi);
- Vector3 rotated(const Vector3 &p_axis, real_t p_phi) const;
+ void rotate(const Vector3 &p_axis, const real_t p_phi);
+ Vector3 rotated(const Vector3 &p_axis, const real_t p_phi) const;
/* Static Methods between 2 vector3s */
- _FORCE_INLINE_ Vector3 lerp(const Vector3 &p_to, real_t p_weight) const;
- _FORCE_INLINE_ Vector3 slerp(const Vector3 &p_to, real_t p_weight) const;
- Vector3 cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_weight) const;
+ _FORCE_INLINE_ Vector3 lerp(const Vector3 &p_to, const real_t p_weight) const;
+ _FORCE_INLINE_ Vector3 slerp(const Vector3 &p_to, const real_t p_weight) const;
+ Vector3 cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, const real_t p_weight) const;
Vector3 move_toward(const Vector3 &p_to, const real_t p_delta) const;
_FORCE_INLINE_ Vector3 cross(const Vector3 &p_b) const;
@@ -143,10 +143,10 @@ struct Vector3 {
_FORCE_INLINE_ Vector3 &operator/=(const Vector3 &p_v);
_FORCE_INLINE_ Vector3 operator/(const Vector3 &p_v) const;
- _FORCE_INLINE_ Vector3 &operator*=(real_t p_scalar);
- _FORCE_INLINE_ Vector3 operator*(real_t p_scalar) const;
- _FORCE_INLINE_ Vector3 &operator/=(real_t p_scalar);
- _FORCE_INLINE_ Vector3 operator/(real_t p_scalar) const;
+ _FORCE_INLINE_ Vector3 &operator*=(const real_t p_scalar);
+ _FORCE_INLINE_ Vector3 operator*(const real_t p_scalar) const;
+ _FORCE_INLINE_ Vector3 &operator/=(const real_t p_scalar);
+ _FORCE_INLINE_ Vector3 operator/(const real_t p_scalar) const;
_FORCE_INLINE_ Vector3 operator-() const;
@@ -168,7 +168,7 @@ struct Vector3 {
y = p_ivec.y;
z = p_ivec.z;
}
- _FORCE_INLINE_ Vector3(real_t p_x, real_t p_y, real_t p_z) {
+ _FORCE_INLINE_ Vector3(const real_t p_x, const real_t p_y, const real_t p_z) {
x = p_x;
y = p_y;
z = p_z;
@@ -208,14 +208,14 @@ Vector3 Vector3::round() const {
return Vector3(Math::round(x), Math::round(y), Math::round(z));
}
-Vector3 Vector3::lerp(const Vector3 &p_to, real_t p_weight) const {
+Vector3 Vector3::lerp(const Vector3 &p_to, const real_t p_weight) const {
return Vector3(
x + (p_weight * (p_to.x - x)),
y + (p_weight * (p_to.y - y)),
z + (p_weight * (p_to.z - z)));
}
-Vector3 Vector3::slerp(const Vector3 &p_to, real_t p_weight) const {
+Vector3 Vector3::slerp(const Vector3 &p_to, const real_t p_weight) const {
real_t theta = angle_to(p_to);
return rotated(cross(p_to).normalized(), theta * p_weight);
}
@@ -303,29 +303,41 @@ 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) {
+Vector3 &Vector3::operator*=(const real_t p_scalar) {
x *= p_scalar;
y *= p_scalar;
z *= p_scalar;
return *this;
}
-_FORCE_INLINE_ Vector3 operator*(real_t p_scalar, const Vector3 &p_vec) {
+_FORCE_INLINE_ Vector3 operator*(const float p_scalar, const Vector3 &p_vec) {
return p_vec * p_scalar;
}
-Vector3 Vector3::operator*(real_t p_scalar) const {
+_FORCE_INLINE_ Vector3 operator*(const double p_scalar, const Vector3 &p_vec) {
+ return p_vec * p_scalar;
+}
+
+_FORCE_INLINE_ Vector3 operator*(const int32_t p_scalar, const Vector3 &p_vec) {
+ return p_vec * p_scalar;
+}
+
+_FORCE_INLINE_ Vector3 operator*(const int64_t p_scalar, const Vector3 &p_vec) {
+ return p_vec * p_scalar;
+}
+
+Vector3 Vector3::operator*(const real_t p_scalar) const {
return Vector3(x * p_scalar, y * p_scalar, z * p_scalar);
}
-Vector3 &Vector3::operator/=(real_t p_scalar) {
+Vector3 &Vector3::operator/=(const real_t p_scalar) {
x /= p_scalar;
y /= p_scalar;
z /= p_scalar;
return *this;
}
-Vector3 Vector3::operator/(real_t p_scalar) const {
+Vector3 Vector3::operator/(const real_t p_scalar) const {
return Vector3(x / p_scalar, y / p_scalar, z / p_scalar);
}
diff --git a/core/math/vector3i.cpp b/core/math/vector3i.cpp
index 2de1e4e331..d3a57af77c 100644
--- a/core/math/vector3i.cpp
+++ b/core/math/vector3i.cpp
@@ -30,12 +30,12 @@
#include "vector3i.h"
-void Vector3i::set_axis(int p_axis, int32_t p_value) {
+void Vector3i::set_axis(const int p_axis, const 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(const int p_axis) const {
ERR_FAIL_INDEX_V(p_axis, 3, 0);
return operator[](p_axis);
}
diff --git a/core/math/vector3i.h b/core/math/vector3i.h
index 37c7c1c368..9308d09045 100644
--- a/core/math/vector3i.h
+++ b/core/math/vector3i.h
@@ -51,16 +51,16 @@ struct Vector3i {
int32_t coord[3] = { 0 };
};
- _FORCE_INLINE_ const int32_t &operator[](int p_axis) const {
+ _FORCE_INLINE_ const int32_t &operator[](const int p_axis) const {
return coord[p_axis];
}
- _FORCE_INLINE_ int32_t &operator[](int p_axis) {
+ _FORCE_INLINE_ int32_t &operator[](const int p_axis) {
return coord[p_axis];
}
- void set_axis(int p_axis, int32_t p_value);
- int32_t get_axis(int p_axis) const;
+ void set_axis(const int p_axis, const int32_t p_value);
+ int32_t get_axis(const int p_axis) const;
int min_axis() const;
int max_axis() const;
@@ -84,12 +84,12 @@ struct Vector3i {
_FORCE_INLINE_ Vector3i &operator%=(const Vector3i &p_v);
_FORCE_INLINE_ Vector3i operator%(const Vector3i &p_v) const;
- _FORCE_INLINE_ Vector3i &operator*=(int32_t p_scalar);
- _FORCE_INLINE_ Vector3i operator*(int32_t p_scalar) const;
- _FORCE_INLINE_ Vector3i &operator/=(int32_t p_scalar);
- _FORCE_INLINE_ Vector3i operator/(int32_t p_scalar) const;
- _FORCE_INLINE_ Vector3i &operator%=(int32_t p_scalar);
- _FORCE_INLINE_ Vector3i operator%(int32_t p_scalar) const;
+ _FORCE_INLINE_ Vector3i &operator*=(const int32_t p_scalar);
+ _FORCE_INLINE_ Vector3i operator*(const int32_t p_scalar) const;
+ _FORCE_INLINE_ Vector3i &operator/=(const int32_t p_scalar);
+ _FORCE_INLINE_ Vector3i operator/(const int32_t p_scalar) const;
+ _FORCE_INLINE_ Vector3i &operator%=(const int32_t p_scalar);
+ _FORCE_INLINE_ Vector3i operator%(const int32_t p_scalar) const;
_FORCE_INLINE_ Vector3i operator-() const;
@@ -103,7 +103,7 @@ struct Vector3i {
operator String() const;
_FORCE_INLINE_ Vector3i() {}
- _FORCE_INLINE_ Vector3i(int32_t p_x, int32_t p_y, int32_t p_z) {
+ _FORCE_INLINE_ Vector3i(const int32_t p_x, const int32_t p_y, const int32_t p_z) {
x = p_x;
y = p_y;
z = p_z;
@@ -175,40 +175,52 @@ 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) {
+Vector3i &Vector3i::operator*=(const int32_t p_scalar) {
x *= p_scalar;
y *= p_scalar;
z *= p_scalar;
return *this;
}
-_FORCE_INLINE_ Vector3i operator*(int32_t p_scalar, const Vector3i &p_vec) {
- return p_vec * p_scalar;
+_FORCE_INLINE_ Vector3i operator*(const int32_t p_scalar, const Vector3i &p_vector) {
+ return p_vector * p_scalar;
}
-Vector3i Vector3i::operator*(int32_t p_scalar) const {
+_FORCE_INLINE_ Vector3i operator*(const int64_t p_scalar, const Vector3i &p_vector) {
+ return p_vector * p_scalar;
+}
+
+_FORCE_INLINE_ Vector3i operator*(const float p_scalar, const Vector3i &p_vector) {
+ return p_vector * p_scalar;
+}
+
+_FORCE_INLINE_ Vector3i operator*(const double p_scalar, const Vector3i &p_vector) {
+ return p_vector * p_scalar;
+}
+
+Vector3i Vector3i::operator*(const int32_t p_scalar) const {
return Vector3i(x * p_scalar, y * p_scalar, z * p_scalar);
}
-Vector3i &Vector3i::operator/=(int32_t p_scalar) {
+Vector3i &Vector3i::operator/=(const int32_t p_scalar) {
x /= p_scalar;
y /= p_scalar;
z /= p_scalar;
return *this;
}
-Vector3i Vector3i::operator/(int32_t p_scalar) const {
+Vector3i Vector3i::operator/(const int32_t p_scalar) const {
return Vector3i(x / p_scalar, y / p_scalar, z / p_scalar);
}
-Vector3i &Vector3i::operator%=(int32_t p_scalar) {
+Vector3i &Vector3i::operator%=(const int32_t p_scalar) {
x %= p_scalar;
y %= p_scalar;
z %= p_scalar;
return *this;
}
-Vector3i Vector3i::operator%(int32_t p_scalar) const {
+Vector3i Vector3i::operator%(const int32_t p_scalar) const {
return Vector3i(x % p_scalar, y % p_scalar, z % p_scalar);
}
diff --git a/core/object/object.cpp b/core/object/object.cpp
index c191109a8f..2bb4b981b9 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -1811,6 +1811,21 @@ void *Object::get_instance_binding(void *p_token, const GDNativeInstanceBindingC
return binding;
}
+bool Object::has_instance_binding(void *p_token) {
+ bool found = false;
+ _instance_binding_mutex.lock();
+ for (uint32_t i = 0; i < _instance_binding_count; i++) {
+ if (_instance_bindings[i].token == p_token) {
+ found = true;
+ break;
+ }
+ }
+
+ _instance_binding_mutex.unlock();
+
+ return found;
+}
+
void Object::_construct_object(bool p_reference) {
type_is_reference = p_reference;
_instance_id = ObjectDB::add_instance(this);
diff --git a/core/object/object.h b/core/object/object.h
index 1f5e17c99f..6523105820 100644
--- a/core/object/object.h
+++ b/core/object/object.h
@@ -809,6 +809,7 @@ public:
void *get_instance_binding(void *p_token, const GDNativeInstanceBindingCallbacks *p_callbacks);
// Used on creation by binding only.
void set_instance_binding(void *p_token, void *p_binding, const GDNativeInstanceBindingCallbacks *p_callbacks);
+ bool has_instance_binding(void *p_token);
void clear_internal_resource_paths();
diff --git a/core/templates/paged_allocator.h b/core/templates/paged_allocator.h
index 481289309f..dfc885c6eb 100644
--- a/core/templates/paged_allocator.h
+++ b/core/templates/paged_allocator.h
@@ -50,7 +50,8 @@ class PagedAllocator {
SpinLock spin_lock;
public:
- T *alloc() {
+ template <class... Args>
+ T *alloc(const Args &&...p_args) {
if (thread_safe) {
spin_lock.lock();
}
@@ -75,7 +76,7 @@ public:
if (thread_safe) {
spin_lock.unlock();
}
- memnew_placement(alloc, T);
+ memnew_placement(alloc, T(p_args...));
return alloc;
}