2003-11-16 04:45:12 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "LightsManager.h"
|
|
|
|
|
#include "GameState.h"
|
|
|
|
|
#include "RageTimer.h"
|
|
|
|
|
#include "arch/Lights/LightsDriver.h"
|
|
|
|
|
#include "RageUtil.h"
|
2003-11-16 06:27:52 +00:00
|
|
|
#include "GameInput.h" // for GameController
|
|
|
|
|
#include "InputMapper.h"
|
2004-07-25 17:07:32 +00:00
|
|
|
#include "Game.h"
|
2004-04-22 05:25:58 +00:00
|
|
|
#include "PrefsManager.h"
|
2003-11-16 04:45:12 +00:00
|
|
|
|
2005-03-15 00:30:26 +00:00
|
|
|
#include "arch/arch.h"
|
2003-11-16 04:45:12 +00:00
|
|
|
|
2004-03-29 09:44:00 +00:00
|
|
|
static const CString CabinetLightNames[NUM_CABINET_LIGHTS] = {
|
|
|
|
|
"MarqueeUpLeft",
|
|
|
|
|
"MarqueeUpRight",
|
|
|
|
|
"MarqueeLrLeft",
|
|
|
|
|
"MarqueeLrRight",
|
|
|
|
|
"ButtonsLeft",
|
|
|
|
|
"ButtonsRight",
|
|
|
|
|
"BassLeft",
|
|
|
|
|
"BassRight",
|
|
|
|
|
};
|
2005-03-05 21:50:33 +00:00
|
|
|
XToString( CabinetLight, NUM_CABINET_LIGHTS );
|
2004-03-29 09:44:00 +00:00
|
|
|
|
2004-03-30 04:44:09 +00:00
|
|
|
static const CString LightsModeNames[NUM_LIGHTS_MODES] = {
|
|
|
|
|
"Attract",
|
|
|
|
|
"Joining",
|
|
|
|
|
"Menu",
|
|
|
|
|
"Demonstration",
|
|
|
|
|
"Gameplay",
|
|
|
|
|
"Stage",
|
|
|
|
|
"Cleared",
|
|
|
|
|
"Test",
|
|
|
|
|
};
|
2005-03-05 21:50:33 +00:00
|
|
|
XToString( LightsMode, NUM_LIGHTS_MODES );
|
2004-03-30 04:44:09 +00:00
|
|
|
|
2004-03-29 09:44:00 +00:00
|
|
|
|
2003-11-16 04:45:12 +00:00
|
|
|
LightsManager* LIGHTSMAN = NULL; // global and accessable from anywhere in our program
|
|
|
|
|
|
|
|
|
|
LightsManager::LightsManager(CString sDriver)
|
|
|
|
|
{
|
2004-03-23 06:11:10 +00:00
|
|
|
m_LightsMode = LIGHTSMODE_JOINING;
|
2003-11-16 04:45:12 +00:00
|
|
|
|
|
|
|
|
m_pDriver = MakeLightsDriver(sDriver);
|
2004-03-30 07:44:29 +00:00
|
|
|
|
2004-04-22 05:25:58 +00:00
|
|
|
ZERO( m_fSecsLeftInCabinetLightBlink );
|
|
|
|
|
ZERO( m_fSecsLeftInGameButtonBlink );
|
2003-11-16 04:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LightsManager::~LightsManager()
|
|
|
|
|
{
|
|
|
|
|
SAFE_DELETE( m_pDriver );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LightsManager::Update( float fDeltaTime )
|
|
|
|
|
{
|
2004-12-03 23:26:59 +00:00
|
|
|
if( !IsEnabled() )
|
|
|
|
|
return;
|
|
|
|
|
|
2004-04-20 02:35:30 +00:00
|
|
|
// update lights falloff
|
|
|
|
|
{
|
|
|
|
|
FOREACH_CabinetLight( cl )
|
2004-04-22 05:25:58 +00:00
|
|
|
fapproach( m_fSecsLeftInCabinetLightBlink[cl], 0, fDeltaTime );
|
|
|
|
|
FOREACH_GameController( gc )
|
|
|
|
|
FOREACH_GameButton( gb )
|
|
|
|
|
fapproach( m_fSecsLeftInGameButtonBlink[gc][gb], 0, fDeltaTime );
|
2004-04-20 02:35:30 +00:00
|
|
|
}
|
2004-03-30 07:44:29 +00:00
|
|
|
|
2003-11-16 06:27:52 +00:00
|
|
|
//
|
2004-04-20 02:35:30 +00:00
|
|
|
// Set new lights state cabinet lights
|
2003-11-16 06:27:52 +00:00
|
|
|
//
|
2004-04-20 02:35:30 +00:00
|
|
|
{
|
2004-04-22 05:25:58 +00:00
|
|
|
ZERO( m_LightsState.m_bCabinetLights );
|
|
|
|
|
ZERO( m_LightsState.m_bGameButtonLights );
|
2004-04-20 02:35:30 +00:00
|
|
|
}
|
2004-03-30 07:44:29 +00:00
|
|
|
|
2004-03-23 06:11:10 +00:00
|
|
|
switch( m_LightsMode )
|
2003-11-16 04:45:12 +00:00
|
|
|
{
|
2004-03-23 06:11:10 +00:00
|
|
|
case LIGHTSMODE_JOINING:
|
2003-11-16 04:45:12 +00:00
|
|
|
{
|
2004-04-02 00:19:01 +00:00
|
|
|
// int iBeat = (int)(GAMESTATE->m_fSongBeat);
|
|
|
|
|
// bool bBlinkOn = (iBeat%2)==0;
|
2004-03-30 07:44:29 +00:00
|
|
|
|
|
|
|
|
FOREACH_PlayerNumber( pn )
|
2003-11-16 04:45:12 +00:00
|
|
|
{
|
2004-03-30 07:44:29 +00:00
|
|
|
if( GAMESTATE->m_bSideIsJoined[pn] )
|
2003-11-16 04:45:12 +00:00
|
|
|
{
|
2004-03-30 07:44:29 +00:00
|
|
|
m_LightsState.m_bCabinetLights[LIGHT_MARQUEE_UP_LEFT+pn] = true;
|
|
|
|
|
m_LightsState.m_bCabinetLights[LIGHT_MARQUEE_LR_LEFT+pn] = true;
|
|
|
|
|
m_LightsState.m_bCabinetLights[LIGHT_BUTTONS_LEFT+pn] = true;
|
|
|
|
|
m_LightsState.m_bCabinetLights[LIGHT_BASS_LEFT+pn] = true;
|
2003-11-16 04:45:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2004-03-23 06:11:10 +00:00
|
|
|
case LIGHTSMODE_ATTRACT:
|
2003-11-16 04:45:12 +00:00
|
|
|
{
|
|
|
|
|
int iSec = (int)RageTimer::GetTimeSinceStart();
|
2004-03-30 07:44:29 +00:00
|
|
|
int iTopIndex = iSec % 4;
|
|
|
|
|
switch( iTopIndex )
|
2003-11-16 04:45:12 +00:00
|
|
|
{
|
2004-03-30 07:44:29 +00:00
|
|
|
case 0: m_LightsState.m_bCabinetLights[LIGHT_MARQUEE_UP_LEFT] = true; break;
|
|
|
|
|
case 1: m_LightsState.m_bCabinetLights[LIGHT_MARQUEE_LR_RIGHT] = true; break;
|
|
|
|
|
case 2: m_LightsState.m_bCabinetLights[LIGHT_MARQUEE_UP_RIGHT] = true; break;
|
|
|
|
|
case 3: m_LightsState.m_bCabinetLights[LIGHT_MARQUEE_LR_LEFT] = true; break;
|
|
|
|
|
default: ASSERT(0);
|
2003-11-16 04:45:12 +00:00
|
|
|
}
|
2004-03-30 07:44:29 +00:00
|
|
|
|
|
|
|
|
bool bOn = (iSec%4)==0;
|
|
|
|
|
m_LightsState.m_bCabinetLights[LIGHT_BASS_LEFT] = bOn;
|
|
|
|
|
m_LightsState.m_bCabinetLights[LIGHT_BASS_RIGHT] = bOn;
|
2003-11-16 04:45:12 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2004-03-23 06:11:10 +00:00
|
|
|
case LIGHTSMODE_MENU:
|
2003-11-16 04:45:12 +00:00
|
|
|
{
|
2004-03-30 07:44:29 +00:00
|
|
|
FOREACH_CabinetLight( cl )
|
|
|
|
|
m_LightsState.m_bCabinetLights[cl] = false;
|
|
|
|
|
|
|
|
|
|
int iBeat = (int)(GAMESTATE->m_fSongBeat);
|
2004-04-02 04:28:40 +00:00
|
|
|
int iTopIndex = iBeat;
|
|
|
|
|
wrap( iTopIndex, 4 );
|
2004-03-30 07:44:29 +00:00
|
|
|
switch( iTopIndex )
|
2003-11-16 04:45:12 +00:00
|
|
|
{
|
2004-03-30 07:44:29 +00:00
|
|
|
case 0: m_LightsState.m_bCabinetLights[LIGHT_MARQUEE_UP_LEFT] = true; break;
|
|
|
|
|
case 1: m_LightsState.m_bCabinetLights[LIGHT_MARQUEE_LR_RIGHT] = true; break;
|
|
|
|
|
case 2: m_LightsState.m_bCabinetLights[LIGHT_MARQUEE_UP_RIGHT] = true; break;
|
|
|
|
|
case 3: m_LightsState.m_bCabinetLights[LIGHT_MARQUEE_LR_LEFT] = true; break;
|
|
|
|
|
default: ASSERT(0);
|
2003-11-16 04:45:12 +00:00
|
|
|
}
|
2004-03-30 07:44:29 +00:00
|
|
|
|
|
|
|
|
bool bBlinkOn = (iBeat%2)==0;
|
|
|
|
|
|
|
|
|
|
FOREACH_PlayerNumber( pn )
|
2003-11-16 04:45:12 +00:00
|
|
|
{
|
2004-03-30 07:44:29 +00:00
|
|
|
if( GAMESTATE->m_bSideIsJoined[pn] )
|
|
|
|
|
{
|
|
|
|
|
m_LightsState.m_bCabinetLights[LIGHT_BUTTONS_LEFT+pn] = bBlinkOn;
|
|
|
|
|
}
|
2003-11-16 04:45:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2004-03-23 06:11:10 +00:00
|
|
|
case LIGHTSMODE_DEMONSTRATION:
|
2004-03-30 04:44:09 +00:00
|
|
|
case LIGHTSMODE_GAMEPLAY:
|
2004-05-20 19:05:37 +00:00
|
|
|
FOREACH_CabinetLight( cl )
|
|
|
|
|
m_LightsState.m_bCabinetLights[cl] = m_fSecsLeftInCabinetLightBlink[cl] > 0;
|
2003-11-16 04:45:12 +00:00
|
|
|
break;
|
2004-03-23 06:11:10 +00:00
|
|
|
case LIGHTSMODE_STAGE:
|
|
|
|
|
case LIGHTSMODE_ALL_CLEARED:
|
2003-11-16 04:45:12 +00:00
|
|
|
{
|
2004-03-23 06:11:10 +00:00
|
|
|
FOREACH_CabinetLight( cl )
|
|
|
|
|
m_LightsState.m_bCabinetLights[cl] = true;
|
2003-11-16 04:45:12 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2004-03-23 06:33:01 +00:00
|
|
|
case LIGHTSMODE_TEST:
|
|
|
|
|
{
|
|
|
|
|
int iSec = (int)RageTimer::GetTimeSinceStart();
|
|
|
|
|
FOREACH_CabinetLight( cl )
|
|
|
|
|
{
|
|
|
|
|
bool bOn = (iSec%NUM_CABINET_LIGHTS) == cl;
|
|
|
|
|
m_LightsState.m_bCabinetLights[cl] = bOn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-11-16 04:45:12 +00:00
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
}
|
2003-11-16 06:27:52 +00:00
|
|
|
|
2004-03-30 08:03:00 +00:00
|
|
|
|
|
|
|
|
// If not joined, has enough credits, and not too late to join, then
|
|
|
|
|
// blink the menu buttons rapidly so they'll press Start
|
|
|
|
|
{
|
|
|
|
|
int iBeat = (int)(GAMESTATE->m_fSongBeat*4);
|
|
|
|
|
bool bBlinkOn = (iBeat%2)==0;
|
|
|
|
|
FOREACH_PlayerNumber( pn )
|
|
|
|
|
{
|
|
|
|
|
if( !GAMESTATE->m_bSideIsJoined[pn] && GAMESTATE->PlayersCanJoin() && GAMESTATE->EnoughCreditsToJoin() )
|
|
|
|
|
{
|
|
|
|
|
m_LightsState.m_bCabinetLights[LIGHT_BUTTONS_LEFT+pn] = bBlinkOn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-16 06:27:52 +00:00
|
|
|
//
|
|
|
|
|
// Update game controller lights
|
|
|
|
|
//
|
|
|
|
|
// FIXME: Works only with Game==dance
|
|
|
|
|
// FIXME: lights pads for players who aren't playing
|
2004-03-23 06:11:10 +00:00
|
|
|
switch( m_LightsMode )
|
2003-11-16 06:27:52 +00:00
|
|
|
{
|
2004-03-23 06:11:10 +00:00
|
|
|
case LIGHTSMODE_ATTRACT:
|
|
|
|
|
case LIGHTSMODE_DEMONSTRATION:
|
2003-11-16 06:27:52 +00:00
|
|
|
{
|
2004-03-23 06:11:10 +00:00
|
|
|
ZERO( m_LightsState.m_bGameButtonLights );
|
2003-11-16 06:27:52 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2004-03-23 06:11:10 +00:00
|
|
|
case LIGHTSMODE_ALL_CLEARED:
|
|
|
|
|
case LIGHTSMODE_STAGE:
|
|
|
|
|
case LIGHTSMODE_JOINING:
|
2003-11-16 06:27:52 +00:00
|
|
|
{
|
2004-03-23 06:11:10 +00:00
|
|
|
FOREACH_GameController( gc )
|
2003-11-16 06:27:52 +00:00
|
|
|
{
|
2004-03-23 06:11:10 +00:00
|
|
|
bool bOn = GAMESTATE->m_bSideIsJoined[gc];
|
2003-11-16 06:27:52 +00:00
|
|
|
|
2004-03-23 06:11:10 +00:00
|
|
|
FOREACH_GameButton( gb )
|
|
|
|
|
m_LightsState.m_bGameButtonLights[gc][gb] = bOn;
|
2003-11-16 06:27:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2004-08-29 04:58:09 +00:00
|
|
|
case LIGHTSMODE_MENU:
|
2004-03-30 04:44:09 +00:00
|
|
|
case LIGHTSMODE_GAMEPLAY:
|
2003-11-16 06:27:52 +00:00
|
|
|
{
|
2004-08-29 04:58:09 +00:00
|
|
|
if( m_LightsMode == LIGHTSMODE_GAMEPLAY && PREFSMAN->m_bBlinkGameplayButtonLightsOnNote )
|
2003-11-16 06:27:52 +00:00
|
|
|
{
|
2004-08-29 04:58:09 +00:00
|
|
|
//
|
|
|
|
|
// Blink on notes.
|
|
|
|
|
//
|
2004-04-22 05:25:58 +00:00
|
|
|
FOREACH_GameController( gc )
|
2003-11-16 06:27:52 +00:00
|
|
|
{
|
2004-04-22 05:25:58 +00:00
|
|
|
FOREACH_GameButton( gb )
|
|
|
|
|
{
|
|
|
|
|
m_LightsState.m_bGameButtonLights[gc][gb] = m_fSecsLeftInGameButtonBlink[gc][gb] > 0 ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-08-29 04:58:09 +00:00
|
|
|
//
|
|
|
|
|
// Blink on button pressess.
|
|
|
|
|
//
|
2004-04-22 05:25:58 +00:00
|
|
|
FOREACH_GameController( gc )
|
|
|
|
|
{
|
|
|
|
|
// don't blink unjoined sides
|
|
|
|
|
if( !GAMESTATE->m_bSideIsJoined[gc] )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
FOREACH_GameButton( gb )
|
|
|
|
|
{
|
|
|
|
|
bool bOn = INPUTMAPPER->IsButtonDown( GameInput(gc,gb) );
|
|
|
|
|
m_LightsState.m_bGameButtonLights[gc][gb] = bOn;
|
|
|
|
|
}
|
2003-11-16 06:27:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2004-03-23 06:33:01 +00:00
|
|
|
case LIGHTSMODE_TEST:
|
|
|
|
|
{
|
|
|
|
|
int iSec = (int)RageTimer::GetTimeSinceStart();
|
|
|
|
|
|
2004-07-25 17:07:32 +00:00
|
|
|
int iNumGameButtonsToShow = GAMESTATE->GetCurrentGame()->GetNumGameplayButtons();
|
2004-04-07 02:27:11 +00:00
|
|
|
|
2004-03-23 06:33:01 +00:00
|
|
|
FOREACH_GameController( gc )
|
|
|
|
|
{
|
|
|
|
|
FOREACH_GameButton( gb )
|
|
|
|
|
{
|
2004-04-07 02:27:11 +00:00
|
|
|
bool bOn = gb==(iSec%iNumGameButtonsToShow);
|
2004-03-23 06:33:01 +00:00
|
|
|
m_LightsState.m_bGameButtonLights[gc][gb] = bOn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-11-16 06:27:52 +00:00
|
|
|
default:
|
|
|
|
|
ASSERT(0);
|
|
|
|
|
}
|
2003-11-16 07:43:39 +00:00
|
|
|
|
|
|
|
|
// apply new light values we set above
|
2004-03-23 06:11:10 +00:00
|
|
|
m_pDriver->Set( &m_LightsState );
|
2003-11-16 04:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
2004-04-22 05:25:58 +00:00
|
|
|
void LightsManager::BlinkCabinetLight( CabinetLight cl )
|
|
|
|
|
{
|
|
|
|
|
m_fSecsLeftInCabinetLightBlink[cl] = LIGHTS_FALLOFF_SECONDS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LightsManager::BlinkGameButton( GameInput gi )
|
2004-03-30 07:44:29 +00:00
|
|
|
{
|
2004-04-22 05:25:58 +00:00
|
|
|
m_fSecsLeftInGameButtonBlink[gi.controller][gi.button] = LIGHTS_FALLOFF_SECONDS;
|
2004-03-30 07:44:29 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-23 06:11:10 +00:00
|
|
|
void LightsManager::SetLightsMode( LightsMode lm )
|
2003-11-16 04:45:12 +00:00
|
|
|
{
|
2004-03-23 06:11:10 +00:00
|
|
|
m_LightsMode = lm;
|
2003-11-20 11:55:45 +00:00
|
|
|
}
|
2004-03-30 04:44:09 +00:00
|
|
|
|
|
|
|
|
LightsMode LightsManager::GetLightsMode()
|
|
|
|
|
{
|
|
|
|
|
return m_LightsMode;
|
|
|
|
|
}
|
2004-06-08 01:24:17 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* (c) 2003-2004 Chris Danford
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|