@@ -299,27 +299,16 @@ void CDriverLevelLoader::Release()
299299// -------------------------------------------------------------
300300// Loads the LEV file data
301301// -------------------------------------------------------------
302- bool CDriverLevelLoader::LoadFromFile ( const char * fileName )
302+ bool CDriverLevelLoader::Load (IVirtualStream* pStream )
303303{
304- // try load driver2 lev file
305- FILE* pReadFile = fopen (fileName, " rb" );
306-
307- if (!pReadFile)
308- {
309- MsgError (" Failed to open LEV file!\n " );
304+ if (!pStream)
310305 return false ;
311- }
312-
313- CFileStream stream (pReadFile);
314-
315- // seek to begin
316- MsgWarning (" -----------\n Loading LEV file '%s'\n " , fileName);
317306
318307 // -------------------------------------------------------------------
319308
320309 // perform auto-detection if format is not specified
321310 if (m_format == LEV_FORMAT_AUTODETECT)
322- m_format = DetectLevelFormat (&stream );
311+ m_format = DetectLevelFormat (pStream );
323312
324313 if (m_map)
325314 m_map->SetFormat (m_format);
@@ -328,17 +317,16 @@ bool CDriverLevelLoader::LoadFromFile(const char* fileName)
328317 m_textures->SetFormat (m_format);
329318
330319 LUMP curLump;
331- stream. Read (&curLump, sizeof (curLump), 1 );
320+ pStream-> Read (&curLump, sizeof (curLump), 1 );
332321
333322 if (curLump.type != LUMP_LUMPDESC)
334323 {
335324 MsgError (" Not a LEV file!\n " );
336- fclose (pReadFile);
337325 return false ;
338326 }
339327
340328 // read chunk offsets
341- stream. Read (m_lumpInfo, sizeof (OUT_CITYLUMP_INFO), 1 );
329+ pStream-> Read (m_lumpInfo, sizeof (OUT_CITYLUMP_INFO), 1 );
342330
343331 DevMsg (SPEW_NORM, " data1_offset = %d\n " , m_lumpInfo->loadtime_offset );
344332 DevMsg (SPEW_NORM, " data1_size = %d\n " , m_lumpInfo->loadtime_size );
@@ -356,53 +344,48 @@ bool CDriverLevelLoader::LoadFromFile(const char* fileName)
356344
357345 // -----------------------------------------------------
358346 // seek to section 1 - lump data 1
359- stream. Seek (m_lumpInfo->loadtime_offset , VS_SEEK_SET);
347+ pStream-> Seek (m_lumpInfo->loadtime_offset , VS_SEEK_SET);
360348
361349 // read lump
362- stream. Read (&curLump, sizeof (curLump), 1 );
350+ pStream-> Read (&curLump, sizeof (curLump), 1 );
363351
364352 if (curLump.type != LUMP_LOADTIME_DATA)
365353 {
366354 MsgError (" Not a LUMP_LOADTIME_DATA!\n " );
367- fclose (pReadFile);
368355 return false ;
369356 }
370357
371358 DevMsg (SPEW_INFO, " entering LUMP_LOADTIME_DATA size = %d\n --------------\n " , curLump.size );
372359
373360 // read sublumps
374- ProcessLumps (&stream );
361+ ProcessLumps (pStream );
375362
376363 // -----------------------------------------------------
377364 // read global textures
378365
379366 if (m_textures)
380367 {
381- stream. Seek (m_lumpInfo->tpage_offset , VS_SEEK_SET);
382- m_textures->LoadPermanentTPages (&stream );
368+ pStream-> Seek (m_lumpInfo->tpage_offset , VS_SEEK_SET);
369+ m_textures->LoadPermanentTPages (pStream );
383370 }
384371
385372 // -----------------------------------------------------
386373 // seek to section 3 - lump data 2
387- stream. Seek (m_lumpInfo->inmem_offset , VS_SEEK_SET);
374+ pStream-> Seek (m_lumpInfo->inmem_offset , VS_SEEK_SET);
388375
389376 // read lump
390- stream. Read (&curLump, sizeof (curLump), 1 );
377+ pStream-> Read (&curLump, sizeof (curLump), 1 );
391378
392379 if (curLump.type != LUMP_INMEMORY_DATA)
393380 {
394381 MsgError (" Not a lump LUMP_INMEMORY_DATA!\n " );
395- fclose (pReadFile);
396382 return false ;
397383 }
398384
399385 DevMsg (SPEW_INFO, " entering LUMP_INMEMORY_DATA size = %d\n --------------\n " , curLump.size );
400386
401387 // read sublumps
402- ProcessLumps (&stream);
403-
404- // completed!
405- fclose (pReadFile);
388+ ProcessLumps (pStream);
406389
407390 return true ;
408391}
0 commit comments