Skip to content

Commit

Permalink
Changed jHeretic: Revised method for drawing the chain on the jHereti…
Browse files Browse the repository at this point in the history
…c statusbar; now drawn in two sections when needed (left and right of the gem) so as to maintain a uniform alpha value for the whole chain.

Fixed jHeretic: The colour of the glowing gem on the statusbar did not change to match the player's colour (as the gem patch does). This might also be considered a kludge given that if the gem patches are changed in a mod it will again look incorrect. Also reordered the lifeGems dpatch_t array so it can be indexed using cfg.playerColor
  • Loading branch information
danij committed Oct 22, 2008
1 parent 2b9b91e commit 43129f7
Showing 1 changed file with 83 additions and 84 deletions.
167 changes: 83 additions & 84 deletions doomsday/plugins/jheretic/src/st_stuff.c
Expand Up @@ -318,83 +318,102 @@ static void shadeChain(float alpha)

static void drawChain(hudstate_t* hud)
{
static int theirColors[] = {
144, // Green.
197, // Yellow.
150, // Red.
220 // Blue.
};
int chainY;
float healthPos;
float gemglow;
float healthPos, gemXOffset, gemglow;
int x, y, w, h, gemNum;
float cw;
float cw, rgba[4];
int player = hud - hudStates;
player_t* plr = &players[player];

if(hud->oldHealth != hud->healthMarker)
{
hud->oldHealth = hud->healthMarker;
healthPos = hud->healthMarker;
if(healthPos < 0)
{
healthPos = 0;
}
if(healthPos > 100)
{
healthPos = 100;
}
hud->oldHealth = hud->healthMarker;

gemglow = healthPos / 100;
chainY = 191;
if(hud->healthMarker != plr->plr->mo->health)
chainY += hud->chainWiggle;

chainY = 191;
if(hud->healthMarker != plr->plr->mo->health)
chainY += hud->chainWiggle;
healthPos = MINMAX_OF(0, hud->healthMarker / 100.f, 1);

// Draw the chain.
x = 21;
y = chainY;
w = 271;
h = 8;
cw = (healthPos / 118) + 0.018f;
if(!IS_NETGAME)
gemNum = 2; // Always use the red gem in single player.
else
gemNum = cfg.playerColor[player];
gemglow = healthPos;

GL_SetPatch(chain.lump, DGL_REPEAT, DGL_CLAMP);
// Draw the chain.
x = 21;
y = chainY;
w = ST_WIDTH - 21 - 28;
h = 8;
cw = (float) w / chain.width;

DGL_Color4f(1, 1, 1, hud->statusbarCounterAlpha);
GL_SetPatch(chain.lump, DGL_REPEAT, DGL_CLAMP);

DGL_Begin(DGL_QUADS);
DGL_Color4f(1, 1, 1, hud->statusbarCounterAlpha);

DGL_TexCoord2f( 0 - cw, 0);
DGL_Vertex2f(x, y);
gemXOffset = (w - lifeGems[gemNum].width) * healthPos;

DGL_TexCoord2f( 0.916f - cw, 0);
DGL_Vertex2f(x + w, y);
if(gemXOffset > 0)
{ // Left chain section.
float cw = gemXOffset / chain.width;

DGL_TexCoord2f( 0.916f - cw, 1);
DGL_Vertex2f(x + w, y + h);
DGL_Begin(DGL_QUADS);
DGL_TexCoord2f(1 - cw, 0);
DGL_Vertex2f(x, y);

DGL_TexCoord2f( 0 - cw, 1);
DGL_Vertex2f(x, y + h);
DGL_TexCoord2f(1, 0);
DGL_Vertex2f(x + gemXOffset, y);

DGL_End();
DGL_TexCoord2f(1, 1);
DGL_Vertex2f(x + gemXOffset, y + h);

// Draw the life gem.
healthPos = (healthPos * 256) / 102;
if(!IS_NETGAME)
gemNum = 2; // Always use the red gem in single player.
else
gemNum = cfg.playerColor[player];
DGL_TexCoord2f(1 - cw, 1);
DGL_Vertex2f(x, y + h);
DGL_End();
}

GL_DrawPatchLitAlpha(x + healthPos, chainY, 1,
hud->statusbarCounterAlpha,
lifeGems[gemNum].lump);
if(gemXOffset + lifeGems[gemNum].width < w)
{ // Right chain section.
float cw =
(w - gemXOffset - lifeGems[gemNum].width) / chain.width;

shadeChain((hud->statusbarCounterAlpha + cfg.statusbarAlpha) /3);
DGL_Begin(DGL_QUADS);
DGL_TexCoord2f(0, 0);
DGL_Vertex2f(x + gemXOffset + lifeGems[gemNum].width, y);

// How about a glowing gem?
GL_BlendMode(BM_ADD);
DGL_Bind(Get(DD_DYNLIGHT_TEXTURE));
DGL_TexCoord2f(cw, 0);
DGL_Vertex2f(x + w, y);

GL_DrawRect(x + healthPos - 11, chainY - 6, 41, 24, 1, 0, 0,
gemglow - (1 - hud->statusbarCounterAlpha));
DGL_TexCoord2f(cw, 1);
DGL_Vertex2f(x + w, y + h);

GL_BlendMode(BM_NORMAL);
DGL_Color4f(1, 1, 1, 1);
DGL_TexCoord2f(0, 1);
DGL_Vertex2f(x + gemXOffset + lifeGems[gemNum].width, y + h);
DGL_End();
}

// Draw the life gem.
GL_DrawPatchLitAlpha(x + gemXOffset, chainY,
1, hud->statusbarCounterAlpha,
lifeGems[gemNum].lump);

shadeChain((hud->statusbarCounterAlpha + cfg.statusbarAlpha) /3);

// How about a glowing gem?
GL_BlendMode(BM_ADD);
DGL_Bind(Get(DD_DYNLIGHT_TEXTURE));

GL_PalIdxToRGB(theirColors[gemNum], rgba);
GL_DrawRect(x + gemXOffset - 11, chainY - 6, 41, 24, rgba[0], rgba[1],
rgba[2], gemglow - (1 - hud->statusbarCounterAlpha));

GL_BlendMode(BM_NORMAL);
DGL_Color4f(1, 1, 1, 1);
}

/**
Expand Down Expand Up @@ -616,8 +635,7 @@ void ST_Ticker(void)

if(!P_IsPaused())
{
int delta;
int curHealth;
int delta, curHealth;

if(cfg.hudTimer == 0)
{
Expand All @@ -637,35 +655,16 @@ void ST_Ticker(void)
{
hud->chainWiggle = P_Random() & 1;
}
curHealth = plr->plr->mo->health;
if(curHealth < 0)
{
curHealth = 0;
}

curHealth = MAX_OF(plr->plr->mo->health, 0);
if(curHealth < hud->healthMarker)
{
delta = (hud->healthMarker - curHealth) >> 2;
if(delta < 1)
{
delta = 1;
}
else if(delta > 8)
{
delta = 8;
}
delta = MINMAX_OF(1, (hud->healthMarker - curHealth) >> 2, 4);
hud->healthMarker -= delta;
}
else if(curHealth > hud->healthMarker)
{
delta = (curHealth - hud->healthMarker) >> 2;
if(delta < 1)
{
delta = 1;
}
else if(delta > 8)
{
delta = 8;
}
delta = MINMAX_OF(1, (curHealth - hud->healthMarker) >> 2, 4);
hud->healthMarker += delta;
}

Expand Down Expand Up @@ -1411,11 +1410,11 @@ void ST_loadGraphics(void)
R_CachePatch(&statBar, "STATBAR");
R_CachePatch(&lifeBar, "LIFEBAR");

for(i = 0; i < 4; ++i)
{
sprintf(nameBuf, "LIFEGEM%d", i);
R_CachePatch(&lifeGems[i], nameBuf);
}
// Order of lifeGems changed to match player color index.
R_CachePatch(&lifeGems[0], "LIFEGEM1");
R_CachePatch(&lifeGems[1], "LIFEGEM3");
R_CachePatch(&lifeGems[2], "LIFEGEM2");
R_CachePatch(&lifeGems[3], "LIFEGEM0");

R_CachePatch(&godLeft, "GOD1");
R_CachePatch(&godRight, "GOD2");
Expand Down

0 comments on commit 43129f7

Please sign in to comment.