Skip to content

Commit

Permalink
Refactor: Removed R_SetupMap() mode DDSMM_AFTER_BUSY
Browse files Browse the repository at this point in the history
Enhanced public API type ddmapinfo_t to also include the fog setup
properties and exported the R_SetupFog() and R_SetupFogDefaults()
routines.

It is now libcommon's G_DoLoadMap() responsiblity to setup the fog
appropriately for the map.
  • Loading branch information
danij-deng committed Jul 11, 2012
1 parent c8869a3 commit 4b375c6
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 26 deletions.
1 change: 0 additions & 1 deletion doomsday/engine/api/dd_share.h
Expand Up @@ -759,7 +759,6 @@ enum {
DDSMM_AFTER_LOADING, ///< After loading a savegame...
DDSMM_FINALIZE, ///< After everything else is done.
DDSMM_INITIALIZE, ///< Before anything else if done.
DDSMM_AFTER_BUSY ///< After leaving busy mode, which was used during setup.
};

/// Sector reverb data indices. @ingroup map
Expand Down
4 changes: 4 additions & 0 deletions doomsday/engine/api/def_share.h
Expand Up @@ -113,6 +113,10 @@ typedef struct {
float ambient;
float gravity;
float parTime;
float fogColor[3]; // Fog color (RGB).
float fogStart;
float fogEnd;
float fogDensity;
} ddmapinfo_t;

