basic lights support

This commit is contained in:
Chris Danford
2003-11-16 04:45:12 +00:00
parent 38ec8ca856
commit 48d5a78429
20 changed files with 397 additions and 2 deletions
+3
View File
@@ -33,6 +33,7 @@
#include "ThemeManager.h"
#include "fstream"
#include "Bookkeeper.h"
#include "LightsManager.h"
#define DEFAULT_MODIFIERS THEME->GetMetric( "Common","DefaultModifiers" )
@@ -142,6 +143,8 @@ void GameState::Reset()
// save stats info intermitently in case of crash
BOOKKEEPER->WriteToDisk();
SONGMAN->SaveMachineScoresToDisk();
LIGHTSMAN->SetLightMode( LIGHTMODE_ATTRACT );
}
void GameState::Update( float fDelta )
+138
View File
@@ -0,0 +1,138 @@
#include "global.h"
/*
-----------------------------------------------------------------------------
Class: LightsManager
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "LightsManager.h"
#include "GameState.h"
#include "RageTimer.h"
#include "arch/Lights/LightsDriver.h"
#include "arch/arch.h"
#include "RageUtil.h"
#include "windows.h"
LightsManager* LIGHTSMAN = NULL; // global and accessable from anywhere in our program
LightsManager::LightsManager(CString sDriver)
{
m_LightMode = LIGHTMODE_JOINING;
m_pDriver = MakeLightsDriver(sDriver);
}
LightsManager::~LightsManager()
{
SAFE_DELETE( m_pDriver );
}
void LightsManager::Update( float fDeltaTime )
{
switch( m_LightMode )
{
case LIGHTMODE_JOINING:
{
switch( GAMESTATE->GetNumSidesJoined() )
{
case 0:
{
int iSec = (int)(RageTimer::GetTimeSinceStart()*2);
float fBeatPercentage = GAMESTATE->m_fSongBeat - (int)GAMESTATE->m_fSongBeat;
bool bOn = (iSec%2)==0;
for( int i=0; i<8; i++ )
m_pDriver->SetLight( (Light)i, bOn );
}
break;
default:
for( int i=0; i<8; i++ )
{
bool bOn = GAMESTATE->m_bSideIsJoined[i%2];
m_pDriver->SetLight( (Light)i, bOn );
}
}
}
break;
case LIGHTMODE_ATTRACT:
{
int iSec = (int)RageTimer::GetTimeSinceStart();
int i;
for( i=0; i<4; i++ )
{
bool bOn = (iSec%4)==i;
m_pDriver->SetLight( (Light)i, bOn );
}
for( i=4; i<6; i++ )
{
bool bOn = false;
m_pDriver->SetLight( (Light)i, bOn );
}
for( i=6; i<8; i++ )
{
bool bOn = (iSec%3)==0;
m_pDriver->SetLight( (Light)i, bOn );
}
}
break;
case LIGHTMODE_MENU:
{
int iSec = (int)RageTimer::GetTimeSinceStart();
int i;
for( i=0; i<2; i++ )
{
bool bOn = (iSec%2)==0;
m_pDriver->SetLight( (Light)i, bOn );
}
for( i=2; i<4; i++ )
{
bool bOn = (iSec%2)==1;
m_pDriver->SetLight( (Light)i, bOn );
}
for( i=4; i<6; i++ )
{
bool bOn = (iSec%2)==0;
m_pDriver->SetLight( (Light)i, bOn );
}
for( i=6; i<8; i++ )
{
bool bOn = (iSec%2)==1;
m_pDriver->SetLight( (Light)i, bOn );
}
}
break;
case LIGHTMODE_DEMONSTRATION:
case LIGHTMODE_GAMEPLAY:
{
float fBeatPercentage = GAMESTATE->m_fSongBeat - (int)GAMESTATE->m_fSongBeat;
bool bOn = fBeatPercentage < 0.1 || fBeatPercentage > 0.9;
for( int i=0; i<8; i++ )
m_pDriver->SetLight( (Light)i, bOn );
}
break;
case LIGHTMODE_ALL_ON:
{
for( int i=0; i<8; i++ )
m_pDriver->SetLight( (Light)i, true );
}
break;
case LIGHTMODE_ALL_OFF:
{
for( int i=0; i<8; i++ )
m_pDriver->SetLight( (Light)i, false );
}
break;
default:
ASSERT(0);
}
}
void LightsManager::SetLightMode( LightMode lm )
{
m_LightMode = lm;
}
+61
View File
@@ -0,0 +1,61 @@
#ifndef LightsManager_H
#define LightsManager_H
/*
-----------------------------------------------------------------------------
Class: LightsManager
Desc: Control lights.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
enum Light
{
LIGHT_MARUQEE_UP_LEFT,
LIGHT_MARUQEE_UP_RIGHT,
LIGHT_MARUQEE_LR_LEFT,
LIGHT_MARUQEE_LR_RIGHT,
LIGHT_MARUQEE_MENU_LEFT,
LIGHT_MARUQEE_MENU_RIGHT,
LIGHT_MARUQEE_BASS_LEFT,
LIGHT_MARUQEE_BASS_RIGHT,
NUM_LIGHTS
};
enum LightMode
{
LIGHTMODE_ATTRACT,
LIGHTMODE_JOINING,
LIGHTMODE_MENU,
LIGHTMODE_DEMONSTRATION,
LIGHTMODE_GAMEPLAY,
LIGHTMODE_ALL_ON,
LIGHTMODE_ALL_OFF,
};
class LightsDriver;
class LightsManager
{
public:
LightsManager(CString sDriver);
~LightsManager();
void Update( float fDeltaTime );
void SetLightMode( LightMode lm );
private:
void SetLight( Light light, bool bOn );
LightsDriver* m_pDriver;
LightMode m_LightMode;
};
extern LightsManager* LIGHTSMAN; // global and accessable from anywhere in our program
#endif
+5
View File
@@ -26,6 +26,7 @@
PrefsManager* PREFSMAN = NULL; // global and accessable from anywhere in our program
const float DEFAULT_SOUND_VOLUME = 1.00f;
const CString DEFAULT_LIGHTS_DRIVER = "Null";
bool g_bAutoRestart = false;
@@ -186,6 +187,7 @@ PrefsManager::PrefsManager()
#endif
m_fSoundVolume = DEFAULT_SOUND_VOLUME;
m_sLightsDriver = DEFAULT_LIGHTS_DRIVER;
/* This is experimental: let's see if preloading helps people's skipping.
* If it doesn't do anything useful, it'll be removed. */
m_bSoundPreloadAll = false;
@@ -285,6 +287,7 @@ void PrefsManager::ReadGlobalPrefsFromDisk()
ini.GetValue( "Options", "EasterEggs", m_bEasterEggs );
ini.GetValue( "Options", "MarvelousTiming", (int&)m_iMarvelousTiming );
ini.GetValue( "Options", "SoundVolume", m_fSoundVolume );
ini.GetValue( "Options", "LightsDriver", m_sLightsDriver );
ini.GetValue( "Options", "SoundPreloadAll", m_bSoundPreloadAll );
ini.GetValue( "Options", "SoundResampleQuality", m_iSoundResampleQuality );
ini.GetValue( "Options", "CoinMode", m_iCoinMode );
@@ -518,6 +521,8 @@ void PrefsManager::SaveGlobalPrefsToDisk() const
ini.SetValue ( "Options", "SoundDrivers", m_sSoundDrivers );
if(m_fSoundVolume != DEFAULT_SOUND_VOLUME)
ini.SetValue( "Options", "SoundVolume", m_fSoundVolume );
if(m_sLightsDriver != DEFAULT_LIGHTS_DRIVER)
ini.SetValue( "Options", "LightsDriver", m_sLightsDriver );
if(m_sMovieDrivers != DEFAULT_MOVIE_DRIVER_LIST)
ini.SetValue ( "Options", "MovieDrivers", m_sMovieDrivers );
+1
View File
@@ -155,6 +155,7 @@ public:
bool m_bAntiAliasing;
CString m_sSoundDrivers;
CString m_sMovieDrivers;
CString m_sLightsDriver;
float m_fSoundVolume;
bool m_bSoundPreloadAll;
int m_iSoundResampleQuality;
+3
View File
@@ -28,6 +28,7 @@
#include "RageTimer.h"
#include "UnlockSystem.h"
#include "Course.h"
#include "LightsManager.h"
const int NUM_SCORE_DIGITS = 9;
@@ -92,6 +93,8 @@ ScreenEvaluation::ScreenEvaluation( CString sClassName ) : Screen(sClassName)
LOG->Trace( "ScreenEvaluation::ScreenEvaluation()" );
LIGHTSMAN->SetLightMode( LIGHTMODE_MENU );
m_bFailed = false; // the evaluation is not showing failed results by default
m_sName = sClassName;
+9
View File
@@ -45,6 +45,7 @@
#include "Course.h"
#include "NoteDataUtil.h"
#include "UnlockSystem.h"
#include "LightsManager.h"
//
// Defines
@@ -92,6 +93,11 @@ ScreenGameplay::ScreenGameplay( CString sName, bool bDemonstration ) : Screen("S
m_bDemonstration = bDemonstration;
if( m_bDemonstration )
LIGHTSMAN->SetLightMode( LIGHTMODE_DEMONSTRATION );
else
LIGHTSMAN->SetLightMode( LIGHTMODE_GAMEPLAY );
SECONDS_BETWEEN_COMMENTS.Refresh();
G_TICK_EARLY_SECONDS.Refresh();
@@ -1709,6 +1715,9 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM )
GAMESTATE->RemoveAllActiveAttacks();
LIGHTSMAN->SetLightMode( LIGHTMODE_ALL_OFF );
if( bAllReallyFailed )
{
this->PostScreenMessage( SM_BeginFailed, 0 );
+3
View File
@@ -36,6 +36,7 @@
#include "Course.h"
#include "ProfileManager.h"
#include "MenuTimer.h"
#include "LightsManager.h"
const int NUM_SCORE_DIGITS = 9;
@@ -78,6 +79,8 @@ ScreenSelectMusic::ScreenSelectMusic( CString sClassName ) : Screen( sClassName
{
LOG->Trace( "ScreenSelectMusic::ScreenSelectMusic()" );
LIGHTSMAN->SetLightMode( LIGHTMODE_MENU );
m_bInCourseDisplayMode = GAMESTATE->IsCourseMode();
/* Cache: */
+3
View File
@@ -19,6 +19,7 @@
#include "GameState.h"
#include "AnnouncerManager.h"
#include "ActorUtil.h"
#include "LightsManager.h"
#define ICON_GAIN_FOCUS_COMMAND THEME->GetMetric (m_sName,"IconGainFocusCommand")
@@ -30,6 +31,8 @@ ScreenSelectStyle::ScreenSelectStyle( CString sClassName ) : ScreenSelect( sClas
{
m_iSelection = 0;
LIGHTSMAN->SetLightMode( LIGHTMODE_MENU );
unsigned i;
for( i=0; i<m_aModeChoices.size(); i++ )
{
+4
View File
@@ -22,6 +22,7 @@
#include "GameState.h"
#include "RageSounds.h"
#include "ThemeManager.h"
#include "LightsManager.h"
#define NEXT_SCREEN THEME->GetMetric ("ScreenStage","NextScreen")
@@ -56,6 +57,9 @@ ScreenStage::ScreenStage( CString sClassName ) : Screen( sClassName )
{
SOUND->StopMusic();
LIGHTSMAN->SetLightMode( LIGHTMODE_ALL_ON );
m_Background.LoadFromAniDir( THEME->GetPathToB("ScreenStage "+GAMESTATE->GetStageText()) );
this->AddChild( &m_Background );
+4 -2
View File
@@ -29,7 +29,7 @@
#include "RageTextureManager.h"
#include "UnlockSystem.h"
#include "ProductInfo.h"
//#include "NetworkManager.h"
#include "LightsManager.h"
#define LOGO_ON_COMMAND THEME->GetMetric("ScreenTitleMenu","LogoOnCommand")
@@ -62,7 +62,6 @@ ScreenTitleMenu::ScreenTitleMenu( CString sClassName ) : ScreenSelect( sClassNam
{
LOG->Trace( "ScreenTitleMenu::ScreenTitleMenu()" );
// Don't show screen title menu (says "Press Start")
// if there are 0 credits and inserted and CoinMode is pay.
if( PREFSMAN->m_iCoinMode == COIN_PAY &&
@@ -78,6 +77,9 @@ ScreenTitleMenu::ScreenTitleMenu( CString sClassName ) : ScreenSelect( sClassNam
* things stinks ... */
GAMESTATE->Reset();
LIGHTSMAN->SetLightMode( LIGHTMODE_JOINING ); // do this after Reset!
CodeDetector::RefreshCacheItems();
m_sprLogo.Load( THEME->GetPathToG(ssprintf("ScreenLogo %s",GAMESTATE->GetCurrentGameDef()->m_szName)) );
+4
View File
@@ -53,6 +53,7 @@
#include "arch/ArchHooks/ArchHooks.h"
#include "RageFile.h"
#include "Bookkeeper.h"
#include "LightsManager.h"
#if defined(_XBOX)
@@ -837,6 +838,7 @@ int main(int argc, char* argv[])
SOUND = new RageSounds;
PROFILEMAN = new ProfileManager;
BOOKKEEPER = new Bookkeeper;
LIGHTSMAN = new LightsManager(PREFSMAN->m_sLightsDriver);
INPUTFILTER = new InputFilter;
INPUTMAPPER = new InputMapper;
INPUTQUEUE = new InputQueue;
@@ -946,6 +948,7 @@ int main(int argc, char* argv[])
SAFE_DELETE( ANNOUNCER );
SAFE_DELETE( PROFILEMAN );
SAFE_DELETE( BOOKKEEPER );
SAFE_DELETE( LIGHTSMAN );
SAFE_DELETE( SOUND );
SAFE_DELETE( SOUNDMAN );
SAFE_DELETE( FONT );
@@ -1081,6 +1084,7 @@ bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput Gam
static void HandleInputEvents(float fDeltaTime)
{
INPUTFILTER->Update( fDeltaTime );
LIGHTSMAN->Update( fDeltaTime );
static InputEventArray ieArray;
ieArray.clear(); // empty the array
+26
View File
@@ -0,0 +1,26 @@
#ifndef LightsDriver_H
#define LightsDriver_H
/*
-----------------------------------------------------------------------------
Class: LightsDriver
Desc: Control lights.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "LightsManager.h"
class LightsDriver
{
public:
LightsDriver() {};
virtual ~LightsDriver() {};
virtual void SetLight( Light light, bool bOn ) = 0;
};
#endif
@@ -0,0 +1,26 @@
#ifndef LightsDriver_Null_H
#define LightsDriver_Null_H
/*
-----------------------------------------------------------------------------
Class: LightsDriver_Null
Desc: Control lights.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "LightsDriver.h"
class LightsDriver_Null : public LightsDriver
{
public:
LightsDriver_Null() {};
virtual ~LightsDriver_Null() {};
virtual void SetLight( Light light, bool bOn ) {};
};
#endif
@@ -0,0 +1,55 @@
#include "global.h"
/*
-----------------------------------------------------------------------------
Class: LightsDriver_Win32Parallel
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "LightsDriver_Win32Parallel.h"
#include "windows.h"
HINSTANCE hDLL = NULL;
typedef void (WINAPI PORTOUT)(short int Port, char Data);
PORTOUT* PortOut = NULL;
typedef short int (WINAPI ISDRIVERINSTALLED)();
ISDRIVERINSTALLED* IsDriverInstalled = NULL;
LightsDriver_Win32Parallel::LightsDriver_Win32Parallel()
{
// init io.dll
hDLL = LoadLibrary("parallel_lights_io.dll");
if(hDLL == NULL)
{
MessageBox(NULL, "Could not LoadLibrary( parallel_lights_io.dll ).", "ERROR", MB_OK );
return;
}
//Get the function pointers
PortOut = (PORTOUT*) GetProcAddress(hDLL, "PortOut");
IsDriverInstalled = (ISDRIVERINSTALLED*) GetProcAddress(hDLL, "IsDriverInstalled");
}
LightsDriver_Win32Parallel::~LightsDriver_Win32Parallel()
{
FreeLibrary( hDLL );
}
void LightsDriver_Win32Parallel::SetLight( Light light, bool bOn )
{
static BYTE data = 0x00;
BYTE mask = 0x01 << light;
if( bOn )
data |= mask;
else
data &= ~mask;
PortOut( 0x378, data );
// ports of interest: 0x278, 0x3BC, 0x378
}
@@ -0,0 +1,27 @@
#ifndef LightsDriver_Win32Parallel_H
#define LightsDriver_Win32Parallel_H
/*
-----------------------------------------------------------------------------
Class: LightsDriver_Win32Parallel
Desc: Control lights.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "arch/Lights/LightsDriver.h"
class LightsDriver_Win32Parallel : public LightsDriver
{
public:
LightsDriver_Win32Parallel();
virtual ~LightsDriver_Win32Parallel();
virtual void SetLight( Light light, bool bOn );
};
#endif
+20
View File
@@ -142,6 +142,26 @@ RageSoundDriver *MakeRageSoundDriver(CString drivers)
return ret;
}
/* Err, this is ugly--breaks arch encapsulation. Hmm. */
LightsDriver *MakeLightsDriver(CString driver)
{
LOG->Trace("Initializing lights driver: %s", driver.c_str());
LightsDriver *ret = NULL;
#ifdef _WINDOWS
if(!driver.CompareNoCase("Parallel")) ret = new LightsDriver_Win32Parallel;
#endif
if(!driver.CompareNoCase("Null")) ret = new LightsDriver_Null;
if( !ret )
{
LOG->Warn("Unknown lights driver name: %s", driver.c_str());
ret = new LightsDriver_Null;
}
return ret;
}
/*
* Copyright (c) 2002 by the person(s) listed below. All rights reserved.
*
+2
View File
@@ -7,6 +7,7 @@ class RageSoundDriver;
class ArchHooks;
class InputHandler;
class LowLevelWindow;
class LightsDriver;
LoadingWindow *MakeLoadingWindow();
ArchHooks *MakeArchHooks();
@@ -14,6 +15,7 @@ LowLevelWindow *MakeLowLevelWindow();
void MakeInputHandlers(vector<InputHandler *> &Add);
RageSoundDriver *MakeRageSoundDriver(CString drivers);
LightsDriver *MakeLightsDriver(CString driver);
/* These definitions are in here, instead of in arch_*.h, because they
* need to be available to other modules. It'd be overkill to create separate
+2
View File
@@ -13,6 +13,8 @@
#include "Sound/RageSoundDriver_DSound_Software.h"
#include "Sound/RageSoundDriver_WaveOut.h"
#include "Lights/LightsDriver_Win32Parallel.h"
#undef SUPPORT_SDL_INPUT
#endif
+1
View File
@@ -33,6 +33,7 @@
#include "LoadingWindow/LoadingWindow_Null.h"
#include "ArchHooks/ArchHooks_none.h"
#include "Sound/RageSoundDriver_Null.h"
#include "Lights/LightsDriver_Null.h"
#if defined(SUPPORT_OPENGL)
#include "LowLevelWindow/LowLevelWindow_SDL.h"