Skip to content

Commit 0dff2eb

Browse files
committed
Merge branch 'master' of github.com:lucasteles/Backdash
2 parents b5e18af + 12be26d commit 0dff2eb

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"rollForward": false
1818
},
1919
"docfx": {
20-
"version": "2.78.4",
20+
"version": "2.78.5",
2121
"commands": [
2222
"docfx"
2323
],

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<PrivateAssets>all</PrivateAssets>
5959
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
6060
</PackageReference>
61-
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.19.*">
61+
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.22.*">
6262
<PrivateAssets>all</PrivateAssets>
6363
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6464
</PackageReference>

src/Backdash/Data/ByteSize.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan
241241
return writer.Write(value, format);
242242
}
243243

244+
/// <summary>Cast <see cref="ByteSize"/> to <see cref="long"/> byte-count value.</summary>
245+
public static explicit operator long(ByteSize size) => size.ByteCount;
246+
247+
/// <summary>Cast <see cref="ByteSize"/> to <see cref="int"/> byte-count value.</summary>
248+
public static explicit operator int(ByteSize size) => (int)size.ByteCount;
249+
244250
/// <inheritdoc />
245251
public static bool operator >(ByteSize left, ByteSize right) => left.ByteCount > right.ByteCount;
246252

src/Backdash/Session/NetcodeSessionExtensions.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,42 @@ public static class NetcodeSessionExtensions
1111
/// <summary>
1212
/// Returns the current state string representation
1313
/// </summary>
14+
public static string GetStateString<T>(this INetcodeSession<T> @this, IStateStringParser? parser = null)
15+
where T : unmanaged
16+
{
17+
var state = @this.GetCurrentSavedFrame();
18+
var currentBytes = state.GameState.WrittenSpan;
19+
return @this.GetStateString(state.Frame, currentBytes, parser);
20+
}
21+
22+
/// <summary>
23+
/// Returns string representation for given <paramref name="state"/>
24+
/// </summary>
1425
public static string GetStateString<T>(
1526
this INetcodeSession<T> @this,
27+
StateSnapshot state,
1628
IStateStringParser? parser = null
17-
) where T : unmanaged =>
18-
@this.GetStateString(@this.GetCurrentSavedFrame(), parser);
29+
) where T : unmanaged
30+
{
31+
var stateBytes = state.State.AsSpan(0, (int)state.Size);
32+
return @this.GetStateString(state.Frame, stateBytes, parser);
33+
}
1934

2035
/// <summary>
21-
/// Returns string representation for given <paramref name="state"/>
36+
/// Returns string representation for given <paramref name="frame"/> and <paramref name="stateBytes"/>
2237
/// </summary>
23-
public static string GetStateString<T>(
38+
static string GetStateString<T>(
2439
this INetcodeSession<T> @this,
25-
SavedFrame state,
40+
Frame frame,
41+
ReadOnlySpan<byte> stateBytes,
2642
IStateStringParser? parser = null
2743
) where T : unmanaged
2844
{
2945
parser ??= JsonStateStringParser.Singleton;
30-
var currentOffset = 0;
31-
var currentBytes = state.GameState.WrittenSpan;
32-
BinaryBufferReader currentReader = new(currentBytes, ref currentOffset, @this.StateSerializationEndianness);
33-
var currentObject = @this.GetHandler().CreateState(state.Frame, ref currentReader);
34-
return parser.GetStateString(state.Frame, in currentReader, currentObject);
46+
var offset = 0;
47+
BinaryBufferReader reader = new(stateBytes, ref offset, @this.StateSerializationEndianness);
48+
var stateObject = @this.GetHandler().CreateState(frame, ref reader);
49+
return parser.GetStateString(frame, in reader, stateObject);
3550
}
3651

3752
/// <summary>

tests/Backdash.Tests/Backdash.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
<PackageReference Include="FakeItEasy.AutoFakeIt" Version="2.0.0"/>
1515
<PackageReference Include="FluentAssertions" Version="[7.2.0]"/>
1616
<PackageReference Include="FsCheck.Xunit" Version="3.3.2" />
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
1818
<PackageReference Include="ObjectLayoutInspector" Version="0.1.4" />
1919
<PackageReference Include="xunit" Version="2.9.3" />
2020
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
<PrivateAssets>all</PrivateAssets>
2323
</PackageReference>
24-
<PackageReference Include="coverlet.collector" Version="8.0.0">
24+
<PackageReference Include="coverlet.collector" Version="8.0.1">
2525
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2626
<PrivateAssets>all</PrivateAssets>
2727
</PackageReference>

0 commit comments

Comments
 (0)