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

Fixed paused actor physics resuming after switching to another actor #3146

Merged
merged 3 commits into from
Jun 27, 2024
Merged
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: 3 additions & 1 deletion doc/angelscript/Script2Game/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ void print(const string message);

SE_GENERIC_MESSAGEBOX_CLICK //!< triggered when the user clicks on a message box button, the argument refers to the button pressed
SE_GENERIC_EXCEPTION_CAUGHT //!< Triggered when C++ exception (usually Ogre::Exception) is thrown; #1 ScriptUnitID, #5 originFuncName, #6 type, #7 message.
SE_GENERIC_MODCACHE_ACTIVITY //!< Triggered when status of modcache changes, args: #1 type, #2 entry number, for other args see `RoR::modCacheActivityType`
SE_GENERIC_MODCACHE_ACTIVITY //!< Triggered when status of modcache changes, args: #1 type, #2 entry number, for other args see `RoR::modCacheActivityType`

SE_GENERIC_TRUCK_LINKING_CHANGED //!< Triggered when 2 actors become linked or unlinked via ties/hooks/ropes/slidenodes; args: #1 state (1=linked, 0=unlinked), #2 action `ActorLinkingRequestType` #3 master ActorInstanceID_t, #4 slave ActorInstanceID_t

SE_ALL_EVENTS = 0xffffffff,
SE_NO_EVENTS = 0
Expand Down
24 changes: 16 additions & 8 deletions source/main/GameContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,21 +1367,20 @@ void GameContext::UpdateCommonInputEvents(float dt)
{
//m_player_actor->hookToggle(-1, HOOK_TOGGLE, -1);
ActorLinkingRequest* hook_rq = new ActorLinkingRequest();
hook_rq->alr_type = ActorLinkingRequestType::HOOK_ACTION;
hook_rq->alr_type = ActorLinkingRequestType::HOOK_TOGGLE;
hook_rq->alr_actor_instance_id = m_player_actor->ar_instance_id;
hook_rq->alr_hook_action = HOOK_TOGGLE;
App::GetGameContext()->PushMessage(Message(MSG_SIM_ACTOR_LINKING_REQUESTED, hook_rq));

//m_player_actor->toggleSlideNodeLock();
ActorLinkingRequest* slidenode_rq = new ActorLinkingRequest();
slidenode_rq->alr_type = ActorLinkingRequestType::SLIDENODE_ACTION;
hook_rq->alr_actor_instance_id = m_player_actor->ar_instance_id;
slidenode_rq->alr_type = ActorLinkingRequestType::SLIDENODE_TOGGLE;
slidenode_rq->alr_actor_instance_id = m_player_actor->ar_instance_id;
App::GetGameContext()->PushMessage(Message(MSG_SIM_ACTOR_LINKING_REQUESTED, slidenode_rq));
}

if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_AUTOLOCK))
{
m_player_actor->hookToggle(-2, HOOK_UNLOCK, -1); //unlock all autolocks
m_player_actor->hookToggle(-2, ActorLinkingRequestType::HOOK_UNLOCK, -1); //unlock all autolocks
}

//strap
Expand All @@ -1398,13 +1397,19 @@ void GameContext::UpdateCommonInputEvents(float dt)
if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_TOGGLE_DEBUG_VIEW))
{
m_player_actor->GetGfxActor()->ToggleDebugView();
// NOTE: Syncing with linked actors is done in `SyncLinkedActors()`
for (ActorPtr& actor : m_player_actor->ar_linked_actors)
{
actor->GetGfxActor()->SetDebugView(m_player_actor->GetGfxActor()->GetDebugView());
}
}

if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_CYCLE_DEBUG_VIEWS))
{
m_player_actor->GetGfxActor()->CycleDebugViews();
// NOTE: Syncing with linked actors is done in `SyncLinkedActors()`
for (ActorPtr& actor : m_player_actor->ar_linked_actors)
{
actor->GetGfxActor()->SetDebugView(m_player_actor->GetGfxActor()->GetDebugView());
}
}

