Skip to content

Commit

Permalink
- integration of cutscene stuff.
Browse files Browse the repository at this point in the history
It's mostly working but right now a bit unstable.
Definitely needs more testing.
  • Loading branch information
coelckers committed May 22, 2021
1 parent b800a2f commit 3815df7
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/common/cutscenes/screenjob.cpp
Expand Up @@ -156,7 +156,7 @@ void AddGenericVideo(DObject* runner, const FString& fn, int soundid, int fps)

int CutsceneDef::GetSound()
{
int id;
int id = -1;
if (soundName.IsNotEmpty()) id = soundEngine->FindSound(soundName);
if (id <= 0) id = soundEngine->FindSoundByResID(soundID);
return id;
Expand Down
1 change: 1 addition & 0 deletions src/d_event.h
Expand Up @@ -98,6 +98,7 @@ enum gameaction_t : int
ga_resumeconversation,
ga_intro,
ga_intermission,
ga_endscreenjob,
};

extern gameaction_t gameaction;
Expand Down
7 changes: 7 additions & 0 deletions src/d_main.cpp
Expand Up @@ -117,6 +117,7 @@
#include "texturemanager.h"
#include "hw_clock.h"
#include "hwrenderer/scene/hw_drawinfo.h"
#include "screenjob.h"

#ifdef __unix__
#include "i_system.h" // for SHARE_DIR
Expand Down Expand Up @@ -1103,6 +1104,11 @@ void D_Display ()
D_PageDrawer ();
break;

case GS_INTRO:
case GS_CUTSCENE:
ScreenJobDraw();
break;

default:
break;
}
Expand Down Expand Up @@ -3433,6 +3439,7 @@ static int D_DoomMain_Internal (void)

R_ParseTrnslate();
PClassActor::StaticInit ();
Job_Init();

// [GRB] Initialize player class list
SetupPlayerClasses ();
Expand Down
4 changes: 4 additions & 0 deletions src/d_net.cpp
Expand Up @@ -2247,6 +2247,10 @@ void Net_DoCommand (int type, uint8_t **stream, int player)
cht_SetInv(&players[player], s, i, !!ReadByte(stream));
break;

case DEM_ENDSCREENJOB:
gameaction = ga_endscreenjob;
break;

case DEM_WARPCHEAT:
{
int x, y, z;
Expand Down
1 change: 1 addition & 0 deletions src/d_protocol.h
Expand Up @@ -162,6 +162,7 @@ enum EDemoCommand
DEM_NETEVENT, // 70 String: Event name, Byte: Arg count; each arg is a 4-byte int
DEM_MDK, // 71 String: Damage type
DEM_SETINV, // 72 SetInventory
DEM_ENDSCREENJOB, // 73 end a cutscene.
};

// The following are implemented by cht_DoCheat in m_cheat.cpp
Expand Down
54 changes: 45 additions & 9 deletions src/g_game.cpp
Expand Up @@ -78,6 +78,7 @@
#include "s_music.h"
#include "p_setup.h"
#include "d_event.h"
#include "screenjob.h"

#include "v_video.h"
#include "g_hub.h"
Expand Down Expand Up @@ -966,6 +967,11 @@ CCMD (spycancel)
//
bool G_Responder (event_t *ev)
{
if (gamestate == GS_INTRO || gamestate == GS_CUTSCENE)
{
return ScreenJobResponder(ev);
}

// check events
if (ev->type != EV_Mouse && primaryLevel->localEventManager->Responder(ev)) // [ZZ] ZScript ate the event // update 07.03.17: mouse events are handled directly
return true;
Expand Down Expand Up @@ -1108,18 +1114,21 @@ void G_Ticker ()
int i;
gamestate_t oldgamestate;

// do player reborns if needed
for (i = 0; i < MAXPLAYERS; i++)
if (gamestate == GS_LEVEL || gamestate == GS_TITLELEVEL)
{
if (playeringame[i])
// do player reborns if needed
for (i = 0; i < MAXPLAYERS; i++)
{
if (players[i].playerstate == PST_GONE)
{
G_DoPlayerPop(i);
}
if (players[i].playerstate == PST_REBORN || players[i].playerstate == PST_ENTER)
if (playeringame[i])
{
primaryLevel->DoReborn(i, false);
if (players[i].playerstate == PST_GONE)
{
G_DoPlayerPop(i);
}
if (players[i].playerstate == PST_REBORN || players[i].playerstate == PST_ENTER)
{
primaryLevel->DoReborn(i, false);
}
}
}
}
Expand Down Expand Up @@ -1185,6 +1194,19 @@ void G_Ticker ()
shotfile = "";
gameaction = ga_nothing;
break;
case ga_intro:
wipegamestate = gamestate = GS_INTRO;
gameaction = ga_nothing;
break;
case ga_intermission:
wipegamestate = gamestate = GS_CUTSCENE;
gameaction = ga_nothing;
break;
case ga_endscreenjob:
EndScreenJob();
if (gameaction == ga_endscreenjob) gameaction = ga_nothing;
break;

case ga_fullconsole:
G_FullConsole ();
gameaction = ga_nothing;
Expand Down Expand Up @@ -1298,6 +1320,20 @@ void G_Ticker ()
WI_Ticker ();
break;

case GS_INTRO:
case GS_CUTSCENE:
if (intermissiondelay > 0)
{
intermissiondelay--;
break;
}
if (ScreenJobTick())
{
// synchronize termination with the playsim.
Net_WriteByte(DEM_ENDSCREENJOB);
}
break;

case GS_FINALE:
F_Ticker ();
break;
Expand Down
92 changes: 66 additions & 26 deletions src/g_level.cpp
Expand Up @@ -421,8 +421,8 @@ void G_DoNewGame (void)
{
gameskill = d_skill;
}
G_InitNew (d_mapname, false);
gameaction = ga_nothing;
G_InitNew (d_mapname, false);
}

