hedgewars/uLandObjects.pas
changeset 107 b08ce0293a51
parent 80 3c3dc6a148ca
child 183 57c2ef19f719
equal deleted inserted replaced
106:98cb6606bf67 107:b08ce0293a51
    71 
    71 
    72 var Rects: PRectArray;
    72 var Rects: PRectArray;
    73     RectCount: Longword;
    73     RectCount: Longword;
    74 
    74 
    75 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY: Longword; Image, Surface: PSDL_Surface);
    75 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY: Longword; Image, Surface: PSDL_Surface);
    76 var i, p: LongWord;
    76 var p: PByteArray;
    77     x, y: Longword;
    77     x, y: Longword;
    78     bpp: integer;
    78     bpp: integer;
    79     r: TSDL_Rect;
    79     r: TSDL_Rect;
    80 begin
    80 begin
    81 r.x:= cpX;
    81 r.x:= cpX;
    86 if SDL_MustLock(Image) then
    86 if SDL_MustLock(Image) then
    87    SDLTry(SDL_LockSurface(Image) >= 0, true);
    87    SDLTry(SDL_LockSurface(Image) >= 0, true);
    88 
    88 
    89 bpp:= Image.format.BytesPerPixel;
    89 bpp:= Image.format.BytesPerPixel;
    90 WriteToConsole('('+inttostr(bpp)+') ');
    90 WriteToConsole('('+inttostr(bpp)+') ');
    91 p:= LongWord(Image.pixels);
    91 p:= Image.pixels;
    92 case bpp of
    92 case bpp of
    93      1: OutError('We don''t work with 8 bit surfaces', true);
    93      1: OutError('We don''t work with 8 bit surfaces', true);
    94      2: for y:= 0 to Pred(Image.h) do
    94      2: for y:= 0 to Pred(Image.h) do
    95             begin
    95             begin
    96             i:= Longword(@Land[cpY + y, cpX]);
       
    97             for x:= 0 to Pred(Image.w) do
    96             for x:= 0 to Pred(Image.w) do
    98                 if PWord(p + x * 2)^ <> 0 then PLongWord(i + x * 4)^:= COLOR_LAND;
    97                 if PWord(@p[x * 2])^ <> 0 then Land[cpY + y, cpX + x]:= COLOR_LAND;
    99             inc(p, Image.pitch);
    98             p:= @p[Image.pitch];
   100             end;
    99             end;
   101      3: for y:= 0 to Pred(Image.h) do
   100      3: for y:= 0 to Pred(Image.h) do
   102             begin
   101             begin
   103             i:= Longword(@Land[cpY + y, cpX]);
       
   104             for x:= 0 to Pred(Image.w) do
   102             for x:= 0 to Pred(Image.w) do
   105                 if  (PByte(p + x * 3 + 0)^ <> 0)
   103                 if  (p[x * 3 + 0] <> 0)
   106                  or (PByte(p + x * 3 + 1)^ <> 0)
   104                  or (p[x * 3 + 1] <> 0)
   107                  or (PByte(p + x * 3 + 2)^ <> 0) then PLongWord(i + x * 4)^:= COLOR_LAND;
   105                  or (p[x * 3 + 2] <> 0) then Land[cpY + y, cpX + x]:= COLOR_LAND;
   108             inc(p, Image.pitch);
   106             p:= @p[Image.pitch];
   109             end;
   107             end;
   110      4: for y:= 0 to Pred(Image.h) do
   108      4: for y:= 0 to Pred(Image.h) do
   111             begin
   109             begin
   112             i:= Longword(@Land[cpY + y, cpX]);
       
   113             for x:= 0 to Pred(Image.w) do
   110             for x:= 0 to Pred(Image.w) do
   114                 if PLongword(p + x * 4)^ <> 0 then PLongWord(i + x * 4)^:= COLOR_LAND;
   111                 if PLongword(@p[x * 4])^ <> 0 then Land[cpY + y, cpX + x]:= COLOR_LAND;
   115             inc(p, Image.pitch);
   112             p:= @p[Image.pitch];
   116             end;
   113             end;
   117      end;
   114      end;
   118 if SDL_MustLock(Image) then
   115 if SDL_MustLock(Image) then
   119    SDL_UnlockSurface(Image);
   116    SDL_UnlockSurface(Image);
   120 WriteLnToConsole(msgOK)
   117 WriteLnToConsole(msgOK)