Blitz3D+ Command Reference

CapturePhysicsProfile world

Parameters

world - live explicit physics world

Description

Each world owns one fixed-size snapshot, initially uncaptured.

CapturePhysicsProfile copies it without changing simulation state, consuming events or allocating native storage. Values stay fixed through stepping, worker changes, object deletion and other worlds' activity until the next explicit capture. Reading values before capture is an error. Freeing the world invalidates the snapshot.

The copy includes all 23 timing fields and 19 counters, including current awake count and process-global native bytes. It uses fixed-size storage and records no native mutation. It may be used before the first step or while the application has paused stepping.

Times are native milliseconds for the most recent physics step, and zero in a new world. Capture does not measure a new interval. Timers overlap/nest and depend on scheduling; do not add them or expect identical values across runs. Zero can mean no work or work below timer resolution.

Counter IDs mix current population, latest native work and lifetime peaks, as described below. Population changes without stepping can therefore coexist with timings from the preceding step. Work fields may retain the previous collision/worker-context result when no new work updates that stage. These are not all cumulative counters.

World arguments must be live explicit physics worlds; invalid, stale and wrong-kind handles raise a runtime error. Metric indices are one-based and checked before returning values. Captures are rejected while the world is stepping.

Requires Extended mode.

See also: PhysicsProfileTime, PhysicsProfileCounter, PhysicsNativeBytes, PhysicsWorkerCount.

Example

; CapturePhysicsProfile Example
; -----------------------------
; Requires Extended mode.

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2
Const CRATE_COUNT=12

SeedRnd MilliSecs()

camera=CreateCamera()
PositionEntity camera,0,6,-12
RotateEntity camera,20,0,0

light=CreateLight()
RotateEntity light,45,-30,0
AmbientLight 60,60,60

; An independent Box3D world with standard gravity
world=CreatePhysicsWorld()

; Blue static floor
ground=CreateCube()
ScaleEntity ground,6,0.5,6
PositionEntity ground,0,-0.5,0
EntityColor ground,80,160,255
ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC)
ground_shape=PhysicsBodyBox(ground_body,12,1,12)

; A pile of crates, dropped from random heights
Dim crates(CRATE_COUNT)
Dim crate_bodies(CRATE_COUNT)
For i=1 To CRATE_COUNT
    crates(i)=CreateCube()
    ScaleEntity crates(i),0.5,0.5,0.5
    crate_bodies(i)=CreatePhysicsBody(world,crates(i),PHYSICS_DYNAMIC)
    crate_shape=PhysicsBodyBox(crate_bodies(i),1,1,1)
Next
DropPile()

capturing=True

While Not KeyDown(1)

    ; R drops the pile again
    If KeyHit(19) Then DropPile()

    If KeyHit(57) Then capturing=Not capturing

    StepPhysics world,1.0/60.0,4

    ; Copy the world's native profile; the copy stays fixed until the next capture
    If capturing Then CapturePhysicsProfile world

    ; Orange crates are awake, grey crates are asleep
    For i=1 To CRATE_COUNT
        If PhysicsBodyIsAwake(crate_bodies(i))
            EntityColor crates(i),255,120,70
        Else
            EntityColor crates(i),150,150,150
        EndIf
    Next

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Arrow keys: move camera   R: drop again   Space: freeze the snapshot"
    Text 0,20,"Esc: exit"
    Text 0,40,"Capturing every step: "+capturing
    For t=1 To 6
        Text 0,60+(t-1)*20,PhysicsProfileTimingName(t)+": "+PhysicsProfileTime(world,t)+" ms"
    Next

    Flip

Wend

FreePhysicsWorld world
End

Function DropPile()
    For i=1 To CRATE_COUNT
        ResetPhysicsBody crate_bodies(i),Rnd(-1.5,1.5),2+i*0.8,Rnd(-1.5,1.5),0,Rnd(Pi),0
    Next
End Function

Index