mirror of
https://github.com/ZDoom/Raze.git
synced 2025-02-07 15:31:11 +00:00
- put ScreenJobRunner declaration into header.
This commit is contained in:
parent
71e5f9b70f
commit
805b91b721
2 changed files with 233 additions and 181 deletions
|
@ -117,29 +117,9 @@ void DImageScreen::Draw(double smoothratio)
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
class ScreenJobRunner
|
ScreenJobRunner::ScreenJobRunner(JobDesc* jobs_, int count, CompletionFunc completion_, bool clearbefore_, bool skipall_)
|
||||||
{
|
|
||||||
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_)
|
|
||||||
: completion(std::move(completion_)), clearbefore(clearbefore_), skipall(skipall_)
|
: completion(std::move(completion_)), clearbefore(clearbefore_), skipall(skipall_)
|
||||||
{
|
{
|
||||||
jobs.Resize(count);
|
jobs.Resize(count);
|
||||||
memcpy(jobs.Data(), jobs_, count * sizeof(JobDesc));
|
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.
|
// 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();
|
jobs[i].job->Release();
|
||||||
}
|
}
|
||||||
AdvanceJob(false);
|
AdvanceJob(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
~ScreenJobRunner()
|
//---------------------------------------------------------------------------
|
||||||
{
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ScreenJobRunner::~ScreenJobRunner()
|
||||||
|
{
|
||||||
DeleteJobs();
|
DeleteJobs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeleteJobs()
|
void ScreenJobRunner::DeleteJobs()
|
||||||
{
|
{
|
||||||
for (auto& job : jobs)
|
for (auto& job : jobs)
|
||||||
{
|
{
|
||||||
job.job->ObjectFlags |= OF_YesReallyDelete;
|
job.job->ObjectFlags |= OF_YesReallyDelete;
|
||||||
delete job.job;
|
delete job.job;
|
||||||
}
|
}
|
||||||
jobs.Clear();
|
jobs.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdvanceJob(bool skip)
|
//---------------------------------------------------------------------------
|
||||||
{
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void ScreenJobRunner::AdvanceJob(bool skip)
|
||||||
|
{
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
{
|
{
|
||||||
//if (jobs[index].postAction) jobs[index].postAction();
|
//if (jobs[index].postAction) jobs[index].postAction();
|
||||||
|
@ -185,10 +177,16 @@ public:
|
||||||
jobs[index].job->Start();
|
jobs[index].job->Start();
|
||||||
}
|
}
|
||||||
inputState.ClearAllInput();
|
inputState.ClearAllInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DisplayFrame(double smoothratio)
|
//---------------------------------------------------------------------------
|
||||||
{
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
int ScreenJobRunner::DisplayFrame(double smoothratio)
|
||||||
|
{
|
||||||
auto& job = jobs[index];
|
auto& job = jobs[index];
|
||||||
auto now = I_GetTimeNS();
|
auto now = I_GetTimeNS();
|
||||||
bool processed = job.job->ProcessInput();
|
bool processed = job.job->ProcessInput();
|
||||||
|
@ -203,20 +201,26 @@ public:
|
||||||
int state = job.job->DrawFrame(smoothratio);
|
int state = job.job->DrawFrame(smoothratio);
|
||||||
twod->SetScreenFade(1.f);
|
twod->SetScreenFade(1.f);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FadeoutFrame(double smoothratio)
|
int ScreenJobRunner::FadeoutFrame(double smoothratio)
|
||||||
{
|
{
|
||||||
auto& job = jobs[index];
|
auto& job = jobs[index];
|
||||||
double ms = (fadeticks + smoothratio) * 1000 / GameTicRate / job.job->fadetime;
|
double ms = (fadeticks + smoothratio) * 1000 / GameTicRate / job.job->fadetime;
|
||||||
float screenfade = 1.f - (float)clamp(ms, 0., 1.);
|
float screenfade = 1.f - (float)clamp(ms, 0., 1.);
|
||||||
twod->SetScreenFade(screenfade);
|
twod->SetScreenFade(screenfade);
|
||||||
job.job->DrawFrame(1.);
|
job.job->DrawFrame(1.);
|
||||||
return (screenfade > 0.f);
|
return (screenfade > 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnEvent(event_t* ev)
|
//---------------------------------------------------------------------------
|
||||||
{
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool ScreenJobRunner::OnEvent(event_t* ev)
|
||||||
|
{
|
||||||
if (paused || index >= jobs.Size()) return false;
|
if (paused || index >= jobs.Size()) return false;
|
||||||
|
|
||||||
if (ev->type == EV_KeyDown)
|
if (ev->type == EV_KeyDown)
|
||||||
|
@ -233,16 +237,16 @@ public:
|
||||||
if (jobs[index].job->state != DScreenJob::running) return false;
|
if (jobs[index].job->state != DScreenJob::running) return false;
|
||||||
|
|
||||||
return jobs[index].job->OnEvent(ev);
|
return jobs[index].job->OnEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnFinished()
|
void ScreenJobRunner::OnFinished()
|
||||||
{
|
{
|
||||||
if (completion) completion(false);
|
if (completion) completion(false);
|
||||||
completion = nullptr; // only finish once.
|
completion = nullptr; // only finish once.
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnTick()
|
void ScreenJobRunner::OnTick()
|
||||||
{
|
{
|
||||||
if (paused) return;
|
if (paused) return;
|
||||||
if (index >= jobs.Size())
|
if (index >= jobs.Size())
|
||||||
{
|
{
|
||||||
|
@ -264,10 +268,16 @@ public:
|
||||||
fadeticks++;
|
fadeticks++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RunFrame()
|
//---------------------------------------------------------------------------
|
||||||
{
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool ScreenJobRunner::RunFrame()
|
||||||
|
{
|
||||||
if (index >= jobs.Size())
|
if (index >= jobs.Size())
|
||||||
{
|
{
|
||||||
DeleteJobs();
|
DeleteJobs();
|
||||||
|
@ -317,8 +327,13 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
ScreenJobRunner *runner;
|
ScreenJobRunner *runner;
|
||||||
|
|
||||||
|
|
|
@ -132,15 +132,52 @@ public:
|
||||||
void Draw(double smooth) override;
|
void Draw(double smooth) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
struct JobDesc
|
struct JobDesc
|
||||||
{
|
{
|
||||||
DScreenJob* job;
|
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
|
enum
|
||||||
{
|
{
|
||||||
SJ_DONTCLEAR = 1,
|
SJ_DONTCLEAR = 1,
|
||||||
|
|
Loading…
Reference in a new issue