home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / gm.c < prev    next >
C/C++ Source or Header  |  1998-06-08  |  19KB  |  612 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/gamemine.c $
  15.  * $Revision: 1.45 $
  16.  * $Author: john $
  17.  * $Date: 1994/10/27 18:51:42 $
  18.  * 
  19.  * Functions for loading mines in the game
  20.  * 
  21.  * $Log: gamemine.c $
  22.  * Revision 1.45  1994/10/27  18:51:42  john
  23.  * Added -piglet option that only loads needed textures for a 
  24.  * mine.  Only saved ~1MB, and code still doesn't free textures
  25.  * before you load a new mine.
  26.  * 
  27.  * Revision 1.44  1994/10/20  12:47:22  matt
  28.  * Replace old save files (MIN/SAV/HOT) with new LVL files
  29.  * 
  30.  * Revision 1.43  1994/10/19  16:46:40  matt
  31.  * Made tmap overrides for robots remap texture numbers
  32.  * 
  33.  * Revision 1.42  1994/10/03  23:37:01  mike
  34.  * Adapt to changed fuelcen_activate parameters.
  35.  * 
  36.  * Revision 1.41  1994/09/23  22:14:49  matt
  37.  * Took out obsolete structure fields
  38.  * 
  39.  * Revision 1.40  1994/08/01  11:04:11  yuan
  40.  * New materialization centers.
  41.  * 
  42.  * Revision 1.39  1994/07/21  19:01:47  mike
  43.  * Call Lsegment stuff.
  44.  * 
  45.  * 
  46.  */
  47.  
  48. #pragma off (unreferenced)
  49. static char rcsid[] = "$Id: gamemine.c 1.45 1994/10/27 18:51:42 john Exp $";
  50. #pragma on (unreferenced)
  51.  
  52. #include <stdio.h>
  53. #include <stdlib.h>
  54. #include <math.h>
  55. #include <string.h>
  56.  
  57. #include "mono.h"
  58.  
  59. #include "inferno.h"
  60. #include "segment.h"
  61. #include "textures.h"
  62. #include "wall.h"
  63. #include "object.h"
  64. #include "gamemine.h"
  65. #include "error.h"
  66. #include "gameseg.h"
  67. #include "switch.h"
  68.  
  69. #include "game.h"
  70.  
  71. #ifdef EDITOR
  72. #include "editor\editor.h"
  73. #include "ui.h"
  74. #endif
  75.  
  76. #include "nocfile.h"        
  77. #include "fuelcen.h"
  78.  
  79. #include "hash.h"
  80. #include "key.h"
  81. #include "piggy.h"
  82.  
  83. //Structures for old mine versions 
  84.  
  85. #define    V15_MAX_VERTICES_PER_SEGMENT    8
  86. #define    V15_MAX_SIDES_PER_SEGMENT        6
  87.  
  88. typedef struct v15_side {
  89.     byte        type;                                    // replaces num_faces and tri_edge, 1 = quad, 2 = 0:2 triangulation, 3 = 1:3 triangulation
  90.     short        tmap_num;
  91.     short        tmap_num2;
  92.     uvl        uvls[4];
  93.     short        wall_num;
  94.     vms_vector    normals[2];                        // 2 normals, if quadrilateral, both the same.
  95. } v15_side;
  96.  
  97. typedef struct v15_segment {
  98.     short        segnum;                                // segment number, not sure what it means
  99.     v15_side    sides[V15_MAX_SIDES_PER_SEGMENT];    // 6 sides
  100.     short        children[V15_MAX_SIDES_PER_SEGMENT];    // indices of 6 children segments, front, left, top, right, bottom, back
  101.     short        verts[V15_MAX_VERTICES_PER_SEGMENT];    // vertex ids of 4 front and 4 back vertices
  102.     short        group;                                // group number to which the segment belongs.
  103.     short        objects;                                // pointer to objects in this segment
  104.     short        special;                                // special property of a segment (such as damaging, trigger, etc.)
  105.     short        value;
  106. } v15_segment;
  107.  
  108. typedef struct {
  109.     int        num_segments;
  110.     int        num_vertices;
  111.     short        segments[MAX_SEGMENTS];
  112.     short        vertices[MAX_VERTICES];
  113. } v15_group;
  114.  
  115. //End of old structures
  116.  
  117. #define REMOVE_EXT(s)  (*(strchr( (s), '.' ))='\0')
  118.  
  119. struct mtfi mine_top_fileinfo;    // Should be same as first two fields below...
  120. struct mfi mine_fileinfo;
  121. struct mh mine_header;
  122. struct me mine_editor;
  123.  
  124. int CreateDefaultNewSegment();
  125.  
  126. static char old_tmap_list[MAX_TEXTURES][13];
  127. short tmap_xlate_table[MAX_TEXTURES];
  128.  
  129. static short tmap_times_used[MAX_TEXTURES];
  130.  
  131. //void JohnError( char * s )
  132. //{
  133. //    Int3();
  134. //}
  135.  
  136.  
  137. // -----------------------------------------------------------------------------
  138. // returns 1 if error, else 0
  139. int game_load_mine(char * filename)
  140. {
  141.     CFILE * LoadFile;
  142.  
  143.     LoadFile = cfopen( filename, CF_READ_MODE );
  144.     if (!LoadFile)
  145.     {
  146.         #ifdef EDITOR
  147.         char  ErrorMessage[200];
  148.  
  149.         sprintf( ErrorMessage, "ERROR: Unable to open mine %s\n", filename );
  150.         stop_time();
  151.         MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
  152.         start_time();
  153.         #endif
  154.  
  155.         return 1;
  156.     }
  157.  
  158.     load_mine_data(LoadFile);
  159.  
  160.     cfclose( LoadFile );
  161.  
  162.     return 0;
  163. }
  164.  
  165.  
  166. // -----------------------------------------------------------------------------
  167. //loads from an already-open file
  168. // returns 0=everything ok, 1=old version, -1=error
  169. int load_mine_data(CFILE *LoadFile)
  170. {
  171.     int   i, j;
  172.     short tmap_xlate;
  173.     int     translate;
  174.     char     *temptr;
  175.     int    mine_start = cftell(LoadFile);
  176.  
  177.     fuelcen_reset();
  178.  
  179.     for (i=0; i<MAX_TEXTURES; i++ )
  180.         tmap_times_used[i] = 0;
  181.     
  182.     #ifdef EDITOR
  183.     // Create a new mine to initialize things.
  184.     //texpage_goto_first();
  185.     create_new_mine();
  186.     #endif
  187.  
  188.     //===================== READ FILE INFO ========================
  189.  
  190.     // These are the default values... version and fileinfo_sizeof
  191.     // don't have defaults.
  192.     mine_fileinfo.header_offset     =   -1;
  193.     mine_fileinfo.header_size       =   sizeof(mine_header);
  194.     mine_fileinfo.editor_offset     =   -1;
  195.     mine_fileinfo.editor_size       =   sizeof(mine_editor);
  196.     mine_fileinfo.vertex_offset     =   -1;
  197.     mine_fileinfo.vertex_howmany    =   0;
  198.     mine_fileinfo.vertex_sizeof     =   sizeof(vms_vector);
  199.     mine_fileinfo.segment_offset    =   -1;
  200.     mine_fileinfo.segment_howmany   =   0;
  201.     mine_fileinfo.segment_sizeof    =   sizeof(segment);
  202.     mine_fileinfo.newseg_verts_offset     =   -1;
  203.     mine_fileinfo.newseg_verts_howmany    =   0;
  204.     mine_fileinfo.newseg_verts_sizeof     =   sizeof(vms_vector);
  205.     mine_fileinfo.group_offset          =    -1;
  206.     mine_fileinfo.group_howmany      =    0;
  207.     mine_fileinfo.group_sizeof          =    sizeof(group);
  208.     mine_fileinfo.texture_offset    =   -1;
  209.     mine_fileinfo.texture_howmany   =   0;
  210.     mine_fileinfo.texture_sizeof    =   13;  // num characters in a name
  211.      mine_fileinfo.walls_offset          =    -1;
  212.     mine_fileinfo.walls_howmany      =    0;
  213.     mine_fileinfo.walls_sizeof          =    sizeof(wall);  
  214.      mine_fileinfo.triggers_offset      =    -1;
  215.     mine_fileinfo.triggers_howmany  =    0;
  216.     mine_fileinfo.triggers_sizeof      =    sizeof(trigger);  
  217.     mine_fileinfo.object_offset        =    -1;
  218.     mine_fileinfo.object_howmany        =    1;
  219.     mine_fileinfo.object_sizeof        =    sizeof(object);  
  220.  
  221.     // Read in mine_top_fileinfo to get size of saved fileinfo.
  222.     
  223.     memset( &mine_top_fileinfo, 0, sizeof(mine_top_fileinfo) );
  224.  
  225.     if (cfseek( LoadFile, mine_start, SEEK_SET ))
  226.         Error( "Error moving to top of file in gamemine.c" );
  227.  
  228.     if (cfread( &mine_top_fileinfo, sizeof(mine_top_fileinfo), 1, LoadFile )!=1)
  229.         Error( "Error reading mine_top_fileinfo in gamemine.c" );
  230.  
  231.     if (mine_top_fileinfo.fileinfo_signature != 0x2884)
  232.         return -1;
  233.  
  234.     // Check version number
  235.     if (mine_top_fileinfo.fileinfo_version < COMPATIBLE_VERSION )
  236.         return -1;
  237.  
  238.     // Now, Read in the fileinfo
  239.     if (cfseek( LoadFile, mine_start, SEEK_SET ))
  240.         Error( "Error seeking to top of file in gamemine.c" );
  241.  
  242.     if (cfread( &mine_fileinfo, mine_top_fileinfo.fileinfo_sizeof, 1, LoadFile )!=1)
  243.         Error( "Error reading mine_fileinfo in gamemine.c" );
  244.  
  245.     //===================== READ HEADER INFO ========================
  246.  
  247.     // Set default values.
  248.     mine_header.num_vertices        =   0;
  249.     mine_header.num_segments        =   0;
  250.  
  251.     if (mine_fileinfo.header_offset > -1 )
  252.     {
  253.         if (cfseek( LoadFile, mine_fileinfo.header_offset, SEEK_SET ))
  254.             Error( "Error seeking to header_offset in gamemine.c" );
  255.     
  256.         if (cfread( &mine_header, mine_fileinfo.header_size, 1, LoadFile )!=1)
  257.             Error( "Error reading mine_header in gamemine.c" );
  258.     }
  259.  
  260.     //===================== READ EDITOR INFO ==========================
  261.  
  262.     // Set default values
  263.     mine_editor.current_seg         =   0;
  264.     mine_editor.newsegment_offset   =   -1; // To be written
  265.     mine_editor.newsegment_size     =   sizeof(segment);
  266.     mine_editor.Curside             =   0;
  267.     mine_editor.Markedsegp          =   -1;
  268.     mine_editor.Markedside          =   0;
  269.  
  270.     if (mine_fileinfo.editor_offset > -1 )
  271.     {
  272.         if (cfseek( LoadFile, mine_fileinfo.editor_offset, SEEK_SET ))
  273.             Error( "Error seeking to editor_offset in gamemine.c" );
  274.     
  275.         if (cfread( &mine_editor, mine_fileinfo.editor_size, 1, LoadFile )!=1)
  276.             Error( "Error reading mine_editor in gamemine.c" );
  277.     }
  278.  
  279.     //===================== READ TEXTURE INFO ==========================
  280.  
  281.     if ( (mine_fileinfo.texture_offset > -1) && (mine_fileinfo.texture_howmany > 0))
  282.     {
  283.         if (cfseek( LoadFile, mine_fileinfo.texture_offset, SEEK_SET ))
  284.             Error( "Error seeking to texture_offset in gamemine.c" );
  285.  
  286.         for (i=0; i< mine_fileinfo.texture_howmany; i++ )
  287.         {
  288.             if (cfread( &old_tmap_list[i], mine_fileinfo.texture_sizeof, 1, LoadFile )!=1)
  289.                 Error( "Error reading old_tmap_list[i] in gamemine.c" );
  290.         }
  291.     }
  292.  
  293.     //=============== GENERATE TEXTURE TRANSLATION TABLE ===============
  294.  
  295.     translate = 0;
  296.     
  297.     Assert (NumTextures < MAX_TEXTURES);
  298.  
  299.     {
  300.         hashtable ht;
  301.     
  302.         hashtable_init( &ht, NumTextures );
  303.     
  304.         // Remove all the file extensions in the textures list
  305.     
  306.         for (i=0;i<NumTextures;i++)    {
  307.             temptr = strchr(TmapInfo[i].filename, '.');
  308.             if (temptr) *temptr = '\0';
  309.             hashtable_insert( &ht, TmapInfo[i].filename, i );
  310.         }
  311.     
  312.         // For every texture, search through the texture list
  313.         // to find a matching name.
  314.         for (j=0;j<mine_fileinfo.texture_howmany;j++)     {
  315.             // Remove this texture name's extension
  316.             temptr = strchr(old_tmap_list[j], '.');
  317.             if (temptr) *temptr = '\0';
  318.     
  319.             tmap_xlate_table[j] = hashtable_search( &ht,old_tmap_list[j]);
  320.             if (tmap_xlate_table[j]    < 0 )    {
  321.                 tmap_xlate_table[j] = 0;
  322.                 mprintf( 0, "Couldn't find texture '%s'\n", old_tmap_list[j] );
  323.             }
  324.             if (tmap_xlate_table[j] != j ) translate = 1;
  325.             tmap_times_used[tmap_xlate_table[j]]++;
  326.         }
  327.     
  328.         {
  329.             int count = 0;
  330.             for (i=0; i<MAX_TEXTURES; i++ )
  331.                 if (tmap_times_used[i])
  332.                     count++;
  333.             mprintf( 0, "This mine has %d unique textures in it (~%.2f MB)\n", count, ((float)(count*4096))/(1024.0*1024.0) );
  334.         }
  335.     
  336.         mprintf( 0, "Translate=%d\n", translate );
  337.     
  338.         hashtable_free( &ht );
  339.     }
  340.  
  341.     //====================== READ VERTEX INFO ==========================
  342.  
  343.     // New check added to make sure we don't read in too many vertices.
  344.     if ( mine_fileinfo.vertex_howmany > MAX_VERTICES )
  345.         {
  346.         mprintf(0, "Num vertices exceeds maximum.  Loading MAX %d vertices\n", MAX_VERTICES);
  347.         mine_fileinfo.vertex_howmany = MAX_VERTICES;
  348.         }
  349.  
  350.     if ( (mine_fileinfo.vertex_offset > -1) && (mine_fileinfo.vertex_howmany > 0))
  351.     {
  352.         if (cfseek( LoadFile, mine_fileinfo.vertex_offset, SEEK_SET ))
  353.             Error( "Error seeking to vertex_offset in gamemine.c" );
  354.  
  355.         for (i=0; i< mine_fileinfo.vertex_howmany; i++ )
  356.         {
  357.             // Set the default values for this vertex
  358.             Vertices[i].x = 1;
  359.             Vertices[i].y = 1;
  360.             Vertices[i].z = 1;
  361.  
  362.             if (cfread( &Vertices[i], mine_fileinfo.vertex_sizeof, 1, LoadFile )!=1)
  363.                 Error( "Error reading Vertices[i] in gamemine.c" );
  364.         }
  365.     }
  366.  
  367.     //==================== READ SEGMENT INFO ===========================
  368.  
  369.     // New check added to make sure we don't read in too many segments.
  370.     if ( mine_fileinfo.segment_howmany > MAX_SEGMENTS ) {
  371.         mprintf(0, "Num segments exceeds maximum.  Loading MAX %d segments\n", MAX_SEGMENTS);
  372.         mine_fileinfo.segment_howmany = MAX_SEGMENTS;
  373.     }
  374.  
  375.     fuelcen_reset();
  376.  
  377.     if ( (mine_fileinfo.segment_offset > -1) && (mine_fileinfo.segment_howmany > 0))    {
  378.  
  379.         if (cfseek( LoadFile, mine_fileinfo.segment_offset,SEEK_SET ))
  380.  
  381.             Error( "Error seeking to segment_offset in gamemine.c" );
  382.  
  383.         for (i=0; i< mine_fileinfo.segment_howmany; i++ ) {
  384.             segment v16_seg;
  385.             v15_segment v15_seg;
  386.  
  387.             // Set the default values for this segment (clear to zero )
  388.             //memset( &Segments[i], 0, sizeof(segment) );
  389.  
  390.             if (mine_top_fileinfo.fileinfo_version >= 16) {
  391.  
  392.                 Assert(mine_fileinfo.segment_sizeof == sizeof(v16_seg));
  393.  
  394.                 if (cfread( &v16_seg, mine_fileinfo.segment_sizeof, 1, LoadFile )!=1)
  395.                     Error( "Error reading segments in gamemine.c" );
  396.  
  397.             }                
  398.             else if (mine_top_fileinfo.fileinfo_version < 16) {
  399.                 int t;
  400.  
  401.                 Assert(mine_fileinfo.segment_sizeof == sizeof(v15_seg));
  402.  
  403.                 if (cfread( &v15_seg, mine_fileinfo.segment_sizeof, 1, LoadFile )!=1)
  404.                     Error( "Error reading segments in gamemine.c" );
  405.  
  406.                 v16_seg.segnum  = v15_seg.segnum;
  407.                 v16_seg.group   = v15_seg.group;
  408.                 v16_seg.objects = v15_seg.objects;
  409.                 v16_seg.special = v15_seg.special;
  410.                 v16_seg.value   = v15_seg.value;
  411.                 
  412.                 for (t=0;t<MAX_SIDES_PER_SEGMENT;t++) {
  413.                     int n;
  414.  
  415.                     v16_seg.children[t] = v15_seg.children[t];
  416.  
  417.                     v16_seg.sides[t].type        = v15_seg.sides[t].type;
  418.                     v16_seg.sides[t].wall_num    = v15_seg.sides[t].wall_num;
  419.                     v16_seg.sides[t].tmap_num    = v15_seg.sides[t].tmap_num;
  420.                     v16_seg.sides[t].tmap_num2    = v15_seg.sides[t].tmap_num2;
  421.                     v16_seg.sides[t].pad            = 0;
  422.  
  423.                     for (n=0;n<4;n++)
  424.                         v16_seg.sides[t].uvls[n] = v15_seg.sides[t].uvls[n];
  425.  
  426.                     for (n=0;n<2;n++)
  427.                         v16_seg.sides[t].normals[n] = v15_seg.sides[t].normals[n];
  428.  
  429.                 }
  430.                 
  431.                 for (t=0;t<MAX_VERTICES_PER_SEGMENT;t++)
  432.                     v16_seg.verts[t]    = v15_seg.verts[t];
  433.  
  434.                 v16_seg.static_light = 0;
  435.  
  436.             }
  437.  
  438.             Segments[i] = v16_seg;
  439.  
  440.             Segments[i].objects = -1;
  441.             Segments[i].group = -1;
  442.  
  443.             if (mine_top_fileinfo.fileinfo_version < 15) {    //used old uvl ranges
  444.                 int sn,uvln;
  445.  
  446.                 for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++)
  447.                     for (uvln=0;uvln<4;uvln++) {
  448.                         Segments[i].sides[sn].uvls[uvln].u /= 64;
  449.                         Segments[i].sides[sn].uvls[uvln].v /= 64;
  450.                         Segments[i].sides[sn].uvls[uvln].l /= 32;
  451.                     }
  452.             }
  453.  
  454.             fuelcen_activate( &Segments[i], Segments[i].special );
  455.  
  456.             if (translate == 1)
  457.                 for (j=0;j<MAX_SIDES_PER_SEGMENT;j++) {
  458.                     unsigned short orient;
  459.                     tmap_xlate = Segments[i].sides[j].tmap_num;
  460.                     Segments[i].sides[j].tmap_num = tmap_xlate_table[tmap_xlate];
  461.                     tmap_xlate = Segments[i].sides[j].tmap_num2 & 0x3FFF;
  462.                     orient = Segments[i].sides[j].tmap_num2 & (~0x3FFF);
  463.                     if (tmap_xlate != 0)
  464.                         Segments[i].sides[j].tmap_num2 = tmap_xlate_table[tmap_xlate] | orient;
  465.                 }
  466.         }
  467.     }
  468.  
  469.     //===================== READ NEWSEGMENT INFO =====================
  470.  
  471.     #ifdef EDITOR
  472.  
  473.     {        // Default segment created.
  474.         vms_vector    sizevec;
  475.         med_create_new_segment(vm_vec_make(&sizevec,DEFAULT_X_SIZE,DEFAULT_Y_SIZE,DEFAULT_Z_SIZE));        // New_segment = Segments[0];
  476.         //memset( &New_segment, 0, sizeof(segment) );
  477.     }
  478.  
  479.     if (mine_editor.newsegment_offset > -1)
  480.     {
  481.         if (cfseek( LoadFile, mine_editor.newsegment_offset,SEEK_SET ))
  482.             Error( "Error seeking to newsegment_offset in gamemine.c" );
  483.         if (cfread( &New_segment, mine_editor.newsegment_size,1,LoadFile )!=1)
  484.             Error( "Error reading new_segment in gamemine.c" );
  485.     }
  486.  
  487.     if ( (mine_fileinfo.newseg_verts_offset > -1) && (mine_fileinfo.newseg_verts_howmany > 0))
  488.     {
  489.         if (cfseek( LoadFile, mine_fileinfo.newseg_verts_offset, SEEK_SET ))
  490.             Error( "Error seeking to newseg_verts_offset in gamemine.c" );
  491.         for (i=0; i< mine_fileinfo.newseg_verts_howmany; i++ )
  492.         {
  493.             // Set the default values for this vertex
  494.             Vertices[NEW_SEGMENT_VERTICES+i].x = 1;
  495.             Vertices[NEW_SEGMENT_VERTICES+i].y = 1;
  496.             Vertices[NEW_SEGMENT_VERTICES+i].z = 1;
  497.             
  498.             if (cfread( &Vertices[NEW_SEGMENT_VERTICES+i], mine_fileinfo.newseg_verts_sizeof,1,LoadFile )!=1)
  499.                 Error( "Error reading Vertices[NEW_SEGMENT_VERTICES+i] in gamemine.c" );
  500.  
  501.             New_segment.verts[i] = NEW_SEGMENT_VERTICES+i;
  502.         }
  503.     }
  504.  
  505.     #endif
  506.                                                             
  507.     //========================= UPDATE VARIABLES ======================
  508.  
  509.     #ifdef EDITOR
  510.  
  511.     // Setting to Markedsegp to NULL ignores Curside and Markedside, which
  512.     // we want to do when reading in an old file.
  513.     
  514.      Markedside = mine_editor.Markedside;
  515.     Curside = mine_editor.Curside;
  516.     for (i=0;i<10;i++)
  517.         Groupside[i] = mine_editor.Groupside[i];
  518.  
  519.     if ( mine_editor.current_seg != -1 )
  520.         Cursegp = mine_editor.current_seg + Segments;
  521.     else
  522.          Cursegp = NULL;
  523.  
  524.     if (mine_editor.Markedsegp != -1 ) 
  525.         Markedsegp = mine_editor.Markedsegp + Segments;
  526.     else
  527.         Markedsegp = NULL;
  528.  
  529.     num_groups = 0;
  530.     current_group = -1;
  531.  
  532.     #endif
  533.  
  534.     Num_vertices = mine_fileinfo.vertex_howmany;
  535.     Num_segments = mine_fileinfo.segment_howmany;
  536.     Highest_vertex_index = Num_vertices-1;
  537.     Highest_segment_index = Num_segments-1;
  538.  
  539.     reset_objects(1);        //one object, the player
  540.  
  541.     #ifdef EDITOR
  542.     Highest_vertex_index = MAX_SEGMENT_VERTICES-1;
  543.     Highest_segment_index = MAX_SEGMENTS-1;
  544.     set_vertex_counts();
  545.     Highest_vertex_index = Num_vertices-1;
  546.     Highest_segment_index = Num_segments-1;
  547.  
  548.     warn_if_concave_segments();
  549.     #endif
  550.  
  551.     #ifdef EDITOR
  552.         med_validate_segment_all();
  553.     #endif
  554.  
  555.     create_local_segment_data();
  556.  
  557.     gamemine_find_textures();
  558.  
  559.     if (mine_top_fileinfo.fileinfo_version < MINE_VERSION )
  560.         return 1;        //old version
  561.     else
  562.         return 0;
  563.  
  564. }
  565.  
  566. ubyte texcount[MAX_TEXTURES];
  567.  
  568. void gamemine_find_textures()
  569. {
  570.     int s, sn;
  571.     int unique = 0;
  572.  
  573.     memset( texcount, 0, MAX_TEXTURES );
  574.  
  575.     for (s=0; s<=Highest_segment_index; s++)    {
  576.         if (Segments[s].segnum != -1) {
  577.             for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) {
  578.                 //if (Segments[s].sides[sn].wall_num > -1 ) {
  579.                 // mprintf( 0, "Segment %d, side %d has wall_num %d\n", s, sn, Segments[s].sides[sn].wall_num );
  580.                 //}
  581.                 if (Segments[s].sides[sn].tmap_num>-1) {
  582.                     //mprintf( 0, "Segment %d, side %d has tmap_num %d\n", s, sn, Segments[s].sides[sn].tmap_num );
  583.                     if (!texcount[Segments[s].sides[sn].tmap_num])    {
  584.                         piggy_read_bitmap_data(Textures[Segments[s].sides[sn].tmap_num]);
  585.                         unique++;
  586.                     }
  587.                     texcount[Segments[s].sides[sn].tmap_num]++;
  588.                 }
  589.                 if ((Segments[s].sides[sn].tmap_num2 & 0x3FFF)>0) {
  590.                     //mprintf( 0, "Segment %d, side %d has tmap_num2 %d\n", s, sn, Segments[s].sides[sn].tmap_num2 & 0x3FFF );
  591.                     if (!texcount[Segments[s].sides[sn].tmap_num2&0x3FFF])    {
  592.                         piggy_read_bitmap_data(Textures[Segments[s].sides[sn].tmap_num2&0x3FFF]);
  593.                         unique++;
  594.                     }
  595.                     texcount[Segments[s].sides[sn].tmap_num2&0x3FFF]++;
  596.                 }
  597.  
  598.             }
  599.         }
  600.     }    
  601.     //mprintf( 0, "Mine used %d textures\n", unique );
  602. }
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.