# HG changeset patch # User sheepluva # Date 1402382823 -7200 # Node ID a90a55ec5b9824e2ac0d2842b070fa8f7804c734 # Parent 7e8d4cd76ce7430980885620f2369af152bc10e9 some minor tweaks and stuff diff -r 7e8d4cd76ce7 -r a90a55ec5b98 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Tue Jun 10 08:19:59 2014 +0200 +++ b/hedgewars/hwengine.pas Tue Jun 10 08:47:03 2014 +0200 @@ -87,6 +87,7 @@ FinishProgress; PlayMusic; SetScale(zoom); + updateViewLimits; ScriptCall('onGameStart'); GameState:= gsGame; end; diff -r 7e8d4cd76ce7 -r a90a55ec5b98 hedgewars/uLandTexture.pas --- a/hedgewars/uLandTexture.pas Tue Jun 10 08:19:59 2014 +0200 +++ b/hedgewars/uLandTexture.pas Tue Jun 10 08:47:03 2014 +0200 @@ -173,20 +173,68 @@ end; procedure DrawLand(dX, dY: LongInt); -var x, y: LongInt; +var x, y, tX, ty, tSize, offscreen: LongInt; + tScale: GLfloat; + overlap: boolean; begin RealLandTexUpdate; +// init values based on quality settings +if (cReducedQuality and rqBlurryLand) <> 0 then + begin + tSize:= TEXSIZE * 2; + tScale:= 2.0; + overlap:= (cReducedQuality and rqClampLess) <> 0; + end +else + begin + tSize:= TEXSIZE; + tScale:= 1.0; + overlap:= false; + end; + +tX:= dX; + +// loop through all columns for x:= 0 to LANDTEXARW -1 do - for y:= 0 to LANDTEXARH - 1 do - with LandTextures[x, y] do - if tex <> nil then - if (cReducedQuality and rqBlurryLand) = 0 then - DrawTexture(dX + x * TEXSIZE, dY + y * TEXSIZE, tex) - else if (cReducedQuality and rqClampLess) = 0 then - DrawTexture(dX + x * TEXSIZE * 2, dY + y * TEXSIZE * 2, tex, 2.0) - else - DrawTexture2(dX + x * TEXSIZE * 2, dY + y * TEXSIZE * 2, tex, 2.0, BLURRYLANDOVERLAP); + begin + + // don't draw column if offscreen + offscreen:= isDxAreaOffscreen(tX, tSize); + + 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; + + // don't draw texture if offscreen + offscreen:= isDyAreaOffscreen(tY, tSize); + + if offscreen = 0 then + begin + if overlap then + DrawTexture2(tX, ty, tex, tScale, BLURRYLANDOVERLAP) + else + DrawTexture(tX, ty, tex, tScale); + end + + // if below screen, skip remaining textures in this column + else if offscreen > 1 then + break; + end; + + end + // if right of screen, skip remaining columns + else if offscreen > 0 then + break; + + // increment texX + inc(tX, tSize); + end; end; procedure SetLandTexture; diff -r 7e8d4cd76ce7 -r a90a55ec5b98 hedgewars/uRender.pas --- a/hedgewars/uRender.pas Tue Jun 10 08:19:59 2014 +0200 +++ b/hedgewars/uRender.pas Tue Jun 10 08:47:03 2014 +0200 @@ -58,6 +58,12 @@ procedure untint(); inline; procedure setTintAdd (f: boolean); inline; +function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline; + +// 0 => not offscreen, <0 => left/top of screen >0 => right/below of screen +function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline; +function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline; + implementation uses uVariables; @@ -69,6 +75,25 @@ var LastTint: LongWord = 0; +function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline; +begin + isAreaOffscreen:= (isDxAreaOffscreen(X, Width) <> 0) or (isDyAreaOffscreen(Y, Height) <> 0); +end; + +function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline; +begin + if X > ViewRightX then exit(1); + if X + Width < ViewLeftX then exit(-1); + isDxAreaOffscreen:= 0; +end; + +function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline; +begin + if Y > ViewBottomY then exit(1); + if Y + Height < ViewTopY then exit(-1); + isDyAreaOffscreen:= 0; +end; + procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline; begin r.y:= r.y + Height * Position; @@ -188,9 +213,15 @@ var TextureBuffer: array [0..3] of TVertex2f; begin -glPushMatrix(); +{$IFDEF GL2} +hglPushMatrix; +hglTranslatef(X, Y, 0); +hglScalef(Scale, Scale, 1); +{$ELSE} +glPushMatrix; glTranslatef(X, Y, 0); glScalef(Scale, Scale, 1); +{$ENDIF} glBindTexture(GL_TEXTURE_2D, Texture^.id); @@ -203,11 +234,17 @@ TextureBuffer[3].X:= Texture^.tb[3].X + Overlap; TextureBuffer[3].Y:= Texture^.tb[3].Y - Overlap; -glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb); -glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer); +SetVertexPointer(@Texture^.vb, Length(Texture^.vb)); +SetTexCoordPointer(@TextureBuffer, Length(Texture^.vb)); + +{$IFDEF GL2} +UpdateModelviewProjection; glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); - -glPopMatrix(); +hglPopMatrix; +{$ELSE} +glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); +glPopMatrix; +{$ENDIF} end; procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); diff -r 7e8d4cd76ce7 -r a90a55ec5b98 hedgewars/uStore.pas --- a/hedgewars/uStore.pas Tue Jun 10 08:19:59 2014 +0200 +++ b/hedgewars/uStore.pas Tue Jun 10 08:47:03 2014 +0200 @@ -72,6 +72,8 @@ procedure BeginWater; procedure EndWater; +procedure updateViewLimits(); + implementation uses uMisc, uConsole, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands, uPhysFSLayer, uDebug @@ -1175,6 +1177,19 @@ end; *) + +procedure updateViewLimits(); +var tmp: real; +begin + // cScaleFactor is 2.0 on "no zoom" + tmp:= cScreenWidth / cScaleFactor; + ViewRightX:= round(tmp); // ceil could make more sense + ViewLeftX:= round(-tmp); // floor could make more sense + tmp:= cScreenHeight / cScaleFactor; + ViewBottomY:= round(tmp) + cScreenHeight div 2; // ceil could make more sense + ViewTopY:= round(-tmp) + cScreenHeight div 2; // floor could make more sense +end; + procedure SetScale(f: GLfloat); begin // leave immediately if scale factor did not change @@ -1203,6 +1218,7 @@ end; cScaleFactor:= f; + updateViewLimits(); {$IFDEF GL2} UpdateModelviewProjection; @@ -1690,6 +1706,7 @@ RegisterVariable('fullscr', @chFullScr, true); cScaleFactor:= 2.0; + updateViewLimits(); Step:= 0; ProgrTex:= nil; SupportNPOTT:= false; diff -r 7e8d4cd76ce7 -r a90a55ec5b98 hedgewars/uVariables.pas --- a/hedgewars/uVariables.pas Tue Jun 10 08:19:59 2014 +0200 +++ b/hedgewars/uVariables.pas Tue Jun 10 08:47:03 2014 +0200 @@ -211,6 +211,9 @@ WorldDx: LongInt; WorldDy: LongInt; + // for tracking the limits of the visible grid based on cScaleFactor + ViewLeftX, ViewRightX, ViewBottomY, ViewTopY: LongInt; + hiTicks: Word; LuaGoals : shortstring;