Move land hash checking into commands
authorunc0rr
Sat, 20 Nov 2010 23:48:04 +0300
changeset 4389 d1c65b60cd68
parent 4388 b14e24444bca
child 4390 f219628ed666
Move land hash checking into commands
hedgewars/CCHandlers.inc
hedgewars/hwengine.pas
hedgewars/uCommands.pas
hedgewars/uIO.pas
hedgewars/uLand.pas
hedgewars/uLandObjects.pas
--- a/hedgewars/CCHandlers.inc	Sat Nov 20 23:20:46 2010 +0300
+++ b/hedgewars/CCHandlers.inc	Sat Nov 20 23:48:04 2010 +0300
@@ -847,3 +847,26 @@
     s:= s; // avoid compiler hint
     uChat.showAll:= not uChat.showAll
 end;
+
+procedure chLandCheck(var s: shortstring);
+begin
+{$IFDEF DEBUGFILE}
+    AddFileLog('CheckLandDigest: ' + s + ' digest : ' + digest);
+{$ENDIF}
+    if digest = '' then
+        digest:= s
+    else
+        TryDo(s = digest, 'Different maps generated, sorry', true);
+end;
+
+procedure chSendLandDigest(var s: shortstring);
+var adler, i: LongInt;
+begin
+    adler:= 1;
+    for i:= 0 to LAND_HEIGHT-1 do
+        Adler32Update(adler, @Land[i,0], LAND_WIDTH);
+    s:= 'M' + IntToStr(adler);
+
+    chLandCheck(s);
+    SendIPCRaw(@s[0], Length(s) + 1)
+end;
--- a/hedgewars/hwengine.pas	Sat Nov 20 23:20:46 2010 +0300
+++ b/hedgewars/hwengine.pas	Sat Nov 20 23:48:04 2010 +0300
@@ -56,6 +56,7 @@
     case GameState of
         gsLandGen: begin
                 GenMap;
+                ParseCommand('sendlanddigest', true);
                 GameState:= gsStart;
                 end;
         gsStart: begin
--- a/hedgewars/uCommands.pas	Sat Nov 20 23:20:46 2010 +0300
+++ b/hedgewars/uCommands.pas	Sat Nov 20 23:48:04 2010 +0300
@@ -17,7 +17,7 @@
 implementation
 uses uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uMobile,
      uRandom, uAmmos, uStats, uChat, SDLh, uSound, uVisualGears, uScript, uTypes,
-     uVariables, uConsole, uFloat, uUtils;
+     uVariables, uConsole, uFloat, uUtils, Adler32;
 
 type  PVariable = ^TVariable;
       TVariable = record
@@ -125,6 +125,8 @@
     isDeveloperMode:= true;
 
     // NOTE: please, keep most frequently used commands on bottom
+    RegisterVariable('landcheck',vtCommand, @chLandCheck    , false);
+    RegisterVariable('sendlanddigest',vtCommand, @chSendLandDigest, false);
     RegisterVariable('flag'    , vtCommand, @chFlag         , false);
     RegisterVariable('script'  , vtCommand, @chScript       , false);
     RegisterVariable('proto'   , vtCommand, @chCheckProto   , true );
--- a/hedgewars/uIO.pas	Sat Nov 20 23:20:46 2010 +0300
+++ b/hedgewars/uIO.pas	Sat Nov 20 23:48:04 2010 +0300
@@ -47,7 +47,7 @@
 procedure NetGetNextCmd;
 
 implementation
-uses uConsole, uConsts, uLand, uChat, uTeams, uVariables, uCommands, uUtils;
+uses uConsole, uConsts, uChat, uTeams, uVariables, uCommands, uUtils;
 
 type PCmd = ^TCmd;
      TCmd = packed record
@@ -154,7 +154,7 @@
      'e': ParseCommand(copy(s, 2, Length(s) - 1), true);
      'E': OutError(copy(s, 2, Length(s) - 1), true);
      'W': OutError(copy(s, 2, Length(s) - 1), false);
-     'M': CheckLandDigest(s);
+     'M': ParseCommand('landcheck ' + s, true);
      'T': case s[2] of
                'L': GameType:= gmtLocal;
                'D': GameType:= gmtDemo;
--- a/hedgewars/uLand.pas	Sat Nov 20 23:20:46 2010 +0300
+++ b/hedgewars/uLand.pas	Sat Nov 20 23:48:04 2010 +0300
@@ -32,10 +32,9 @@
 procedure freeModule;
 procedure GenMap;
 function  GenPreview: TPreview;
-procedure CheckLandDigest(s: shortstring);
 
 implementation
-uses uConsole, uStore, uRandom, uLandObjects, Adler32, uIO, uLandTexture, sysutils,
+uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture, sysutils,
      uVariables, uUtils;
 
 operator=(const a, b: direction) c: Boolean;
@@ -48,30 +47,6 @@
               ar: array[0..Pred(cMaxEdgePoints)] of TPoint;
               end;
 
-procedure LogLandDigest;
-var s: shortstring;
-    adler, i: LongInt;
-begin
-adler:= 1;
-for i:= 0 to LAND_HEIGHT-1 do
-    Adler32Update(adler, @Land[i,0], LAND_WIDTH);
-s:= 'M'+inttostr(adler);
-
-CheckLandDigest(s);
-SendIPCRaw(@s[0], Length(s) + 1)
-end;
-
-procedure CheckLandDigest(s: shortstring);
-begin
-{$IFDEF DEBUGFILE}
-    AddFileLog('CheckLandDigest: ' + s + ' digest : ' + digest);
-{$ENDIF}
-    if digest = '' then
-        digest:= s
-    else
-        TryDo(s = digest, 'Different maps generated, sorry', true);
-end;
-
 procedure DrawLine(X1, Y1, X2, Y2: LongInt; Color: Longword);
 var
   eX, eY, dX, dY: LongInt;
@@ -1212,8 +1187,6 @@
 
     AddProgress;
 
-{$IFDEF DEBUGFILE}LogLandDigest;{$ENDIF}
-
 // check for land near top
 c:= 0;
 if (GameFlags and gfBorder) <> 0 then
--- a/hedgewars/uLandObjects.pas	Sat Nov 20 23:20:46 2010 +0300
+++ b/hedgewars/uLandObjects.pas	Sat Nov 20 23:48:04 2010 +0300
@@ -29,7 +29,7 @@
 procedure AddOnLandObjects(Surface: PSDL_Surface);
 
 implementation
-uses uStore, uConsts, uMisc, uConsole, uRandom, uVisualGears, uSound, GLunit,
+uses uStore, uConsts, uConsole, uRandom, uVisualGears, uSound, GLunit,
      uTypes, uVariables, uUtils, uIO;
 
 const MaxRects = 512;