-
Notifications
You must be signed in to change notification settings - Fork 0
Features/0.4.3.2 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
922e1db
Fix assets
teoadal f8967e0
Fix assets
teoadal 70ae30d
Fix assets
teoadal 80216b9
Fix assets
teoadal 95d66b3
0.4.3 map bench
teoadal 3e55cd4
0.4.3 map bench
teoadal d99ead0
0.4.3 map bench
teoadal 07607e6
0.4.3 map bench
teoadal c66738f
0.4.3 map bench
teoadal da3ee53
Merge remote-tracking branch 'origin/features/0.4.3.2' into features/…
teoadal 9305584
0.4.3 map bench
teoadal 65e32d4
0.4.3 map bench
teoadal 30a1a50
0.4.3 map bench
teoadal 4d779df
0.4.3 map bench
teoadal 97864b0
0.4.3 map bench
teoadal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
| <CentralPackageVersionOverrideEnabled>true</CentralPackageVersionOverrideEnabled> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageVersion Include="MonoGame.Framework.DesktopGL" Version="3.8.4.1"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageVersion Include="DefaultEcs" Version="0.17.2"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageVersion Include="AutoFixture.Xunit2" Version="4.18.1"/> | ||
| <PackageVersion Include="BenchmarkDotNet" Version="0.15.8"/> | ||
| <PackageVersion Include="FluentAssertions" Version="8.8.0"/> | ||
| <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1"/> | ||
| <PackageVersion Include="Moq" Version="4.20.72"/> | ||
| <PackageVersion Include="xunit" Version="2.9.3"/> | ||
| <PackageVersion Include="JunitXml.TestLogger" Version="7.1.0"/> | ||
| <PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5"/> | ||
| <PackageVersion Include="coverlet.msbuild" Version="6.0.4"/> | ||
| <PackageVersion Include="coverlet.collector" Version="6.0.4"/> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| using System.Globalization; | ||
| using System.Text; | ||
| using Microsoft.Xna.Framework.Content; | ||
| using Microsoft.Xna.Framework.Graphics; | ||
|
|
||
| namespace Hexecs.Benchmarks.Map; | ||
|
|
||
| internal sealed class BenchmarkCounter | ||
| { | ||
| private readonly Func<int> _countResolver; | ||
| private readonly int[] _fpsHistory; | ||
|
|
||
| private double _frameTime; | ||
| private int _fps; | ||
| private int _frameCount; | ||
| private double _fpsTimer; | ||
|
|
||
| private int _historyIndex; | ||
| private bool _historyFull; | ||
| private double _avgFps; | ||
| private long _historySum; | ||
|
|
||
| private readonly SpriteFont _font; | ||
| private readonly SpriteBatch _spriteBatch; | ||
|
|
||
| // Используем StringBuilder как буфер | ||
| private readonly StringBuilder _stringBuilder = new(128); | ||
| private readonly Vector2 _textPos = new(10, 10); | ||
| private readonly Vector2 _shadowPos = new(11, 11); | ||
|
|
||
| public BenchmarkCounter(Func<int> countResolver, ContentManager contentManager, GraphicsDevice graphicsDevice) | ||
| { | ||
| _countResolver = countResolver; | ||
| _fpsHistory = new int[60]; | ||
| _font = contentManager.Load<SpriteFont>("DebugFont"); | ||
| _spriteBatch = new SpriteBatch(graphicsDevice); | ||
| } | ||
|
|
||
| public void Draw(GameTime gameTime) | ||
| { | ||
| _frameCount++; | ||
|
|
||
| _spriteBatch.Begin(); | ||
|
|
||
| _spriteBatch.DrawString(_font, _stringBuilder, _shadowPos, Color.Black); | ||
| _spriteBatch.DrawString(_font, _stringBuilder, _textPos, Color.Yellow); | ||
|
|
||
| _spriteBatch.End(); | ||
| } | ||
|
|
||
| public void Update(GameTime gameTime) | ||
| { | ||
| var elapsedSeconds = gameTime.ElapsedGameTime.TotalSeconds; | ||
| _frameTime = gameTime.ElapsedGameTime.TotalMilliseconds; | ||
| _fpsTimer += elapsedSeconds; | ||
|
|
||
| if (_fpsTimer >= 1.0) | ||
| { | ||
| _fps = _frameCount; | ||
|
|
||
| _historySum -= _fpsHistory[_historyIndex]; | ||
| _fpsHistory[_historyIndex] = _fps; | ||
| _historySum += _fps; | ||
|
|
||
| _historyIndex = (_historyIndex + 1) % 60; | ||
| if (_historyIndex == 0) _historyFull = true; | ||
|
|
||
| var historyCount = _historyFull ? 60 : _historyIndex; | ||
| _avgFps = (double)_historySum / historyCount; | ||
|
|
||
| var alloc = GC.GetTotalMemory(false) / 1024.0 / 1024.0; | ||
| var count = _countResolver(); | ||
|
|
||
| // Очищаем буфер и записываем новые данные без создания строк | ||
| var culture = CultureInfo.InvariantCulture; | ||
|
|
||
| _stringBuilder.Clear(); | ||
| _stringBuilder | ||
| .Append($"{_fps} FPS") | ||
| .Append(culture, $" | Avg:{_avgFps:F1} fps") | ||
| .Append(culture, $" | Entities:{count:N0}") | ||
| .Append(culture, $" | Frame time:{_frameTime:F1}ms") | ||
| .Append(culture, $" | Alloc:{alloc:F3}mb"); | ||
|
|
||
| _frameCount = 0; | ||
| _fpsTimer = 0; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| using Hexecs.Benchmarks.Map.Common; | ||
| using Hexecs.Benchmarks.Map.Common.Visibles; | ||
| using Hexecs.Benchmarks.Map.Terrains; | ||
| using Hexecs.Benchmarks.Map.Terrains.Commands.Generate; | ||
| using Hexecs.Benchmarks.Map.Utils; | ||
| using Hexecs.Worlds; | ||
| using Microsoft.Xna.Framework.Graphics; | ||
| using Microsoft.Xna.Framework.Input; | ||
|
|
||
| namespace Hexecs.Benchmarks.Map; | ||
|
|
||
| internal sealed class CityGame : Game | ||
| { | ||
| private BenchmarkCounter _benchmarkCounter = null!; | ||
| private Camera _camera = null!; | ||
| private readonly GraphicsDeviceManager _graphics; | ||
| private World _world = null!; | ||
|
|
||
| public CityGame() | ||
| { | ||
| _graphics = new GraphicsDeviceManager(this) | ||
| { | ||
| PreferredBackBufferWidth = 1280, | ||
| PreferredBackBufferHeight = 720, | ||
| GraphicsProfile = GraphicsProfile.HiDef, | ||
| PreferMultiSampling = true, | ||
| SynchronizeWithVerticalRetrace = true, | ||
| IsFullScreen = false, | ||
| HardwareModeSwitch = false | ||
| }; | ||
|
|
||
| // Включаем поддержку сглаживания для устройства | ||
| _graphics.PreparingDeviceSettings += (_, e) => | ||
| { | ||
| e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 8; // 8x MSAA | ||
| }; | ||
|
|
||
| _graphics.ApplyChanges(); | ||
|
|
||
| IsFixedTimeStep = false; | ||
| Content.RootDirectory = "Content"; | ||
| } | ||
|
|
||
| protected override void Initialize() | ||
| { | ||
| GraphicsDevice.SamplerStates[0] = SamplerState.AnisotropicClamp; | ||
|
|
||
| _camera = new Camera(GraphicsDevice); | ||
| _world = new WorldBuilder() | ||
| .UseDefaultParallelWorker(Math.Min(6, Environment.ProcessorCount)) | ||
| .UseSingleton(Content) | ||
| .UseSingleton(GraphicsDevice) | ||
| .UseSingleton(_camera) | ||
| .UseTerrain() | ||
| .UseDefaultActorContext(context => context | ||
| .Capacity(3_000_000) | ||
| .AddCommon() | ||
| .AddTerrain() | ||
| .AddVisible()) | ||
| .Build(); | ||
|
|
||
| _world.Actors.Execute(new GenerateTerrainCommand()); | ||
|
|
||
| _benchmarkCounter = new BenchmarkCounter(() => _world.Actors.Length, Content, GraphicsDevice); | ||
|
|
||
| base.Initialize(); | ||
| } | ||
|
|
||
| protected override void Dispose(bool disposing) | ||
| { | ||
| if (disposing) | ||
| { | ||
| _world.Dispose(); | ||
| } | ||
|
|
||
| base.Dispose(disposing); | ||
| } | ||
|
|
||
| protected override void Draw(GameTime gameTime) | ||
| { | ||
| GraphicsDevice.Clear(Color.White); | ||
|
|
||
| _world.Draw(gameTime.ElapsedGameTime, gameTime.TotalGameTime); | ||
| _benchmarkCounter.Draw(gameTime); | ||
|
|
||
| base.Draw(gameTime); | ||
| } | ||
|
|
||
| protected override void Update(GameTime gameTime) | ||
| { | ||
| var keyboard = Keyboard.GetState(); | ||
| if (keyboard.IsKeyDown(Keys.Space)) | ||
| { | ||
| } | ||
|
|
||
| _camera.Update(gameTime); | ||
| _benchmarkCounter.Update(gameTime); | ||
| _world.Update(gameTime.ElapsedGameTime, gameTime.TotalGameTime); | ||
|
|
||
| base.Update(gameTime); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using Hexecs.Benchmarks.Map.Common.Positions; | ||
|
|
||
| namespace Hexecs.Benchmarks.Map.Common; | ||
|
|
||
| internal static class CommonInstaller | ||
| { | ||
| public static ActorContextBuilder AddCommon(this ActorContextBuilder builder) | ||
| { | ||
| builder.AddPositions(); | ||
|
|
||
| return builder; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Hexecs.Benchmarks.Map.Common.Positions; | ||
|
|
||
| public struct Position : IActorComponent | ||
| { | ||
| public Point Grid; | ||
| public Point World; | ||
| } |
3 changes: 3 additions & 0 deletions
3
src/Hexecs.Benchmarks.City/Common/Positions/PositionAbility.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| namespace Hexecs.Benchmarks.Map.Common.Positions; | ||
|
|
||
| public readonly struct PositionAbility: IAssetComponent; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code should not contain multiple blank lines in a row.