StopPhysicsRecording ( world,file$ )
Parameters
|
world - physics-world handle returned by CreatePhysicsWorld; must currently be recording file$ - name of the file to save the recording to |
Description
|
Stops recording and saves the physics recording to a file. Ends the session begun by StartPhysicsRecording and writes everything - the starting snapshot, every recorded operation and the state hashes used for verification - into one self-contained file. Returns True. Note that failures do not return False: stopping a world that is not recording, or a file that cannot be written, raises a runtime error instead. Feed the saved file to ValidatePhysicsRecording to confirm a replay reproduces the recorded simulation exactly. Requires Extended mode. See also: StartPhysicsRecording, ValidatePhysicsRecording, StepPhysics. |
Example
; StopPhysicsRecording Example ; ---------------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() Const PHYSICS_STATIC=0 Const PHYSICS_DYNAMIC=2 camera=CreateCamera() PositionEntity camera,0,3,-6 light=CreateLight() RotateEntity light,45,-30,0 AmbientLight 50,50,50 world=CreatePhysicsWorld() PhysicsGravity world,0,-9.81,0 ; Static ground slab ground=CreateCube() ScaleEntity ground,4,0.5,4 PositionEntity ground,0,-0.5,5,True EntityColor ground,80,160,255 ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC) ground_shape=PhysicsBodyBox(ground_body,8,1,8,0) ; A bouncy ball gives the recording something to capture ball=CreateSphere(16) ScaleEntity ball,0.5,0.5,0.5 PositionEntity ball,0,4,5,True EntityColor ball,255,120,70 ball_body=CreatePhysicsBody(world,ball,PHYSICS_DYNAMIC) ball_shape=PhysicsBodySphere(ball_body,1,1) PhysicsShapeRestitution ball_shape,0.7 recording_file$="physics_example.b3rec" ; Begin capturing a deterministic recording of the simulation StartPhysicsRecording world recording=1 frames=0 saved=0 valid=0 While Not KeyDown(1) If recording frames=frames+1 ; Space (or 300 recorded frames) stops and validates the recording If KeyHit(57) Or frames>=300 saved=StopPhysicsRecording(world,recording_file) valid=ValidatePhysicsRecording(recording_file,1) recording=0 EndIf Else ; Space re-drops the ball and starts a fresh recording If KeyHit(57) FreePhysicsBody ball_body PositionEntity ball,0,4,5,True ball_body=CreatePhysicsBody(world,ball,PHYSICS_DYNAMIC) ball_shape=PhysicsBodySphere(ball_body,1,1) PhysicsShapeRestitution ball_shape,0.7 StartPhysicsRecording world recording=1 frames=0 EndIf EndIf StepPhysics world,1.0/60.0,4 ; 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 If recording Text 0,0,"Space: stop and validate Arrow keys: move camera Esc: exit" Text 0,20,"Recording frame "+frames+" (Space calls StopPhysicsRecording)" Else Text 0,0,"Space: record again Arrow keys: move camera Esc: exit" Text 0,20,"StopPhysicsRecording(world,recording_file$) = "+saved+" Validated: "+valid EndIf Flip Wend ; Tidy up the recording file the example created If FileType(recording_file)=1 Then DeleteFile recording_file FreePhysicsWorld world End
Index