Skip to content

Systems ​

Systems own cross-entity logic. They iterate components across multiple entities.

Built-in Systems ​

Rendering ​

SystemPurpose
Renderer3DSystemCollects MeshRenderer + Transform3D, builds RenderCommandList
Renderer2DSystemRenders SpriteRenderer entities via the 2D renderer
Camera3DSystemUpdates 3D view/projection matrices, pushes SetCamera command
Camera2DSystemUpdates the active 2D camera
InstancedTerrainSystemRenders instanced terrain via DrawMeshInstanced commands
UISystemManages UI layers and widget rendering
OutlineSystemEmits DrawOutline for every enabled Outline; register before Renderer3DSystem
LightConeSystemDraws the visible beam of every lit LightCone + SpotLight in view
SurfaceTextSystemKeeps every SurfaceText on its current text and language
FoliageInstanceSystemDraws FoliageInstances as static instanced batches
GrassSystemGrass blades of every GrassField near the camera
ParticleSystemSimulates and draws ParticleEmitter entities
WaterDisturbanceSystemWake trails and swimmer rings of every WaterDisturber

The systems in the lower half of this table read the camera of the frame: register them after Camera3DSystem and before Renderer3DSystem.

Physics ​

SystemPurpose
Physics3DSystem3D collision detection, character controller, capsule vs AABB
Physics2DSystem2D collision detection
RigidBody3DSystemIntegrates rigid body velocities and applies forces
DoorSystemUpdates hinge and linear joints with damping and angle/distance limits

Environment ​

SystemPurpose
DayNightSystemDrives day/night cycle, updates sun direction, sky colors, ambient light, fog
WindSystemAdvances wind time, modulates intensity with layered gusts
WeatherSystemManages weather state transitions (Clear/Cloudy/Rain/Snow/Storm/Fog)
PrecipitationSystemRenders rain and snow particles
SeasonSystemUpdates seasonal parameters
EnvironmentalSystemBase environmental simulation
AtmosphericEnvironmentalSystemExtends EnvironmentalSystem for atmospheric physics
SystemPurpose
NavigationSystemMoves NavMeshAgent entities along NavMesh paths and authored waypoints
SignalMotionSystemDrives SignalTrack / SignalSpin / SignalSwitch from Signals channels; register before Transform3DSystem
PosePlayerSystemPlays PosePlayer clips onto bound figure parts; register before Transform3DSystem

Transform & Hierarchy ​

SystemPurpose
Transform3DSystemUpdates Transform3D world matrices from parent/child hierarchy
HierarchySystemUpdates Transform2D world matrices based on 2D hierarchy

Input & Audio ​

SystemPurpose
InputMapSystemProcesses input bindings and dispatches input actions
AudioSystemManages audio playback, stops sources on entity destroy
AudioListenerSystemKeeps the spatial-audio listener on the active 3D camera

Custom Systems ​

php
use PHPolygon\ECS\AbstractSystem;
use PHPolygon\ECS\World;

class DamageSystem extends AbstractSystem
{
    public function update(World $world, float $dt): void
    {
        foreach ($world->query(Health::class, DamageReceiver::class) as $entity) {
            $health = $entity->get(Health::class);
            $receiver = $entity->get(DamageReceiver::class);

            foreach ($receiver->pendingDamage as $damage) {
                $health->damage($damage);
            }
            $receiver->pendingDamage = [];

            if ($health->isDead()) {
                $world->destroyEntity($entity->id);
            }
        }
    }
}

System Phases ​

Every system has an update(World $world, float $dt) and a render(World $world) method; within each, systems run in the order they were added. World::addSystem() takes an optional SystemPhase that only matters when the engine runs threaded subsystems (ext-parallel):

PhaseWhenTypical use
SystemPhase::MainThread (default)Before thread results arriveInput, camera, player movement
SystemPhase::ThreadedHandled by the thread scheduler, skipped on the main threadWork moved to a worker
SystemPhase::PostThreadAfter thread results are appliedTransform propagation
php
use PHPolygon\ECS\SystemPhase;

$world->addSystem(new Transform3DSystem(), SystemPhase::PostThread);

Naming Convention ​

System classes use noun + System suffix: Renderer3DSystem, Physics3DSystem.

Released under the MIT License.