//==========================================================================
Expand Down Expand Up @@ -824,7 +824,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, SecretExitLevel, LevelLocals_SecretE
//==========================================================================
static wbstartstruct_t staticWmInfo;

void G_DoCompleted (void)
void G_DoCompletedCont (bool)
{
gameaction = ga_nothing;

Expand Down Expand Up @@ -870,6 +870,22 @@ void G_DoCompleted (void)
}
}

void G_DoCompleted(void)
{
auto info = FindLevelInfo(nextlevel, false);
auto exitscene = &primaryLevel->info->exitScene;
if (!exitscene->isdefined())
{
if (info == nullptr || info->cluster != primaryLevel->cluster)
{
auto cluster = FindClusterInfo(primaryLevel->cluster);
if (cluster) exitscene = &cluster->exitScene;

}
}
if ((exitscene->transitiononly && info == nullptr) || !StartCutscene(primaryLevel->info->exitScene, 0, G_DoCompletedCont)) G_DoCompletedCont(false);
}

//==========================================================================
//
// Prepare the level to be exited and
Expand Down Expand Up @@ -1072,38 +1088,62 @@ extern gamestate_t wipegamestate;
void G_DoLoadLevel(const FString &nextmapname, int position, bool autosave, bool newGame)
{
gamestate_t oldgs = gamestate;
gamestate_t oldwgs = wipegamestate;

// Here the new level needs to be allocated.
primaryLevel->DoLoadLevel(nextmapname, position, autosave, newGame);

// Reset the global state for the new level.
if (wipegamestate == GS_LEVEL)
wipegamestate = GS_FORCEWIPE;

if (gamestate != GS_TITLELEVEL)
CutsceneDef sink;
CutsceneDef* def = &sink;
auto info = FindLevelInfo(nextmapname, false);
if (info)
{
gamestate = GS_LEVEL;
def = &info->enterScene;
if (!def->isdefined())
{
if (info->cluster != primaryLevel->cluster)
{
auto cluster = FindClusterInfo(info->cluster);
if (cluster) def = &cluster->enterScene;
}
}
}
auto completion = [=](bool)
{
gamestate = oldgs;
wipegamestate = oldwgs;
// Here the new level needs to be allocated.
primaryLevel->DoLoadLevel(nextmapname, position, autosave, newGame);

gameaction = ga_nothing;
// Reset the global state for the new level.
if (wipegamestate == GS_LEVEL)
wipegamestate = GS_FORCEWIPE;

// clear cmd building stuff
buttonMap.ResetButtonStates();
if (gamestate != GS_TITLELEVEL)
{
gamestate = GS_LEVEL;
}

SendItemUse = nullptr;
SendItemDrop = nullptr;
mousex = mousey = 0;
sendpause = sendsave = sendturn180 = SendLand = false;
LocalViewAngle = 0;
LocalViewPitch = 0;
paused = 0;
gameaction = ga_nothing;

// clear cmd building stuff
buttonMap.ResetButtonStates();

SendItemUse = nullptr;
SendItemDrop = nullptr;
mousex = mousey = 0;
sendpause = sendsave = sendturn180 = SendLand = false;
LocalViewAngle = 0;
LocalViewPitch = 0;
paused = 0;

if (demoplayback || oldgs == GS_STARTUP || oldgs == GS_TITLELEVEL)
C_HideConsole();

if (demoplayback || oldgs == GS_STARTUP || oldgs == GS_TITLELEVEL)
C_HideConsole();
C_FlushDisplay();
P_ResetSightCounters(true);
I_UpdateWindowTitle();
};

C_FlushDisplay();
P_ResetSightCounters(true);
I_UpdateWindowTitle();
if ((newGame && def->transitiononly) || !StartCutscene(*def, 0, completion))
completion(false);
}

