| entity - any entity |
|
Returns whether an object's streamed data is loaded: 0 loaded, 1 parked, 2 unloaded. In a world that streams, an object always exists, but the data behind it - its mesh and textures - loads as cameras come near, and the sound it plays (a sound emitter's) loads where it can be heard. Parked data is still in memory but not on the GPU; unloaded data has gone, apart from its bounds, counts, sizes and a small version of each texture. The answer is the least loaded of the object's geometry, textures and sound. An object that does not stream, and anything in a world that does not, is always 0. You never need to check this before using an object: anything that reads data not loaded loads it on the spot, with the same answer. It is here for the World Editor's Show what's loaded view, for tests and for curiosity. See also: EntityLoadDistance, EntityKeepLoaded, SetWorldStreaming, WorldStreaming. |
; EntityLoadState Example
; -----------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
; A road of avocados and boom boxes, each loading as the camera comes near
world=LoadWorldAsync("../../../samples/worlds/help-streaming.world",WORLD_LOAD_STREAMING)
While Not WorldReady(world)
If WorldLoadState(world)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(world)
Cls
Text 0,0,"Loading what the start of the road needs..."
Flip
Wend
SetWorld world
camera=FindWorldEntity(world,"camera")
; A small budget, so that data far behind unloads again
SetStreamingBudget 200
While Not KeyDown(1)
; The camera drives along the road by itself, back to the start at its end
MoveEntity camera,0,0,0.3
If EntityZ(camera)>1100 Then PositionEntity camera,0,1.6,0
; Arrow keys move the camera (bigger steps suit the road's length)
If KeyDown(200) Then MoveEntity camera,0,0,0.5
If KeyDown(208) Then MoveEntity camera,0,0,-0.5
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
RenderWorld
; Label each object on screen with its state
For n=1 To 40
thing=FindWorldEntity(world,"thing-"+n)
CameraProject camera,EntityX(thing,True),EntityY(thing,True)+1,EntityZ(thing,True)
If ProjectedZ()>0
state=EntityLoadState(thing)
If state=0 Then Color 120,255,120 Else If state=1 Then Color 255,220,90 Else Color 255,110,110
Text ProjectedX(),ProjectedY(),state,True,True
EndIf
Next
Color 255,255,255
Text 0,0,"Arrow keys: drive along the road Esc: exit"
Text 0,20,"EntityLoadState: 0 loaded, 1 parked, 2 unloaded"
Flip
Wend
End