add permenent digest logging
authoralfadur
Mon, 26 Aug 2019 23:17:17 +0300
changeset 15360 34eb5cc72241
parent 15359 c117e17b90bc
child 15363 c5934cdeecb6
add permenent digest logging
hedgewars/uConsts.pas
hedgewars/uLandObjects.pas
hedgewars/uStore.pas
--- a/hedgewars/uConsts.pas	Mon Aug 26 14:27:03 2019 -0400
+++ b/hedgewars/uConsts.pas	Mon Aug 26 23:17:17 2019 +0300
@@ -110,6 +110,8 @@
     ifCritical    = $00000002;  // image is critical for gameplay (exit game if unable to load)
     ifColorKey    = $00000004;  // image uses transparent pixels (color keying)
     ifIgnoreCaps  = $00000008;  // ignore hardware capabilities when loading (i.e. image will not be drawn using OpenGL)
+    ifDigestAlpha = $00000010;  // add alpha channel to the digest
+    ifDigestAll   = $00000020;  // add all channels to the digest
 
     // texture priority (allows OpenGL to keep frequently used textures in video memory more easily)
     tpLowest      = 0.00;
--- a/hedgewars/uLandObjects.pas	Mon Aug 26 14:27:03 2019 -0400
+++ b/hedgewars/uLandObjects.pas	Mon Aug 26 23:17:17 2019 +0300
@@ -36,7 +36,7 @@
 implementation
 uses uStore, uConsts, uConsole, uRandom, uSound
      , uTypes, uVariables, uDebug, uUtils
-     , uPhysFSLayer, adler32, uRenderUtils;
+     , uPhysFSLayer, uRenderUtils;
 
 const MaxRects = 512;
       MAXOBJECTRECTS = 16;
@@ -346,51 +346,13 @@
     CountNonZeroz:= lRes;
 end;
 
-procedure ChecksumLandObjectImage(Image: PSDL_Surface; alphaOnly: boolean);
-var y, x: LongInt;
-var rowData: PByteArray;
-begin
-    if Image = nil then exit;
-
-    if alphaOnly then
-        rowData := GetMem(Image^.w);
-
-    if SDL_MustLock(Image) then
-        SDL_LockSurface(Image);
-
-    if checkFails(Image^.format^.BytesPerPixel = 4, 'Land object image should be 32bit', true) then
-    begin
-        if SDL_MustLock(Image) then
-            SDL_UnlockSurface(Image);
-        exit
-    end;
-
-    for y := 0 to Image^.h - 1 do
-        if alphaOnly then
-            begin
-            for x := 0 to Image^.w - 1 do
-                rowData^[x] := PByteArray(Image^.pixels)^[y * Image^.pitch + x * 4 + AByteIndex];
-            syncedPixelDigest:= Adler32Update(syncedPixelDigest, rowData, Image^.w);
-            end
-        else
-            syncedPixelDigest:= Adler32Update(syncedPixelDigest, @PByteArray(Image^.pixels)^[y*Image^.pitch], Image^.w*4);
-
-    if SDL_MustLock(Image) then
-        SDL_UnlockSurface(Image);
-
-    if alphaOnly then
-        FreeMem(rowData, Image^.w);
-end;
-
 function AddGirder(gX: LongInt; var girSurf: PSDL_Surface): boolean;
 var x1, x2, y, k, i, girderHeight: LongInt;
     rr: TSDL_Rect;
     bRes: boolean;
 begin
 if girSurf = nil then
-    girSurf:= LoadDataImageAltPath(ptCurrTheme, ptGraphics, 'Girder', ifCritical or ifColorKey or ifIgnoreCaps);
-
-ChecksumLandObjectImage(girsurf, true);
+    girSurf:= LoadDataImageAltPath(ptCurrTheme, ptGraphics, 'Girder', ifCritical or ifColorKey or ifIgnoreCaps or ifDigestAlpha);
 
 girderHeight:= girSurf^.h;
 
@@ -745,11 +707,10 @@
     Delete(s, 1, i);
     i:= Pos(',', s);
     if i = 0 then i:= Succ(Length(S));
-    Surf:= LoadDataImage(ptCurrTheme, Trim(Copy(s, 1, Pred(i))), ifColorKey or ifIgnoreCaps or ifCritical);
+    Surf:= LoadDataImage(ptCurrTheme, Trim(Copy(s, 1, Pred(i))), ifColorKey or ifIgnoreCaps or ifCritical or ifDigestAlpha );
     Width:= Surf^.w;
     Height:= Surf^.h;
     Delete(s, 1, i);
-    ChecksumLandObjectImage(Surf, true);
     end;
 end;
 
@@ -949,19 +910,22 @@
             begin
             i:= Pos(',', s);
             Name:= Trim(Copy(s, 1, Pred(i)));
-            Surf:= LoadDataImage(ptCurrTheme, Name, ifColorKey or ifIgnoreCaps or ifCritical);
+
+            Mask:= LoadDataImage(ptCurrTheme, Trim(Copy(s, 1, Pred(i)))+'_mask', ifColorKey or ifIgnoreCaps or ifDigestAll);
+            if Mask = nil then
+                Surf:= LoadDataImage(ptCurrTheme, Name, ifColorKey or ifIgnoreCaps or ifCritical or ifDigestAlpha)
+            else
+                Surf:= LoadDataImage(ptCurrTheme, Name, ifColorKey or ifIgnoreCaps or ifCritical);
+
             Width:= Surf^.w;
             Height:= Surf^.h;
