raze-gles/source/core/screenjob.h

198 lines
4.3 KiB
C
Raw Normal View History

#pragma once
#include <functional>
2020-06-27 09:48:55 +00:00
#include "dobject.h"
#include "v_2ddrawer.h"
#include "d_eventbase.h"
#include "s_soundinternal.h"
2020-06-28 08:14:42 +00:00
using CompletionFunc = std::function<void(bool)>;
struct JobDesc;
class ScreenJobRunner;
2020-06-27 09:48:55 +00:00
#if 0
2020-06-27 09:48:55 +00:00
class DScreenJob : public DObject
{
DECLARE_CLASS(DScreenJob, DObject)
public:
const int flags;
const float fadetime; // in milliseconds
2020-07-03 07:59:24 +00:00
int fadestate = fadein;
friend class ScreenJobRunner;
//protected:
int ticks = 0;
int state = running;
bool pausable = true;
2020-06-27 09:48:55 +00:00
public:
enum
{
running = 1, // normal operation
skipped = 2, // finished by user skipping
finished = 3, // finished by completing its sequence
stopping = 4, // running ending animations / fadeout, etc. Will not accept more input.
stopped = 5, // we're done here.
};
enum
{
2020-07-03 07:59:24 +00:00
visible = 0,
fadein = 1,
fadeout = 2,
stopmusic = 4,
stopsound = 8,
};
DScreenJob(int fade = 0, float fadet = 250.f) : flags(fade), fadetime(fadet) {}
virtual bool ProcessInput()
{
return false;
}
virtual void Start() {}
virtual bool OnEvent(event_t* evt) { return false; }
virtual void OnTick() { /*state = finished;*/ }
virtual void Draw(double smoothratio) {}
int DrawFrame(double smoothratio)
{
2021-04-16 18:08:20 +00:00
if (state != running) smoothratio = 1; // this is necessary because the ticker won't be incremented anymore to avoid having a negative time span.
Draw(smoothratio);
if (state == skipped) return -1;
if (state == finished) return 0;
return 1;
}
2020-07-03 07:59:24 +00:00
int GetFadeState() const { return fadestate; }
virtual void OnDestroy() override;
2020-06-27 09:48:55 +00:00
};
2020-06-28 20:17:27 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
class DSkippableScreenJob : public DScreenJob
{
DECLARE_CLASS(DSkippableScreenJob, DScreenJob)
public:
DSkippableScreenJob(int fade = 0, float fadet = 250.f) : DScreenJob(fade, fadet)
{}
bool OnEvent(event_t* evt) override;
2021-04-16 16:43:59 +00:00
virtual void Skipped() {}
};
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
class DBlackScreen : public DScreenJob
{
DECLARE_CLASS(DBlackScreen, DScreenJob)
public:
int wait;
bool cleared = false;
public:
DBlackScreen(int w, int flags = 0) : DScreenJob(flags & ~(fadein|fadeout)), wait(w) {}
void OnTick() override;
void Draw(double smooth) override;
};
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
class DImageScreen : public DSkippableScreenJob
2020-06-28 20:17:27 +00:00
{
DECLARE_CLASS(DImageScreen, DScreenJob)
public:
2020-06-28 20:17:27 +00:00
int tilenum = -1;
int trans;
int waittime; // in ms.
bool cleared = false;
FTextureID texid;
2020-06-28 20:17:27 +00:00
FGameTexture* tex = nullptr;
public:
DImageScreen(FGameTexture* tile, int fade = DScreenJob::fadein | DScreenJob::fadeout, int wait = 3000, int translation = 0) : DSkippableScreenJob(fade), waittime(wait)
2020-06-28 20:17:27 +00:00
{
tex = tile;
trans = translation;
2020-06-28 20:17:27 +00:00
}
DImageScreen(int tile, int fade = DScreenJob::fadein | DScreenJob::fadeout, int wait = 3000, int translation = 0) : DSkippableScreenJob(fade), waittime(wait)
2020-06-28 20:17:27 +00:00
{
tilenum = tile;
trans = translation;
2020-06-28 20:17:27 +00:00
}
void OnTick() override;
void Draw(double smooth) override;
2020-06-28 20:17:27 +00:00
};
#endif
2020-06-28 20:17:27 +00:00
#if 0
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-06-28 20:17:27 +00:00
class ScreenJobRunner
{
enum
{
State_Clear,
State_Run,
State_Fadeout
};
2021-04-21 22:51:14 +00:00
TArray<DScreenJob*> 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:
2021-04-21 22:51:14 +00:00
ScreenJobRunner(TArray<DScreenJob*>& jobs, 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();
};
#endif
2021-04-21 22:18:53 +00:00
enum
{
SJ_BLOCKUI = 1,
2021-04-21 22:18:53 +00:00
};
#if 0
2020-06-27 09:48:55 +00:00
2021-04-21 22:51:14 +00:00
void RunScreenJob(TArray<DScreenJob*>& jobs, CompletionFunc completion, int flags = 0);
#endif
void EndScreenJob();
void DeleteScreenJob();
bool ScreenJobResponder(event_t* ev);
bool ScreenJobTick();
void ScreenJobDraw();