34 procedure SetLand(var LandWord: Word; Pixel: LongWord); inline; |
34 procedure SetLand(var LandWord: Word; Pixel: LongWord); inline; |
35 |
35 |
36 implementation |
36 implementation |
37 uses uStore, uConsts, uConsole, uRandom, uSound |
37 uses uStore, uConsts, uConsole, uRandom, uSound |
38 , uTypes, uVariables, uDebug, uUtils |
38 , uTypes, uVariables, uDebug, uUtils |
39 , uPhysFSLayer, adler32, uRenderUtils; |
39 , uPhysFSLayer, uRenderUtils; |
40 |
40 |
41 const MaxRects = 512; |
41 const MaxRects = 512; |
42 MAXOBJECTRECTS = 16; |
42 MAXOBJECTRECTS = 16; |
43 MAXTHEMEOBJECTS = 32; |
43 MAXTHEMEOBJECTS = 32; |
44 cThemeCFGFilename = 'theme.cfg'; |
44 cThemeCFGFilename = 'theme.cfg'; |
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; alphaOnly: boolean); |
|
350 var y, x: LongInt; |
|
351 var rowData: PByteArray; |
|
352 begin |
|
353 if Image = nil then exit; |
|
354 |
|
355 if alphaOnly then |
|
356 rowData := GetMem(Image^.w); |
|
357 |
|
358 if SDL_MustLock(Image) then |
|
359 SDL_LockSurface(Image); |
|
360 |
|
361 if checkFails(Image^.format^.BytesPerPixel = 4, 'Land object image should be 32bit', true) then |
|
362 begin |
|
363 if SDL_MustLock(Image) then |
|
364 SDL_UnlockSurface(Image); |
|
365 exit |
|
366 end; |
|
367 |
|
368 for y := 0 to Image^.h - 1 do |
|
369 if alphaOnly then |
|
370 begin |
|
371 for x := 0 to Image^.w - 1 do |
|
372 rowData^[x] := PByteArray(Image^.pixels)^[y * Image^.pitch + x * 4 + AByteIndex]; |
|
373 syncedPixelDigest:= Adler32Update(syncedPixelDigest, rowData, Image^.w); |
|
374 end |
|
375 else |
|
376 syncedPixelDigest:= Adler32Update(syncedPixelDigest, @PByteArray(Image^.pixels)^[y*Image^.pitch], Image^.w*4); |
|
377 |
|
378 if SDL_MustLock(Image) then |
|
379 SDL_UnlockSurface(Image); |
|
380 |
|
381 if alphaOnly then |
|
382 FreeMem(rowData, Image^.w); |
|
383 end; |
|
384 |
|
385 function AddGirder(gX: LongInt; var girSurf: PSDL_Surface): boolean; |
349 function AddGirder(gX: LongInt; var girSurf: PSDL_Surface): boolean; |
386 var x1, x2, y, k, i, girderHeight: LongInt; |
350 var x1, x2, y, k, i, girderHeight: LongInt; |
387 rr: TSDL_Rect; |
351 rr: TSDL_Rect; |
388 bRes: boolean; |
352 bRes: boolean; |
389 begin |
353 begin |
390 if girSurf = nil then |
354 if girSurf = nil then |
391 girSurf:= LoadDataImageAltPath(ptCurrTheme, ptGraphics, 'Girder', ifCritical or ifColorKey or ifIgnoreCaps); |
355 girSurf:= LoadDataImageAltPath(ptCurrTheme, ptGraphics, 'Girder', ifCritical or ifColorKey or ifIgnoreCaps or ifDigestAlpha); |
392 |
|
393 ChecksumLandObjectImage(girsurf, true); |
|
394 |
356 |
395 girderHeight:= girSurf^.h; |
357 girderHeight:= girSurf^.h; |
396 |
358 |
397 y:= topY+150; |
359 y:= topY+150; |
398 repeat |
360 repeat |
743 i:= Pos(',', s); |
705 i:= Pos(',', s); |
744 Position.Y:= StrToInt(Trim(Copy(s, 1, Pred(i)))); |
706 Position.Y:= StrToInt(Trim(Copy(s, 1, Pred(i)))); |
745 Delete(s, 1, i); |
707 Delete(s, 1, i); |
746 i:= Pos(',', s); |
708 i:= Pos(',', s); |
747 if i = 0 then i:= Succ(Length(S)); |
709 if i = 0 then i:= Succ(Length(S)); |
748 Surf:= LoadDataImage(ptCurrTheme, Trim(Copy(s, 1, Pred(i))), ifColorKey or ifIgnoreCaps or ifCritical); |
710 Surf:= LoadDataImage(ptCurrTheme, Trim(Copy(s, 1, Pred(i))), ifColorKey or ifIgnoreCaps or ifCritical or ifDigestAlpha ); |
749 Width:= Surf^.w; |
711 Width:= Surf^.w; |
750 Height:= Surf^.h; |
712 Height:= Surf^.h; |
751 Delete(s, 1, i); |
713 Delete(s, 1, i); |
752 ChecksumLandObjectImage(Surf, true); |
|
753 end; |
714 end; |
754 end; |
715 end; |
755 |
716 |
756 procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects); |
717 procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects); |
757 var s, key, nameRef: shortstring; |
718 var s, key, nameRef: shortstring; |
947 inc(ThemeObjects.Count); |
908 inc(ThemeObjects.Count); |
948 with ThemeObjects.objs[Pred(ThemeObjects.Count)] do |
909 with ThemeObjects.objs[Pred(ThemeObjects.Count)] do |
949 begin |
910 begin |
950 i:= Pos(',', s); |
911 i:= Pos(',', s); |
951 Name:= Trim(Copy(s, 1, Pred(i))); |
912 Name:= Trim(Copy(s, 1, Pred(i))); |
952 Surf:= LoadDataImage(ptCurrTheme, Name, ifColorKey or ifIgnoreCaps or ifCritical); |
913 |
|
914 Mask:= LoadDataImage(ptCurrTheme, Trim(Copy(s, 1, Pred(i)))+'_mask', ifColorKey or ifIgnoreCaps or ifDigestAll); |
|
915 if Mask = nil then |
|
916 Surf:= LoadDataImage(ptCurrTheme, Name, ifColorKey or ifIgnoreCaps or ifCritical or ifDigestAlpha) |
|
917 else |
|
918 Surf:= LoadDataImage(ptCurrTheme, Name, ifColorKey or ifIgnoreCaps or ifCritical); |
|
919 |
953 Width:= Surf^.w; |
920 Width:= Surf^.w; |
954 Height:= Surf^.h; |
921 Height:= Surf^.h; |
955 Mask:= LoadDataImage(ptCurrTheme, Trim(Copy(s, 1, Pred(i)))+'_mask', ifColorKey or ifIgnoreCaps); |
922 |
956 Delete(s, 1, i); |
923 Delete(s, 1, i); |
957 i:= Pos(',', s); |
924 i:= Pos(',', s); |
958 Maxcnt:= StrToInt(Trim(Copy(s, 1, Pred(i)))); |
925 Maxcnt:= StrToInt(Trim(Copy(s, 1, Pred(i)))); |
959 Delete(s, 1, i); |
926 Delete(s, 1, i); |
960 if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then |
927 if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then |
961 OutError('Broken theme. Object''s max. count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true); |
928 OutError('Broken theme. Object''s max. count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true); |
962 if Mask = nil then |
|
963 ChecksumLandObjectImage(Surf, true); |
|
964 ChecksumLandObjectImage(Mask, false); |
|
965 |
929 |
966 inrectcnt := 0; |
930 inrectcnt := 0; |
967 |
931 |
968 for ii := 1 to Length(S) do |
932 for ii := 1 to Length(S) do |
969 if S[ii] = ',' then |
933 if S[ii] = ',' then |