|
entity - any entity with a model camera - the camera to measure from: its zoom, viewport and range detail# (optional) - a detail scale, as WorldStreamingDetail takes; 1 (default) |
|
Returns how far from a camera an object's data loads in a streaming world. An object loads where its size would cover about six pixels across, worked out from its bounds, the camera's zoom and the width of its view, and never beyond the camera's range (or its fog, under linear fog). For an object with levels of detail, the full mesh loads where the first level takes over. A moving camera reaches a little farther ahead of itself. The World Editor's Show what's loaded view draws with it: the editor's own view does not stream, so it shows what a game camera there would load. Data stays loaded until it is a quarter farther away than this, and goes only when memory runs short. See also: EntityLoadState, WorldStreamingDetail, SetWorldStreaming. |
; EntityLoadDistance 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")
zoom#=1
While Not KeyDown(1)
; Z / X zoom the camera in and out: a zoomed-in view loads detail farther away
If KeyDown(44) And zoom<8 Then zoom=zoom*1.02
If KeyDown(45) And zoom>0.5 Then zoom=zoom/1.02
CameraZoom camera,zoom
; 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
Text 0,0,"Arrow keys: drive Z / X : zoom Esc: exit"
Text 0,20,"CameraZoom "+zoom
; How far away the next object ahead loads, and how far away it is
ahead=NextAhead(world,camera)
If ahead
Text 0,40,"EntityLoadDistance(ahead,camera) = "+Int(EntityLoadDistance(ahead,camera))+" m"
Text 0,60,"The next object ahead is "+Int(EntityDistance(camera,ahead))+" m away"
EndIf
Flip
Wend
End
; The next of the road's 40 objects ahead of the camera, or 0 past the last
Function NextAhead(world,camera)
For n=1 To 40
thing=FindWorldEntity(world,"thing-"+n)
If EntityZ(thing)>EntityZ(camera) Then Return thing
Next
Return 0
End Function