1. Dashboard
  2. Getting Started
  3. GitHub
  4. API
  5. Articles
  6. Level Editor
  7. Members
    1. Recent Activity
    2. Users Online
    3. Staff
    4. Search Members
  8. Forum
  9. Discord
  • Login
  • Register
  • Search
Getting Started
  • Everywhere
  • Getting Started
  • Articles
  • Pages
  • Forum
  • More Options
  1. GFX-Engine
  2. Articles
  3. Getting Started

Scene & Gameplay

  • Andy
  • December 26, 2025 at 11:29 AM
  • 366 Views
  • 0 Comments

This article explains how gameplay logic, scene structure, and runtime behavior are organized in GFX-Next. It provides an overview of the core architectural concepts and shows how these elements interact to form a cohesive execution model. By outlining responsibilities, data flow, and lifecycle management, the article helps developers understand how to design, extend, and debug systems built on top of GFX-Next more effectively.

Contents [hideshow]
  1. The Scene as the Runtime Context
  2. GameElements: The Building Blocks
    1. Core Properties
  3. Hierarchies & Transform Propagation
    1. 4. Behaviors: Gameplay Logic Composition
    2. Why Behaviors?
    3. 5. Physics as a First-Class System
    4. Design Philosophy
  4. 6. Scene Update Order
  5. 7. Runtime Safety: Add vs Enqueue
  6. 8. Enqueue System (Mid-Frame Safe Modifications)
    1. Example: Spawning a Projectile During Gameplay
    2. What happens here?
  7. 9. Frame-End Synchronization
  8. 10. Rule of Thumb
  9. Summary

The scene system is designed to be:

  • explicit
  • editor-friendly
  • flexible enough for both simple games and complex simulations

1. The Scene as the Runtime Context

A Scene represents the active world state.

C#
this.Scene = new Scene3D();
Scene.Init(Viewport, RenderDevice);

A scene owns:

  • all game elements
  • the physics handler
  • lighting and environment
  • render targets and render statistics

Only one scene is active at a time, but scenes can be created, destroyed, or swapped freely.

2. GameElements: The Building Blocks

Everything that exists in a scene is a GameElement.

Examples:

  • Primitive
  • StaticModel
  • AnimatedModel
  • LightHandle
  • Empty (logic-only objects)
C#
Scene.AddGameElement(ground);
Scene.AddGameElement(Player);

Core Properties

Every GameElement has:

  • a Transform
  • a Name
  • a lifecycle (Init, Update, Render, Dispose)
  • optional children
  • optional behaviors

This makes all elements uniformly manageable.

3. Hierarchies & Transform Propagation

Game elements can form parent-child hierarchies.

C#
Player.AddChild(new StaticModel("BlasterViewmodel", _viewModelMesh));

Key rules:

  • Child transforms are relative to their parent
  • World transforms are resolved automatically
  • Moving the parent affects all children

This is essential for:

  • player models
  • weapons
  • cameras
  • attachments

4. Behaviors: Gameplay Logic Composition

Gameplay logic is attached via behaviors, not inheritance.

C#
Player.AddBehavior(new FPSController());
Player.AddBehavior(new CapsuleRigidBody(PhysicsHandler));

Why Behaviors?

  • No deep inheritance trees
  • Logic is reusable
  • GameElements stay data-oriented
  • Systems stay decoupled

A behavior can:

  • react to updates
  • interact with physics
  • modify transforms
  • communicate with other components

5. Physics as a First-Class System

Physics is integrated at the scene level.

C#
this.PhysicsHandler = new PhysicsHandler3D(gravity);
Scene.PhysicsHandler = this.PhysicsHandler;

Colliders and rigid bodies are added as behaviors:

C#
var collider = ground.AddBehavior(new BoxCollider(PhysicsHandler));
collider.CreateCollider(0);

Design Philosophy

  • Physics is explicit
  • No automatic collider generation
  • Debug rendering is optional
  • Physics can be disabled per scene

This makes physics predictable and editor-safe.

6. Scene Update Order

Each frame follows a deterministic order:

  1. Physics update
  2. Scene update
  3. GameElement updates
  4. Behavior updates
C#
Scene.UpdatePhysics(deltaTime);
Scene.Update(deltaTime);

This guarantees:

  • stable simulation
  • consistent behavior mention
  • deterministic gameplay

7. Runtime Safety: Add vs Enqueue

Important Rule

Scene structure must NOT be modified directly during the frame loop.

Do not do this inside Update or Render:

C#
Scene.AddGameElement(element);
Scene.RemoveElement(element);

Doing so would:

  • invalidate iterators
  • cause unstable behavior
  • break editor/runtime parity

8. Enqueue System (Mid-Frame Safe Modifications)

All runtime changes must be enqueued and processed at the end of the frame.

Example: Spawning a Projectile During Gameplay

C#
private void SpawnProjectile(BaseScene scene, Vector3 position, Vector3 direction)
{
    var instancer = scene.FindElement<MeshInstancer>("ProjectileInstancer");
    if (instancer != null)
    {
        var instance = instancer.FindHiddenInstances(1).FirstOrDefault();
        if (instance != null)
        {
            var enqueEntry = new EnqueScene3DEntry()
            {
                Element = instancer.CreateInstanceHandle(instance),
                EnqueAction = enque_element,
                ExtraData = new Dictionary<string, object>()
                {
                    { "position", position },
                    { "direction", direction }
                }
            };

            scene.EnqueEntries.Add(enqueEntry);
        }
    }
}
Display More

What happens here?

  1. A pooled instance is requested
  2. The instance is not activated immediately
  3. A scene entry is created
  4. The entry is queued for processing
  5. The scene applies the change after the frame

9. Frame-End Synchronization

All queued operations are applied at the end of the frame:

C#
public override void OnFrameEnd()
{
    Scene.EnqueElements();
}

This ensures:

  • safe element creation and removal
  • synchronized physics and rendering
  • consistent scene state for the next frame

10. Rule of Thumb

SituationMethod
Scene setup (before loop)Scene.AddGameElement
Gameplay runtimeEnqueue system
Update / RenderNever modify scene directly
Quote

Before the loop → Add
Inside the loop → Enqueue

Summary

The Scene & Gameplay system in GFX-Next is built around:

  • a single authoritative scene
  • uniform GameElements
  • behavior-based gameplay logic
  • explicit physics integration
  • a safe enqueue system for runtime changes

This approach keeps gameplay code predictable, editor-safe, and stable under complex runtime behavior.

Images

  • coordinates.png
    • 93.33 kB
    • 1,280 × 1,200
  • Screenshot 2025-12-26 122739.png
    • 9.6 kB
    • 802 × 632
  • Tutorial
  • Previous Article Core Concepts
  • Next Article Asset Management & Resource Lifetime

Related Articles

Core Concepts

This section explains the fundamental concepts behind GFX-Next.
It assumes familiarity with C#, object-oriented design, and general game development workflows.

GFX-Next is designed around explicit control, clear ownership, and minimal hidden behavior.
Understanding these core ideas is essential before diving into advanced features.
Andy
December 25, 2025 at 7:47 PM
0

Categories

  1. Advanced Tutorial 1
  2. Getting Started 8
  3. Default Category 1
  4. Reset Filter

Partner & Supporter

  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™