typedef struct {
Expand Down
4 changes: 3 additions & 1 deletion doomsday/engine/api/doomsday.def
@@ -1,6 +1,6 @@
; Doomsday Engine API (Routines exported from Doomsday.exe).
;
; Highest ordinal is currently: --> 853 <--
; Highest ordinal is currently: --> 855 <--
; Other free ordinals: 57

NAME "DOOMSDAY"
Expand Down Expand Up @@ -640,6 +640,8 @@ EXPORTS
DD_GetFrameRate @88 NONAME

R_SetupMap @89 NONAME
R_SetupFogDefaults @854 NONAME
R_SetupFog @855 NONAME

R_PrecacheMobjNum @427 NONAME
R_PrecacheModelsForState @240 NONAME
Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -584,6 +584,8 @@ boolean DD_IsSharpTick(void);
int DD_GetFrameRate(void);

void R_SetupMap(int mode, int flags);
void R_SetupFogDefaults(void);
void R_SetupFog(float start, float end, float density, float* rgb);

void R_PrecacheMobjNum(int mobjtypeNum);
void R_PrecacheModelsForState(int stateIndex);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/include/r_world.h
Expand Up @@ -60,8 +60,8 @@ extern boolean ddMapSetup;
*/
void R_SetupMap(int mode, int flags);

void R_SetupFog(float start, float end, float density, float* rgb);
void R_SetupFogDefaults(void);
void R_SetupFogDefaults(void);
void R_SetupFog(float start, float end, float density, float* rgb);

/**
* Sector light color may be affected by the sky light color.
Expand Down
8 changes: 6 additions & 2 deletions doomsday/engine/portable/src/def_main.c
Expand Up @@ -1755,8 +1755,12 @@ int Def_Get(int type, const char* id, void* out)
mout->ambient = map->ambient;
mout->gravity = map->gravity;
mout->parTime = map->parTime;
return true;
}
mout->fogStart = map->fogStart;
mout->fogEnd = map->fogEnd;
mout->fogDensity = map->fogDensity;
memcpy(mout->fogColor, map->fogColor, sizeof(mout->fogColor));
return true; }

case DD_DEF_TEXT:
if(id && id[0])
{
Expand Down
15 changes: 3 additions & 12 deletions doomsday/engine/portable/src/r_world.c
Expand Up @@ -886,6 +886,7 @@ lineowner_t* R_GetVtxLineOwner(const Vertex *v, const LineDef *line)
return NULL;
}

/// @note Part of the Doomsday public API.
void R_SetupFog(float start, float end, float density, float *rgb)
{
Con_Execute(CMDS_DDAY, "fog on", true, false);
Expand All @@ -896,6 +897,7 @@ void R_SetupFog(float start, float end, float density, float *rgb)
rgb[0] * 255, rgb[1] * 255, rgb[2] * 255);
}

/// @note Part of the Doomsday public API.
void R_SetupFogDefaults(void)
{
// Go with the defaults.
Expand Down Expand Up @@ -1437,21 +1439,10 @@ void R_SetupMap(int mode, int flags)
Z_PrintStatus();
return;
}
case DDSMM_AFTER_BUSY: {
// Shouldn't do anything time-consuming, as we are no longer in busy mode.
ded_mapinfo_t* mapInfo;

assert(theMap);

mapInfo = Def_GetMapInfo(GameMap_Uri(theMap));
if(!mapInfo || !(mapInfo->flags & MIF_FOG))
R_SetupFogDefaults();
else
R_SetupFog(mapInfo->fogStart, mapInfo->fogEnd, mapInfo->fogDensity, mapInfo->fogColor);
break;
}
default:
Con_Error("R_SetupMap: Unknown setup mode %i", mode);
exit(1); // Unreachable.
}
}

Expand Down
41 changes: 33 additions & 8 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -1267,10 +1267,24 @@ void G_EndGame(void)
Hu_MsgStart(MSG_YESNO, IS_CLIENT? GET_TXT(TXT_DISCONNECT) : ENDGAME, G_EndGameResponse, 0, NULL);
}

static void R_SetupMapFog(void)
/// @param mapInfo Can be @c NULL.
static void initFogForMap(ddmapinfo_t* mapInfo)
{
#if __JHEXEN__
int fadeTable = P_GetMapFadeTable(gameMap);
int fadeTable;
#endif

if(!mapInfo || !(mapInfo->flags & MIF_FOG))
{
R_SetupFogDefaults();
}
else
{
R_SetupFog(mapInfo->fogStart, mapInfo->fogEnd, mapInfo->fogDensity, mapInfo->fogColor);
}

#if __JHEXEN__
fadeTable = P_GetMapFadeTable(gameMap);
if(fadeTable == W_GetLumpNumForName("COLORMAP"))
{
// We don't want fog in this case.
Expand Down Expand Up @@ -1299,8 +1313,9 @@ static int G_LoadMapWorker(void* params)

void G_DoLoadMap(loadmap_params_t* p)
{
boolean hasBrief = false, hasMapInfo = false;
ddfinale_t fin;
boolean hasBrief;
ddmapinfo_t mapInfo;

DENG_ASSERT(p);

Expand All @@ -1309,9 +1324,10 @@ void G_DoLoadMap(loadmap_params_t* p)

// Determine whether there is a briefing to run before the map starts
// (played after the map has been loaded).
hasBrief = G_BriefingEnabled(p->episode, p->map, &fin);
if(!hasBrief)
if(G_BriefingEnabled(p->episode, p->map, &fin))
{
hasBrief = true;

#if __JHEXEN__
/**
* @note Kludge: Due to the way music is managed with Hexen, unless we
Expand All @@ -1333,6 +1349,14 @@ void G_DoLoadMap(loadmap_params_t* p)
S_PauseMusic(true);
}

// Is MapInfo data available for this map?
{ ddstring_t* mapUriStr = Uri_Compose(p->mapUri);
if(mapUriStr)
{
hasMapInfo = Def_Get(DD_DEF_MAP_INFO, Str_Text(mapUriStr), &mapInfo);
Str_Delete(mapUriStr);
}}

// Delete raw images to conserve texture memory.
DD_Executef(true, "texreset raw");

Expand All @@ -1347,8 +1371,9 @@ void G_DoLoadMap(loadmap_params_t* p)
G_LoadMapWorker, p, "Loading map...");

// Process work which could not be done during busy mode...
R_SetupMap(DDSMM_AFTER_BUSY, 0);
R_SetupMapFog();
/// @todo Is it still necessary to peform this fog setup in the main thread,
/// or does the deferred GL-task mechanism handle it all?
initFogForMap(hasMapInfo? &mapInfo : 0);

// Wrap up, map loading is now complete.
G_SetGameAction(GA_NONE);
Expand All @@ -1361,7 +1386,7 @@ void G_DoLoadMap(loadmap_params_t* p)
}
else
{
// No briefing, start the map.
// No briefing; begin the map.
G_BeginMap();
}
}
Expand Down

0 comments on commit 4b375c6

Please sign in to comment.