home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / RAYCAST.ZIP / DOWAVE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-19  |  3.0 KB  |  128 lines

  1. #include "ray.h"
  2. #include "globals.h"
  3. #include "voxel.h"
  4. #include "waves.h"
  5. #include <mem.h>
  6.  
  7. #define WATER_LEVEL 48
  8.  
  9. typedef struct VOX_WAVE_INFO * pvox_wave_info;
  10.  
  11. typedef struct VOX_WAVE_INFO {
  12.   short y;
  13.   short start_x, length;
  14.   PUCHAR alt_array, color_array;
  15.   } vox_wave_info;
  16.  
  17. inline BOOL Is_Water(short x, short y)
  18. {
  19.   if (alt_array[(y<<ALT_Y_SHIFT)+x]<WATER_LEVEL) {
  20.     return TRUE;
  21.   } else {
  22.     return FALSE;
  23.   }
  24. }
  25.  
  26. inline long Go_To_End(short & x, short y)
  27. {
  28. long length=0;
  29. while ((x<ALT_WIDTH)&&(Is_Water(x,y))) {
  30.    x++;
  31.    length++;
  32.    }
  33. return length;
  34. }
  35.  
  36. pvox_wave_info waves;
  37. long number_of_waves;
  38.  
  39. void Do_Waves() {
  40.  
  41. PUCHAR alt_base, col_base; 
  42. long base_ptr;
  43. UCHAR alt_temp, col_temp;
  44.  
  45. pvox_wave_info cur_wave;
  46.  
  47. for (short wave_index=0; wave_index<number_of_waves; wave_index++) {
  48.   cur_wave=waves+wave_index;
  49.   base_ptr=(cur_wave->y<<ALT_Y_SHIFT)+cur_wave->start_x;
  50.   alt_base=cur_wave->alt_array+base_ptr;
  51.   col_base=cur_wave->color_array+base_ptr;
  52.   alt_temp=*(alt_base+(cur_wave->length-1));
  53.   col_temp=*(col_base+(cur_wave->length-1));
  54.   memmove(alt_base+1,alt_base,cur_wave->length-1); 
  55.   memmove(col_base+1,col_base,cur_wave->length-1);
  56.   *(alt_base)=alt_temp;
  57.   *(col_base)=col_temp;
  58.   }
  59.  
  60. }
  61.  
  62. void Close_Waves() {
  63.   if (waves!=NULL)
  64.      DelPtr(waves);
  65.   }
  66.  
  67. void Setup_Waves() {
  68. long temp_length;
  69. short save_x;
  70. short cur_x, cur_y;
  71. short wave_index;
  72. pvox_wave_info cur_wave;
  73. short sec_index;
  74.  
  75. number_of_waves=0;
  76. for (sec_index=0; sec_index<Number_Of_Sectors; sec_index++) {
  77.    if (Sector_List[sec_index].flags & VOXEL_SECTOR) {
  78.       alt_array=(PUCHAR)Sector_List[sec_index].extra_data;
  79.       color_array=alt_array+ALT_TO_COL_DIFF;
  80.       for (cur_y=0; cur_y<ALT_HEIGHT; cur_y++) {
  81.          cur_x=0;
  82.          while (cur_x<ALT_WIDTH) {
  83.             if (Is_Water(cur_x, cur_y)) {
  84.                temp_length=Go_To_End(cur_x, cur_y);
  85.                if (temp_length>1)
  86.                   number_of_waves++;
  87.             }
  88.             cur_x++;
  89.          }
  90.       }
  91.    }
  92. }
  93.  
  94. if (number_of_waves==0) {
  95.    waves=NULL;
  96.    return;
  97. }
  98.  
  99. waves=(pvox_wave_info)NewPtr(number_of_waves*sizeof(vox_wave_info));
  100.  
  101. wave_index=0;
  102. for (sec_index=0; sec_index<Number_Of_Sectors; sec_index++) {
  103.    if (Sector_List[sec_index].flags & VOXEL_SECTOR) {
  104.       alt_array=(PUCHAR)Sector_List[sec_index].extra_data;
  105.       color_array=alt_array+ALT_TO_COL_DIFF;
  106.       for (cur_y=0; cur_y<ALT_HEIGHT; cur_y++) {
  107.          cur_x=0;
  108.          while (cur_x<ALT_WIDTH) {
  109.          if (Is_Water(cur_x, cur_y)) {
  110.             save_x=cur_x;
  111.             temp_length=Go_To_End(cur_x, cur_y);
  112.             if (temp_length>1) {
  113.                cur_wave=waves+wave_index;
  114.                cur_wave->y=cur_y;
  115.                cur_wave->start_x=save_x;
  116.                cur_wave->length=temp_length;
  117.                cur_wave->alt_array=alt_array;
  118.                cur_wave->color_array=color_array;
  119.                wave_index++;
  120.             }
  121.          }
  122.          cur_x++;
  123.          }
  124.       }
  125.    }
  126. }
  127. }
  128.