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
DisplayEffect.cs
2
4
12public abstract class DisplayEffect
13{
14 private EffectsManager? _owner;
15 private object? _target;
16 private float _elapsedSeconds;
17
23 private protected DisplayEffect(
24 float durationSeconds,
25 EasingKind easing = EasingKind.Linear)
26 {
27 DurationSeconds = Math.Max(0f, durationSeconds);
28 Easing = easing;
29 }
30
32 public event Action<DisplayEffect>? Completed;
33
35 public event Action<DisplayEffect>? Cancelled;
36
38 public Guid Id { get; } = Guid.NewGuid();
39
41 public float DurationSeconds { get; }
42
44 public EasingKind Easing { get; }
45
47 public EffectStatus Status { get; private set; } = EffectStatus.Pending;
48
50 public float Progress { get; private set; }
51
52 internal object Target => _target
53 ?? throw new InvalidOperationException("The effect has not been started.");
54
55 internal abstract EffectChannel Channel { get; }
56
57 internal abstract bool SupportsTarget(object target);
58
64 private protected TTarget GetTarget<TTarget>() where TTarget : class =>
65 Target as TTarget
66 ?? throw new InvalidOperationException(
67 $"{GetType().Name} cannot operate on target type {Target.GetType().Name}.");
68
69 internal void StartInternal(EffectsManager owner, object target)
70 {
71 if (Status != EffectStatus.Pending)
72 throw new InvalidOperationException("An effect instance can only be started once.");
73
74 _owner = owner;
75 _target = target;
76 Status = EffectStatus.Running;
77
78 OnStarting();
79
80 if (DurationSeconds <= 0f)
81 {
82 Progress = 1f;
83 ApplyProgress(1f);
84 CompleteInternal();
85 return;
86 }
87
88 ApplyProgress(EasingFunctions.From(Easing)(0f));
89 }
90
91 internal bool AdvanceInternal(float deltaSeconds)
92 {
93 if (Status != EffectStatus.Running)
94 return true;
95
96 _elapsedSeconds = Math.Min(
98 _elapsedSeconds + Math.Max(0f, deltaSeconds));
99
101 ? 1f
102 : Math.Clamp(_elapsedSeconds / DurationSeconds, 0f, 1f);
103
104 float easedProgress = EasingFunctions.From(Easing)(Progress);
105 ApplyProgress(easedProgress);
106
107 if (Progress >= 1f)
108 CompleteInternal();
109
110 return Status != EffectStatus.Running;
111 }
112
116 public void Cancel() => _owner?.Cancel(this);
117
118 internal void CancelInternal(bool restoreState)
119 {
120 if (Status != EffectStatus.Running)
121 return;
122
123 if (restoreState)
125
126 Status = EffectStatus.Cancelled;
127 _owner = null;
128 Cancelled?.Invoke(this);
129 }
130
131 private void CompleteInternal()
132 {
133 if (Status != EffectStatus.Running)
134 return;
135
136 OnCompleted();
137 Status = EffectStatus.Completed;
138 _owner = null;
139 Completed?.Invoke(this);
140 }
141
145 private protected virtual void OnStarting()
146 {
147 }
148
153 private protected abstract void ApplyProgress(float progress);
154
158 private protected virtual void OnCompleted()
159 {
160 }
161
165 private protected abstract void RestoreOriginalState();
166}
167
168internal enum EffectChannel
169{
173 Transform,
177 Opacity,
181 Reveal,
185 Zoom
186}
virtual void OnCompleted()
Runs the effect-specific completion behavior.
float DurationSeconds
Gets the requested effect duration in seconds.
void RestoreOriginalState()
Restores the target state captured when the effect started.
DisplayEffect(float durationSeconds, EasingKind easing=EasingKind.Linear)
Initializes a new instance of the DisplayEffect class.
Action< DisplayEffect >? Cancelled
Occurs when the effect is cancelled or replaced.
TTarget GetTarget< TTarget >()
Gets the effect target as the requested reference type.
void Cancel()
Cancels the effect and restores the presentation state that existed when it began.
EffectStatus Status
Gets the current lifecycle state.
void ApplyProgress(float progress)
Applies the eased effect progress to the target.
EasingKind Easing
Gets the easing curve used to transform normalized progress.
virtual void OnStarting()
Captures or prepares target state before the effect starts.
float Progress
Gets the normalized, uneased progress in the range 0 through 1.
Action< DisplayEffect >? Completed
Occurs when the effect reaches its requested duration.
Guid Id
Gets the effect's unique identifier.
Owns and advances display effects for one RenderSurfaceHost.
EffectStatus
Describes the current lifecycle state of a display effect.
@ Completed
The effect reached its requested duration.
EasingKind
Enumeration of all supported easing functions for animation and movement interpolation....
Definition EasingKind.cs:9