Skip to content

Commit

Permalink
Reinstated the fading of the HUD fog effect and fixed a problem with …
Browse files Browse the repository at this point in the history
…the menu not being closed after starting a new game in Nightmare! difficulty.
  • Loading branch information
danij committed Dec 5, 2008
1 parent 55e3e8f commit eb4b43f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
2 changes: 2 additions & 0 deletions doomsday/plugins/common/include/hu_stuff.h
Expand Up @@ -79,6 +79,8 @@ void Hu_Drawer(void);
void Hu_Ticker(void);
void Hu_FogEffectTicker(timespan_t time);

void Hu_FogEffectSetAlphaTarget(float alpha);

// Implements patch replacement.
void WI_DrawPatch(int x, int y, float r, float g, float b, float a,
dpatch_t* patch, char *altstring, boolean builtin, int halign);
Expand Down
8 changes: 4 additions & 4 deletions doomsday/plugins/common/src/hu_menu.c
Expand Up @@ -1880,6 +1880,8 @@ void Hu_MenuCommand(menucommand_e cmd)
{
if(cmd == MCMD_CLOSE || cmd == MCMD_CLOSEFAST)
{
Hu_FogEffectSetAlphaTarget(0);

if(cmd == MCMD_CLOSEFAST)
{ // Hide the menu instantly.
menuAlpha = menuTargetAlpha = 0;
Expand All @@ -1904,6 +1906,7 @@ void Hu_MenuCommand(menucommand_e cmd)

Con_Open(false);

Hu_FogEffectSetAlphaTarget(1);
Hu_MenuSetAlpha(1);
menuActive = true;
menu_color = 0;
Expand Down Expand Up @@ -3358,10 +3361,6 @@ int M_EndGameResponse(msgresponse_t response, void* context)
{
if(response == MSG_YES)
{
currentMenu->lastOn = itemOn;
menuAlpha = menuTargetAlpha = 0;

menuActive = false;
G_StartTitle();
return true;
}
Expand Down Expand Up @@ -3554,6 +3553,7 @@ int M_VerifyNightmare(msgresponse_t response, void* context)
{
if(response == MSG_YES)
{
Hu_MenuCommand(MCMD_CLOSEFAST);
#if __JHERETIC__
G_DeferedInitNew(SM_NIGHTMARE, MenuEpisode, 1);
#else
Expand Down
43 changes: 30 additions & 13 deletions doomsday/plugins/common/src/hu_stuff.c
Expand Up @@ -92,6 +92,7 @@ typedef struct fogeffectlayer_s {

typedef struct fogeffectdata_s {
DGLuint texture;
float alpha, targetAlpha;
fogeffectlayer_t layers[2];
float joinY;
boolean scrollDir;
Expand Down Expand Up @@ -135,11 +136,10 @@ cvar_t hudCVars[] = {

// PRIVATE DATA DEFINITIONS ------------------------------------------------

static dpatch_t borderPatches[8];

static hudstate_t hudStates[MAXPLAYERS];

static boolean fogEffectActive = false;
static dpatch_t borderPatches[8];

static fogeffectdata_t fogEffectData;

// Code -------------------------------------------------------------------
Expand Down Expand Up @@ -193,6 +193,7 @@ void Hu_LoadData(void)

// Intialize the background fog effect.
fogEffectData.texture = 0;
fogEffectData.alpha = fogEffectData.targetAlpha = 0;
fogEffectData.joinY = 0.5f;
fogEffectData.scrollDir = true;
fogEffectData.layers[0].texOffset[VX] =
Expand Down Expand Up @@ -1174,10 +1175,22 @@ void Hu_FogEffectTicker(timespan_t time)
if(!M_RunTrigger(&fixed, time))
return;

fogEffectActive = Hu_IsMessageActive() ||
((Hu_MenuIsActive() || Hu_MenuAlpha() > 0) && !MN_CurrentMenuHasBackground());
// Move towards the target alpha
if(fog->alpha != fog->targetAlpha)
{
float diff = fog->targetAlpha - fog->alpha;

if(fabs(diff) > FOGALPHA_FADE_STEP)
{
fog->alpha += FOGALPHA_FADE_STEP * (diff > 0? 1 : -1);
}
else
{
fog->alpha = fog->targetAlpha;
}
}

if(!fogEffectActive)
if(!(fog->alpha > 0))
return;

for(i = 0; i < 2; ++i)
Expand Down Expand Up @@ -2010,10 +2023,7 @@ void Hu_DrawFogEffect(int effectID, DGLuint tex, float texOffset[2],
const float xscale = 2.0f;
const float yscale = 1.0f;

if(alpha <= 0)
return;

if(cfg.menuEffects > 1)
if(!(alpha > 0))
return;

if(effectID == 4)
Expand Down Expand Up @@ -2127,10 +2137,10 @@ static void drawFogEffect(void)
// Two layers.
Hu_DrawFogEffect(cfg.hudFog, mfd->texture,
mfd->layers[0].texOffset, mfd->layers[0].texAngle,
1, fogEffectData.joinY);
mfd->alpha, fogEffectData.joinY);
Hu_DrawFogEffect(cfg.hudFog, mfd->texture,
mfd->layers[1].texOffset, mfd->layers[1].texAngle,
1, fogEffectData.joinY);
mfd->alpha, fogEffectData.joinY);

// Restore original matrices.
DGL_MatrixMode(DGL_MODELVIEW);
Expand All @@ -2150,7 +2160,9 @@ void Hu_Drawer(void)
DGL_Ortho(0, 0, 320, 200, -1, 1);

// Draw the fog effect?
if(fogEffectActive)
if(fogEffectData.alpha > 0 && cfg.menuEffects <= 1 &&
!((Hu_MenuIsActive() || Hu_MenuAlpha() > 0) &&
MN_CurrentMenuHasBackground()))
drawFogEffect();

if(Hu_IsMessageActive())
Expand All @@ -2162,3 +2174,8 @@ void Hu_Drawer(void)
DGL_PopMatrix();
}
}

void Hu_FogEffectSetAlphaTarget(float alpha)
{
fogEffectData.targetAlpha = MINMAX_OF(0, alpha, 1);
}

0 comments on commit eb4b43f

Please sign in to comment.