AsyncLoadBudget# ( )
Parameters
| None. |
Description
|
Returns the automatic per-frame world-loading budget, in milliseconds. This is the value set by SetAsyncLoadBudget (2 by default): the main-thread time that Flip, FlipCanvas, Delay, and WaitTimer may spend finalizing background world loads each frame. It is also what UpdateAsyncLoads uses when called with -1 or no argument. Read it to save and restore the budget around a change - for example, boost the budget while a dedicated loading screen is up, then put the old value back when gameplay resumes. For the full story, see the Async World Loading guide. Requires Extended mode. See also: SetAsyncLoadBudget, UpdateAsyncLoads, LoadWorldAsync. |
Example
; AsyncLoadBudget Example ; ----------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() ; A simple loading screen lives in the default world camera=CreateCamera() PositionEntity camera,0,0,-5 light=CreateLight() RotateEntity light,45,45,0 spinner=CreateCube() EntityColor spinner,80,170,255 While Not KeyDown(1) ; Load (or reload) the castle world in the background SetWorld 0 castle_world=LoadWorldAsync("../../../samples/worlds/castle/castle.world") While Not WorldReady(castle_world) If WorldLoadState(castle_world)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(castle_world) ; + / - change the automatic budget while loading runs If KeyDown(13) Then SetAsyncLoadBudget AsyncLoadBudget()+0.1 If KeyDown(12) And AsyncLoadBudget()>0.1 Then SetAsyncLoadBudget AsyncLoadBudget()-0.1 TurnEntity spinner,0.5,1,0.25 RenderWorld ; AsyncLoadBudget reports the main-thread milliseconds that the ; automatic async pumps (Flip, Delay...) may spend finalizing Text 0,0,"Loading... + / - : change budget Esc: exit" Text 0,20,"AsyncLoadBudget() = "+AsyncLoadBudget()+" ms" Text 0,40,"Progress: "+(WorldLoadProgress(castle_world)/10.0)+"%" Flip Wend ; The world is ready: select it and use its authored camera SetWorld castle_world castle_cam=FindWorldEntity(castle_world,"camera-main") PointEntity castle_cam,FindWorldEntity(castle_world,"castle") ; Explore the castle until R reloads it or Esc exits While Not KeyDown(1) If KeyDown(200) Then MoveEntity castle_cam,0,0,1 If KeyDown(208) Then MoveEntity castle_cam,0,0,-1 If KeyDown(203) Then TurnEntity castle_cam,0,1,0 If KeyDown(205) Then TurnEntity castle_cam,0,-1,0 If KeyDown(13) Then SetAsyncLoadBudget AsyncLoadBudget()+0.1 If KeyDown(12) And AsyncLoadBudget()>0.1 Then SetAsyncLoadBudget AsyncLoadBudget()-0.1 RenderWorld Text 0,0,"Arrow keys: move camera + / - : change budget R: reload Esc: exit" Text 0,20,"AsyncLoadBudget() = "+AsyncLoadBudget()+" ms (used while worlds load)" Flip If KeyHit(19) Then Exit Wend SetWorld 0 FreeWorld castle_world Wend End
Index