Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Physics interpolation - Fix multithreaded rendering #59875

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scene/main/scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ bool SceneTree::iteration(float p_time) {

current_frame++;

if (root->get_world().is_valid()) {
if (_physics_interpolation_enabled && root->get_world().is_valid()) {
RID scenario = root->get_world()->get_scenario();
if (scenario.is_valid()) {
VisualServer::get_singleton()->scenario_tick(scenario);
Expand Down Expand Up @@ -686,7 +686,7 @@ bool SceneTree::idle(float p_time) {

#endif

if (root->get_world().is_valid()) {
if (_physics_interpolation_enabled && root->get_world().is_valid()) {
RID scenario = root->get_world()->get_scenario();
if (scenario.is_valid()) {
VisualServer::get_singleton()->scenario_pre_draw(scenario, true);
Expand Down
8 changes: 0 additions & 8 deletions servers/visual/visual_server_raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ void VisualServerRaster::request_frame_drawn_callback(Object *p_where, const Str
frame_drawn_callbacks.push_back(fdc);
}

void VisualServerRaster::scenario_tick(RID p_scenario) {
VSG::scene->_scenario_tick(p_scenario);
}

void VisualServerRaster::scenario_pre_draw(RID p_scenario, bool p_will_draw) {
VSG::scene->_scenario_pre_draw(p_scenario, p_will_draw);
}

void VisualServerRaster::draw(bool p_swap_buffers, double frame_step) {
//needs to be done before changes is reset to 0, to not force the editor to redraw
VS::get_singleton()->emit_signal("frame_pre_draw");
Expand Down
12 changes: 9 additions & 3 deletions servers/visual/visual_server_raster.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ class VisualServerRaster : public VisualServer {

#define BIND1(m_name, m_type1) \
void m_name(m_type1 arg1) { DISPLAY_CHANGED BINDBASE->m_name(arg1); }
#define BIND1N(m_name, m_type1) \
void m_name(m_type1 arg1) { BINDBASE->m_name(arg1); }
#define BIND2(m_name, m_type1, m_type2) \
void m_name(m_type1 arg1, m_type2 arg2) { DISPLAY_CHANGED BINDBASE->m_name(arg1, arg2); }
#define BIND2C(m_name, m_type1, m_type2) \
void m_name(m_type1 arg1, m_type2 arg2) const { BINDBASE->m_name(arg1, arg2); }
#define BIND2N(m_name, m_type1, m_type2) \
void m_name(m_type1 arg1, m_type2 arg2) { BINDBASE->m_name(arg1, arg2); }
#define BIND3(m_name, m_type1, m_type2, m_type3) \
void m_name(m_type1 arg1, m_type2 arg2, m_type3 arg3) { DISPLAY_CHANGED BINDBASE->m_name(arg1, arg2, arg3); }
#define BIND4(m_name, m_type1, m_type2, m_type3, m_type4) \
Expand Down Expand Up @@ -149,7 +153,6 @@ class VisualServerRaster : public VisualServer {
#define BINDBASE VSG::storage

/* TEXTURE API */

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to keep this separation, like done for other section comments.

BIND0R(RID, texture_create)
BIND7(texture_allocate, RID, int, int, int, Image::Format, TextureType, uint32_t)
BIND3(texture_set_data, RID, const Ref<Image> &, int)
Expand Down Expand Up @@ -448,6 +451,11 @@ class VisualServerRaster : public VisualServer {
//from now on, calls forwarded to this singleton
#define BINDBASE VSG::scene

/* EVENT QUEUING */

BIND1N(scenario_tick, RID)
BIND2N(scenario_pre_draw, RID, bool)

/* CAMERA API */

BIND0R(RID, camera_create)
Expand Down Expand Up @@ -764,8 +772,6 @@ class VisualServerRaster : public VisualServer {
virtual bool has_changed(ChangedPriority p_priority = CHANGED_PRIORITY_ANY) const;
virtual void init();
virtual void finish();
virtual void scenario_tick(RID p_scenario);
virtual void scenario_pre_draw(RID p_scenario, bool p_will_draw);

/* STATUS INFORMATION */

Expand Down
4 changes: 2 additions & 2 deletions servers/visual/visual_server_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ void VisualServerScene::scenario_set_physics_interpolation_enabled(RID p_scenari
scenario->_interpolation_data.interpolation_enabled = p_enabled;
}

void VisualServerScene::_scenario_tick(RID p_scenario) {
void VisualServerScene::scenario_tick(RID p_scenario) {
Scenario *scenario = scenario_owner.get(p_scenario);
ERR_FAIL_COND(!scenario);

Expand All @@ -485,7 +485,7 @@ void VisualServerScene::_scenario_tick(RID p_scenario) {
}
}

void VisualServerScene::_scenario_pre_draw(RID p_scenario, bool p_will_draw) {
void VisualServerScene::scenario_pre_draw(RID p_scenario, bool p_will_draw) {
Scenario *scenario = scenario_owner.get(p_scenario);
ERR_FAIL_COND(!scenario);

Expand Down
4 changes: 2 additions & 2 deletions servers/visual/visual_server_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ class VisualServerScene {
virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment);
virtual void scenario_set_reflection_atlas_size(RID p_scenario, int p_size, int p_subdiv);
virtual void scenario_set_physics_interpolation_enabled(RID p_scenario, bool p_enabled);
void _scenario_tick(RID p_scenario);
void _scenario_pre_draw(RID p_scenario, bool p_will_draw);
void scenario_tick(RID p_scenario);
void scenario_pre_draw(RID p_scenario, bool p_will_draw);

/* INSTANCING API */

Expand Down
30 changes: 0 additions & 30 deletions servers/visual/visual_server_wrap_mt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ void VisualServerWrapMT::thread_exit() {
exit.set();
}

void VisualServerWrapMT::thread_scenario_tick(RID p_scenario) {
if (!draw_pending.decrement()) {
visual_server->scenario_tick(p_scenario);
}
}

void VisualServerWrapMT::thread_scenario_pre_draw(RID p_scenario, bool p_will_draw) {
if (!draw_pending.decrement()) {
visual_server->scenario_pre_draw(p_scenario, p_will_draw);
}
}

void VisualServerWrapMT::thread_draw(bool p_swap_buffers, double frame_step) {
if (!draw_pending.decrement()) {
visual_server->draw(p_swap_buffers, frame_step);
Expand Down Expand Up @@ -94,24 +82,6 @@ void VisualServerWrapMT::sync() {
}
}

void VisualServerWrapMT::scenario_tick(RID p_scenario) {
if (create_thread) {
draw_pending.increment();
command_queue.push(this, &VisualServerWrapMT::thread_scenario_tick, p_scenario);
} else {
visual_server->scenario_tick(p_scenario);
}
}

void VisualServerWrapMT::scenario_pre_draw(RID p_scenario, bool p_will_draw) {
if (create_thread) {
draw_pending.increment();
command_queue.push(this, &VisualServerWrapMT::thread_scenario_pre_draw, p_scenario, p_will_draw);
} else {
visual_server->scenario_pre_draw(p_scenario, p_will_draw);
}
}

void VisualServerWrapMT::draw(bool p_swap_buffers, double frame_step) {
if (create_thread) {
draw_pending.increment();
Expand Down
4 changes: 2 additions & 2 deletions servers/visual/visual_server_wrap_mt.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,13 +669,13 @@ class VisualServerWrapMT : public VisualServer {
/* EVENT QUEUING */

FUNC3(request_frame_drawn_callback, Object *, const StringName &, const Variant &)
FUNC1(scenario_tick, RID)
FUNC2(scenario_pre_draw, RID, bool)

virtual void init();
virtual void finish();
virtual void draw(bool p_swap_buffers, double frame_step);
virtual void sync();
virtual void scenario_tick(RID p_scenario);
virtual void scenario_pre_draw(RID p_scenario, bool p_will_draw);
FUNC1RC(bool, has_changed, ChangedPriority)

/* RENDER INFO */
Expand Down