Compare commits

...

7 Commits

Author SHA1 Message Date
Lukas Tenbrink 0c3a8220cf
Merge f8280dff92 into a98d41f62b 2024-10-25 00:28:09 +02:00
David Snopek a98d41f62b
Merge pull request #1590 from dsnopek/reload-instance-bindings
Correctly set instance bindings on reload
2024-10-17 16:05:02 +02:00
David Snopek 96675a814b
Merge pull request #1625 from Flarkk/looking_at
Add `p_use_model_front` to `Basis::looking_at()`
2024-10-17 16:02:02 +02:00
Florent Guiocheau 02fd535454 Add p_use_model_front to Basis::looking_at() 2024-10-14 21:50:12 +02:00
Lukas Tenbrink f8280dff92
Appease formatter 2024-09-26 15:06:46 +02:00
Lukas Tenbrink d586975dcf
Rename Vector4.components -> coords.
The use of .components is deprecated.
2024-09-26 15:04:06 +02:00
David Snopek cb543c192a Correctly set instance bindings on reload 2024-09-17 09:18:08 -05:00
6 changed files with 26 additions and 35 deletions

View File

@ -61,6 +61,10 @@ class Wrapped {
thread_local static const StringName *_constructing_extension_class_name;
thread_local static const GDExtensionInstanceBindingCallbacks *_constructing_class_binding_callbacks;
#ifdef HOT_RELOAD_ENABLED
thread_local static GDExtensionObjectPtr _constructing_recreate_owner;
#endif
template <typename T>
_ALWAYS_INLINE_ static void _set_construct_info() {
_constructing_extension_class_name = T::_get_extension_class_name();
@ -71,15 +75,6 @@ protected:
virtual bool _is_extension_class() const { return false; }
static const StringName *_get_extension_class_name(); // This is needed to retrieve the class name before the godot object has its _extension and _extension_instance members assigned.
#ifdef HOT_RELOAD_ENABLED
struct RecreateInstance {
GDExtensionClassInstancePtr wrapper;
GDExtensionObjectPtr owner;
RecreateInstance *next;
};
inline static RecreateInstance *recreate_instance = nullptr;
#endif
void _notification(int p_what) {}
bool _set(const StringName &p_name, const Variant &p_property) { return false; }
bool _get(const StringName &p_name, Variant &r_property) const { return false; }

View File

@ -129,9 +129,8 @@ private:
static GDExtensionClassInstancePtr _recreate_instance_func(void *data, GDExtensionObjectPtr obj) {
if constexpr (!std::is_abstract_v<T>) {
#ifdef HOT_RELOAD_ENABLED
Wrapped::_constructing_recreate_owner = obj;
T *new_instance = (T *)memalloc(sizeof(T));
Wrapped::RecreateInstance recreate_data = { new_instance, obj, Wrapped::recreate_instance };
Wrapped::recreate_instance = &recreate_data;
memnew_placement(new_instance, T);
return new_instance;
#else

View File

@ -224,7 +224,7 @@ struct _NO_DISCARD_ Basis {
operator Quaternion() const { return get_quaternion(); }
static Basis looking_at(const Vector3 &p_target, const Vector3 &p_up = Vector3(0, 1, 0));
static Basis looking_at(const Vector3 &p_target, const Vector3 &p_up = Vector3(0, 1, 0), bool p_use_model_front = false);
Basis(const Quaternion &p_quaternion) { set_quaternion(p_quaternion); }
Basis(const Quaternion &p_quaternion, const Vector3 &p_scale) { set_quaternion_scale(p_quaternion, p_scale); }

View File

@ -55,16 +55,17 @@ struct _NO_DISCARD_ Vector4 {
real_t z;
real_t w;
};
real_t components[4] = { 0, 0, 0, 0 };
[[deprecated("Use coord instead")]] real_t components[4];
real_t coord[4] = { 0, 0, 0, 0 };
};
_FORCE_INLINE_ real_t &operator[](const int p_axis) {
DEV_ASSERT((unsigned int)p_axis < 4);
return components[p_axis];
return coord[p_axis];
}
_FORCE_INLINE_ const real_t &operator[](const int p_axis) const {
DEV_ASSERT((unsigned int)p_axis < 4);
return components[p_axis];
return coord[p_axis];
}
Vector4::Axis min_axis_index() const;

View File

@ -42,6 +42,10 @@ namespace godot {
thread_local const StringName *Wrapped::_constructing_extension_class_name = nullptr;
thread_local const GDExtensionInstanceBindingCallbacks *Wrapped::_constructing_class_binding_callbacks = nullptr;
#ifdef HOT_RELOAD_ENABLED
thread_local GDExtensionObjectPtr Wrapped::_constructing_recreate_owner = nullptr;
#endif
const StringName *Wrapped::_get_extension_class_name() {
return nullptr;
}
@ -55,25 +59,14 @@ void Wrapped::_postinitialize() {
Wrapped::Wrapped(const StringName p_godot_class) {
#ifdef HOT_RELOAD_ENABLED
if (unlikely(Wrapped::recreate_instance)) {
RecreateInstance *recreate_data = Wrapped::recreate_instance;
RecreateInstance *previous = nullptr;
while (recreate_data) {
if (recreate_data->wrapper == this) {
_owner = recreate_data->owner;
if (previous) {
previous->next = recreate_data->next;
} else {
Wrapped::recreate_instance = recreate_data->next;
}
return;
}
previous = recreate_data;
recreate_data = recreate_data->next;
}
}
if (unlikely(Wrapped::_constructing_recreate_owner)) {
_owner = Wrapped::_constructing_recreate_owner;
Wrapped::_constructing_recreate_owner = nullptr;
} else
#endif
_owner = godot::internal::gdextension_interface_classdb_construct_object(reinterpret_cast<GDExtensionConstStringNamePtr>(p_godot_class._native_ptr()));
{
_owner = godot::internal::gdextension_interface_classdb_construct_object(reinterpret_cast<GDExtensionConstStringNamePtr>(p_godot_class._native_ptr()));
}
if (_constructing_extension_class_name) {
godot::internal::gdextension_interface_object_set_instance(_owner, reinterpret_cast<GDExtensionConstStringNamePtr>(_constructing_extension_class_name), this);

View File

@ -1037,12 +1037,15 @@ void Basis::rotate_sh(real_t *p_values) {
p_values[8] = d4 * s_scale_dst4;
}
Basis Basis::looking_at(const Vector3 &p_target, const Vector3 &p_up) {
Basis Basis::looking_at(const Vector3 &p_target, const Vector3 &p_up, bool p_use_model_front) {
#ifdef MATH_CHECKS
ERR_FAIL_COND_V_MSG(p_target.is_zero_approx(), Basis(), "The target vector can't be zero.");
ERR_FAIL_COND_V_MSG(p_up.is_zero_approx(), Basis(), "The up vector can't be zero.");
#endif
Vector3 v_z = -p_target.normalized();
Vector3 v_z = p_target.normalized();
if (!p_use_model_front) {
v_z = -v_z;
}
Vector3 v_x = p_up.cross(v_z);
#ifdef MATH_CHECKS
ERR_FAIL_COND_V_MSG(v_x.is_zero_approx(), Basis(), "The target vector and up vector can't be parallel to each other.");