TerrainRebuiltChunks ( terrain )
Parameters
| terrain - terrain entity to query |
Description
|
Returns how many terrain chunk meshes had to be rebuilt in the last render pass. Chunks cache the mesh they generate, keyed by the combination they were built for: detail level, morph step, the edge-stitching pattern needed to meet their neighbours, and whether terrain shading is on. When the camera has settled and nothing has been edited, every visible chunk finds its mesh already in the cache and this reads 0. That is the number you want in a steady state. It climbs when real work happens: after EndTerrainUpdate commits an edit, when chunks cross a level-of-detail boundary as the camera moves, when a neighbour changes level and the seam between them has to be restitched, when TerrainShading is toggled, and during the first frames after a terrain is created while the caches fill up. That makes it the cost meter for runtime terrain deformation. Animate a rippling patch every frame and you will see a steady non-zero figure equal to the chunks you keep dirtying. If it is higher than you like, edit a smaller region, edit less often, or make sure the edits are wrapped in BeginTerrainUpdate and EndTerrainUpdate so one dirty rectangle is committed instead of hundreds. TerrainUploadBytes measures the same events in bytes. Gotcha: read it after RenderWorld - it is cleared at the start of every render pass and describes the pass that just finished. A non-zero reading while the camera moves smoothly is normal rather than a bug, because level transitions have to build something; what you are hunting for is a number that stays high with the camera standing still. See also: TerrainUploadBytes, BeginTerrainUpdate, EndTerrainUpdate, ModifyTerrain, TerrainVisibleChunks. |
Example
; TerrainRebuiltChunks Example ; ---------------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,6,-40 CameraClsColor camera,110,150,200 light=CreateLight(1) RotateEntity light,50,-30,0 ; Rolling hills built from a sine-wave height field terrain=CreateTerrain(128) For z=0 To 127 For x=0 To 127 ModifyTerrain terrain,x,z,0.2+Sin(x*10)*Cos(z*10)*0.12 Next Next ScaleEntity terrain,0.5,20,0.5 PositionEntity terrain,-32,-5,-32 TerrainShading terrain,True TerrainDetail terrain,8000,True ; Plain grass texture drawn in code grass=CreateTexture(8,8,1+8) SetBuffer TextureBuffer(grass) : ClsColor 75,135,60 : Cls : SetBuffer BackBuffer() EntityTexture terrain,grass phase#=0 sun_angle#=-30 While Not KeyDown(1) ; Hold Space to keep deforming a patch - its chunks must rebuild If KeyDown(57) phase=phase+6 BeginTerrainUpdate terrain For z=52 To 75 For x=52 To 75 ripple#=Sin((x-52)*7.8)*Sin((z-52)*7.8)*Sin((x+z)*15+phase)*0.06 ModifyTerrain terrain,x,z,0.2+Sin(x*10)*Cos(z*10)*0.12+ripple Next Next EndTerrainUpdate terrain EndIf ; The sun slowly circles so the hills' shading shifts sun_angle=sun_angle+0.2 RotateEntity light,50,sun_angle,0 ; Arrow keys move the camera - LOD switches also cause rebuilds If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld ; How many chunk cache entries were rebuilt in that render pass rebuilt=TerrainRebuiltChunks(terrain) Text 0,0,"Arrow keys: fly Hold Space: deform terrain Esc: exit" Text 0,20,"TerrainRebuiltChunks(terrain) = "+rebuilt Text 0,40,"A stationary, warmed terrain reports 0" Flip Wend End
Index