home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / bomb.tar.gz / bomb.tar / bomb / rug_multi.c < prev    next >
C/C++ Source or Header  |  1997-04-25  |  4KB  |  127 lines

  1. /*
  2.     bomb - automatic interactive visual stimulation
  3.     Copyright (C) 1994  Scott Draves <spot@cs.cmu.edu>
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include "defs.h"
  21.  
  22. #define SHOW_DRIVER 0
  23.  
  24. void step_rule_rug_multi(int frame, rule_t *p, image8_t *fb)
  25. {
  26.    int x, y;
  27.    board_t *s_heat_board, *d_heat_board;
  28.    board_t *s_game_board, *d_game_board;
  29.    u_char *lp0, *lp1;
  30.    static int ptab[] = {1, 2, 4, 5};
  31.    int nplanes = ptab[iclamp(p->brain_shift, 4)];
  32.    int stripe_height = SMALL_YSIZE / nplanes;
  33.    static int phase = 0;
  34.    int slowdown = nplanes * p->driver_slowdown;
  35.    if (++phase >= nplanes)
  36.       phase = 0;
  37.  
  38.    dbuf = frame&1;
  39.    s_heat_board=&board[dbuf];
  40.    d_heat_board=&board[1-dbuf];
  41.  
  42.    dbuf = (frame/slowdown)&1;
  43.    s_game_board=&board2[dbuf];
  44.    d_game_board=&board2[1-dbuf];
  45.  
  46.    for(y=0;y<=SMALL_YSIZE+1;y++) {
  47.       (*s_game_board)[0][y] = (*s_game_board)[SMALL_XSIZE][y];
  48.       (*s_game_board)[SMALL_XSIZE+1][y] = (*s_game_board)[1][y];
  49.       (*s_heat_board)[0][y] = (*s_heat_board)[SMALL_XSIZE][y];
  50.       (*s_heat_board)[SMALL_XSIZE+1][y] = (*s_heat_board)[1][y];
  51.    }
  52.    for(x=0;x<=SMALL_XSIZE+1;x++) {
  53.       (*s_game_board)[x][0] = (*s_game_board)[x][SMALL_YSIZE];
  54.       (*s_game_board)[x][SMALL_YSIZE+1] = (*s_game_board)[x][1];
  55.       (*s_heat_board)[x][0] = (*s_heat_board)[x][SMALL_YSIZE];
  56.       (*s_heat_board)[x][SMALL_YSIZE+1] = (*s_heat_board)[x][1];
  57.    }
  58.  
  59.    if (0 == ((frame+1) % slowdown))
  60.       for (y = 1; y<=SMALL_YSIZE; y++) {
  61.      for (x=1; x<=SMALL_XSIZE; x++) {
  62.         int ht = (((*s_game_board)[x  ][y  ]) +
  63.               (*s_game_board)[x+1][y  ] +
  64.               (*s_game_board)[x-1][y  ] +
  65.               (*s_game_board)[x  ][y+1] +
  66.               (*s_game_board)[x  ][y-1])/5;
  67.         (*d_game_board)[x][y] = (ht - 1) & 471;
  68.      }
  69.       }
  70.  
  71.    for (y=1; y<=SMALL_YSIZE; y++) {
  72.       lp0 = fb->p + (fb->stride * (y - 1));
  73.       lp1 = lp0 + fb->stride * SMALL_YSIZE;
  74.       for (x=1; x<=SMALL_XSIZE; x++) {
  75.      int heat, dh;
  76.      int driver, hn, hs, he, hw, hc, denom;
  77.      int gy;
  78.  
  79.      driver = 0;
  80.      for (gy = 1 + ((y-1)/nplanes); gy <= SMALL_YSIZE; gy += stripe_height) {
  81.         int v;
  82.         v = (*s_game_board)[x][gy];
  83.         driver = ((driver<<1) | (v < 20));
  84.      }
  85.  
  86.      hn = (*s_heat_board)[x  ][y-1];
  87.      hs = (*s_heat_board)[x  ][y+1];
  88.      he = (*s_heat_board)[x+1][y  ];
  89.      hw = (*s_heat_board)[x-1][y  ];
  90.      hc = (*s_heat_board)[x  ][y  ];
  91.      denom = 5;
  92.      heat = hn + hs + he + hw + hc;
  93.      dh = p->speed;
  94.      if (driver&0x1)   { heat -= hn; denom--;}
  95.      if (driver&0x2)   { heat -= hs; denom--;}
  96.      if (driver&0x4)   { heat -= he; denom--;}
  97.      if (driver&0x8)   { heat -= hw; denom--;}
  98.      heat = ((heat / denom) + dh) & p->mask;
  99.      (*d_heat_board)[x][y] = heat;
  100.  
  101. #if SHOW_DRIVER
  102.      p1 = iclamp(p1, 2 + nplanes);
  103.      switch (p1) {
  104.       case 0:
  105.         // if (p->remap)
  106.            heat = remap[heat];
  107.         break;
  108.       case 1:
  109.         heat = driver ^ (driver >> 8) ^ (driver >> 16);
  110.         break;
  111.       default:
  112.         heat = (driver & (1 << (p1 - 2))) ? 0 : 100;
  113.         break;
  114.      }
  115. #else
  116.      // if (p->remap)
  117.         heat = remap[heat];
  118. #endif
  119.  
  120.      lp0[SMALL_XSIZE] = heat;
  121.      *lp0++ = heat;
  122.      lp1[SMALL_XSIZE] = heat;
  123.      *lp1++ = heat;
  124.       }
  125.    }
  126. }
  127.