Skip to content

Commit c017ad8

Browse files
committed
Reverted the SyncLinkedActors() commit which caused RigsOfRods#3105
This reverts commit 9431e1b where I tried to tidy-up duplicate syncing code but oversimplified the logic to reset unlinked actors. As result, the physics paused state and skeletonview state could only be active on player's actor and connected actor, not on any free standing one.
1 parent cfeba57 commit c017ad8

File tree

7 files changed

+128
-73
lines changed

7 files changed

+128
-73
lines changed

source/main/GameContext.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -1398,13 +1398,19 @@ void GameContext::UpdateCommonInputEvents(float dt)
13981398
if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_TOGGLE_DEBUG_VIEW))
13991399
{
14001400
m_player_actor->GetGfxActor()->ToggleDebugView();
1401-
// NOTE: Syncing with linked actors is done in `SyncLinkedActors()`
1401+
for (ActorPtr& actor : m_player_actor->ar_linked_actors)
1402+
{
1403+
actor->GetGfxActor()->SetDebugView(m_player_actor->GetGfxActor()->GetDebugView());
1404+
}
14021405
}
14031406

14041407
if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_CYCLE_DEBUG_VIEWS))
14051408
{
14061409
m_player_actor->GetGfxActor()->CycleDebugViews();
1407-
// NOTE: Syncing with linked actors is done in `SyncLinkedActors()`
1410+
for (ActorPtr& actor : m_player_actor->ar_linked_actors)
1411+
{
1412+
actor->GetGfxActor()->SetDebugView(m_player_actor->GetGfxActor()->GetDebugView());
1413+
}
14081414
}
14091415

14101416
if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_RESCUE_TRUCK, 0.5f) &&
@@ -1463,7 +1469,10 @@ void GameContext::UpdateCommonInputEvents(float dt)
14631469
// toggle physics
14641470
if (RoR::App::GetInputEngine()->getEventBoolValueBounce(EV_TRUCK_TOGGLE_PHYSICS))
14651471
{
1466-
// NOTE: Syncing with linked actors is done in `SyncLinkedActors()`
1472+
for (ActorPtr& actor : App::GetGameContext()->GetPlayerActor()->ar_linked_actors)
1473+
{
1474+
actor->ar_physics_paused = !App::GetGameContext()->GetPlayerActor()->ar_physics_paused;
1475+
}
14671476
App::GetGameContext()->GetPlayerActor()->ar_physics_paused = !App::GetGameContext()->GetPlayerActor()->ar_physics_paused;
14681477
}
14691478

source/main/gameplay/RepairMode.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,28 @@ void RepairMode::UpdateInputEvents(float dt)
124124

125125
App::GetGameContext()->GetPlayerActor()->requestRotation(rotation, rotation_center);
126126
App::GetGameContext()->GetPlayerActor()->requestTranslation(translation);
127-
// NOTE: Syncing with linked actors is done in `SyncLinkedActors()`
127+
128+
if (App::sim_soft_reset_mode->getBool())
129+
{
130+
for (ActorPtr& actor : App::GetGameContext()->GetPlayerActor()->ar_linked_actors)
131+
{
132+
actor->requestRotation(rotation, rotation_center);
133+
actor->requestTranslation(translation);
134+
}
135+
}
128136

