extend land digest to all surfaces that could possibly be loaded into Land[] - i.e. ones that impact sync
authornemo
Wed, 18 Oct 2017 20:33:20 -0400
changeset 12711 20dbb3a03e61
parent 12710 1ab53b945140
child 12712 31f7e0a31736
extend land digest to all surfaces that could possibly be loaded into Land[] - i.e. ones that impact sync
hedgewars/hwengine.pas
hedgewars/uLand.pas
hedgewars/uLandObjects.pas
hedgewars/uStore.pas
hedgewars/uVariables.pas
--- a/hedgewars/hwengine.pas	Wed Oct 18 05:28:22 2017 +0200
+++ b/hedgewars/hwengine.pas	Wed Oct 18 20:33:20 2017 -0400
@@ -74,7 +74,6 @@
             SetLandTexture;
             UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT, false);
             setAILandMarks;
-            ParseCommand('sendlanddigest', true);
             GameState:= gsStart;
             end;
         gsStart:
@@ -88,6 +87,7 @@
             AddFlakes;
             SetRandomSeed(cSeed, false);
             StoreLoad(false);
+            ParseCommand('sendlanddigest', true); // extending land digest to all synced pixels (anything that could modify land)
             if not allOK then exit;
             AssignHHCoords;
             AddMiscGears;
--- a/hedgewars/uLand.pas	Wed Oct 18 05:28:22 2017 +0200
+++ b/hedgewars/uLand.pas	Wed Oct 18 20:33:20 2017 -0400
@@ -978,16 +978,15 @@
     if digest = '' then
         digest:= s
     else
-        checkFails(s = digest, 'Different maps generated, sorry', true);
+        checkFails(s = digest, 'Different map or critical resources loaded, sorry', true);
 end;
 
 procedure chSendLandDigest(var s: shortstring);
-var adler, i: LongInt;
+var i: LongInt;
 begin
-    adler:= 1;
     for i:= 0 to LAND_HEIGHT-1 do
-        adler:= Adler32Update(adler, @Land[i,0], LAND_WIDTH);
-    s:= 'M' + IntToStr(adler) + cScriptName;
+        syncedPixelDigest:= Adler32Update(syncedPixelDigest, @Land[i,0], LAND_WIDTH);
+    s:= 'M' + IntToStr(syncedPixelDigest); // + cScriptName; script name is no longer needed. scripts are hashed
 
     ScriptSetString('LandDigest', s);
 
--- a/hedgewars/uLandObjects.pas	Wed Oct 18 05:28:22 2017 +0200
+++ b/hedgewars/uLandObjects.pas	Wed Oct 18 20:33:20 2017 -0400
@@ -35,7 +35,7 @@
 implementation
 uses uStore, uConsts, uConsole, uRandom, uSound
      , uTypes, uVariables, uDebug, uUtils
-     , uPhysFSLayer;
+     , uPhysFSLayer, adler32;
 
 const MaxRects = 512;
       MAXOBJECTRECTS = 16;
@@ -261,6 +261,9 @@
 if girSurf = nil then
     girSurf:= LoadDataImageAltPath(ptCurrTheme, ptGraphics, 'Girder', ifCritical or ifColorKey or ifIgnoreCaps);
 
+for y := 0 to girsurf^.h-1 do
+    syncedPixelDigest:= Adler32Update(syncedPixelDigest, @PLongWordArray(girsurf^.pixels)^[y*girsurf^.w], girsurf^.w);
+
 girderHeight:= girSurf^.h;
 
 y:= topY+150;
@@ -498,7 +501,7 @@
 procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects);
 var s, key: shortstring;
     f: PFSFile;
-    i: LongInt;
+    i, y: LongInt;
     ii, t: Longword;
     c2: TSDL_Color;
 begin
@@ -695,6 +698,8 @@
             Delete(s, 1, i);
             if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then
                 OutError('Object''s max count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true);
+            for y := 0 to Surf^.h-1 do
+                syncedPixelDigest:= Adler32Update(syncedPixelDigest, @PLongWordArray(Surf^.pixels)^[y*Surf^.w], Surf^.w);
 
             inrectcnt := 0;
 
--- a/hedgewars/uStore.pas	Wed Oct 18 05:28:22 2017 +0200
+++ b/hedgewars/uStore.pas	Wed Oct 18 20:33:20 2017 -0400
@@ -62,7 +62,7 @@
 
 implementation
 uses uMisc, uConsole, uVariables, uUtils, uTextures, uRender, uRenderUtils,
-     uCommands, uPhysFSLayer, uDebug
+     uCommands, uPhysFSLayer, uDebug, adler32
     {$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF};
 
 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
@@ -373,7 +373,7 @@
 var ii: TSprite;
     ai: TAmmoType;
     tmpsurf, tmpoverlay: PSDL_Surface;
-    i, imflags: LongInt;
+    i, y, imflags: LongInt;
 begin
 AddFileLog('StoreLoad()');
 
@@ -471,6 +471,10 @@
 {$IFDEF USE_CONTEXT_RESTORE}
                     Surface:= tmpsurf
 {$ELSE}
+                    if checkSum then
+                        for y := 0 to tmpsurf^.h-1 do
+                            syncedPixelDigest:= Adler32Update(syncedPixelDigest, @PLongWordArray(tmpsurf^.pixels)^[y*tmpsurf^.w], tmpsurf^.w);
+
                     if saveSurf then
                         Surface:= tmpsurf
                     else
--- a/hedgewars/uVariables.pas	Wed Oct 18 05:28:22 2017 +0200
+++ b/hedgewars/uVariables.pas	Wed Oct 18 20:33:20 2017 -0400
@@ -69,7 +69,8 @@
     cAudioCodec        : shortstring;
 {$ENDIF}
 //////////////////////////
-    cMapName        : shortstring;
+    cMapName           : shortstring;
+    syncedPixelDigest  : LongInt;
     isCursorVisible : boolean;
     isInLag         : boolean;
     isPaused        : boolean;
@@ -2855,6 +2856,7 @@
 
     LuaGoals:= '';
     cMapName:= '';
+    syncedPixelDigest:= 1;
 
     LuaTemplateNumber:= 0;