summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/input_map.cpp2
-rw-r--r--core/math/expression.cpp9
-rw-r--r--core/math/expression.h1
-rw-r--r--core/math/math_funcs.h2
-rw-r--r--core/math/vector2.cpp7
-rw-r--r--core/math/vector2.h1
-rw-r--r--core/math/vector3.cpp7
-rw-r--r--core/math/vector3.h1
-rw-r--r--core/os/input_event.cpp13
-rw-r--r--core/os/input_event.h4
-rw-r--r--core/script_language.h4
-rw-r--r--core/variant_call.cpp4
12 files changed, 52 insertions, 3 deletions
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 15f68f9c2a..012c6a7c4f 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -202,7 +202,7 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
if (p_pressed != NULL)
*p_pressed = input_event_action->is_pressed();
if (p_strength != NULL)
- *p_strength = (*p_pressed) ? 1.0f : 0.0f;
+ *p_strength = (*p_pressed) ? input_event_action->get_strength() : 0.0f;
return input_event_action->get_action() == p_action;
}
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index 079c9b524f..e484e9194d 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -70,6 +70,7 @@ const char *Expression::func_name[Expression::FUNC_MAX] = {
"inverse_lerp",
"range_lerp",
"smoothstep",
+ "move_toward",
"dectime",
"randomize",
"randi",
@@ -189,6 +190,7 @@ int Expression::get_func_argument_count(BuiltinFunc p_func) {
case MATH_LERP:
case MATH_INVERSE_LERP:
case MATH_SMOOTHSTEP:
+ case MATH_MOVE_TOWARD:
case MATH_DECTIME:
case MATH_WRAP:
case MATH_WRAPF:
@@ -407,6 +409,13 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
VALIDATE_ARG_NUM(2);
*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);
diff --git a/core/math/expression.h b/core/math/expression.h
index f20619f0b6..79f6f3989d 100644
--- a/core/math/expression.h
+++ b/core/math/expression.h
@@ -68,6 +68,7 @@ public:
MATH_INVERSE_LERP,
MATH_RANGE_LERP,
MATH_SMOOTHSTEP,
+ MATH_MOVE_TOWARD,
MATH_DECTIME,
MATH_RANDOMIZE,
MATH_RAND,
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 82b5b56c01..0e3bd8a318 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -224,6 +224,8 @@ public:
float x = CLAMP((p_weight - p_from) / (p_to - p_from), 0.0f, 1.0f);
return x * x * (3.0f - 2.0f * x);
}
+ static _ALWAYS_INLINE_ double move_toward(double p_from, double p_to, double p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SGN(p_to - p_from) * p_delta; }
+ static _ALWAYS_INLINE_ float move_toward(float p_from, float p_to, float p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SGN(p_to - p_from) * p_delta; }
static _ALWAYS_INLINE_ double linear2db(double p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; }
static _ALWAYS_INLINE_ float linear2db(float p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; }
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp
index 5c1ea5943d..779a28be66 100644
--- a/core/math/vector2.cpp
+++ b/core/math/vector2.cpp
@@ -164,6 +164,13 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c
return out;
}
+Vector2 Vector2::move_toward(const Vector2 &p_to, const real_t p_delta) const {
+ Vector2 v = *this;
+ Vector2 vd = p_to - v;
+ real_t len = vd.length();
+ return len <= p_delta || len < CMP_EPSILON ? p_to : v + vd / len * p_delta;
+}
+
// slide returns the component of the vector along the given plane, specified by its normal vector.
Vector2 Vector2::slide(const Vector2 &p_normal) const {
#ifdef MATH_CHECKS
diff --git a/core/math/vector2.h b/core/math/vector2.h
index a0c6024c9f..78a1641c1e 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -79,6 +79,7 @@ struct Vector2 {
_FORCE_INLINE_ Vector2 linear_interpolate(const Vector2 &p_b, real_t p_t) const;
_FORCE_INLINE_ Vector2 slerp(const Vector2 &p_b, real_t p_t) const;
Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const;
+ Vector2 move_toward(const Vector2 &p_to, const real_t p_delta) const;
Vector2 slide(const Vector2 &p_normal) const;
Vector2 bounce(const Vector2 &p_normal) const;
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index 1c28934422..73927821cf 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -127,6 +127,13 @@ Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, c
return out;
}
+Vector3 Vector3::move_toward(const Vector3 &p_to, const real_t p_delta) const {
+ Vector3 v = *this;
+ Vector3 vd = p_to - v;
+ real_t len = vd.length();
+ return len <= p_delta || len < CMP_EPSILON ? p_to : v + vd / len * p_delta;
+}
+
Vector3::operator String() const {
return (rtos(x) + ", " + rtos(y) + ", " + rtos(z));
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 21fc09653f..6423147282 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -94,6 +94,7 @@ struct Vector3 {
_FORCE_INLINE_ Vector3 slerp(const Vector3 &p_b, real_t p_t) const;
Vector3 cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
Vector3 cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
+ Vector3 move_toward(const Vector3 &p_to, const real_t p_delta) const;
_FORCE_INLINE_ Vector3 cross(const Vector3 &p_b) const;
_FORCE_INLINE_ real_t dot(const Vector3 &p_b) const;
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index a072017353..9c5066da3d 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -1010,6 +1010,14 @@ bool InputEventAction::is_pressed() const {
return pressed;
}
+void InputEventAction::set_strength(float p_strength) {
+ strength = CLAMP(p_strength, 0.0f, 1.0f);
+}
+
+float InputEventAction::get_strength() const {
+ return strength;
+}
+
bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const {
if (p_event.is_null())
return false;
@@ -1051,14 +1059,19 @@ void InputEventAction::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed);
//ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventAction::is_pressed);
+ ClassDB::bind_method(D_METHOD("set_strength", "strength"), &InputEventAction::set_strength);
+ ClassDB::bind_method(D_METHOD("get_strength"), &InputEventAction::get_strength);
+
// ClassDB::bind_method(D_METHOD("is_action", "name"), &InputEventAction::is_action);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength");
}
InputEventAction::InputEventAction() {
pressed = false;
+ strength = 1.0f;
}
/////////////////////////////
diff --git a/core/os/input_event.h b/core/os/input_event.h
index ba01516519..7a9a1f71c3 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -475,6 +475,7 @@ class InputEventAction : public InputEvent {
StringName action;
bool pressed;
+ float strength;
protected:
static void _bind_methods();
@@ -486,6 +487,9 @@ public:
void set_pressed(bool p_pressed);
virtual bool is_pressed() const;
+ void set_strength(float p_strength);
+ float get_strength() const;
+
virtual bool is_action(const StringName &p_action) const;
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const;
diff --git a/core/script_language.h b/core/script_language.h
index b2dab666c4..b0c60b4e90 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -250,7 +250,7 @@ public:
virtual Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { return ERR_UNAVAILABLE; }
virtual bool overrides_external_editor() { return false; }
- virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, bool &r_force, String &r_call_hint) { return ERR_UNAVAILABLE; }
+ virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<String> *r_options, bool &r_force, String &r_call_hint) { return ERR_UNAVAILABLE; }
struct LookupResult {
enum Type {
@@ -269,7 +269,7 @@ public:
int location;
};
- virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result) { return ERR_UNAVAILABLE; }
+ virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) { return ERR_UNAVAILABLE; }
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const = 0;
virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) = 0;
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index bffb9485b0..24f12df5db 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -348,6 +348,7 @@ struct _VariantCall {
VCALL_LOCALMEM2R(Vector2, linear_interpolate);
VCALL_LOCALMEM2R(Vector2, slerp);
VCALL_LOCALMEM4R(Vector2, cubic_interpolate);
+ VCALL_LOCALMEM2R(Vector2, move_toward);
VCALL_LOCALMEM1R(Vector2, rotated);
VCALL_LOCALMEM0R(Vector2, tangent);
VCALL_LOCALMEM0R(Vector2, floor);
@@ -389,6 +390,7 @@ struct _VariantCall {
VCALL_LOCALMEM2R(Vector3, linear_interpolate);
VCALL_LOCALMEM2R(Vector3, slerp);
VCALL_LOCALMEM4R(Vector3, cubic_interpolate);
+ VCALL_LOCALMEM2R(Vector3, move_toward);
VCALL_LOCALMEM1R(Vector3, dot);
VCALL_LOCALMEM1R(Vector3, cross);
VCALL_LOCALMEM1R(Vector3, outer);
@@ -1585,6 +1587,7 @@ void register_variant_methods() {
ADDFUNC2R(VECTOR2, VECTOR2, Vector2, linear_interpolate, VECTOR2, "b", REAL, "t", varray());
ADDFUNC2R(VECTOR2, VECTOR2, Vector2, slerp, VECTOR2, "b", REAL, "t", varray());
ADDFUNC4R(VECTOR2, VECTOR2, Vector2, cubic_interpolate, VECTOR2, "b", VECTOR2, "pre_a", VECTOR2, "post_b", REAL, "t", varray());
+ ADDFUNC2R(VECTOR2, VECTOR2, Vector2, move_toward, VECTOR2, "to", REAL, "delta", varray());
ADDFUNC1R(VECTOR2, VECTOR2, Vector2, rotated, REAL, "phi", varray());
ADDFUNC0R(VECTOR2, VECTOR2, Vector2, tangent, varray());
ADDFUNC0R(VECTOR2, VECTOR2, Vector2, floor, varray());
@@ -1626,6 +1629,7 @@ void register_variant_methods() {
ADDFUNC2R(VECTOR3, VECTOR3, Vector3, slerp, VECTOR3, "b", REAL, "t", varray());
ADDFUNC4R(VECTOR3, VECTOR3, Vector3, cubic_interpolate, VECTOR3, "b", VECTOR3, "pre_a", VECTOR3, "post_b", REAL, "t", varray());
ADDFUNC1R(VECTOR3, VECTOR3, Vector3, direction_to, VECTOR3, "b", varray());
+ ADDFUNC2R(VECTOR3, VECTOR3, Vector3, move_toward, VECTOR3, "to", REAL, "delta", varray());
ADDFUNC1R(VECTOR3, REAL, Vector3, dot, VECTOR3, "b", varray());
ADDFUNC1R(VECTOR3, VECTOR3, Vector3, cross, VECTOR3, "b", varray());
ADDFUNC1R(VECTOR3, BASIS, Vector3, outer, VECTOR3, "b", varray());