From 32e6e2c6259e67684ad7ed33299755398c1fe8c6 Mon Sep 17 00:00:00 2001 From: Mark Cannon Date: Sat, 16 Aug 2008 04:28:40 +0000 Subject: [PATCH] Removed a lot of non-working code, added proper sensor reading (tentative), added disqualification for slow song rate git-svn-id: https://openitg.svn.sourceforge.net/svnroot/openitg@486 83fadc84-e282-4d84-a09a-c4228d6ae7e5 --- ToDo.txt | 3 -- changelog.txt | 4 ++ src/GameState.cpp | 3 ++ src/InputMapper.cpp | 13 ------ src/InputMapper.h | 2 - src/RageUtil.cpp | 47 ++++++++++++++++++--- src/RageUtil.h | 15 +++++-- src/ScreenPlayerOptions.cpp | 31 +++++--------- src/ScreenPlayerOptions.h | 6 ++- src/ScreenSelectMusic.cpp | 9 ++-- src/arch/InputHandler/InputHandler.cpp | 4 +- src/arch/InputHandler/InputHandler.h | 3 -- src/arch/InputHandler/InputHandler_PIUIO.cpp | 62 +++++++--------------------- src/arch/InputHandler/InputHandler_PIUIO.h | 9 +--- 14 files changed, 98 insertions(+), 113 deletions(-) diff --git a/ToDo.txt b/ToDo.txt index 648b041e..a515892e 100644 --- a/ToDo.txt +++ b/ToDo.txt @@ -4,9 +4,6 @@ -Switching modes on the main menu causes OpenITG to hang -Figure out what the hell's up with saving USB stats -/* Things to test on the arcade */ --See if separate coin counters have separate bit mappings - /* Minor bug fixing */ -InputHandler_PIUIO's coin code is broken -"Random" selections for non-existant BGVids always return the same video diff --git a/changelog.txt b/changelog.txt index 6c1bf9c1..9ca285f9 100755 --- a/changelog.txt +++ b/changelog.txt @@ -5,10 +5,14 @@ OpenITG, alpha 8 (in development) PacDrive ("pacdrive") - run lights using an Ultimarc PacDrive -Misc. changes: Allow multiple lights drivers (use at your own risk) + Disqualification for music rate under 1.0x -ITGIO changes: Softcoded ITGIO input and added default mappings Added mappings for all cabinet lighting Fixed "no output on ITGIO" issue (read: full I/O support) +-PIUIO changes: + Support for r16 kernel hack handling + Lots of misc. structural changes -New modifier: HoldsToRolls, a reversed NoRolls (make Bend Your Mind a living hell!) -Fixed mistakes: diff --git a/src/GameState.cpp b/src/GameState.cpp index 788d2d5a..e39369a7 100755 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -1087,6 +1087,9 @@ bool GameState::IsDisqualified( PlayerNumber pn ) if( !PREFSMAN->m_bDisqualification ) return false; + if( GAMESTATE->m_SongOptions.m_fMusicRate < 1.0f ) + return true; + if( GAMESTATE->IsCourseMode() ) { return GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions.IsEasierForCourseAndTrail( diff --git a/src/InputMapper.cpp b/src/InputMapper.cpp index 83c7ac81..1f85b71b 100755 --- a/src/InputMapper.cpp +++ b/src/InputMapper.cpp @@ -600,19 +600,6 @@ bool InputMapper::IsMapped( StyleInput StyleI ) return IsMapped( GameI ); } -// XXX: There *must* be a better way to do this... -bool InputMapper::IsMappedForStyle( DeviceInput DeviceI ) -{ - if( !GAMESTATE->m_pCurStyle ) - return false; - - GameInput GameI; - DeviceToGame( DeviceI, GameI ); - - StyleInput StyleI = GAMESTATE->m_pCurStyle->GameInputToStyleInput( GameI ); - return StyleI.IsValid(); -} - void InputMapper::UpdateTempDItoGI() { // clear out m_tempDItoGI diff --git a/src/InputMapper.h b/src/InputMapper.h index 20df3c5a..39f55920 100755 --- a/src/InputMapper.h +++ b/src/InputMapper.h @@ -36,8 +36,6 @@ public: bool IsMapped( GameInput GameI ); bool IsMapped( StyleInput StyleI ); - bool IsMappedForStyle( DeviceInput DeviceI ); - bool DeviceToGame( DeviceInput DeviceI, GameInput& GameI ); // return true if there is a mapping from device to pad bool GameToDevice( GameInput GameI, int iSoltNum, DeviceInput& DeviceI ); // return true if there is a mapping from pad to device diff --git a/src/RageUtil.cpp b/src/RageUtil.cpp index a94cf02e..d4bb9e11 100755 --- a/src/RageUtil.cpp +++ b/src/RageUtil.cpp @@ -10,9 +10,6 @@ #include #include -// a global flag used to interrupt a currently-running copy dialog. -bool g_bInterruptCopy; - int randseed = time(NULL); // From "Numerical Recipes in C". @@ -1487,8 +1484,18 @@ void FileWrite(RageFileBasic& f, float fWrite) f.PutLine( ssprintf("%f", fWrite) ); } +// a flag that can be used to interrupt a current copy operation +bool g_bInterruptCopy = false; + +void InterruptCopy() +{ + g_bInterruptCopy = true; +} + bool FileCopy( CString sSrcFile, CString sDstFile ) { + g_bInterruptCopy = false; + if( !sSrcFile.CompareNoCase(sDstFile) ) { LOG->Warn( "Tried to copy \"%s\" over itself", sSrcFile.c_str() ); @@ -1514,10 +1521,10 @@ bool FileCopy( CString sSrcFile, CString sDstFile ) return true; } -// This is, admittedly, ugly, but given the circumstances, this is the easiest -// way to get this to work. Occam's Razor has never failed me before... bool CopyWithProgress( CString sSrcFile, CString sDstFile, void(*OnUpdate)(float), CString &sError ) { + g_bInterruptCopy = false; + if( !sSrcFile.CompareNoCase(sDstFile) ) { sError = ssprintf( "Tried to copy \"%s\" over itself", sSrcFile.c_str() ); @@ -1594,6 +1601,8 @@ bool CopyWithProgress( CString sSrcFile, CString sDstFile, void(*OnUpdate)(float bool FileCopy( RageFileBasic &in, RageFileBasic &out, CString &sError, bool *bReadError ) { + g_bInterruptCopy = false; + while( !g_bInterruptCopy ) { CString data; @@ -1635,6 +1644,34 @@ bool FileCopy( RageFileBasic &in, RageFileBasic &out, CString &sError, bool *bRe return true; } +template +bool IsBitSet( T data, short bit ) +{ + int iBits = sizeof(T) * 8; + ASSERT_M( iBits > bit, "bit out of range" ); + + return data && ((T)1 << (iBits-bit)); +} + +template +void SetBit( T &data, short bit, bool on ) +{ + int iBits = sizeof(T) * 8; + ASSERT_M( iBits > bit, "bit out of range" ); +} + +template +CString BitsToString( T data ) +{ + int iBits = sizeof(T) * 8; + CString ret; + + for( int i = 0; i < iBits; i++ ) + ret.Insert( IsBitSet( data, i ) ? "1" : "0" ); + + return ret; +} + /* * Copyright (c) 2001-2004 Chris Danford, Glenn Maynard * Copyright (c) 2008 BoXoRRoXoRs diff --git a/src/RageUtil.h b/src/RageUtil.h index f92e93d9..5f8f162e 100755 --- a/src/RageUtil.h +++ b/src/RageUtil.h @@ -427,12 +427,21 @@ void FileWrite(RageFileBasic& f, int iWrite); void FileWrite(RageFileBasic& f, size_t uWrite); void FileWrite(RageFileBasic& f, float fWrite); +// stops a currently-running copy operation +void InterruptCopy(); + bool FileCopy( CString sSrcFile, CString sDstFile ); bool FileCopy( RageFileBasic &in, RageFileBasic &out, CString &sError, bool *bReadError = NULL ); bool CopyWithProgress( CString sSrcFile, CString sDstFile, void(*OnUpdate)(float), CString &sError ); -/* We will probably never need to use this. */ -//bool CopyWithProgress( RageFileBasic &in, RageFileBasic &out, RageFileBasic &read, -// CString &sError, void(*OnUpdate)(float), bool *bReadError = NULL ); + + +// a few bitwise operators that may come in handy +template +void SetBit( T data, short bit, bool on ); +template +bool IsBitSet( T data, short bit ); +template +CString BitsToString( T data ); #endif diff --git a/src/ScreenPlayerOptions.cpp b/src/ScreenPlayerOptions.cpp index e85d45fd..4d686505 100755 --- a/src/ScreenPlayerOptions.cpp +++ b/src/ScreenPlayerOptions.cpp @@ -67,7 +67,9 @@ void ScreenPlayerOptions::Init() FOREACH_HumanPlayer( p ) { - m_bRowCausesDisqualified[p].resize( m_Rows.size(), false ); + // save original player options + m_OriginalOptions[p] = GAMESTATE->m_pPlayerState[p]->m_PlayerOptions; + for( unsigned r=0; rm_pPlayerState[p]->m_PlayerOptions = m_OriginalOptions[p]; + if( SCREENMAN->IsStackedScreen(this) ) { SCREENMAN->PopTopScreen( SM_BackFromPlayerOptions ); @@ -199,32 +205,15 @@ void ScreenPlayerOptions::UpdateDisqualified( int row, PlayerNumber pn ) { ASSERT( GAMESTATE->IsHumanPlayer(pn) ); - // save original player options - PlayerOptions poOrig = GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions; - // Find out if the current row when exprorted causes disqualification. // Exporting the row will fill GAMESTATE->m_PlayerOptions. - GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions = PlayerOptions(); vector v; v.push_back( pn ); ExportOptions( row, v ); - bool bRowCausesDisqualified = GAMESTATE->IsDisqualified( pn ); - m_bRowCausesDisqualified[pn][row] = bRowCausesDisqualified; - - // Update disqualified graphic - bool bDisqualified = false; - FOREACH_CONST( bool, m_bRowCausesDisqualified[pn], b ) - { - if( *b ) - { - bDisqualified = true; - break; - } - } - m_sprDisqualify[pn]->SetHidden( !bDisqualified ); - // restore previous player options in case the user escapes back after this - GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions = poOrig; + // for song options, one change may disqualify both players - update each sprite + FOREACH_PlayerNumber( p ) + m_sprDisqualify[p]->SetVisible( GAMESTATE->IsDisqualified(p) ); } /* diff --git a/src/ScreenPlayerOptions.h b/src/ScreenPlayerOptions.h index 957c991e..2d8f6a2d 100755 --- a/src/ScreenPlayerOptions.h +++ b/src/ScreenPlayerOptions.h @@ -2,6 +2,7 @@ #define SCREENPLAYEROPTIONS_H #include "ScreenOptionsMaster.h" +#include "PlayerOptions.h" AutoScreenMessage( SM_BackFromPlayerOptions ) @@ -20,7 +21,6 @@ private: void GoToNextScreen(); void GoToPrevScreen(); - vector m_bRowCausesDisqualified[NUM_PLAYERS]; void UpdateDisqualified( int row, PlayerNumber pn ); bool m_bAcceptedChoices; @@ -29,8 +29,10 @@ private: Sprite m_sprOptionsMessage; RageSound m_CancelAll; - AutoActor m_sprCancelAll[NUM_PLAYERS]; + + // used to restore options if we back out + PlayerOptions m_OriginalOptions[NUM_PLAYERS]; }; #endif diff --git a/src/ScreenSelectMusic.cpp b/src/ScreenSelectMusic.cpp index d818529d..5a52fb96 100755 --- a/src/ScreenSelectMusic.cpp +++ b/src/ScreenSelectMusic.cpp @@ -70,8 +70,6 @@ static bool g_bSampleMusicWaiting = false; static RageTimer g_StartedLoadingAt(RageZeroTimer); static bool g_bGoToOptions = false; -extern bool g_bInterruptCopy; // from RageUtil - REGISTER_SCREEN_CLASS( ScreenSelectMusic ); ScreenSelectMusic::ScreenSelectMusic( CString sClassName ) : ScreenWithMenuElements( sClassName ), FOV( m_sName, "FOV" ), @@ -1344,10 +1342,11 @@ void UpdateLoadProgress( float fPercent ) ( INPUTMAPPER->IsButtonDown(MenuInput(pn, MENU_BUTTON_LEFT)) && INPUTMAPPER->IsButtonDown(MenuInput(pn, MENU_BUTTON_RIGHT)) ); - g_bInterruptCopy = bInterrupt; - if( bInterrupt ) - LOG->Debug( "Load interrupted." ); + { + InterruptCopy(); + LOG->Warn( "Custom song load interrupted." ); + } SCREENMAN->OverlayMessage( sMessage ); SCREENMAN->Draw(); diff --git a/src/arch/InputHandler/InputHandler.cpp b/src/arch/InputHandler/InputHandler.cpp index ef284018..d5393e3d 100755 --- a/src/arch/InputHandler/InputHandler.cpp +++ b/src/arch/InputHandler/InputHandler.cpp @@ -17,7 +17,9 @@ void InputHandler::UpdateTimer() void InputHandler::ButtonPressed( DeviceInput di, bool Down ) { - //LOG->Debug( "%s %s", di.toString().c_str(), Down ? "pressed" : "released" ); + // this gets spammed a lot. + if( di.button != KEY_SPACE ) + LOG->Debug( "%s %s", di.toString().c_str(), Down ? "pressed" : "released" ); if( di.ts.IsZero() ) { diff --git a/src/arch/InputHandler/InputHandler.h b/src/arch/InputHandler/InputHandler.h index f0236e51..8d9cfb9c 100755 --- a/src/arch/InputHandler/InputHandler.h +++ b/src/arch/InputHandler/InputHandler.h @@ -29,9 +29,6 @@ public: virtual ~InputHandler() { } virtual void Update( float fDeltaTime ) { } virtual void GetDevicesAndDescriptions( vector& vDevicesOut, vector& vDescriptionsOut ) = 0; - /* Devices that report sensors may need to determine which buttons to report for, - * and it'd be too slow to poll. Call manually as needed. */ - virtual void ReloadSensorReports() { } /* In Windows, some devices need to be recreated if we recreate our main window. * Override this if you need to do that. */ diff --git a/src/arch/InputHandler/InputHandler_PIUIO.cpp b/src/arch/InputHandler/InputHandler_PIUIO.cpp index 41682160..e7141933 100644 --- a/src/arch/InputHandler/InputHandler_PIUIO.cpp +++ b/src/arch/InputHandler/InputHandler_PIUIO.cpp @@ -47,8 +47,6 @@ InputHandler_PIUIO::InputHandler_PIUIO() InternalInputHandler = &InputHandler_PIUIO::HandleInputNormal; } - ReloadSensorReports(); - InputThread.SetName( "PIUIO thread" ); InputThread.Create( InputThread_Start, this ); } @@ -80,17 +78,6 @@ void InputHandler_PIUIO::GetDevicesAndDescriptions( vector& vDevice } } -void InputHandler_PIUIO::ReloadSensorReports() -{ - if( !INPUTMAPPER ) - return; - - // figure out which inputs we should report sensors on - pads only - // XXX: make this refresh whenever mappings have changed! - for( int i = 0; i < 32; i++ ) - m_bReportSensor[i] = INPUTMAPPER->IsMappedForStyle( DeviceInput(DEVICE_JOY1, JOY_1+i) ); -} - int InputHandler_PIUIO::InputThread_Start( void *p ) { ((InputHandler_PIUIO *) p)->InputThreadMain(); @@ -125,39 +112,25 @@ static CString InputToBinary( uint32_t array ) static CString SensorNames[] = { "right", "left", "bottom", "top" }; -static CString GetSensorDescription( bool *bSensorArray ) +static CString GetSensorDescription( bool *bArray ) { - CStringArray retSensors; + CStringArray sensors; for( int i = 0; i < 4; i++ ) - if( bSensorArray[i] ) retSensors.push_back( SensorNames[i] ); + if( bArray[i] ) sensors.push_back( SensorNames[i] ); - return join(", ", retSensors); -} + /* HACK: if all sensors are reporting, then don't return anything. + * On PIUIO, all buttons always return all sensors except pads. */ + if( sensors.size() == 4 ) + return ""; -// XXX: phase out as soon as possible -const bool IsPadInput( int iButton ) -{ - switch( iButton+1 ) - { - case 13: case 14: case 15: case 16: /* Player 2 */ - case 29: case 30: case 31: case 32: /* Player 1 */ - return true; - break; - default: - return false; - } - - return false; + return join(", ", sensors); } /* code to handle the r16 kernel hack */ void InputHandler_PIUIO::HandleInputKernel() { ZERO( m_iBulkReadData ); - ZERO( m_iInputField ); - - CHECKPOINT; m_iLightData &= 0xFFFCFFFC; @@ -186,7 +159,7 @@ void InputHandler_PIUIO::HandleInputKernel() // figure out which sensors were enabled for( int j = 0; j < 32; j++ ) if( m_iBulkReadData[i*2] & (1 << 32-j) ) - m_bInputs[j][i] = true; + m_bSensors[j][i] = true; } } @@ -194,9 +167,6 @@ void InputHandler_PIUIO::HandleInputKernel() void InputHandler_PIUIO::HandleInputNormal() { ZERO( m_iInputData ); - ZERO( m_iInputField ); - - CHECKPOINT; for (uint32_t i = 0; i < 4; i++) { @@ -217,19 +187,18 @@ void InputHandler_PIUIO::HandleInputNormal() /* Toggle sensor bits - Left, Right, Up, Down */ for( int j = 0; j < 32; j++ ) if( m_iInputData[i] & (1 << 32-j) ) - m_bInputs[j][i] = true; + m_bSensors[j][i] = true; } } -// XXX fixed 4/7/08. Game. Set. Match. --infamouspat -// ITT history :D -- vyhd void InputHandler_PIUIO::HandleInput() { m_InputTimer.Touch(); - // reset - ZERO( m_bInputs ); + // reset our reading data + ZERO( m_bSensors ); + ZERO( m_iInputField ); // sets up m_iInputField for usage (this->*InternalInputHandler)(); @@ -241,7 +210,6 @@ void InputHandler_PIUIO::HandleInput() // construct outside the loop, to save some processor time DeviceInput di(DEVICE_JOY1, JOY_1); - /* Actually handle the input now */ for( int iButton = 0; iButton < 32; iButton++ ) { di.button = JOY_1+iButton; @@ -251,9 +219,7 @@ void InputHandler_PIUIO::HandleInput() di.ts.Touch(); /* Set a description of detected sensors to the arrows */ - // XXX: phase out ASAP! - if( IsPadInput(iButton) ) - INPUTFILTER->SetButtonComment( di, GetSensorDescription(m_bInputs[iButton]) ); + INPUTFILTER->SetButtonComment( di, GetSensorDescription(m_bSensors[iButton]) ); /* Is the button we're looking for flagged in the input data? */ ButtonPressed( di, m_iInputField & (1 << (31-iButton)) ); diff --git a/src/arch/InputHandler/InputHandler_PIUIO.h b/src/arch/InputHandler/InputHandler_PIUIO.h index 3a7ff2cc..2bf2ff1e 100644 --- a/src/arch/InputHandler/InputHandler_PIUIO.h +++ b/src/arch/InputHandler/InputHandler_PIUIO.h @@ -19,9 +19,8 @@ public: ~InputHandler_PIUIO(); void GetDevicesAndDescriptions( vector& vDevicesOut, vector& vDescriptionsOut ); - void ReloadSensorReports(); private: - + PIUIO Board; RageThread InputThread; @@ -40,10 +39,7 @@ private: void InputThreadMain(); // keeps track of which sensors are on for each input - bool m_bInputs[32][4]; - - // used to determine which inputs have sensor comments - bool m_bReportSensor[32]; + bool m_bSensors[32][4]; /* the fully combined bit field that input is read from */ uint32_t m_iInputField; @@ -67,7 +63,6 @@ private: RageTimer m_USBTimer; unsigned int m_iReadCount; float m_fTotalReadTime; - }; -- 2.11.0