home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / vexsrc / palette.cpp < prev    next >
C/C++ Source or Header  |  1995-03-29  |  4KB  |  155 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. // palette fade/interpolation functions
  20. // uses palette information from .3ds file...
  21.  
  22. //#include <io.h>
  23. #include "ovlio.h"
  24. #include <mem.h>
  25. #include "ints.h"
  26. #include "colors2.h"
  27. #include "matrix.h"
  28. #include "vect.h"
  29.  
  30. static unsigned char (*srcpal)[3];
  31. static unsigned char (*dstpal)[3];
  32. static unsigned char (*curpal)[3];
  33. static char *events;
  34. static char *evptr;
  35. #define MAXFADES 8
  36. static unsigned char fadeoffs[MAXFADES];
  37. static short fadenums[MAXFADES];
  38. static long fadet0[MAXFADES];
  39. static long fadet[MAXFADES];
  40.  
  41. #pragma argsused
  42. short initpalette(short file)
  43. {
  44.   srcpal=new unsigned char[256][3];
  45.   dstpal=new unsigned char[256][3];
  46.   curpal=new unsigned char[256][3];
  47.   if (!srcpal||!dstpal||!curpal)
  48.     return 0;
  49.   short buflen;
  50.   oread(file, &buflen, 2);
  51.   events=new char[buflen];
  52.   if (!events)
  53.     return 0;
  54.   oread(file, events, buflen);
  55.   evptr=events;
  56.   return 1;
  57. }
  58.  
  59. void setpalette()
  60. {
  61.   short i;
  62.   for (i=0; i<MAXFADES; i++)
  63.   {
  64.     if (!fadenums[i])
  65.       continue;
  66.     if (fadet[i]+fadet0[i]<curtime)
  67.     {
  68.       memcpy(srcpal+fadeoffs[i], dstpal+fadeoffs[i], fadenums[i]*3);
  69.       SetColors(srcpal+fadeoffs[i], fadeoffs[i], fadenums[i]);
  70.       fadenums[i]=0;
  71.     }
  72.   }
  73.  
  74.   while (*(long*)evptr<=curtime)
  75.   {
  76.     long t0=*(long*)evptr;
  77.     char cmd=evptr[4];
  78.     evptr+=5;
  79.     unsigned char c0;
  80.     short n;
  81.     long t;
  82.     unsigned char crs, cgs, cbs, crd, cgd, cbd;
  83.     switch (cmd)
  84.     {
  85.     case 0:
  86.       c0=*evptr++;
  87.       n=*(short*)evptr;
  88.       evptr+=2;
  89.       crs=*evptr++;
  90.       cgs=*evptr++;
  91.       cbs=*evptr++;
  92.       crd=*evptr++;
  93.       cgd=*evptr++;
  94.       cbd=*evptr++;
  95.       InterpolCols(srcpal+c0, n, crs, cgs, cbs, crd, cgd, cbd);
  96.       SetColors(srcpal+c0, c0, n);
  97.       break;
  98.     case 1:
  99.       for (i=0; i<(MAXFADES-1); i++)
  100.         if (!fadenums[i])
  101.           break;
  102.       t=*(long*)evptr;
  103.       evptr+=4;
  104.       c0=*evptr++;
  105.       n=*(short*)evptr;
  106.       evptr+=2;
  107.       crs=*evptr++;
  108.       cgs=*evptr++;
  109.       cbs=*evptr++;
  110.       crd=*evptr++;
  111.       cgd=*evptr++;
  112.       cbd=*evptr++;
  113.       InterpolCols(dstpal+c0, n, crs, cgs, cbs, crd, cgd, cbd);
  114.       fadet0[i]=t0;
  115.       fadet[i]=t;
  116.       fadenums[i]=n;
  117.       fadeoffs[i]=c0;
  118.       break;
  119.     }
  120.   }
  121.  
  122.   for (i=0; i<MAXFADES; i++)
  123.   {
  124.     if (!fadenums[i])
  125.       continue;
  126.     if (fadet[i]+fadet0[i]<curtime)
  127.     {
  128.       memcpy(srcpal+fadeoffs[i], dstpal+fadeoffs[i], fadenums[i]*3);
  129.       SetColors(srcpal+fadeoffs[i], fadeoffs[i], fadenums[i]);
  130.       fadenums[i]=0;
  131.     }
  132.     else
  133.     {
  134.       MakeFadeStep(curpal+fadeoffs[i], srcpal+fadeoffs[i], dstpal+fadeoffs[i], fadenums[i], IntMulDiv(128, curtime-fadet0[i], fadet[i]));
  135.       SetColors(curpal+fadeoffs[i], fadeoffs[i], fadenums[i]);
  136.     }
  137.   }
  138. /*
  139.   if (!evptr)
  140.   {
  141.     InterpolCols(curpal, 128, 0, 0, 0, 255, 255, 255);
  142.     InterpolCols(curpal+128, 128, 128, 0, 0, 255, 0, 0);
  143.     SetColors(curpal, 0, 256);
  144.     evptr++;
  145.   }
  146. */
  147. }
  148.  
  149. void closepalette()
  150. {
  151.   delete srcpal;
  152.   delete dstpal;
  153.   delete curpal;
  154. }
  155.