hedgewars/uLandObjects.pas
changeset 11006 cb06b7985261
parent 10941 6f1b2d0dacdf
child 11046 47a8c19ecb60
equal deleted inserted replaced
11005:71927bdb776a 11006:cb06b7985261
    24 
    24 
    25 procedure AddObjects();
    25 procedure AddObjects();
    26 procedure FreeLandObjects();
    26 procedure FreeLandObjects();
    27 procedure LoadThemeConfig;
    27 procedure LoadThemeConfig;
    28 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface); inline;
    28 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface); inline;
    29 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface; LandFlags: Word);
    29 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface; LandFlags: Word); inline;
       
    30 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface; LandFlags: Word; Flip: boolean);
    30 procedure BlitImageUsingMask(cpX, cpY: Longword;  Image, Mask: PSDL_Surface);
    31 procedure BlitImageUsingMask(cpX, cpY: Longword;  Image, Mask: PSDL_Surface);
    31 procedure AddOnLandObjects(Surface: PSDL_Surface);
    32 procedure AddOnLandObjects(Surface: PSDL_Surface);
    32 procedure SetLand(var LandWord: Word; Pixel: LongWord); inline;
    33 procedure SetLand(var LandWord: Word; Pixel: LongWord); inline;
    33 
    34 
    34 implementation
    35 implementation
    90         LandWord:= lfObject or lfBouncy
    91         LandWord:= lfObject or lfBouncy
    91 end;
    92 end;
    92 
    93 
    93 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface); inline;
    94 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface); inline;
    94 begin
    95 begin
    95     BlitImageAndGenerateCollisionInfo(cpX, cpY, Width, Image, 0);
    96     BlitImageAndGenerateCollisionInfo(cpX, cpY, Width, Image, 0, false);
    96 end;
    97 end;
    97 
    98 
    98 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface; LandFlags: Word);
    99 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface; LandFlags: Word); inline;
       
   100 begin
       
   101     BlitImageAndGenerateCollisionInfo(cpX, cpY, Width, Image, LandFlags, false);
       
   102 end;
       
   103 
       
   104 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface; LandFlags: Word; Flip: boolean);
    99 var p: PLongwordArray;
   105 var p: PLongwordArray;
   100     x, y: Longword;
   106     px, x, y: Longword;
   101     bpp: LongInt;
   107     bpp: LongInt;
   102 begin
   108 begin
   103 WriteToConsole('Generating collision info... ');
   109 WriteToConsole('Generating collision info... ');
   104 
   110 
   105 if SDL_MustLock(Image) then
   111 if SDL_MustLock(Image) then
   113 
   119 
   114 p:= Image^.pixels;
   120 p:= Image^.pixels;
   115 for y:= 0 to Pred(Image^.h) do
   121 for y:= 0 to Pred(Image^.h) do
   116     begin
   122     begin
   117     for x:= 0 to Pred(Width) do
   123     for x:= 0 to Pred(Width) do
   118         if (p^[x] and AMask) <> 0 then
   124         begin
       
   125         // map image pixels per line backwards if in flip mode
       
   126         if Flip then
       
   127             px:= Pred(Image^.w) - x
       
   128         else
       
   129             px:= x;
       
   130 
       
   131         if (p^[px] and AMask) <> 0 then
   119             begin
   132             begin
   120             if (cReducedQuality and rqBlurryLand) = 0 then
   133             if (cReducedQuality and rqBlurryLand) = 0 then
   121                 begin
   134                 begin
   122                 if (LandPixels[cpY + y, cpX + x] = 0)
   135                 if (LandPixels[cpY + y, cpX + x] = 0)
   123                 or (((p^[x] and AMask) <> 0) and (((LandPixels[cpY + y, cpX + x] and AMask) shr AShift) < 255)) then
   136                 or (((p^[px] and AMask) <> 0) and (((LandPixels[cpY + y, cpX + x] and AMask) shr AShift) < 255)) then
   124                     LandPixels[cpY + y, cpX + x]:= p^[x];
   137                     LandPixels[cpY + y, cpX + x]:= p^[px];
   125                 end
   138                 end
   126             else
   139             else
   127                 if LandPixels[(cpY + y) div 2, (cpX + x) div 2] = 0 then
   140                 if LandPixels[(cpY + y) div 2, (cpX + x) div 2] = 0 then
   128                     LandPixels[(cpY + y) div 2, (cpX + x) div 2]:= p^[x];
   141                     LandPixels[(cpY + y) div 2, (cpX + x) div 2]:= p^[px];
   129 
   142 
   130             if (Land[cpY + y, cpX + x] <= lfAllObjMask) and ((p^[x] and AMask) <> 0) then
   143             if (Land[cpY + y, cpX + x] <= lfAllObjMask) and ((p^[px] and AMask) <> 0) then
   131                 Land[cpY + y, cpX + x]:= lfObject or LandFlags
   144                 Land[cpY + y, cpX + x]:= lfObject or LandFlags
   132             end;
   145             end;
       
   146         end;
   133     p:= PLongwordArray(@(p^[Image^.pitch shr 2]))
   147     p:= PLongwordArray(@(p^[Image^.pitch shr 2]))
   134     end;
   148     end;
   135 
   149 
   136 if SDL_MustLock(Image) then
   150 if SDL_MustLock(Image) then
   137     SDL_UnlockSurface(Image);
   151     SDL_UnlockSurface(Image);