if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_RESCUE_TRUCK, 0.5f) &&
Expand Down Expand Up @@ -1463,7 +1468,10 @@ void GameContext::UpdateCommonInputEvents(float dt)
// toggle physics
if (RoR::App::GetInputEngine()->getEventBoolValueBounce(EV_TRUCK_TOGGLE_PHYSICS))
{
// NOTE: Syncing with linked actors is done in `SyncLinkedActors()`
for (ActorPtr& actor : App::GetGameContext()->GetPlayerActor()->ar_linked_actors)
{
actor->ar_physics_paused = !App::GetGameContext()->GetPlayerActor()->ar_physics_paused;
}
App::GetGameContext()->GetPlayerActor()->ar_physics_paused = !App::GetGameContext()->GetPlayerActor()->ar_physics_paused;
}

Expand Down
18 changes: 16 additions & 2 deletions source/main/gameplay/RepairMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,28 @@ void RepairMode::UpdateInputEvents(float dt)

App::GetGameContext()->GetPlayerActor()->requestRotation(rotation, rotation_center);
App::GetGameContext()->GetPlayerActor()->requestTranslation(translation);
// NOTE: Syncing with linked actors is done in `SyncLinkedActors()`

if (App::sim_soft_reset_mode->getBool())
{
for (ActorPtr& actor : App::GetGameContext()->GetPlayerActor()->ar_linked_actors)
{
actor->requestRotation(rotation, rotation_center);
actor->requestTranslation(translation);
}
}

