Skip to content

Commit

Permalink
call state change event after death event, to prevent unwanted cleanu…
Browse files Browse the repository at this point in the history
…ps (#1035)

* call state change event after death event, to prevent unwanted cleanups

* fix arm ci

* remove a problematic fix ported from fixes.inc
  • Loading branch information
AmyrAhmady authored Jan 1, 2025
1 parent 0513223 commit 8e9a310
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ jobs:
build-arm-gnu:
name: ARM build (GNU)
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

strategy:
matrix:
Expand Down
28 changes: 0 additions & 28 deletions Server/Source/player_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,34 +785,6 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
{
PacketHelper::broadcastToStreamed(clearPlayerTasksRPC, *this, false /* skipFrom */);
}

IPlayerVehicleData* data = queryExtension<IPlayerVehicleData>(*this);
if (!data || !data->getVehicle())
{
// TODO: This must be fixed on client side
// *
// * <problem>
// * ClearAnimations doesn't do anything when the animation ends if we
// * pass 1 for the freeze parameter in ApplyAnimation.
// * </problem>
// * <solution>
// * Apply an idle animation for stop and then use ClearAnimation.
// * </solution>
// * <see>FIXES_ClearAnimations</see>
// * <author href="https://github.com/simonepri/" >simonepri</author>
// *
AnimationData animationData(4.0f, false, false, false, false, 1, "", "");

animationData.lib = "PED";
animationData.name = "IDLE_STANCE";
applyAnimationImpl(animationData, syncType);
animationData.lib = "PED";
animationData.name = "IDLE_CHAT";
applyAnimationImpl(animationData, syncType);
animationData.lib = "PED";
animationData.name = "WALK_PLAYER";
applyAnimationImpl(animationData, syncType);
}
}

void clearAnimations(PlayerAnimationSyncType syncType) override
Expand Down
15 changes: 14 additions & 1 deletion Server/Source/player_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,12 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
}

Player& player = static_cast<Player&>(peer);
player.setState(PlayerState_Wasted);

// Keep a record of current state before changing it to wasted, and do not dispatch state change event
// We're doing this so state change event listeners don't reset player data (like removing the link between player and the vehicle they're in when dead)
// Then dispatch the event manually later, after onPlayerDeath event dispatch.
PlayerState oldState = player.getState();
player.setState(PlayerState_Wasted, /* dispatchEvents = */ false);

IPlayer* killer = self.storage.get(onPlayerDeathRPC.KillerID);
uint8_t reason = onPlayerDeathRPC.Reason;
Expand Down Expand Up @@ -407,6 +412,14 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
killer,
reason);

// Dispatch state change event manually after onPlayerDeath, so reset player data after listeners already handled death event.
// Use stored state from above as old state and newly stored state in player data as new one.
self.playerChangeDispatcher.dispatch(
&PlayerChangeEventHandler::onPlayerStateChange,
peer,
peer.getState(),
oldState);

NetCode::RPC::PlayerDeath playerDeathRPC;
playerDeathRPC.PlayerID = player.poolID;
PacketHelper::broadcast(playerDeathRPC, self, &peer);
Expand Down

0 comments on commit 8e9a310

Please sign in to comment.