home *** CD-ROM | disk | FTP | other *** search
/ Deathday Collection / dday.bin / edit / dfe / things.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-24  |  4KB  |  150 lines

  1. {****************************************************************************
  2. *                      The DOOM Hacker's Tool Kit                           *
  3. *****************************************************************************
  4. * Unit:       THINGS                                                           *
  5. * Purpose: Loading and displaying Picture Format objects from the WAD File  *
  6. * Date:    4/28/94                                                          *
  7. * Author:  Joshua Jackson        Internet: joshjackson@delphi.com           *
  8. ****************************************************************************}
  9.  
  10. {$O+,F+}
  11. unit Things;
  12.  
  13. interface
  14.  
  15. uses Wad,WadDecl,ObjCache;
  16.  
  17. type  PWadThing=^TWadThing;
  18.         TWadThing=object
  19.             SBuff:PPictureBuff;
  20.             Constructor Init(WDir:PWadDirectory;ThingName:ObjNameStr);
  21.             Procedure Draw(Scale,XOffset,YOffset:word);
  22.             Function Height:word;
  23.             Function Width:word;
  24.             Destructor Done;
  25.         end;
  26.  
  27. implementation
  28.  
  29. uses Graph,Crt;
  30.  
  31. Constructor TWadThing.Init(WDir:PWadDirectory;ThingName:ObjNameStr);
  32.  
  33.     type    POffsetList=^TOffsetList;
  34.             TOffsetList=array[0..320] of longint;
  35.             SpDim=record
  36.                 xsize    :integer;
  37.                 ysize    :integer;
  38.                 xofs    :integer;
  39.                 yofs    :integer;
  40.             end;
  41.  
  42.     var    sd:SpDim;
  43.             x,y:integer;
  44.             srow,rowlen:byte;
  45.             spSize,l:word;
  46.             pixel:byte;
  47.             Offsets:POffsetList;
  48.             BuffPos:word;
  49.             RowBuff:array[1..320] of byte;
  50.             ObjCache:PObjectCache;
  51.  
  52.     begin
  53.         BuffPos:=0;
  54.         l:=WDir^.FindObject(ThingName);
  55.         if l=0 then begin
  56.             TextMode(co80);
  57.             writeln('WadThing_Init: Could not locate picture ID: ',ThingName);
  58.             WDir^.Done;
  59.             halt;
  60.         end;
  61.         seek(WDir^.WadFile,WDir^.DirEntry^[l].ObjStart);
  62.         New(Sbuff);                                        {Allocate New Sprite Descriptor}
  63.         BlockRead(WDir^.WadFile,sd.XSize,8);
  64.         spSize:=sd.xSize * sd.ySize;                    {Calc Total Sprite Image Size}
  65.         if spSize > 64000 then begin                    {Error Check}
  66.             TextMode(co80);
  67.             writeln('WadThing_Init: Invalid Image Size');
  68.             WDir^.Done;
  69.             halt;
  70.         end;
  71.         GetMem(Sbuff^.Image,spSize);    {Allocate Sprite Image Buffer}
  72.         fillchar(Sbuff^.Image^,spsize,#0);
  73.         GetMem(Offsets, sd.xSize * 4);        {Allocate Row Offset Buffer}
  74.         ObjCache:=New(PObjectCache, Init(WDir, l));
  75.         ObjCache^.IncPos(8);
  76.         ObjCache^.CacheRead(Offsets^,sd.xSize * 4);
  77.         for x:= 0 to sd.xsize - 1 do begin   {-1}
  78.             ObjCache^.SetPos(Offsets^[x]);
  79.             ObjCache^.CacheRead(SRow,1);
  80.             while srow<>255 do begin
  81.                 ObjCache^.CacheRead(RowLen,1);
  82.                 ObjCache^.CacheRead(RowBuff, RowLen+2);
  83.                 for y:=0 to rowlen  do begin {-1}
  84.                     pixel:=RowBuff[y+2];
  85.                     l:=x +  (srow + y) * sd.xsize;
  86.                     if l < spSize then
  87.                         Sbuff^.Image^[l]:=Pixel;
  88.                 end; {for y}
  89.                 ObjCache^.CacheRead(SRow,1);
  90.             end; {while}
  91.         end; {for x}
  92.         ObjCache^.Done;
  93.         Dispose(ObjCache);
  94.         freemem(offsets, sd.xsize * 4);
  95.         SBuff^.x:=sd.xsize;
  96.         SBuff^.y:=sd.ysize;
  97.         SBuff^.xofs:=sd.xofs;
  98.         SBuff^.yofs:=sd.yofs;
  99.     end;
  100.  
  101. Procedure TWadThing.Draw(Scale,XOffset,YOffset:word);
  102.  
  103.     var     y1,y2,x1,x2,NewX,NewY,NewSize:integer;
  104.             Tempix,xPix,yPix,oxpix,oypix:integer;
  105.             xSize:integer;
  106.             VidPtr:^byte;
  107.  
  108.     begin
  109.         oxpix:=0;
  110.         oypix:=0;
  111.         XSize:=SBuff^.x;
  112.         for y1:=0 to (SBuff^.y - 1) do begin
  113.             yPix:=y1 * Scale div 100;
  114.             for y2:=oypix to ypix do begin
  115.                 oxpix:=0;
  116.                 for x1:=0 to (SBuff^.x - 1) do begin
  117.                     xPix:=x1 * Scale div 100;
  118.                     if ((x1 * Scale) mod 100) < 50 then
  119.                         Dec(XPix);
  120.                     for x2:=oxpix to xpix do begin
  121.                         PutPixel(x2+Xoffset,y2+YOffset,Sbuff^.Image^[(y1*xSize)+x1]);
  122.                     end;
  123.                     oxpix:=xpix+1;
  124.                 end;
  125.             end;
  126.             oypix:=ypix+1;
  127.         end;
  128.     end;
  129.  
  130. Function TWadThing.Height:word;
  131.  
  132.     begin
  133.         Height:=SBuff^.y;
  134.     end;
  135.  
  136. Function TWadThing.Width:word;
  137.  
  138.     begin
  139.         Width:=SBuff^.x;
  140.     end;
  141.  
  142. Destructor TWadThing.Done;
  143.  
  144.     begin
  145.         FreeMem(SBuff^.Image,SBuff^.y * SBuff^.x);
  146.         Dispose(SBuff);
  147.     end;
  148.  
  149. end.
  150.