Gondwana Game Engine Development (master) - 2.7.0
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
EngineConfiguration.cs
5using Newtonsoft.Json;
6
8
12[JsonObject]
13public partial class EngineConfiguration
14{
15 private float _renderScale = 1f;
16
22 public float RenderScale
23 {
24 get => _renderScale;
25 set
26 {
27 if (!float.IsFinite(value) || value <= 0)
28 throw new ArgumentOutOfRangeException(nameof(value), "RenderScale must be finite and positive.");
29
30 if (_renderScale == value)
31 return;
32
33 var surfaces = RenderSurfaceHostRegistry.Snapshot();
34
35 // Validate every dimension before publishing intent or queuing any changes.
36 foreach (var surface in surfaces)
37 {
38 if (surface.RenderSurfaceAdapter is { } adapter)
39 {
40 PresentationTransform.ScaleDimension(adapter.Width, value);
41 PresentationTransform.ScaleDimension(adapter.Height, value);
42 }
43 }
44
45 _renderScale = value;
46
47 foreach (var surface in surfaces)
48 surface.RequestRenderScale(value);
49 }
50 }
51
52 private RenderScalingFilter _renderScalingFilter = RenderScalingFilter.Linear;
53
56 {
57 get => _renderScalingFilter;
58 set
59 {
60 if (!Enum.IsDefined(value))
61 throw new ArgumentOutOfRangeException(nameof(value));
62
63 _renderScalingFilter = value;
64
65 foreach (var surface in RenderSurfaceHostRegistry.Snapshot())
66 surface.InvalidatePresentation();
67 }
68 }
69
70 private int _targetFPS = 60;
71
84 public int TargetFPS
85 {
86 get => _targetFPS;
87 set
88 {
89 _targetFPS = value < 0 ? 0 : value;
90
91 // Propagate to all active GPU backbuffers so their TargetFps stays in sync.
92 foreach (var surface in RenderSurfaceHostRegistry.Snapshot())
93 {
94 if (surface.Backbuffer is GpuBackbuffer gpuBb)
95 gpuBb.TargetFps = _targetFPS;
96 }
97 }
98 }
99
100 private int _timerDrivenSimulationRate = 120;
101
108 {
109 get => _timerDrivenSimulationRate;
110 set => _timerDrivenSimulationRate = Math.Max(1, value);
111 }
112
113 private int _maxTimerDrivenSimulationSteps = 8;
114
122 {
123 get => _maxTimerDrivenSimulationSteps;
124 set => _maxTimerDrivenSimulationSteps = Math.Max(1, value);
125 }
126
127 private float _startInitializationWaitTimeout = 30f;
128
138 {
139 get => _startInitializationWaitTimeout;
140 set => _startInitializationWaitTimeout =
141 !float.IsFinite(value) || value <= 0f
142 ? 0.001f
143 : Math.Min(value, (float)TimeSpan.MaxValue.TotalSeconds);
144 }
145
146 private bool _vSync = true;
147
171 public bool VSync
172 {
173 get => _vSync;
174 set
175 {
176 _vSync = value;
177
178 // Propagate to all active GPU backbuffers so their VSync stays in sync.
179 foreach (var surface in RenderSurfaceHostRegistry.Snapshot())
180 {
181 if (surface.Backbuffer is GpuBackbuffer gpuBb)
182 gpuBb.VSync = _vSync;
183 }
184 }
185 }
186
187 private int _msaaSampleCount = 1;
188
217 {
218 get => _msaaSampleCount;
219 set
220 {
221 _msaaSampleCount = value < 1 ? 1 : value;
222
223 // Propagate to all active GPU backbuffers so their MsaaSampleCount stays in sync.
224 foreach (var surface in RenderSurfaceHostRegistry.Snapshot())
225 {
226 if (surface.Backbuffer is GpuBackbuffer gpuBb)
227 gpuBb.MsaaSampleCount = _msaaSampleCount;
228 }
229 }
230 }
231
232 private double _samplingTimeForCPS = 1.5;
233
242 [Obsolete(
243 "Legacy CPS/FPS sampling is deprecated. Use Engine.Profiler.Configure(...) for runtime telemetry.",
244 DiagnosticId = "GOND0001")]
245 public double SamplingTimeForCPS
246 {
247 get => _samplingTimeForCPS;
248 set => _samplingTimeForCPS = value < 0 ? 0 : value;
249 }
250
257 [JsonIgnore]
258 [Obsolete(
259 "Legacy CPS/FPS sampling is deprecated. Use Engine.Profiler.Configure(...) for runtime telemetry.",
260 DiagnosticId = "GOND0001")]
261 public long SamplingTimeForCPSTicks => LegacyCpsSamplingTicks;
262
266 internal double LegacyCpsSamplingTime
267 {
268 get => _samplingTimeForCPS;
269 set => _samplingTimeForCPS = value < 0 ? 0 : value;
270 }
271
275 internal long LegacyCpsSamplingTicks =>
276 (long)(_samplingTimeForCPS * HighResTimer.TicksPerSecond);
277
283 public double TimeBetweenKeyboardEvents { get; set; } = 0.03;
284
285 private double _gamepadConnectionUpdateFrequencyHz = 0.2;
286
296 {
297 get => _gamepadConnectionUpdateFrequencyHz;
298 set => _gamepadConnectionUpdateFrequencyHz =
299 double.IsFinite(value) && value > 0d ? value : 0d;
300 }
301
302 private double _gamepadPollFrequencyHz = 60d;
303
312 {
313 get => _gamepadPollFrequencyHz;
314 set => _gamepadPollFrequencyHz =
315 double.IsFinite(value) && value > 0d ? value : 0d;
316 }
317
324 public double TimeBetweenGamepadEvents { get; set; } = 0.03;
325
331 public double TimeBetweenMouseEvents { get; set; } = 0.03;
332
338 public double TimeBetweenTouchEvents { get; set; } = 0.03;
339
355 public EngineLoggingMode LoggingMode { get; set; } = EngineLoggingMode.Asynchronous;
356
357 private int _loggingQueueCapacity = 8192;
358
369 {
370 get => _loggingQueueCapacity;
371 set
372 {
373 if (value <= 0)
374 throw new ArgumentOutOfRangeException(nameof(value), "Capacity must be > 0.");
375
376 _loggingQueueCapacity = value;
377 }
378 }
379
384 public bool FlushAsyncLogsOnShutdown { get; set; } = true;
385
389 public List<StateFileMount>? StateFiles { get; set; }
390
391 #region ConfigurationSections
392
427 [JsonProperty]
428 public Dictionary<string, Dictionary<string, string>> ConfigurationSections { get; set; } = new();
429
437 public bool HasConfigurationSection(string section)
438 {
439 return ConfigurationSections.ContainsKey(section);
440 }
441
449 public Dictionary<string, string> CreateConfigurationSection(string section)
450 {
451 ArgumentException.ThrowIfNullOrWhiteSpace(section);
452
453 if (!ConfigurationSections.TryGetValue(section, out var values))
454 {
455 values = new Dictionary<string, string>();
456 ConfigurationSections[section] = values;
457 }
458
459 return values;
460 }
461
469 public bool RemoveConfigurationSection(string section)
470 {
471 ArgumentException.ThrowIfNullOrWhiteSpace(section);
472
473 return ConfigurationSections.Remove(section);
474 }
475
483 public IReadOnlyDictionary<string, string>? GetConfigurationSection(string section)
484 {
485 ArgumentException.ThrowIfNullOrWhiteSpace(section);
486
487 return ConfigurationSections.TryGetValue(section, out var values)
488 ? values
489 : null;
490 }
491
500 public bool HasConfigurationValue(string section, string key)
501 {
502 ArgumentException.ThrowIfNullOrWhiteSpace(section);
503 ArgumentException.ThrowIfNullOrWhiteSpace(key);
504
505 return ConfigurationSections.TryGetValue(section, out var values)
506 && values.ContainsKey(key);
507 }
508
518 public string? GetConfigurationValue(string section, string key, string? defaultValue = null)
519 {
520 ArgumentException.ThrowIfNullOrWhiteSpace(section);
521 ArgumentException.ThrowIfNullOrWhiteSpace(key);
522
523 return ConfigurationSections.TryGetValue(section, out var values)
524 && values.TryGetValue(key, out var value)
525 ? value
526 : defaultValue;
527 }
528
535 public void SetConfigurationValue(string section, string key, string value)
536 {
537 ArgumentException.ThrowIfNullOrWhiteSpace(section);
538 ArgumentException.ThrowIfNullOrWhiteSpace(key);
539 ArgumentNullException.ThrowIfNull(value);
540
541 var values = CreateConfigurationSection(section);
542 values[key] = value;
543 }
544
553 public bool RemoveConfigurationValue(string section, string key)
554 {
555 ArgumentException.ThrowIfNullOrWhiteSpace(section);
556 ArgumentException.ThrowIfNullOrWhiteSpace(key);
557
558 return ConfigurationSections.TryGetValue(section, out var values)
559 && values.Remove(key);
560 }
561
569 public bool ClearConfigurationSection(string section)
570 {
571 ArgumentException.ThrowIfNullOrWhiteSpace(section);
572
573 if (!ConfigurationSections.TryGetValue(section, out var values))
574 return false;
575
576 values.Clear();
577 return true;
578 }
579
584 {
585 ConfigurationSections.Clear();
586 }
587
599 public Dictionary<string, string>? this[string section]
600 {
601 get
602 {
603 ArgumentException.ThrowIfNullOrWhiteSpace(section);
604
605 return ConfigurationSections.TryGetValue(section, out var values)
606 ? values
607 : null;
608 }
609 set
610 {
611 ArgumentException.ThrowIfNullOrWhiteSpace(section);
612
613 if (value == null)
614 {
615 ConfigurationSections.Remove(section);
616 }
617 else
618 {
619 ConfigurationSections[section] = value;
620 }
621 }
622 }
623
636 public string? this[string section, string key]
637 {
638 get
639 {
640 ArgumentException.ThrowIfNullOrWhiteSpace(section);
641 ArgumentException.ThrowIfNullOrWhiteSpace(key);
642
643 return ConfigurationSections.TryGetValue(section, out var values)
644 && values.TryGetValue(key, out var value)
645 ? value
646 : null;
647 }
648 set
649 {
650 ArgumentException.ThrowIfNullOrWhiteSpace(section);
651 ArgumentException.ThrowIfNullOrWhiteSpace(key);
652
653 if (value == null)
654 {
655 if (ConfigurationSections.TryGetValue(section, out var values))
656 {
657 values.Remove(key);
658 }
659
660 return;
661 }
662
663 if (!ConfigurationSections.TryGetValue(section, out var sectionValues))
664 {
665 sectionValues = new Dictionary<string, string>();
666 ConfigurationSections[section] = sectionValues;
667 }
668
669 sectionValues[key] = value;
670 }
671 }
672
673 #endregion ConfigurationSections
674}
Settings used by the engine when cycling.
int LoggingQueueCapacity
Maximum number of queued log events when LoggingMode is EngineLoggingMode.Asynchronous....
bool RemoveConfigurationValue(string section, string key)
Removes a configuration value from the specified section.
RenderScalingFilter RenderScalingFilter
Filtering for the finished Backbuffer image; independent of View.Zoom and tile filtering.
long SamplingTimeForCPSTicks
Total number of system ticks between each legacy CPS sampling.
int TimerDrivenSimulationRate
Gets or sets the number of fixed simulation updates performed per second in timer-driven mode....
bool RemoveConfigurationSection(string section)
Removes the specified configuration section and all key/value pairs contained within it.
double TimeBetweenMouseEvents
Minimum time (in seconds) allowed between Mouse events. Use this to prevent flooding the system with ...
void ClearConfigurationSections()
Removes all configuration sections and all contained key/value pairs.
double TimeBetweenGamepadEvents
Minimum time (in seconds) allowed between Gamepad events. Use this to prevent flooding the system wit...
IReadOnlyDictionary< string, string >? GetConfigurationSection(string section)
Gets a read-only view of all key/value pairs in the specified configuration section.
double GamepadPollFrequencyHz
Gets or sets how often the engine refreshes the state of already-connected gamepads.
float RenderScale
Establishes logical Backbuffer dimensions from current adapter dimensions. Default is one; values abo...
string? GetConfigurationValue(string section, string key, string? defaultValue=null)
Gets a configuration value from the specified section.
float StartInitializationWaitTimeout
Gets or sets how long Engine.Start(SynchronizationContext) waits when another thread is already runni...
List< StateFileMount >? StateFiles
Optional collection of serialized EngineStates to mount at initialization.
void SetConfigurationValue(string section, string key, string value)
Sets a configuration value in the specified section, creating the section if necessary.
Dictionary< string, string > CreateConfigurationSection(string section)
Creates a configuration section if it does not already exist.
EngineLoggingMode LoggingMode
Controls whether engine logging operations are performed synchronously or asynchronously.
double GamepadConnectionUpdateFrequencyHz
Gets or sets how often the engine checks for gamepad connection and disconnection changes.
int MsaaSampleCount
Gets or sets the number of MSAA (multisample anti-aliasing) samples used when creating GPU render-tar...
bool VSync
Gets or sets a value indicating whether vertical synchronisation (vsync) is enabled.
double TimeBetweenKeyboardEvents
Minimum time (in seconds) allowed between Keyboard events. Use this to prevent flooding the system wi...
double SamplingTimeForCPS
Total number of seconds between legacy Cycles Per Second (CPS) calculations. Default is 1....
bool ClearConfigurationSection(string section)
Clears all key/value pairs from the specified configuration section without removing the section itse...
bool FlushAsyncLogsOnShutdown
If true, the engine will attempt to flush queued async log events during shutdown....
bool HasConfigurationSection(string section)
Determines whether the specified configuration section exists.
int TargetFPS
Target screen refresh rate for the Engine. Setting the number lower allows more time for the processo...
int MaxTimerDrivenSimulationSteps
Gets or sets the maximum number of fixed simulation updates that one externally driven Tick() call ma...
Dictionary< string, Dictionary< string, string > > ConfigurationSections
Gets or sets a collection of structured configuration values organized into named sections.
bool HasConfigurationValue(string section, string key)
Determines whether a configuration value exists in the specified section.
double TimeBetweenTouchEvents
Minimum time (in seconds) allowed between Touch events. Use this to prevent flooding the system with ...
Provides a fully GPU-rendered backbuffer implementation using SkiaSharp and OpenGL.
EngineLoggingMode
Specifies the logging mode for the engine.
readonly record struct PresentationTransform(float Scale, SKRect DestinationRect)
Aspect-preserving mapping between logical Backbuffer ScreenPx and adapter pixels.
RenderScalingFilter
Filtering used only when presenting the finished Backbuffer.