Blitz3D+ Command Reference

PhysicsQueryLimit query,maximum

Parameters

query - query handle

maximum - integer limit, 1 through 65536

Description

Sets the result limit to an integer from 1 through 65536 (default 1024).

All-hit/overlap runs exceeding it raise an error and retain the previous snapshot; no partial result is presented as success. Closest-hit casts and closest-point measurements use one result slot. Shape-distance pairs require a limit of at least 2. Sensor occupancy uses the limit for visitors; contact capture uses it for manifolds; character movement uses it for starting-pose planes. A full native batch of 64 planes from one shape is conservatively rejected because a complete result cannot be guaranteed. The native scratch capacity for contact pairs or sensor visitors is separately capped at 65536 and reported as an error if exceeded.

Result buffers share a 64 MiB budget per loaded runtime, including retained hit/manifold/character-plane capacity and temporary result/native-data buffers used for an atomic rerun. Capacity is reserved before entering native callbacks; even a no-hit run can retain its reserved capacity. Lower the limit and rerun, or free queries, to release storage. Allocation/budget failures also preserve previous results. Changing the limit alone does not resize the current snapshot.

Results are copied. They survive StepPhysics and other queries until this query runs successfully again or is freed. Failed runs preserve the previous results. Freeing the owning world frees its queries. Invalid/stale/wrong-kind handles and invalid hit indices raise runtime errors.

Requires Extended mode.

See also: CreatePhysicsQuery, PhysicsQueryFilter, PhysicsQueryTarget, QueryPhysicsRay, QueryPhysicsSphere.

Example

; PhysicsQueryLimit Example
; -------------------------
; Requires Extended mode.

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

Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2

camera=CreateCamera()
PositionEntity camera,0,7,-8
RotateEntity camera,40,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 ring of crates to aim at
For i=1 To 8
    crate=CreateCube()
    ScaleEntity crate,0.5,0.5,0.5
    PositionEntity crate,Cos(i*45)*4,0.5,Sin(i*45)*4
    EntityColor crate,255,120,70
    crate_body=CreatePhysicsBody(world,crate,PHYSICS_STATIC)
    crate_shape=PhysicsBodyBox(crate_body,1,1,1)
Next

; A query object runs searches and keeps a copy of their results
query=CreatePhysicsQuery(world)

; Keep at most 4 hits; a run that finds more is an error, so size it generously
PhysicsQueryLimit query,4

; Start aimed at a crate
angle#=45

While Not KeyDown(1)

    ; A and D sweep the ray around the centre
    If KeyDown(30) Then angle=angle+1.5
    If KeyDown(32) Then angle=angle-1.5
    dx#=Cos(angle)*6
    dz#=Sin(angle)*6

    StepPhysics world,1.0/60.0,4

    ; Cast right across the ring; True keeps a hit for every shape the ray passes through
    hits=QueryPhysicsRay(query,-dx,0.5,-dz,dx*2,0,dz*2,True)

    ; 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

    ; Draw the ray from the centre to the first hit, or to its full length
    CameraProject camera,0,0.5,0
    start_x=ProjectedX()
    start_y=ProjectedY()
    If hits>0
        CameraProject camera,PhysicsQueryX(query,1),PhysicsQueryY(query,1),PhysicsQueryZ(query,1)
    Else
        CameraProject camera,dx,0.5,dz
    EndIf
    Line start_x,start_y,ProjectedX(),ProjectedY()

    Text 0,0,"Arrow keys: move camera   A / D: sweep the ray   Esc: exit"
    Text 0,20,"PhysicsQueryLimit query,4"
    Text 0,40,"Hits this time: "+hits

    Flip

Wend

FreePhysicsWorld world
End

Index