m_live_repair_timer = 0.0f;
}
else if (App::GetInputEngine()->isKeyDownValueBounce(OIS::KC_SPACE))
{
App::GetGameContext()->GetPlayerActor()->requestAngleSnap(45);
// NOTE: Syncing with linked actors is done in `SyncLinkedActors()`
if (App::sim_soft_reset_mode->getBool())
{
for (ActorPtr& actor : App::GetGameContext()->GetPlayerActor()->ar_linked_actors)
{
actor->requestAngleSnap(45);
}
}
}
else
{
Expand Down
5 changes: 2 additions & 3 deletions source/main/gameplay/SceneMouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,10 @@ bool SceneMouse::mouseMoved(const OIS::MouseEvent& _arg)
{
if (it->hk_hook_node->pos == minnode)
{
//grab_truck->hookToggle(it->hk_group, MOUSE_HOOK_TOGGLE, minnode);
//grab_truck->hookToggle(it->hk_group, HOOK_MOUSE_TOGGLE, minnode);
ActorLinkingRequest* rq = new ActorLinkingRequest();
rq->alr_type = ActorLinkingRequestType::HOOK_ACTION;
rq->alr_type = ActorLinkingRequestType::HOOK_MOUSE_TOGGLE;
rq->alr_actor_instance_id = grab_truck->ar_instance_id;
rq->alr_hook_action = MOUSE_HOOK_TOGGLE;
rq->alr_hook_group = it->hk_group;
rq->alr_hook_mousenode = minnode;
App::GetGameContext()->PushMessage(Message(MSG_SIM_ACTOR_LINKING_REQUESTED, rq));
Expand Down
2 changes: 2 additions & 0 deletions source/main/gameplay/ScriptEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ enum scriptEvents
SE_GENERIC_EXCEPTION_CAUGHT = BITMASK(24), //!< Triggered when C++ exception (usually Ogre::Exception) is thrown; #1 ScriptUnitID, #5 originFuncName, #6 type, #7 message.
SE_GENERIC_MODCACHE_ACTIVITY = BITMASK(25), //!< Triggered when status of modcache changes, args: #1 type, #2 entry number, for other args see `RoR::modCacheActivityType`

SE_GENERIC_TRUCK_LINKING_CHANGED = BITMASK(26), //!< Triggered when 2 actors become linked or unlinked via ties/hooks/ropes/slidenodes; args: #1 state (1=linked, 0=unlinked), #2 action `ActorLinkingRequestType` #3 master ActorInstanceID_t, #4 slave ActorInstanceID_t

SE_ALL_EVENTS = 0xffffffff,
SE_NO_EVENTS = 0

Expand Down
10 changes: 6 additions & 4 deletions source/main/gui/panels/GUI_VehicleButtons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,10 @@ void VehicleButtons::DrawActorPhysicsButton(RoR::GfxActor* actorx)

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

Expand Down Expand Up @@ -1180,14 +1183,13 @@ void VehicleButtons::DrawLockButton(RoR::GfxActor* actorx)
{
//actorx->GetActor()->hookToggle(-1, HOOK_TOGGLE, -1);
ActorLinkingRequest* hook_rq = new ActorLinkingRequest();
hook_rq->alr_type = ActorLinkingRequestType::HOOK_ACTION;
hook_rq->alr_type = ActorLinkingRequestType::HOOK_TOGGLE;
hook_rq->alr_actor_instance_id = actorx->GetActor()->ar_instance_id;
hook_rq->alr_hook_action = HOOK_TOGGLE;
App::GetGameContext()->PushMessage(Message(MSG_SIM_ACTOR_LINKING_REQUESTED, hook_rq));

//actorx->GetActor()->toggleSlideNodeLock();
ActorLinkingRequest* slidenode_rq = new ActorLinkingRequest();
slidenode_rq->alr_type = ActorLinkingRequestType::SLIDENODE_ACTION;
slidenode_rq->alr_type = ActorLinkingRequestType::SLIDENODE_TOGGLE;
hook_rq->alr_actor_instance_id = actorx->GetActor()->ar_instance_id;
App::GetGameContext()->PushMessage(Message(MSG_SIM_ACTOR_LINKING_REQUESTED, slidenode_rq));
}
Expand Down
22 changes: 11 additions & 11 deletions source/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,23 +1142,26 @@ int main(int argc, char *argv[])
{
switch (request->alr_type)
{
case ActorLinkingRequestType::HOOK_ACTION:
actor->hookToggle(request->alr_hook_group, request->alr_hook_action, request->alr_hook_mousenode);
if (request->alr_hook_action == MOUSE_HOOK_TOGGLE)
{
case ActorLinkingRequestType::HOOK_LOCK:
case ActorLinkingRequestType::HOOK_UNLOCK:
case ActorLinkingRequestType::HOOK_TOGGLE:
actor->hookToggle(request->alr_hook_group, request->alr_type);
break;

case ActorLinkingRequestType::HOOK_MOUSE_TOGGLE:
actor->hookToggle(request->alr_hook_group, request->alr_type, request->alr_hook_mousenode);
TRIGGER_EVENT_ASYNC(SE_TRUCK_MOUSE_GRAB, request->alr_actor_instance_id);
}
break;

case ActorLinkingRequestType::TIE_ACTION:
case ActorLinkingRequestType::TIE_TOGGLE:
actor->tieToggle(request->alr_tie_group);
break;

case ActorLinkingRequestType::ROPE_ACTION:
case ActorLinkingRequestType::ROPE_TOGGLE:
actor->ropeToggle(request->alr_rope_group);
break;

case ActorLinkingRequestType::SLIDENODE_ACTION:
case ActorLinkingRequestType::SLIDENODE_TOGGLE:
actor->toggleSlideNodeLock();
break;
}
Expand Down Expand Up @@ -1651,9 +1654,6 @@ int main(int argc, char *argv[])
App::GetSoundScriptManager()->update(dt); // update 3d audio listener position
#endif // USE_OPENAL

// Sync shared state (lights, brakes, debugviews, pause/reset) between linked actors.
App::GetGameContext()->GetActorManager()->SyncLinkedActors();

#ifdef USE_ANGELSCRIPT
App::GetScriptEngine()->framestep(dt);
#endif // USE_ANGELSCRIPT
Expand Down
Loading