MCPcopy Create free account
hub / github.com/ZDoom/gzdoom / P_SetupLevel

Function P_SetupLevel

src/p_setup.cpp:412–628  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410//===========================================================================
411
412void P_SetupLevel(FLevelLocals *Level, int position, bool newGame)
413{
414 int i;
415
416 Level->ShaderStartTime = I_msTimeFS(); // indicate to the shader system that the level just started
417
418 // This is motivated as follows:
419
420 Level->maptype = MAPTYPE_UNKNOWN;
421
422 if (!savegamerestore)
423 {
424 Level->SetMusicVolume(Level->MusicVolume);
425 for (i = 0; i < MAXPLAYERS; ++i)
426 {
427 Level->Players[i]->killcount = Level->Players[i]->secretcount
428 = Level->Players[i]->itemcount = 0;
429 }
430 }
431 for (i = 0; i < MAXPLAYERS; ++i)
432 {
433 Level->Players[i]->mo = nullptr;
434 }
435 GPalette.ClearTranslationSlot(TRANSLATION_LevelScripted);
436
437
438 // Initial height of PointOfView will be set by player think.
439 auto p = Level->GetConsolePlayer();
440 if (p) p->viewz = NO_VALUE;
441
442 // Make sure all sounds are stopped before Z_FreeTags.
443 S_Start();
444 S_ResetMusic();
445
446 // Don't start the music if loading a savegame, because the music is stored there.
447 // Don't start the music if revisiting a level in a hub for the same reason.
448 if (!primaryLevel->IsReentering())
449 {
450 primaryLevel->SetMusic();
451 }
452
453 // [RH] clear out the mid-screen message
454 C_MidPrint(nullptr, nullptr);
455
456 // Free all level data from the previous map
457 P_FreeLevelData();
458
459 MapData *map = P_OpenMapData(Level->MapName.GetChars(), true);
460 if (map == nullptr)
461 {
462 I_Error("Unable to open map '%s'\n", Level->MapName.GetChars());
463 }
464
465 // [ZZ] init per-map static handlers. we need to call this before everything is set up because otherwise scripts don't receive PlayerEntered event
466 // (which happens at god-knows-what stage in this function, but definitely not the last part, because otherwise it'd work to put E_InitStaticHandlers before the player spawning)
467 Level->localEventManager->InitStaticHandlers(Level, true);
468
469 // generate a checksum for the level, to be included and checked with savegames.

Callers 1

DoLoadLevelMethod · 0.85

Calls 15

I_msTimeFSFunction · 0.85
S_StartFunction · 0.85
S_ResetMusicFunction · 0.85
C_MidPrintFunction · 0.85
P_FreeLevelDataFunction · 0.85
P_OpenMapDataFunction · 0.85
I_ErrorFunction · 0.85
T_PreprocessScriptsFunction · 0.85
P_ClearParticlesFunction · 0.85
PrecacheLevelFunction · 0.85
S_PrecacheLevelFunction · 0.85
AnnounceGameStartFunction · 0.85

Tested by

no test coverage detected