MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / LoadLevel

Function LoadLevel

Descent3/LoadLevel.cpp:3605–4167  ·  view source on GitHub ↗

Load a level file Returns 1 if file read ok, else 0

Source from the content-addressed store, hash-verified

3603// Load a level file
3604// Returns 1 if file read ok, else 0
3605int LoadLevel(char *filename, void (*cb_fn)(const char *, int, int)) {
3606 CFILE *ifile;
3607 char tag[4];
3608 int n, i, retval = 1;
3609
3610 int version;
3611 bool f_read_AABB = false;
3612 bool no_128s = true;
3613 int total = 0;
3614#ifdef EDITOR
3615 Disable_editor_rendering = 1;
3616 Num_failed_xlate_items = 0;
3617#endif
3618 PrintDedicatedMessage(TXT_DS_OPENLEVEL, filename);
3619
3620 RestartLevelMD5();
3621
3622 ifile = cfopen(filename, "rb");
3623 if (!ifile) {
3624 retval = 0;
3625 goto end_loadlevel;
3626 }
3627
3628 try { // catch cfile errors
3629
3630 filelen = cfilelength(ifile);
3631
3632 // Read & check tag
3633 cf_ReadBytes((uint8_t *)tag, 4, ifile);
3634 if (strncmp(tag, LEVEL_FILE_TAG, 4)) {
3635 cfclose(ifile);
3636 retval = 0;
3637 goto end_loadlevel;
3638 }
3639
3640 // Read & check version number
3641 version = cf_ReadInt(ifile);
3642
3643 // Check for too-new version
3644 if (version > LEVEL_FILE_VERSION) {
3645 cfclose(ifile);
3646#if (defined(EDITOR) || defined(NEWEDITOR))
3647 if (GetFunctionMode() == EDITOR_MODE)
3648 EditorMessageBox("Can't load level file \"%s\": Its version (%d) is newer than current version (%d).", filename,
3649 version, LEVEL_FILE_VERSION);
3650#endif
3651 retval = 0;
3652 goto end_loadlevel;
3653 }
3654
3655 // Check for too-old version
3656 if (version < LEVEL_FILE_OLDEST_COMPATIBLE_VERSION) {
3657 cfclose(ifile);
3658#if (defined(EDITOR) || defined(NEWEDITOR))
3659 if (GetFunctionMode() == EDITOR_MODE)
3660 EditorMessageBox(
3661 "Can't load level file \"%s\": Its version (%d) is older than the oldest compatible version (%d).",
3662 filename, version, LEVEL_FILE_OLDEST_COMPATIBLE_VERSION);

Callers 5

EditorLoadLevelFunction · 0.85
ListObjectsInAllLevelsFunction · 0.85
ProcessPagesForLevelMethod · 0.85
GameToEditorFunction · 0.85
LoadMissionLevelFunction · 0.85

Calls 15

PrintDedicatedMessageFunction · 0.85
RestartLevelMD5Function · 0.85
cfopenFunction · 0.85
cfilelengthFunction · 0.85
cf_ReadBytesFunction · 0.85
cfcloseFunction · 0.85
cf_ReadIntFunction · 0.85
GetFunctionModeFunction · 0.85
FreeAllRoomsFunction · 0.85
FreeAllObjectsFunction · 0.85
ResetLightGlowsFunction · 0.85
ResetObjectListFunction · 0.85

Tested by

no test coverage detected