Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
henrik committed Nov 30, 2023
1 parent ee0ea4c commit 2dd0e8d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3621,6 +3621,9 @@ bool Main::iteration() {

PhysicsServer2D::get_singleton()->end_sync();
PhysicsServer2D::get_singleton()->step(physics_step * time_scale);
if (Engine::get_singleton()->get_physics_flush_transforms()) {
PhysicsServer2D::get_singleton()->flush_transforms();
}

message_queue->flush();

Expand Down
10 changes: 10 additions & 0 deletions servers/physics_3d/godot_physics_server_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,16 @@ void GodotPhysicsServer3D::end_sync() {
doing_sync = false;
}

void GodotPhysicsServer3D::flush_transforms() {
if (!active)
return;

for (Set<const GodotSpace3D *>::Element *E = active_spaces.front(); E; E = E->next()) {
GodotSpace3D *space = (GodotSpace3D *)E->get();
space->flush_transforms();
}
};

void GodotPhysicsServer3D::finish() {
memdelete(stepper);
}
Expand Down
8 changes: 8 additions & 0 deletions servers/physics_3d/godot_space_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,14 @@ void GodotSpace3D::soft_body_remove_from_active_list(SelfList<GodotSoftBody3D> *
active_soft_body_list.remove(p_soft_body);
}

void GodotSpace3D::flush_transforms() {
while (flush_transform_list.first()) {
BodySW *b = flush_transform_list.first()->self();
flush_transform_list.remove(flush_transform_list.first());
b->flush_transforms();
}
}

void GodotSpace3D::call_queries() {
while (state_query_list.first()) {
GodotBody3D *b = state_query_list.first()->self();
Expand Down
5 changes: 5 additions & 0 deletions servers/physics_3d/godot_space_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class GodotSpace3D {
SelfList<GodotBody3D>::List active_list;
SelfList<GodotBody3D>::List mass_properties_update_list;
SelfList<GodotBody3D>::List state_query_list;
SelfList<GodotBody3D>::List flush_transform_list;
SelfList<GodotArea3D>::List monitor_query_list;
SelfList<GodotArea3D>::List area_moved_list;
SelfList<GodotSoftBody3D>::List active_soft_body_list;
Expand Down Expand Up @@ -144,6 +145,9 @@ class GodotSpace3D {
void body_add_to_state_query_list(SelfList<GodotBody3D> *p_body);
void body_remove_from_state_query_list(SelfList<GodotBody3D> *p_body);

void body_add_to_flush_transform_list(SelfList<BodySW> *p_body);
void body_remove_from_flush_transform_list(SelfList<BodySW> *p_body);

void area_add_to_monitor_query_list(SelfList<GodotArea3D> *p_area);
void area_remove_from_monitor_query_list(SelfList<GodotArea3D> *p_area);
void area_add_to_moved_list(SelfList<GodotArea3D> *p_area);
Expand Down Expand Up @@ -171,6 +175,7 @@ class GodotSpace3D {

void update();
void setup();
void flush_transforms();
void call_queries();

bool is_locked() const;
Expand Down
4 changes: 4 additions & 0 deletions servers/physics_server_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "core/object/class_db.h"
#include "core/object/ref_counted.h"

#include <functional>

class PhysicsDirectSpaceState2D;
template <typename T>
class TypedArray;
Expand Down Expand Up @@ -476,6 +478,7 @@ class PhysicsServer2D : public Object {

virtual void body_set_state_sync_callback(RID p_body, const Callable &p_callable) = 0;
virtual void body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata = Variant()) = 0;
virtual void body_set_flush_transform_callback(RID p_body, Object *p_receiver, std::function<void(PhysicsDirectBodyState3D*)> callback) = 0;

virtual bool body_collide_shape(RID p_body, int p_body_shape, RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, Vector2 *r_results, int p_result_max, int &r_result_count) = 0;

Expand Down Expand Up @@ -598,6 +601,7 @@ class PhysicsServer2D : public Object {
virtual void flush_queries() = 0;
virtual void end_sync() = 0;
virtual void finish() = 0;
virtual void flush_transforms() = 0;

virtual bool is_flushing_queries() const = 0;

Expand Down

0 comments on commit 2dd0e8d

Please sign in to comment.