Skip to content

Commit

Permalink
API: Access DED Finale definitions in the database directly
Browse files Browse the repository at this point in the history
The old Def_Get/Def_Set API mechanism for manipulating the finale defs
was removed as one can now access the finale def database directly.
  • Loading branch information
danij-deng committed Aug 19, 2014
1 parent 6789358 commit dd0de24
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 166 deletions.
6 changes: 3 additions & 3 deletions doomsday/api/dd_share.h
Expand Up @@ -200,9 +200,9 @@ enum {
DD_DEF_SECTOR_TYPE,
DD_PSPRITE_BOB_X,
DD_PSPRITE_BOB_Y,
DD_DEF_FINALE_AFTER,
DD_DEF_FINALE_BEFORE,
DD_DEF_FINALE,
DD_UNUSED19, // DD_DEF_FINALE_AFTER,
DD_UNUSED20, // DD_DEF_FINALE_BEFORE,
DD_UNUSED21, // DD_DEF_FINALE,
DD_RENDER_RESTART_PRE,
DD_RENDER_RESTART_POST,
DD_DEF_SOUND_BY_NAME,
Expand Down
9 changes: 3 additions & 6 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -720,11 +720,8 @@ D_CMD(Tutorial)
void DD_StartTitle()
{
#ifdef __CLIENT__
ddfinale_t fin;
if(!Def_Get(DD_DEF_FINALE, "background", &fin))
{
return;
}
Record const *finale = defs.finales.tryFind("id", "background");
if(!finale) return;

ddstring_t setupCmds; Str_Init(&setupCmds);

Expand All @@ -743,7 +740,7 @@ void DD_StartTitle()
Str_Appendf(&setupCmds, "precolor %i %f %f %f\n", i, color->red, color->green, color->blue);
}

titleFinale = FI_Execute2(fin.script, FF_LOCAL, Str_Text(&setupCmds));
titleFinale = FI_Execute2(finale->gets("script").toUtf8().constData(), FF_LOCAL, Str_Text(&setupCmds));
Str_Free(&setupCmds);
#endif
}
Expand Down
54 changes: 0 additions & 54 deletions doomsday/client/src/def_main.cpp
Expand Up @@ -1997,60 +1997,6 @@ int Def_Get(int type, char const *id, void *out)
if(out) *(char**) out = 0;
return false; }

case DD_DEF_FINALE: { // Find InFine script by ID.
finalescript_t *fin = (finalescript_t *) out;
for(int i = defs.finales.size() - 1; i >= 0; i--)
{
if(stricmp(defs.finales[i].id, id)) continue;

if(fin)
{
fin->before = (uri_s *)defs.finales[i].before;
fin->after = (uri_s *)defs.finales[i].after;
fin->script = defs.finales[i].script;
}
return true;
}
return false; }

case DD_DEF_FINALE_BEFORE: {
finalescript_t *fin = (finalescript_t *) out;
de::Uri *uri = new de::Uri(id, RC_NULL);
for(int i = defs.finales.size() - 1; i >= 0; i--)
{
if(!defs.finales[i].before || *defs.finales[i].before != *uri) continue;

if(fin)
{
fin->before = (uri_s *)defs.finales[i].before;
fin->after = (uri_s *)defs.finales[i].after;
fin->script = defs.finales[i].script;
}
delete uri;
return true;
}
delete uri;
return false; }

case DD_DEF_FINALE_AFTER: {
finalescript_t *fin = (finalescript_t *) out;
de::Uri *uri = new de::Uri(id, RC_NULL);
for(int i = defs.finales.size() - 1; i >= 0; i--)
{
if(!defs.finales[i].after || *defs.finales[i].after != *uri) continue;

if(fin)
{
fin->before = (uri_s *)defs.finales[i].before;
fin->after = (uri_s *)defs.finales[i].after;
fin->script = defs.finales[i].script;
}
delete uri;
return true;
}
delete uri;
return false; }

