|
static_shapes - initial capacity hint for static shapes dynamic_shapes - initial capacity hint for moving shapes, including kinematic bodies' shapes static_bodies - initial capacity hint for static bodies dynamic_bodies - initial capacity hint for moving bodies, including kinematic bodies contacts - initial capacity hint for contacts |
|
Creates and returns an ordinary owned physics world with native initial-capacity hints. Zero lets the relevant native storage start with its normal minimum. All counts must be non-negative. The sum of static_shapes and dynamic_shapes, the sum of static_bodies and dynamic_bodies, and contacts must each be at most 1,048,575; overflow is rejected before creating a world. These are allocation hints, not hard population limits or a guarantee of allocation-free stepping. Shape-specific storage and later growth can still allocate. Large reservations move memory cost to world creation. Measure your own population: the native regression's 1,024-body/sphere workload made 1,086 allocations during population with default capacity and 1,033 with reservations. That measurement excludes the allocations already performed during world creation. All simulation defaults match CreatePhysicsWorld: gravity (0,-10,0) m/s², sleeping and continuous collision enabled, one worker, maximum linear speed 400 m/s, restitution/hit thresholds 1 m/s, contact tuning 30 Hz / damping 10 / recovery speed 3 m/s, and contact recycling distance 0.05 m. Use the ordinary world commands to populate, step, query, record and free it. Existing worlds are never recreated by a capacity request. Ordinary world/body arguments must be live handles of the correct kind; invalid or stale handles raise a runtime error. Mutations are rejected while the owning world is stepping. See also: CreatePhysicsWorld, FreePhysicsWorld, PhysicsWorkerCount. |
; CreatePhysicsWorldReserved Example
; ----------------------------------
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
; Reserve room for the floor, the crates and their contacts up front
world=CreatePhysicsWorldReserved(1,CRATE_COUNT,1,CRATE_COUNT,64)
; 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()
While Not KeyDown(1)
; R drops the pile again
If KeyHit(19) Then DropPile()
StepPhysics world,1.0/60.0,4
; 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 Esc: exit"
Text 0,20,"CreatePhysicsWorldReserved(1,"+CRATE_COUNT+",1,"+CRATE_COUNT+",64)"
Text 0,40,"Bodies: "+CountPhysicsBodies(world)+" native memory: "+PhysicsNativeBytes()+" bytes"
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