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

  1. #include "ray.h"
  2. #include "globals.h"
  3. #include "rgobject.h"
  4. #include "rayfile.h"
  5. #include "texconst.h"
  6. #include "utils.h"
  7.  
  8. void FlipBMP(Ptr data, unsigned short width, unsigned short height);
  9. void Flip_Vert_BMP(PUCHAR source_image, USHORT width, USHORT height);    
  10.  
  11. void F_Get_Wall_Textures()
  12. {
  13.    if (wall_tex_loaded)
  14.       F_Clear_WT();
  15.    wall_tex_loaded=TRUE;
  16.    short dir_index=F_Find_Dir("WALLTEXS");
  17.    if (dir_index==-1)
  18.       return;
  19.    F_Seek(directory[dir_index].start);
  20.    short num_straight_tex;
  21.    F_Get_Short(num_straight_tex);
  22.    char filename[13];       
  23.    RCastGobject texturetemp(num_straight_tex);
  24.    texturetemp.Hold();
  25.    short next_image_num;
  26.    short counter, counter2;
  27.  
  28.    // in order that we can use animated maps, we first
  29.    // read the textures linearly, into one resource.
  30.    // we then read a list of animation arrangments
  31.    // so that multiple animations can be arranged from the same textures
  32.  
  33.    Number_Of_Textures=directory[dir_index].length+1;
  34.  
  35.    wall=(wall_entry *)NewPtr((Number_Of_Textures) * sizeof(wall_entry));
  36.  
  37.    wall[0].num_image=num_straight_tex;
  38.    wall[0].images=(Byte **)NewPtr(num_straight_tex * sizeof(Byte *));
  39.    wall[0].width=0;
  40.    wall[0].height=0;
  41.    wall[0].shift=0;
  42.  
  43.    for (counter=0; counter < num_straight_tex; counter++) {
  44.       F_Get_String_NT(filename, F_NAME_LENGTH);
  45.       texturetemp.assigninfile(filename);
  46.       texturetemp.load(counter);
  47.       FlipBMP(texturetemp.Image(counter), texturetemp.Width(), texturetemp.Height());
  48.       wall[0].images[counter]=texturetemp.Image(counter);
  49.    } /* endfor */
  50.  
  51.    for (counter=1; counter < Number_Of_Textures; counter++) {
  52.       wall[counter].cur_image=0;
  53.       wall[counter].anim_sum=0;
  54.       F_Get_Short(wall[counter].num_image);
  55.       F_Get_Long(wall[counter].anim_speed);
  56.       F_Get_Short(wall[counter].width);
  57.       F_Get_Short(wall[counter].height);
  58.       wall[counter].shift=Check2Shift(wall[counter].height);
  59.       wall[counter].images=(Byte **)NewPtr(wall[counter].num_image * sizeof(Byte *));
  60.       for (counter2=0; counter2 < wall[counter].num_image; counter2++) {
  61.          F_Get_Short(next_image_num);
  62.          wall[counter].images[counter2]=wall[0].images[next_image_num];
  63.       } /* endfor */
  64.    } /* endfor */
  65.  
  66. }
  67.  
  68. void FlipBMP(Ptr data, unsigned short width, unsigned short height)
  69. {
  70. Ptr tempptr=NewPtr(sizeof(char)*width*height);
  71. for (int i=0; i<height; i++) {
  72.    for (int j=0; j<width; j++) {
  73.       tempptr[j*height+i]=data[i*width+j];
  74.    } /* endfor */
  75. }
  76. memcpy(data,tempptr,(sizeof(char)*width*height));
  77. DelPtr( tempptr);
  78. }
  79.  
  80. void F_Clear_WT()
  81. {
  82.  
  83.    short counter1;
  84.  
  85.    for (counter1=0; counter1 < wall[0].num_image; counter1++) {
  86.       delete wall[0].images[counter1];
  87.    }
  88.  
  89.    for (counter1=0; counter1 < Number_Of_Textures; counter1++) {
  90.       if (wall[counter1].images!=NULL)
  91.         DelPtr( wall[counter1].images);
  92.    } /* endfor */
  93.  
  94.    DelPtr( wall);
  95.  
  96. }
  97.  
  98.     
  99. void F_Get_Floor_Textures()
  100. {
  101.    if (floor_tex_loaded)
  102.       F_Clear_FT();
  103.    floor_tex_loaded=TRUE;
  104.    short dir_index=F_Find_Dir("FLOORTEX");
  105.    if (dir_index==-1)
  106.       return;
  107.    F_Seek(directory[dir_index].start);
  108.    short num_straight_tex;
  109.    F_Get_Short(num_straight_tex);
  110.    char filename[13];       
  111.    RCastGobject texturetemp(num_straight_tex);
  112.    texturetemp.Hold();
  113.    short next_image_num;
  114.    short counter, counter2;
  115.    short tex_list_num;
  116.  
  117.    // in order that we can use animated maps, we first
  118.    // read the textures linearly, into one resource.
  119.    // we then read a list of animation arrangments
  120.    // so that multiple animations can be arranged from the same textures
  121.  
  122.    Number_Of_FTs=directory[dir_index].length+2;
  123.  
  124.    tex_list_num=Number_Of_FTs-1;
  125.  
  126.    floortex=(wall_entry *)NewPtr((Number_Of_FTs) * sizeof(wall_entry));
  127.  
  128.    floortex[tex_list_num].num_image=num_straight_tex;
  129.    floortex[tex_list_num].images=(Byte **)NewPtr(num_straight_tex * sizeof(Byte *));
  130.  
  131.    for (counter=0; counter < num_straight_tex; counter++) {
  132.       F_Get_String_NT(filename, 13);
  133.       texturetemp.assigninfile(filename);
  134.       texturetemp.load(counter);
  135.       Flip_Vert_BMP(texturetemp.Image(counter), texturetemp.Width(), texturetemp.Height());
  136.       floortex[tex_list_num].images[counter]=texturetemp.Image(counter);
  137.    } /* endfor */
  138.  
  139.    for (counter=0; counter < (Number_Of_FTs-2); counter++) {
  140.       floortex[counter].cur_image=0;
  141.       floortex[counter].anim_sum=0;
  142.       F_Get_Short(floortex[counter].num_image);
  143.       F_Get_Long(floortex[counter].anim_speed);
  144.       floortex[counter].width=FLOOR_WIDTH;
  145.       floortex[counter].height=FLOOR_HEIGHT;
  146.       floortex[counter].shift=FLOOR_SHIFT;
  147.       floortex[counter].images=(Byte **)NewPtr(floortex[counter].num_image * sizeof(Byte *));
  148.       for (counter2=0; counter2 < floortex[counter].num_image; counter2++) {
  149.          F_Get_Short(next_image_num);
  150.          floortex[counter].images[counter2]=floortex[tex_list_num].images[next_image_num];
  151.       } /* endfor */
  152.    } /* endfor */
  153.  
  154.    F_Get_Sky();
  155.  
  156. }
  157.  
  158. void Flip_Vert_BMP(PUCHAR source_image, USHORT width, USHORT height)
  159. {
  160. USHORT rev_y, norm_y, x;
  161. PUCHAR dest_image;
  162.  
  163. if ((dest_image=NewPtr(width*height*sizeof(UCHAR)))==NULL)
  164.   return;
  165.  
  166. rev_y=height-1;
  167. for (norm_y=0; norm_y<height; norm_y++) {
  168.   for (x=0; x<width; x++) {
  169.     dest_image[norm_y*width+x]=source_image[rev_y*width+x];
  170.   }
  171.   rev_y--;
  172. }
  173.  
  174. memcpy(source_image, dest_image, width * height * sizeof(UCHAR));
  175. DelPtr( dest_image);
  176. }
  177.  
  178. void F_Clear_FT()
  179. {
  180.  
  181.    short counter1;
  182.  
  183.    for (counter1=0; counter1 < floortex[Number_Of_FTs-1].num_image; counter1++) {
  184.       delete floortex[Number_Of_FTs-1].images[counter1];
  185.    }
  186.  
  187.    F_Clear_Sky();
  188.  
  189.    for (counter1=0; counter1< (Number_Of_FTs); counter1++) {
  190.       if (floortex[counter1].images!=NULL)
  191.       DelPtr( floortex[counter1].images);
  192.    } /* endfor */
  193.  
  194.    DelPtr( floortex);
  195.  
  196. }
  197.  
  198. void F_Get_Sky()
  199. {
  200.    short dir_index=F_Find_Dir("SKYTEX  ");
  201.    if (dir_index==-1)
  202.       return;
  203.    F_Seek(directory[dir_index].start);
  204.  
  205.    sky_texture=&floortex[Number_Of_FTs-2];
  206.  
  207.    sky_texture->cur_image=0;
  208.    sky_texture->anim_sum=0;
  209.  
  210.    F_Get_Short(sky_texture->num_image);
  211.    F_Get_Long(sky_texture->anim_speed);
  212.    sky_texture->width=SKY_WIDTH;
  213.    sky_texture->height=SKY_HEIGHT;
  214.    sky_texture->shift=SKY_SHIFT;
  215.  
  216.    char filename[13];
  217.    RCastGobject sky_temp(sky_texture->num_image);
  218.    sky_temp.Hold();
  219.    sky_texture->images=(Byte **)NewPtr(sky_texture->num_image * sizeof(Byte *));
  220.    for (short cur_tex=0; cur_tex<sky_texture->num_image; cur_tex++) {
  221.       F_Get_String_NT(filename, 13);
  222.       sky_temp.assigninfile(filename);
  223.       sky_temp.load(cur_tex);
  224.       FlipBMP(sky_temp.Image(cur_tex), sky_temp.Width(), sky_temp.Height());
  225.       sky_texture->images[cur_tex]=sky_temp.Image(cur_tex);
  226.    }
  227. }
  228.  
  229. void F_Clear_Sky()
  230. {
  231.    for (short cur_tex=0; cur_tex<sky_texture->num_image; cur_tex++)
  232.       delete sky_texture->images[cur_tex];
  233.  
  234. }
  235.  
  236.  
  237.