diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml index 65a4762..e0e7416 100644 --- a/.github/workflows/check-pr.yml +++ b/.github/workflows/check-pr.yml @@ -24,7 +24,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore - name: Restore tools diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index f51e3fc..ee67456 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -30,7 +30,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore - name: Restore tools diff --git a/Ion.Examples/Ion.Examples.Breakout/Assets/15-Breakout-Tiles.png b/Ion.Examples/Ion.Examples.Breakout/Assets/15-Breakout-Tiles.png new file mode 100644 index 0000000..cc7f41f Binary files /dev/null and b/Ion.Examples/Ion.Examples.Breakout/Assets/15-Breakout-Tiles.png differ diff --git a/Ion.Examples/Ion.Examples.Breakout/Assets/49-Breakout-Tiles.png b/Ion.Examples/Ion.Examples.Breakout/Assets/49-Breakout-Tiles.png new file mode 100644 index 0000000..9a867ca Binary files /dev/null and b/Ion.Examples/Ion.Examples.Breakout/Assets/49-Breakout-Tiles.png differ diff --git a/Ion.Examples/Ion.Examples.Breakout/Assets/58-Breakout-Tiles.png b/Ion.Examples/Ion.Examples.Breakout/Assets/58-Breakout-Tiles.png new file mode 100644 index 0000000..0e68d0e Binary files /dev/null and b/Ion.Examples/Ion.Examples.Breakout/Assets/58-Breakout-Tiles.png differ diff --git a/Ion.Examples/Ion.Examples.Breakout/Assets/Ball1.png b/Ion.Examples/Ion.Examples.Breakout/Assets/Ball1.png deleted file mode 100644 index b6325e7..0000000 Binary files a/Ion.Examples/Ion.Examples.Breakout/Assets/Ball1.png and /dev/null differ diff --git a/Ion.Examples/Ion.Examples.Breakout/Assets/Block1.png b/Ion.Examples/Ion.Examples.Breakout/Assets/Block1.png deleted file mode 100644 index 4f2b598..0000000 Binary files a/Ion.Examples/Ion.Examples.Breakout/Assets/Block1.png and /dev/null differ diff --git a/Ion.Examples/Ion.Examples.Breakout/Ion.Examples.Breakout.csproj b/Ion.Examples/Ion.Examples.Breakout/Ion.Examples.Breakout.csproj index 460fa4a..bc3f76e 100644 --- a/Ion.Examples/Ion.Examples.Breakout/Ion.Examples.Breakout.csproj +++ b/Ion.Examples/Ion.Examples.Breakout/Ion.Examples.Breakout.csproj @@ -8,23 +8,29 @@ + + + Always + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + - + - - PreserveNewest - - - PreserveNewest - PreserveNewest diff --git a/Ion.Examples/Ion.Examples.Breakout/Program.cs b/Ion.Examples/Ion.Examples.Breakout/Program.cs index 1364599..39d0c50 100644 --- a/Ion.Examples/Ion.Examples.Breakout/Program.cs +++ b/Ion.Examples/Ion.Examples.Breakout/Program.cs @@ -11,7 +11,7 @@ builder.Services.AddIon(builder.Configuration, graphics => { graphics.Output = GraphicsOutput.Window; - graphics.ClearColor = Color.DarkSlateGray; + graphics.ClearColor = new Color(0x333); }); builder.Services.AddSingleton(); @@ -34,14 +34,14 @@ public class BreakoutSystems(IWindow window, IInputState input, ISpriteBatch spr private readonly Color[] _blockColors = new Color[ROWS * COLS]; private readonly RectangleF[] _blockRects = new RectangleF[ROWS * COLS]; - private Vector2 _blockSize = new(100, 25f); + private Vector2 _blockSize = new(192f, 64f); private readonly float _blockGap = 10f; private readonly float _playerGap = 150f; private readonly float _bottomGap = 20f; - private RectangleF _playerRect = new(0, 0, 160, 20f); + private RectangleF _paddleRect = new(0, 0, 244f, 64f); - private RectangleF _ballRect = new(0, 0, 20f, 20f); + private RectangleF _ballRect = new(0, 0, 32f, 32f); private Vector2 _ballVelocity = Vector2.Zero; private readonly float _initialBallSpeed = 200f; private float _ballSpeed = 200f; @@ -54,7 +54,7 @@ public class BreakoutSystems(IWindow window, IInputState input, ISpriteBatch spr private Texture2D _blockTexture = default!; private Texture2D _ballTexture = default!; - private readonly RectangleF _ballSprite = new RectangleF(1, 1, 14, 14); + private Texture2D _paddleTexture = default!; private SoundEffect _bonkSound = default!; private SoundEffect _pingSound = default!; @@ -66,8 +66,9 @@ public class BreakoutSystems(IWindow window, IInputState input, ISpriteBatch spr [Init] public void SetupBlocks(GameTime dt, GameLoopDelegate next) { - _blockTexture = assets.Load("Block1.png"); - _ballTexture = assets.Load("Ball1.png"); + _blockTexture = assets.Load("15-Breakout-Tiles.png"); + _paddleTexture = assets.Load("49-Breakout-Tiles.png"); + _ballTexture = assets.Load("58-Breakout-Tiles.png"); _bonkSound = assets.Load("Bonk.wav"); _pingSound = assets.Load("Ping.mp3"); _scoreFontSet = assets.Load("BungeeRegular", "Bungee-Regular.ttf"); @@ -88,7 +89,7 @@ public void SetupBlocks(GameTime dt, GameLoopDelegate next) window.Size = new Vector2((COLS * _blockSize.X) + ((COLS + 1) * _blockGap), (ROWS * _blockSize.Y) + ((ROWS + 1) * _blockGap) + _playerGap + _blockSize.Y + _bottomGap); window.IsResizable = false; - _playerRect.Location = new Vector2(Math.Clamp(input.MousePosition.X - (_playerRect.Height / 2f), 0, window.Width - _playerRect.Width), window.Size.Y - (_blockSize.Y + _bottomGap)); + _paddleRect.Location = new Vector2(Math.Clamp(input.MousePosition.X - (_paddleRect.Height / 2f), 0, window.Width - _paddleRect.Width), window.Size.Y - (_blockSize.Y + _bottomGap)); _repositionBlocks(); @@ -121,11 +122,11 @@ public void Update(GameTime dt, GameLoopDelegate next) } - if (isMouseGrabbed) _playerRect.X = Math.Clamp(input.MousePosition.X - (_playerRect.Height / 2f), 0, window.Width - _playerRect.Width); + if (isMouseGrabbed) _paddleRect.X = Math.Clamp(input.MousePosition.X - (_paddleRect.Height / 2f), 0, window.Width - _paddleRect.Width); if (_ballIsCaptured) { - _ballRect.Location = _playerRect.Location + new Vector2((_playerRect.Width - _ballRect.Width) / 2f, -(_ballRect.Height + 1)); + _ballRect.Location = _paddleRect.Location + new Vector2((_paddleRect.Width - _ballRect.Width) / 2f, -(_ballRect.Height + 1)); if (input.Pressed(MouseButton.Left) && isMouseGrabbed) { @@ -170,7 +171,7 @@ public void Update(GameTime dt, GameLoopDelegate next) // Ball to player collisions if (_ballRect.Bottom > 250 && _ballVelocity.Y > 0) { - RectangleF.Intersect(ref _ballRect, ref _playerRect, out var intersection); + RectangleF.Intersect(ref _ballRect, ref _paddleRect, out var intersection); if (intersection.IsEmpty is false) { @@ -237,12 +238,12 @@ public void Render(GameTime dt, GameLoopDelegate next) for (var col = 0; col < COLS; col++) { var i = (row * COLS) + col; - if (_blockStates[i]) spriteBatch.Draw(_blockTexture, _blockRects[i], color: _blockColors[i]); + if (_blockStates[i]) spriteBatch.Draw(_blockTexture, _blockRects[i]);//, color: _blockColors[i]); } } - spriteBatch.Draw(_blockTexture, _playerRect, color: Color.DarkBlue); - spriteBatch.Draw(_ballTexture, _ballRect, color: Color.DarkRed, sourceRectangle: _ballSprite); + spriteBatch.Draw(_paddleTexture, _paddleRect);//, color: Color.DarkBlue); + spriteBatch.Draw(_ballTexture, _ballRect);//, color: Color.DarkRed); spriteBatch.DrawString(_scoreFont, $"Score: {_score}", new Vector2(20f), Color.Red); next(dt); @@ -269,12 +270,12 @@ private void _handlePlayerCollision(ref RectangleF intersection) { _ballVelocity.X *= -1f; _ballVelocity = Vector2.Normalize(_ballVelocity); - _ballRect.X = intersection.Left == _playerRect.Left ? _playerRect.X - (_ballRect.Width+1) : _playerRect.Right + 1; + _ballRect.X = intersection.Left == _paddleRect.Left ? _paddleRect.X - (_ballRect.Width+1) : _paddleRect.Right + 1; return; } _ballVelocity.Y *= -1f; - var offsetFromPaddle = (_ballRect.Left - _playerRect.X) / (_playerRect.Width - _ballRect.Width); + var offsetFromPaddle = (_ballRect.Left - _paddleRect.X) / (_paddleRect.Width - _ballRect.Width); _ballVelocity = Vector2.Lerp(_paddleBounceMin, _paddleBounceMax, offsetFromPaddle); diff --git a/Ion.Examples/Ion.Examples.Breakout/appsettings.json b/Ion.Examples/Ion.Examples.Breakout/appsettings.json index e106015..44b36fa 100644 --- a/Ion.Examples/Ion.Examples.Breakout/appsettings.json +++ b/Ion.Examples/Ion.Examples.Breakout/appsettings.json @@ -7,7 +7,7 @@ }, "Ion": { "Title": "Ion Breakout Example", - "MaxFPS": 500, + "MaxFPS": 120, "Debug": { "TraceEnabled": true }, diff --git a/Ion.Examples/Ion.Examples.Scenes/Ion.Examples.Scenes.csproj b/Ion.Examples/Ion.Examples.Scenes/Ion.Examples.Scenes.csproj index 7bab2bc..9accbf9 100644 --- a/Ion.Examples/Ion.Examples.Scenes/Ion.Examples.Scenes.csproj +++ b/Ion.Examples/Ion.Examples.Scenes/Ion.Examples.Scenes.csproj @@ -19,7 +19,7 @@ - + \ No newline at end of file diff --git a/Ion.Examples/Ion.Examples.Scenes/Program.cs b/Ion.Examples/Ion.Examples.Scenes/Program.cs index 6b5a85a..d97c84d 100644 --- a/Ion.Examples/Ion.Examples.Scenes/Program.cs +++ b/Ion.Examples/Ion.Examples.Scenes/Program.cs @@ -9,6 +9,8 @@ using Ion.Extensions.Scenes; using Ion.Extensions.Coroutines; +using Ion.Examples.Scenes; + var builder = IonApplication.CreateBuilder(args); builder.Services.AddDebugUtils(builder.Configuration); @@ -28,16 +30,17 @@ game.UseEvents(); game.UseVeldridGraphics(); - game.UseFirst((GameLoopDelegate next, IInputState input, ICoroutineRunner coroutine) => { IEnumerator CountDown(int from) { - while (from >= 0) + while (from > 0) { Console.WriteLine("Countdown: " + from--); - yield return Wait.Until(() => input.Pressed(Key.Space)); + yield return Wait.For(TimeSpan.FromSeconds(1)); } + + Console.WriteLine("Countdown done!"); } return dt => @@ -67,7 +70,7 @@ IEnumerator CountDown(int from) { var logFrameNumber = Throttler.Wrap(TimeSpan.FromSeconds(0.5), (dt) => { - Console.WriteLine($"Frame: {dt.Frame}!"); + //Console.WriteLine($"Frame: {dt.Frame}!"); }); return dt => @@ -88,7 +91,7 @@ IEnumerator CountDown(int from) { var flip = false; var switchScene = Throttler.Wrap(TimeSpan.FromSeconds(3), (dt) => { - eventEmitter.EmitChangeScene(flip ? (int)Scenes.MainMenu : (int)Scenes.Gameplay); + eventEmitter.EmitChangeScene(flip ? Scene.MainMenu : Scene.Gameplay); flip = !flip; }); @@ -96,7 +99,7 @@ IEnumerator CountDown(int from) { if (events.On(out var e)) Console.WriteLine($"Int event! {e.Data}"); next(dt); - switchScene(dt); + //switchScene(dt); }; }); @@ -115,7 +118,7 @@ IEnumerator CountDown(int from) }; }); -game.UseScene((int)Scenes.MainMenu, scene => +game.UseScene(Scene.MainMenu, scene => { scene.UseRender((GameLoopDelegate next, ISpriteBatch spriteBatch) => { @@ -129,7 +132,7 @@ IEnumerator CountDown(int from) scene.UseSystem(); }); -game.UseScene((int)Scenes.Gameplay, scene => +game.UseScene(Scene.Gameplay, scene => { scene.UseRender((GameLoopDelegate next, ISpriteBatch spriteBatch) => { @@ -145,71 +148,76 @@ IEnumerator CountDown(int from) game.Run(); -enum Scenes -{ - MainMenu = 1, - Gameplay, -} - -public partial class TestMiddleware +namespace Ion.Examples.Scenes { - private readonly Queue _frameTimes = new Queue(); - - public TestMiddleware() + public enum Scene { - Console.WriteLine("TestMiddleware Constructor"); + MainMenu = 1, + Gameplay, + Test, } - [First] - public void CoolFirstMiddleware(GameTime dt, GameLoopDelegate next) + public partial class TestMiddleware { - //Console.WriteLine($"Class First {dt.Frame}"); - next(dt); - } + private readonly Queue _frameTimes = new(); - [FixedUpdate] - public GameLoopDelegate FancyFixedUpdate(GameLoopDelegate next) - { - Console.WriteLine("Class Fixed Update SETUP"); - uint count = 0; - return dt => + public TestMiddleware() + { + Console.WriteLine("TestMiddleware Constructor"); + } + + [First] + public void CoolFirstMiddleware(GameTime dt, GameLoopDelegate next) { - count++; - //Console.WriteLine($"Class Fixed Update inside {count++}"); + //Console.WriteLine($"Class First {dt.Frame}"); next(dt); - }; - } + } - [Render] - public GameLoopDelegate Render(GameLoopDelegate next) - { - var stopwatch = new Stopwatch(); + [FixedUpdate] + public GameLoopDelegate FancyFixedUpdate(GameLoopDelegate next) + { + Console.WriteLine("Class Fixed Update SETUP"); + uint count = 0; + return dt => + { + count++; + //Console.WriteLine($"Class Fixed Update inside {count++}"); + next(dt); + }; + } - return dt => + [Render] + public GameLoopDelegate Render(GameLoopDelegate next) { - stopwatch.Restart(); - next(dt); - stopwatch.Stop(); - _frameTimes.Enqueue((float)stopwatch.Elapsed.TotalSeconds); - while (_frameTimes.Count > 60) _frameTimes.Dequeue(); - }; + var stopwatch = new Stopwatch(); + + return dt => + { + stopwatch.Restart(); + next(dt); + stopwatch.Stop(); + _frameTimes.Enqueue((float)stopwatch.Elapsed.TotalSeconds); + while (_frameTimes.Count > 60) _frameTimes.Dequeue(); + }; + } } -} -static class Throttler -{ - public static Action Wrap(TimeSpan interval, Action action) + static class Throttler { - var total = 0f; - - return (dt) => + public static Action Wrap(TimeSpan interval, Action action) { - total += dt.Delta; - if (total > interval.TotalSeconds) + var total = 0f; + + return (dt) => { - total = 0; - action(dt); - } - }; + total += dt.Delta; + if (total > interval.TotalSeconds) + { + total = 0; + action(dt); + } + }; + } } -} + +} \ No newline at end of file diff --git a/Ion.sln b/Ion.sln index 291af50..f6c6cbe 100644 --- a/Ion.sln +++ b/Ion.sln @@ -46,8 +46,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Extensions.Graphics.Vel EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Core.InternalGenerators", "Ion\Ion.Core.InternalGenerators\Ion.Core.InternalGenerators.csproj", "{DFD31B44-8064-4143-9B38-572729A89071}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Extensions.Scenes.InternalGenerators", "Ion\Ion.Extensions.Scenes.InternalGenerators\Ion.Extensions.Scenes.InternalGenerators.csproj", "{0B90C501-3304-40D0-B099-CF89A6DF37E0}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Extensions.Debug.Abstractions", "Ion\Ion.Extensions.Debug.Abstractions\Ion.Extensions.Debug.Abstractions.csproj", "{4E7E36EE-B7D7-41FE-9E0F-4FF52A18207A}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Extensions.Coroutines", "Ion\Ion.Extensions.Coroutines\Ion.Extensions.Coroutines.csproj", "{5C41D010-5952-4155-B2C4-B85FA220B62E}" @@ -72,159 +70,112 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Extensions.Assets.Abstr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Extensions.Assets", "Ion\Ion.Extensions.Assets\Ion.Extensions.Assets.csproj", "{63F8B34A-3056-4EB4-A6AA-76508E7CA707}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Extensions.Graphics.WGPU", "Ion\Ion.Extensions.Graphics.WGPU\Ion.Extensions.Graphics.WGPU.csproj", "{DC575907-E24D-4991-B90F-286B8EE342DD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Extensions.Scenes.Generators", "Ion\Ion.Extensions.Scenes.Generators\Ion.Extensions.Scenes.Generators.csproj", "{2488F296-352B-4FE6-8040-1E39DAD95C4F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ion.Extensions.Scenes.Generators.Tests", "Ion\Ion.Extensions.Scenes.Generators.Tests\Ion.Extensions.Scenes.Generators.Tests.csproj", "{B3E523F8-E19C-47EF-B344-74B736AEF1FA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - DebugGenerators|Any CPU = DebugGenerators|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {94ACED8A-3370-48F3-A749-68C81FDDE652}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {94ACED8A-3370-48F3-A749-68C81FDDE652}.Debug|Any CPU.Build.0 = Debug|Any CPU - {94ACED8A-3370-48F3-A749-68C81FDDE652}.DebugGenerators|Any CPU.ActiveCfg = DebugGenerators|Any CPU - {94ACED8A-3370-48F3-A749-68C81FDDE652}.DebugGenerators|Any CPU.Build.0 = DebugGenerators|Any CPU {94ACED8A-3370-48F3-A749-68C81FDDE652}.Release|Any CPU.ActiveCfg = Release|Any CPU {94ACED8A-3370-48F3-A749-68C81FDDE652}.Release|Any CPU.Build.0 = Release|Any CPU {FF7891A1-606D-413D-B9F2-918D2DB5F266}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FF7891A1-606D-413D-B9F2-918D2DB5F266}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FF7891A1-606D-413D-B9F2-918D2DB5F266}.DebugGenerators|Any CPU.ActiveCfg = DebugGenerators|Any CPU - {FF7891A1-606D-413D-B9F2-918D2DB5F266}.DebugGenerators|Any CPU.Build.0 = DebugGenerators|Any CPU {FF7891A1-606D-413D-B9F2-918D2DB5F266}.Release|Any CPU.ActiveCfg = Release|Any CPU {FF7891A1-606D-413D-B9F2-918D2DB5F266}.Release|Any CPU.Build.0 = Release|Any CPU {74342FF5-BD87-4F81-A783-1A13ADE5F052}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {74342FF5-BD87-4F81-A783-1A13ADE5F052}.Debug|Any CPU.Build.0 = Debug|Any CPU - {74342FF5-BD87-4F81-A783-1A13ADE5F052}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {74342FF5-BD87-4F81-A783-1A13ADE5F052}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {74342FF5-BD87-4F81-A783-1A13ADE5F052}.Release|Any CPU.ActiveCfg = Release|Any CPU {74342FF5-BD87-4F81-A783-1A13ADE5F052}.Release|Any CPU.Build.0 = Release|Any CPU {B6044750-A205-4D10-AD02-02707AE9FC0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B6044750-A205-4D10-AD02-02707AE9FC0A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B6044750-A205-4D10-AD02-02707AE9FC0A}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {B6044750-A205-4D10-AD02-02707AE9FC0A}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {B6044750-A205-4D10-AD02-02707AE9FC0A}.Release|Any CPU.ActiveCfg = Release|Any CPU {B6044750-A205-4D10-AD02-02707AE9FC0A}.Release|Any CPU.Build.0 = Release|Any CPU {700C404D-596B-4F79-9E4A-1B49355059D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {700C404D-596B-4F79-9E4A-1B49355059D5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {700C404D-596B-4F79-9E4A-1B49355059D5}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {700C404D-596B-4F79-9E4A-1B49355059D5}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {700C404D-596B-4F79-9E4A-1B49355059D5}.Release|Any CPU.ActiveCfg = Release|Any CPU {700C404D-596B-4F79-9E4A-1B49355059D5}.Release|Any CPU.Build.0 = Release|Any CPU {59A49B7B-62B2-4343-838E-AE7E883BDB52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {59A49B7B-62B2-4343-838E-AE7E883BDB52}.Debug|Any CPU.Build.0 = Debug|Any CPU - {59A49B7B-62B2-4343-838E-AE7E883BDB52}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {59A49B7B-62B2-4343-838E-AE7E883BDB52}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {59A49B7B-62B2-4343-838E-AE7E883BDB52}.Release|Any CPU.ActiveCfg = Release|Any CPU {59A49B7B-62B2-4343-838E-AE7E883BDB52}.Release|Any CPU.Build.0 = Release|Any CPU {BC64E83E-4034-407F-810C-671EC13AD1D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BC64E83E-4034-407F-810C-671EC13AD1D7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BC64E83E-4034-407F-810C-671EC13AD1D7}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {BC64E83E-4034-407F-810C-671EC13AD1D7}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {BC64E83E-4034-407F-810C-671EC13AD1D7}.Release|Any CPU.ActiveCfg = Release|Any CPU {BC64E83E-4034-407F-810C-671EC13AD1D7}.Release|Any CPU.Build.0 = Release|Any CPU {C6AE892E-ED53-4CF9-B3D4-5F904E6E352D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C6AE892E-ED53-4CF9-B3D4-5F904E6E352D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C6AE892E-ED53-4CF9-B3D4-5F904E6E352D}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {C6AE892E-ED53-4CF9-B3D4-5F904E6E352D}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {C6AE892E-ED53-4CF9-B3D4-5F904E6E352D}.Release|Any CPU.ActiveCfg = Release|Any CPU {C6AE892E-ED53-4CF9-B3D4-5F904E6E352D}.Release|Any CPU.Build.0 = Release|Any CPU {B3B07001-6598-48DF-8320-C65870A9E0F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B3B07001-6598-48DF-8320-C65870A9E0F5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B3B07001-6598-48DF-8320-C65870A9E0F5}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {B3B07001-6598-48DF-8320-C65870A9E0F5}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {B3B07001-6598-48DF-8320-C65870A9E0F5}.Release|Any CPU.ActiveCfg = Release|Any CPU {B3B07001-6598-48DF-8320-C65870A9E0F5}.Release|Any CPU.Build.0 = Release|Any CPU {DFD31B44-8064-4143-9B38-572729A89071}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DFD31B44-8064-4143-9B38-572729A89071}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DFD31B44-8064-4143-9B38-572729A89071}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {DFD31B44-8064-4143-9B38-572729A89071}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {DFD31B44-8064-4143-9B38-572729A89071}.Release|Any CPU.ActiveCfg = Release|Any CPU {DFD31B44-8064-4143-9B38-572729A89071}.Release|Any CPU.Build.0 = Release|Any CPU - {0B90C501-3304-40D0-B099-CF89A6DF37E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0B90C501-3304-40D0-B099-CF89A6DF37E0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0B90C501-3304-40D0-B099-CF89A6DF37E0}.DebugGenerators|Any CPU.ActiveCfg = DebugGenerators|Any CPU - {0B90C501-3304-40D0-B099-CF89A6DF37E0}.DebugGenerators|Any CPU.Build.0 = DebugGenerators|Any CPU - {0B90C501-3304-40D0-B099-CF89A6DF37E0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0B90C501-3304-40D0-B099-CF89A6DF37E0}.Release|Any CPU.Build.0 = Release|Any CPU {4E7E36EE-B7D7-41FE-9E0F-4FF52A18207A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4E7E36EE-B7D7-41FE-9E0F-4FF52A18207A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4E7E36EE-B7D7-41FE-9E0F-4FF52A18207A}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {4E7E36EE-B7D7-41FE-9E0F-4FF52A18207A}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {4E7E36EE-B7D7-41FE-9E0F-4FF52A18207A}.Release|Any CPU.ActiveCfg = Release|Any CPU {4E7E36EE-B7D7-41FE-9E0F-4FF52A18207A}.Release|Any CPU.Build.0 = Release|Any CPU {5C41D010-5952-4155-B2C4-B85FA220B62E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5C41D010-5952-4155-B2C4-B85FA220B62E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5C41D010-5952-4155-B2C4-B85FA220B62E}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {5C41D010-5952-4155-B2C4-B85FA220B62E}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {5C41D010-5952-4155-B2C4-B85FA220B62E}.Release|Any CPU.ActiveCfg = Release|Any CPU {5C41D010-5952-4155-B2C4-B85FA220B62E}.Release|Any CPU.Build.0 = Release|Any CPU {270CA94E-3C14-42BE-AEBB-58C236C39E15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {270CA94E-3C14-42BE-AEBB-58C236C39E15}.Debug|Any CPU.Build.0 = Debug|Any CPU - {270CA94E-3C14-42BE-AEBB-58C236C39E15}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {270CA94E-3C14-42BE-AEBB-58C236C39E15}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {270CA94E-3C14-42BE-AEBB-58C236C39E15}.Release|Any CPU.ActiveCfg = Release|Any CPU {270CA94E-3C14-42BE-AEBB-58C236C39E15}.Release|Any CPU.Build.0 = Release|Any CPU {7E6D0EA0-9329-42D7-8B50-F6FB43241E99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7E6D0EA0-9329-42D7-8B50-F6FB43241E99}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7E6D0EA0-9329-42D7-8B50-F6FB43241E99}.DebugGenerators|Any CPU.ActiveCfg = DebugGenerators|Any CPU - {7E6D0EA0-9329-42D7-8B50-F6FB43241E99}.DebugGenerators|Any CPU.Build.0 = DebugGenerators|Any CPU {7E6D0EA0-9329-42D7-8B50-F6FB43241E99}.Release|Any CPU.ActiveCfg = Release|Any CPU {7E6D0EA0-9329-42D7-8B50-F6FB43241E99}.Release|Any CPU.Build.0 = Release|Any CPU {B37F3A4D-9F4A-4CCD-8408-4B1BFF40DE96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B37F3A4D-9F4A-4CCD-8408-4B1BFF40DE96}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B37F3A4D-9F4A-4CCD-8408-4B1BFF40DE96}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {B37F3A4D-9F4A-4CCD-8408-4B1BFF40DE96}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {B37F3A4D-9F4A-4CCD-8408-4B1BFF40DE96}.Release|Any CPU.ActiveCfg = Release|Any CPU {B37F3A4D-9F4A-4CCD-8408-4B1BFF40DE96}.Release|Any CPU.Build.0 = Release|Any CPU {DB97F94C-5366-4591-9AC3-CAF5C60EEA75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DB97F94C-5366-4591-9AC3-CAF5C60EEA75}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DB97F94C-5366-4591-9AC3-CAF5C60EEA75}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {DB97F94C-5366-4591-9AC3-CAF5C60EEA75}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {DB97F94C-5366-4591-9AC3-CAF5C60EEA75}.Release|Any CPU.ActiveCfg = Release|Any CPU {DB97F94C-5366-4591-9AC3-CAF5C60EEA75}.Release|Any CPU.Build.0 = Release|Any CPU {3FF057BB-9D7B-4CA4-A0E4-E5430DBA5C92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3FF057BB-9D7B-4CA4-A0E4-E5430DBA5C92}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3FF057BB-9D7B-4CA4-A0E4-E5430DBA5C92}.DebugGenerators|Any CPU.ActiveCfg = DebugGenerators|Any CPU - {3FF057BB-9D7B-4CA4-A0E4-E5430DBA5C92}.DebugGenerators|Any CPU.Build.0 = DebugGenerators|Any CPU {3FF057BB-9D7B-4CA4-A0E4-E5430DBA5C92}.Release|Any CPU.ActiveCfg = Release|Any CPU {3FF057BB-9D7B-4CA4-A0E4-E5430DBA5C92}.Release|Any CPU.Build.0 = Release|Any CPU {37A9A838-82CF-45A8-B5C6-28742BBAB223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {37A9A838-82CF-45A8-B5C6-28742BBAB223}.Debug|Any CPU.Build.0 = Debug|Any CPU - {37A9A838-82CF-45A8-B5C6-28742BBAB223}.DebugGenerators|Any CPU.ActiveCfg = DebugGenerators|Any CPU - {37A9A838-82CF-45A8-B5C6-28742BBAB223}.DebugGenerators|Any CPU.Build.0 = DebugGenerators|Any CPU {37A9A838-82CF-45A8-B5C6-28742BBAB223}.Release|Any CPU.ActiveCfg = Release|Any CPU {37A9A838-82CF-45A8-B5C6-28742BBAB223}.Release|Any CPU.Build.0 = Release|Any CPU {8B15406E-E3BD-4C0B-A9B1-DFCE63B38952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8B15406E-E3BD-4C0B-A9B1-DFCE63B38952}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8B15406E-E3BD-4C0B-A9B1-DFCE63B38952}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {8B15406E-E3BD-4C0B-A9B1-DFCE63B38952}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {8B15406E-E3BD-4C0B-A9B1-DFCE63B38952}.Release|Any CPU.ActiveCfg = Release|Any CPU {8B15406E-E3BD-4C0B-A9B1-DFCE63B38952}.Release|Any CPU.Build.0 = Release|Any CPU {647E9B1E-21CB-48A0-881D-072446AD0E39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {647E9B1E-21CB-48A0-881D-072446AD0E39}.Debug|Any CPU.Build.0 = Debug|Any CPU - {647E9B1E-21CB-48A0-881D-072446AD0E39}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {647E9B1E-21CB-48A0-881D-072446AD0E39}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {647E9B1E-21CB-48A0-881D-072446AD0E39}.Release|Any CPU.ActiveCfg = Release|Any CPU {647E9B1E-21CB-48A0-881D-072446AD0E39}.Release|Any CPU.Build.0 = Release|Any CPU {C8C50528-0151-41B3-A78C-505034B1E1C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C8C50528-0151-41B3-A78C-505034B1E1C6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C8C50528-0151-41B3-A78C-505034B1E1C6}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {C8C50528-0151-41B3-A78C-505034B1E1C6}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {C8C50528-0151-41B3-A78C-505034B1E1C6}.Release|Any CPU.ActiveCfg = Release|Any CPU {C8C50528-0151-41B3-A78C-505034B1E1C6}.Release|Any CPU.Build.0 = Release|Any CPU {63F8B34A-3056-4EB4-A6AA-76508E7CA707}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {63F8B34A-3056-4EB4-A6AA-76508E7CA707}.Debug|Any CPU.Build.0 = Debug|Any CPU - {63F8B34A-3056-4EB4-A6AA-76508E7CA707}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {63F8B34A-3056-4EB4-A6AA-76508E7CA707}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU {63F8B34A-3056-4EB4-A6AA-76508E7CA707}.Release|Any CPU.ActiveCfg = Release|Any CPU {63F8B34A-3056-4EB4-A6AA-76508E7CA707}.Release|Any CPU.Build.0 = Release|Any CPU - {DC575907-E24D-4991-B90F-286B8EE342DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DC575907-E24D-4991-B90F-286B8EE342DD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DC575907-E24D-4991-B90F-286B8EE342DD}.DebugGenerators|Any CPU.ActiveCfg = Debug|Any CPU - {DC575907-E24D-4991-B90F-286B8EE342DD}.DebugGenerators|Any CPU.Build.0 = Debug|Any CPU - {DC575907-E24D-4991-B90F-286B8EE342DD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DC575907-E24D-4991-B90F-286B8EE342DD}.Release|Any CPU.Build.0 = Release|Any CPU + {2488F296-352B-4FE6-8040-1E39DAD95C4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2488F296-352B-4FE6-8040-1E39DAD95C4F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2488F296-352B-4FE6-8040-1E39DAD95C4F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2488F296-352B-4FE6-8040-1E39DAD95C4F}.Release|Any CPU.Build.0 = Release|Any CPU + {B3E523F8-E19C-47EF-B344-74B736AEF1FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B3E523F8-E19C-47EF-B344-74B736AEF1FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B3E523F8-E19C-47EF-B344-74B736AEF1FA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B3E523F8-E19C-47EF-B344-74B736AEF1FA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -241,7 +192,6 @@ Global {C6AE892E-ED53-4CF9-B3D4-5F904E6E352D} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} {B3B07001-6598-48DF-8320-C65870A9E0F5} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} {DFD31B44-8064-4143-9B38-572729A89071} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} - {0B90C501-3304-40D0-B099-CF89A6DF37E0} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} {4E7E36EE-B7D7-41FE-9E0F-4FF52A18207A} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} {5C41D010-5952-4155-B2C4-B85FA220B62E} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} {270CA94E-3C14-42BE-AEBB-58C236C39E15} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} @@ -254,7 +204,8 @@ Global {647E9B1E-21CB-48A0-881D-072446AD0E39} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} {C8C50528-0151-41B3-A78C-505034B1E1C6} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} {63F8B34A-3056-4EB4-A6AA-76508E7CA707} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} - {DC575907-E24D-4991-B90F-286B8EE342DD} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} + {2488F296-352B-4FE6-8040-1E39DAD95C4F} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} + {B3E523F8-E19C-47EF-B344-74B736AEF1FA} = {A38C6AA1-BA6E-4DBC-BC7C-F0BD034224CE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {CCF839E2-AF6A-4444-95F2-76F60225DC55} diff --git a/Ion/Ion.Core.InternalGenerators/UseDelegateServicesGenerator.cs b/Ion/Ion.Core.InternalGenerators/UseDelegateServicesGenerator.cs index b98a522..146a43e 100644 --- a/Ion/Ion.Core.InternalGenerators/UseDelegateServicesGenerator.cs +++ b/Ion/Ion.Core.InternalGenerators/UseDelegateServicesGenerator.cs @@ -1,30 +1,35 @@ using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; - using SourceGeneratorUtils; +using System.Collections.Immutable; + +using System.Diagnostics; + namespace Ion.Core.InternalGenerators; [Generator] public class UseDelegateServicesGenerator : IIncrementalGenerator { private const int MAX_SERVICES = 8; - private static readonly string[] STAGES = new[] { "Init", "First", "FixedUpdate", "Update", "Render", "Last", "Destroy" }; + private static readonly string[] STAGES = ["Init", "First", "FixedUpdate", "Update", "Render", "Last", "Destroy"]; public void Initialize(IncrementalGeneratorInitializationContext context) { #if DEBUGGENERATORS - if (!Debugger.IsAttached) - { - Debugger.Launch(); - } + //if (!Debugger.IsAttached) + //{ + // Debugger.Launch(); + //} #endif + // Add the marker attribute to the compilation - context.RegisterPostInitializationOutput(ctx => ctx.AddSource("UseDelegateServiceExtensions.g.cs", GetUseDelegateServiceExtensions())); + context.RegisterPostInitializationOutput(ctx => ctx.AddSource("UseDelegateServiceExtensions.g.cs", _getUseDelegateServiceExtensions())); } - private static SourceText GetUseDelegateServiceExtensions() + private static SourceText _getUseDelegateServiceExtensions() { var source = new SourceWriter(); source.WriteLine("using Microsoft.Extensions.DependencyInjection;"); diff --git a/Ion/Ion.Extensions.Assets.Abstractions/AssetTypes/IFontSet.cs b/Ion/Ion.Extensions.Assets.Abstractions/AssetTypes/IFontSet.cs deleted file mode 100644 index 78c7b19..0000000 --- a/Ion/Ion.Extensions.Assets.Abstractions/AssetTypes/IFontSet.cs +++ /dev/null @@ -1,17 +0,0 @@ - -using System.Numerics; - -namespace Ion.Extensions.Assets; - -public interface IFontSet : IAsset -{ - -} - -public interface IFont -{ - IFontSet FontSet { get; } - float FontSize { get; } - - Vector2 MeasureString(string text); -} diff --git a/Ion/Ion.Extensions.Assets.Abstractions/AssetTypes/ISoundEffect.cs b/Ion/Ion.Extensions.Audio.Abstractions/Assets/ISoundEffect.cs similarity index 51% rename from Ion/Ion.Extensions.Assets.Abstractions/AssetTypes/ISoundEffect.cs rename to Ion/Ion.Extensions.Audio.Abstractions/Assets/ISoundEffect.cs index f25625d..ca04988 100644 --- a/Ion/Ion.Extensions.Assets.Abstractions/AssetTypes/ISoundEffect.cs +++ b/Ion/Ion.Extensions.Audio.Abstractions/Assets/ISoundEffect.cs @@ -1,5 +1,6 @@ - -namespace Ion.Extensions.Assets; +using Ion.Extensions.Assets; + +namespace Ion.Extensions.Audio; public interface ISoundEffect : IAsset { diff --git a/Ion/Ion.Extensions.Audio.Abstractions/IAudioManager.cs b/Ion/Ion.Extensions.Audio.Abstractions/IAudioManager.cs index b8d53ed..7bc7f8c 100644 --- a/Ion/Ion.Extensions.Audio.Abstractions/IAudioManager.cs +++ b/Ion/Ion.Extensions.Audio.Abstractions/IAudioManager.cs @@ -1,11 +1,8 @@ -using Ion.Extensions.Assets; +namespace Ion.Extensions.Audio; -namespace Ion.Extensions.Audio +public interface IAudioManager { - public interface IAudioManager - { - float MasterVolume { get; set; } + float MasterVolume { get; set; } - void Play(ISoundEffect soundEffect, float volume = 1f, float pitchShift = 0f); - } + void Play(ISoundEffect soundEffect, float volume = 1f, float pitchShift = 0f); } \ No newline at end of file diff --git a/Ion/Ion.Extensions.Coroutines.Abstractions/Wait.cs b/Ion/Ion.Extensions.Coroutines.Abstractions/Wait.cs index ea60c6c..af9845e 100644 --- a/Ion/Ion.Extensions.Coroutines.Abstractions/Wait.cs +++ b/Ion/Ion.Extensions.Coroutines.Abstractions/Wait.cs @@ -4,6 +4,8 @@ public static class Wait { public static IWait For(float delay) => new WaitFor(delay); + public static IWait For(TimeSpan delay) => new WaitFor((float)delay.TotalSeconds); + public static IWait For() where TEvent : unmanaged => new WaitForEvent(); public static IWait Until(Func predicate) => new WaitUntil(predicate); diff --git a/Ion/Ion.Extensions.Coroutines.Generators/CoroutinesGenerator.cs b/Ion/Ion.Extensions.Coroutines.Generators/CoroutinesGenerator.cs index 795d329..741b62e 100644 --- a/Ion/Ion.Extensions.Coroutines.Generators/CoroutinesGenerator.cs +++ b/Ion/Ion.Extensions.Coroutines.Generators/CoroutinesGenerator.cs @@ -11,10 +11,10 @@ public class CoroutinesGenerator : IIncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { #if DEBUGGENERATORS - if (!Debugger.IsAttached) - { - Debugger.Launch(); - } + //if (!System.Diagnostics.Debugger.IsAttached) + //{ + // System.Diagnostics.Debugger.Launch(); + //} #endif // Add the marker attribute to the compilation diff --git a/Ion/Ion.Extensions.Graphics.Abstractions/Assets/IFontSet.cs b/Ion/Ion.Extensions.Graphics.Abstractions/Assets/IFontSet.cs new file mode 100644 index 0000000..c11c867 --- /dev/null +++ b/Ion/Ion.Extensions.Graphics.Abstractions/Assets/IFontSet.cs @@ -0,0 +1,15 @@ +using System.Numerics; + +using Ion.Extensions.Assets; + +namespace Ion.Extensions.Graphics; + +public interface IFontSet : IAsset { } + +public interface IFont +{ + IFontSet FontSet { get; } + float FontSize { get; } + + Vector2 MeasureString(string text); +} diff --git a/Ion/Ion.Extensions.Graphics.Abstractions/Color.cs b/Ion/Ion.Extensions.Graphics.Abstractions/Color.cs index 10f91c5..87e32ea 100644 --- a/Ion/Ion.Extensions.Graphics.Abstractions/Color.cs +++ b/Ion/Ion.Extensions.Graphics.Abstractions/Color.cs @@ -48,26 +48,44 @@ public struct Color : IEquatable /// /// Constructs an RGBA color from a packed value. /// The value is a 32-bit unsigned integer, with A in the least significant octet. + /// Acceptable formats include 8 value (RRGGBBAA), 6 value (RRGGBB), 4 value (RGBA) and 3 value (RGB). /// - /// The packed value. - public Color(uint packedValue) + /// The packed value. + public Color(uint hex) { float r, g, b, a; unchecked { - if ((packedValue & 0xff000000) != 0) + if (hex <= 0xFFF) // RGB { - r = (byte)packedValue >> 24; - g = (byte)packedValue >> 16; - b = (byte)packedValue >> 8; - a = (byte)packedValue; - } else { - r = (byte)packedValue >> 16; - g = (byte)packedValue >> 8; - b = (byte)packedValue; - a = 0; + r = (byte)((hex >> 8 & 0xF) * 0x11); // replicate 4-bit value + g = (byte)((hex >> 4 & 0xF) * 0x11); // replicate 4-bit value + b = (byte)((hex & 0xF) * 0x11); // replicate 4-bit value + a = 255; // fully opaque } - + else if (hex <= 0xFFFF) + { + r = (byte)((hex >> 16 & 0xF) * 0x11); // replicate 4-bit value + g = (byte)((hex >> 8 & 0xF) * 0x11); // replicate 4-bit value + g = (byte)((hex >> 4 & 0xF) * 0x11); // replicate 4-bit value + b = (byte)((hex & 0xF) * 0x11); // replicate 4-bit value + a = 255; // fully opaque + } + else if (hex <= 0xFFFFFF) // RRGGBB + { + r = (byte)((hex >> 16) & 0xFF); + g = (byte)((hex >> 8) & 0xFF); + b = (byte)(hex & 0xFF); + a = 255; // fully opaque + } + else // RRGGBBAA + { + r = (byte)((hex >> 24) & 0xFF); + g = (byte)((hex >> 16) & 0xFF); + b = (byte)((hex >> 8) & 0xFF); + a = (byte)(hex & 0xFF); + } + } _channels = new Vector4(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f); diff --git a/Ion/Ion.Extensions.Graphics.Veldrid/2D/SpriteRenderer.cs b/Ion/Ion.Extensions.Graphics.Veldrid/2D/SpriteRenderer.cs index 20215db..e086449 100644 --- a/Ion/Ion.Extensions.Graphics.Veldrid/2D/SpriteRenderer.cs +++ b/Ion/Ion.Extensions.Graphics.Veldrid/2D/SpriteRenderer.cs @@ -28,18 +28,11 @@ ITraceTimer trace private bool _beginCalled = false; - private class BufferContainer + private class BufferContainer(DeviceBuffer buffer, ResourceSet instanceSet, ResourceSet textureSet) { - public DeviceBuffer Buffer { get; set; } - public ResourceSet InstanceSet { get; set; } - public ResourceSet TextureSet { get; set; } - - public BufferContainer(DeviceBuffer buffer, ResourceSet instanceSet, ResourceSet textureSet) - { - Buffer = buffer; - InstanceSet = instanceSet; - TextureSet = textureSet; - } + public DeviceBuffer Buffer { get; set; } = buffer; + public ResourceSet InstanceSet { get; set; } = instanceSet; + public ResourceSet TextureSet { get; set; } = textureSet; public void Dispose() { @@ -49,7 +42,7 @@ public void Dispose() } } - private readonly Dictionary _buffers = new(); + private readonly Dictionary _buffers = []; private const string VertexCode = @" #version 450 diff --git a/Ion/Ion.Extensions.Scenes.Abstractions/Ion.Extensions.Scenes.Abstractions.csproj b/Ion/Ion.Extensions.Scenes.Abstractions/Ion.Extensions.Scenes.Abstractions.csproj index de6a467..ecf5c87 100644 --- a/Ion/Ion.Extensions.Scenes.Abstractions/Ion.Extensions.Scenes.Abstractions.csproj +++ b/Ion/Ion.Extensions.Scenes.Abstractions/Ion.Extensions.Scenes.Abstractions.csproj @@ -4,12 +4,12 @@ true enable enable + true - \ No newline at end of file diff --git a/Ion/Ion.Extensions.Scenes.Abstractions/SceneEvents.cs b/Ion/Ion.Extensions.Scenes.Abstractions/SceneEvents.cs index 3aa7bb5..f159268 100644 --- a/Ion/Ion.Extensions.Scenes.Abstractions/SceneEvents.cs +++ b/Ion/Ion.Extensions.Scenes.Abstractions/SceneEvents.cs @@ -5,8 +5,5 @@ public record struct ChangeSceneEvent(int NextSceneId); public static class EventEmitterExtensions { - public static void EmitChangeScene(this IEventEmitter eventEmitter, int nextSceneId) - { - eventEmitter.Emit(new ChangeSceneEvent(nextSceneId)); - } + public static void EmitChangeScene(this IEventEmitter eventEmitter, int nextSceneId) => eventEmitter.Emit(new ChangeSceneEvent(nextSceneId)); } diff --git a/Ion/Ion.Extensions.Scenes.Abstractions/Scene.cs b/Ion/Ion.Extensions.Scenes.Abstractions/SceneInstance.cs similarity index 90% rename from Ion/Ion.Extensions.Scenes.Abstractions/Scene.cs rename to Ion/Ion.Extensions.Scenes.Abstractions/SceneInstance.cs index 6578dbb..ca88ee4 100644 --- a/Ion/Ion.Extensions.Scenes.Abstractions/Scene.cs +++ b/Ion/Ion.Extensions.Scenes.Abstractions/SceneInstance.cs @@ -1,6 +1,6 @@ namespace Ion.Extensions.Scenes; -public class Scene +public class SceneInstance { public int Id { get; } public string Name { get; } @@ -13,7 +13,7 @@ public class Scene public GameLoopDelegate Last { get; set; } = (dt) => { }; public GameLoopDelegate Destroy { get; set; } = (dt) => { }; - internal Scene(int id) + internal SceneInstance(int id) { Id = id; Name = $"Scene{id}"; diff --git a/Ion/Ion.Extensions.Scenes.Generators.Tests/GlobalUsings.cs b/Ion/Ion.Extensions.Scenes.Generators.Tests/GlobalUsings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/Ion/Ion.Extensions.Scenes.Generators.Tests/GlobalUsings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/Ion/Ion.Extensions.Scenes.Generators.Tests/Ion.Extensions.Scenes.Generators.Tests.csproj b/Ion/Ion.Extensions.Scenes.Generators.Tests/Ion.Extensions.Scenes.Generators.Tests.csproj new file mode 100644 index 0000000..104ae8f --- /dev/null +++ b/Ion/Ion.Extensions.Scenes.Generators.Tests/Ion.Extensions.Scenes.Generators.Tests.csproj @@ -0,0 +1,32 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/Ion/Ion.Extensions.Scenes.Generators.Tests/SceneGeneratorTests.cs b/Ion/Ion.Extensions.Scenes.Generators.Tests/SceneGeneratorTests.cs new file mode 100644 index 0000000..9884504 --- /dev/null +++ b/Ion/Ion.Extensions.Scenes.Generators.Tests/SceneGeneratorTests.cs @@ -0,0 +1,63 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; + +namespace Ion.Extensions.Scenes.Generators.Tests; + +public class SceneGeneratorTests +{ + [Fact(Skip = "WIP")] + public Task TestSceneGenerator() + { + // The source code to test + var source = @" +using Ion.Extensions.Scenes; + +namespace Test.SceneGenerator { + [Scenes] + public enum Scene + { + MainMenu = 1, + Gameplay, + } +}"; + + // Pass the source code to our helper and snapshot test the output + return TestHelper.Verify(source); + } +} + +public static class TestHelper +{ + public static Task Verify(string source) + { + // Parse the provided string into a C# syntax tree + SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source); + + // Create a Roslyn compilation for the syntax tree. + CSharpCompilation compilation = CSharpCompilation.Create( + assemblyName: "Tests", + syntaxTrees: [syntaxTree]); + + + // Create an instance of our incremental source generator + var generator = new ScenesGenerator(); + + // The GeneratorDriver is used to run our generator against a compilation + GeneratorDriver driver = CSharpGeneratorDriver.Create(generator); + + // Run the source generator! + driver = driver.RunGenerators(compilation); + + var runResults = driver.GetRunResult(); + foreach(var generatedTree in runResults.GeneratedTrees) + { + var filename = generatedTree.FilePath; + var contents = generatedTree.GetText().ToString(); + Console.WriteLine(@$"// Generated File: {filename} +{contents}"); + } + + // Use verify to snapshot test the source generator output! + return Verifier.Verify(driver); + } +} \ No newline at end of file diff --git a/Ion/Ion.Extensions.Scenes.Generators/Ion.Extensions.Scenes.Generators.csproj b/Ion/Ion.Extensions.Scenes.Generators/Ion.Extensions.Scenes.Generators.csproj new file mode 100644 index 0000000..66deadf --- /dev/null +++ b/Ion/Ion.Extensions.Scenes.Generators/Ion.Extensions.Scenes.Generators.csproj @@ -0,0 +1,40 @@ + + + netstandard2.0 + enable + true + Preview + false + True + True + True + True + True + Debug;Release + + + + Ion.Extensions.Scenes.Generators + 0.1.0.0 + Jim Buck + https://LICENSE_URL_HERE_OR_DELETE_THIS_LINE + https://PROJECT_URL_HERE_OR_DELETE_THIS_LINE + https://ICON_URL_HERE_OR_DELETE_THIS_LINE + https://REPOSITORY_URL_HERE_OR_DELETE_THIS_LINE + false + Source Generator for Scene Extensions + Summary of changes made in this release of the package. + Copyright Jim Buck 2024 + ion;game engine;analyzers + true + + + + + + + + + + + diff --git a/Ion/Ion.Extensions.Scenes.Generators/ScenesGenerator.cs b/Ion/Ion.Extensions.Scenes.Generators/ScenesGenerator.cs new file mode 100644 index 0000000..bf10927 --- /dev/null +++ b/Ion/Ion.Extensions.Scenes.Generators/ScenesGenerator.cs @@ -0,0 +1,138 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Text; +using SourceGeneratorUtils; + +using System.Diagnostics; +using System.Collections.Immutable; + +namespace Ion.Extensions.Scenes.Generators; + +[Generator] +public class ScenesGenerator : IIncrementalGenerator +{ + private static readonly string CONTAINING_NAMESPACE = "Ion.Extensions.Scenes"; + private static readonly string SCENE_ATTRIBUTE_NAME = "ScenesEnumAttribute"; + private static readonly string[] VALID_SCENE_ENUM_NAMES = ["Scene", "Scenes"]; + + public void Initialize(IncrementalGeneratorInitializationContext context) + { +#if DEBUGGENERATORS + if (!Debugger.IsAttached) + { + Debugger.Launch(); + } +#endif + + Debug.WriteLine($"{nameof(ScenesGenerator)}.{nameof(Initialize)}"); + + Debug.WriteLine($"{nameof(ScenesGenerator)} CreateAttributes"); + + // Add the marker attribute to the compilation + context.RegisterPostInitializationOutput(ctx => ctx.AddSource($"{SCENE_ATTRIBUTE_NAME}.g.cs", _getScenesAttribute())); + + + IncrementalValuesProvider enumDeclarations = context.SyntaxProvider + .CreateSyntaxProvider( + predicate: static (s, _) => _isSyntaxTargetForGeneration(s), + transform: static (ctx, _) => _getSemanticTargetForGeneration(ctx)) + .Where(static m => m is not null)!; // filter out attributed enums that we don't care about + + Debug.WriteLine($"{nameof(ScenesGenerator)} Extensions"); + // Combine the selected classes with the `Compilation` + IncrementalValueProvider<(Compilation, ImmutableArray)> compilationAndEnums = context.CompilationProvider.Combine(enumDeclarations.Collect()); + context.RegisterSourceOutput(compilationAndEnums, static (spc, source) => _execute(source.Item1, source.Item2, spc)); + } + + private static SourceText _getScenesAttribute() + { + return SourceText.From($@" +namespace {CONTAINING_NAMESPACE}; + +[AttributeUsage(AttributeTargets.Enum, AllowMultiple = false)] +public class {SCENE_ATTRIBUTE_NAME} : Attribute {{ }} +", System.Text.Encoding.UTF8); + } + + static bool _isSyntaxTargetForGeneration(SyntaxNode node) + { + if (node is not EnumDeclarationSyntax e) return false; + + if (VALID_SCENE_ENUM_NAMES.Contains(e.Identifier.Text)) return true; + + return e.AttributeLists.Count > 0; + } + + static EnumDeclarationSyntax? _getSemanticTargetForGeneration(GeneratorSyntaxContext context) + { + var enumDeclarationSyntax = (EnumDeclarationSyntax)context.Node; + + if (VALID_SCENE_ENUM_NAMES.Contains(enumDeclarationSyntax.Identifier.Text)) return enumDeclarationSyntax; + + foreach (AttributeListSyntax attributeListSyntax in enumDeclarationSyntax.AttributeLists) + { + foreach (AttributeSyntax attributeSyntax in attributeListSyntax.Attributes) + { + var symbolInfo = context.SemanticModel.GetSymbolInfo(attributeSyntax); + List symbols = [symbolInfo.Symbol, ..symbolInfo.CandidateSymbols]; + + foreach(var symbol in symbols) + { + if (symbol is not ISymbol attributeSymbol) continue; + + INamedTypeSymbol attributeContainingTypeSymbol = attributeSymbol.ContainingType; + + if (attributeContainingTypeSymbol.ContainingNamespace.ToDisplayString() == CONTAINING_NAMESPACE && attributeContainingTypeSymbol.Name == SCENE_ATTRIBUTE_NAME) return enumDeclarationSyntax; + } + } + } + + return null; + } + + static void _execute(Compilation compilation, ImmutableArray enums, SourceProductionContext context) + { + if (enums.IsDefaultOrEmpty) return; + + IEnumerable distinctEnums = enums.Distinct(); + + foreach(var enumDeclarationSyntax in distinctEnums) + { + SemanticModel semanticModel = compilation.GetSemanticModel(enumDeclarationSyntax.SyntaxTree); + + var enumSymbol = semanticModel.GetDeclaredSymbol(enumDeclarationSyntax); + + if (enumSymbol is null) continue; + + var enumNamespace = enumSymbol.ContainingNamespace.ToDisplayString(); + var enumName = enumSymbol.Name; + + var sourceText = _createExtensionMethods(enumNamespace, enumName); + context.AddSource($"{enumSymbol.Name}SceneExtensions.g.cs", sourceText); + } + } + + static SourceText _createExtensionMethods(string enumNamespace, string enumName) + { + var source = new SourceWriter(); + + source.WriteLine($"namespace Ion.Extensions.Scenes;"); + + source.WriteLine($"public static class {enumName}SceneExtensions"); + source.OpenBlock(); + + #region UseScene Extension + source.WriteLine($"public static IIonApplication UseScene(this IIonApplication app, {enumNamespace}.{enumName} sceneId, Action configure) => app.UseScene((int)sceneId, configure);"); + #endregion + + source.WriteEmptyLines(1); + + #region EmitChangeScene Extension + source.WriteLine($"public static void EmitChangeScene(this IEventEmitter eventEmitter, {enumNamespace}.{enumName} nextSceneId) => eventEmitter.EmitChangeScene((int)nextSceneId);"); + #endregion + + source.CloseBlock(); + + return source.ToSourceText(); + } +} \ No newline at end of file diff --git a/Ion/Ion.Extensions.Scenes.InternalGenerators/UseDelegateServicesSceneGenerator.cs b/Ion/Ion.Extensions.Scenes.Generators/UseDelegateServicesSceneGenerator.cs similarity index 83% rename from Ion/Ion.Extensions.Scenes.InternalGenerators/UseDelegateServicesSceneGenerator.cs rename to Ion/Ion.Extensions.Scenes.Generators/UseDelegateServicesSceneGenerator.cs index 6b95da8..d20ca92 100644 --- a/Ion/Ion.Extensions.Scenes.InternalGenerators/UseDelegateServicesSceneGenerator.cs +++ b/Ion/Ion.Extensions.Scenes.Generators/UseDelegateServicesSceneGenerator.cs @@ -1,30 +1,31 @@ -using Microsoft.CodeAnalysis; +using System.Diagnostics; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Text; using SourceGeneratorUtils; -namespace Ion.Extensions.Scenes.InternalGenerators; +namespace Ion.Extensions.Scenes.Generators; [Generator] public class UseDelegateServicesSceneGenerator : IIncrementalGenerator { private const int MAX_SERVICES = 8; - private static readonly string[] STAGES = new[] { "Init", "First", "FixedUpdate", "Update", "Render", "Last", "Destroy" }; + private static readonly string[] STAGES = ["Init", "First", "FixedUpdate", "Update", "Render", "Last", "Destroy"]; public void Initialize(IncrementalGeneratorInitializationContext context) { #if DEBUGGENERATORS - if (!Debugger.IsAttached) - { - Debugger.Launch(); - } + //if (!Debugger.IsAttached) + //{ + // Debugger.Launch(); + //} #endif // Add the marker attribute to the compilation - context.RegisterPostInitializationOutput(ctx => ctx.AddSource("UseDelegateServiceSceneExtensions.g.cs", GetUseDelegateServiceExtensions())); + context.RegisterPostInitializationOutput(ctx => ctx.AddSource("UseDelegateServiceSceneExtensions.g.cs", _getUseDelegateServiceExtensions())); } - private static SourceText GetUseDelegateServiceExtensions() + private static SourceText _getUseDelegateServiceExtensions() { var source = new SourceWriter(); source.WriteLine("using Microsoft.Extensions.DependencyInjection;"); diff --git a/Ion/Ion.Extensions.Scenes.InternalGenerators/Ion.Extensions.Scenes.InternalGenerators.csproj b/Ion/Ion.Extensions.Scenes.InternalGenerators/Ion.Extensions.Scenes.InternalGenerators.csproj deleted file mode 100644 index 3541cb5..0000000 --- a/Ion/Ion.Extensions.Scenes.InternalGenerators/Ion.Extensions.Scenes.InternalGenerators.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - netstandard2.0 - false - enable - true - Preview - True - True - true - True - Debug;Release;DebugGenerators - - - - - - - - - - - - - - - - - diff --git a/Ion/Ion.Extensions.Scenes/SceneBuilder.cs b/Ion/Ion.Extensions.Scenes/SceneBuilder.cs index ae851a2..efceff2 100644 --- a/Ion/Ion.Extensions.Scenes/SceneBuilder.cs +++ b/Ion/Ion.Extensions.Scenes/SceneBuilder.cs @@ -2,7 +2,7 @@ namespace Ion.Extensions.Scenes; -internal class SceneBuilder : ISceneBuilder +internal class SceneBuilder(int sceneId, IConfiguration config, IServiceProvider services) : ISceneBuilder { private readonly IMiddlewarePipelineBuilder _init = new MiddlewarePipelineBuilder(); private readonly IMiddlewarePipelineBuilder _first = new MiddlewarePipelineBuilder(); @@ -12,18 +12,11 @@ internal class SceneBuilder : ISceneBuilder private readonly IMiddlewarePipelineBuilder _last = new MiddlewarePipelineBuilder(); private readonly IMiddlewarePipelineBuilder _destroy = new MiddlewarePipelineBuilder(); - public int SceneId { get; } + public int SceneId { get; } = sceneId; - public IConfiguration Configuration { get; } + public IConfiguration Configuration { get; } = config; - public IServiceProvider Services { get; } - - public SceneBuilder(int sceneId, IConfiguration config, IServiceProvider services) - { - SceneId = sceneId; - Configuration = config; - Services = services; - } + public IServiceProvider Services { get; } = services; public ISceneBuilder UseInit(Func middleware) { @@ -68,9 +61,9 @@ public ISceneBuilder UseDestroy(Func middlew return this; } - internal Scene Build() + internal SceneInstance Build() { - return new Scene(SceneId) + return new SceneInstance(SceneId) { Init = _init.Build(), First = _first.Build(), diff --git a/Ion/Ion.Extensions.Scenes/Systems/SceneSystem.cs b/Ion/Ion.Extensions.Scenes/Systems/SceneSystem.cs index abddf8b..4038c43 100644 --- a/Ion/Ion.Extensions.Scenes/Systems/SceneSystem.cs +++ b/Ion/Ion.Extensions.Scenes/Systems/SceneSystem.cs @@ -6,7 +6,7 @@ namespace Ion.Extensions.Scenes; -internal delegate Scene SceneBuilderFactory(IConfiguration config, IServiceProvider services); +internal delegate SceneInstance SceneBuilderFactory(IConfiguration config, IServiceProvider services); /// /// Creates a new SceneManager instance, keeping a reference to the service provider. @@ -23,7 +23,7 @@ ITraceTimer trace private readonly ITraceTimer _trace = trace; private readonly Dictionary _scenesBuilders = new(); - private Scene? _activeScene; + private SceneInstance? _activeScene; private Transition? _activeTransition; private IServiceScope? _activeScope; private int _nextSceneId = 0; diff --git a/Ion/Ion/Ion.csproj b/Ion/Ion/Ion.csproj index 8200bae..f5a2294 100644 --- a/Ion/Ion/Ion.csproj +++ b/Ion/Ion/Ion.csproj @@ -1,4 +1,4 @@ - + net8.0 enable @@ -11,6 +11,7 @@ +