Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
BlazorLogicalResolutionBinding.cs
2
4
8internal sealed class BlazorLogicalResolutionBinding : IDisposable
9{
10 private readonly RenderSurfaceAdapterBase _adapter;
11 private readonly Action<float> _applyScale;
12 private readonly int _logicalWidth;
13 private readonly int _logicalHeight;
14 private bool _established;
15 private bool _disposed;
16
22 internal BlazorLogicalResolutionBinding(
23 RenderSurfaceAdapterBase adapter,
24 int logicalWidth,
25 int logicalHeight,
26 Action<float> applyScale)
27 {
28 ArgumentNullException.ThrowIfNull(adapter);
29 ArgumentNullException.ThrowIfNull(applyScale);
30 ArgumentOutOfRangeException.ThrowIfNegativeOrZero(logicalWidth);
31 ArgumentOutOfRangeException.ThrowIfNegativeOrZero(logicalHeight);
32
33 _adapter = adapter;
34 _logicalWidth = logicalWidth;
35 _logicalHeight = logicalHeight;
36 _applyScale = applyScale;
37
38 // Subscribe first so a paint between subscription and the size check is not missed.
39 _adapter.Resized += OnResized;
40 try
41 {
42 TryEstablish(_adapter.Width, _adapter.Height);
43 }
44 catch
45 {
46 _adapter.Resized -= OnResized;
47 throw;
48 }
49 }
50
53 private void OnResized(RenderSurfaceAdapterResizedEventArgs args)
54 => TryEstablish(args.NewWidth, args.NewHeight);
55
59 private void TryEstablish(int width, int height)
60 {
61 // WebGL uses a 1x1 placeholder until its first real paint.
62 if (_disposed || _established || width <= 1 || height <= 1)
63 return;
64
65 // Round physical size outwards: never crop the requested logical game board.
66 float scale = Math.Max((float)_logicalWidth / width, (float)_logicalHeight / height);
67 _applyScale(scale);
68 _established = true;
69 _adapter.Resized -= OnResized;
70 }
71
73 public void Dispose()
74 {
75 if (_disposed)
76 return;
77
78 _disposed = true;
79 _adapter.Resized -= OnResized;
80 }
81}