case DD_DEF_LINE_TYPE: {
int typeId = strtol(id, (char **)NULL, 10);
for(int i = defs.lineTypes.size() - 1; i >= 0; i--)
Expand Down
21 changes: 0 additions & 21 deletions doomsday/plugins/common/include/g_common.h
Expand Up @@ -104,22 +104,6 @@ bool G_SetGameActionLoadSession(de::String slotId);
*/
void G_SetGameActionMapCompleted(de::Uri const &nextMapUri, uint nextMapEntryPoint, dd_bool secretExit);

/**
* Returns the InFine @em briefing script for the specified @a mapUri; otherwise @c 0.
*
* @param mapUri Identifier of the map to lookup the briefing for. Can be @c 0 in which
* case the briefing for the @em current map will be returned.
*/
char const *G_InFineBriefing(de::Uri const *mapUri = 0);

/**
* Returns the InFine @em debriefing script for the specified @a mapUri; otherwise @c 0.
*
* @param mapUri Identifier of the map to lookup the debriefing for. Can be @c 0 in which
* case the debriefing for the @em current map will be returned.
*/
char const *G_InFineDebriefing(de::Uri const *mapUri = 0);

/**
* @param episodeId Identifier of the episode to lookup the title of. Can be @c 0 in
* which case the title for the @em current episode will be returned
Expand Down Expand Up @@ -148,11 +132,6 @@ patchid_t G_MapTitlePatch(de::Uri const *mapUri = 0);
extern "C" {
#endif

/**
* Returns the InFine script with the specified @a scriptId; otherwise @c 0.
*/
char const *G_InFine(char const *scriptId);

/**
* Reveal the game @em help display.
*/
Expand Down
19 changes: 11 additions & 8 deletions doomsday/plugins/common/src/fi_lib.cpp
Expand Up @@ -604,18 +604,21 @@ D_CMD(StartFinale)
{
DENG2_UNUSED2(src, argc);

// Only one active overlay allowed.
String scriptId = argv[1];

// Only one active overlay is allowed.
if(FI_StackActive()) return false;

ddfinale_t fin;
if(!Def_Get(DD_DEF_FINALE, argv[1], &fin))
if(Record const *finale = Defs().finales.tryFind("id", scriptId))
{
App_Log(DE2_SCR_ERROR, "Script '%s' is not defined.", argv[1]);
return false;
G_SetGameAction(GA_NONE);
FI_StackExecute(finale->gets("script").toUtf8().constData(), FF_LOCAL, FIMODE_OVERLAY);
return true;
}
G_SetGameAction(GA_NONE);
FI_StackExecute(fin.script, FF_LOCAL, FIMODE_OVERLAY);
return true;

LOG_SCR_ERROR("Script '%s' is not defined") << scriptId;
return false;

}

D_CMD(StopFinale)
Expand Down
109 changes: 40 additions & 69 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -1279,14 +1279,14 @@ void G_StartHelp()
return;
}

ddfinale_t fin;
if(Def_Get(DD_DEF_FINALE, "help", &fin))
char const *scriptId = "help";
if(Record const *finale = Defs().finales.tryFind("id", scriptId))
{
Hu_MenuCommand(MCMD_CLOSEFAST);
G_StartFinale(fin.script, FF_LOCAL, FIMODE_NORMAL, "help");
G_StartFinale(finale->gets("script").toUtf8().constData(), FF_LOCAL, FIMODE_NORMAL, scriptId);
return;
}
App_Log(DE2_SCR_WARNING, "InFine script 'help' not defined");
LOG_SCR_WARNING("InFine script '%s' not defined") << scriptId;
}

/**
Expand Down Expand Up @@ -2392,13 +2392,46 @@ void G_IntermissionBegin()
S_PauseMusic(false);
}

/**
* Lookup the debriefing Finale for the current episode and map (if any).
*/
static Record const *finaleDebriefing()
{
if(::briefDisabled) return 0;

#if __JHEXEN__
if(cfg.overrideHubMsg && G_GameState() == GS_MAP)
{
defn::Episode epsd(*COMMON_GAMESESSION->episodeDef());
Record const *currentHub = epsd.tryFindHubByMapId(::gameMapUri.compose());
if(currentHub != epsd.tryFindHubByMapId(::nextMapUri.compose()))
{
return 0;
}
}
#endif

// In a networked game the server will schedule the debrief.
if(IS_CLIENT || Get(DD_PLAYBACK)) return 0;

// If we're already in the INFINE state, don't start a finale.
if(G_GameState() == GS_INFINE) return 0;

// Is there such a finale definition?
return Defs().finales.tryFind("after", ::gameMapUri.compose());
}

/// @todo common::GameSession should handle this -ds
void G_IntermissionDone()
{
// We have left Intermission, however if there is an InFine for debriefing we should run it now.
if(G_StartFinale(G_InFineDebriefing()/*current map*/, 0, FIMODE_AFTER, 0))
if(Record const *finale = finaleDebriefing())
{
// The GA_ENDDEBRIEFING action is taken after the debriefing stops.
return;
if(G_StartFinale(finale->gets("script").toUtf8().constData(), 0, FIMODE_AFTER, 0))
{
// The GA_ENDDEBRIEFING action is taken after the debriefing stops.
return;
}
}

// We have either just returned from a debriefing or there wasn't one.
Expand Down Expand Up @@ -2649,68 +2682,6 @@ patchid_t G_MapTitlePatch(de::Uri const *mapUri)
return 0;
}

