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

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