SetWorldStreaming world,enabled

Parameters

world - a ready world loaded by LoadWorldAsync

enabled - True to stream the world's objects' data, False to load all of it back and keep it

Description

Turns world streaming on or off for a world that has loaded.

A streaming world keeps every object it places, but loads the heavy data behind them - mesh geometry and textures - as cameras come near, and lets it go again when memory runs short. Turn it on with WORLD_LOAD_STREAMING when you load the world, or with the world's Loading setting in the World Editor. This command switches it for a world that is already loaded: off loads everything back and keeps it, which suits a cut scene that must never wait; on again starts unloading what is far away once over the memory budget.

Turning it on for a world that loaded without it saves memory from then on, but not starting time: the start is decided when a world loads. Your program sees no difference either way, apart from timing - counts, sizes, vertices and picks always give the same answers, and data that is needed but not loaded loads on the spot.

For the full story, see the Async World Loading guide.

See also: LoadWorldAsync, WorldStreaming, SetStreamingBudget, WorldStreamingDetail, EntityKeepLoaded.

Example

; SetWorldStreaming 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 memory budget, so that data far behind the camera unloads
SetStreamingBudget 200

streaming=True

While Not KeyDown(1)

    ; Space turns streaming off (everything loads back) and on again
    If KeyHit(57)
        streaming=Not streaming
        SetWorldStreaming world,streaming
    EndIf

    ; 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 along the road   Space: streaming on / off   Esc: exit"
    Text 0,20,"SetWorldStreaming world,"+streaming+"   objects loaded: "+CountLoaded(world)+" of 40"

    Flip

Wend

End

; How many of the road's 40 objects have their data loaded
Function CountLoaded(world)
    loaded=0
    For n=1 To 40
        If EntityLoadState(FindWorldEntity(world,"thing-"+n))=0 Then loaded=loaded+1
    Next
    Return loaded
End Function

Index