Cache land texture update until frame render. This greately improves performance when there are many explosions, or you're using drilling weapon
authorunc0rr
Fri, 30 Jan 2009 14:59:59 +0000
changeset 1779 9d88af62a3bb
parent 1778 1d9395d1e104
child 1780 9b26e9f6ee96
Cache land texture update until frame render. This greately improves performance when there are many explosions, or you're using drilling weapon
hedgewars/uLand.pas
hedgewars/uWorld.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.
--- 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