From 2187d0629b58833bf46ebbb35176df4b43973981 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 29 Apr 2005 00:26:48 +0000 Subject: [PATCH] add LightsManager::BlinkActorLightsBetween --- stepmania/src/LightsManager.cpp | 70 +++++++++++++++++++++++++++++++++ stepmania/src/LightsManager.h | 3 ++ 2 files changed, 73 insertions(+) diff --git a/stepmania/src/LightsManager.cpp b/stepmania/src/LightsManager.cpp index 80e2391bdf..0516ad1f2d 100644 --- a/stepmania/src/LightsManager.cpp +++ b/stepmania/src/LightsManager.cpp @@ -8,6 +8,8 @@ #include "InputMapper.h" #include "Game.h" #include "PrefsManager.h" +#include "NoteData.h" +#include "Actor.h" #include "arch/arch.h" @@ -58,8 +60,76 @@ LightsManager::~LightsManager() SAFE_DELETE( m_pDriver ); } +// XXX: make themable +static const float g_fLightEffectRiseSeconds = 0.075f; +static const float g_fLightEffectFalloffSeconds = 0.35f; + +// duration to "power" an actor light +static float g_fCabinetLightDuration[NUM_CABINET_LIGHTS]; + +// current "power" of each actor light +static float g_fCabinetLights[NUM_CABINET_LIGHTS]; + +/* + * Using data from pLightData, blink actor lights (eg. "effectclock,MarqueeLrRight") + * within [iStart,iEnd). This is available even if no light driver is active. + */ +void LightsManager::BlinkActorLightsBetween( int iStart, int iEnd, const NoteData *pLightData ) +{ + if( iStart >= iEnd ) + return; + + FOREACH_CabinetLight( cl ) + { + bool bBlinkCabinetLight = false; + + // for each index we crossed since the last update: + FOREACH_NONEMPTY_ROW_IN_TRACK_RANGE( *pLightData, cl, r, iStart, iEnd ) + { + if( pLightData->GetTapNote( cl, r ).type != TapNote::empty ) + bBlinkCabinetLight |= true; + } + + if( pLightData->IsHoldNoteAtBeat( cl, iEnd ) ) + bBlinkCabinetLight |= true; + + if( bBlinkCabinetLight ) + g_fCabinetLightDuration[cl] = g_fLightEffectRiseSeconds; + } +} + +float LightsManager::GetActorLightLatencySeconds() const +{ + return g_fLightEffectRiseSeconds; +} + void LightsManager::Update( float fDeltaTime ) { + // + // Update actor effect lights. + // + FOREACH_CabinetLight( cl ) + { + float fTime = fDeltaTime; + float &fDuration = g_fCabinetLightDuration[cl]; + if( fDuration > 0 ) + { + /* The light has power left. Brighten it. */ + float fSeconds = min( fDuration, fTime ); + fDuration -= fSeconds; + fTime -= fSeconds; + fapproach( g_fCabinetLights[cl], 1, fSeconds / g_fLightEffectRiseSeconds ); + } + + if( fTime > 0 ) + { + /* The light is out of power. Dim it. */ + fapproach( g_fCabinetLights[cl], 0, fTime / g_fLightEffectFalloffSeconds ); + } + + Actor::SetBGMLight( cl, g_fCabinetLights[cl] ); + } + if( !IsEnabled() ) return; diff --git a/stepmania/src/LightsManager.h b/stepmania/src/LightsManager.h index 0a0ce2b16d..ef8b0ea1e8 100644 --- a/stepmania/src/LightsManager.h +++ b/stepmania/src/LightsManager.h @@ -48,6 +48,7 @@ struct LightsState }; class LightsDriver; +class NoteData; class LightsManager { @@ -60,6 +61,8 @@ public: void BlinkCabinetLight( CabinetLight cl ); void BlinkGameButton( GameInput gi ); + void BlinkActorLightsBetween( int iStart, int iEnd, const NoteData *pLightData ); + float GetActorLightLatencySeconds() const; void SetLightsMode( LightsMode lm ); LightsMode GetLightsMode();