- Update land texture after explosions
authorunc0rr
Sun, 27 Jan 2008 17:27:13 +0000
changeset 766 cdc8f75ab7bc
parent 765 a45111da760e
child 767 697728ffe39f
- Update land texture after explosions - Restore loading progress
hedgewars/hwengine.dpr
hedgewars/uLand.pas
hedgewars/uLandGraphics.pas
hedgewars/uStore.pas
--- a/hedgewars/hwengine.dpr	Sun Jan 27 17:04:54 2008 +0000
+++ b/hedgewars/hwengine.dpr	Sun Jan 27 17:27:13 2008 +0000
@@ -111,7 +111,6 @@
               end;
      end;
 
-//SDL_Flip(SDLPrimSurface);
 SDL_GL_SwapBuffers();
 if flagMakeCapture then
    begin
--- a/hedgewars/uLand.pas	Sun Jan 27 17:04:54 2008 +0000
+++ b/hedgewars/uLand.pas	Sun Jan 27 17:27:13 2008 +0000
@@ -25,11 +25,12 @@
 
 var  Land: TLandArray;
      LandSurface: PSDL_Surface;
-     LandTexture: PTexture;
+     LandTexture: PTexture = nil;
 
 procedure GenMap;
-function GenPreview: TPreview;
+function  GenPreview: TPreview;
 procedure CheckLandDigest(s: shortstring);
+procedure UpdateLandTexture;
 
 implementation
 uses uConsole, uStore, uMisc, uRandom, uTeams, uLandObjects, uSHA, uIO;
@@ -532,7 +533,7 @@
 AddObjects(tmpsurf, LandSurface);
 SDL_FreeSurface(tmpsurf);
 
-LandTexture:= Surface2Tex(LandSurface);
+UpdateLandTexture;
 AddProgress
 end;
 
@@ -554,7 +555,7 @@
 BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface);
 SDL_FreeSurface(tmpsurf);
 
-LandTexture:= Surface2Tex(LandSurface)
+UpdateLandTexture
 end;
 
 procedure LoadMap;
@@ -592,7 +593,7 @@
 if SDL_MustLock(LandSurface) then
    SDL_UnlockSurface(LandSurface);
 
-LandTexture:= Surface2Tex(LandSurface)
+UpdateLandTexture
 end;
 
 procedure GenMap;
@@ -628,6 +629,12 @@
 GenPreview:= Preview
 end;
 
+procedure UpdateLandTexture;
+begin
+if LandTexture <> nil then FreeTexture(LandTexture);
+LandTexture:= Surface2Tex(LandSurface)
+end;
+
 initialization
 
 end.
--- a/hedgewars/uLandGraphics.pas	Sun Jan 27 17:04:54 2008 +0000
+++ b/hedgewars/uLandGraphics.pas	Sun Jan 27 17:27:13 2008 +0000
@@ -222,6 +222,8 @@
 
 if SDL_MustLock(LandSurface) then
    SDL_UnlockSurface(LandSurface);
+
+UpdateLandTexture
 end;
 
 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
@@ -252,6 +254,8 @@
 
 if SDL_MustLock(LandSurface) then
    SDL_UnlockSurface(LandSurface);
+
+UpdateLandTexture
 end;
 
 //
@@ -317,7 +321,9 @@
     end;
 
 if SDL_MustLock(LandSurface) then
-   SDL_UnlockSurface(LandSurface)
+   SDL_UnlockSurface(LandSurface);
+
+UpdateLandTexture
 end;
 
 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean;
--- a/hedgewars/uStore.pas	Sun Jan 27 17:04:54 2008 +0000
+++ b/hedgewars/uStore.pas	Sun Jan 27 17:27:13 2008 +0000
@@ -249,7 +249,10 @@
     WriteLnToConsole(msgOK);
     val(s, cExplosionBorderColor, c);
     TryDo(c = 0, 'Theme data corrupted', true);
-    AdjustColor(cExplosionBorderColor);
+    cExplosionBorderColor:= SDL_MapRGB(LandSurface^.format,
+                                       cExplosionBorderColor shr 16,
+                                       cExplosionBorderColor shr 8,
+                                       cExplosionBorderColor and $FF);
     end;
 
 begin
@@ -545,10 +548,7 @@
 end;
 
 procedure SetupOpenGL;
-//var aspect: real;
 begin
-//aspect:= cScreenWidth / cScreenHeight;
-
 glLoadIdentity;
 glViewport(0, 0, cScreenWidth, cScreenHeight);
 glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
@@ -558,32 +558,35 @@
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
-var ProgrSurf: PSDL_Surface = nil;
+var ProgrTex: PTexture = nil;
     Step: integer = 0;
 
 procedure AddProgress;
 var r: TSDL_Rect;
+    texsurf: PSDL_Surface;
 begin
 if Step = 0 then
    begin
    WriteToConsole(msgLoading + 'progress sprite: ');
-   ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true);
+   texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true);
+   ProgrTex:= Surface2Tex(texsurf);
+   SDL_FreeSurface(texsurf)
    end;
-SDL_FillRect(SDLPrimSurface, nil, 0);
+glClear(GL_COLOR_BUFFER_BIT);
 r.x:= 0;
-r.w:= ProgrSurf^.w;
-r.h:= ProgrSurf^.w;
-r.y:= (Step mod (ProgrSurf^.h div ProgrSurf^.w)) * ProgrSurf^.w;
-//DrawFromRect((cScreenWidth - ProgrSurf^.w) div 2,
-//             (cScreenHeight - ProgrSurf^.w) div 2, @r, ProgrSurf, SDLPrimSurface);
-SDL_Flip(SDLPrimSurface);
+r.w:= ProgrTex^.w;
+r.h:= ProgrTex^.w;
+r.y:= (Step mod (ProgrTex^.h div ProgrTex^.w)) * ProgrTex^.w;
+DrawFromRect((cScreenWidth - ProgrTex^.w) div 2,
+             (cScreenHeight - ProgrTex^.w) div 2, @r, ProgrTex, SDLPrimSurface);
+SDL_GL_SwapBuffers();
 inc(Step);
 end;
 
 procedure FinishProgress;
 begin
 WriteLnToConsole('Freeing progress surface... ');
-SDL_FreeSurface(ProgrSurf)
+FreeTexture(ProgrTex)
 end;
 
 end.