Skip to content

Commit 3034362

Browse files
authored
Features/0.4.3.2 (#4)
* Fix assets
1 parent 20b81f3 commit 3034362

104 files changed

Lines changed: 2915 additions & 1227 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Directory.Build.props

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,47 @@
88
<WarningsAsErrors>true</WarningsAsErrors>
99
<NoWarn>$(NoWarn);1591</NoWarn>
1010
</PropertyGroup>
11-
<Choose>
12-
<When Condition="$(MSBuildProjectName.EndsWith('Benchmarks'))">
13-
<PropertyGroup>
14-
<OutputType>Exe</OutputType>
15-
<IsPackable>false</IsPackable>
16-
<IsPublishable>false</IsPublishable>
17-
</PropertyGroup>
1811

19-
<ItemGroup>
20-
<PackageReference Include="BenchmarkDotNet" Version="0.15.8"/>
21-
</ItemGroup>
22-
</When>
23-
<When Condition="$(MSBuildProjectName.EndsWith('Tests'))">
24-
<PropertyGroup>
25-
<IsPackable>false</IsPackable>
26-
<IsTestProject>true</IsTestProject>
27-
<IsPublishable>false</IsPublishable>
28-
</PropertyGroup>
12+
<!-- Для проектов Benchmarks -->
13+
14+
<PropertyGroup Condition="$(MSBuildProjectName.Contains('Benchmarks'))">
15+
<IsPackable>false</IsPackable>
16+
<IsPublishable>false</IsPublishable>
17+
</PropertyGroup>
18+
19+
<ItemGroup Condition="$(MSBuildProjectName.Contains('Benchmarks'))">
20+
<AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute"/>
21+
</ItemGroup>
22+
23+
<ItemGroup Condition="$(MSBuildProjectName.EndsWith('Benchmarks'))">
24+
<PackageReference Include="BenchmarkDotNet"/>
25+
</ItemGroup>
26+
27+
<!-- Для проектов Tests -->
28+
<PropertyGroup Condition="$(MSBuildProjectName.EndsWith('Tests'))">
29+
<IsPackable>false</IsPackable>
30+
<IsTestProject>true</IsTestProject>
31+
<IsPublishable>false</IsPublishable>
32+
</PropertyGroup>
2933

30-
<ItemGroup>
31-
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1"/>
32-
<PackageReference Include="FluentAssertions" Version="8.8.0"/>
33-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1"/>
34-
<PackageReference Include="Moq" Version="4.20.72"/>
35-
<PackageReference Include="xunit" Version="2.9.3"/>
36-
<PackageReference Include="JunitXml.TestLogger" Version="7.1.0"/>
37-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
38-
<PrivateAssets>all</PrivateAssets>
39-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
40-
</PackageReference>
41-
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
42-
<PrivateAssets>all</PrivateAssets>
43-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
44-
</PackageReference>
45-
<PackageReference Include="coverlet.collector" Version="6.0.4">
46-
<PrivateAssets>all</PrivateAssets>
47-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
48-
</PackageReference>
49-
</ItemGroup>
50-
</When>
51-
</Choose>
34+
<ItemGroup Condition="$(MSBuildProjectName.EndsWith('Tests'))">
35+
<PackageReference Include="AutoFixture.Xunit2"/>
36+
<PackageReference Include="FluentAssertions"/>
37+
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
38+
<PackageReference Include="Moq"/>
39+
<PackageReference Include="xunit"/>
40+
<PackageReference Include="JunitXml.TestLogger"/>
41+
<PackageReference Include="xunit.runner.visualstudio">
42+
<PrivateAssets>all</PrivateAssets>
43+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
44+
</PackageReference>
45+
<PackageReference Include="coverlet.msbuild">
46+
<PrivateAssets>all</PrivateAssets>
47+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
48+
</PackageReference>
49+
<PackageReference Include="coverlet.collector">
50+
<PrivateAssets>all</PrivateAssets>
51+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
52+
</PackageReference>
53+
</ItemGroup>
5254
</Project>

Directory.Packages.props

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
<CentralPackageVersionOverrideEnabled>true</CentralPackageVersionOverrideEnabled>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0"/>
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<PackageVersion Include="MonoGame.Framework.DesktopGL" Version="3.8.4.1"/>
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageVersion Include="DefaultEcs" Version="0.17.2"/>
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<PackageVersion Include="AutoFixture.Xunit2" Version="4.18.1"/>
21+
<PackageVersion Include="BenchmarkDotNet" Version="0.15.8"/>
22+
<PackageVersion Include="FluentAssertions" Version="8.8.0"/>
23+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1"/>
24+
<PackageVersion Include="Moq" Version="4.20.72"/>
25+
<PackageVersion Include="xunit" Version="2.9.3"/>
26+
<PackageVersion Include="JunitXml.TestLogger" Version="7.1.0"/>
27+
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5"/>
28+
<PackageVersion Include="coverlet.msbuild" Version="6.0.4"/>
29+
<PackageVersion Include="coverlet.collector" Version="6.0.4"/>
30+
</ItemGroup>
31+
</Project>

Hexecs.sln

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hexecs.Tests", "src\Hexecs.
55
EndProject
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hexecs.Benchmarks", "src\Hexecs.Benchmarks\Hexecs.Benchmarks.csproj", "{6B3B5C57-80EF-4CC7-A0CE-5533B7628FDB}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hexecs.Benchmarks.MonoGame", "src\Hexecs.Benchmarks.MonoGame\Hexecs.Benchmarks.MonoGame.csproj", "{1F5BACA8-7AC3-48B4-9F28-532F7684C80B}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hexecs.Benchmarks.Noise", "src\Hexecs.Benchmarks.Noise\Hexecs.Benchmarks.Noise.csproj", "{0CA9A4D9-359D-4F10-8A45-DC3D1A3940AB}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hexecs.Benchmarks.City", "src\Hexecs.Benchmarks.City\Hexecs.Benchmarks.City.csproj", "{B95D5C8E-90D4-4719-A6B4-81120C3BAD39}"
11+
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmarks", "Benchmarks", "{9BB142FC-044B-48F4-A183-5B2BA50E4658}"
913
EndProject
1014
Global
1115
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -25,9 +29,18 @@ Global
2529
{6B3B5C57-80EF-4CC7-A0CE-5533B7628FDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
2630
{6B3B5C57-80EF-4CC7-A0CE-5533B7628FDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
2731
{6B3B5C57-80EF-4CC7-A0CE-5533B7628FDB}.Release|Any CPU.Build.0 = Release|Any CPU
28-
{1F5BACA8-7AC3-48B4-9F28-532F7684C80B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29-
{1F5BACA8-7AC3-48B4-9F28-532F7684C80B}.Debug|Any CPU.Build.0 = Debug|Any CPU
30-
{1F5BACA8-7AC3-48B4-9F28-532F7684C80B}.Release|Any CPU.ActiveCfg = Release|Any CPU
31-
{1F5BACA8-7AC3-48B4-9F28-532F7684C80B}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{0CA9A4D9-359D-4F10-8A45-DC3D1A3940AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{0CA9A4D9-359D-4F10-8A45-DC3D1A3940AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{0CA9A4D9-359D-4F10-8A45-DC3D1A3940AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{0CA9A4D9-359D-4F10-8A45-DC3D1A3940AB}.Release|Any CPU.Build.0 = Release|Any CPU
36+
{B95D5C8E-90D4-4719-A6B4-81120C3BAD39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37+
{B95D5C8E-90D4-4719-A6B4-81120C3BAD39}.Debug|Any CPU.Build.0 = Debug|Any CPU
38+
{B95D5C8E-90D4-4719-A6B4-81120C3BAD39}.Release|Any CPU.ActiveCfg = Release|Any CPU
39+
{B95D5C8E-90D4-4719-A6B4-81120C3BAD39}.Release|Any CPU.Build.0 = Release|Any CPU
40+
EndGlobalSection
41+
GlobalSection(NestedProjects) = preSolution
42+
{6B3B5C57-80EF-4CC7-A0CE-5533B7628FDB} = {9BB142FC-044B-48F4-A183-5B2BA50E4658}
43+
{B95D5C8E-90D4-4719-A6B4-81120C3BAD39} = {9BB142FC-044B-48F4-A183-5B2BA50E4658}
44+
{0CA9A4D9-359D-4F10-8A45-DC3D1A3940AB} = {9BB142FC-044B-48F4-A183-5B2BA50E4658}
3245
EndGlobalSection
3346
EndGlobal
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System.Globalization;
2+
using System.Text;
3+
using Microsoft.Xna.Framework.Content;
4+
using Microsoft.Xna.Framework.Graphics;
5+
6+
namespace Hexecs.Benchmarks.Map;
7+
8+
internal sealed class BenchmarkCounter
9+
{
10+
private readonly Func<int> _countResolver;
11+
private readonly int[] _fpsHistory;
12+
13+
private double _frameTime;
14+
private int _fps;
15+
private int _frameCount;
16+
private double _fpsTimer;
17+
18+
private int _historyIndex;
19+
private bool _historyFull;
20+
private double _avgFps;
21+
private long _historySum;
22+
23+
private readonly SpriteFont _font;
24+
private readonly SpriteBatch _spriteBatch;
25+
26+
// Используем StringBuilder как буфер
27+
private readonly StringBuilder _stringBuilder = new(128);
28+
private readonly Vector2 _textPos = new(10, 10);
29+
private readonly Vector2 _shadowPos = new(11, 11);
30+
31+
public BenchmarkCounter(Func<int> countResolver, ContentManager contentManager, GraphicsDevice graphicsDevice)
32+
{
33+
_countResolver = countResolver;
34+
_fpsHistory = new int[60];
35+
_font = contentManager.Load<SpriteFont>("DebugFont");
36+
_spriteBatch = new SpriteBatch(graphicsDevice);
37+
}
38+
39+
public void Draw(GameTime gameTime)
40+
{
41+
_frameCount++;
42+
43+
_spriteBatch.Begin();
44+
45+
_spriteBatch.DrawString(_font, _stringBuilder, _shadowPos, Color.Black);
46+
_spriteBatch.DrawString(_font, _stringBuilder, _textPos, Color.Yellow);
47+
48+
_spriteBatch.End();
49+
}
50+
51+
public void Update(GameTime gameTime)
52+
{
53+
var elapsedSeconds = gameTime.ElapsedGameTime.TotalSeconds;
54+
_frameTime = gameTime.ElapsedGameTime.TotalMilliseconds;
55+
_fpsTimer += elapsedSeconds;
56+
57+
if (_fpsTimer >= 1.0)
58+
{
59+
_fps = _frameCount;
60+
61+
_historySum -= _fpsHistory[_historyIndex];
62+
_fpsHistory[_historyIndex] = _fps;
63+
_historySum += _fps;
64+
65+
_historyIndex = (_historyIndex + 1) % 60;
66+
if (_historyIndex == 0) _historyFull = true;
67+
68+
var historyCount = _historyFull ? 60 : _historyIndex;
69+
_avgFps = (double)_historySum / historyCount;
70+
71+
var alloc = GC.GetTotalMemory(false) / 1024.0 / 1024.0;
72+
var count = _countResolver();
73+
74+
// Очищаем буфер и записываем новые данные без создания строк
75+
var culture = CultureInfo.InvariantCulture;
76+
77+
_stringBuilder.Clear();
78+
_stringBuilder
79+
.Append($"{_fps} FPS")
80+
.Append(culture, $" | Avg:{_avgFps:F1} fps")
81+
.Append(culture, $" | Entities:{count:N0}")
82+
.Append(culture, $" | Frame time:{_frameTime:F1}ms")
83+
.Append(culture, $" | Alloc:{alloc:F3}mb");
84+
85+
_frameCount = 0;
86+
_fpsTimer = 0;
87+
}
88+
}
89+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using Hexecs.Benchmarks.Map.Common;
2+
using Hexecs.Benchmarks.Map.Common.Visibles;
3+
using Hexecs.Benchmarks.Map.Terrains;
4+
using Hexecs.Benchmarks.Map.Terrains.Commands.Generate;
5+
using Hexecs.Benchmarks.Map.Utils;
6+
using Hexecs.Worlds;
7+
using Microsoft.Xna.Framework.Graphics;
8+
using Microsoft.Xna.Framework.Input;
9+
10+
namespace Hexecs.Benchmarks.Map;
11+
12+
internal sealed class CityGame : Game
13+
{
14+
private BenchmarkCounter _benchmarkCounter = null!;
15+
private Camera _camera = null!;
16+
private readonly GraphicsDeviceManager _graphics;
17+
private World _world = null!;
18+
19+
public CityGame()
20+
{
21+
_graphics = new GraphicsDeviceManager(this)
22+
{
23+
PreferredBackBufferWidth = 1280,
24+
PreferredBackBufferHeight = 720,
25+
GraphicsProfile = GraphicsProfile.HiDef,
26+
PreferMultiSampling = true,
27+
SynchronizeWithVerticalRetrace = true,
28+
IsFullScreen = false,
29+
HardwareModeSwitch = false
30+
};
31+
32+
// Включаем поддержку сглаживания для устройства
33+
_graphics.PreparingDeviceSettings += (_, e) =>
34+
{
35+
e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 8; // 8x MSAA
36+
};
37+
38+
_graphics.ApplyChanges();
39+
40+
IsFixedTimeStep = false;
41+
Content.RootDirectory = "Content";
42+
}
43+
44+
protected override void Initialize()
45+
{
46+
GraphicsDevice.SamplerStates[0] = SamplerState.AnisotropicClamp;
47+
48+
_camera = new Camera(GraphicsDevice);
49+
_world = new WorldBuilder()
50+
.UseDefaultParallelWorker(Math.Min(6, Environment.ProcessorCount))
51+
.UseSingleton(Content)
52+
.UseSingleton(GraphicsDevice)
53+
.UseSingleton(_camera)
54+
.UseTerrain()
55+
.UseDefaultActorContext(context => context
56+
.Capacity(3_000_000)
57+
.AddCommon()
58+
.AddTerrain()
59+
.AddVisible())
60+
.Build();
61+
62+
_world.Actors.Execute(new GenerateTerrainCommand());
63+
64+
_benchmarkCounter = new BenchmarkCounter(() => _world.Actors.Length, Content, GraphicsDevice);
65+
66+
base.Initialize();
67+
}
68+
69+
protected override void Dispose(bool disposing)
70+
{
71+
if (disposing)
72+
{
73+
_world.Dispose();
74+
}
75+
76+
base.Dispose(disposing);
77+
}
78+
79+
protected override void Draw(GameTime gameTime)
80+
{
81+
GraphicsDevice.Clear(Color.White);
82+
83+
_world.Draw(gameTime.ElapsedGameTime, gameTime.TotalGameTime);
84+
_benchmarkCounter.Draw(gameTime);
85+
86+
base.Draw(gameTime);
87+
}
88+
89+
protected override void Update(GameTime gameTime)
90+
{
91+
var keyboard = Keyboard.GetState();
92+
if (keyboard.IsKeyDown(Keys.Space))
93+
{
94+
}
95+
96+
_camera.Update(gameTime);
97+
_benchmarkCounter.Update(gameTime);
98+
_world.Update(gameTime.ElapsedGameTime, gameTime.TotalGameTime);
99+
100+
base.Update(gameTime);
101+
}
102+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Hexecs.Benchmarks.Map.Common.Positions;
2+
3+
namespace Hexecs.Benchmarks.Map.Common;
4+
5+
internal static class CommonInstaller
6+
{
7+
public static ActorContextBuilder AddCommon(this ActorContextBuilder builder)
8+
{
9+
builder.AddPositions();
10+
11+
return builder;
12+
}
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Hexecs.Benchmarks.Map.Common.Positions;
2+
3+
public struct Position : IActorComponent
4+
{
5+
public Point Grid;
6+
public Point World;
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Hexecs.Benchmarks.Map.Common.Positions;
2+
3+
public readonly struct PositionAbility: IAssetComponent;

0 commit comments

Comments
 (0)