home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / 2d / effects.c < prev    next >
Text File  |  1998-06-08  |  4KB  |  127 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/2d/rcs/effects.c $
  15.  * $Revision: 1.5 $
  16.  * $Author: john $
  17.  * $Date: 1994/11/18 22:51:04 $
  18.  * 
  19.  * special effects stuff
  20.  * 
  21.  * $Log: effects.c $
  22.  * Revision 1.5  1994/11/18  22:51:04  john
  23.  * Changed a bunch of shorts to ints in calls.
  24.  * 
  25.  * Revision 1.4  1994/04/22  11:16:00  john
  26.  * *** empty log message ***
  27.  * 
  28.  * Revision 1.3  1994/02/01  13:18:45  john
  29.  * *** empty log message ***
  30.  * 
  31.  * Revision 1.2  1993/10/26  13:18:15  john
  32.  * *** empty log message ***
  33.  * 
  34.  * Revision 1.1  1993/10/25  14:56:56  john
  35.  * Initial revision
  36.  * 
  37.  * 
  38.  */
  39.  
  40.  
  41. #pragma off (unreferenced)
  42. static char rcsid[] = "$Id: effects.c 1.5 1994/11/18 22:51:04 john Exp $";
  43. #pragma on (unreferenced)
  44.  
  45. #include <stdlib.h>
  46. #include <stdio.h>
  47.  
  48.  
  49. #include "mem.h"
  50. #include "gr.h"
  51. #include "grdef.h"
  52. #include "effect2d.h"
  53.  
  54. int bitwidth(unsigned int n)
  55. {
  56.     int width = 0;
  57.  
  58.     while ( n!=0 )  {
  59.         n >>= 1;
  60.         width++;
  61.     }
  62.     return width;
  63. }
  64.  
  65. long randmasks[] = { 0,0,0x03,0x06,0x0c,0x14,0x30,0x60,0xb8,\
  66. 0x110,0x240,0x500,0xca0,0x1b00,0x3500,0x6000,0xb400,\
  67. 0x12000,0x204000,0x720000,0x90000,0x140000,0x300000,0x400000,\
  68. 0xd80000,0x1200000,0x3880000,0x7200000,0x9000000,0x14000000,\
  69. 0x32800000,0x48000000,0xa3000000 };
  70.  
  71. void dissolve_in(grs_bitmap * bitmap )
  72. {
  73.     int height, width, zz;
  74.     int rwidth, cwidth;     /* bit width for rows, for columns */
  75.     int regwidth;           /* "width" of sequence generator */
  76.     long mask;     /* mask to XOR with to create sequence */
  77.     int rowshift;  /* shift distance to get row  */
  78.                                                     /* from element */
  79.     int colmask; /* mask to extract column from element */
  80.     unsigned long element; /* one element of random */                                                                 /* sequence */
  81.     int row, column;    /* row and column for one pixel */
  82.  
  83.     /* Find the mask to produce all rows and columns. */
  84.     height = bitmap->bm_h;
  85.     width = bitmap->bm_w;
  86.  
  87.     rwidth = bitwidth (height); /* how many bits needed for height? */
  88.     cwidth = bitwidth (width);  /* how many bits needed for width? */
  89.     regwidth = rwidth + cwidth; /* how wide must the register be? */
  90.     mask = randmasks[regwidth]; /* which mask is for that width? */
  91.  
  92.     /* Find values to extract row and col numbers from each element. */
  93.     rowshift = cwidth; /* find dist to shift to get top bits (row) */
  94.     colmask = (1<<cwidth)-1;        /* find mask to extract  */
  95.                                                 /* bottom bits (col) */
  96.  
  97.     /* Now cycle through all sequence elements. */
  98.  
  99.     element = 1;    /* 1st element (could be any nonzero) */
  100.     do {
  101.         for (zz=0; zz < 100; zz++);
  102.         row = element >> rowshift; /* find row number for this pixel */
  103.         column = element & colmask; /* and how many columns across? */
  104.         /* does element fall in the array? */
  105.         /* ...must check row AND column */
  106.  
  107.         if ((row < height) && (column < width)) {
  108.             // Draw the (r,c)'th pixel
  109.             gr_setcolor(gr_ugpixel( bitmap, column, row ));
  110.              gr_upixel(column, row);
  111.         }
  112.  
  113.         /* Compute the next sequence element */
  114.         if (element & 1)                /* is the low bit set? */
  115.             element = (element >>1)^mask; /* yes: shift value, */
  116.         else
  117.             element = (element >>1); /* no: just shift the value */
  118.     } while (element != 1);         /* loop until we return to */
  119.                                     /*  original element */
  120.  
  121.     gr_setcolor(gr_ugpixel( bitmap, 0, 0 ));
  122.     gr_upixel(0,0);
  123.  
  124. }
  125.  
  126. 
  127.