From 71e5f9b70fe972c8872dc324f08d8d56c9891103 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 22 Apr 2021 00:25:55 +0200 Subject: [PATCH] - changed screen job list to work without per-job completion callbacks. They made things more complex than necessary and do not translate well to scripting. --- source/core/screenjob.cpp | 11 +++- source/core/screenjob.h | 13 +++-- source/games/blood/src/credits.cpp | 24 ++++++-- source/games/duke/src/2d_d.cpp | 89 +++++++++++++++++++++--------- source/games/duke/src/2d_r.cpp | 16 +++--- source/games/sw/src/2d.cpp | 4 +- 6 files changed, 107 insertions(+), 50 deletions(-) diff --git a/source/core/screenjob.cpp b/source/core/screenjob.cpp index 628378b27..40d1c0963 100644 --- a/source/core/screenjob.cpp +++ b/source/core/screenjob.cpp @@ -56,6 +56,11 @@ IMPLEMENT_CLASS(DScreenJob, true, false) IMPLEMENT_CLASS(DImageScreen, true, false) +void DScreenJob::OnDestroy() +{ + if (flags & stopmusic) Mus_Stop(); + if (flags & stopsound) FX_StopAllSounds(); +} bool DSkippableScreenJob::OnEvent(event_t* evt) { @@ -164,7 +169,7 @@ public: { if (index >= 0) { - if (jobs[index].postAction) jobs[index].postAction(); + //if (jobs[index].postAction) jobs[index].postAction(); jobs[index].job->Destroy(); } index++; @@ -176,7 +181,7 @@ public: actionState = clearbefore ? State_Clear : State_Run; if (index < jobs.Size()) { - jobs[index].job->fadestate = !paused && jobs[index].job->fadestyle & DScreenJob::fadein? DScreenJob::fadein : DScreenJob::visible; + jobs[index].job->fadestate = !paused && jobs[index].job->flags & DScreenJob::fadein? DScreenJob::fadein : DScreenJob::visible; jobs[index].job->Start(); } inputState.ClearAllInput(); @@ -289,7 +294,7 @@ public: if (terminateState < 1) { // Must lock before displaying. - if (jobs[index].job->fadestyle & DScreenJob::fadeout) + if (jobs[index].job->flags & DScreenJob::fadeout) { jobs[index].job->fadestate = DScreenJob::fadeout; jobs[index].job->state = DScreenJob::stopping; diff --git a/source/core/screenjob.h b/source/core/screenjob.h index 733a8e6f8..3eed95e10 100644 --- a/source/core/screenjob.h +++ b/source/core/screenjob.h @@ -3,6 +3,7 @@ #include "dobject.h" #include "v_2ddrawer.h" #include "d_eventbase.h" +#include "s_soundinternal.h" using CompletionFunc = std::function; struct JobDesc; @@ -11,7 +12,7 @@ class ScreenJobRunner; class DScreenJob : public DObject { DECLARE_CLASS(DScreenJob, DObject) - const int fadestyle; + const int flags; const float fadetime; // in milliseconds int fadestate = fadein; @@ -35,9 +36,11 @@ public: visible = 0, fadein = 1, fadeout = 2, + stopmusic = 4, + stopsound = 8, }; - DScreenJob(int fade = 0, float fadet = 250.f) : fadestyle(fade), fadetime(fadet) {} + DScreenJob(int fade = 0, float fadet = 250.f) : flags(fade), fadetime(fadet) {} virtual bool ProcessInput() { @@ -60,6 +63,7 @@ public: int GetFadeState() const { return fadestate; } + virtual void OnDestroy() override; }; //--------------------------------------------------------------------------- @@ -90,7 +94,7 @@ class DBlackScreen : public DScreenJob bool cleared = false; public: - DBlackScreen(int w) : wait(w) {} + DBlackScreen(int w, int flags = 0) : DScreenJob(flags & ~(fadein|fadeout)), wait(w) {} void OnTick() override; void Draw(double smooth) override; }; @@ -134,8 +138,7 @@ public: struct JobDesc { DScreenJob* job; - void (*postAction)(); - //bool ignoreifskipped; + //void (*postAction)(); }; enum diff --git a/source/games/blood/src/credits.cpp b/source/games/blood/src/credits.cpp index 98e37caf2..89efa42ed 100644 --- a/source/games/blood/src/credits.cpp +++ b/source/games/blood/src/credits.cpp @@ -36,6 +36,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS +class DBloodIntroImage : public DImageScreen +{ + bool mus; + +public: + DBloodIntroImage(int tilenum, int flags = 0, bool withmusic = false) : DImageScreen(tilenum, flags), mus(withmusic) + {} + + void Start() override + { + sndStartSample("THUNDER2", 128, -1); + if (mus) sndPlaySpecialMusicOrNothing(MUS_INTRO); + } +}; //--------------------------------------------------------------------------- // @@ -70,8 +84,7 @@ void playlogos() } else { - jobs[job++] = { Create(1), []() { sndStartSample("THUNDER2", 128, -1); } }; - jobs[job++] = { Create(2050) }; + jobs[job++] = { Create(2050) }; } if (fileSystem.FindFile("gti.smk") != -1) { @@ -79,12 +92,11 @@ void playlogos() } else { - jobs[job++] = { Create(1), []() { sndStartSample("THUNDER2", 128, -1); } }; - jobs[job++] = { Create(2052) }; + jobs[job++] = { Create(2052) }; } } - jobs[job++] = { Create(1), []() { sndPlaySpecialMusicOrNothing(MUS_INTRO); sndStartSample("THUNDER2", 128, -1); }}; - jobs[job++] = { Create(2518, DScreenJob::fadein) }; + jobs[job++] = { Create(1) }; + jobs[job++] = { Create(2518, DScreenJob::fadein, true) }; RunScreenJob(jobs, job, [](bool) { Mus_Stop(); diff --git a/source/games/duke/src/2d_d.cpp b/source/games/duke/src/2d_d.cpp index f59ff35dd..da895e94d 100644 --- a/source/games/duke/src/2d_d.cpp +++ b/source/games/duke/src/2d_d.cpp @@ -170,6 +170,11 @@ class DDRealmsScreen : public DSkippableScreenJob public: DDRealmsScreen() : DSkippableScreenJob(fadein | fadeout) {} + void Start() override + { + S_PlaySpecialMusic(MUS_INTRO); + } + void OnTick() override { if (ticks >= 7 * GameTicRate) state = finished; @@ -200,6 +205,11 @@ public: { } + void Start() override + { + if (isNam() || userConfig.nologo) S_PlaySpecialMusic(MUS_INTRO); + } + void OnTick() override { int clock = ticks * 120 / GameTicRate; @@ -276,6 +286,11 @@ public: } } } + + void OnDestroy() override + { + S_PlaySound(NITEVISION_ONOFF, CHAN_AUTO, CHANF_UI); + } }; //--------------------------------------------------------------------------- @@ -301,12 +316,10 @@ void Logo_d(const CompletionFunc &completion) int job = 0; if (!userConfig.nologo) { - if (!isShareware()) jobs[job++] = { PlayVideo("logo.anm", logosound, logoframetimes), []() { S_PlaySpecialMusic(MUS_INTRO); } }; - else jobs[job++] = { Create(1), []() { S_PlaySpecialMusic(MUS_INTRO); } }; - if (!isNam()) jobs[job++] = { Create(), nullptr }; + if (!isShareware()) jobs[job++] = { PlayVideo("logo.anm", logosound, logoframetimes) }; + if (!isNam()) jobs[job++] = { Create(), }; } - else S_PlaySpecialMusic(MUS_INTRO); - jobs[job++] = { Create(), []() { S_PlaySound(NITEVISION_ONOFF, CHAN_AUTO, CHANF_UI); } }; + jobs[job++] = { Create() }; RunScreenJob(jobs, job, completion, SJ_BLOCKUI); } @@ -422,6 +435,18 @@ public: } }; + +class DE2EndScreen : public DImageScreen +{ +public: + DE2EndScreen() : DImageScreen(E2ENDSCREEN, DScreenJob::fadein | DScreenJob::fadeout | DScreenJob::stopsound, 0x7fffffff, 0) + {} + + void Start() override + { + S_PlaySound(PIPEBOMB_EXPLODE, CHAN_AUTO, CHANF_UI); + } +}; //--------------------------------------------------------------------------- // // @@ -513,6 +538,11 @@ public: } if (state != running) FX_StopAllSounds(); } + + void OnDestroy() override + { + if (!isPlutoPak()) S_PlaySound(ENDSEQVOL3SND4, CHAN_AUTO, CHANF_UI); + } }; //--------------------------------------------------------------------------- @@ -535,6 +565,11 @@ public: BigText(160, 70 + 16 + 16 + 16, GStrings("Look for a Duke Nukem 3D")); BigText(160, 70 + 16 + 16 + 16 + 16, GStrings("sequel soon.")); } + + void Start() override + { + S_PlaySound(ENDSEQVOL3SND4, CHAN_AUTO, CHANF_UI); + } }; //--------------------------------------------------------------------------- @@ -548,7 +583,7 @@ class DEpisode5End : public DImageScreen int sound = 0; public: - DEpisode5End() : DImageScreen(FIREFLYGROWEFFECT, fadein|fadeout) + DEpisode5End() : DImageScreen(FIREFLYGROWEFFECT, fadein|fadeout|stopsound) { } @@ -644,45 +679,45 @@ static void bonussequence_d(int num, JobDesc *jobs, int &job) switch (num) { case 0: - jobs[job++] = { Create(), nullptr }; - jobs[job++] = { Create(E1ENDSCREEN, DScreenJob::fadein|DScreenJob::fadeout, 0x7fffffff), []() { Mus_Stop(); } }; + jobs[job++] = { Create() }; + jobs[job++] = { Create(E1ENDSCREEN, DScreenJob::fadein|DScreenJob::fadeout|DScreenJob::stopmusic, 0x7fffffff) }; break; case 1: Mus_Stop(); - jobs[job++] = { PlayVideo("cineov2.anm", cineov2sound, framespeed_18), []() { S_PlaySound(PIPEBOMB_EXPLODE, CHAN_AUTO, CHANF_UI); } }; - jobs[job++] = { Create(E2ENDSCREEN, DScreenJob::fadein | DScreenJob::fadeout, 0x7fffffff), []() { FX_StopAllSounds(); } }; + jobs[job++] = { PlayVideo("cineov2.anm", cineov2sound, framespeed_18) }; + jobs[job++] = { Create() }; break; case 2: Mus_Stop(); if (g_gameType & GAMEFLAG_DUKEDC) { - jobs[job++] = { PlayVideo("radlogo.anm", dukedcsound, framespeed_10), nullptr }; + jobs[job++] = { PlayVideo("radlogo.anm", dukedcsound, framespeed_10) }; } else { - jobs[job++] = { PlayVideo("cineov3.anm", cineov3sound, framespeed_10), nullptr }; - jobs[job++] = { Create(200), []() { FX_StopAllSounds(); } }; - jobs[job++] = { Create(), []() { if (!isPlutoPak()) S_PlaySound(ENDSEQVOL3SND4, CHAN_AUTO, CHANF_UI); } }; + jobs[job++] = { PlayVideo("cineov3.anm", cineov3sound, framespeed_10) }; + jobs[job++] = { Create(200, DScreenJob::stopsound) }; + jobs[job++] = { Create() }; if (!isPlutoPak()) jobs[job++] = { Create(TexMan.GetGameTextureByName("DUKETEAM.ANM", false, FTextureManager::TEXMAN_ForceLookup), - DScreenJob::fadein | DScreenJob::fadeout, 0x7fffffff), []() { FX_StopAllSounds(); } }; + DScreenJob::fadein | DScreenJob::fadeout | DScreenJob::stopsound, 0x7fffffff) }; } break; case 3: Mus_Stop(); - jobs[job++] = { PlayVideo("vol4e1.anm", vol4e1, framespeed_10), nullptr }; - jobs[job++] = { PlayVideo("vol4e2.anm", vol4e2, framespeed_10), nullptr }; - jobs[job++] = { PlayVideo("vol4e3.anm", vol4e3, framespeed_10), []() { S_PlaySound(ENDSEQVOL3SND4, CHAN_AUTO, CHANF_UI); } }; - jobs[job++] = { Create(), nullptr }; + jobs[job++] = { PlayVideo("vol4e1.anm", vol4e1, framespeed_10) }; + jobs[job++] = { PlayVideo("vol4e2.anm", vol4e2, framespeed_10) }; + jobs[job++] = { PlayVideo("vol4e3.anm", vol4e3, framespeed_10) }; + jobs[job++] = { Create() }; jobs[job++] = { Create(TexMan.GetGameTextureByName("DUKETEAM.ANM", false, FTextureManager::TEXMAN_ForceLookup), - DScreenJob::fadein | DScreenJob::fadeout, 0x7fffffff), []() { FX_StopAllSounds(); } }; + DScreenJob::fadein | DScreenJob::fadeout | DScreenJob::stopsound, 0x7fffffff) }; break; case 4: Mus_Stop(); - jobs[job++] = { Create(), []() { FX_StopAllSounds(); } }; + jobs[job++] = { Create() }; break; } } @@ -698,8 +733,8 @@ void showtwoscreens(const CompletionFunc& completion) JobDesc jobs[2]; int job = 0; - jobs[job++] = { Create(3291), nullptr }; - jobs[job++] = { Create(3290), nullptr }; + jobs[job++] = { Create(3291) }; + jobs[job++] = { Create(3290) }; RunScreenJob(jobs, job, completion); } @@ -709,7 +744,7 @@ void doorders(const CompletionFunc& completion) int job = 0; for (int i = 0; i < 4; i++) - jobs[job++] = { Create(ORDERING + i), nullptr }; + jobs[job++] = { Create(ORDERING + i) }; RunScreenJob(jobs, job, completion); } @@ -1128,9 +1163,9 @@ void e4intro(const CompletionFunc& completion) static const int framespeed_14[] = { 14, 14, 14 }; S_PlaySpecialMusic(MUS_BRIEFING); - jobs[job++] = { PlayVideo("vol41a.anm", vol41a, framespeed_10), nullptr }; - jobs[job++] = { PlayVideo("vol42a.anm", vol42a, framespeed_14), nullptr }; - jobs[job++] = { PlayVideo("vol43a.anm", vol43a, framespeed_10), nullptr }; + jobs[job++] = { PlayVideo("vol41a.anm", vol41a, framespeed_10) }; + jobs[job++] = { PlayVideo("vol42a.anm", vol42a, framespeed_14) }; + jobs[job++] = { PlayVideo("vol43a.anm", vol43a, framespeed_10) }; RunScreenJob(jobs, job, completion, SJ_SKIPALL); } diff --git a/source/games/duke/src/2d_r.cpp b/source/games/duke/src/2d_r.cpp index a7350a928..27bd4bd1d 100644 --- a/source/games/duke/src/2d_r.cpp +++ b/source/games/duke/src/2d_r.cpp @@ -196,13 +196,13 @@ void Logo_r(const CompletionFunc& completion) } else if (!isRRRA()) { - jobs[job++] = { PlayVideo("rr_intro.anm", introsound, framespeed), nullptr }; - jobs[job++] = { PlayVideo("redneck.anm", rednecksound, framespeed), nullptr }; - jobs[job++] = { PlayVideo("xatlogo.anm", xatrixsound, framespeed), nullptr }; + jobs[job++] = { PlayVideo("rr_intro.anm", introsound, framespeed) }; + jobs[job++] = { PlayVideo("redneck.anm", rednecksound, framespeed) }; + jobs[job++] = { PlayVideo("xatlogo.anm", xatrixsound, framespeed) }; } else { - jobs[job++] = { PlayVideo("redint.mve"), nullptr }; + jobs[job++] = { PlayVideo("redint.mve") }; } RunScreenJob(jobs, job, completion, SJ_BLOCKUI); } @@ -235,13 +235,13 @@ static void bonussequence_r(int num, JobDesc* jobs, int& job) switch (num) { case 0: - jobs[job++] = { PlayVideo("turdmov.anm", turdmov, framespeed), nullptr }; - jobs[job++] = { Create(TENSCREEN), nullptr }; + jobs[job++] = { PlayVideo("turdmov.anm", turdmov, framespeed) }; + jobs[job++] = { Create(TENSCREEN) }; break; case 1: - jobs[job++] = { PlayVideo("rr_outro.anm", rr_outro, framespeed), nullptr }; - jobs[job++] = { Create(TENSCREEN), nullptr }; + jobs[job++] = { PlayVideo("rr_outro.anm", rr_outro, framespeed) }; + jobs[job++] = { Create(TENSCREEN) }; break; default: diff --git a/source/games/sw/src/2d.cpp b/source/games/sw/src/2d.cpp index 92cc36ccf..325a44430 100644 --- a/source/games/sw/src/2d.cpp +++ b/source/games/sw/src/2d.cpp @@ -356,6 +356,7 @@ public: seconds = (second_tics % 60); } private: + static void gNextState(STATE** State) { // Transition to the next state @@ -403,6 +404,7 @@ private: void Start() override { + FX_StopAllSounds(); PlaySong(nullptr, ThemeSongs[1], ThemeTrack[1]); } @@ -610,7 +612,7 @@ void StatScreen(int FinishAnim, CompletionFunc completion) if (FinishAnim) { StopSound(); - jobs[job++] = { GetFinishAnim(FinishAnim), []() { soundEngine->StopAllChannels(); } }; + jobs[job++] = { GetFinishAnim(FinishAnim) }; jobs[job++] = { Create() }; if (FinishAnim == ANIM_ZILLA) jobs[job++] = { Create() };