hedgewars/uLandObjects.pas
changeset 15345 4e91a7050add
parent 15161 84e98f0f7f7b
child 15347 0230c4766aa6
equal deleted inserted replaced
15344:cf4a9632e649 15345:4e91a7050add
   344         if Land[i, x] <> 0 then
   344         if Land[i, x] <> 0 then
   345             inc(lRes);
   345             inc(lRes);
   346     CountNonZeroz:= lRes;
   346     CountNonZeroz:= lRes;
   347 end;
   347 end;
   348 
   348 
   349 procedure ChecksumLandObjectImage(Image: PSDL_Surface);
   349 procedure ChecksumLandObjectImage(Image: PSDL_Surface; alphaOnly: boolean);
   350 var y: LongInt;
   350 var y, x: LongInt;
       
   351 var rowData: PByte;
   351 begin
   352 begin
   352     if Image = nil then exit;
   353     if Image = nil then exit;
       
   354 
       
   355     if alphaOnly then
       
   356         rowData := GetMem(Image^.w);
   353 
   357 
   354     if SDL_MustLock(Image) then
   358     if SDL_MustLock(Image) then
   355         SDL_LockSurface(Image);
   359         SDL_LockSurface(Image);
   356 
   360 
   357     if checkFails(Image^.format^.BytesPerPixel = 4, 'Land object image should be 32bit', true) then
   361     if checkFails(Image^.format^.BytesPerPixel = 4, 'Land object image should be 32bit', true) then
   359         if SDL_MustLock(Image) then
   363         if SDL_MustLock(Image) then
   360             SDL_UnlockSurface(Image);
   364             SDL_UnlockSurface(Image);
   361         exit
   365         exit
   362     end;
   366     end;
   363 
   367 
   364     for y := 0 to Image^.h-1 do
   368     for y := 0 to Image^.h - 1 do
   365         syncedPixelDigest:= Adler32Update(syncedPixelDigest, @PByteArray(Image^.pixels)^[y*Image^.pitch], Image^.w*4);
   369         begin
       
   370         if alphaOnly then
       
   371             begin
       
   372             for x := 0 to Image^.w - 1 do
       
   373                 (rowData + x)^:= (PByte(Image^.pixels) + y * Image^.pitch + x * 4 + AByteIndex)^;
       
   374             syncedPixelDigest:= Adler32Update(syncedPixelDigest, rowData, Image^.w);
       
   375             end
       
   376         else
       
   377             syncedPixelDigest:= Adler32Update(syncedPixelDigest, @PByteArray(Image^.pixels)^[y*Image^.pitch], Image^.w*4);
       
   378 
       
   379         AddFileLog(IntToStr(syncedPixelDigest));
       
   380         end;
   366 
   381 
   367     if SDL_MustLock(Image) then
   382     if SDL_MustLock(Image) then
   368         SDL_UnlockSurface(Image);
   383         SDL_UnlockSurface(Image);
       
   384 
       
   385     if alphaOnly then
       
   386         FreeMem(rowData, Image^.w);
   369 end;
   387 end;
   370 
   388 
   371 function AddGirder(gX: LongInt; var girSurf: PSDL_Surface): boolean;
   389 function AddGirder(gX: LongInt; var girSurf: PSDL_Surface): boolean;
   372 var x1, x2, y, k, i, girderHeight: LongInt;
   390 var x1, x2, y, k, i, girderHeight: LongInt;
   373     rr: TSDL_Rect;
   391     rr: TSDL_Rect;
   374     bRes: boolean;
   392     bRes: boolean;
   375 begin
   393 begin
   376 if girSurf = nil then
   394 if girSurf = nil then
   377     girSurf:= LoadDataImageAltPath(ptCurrTheme, ptGraphics, 'Girder', ifCritical or ifColorKey or ifIgnoreCaps);
   395     girSurf:= LoadDataImageAltPath(ptCurrTheme, ptGraphics, 'Girder', ifCritical or ifColorKey or ifIgnoreCaps);
   378 
   396 
   379 ChecksumLandObjectImage(girsurf);
   397 ChecksumLandObjectImage(girsurf, true);
   380 
   398 
   381 girderHeight:= girSurf^.h;
   399 girderHeight:= girSurf^.h;
   382 
   400 
   383 y:= topY+150;
   401 y:= topY+150;
   384 repeat
   402 repeat
   733     if i = 0 then i:= Succ(Length(S));
   751     if i = 0 then i:= Succ(Length(S));
   734     Surf:= LoadDataImage(ptCurrTheme, Trim(Copy(s, 1, Pred(i))), ifColorKey or ifIgnoreCaps or ifCritical);
   752     Surf:= LoadDataImage(ptCurrTheme, Trim(Copy(s, 1, Pred(i))), ifColorKey or ifIgnoreCaps or ifCritical);
   735     Width:= Surf^.w;
   753     Width:= Surf^.w;
   736     Height:= Surf^.h;
   754     Height:= Surf^.h;
   737     Delete(s, 1, i);
   755     Delete(s, 1, i);
   738     ChecksumLandObjectImage(Surf);
   756     ChecksumLandObjectImage(Surf, true);
   739     end;
   757     end;
   740 end;
   758 end;
   741 
   759 
   742 procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects);
   760 procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects);
   743 var s, key, nameRef: shortstring;
   761 var s, key, nameRef: shortstring;
   943             i:= Pos(',', s);
   961             i:= Pos(',', s);
   944             Maxcnt:= StrToInt(Trim(Copy(s, 1, Pred(i))));
   962             Maxcnt:= StrToInt(Trim(Copy(s, 1, Pred(i))));
   945             Delete(s, 1, i);
   963             Delete(s, 1, i);
   946             if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then
   964             if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then
   947                 OutError('Broken theme. Object''s max. count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true);
   965                 OutError('Broken theme. Object''s max. count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true);
   948             ChecksumLandObjectImage(Surf);
   966             ChecksumLandObjectImage(Surf, true);
   949             ChecksumLandObjectImage(Mask);
   967             ChecksumLandObjectImage(Mask, false);
   950 
   968 
   951             inrectcnt := 0;
   969             inrectcnt := 0;
   952 
   970 
   953             for ii := 1 to Length(S) do
   971             for ii := 1 to Length(S) do
   954               if S[ii] = ',' then
   972               if S[ii] = ',' then