Skip to content

Commit ccc959e

Browse files
committed
expose random extensions
1 parent 2968474 commit ccc959e

File tree

20 files changed

+130
-112
lines changed

20 files changed

+130
-112
lines changed

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.18.*">
61+
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.19.*">
6262
<PrivateAssets>all</PrivateAssets>
6363
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6464
</PackageReference>

benchmarks/Backdash.Benchmarks/Cases/CompareSerializationBenchmark.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,21 @@ public static TestData Generate(Random random)
127127
TestData testData = new()
128128
{
129129
Field1 = random.NextBool(),
130-
Field2 = random.Next<ulong>(),
130+
Field2 = random.Generate<ulong>(),
131131
};
132132

133133
for (int i = 0; i < testData.Field3.Length; i++)
134134
{
135135
ref var entry = ref testData.Field3[i];
136136
entry.Field1 = random.Next();
137-
entry.Field2 = random.Next<uint>();
138-
entry.Field3 = random.Next<ulong>();
139-
entry.Field4 = random.Next<long>();
140-
entry.Field5 = random.Next<short>();
141-
entry.Field6 = random.Next<ushort>();
142-
entry.Field7 = random.Next<byte>();
143-
entry.Field8 = random.Next<sbyte>();
144-
random.Next(entry.Field9.AsSpan());
137+
entry.Field2 = random.Generate<uint>();
138+
entry.Field3 = random.Generate<ulong>();
139+
entry.Field4 = random.Generate<long>();
140+
entry.Field5 = random.Generate<short>();
141+
entry.Field6 = random.Generate<ushort>();
142+
entry.Field7 = random.Generate<byte>();
143+
entry.Field8 = random.Generate<sbyte>();
144+
random.Generate(entry.Field9.AsSpan());
145145
}
146146

147147
return testData;

benchmarks/Backdash.Benchmarks/Cases/SerializationBenchmark.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public TestData(Random random, int itemsSize, bool useIn, bool useRef, bool with
8383
this(itemsSize, useIn, useRef)
8484
{
8585
Field1 = random.NextBool();
86-
Field2 = random.Next<ulong>();
86+
Field2 = random.Generate<ulong>();
8787

8888
for (int i = 0; i < Field3.Length; i++)
8989
Field3[i] = new(random, useIn, useRef, withValues);
@@ -159,14 +159,14 @@ public struct TestEntryData(bool useIn, bool useRef, bool withValues)
159159
public TestEntryData(Random random, bool useIn, bool useRef, bool withValues) : this(useIn, useRef, withValues)
160160
{
161161
Field1 = random.Next();
162-
Field2 = random.Next<uint>();
163-
Field3 = random.Next<ulong>();
164-
Field4 = random.Next<long>();
165-
Field5 = random.Next<short>();
166-
Field6 = random.Next<ushort>();
167-
Field7 = random.Next<byte>();
168-
Field8 = random.Next<sbyte>();
169-
Field9 = random.Next<Int128>();
162+
Field2 = random.Generate<uint>();
163+
Field3 = random.Generate<ulong>();
164+
Field4 = random.Generate<long>();
165+
Field5 = random.Generate<short>();
166+
Field6 = random.Generate<ushort>();
167+
Field7 = random.Generate<byte>();
168+
Field8 = random.Generate<sbyte>();
169+
Field9 = random.Generate<Int128>();
170170
Field10 = withValues ? new(random) : new();
171171
}
172172

@@ -257,6 +257,6 @@ public static bool Equals(in TestEntryData left, in TestEntryData right) =>
257257
public struct TestDataValues
258258
{
259259
int element0;
260-
public TestDataValues(Random random) => random.Next((Span<int>)this);
260+
public TestDataValues(Random random) => random.Generate((Span<int>)this);
261261
}
262262
}

benchmarks/Backdash.Benchmarks/Cases/StructWriteBenchmark.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ namespace Backdash.Benchmarks.Cases;
1111
[InProcess, MemoryDiagnoser]
1212
public class StructWriteSingleBenchmark
1313
{
14-
static readonly int tSize = Unsafe.SizeOf<StructData>();
15-
readonly byte[] arrayBuffer = new byte[tSize];
14+
static readonly int typeSize = Unsafe.SizeOf<StructData>();
15+
readonly byte[] arrayBuffer = new byte[typeSize];
1616

1717
StructData data;
1818

1919
[GlobalSetup]
2020
public void Setup()
2121
{
2222
Random random = new(42);
23-
data = random.Next<StructData>();
23+
data = random.Generate<StructData>();
2424
}
2525

2626
[IterationSetup]
@@ -67,7 +67,7 @@ public class StructWriteSpanBenchmark
6767
public void Setup()
6868
{
6969
Random random = new(42);
70-
dataArray = random.Next<StructData>(N);
70+
dataArray = random.Generate<StructData>(N);
7171
resultArray = new StructData[N];
7272
}
7373

benchmarks/Backdash.Benchmarks/Extensions.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

samples/Backdash.Samples.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_files", "_files", "{0F1370
3737
..\GitVersion.yml = ..\GitVersion.yml
3838
..\global.json = ..\global.json
3939
..\.config\dotnet-tools.json = ..\.config\dotnet-tools.json
40+
..\Directory.Build.props = ..\Directory.Build.props
4041
EndProjectSection
4142
EndProject
4243
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{79955002-3B66-49BE-82D3-6EA518A87F5E}"

samples/LobbyServer

samples/SpaceWar.Lobby/Game1.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ protected override void Initialize()
3333
protected override void LoadContent()
3434
{
3535
SpriteBatch = new(GraphicsDevice);
36+
SceneManager = new(this, startScene: new ChooseLobbyScene());
3637

37-
Services.AddService(new GameAssets(Content, GraphicsDevice));
38-
Services.AddService(settings);
3938
Services.AddService(SpriteBatch);
40-
Services.AddService(new LobbyHttpClient(settings));
41-
42-
SceneManager = new(this, startScene: new ChooseLobbyScene());
4339
Services.AddService(SceneManager);
40+
Services.AddService(settings);
41+
Services.AddService(new GameAssets(Content, GraphicsDevice));
42+
Services.AddService(new LobbyHttpClient(settings));
4443
}
4544

4645
protected override void Update(GameTime gameTime)

samples/SpaceWar.Lobby/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Ensure the server submodule is updated in the [server directory](https://github.
3939

4040
```bash
4141
git submodule update --init --recursive
42+
git submodule update --recursive --remote
4243
```
4344

4445
> [!TIP]

samples/SpaceWar.Shared/SpaceWar.Shared.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
<Nullable>enable</Nullable>
88
<PublishReadyToRun>false</PublishReadyToRun>
99
<TieredCompilation>false</TieredCompilation>
10+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1011
</PropertyGroup>
1112
<ItemGroup>
12-
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.4.1" />
13-
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.4.1" />
13+
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.4.1"/>
14+
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.4.1"/>
1415
</ItemGroup>
1516
<ItemGroup>
1617
<ProjectReference Include="..\..\src\Backdash\Backdash.csproj"/>

0 commit comments

Comments
 (0)