2020-06-27 09:48:55 +00:00
|
|
|
/*
|
|
|
|
** screenjob.cpp
|
|
|
|
**
|
|
|
|
** Generic asynchronous screen display
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2020 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
2020-06-20 07:46:41 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "build.h"
|
|
|
|
#include "screenjob.h"
|
2020-06-27 09:48:55 +00:00
|
|
|
#include "i_time.h"
|
|
|
|
#include "v_2ddrawer.h"
|
2020-06-27 22:32:28 +00:00
|
|
|
#include "animlib.h"
|
|
|
|
#include "v_draw.h"
|
|
|
|
#include "s_soundinternal.h"
|
|
|
|
#include "animtexture.h"
|
2020-07-19 10:48:31 +00:00
|
|
|
#include "gamestate.h"
|
2020-10-04 16:31:48 +00:00
|
|
|
#include "razemenu.h"
|
2020-07-26 16:02:24 +00:00
|
|
|
#include "raze_sound.h"
|
2020-07-29 21:18:08 +00:00
|
|
|
#include "SmackerDecoder.h"
|
2020-07-23 20:26:07 +00:00
|
|
|
#include "movie/playmve.h"
|
2020-07-28 19:05:14 +00:00
|
|
|
#include "gamecontrol.h"
|
2020-09-10 15:54:27 +00:00
|
|
|
#include <vpx/vpx_decoder.h>
|
|
|
|
#include <vpx/vp8dx.h>
|
2020-09-05 09:58:19 +00:00
|
|
|
#include "raze_music.h"
|
2021-04-22 16:52:39 +00:00
|
|
|
#include "vm.h"
|
2021-04-26 19:13:11 +00:00
|
|
|
#include "mapinfo.h"
|
|
|
|
|
|
|
|
static DObject* runner;
|
|
|
|
static SummaryInfo sinfo;
|
|
|
|
static PClass* runnerclass;
|
|
|
|
static PType* runnerclasstype;
|
|
|
|
static PType* maprecordtype;
|
|
|
|
static PType* summaryinfotype;
|
|
|
|
static CompletionFunc completion;
|
|
|
|
static int ticks;
|
2021-04-27 22:51:28 +00:00
|
|
|
static SummaryInfo summaryinfo;
|
2021-04-26 19:13:11 +00:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2020-06-20 07:46:41 +00:00
|
|
|
|
2021-04-26 21:10:38 +00:00
|
|
|
void Job_Init()
|
2021-04-15 22:11:02 +00:00
|
|
|
{
|
2021-04-26 19:13:11 +00:00
|
|
|
static bool done = false;
|
|
|
|
if (!done)
|
2021-04-15 22:11:02 +00:00
|
|
|
{
|
2021-04-26 19:13:11 +00:00
|
|
|
done = true;
|
|
|
|
GC::AddMarkerFunc([] { GC::Mark(runner); });
|
2021-04-15 22:11:02 +00:00
|
|
|
}
|
2021-04-26 19:13:11 +00:00
|
|
|
runnerclass = PClass::FindClass("ScreenJobRunner");
|
|
|
|
if (!runnerclass) I_FatalError("ScreenJobRunner not defined");
|
|
|
|
runnerclasstype = NewPointer(runnerclass);
|
2021-04-15 22:02:09 +00:00
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
maprecordtype = NewPointer(NewStruct("MapRecord", nullptr, true));
|
|
|
|
summaryinfotype = NewPointer(NewStruct("SummaryInfo", nullptr, true));
|
2020-07-29 21:18:08 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
//=============================================================================
|
2020-06-28 20:17:27 +00:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
2021-04-26 19:13:11 +00:00
|
|
|
//=============================================================================
|
2020-06-28 20:17:27 +00:00
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
static VMFunction* LookupFunction(const char* qname, bool validate = true)
|
2020-06-28 20:17:27 +00:00
|
|
|
{
|
2021-05-11 23:50:41 +00:00
|
|
|
size_t p = strcspn(qname, ".");
|
2021-04-26 19:13:11 +00:00
|
|
|
if (p == 0) I_Error("Call to undefined function %s", qname);
|
|
|
|
FString clsname(qname, p);
|
|
|
|
FString funcname = qname + p + 1;
|
|
|
|
|
|
|
|
auto func = PClass::FindFunction(clsname, funcname);
|
|
|
|
if (func == nullptr) I_Error("Call to undefined function %s", qname);
|
|
|
|
if (validate)
|
2020-09-04 19:17:24 +00:00
|
|
|
{
|
2021-04-26 19:13:11 +00:00
|
|
|
// these conditions must be met by all functions for this interface.
|
|
|
|
if (func->Proto->ReturnTypes.Size() != 0) I_Error("Bad cutscene function %s. Return value not allowed", qname);
|
|
|
|
if (func->ImplicitArgs != 0) I_Error("Bad cutscene function %s. Must be static", qname);
|
2020-09-04 19:17:24 +00:00
|
|
|
}
|
2021-04-26 19:13:11 +00:00
|
|
|
return func;
|
2021-04-15 22:11:02 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
2020-07-19 09:57:00 +00:00
|
|
|
//
|
|
|
|
//
|
2021-04-26 19:13:11 +00:00
|
|
|
//=============================================================================
|
2020-07-19 09:57:00 +00:00
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
void CallCreateFunction(const char* qname, DObject* runner)
|
2020-07-19 09:57:00 +00:00
|
|
|
{
|
2021-04-26 19:13:11 +00:00
|
|
|
auto func = LookupFunction(qname);
|
|
|
|
if (func->Proto->ArgumentTypes.Size() != 1) I_Error("Bad cutscene function %s. Must receive precisely one argument.", qname);
|
|
|
|
if (func->Proto->ArgumentTypes[0] != runnerclasstype) I_Error("Bad cutscene function %s. Must receive ScreenJobRunner reference.", qname);
|
|
|
|
VMValue val = runner;
|
|
|
|
VMCall(func, &val, 1, nullptr, 0);
|
2021-04-21 22:35:48 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
//=============================================================================
|
2021-04-21 22:35:48 +00:00
|
|
|
//
|
|
|
|
//
|
2021-04-26 19:13:11 +00:00
|
|
|
//
|
|
|
|
//=============================================================================
|
2021-04-21 22:35:48 +00:00
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
void CallCreateMapFunction(const char* qname, DObject* runner, MapRecord* map)
|
2021-04-21 22:35:48 +00:00
|
|
|
{
|
2021-04-26 19:13:11 +00:00
|
|
|
auto func = LookupFunction(qname);
|
2021-04-27 22:51:28 +00:00
|
|
|
if (func->Proto->ArgumentTypes.Size() == 1) return CallCreateFunction(qname, runner); // accept functions without map parameter as well here.
|
2021-04-26 19:13:11 +00:00
|
|
|
if (func->Proto->ArgumentTypes.Size() != 2) I_Error("Bad map-cutscene function %s. Must receive precisely two arguments.", qname);
|
|
|
|
if (func->Proto->ArgumentTypes[0] != runnerclasstype && func->Proto->ArgumentTypes[1] != maprecordtype)
|
|
|
|
I_Error("Bad cutscene function %s. Must receive ScreenJobRunner and MapRecord reference.", qname);
|
|
|
|
VMValue val[2] = { runner, map };
|
|
|
|
VMCall(func, val, 2, nullptr, 0);
|
2021-04-21 22:35:48 +00:00
|
|
|
}
|
2020-07-19 10:48:31 +00:00
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
//=============================================================================
|
2021-04-21 22:35:48 +00:00
|
|
|
//
|
|
|
|
//
|
2021-04-26 19:13:11 +00:00
|
|
|
//
|
|
|
|
//=============================================================================
|
2021-04-21 22:35:48 +00:00
|
|
|
|
2021-04-30 14:21:37 +00:00
|
|
|
void CallCreateSummaryFunction(const char* qname, DObject* runner, MapRecord* map, SummaryInfo* info, MapRecord* map2)
|
2021-04-21 22:35:48 +00:00
|
|
|
{
|
2021-04-26 19:13:11 +00:00
|
|
|
auto func = LookupFunction(qname);
|
2021-04-30 14:21:37 +00:00
|
|
|
auto s = func->Proto->ArgumentTypes.Size();
|
|
|
|
auto at = func->Proto->ArgumentTypes.Data();
|
|
|
|
if (s != 3 && s != 4) I_Error("Bad map-cutscene function %s. Must receive precisely three or four arguments.", qname);
|
|
|
|
if (at[0] != runnerclasstype && at[1] != maprecordtype && at[2] != summaryinfotype && (s == 3 || at[3] == maprecordtype))
|
|
|
|
I_Error("Bad cutscene function %s. Must receive ScreenJobRunner, MapRecord and SummaryInfo reference,", qname);
|
|
|
|
if (info) summaryinfo = *info; // must be copied to a persistent location.
|
|
|
|
else summaryinfo = {};
|
|
|
|
VMValue val[] = { runner, map, &summaryinfo, map2 };
|
|
|
|
VMCall(func, val, s, nullptr, 0);
|
2021-04-21 22:35:48 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
//=============================================================================
|
2021-04-21 22:35:48 +00:00
|
|
|
//
|
|
|
|
//
|
2021-04-26 19:13:11 +00:00
|
|
|
//
|
|
|
|
//=============================================================================
|
2020-07-19 09:57:00 +00:00
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
DObject* CreateRunner(bool clearbefore = true)
|
2021-04-21 22:35:48 +00:00
|
|
|
{
|
2021-04-26 19:13:11 +00:00
|
|
|
auto obj = runnerclass->CreateNew();
|
|
|
|
auto func = LookupFunction("ScreenJobRunner.Init", false);
|
|
|
|
VMValue val[3] = { obj, clearbefore, false };
|
|
|
|
VMCall(func, val, 3, nullptr, 0);
|
|
|
|
return obj;
|
2021-04-21 22:35:48 +00:00
|
|
|
}
|
2021-04-16 20:39:48 +00:00
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
//=============================================================================
|
2021-04-21 22:35:48 +00:00
|
|
|
//
|
|
|
|
//
|
2021-04-26 19:13:11 +00:00
|
|
|
//
|
|
|
|
//=============================================================================
|
2021-04-21 22:35:48 +00:00
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
void AddGenericVideo(DObject* runner, const FString& fn, int soundid, int fps)
|
2021-04-21 22:35:48 +00:00
|
|
|
{
|
2021-04-26 19:13:11 +00:00
|
|
|
auto obj = runnerclass->CreateNew();
|
|
|
|
auto func = LookupFunction("ScreenJobRunner.AddGenericVideo", false);
|
|
|
|
VMValue val[] = { runner, &fn, soundid, fps };
|
|
|
|
VMCall(func, val, 4, nullptr, 0);
|
2021-04-21 22:35:48 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
//=============================================================================
|
2021-04-21 22:35:48 +00:00
|
|
|
//
|
|
|
|
//
|
2021-04-26 19:13:11 +00:00
|
|
|
//
|
|
|
|
//=============================================================================
|
2021-04-21 22:35:48 +00:00
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
void CutsceneDef::Create(DObject* runner)
|
2021-04-21 22:35:48 +00:00
|
|
|
{
|
2021-04-26 20:56:37 +00:00
|
|
|
if (function.IsNotEmpty())
|
2021-04-21 22:35:48 +00:00
|
|
|
{
|
2021-04-26 20:56:37 +00:00
|
|
|
CallCreateFunction(function, runner);
|
|
|
|
}
|
|
|
|
else if (video.IsNotEmpty())
|
|
|
|
{
|
2021-05-02 16:10:59 +00:00
|
|
|
AddGenericVideo(runner, video, GetSound(), framespersec);
|
2021-04-21 22:35:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
//=============================================================================
|
2021-04-21 22:35:48 +00:00
|
|
|
//
|
|
|
|
//
|
2021-04-26 19:13:11 +00:00
|
|
|
//
|
|
|
|
//=============================================================================
|
2021-04-25 18:02:40 +00:00
|
|
|
|
2021-04-27 23:15:15 +00:00
|
|
|
bool CutsceneDef::Create(DObject* runner, MapRecord* map, bool transition)
|
2020-07-19 09:57:00 +00:00
|
|
|
{
|
2021-04-27 23:15:15 +00:00
|
|
|
if (!transition && transitiononly) return false;
|
2021-04-27 22:51:28 +00:00
|
|
|
if (function.CompareNoCase("none") == 0)
|
|
|
|
return true; // play nothing but return as being validated
|
|
|
|
if (function.IsNotEmpty())
|
2021-04-26 20:56:37 +00:00
|
|
|
{
|
2021-04-27 22:51:28 +00:00
|
|
|
CallCreateMapFunction(function, runner, map);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (video.IsNotEmpty())
|
|
|
|
{
|
2021-05-02 16:10:59 +00:00
|
|
|
AddGenericVideo(runner, video, GetSound(), framespersec);
|
2021-04-26 20:56:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2020-07-19 09:57:00 +00:00
|
|
|
}
|
2021-04-26 19:13:11 +00:00
|
|
|
|
2021-04-27 22:51:28 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2020-07-19 09:57:00 +00:00
|
|
|
|
2020-07-19 10:48:31 +00:00
|
|
|
void DeleteScreenJob()
|
2020-07-19 09:57:00 +00:00
|
|
|
{
|
2021-04-26 21:10:38 +00:00
|
|
|
if (runner) runner->Destroy();
|
2021-04-26 19:13:11 +00:00
|
|
|
runner = nullptr;
|
2020-07-19 10:48:31 +00:00
|
|
|
}
|
2020-07-19 09:57:00 +00:00
|
|
|
|
2021-04-15 22:50:13 +00:00
|
|
|
void EndScreenJob()
|
|
|
|
{
|
|
|
|
DeleteScreenJob();
|
2021-04-26 19:13:11 +00:00
|
|
|
if (completion) completion(false);
|
|
|
|
completion = nullptr;
|
2021-04-15 22:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-27 22:51:28 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2021-04-15 22:50:13 +00:00
|
|
|
bool ScreenJobResponder(event_t* ev)
|
|
|
|
{
|
2021-04-25 18:02:40 +00:00
|
|
|
if (ev->type == EV_KeyDown)
|
|
|
|
{
|
|
|
|
// We never reach the key binding checks in G_Responder, so for the console we have to check for ourselves here.
|
|
|
|
auto binding = Bindings.GetBinding(ev->data1);
|
|
|
|
if (binding.CompareNoCase("toggleconsole") == 0)
|
|
|
|
{
|
|
|
|
C_ToggleConsole();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2021-04-26 19:13:11 +00:00
|
|
|
FInputEvent evt = ev;
|
|
|
|
if (runner)
|
|
|
|
{
|
|
|
|
IFVIRTUALPTRNAME(runner, NAME_ScreenJobRunner, OnEvent)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
VMValue parm[] = { runner, &evt };
|
|
|
|
VMReturn ret(&result);
|
|
|
|
VMCall(func, parm, 2, &ret, 1);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2021-04-15 22:50:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-27 22:51:28 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
bool ScreenJobTick()
|
2021-04-15 22:50:13 +00:00
|
|
|
{
|
2021-04-26 19:13:11 +00:00
|
|
|
ticks++;
|
|
|
|
if (runner)
|
|
|
|
{
|
|
|
|
IFVIRTUALPTRNAME(runner, NAME_ScreenJobRunner, OnTick)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
VMValue parm[] = { runner };
|
2021-04-26 21:21:16 +00:00
|
|
|
VMReturn ret(&result);
|
|
|
|
VMCall(func, parm, 1, &ret, 1);
|
2021-04-26 19:13:11 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2021-04-15 22:50:13 +00:00
|
|
|
}
|
|
|
|
|
2021-04-27 22:51:28 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2021-04-26 19:13:11 +00:00
|
|
|
void ScreenJobDraw()
|
2020-07-19 10:48:31 +00:00
|
|
|
{
|
2021-04-26 19:13:11 +00:00
|
|
|
double smoothratio = I_GetTimeFrac();
|
|
|
|
|
|
|
|
if (runner)
|
2020-07-26 10:43:32 +00:00
|
|
|
{
|
2021-04-27 22:51:28 +00:00
|
|
|
twod->ClearScreen();
|
2021-04-26 19:13:11 +00:00
|
|
|
IFVIRTUALPTRNAME(runner, NAME_ScreenJobRunner, RunFrame)
|
|
|
|
{
|
|
|
|
VMValue parm[] = { runner, smoothratio };
|
|
|
|
VMCall(func, parm, 2, nullptr, 0);
|
|
|
|
}
|
2020-07-26 10:43:32 +00:00
|
|
|
}
|
2020-07-19 09:57:00 +00:00
|
|
|
}
|
2021-04-26 20:56:37 +00:00
|
|
|
|
2021-04-27 22:51:28 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2021-04-27 22:59:07 +00:00
|
|
|
bool ScreenJobValidate()
|
|
|
|
{
|
|
|
|
if (runner)
|
|
|
|
{
|
|
|
|
IFVIRTUALPTRNAME(runner, NAME_ScreenJobRunner, Validate)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
VMValue parm[] = { runner };
|
|
|
|
VMReturn ret(&res);
|
|
|
|
VMCall(func, parm, 2, &ret, 1);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
2021-04-27 22:51:28 +00:00
|
|
|
bool StartCutscene(CutsceneDef& cs, int flags, const CompletionFunc& completion_)
|
|
|
|
{
|
2021-04-28 18:16:13 +00:00
|
|
|
if ((cs.function.IsNotEmpty() || cs.video.IsNotEmpty()) && cs.function.CompareNoCase("none") != 0)
|
2021-04-27 22:51:28 +00:00
|
|
|
{
|
|
|
|
completion = completion_;
|
|
|
|
runner = CreateRunner();
|
|
|
|
GC::WriteBarrier(runner);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
cs.Create(runner);
|
2021-04-27 22:59:07 +00:00
|
|
|
if (!ScreenJobValidate())
|
|
|
|
{
|
|
|
|
runner->Destroy();
|
|
|
|
runner = nullptr;
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-01 17:46:17 +00:00
|
|
|
if (flags & SJ_DELAY) intermissiondelay = 10; // need to wait a bit at the start to let the timer catch up.
|
|
|
|
else intermissiondelay = 0;
|
2021-04-27 22:59:07 +00:00
|
|
|
gameaction = (flags & SJ_BLOCKUI) ? ga_intro : ga_intermission;
|
2021-04-27 22:51:28 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2021-04-27 22:59:07 +00:00
|
|
|
if (runner) runner->Destroy();
|
2021-04-27 22:51:28 +00:00
|
|
|
runner = nullptr;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StartCutscene(const char* s, int flags, const CompletionFunc& completion)
|
|
|
|
{
|
|
|
|
CutsceneDef def;
|
|
|
|
def.function = s;
|
|
|
|
return StartCutscene(def, 0, completion);
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2021-04-26 20:56:37 +00:00
|
|
|
|
|
|
|
void PlayLogos(gameaction_t complete_ga, gameaction_t def_ga, bool stopmusic)
|
|
|
|
{
|
|
|
|
Mus_Stop();
|
|
|
|
FX_StopAllSounds(); // JBF 20031228
|
|
|
|
if (userConfig.nologo)
|
|
|
|
{
|
|
|
|
gameaction = def_ga;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-01 17:46:17 +00:00
|
|
|
if (!StartCutscene(globalCutscenes.Intro, SJ_BLOCKUI|SJ_DELAY, [=](bool) {
|
2021-04-28 18:16:13 +00:00
|
|
|
gameaction = complete_ga;
|
|
|
|
})) gameaction = def_ga;
|
2021-04-26 20:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 22:51:28 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ShowScoreboard(int numplayers, const CompletionFunc& completion_)
|
|
|
|
{
|
|
|
|
completion = completion_;
|
|
|
|
runner = CreateRunner();
|
|
|
|
GC::WriteBarrier(runner);
|
|
|
|
|
|
|
|
const char* qname = globalCutscenes.MPSummaryScreen;
|
|
|
|
auto func = LookupFunction(qname);
|
|
|
|
if (func->Proto->ArgumentTypes.Size() != 2) I_Error("Bad map-cutscene function %s. Must receive precisely two arguments.", qname);
|
|
|
|
if (func->Proto->ArgumentTypes[0] != runnerclasstype && func->Proto->ArgumentTypes[1] != TypeSInt32)
|
|
|
|
I_Error("Bad cutscene function %s. Must receive ScreenJobRunner reference and integer.", qname);
|
|
|
|
VMValue val[2] = { runner, numplayers };
|
|
|
|
VMCall(func, val, 2, nullptr, 0);
|
2021-04-27 22:59:07 +00:00
|
|
|
if (!ScreenJobValidate())
|
|
|
|
{
|
|
|
|
runner->Destroy();
|
|
|
|
runner = nullptr;
|
|
|
|
if (completion) completion(false);
|
|
|
|
completion = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
2021-04-27 22:51:28 +00:00
|
|
|
gameaction = ga_intermission;
|
|
|
|
}
|
|
|
|
|
2021-04-27 23:15:15 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2021-04-27 23:12:07 +00:00
|
|
|
//
|
2021-04-27 23:15:15 +00:00
|
|
|
//
|
2021-04-27 23:12:07 +00:00
|
|
|
//
|
2021-04-27 23:15:15 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2021-04-27 23:12:07 +00:00
|
|
|
|
2021-04-27 23:15:15 +00:00
|
|
|
void ShowIntermission(MapRecord* fromMap, MapRecord* toMap, SummaryInfo* info, CompletionFunc completion_)
|
2021-04-27 23:12:07 +00:00
|
|
|
{
|
2021-04-27 23:15:15 +00:00
|
|
|
completion = completion_;
|
2021-04-27 23:12:07 +00:00
|
|
|
runner = CreateRunner();
|
|
|
|
GC::WriteBarrier(runner);
|
|
|
|
|
2021-04-27 23:15:15 +00:00
|
|
|
// retrieve cluster relations for cluster-based cutscenes.
|
2021-05-01 22:35:56 +00:00
|
|
|
ClusterDef* fromcluster = nullptr, *tocluster = nullptr;
|
|
|
|
if (fromMap) fromcluster = FindCluster(fromMap->cluster);
|
|
|
|
if (toMap) tocluster = FindCluster(toMap->cluster);
|
|
|
|
if (fromcluster == tocluster) fromcluster = tocluster = nullptr;
|
2021-04-27 23:12:07 +00:00
|
|
|
|
2021-04-27 22:51:28 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-04-27 23:15:15 +00:00
|
|
|
if (fromMap)
|
2021-04-27 22:51:28 +00:00
|
|
|
{
|
2021-04-27 23:15:15 +00:00
|
|
|
if (!fromMap->outro.Create(runner, fromMap, !!toMap))
|
|
|
|
{
|
2021-05-02 12:01:10 +00:00
|
|
|
if (fromcluster == nullptr || !fromcluster->outro.Create(runner, fromMap, !!toMap))
|
2021-04-27 23:15:15 +00:00
|
|
|
globalCutscenes.DefaultMapOutro.Create(runner, fromMap, !!toMap);
|
|
|
|
}
|
2021-04-27 22:51:28 +00:00
|
|
|
|
2021-04-27 23:15:15 +00:00
|
|
|
}
|
2021-04-30 14:21:37 +00:00
|
|
|
if (fromMap || (g_gameType & GAMEFLAG_PSEXHUMED))
|
|
|
|
CallCreateSummaryFunction(globalCutscenes.SummaryScreen, runner, fromMap, info, toMap);
|
2021-04-27 22:51:28 +00:00
|
|
|
|
|
|
|
if (toMap)
|
|
|
|
{
|
2021-04-27 23:15:15 +00:00
|
|
|
if (!toMap->intro.Create(runner, toMap, !!fromMap))
|
|
|
|
{
|
2021-05-02 12:01:10 +00:00
|
|
|
if (tocluster == nullptr || !tocluster->intro.Create(runner, toMap, !!fromMap))
|
2021-04-27 23:15:15 +00:00
|
|
|
globalCutscenes.DefaultMapIntro.Create(runner, toMap, !!fromMap);
|
|
|
|
}
|
2021-05-11 22:36:04 +00:00
|
|
|
// Skip the load screen if the level is started from the console.
|
|
|
|
// In this case the load screen is not helpful as it blocks the actual level start,
|
|
|
|
// requiring closing and reopening the console first before entering any commands that need the level.
|
|
|
|
if (ConsoleState == c_up || ConsoleState == c_rising)
|
|
|
|
globalCutscenes.LoadingScreen.Create(runner, toMap, true);
|
2021-04-27 22:51:28 +00:00
|
|
|
}
|
|
|
|
else if (isShareware())
|
|
|
|
{
|
|
|
|
globalCutscenes.SharewareEnd.Create(runner);
|
|
|
|
}
|
2021-04-27 22:59:07 +00:00
|
|
|
if (!ScreenJobValidate())
|
|
|
|
{
|
|
|
|
runner->Destroy();
|
|
|
|
runner = nullptr;
|
|
|
|
if (completion) completion(false);
|
|
|
|
completion = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
2021-04-27 22:51:28 +00:00
|
|
|
gameaction = ga_intermission;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2021-04-27 22:59:07 +00:00
|
|
|
if (runner) runner->Destroy();
|
2021-04-27 22:51:28 +00:00
|
|
|
runner = nullptr;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2021-04-26 22:01:25 +00:00
|
|
|
|
|
|
|
CCMD(testcutscene)
|
|
|
|
{
|
|
|
|
if (argv.argc() < 2)
|
|
|
|
{
|
|
|
|
Printf("Usage: testcutscene <buildfunction>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
2021-04-27 23:12:07 +00:00
|
|
|
if (StartCutscene(argv[1], 0, [](bool) {}))
|
2021-04-26 22:01:25 +00:00
|
|
|
{
|
|
|
|
C_HideConsole();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const CRecoverableError& err)
|
|
|
|
{
|
2021-04-27 22:51:28 +00:00
|
|
|
Printf(TEXTCOLOR_RED "Unable to play cutscene: %s\n", err.what());
|
2021-04-26 22:01:25 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-27 22:51:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-26 20:56:37 +00:00
|
|
|
/*
|
|
|
|
Blood:
|
|
|
|
if (!userConfig.nologo && gGameOptions.nGameType == 0) playlogos();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gameaction = ga_mainmenu;
|
|
|
|
}
|
|
|
|
RunScreenJob(jobs, [](bool) {
|
|
|
|
Mus_Stop();
|
|
|
|
gameaction = ga_mainmenu;
|
|
|
|
}, SJ_BLOCKUI);
|
|
|
|
|
|
|
|
Exhumed:
|
|
|
|
if (!userConfig.nologo) DoTitle([](bool) { gameaction = ga_mainmenu; });
|
|
|
|
else gameaction = ga_mainmenu;
|
|
|
|
|
|
|
|
SW:
|
|
|
|
if (!userConfig.nologo) Logo([](bool)
|
|
|
|
{
|
|
|
|
gameaction = ga_mainmenunostopsound;
|
|
|
|
});
|
|
|
|
else gameaction = ga_mainmenu;
|
|
|
|
|
|
|
|
*/
|