hedgewars/uLandPainted.pas
changeset 4494 9585435e20f7
parent 4490 f6840f7e2f60
child 4648 d8e1b43482d2
equal deleted inserted replaced
4493:45db8e97d282 4494:9585435e20f7
    21 unit uLandPainted;
    21 unit uLandPainted;
    22 
    22 
    23 interface
    23 interface
    24 
    24 
    25 procedure LoadFromFile(fileName: shortstring);
    25 procedure LoadFromFile(fileName: shortstring);
       
    26 procedure Draw;
    26 procedure initModule;
    27 procedure initModule;
    27 
    28 
    28 implementation
    29 implementation
    29 uses uLandGraphics, uConsts, uUtils, SDLh, uCommands;
    30 uses uLandGraphics, uConsts, uUtils, SDLh, uCommands;
    30 
    31 
    31 type PointRec = packed record
    32 type PointRec = packed record
    32     X, Y: SmallInt;
    33     X, Y: SmallInt;
    33     flags: byte;
    34     flags: byte;
    34     end;
    35     end;
       
    36 
       
    37 type
       
    38     PPointEntry = ^PointEntry;
       
    39     PointEntry = record
       
    40         point: PointRec;
       
    41         next: PPointEntry;
       
    42         end;
       
    43 
       
    44 var pointsListHead, pointsListLast: PPointEntry;
    35 
    45 
    36 procedure DrawLineOnLand(X1, Y1, X2, Y2: LongInt);
    46 procedure DrawLineOnLand(X1, Y1, X2, Y2: LongInt);
    37 var  eX, eY, dX, dY: LongInt;
    47 var  eX, eY, dX, dY: LongInt;
    38     i, sX, sY, x, y, d: LongInt;
    48     i, sX, sY, x, y, d: LongInt;
    39     b: boolean;
    49     b: boolean;
   123 
   133 
   124     closeFile(f);
   134     closeFile(f);
   125 end;
   135 end;
   126 
   136 
   127 procedure chDraw(var s: shortstring);
   137 procedure chDraw(var s: shortstring);
       
   138 var rec: PointRec;
       
   139     prec: ^PointRec;
       
   140     pe: PPointEntry;
       
   141     i, l: byte;
   128 begin
   142 begin
       
   143     i:= 1;
       
   144     l:= length(s);
       
   145     while i < l do
       
   146         begin
       
   147         prec:= @s[i];
       
   148         rec:= prec^;
       
   149         rec.X:= SDLNet_Read16(@rec.X);
       
   150         rec.Y:= SDLNet_Read16(@rec.Y);
       
   151 
       
   152         pe:= new(PPointEntry);
       
   153         if pointsListLast = nil then
       
   154             pointsListHead:= pe
       
   155         else
       
   156             pointsListLast^.next:= pe;
       
   157         pointsListLast:= pe;
       
   158 
       
   159         pe^.point:= rec;
       
   160         pe^.next:= nil;
       
   161 
       
   162         inc(i, 5)
       
   163         end;
       
   164 end;
       
   165 
       
   166 procedure Draw;
       
   167 var pe: PPointEntry;
       
   168     prevPoint: PointRec;
       
   169 begin
       
   170     pe:= pointsListHead;
       
   171 
       
   172     while(pe <> nil) do
       
   173         begin
       
   174         if (pe^.point.flags and $80 <> 0) then
       
   175             FillRoundInLand(pe^.point.X, pe^.point.Y, 34, lfBasic)
       
   176             else
       
   177             DrawLineOnLand(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y);
       
   178 
       
   179         prevPoint:= pe^.point;
       
   180         pe:= pe^.next;
       
   181         end;
   129 end;
   182 end;
   130 
   183 
   131 procedure initModule;
   184 procedure initModule;
   132 begin
   185 begin
       
   186     pointsListHead:= nil;
       
   187     pointsListLast:= nil;
       
   188 
   133     RegisterVariable('draw', vtCommand, @chDraw, false);
   189     RegisterVariable('draw', vtCommand, @chDraw, false);
   134 end;
   190 end;
   135 
   191 
   136 end.
   192 end.