home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / vexsrc / textures.cpp < prev    next >
C/C++ Source or Header  |  1995-03-29  |  5KB  |  167 lines

  1. /*****************************************************************************
  2.                                   ATTENTION!
  3.                            this source is VOTEWARE,
  4.               you may only use it to the conditions listed below:
  5.  
  6.   -You may modify it, or use parts of it in your own source as long as
  7.     this header stays on top of all files containing this source.
  8.   -You must give proper credit to the author, Niklas Beisert / pascal.
  9.   -You may not use it in commercial productions without the written
  10.     permission of the author.
  11.   -AND MOST IMPORTANT: you have to buy an Assembly '94 CD-ROM
  12.     by Sound Solutions (if you don't have it already) and vote for VEX-InTrO
  13.     in the PC-64k-Intro-Compo! (if you have already sent your voting card,
  14.     buy another one and fill it out CORRECTLY!!!)
  15. *****************************************************************************/
  16.  
  17.  
  18.  
  19. // the texture read and calculate(sinplasma) funtions
  20.  
  21. #include <mem.h>
  22. //#include <io.h>
  23. #include "ovlio.h"
  24. #include <stdlib.h>
  25. #include "sinplasa.h"
  26. #include "ints.h"
  27. #include "matrix.h"
  28. #include "vect.h"
  29.  
  30. extern long *SinTab;
  31.  
  32. struct sinplaspar
  33. {
  34.   long p;
  35.   long f;
  36.   long ft;
  37.   short a;
  38.   short w;
  39. };
  40.  
  41. static struct
  42. {
  43.   short type;
  44.   short x;
  45.   short y;
  46.   char *bmp;
  47.   char oper;
  48.   long lasttime;
  49.   char *sptab;
  50.   sinplaspar *sp;
  51. } textures[32];
  52. short texturenum;
  53.  
  54. void makeplasma(unsigned char *buf, short resbit, short xabits=0, short yabits=0, short colbits=8, short p=500, long seed=0x17091977);
  55.  
  56. short inittexture(short file)
  57. {
  58.   oread(file, &texturenum, 2);
  59.   short i;
  60.   for (i=0; i<texturenum; i++)
  61.   {
  62.     oread(file, &textures[i].type, 2);
  63.     short resbit, xabits, yabits, colbits, p;
  64.     long seed;
  65.     switch (textures[i].type)
  66.     {
  67.     case 0:
  68.       oread(file, &textures[i].x, 2);
  69.       oread(file, &textures[i].y, 2);
  70.       textures[i].bmp=new char[textures[i].x*textures[i].y];
  71.       if (!textures[i].bmp)
  72.         return 0;
  73.       oread(file, textures[i].bmp, textures[i].x*textures[i].y);
  74.       break;
  75.     case 1:
  76.       oread(file, &resbit, 2);
  77.       oread(file, &xabits, 2);
  78.       oread(file, &yabits, 2);
  79.       oread(file, &colbits, 2);
  80.       oread(file, &p, 2);
  81.       oread(file, &seed, 4);
  82.       textures[i].type=0;
  83.       textures[i].x=1<<(resbit+xabits);
  84.       textures[i].y=1<<(resbit+yabits);
  85.       textures[i].bmp=new char[textures[i].x*textures[i].y];
  86.       if (!textures[i].bmp)
  87.         return 0;
  88.       makeplasma((unsigned char*)textures[i].bmp, resbit, xabits, yabits, colbits, p, seed);
  89.       break;
  90.     case 2:
  91.       oread(file, &textures[i].x, 2);
  92.       oread(file, &textures[i].y, 2);
  93.       textures[i].bmp=new char[textures[i].x*textures[i].y];
  94.       if (!textures[i].bmp)
  95.         return 0;
  96.       unsigned char maxcol;
  97.       oread(file, &maxcol, 1);
  98.       oread(file, &textures[i].oper, 1);
  99.       textures[i].sp=new sinplaspar[textures[i].oper];
  100.       textures[i].sptab=new char[2048];
  101.       oread(file, textures[i].sp, 16*textures[i].oper);
  102.       textures[i].lasttime=-1;
  103.       makesintab(textures[i].sptab, maxcol/textures[i].oper);
  104.       break;
  105.     }
  106.   }
  107.   return 1;
  108. }
  109.  
  110. void closetexture()
  111. {
  112.   short i;
  113.   for (i=0; i<texturenum; i++)
  114.   switch (textures[i].type)
  115.   {
  116.   case 0:
  117.     delete textures[i].bmp;
  118.     break;
  119.   case 2:
  120.     delete textures[i].bmp;
  121.     delete textures[i].sp;
  122.     delete textures[i].sptab;
  123.     break;
  124.   }
  125. }
  126.  
  127. #pragma argsused
  128. void gettexture(short num, const texturespot *text, short n, long (*vert)[2], char *&bmp, unsigned short &wid)
  129. {
  130.   short i, x, y;
  131.   char *bm;
  132.   x=textures[num].x;
  133.   y=textures[num].y;
  134.   bm=textures[num].bmp;
  135.   for (i=0; i<n; i++)
  136.   {
  137.     vert[i][0]=IntMul(itol(x), text[i].x);
  138.     vert[i][1]=IntMul(itol(y), text[i].y);
  139.   }
  140.   bmp=bm;
  141.   wid=x;
  142.   if ((textures[num].type==2)&&(textures[num].lasttime!=curtime))
  143.   {
  144.     textures[num].lasttime=curtime;
  145.     short nm=textures[num].oper;
  146.     sinplaspar *par=textures[num].sp;
  147.     char *ps=textures[num].sptab;
  148.     memset(bm, 0, x*y);
  149.     for (i=0; i<nm; i++)
  150.     {
  151.       char *scr=bm;
  152.       short a=par->a+IntMul(par->w, curtime);
  153.       long fx=IntMul(SinTab[(a+512)&2047], par->f);
  154.       long fy=IntMul(SinTab[a&2047], par->f);
  155.       long p=par->p+IntMul(par->ft, curtime)-(y>>1)*fy-(x>>1)*fx;
  156.       short j;
  157.       for (j=0; j<y; j++)
  158.       {
  159.         plasmaline(ps, scr, x, p, fx);
  160.         p+=fy;
  161.         scr+=x;
  162.       }
  163.       par++;
  164.     }
  165.   }
  166. }
  167.