PreloadWorldView world,x#,y#,z#[,seconds#]

Parameters

world - a ready world loaded by LoadWorldAsync

x#, y#, z# - a point in the world, where you are about to put a camera

seconds# (optional) - how long the point counts as a view; 5 (default)

Description

Loads what a camera at a point would need, before you move a camera there.

A streaming world loads data for the cameras it has drawn. When your game is about to jump somewhere - a respawn point, the far side of a portal, the start of a cut scene - call PreloadWorldView with the place first: the data around it starts loading at once, as if a camera were already there looking every way, and keeps loading for that many seconds. WorldStreaming is True while anything that view needs is still missing, so the classic loading screen is a loop that waits for it to turn False, then moves the camera.

Without a preload, a jump is a cut: RenderWorld waits briefly for what fills the view (WorldStreamingWait), and the rest fades in.

See also: WorldStreaming, WorldStreamingProgress, WorldStreamingWait, EntityKeepLoaded.

Example

; PreloadWorldView 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")

While Not KeyDown(1)

    ; T teleports to the far end of the road, after a loading screen
    If KeyHit(20)
        ; Ask for what a camera there needs, then wait for it
        PreloadWorldView world,0,1.6,1000
        While WorldStreaming(world)
            Cls
            Text 0,0,"Loading the far end of the road... "+(WorldStreamingProgress(world)/10.0)+"%"
            Flip
        Wend
        PositionEntity camera,0,1.6,1000
    EndIf

    ; H goes home to the start of the road
    If KeyHit(35) Then PositionEntity camera,0,1.6,0

    ; 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   T: teleport to the far end   H: home   Esc: exit"
    Text 0,20,"PreloadWorldView world,0,1.6,1000 loads it before the camera arrives"

    Flip

Wend

End

Index