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

  1. #include "ray.h"
  2. #include "globals.h"
  3. #include "rayfile.h"
  4. #include "blockbsp.h"
  5. #include "SortSeg.h"
  6. #include "genbsp.h"
  7. #include "blockmap.h"
  8. #include "fixed.h"
  9. #include "scrmes.h"
  10.  
  11. inline sector * Get_Sec_From_SSec(ssector * cur_ss)
  12. {
  13.    seg * cur_seg=Seg_List+cur_ss->seg_start;
  14.    return (cur_seg->ld->s[(short)cur_seg->left_sidedef]->sec);
  15. }
  16.  
  17. void F_Clear_World()
  18. {
  19.    DelPtr(Vector_List);
  20.    DelPtr(Sd_List);
  21.    DelPtr(Ld_List);
  22.    DelPtr(Seg_List);
  23.    DelPtr(SS_List);
  24.    for (short sec_index=0; sec_index<Number_Of_Sectors; sec_index++) {
  25.       if (Sector_List[sec_index].extra_data!=NULL) {
  26.          DelPtr(Sector_List[sec_index].extra_data);
  27.       }
  28.    }
  29.    DelPtr(Sector_List);
  30.    DelPtr(bsp_tree);
  31.    Clear_Block_Map();
  32.    Clear_BSP_Block();
  33. }
  34.  
  35.  void F_Load_World()
  36. {
  37.    if (world_loaded)
  38.       F_Clear_World();
  39.    Screen_Message("Loading sectors!");
  40.    F_Get_Sectors();               
  41.    Screen_Message("Loading vectors!");
  42.    F_Get_Vectors();
  43.    Screen_Message("Loading sidedefs!");
  44.    F_Get_SDs();
  45.    Screen_Message("Loading linedefs!");
  46.    F_Get_LDs();
  47.    Screen_Message("Loading segs!");
  48.    F_Get_Segs();
  49.    Screen_Message("Loading sub sectors!");
  50.    F_Get_SSectors();
  51.    Screen_Message("Loading the bsp!");
  52.    F_Get_BSP();
  53.    world_loaded=TRUE;
  54. }
  55.  
  56.  void F_Get_Vectors()
  57. {
  58.   short dir_index=F_Find_And_Setup("VECTORS ", (void **)&Vector_List, sizeof(vector2));
  59.    if (dir_index==-1)
  60.       return;
  61.    Number_Of_Vectors=directory[dir_index].length;
  62.    vector2 * cur_vec;
  63.    short counter;
  64.    for (counter=0; counter< Number_Of_Vectors; counter++) {
  65.       cur_vec=Vector_List+counter;    
  66.       F_Get_Long(cur_vec->x);
  67.       F_Get_Long(cur_vec->y);
  68.    }
  69.    
  70. }
  71.  
  72.  void F_Get_SDs()
  73. {
  74.    short dir_index=F_Find_And_Setup("SIDEDEFS", (void **)&Sd_List, sizeof(sidedef));
  75.     if (dir_index==-1)
  76.       return;
  77.    Number_Of_Sidedefs=directory[dir_index].length;
  78.    short counter;
  79.    short temp_short;
  80.    sidedef * cur_sd;
  81.    for (counter=0; counter < Number_Of_Sidedefs; counter++) {
  82.      cur_sd=Sd_List+counter;
  83.      F_Get_UShort(cur_sd->attributes);
  84.      F_Get_Short(cur_sd->x_offset);
  85.      F_Get_Short(cur_sd->y_offset);
  86.      F_Get_Short(cur_sd->texture_normal);
  87.      F_Get_Short(cur_sd->texture_low);
  88.      F_Get_Short(cur_sd->texture_high);
  89.      F_Get_Short(temp_short);
  90.  
  91.      if (temp_short==-1) {
  92.         cur_sd->sec=NULL;
  93.      } else {
  94.         cur_sd->sec=(Sector_List+temp_short);
  95.      } /* endif */
  96.  
  97.      }
  98.  
  99. }
  100.  
  101.  void F_Get_LDs()
  102. {
  103.    short dir_index=F_Find_And_Setup("LINEDEFS", (void **)&Ld_List, sizeof(linedef));
  104.    if (dir_index==-1)
  105.       return;
  106.    Number_Of_Linedefs=directory[dir_index].length;
  107.    short counter;
  108.    short temp_short;
  109.    long x1,y1,x2,y2;
  110.    linedef * cur_ld;
  111.    for (counter=0; counter < Number_Of_Linedefs; counter++) {
  112.      cur_ld=Ld_List+counter;
  113.      F_Get_Short(temp_short);
  114.      cur_ld->v[0]=temp_short;
  115.      F_Get_Short(temp_short);
  116.      cur_ld->v[1]=temp_short;
  117.      F_Get_Short(temp_short);
  118.      if (temp_short >=0)
  119.         cur_ld->s[0]=(Sd_List+temp_short);
  120.      else cur_ld->s[0]=NULL;
  121.      F_Get_Short(temp_short);
  122.      if (temp_short >=0)
  123.         cur_ld->s[1]=(Sd_List+temp_short);
  124.      else cur_ld->s[1]=NULL;
  125.      F_Get_UShort(cur_ld->tag);
  126.      F_Get_UShort(cur_ld->tag_type);
  127.      F_Get_UShort(cur_ld->attributes);
  128.      x1=Vector_List[cur_ld->v[0]].x;
  129.      y1=Vector_List[cur_ld->v[0]].y;
  130.      x2=Vector_List[cur_ld->v[1]].x;
  131.      y2=Vector_List[cur_ld->v[1]].y;
  132.      cur_ld->distance=longsqrtHP((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  133.    }
  134.    Generate_Block_Map();
  135. }
  136.  
  137.  void F_Get_Segs()
  138. {
  139.    short dir_index=F_Find_And_Setup("SEGS    ", (void **)&Seg_List, sizeof(seg));
  140.    if (dir_index==-1)
  141.       return;
  142.    Number_Of_Segs=directory[dir_index].length;       
  143.    short counter;
  144.    short temp_short;
  145.    Byte temp_byte;
  146.    seg * cur_seg;
  147.    for (counter=0; counter< Number_Of_Segs; counter++) {
  148.      cur_seg=Seg_List+counter;
  149.      F_Get_Short(temp_short);  
  150.      cur_seg->v[0]=temp_short;
  151.      F_Get_Short(temp_short);
  152.      cur_seg->v[1]=temp_short;
  153.      F_Get_Long(cur_seg->angle);
  154.      F_Get_Short(temp_short);
  155.      cur_seg->ld=Ld_List+temp_short;
  156.      F_Get_Byte(temp_byte);
  157.      cur_seg->left_sidedef=(BOOL)temp_byte;
  158.      F_Get_Long(cur_seg->linedef_offset);
  159.      }
  160. }
  161.  
  162.  void F_Get_SSectors()
  163. {
  164.    short dir_index=F_Find_And_Setup("SSECTORS", (void **)&SS_List, sizeof(ssector));
  165.    if (dir_index==-1)
  166.       return;
  167.    Number_Of_SSectors=directory[dir_index].length;   
  168.    short counter;
  169.    ssector * cur_ssec;
  170.    for (counter=0; counter< Number_Of_SSectors; counter++) {
  171.      cur_ssec=SS_List+counter;
  172.      F_Get_Short(cur_ssec->seg_start);
  173.      F_Get_Short(cur_ssec->seg_end);
  174.      cur_ssec->num_objects=0;
  175.      cur_ssec->objects=NULL;
  176.      cur_ssec->flags=Get_Sec_From_SSec(cur_ssec)->flags;
  177.      }
  178. }
  179.  
  180.  void F_Get_Sectors()
  181. {
  182.    long cur_pos, extra_data_offset;
  183.  
  184.    short dir_index=F_Find_And_Setup("SECTORS ", (void **)&Sector_List, sizeof(sector));
  185.    if (dir_index==-1)
  186.       return;
  187.    Number_Of_Sectors=directory[dir_index].length;     
  188.    short counter;
  189.    sector * cur_sec;
  190.    for (counter=0; counter < Number_Of_Sectors; counter++) {
  191.      cur_sec=Sector_List+counter;
  192.      F_Get_UShort(cur_sec->tag);
  193.      F_Get_Short(cur_sec->floor_height);
  194.      F_Get_Short(cur_sec->ceil_height);
  195.      F_Get_Short(cur_sec->floor_tex);
  196.      F_Get_Short(cur_sec->ceil_tex);
  197.      F_Get_Byte(cur_sec->light);
  198.      F_Get_UShort(cur_sec->flags);
  199.      if (cur_sec->flags & VOXEL_SECTOR) {
  200.         F_Get_Long(extra_data_offset);
  201.         cur_pos=F_Abs_Pos();
  202.         Load_Vox_Map((PUCHAR &)cur_sec->extra_data, extra_data_offset);
  203.         F_Seek_Abs(cur_pos);
  204.         } else cur_sec->extra_data=NULL;
  205.      }
  206. }
  207.  
  208.  void F_Get_BSP()
  209. {
  210.    short dir_index=F_Find_And_Setup("NODES   ", (void **)&bsp_tree, sizeof(bsp_node));
  211.    if (dir_index==-1) {
  212.       Generate_BSP();
  213.       Generate_BSP_Block();
  214.       return;
  215.    }
  216.    Number_Of_Nodes=directory[dir_index].length;
  217.    bsp_start_node=0;
  218.    short counter;
  219.    bsp_node * cur_node;
  220.    prectl cur_rect;
  221.    for (counter=0; counter < Number_Of_Nodes; counter++) {
  222.      cur_node=bsp_tree+counter;
  223.      F_Get_Long(cur_node->x1);
  224.      F_Get_Long(cur_node->y1);
  225.      F_Get_Long(cur_node->x2);
  226.      F_Get_Long(cur_node->y2);
  227.      cur_rect=&(cur_node->left_bound);
  228.      F_Get_Long(cur_rect->top);
  229.      F_Get_Long(cur_rect->left);
  230.      F_Get_Long(cur_rect->bottom);
  231.      F_Get_Long(cur_rect->right);
  232.      cur_rect=&(cur_node->right_bound);
  233.      F_Get_Long(cur_rect->top);
  234.      F_Get_Long(cur_rect->left);
  235.      F_Get_Long(cur_rect->bottom);
  236.      F_Get_Long(cur_rect->right);
  237.      F_Get_UShort(cur_node->left_child);
  238.      F_Get_UShort(cur_node->right_child);
  239.    }
  240.    Generate_BSP_Block();
  241. }
  242.  
  243.  
  244.