char const *G_InFine(char const *scriptId)
{
ddfinale_t fin;
if(Def_Get(DD_DEF_FINALE, scriptId, &fin))
{
return fin.script;
}
return 0;
}

char const *G_InFineBriefing(de::Uri const *mapUri)
{
if(!mapUri) mapUri = &gameMapUri;

// If we're already in the INFINE state, don't start a finale.
if(briefDisabled) return 0;

if(G_GameState() == GS_INFINE || IS_CLIENT || Get(DD_PLAYBACK))
return 0;

// Is there such a finale definition?
ddfinale_t fin;
if(Def_Get(DD_DEF_FINALE_BEFORE, mapUri->compose().toUtf8().constData(), &fin))
{
return fin.script;
}
return 0;
}

char const *G_InFineDebriefing(de::Uri const *mapUri)
{
if(!mapUri) mapUri = &::gameMapUri;

// If we're already in the INFINE state, don't start a finale.
if(briefDisabled) return 0;

#if __JHEXEN__
if(cfg.overrideHubMsg && G_GameState() == GS_MAP)
{
defn::Episode epsd(*COMMON_GAMESESSION->episodeDef());
Record const *currentHub = epsd.tryFindHubByMapId(::gameMapUri.compose());
if(currentHub != epsd.tryFindHubByMapId(::nextMapUri.compose()))
{
return 0;
}
}
#endif

if(G_GameState() == GS_INFINE || IS_CLIENT || Get(DD_PLAYBACK))
{
return 0;
}

// Is there such a finale definition?
ddfinale_t fin;
if(Def_Get(DD_DEF_FINALE_AFTER, mapUri->compose().toUtf8().constData(), &fin))
{
return fin.script;
}
return 0;
}

/**
* Stops both playback and a recording. Called at critical points like
* starting a new game, or ending the game in the menu.
Expand Down
27 changes: 22 additions & 5 deletions doomsday/plugins/common/src/gamesession.cpp
Expand Up @@ -84,6 +84,23 @@ namespace internal
SV_CloseFile();
return data;
}

/**
* Lookup the briefing Finale for the current episode and map (if any).
*/
static Record const *finaleBriefing()
{
if(::briefDisabled) return 0;

// In a networked game the server will schedule the brief.
if(IS_CLIENT || Get(DD_PLAYBACK)) return 0;

// If we're already in the INFINE state, don't start a finale.
if(G_GameState() == GS_INFINE) return 0;

// Is there such a finale definition?
return Defs().finales.tryFind("before", ::gameMapUri.compose());
}
}

using namespace internal;
Expand Down Expand Up @@ -518,9 +535,9 @@ DENG2_PIMPL(GameSession), public SavedSession::IMapStateReaderFactory
// Are we playing a briefing? (No, if we've already visited this map).
if(revisit)
{
briefDisabled = true;
::briefDisabled = true;
}
char const *briefing = G_InFineBriefing(); // current map
Record const *briefing = finaleBriefing();

// Restart the map music?
if(!briefing)
Expand Down Expand Up @@ -562,7 +579,7 @@ DENG2_PIMPL(GameSession), public SavedSession::IMapStateReaderFactory
reader->read(gameMapUriAsText);
}

if(!G_StartFinale(briefing, 0, FIMODE_BEFORE, 0))
if(!briefing || !G_StartFinale(briefing->gets("script").toUtf8().constData(), 0, FIMODE_BEFORE, 0))
{
// No briefing; begin the map.
HU_WakeWidgets(-1/* all players */);
Expand Down Expand Up @@ -938,9 +955,9 @@ void GameSession::endAndBeginTitle()
{
end();

if(char const *script = G_InFine("title"))
if(Record const *finale = Defs().finales.tryFind("id", "title"))
{
G_StartFinale(script, FF_LOCAL, FIMODE_NORMAL, "title");
G_StartFinale(finale->gets("script").toUtf8().constData(), FF_LOCAL, FIMODE_NORMAL, "title");
return;
}
/// @throw Error A title script must always be defined.
Expand Down

0 comments on commit dd0de24

Please sign in to comment.