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

游戏

开发平台:

Visual C++

  1. #include "ray.h"
  2. #include "resnames.h"
  3. #include "globals.h"
  4. #include "voxel.h"
  5. #include "rayfile.h"
  6. #include "waves.h"
  7. #include "prevarr.h"
  8. #include "scrconf.h"
  9. #include "gentree.h"
  10. #include "sprvox.h"
  11. #include "verttan.h"
  12. #define VOX_PAL_FILE "vox.pal"
  13. #define START_DIS VOXEL_SPEED_SCALE
  14. #define START_HEIGHT 3
  15. BOOL voxel_running=FALSE;
  16. PUCHAR pal_save;
  17. //long old_px, old_py, old_pv_angle; No longer needed as engines use one coordinate system
  18. void Setup_G_Table();
  19. void Setup_Y_Jumps();
  20. void Setup_Alt_Scaler();
  21. void Setup_H_Table();
  22. void Setup_Change_Table();
  23. inline void Del_Alt_Scaler() {
  24.   for (short i=0; i<DIST_MAX; i++)
  25.     DelPtr(alt_scaler[i]);
  26.   DelPtr(alt_scaler);
  27. }
  28. void Close_Voxel()
  29. {
  30.    if (!voxel_running) {
  31.       return;
  32.    } /* endif */
  33.    DelPtr(g_table);
  34.    DelPtr(y_jumps);
  35.    Del_Alt_Scaler();
  36.    Close_Waves();  
  37.    voxel_running=FALSE;
  38. }
  39. void Init_Voxel()
  40. {
  41. DIST_SCALER=START_DIS;
  42. V_Set_Dist_Scale(START_HEIGHT);
  43. Setup_Voxel_Tables();
  44. Setup_Waves();
  45. voxel_running=TRUE;
  46. Init_Vox_Sprite_Table();
  47. }
  48. void Setup_Voxel_Tables()
  49. {
  50.    Setup_Y_Jumps();
  51.    Setup_G_Table();
  52.    Setup_Alt_Scaler();
  53.    Setup_H_Table();
  54.    Setup_Change_Table();
  55. }
  56. void Setup_Y_Jumps()
  57. {
  58.    y_jumps=(PULONG)NewPtr(Get_Phys_Screen_Height() * sizeof(ULONG));
  59. if (Get_Phys_Orientation()>0) {
  60.    ULONG cur_offset=0;
  61.    for (USHORT cur_y=0; cur_y<Get_Phys_Screen_Height(); cur_y++) {
  62.       y_jumps[cur_y]=cur_offset;
  63.       cur_offset+=(ULONG)Get_Phys_Screen_Width();
  64.    } /* endfor */
  65. } else {
  66.    ULONG cur_offset=(Get_Phys_Screen_Height()-1)*Get_Phys_Screen_Width();
  67.    for (USHORT cur_y=0; cur_y<Get_Phys_Screen_Height(); cur_y++) {
  68.       y_jumps[cur_y]=cur_offset;
  69.       cur_offset-=(ULONG)Get_Phys_Screen_Width();
  70.    }
  71. }
  72. }
  73. void Setup_H_Table() {
  74.    h_table=(PLONG)NewPtr(Get_Phys_Screen_Height() *2 * MAX_TABLED_HC_INTP*sizeof(long));
  75.    short cur_height_diff, cur_r_length;
  76.    short real_height_diff;
  77.    for (cur_height_diff=0; cur_height_diff<(Get_Phys_Screen_Height()*2); cur_height_diff++) {
  78.       real_height_diff=cur_height_diff-Get_Phys_Screen_Height();
  79.          // set 0 manually as loop cause div by 0
  80.          h_table[cur_height_diff*MAX_TABLED_HC_INTP]=0;
  81.          for (cur_r_length=1; cur_r_length<MAX_TABLED_HC_INTP; cur_r_length++) {
  82.             h_table[MAX_TABLED_HC_INTP*cur_height_diff+cur_r_length]=(long)
  83.                (((long)real_height_diff << HEIGHT_CHANGE_SHIFT) /
  84.                (long)cur_r_length);
  85.          } /* endfor */
  86.       } /* endif */
  87. }
  88. void Setup_Change_Table() {
  89.    vox_change_table=(PVOID)NewPtr(Get_Phys_Screen_Width()*HCP_SIZE);
  90. }
  91. void Setup_G_Table()
  92. {
  93.    g_table=(PSHORT)NewPtr((Get_Phys_Screen_Width()+1)*COLOR_DIFF_COUNT*sizeof(short));
  94.    short cur_col_diff, cur_r_length;
  95.    short real_col_diff;
  96.    for (cur_col_diff=0; cur_col_diff<COLOR_DIFF_COUNT; cur_col_diff++) {
  97.       real_col_diff=cur_col_diff-G_TABLE_ADJUST;
  98.       // is this a color diff there is posible interpolation for
  99.       if ((real_col_diff<MAX_INT_LIGHT_DIFF)&&(real_col_diff>MIN_INT_LIGHT_DIFF)) {
  100.          // set 0 manually as loop cause div by 0
  101.          g_table[cur_col_diff]=0;
  102.          for (cur_r_length=1; cur_r_length<(Get_Phys_Screen_Width()+1); cur_r_length++) {
  103.             g_table[COLOR_DIFF_COUNT*cur_r_length+cur_col_diff]=(short)
  104.                (((long)real_col_diff << LIGHT_FP_SHIFT) /
  105.                (long)cur_r_length);
  106.          } /* endfor */
  107.       } else {
  108.          for (cur_r_length=0; cur_r_length<(Get_Phys_Screen_Width()+1); cur_r_length++) {
  109.             g_table[COLOR_DIFF_COUNT*cur_r_length+cur_col_diff]=0;
  110.          } /* endfor */
  111.       } /* endif */
  112.    } /* endfor */
  113. }
  114. void Setup_Alt_Scaler()
  115. {
  116.    short cur_dis;
  117.    short cur_alt;
  118.    long temp_calc;
  119.    // allocate altitudes
  120.    alt_scaler=(PSHORT *)NewPtr(DIST_MAX * sizeof(PSHORT));
  121.    for (cur_dis=0; cur_dis<DIST_MAX; cur_dis++) {
  122.       alt_scaler[cur_dis]=(PSHORT)NewPtr(ALT_MAX * sizeof(SHORT));
  123.    } /* endfor */
  124.    // get screen heights by altitudes
  125.    for (cur_dis=1; cur_dis<DIST_MAX; cur_dis++) {
  126.       for (cur_alt=0; cur_alt<ALT_MAX; cur_alt++) {
  127.          temp_calc=(LONG)(ALT_MAX-(cur_alt+1));
  128.          temp_calc*=HEIGHT_SCALER;
  129.          temp_calc*=(y_trans/(cur_dis*DIST_SCALER));
  130.          temp_calc>>=SHIFT;
  131.          alt_scaler[cur_dis][cur_alt]=(SHORT)temp_calc;
  132.       } /* endfor */
  133.    } /* endfor */
  134. }
  135. void V_Recalc_Alts()
  136. {
  137. if (voxel_running) {
  138.    Del_Alt_Scaler();
  139.    Setup_Alt_Scaler();
  140. }
  141. }
  142. void V_Recalc_Screen() {
  143.    if (voxel_running) {
  144.       DelPtr(y_jumps);
  145.       DelPtr(g_table);
  146.       DelPtr(h_table);
  147.       DelPtr(vox_change_table);
  148.       Setup_Y_Jumps();
  149.       Setup_G_Table();
  150.       Setup_H_Table();
  151.       Setup_Change_Table();
  152.    }
  153. }
  154. void V_Recalc_Length() {
  155.    if (voxel_running) {
  156.       v_horiz_length=WINDOW_WIDTH;
  157.    }
  158. }