129137
m_live_repair_timer = 0.0f;
130138
}
131139
else if (App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE))
132140
{
133141
App::GetGameContext()->GetPlayerActor()->requestAngleSnap(45);
134-
// NOTE: Syncing with linked actors is done in `SyncLinkedActors()`
142+
if (App::sim_soft_reset_mode->getBool())
143+
{
144+
for (ActorPtr& actor : App::GetGameContext()->GetPlayerActor()->ar_linked_actors)
145+
{
146+
actor->requestAngleSnap(45);
147+
}
148+
}
135149
}
136150
else
137151
{

source/main/gui/panels/GUI_VehicleButtons.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,10 @@ void VehicleButtons::DrawActorPhysicsButton(RoR::GfxActor* actorx)
627627

628628
if (ImGui::ImageButton(reinterpret_cast<ImTextureID>(m_actor_physics_icon->getHandle()), ImVec2(24, 24)))
629629
{
630-
// NOTE: Syncing with linked actors is done in `SyncLinkedActors()`
630+
for (ActorPtr& actor : actorx->GetActor()->ar_linked_actors)
631+
{
632+
actor->ar_physics_paused = !actorx->GetActor()->ar_physics_paused;
633+
}
631634
actorx->GetActor()->ar_physics_paused = !actorx->GetActor()->ar_physics_paused;
632635
}
633636

source/main/main.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -1651,9 +1651,6 @@ int main(int argc, char *argv[])
16511651
App::GetSoundScriptManager()->update(dt); // update 3d audio listener position
16521652
#endif // USE_OPENAL
16531653

1654-
// Sync shared state (lights, brakes, debugviews, pause/reset) between linked actors.
1655-
App::GetGameContext()->GetActorManager()->SyncLinkedActors();
1656-
16571654
#ifdef USE_ANGELSCRIPT
16581655
App::GetScriptEngine()->framestep(dt);
16591656
#endif // USE_ANGELSCRIPT

source/main/physics/Actor.cpp

+96-5
Original file line numberDiff line numberDiff line change
@@ -3436,7 +3436,27 @@ void Actor::tieToggle(int group)
34363436
if (it->ti_locked_actor != this)
34373437
{
34383438
this->RemoveInterActorBeam(it->ti_beam);
3439-
// NOTE: updating skeletonview on the tied actors is now done in `SyncLinkedActors()`
3439+
// update skeletonview on the untied actors
3440+
auto linked_actors = it->ti_locked_actor->ar_linked_actors;
3441+
if (!(std::find(linked_actors.begin(), linked_actors.end(), this) != linked_actors.end()))
3442+
{
3443+
if (this == player_actor.GetRef())
3444+
{
3445+
it->ti_locked_actor->GetGfxActor()->SetDebugView(DebugViewType::DEBUGVIEW_NONE);
3446+
for (ActorPtr& actor : it->ti_locked_actor->ar_linked_actors)
3447+
{
3448+
actor->GetGfxActor()->SetDebugView(DebugViewType::DEBUGVIEW_NONE);
3449+
}
3450+
}
3451+
else if (it->ti_locked_actor == player_actor)
3452+
{
3453+
m_gfx_actor->SetDebugView(DebugViewType::DEBUGVIEW_NONE);
3454+
for (ActorPtr& actor : this->ar_linked_actors)
3455+
{
3456+
actor->GetGfxActor()->SetDebugView(DebugViewType::DEBUGVIEW_NONE);
3457+
}
3458+
}
3459+
}
34403460
}
34413461
it->ti_locked_actor = nullptr;
34423462
}
@@ -3507,7 +3527,23 @@ void Actor::tieToggle(int group)
35073527
if (it->ti_beam->bm_inter_actor)
35083528
{
35093529
AddInterActorBeam(it->ti_beam, this, nearest_actor);
3510-
// NOTE: updating skeletonview on the tied actors is now done in `SyncLinkedActors()`
3530+
// update skeletonview on the tied actors
3531+
if (this == player_actor.GetRef())
3532+
{
3533+
nearest_actor->GetGfxActor()->SetDebugView(m_gfx_actor->GetDebugView());
3534+
for (ActorPtr& actor : nearest_actor->ar_linked_actors)
3535+
{
3536+
actor->GetGfxActor()->SetDebugView(m_gfx_actor->GetDebugView());
3537+
}
3538+
}
3539+
else if (nearest_actor == player_actor)
3540+
{
3541+
m_gfx_actor->SetDebugView(player_actor->GetGfxActor()->GetDebugView());
3542+
for (ActorPtr& actor : this->ar_linked_actors)
3543+
{
3544+
actor->GetGfxActor()->SetDebugView(player_actor->GetGfxActor()->GetDebugView());
3545+
}
3546+
}
35113547
}
35123548
}
35133549
}
@@ -3539,7 +3575,27 @@ void Actor::ropeToggle(int group)
35393575
if (it->rp_locked_actor != this)
35403576
{
35413577
this->RemoveInterActorBeam(it->rp_beam);
3542-
// NOTE: updating skeletonview on the unroped actors is now done in `SyncLinkedActors()`
3578+
// update skeletonview on the unroped actors
3579+
auto linked_actors = it->rp_locked_actor->ar_linked_actors;
3580+
if (!(std::find(linked_actors.begin(), linked_actors.end(), this) != linked_actors.end()))
3581+
{
3582+
if (this == player_actor.GetRef())
3583+
{
3584+
it->rp_locked_actor->GetGfxActor()->SetDebugView(DebugViewType::DEBUGVIEW_NONE);
3585+
for (ActorPtr& actor : it->rp_locked_actor->ar_linked_actors)
3586+
{
3587+
actor->GetGfxActor()->SetDebugView(DebugViewType::DEBUGVIEW_NONE);
3588+
}
3589+
}
3590+
else if (it->rp_locked_actor == player_actor)
3591+
{
3592+
m_gfx_actor->SetDebugView(DebugViewType::DEBUGVIEW_NONE);
3593+
for (ActorPtr& actor : this->ar_linked_actors)
3594+
{
3595+
actor->GetGfxActor()->SetDebugView(DebugViewType::DEBUGVIEW_NONE);
3596+
}
3597+
}
3598+
}
35433599
}
35443600
it->rp_locked_actor = nullptr;
35453601
it->rp_locked_ropable = nullptr;
@@ -3584,7 +3640,23 @@ void Actor::ropeToggle(int group)
35843640
if (nearest_actor != this)
35853641
{
35863642
AddInterActorBeam(it->rp_beam, this, nearest_actor);
3587-
// NOTE: updating skeletonview on the roped up actor is now done in `SyncLinkedActors()`
3643+
// update skeletonview on the roped up actors
3644+
if (this == player_actor.GetRef())
3645+
{
3646+
nearest_actor->GetGfxActor()->SetDebugView(m_gfx_actor->GetDebugView());
3647+
for (ActorPtr& actor : nearest_actor->ar_linked_actors)
3648+
{
3649+
actor->GetGfxActor()->SetDebugView(m_gfx_actor->GetDebugView());
3650+
}
3651+
}
3652+
else if (nearest_actor == player_actor)
3653+
{
3654+
m_gfx_actor->SetDebugView(player_actor->GetGfxActor()->GetDebugView());
3655+
for (ActorPtr& actor : this->ar_linked_actors)
3656+
{
3657+
actor->GetGfxActor()->SetDebugView(player_actor->GetGfxActor()->GetDebugView());
3658+
}
3659+
}
35883660
}
35893661
}
35903662
}
@@ -3716,7 +3788,26 @@ void Actor::hookToggle(int group, HookAction mode, NodeNum_t mousenode /*=NODENU
37163788
it->hk_beam->bm_disabled = true;
37173789
}
37183790

3719-
// NOTE: updating skeletonview on the (un)hooked actor is now done in `SyncLinkedActors()`
3791+
// update skeletonview on the (un)hooked actor
3792+
if (it->hk_locked_actor != prev_locked_actor)
3793+
{
3794+
if (it->hk_locked_actor)
3795+
{
3796+
it->hk_locked_actor->GetGfxActor()->SetDebugView(m_gfx_actor->GetDebugView());
3797+
for (ActorPtr& actor : it->hk_locked_actor->ar_linked_actors)
3798+
{
3799+
actor->GetGfxActor()->SetDebugView(m_gfx_actor->GetDebugView());
3800+
}
3801+
}
3802+
else if (prev_locked_actor != this)
3803+
{
3804+
prev_locked_actor->GetGfxActor()->SetDebugView(m_gfx_actor->GetDebugView());
3805+
for (ActorPtr& actor : prev_locked_actor->ar_linked_actors)
3806+
{
3807+
actor->GetGfxActor()->SetDebugView(m_gfx_actor->GetDebugView());
3808+
}
3809+
}
3810+
}
37203811
}
37213812
}
37223813

source/main/physics/ActorManager.cpp

-55
Original file line numberDiff line numberDiff line change
@@ -721,61 +721,6 @@ void ActorManager::ForwardCommands(ActorPtr source_actor)
721721
}
722722
}
723723

724-
// Internal helper for future extensions
725-
void SyncSlaveActorWithMasterActor(const ActorPtr& slave, const ActorPtr& master)
726-
{
727-
// Always sync the paused state
728-
slave->ar_physics_paused = master->ar_physics_paused;
729-
730-
// Always sync skeletonview
731-
slave->GetGfxActor()->SetDebugView(master->GetGfxActor()->GetDebugView());
732-
733-
// Sync live repair movement if requested
734-
if (App::sim_soft_reset_mode->getBool())
735-
{
736-
slave->requestRotation(master->m_rotation_request, master->m_rotation_request_center);
737-
slave->requestTranslation(master->m_translation_request);
738-
slave->requestAngleSnap(master->m_anglesnap_request);
739-
}
740-
}
741-
742-
// internal helper for future extensions
743-
void ResetUnlinkedActor(const ActorPtr& loner)
744-
{
745-
// Always unpause
746-
loner->ar_physics_paused = false;
747-
748-
// Always disable skeletonview
749-
loner->GetGfxActor()->SetDebugView(DebugViewType::DEBUGVIEW_NONE);
750-
}
751-
752-
void ActorManager::SyncLinkedActors()
753-
{
754-
// Sync shared state (debugviews, pause, repair) between linked actors
755-
// Reset state of non-linked actors
756-
// -------------------------------------------------------------------
757-
758-
// For now, we only sync state of player-driven actor with all it's linked actors
759-
// TBD: Maintain a graph of master->slave relations so AI vehicles sync too.
760-
if (App::GetGameContext()->GetPlayerActor())
761-
{
762-
for (const ActorPtr& actor : App::GetGameContext()->GetPlayerActor()->ar_linked_actors)
763-
{
764-
SyncSlaveActorWithMasterActor(actor, App::GetGameContext()->GetPlayerActor());
765-
}
766-
}
767-
768-
// Reset unlinked actors, except the player actor
769-
for (const ActorPtr& actor: m_actors)
770-
{
771-
if (actor->ar_linked_actors.size() == 0
772-
&& actor != App::GetGameContext()->GetPlayerActor())
773-
{
774-
ResetUnlinkedActor(actor);
775-
}
776-
}
777-
}
778-
779724
void ActorManager::UpdateSleepingState(ActorPtr player_actor, float dt)
780725
{
781726
if (!m_forced_awake)

source/main/physics/ActorManager.h

-4
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,8 @@ class ActorManager
109109

110110
std::pair<ActorPtr, float> GetNearestActor(Ogre::Vector3 position);
111111

112-
/// @name Actor grouping
113-
/// @{
114112
// A list of all beams interconnecting two actors
115113
std::map<beam_t*, std::pair<ActorPtr, ActorPtr>> inter_actor_links;
116-
void SyncLinkedActors();
117-
/// @}
118114

119115
static const ActorPtr ACTORPTR_NULL; // Dummy value to be returned as const reference.
120116

0 commit comments

Comments
 (0)