DOWAVE.CPP
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:3k
源码类别:

游戏

开发平台:

Visual C++

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