home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / bomb.tar.gz / bomb.tar / bomb / fuse.c < prev    next >
C/C++ Source or Header  |  1997-07-14  |  5KB  |  208 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. #include "image.h"
  22. #include "image_db.h"
  23. #include "match.h"
  24.  
  25. #define MAX_ORDER 1000
  26.  
  27. #define FR R8b
  28.  
  29. #define nclimbers 200
  30. struct {
  31.    Image src;
  32.    image8_t dst;
  33.    int score;
  34. } tiles[nclimbers];
  35. int tiles_ready = 0;
  36. int current_climber = 0;
  37.  
  38. void step_rule_fuse(int frame, rule_t *p, image8_t *fb)
  39. {
  40.    int i;
  41.    image8_t dest = *fb;
  42.    static int order = 0;
  43.    int bsize;
  44.    extern int scramble;
  45.    int dr = iclamp(p->drift, fuse_ndrifts);
  46.  
  47.    if (scramble) {
  48.      dr = 0;
  49.      scramble--;
  50.    }
  51.  
  52.    switch (dr) {
  53.     case 0:
  54.       bsize = p->bsize;
  55.       /* bsize = TILE_SIZE; */
  56.       dest.width = bsize;
  57.       dest.height = bsize;
  58.  
  59.       for (i = 0; i < 100; i++) {
  60.      int dest_x = FR%(fb->width - bsize);
  61.      int dest_y = FR%(fb->height - bsize);
  62.      Image *src_img =
  63.         &global_images[iclamp(R, p->image_window_size)];
  64.      Image src_rect;
  65.      image_random_tile(&src_rect, src_img, bsize);
  66.      dest.p = fb->p + fb->stride * dest_y + dest_x;
  67.      image8_blit(&src_rect, &dest);
  68.       }
  69.       order = 0.8 * order;
  70.       break;
  71.     case 1:
  72.       if (1) {
  73.     int ntries;
  74.     int tuner;
  75.     int nb;
  76.     
  77.     bsize = TILE_SIZE;
  78.     dest.width = bsize;
  79.     dest.height = bsize;
  80.  
  81.     tuner = p->search_time;
  82.     if (tuner < 0)
  83.       tuner = 0;
  84.     else if (tuner > 10)
  85.       tuner = 10;
  86.     p->search_time = tuner;
  87.  
  88.     ntries = 1 + order/10 * pow(1.5, tuner);
  89.     nb = 500/ntries;
  90.     if (nb < 1) nb = 1;
  91. #if 0
  92.     printf("ntries=%d nb=%d\n", ntries, nb);
  93. #endif
  94.     for (i = 0; i < nb; i++) {
  95.       int dest_x, dest_y;
  96.       Image match;
  97.       order++;
  98.       if (order > MAX_ORDER)
  99.         order = MAX_ORDER;
  100.  
  101.       dest_x = FR%(fb->width - bsize);
  102.       dest_y = FR%(fb->height - bsize);
  103.       dest.p = fb->p + dest_x + dest_y * fb->stride;
  104.  
  105.       image8_match2(&dest, &match,
  106.             global_images, global_images_small,
  107.             p->image_window_size,
  108.             1 + ntries/(SMALL_FACTOR * SMALL_FACTOR), ntries);
  109.       image8_blit(&match, &dest);
  110.     }
  111.       }
  112.       break;
  113.  
  114.       /*
  115.     case 2:
  116.       bsize = p->bsize;
  117.       if (!tiles_ready) {
  118.      int i;
  119.      for (i = 0; i < nclimbers; i++) {
  120.         int dest_x, dest_y;
  121.         Image *src_img =
  122.            &global_images[iclamp(R, p->image_window_size)];
  123.         image_random_tile(&tiles[i].src, src_img, bsize);
  124.  
  125.         dest_x = FR%(fb->width - bsize);
  126.         dest_y = FR%(fb->height - bsize);
  127.         tiles[i].dst.stride = fb->stride;
  128.         tiles[i].dst.width = bsize;
  129.         tiles[i].dst.height = bsize;
  130.         tiles[i].dst.p = fb->p + fb->stride * dest_y + dest_x;
  131.      }
  132.      tiles_ready = 1;
  133.       }
  134.       if (1) {
  135.      int i;
  136.      int last = current_climber + 2;
  137.      for (i = current_climber; i < last; i++) {
  138.         int j = i%nclimbers;
  139.         if (image8_climb(&tiles[j].dst, &tiles[j].src)) {
  140.            int dest_x, dest_y;
  141.            dest_x = FR%(fb->width - bsize);
  142.            dest_y = FR%(fb->height - bsize);
  143.            dest.p = fb->p + dest_x + dest_y * fb->stride;
  144.         }
  145.      }
  146.      for (i = current_climber; i < last; i++) {
  147.         int j = i%nclimbers;
  148.         image8_blit(&tiles[j].src, &tiles[j].dst);
  149.      }
  150.      current_climber = last;
  151.       }
  152.       break;
  153.       */
  154.     case 2:
  155.       for (i = 0; i < 5; i++) {
  156.      static int track = 0;
  157.      Image src_img =
  158.         global_images[iclamp(track++, p->image_window_size)];
  159.      image8_t dst = *fb;
  160.      if (dst.width < src_img.width) {
  161.         src_img.pixels += (src_img.width - dst.width) / 2;
  162.         src_img.width = dst.width;
  163.      } else {
  164.         dst.p += (dst.width - src_img.width) / 2;
  165.         dst.width = src_img.width;
  166.      }
  167.      if (dst.height < src_img.height) {
  168.         src_img.pixels += src_img.stride * ((src_img.height - dst.height) / 2);
  169.         src_img.height = dst.height;
  170.      } else {
  171.         dst.p += dst.stride * ((dst.height - src_img.height) / 2);
  172.         dst.height = src_img.height;
  173.      }
  174.      image8_blit(&src_img, &dst);
  175.      order = MAX_ORDER;
  176.       }
  177.       break;
  178.     case 3:
  179.       for (i = 0; i < 5; i++) {
  180.      static int track = 0;
  181.      Image src_img =
  182.         global_images[iclamp(track++, p->image_window_size)];
  183.      image8_t dst = *fb;
  184.      if (dst.width < src_img.width) {
  185.         src_img.pixels += (src_img.width - dst.width) / 2;
  186.         src_img.width = dst.width;
  187.      } else if (dst.width == src_img.width) {
  188.         src_img.width = dst.width;
  189.      } else {
  190.         dst.p += FR%((dst.width - src_img.width));
  191.         dst.width = src_img.width;
  192.      }
  193.      if (dst.height < src_img.height) {
  194.         src_img.pixels += src_img.stride * ((src_img.height - dst.height) / 2);
  195.         src_img.height = dst.height;
  196.      } else if (dst.height == src_img.height) {
  197.        dst.height = src_img.height;
  198.      } else {
  199.         dst.p += dst.stride * (FR%(dst.height - src_img.height));
  200.         dst.height = src_img.height;
  201.      }
  202.      image8_blit(&src_img, &dst);
  203.      order = MAX_ORDER;
  204.       }
  205.       break;
  206.    }
  207. }
  208.