Skip to content

Commit 3cd3f42

Browse files
committed
tweak(drawable): Decouple material opacity of detected stealth models from render update
Scalar value is calculated ahead of rendering.
1 parent 844c436 commit 3cd3f42

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,9 @@ class Drawable : public Thing,
542542
void setEffectiveOpacity( Real pulseFactor, Real explicitOpacity = -1.0f );
543543

544544
// this is for the add'l pass fx which operates completely independently of the stealth opacity effects. Draw() does the fading every frame.
545-
Real getSecondMaterialPassOpacity() const { return m_secondMaterialPassOpacity; } ///< get alpha/opacity value used to render add'l rendering pass.
546-
void setSecondMaterialPassOpacity( Real op ) { m_secondMaterialPassOpacity = op; }; ///< set alpha/opacity value used to render add'l rendering pass.
545+
Real getSecondMaterialPassOpacity() const { return m_secondMaterialPassOpacity; } ///< get alpha/opacity value used to render add'l rendering pass.
546+
void setSecondMaterialPassOpacity( Real op ) { m_secondMaterialPassOpacity = op; }; ///< set alpha/opacity value used to render add'l rendering pass.
547+
void allowRefillSecondMaterialPassOpacity() { m_secondMaterialPassOpacityAllowRefill = TRUE; } ///< allow the second material opacity to be set to 1.0f
547548

548549
// both of these assume that you are starting at one extreme 100% or 0% opacity and are trying to go to the other!! -- amit
549550
void fadeOut( UnsignedInt frames ); ///< fade object out...how gradually this is done is determined by frames
@@ -723,7 +724,9 @@ class Drawable : public Thing,
723724
UnsignedInt m_expirationDate; ///< if nonzero, Drawable should destroy itself at this frame
724725
DrawableIconInfo* m_iconInfo; ///< lazily allocated!
725726

726-
Real m_secondMaterialPassOpacity; ///< drawable gets rendered again in hardware with an extra material layer
727+
Real m_secondMaterialPassOpacity; ///< drawable gets rendered again in hardware with an extra material layer
728+
Real m_secondMaterialPassOpacityScalar; ///< multiply opacity by scalar value; useful for non-default render framerates
729+
Bool m_secondMaterialPassOpacityAllowRefill; ///< allow the second material opacity to be set to 1.0f
727730
// --------- BYTE-SIZED THINGS GO HERE
728731
Byte m_selected; ///< drawable is selected or not
729732
Bool m_hidden; ///< drawable is "hidden" or not (overrides stealth effects)

GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
#endif
8888

8989

90-
#define VERY_TRANSPARENT_MATERIAL_PASS_OPACITY (0.001f)
91-
#define MATERIAL_PASS_OPACITY_FADE_SCALAR (0.8f)
90+
#define MATERIAL_PASS_OPACITY_MIN (0.001f)
91+
#define MATERIAL_PASS_OPACITY_DEFAULT_FADE_SCALAR (0.8f)
9292

9393
static const char *const TheDrawableIconNames[] =
9494
{
@@ -433,6 +433,8 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatusBits statu
433433
m_hidden = false;
434434
m_hiddenByStealth = false;
435435
m_secondMaterialPassOpacity = 0.0f;
436+
m_secondMaterialPassOpacityScalar = MATERIAL_PASS_OPACITY_DEFAULT_FADE_SCALAR;
437+
m_secondMaterialPassOpacityAllowRefill = false;
436438
m_drawableFullyObscuredByShroud = false;
437439

438440
m_receivesDynamicLights = TRUE; // a good default... overridden by one of my draw modules if at all
@@ -2607,17 +2609,37 @@ void Drawable::setStealthLook(StealthLookType look)
26072609
//-------------------------------------------------------------------------------------------------
26082610
void Drawable::draw()
26092611
{
2610-
if ( testTintStatus( TINT_STATUS_FRENZY ) == FALSE )
2612+
if (testTintStatus(TINT_STATUS_FRENZY) == FALSE)
26112613
{
2612-
if ( getObject() && getObject()->isEffectivelyDead() )
2613-
m_secondMaterialPassOpacity = 0.0f;//dead folks don't stealth anyway
2614-
else if ( m_secondMaterialPassOpacity > VERY_TRANSPARENT_MATERIAL_PASS_OPACITY )// keep fading any add'l material unless something has set it to zero
2615-
m_secondMaterialPassOpacity *= MATERIAL_PASS_OPACITY_FADE_SCALAR;
2616-
else
2617-
m_secondMaterialPassOpacity = 0.0f;
2614+
if (getObject() && getObject()->isEffectivelyDead())
2615+
{
2616+
m_secondMaterialPassOpacity = 0.0f;//dead folks don't stealth anyway
2617+
}
2618+
else if (!TheFramePacer->isGameHalted())
2619+
{
2620+
// TheSuperHackers @tweak The opacity step is now decoupled from the render update.
2621+
if (m_secondMaterialPassOpacity > MATERIAL_PASS_OPACITY_MIN)
2622+
{
2623+
m_secondMaterialPassOpacity *= m_secondMaterialPassOpacityScalar;
2624+
}
2625+
else if (m_secondMaterialPassOpacityAllowRefill)
2626+
{
2627+
// min opacity = (X ^ (framerate / updatesPerSec)) -> e.g. [ 0.05 = X ^ (100 / 2) ] -> [ X = 0.941845 ] -> [ 0.941845 ^ 50 = 0.05 ]
2628+
// changes to the updates per second value need to be tested with a single stealth detector, max 30 logic frames and unlimited render frames
2629+
const Real updatesPerSec = 2.0f;
2630+
const Real scalar = pow(MATERIAL_PASS_OPACITY_MIN, updatesPerSec / TheFramePacer->getUpdateFps());
2631+
2632+
m_secondMaterialPassOpacity = scalar;
2633+
m_secondMaterialPassOpacityScalar = scalar;
2634+
m_secondMaterialPassOpacityAllowRefill = FALSE;
2635+
}
2636+
else
2637+
{
2638+
m_secondMaterialPassOpacity = 0.0f;
2639+
}
2640+
}
26182641
}
26192642

2620-
26212643
if (m_hidden || m_hiddenByStealth || getFullyObscuredByShroud())
26222644
return; // my, that was easy
26232645

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthDetectorUpdate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ UpdateSleepTime StealthDetectorUpdate::update( void )
306306
Drawable *theirDraw = them->getDrawable();
307307
if ( theirDraw && !them->isKindOf(KINDOF_MINE))
308308
{
309-
theirDraw->setSecondMaterialPassOpacity( 1.0f );
309+
// TheSuperHackers @tweak Don't set opacity here as it should be decoupled from the logic frame rate and not be set for every stealth detector.
310+
theirDraw->allowRefillSecondMaterialPassOpacity();
310311
}
311312

312313
if (data->m_IRGridParticleSysTmpl)

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ void StealthUpdate::hintDetectableWhileUnstealthed()
431431
{
432432
Drawable *selfDraw = self->getDrawable();
433433
if ( selfDraw )
434-
selfDraw->setSecondMaterialPassOpacity( 1.0f );
434+
// TheSuperHackers @tweak Don't set opacity here as it should be decoupled from the logic frame rate.
435+
selfDraw->allowRefillSecondMaterialPassOpacity();
435436
}
436437
}
437438
}

0 commit comments

Comments
 (0)