From 6ed1d5e6780a04c532449eeac24a5436ac0d7141 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Apr 2021 00:11:02 +0200 Subject: [PATCH] - DBlackScreen and DImageScreen migrated to event-based handling. --- source/core/movie/movieplayer.cpp | 6 ++-- source/core/screenjob.cpp | 41 ++++++++++++++++----------- source/core/screenjob.h | 17 +++++++---- source/games/blood/src/credits.cpp | 4 +-- source/games/duke/src/2d_d.cpp | 2 +- source/games/exhumed/src/gameloop.cpp | 2 +- source/games/exhumed/src/movie.cpp | 2 +- 7 files changed, 44 insertions(+), 30 deletions(-) diff --git a/source/core/movie/movieplayer.cpp b/source/core/movie/movieplayer.cpp index b72f39f21..e65a04d63 100644 --- a/source/core/movie/movieplayer.cpp +++ b/source/core/movie/movieplayer.cpp @@ -666,8 +666,10 @@ public: DMoviePlayer(MoviePlayer* mp) { player = mp; + pausable = false; } + void Draw(double smoothratio) override { if (!player) @@ -799,14 +801,14 @@ DScreenJob* PlayVideo(const char* filename, const AnimSound* ans, const int* fra { if (!filename) { - return Create(); + return Create(1); } FString error; auto movie = OpenMovie(filename, ans, frameticks, nosoundcutoff, error); if (!movie) { Printf(TEXTCOLOR_YELLOW, "%s", error.GetChars()); - return Create(); + return Create(1); } return Create(movie); } diff --git a/source/core/screenjob.cpp b/source/core/screenjob.cpp index 29da6dbec..cbcb39a27 100644 --- a/source/core/screenjob.cpp +++ b/source/core/screenjob.cpp @@ -63,12 +63,19 @@ bool DSkippableScreenJob::OnEvent(event_t* evt) return true; } - -int DBlackScreen::Frame(uint64_t clock, bool skiprequest) +void DBlackScreen::OnTick() { - int span = int(clock / 1'000'000); + if (cleared) + { + int span = ticks * 1000 / GameTicRate; + if (span > wait) state = finished; + } +} + +void DBlackScreen::Draw(double) +{ + cleared = true; twod->ClearScreen(); - return span < wait ? 1 : -1; } //--------------------------------------------------------------------------- @@ -77,22 +84,22 @@ int DBlackScreen::Frame(uint64_t clock, bool skiprequest) // //--------------------------------------------------------------------------- -int DImageScreen::Frame(uint64_t clock, bool skiprequest) +void DImageScreen::OnTick() { - if (tilenum > 0) + if (cleared) { - tex = tileGetTexture(tilenum, true); + int span = ticks * 1000 / GameTicRate; + if (span > waittime) state = finished; } - if (!tex) - { - twod->ClearScreen(); - return 0; - } - int span = int(clock / 1'000'000); +} + + +void DImageScreen::Draw(double smoothratio) +{ + if (tilenum > 0) tex = tileGetTexture(tilenum, true); twod->ClearScreen(); - DrawTexture(twod, tex, 0, 0, DTA_FullscreenEx, FSMode_ScaleToFit43, DTA_LegacyRenderStyle, STYLE_Normal, DTA_TranslationIndex, trans, TAG_DONE); - // Only end after having faded out. - return skiprequest ? -1 : span > waittime? 0 : 1; + if (tex) DrawTexture(twod, tex, 0, 0, DTA_FullscreenEx, FSMode_ScaleToFit43, DTA_LegacyRenderStyle, STYLE_Normal, DTA_TranslationIndex, trans, TAG_DONE); + cleared = true; } //--------------------------------------------------------------------------- @@ -200,7 +207,7 @@ public: screenfade = 1.f; } job.job->SetClock(clock); - int state = job.job->Frame(clock, skiprequest, I_GetTimeFrac()); + int state = job.job->Frame(clock, skiprequest, M_Active()? 1. : I_GetTimeFrac()); clock = job.job->GetClock(); if (clock == 0) clock = 1; return state; diff --git a/source/core/screenjob.h b/source/core/screenjob.h index 39c24fae7..cdf72014a 100644 --- a/source/core/screenjob.h +++ b/source/core/screenjob.h @@ -20,6 +20,7 @@ class DScreenJob : public DObject protected: int ticks = 0; int state = running; + bool pausable = true; public: enum @@ -55,7 +56,7 @@ public: } virtual bool OnEvent(event_t* evt) { return false; } - virtual void OnTick() { } + virtual void OnTick() { /*state = finished;*/ } virtual int Frame(uint64_t clock, bool skiprequest) { return 1; } virtual void Draw(double smoothratio) {} @@ -95,10 +96,12 @@ protected: class DBlackScreen : public DScreenJob { int wait; + bool cleared = false; public: DBlackScreen(int w) : wait(w) {} - int Frame(uint64_t clock, bool skiprequest) override; + void OnTick() override; + void Draw(double smooth) override; }; //--------------------------------------------------------------------------- @@ -107,29 +110,31 @@ public: // //--------------------------------------------------------------------------- -class DImageScreen : public DScreenJob +class DImageScreen : public DSkippableScreenJob { DECLARE_CLASS(DImageScreen, DScreenJob) int tilenum = -1; int trans; int waittime; // in ms. + bool cleared = false; FGameTexture* tex = nullptr; public: - DImageScreen(FGameTexture* tile, int fade = DScreenJob::fadein | DScreenJob::fadeout, int wait = 3000, int translation = 0) : DScreenJob(fade), waittime(wait) + DImageScreen(FGameTexture* tile, int fade = DScreenJob::fadein | DScreenJob::fadeout, int wait = 3000, int translation = 0) : DSkippableScreenJob(fade), waittime(wait) { tex = tile; trans = translation; } - DImageScreen(int tile, int fade = DScreenJob::fadein | DScreenJob::fadeout, int wait = 3000, int translation = 0) : DScreenJob(fade), waittime(wait) + DImageScreen(int tile, int fade = DScreenJob::fadein | DScreenJob::fadeout, int wait = 3000, int translation = 0) : DSkippableScreenJob(fade), waittime(wait) { tilenum = tile; trans = translation; } - int Frame(uint64_t clock, bool skiprequest) override; + void OnTick() override; + void Draw(double smooth) override; }; diff --git a/source/games/blood/src/credits.cpp b/source/games/blood/src/credits.cpp index c18453352..90f9cbc9d 100644 --- a/source/games/blood/src/credits.cpp +++ b/source/games/blood/src/credits.cpp @@ -64,7 +64,7 @@ void playlogos() if (!userConfig.nologo) { - if (fileSystem.FindFile("logo.smk")) + if (fileSystem.FindFile("logo.smk") != -1) { jobs[job++] = { PlayVideo("logo.smk", &logosound[0], 0) }; } @@ -73,7 +73,7 @@ void playlogos() jobs[job++] = { Create(1), []() { sndStartSample("THUNDER2", 128, -1); } }; jobs[job++] = { Create(2050) }; } - if (fileSystem.FindFile("gti.smk")) + if (fileSystem.FindFile("gti.smk") != -1) { jobs[job++] = { PlayVideo("gti.smk", &logosound[2], 0) }; } diff --git a/source/games/duke/src/2d_d.cpp b/source/games/duke/src/2d_d.cpp index 28e268964..4b50d99bd 100644 --- a/source/games/duke/src/2d_d.cpp +++ b/source/games/duke/src/2d_d.cpp @@ -296,7 +296,7 @@ void Logo_d(const CompletionFunc &completion) if (!userConfig.nologo) { if (!isShareware()) jobs[job++] = { PlayVideo("logo.anm", logosound, logoframetimes), []() { S_PlaySpecialMusic(MUS_INTRO); } }; - else jobs[job++] = { Create(), []() { S_PlaySpecialMusic(MUS_INTRO); } }; + else jobs[job++] = { Create(1), []() { S_PlaySpecialMusic(MUS_INTRO); } }; if (!isNam()) jobs[job++] = { Create(), nullptr }; } else S_PlaySpecialMusic(MUS_INTRO); diff --git a/source/games/exhumed/src/gameloop.cpp b/source/games/exhumed/src/gameloop.cpp index cb05c6774..1028c1548 100644 --- a/source/games/exhumed/src/gameloop.cpp +++ b/source/games/exhumed/src/gameloop.cpp @@ -167,7 +167,7 @@ static void Intermission(MapRecord *from_map, MapRecord *to_map) showmap(from_map ? from_map->levelNumber : -1, to_map->levelNumber, nBestLevel, jobs); } else - jobs.Push({ Create() }); // we need something in here even in the multiplayer case. + jobs.Push({ Create(1) }); // we need something in here even in the multiplayer case. } } else diff --git a/source/games/exhumed/src/movie.cpp b/source/games/exhumed/src/movie.cpp index d26b9ce52..b743b473c 100644 --- a/source/games/exhumed/src/movie.cpp +++ b/source/games/exhumed/src/movie.cpp @@ -274,7 +274,7 @@ DScreenJob* PlayMovie(const char* fileName) auto fp = fileSystem.OpenFileReader(fileName); if (!fp.isOpen()) { - return Create(); + return Create(1); } char buffer[4]; fp.Read(buffer, 4);