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

游戏

开发平台:

Visual C++

  1. #include "ray.h"
  2. #include "resnames.h"
  3. #include "rayfile.h"
  4. #include "globals.h"
  5. #include "scrmes.h"
  6. BOOL Scan_Check_Res(PCHAR res_check)
  7. {
  8. CHAR resource_name[RESOURCE_LENGTH+1];
  9. base_index=0;
  10. strncpy(resource_name, res_check, RESOURCE_LENGTH+1);
  11. if ((base_index=F_Find_Dir(resource_name))!=-1)
  12.    return TRUE;
  13. else return FALSE;
  14. }
  15. BOOL Spec_Check_Res(PCHAR find_res, PCHAR test_res)
  16. {
  17.    if ((Cmp_Str_N(find_res, test_res, RESOURCE_LENGTH)) &&
  18.       ((base_index=F_Find_Dir(find_res))!=-1)) {
  19.          return TRUE;
  20.    } else {
  21.          return FALSE;
  22.    } /* endif */
  23. }
  24. BOOL Cmp_Str_N(char * s1, char * s2, short n)
  25. {
  26.    BOOL still_equal=TRUE;
  27.    short counter;
  28.    for (counter=0; counter<n; counter++) {
  29.       if (s1[counter]!=s2[counter]) {
  30.          still_equal=FALSE;
  31.       }
  32.    } /* endfor */
  33. return still_equal;
  34. }
  35. void F_Init() {
  36.    world_loaded=FALSE;
  37.    wall_tex_loaded=FALSE;
  38.    floor_tex_loaded=FALSE;
  39.    sound_loaded=FALSE;
  40. }
  41. void F_Shutdown() {
  42.    if (world_loaded)
  43.       F_Clear_World();
  44.    if (wall_tex_loaded)
  45.       F_Clear_WT();
  46.    if (floor_tex_loaded)
  47.       F_Clear_FT();
  48.    if (sound_loaded)
  49.       F_Clear_Sound();
  50. }
  51.  void F_Setup(char * filename)
  52. {
  53. fp.open(filename, ios::text | ios::in | ios::out);
  54. F_Seek(0);
  55. fp.read(header.header, 8);
  56. if (header.header[0]=='B') {
  57.    binary_mode=TRUE;
  58.    fp.close();
  59.    fp.open(filename, ios::binary | ios::in | ios::out);
  60.    F_Seek(0);
  61.    fp.read(header.header, 8);
  62. } else {
  63.    binary_mode=FALSE;
  64.    fp.ignore(100, 'n');
  65. }
  66. F_Get_Long(header.dir_entries);
  67. F_Get_Long(header.dir_location);
  68. F_Seek(header.dir_location);
  69. directory=(dir_entry *)NewPtr(header.dir_entries * sizeof(dir_entry));
  70. short counter;
  71. dir_entry * cur_dir;
  72. for (counter=0; counter<header.dir_entries; counter++) 
  73. {
  74.   cur_dir=directory+counter;
  75.   F_Get_String(cur_dir->name, 8);
  76.   F_Get_Long(cur_dir->start);
  77.   F_Get_Long(cur_dir->length);
  78. }
  79. }
  80.  void F_Close()
  81. {
  82. fp.close();
  83. }
  84.  void F_Seek(long offset)
  85. {
  86. if (binary_mode)
  87.   fp.seekg(offset, ios::beg);
  88. else {
  89.   fp.seekg(0, ios::beg);
  90.   short counter;
  91.   for (counter=0; counter< offset; counter++) {
  92.     fp.ignore(-1, 'n');
  93.     }
  94.   }
  95. }
  96.  void F_Scan_Load(char * filename)
  97. {
  98. F_Setup(filename);
  99. if (Scan_Check_Res((PCHAR)WORLD_RES)) {
  100.   Screen_Message("Loading world!");
  101.   F_Load_World();
  102. }
  103. if (Scan_Check_Res((PCHAR)WTEX_RES)) {
  104.   Screen_Message("Loading wall textures!");
  105.   F_Get_Wall_Textures();
  106. }
  107. if (Scan_Check_Res((PCHAR)FTEX_RES)) {
  108.    Screen_Message("Loading floor textures!");
  109.    F_Get_Floor_Textures();
  110. }
  111. if (Scan_Check_Res((PCHAR)SOUND_RES)) {
  112.    Screen_Message("Loading music!");
  113.    F_Get_Sound();
  114. }
  115. if (Scan_Check_Res((PCHAR)OBJECT_TYPE_RES)) {
  116.    Screen_Message("Loading object types!");
  117.    F_Get_Object_Types();
  118. }
  119. if (Scan_Check_Res((PCHAR)OBJECT_RES)) {
  120.    Screen_Message("Loading objects!");
  121.    F_Get_Objects();
  122. }
  123. F_Close();
  124. }
  125.  void F_Spec_Load(short num_elements, char * filename, ... )
  126. {
  127. va_list vars;
  128. short index; char * cur_v;
  129. va_start(vars, filename);
  130. F_Setup(filename);
  131. for (index=0; index< num_elements; index++) {
  132.   cur_v=va_arg(vars, char *);
  133.   base_index=0;
  134.   if (Spec_Check_Res((PCHAR)WTEX_RES, cur_v)) {
  135.     Screen_Message("Loading wall textures!");
  136.     F_Get_Wall_Textures();
  137.   } else if (Spec_Check_Res((PCHAR)FTEX_RES, cur_v)) {
  138.      Screen_Message("Loading floor textures!");
  139.      F_Get_Floor_Textures();
  140.   } else if (Spec_Check_Res((PCHAR)SOUND_RES, cur_v)) {
  141.      Screen_Message("Loading music!");
  142.      F_Get_Sound();
  143.   } else if (Spec_Check_Res((PCHAR)OBJECT_TYPE_RES, cur_v)) {
  144.      Screen_Message("Loading object types!");
  145.      F_Get_Object_Types();
  146.   } else if (Spec_Check_Res((PCHAR)OBJECT_RES, cur_v)) {
  147.      Screen_Message("Loading objects!");
  148.      F_Get_Objects();
  149.   } else if (Scan_Check_Res(cur_v)) {
  150.     Screen_Message("Loading world!");
  151.     F_Load_World();
  152.   }
  153. }  
  154. F_Close();
  155. va_end(vars);
  156. }
  157.  SHORT F_Find_Dir(char * name)
  158. {
  159. BOOL found=FALSE;
  160. short counter;
  161. for (counter=base_index; counter< header.dir_entries; counter++) {
  162.    if (Cmp_Str_N(name, directory[counter].name, 8)) {
  163.       found=TRUE;
  164.       break;
  165.    }
  166. } /* endfor */
  167. if (found==TRUE) {
  168.    return counter;
  169. } else {
  170.    return -1;
  171. } /* endif */
  172. }
  173.  short F_Find_And_Setup(char * string, void * * table, short memsize)
  174. {
  175.    short temp_index;  
  176.    if ((temp_index=F_Find_Dir(string))==-1)
  177.      return temp_index;
  178.    (*table)=(void *)NewPtr(directory[temp_index].length * memsize);
  179.    F_Seek(directory[temp_index].start);
  180.    return temp_index;
  181. }