EntityKeepLoaded entity[,keep]

Parameters

entity - an object a streaming world placed, or a copy of one

keep (optional) - True to keep its data loaded (default), False to let it stream again

Description

Keeps an object's data loaded in a streaming world, however far away it is.

Streaming loads an object's mesh and textures as cameras come near, and the sound it plays where it can be heard, and may let them go when memory runs short. That is invisible to your program, apart from timing: anything that reads data not loaded loads it on the spot. Keep an object loaded when it must be ready the instant you want it, such as a vehicle a cut scene jumps to. Its children are kept too. The data loads now if it has not.

In the World Editor this is the object's Always keep loaded setting ("keepLoaded" in the .world file). Keep it for the few things that need it: everything kept loaded counts against the memory budget all the time.

See also: EntityLoadState, PreloadWorldView, SetWorldStreaming, SetStreamingBudget.

Example

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

; The boom box at the far end of the road
far_box=FindWorldEntity(world,"thing-40")
kept=False

While Not KeyDown(1)

    ; K keeps the far boom box loaded, or lets it stream again
    If KeyHit(37)
        kept=Not kept
        EntityKeepLoaded far_box,kept
    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   K: keep the far boom box loaded   Esc: exit"
    Text 0,20,"EntityKeepLoaded far_box,"+kept+"   its data: "+StateName$(EntityLoadState(far_box))

    Flip

Wend

End

Function StateName$(state)
    If state=0 Then Return "loaded"
    If state=1 Then Return "parked"
    Return "unloaded"
End Function

Index