2020-06-27 11:48:55 +02: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 09:46:41 +02:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "build.h"
|
2021-05-22 01:34:00 +02:00
|
|
|
#include "screenjob_.h"
|
2020-06-27 11:48:55 +02:00
|
|
|
#include "i_time.h"
|
|
|
|
#include "v_2ddrawer.h"
|
2020-06-28 00:32:28 +02:00
|
|
|
#include "animlib.h"
|
|
|
|
#include "v_draw.h"
|
|
|
|
#include "s_soundinternal.h"
|
|
|
|
#include "animtexture.h"
|
2020-07-19 12:48:31 +02:00
|
|
|
#include "gamestate.h"
|
2020-10-04 18:31:48 +02:00
|
|
|
#include "razemenu.h"
|
2020-07-26 18:02:24 +02:00
|
|
|
#include "raze_sound.h"
|
2020-07-28 21:05:14 +02:00
|
|
|
#include "gamecontrol.h"
|
2020-09-05 11:58:19 +02:00
|
|
|
#include "raze_music.h"
|
2021-04-22 18:52:39 +02:00
|
|
|
#include "vm.h"
|
2021-04-26 21:13:11 +02:00
|
|
|
#include "mapinfo.h"
|
|
|
|
|
|
|
|
static PType* maprecordtype;
|
|
|
|
static PType* summaryinfotype;
|
|
|
|
static int ticks;
|
2021-04-28 00:51:28 +02:00
|
|
|
static SummaryInfo summaryinfo;
|
2021-04-26 21:13:11 +02:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2020-06-20 09:46:41 +02:00
|
|
|
|
2021-05-22 01:34:00 +02:00
|
|
|
void Local_Job_Init()
|
2021-04-16 00:11:02 +02:00
|
|
|
{
|
2021-04-26 21:13:11 +02:00
|
|
|
maprecordtype = NewPointer(NewStruct("MapRecord", nullptr, true));
|
|
|
|
summaryinfotype = NewPointer(NewStruct("SummaryInfo", nullptr, true));
|
2020-07-29 23:18:08 +02:00
|
|
|
}
|
2021-04-26 21:13:11 +02:00
|
|
|
//=============================================================================
|
2021-04-22 00:35:48 +02:00
|
|
|
//
|
|
|
|
//
|
2021-04-26 21:13:11 +02:00
|
|
|
//
|
|
|
|
//=============================================================================
|
2021-04-22 00:35:48 +02:00
|
|
|
|
2021-05-23 14:36:54 +02:00
|
|
|
static void CallCreateMapFunction(const char* qname, DObject* runner, MapRecord* map)
|
2021-04-22 00:35:48 +02:00
|
|
|
{
|
2021-04-26 21:13:11 +02:00
|
|
|
auto func = LookupFunction(qname);
|
2021-04-28 00:51:28 +02:00
|
|
|
if (func->Proto->ArgumentTypes.Size() == 1) return CallCreateFunction(qname, runner); // accept functions without map parameter as well here.
|
2021-04-26 21:13:11 +02:00
|
|
|
if (func->Proto->ArgumentTypes.Size() != 2) I_Error("Bad map-cutscene function %s. Must receive precisely two arguments.", qname);
|
2022-06-06 15:28:41 +02:00
|
|
|
if (func->Proto->ArgumentTypes[0] != cutscene.runnerclasstype && func->Proto->ArgumentTypes[1] != maprecordtype)
|
2021-04-26 21:13:11 +02:00
|
|
|
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-22 00:35:48 +02:00
|
|
|
}
|
2020-07-19 12:48:31 +02:00
|
|
|
|
2021-04-26 21:13:11 +02:00
|
|
|
//=============================================================================
|
2021-04-22 00:35:48 +02:00
|
|
|
//
|
|
|
|
//
|
2021-04-26 21:13:11 +02:00
|
|
|
//
|
|
|
|
//=============================================================================
|
2021-04-22 00:35:48 +02:00
|
|
|
|
2021-04-30 16:21:37 +02:00
|
|
|
void CallCreateSummaryFunction(const char* qname, DObject* runner, MapRecord* map, SummaryInfo* info, MapRecord* map2)
|
2021-04-22 00:35:48 +02:00
|
|
|
{
|
2021-11-29 00:44:28 +01:00
|
|
|
if (qname == nullptr || *qname == 0) return; // no level summary defined.
|
2021-04-26 21:13:11 +02:00
|
|
|
auto func = LookupFunction(qname);
|
2021-04-30 16:21:37 +02: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);
|
2022-06-06 15:28:41 +02:00
|
|
|
if (at[0] != cutscene.runnerclasstype && at[1] != maprecordtype && at[2] != summaryinfotype && (s == 3 || at[3] == maprecordtype))
|
2021-04-30 16:21:37 +02:00
|
|
|
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-22 00:35:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-26 21:13:11 +02:00
|
|
|
//=============================================================================
|
2021-04-22 00:35:48 +02:00
|
|
|
//
|
|
|
|
//
|
2021-04-26 21:13:11 +02:00
|
|
|
//
|
|
|
|
//=============================================================================
|
2020-07-19 11:57:00 +02:00
|
|
|
|
2021-05-22 01:34:00 +02:00
|
|
|
bool CreateCutscene(CutsceneDef* cs, DObject* runner, MapRecord* map, bool transition)
|
2021-04-22 00:35:48 +02:00
|
|
|
{
|
2021-05-22 01:34:00 +02:00
|
|
|
if (!transition && cs->transitiononly) return false;
|
|
|
|
if (cs->function.CompareNoCase("none") == 0)
|
2021-04-28 00:51:28 +02:00
|
|
|
return true; // play nothing but return as being validated
|
2021-05-22 01:34:00 +02:00
|
|
|
if (cs->function.IsNotEmpty())
|
2021-04-26 22:56:37 +02:00
|
|
|
{
|
2021-05-22 01:34:00 +02:00
|
|
|
CallCreateMapFunction(cs->function, runner, map);
|
2021-04-28 00:51:28 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-05-22 01:34:00 +02:00
|
|
|
else if (cs->video.IsNotEmpty())
|
2021-04-28 00:51:28 +02:00
|
|
|
{
|
2021-05-22 01:34:00 +02:00
|
|
|
AddGenericVideo(runner, cs->video, cs->GetSound(), cs->framespersec);
|
2021-04-26 22:56:37 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2020-07-19 11:57:00 +02:00
|
|
|
}
|
2021-04-26 21:13:11 +02:00
|
|
|
|
2021-04-28 00:51:28 +02:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2020-07-19 11:57:00 +02:00
|
|
|
|
2021-04-26 22:56:37 +02: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-23 14:36:54 +02:00
|
|
|
if (!StartCutscene(globalCutscenes.Intro, SJ_BLOCKUI, [=](bool) {
|
2021-04-28 20:16:13 +02:00
|
|
|
gameaction = complete_ga;
|
|
|
|
})) gameaction = def_ga;
|
2021-04-26 22:56:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-28 00:51:28 +02:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ShowScoreboard(int numplayers, const CompletionFunc& completion_)
|
|
|
|
{
|
2022-06-06 15:28:41 +02:00
|
|
|
cutscene.completion = completion_;
|
|
|
|
cutscene.runner = CreateRunner();
|
|
|
|
Printf("Created runner at %p\n", cutscene.runner);
|
|
|
|
GC::WriteBarrier(cutscene.runner);
|
2021-04-28 00:51:28 +02:00
|
|
|
|
|
|
|
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);
|
2022-06-06 15:28:41 +02:00
|
|
|
if (func->Proto->ArgumentTypes[0] != cutscene.runnerclasstype && func->Proto->ArgumentTypes[1] != TypeSInt32)
|
2021-04-28 00:51:28 +02:00
|
|
|
I_Error("Bad cutscene function %s. Must receive ScreenJobRunner reference and integer.", qname);
|
2022-06-06 15:28:41 +02:00
|
|
|
VMValue val[2] = { cutscene.runner, numplayers };
|
2021-04-28 00:51:28 +02:00
|
|
|
VMCall(func, val, 2, nullptr, 0);
|
2021-04-28 00:59:07 +02:00
|
|
|
if (!ScreenJobValidate())
|
|
|
|
{
|
2022-06-06 15:28:41 +02:00
|
|
|
cutscene.runner->Destroy();
|
|
|
|
cutscene.runner = nullptr;
|
|
|
|
if (cutscene.completion) cutscene.completion(false);
|
|
|
|
cutscene.completion = nullptr;
|
2021-04-28 00:59:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-04-28 00:51:28 +02:00
|
|
|
gameaction = ga_intermission;
|
|
|
|
}
|
|
|
|
|
2021-04-28 01:15:15 +02:00
|
|
|
//---------------------------------------------------------------------------
|
2021-04-28 01:12:07 +02:00
|
|
|
//
|
2021-04-28 01:15:15 +02:00
|
|
|
//
|
2021-04-28 01:12:07 +02:00
|
|
|
//
|
2021-04-28 01:15:15 +02:00
|
|
|
//---------------------------------------------------------------------------
|
2021-04-28 01:12:07 +02:00
|
|
|
|
2021-04-28 01:15:15 +02:00
|
|
|
void ShowIntermission(MapRecord* fromMap, MapRecord* toMap, SummaryInfo* info, CompletionFunc completion_)
|
2021-04-28 01:12:07 +02:00
|
|
|
{
|
2022-06-06 15:28:41 +02:00
|
|
|
if (cutscene.runner != nullptr)
|
2022-01-15 19:20:58 +01:00
|
|
|
return; // protection against double exits.
|
2021-12-07 00:12:04 +01:00
|
|
|
if (fromMap == toMap)
|
|
|
|
{
|
|
|
|
// don't show intermission when restarting the same level.
|
|
|
|
completion_(false);
|
|
|
|
return;
|
|
|
|
}
|
2021-08-13 22:25:13 +02:00
|
|
|
bool bossexit = g_bossexit;
|
|
|
|
g_bossexit = false;
|
|
|
|
|
2022-06-06 15:28:41 +02:00
|
|
|
cutscene.completion = completion_;
|
|
|
|
cutscene.runner = CreateRunner();
|
|
|
|
GC::WriteBarrier(cutscene.runner);
|
2021-04-28 01:12:07 +02:00
|
|
|
|
2022-06-06 15:28:41 +02:00
|
|
|
// retrieve cluster relations for cluster-based cutscene.
|
2021-05-02 00:35:56 +02: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-28 01:12:07 +02:00
|
|
|
|
2022-06-06 15:28:41 +02:00
|
|
|
auto runner = cutscene.runner;
|
2021-04-28 00:51:28 +02:00
|
|
|
try
|
|
|
|
{
|
2021-08-13 22:25:13 +02:00
|
|
|
if (fromMap && (!(fromMap->gameflags & LEVEL_BOSSONLYCUTSCENE) || bossexit))
|
2021-04-28 00:51:28 +02:00
|
|
|
{
|
2021-05-22 01:34:00 +02:00
|
|
|
if (!CreateCutscene(&fromMap->outro, runner, fromMap, !!toMap))
|
2021-04-28 01:15:15 +02:00
|
|
|
{
|
2021-05-22 01:34:00 +02:00
|
|
|
if (fromcluster == nullptr || !CreateCutscene(&fromcluster->outro, runner, fromMap, !!toMap))
|
|
|
|
CreateCutscene(&globalCutscenes.DefaultMapOutro, runner, fromMap, !!toMap);
|
2021-04-28 01:15:15 +02:00
|
|
|
}
|
2021-04-28 00:51:28 +02:00
|
|
|
|
2021-04-28 01:15:15 +02:00
|
|
|
}
|
2021-04-30 16:21:37 +02:00
|
|
|
if (fromMap || (g_gameType & GAMEFLAG_PSEXHUMED))
|
|
|
|
CallCreateSummaryFunction(globalCutscenes.SummaryScreen, runner, fromMap, info, toMap);
|
2021-04-28 00:51:28 +02:00
|
|
|
|
2021-08-13 22:25:13 +02:00
|
|
|
if (toMap)
|
2021-04-28 00:51:28 +02:00
|
|
|
{
|
2021-05-22 01:34:00 +02:00
|
|
|
if (!CreateCutscene(&toMap->intro, runner, toMap, !!fromMap))
|
2021-04-28 01:15:15 +02:00
|
|
|
{
|
2021-05-22 01:34:00 +02:00
|
|
|
if (tocluster == nullptr || !CreateCutscene(&tocluster->intro, runner, toMap, !!fromMap))
|
|
|
|
CreateCutscene(&globalCutscenes.DefaultMapIntro, runner, toMap, !!fromMap);
|
2021-04-28 01:15:15 +02:00
|
|
|
}
|
2021-08-26 10:34:00 +10:00
|
|
|
// Skip the load screen if the level is started from the console or loading screens are disabled.
|
2021-05-12 00:36:04 +02:00
|
|
|
// 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.
|
2021-08-26 10:34:00 +10:00
|
|
|
if ((ConsoleState == c_up || ConsoleState == c_rising) && cl_loadingscreens)
|
2021-05-22 01:34:00 +02:00
|
|
|
CreateCutscene(&globalCutscenes.LoadingScreen, runner, toMap, true);
|
2021-04-28 00:51:28 +02:00
|
|
|
}
|
|
|
|
else if (isShareware())
|
|
|
|
{
|
|
|
|
globalCutscenes.SharewareEnd.Create(runner);
|
|
|
|
}
|
2021-04-28 00:59:07 +02:00
|
|
|
if (!ScreenJobValidate())
|
|
|
|
{
|
|
|
|
runner->Destroy();
|
2022-06-06 15:28:41 +02:00
|
|
|
cutscene.runner = nullptr;
|
|
|
|
if (cutscene.completion) cutscene.completion(false);
|
|
|
|
cutscene.completion = nullptr;
|
2021-04-28 00:59:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-04-28 00:51:28 +02:00
|
|
|
gameaction = ga_intermission;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2021-04-28 00:59:07 +02:00
|
|
|
if (runner) runner->Destroy();
|
2022-06-06 15:28:41 +02:00
|
|
|
cutscene.runner = nullptr;
|
2021-04-28 00:51:28 +02:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2021-05-22 01:34:00 +02:00
|
|
|
|