| world - a world loaded with LoadWorldAsync that has finished loading |
|
Returns True if every file a loaded world was built from is unchanged on disk. A world loads from many files: the .world itself, its models, prefabs and resource definitions, and the files those use in turn. WorldSourcesCurrent checks them all again, and returns False if any has changed or been deleted - or has appeared, where an optional file was missing when the world loaded. Use it in a tool before saving or reusing what you loaded: if another program changed the files since, load the world again rather than saving over its changes. The World Editor uses it to keep scene joints from pointing at bodies whose files have changed. It reads every file again, so call it when it matters - before a save or an edit - not every frame. The world must have finished loading: check WorldReady first, as a world that is still loading is a runtime error. See also: WorldReady, LoadWorldAsync, WorldNetworkFingerprint, WorldPhysicsBodyEntries. |
; WorldSourcesCurrent Example
; ---------------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
; Ask first: this example writes demo_marker.world next to itself
Cls
Text 0,0,"This example copies a world file to demo_marker.world next to itself,"
Text 0,20,"changes it, and deletes it when you exit."
Text 0,40,"Press Y to continue, any other key to skip."
Flip
WaitKey
If Not KeyDown(21) Then End
; Load our own copy of a small world
CopyFile "../../../samples/worlds/help-marker.world","demo_marker.world"
scene=LoadWorldAsync("demo_marker.world")
While WorldReady(scene)=0
If WorldLoadState(scene)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(scene)
UpdateAsyncLoads 2
Wend
SetWorld scene
camera=CreateCamera()
PositionEntity camera,0,1,-5
light=CreateLight()
RotateEntity light,45,45,0
; A spinning marker where the world's player spawn point is
marker=CreateCube()
ScaleEntity marker,0.5,0.5,0.5
EntityColor marker,255,200,60
spawn=FindWorldEntity(scene,"player-spawn")
PositionEntity marker,EntityX(spawn,True),EntityY(spawn,True),EntityZ(spawn,True)
PointEntity camera,marker
; Checking reads every file again, so do it when it matters, not every frame
current=WorldSourcesCurrent(scene)
While Not KeyDown(1)
; E changes the file behind the world's back, as another program might
If KeyHit(18) Then
file=OpenFile("demo_marker.world")
SeekFile file,FileSize("demo_marker.world")
WriteLine file,""
CloseFile file
EndIf
; C checks the files again, as a tool would before saving
If KeyHit(46) Then current=WorldSourcesCurrent(scene)
; 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
TurnEntity marker,1,2,0
RenderWorld
Text 0,0,"Arrow keys: move camera E: edit the world file C: check again Esc: exit"
If current Then
Text 0,20,"WorldSourcesCurrent(scene) = 1: the files match what was loaded"
Else
Text 0,20,"WorldSourcesCurrent(scene) = 0: a file changed since loading"
EndIf
Flip
Wend
; The copied world was only for this demonstration
FreeWorld scene
DeleteFile "demo_marker.world"
End