# HG changeset patch # User sheepluva # Date 1402399618 -7200 # Node ID 237b403f92beaf54f943c5298afcc72aad8394e2 # Parent a90a55ec5b9824e2ac0d2842b070fa8f7804c734 figure out visible land tiles in advance diff -r a90a55ec5b98 -r 237b403f92be hedgewars/uLandTexture.pas --- a/hedgewars/uLandTexture.pas Tue Jun 10 08:47:03 2014 +0200 +++ b/hedgewars/uLandTexture.pas Tue Jun 10 13:26:58 2014 +0200 @@ -30,7 +30,7 @@ procedure SetLandTexture; implementation -uses uConsts, GLunit, uTypes, uVariables, uTextures, uDebug, uRender; +uses uConsts, GLunit, uTypes, uVariables, uTextures, uDebug, uRender, uUtils; const TEXSIZE = 128; // in avoid tile borders stretch the blurry texture by 1 pixel more @@ -173,7 +173,7 @@ end; procedure DrawLand(dX, dY: LongInt); -var x, y, tX, ty, tSize, offscreen: LongInt; +var x, y, tX, ty, tSize, fx, lx, fy, ly: LongInt; tScale: GLfloat; overlap: boolean; begin @@ -193,46 +193,57 @@ overlap:= false; end; -tX:= dX; - -// loop through all columns -for x:= 0 to LANDTEXARW -1 do - begin - - // don't draw column if offscreen - offscreen:= isDxAreaOffscreen(tX, tSize); +// figure out visible area +// first column +tx:= ViewLeftX - dx; +fx:= tx div tSize; +if tx < 0 then dec(fx); +fx:= max(0, fx); - if offscreen = 0 then - begin - // loop through all textures in this column - for y:= 0 to LANDTEXARH - 1 do - with LandTextures[x, y] do - if tex <> nil then - begin - ty:= dY + y * tSize; +// last column +tx:= ViewRightX - dx; +lx:= tx div tSize; +if tx < 0 then dec(lx); +lx:= min(LANDTEXARW -1, lx); + +// all offscreen +if (fx > lx) then + exit; + +// first row +ty:= ViewTopY - dy; +fy:= ty div tSize; +if ty < 0 then dec(fy); +fy:= max(0, fy); - // don't draw texture if offscreen - offscreen:= isDyAreaOffscreen(tY, tSize); +// last row +ty:= ViewBottomY - dy; +ly:= ty div tSize; +if ty < 0 then dec(ly); +ly:= min(LANDTEXARH -1, ly); - if offscreen = 0 then - begin - if overlap then - DrawTexture2(tX, ty, tex, tScale, BLURRYLANDOVERLAP) - else - DrawTexture(tX, ty, tex, tScale); - end +// all offscreen +if (fy > ly) then + exit; + +tX:= dX + tsize * fx; - // if below screen, skip remaining textures in this column - else if offscreen > 1 then - break; - end; +// loop through columns +for x:= fx to lx do + begin + // loop through textures in this column + for y:= fy to ly do + with LandTextures[x, y] do + if tex <> nil then + begin + ty:= dY + y * tSize; + if overlap then + DrawTexture2(tX, ty, tex, tScale, BLURRYLANDOVERLAP) + else + DrawTexture(tX, ty, tex, tScale); + end; - end - // if right of screen, skip remaining columns - else if offscreen > 0 then - break; - - // increment texX + // increment tX inc(tX, tSize); end; end;