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
DirectDrawingMovableBase.cs
1using System.Drawing;
2using System.Numerics;
8
10
46{
47 private Vector2 _posPx;
48
79 SceneLayer? sceneLayer,
80 View? view,
81 Rectangle? screenBounds,
82 Rectangle? worldBounds,
83 string? name = null)
84 : base(renderSurfaceHost, mode, sceneLayer, view, screenBounds, worldBounds, name)
85 {
86 Rectangle bounds = (mode == DirectDrawingMode.SceneLayer ? worldBounds : screenBounds)!.Value;
87 _posPx = new Vector2(bounds.X, bounds.Y);
88
89 var movementState = MovementState.ForPixel();
90 Movement = new MovementController(this, movementState);
91 }
92
138
151
171 public Vector2 GetPosition() => _posPx;
172
201 public void SetPosition(Vector2 p)
202 {
203 // mark old area dirty
204 ForceRefresh();
205
206 // keep precise position for movement math
207 _posPx = p;
208
209 // pixel-align only for rendering bounds
210 int x = (int)MathF.Round(p.X);
211 int y = (int)MathF.Round(p.Y);
212
213 if (Mode == DirectDrawingMode.SceneLayer)
214 {
215 var r = WorldBounds;
216 WorldBounds = new Rectangle(x, y, r.Width, r.Height);
217 }
218 else
219 {
220 var r = ScreenBounds;
221 ScreenBounds = new Rectangle(x, y, r.Width, r.Height);
222 }
223
224 // mark new area dirty
225 ForceRefresh();
226 }
227
228 void IDirectCompositeChild.SetIsVisible(bool visible)
229 {
230 Visible = visible;
231 }
232
233 void IDirectCompositeChild.SetZOrder(int zOrder)
234 {
235 ZOrder = zOrder;
236 }
237
238 void IDirectCompositeChild.SetOpacity(float opacity)
239 {
240 Opacity = opacity;
241 }
242
243 void IDirectCompositeChild.FadeTo(float targetOpacity, float durationSec)
244 {
245 base.FadeTo(
246 targetOpacity,
247 durationSec);
248 }
249
267 public override void Update(long tick)
268 {
269 // DirectDrawingBase registers the instance with DirectDrawingManager from
270 // its constructor. The update thread can therefore observe this derived
271 // instance before this constructor has assigned Movement.
272 if (Movement is null)
273 {
274 base.Update(tick);
275 return;
276 }
277
278 if (tick <= _lastTick)
279 return;
280
281 float dt =
282 HighResTimer.GetDuration(_lastTick, tick);
283
284 Movement.AdvanceMovement(dt);
285
286 base.Update(tick);
287 }
288}
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,...