Skip to content

Commit de53d2a

Browse files
committed
fix local-replay recording
1 parent 63653bf commit de53d2a

4 files changed

Lines changed: 63 additions & 18 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="SpaceWar (replay last-local)" type="DotNetProject" factoryName=".NET Project">
3+
<option name="EXE_PATH" value="$PROJECT_DIR$/SpaceWar/bin/Debug/net8.0/SpaceWar.exe" />
4+
<option name="PROGRAM_PARAMETERS" value="9000 2 replay last_local.inputs" />
5+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/SpaceWar/bin/Debug/net8.0" />
6+
<option name="PASS_PARENT_ENVS" value="1" />
7+
<option name="ENV_FILE_PATHS" value="" />
8+
<option name="REDIRECT_INPUT_PATH" value="" />
9+
<option name="MIXED_MODE_DEBUG" value="0" />
10+
<option name="USE_MONO" value="0" />
11+
<option name="RUNTIME_ARGUMENTS" value="" />
12+
<option name="AUTO_ATTACH_CHILDREN" value="0" />
13+
<option name="PROJECT_PATH" value="$PROJECT_DIR$/SpaceWar/SpaceWar.csproj" />
14+
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
15+
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
16+
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
17+
<option name="PROJECT_KIND" value="DotNetCore" />
18+
<option name="PROJECT_TFM" value="net8.0" />
19+
<method v="2">
20+
<option name="Build" />
21+
</method>
22+
</configuration>
23+
</component>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="SpaceWar (replay player1)" type="DotNetProject" factoryName=".NET Project">
3+
<option name="EXE_PATH" value="$PROJECT_DIR$/SpaceWar/bin/Debug/net8.0/SpaceWar.exe" />
4+
<option name="PROGRAM_PARAMETERS" value="9000 2 replay player1.inputs" />
5+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/SpaceWar/bin/Debug/net8.0" />
6+
<option name="PASS_PARENT_ENVS" value="1" />
7+
<option name="ENV_FILE_PATHS" value="" />
8+
<option name="REDIRECT_INPUT_PATH" value="" />
9+
<option name="MIXED_MODE_DEBUG" value="0" />
10+
<option name="USE_MONO" value="0" />
11+
<option name="RUNTIME_ARGUMENTS" value="" />
12+
<option name="AUTO_ATTACH_CHILDREN" value="0" />
13+
<option name="PROJECT_PATH" value="$PROJECT_DIR$/SpaceWar/SpaceWar.csproj" />
14+
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
15+
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
16+
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
17+
<option name="PROJECT_KIND" value="DotNetCore" />
18+
<option name="PROJECT_TFM" value="net8.0" />
19+
<method v="2">
20+
<option name="Build" />
21+
</method>
22+
</configuration>
23+
</component>

samples/SpaceWar/Game1.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,20 @@ void SaveInputsFile()
6969
if (session.GetSavedInputs() is not { } listener) return;
7070
Console.WriteLine($"Confirmed Inputs: {listener.Count}");
7171

72-
if (!session.TryGetLocalPlayer(out var player))
73-
return;
72+
string fileName = null;
73+
if (session.IsRemote())
74+
{
75+
if (!session.TryGetLocalPlayer(out var player)) return;
76+
fileName = $"player{player.Number}";
77+
}
78+
else if (session.IsLocal())
79+
{
80+
fileName = "last_local";
81+
}
7482

83+
if (string.IsNullOrWhiteSpace(fileName)) return;
7584
var inputs = listener.GetCompressedInputs();
76-
File.WriteAllBytes($"player{player.Number}.inputs", inputs);
85+
File.WriteAllBytes($"{fileName}.inputs", inputs);
7786
}
7887

7988
protected override void LoadContent()
@@ -181,12 +190,12 @@ void HandleNonGameKeys()
181190
if (session.IsOnline())
182191
return;
183192

184-
if (keyboard.IsKeyPressed(Keys.S))
193+
if (keyboard.IsKeyPressed(Keys.C))
185194
{
186195
snapshot = session.GetStateSnapshot();
187196
session.WriteLog($"Snapshot saved {snapshot?.Frame}");
188197
}
189-
else if (keyboard.IsKeyPressed(Keys.L) && snapshot is not null)
198+
else if (keyboard.IsKeyPressed(Keys.V) && snapshot is not null)
190199
{
191200
session.LoadSnapshot(snapshot);
192201
session.WriteLog("Snapshot loaded");

src/Backdash/Session/Backends/LocalSession.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ public ResultCode SynchronizeInputs()
230230

231231
public void AdvanceFrame()
232232
{
233+
SyncListeners();
233234
CurrentFrame++;
234235
SaveCurrentFrame();
235-
SyncListeners();
236236
Array.Clear(inputBuffer);
237237
Array.Clear(syncInputBuffer);
238238
logger.Write(LogLevel.Trace, $"End of frame({CurrentFrame.Number})");
@@ -241,18 +241,8 @@ public void AdvanceFrame()
241241
void SyncListeners()
242242
{
243243
if (inputListener is null) return;
244-
var frame = CurrentFrame;
245-
GameInput<ConfirmedInputs<TInput>> confirmed = new(frame);
246-
confirmed.Data.Count = (byte)NumberOfPlayers;
247-
confirmed.Frame = frame;
248-
GameInput<TInput> current = new();
249-
250-
for (var playerNumber = 0; playerNumber < NumberOfPlayers; playerNumber++)
251-
{
252-
if (!inputQueues[playerNumber].GetConfirmedInput(in frame, ref current)) return;
253-
confirmed.Data.Inputs[playerNumber] = current.Data;
254-
inputListener.OnConfirmed(in confirmed.Frame, in confirmed.Data);
255-
}
244+
ConfirmedInputs<TInput> confirmed = new(inputBuffer);
245+
inputListener.OnConfirmed(CurrentFrame, in confirmed);
256246
}
257247

258248
void TryDropSavedInputsAfter(Frame newFrame)

0 commit comments

Comments
 (0)