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

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

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

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

Systems execute in defined phases via the SystemPhase enum:

PhaseWhenTypical use
PreUpdateBefore main updateInput processing, physics preparation
UpdateMain game logicGameplay systems, AI, animation
RenderAfter updateCamera, renderer, UI systems
PostUpdateAfter renderCleanup, event dispatch

Naming Convention

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

Released under the MIT License.