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
DirectDrawingMovableBase.cs
1using System.Drawing;
2using System.Numerics;
8
10
46{
47 private Vector2 _posPx;
48
78 RenderSurfaceHostBase renderSurfaceHost,
80 SceneLayer? sceneLayer,
81 View? view,
82 Rectangle? screenBounds,
83 Rectangle? worldBounds,
84 string? name = null)
85 : base(
86 renderSurfaceHost,
87 mode,
88 sceneLayer,
89 view,
90 screenBounds,
91 worldBounds,
92 name)
93 {
94 Rectangle bounds = (mode == DirectDrawingMode.SceneLayer ? worldBounds : screenBounds)!.Value;
95 _posPx = new Vector2(bounds.X, bounds.Y);
96
97 var movementState = MovementState.ForPixel();
98 Movement = new MovementController(this, movementState);
99 }
100
146
159
179 public Vector2 GetPosition() => _posPx;
180
209 public void SetPosition(Vector2 p)
210 {
211 // mark old area dirty
212 ForceRefresh();
213
214 // keep precise position for movement math
215 _posPx = p;
216
217 // pixel-align only for rendering bounds
218 int x = (int)MathF.Round(p.X);
219 int y = (int)MathF.Round(p.Y);
220
221 if (Mode == DirectDrawingMode.SceneLayer)
222 {
223 var r = WorldBounds;
224
225 WorldBounds = new Rectangle(
226 x,
227 y,
228 r.Width,
229 r.Height);
230 }
231 else
232 {
233 var r = ScreenBounds;
234
235 ScreenBounds = new Rectangle(
236 x,
237 y,
238 r.Width,
239 r.Height);
240 }
241
242 // mark new area dirty
243 ForceRefresh();
244 }
245
246 void IDirectCompositeChild.SetIsVisible(bool visible)
247 {
248 Visible = visible;
249 }
250
251 void IDirectCompositeChild.SetZOrder(int zOrder)
252 {
253 ZOrder = zOrder;
254 }
255
256 void IDirectCompositeChild.SetOpacity(float opacity)
257 {
258 Opacity = opacity;
259 }
260
261 void IDirectCompositeChild.FadeTo(float targetOpacity, float durationSec)
262 {
263 base.FadeTo(
264 targetOpacity,
265 durationSec);
266 }
267
285 public override void Update(long tick)
286 {
287 // DirectDrawingBase registers the instance with DirectDrawingManager from
288 // its constructor. The update thread can therefore observe this derived
289 // instance before this constructor has assigned Movement.
290 if (Movement is null)
291 {
292 base.Update(tick);
293 return;
294 }
295
296 if (tick <= _lastTick)
297 return;
298
299 float dt =
300 HighResTimer.GetDuration(_lastTick, tick);
301
302 Movement.AdvanceMovement(dt);
303
304 base.Update(tick);
305 }
306}
int ZOrder
Gets or sets the Z-order (depth) used for sorting this direct drawing relative to other drawables.
View? View
Gets the view to which this direct drawing is attached, or null if the drawing is in scene-layer mode...
long _lastTick
The last engine tick value used for delta-time calculations in Update.
bool Visible
Gets or sets a value indicating whether this direct drawing is visible and should be rendered.
float Opacity
Gets or sets the current opacity of this direct drawing.
SceneLayer? SceneLayer
Gets the scene layer to which this direct drawing is attached, or null if the drawing is in view mode...
Rectangle WorldBounds
Gets or sets the world-space bounds of this direct drawing in pixels.
DirectDrawingMode Mode
Gets the drawing mode that determines how this direct drawing is positioned and transformed.
DirectDrawingBase(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, SceneLayer? sceneLayer, View? view, Rectangle? screenBounds, Rectangle? worldBounds, string? nickname=null)
Initializes a new instance of the DirectDrawingBase class.
Rectangle ScreenBounds
Gets or sets the screen-space bounds of this direct drawing in pixels.
Vector2 GetPosition()
Gets the current position of this direct drawing in pixel coordinates.
override void Update(long tick)
Advances this direct drawing's movement using the elapsed time since its previous update,...
DirectDrawingMovableBase(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, SceneLayer? sceneLayer, View? view, Rectangle? screenBounds, Rectangle? worldBounds, string? name=null)
Initializes a new instance of the DirectDrawingMovableBase class with integrated movement capabilitie...
MovementSpace PositionSpace
Gets the coordinate space in which this movable object's position is expressed.
void SetPosition(Vector2 p)
Sets the position of this direct drawing to the specified pixel coordinates.
MovementController Movement
Gets the movement controller responsible for changing this direct drawing's position over time.
Central controller responsible for managing all movement modes for a single IMovable object....
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
Defines a movable direct drawable that may be owned by a DirectComposite.
void SetIsVisible(bool visible)
Applies a visibility value to this child.
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.
@ SceneLayer
Performs direct drawing within a scene layer using world-space coordinates.
MovementSpace
Specifies the coordinate system used for movement calculations and updates.
Represents the current motion state of an IMovable object, including velocity, acceleration,...