Author SHA1 Message Date
ActualHorse a2c0d299d4 draw_debug_polygons() now handles parenting the line mesh all on its own. 2026-09-13 00:52:11 -04:00
ActualHorse bd78ca9046 PlayerSpawn now *actually* uses the new print macros. 2026-09-13 00:50:54 -04:00
ActualHorse 36c7f87dc0 - Hurtboxes now create their own collision shape nodes automatically.
- Character3D prevent crashes on _ready by checking for a valid skeleton.
- Fixed deadzone reading as cleared for all axes when only one has done so.
- Singletons once again deregistered, since it seems to now cause less crashes.
- PlayerSpawn now uses the new error-printing macro.
2026-09-13 00:02:40 -04:00
9 changed files with 87 additions and 39 deletions
@@ -19,6 +19,8 @@ using namespace godot;
void Character3D::_ready() void Character3D::_ready()
{
if (this->skeleton)
{ {
TypedArray<Node> child_mesh_candidates = this->skeleton->get_children(); TypedArray<Node> child_mesh_candidates = this->skeleton->get_children();
const uint32_t num_children = child_mesh_candidates.size(); const uint32_t num_children = child_mesh_candidates.size();
@@ -30,6 +32,13 @@ void Character3D::_ready()
} }
} }
} }
#ifdef DEBUG_ENABLED
else
{
PRINT_ERROR(CHARACTER3D_TAG, "No skeleton has been set, and there is currently no way to seek one out in the hierarchy. This will be a problem.");
}
#endif // DEBUG_ENABLED
}
void Character3D::take_damage(const Dictionary &hit_data) void Character3D::take_damage(const Dictionary &hit_data)
@@ -54,6 +63,8 @@ void Character3D::take_damage(const Dictionary &hit_data)
void Character3D::_activate_ragdoll() void Character3D::_activate_ragdoll()
{
if (this->physical_bone_simulator)
{ {
const TypedArray<Node> &physical_bones = this->physical_bone_simulator->get_children(); const TypedArray<Node> &physical_bones = this->physical_bone_simulator->get_children();
const uint32_t num_physical_bones = physical_bones.size(); const uint32_t num_physical_bones = physical_bones.size();
@@ -66,6 +77,7 @@ void Character3D::_activate_ragdoll()
} }
this->physical_bone_simulator->physical_bones_start_simulation(); this->physical_bone_simulator->physical_bones_start_simulation();
} }
}
void Character3D::_on_fell_out_of_world() void Character3D::_on_fell_out_of_world()
+31 -5
View File
@@ -10,6 +10,7 @@
#include "character_3d.h" #include "character_3d.h"
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/physical_bone3d.hpp> #include <godot_cpp/classes/physical_bone3d.hpp>
#include <godot_cpp/classes/scene_tree.hpp> #include <godot_cpp/classes/scene_tree.hpp>
#include <godot_cpp/classes/scene_tree_timer.hpp> #include <godot_cpp/classes/scene_tree_timer.hpp>
@@ -17,8 +18,35 @@
using namespace godot; using namespace godot;
void HurtboxBase::_enter_tree()
{
if (!this->collision_shape)
{
this->collision_shape = memnew(CollisionShape3D);
this->collision_shape->set_shape(this->shape);
this->add_child(this->collision_shape);
}
Area3D::_enter_tree();
}
void HurtboxBase::_exit_tree()
{
if (this->collision_shape)
{
this->collision_shape->set_shape(this->shape);
this->remove_child(this->collision_shape);
this->collision_shape->queue_free();
}
Area3D::_exit_tree();
}
void HurtboxBase::_ready() void HurtboxBase::_ready()
{ {
#ifdef DEBUG_ENABLED
if(Engine::get_singleton()->is_editor_hint()) { this->set_physics_process(false); return; }
#endif // DEBUG_ENABLED
this->set_process(false); this->set_process(false);
this->remaining_life = this->lifetime; this->remaining_life = this->lifetime;
@@ -27,11 +55,6 @@ void HurtboxBase::_ready()
void HurtboxBase::_physics_process(double delta) void HurtboxBase::_physics_process(double delta)
{ {
if (this->remaining_life <= 0.0f)
{
this->collision_shape->set_disabled(true);
}
TypedArray<Character3D> characters_hit_this_frame; TypedArray<Character3D> characters_hit_this_frame;
const TypedArray<Node3D> &bodies = this->get_overlapping_bodies(); const TypedArray<Node3D> &bodies = this->get_overlapping_bodies();
@@ -73,6 +96,9 @@ void HurtboxBase::_physics_process(double delta)
this->hit_character_bodies.append_array(characters_hit_this_frame); this->hit_character_bodies.append_array(characters_hit_this_frame);
if (this->remaining_life <= 0.0f)
this->collision_shape->set_disabled(true);
else
this->remaining_life -= delta; this->remaining_life -= delta;
} }
+7 -3
View File
@@ -12,6 +12,7 @@
#include "character_3d.h" #include "character_3d.h"
#include <godot_cpp/classes/collision_shape3d.hpp> #include <godot_cpp/classes/collision_shape3d.hpp>
#include <godot_cpp/classes/shape3d.hpp>
#include <godot_cpp/classes/area3d.hpp> #include <godot_cpp/classes/area3d.hpp>
using namespace godot; using namespace godot;
@@ -23,11 +24,13 @@ class HurtboxBase : public Area3D
GDCLASS(HurtboxBase, Area3D); GDCLASS(HurtboxBase, Area3D);
public: public:
virtual void _enter_tree() override;
virtual void _exit_tree() override;
virtual void _ready() override; virtual void _ready() override;
virtual void _physics_process(double delta) override; virtual void _physics_process(double delta) override;
void set_collision_shape(CollisionShape3D *cs) { this->collision_shape = cs; } void set_shape(Ref<Shape3D> s) { this->shape = s; }
CollisionShape3D *get_collision_shape() const { return this->collision_shape; } Ref<Shape3D> get_shape() const { return this->shape; }
void set_lifetime(const float lt) { this->lifetime = lt; } void set_lifetime(const float lt) { this->lifetime = lt; }
float get_lifetime() const { return this->lifetime; } float get_lifetime() const { return this->lifetime; }
@@ -42,6 +45,7 @@ private:
Dictionary _create_hit_data_struct() const; Dictionary _create_hit_data_struct() const;
void _send_next_in_queue(); void _send_next_in_queue();
Ref<Shape3D> shape = nullptr;
CollisionShape3D *collision_shape = nullptr; CollisionShape3D *collision_shape = nullptr;
float lifetime = 0.05f; float lifetime = 0.05f;
@@ -55,7 +59,7 @@ private:
protected: protected:
static void _bind_methods() static void _bind_methods()
{ {
ADD_GETTER_SETTER_HINTED(HurtboxBase, collision_shape, Variant::OBJECT, PROPERTY_HINT_NODE_TYPE, "CollisionShape3D"); ADD_GETTER_SETTER_HINTED(HurtboxBase, shape, Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Shape3D");
ADD_GETTER_SETTER(HurtboxBase, lifetime, Variant::FLOAT); ADD_GETTER_SETTER(HurtboxBase, lifetime, Variant::FLOAT);
ADD_GETTER_SETTER(HurtboxBase, hit_points, Variant::INT); ADD_GETTER_SETTER(HurtboxBase, hit_points, Variant::INT);
+9 -11
View File
@@ -490,15 +490,7 @@ PackedVector3Array MeshEditingLibrary::slice_mesh(MeshInstance3D *original_mesh_
std::vector<MeshEditPolygon2D> error_polygons; std::vector<MeshEditPolygon2D> error_polygons;
const Transform3D &plane_inverse_transform = MeshEditingLibrary::project_edges(edges_2d, original_mesh_instance->get_transform(), clip_edges, local_plane); const Transform3D &plane_inverse_transform = MeshEditingLibrary::project_edges(edges_2d, original_mesh_instance->get_transform(), clip_edges, local_plane);
MeshEditingLibrary::build_2d_polygons_from_edges(polygon_set, edges_2d, error_polygons); MeshEditingLibrary::build_2d_polygons_from_edges(polygon_set, edges_2d, error_polygons);
MeshEditingLibrary::draw_debug_polygons(original_mesh_instance, error_polygons, plane_inverse_transform, Color(1.0f, 0.0f, 0.0f, 1.0f));
if (error_polygons.size() > 0)
{
Ref<Mesh> debug_mesh = MeshEditingLibrary::draw_debug_polygons(error_polygons, plane_inverse_transform, Color(1.0f, 0.0f, 0.0f, 1.0f));
MeshInstance3D *mi = memnew(MeshInstance3D);
original_mesh_instance->add_child(mi);
mi->set_transform(Transform3D());
mi->set_mesh(debug_mesh);
}
MeshSlicePlaneOrientation uv_plane = MeshSlicePlaneOrientation::Z; MeshSlicePlaneOrientation uv_plane = MeshSlicePlaneOrientation::Z;
const Basis &mesh_instance_basis = original_mesh_instance->get_basis(); const Basis &mesh_instance_basis = original_mesh_instance->get_basis();
@@ -880,9 +872,12 @@ const Vector2 MeshEditingLibrary::calculate_planar_uv(const Vector3 &vertex, con
} }
Ref<Mesh> MeshEditingLibrary::draw_debug_polygons(const std::vector<MeshEditPolygon2D> &polygons, const Transform3D &plane_transform, const Color &colour) void MeshEditingLibrary::draw_debug_polygons(Node3D *mesh_parent_node, const std::vector<MeshEditPolygon2D> &polygons, const Transform3D &plane_transform, const Color &colour)
{ {
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
if (polygons.size() <= 0)
return;
Ref<StandardMaterial3D> material; Ref<StandardMaterial3D> material;
material.instantiate(); material.instantiate();
material->set_flag(BaseMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); material->set_flag(BaseMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
@@ -912,6 +907,9 @@ Ref<Mesh> MeshEditingLibrary::draw_debug_polygons(const std::vector<MeshEditPoly
} }
im->surface_end(); im->surface_end();
return im; MeshInstance3D *mi = memnew(MeshInstance3D);
mesh_parent_node->add_child(mi);
mi->set_transform(Transform3D());
mi->set_mesh(im);
#endif // DEBUG_ENABLED #endif // DEBUG_ENABLED
} }
+1 -1
View File
@@ -90,7 +90,7 @@ private:
static bool find_next_edge(MeshEditEdge2D &out_next_edge, std::vector<MeshEditEdge2D> &in_edge_set, const MeshEditVert2D &start); static bool find_next_edge(MeshEditEdge2D &out_next_edge, std::vector<MeshEditEdge2D> &in_edge_set, const MeshEditVert2D &start);
static void fix_polygon_winding(MeshEditPolygon2D &polygon); static void fix_polygon_winding(MeshEditPolygon2D &polygon);
static Ref<Mesh> draw_debug_polygons(const std::vector<MeshEditPolygon2D> &polygons, const Transform3D &plane_transform, const Color &colour); static void draw_debug_polygons(Node3D *mesh_parent_node, const std::vector<MeshEditPolygon2D> &polygons, const Transform3D &plane_transform, const Color &colour);
// Godot boilerplate below // Godot boilerplate below
protected: protected:
+1 -1
View File
@@ -68,7 +68,7 @@ bool PlayerOrigin::spawn_player(Node3D *parent, Ref<PackedScene> player) const
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
else else
{ {
UtilityFunctions::push_error("Empty sublevel in PlayerSpawn object \"", this->tag, "\""); PRINT_ERROR(PLAYERSPAWN_LOG_TAG, "Empty sublevel in PlayerSpawn object \"", this->tag, "\"");
} }
#endif #endif
} }
+2
View File
@@ -14,6 +14,8 @@
#include <godot_cpp/classes/packed_scene.hpp> #include <godot_cpp/classes/packed_scene.hpp>
using namespace godot; using namespace godot;
#define PLAYERSPAWN_LOG_TAG "PlayerSpawn"
#define PLAYER_ORIGIN_TAG "origin" #define PLAYER_ORIGIN_TAG "origin"
+3 -3
View File
@@ -88,9 +88,9 @@ void uninitialize_orng_module(ModuleInitializationLevel p_level) {
if (p_level == ModuleInitializationLevel::MODULE_INITIALIZATION_LEVEL_SCENE) if (p_level == ModuleInitializationLevel::MODULE_INITIALIZATION_LEVEL_SCENE)
{ {
// GDSINGLETON_UNREGISTER_CLASS(_vendor_service_singleton); // GDSINGLETON_UNREGISTER_CLASS(_vendor_service_singleton);
// GDSINGLETON_UNREGISTER_CLASS(_scene_loader_singleton); GDSINGLETON_UNREGISTER_CLASS(_scene_loader_singleton);
// GDSINGLETON_UNREGISTER_CLASS(_save_manager_singleton); GDSINGLETON_UNREGISTER_CLASS(_save_manager_singleton);
// GDSINGLETON_UNREGISTER_CLASS(_input_handler_singleton); GDSINGLETON_UNREGISTER_CLASS(_input_handler_singleton);
} }
} }
+9 -3
View File
@@ -55,7 +55,8 @@ void InputResource::update_axes(const float delta)
const StringName &signal_1d = prefix + INPUTAXIS_ONE_DIMENSIONAL_SUFFIX + INPUTHANDLER_SUFFIX_SIGNAL; const StringName &signal_1d = prefix + INPUTAXIS_ONE_DIMENSIONAL_SUFFIX + INPUTHANDLER_SUFFIX_SIGNAL;
if (this->has_signal(signal_1d)) if (this->has_signal(signal_1d))
{ {
const float x_axis = axis->get_x_axis(); float x_axis = axis->get_x_axis();
if (UtilityFunctions::absf(x_axis) < axis_deadzone) x_axis = 0.0f;
if (current_input.x != x_axis || current_input.length() > SMALL_NUMBER) if (current_input.x != x_axis || current_input.length() > SMALL_NUMBER)
this->emit_signal(signal_1d, delta, x_axis); this->emit_signal(signal_1d, delta, x_axis);
current_input.x = x_axis; current_input.x = x_axis;
@@ -64,7 +65,9 @@ void InputResource::update_axes(const float delta)
const StringName &signal_2d = prefix + INPUTAXIS_TWO_DIMENSIONAL_SUFFIX + INPUTHANDLER_SUFFIX_SIGNAL; const StringName &signal_2d = prefix + INPUTAXIS_TWO_DIMENSIONAL_SUFFIX + INPUTHANDLER_SUFFIX_SIGNAL;
if (this->has_signal(signal_2d)) if (this->has_signal(signal_2d))
{ {
const Vector2 &vector = axis->get_lateral_vector(); Vector2 &vector = axis->get_lateral_vector();
if (UtilityFunctions::absf(vector.x) < axis_deadzone) vector.x = 0.0f;
if (UtilityFunctions::absf(vector.y) < axis_deadzone) vector.y = 0.0f;
if ((current_input.x != vector.x || current_input.z != vector.y) || current_input.length() > SMALL_NUMBER) if ((current_input.x != vector.x || current_input.z != vector.y) || current_input.length() > SMALL_NUMBER)
this->emit_signal(signal_2d, delta, vector); this->emit_signal(signal_2d, delta, vector);
current_input.x = vector.x; current_input.z = vector.y; current_input.x = vector.x; current_input.z = vector.y;
@@ -73,7 +76,10 @@ void InputResource::update_axes(const float delta)
const StringName &signal_3d = prefix + INPUTAXIS_THREE_DIMENSIONAL_SUFFIX + INPUTHANDLER_SUFFIX_SIGNAL; const StringName &signal_3d = prefix + INPUTAXIS_THREE_DIMENSIONAL_SUFFIX + INPUTHANDLER_SUFFIX_SIGNAL;
if (this->has_signal(signal_3d)) if (this->has_signal(signal_3d))
{ {
const Vector3 &vector = axis->get_spherical_vector(); Vector3 &vector = axis->get_spherical_vector();
if (UtilityFunctions::absf(vector.x) < axis_deadzone) vector.x = 0.0f;
if (UtilityFunctions::absf(vector.y) < axis_deadzone) vector.y = 0.0f;
if (UtilityFunctions::absf(vector.z) < axis_deadzone) vector.z = 0.0f;
if (current_input != vector || current_input.length() > SMALL_NUMBER) if (current_input != vector || current_input.length() > SMALL_NUMBER)
this->emit_signal(signal_3d, delta, vector); this->emit_signal(signal_3d, delta, vector);
current_input = vector; current_input = vector;