-            Mask:= LoadDataImage(ptCurrTheme, Trim(Copy(s, 1, Pred(i)))+'_mask', ifColorKey or ifIgnoreCaps);
+
             Delete(s, 1, i);
             i:= Pos(',', s);
             Maxcnt:= StrToInt(Trim(Copy(s, 1, Pred(i))));
             Delete(s, 1, i);
             if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then
                 OutError('Broken theme. Object''s max. count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true);
-            if Mask = nil then
-                ChecksumLandObjectImage(Surf, true);
-            ChecksumLandObjectImage(Mask, false);
 
             inrectcnt := 0;
 
--- a/hedgewars/uStore.pas	Mon Aug 26 14:27:03 2019 -0400
+++ b/hedgewars/uStore.pas	Mon Aug 26 23:17:17 2019 +0300
@@ -385,8 +385,7 @@
 var ii: TSprite;
     ai: TAmmoType;
     tmpsurf, tmpoverlay: PSDL_Surface;
-    i, y, x, imflags: LongInt;
-    rowData: PByteArray;
+    i, imflags: LongInt;
     keyConfirm, keyQuit: shortstring;
 begin
 AddFileLog('StoreLoad()');
@@ -431,18 +430,10 @@
                     imflags := (imflags or ifCritical);
 
                 // load the image
-                tmpsurf := LoadDataImageAltPath(Path, AltPath, FileName, imflags);
-                if (tmpsurf <> nil) and checkSum then
-                    begin
-                    rowData := GetMem(tmpsurf^.w);
-                    for y := 0 to tmpsurf^.h-1 do
-                        begin
-                        for x := 0 to tmpsurf^.w - 1 do
-                            rowData^[x] := PByteArray(tmpsurf^.pixels)^[y * tmpsurf^.pitch + x * 4 + AByteIndex];
-                        syncedPixelDigest:= Adler32Update(syncedPixelDigest, rowData, tmpsurf^.w);
-                        end;
-                    FreeMem(rowData, tmpsurf^.w);
-                    end;
+                if checkSum then
+                    tmpsurf := LoadDataImageAltPath(Path, AltPath, FileName, imflags or ifDigestAlpha)
+                else
+                    tmpsurf := LoadDataImageAltPath(Path, AltPath, FileName, imflags);
                 end;
 
             if tmpsurf <> nil then
@@ -646,10 +637,13 @@
 function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
 var tmpsurf: PSDL_Surface;
     s: shortstring;
-    logMsg: shortstring;
+    logMsg, digestMsg: shortstring;
     rwops: PSDL_RWops;
+    y, x: LongInt;
+    rowData: PByteArray;
 begin
     LoadImage:= nil;
+    digestMsg:= '';
     logMsg:= msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + ']';
 
     s:= filename + '.png';
@@ -700,8 +694,37 @@
     if (imageFlags and ifColorKey) <> 0 then
         if checkFails(SDL_SetColorKey(tmpsurf, SDL_TRUE, 0) = 0, errmsgTransparentSet, true) then exit;
 
+    if ((imageFlags and (ifDigestAll or ifDigestAlpha)) <> 0)
+        and (tmpsurf^.format^.BytesPerPixel = 4)then
+        begin
+        if SDL_MustLock(tmpsurf) then
+            SDL_LockSurface(tmpsurf);
+
+        if (imageFlags and ifDigestAll) <> 0 then
+            begin
+            for y := 0 to tmpsurf^.h - 1 do
+                syncedPixelDigest:= Adler32Update(syncedPixelDigest, @PByteArray(tmpsurf^.pixels)^[y*tmpsurf^.pitch], tmpsurf^.w*4);
+            digestMsg := ' [CD: ' + inttostr(syncedPixelDigest) + ']'
+            end
+        else if (imageFlags and ifDigestAlpha) <> 0 then
+            begin
+            rowData := GetMem(tmpsurf^.w);
+            for y := 0 to tmpsurf^.h - 1 do
+                begin
+                for x := 0 to tmpsurf^.w - 1 do
+                    rowData^[x] := PByteArray(tmpsurf^.pixels)^[y * tmpsurf^.pitch + x * 4 + AByteIndex];
+                syncedPixelDigest:= Adler32Update(syncedPixelDigest, rowData, tmpsurf^.w);
+                end;
+            FreeMem(rowData, tmpsurf^.w);
+            digestMsg := ' [AD: ' + inttostr(syncedPixelDigest) + ']'
+            end;
+
+        if SDL_MustLock(tmpsurf) then
+            SDL_UnlockSurface(tmpsurf);
+        end;
+
     // log success
-    WriteLnToConsole(logMsg + ' ' + msgOK + ' (' + inttostr(tmpsurf^.w) + 'x' + inttostr(tmpsurf^.h) + ')');
+    WriteLnToConsole(logMsg + ' ' + msgOK + ' (' + inttostr(tmpsurf^.w) + 'x' + inttostr(tmpsurf^.h) + ')' + digestMsg);
 
     LoadImage:= tmpsurf //Result
 end;