- put ScreenJobRunner declaration into header.

This commit is contained in:
Christoph Oelckers 2021-04-22 00:35:48 +02:00
parent 71e5f9b70f
commit 805b91b721
2 changed files with 233 additions and 181 deletions

View file

@ -117,29 +117,9 @@ void DImageScreen::Draw(double smoothratio)
//
//---------------------------------------------------------------------------
class ScreenJobRunner
{
enum
{
State_Clear,
State_Run,
State_Fadeout
};
TArray<JobDesc> jobs;
CompletionFunc completion;
int index = -1;
float screenfade;
bool clearbefore;
bool skipall;
int actionState;
int terminateState;
int fadeticks = 0;
int last_paused_tic = -1;
public:
ScreenJobRunner(JobDesc* jobs_, int count, CompletionFunc completion_, bool clearbefore_, bool skipall_)
ScreenJobRunner::ScreenJobRunner(JobDesc* jobs_, int count, CompletionFunc completion_, bool clearbefore_, bool skipall_)
: completion(std::move(completion_)), clearbefore(clearbefore_), skipall(skipall_)
{
{
jobs.Resize(count);
memcpy(jobs.Data(), jobs_, count * sizeof(JobDesc));
// Release all jobs from the garbage collector - the code as it is cannot deal with them getting collected. This should be removed later once the GC is working.
@ -148,25 +128,37 @@ public:
jobs[i].job->Release();
}
AdvanceJob(false);
}
}
~ScreenJobRunner()
{
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
ScreenJobRunner::~ScreenJobRunner()
{
DeleteJobs();
}
}
void DeleteJobs()
{
void ScreenJobRunner::DeleteJobs()
{
for (auto& job : jobs)
{
job.job->ObjectFlags |= OF_YesReallyDelete;
delete job.job;
}
jobs.Clear();
}
}
void AdvanceJob(bool skip)
{
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void ScreenJobRunner::AdvanceJob(bool skip)
{
if (index >= 0)
{
//if (jobs[index].postAction) jobs[index].postAction();
@ -185,10 +177,16 @@ public:
jobs[index].job->Start();
}
inputState.ClearAllInput();
}
}
int DisplayFrame(double smoothratio)
{
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int ScreenJobRunner::DisplayFrame(double smoothratio)
{
auto& job = jobs[index];
auto now = I_GetTimeNS();
bool processed = job.job->ProcessInput();
@ -203,20 +201,26 @@ public:
int state = job.job->DrawFrame(smoothratio);
twod->SetScreenFade(1.f);
return state;
}
}
int FadeoutFrame(double smoothratio)
{
int ScreenJobRunner::FadeoutFrame(double smoothratio)
{
auto& job = jobs[index];
double ms = (fadeticks + smoothratio) * 1000 / GameTicRate / job.job->fadetime;
float screenfade = 1.f - (float)clamp(ms, 0., 1.);
twod->SetScreenFade(screenfade);
job.job->DrawFrame(1.);
return (screenfade > 0.f);
}
}
bool OnEvent(event_t* ev)
{
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool ScreenJobRunner::OnEvent(event_t* ev)
{
if (paused || index >= jobs.Size()) return false;
if (ev->type == EV_KeyDown)
@ -233,16 +237,16 @@ public:
if (jobs[index].job->state != DScreenJob::running) return false;
return jobs[index].job->OnEvent(ev);
}
}
void OnFinished()
{
void ScreenJobRunner::OnFinished()
{
if (completion) completion(false);
completion = nullptr; // only finish once.
}
}
void OnTick()
{
void ScreenJobRunner::OnTick()
{
if (paused) return;
if (index >= jobs.Size())
{
@ -264,10 +268,16 @@ public:
fadeticks++;
}
}
}
}
bool RunFrame()
{
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool ScreenJobRunner::RunFrame()
{
if (index >= jobs.Size())
{
DeleteJobs();
@ -317,8 +327,13 @@ public:
}
}
return true;
}
};
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
ScreenJobRunner *runner;

View file

@ -132,15 +132,52 @@ public:
void Draw(double smooth) override;
};
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
struct JobDesc
{
DScreenJob* job;
//void (*postAction)();
};
class ScreenJobRunner
{
enum
{
State_Clear,
State_Run,
State_Fadeout
};
TArray<JobDesc> jobs;
CompletionFunc completion;
int index = -1;
float screenfade;
bool clearbefore;
bool skipall;
int actionState;
int terminateState;
int fadeticks = 0;
int last_paused_tic = -1;
public:
ScreenJobRunner(JobDesc* jobs_, int count, CompletionFunc completion_, bool clearbefore_, bool skipall_);
~ScreenJobRunner();
void DeleteJobs();
void AdvanceJob(bool skip);
int DisplayFrame(double smoothratio);
int FadeoutFrame(double smoothratio);
bool OnEvent(event_t* ev);
void OnFinished();
void OnTick();
bool RunFrame();
};
enum
{
SJ_DONTCLEAR = 1,