Example #1
0
static bool readSurfaces( const char *filename, std::vector< RenderSurface > &surfaces )
{
	uint64_t hashedName = HashedString( 0, filename );
	char outfile[256];
	PHYSFS_mkdir( "static_models/" );
	sprintf( outfile, "static_models/%08x_%08x.sm", (uint32_t)(hashedName>>32), (uint32_t)(hashedName&0xffffffff) );
	PHYSFS_File *model = PHYSFS_openRead( outfile );
	if ( model )
	{
		unsigned int ver, numSurf;
		PHYSFS_readULE32( model, &ver );
		PHYSFS_readULE32( model, &numSurf );
		surfaces.resize( numSurf );
		for ( uint32_t i=0; i<surfaces.size(); i++ )
		{
			RenderSurface &surf = surfaces[i];
			PHYSFS_readCStr( model, surf.name );
			std::string mat;
			PHYSFS_readCStr( model, mat );
			surf.mat = materialManager()->Load( mat.c_str() );

			ModelGeometry *geom = new ModelGeometry;
			surf.geom = geom;
			PHYSFS_readSLE32( model, &geom->m_numIndices );
			PHYSFS_readSLE32( model, &geom->m_numVerts );
			geom->m_indices = new unsigned short[geom->m_numIndices];
			geom->m_verts = new ModelVert[geom->m_numVerts];
			PHYSFS_read( model, geom->m_indices, sizeof(uint16_t)*geom->m_numIndices, 1 );
			PHYSFS_read( model, geom->m_verts, sizeof(geom->m_verts[0])*geom->m_numVerts, 1 );
		}
		PHYSFS_close( model );
		return true;
	}
	return false;
}
Uint32 ReadFile::readULE32()
{
    Uint32 val;
    if(!PHYSFS_readULE32(file, &val))
        throw Exception("read error: %s", PHYSFS_getLastError());
    return val;
}
static inline uint32_t read32LE(PHYSFS_file* file)
{
  uint32_t result;
  if(PHYSFS_readULE32(file, &result) == 0)
    throw SoundError("file too short");

  return result;
}
Example #4
0
uint32 FileStream::getU32()
{
    uint32 v = 0;
    if(!m_caching) {
        if(PHYSFS_readULE32(m_fileHandle, &v) == 0)
            throwError("read failed", true);
    } else {
        if(m_pos+4 > m_data.size())
            throwError("read failed");

        v = stdext::readLE32(&m_data[m_pos]);
        m_pos += 4;
    }
    return v;
}
Example #5
0
uint32_t FileRead::readUInt32()
{
	check_file_open();

	if ( length() - tell() < 4)
	{
		BOOST_THROW_EXCEPTION( EOFException(mFileName) );
	}

	PHYSFS_uint32 ret;
	if(!PHYSFS_readULE32( reinterpret_cast<PHYSFS_file*>(mHandle),	&ret))
	{
		BOOST_THROW_EXCEPTION( PhysfsFileException(mFileName) );
	}

	return ret;
}