From 0dc6980e5c6111936b89ccc9fbb1c70861049807 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 27 Apr 2021 20:04:11 +0200 Subject: [PATCH] - made episode intro cutscenes a game independent feature. So far only defined for Duke E4 but all the logic is outside the game code now and can be universally handled. --- source/core/mainloop.cpp | 32 ++++++++++- source/core/mapinfo.h | 1 + source/core/parsefuncs.h | 2 +- source/games/blood/src/blood.cpp | 8 +-- source/games/blood/src/levels.cpp | 1 + source/games/duke/src/2d_d.cpp | 57 ------------------- source/games/duke/src/funct.h | 1 - source/games/duke/src/gamedef.cpp | 2 + source/games/duke/src/gameloop.cpp | 48 ++-------------- source/games/duke/src/premap.cpp | 51 ++++++----------- source/games/exhumed/src/exhumed.cpp | 1 + source/games/exhumed/src/gameloop.cpp | 16 +----- source/games/sw/src/game.cpp | 8 +-- source/games/sw/src/scrip2.cpp | 1 + .../static/filter/redneck/engine/engine.def | 3 +- 15 files changed, 61 insertions(+), 171 deletions(-) diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index da2d99565..4d52eaa7b 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -133,6 +133,23 @@ void G_BuildTiccmd(ticcmd_t* cmd) //========================================================================== bool newGameStarted; +void NewGame(MapRecord* map, int skill, bool ns = false) +{ + newGameStarted = true; + int volume = map->cluster - 1; + if (volume >= 0 && volume < MAXVOLUMES) + { + if (StartCutscene(volumeList[volume].intro, 0, [=](bool) { gi->NewGame(map, skill, ns); })) return; + } + gi->NewGame(map, skill, ns); +} + +//========================================================================== +// +// +// +//========================================================================== + static void GameTicker() { int i; @@ -159,7 +176,7 @@ static void GameTicker() FX_SetReverb(0); gi->FreeLevelData(); gameaction = ga_level; - gi->NewGame(g_nextmap, -1); + NewGame(g_nextmap, -1); BackupSaveGame = ""; } break; @@ -191,13 +208,12 @@ static void GameTicker() FX_StopAllSounds(); case ga_newgamenostopsound: DeleteScreenJob(); - newGameStarted = true; FX_SetReverb(0); gi->FreeLevelData(); C_FlushDisplay(); gameaction = ga_level; BackupSaveGame = ""; - gi->NewGame(g_nextmap, g_nextskill, ga == ga_newgamenostopsound); + NewGame(g_nextmap, g_nextskill, ga == ga_newgamenostopsound); break; case ga_startup: @@ -637,6 +653,16 @@ void MainLoop () // Clamp the timer to TICRATE until the playloop has been entered. r_NoInterpolate = true; + if (userConfig.CommandMap.IsNotEmpty()) + { + auto maprecord = FindMapByName(userConfig.CommandMap); + userConfig.CommandMap = ""; + if (maprecord) + { + NewGame(maprecord, /*userConfig.skill*/2); // todo: fix the skill. + } + } + for (;;) { try diff --git a/source/core/mapinfo.h b/source/core/mapinfo.h index cdd607daf..c8b5c0367 100644 --- a/source/core/mapinfo.h +++ b/source/core/mapinfo.h @@ -93,6 +93,7 @@ struct MapRecord int cdSongId = -1; int flags = 0; int levelNumber = -1; + int cluster = -1; // The rest is only used by Blood int nextLevel = -1; diff --git a/source/core/parsefuncs.h b/source/core/parsefuncs.h index 888df2157..4e6dbc20c 100644 --- a/source/core/parsefuncs.h +++ b/source/core/parsefuncs.h @@ -96,7 +96,7 @@ void parseDefineCutscene(FScanner& sc, FScriptPosition& pos) { parseCutscene(sc, globalCutscenes.DefaultMapOutro); } - else if (sc.Compare("episode")) + else if (sc.Compare({ "episode", "volume", "cluster" })) { FScanner::SavedPos eblockend; sc.MustGetNumber(); diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index f4ca01954..20130881d 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -523,13 +523,7 @@ static void gameInit() void GameInterface::Startup() { gameInit(); - if (userConfig.CommandMap.IsNotEmpty()) - { - } - else - { - PlayLogos(ga_mainmenu, ga_mainmenu, true); - } + PlayLogos(ga_mainmenu, ga_mainmenu, true); } diff --git a/source/games/blood/src/levels.cpp b/source/games/blood/src/levels.cpp index 21286c08a..a64fac507 100644 --- a/source/games/blood/src/levels.cpp +++ b/source/games/blood/src/levels.cpp @@ -185,6 +185,7 @@ void levelLoadDefaults(void) const char *pMap = BloodINI->GetKeyString(buffer, buffer2, NULL); CheckSectionAbend(pMap); pLevelInfo->levelNumber = levelnum(i, j); + pLevelInfo->cluster = i + 1; pLevelInfo->labelName = pMap; pLevelInfo->fileName.Format("%s.map", pMap); levelLoadMapInfo(BloodINI, pLevelInfo, pMap, i, j); diff --git a/source/games/duke/src/2d_d.cpp b/source/games/duke/src/2d_d.cpp index b20e6c395..526cc1458 100644 --- a/source/games/duke/src/2d_d.cpp +++ b/source/games/duke/src/2d_d.cpp @@ -181,63 +181,6 @@ void dobonus_d(int bonusonly, const CompletionFunc& completion) #endif } -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -void e4intro(const CompletionFunc& completion) -{ -#if 0 - TArray jobs; - - static const AnimSound vol42a[] = - { - { 1, INTRO4_B + 1 }, - { 12, SHORT_CIRCUIT + 1 }, - { 18, INTRO4_5 + 1 }, - { 34, SHORT_CIRCUIT + 1 }, - { -1,-1 } - }; - - static const AnimSound vol41a[] = - { - { 1, INTRO4_1 + 1 }, - { 7, INTRO4_3 + 1 }, - { 12, INTRO4_2 + 1 }, - { 26, INTRO4_4 + 1 }, - { -1,-1 } - }; - - static const AnimSound vol43a[] = - { - { 10, INTRO4_6 + 1 }, - { -1,-1 } - }; - - static const int framespeed_10[] = { 10, 10, 10 }; - static const int framespeed_14[] = { 14, 14, 14 }; - - S_PlaySpecialMusic(MUS_BRIEFING); - jobs.Push(PlayVideo("vol41a.anm", vol41a, framespeed_10)); - jobs.Push(PlayVideo("vol42a.anm", vol42a, framespeed_14)); - jobs.Push(PlayVideo("vol43a.anm", vol43a, framespeed_10)); - RunScreenJob(jobs, completion, SJ_SKIPALL); -#endif -} - -#if 0 - -void loadscreen_d(MapRecord *rec, CompletionFunc func) -{ - TArray jobs(1, true); - - jobs[0] = Create(rec); - RunScreenJob(jobs, func); -} -#endif - void PrintPaused_d() { BigText(160, 100, GStrings("Game Paused")); diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 39fc8a07f..5e0bcc0e1 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -224,7 +224,6 @@ void e4intro(const CompletionFunc& completion); void exitlevel(MapRecord *next); void enterlevel(MapRecord* mi, int gm); void donewgame(MapRecord* map, int sk); -void startnewgame(MapRecord* map, int skill); int playercolor2lookup(int color); void PlayerColorChanged(void); bool movementBlocked(player_struct *p); diff --git a/source/games/duke/src/gamedef.cpp b/source/games/duke/src/gamedef.cpp index 687d3dca6..6eb5c81da 100644 --- a/source/games/duke/src/gamedef.cpp +++ b/source/games/duke/src/gamedef.cpp @@ -1714,6 +1714,7 @@ int ConCompiler::parsecommand() (((*(textptr + 3) - '0') * 10 + (*(textptr + 4) - '0')) * 26); map->levelNumber = levnum; + map->cluster = j + 1; textptr += 5; while (*textptr == ' ' || *textptr == '\t') textptr++; @@ -3251,6 +3252,7 @@ void FixMapinfo() maprec->SetFileName("endgame.map"); maprec->SetName("$TXT_CLOSEENCOUNTERS"); maprec->levelNumber = levelnum(1, 7); + maprec->cluster = 2; } } } diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 2c5b20025..183e4676d 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -113,28 +113,8 @@ void GameInterface::Ticker() void GameInterface::Startup() { - ps[myconnectindex].ftq = 0; - - if (userConfig.CommandMap.IsNotEmpty()) - { - auto maprecord = FindMapByName(userConfig.CommandMap); - userConfig.CommandMap = ""; - if (maprecord) - { - ud.m_respawn_monsters = ud.player_skill == 4; - - for (int i = 0; i != -1; i = connectpoint2[i]) - { - resetweapons(i); - resetinventory(i); - } - startnewgame(maprecord, /*userConfig.skill*/2); - } - } - else - { - PlayLogos(ga_mainmenunostopsound, ga_mainmenunostopsound, false); - } + ps[myconnectindex].ftq = 0; + PlayLogos(ga_mainmenunostopsound, ga_mainmenunostopsound, false); } //--------------------------------------------------------------------------- @@ -159,15 +139,12 @@ void GameInterface::Render() // // //--------------------------------------------------------------------------- -void loadscreen_d(MapRecord* rec, CompletionFunc func); -void loadscreen_r(MapRecord* rec, CompletionFunc func); void GameInterface::NextLevel(MapRecord* map, int skill) { #if 0 - // Loading is so fast on modern system so that this only serves as an irritant, not an asset. - auto loadscreen = isRR() ? loadscreen_r : loadscreen_d; - loadscreen_d(map, [=](bool) + // Loading is so fast on modern systems that this only serves as an irritant, not an asset. + loadscreen(map, [=](bool) { enterlevel(map, 0); gameaction = ga_level; @@ -182,23 +159,6 @@ void GameInterface::NextLevel(MapRecord* map, int skill) // //--------------------------------------------------------------------------- -void GameInterface::NewGame(MapRecord* map, int skill, bool) -{ - // Hmm... What about the other players? - ps[0].last_extra = gs.max_player_health; - resetweapons(0); - resetinventory(0); - if (skill != -1) skill = skill + 1; - - startnewgame(map, skill); -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - void GameInterface::LevelCompleted(MapRecord* map, int skill) { exitlevel(map); diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 8ab43593b..074020dda 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -812,33 +812,6 @@ void donewgame(MapRecord* map, int sk) } } -template -void newgame(MapRecord* map, int sk, func completion) -{ - auto completion1 = [=](bool res) - { - if (!isRR() && map->levelNumber == levelnum(3, 0) && (ud.multimode < 2)) - { - e4intro([=](bool) { donewgame(map, sk); completion(res); }); - } - else - { - donewgame(map, sk); - completion(res); - } - }; - - if (ud.m_recstat != 2 && ud.last_level >= 0 && ud.multimode > 1 && ud.coop != 1) - dobonus(1, completion1); - -#if 0 // this is one lousy hack job that's hopefully not needed anymore. - else if (isRR() && !isRRRA() && map->levelNumber == levelnum(0, 6)) - dobonus(0, completion1); -#endif - - else completion1(false); -} - //--------------------------------------------------------------------------- // // @@ -983,9 +956,19 @@ void enterlevel(MapRecord *mi, int gamemode) // //--------------------------------------------------------------------------- -void startnewgame(MapRecord* map, int skill) +void GameInterface::NewGame(MapRecord* map, int skill, bool) { + for (int i = 0; i != -1; i = connectpoint2[i]) + { + resetweapons(i); + resetinventory(i); + } + + ps[0].last_extra = gs.max_player_health; + + if (skill == -1) skill = ud.player_skill; + else skill++; ud.player_skill = skill; ud.m_respawn_monsters = (skill == 4); ud.m_monsters_off = ud.monsters_off = 0; @@ -993,13 +976,11 @@ void startnewgame(MapRecord* map, int skill) ud.m_respawn_inventory = 0; ud.multimode = 1; - newgame(map, skill, [=](bool) - { - enterlevel(map, 0); - PlayerColorChanged(); - inputState.ClearAllInput(); - gameaction = ga_level; - }); + donewgame(map, skill); + enterlevel(map, 0); + PlayerColorChanged(); + inputState.ClearAllInput(); + gameaction = ga_level; } //--------------------------------------------------------------------------- diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 462c2923f..2426b2208 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -494,6 +494,7 @@ void GameInterface::app_init() mi->labelName.Format("LEV%d", i); mi->name.Format("$TXT_EX_MAP%02d", i); mi->levelNumber = i; + mi->cluster = i? 1 : 2; // training is cluster 2 int nTrack = i; if (nTrack != 0) nTrack--; diff --git a/source/games/exhumed/src/gameloop.cpp b/source/games/exhumed/src/gameloop.cpp index 50ff8a55c..a95e8299d 100644 --- a/source/games/exhumed/src/gameloop.cpp +++ b/source/games/exhumed/src/gameloop.cpp @@ -155,21 +155,7 @@ void GameInterface::Startup() { resettiming(); EndLevel = 0; - - if (userConfig.CommandMap.IsNotEmpty()) - { - /* - auto map = FindMapByName(userConfig.CommandMap); - if (map) DeferedStartMap(map, 0); - userConfig.CommandMap = ""; - goto again; - */ - } - else - { - PlayLogos(ga_mainmenu, ga_mainmenu, false); - } - + PlayLogos(ga_mainmenu, ga_mainmenu, false); } void GameInterface::ErrorCleanup() diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index c228e73fe..adc6cbd0e 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -645,13 +645,7 @@ void GameInterface::Render() void GameInterface::Startup() { - if (userConfig.CommandMap.IsNotEmpty()) - { - } - else - { - PlayLogos(ga_mainmenunostopsound, ga_mainmenu, false); - } + PlayLogos(ga_mainmenunostopsound, ga_mainmenu, false); } diff --git a/source/games/sw/src/scrip2.cpp b/source/games/sw/src/scrip2.cpp index c6be81a83..d5302df48 100644 --- a/source/games/sw/src/scrip2.cpp +++ b/source/games/sw/src/scrip2.cpp @@ -447,6 +447,7 @@ void LoadCustomInfoFromScript(const char *filename) { curMap = AllocateMap(); curMap->levelNumber = mapno; + curMap->cluster = mapno < 5 ? 1 : 2; } if (sc.CheckString("{")) diff --git a/wadsrc/static/filter/redneck/engine/engine.def b/wadsrc/static/filter/redneck/engine/engine.def index c6a49fa42..a569487ad 100644 --- a/wadsrc/static/filter/redneck/engine/engine.def +++ b/wadsrc/static/filter/redneck/engine/engine.def @@ -5,7 +5,8 @@ definecutscene intro function RRCutscenes.BuildIntro } -definecutscene map e1l7 // episode 1 +// The 'E1End' cutscene is tied to the level as it is not an end-of-game event. +definecutscene map e1l7 { outro {