Ejemplo n.º 1
0
//---------- Begin of function void ResourceIdx::init ---------//
//!
//! <char*> resName		= name of the resource file (e.g. "GIF.RES")
//! <int>   readAll		= whether read all data into the buffer or read one each time
//!									(default:0)
//! [int]   useCommonBuf = whether use the common buffer to store the data or not
//!									(default:0)
//!
void ResourceIdx::init(char* resName, int readAll, int useCommonBuf) {
    long dataSize;

    if( init_flag )                                 // if a resource is already opened, close it first
	deinit();

    //------------- open resource file ----------//

    file_open( resName );

    //------------ Init vars ---------------------//

    read_all      = readAll;
    use_common_buf   = useCommonBuf;
    data_buf      = NULL;
    data_buf_size = 0;

    rec_count     = file_get_short();
    cur_rec_no    = -1;

    user_data_buf       = NULL;
    user_data_buf_size  = 0;
    user_start_read_pos = 0;

    //---------- Read in record index -------------//

    index_buf = (ResIndex*) mem_add( (rec_count+1) * sizeof(ResIndex) );

    // rec_count+1 is the last index pointer for calculating last record size

    file_read( index_buf, sizeof(ResIndex) * (rec_count+1) );

    //---------- Read in record data -------------//

    if( read_all ) {
	dataSize = index_buf[rec_count].pointer - index_buf[0].pointer;

	data_buf = mem_add( dataSize );

	file_read( data_buf, dataSize );
	file_close();
    }
    else {
	if( use_common_buf )
	    data_buf = sys.common_data_buf;
    }

    init_flag = 1;
}
Ejemplo n.º 2
0
Archivo: ores.cpp Proyecto: 112212/7k2
//---------- Begin of function Resource::init ----------//
//
// <char*> resName   = name of the resource file (e.g. "GIF.RES")
// <int>   readAll   = whether read all data into the buffer or read one each time
// [int]   useCommonBuf = whether use the common buffer to store the data or not
//                     (default:0)
//
void Resource::init(char* resName, int readAll, int useCommonBuf)
{
   if( init_flag )
      deinit();

   //-------------------------------------------//

   long dataSize;

   file_open(resName);

   read_all      = readAll;
   use_common_buf   = useCommonBuf;
   data_buf      = NULL;
   data_buf_size = 0 ;

   rec_count  = file_get_short();
   cur_rec_no = -1;

   //---------- Read in record index -------------//

   index_buf = (uint32_t*) mem_add( (rec_count+1) * sizeof(uint32_t) );

   // rec_count+1 is the last index pointer for calculating last record size

   file_read( index_buf, sizeof(uint32_t) * (rec_count+1) );

   //---------- Read in record data -------------//

   if( read_all )
   {
      dataSize = index_buf[rec_count] - index_buf[0];

      data_buf = mem_add( dataSize );
      file_read( data_buf, dataSize );

      file_close();
   }
   else
   {
      if( use_common_buf )
         data_buf = sys.common_data_buf;
   }

   init_flag = 1;
}