- DBlackScreen and DImageScreen migrated to event-based handling.

This commit is contained in:
Christoph Oelckers 2021-04-16 00:11:02 +02:00
parent aad6158288
commit 6ed1d5e678
7 changed files with 44 additions and 30 deletions

View file

@ -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<DScreenJob>();
return Create<DBlackScreen>(1);
}
FString error;
auto movie = OpenMovie(filename, ans, frameticks, nosoundcutoff, error);
if (!movie)
{
Printf(TEXTCOLOR_YELLOW, "%s", error.GetChars());
return Create<DScreenJob>();
return Create<DBlackScreen>(1);
}
return Create<DMoviePlayer>(movie);
}

View file

@ -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;

View file

@ -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;
};

View file

@ -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<DBlackScreen>(1), []() { sndStartSample("THUNDER2", 128, -1); } };
jobs[job++] = { Create<DImageScreen>(2050) };
}
if (fileSystem.FindFile("gti.smk"))
if (fileSystem.FindFile("gti.smk") != -1)
{
jobs[job++] = { PlayVideo("gti.smk", &logosound[2], 0) };
}

View file

@ -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<DScreenJob>(), []() { S_PlaySpecialMusic(MUS_INTRO); } };
else jobs[job++] = { Create<DBlackScreen>(1), []() { S_PlaySpecialMusic(MUS_INTRO); } };
if (!isNam()) jobs[job++] = { Create<DDRealmsScreen>(), nullptr };
}
else S_PlaySpecialMusic(MUS_INTRO);

View file

@ -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<DScreenJob>() }); // we need something in here even in the multiplayer case.
jobs.Push({ Create<DBlackScreen>(1) }); // we need something in here even in the multiplayer case.
}
}
else

View file

@ -274,7 +274,7 @@ DScreenJob* PlayMovie(const char* fileName)
auto fp = fileSystem.OpenFileReader(fileName);
if (!fp.isOpen())
{
return Create<DScreenJob>();
return Create<DBlackScreen>(1);
}
char buffer[4];
fp.Read(buffer, 4);