- Duke's intro works, without fading.

This commit is contained in:
Christoph Oelckers 2021-04-26 23:10:38 +02:00
parent 1166b00af2
commit 26a7700579
7 changed files with 56 additions and 26 deletions

View file

@ -948,6 +948,7 @@ int RunGame()
LoadScripts();
StartScreen->Progress();
SetDefaultStrings();
Job_Init();
if (Args->CheckParm("-sounddebug"))
C_DoCommand("stat sounddebug");

View file

@ -333,6 +333,7 @@ static void GameTicker()
case GS_INTRO:
if (ScreenJobTick())
{
Printf("Sending event\n");
// synchronize termination with the playsim.
Net_WriteByte(DEM_ENDSCREENJOB);
}

View file

@ -86,14 +86,15 @@ class AnmPlayer : public MoviePlayer
int nextframetime = 0;
AnimTextures animtex;
const TArray<int> animSnd;
const int* frameTicks;
int frameTicks[3];
public:
bool isvalid() { return numframes > 0; }
AnmPlayer(FileReader& fr, TArray<int>& ans, const int *frameticks, int flags_)
: animSnd(std::move(ans)), frameTicks(frameticks)
: animSnd(std::move(ans))
{
memcpy(frameTicks, frameticks, 3 * sizeof(int));
flags = flags_;
buffer = fr.ReadPadded(1);
fr.Close();
@ -798,7 +799,7 @@ DEFINE_ACTION_FUNCTION(_MoviePlayer, Frame)
{
PARAM_SELF_STRUCT_PROLOGUE(MoviePlayer);
PARAM_FLOAT(clock);
self->Frame(int64_t(clock));
ACTION_RETURN_INT(self->Frame(int64_t(clock)));
return 0;
}

View file

@ -69,7 +69,7 @@ static int ticks;
//
//=============================================================================
static void Job_Init()
void Job_Init()
{
static bool done = false;
if (!done)
@ -215,6 +215,7 @@ bool StartCutscene(CutsceneDef& cs, int flags, CompletionFunc completion_)
{
completion = completion_;
runner = CreateRunner();
GC::WriteBarrier(runner);
cs.Create(runner);
gameaction = (flags & SJ_BLOCKUI) ? ga_intro : ga_intermission;
return true;
@ -225,12 +226,13 @@ bool StartCutscene(CutsceneDef& cs, int flags, CompletionFunc completion_)
void DeleteScreenJob()
{
runner->Destroy();
if (runner) runner->Destroy();
runner = nullptr;
}
void EndScreenJob()
{
Printf("EndScreenJob\n");
DeleteScreenJob();
if (completion) completion(false);
completion = nullptr;

View file

@ -10,6 +10,9 @@ using CompletionFunc = std::function<void(bool)>;
struct JobDesc;
class ScreenJobRunner;
void Job_Init();
#if 0
class DScreenJob : public DObject
{

View file

@ -26,7 +26,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
*/
//-------------------------------------------------------------------------
struct DukeCutscenes
class DukeCutscenes // Note: must be class, not struct, otherwise we cannot easily look up the methods from C++.
{
//---------------------------------------------------------------------------
//
@ -205,7 +205,7 @@ struct DukeCutscenes
static void BuildMPSummary(ScreenJobRunner runner, MapRecord map, SummaryInfo stats)
{
runner.Append(new("DukeMultiplayerBonusScreen").Init(playerswhenstarted));
runner.Append(new("DukeMultiplayerBonusScreen").Init(stats.playercount));
}
//---------------------------------------------------------------------------
@ -260,7 +260,7 @@ struct DukeCutscenes
}
struct RRCutscenes
class RRCutscenes
{
//---------------------------------------------------------------------------
@ -301,7 +301,7 @@ struct RRCutscenes
static void BuildE1End(ScreenJobRunner runner)
{
if (!isRRRA())
if (!Raze.isRRRA())
{
Array<int> soundinfo;
soundinfo.Pushv(1, RRSnd.CHKAMMO + 1);
@ -318,7 +318,7 @@ struct RRCutscenes
static void BuildE2End(ScreenJobRunner runner)
{
if (!isRRRA())
if (!Raze.isRRRA())
{
Array<int> soundinfo;
soundinfo.Pushv(1, RRSnd.LN_FINAL + 1);

View file

@ -7,15 +7,14 @@ class ScreenJob : Object
int ticks;
int jobstate;
bool pausable;
enum EJobState
{
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.
running = 0, // normal operation
skipped = 1, // finished by user skipping
finished = 2, // finished by completing its sequence
stopping = 3, // running ending animations / fadeout, etc. Will not accept more input.
stopped = 4, // we're done here.
};
enum EJobFlags
{
@ -31,7 +30,6 @@ class ScreenJob : Object
flags = fadet;
fadetime = fadet;
jobstate = running;
pausable = true;
}
virtual bool ProcessInput()
@ -78,8 +76,10 @@ class SkippableScreenJob : ScreenJob
override bool OnEvent(InputEvent evt)
{
Console.Printf("OnEvent");
if (evt.type == InputEvent.Type_KeyDown && !Raze.specialKeyEvent(evt))
{
Console.Printf("Skip requested");
jobstate = skipped;
OnSkip();
}
@ -230,7 +230,7 @@ struct MoviePlayer native
native static MoviePlayer Create(String filename, Array<int> soundinfo, int flags, int frametime, int firstframetime, int lastframetime);
native void Start();
native bool Frame(double clock);
native bool Destroy();
native void Destroy();
}
//---------------------------------------------------------------------------
@ -246,8 +246,8 @@ class MoviePlayerJob : SkippableScreenJob
ScreenJob Init(MoviePlayer mp)
{
Super.Init();
player = mp;
pausable = false;
return self;
}
@ -272,19 +272,25 @@ class MoviePlayerJob : SkippableScreenJob
override void Draw(double smoothratio)
{
Console.Printf("MoviePlayer.Draw state = %d", jobstate);
if (!player)
{
Console.Printf("MoviePlayer.Draw: end");
jobstate = stopped;
return;
}
if (!started)
{
Console.Printf("MoviePlayer.Draw: start");
started = true;
player.Start();
}
double clock = (ticks + smoothratio) * 1000000000. / GameTicRate;
Console.Printf("MoviePlayer.Frame %d %f", ticks, clock);
if (jobstate == running && !player.Frame(clock))
{
Console.Printf("MoviePlayer.finish");
jobstate = finished;
}
}
@ -352,6 +358,7 @@ class ScreenJobRunner : Object
void Append(ScreenJob job)
{
Console.Printf("Appending job of type " .. job.GetClassName() );
jobs.Push(job);
}
@ -365,6 +372,7 @@ class ScreenJobRunner : Object
{
if (index == jobs.Size()-1)
{
Console.Printf("AdvanceJob: reached end of list");
index++;
return; // we need to retain the last element until the runner is done.
}
@ -379,6 +387,7 @@ class ScreenJobRunner : Object
actionState = clearbefore ? State_Clear : State_Run;
if (index < jobs.Size())
{
Console.Printf("AdvanceJob: starting job at index %d, type %s", index, jobs[index].GetClassName());
jobs[index].fadestate = !paused && jobs[index].flags & ScreenJob.fadein? ScreenJob.fadein : ScreenJob.visible;
jobs[index].Start();
}
@ -406,6 +415,7 @@ class ScreenJobRunner : Object
double ms = (job.ticks + smoothratio) * 1000 / GameTicRate / job.fadetime;
double screenfade = clamp(ms, 0., 1.);
Screen.SetScreenFade(screenfade);
Console.Printf("DisplayFrame: fading in %s with %f", job.GetClassName(), screenfade);
if (screenfade == 1.) job.fadestate = ScreenJob.visible;
}
int state = job.DrawFrame(smoothratio);
@ -428,6 +438,7 @@ class ScreenJobRunner : Object
Screen.SetScreenFade(screenfade);
job.DrawFrame(1.);
Screen.SetScreenFade(1.);
Console.Printf("FadeoutFrame: fading out %s with %f", job.GetClassName(), screenfade);
return (screenfade > 0.);
}
@ -441,6 +452,7 @@ class ScreenJobRunner : Object
{
if (paused || index >= jobs.Size()) return false;
if (jobs[index].jobstate != ScreenJob.running) return false;
if (ev.type == InputEvent.Type_KeyDown) Console.Printf("OnEvent: dispatching key %d to job %s", ev.keyScan, jobs[index].GetClassName());
return jobs[index].OnEvent(ev);
}
@ -453,23 +465,26 @@ class ScreenJobRunner : Object
virtual bool OnTick()
{
if (paused) return false;
if (jobs.Size() == 0) return true;
if (advance)
if (index >= jobs.Size() || jobs.Size() == 0) return true;
if (advance || index < 0)
{
advance = false;
AdvanceJob(terminateState < 0);
if (index >= jobs.Size())
{
Console.Printf("OnTick: done");
return true;
}
}
if (jobs[index].jobstate == ScreenJob.running)
{
jobs[index].ticks++;
Console.Printf("OnTick: job %s, ticks = %d", jobs[index].GetClassName(), jobs[index].ticks);
jobs[index].OnTick();
}
else if (jobs[index].jobstate == ScreenJob.stopping)
{
Console.Printf("OnTick: fadeticks for %s", jobs[index].GetClassName());
fadeticks++;
}
return false;
@ -484,10 +499,14 @@ class ScreenJobRunner : Object
virtual bool RunFrame(double smoothratio)
{
// ensure that we won't go back in time if the menu is dismissed without advancing our ticker
bool menuon = paused;
if (menuon) last_paused_tic = jobs[index].ticks;
else if (last_paused_tic == jobs[index].ticks) menuon = true;
if (menuon || index >= jobs.Size()) smoothratio = 1.;
if (index < jobs.Size())
{
bool menuon = paused;
if (menuon) last_paused_tic = jobs[index].ticks;
else if (last_paused_tic == jobs[index].ticks) menuon = true;
if (menuon) smoothratio = 1.;
}
else smoothratio = 1.;
if (actionState == State_Clear)
{
@ -499,6 +518,8 @@ class ScreenJobRunner : Object
terminateState = DisplayFrame(smoothratio);
if (terminateState < 1 && index < jobs.Size())
{
Console.Printf("RunFrame: job %s, state %d", jobs[index].GetClassName(), terminateState);
if (jobs[index].flags & ScreenJob.fadeout)
{
jobs[index].fadestate = ScreenJob.fadeout;
@ -508,6 +529,7 @@ class ScreenJobRunner : Object
}
else
{
Console.Printf("RunState: advancing");
advance = true;
}
}