void FLevelLocals::DoLoadLevel(const FString &nextmapname, int position, bool autosave, bool newGame)
Expand Down
41 changes: 41 additions & 0 deletions src/gamedata/g_mapinfo.cpp
Expand Up @@ -689,6 +689,30 @@ void FMapInfoParser::ParseExitMusic(FName formap, level_info_t *info)
}
}

//==========================================================================
//
//
//
//==========================================================================

void FMapInfoParser::ParseCutscene(CutsceneDef& cdef)
{
FString sound;
sc.MustGetStringName("{");
while (!sc.CheckString("}"))
{
sc.MustGetString();
if (sc.Compare("video")) { ParseAssign(); sc.MustGetString(); cdef.video = sc.String; cdef.function = ""; }
else if (sc.Compare("function")) { ParseAssign(); sc.SetCMode(false); sc.MustGetString(); sc.SetCMode(true); cdef.function = sc.String; cdef.video = ""; }
else if (sc.Compare("sound")) { ParseAssign(); sc.MustGetString(); cdef.soundName = sc.String; }
else if (sc.Compare("soundid")) { ParseAssign(); sc.MustGetNumber(); cdef.soundID = sc.Number; }
else if (sc.Compare("fps")) { ParseAssign(); sc.MustGetNumber(); cdef.framespersec = sc.Number; }
else if (sc.Compare("transitiononly")) cdef.transitiononly = true;
else if (sc.Compare("delete")) { cdef.function = "none"; cdef.video = ""; } // this means 'play nothing', not 'not defined'.
else if (sc.Compare("clear")) cdef = {};
}
}

//==========================================================================
//
//
Expand Down Expand Up @@ -845,6 +869,14 @@ void FMapInfoParser::ParseCluster()
{
clusterinfo->flags |= CLUSTER_EXITTEXTINLUMP;
}
else if (sc.Compare("enterscene"))
{
ParseCutscene(clusterinfo->enterScene);
}
else if (sc.Compare("exitscene"))
{
ParseCutscene(clusterinfo->exitScene);
}
else if (!ParseCloseBrace())
{
// Unknown
Expand Down Expand Up @@ -1540,6 +1572,15 @@ DEFINE_MAP_OPTION(loadacs, false)
info->acsName = parse.sc.String;
}

DEFINE_MAP_OPTION(enterscene, false)
{
parse.ParseCutscene(info->enterScene);
}

DEFINE_MAP_OPTION(exitscene, false)
{
parse.ParseCutscene(info->exitScene);
}

//==========================================================================
//
Expand Down
5 changes: 5 additions & 0 deletions src/gamedata/g_mapinfo.h
Expand Up @@ -39,6 +39,7 @@
#include "vectors.h"
#include "sc_man.h"
#include "file_zip.h"
#include "screenjob.h"

struct level_info_t;
struct cluster_info_t;
Expand Down Expand Up @@ -100,6 +101,7 @@ struct FMapInfoParser
void ParseExitText(FName formap, level_info_t *info);
void ParseExitMusic(FName formap, level_info_t *info);
void ParseExitBackdrop(FName formap, level_info_t *info, bool ispic);
void ParseCutscene(CutsceneDef& cdef);

void ParseCluster();
void ParseNextMap(FString &mapname);
Expand Down Expand Up @@ -393,6 +395,8 @@ struct level_info_t
FString acsName;
bool fs_nocheckposition;

CutsceneDef exitScene, enterScene;


level_info_t()
{
Expand Down Expand Up @@ -426,6 +430,7 @@ struct cluster_info_t
int cdtrack;
FString ClusterName;
unsigned int cdid;
CutsceneDef exitScene, enterScene;

void Reset();

Expand Down
4 changes: 2 additions & 2 deletions wadsrc/static/zscript/engine/screenjob.zs
Expand Up @@ -553,7 +553,7 @@ class ScreenJobRunner : Object
let font = generic_ui? NewSmallFont : SmallFont;

let linelen = hudwidth < 640 ? hudwidth * 0.9 - 40 : 560;
let lines = font.BreakLines(text, linelen);
let lines = font.BreakLines(text, int(linelen));

int count = lines.Count();
int height = 20 + font.GetHeight() * count;
Expand All @@ -573,7 +573,7 @@ class ScreenJobRunner : Object
y = hudheight * 0.9 - height;
if (y < 0) y = 0;

Screen.Dim(0, 0.5f, x * hscale, y * vscale, w * hscale, height * vscale);
Screen.Dim(0, 0.5f, int(x * hscale), int(y * vscale), int(w * hscale), int(height * vscale));
x += 20;
y += 10;

Expand Down

0 comments on commit 3815df7

Please sign in to comment.