hedgewars/uLand.pas
branchtransitional_engine
changeset 15901 f39f0f614dbf
parent 15900 128ace913837
child 15904 33798b649d9c
equal deleted inserted replaced
15900:128ace913837 15901:f39f0f614dbf
    39     maskOnly: boolean;
    39     maskOnly: boolean;
    40 
    40 
    41 procedure PrettifyLandAlpha();
    41 procedure PrettifyLandAlpha();
    42 begin
    42 begin
    43     if (cReducedQuality and rqBlurryLand) <> 0 then
    43     if (cReducedQuality and rqBlurryLand) <> 0 then
    44         PrettifyAlpha2D(LandPixels, LAND_HEIGHT div 2, LAND_WIDTH div 2)
    44         PrettifyAlpha2D(LAND_HEIGHT div 2, LAND_WIDTH div 2)
    45     else
    45     else
    46         PrettifyAlpha2D(LandPixels, LAND_HEIGHT, LAND_WIDTH);
    46         PrettifyAlpha2D(LAND_HEIGHT, LAND_WIDTH);
    47 end;
    47 end;
    48 
    48 
    49 procedure DrawBorderFromImage(Surface: PSDL_Surface);
    49 procedure DrawBorderFromImage(Surface: PSDL_Surface);
    50 var tmpsurf: PSDL_Surface;
    50 var tmpsurf: PSDL_Surface;
    51     x, yd, yu: LongInt;
    51     x, yd, yu: LongInt;
   105                     for i:= max(s, y - 8) to y - 1 do
   105                     for i:= max(s, y - 8) to y - 1 do
   106                         begin
   106                         begin
   107                         if ((x + i) and 16) = 0 then c:= c1 else c:= c2;
   107                         if ((x + i) and 16) = 0 then c:= c1 else c:= c2;
   108 
   108 
   109                         if (cReducedQuality and rqBlurryLand) = 0 then
   109                         if (cReducedQuality and rqBlurryLand) = 0 then
   110                             LandPixels[i, x]:= c
   110                             LandPixelSet(i, x, c)
   111                         else
   111                         else
   112                             LandPixels[i div 2, x div 2]:= c
   112                             LandPixelSet(i div 2, x div 2, c)
   113                         end;
   113                         end;
   114                     s:= LAND_HEIGHT
   114                     s:= LAND_HEIGHT
   115                     end
   115                     end
   116                 else
   116                 else
   117             else
   117             else
   120                 if s + 8 > y then
   120                 if s + 8 > y then
   121                     begin
   121                     begin
   122                     if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
   122                     if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
   123 
   123 
   124                     if (cReducedQuality and rqBlurryLand) = 0 then
   124                     if (cReducedQuality and rqBlurryLand) = 0 then
   125                         LandPixels[y, x]:= c
   125                         LandPixelSet(y, x, c)
   126                     else
   126                     else
   127                         LandPixels[y div 2, x div 2]:= c
   127                         LandPixelSet(y div 2, x div 2, c)
   128                     end;
   128                     end;
   129                 end;
   129                 end;
   130 
   130 
   131     // horizontal
   131     // horizontal
   132     s:= LAND_WIDTH;
   132     s:= LAND_WIDTH;
   139                     for i:= max(s, x - 8) to x - 1 do
   139                     for i:= max(s, x - 8) to x - 1 do
   140                         begin
   140                         begin
   141                         if ((y + i) and 16) = 0 then c:= c1 else c:= c2;
   141                         if ((y + i) and 16) = 0 then c:= c1 else c:= c2;
   142 
   142 
   143                         if (cReducedQuality and rqBlurryLand) = 0 then
   143                         if (cReducedQuality and rqBlurryLand) = 0 then
   144                             LandPixels[y, i]:= c
   144                             LandPixelSet(y, i, c)
   145                         else
   145                         else
   146                             LandPixels[y div 2, i div 2]:= c
   146                             LandPixelSet(y div 2, i div 2, c)
   147                         end;
   147                         end;
   148                     s:= LAND_WIDTH
   148                     s:= LAND_WIDTH
   149                     end
   149                     end
   150                 else
   150                 else
   151             else
   151             else
   154                 if s + 8 > x then
   154                 if s + 8 > x then
   155                     begin
   155                     begin
   156                     if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
   156                     if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
   157 
   157 
   158                     if (cReducedQuality and rqBlurryLand) = 0 then
   158                     if (cReducedQuality and rqBlurryLand) = 0 then
   159                         LandPixels[y, x]:= c
   159                         LandPixelSet(y, x, c)
   160                     else
   160                     else
   161                         LandPixels[y div 2, x div 2]:= c
   161                         LandPixelSet(y div 2, x div 2, c)
   162                     end;
   162                     end;
   163                 end
   163                 end
   164 end;
   164 end;
   165 
   165 
   166 procedure ColorizeLandFast(mapsurf: PSDL_Surface);
   166 procedure ColorizeLandFast(mapsurf: PSDL_Surface);
   404 for y:= 0 to LAND_HEIGHT - 1 do
   404 for y:= 0 to LAND_HEIGHT - 1 do
   405     begin
   405     begin
   406     for x:= 0 to LAND_WIDTH - 1 do
   406     for x:= 0 to LAND_WIDTH - 1 do
   407     if LandGet(y, x) <> 0 then
   407     if LandGet(y, x) <> 0 then
   408         if (cReducedQuality and rqBlurryLand) = 0 then
   408         if (cReducedQuality and rqBlurryLand) = 0 then
   409             LandPixels[y, x]:= p^[x]// or AMask
   409             LandPixelSet(y, x, p^[x])// or AMask
   410         else
   410         else
   411             LandPixels[y div 2, x div 2]:= p^[x];
   411             LandPixelSet(y div 2, x div 2, p^[x]);
   412 
   412 
   413     p:= PLongwordArray(@(p^[Surface^.pitch div 4]));
   413     p:= PLongwordArray(@(p^[Surface^.pitch div 4]));
   414     end;
   414     end;
   415 
   415 
   416 if SDL_MustLock(Surface) then
   416 if SDL_MustLock(Surface) then
   442                (((LandGet(y, x-1) = lfBasic) and ((LandGet(y+1,x) = lfBasic)) or (LandGet(y-1,x) = lfBasic)) or
   442                (((LandGet(y, x-1) = lfBasic) and ((LandGet(y+1,x) = lfBasic)) or (LandGet(y-1,x) = lfBasic)) or
   443                ((LandGet(y, x+1) = lfBasic) and ((LandGet(y-1,x) = lfBasic) or (LandGet(y+1,x) = lfBasic)))) then
   443                ((LandGet(y, x+1) = lfBasic) and ((LandGet(y-1,x) = lfBasic) or (LandGet(y+1,x) = lfBasic)))) then
   444             begin
   444             begin
   445                 if (cReducedQuality and rqBlurryLand) = 0 then
   445                 if (cReducedQuality and rqBlurryLand) = 0 then
   446                     begin
   446                     begin
   447                     if (LandGet(y, x-1) = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then
   447                     if (LandGet(y, x-1) = lfBasic) and (LandPixelGet(y, x-1) and AMask <> 0) then
   448                         LandPixels[y, x]:= LandPixels[y, x-1]
   448                         LandPixelSet(y, x, LandPixelGet(y, x-1))
   449 
   449 
   450                     else if (LandGet(y, x+1) = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then
   450                     else if (LandGet(y, x+1) = lfBasic) and (LandPixelGet(y, x+1) and AMask <> 0) then
   451                         LandPixels[y, x]:= LandPixels[y, x+1]
   451                         LandPixelSet(y, x, LandPixelGet(y, x+1))
   452 
   452 
   453                     else if (LandGet(y-1, x) = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then
   453                     else if (LandGet(y-1, x) = lfBasic) and (LandPixelGet(y-1, x) and AMask <> 0) then
   454                         LandPixels[y, x]:= LandPixels[y-1, x]
   454                         LandPixelSet(y, x, LandPixelGet(y-1, x))
   455 
   455 
   456                     else if (LandGet(y+1, x) = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then
   456                     else if (LandGet(y+1, x) = lfBasic) and (LandPixelGet(y+1, x) and AMask <> 0) then
   457                         LandPixels[y, x]:= LandPixels[y+1, x];
   457                         LandPixelSet(y, x, LandPixelGet(y+1, x));
   458 
   458 
   459                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
   459                     if (((LandPixelGet(y,x) and AMask) shr AShift) > 10) then
   460                         LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift)
   460                         LandPixelSet(y, x, (LandPixelGet(y,x) and (not AMask)) or (128 shl AShift))
   461                     end;
   461                     end;
   462                 LandSet(y, x, lfObject)
   462                 LandSet(y, x, lfObject)
   463             end
   463             end
   464             else if (LandGet(y, x) = 0) and
   464             else if (LandGet(y, x) = 0) and
   465                     (((LandGet(y, x-1) = lfBasic) and (LandGet(y+1,x-1) = lfBasic) and (LandGet(y+2,x) = lfBasic)) or
   465                     (((LandGet(y, x-1) = lfBasic) and (LandGet(y+1,x-1) = lfBasic) and (LandGet(y+2,x) = lfBasic)) or
   475 
   475 
   476                 if (cReducedQuality and rqBlurryLand) = 0 then
   476                 if (cReducedQuality and rqBlurryLand) = 0 then
   477 
   477 
   478                     begin
   478                     begin
   479 
   479 
   480                     if (LandGet(y, x-1) = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then
   480                     if (LandGet(y, x-1) = lfBasic) and (LandPixelGet(y,x-1) and AMask <> 0) then
   481                         LandPixels[y, x]:= LandPixels[y, x-1]
   481                         LandPixelSet(y, x, LandPixelGet(y, x-1))
   482 
   482 
   483                     else if (LandGet(y, x+1) = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then
   483                     else if (LandGet(y, x+1) = lfBasic) and (LandPixelGet(y,x+1) and AMask <> 0) then
   484                         LandPixels[y, x]:= LandPixels[y, x+1]
   484                         LandPixelSet(y, x, LandPixelGet(y, x+1))
   485 
   485 
   486                     else if (LandGet(y+1, x) = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then
   486                     else if (LandGet(y+1, x) = lfBasic) and (LandPixelGet(y+1,x) and AMask <> 0) then
   487                         LandPixels[y, x]:= LandPixels[y+1, x]
   487                         LandPixelSet(y, x, LandPixelGet(y+1, x))
   488 
   488 
   489                     else if (LandGet(y-1, x) = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then
   489                     else if (LandGet(y-1, x) = lfBasic) and (LandPixelGet(y-1,x) and AMask <> 0) then
   490                         LandPixels[y, x]:= LandPixels[y-1, x];
   490                         LandPixelSet(y, x, LandPixelGet(y-1, x));
   491 
   491 
   492                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
   492                     if (((LandPixelGet(y,x) and AMask) shr AShift) > 10) then
   493                         LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift)
   493                         LandPixelSet(y, x, (LandPixelGet(y,x) and (not AMask)) or (64 shl AShift))
   494                     end;
   494                     end;
   495                 LandSet(y, x, lfObject)
   495                 LandSet(y, x, lfObject)
   496             end;
   496             end;
   497 
   497 
   498     AddProgress();
   498     AddProgress();
   760             c:= AMask
   760             c:= AMask
   761         else
   761         else
   762             c:= AMask or RMask or GMask; // FF00FFFF
   762             c:= AMask or RMask or GMask; // FF00FFFF
   763 
   763 
   764         if (cReducedQuality and rqBlurryLand) = 0 then
   764         if (cReducedQuality and rqBlurryLand) = 0 then
   765             LandPixels[y, x]:= c
   765             LandPixelSet(y, x, c)
   766         else
   766         else
   767             LandPixels[y div 2, x div 2]:= c
   767             LandPixelSet(y div 2, x div 2, c)
   768         end
   768         end
   769 end;
   769 end;
   770 
   770 
   771 procedure GenMap;
   771 procedure GenMap;
   772 var x, y, w, c, c2: Longword;
   772 var x, y, w, c, c2: Longword;
   862                     else
   862                     else
   863                         c2:= AMask or RMask or GMask; // yellow
   863                         c2:= AMask or RMask or GMask; // yellow
   864 
   864 
   865                     if (cReducedQuality and rqBlurryLand) = 0 then
   865                     if (cReducedQuality and rqBlurryLand) = 0 then
   866                         begin
   866                         begin
   867                         LandPixels[y, leftX + w]:= c;
   867                         LandPixelSet(y, leftX + w, c);
   868                         LandPixels[y, rightX - w]:= c2;
   868                         LandPixelSet(y, rightX - w, c2);
   869                         end
   869                         end
   870                     else
   870                     else
   871                         begin
   871                         begin
   872                         LandPixels[y div 2, (leftX + w) div 2]:= c;
   872                         LandPixelSet(y div 2, (leftX + w) div 2, c);
   873                         LandPixels[y div 2, (rightX - w) div 2]:= c2;
   873                         LandPixelSet(y div 2, (rightX - w) div 2, c2);
   874                         end;
   874                         end;
   875                     end;
   875                     end;
   876 
   876 
   877         // Top border
   877         // Top border
   878         for x:= LongWord(leftX) to LongWord(rightX) do
   878         for x:= LongWord(leftX) to LongWord(rightX) do
   882                 c:= AMask // black
   882                 c:= AMask // black
   883             else
   883             else
   884                 c:= AMask or RMask or GMask; // yellow
   884                 c:= AMask or RMask or GMask; // yellow
   885 
   885 
   886             if (cReducedQuality and rqBlurryLand) = 0 then
   886             if (cReducedQuality and rqBlurryLand) = 0 then
   887                 LandPixels[topY + w, x]:= c
   887                 LandPixelSet(topY + w, x, c)
   888             else
   888             else
   889                 LandPixels[(topY + w) div 2, x div 2]:= c;
   889                 LandPixelSet((topY + w) div 2, x div 2, c);
   890             end;
   890             end;
   891         end;
   891         end;
   892     end;
   892     end;
   893 
   893 
   894 // Bottom border
   894 // Bottom border
   912     begin
   912     begin
   913     if (cReducedQuality and rqBlurryLand) = 0 then
   913     if (cReducedQuality and rqBlurryLand) = 0 then
   914         for x:= LongWord(leftX) to LongWord(rightX) do
   914         for x:= LongWord(leftX) to LongWord(rightX) do
   915             for y:= LongWord(topY) to LAND_HEIGHT-1 do
   915             for y:= LongWord(topY) to LAND_HEIGHT-1 do
   916                 begin
   916                 begin
   917                 w:= LandPixels[y,x];
   917                 w:= LandPixelGet(y,x);
   918                 w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
   918                 w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
   919                       (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
   919                       (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
   920                       (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   920                       (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   921                 if w > 255 then
   921                 if w > 255 then
   922                     w:= 255;
   922                     w:= 255;
   923                 w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y,x] and AMask);
   923                 w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixelGet(y,x) and AMask);
   924                 LandPixels[y,x]:= w or (LandPixels[y, x] and AMask)
   924                 LandPixelSet(y, x, w or (LandPixelGet(y, x) and AMask))
   925                 end
   925                 end
   926     else
   926     else
   927         for x:= LongWord(leftX div 2) to LongWord(rightX div 2) do
   927         for x:= LongWord(leftX div 2) to LongWord(rightX div 2) do
   928             for y:= LongWord(topY div 2) to LAND_HEIGHT-1 div 2 do
   928             for y:= LongWord(topY div 2) to LAND_HEIGHT-1 div 2 do
   929                 begin
   929                 begin
   930                 w:= LandPixels[y div 2,x div 2];
   930                 w:= LandPixelGet(y div 2,x div 2);
   931                 w:= ((w shr RShift and $FF) +  (w shr BShift and $FF) + (w shr GShift and $FF)) div 3;
   931                 w:= ((w shr RShift and $FF) +  (w shr BShift and $FF) + (w shr GShift and $FF)) div 3;
   932                 w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask);
   932                 w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixelGet(y div 2,x div 2) and AMask);
   933                 LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask)
   933                 LandPixelSet(y, x, w or (LandPixelGet(y div 2, x div 2) and AMask))
   934                 end
   934                 end
   935     end;
   935     end;
   936 
   936 
   937 PrettifyLandAlpha();
   937 PrettifyLandAlpha();
   938 
   938 
  1070 procedure chSendLandDigest(var s: shortstring);
  1070 procedure chSendLandDigest(var s: shortstring);
  1071 var i: LongInt;
  1071 var i: LongInt;
  1072     landPixelDigest  : LongInt;
  1072     landPixelDigest  : LongInt;
  1073 begin
  1073 begin
  1074     landPixelDigest:= 1;
  1074     landPixelDigest:= 1;
  1075 //    for i:= 0 to LAND_HEIGHT-1 do
  1075     for i:= 0 to LAND_HEIGHT-1 do
  1076 //        landPixelDigest:= Adler32Update(landPixelDigest, @LandGet(i,x), 2);
  1076         landPixelDigest:= Adler32Update(landPixelDigest, LandRow(i), LAND_WIDTH*2);
  1077     s:= 'M' + IntToStr(syncedPixelDigest)+'|'+IntToStr(landPixelDigest);
  1077     s:= 'M' + IntToStr(syncedPixelDigest)+'|'+IntToStr(landPixelDigest);
  1078 
  1078 
  1079     ScriptSetString('LandDigest',IntToStr(landPixelDigest));
  1079     ScriptSetString('LandDigest',IntToStr(landPixelDigest));
  1080 
  1080 
  1081     chLandCheck(s);
  1081     chLandCheck(s);
  1095 end;
  1095 end;
  1096 
  1096 
  1097 procedure freeModule;
  1097 procedure freeModule;
  1098 begin
  1098 begin
  1099     DisposeLand;
  1099     DisposeLand;
  1100     SetLength(LandPixels, 0, 0);
       
  1101     SetLength(LandDirty, 0, 0);
  1100     SetLength(LandDirty, 0, 0);
  1102 end;
  1101 end;
  1103 
  1102 
  1104 end.
  1103 end.