MCPcopy Create free account
hub / github.com/ZDoom/Raze / loadMap

Function loadMap

source/core/maploader.cpp:469–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

467}
468
469void loadMap(const char* filename, int flags, DVector3* pos, int16_t* ang, sectortype** cursect, SpawnSpriteDef& sprites)
470{
471 FileReader fr = fileSystem.OpenFileReader(filename);
472 if (!fr.isOpen()) I_Error("Unable to open map %s", filename);
473 int mapversion = fr.ReadInt32();
474 if (mapversion < 5 || mapversion > 9) // 9 is most likely useless but let's try anyway.
475 {
476 I_Error("%s: Invalid map format, expected 5-9, got %d", filename, mapversion);
477 }
478
479 pos->X = fr.ReadInt32() * maptoworld;
480 pos->Y = fr.ReadInt32() * maptoworld;
481 pos->Z = fr.ReadInt32() * zmaptoworld;
482 *ang = fr.ReadInt16() & 2047;
483
484 int cursectnum = fr.ReadUInt16();
485
486 // Get the basics out before loading the data so that we can set up the global storage.
487 unsigned numsectors = fr.ReadUInt16();
488 auto sectorpos = fr.Tell();
489 fr.Seek((mapversion == 5 ? sectorsize5 : mapversion == 6 ? sectorsize6 : sectorsize7) * numsectors, FileReader::SeekCur);
490 unsigned numwalls = fr.ReadUInt16();
491 auto wallpos = fr.Tell();
492 fr.Seek((mapversion == 5 ? wallsize5 : mapversion == 6 ? wallsize6 : wallsize7)* numwalls, FileReader::SeekCur);
493 int numsprites = fr.ReadUInt16();
494 auto spritepos = fr.Tell();
495
496 // Now that we know the map's size, set up the globals.
497 allocateMapArrays(numwalls, numsectors, numsprites);
498 sprites.sprites.Resize(numsprites);
499 memset(sprites.sprites.Data(), 0, numsprites * sizeof(spritetype));
500
501 // Now load the actual data.
502 fr.Seek(sectorpos, FileReader::SeekSet);
503 for (unsigned i = 0; i < sector.Size(); i++)
504 {
505 switch (mapversion)
506 {
507 case 5: ReadSectorV5(fr, sector[i]); break;
508 case 6: ReadSectorV6(fr, sector[i]); break;
509 default: ReadSectorV7(fr, sector[i]); break;
510 }
511 // If we do not do this here, we need to do a lot more contortions to exclude this default from getting written out to savegames.
512 if (isExhumed())
513 {
514 sector[i].Sound = -1;
515 }
516 }
517
518 fr.Seek(wallpos, FileReader::SeekSet);
519 for (unsigned i = 0; i < wall.Size(); i++)
520 {
521 switch (mapversion)
522 {
523 case 5: ReadWallV5(fr, wall[i]); break;
524 case 6: ReadWallV6(fr, wall[i]); break;
525 default: ReadWallV7(fr, wall[i]); break;
526 }

Callers 4

LoadTheMapFunction · 0.85
InitLevelFunction · 0.85
LoadLevelFunction · 0.85
loadMapBackupFunction · 0.85

Calls 15

I_ErrorFunction · 0.85
allocateMapArraysFunction · 0.85
ReadSectorV5Function · 0.85
ReadSectorV6Function · 0.85
ReadSectorV7Function · 0.85
isExhumedFunction · 0.85
ReadWallV5Function · 0.85
ReadWallV6Function · 0.85
ReadWallV7Function · 0.85
ReadSpriteV5Function · 0.85
ReadSpriteV6Function · 0.85
ReadSpriteV7Function · 0.85

Tested by

no test coverage detected