Ejemplo n.º 1
0
void CAL_SetupGrFile()
{
    char fname[13];
    bstone::FileStream handle;
    Uint8* compseg;

    //
    // load ???dict.ext (huffman dictionary for graphics files)
    //

    strcpy(fname, gdictname);
    strcat(fname, extension);

    handle.open(fname);

    if (!handle.is_open())
        CA_CannotOpen(fname);

    handle.read(&grhuffman, sizeof(grhuffman));

    //
    // load the data offsets from ???head.ext
    //
    int grstarts_size = (NUMCHUNKS + 1) * FILEPOSSIZE;

    grstarts = new Sint32[(grstarts_size + 3) / 4];

    strcpy(fname, gheadname);
    strcat(fname, extension);

    handle.open(fname);

    if (!handle.is_open())
        CA_CannotOpen(fname);

    handle.read(grstarts, grstarts_size);

    //
    // Open the graphics file, leaving it open until the game is finished
    //
    OpenGrFile();

    //
    // load the pic and sprite headers into the arrays in the data segment
    //
    pictable = new pictabletype[NUMPICS];
    CAL_GetGrChunkLength(STRUCTPIC);		// position file pointer
    compseg = new Uint8[chunkcomplen];
    grhandle.read(compseg, chunkcomplen);

    CAL_HuffExpand(
        compseg,
        (Uint8*)pictable,
        NUMPICS * sizeof(pictabletype),
        grhuffman);

    delete [] compseg;
}
Ejemplo n.º 2
0
/*
-----------------------------------------------------------------------------
 Function: CAL_SetupGrFile() -Initialize graphic files and arrays.
 
 Parameters: extension -[in] Pointer to a null-terminated string that 
                            specifies the file extension.
                            (must be in '.XXX' format).
 
 Returns: 1 on success, 0 otherwise.
 
 Notes: 
        Uses global variables grhandle and pictable.
        1. Open vgadict.XXX, read huffman dictionary data.
        2. Open vgahead.XXX, read data offsets.
        3. Open vgagraph.XXX, read pic and sprite header, expand data.
-----------------------------------------------------------------------------
*/
PRIVATE W8 CAL_SetupGrFile( const char *extension )
{
	void *compseg;
	FILE *handle;
	char filename[ 16 ];
	SW32 chunkcomplen; // chunk compressed length
	
//
// load vgadict.ext (huffman dictionary for graphics files)
//
	cs_strlcpy( filename, GFXDICTFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( ( handle = fopen( cs_strupr( filename ), "rb" ) ) ==  NULL )
	{
		if( ( handle = fopen( cs_strlwr( filename ), "rb" ) ) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
  
	fread( grhuffman, sizeof( grhuffman ), 1, handle );
	fclose( handle );
	
//
// Open then load the data offsets from vgahead.ext
//	
	
	cs_strlcpy( filename, GFXHEADFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( (handle = fopen( cs_strupr( filename ), "rb" )) ==  NULL )
	{
		if( (handle = fopen( cs_strlwr( filename ), "rb" )) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
	
	grstarts = MM_MALLOC( (NUMCHUNKS+1) * FILEPOSSIZE );
	if( grstarts == NULL )
	{
		return 0;
	}
  
	fread( grstarts, sizeof( long ), (NUMCHUNKS+1) * FILEPOSSIZE, handle );
	
	fclose( handle );
	
//
// Open the graphics file 'vgagraph.XXX'.
//
	
	cs_strlcpy( filename, GFXFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( ( grhandle = fopen( cs_strupr( filename ), "rb" ) ) ==  NULL )
	{
		if( ( grhandle = fopen( cs_strlwr( filename ), "rb" ) ) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
  
//
// load the pic and sprite headers into the arrays.
//
	pictable = MM_MALLOC( NUMPICS * sizeof( pictabletype ) );
	if( pictable == NULL )
	{
		return 0;
	}
  
  
	chunkcomplen = CAL_GetGrChunkLength( STRUCTPIC );  // position file pointer
	
	compseg = MM_MALLOC( chunkcomplen );
	if( compseg == NULL )
	{
		return 0;
	}
	
	fread( compseg, chunkcomplen, 1, grhandle );
	
	CAL_HuffExpand( compseg, (PW8)pictable, 
	                NUMPICS * sizeof( pictabletype ), 
                    grhuffman );

	MM_FREE( compseg ); 
 
    return 1;                 
}