# HG changeset patch
# User unc0rr
# Date 1233327599 0
# Node ID 9d88af62a3bb7037b5719c557447c083aecc4889
# Parent  1d9395d1e1045befe139e644fea57230fd3088bf
Cache land texture update until frame render. This greately improves performance when there are many explosions, or you're using drilling weapon

diff -r 1d9395d1e104 -r 9d88af62a3bb hedgewars/uLand.pas
--- a/hedgewars/uLand.pas	Fri Jan 30 14:57:02 2009 +0000
+++ b/hedgewars/uLand.pas	Fri Jan 30 14:59:59 2009 +0000
@@ -38,6 +38,7 @@
 function  GenPreview: TPreview;
 procedure CheckLandDigest(s: shortstring);
 procedure UpdateLandTexture(Y, Height: LongInt);
+procedure RealLandTexUpdate;
 
 implementation
 uses uConsole, uStore, uMisc, uRandom, uTeams, uLandObjects, uSHA, uIO;
@@ -47,6 +48,9 @@
               ar: array[0..Pred(cMaxEdgePoints)] of TPoint;
               end;
 
+var updTopY: LongInt = LAND_HEIGHT;
+    updBottomY: LongInt = 0;
+
 procedure LogLandDigest;
 var ctx: TSHA1Context;
     dig: TSHA1Digest;
@@ -730,15 +734,27 @@
 TryDo((Y >= 0) and (Y < LAND_HEIGHT), 'UpdateLandTexture: wrong Y parameter', true);
 TryDo(Y + Height <= LAND_HEIGHT, 'UpdateLandTexture: wrong Height parameter', true);
 
+if Y < updTopY then updTopY:= Y;
+if Y + Height > updBottomY then updBottomY:= Y + Height
+end;
+
+procedure RealLandTexUpdate;
+begin
+if updBottomY = 0 then exit;
+
 if LandTexture = nil then
 	LandTexture:= NewTexture(LAND_WIDTH, LAND_HEIGHT, @LandPixels)
 else
 	begin
 	glBindTexture(GL_TEXTURE_2D, LandTexture^.id);
-	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, Y, LAND_WIDTH, Height, GL_RGBA, GL_UNSIGNED_BYTE, @LandPixels[Y, 0]);
-	end
+	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, updTopY, LAND_WIDTH, updBottomY - updTopY, GL_RGBA, GL_UNSIGNED_BYTE, @LandPixels[updTopY, 0]);
+	end;
+
+updTopY:= LAND_HEIGHT + 1;
+updBottomY:= 0
 end;
 
+
 initialization
 
 end.
diff -r 1d9395d1e104 -r 9d88af62a3bb hedgewars/uWorld.pas
--- a/hedgewars/uWorld.pas	Fri Jan 30 14:57:02 2009 +0000
+++ b/hedgewars/uWorld.pas	Fri Jan 30 14:59:59 2009 +0000
@@ -40,7 +40,8 @@
 
 implementation
 uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, GL,
-     uAmmos, uVisualGears, uChat;
+     uAmmos, uVisualGears, uChat, uLand;
+     
 const FPS: Longword = 0;
       CountTicks: Longword = 0;
       SoundTimerTicks: Longword = 0;
@@ -190,6 +191,8 @@
 //glPushMatrix;
 //glScalef(1.0, 1.0, 1.0);
 
+RealLandTexUpdate;
+
 if not isPaused then MoveCamera;
 
 // background