mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Add BeforeApplyState event to replay playback (#4536)
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Replays;
|
||||
using Robust.Shared.Serialization.Markdown.Mapping;
|
||||
@@ -128,6 +129,11 @@ public interface IReplayPlaybackManager
|
||||
/// </summary>
|
||||
event Action? ReplayUnpaused;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked just before a replay applies a game state.
|
||||
/// </summary>
|
||||
event Action<(GameState Current, GameState? Next)>? BeforeApplyState;
|
||||
|
||||
/// <summary>
|
||||
/// If currently replaying a client-side recording, this is the user that recorded the replay.
|
||||
/// Useful for setting default observer spawn positions.
|
||||
@@ -137,5 +143,5 @@ public interface IReplayPlaybackManager
|
||||
/// <summary>
|
||||
/// Fetches the entity that the <see cref="Recorder"/> is currently attached to.
|
||||
/// </summary>
|
||||
public bool TryGetRecorderEntity([NotNullWhen(true)] out EntityUid? uid);
|
||||
bool TryGetRecorderEntity([NotNullWhen(true)] out EntityUid? uid);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ internal sealed partial class ReplayPlaybackManager
|
||||
_gameState.ClearDetachQueue();
|
||||
EnsureDetachedExist(checkpoint);
|
||||
_gameState.DetachImmediate(checkpoint.Detached);
|
||||
BeforeApplyState?.Invoke((checkpoint.State, next));
|
||||
_gameState.ApplyGameState(checkpoint.State, next);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,9 @@ internal sealed partial class ReplayPlaybackManager
|
||||
// Clear existing lerps
|
||||
_entMan.EntitySysManager.GetEntitySystem<TransformSystem>().Reset();
|
||||
|
||||
_gameState.ApplyGameState(state, Replay.NextState);
|
||||
var next = Replay.NextState;
|
||||
BeforeApplyState?.Invoke((state, next));
|
||||
_gameState.ApplyGameState(state, next);
|
||||
ProcessMessages(Replay.CurMessages, skipEffectEvents);
|
||||
|
||||
// TODO REPLAYS block audio
|
||||
|
||||
@@ -42,7 +42,9 @@ internal sealed partial class ReplayPlaybackManager
|
||||
{
|
||||
var state = Replay.CurState;
|
||||
_gameState.UpdateFullRep(state, cloneDelta: true);
|
||||
_gameState.ApplyGameState(state, Replay.NextState);
|
||||
var next = Replay.NextState;
|
||||
BeforeApplyState?.Invoke((state, next));
|
||||
_gameState.ApplyGameState(state, next);
|
||||
DebugTools.Assert(Replay.LastApplied >= state.FromSequence);
|
||||
DebugTools.Assert(Replay.LastApplied + 1 <= state.ToSequence);
|
||||
Replay.LastApplied = state.ToSequence;
|
||||
|
||||
@@ -12,6 +12,7 @@ using Robust.Client.Upload;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Network;
|
||||
@@ -44,6 +45,7 @@ internal sealed partial class ReplayPlaybackManager : IReplayPlaybackManager
|
||||
public event Action? ReplayPlaybackStopped;
|
||||
public event Action? ReplayPaused;
|
||||
public event Action? ReplayUnpaused;
|
||||
public event Action<(GameState Current, GameState? Next)>? BeforeApplyState;
|
||||
|
||||
public ReplayData? Replay { get; private set; }
|
||||
public NetUserId? Recorder => Replay?.Recorder;
|
||||
|
||||
Reference in New Issue
Block a user