Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Synesthesia.AssetGenerators/AssetGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Synesthesia.Engine.Graphics.Textures;
using Synesthesia.Engine.Platform.Host;
using Synesthesia.Engine.Resources;
using SynesthesiaUtil;
using Synesthesia.Utils;

namespace Synesthesia.AssetGenerators;

Expand Down
51 changes: 2 additions & 49 deletions Synesthesia.Demo/Demo.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
锘縰sing System.Numerics;
using Synesthesia.Engine;
using Synesthesia.Engine.Components.Two.Default;
using Synesthesia.Engine.Graphics.Layout;
using Synesthesia.Engine.Graphics.Two.Container;
锘縰sing Synesthesia.Engine;
using Synesthesia.Engine.Platform.Host;
using Synesthesia.Engine.Util.Bindables;

namespace Synesthesia.Demo;

internal static class Demo
{
private static DefaultButton? button;
private static DefaultTextbox? textbox;
private static DefaultToggle? toggle;

[STAThread]
private static void Main(string[] args)
{
Expand All @@ -23,46 +15,7 @@ private static void Main(string[] args)

game.OnInitialized.Subscribe(_ =>
{
game.DrawableScene2D.Children =
[
new FillFlowContainer2D
{
AutoSizeAxes = Axes.Both,
Direction = Direction.Vertical,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Spacing = 10,
Children =
[
button = new DefaultButton
{
Size = new Vector2(140, 50),
Text = "Testing",
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
ButtonStyle = DefaultButton.Style.Tertiary,
},

toggle = new DefaultToggle
{
Size = new Vector2(65, 24),
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Checked = toggled
},

textbox = new DefaultTextbox
{
Size = new Vector2(200, 40),
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
}
]
},
];

textbox.Text.Value = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
textbox.IsPassword.BindTo(toggled);
game.DrawableScene2D.Children = [];
});

game.Run();
Expand Down
2 changes: 1 addition & 1 deletion Synesthesia.Engine/Animations/Animation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Synesthesia.Engine.Animations.Easings;
using Synesthesia.Engine.Graphics.Two;
using SynesthesiaUtil.Extensions;
using Synesthesia.Utils.Extensions;

namespace Synesthesia.Engine.Animations;

Expand Down
3 changes: 2 additions & 1 deletion Synesthesia.Engine/Animations/AnimationSequence.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using SynesthesiaUtil.Extensions;

using Synesthesia.Utils.Extensions;

namespace Synesthesia.Engine.Animations;

public sealed class AnimationSequence : IAnimation
{
public readonly List<IAnimation> Animations = [];

Check warning on line 8 in Synesthesia.Engine/Animations/AnimationSequence.cs

View workflow job for this annotation

GitHub Actions / build

Prefer using collection abstraction instead of implementation (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0016.md)

public AnimationState State { get; set; } = AnimationState.Ready;

Expand Down
2 changes: 1 addition & 1 deletion Synesthesia.Engine/Animations/Animator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Synesthesia.Engine.Timing;
using Synesthesia.Engine.Util.Statistics;
using SynesthesiaUtil.Extensions;
using Synesthesia.Utils.Extensions;

namespace Synesthesia.Engine.Animations;

Expand Down
2 changes: 1 addition & 1 deletion Synesthesia.Engine/Animations/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using Synesthesia.Engine.Animations.Easings;
using SynesthesiaUtil.Extensions;
using Synesthesia.Utils.Extensions;

namespace Synesthesia.Engine.Animations;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using Synesthesia.Engine.Util;
using Synesthesia.Engine.Util.Bindables;
using Synesthesia.Engine.Util.Pooling;
using SynesthesiaUtil.Extensions;
using Synesthesia.Utils.Extensions;

namespace Synesthesia.Engine.Components.Two.Barebones;

Expand Down
4 changes: 2 additions & 2 deletions Synesthesia.Engine/Components/Two/Debug/EngineDebugOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

using System.Numerics;
using Synesthesia.Engine.Animations.Easings;
using Synesthesia.Engine.Extensions;
using Synesthesia.Engine.Graphics.Layout;
using Synesthesia.Engine.Graphics.Two;
using Synesthesia.Engine.Graphics.Two.Container;
using Synesthesia.Engine.Input;
using Synesthesia.Engine.Input.ActionBindings;
using Synesthesia.Engine.Timing;
using SynesthesiaUtil;
using SynesthesiaUtil.Extensions;
using Synesthesia.Utils;

namespace Synesthesia.Engine.Components.Two.Debug;

Expand Down
5 changes: 3 additions & 2 deletions Synesthesia.Engine/Components/Two/Debug/StatisticsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using Synesthesia.Engine.Timing;
using Synesthesia.Engine.Util;
using Synesthesia.Engine.Util.Statistics;
using SynesthesiaUtil;
using Synesthesia.Utils;

namespace Synesthesia.Engine.Components.Two.Debug;

Expand All @@ -30,7 +30,8 @@ public class StatisticsPanel : EngineDebugElement
new EngineStatisticLine(EngineStatistics.Type.Drawables),
new DrawStatisticLine(DrawStatistics.Type.Invalidations),
new Spacer(),
new DrawStatisticLine(DrawStatistics.Type.DrawCalls),
new DrawStatisticLine(DrawStatistics.Type.DrawCalls2D),
new DrawStatisticLine(DrawStatistics.Type.DrawCalls3D),
new DrawStatisticLine(DrawStatistics.Type.TextureBinds),
new DrawStatisticLine(DrawStatistics.Type.ShaderBinds),
new DrawStatisticLine(DrawStatistics.Type.TextureUploadQueue),
Expand Down
4 changes: 2 additions & 2 deletions Synesthesia.Engine/Extensions/SDL3Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using Synesthesia.Engine.Logging;
using Synesthesia.Engine.Platform;
using Synesthesia.Engine.Util.Exceptions;
using SynesthesiaUtil;
using SynesthesiaUtil.Extensions;
using Synesthesia.Utils;
using Synesthesia.Utils.Extensions;

namespace Synesthesia.Engine.Extensions;

Expand Down
5 changes: 3 additions & 2 deletions Synesthesia.Engine/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
/// </code>
/// </example>
public readonly IResourceStore<Texture> TextureResourceStore = new ResourceStoreBuilder<Texture>()
.AddLoaders(new Dictionary<string, Func<Stream, string, Texture>>

Check warning on line 56 in Synesthesia.Engine/Game.cs

View workflow job for this annotation

GitHub Actions / build

Use an overload that has a IEqualityComparer<string> or IComparer<string> parameter (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0002.md)
{
{ "png", (stream, _) => ResourceLoaders.LoadTexture(stream) },
{ "bmp", (stream, _) => ResourceLoaders.LoadTexture(stream) },
Expand All @@ -70,7 +70,7 @@
.Build();

public readonly IResourceStore<TextureAtlas> TextureAtlasResourceStore = new ResourceStoreBuilder<TextureAtlas>()
.AddLoaders(new Dictionary<string, Func<Stream, string, TextureAtlas>>

Check warning on line 73 in Synesthesia.Engine/Game.cs

View workflow job for this annotation

GitHub Actions / build

Use an overload that has a IEqualityComparer<string> or IComparer<string> parameter (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0002.md)
{
{ ResourceLoaders.TEXTURE_ATLAS_FILE_EXT, (stream, _) => ResourceLoaders.LoadFromTextureAtlasFile(stream) },
})
Expand Down Expand Up @@ -102,7 +102,7 @@
/// </code>
/// </example>
public readonly IResourceStore<Font> FontResourceStore = new ResourceStoreBuilder<Font>()
.AddLoaders(new Dictionary<string, Func<Stream, string, Font>>

Check warning on line 105 in Synesthesia.Engine/Game.cs

View workflow job for this annotation

GitHub Actions / build

Use an overload that has a IEqualityComparer<string> or IComparer<string> parameter (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0002.md)
{
{ "ttf", ResourceLoaders.LoadFont },
{ ResourceLoaders.FONT_ATLAS_FILE_EXT, ResourceLoaders.LoadFontFromAtlas },
Expand Down Expand Up @@ -168,9 +168,10 @@
if (initialized) throw new InvalidOperationException("Game is already initialized");

WindowHost.Initialize();
renderThread = new RenderThread(WindowHost.Renderer);
renderThread = new RenderThread(WindowHost.GraphicsDevice);

DependencyContainer.AddSingleton(renderThread.Renderer);
DependencyContainer.AddSingleton(renderThread.GraphicsDevice);
DependencyContainer.AddSingleton(renderThread.GraphicsDevice.Renderer2D);
DependencyContainer.AddSingleton(renderThread);

WindowHost.Surface.ReleaseOwnership();
Expand Down
10 changes: 4 additions & 6 deletions Synesthesia.Engine/Graphics/Textures/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ public class Font(int size, FontAtlas atlas) : IDisposable
public readonly int Size = size;
public readonly FontAtlas Atlas = atlas;

public static readonly IBinaryCodec<Font> BINARY_CODEC = BinaryCodec.Of
(
BinaryCodec.INT, f => f.Size,
FontAtlas.BINARY_CODEC, f => f.Atlas,
(size, atlas) => new Font(size, atlas)
);
public static readonly IBinaryCodec<Font> BINARY_CODEC = BinaryCodecs.For<Font>()
.Field(BinaryCodecs.INT, f => f.Size)
.Field(FontAtlas.BINARY_CODEC, f => f.Atlas)
.Build((size, atlas) => new Font(size, atlas));

public override string ToString() => $"Font(Size={Size}, Atlas={Atlas})";

Expand Down
15 changes: 7 additions & 8 deletions Synesthesia.Engine/Graphics/Textures/FontAtlas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ public class FontAtlas : IDisposable

public override string ToString() => $"FontAtlas(TextureAtlas={TextureAtlas}, LineHeight={LineHeight}, Ascent={Ascent}, Descent={Descent}, Glyphs={Glyphs.Count})";

public static readonly IBinaryCodec<FontAtlas> BINARY_CODEC = BinaryCodec.Of
(
TextureAtlas.BINARY_CODEC, f => f.TextureAtlas,
BinaryCodec.INT.MapTo(GlyphInfo.BINARY_CODEC), f => f.Glyphs,
BinaryCodec.FLOAT, f => f.LineHeight,
BinaryCodec.FLOAT, f => f.Ascent,
BinaryCodec.FLOAT, f => f.Descent,
(atlas, glyphs, lineHeight, ascent, descent) => new FontAtlas
public static readonly IBinaryCodec<FontAtlas> BINARY_CODEC = BinaryCodecs.For<FontAtlas>()
.Field(TextureAtlas.BINARY_CODEC, f => f.TextureAtlas)
.Field(BinaryCodecs.INT.MapTo(GlyphInfo.BINARY_CODEC), f => f.Glyphs)
.Field(BinaryCodecs.FLOAT, f => f.LineHeight)
.Field(BinaryCodecs.FLOAT, f => f.Ascent)
.Field(BinaryCodecs.FLOAT, f => f.Descent)
.Build((atlas, glyphs, lineHeight, ascent, descent) => new FontAtlas
{
TextureAtlas = atlas,
Glyphs = glyphs,
Expand Down
12 changes: 5 additions & 7 deletions Synesthesia.Engine/Graphics/Textures/GlyphInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ public readonly struct GlyphInfo(int regionHandle, Vector2 bearing, float advanc
public readonly Vector2 Bearing = bearing;
public readonly float Advance = advance;

public static readonly IBinaryCodec<GlyphInfo> BINARY_CODEC = BinaryCodec.Of
(
BinaryCodec.INT, g => g.RegionHandle,
ExtraCodecs.VECTOR_2, g => g.Bearing,
BinaryCodec.FLOAT, g => g.Advance,
(handle, bearing, advance) => new GlyphInfo(handle, bearing, advance)
);
public static readonly IBinaryCodec<GlyphInfo> BINARY_CODEC = BinaryCodecs.For<GlyphInfo>()
.Field(BinaryCodecs.INT, g => g.RegionHandle)
.Field(ExtraCodecs.VECTOR_2, g => g.Bearing)
.Field(BinaryCodecs.FLOAT, g => g.Advance)
.Build((handle, bearing, advance) => new GlyphInfo(handle, bearing, advance));
}
2 changes: 1 addition & 1 deletion Synesthesia.Engine/Graphics/Textures/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Texture(TextureData textureData, bool uploadImmediately)

public void EnqueueUpload()
{
OpenGlRenderer.TEXTURE_UPLOAD_QUEUE.Enqueue(this);
GraphicsDevice.TEXTURE_UPLOAD_QUEUE.Enqueue(this);
UploadQueued = true;
}

Expand Down
14 changes: 6 additions & 8 deletions Synesthesia.Engine/Graphics/Textures/TextureAtlas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ public TextureAtlas(int width, int height, Texture texture, Dictionary<int, Text

public bool IsUploaded => Texture.IsUploaded;

public static readonly IBinaryCodec<TextureAtlas> BINARY_CODEC = BinaryCodec.Of
(
BinaryCodec.INT, a => a.Width,
BinaryCodec.INT, a => a.Height,
TextureData.BINARY_CODEC.Transform<Texture>(texture => texture.TextureData, textureData => new Texture(textureData, true)), a => a.Texture,
BinaryCodec.INT.MapTo(TextureRegion.BINARY_CODEC), a => a.TextureRegions,
(width, height, texture, areas) => new TextureAtlas(width, height, texture, areas)
);
public static readonly IBinaryCodec<TextureAtlas> BINARY_CODEC = BinaryCodecs.For<TextureAtlas>()
.Field(BinaryCodecs.INT, a => a.Width)
.Field(BinaryCodecs.INT, a => a.Height)
.Field(TextureData.BINARY_CODEC.Transform<Texture>(texture => texture.TextureData, textureData => new Texture(textureData, true)), a => a.Texture)
.Field(BinaryCodecs.INT.MapTo(TextureRegion.BINARY_CODEC), a => a.TextureRegions)
.Build((width, height, texture, areas) => new TextureAtlas(width, height, texture, areas));

public TextureRegion GetRegion(int handle) => GetRegionOrNull(handle) ?? throw new InvalidOperationException($"No texture in atlas with handle {handle}");

Expand Down
12 changes: 6 additions & 6 deletions Synesthesia.Engine/Graphics/Textures/TextureData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class TextureData(int width, int height, byte[] data, PixelFormat pixelFo
public byte[] Data { get; set; } = data;
public PixelFormat PixelFormat { get; set; } = pixelFormat;

public static readonly IBinaryCodec<TextureData> BINARY_CODEC = BinaryCodec.Of<int, int, byte[], PixelFormat, TextureData>(
BinaryCodec.INT, d => d.Width,
BinaryCodec.INT, d => d.Height,
BinaryCodec.BYTE_ARRAY, d => d.Data,
BinaryCodec.Enum<PixelFormat>(), d => d.PixelFormat,
(w, h, data, format) => new TextureData(w, h, data, format));
public static readonly IBinaryCodec<TextureData> BINARY_CODEC = BinaryCodecs.For<TextureData>()
.Field(BinaryCodecs.INT, d => d.Width)
.Field(BinaryCodecs.INT, d => d.Height)
.Field(BinaryCodecs.BYTE_ARRAY, d => d.Data)
.Field(BinaryCodecs.Enum<PixelFormat>(), d => d.PixelFormat)
.Build((w, h, data, format) => new TextureData(w, h, data, format));

public override string ToString() => $"TextureData(Width={Width}, Height={Height}, Data={Data.Length} PixelFormat={PixelFormat})";
}
10 changes: 4 additions & 6 deletions Synesthesia.Engine/Graphics/Textures/TextureRegion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ public readonly struct TextureRegion(RectangleF uvRect, Vector2 size)
public readonly RectangleF UvRect = uvRect;
public readonly Vector2 Size = size;

public static readonly IBinaryCodec<TextureRegion> BINARY_CODEC = BinaryCodec.Of
(
ExtraCodecs.RECTANGLE_F, r => r.UvRect,
ExtraCodecs.VECTOR_2, r => r.Size,
(uv, size) => new TextureRegion(uv, size)
);
public static readonly IBinaryCodec<TextureRegion> BINARY_CODEC = BinaryCodecs.For<TextureRegion>()
.Field(ExtraCodecs.RECTANGLE_F, r => r.UvRect)
.Field(ExtraCodecs.VECTOR_2, r => r.Size)
.Build((uv, size) => new TextureRegion(uv, size));
}
4 changes: 2 additions & 2 deletions Synesthesia.Engine/Graphics/Two/Box2d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
using Synesthesia.Engine.Graphics.Layout;
using Synesthesia.Engine.Graphics.Textures;
using Synesthesia.Engine.Platform.Render;
using SynesthesiaUtil.Extensions;
using Synesthesia.Utils.Extensions;

namespace Synesthesia.Engine.Graphics.Two;

public class Box2D : Drawable2D
{
[Singleton]
private OpenGlRenderer renderer = null!;
private Renderer2D renderer = null!;

private RectangleF uvCoords = new(0, 0, 1, 1);
private Vector2 drawSize;
Expand Down
4 changes: 2 additions & 2 deletions Synesthesia.Engine/Graphics/Two/Circle2d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
using Synesthesia.Engine.Dependency;
using Synesthesia.Engine.Graphics.Layout;
using Synesthesia.Engine.Platform.Render;
using SynesthesiaUtil.Extensions;
using Synesthesia.Utils.Extensions;

namespace Synesthesia.Engine.Graphics.Two;

public class Circle2D : Drawable2D
{
[Singleton]
private OpenGlRenderer renderer = null!;
private Renderer2D renderer = null!;

public Color Color
{
Expand Down
25 changes: 14 additions & 11 deletions Synesthesia.Engine/Graphics/Two/CompositeDrawable2d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Synesthesia.Engine.Platform.Render;
using Synesthesia.Engine.Timing;
using Synesthesia.Engine.Util.Pooling;
using SynesthesiaUtil.Extensions;
using Synesthesia.Utils.Extensions;

namespace Synesthesia.Engine.Graphics.Two;

Expand All @@ -25,7 +25,10 @@ public class CompositeDrawable2D : Drawable2D
protected internal List<Drawable2D> InternalChildren = [];

[Singleton]
private OpenGlRenderer renderer = null!;
private GraphicsDevice graphicsDevice = null!;

[Singleton]
private Renderer2D renderer = null!;

public float CornerRadius
{
Expand Down Expand Up @@ -179,15 +182,15 @@ protected override void OnDraw2d()

if (Masking)
{
renderer.VertexBatch2D.Flush();
graphicsDevice.FlushAllVertexBuffers();

renderer.BeginStencil();
renderer.BeginStencilMask();
graphicsDevice.BeginStencil();
graphicsDevice.BeginStencilMask();

drawStencilQuad();

renderer.VertexBatch2D.Flush();
renderer.EndStencilMask();
graphicsDevice.FlushAllVertexBuffers();
graphicsDevice.EndStencilMask();
}

using (snapshot)
Expand All @@ -200,13 +203,13 @@ protected override void OnDraw2d()

if (Masking)
{
renderer.VertexBatch2D.Flush();
renderer.FlushVertexBatch();

renderer.BeginStencilRestore();
graphicsDevice.BeginStencilRestore();
drawStencilQuad();
renderer.VertexBatch2D.Flush();
renderer.FlushVertexBatch();

renderer.EndStencil();
graphicsDevice.EndStencil();
}

if (BorderThickness > 0)
Expand Down
Loading
Loading