diff --git a/stepmania/src/NoteDisplay.cpp b/stepmania/src/NoteDisplay.cpp index ab0eaf6d60..38d2453516 100644 --- a/stepmania/src/NoteDisplay.cpp +++ b/stepmania/src/NoteDisplay.cpp @@ -183,164 +183,117 @@ Sprite *MakeRefcountedSprite( const CString &sPath ) return (Sprite *) pRes->m_pActor; /* XXX ick */ } -NoteDisplay::NoteDisplay() +NoteColorActor::NoteColorActor() { for( int i=0; iGetPathToFromNoteSkinAndButton(sNoteSkin, sButton, sElement+" "+NoteTypeToString((NoteType)i)) ); + } + else + { + m_p[0] = MakeRefcountedActor( NOTESKIN->GetPathToFromNoteSkinAndButton(sNoteSkin, sButton, sElement) ); + } +} + +Actor* NoteColorActor::Get( NoteType nt ) +{ + if( m_bIsNoteColor ) + nt = min( nt, (NoteType) (NOTE_COLOR_IMAGES-1) ); + else + nt = NoteType(0); + + return m_p[ m_bIsNoteColor ? nt : 0 ]; +} + + +NoteColorSprite::NoteColorSprite() +{ + for( int i=0; iGetPathToFromNoteSkinAndButton(sNoteSkin, sButton, sElement+" "+NoteTypeToString((NoteType)i)) ); + } + else + { + m_p[0] = MakeRefcountedSprite( NOTESKIN->GetPathToFromNoteSkinAndButton(sNoteSkin, sButton, sElement) ); + } +} + +Sprite* NoteColorSprite::Get( NoteType nt ) +{ + if( m_bIsNoteColor ) + nt = min( nt, (NoteType) (NOTE_COLOR_IMAGES-1) ); + else + nt = NoteType(0); + + return m_p[ m_bIsNoteColor ? nt : 0 ]; +} + + +NoteDisplay::NoteDisplay() +{ cache = new NoteMetricCache_t; } NoteDisplay::~NoteDisplay() { - for( int i=0; iGetCurrentGame()->ColToButtonName( iColNum ); + CString sButton = GAMESTATE->GetCurrentGame()->ColToButtonName( iColNum ); - cache->Load( NoteSkin, Button ); + cache->Load( sNoteSkin, sButton ); - // Look up note names once and store them here. - CString sNoteType[ NOTE_COLOR_IMAGES ]; - for( int i=0; im_bAnimationIsNoteColor[PART_TAP] ) - { - for( int i=0; iGetPathToFromNoteSkinAndButton(NoteSkin, Button, "tap note "+sNoteType[i]) ); - } - else - { - m_pTapNote[0] = MakeRefcountedActor( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "tap note") ); - } - - if( cache->m_bAnimationIsNoteColor[PART_ADDITION] ) - { - for( int i=0; iGetPathToFromNoteSkinAndButton(NoteSkin, Button, "tap addition "+sNoteType[i]) ); - } - else - { - m_pTapAddition[0] = MakeRefcountedActor( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "tap addition") ); - } - - if( cache->m_bAnimationIsNoteColor[PART_MINE] ) - { - for( int i=0; iGetPathToFromNoteSkinAndButton(NoteSkin, Button, "tap mine "+sNoteType[i]) ); - } - else - { - m_pTapMine[0] = MakeRefcountedActor( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "tap mine") ); - } - - if( cache->m_bAnimationIsNoteColor[PART_HOLD_HEAD] ) - { - for( int i=0; iGetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold head active "+sNoteType[i]) ); - m_pHoldHeadInactive[i] = MakeRefcountedActor( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold head inactive "+sNoteType[i]) ); - } - } - else - { - m_pHoldHeadActive[0] = MakeRefcountedActor( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold head active") ); - m_pHoldHeadInactive[0] = MakeRefcountedActor( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold head inactive") ); - } - - if( cache->m_bAnimationIsNoteColor[PART_HOLD_TOP_CAP] ) - { - for( int i=0; iGetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold topcap active "+sNoteType[i]) ); - m_pHoldTopCapInactive[i] = MakeRefcountedSprite( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold topcap inactive "+sNoteType[i]) ); - } - } - else - { - m_pHoldTopCapActive[0] = MakeRefcountedSprite( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold topcap active") ); - m_pHoldTopCapInactive[0] = MakeRefcountedSprite( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold topcap inactive") ); - } - - if( cache->m_bAnimationIsNoteColor[PART_HOLD_BODY] ) - { - for( int i=0; iGetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold body active "+sNoteType[i]) ); - m_pHoldBodyInactive[i] = MakeRefcountedSprite( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold body inactive "+sNoteType[i]) ); - } - } - else - { - m_pHoldBodyActive[0] = MakeRefcountedSprite( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold body active") ); - m_pHoldBodyInactive[0] = MakeRefcountedSprite( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold body inactive") ); - } - - if( cache->m_bAnimationIsNoteColor[PART_HOLD_BOTTOM_CAP] ) - { - for( int i=0; iGetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold bottomcap active "+sNoteType[i]) ); - m_pHoldBottomCapInactive[i] = MakeRefcountedSprite( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold bottomcap inactive "+sNoteType[i]) ); - } - } - else - { - m_pHoldBottomCapActive[0] = MakeRefcountedSprite( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold bottomcap active") ); - m_pHoldBottomCapInactive[0] = MakeRefcountedSprite( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold bottomcap inactive") ); - } - - if( cache->m_bAnimationIsNoteColor[PART_HOLD_TAIL] ) - { - for( int i=0; iGetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold tail active "+sNoteType[i]) ); - m_pHoldTailInactive[i] = MakeRefcountedActor( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold tail inactive "+sNoteType[i]) ); - } - } - else - { - m_pHoldTailActive[0] = MakeRefcountedActor( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold tail active") ); - m_pHoldTailInactive[0] = MakeRefcountedActor( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin, Button, "hold tail inactive") ); - } + m_TapNote.Load( cache->m_bAnimationIsNoteColor[PART_TAP], sNoteSkin, sButton, "tap note" ); + m_TapAddition.Load( cache->m_bAnimationIsNoteColor[PART_ADDITION], sNoteSkin, sButton, "tap addition" ); + m_TapMine.Load( cache->m_bAnimationIsNoteColor[PART_MINE], sNoteSkin, sButton, "tap mine" ); + m_HoldHeadActive.Load( cache->m_bAnimationIsNoteColor[PART_HOLD_HEAD], sNoteSkin, sButton, "hold head active" ); + m_HoldHeadInactive.Load( cache->m_bAnimationIsNoteColor[PART_HOLD_HEAD], sNoteSkin, sButton, "hold head inactive" ); + m_HoldTopCapActive.Load( cache->m_bAnimationIsNoteColor[PART_HOLD_TOP_CAP], sNoteSkin, sButton, "hold topcap active" ); + m_HoldTopCapInactive.Load( cache->m_bAnimationIsNoteColor[PART_HOLD_TOP_CAP], sNoteSkin, sButton, "hold topcap inactive" ); + m_HoldBodyActive.Load( cache->m_bAnimationIsNoteColor[PART_HOLD_BODY], sNoteSkin, sButton, "hold body active" ); + m_HoldBodyInactive.Load( cache->m_bAnimationIsNoteColor[PART_HOLD_BODY], sNoteSkin, sButton, "hold body inactive" ); + m_HoldBottomCapActive.Load( cache->m_bAnimationIsNoteColor[PART_HOLD_BOTTOM_CAP], sNoteSkin, sButton, "hold bottomcap active" ); + m_HoldBottomCapInactive.Load( cache->m_bAnimationIsNoteColor[PART_HOLD_BOTTOM_CAP], sNoteSkin, sButton, "hold bottomcap inactive" ); + m_HoldTailActive.Load( cache->m_bAnimationIsNoteColor[PART_HOLD_TAIL], sNoteSkin, sButton, "hold tail active" ); + m_HoldTailInactive.Load( cache->m_bAnimationIsNoteColor[PART_HOLD_TAIL], sNoteSkin, sButton, "hold tail inactive" ); } bool NoteDisplay::DrawHoldHeadForTapsOnSameRow() const @@ -394,15 +347,8 @@ void NoteDisplay::SetActiveFrame( float fNoteBeat, Actor &actorToSet, float fAni Actor * NoteDisplay::GetTapNoteActor( float fNoteBeat ) { - NoteType nt = NoteType(0); - if( cache->m_bAnimationIsNoteColor[PART_TAP] ) - nt = BeatToNoteType( fNoteBeat ); -// NOTE_TYPE_INVALID is 192nds at this point. - if( nt == NOTE_TYPE_INVALID ) - nt = NOTE_TYPE_192ND; - nt = min( nt, (NoteType) (NOTE_COLOR_IMAGES-1) ); - - Actor *pActorOut = m_pTapNote[nt]; + NoteType nt = BeatToNoteType( fNoteBeat ); + Actor *pActorOut = m_TapNote.Get( nt ); SetActiveFrame( fNoteBeat, @@ -416,15 +362,8 @@ Actor * NoteDisplay::GetTapNoteActor( float fNoteBeat ) Actor * NoteDisplay::GetTapAdditionActor( float fNoteBeat ) { - NoteType nt = NoteType(0); - if( cache->m_bAnimationIsNoteColor[PART_ADDITION] ) - nt = BeatToNoteType( fNoteBeat ); -// NOTE_TYPE_INVALID is 192nds at this point. - if( nt == NOTE_TYPE_INVALID ) - nt = NOTE_TYPE_192ND; - nt = min( nt, (NoteType) (NOTE_COLOR_IMAGES-1) ); - - Actor *pActorOut = m_pTapAddition[nt]; + NoteType nt = BeatToNoteType( fNoteBeat ); + Actor *pActorOut = m_TapAddition.Get( nt ); SetActiveFrame( fNoteBeat, @@ -438,14 +377,8 @@ Actor * NoteDisplay::GetTapAdditionActor( float fNoteBeat ) Actor * NoteDisplay::GetTapMineActor( float fNoteBeat ) { - NoteType nt = NoteType(0); - if( cache->m_bAnimationIsNoteColor[PART_MINE] ) - nt = BeatToNoteType( fNoteBeat ); - if( nt == NOTE_TYPE_INVALID ) - nt = NOTE_TYPE_192ND; - nt = min( nt, (NoteType) (NOTE_COLOR_IMAGES-1) ); - - Actor *pActorOut = m_pTapMine[nt]; + NoteType nt = BeatToNoteType( fNoteBeat ); + Actor *pActorOut = m_TapMine.Get( nt ); SetActiveFrame( fNoteBeat, @@ -459,15 +392,8 @@ Actor * NoteDisplay::GetTapMineActor( float fNoteBeat ) Sprite * NoteDisplay::GetHoldTopCapSprite( float fNoteBeat, bool bIsBeingHeld ) { - NoteType nt = NoteType(0); - if( cache->m_bAnimationIsNoteColor[PART_HOLD_TOP_CAP] ) - nt = BeatToNoteType( fNoteBeat ); -// NOTE_TYPE_INVALID is 192nds at this point. - if( nt == NOTE_TYPE_INVALID ) - nt = NOTE_TYPE_192ND; - nt = min( nt, (NoteType) (NOTE_COLOR_IMAGES-1) ); - - Sprite *pSpriteOut = bIsBeingHeld ? m_pHoldTopCapActive[nt] : m_pHoldTopCapInactive[nt]; + NoteType nt = BeatToNoteType( fNoteBeat ); + Sprite *pSpriteOut = (bIsBeingHeld ? m_HoldTopCapActive : m_HoldTopCapInactive).Get( nt ); SetActiveFrame( fNoteBeat, @@ -481,15 +407,8 @@ Sprite * NoteDisplay::GetHoldTopCapSprite( float fNoteBeat, bool bIsBeingHeld ) Sprite * NoteDisplay::GetHoldBottomCapSprite( float fNoteBeat, bool bIsBeingHeld ) { - NoteType nt = NoteType(0); - if( cache->m_bAnimationIsNoteColor[PART_HOLD_BOTTOM_CAP] ) - nt = BeatToNoteType( fNoteBeat ); -// NOTE_TYPE_INVALID is 192nds at this point. - if( nt == NOTE_TYPE_INVALID ) - nt = NOTE_TYPE_192ND; - nt = min( nt, (NoteType) (NOTE_COLOR_IMAGES-1) ); - - Sprite *pSpriteOut = bIsBeingHeld ? m_pHoldBottomCapActive[nt] : m_pHoldBottomCapInactive[nt]; + NoteType nt = BeatToNoteType( fNoteBeat ); + Sprite *pSpriteOut = (bIsBeingHeld ? m_HoldBottomCapActive : m_HoldBottomCapInactive).Get( nt ); SetActiveFrame( fNoteBeat, @@ -504,15 +423,8 @@ Sprite * NoteDisplay::GetHoldBottomCapSprite( float fNoteBeat, bool bIsBeingHeld Actor* NoteDisplay::GetHoldHeadActor( float fNoteBeat, bool bIsBeingHeld ) { - NoteType nt = NoteType(0); - if( cache->m_bAnimationIsNoteColor[PART_HOLD_HEAD] ) - nt = BeatToNoteType( fNoteBeat ); -// NOTE_TYPE_INVALID is 192nds at this point. - if( nt == NOTE_TYPE_INVALID ) - nt = NOTE_TYPE_192ND; - nt = min( nt, (NoteType) (NOTE_COLOR_IMAGES-1) ); - - Actor *pActorOut = bIsBeingHeld ? m_pHoldHeadActive[nt] : m_pHoldHeadInactive[nt]; + NoteType nt = BeatToNoteType( fNoteBeat ); + Actor *pActorOut = (bIsBeingHeld ? m_HoldHeadActive : m_HoldHeadInactive).Get( nt ); SetActiveFrame( fNoteBeat, @@ -526,15 +438,8 @@ Actor* NoteDisplay::GetHoldHeadActor( float fNoteBeat, bool bIsBeingHeld ) Sprite *NoteDisplay::GetHoldBodySprite( float fNoteBeat, bool bIsBeingHeld ) { - NoteType nt = NoteType(0); - if( cache->m_bAnimationIsNoteColor[PART_HOLD_BODY] ) - nt = BeatToNoteType( fNoteBeat ); -// NOTE_TYPE_INVALID is 192nds at this point. - if( nt == NOTE_TYPE_INVALID ) - nt = NOTE_TYPE_192ND; - nt = min( nt, (NoteType) (NOTE_COLOR_IMAGES-1) ); - - Sprite *pSpriteOut = bIsBeingHeld ? m_pHoldBodyActive[nt] : m_pHoldBodyInactive[nt]; + NoteType nt = BeatToNoteType( fNoteBeat ); + Sprite *pSpriteOut = (bIsBeingHeld ? m_HoldBodyActive : m_HoldBodyInactive).Get( nt ); SetActiveFrame( fNoteBeat, @@ -548,15 +453,8 @@ Sprite *NoteDisplay::GetHoldBodySprite( float fNoteBeat, bool bIsBeingHeld ) Actor* NoteDisplay::GetHoldTailActor( float fNoteBeat, bool bIsBeingHeld ) { - NoteType nt = NoteType(0); - if( cache->m_bAnimationIsNoteColor[PART_HOLD_TAIL] ) - nt = BeatToNoteType( fNoteBeat ); -// NOTE_TYPE_INVALID is 192nds at this point. - if( nt == NOTE_TYPE_INVALID ) - nt = NOTE_TYPE_192ND; - nt = min( nt, (NoteType) (NOTE_COLOR_IMAGES-1) ); - - Actor *pActorOut = bIsBeingHeld ? m_pHoldTailActive[nt] : m_pHoldTailInactive[nt]; + NoteType nt = BeatToNoteType( fNoteBeat ); + Actor *pActorOut = (bIsBeingHeld ? m_HoldTailActive : m_HoldTailInactive).Get( nt ); SetActiveFrame( fNoteBeat, diff --git a/stepmania/src/NoteDisplay.h b/stepmania/src/NoteDisplay.h index a0cea2a555..1a1d62a3bc 100644 --- a/stepmania/src/NoteDisplay.h +++ b/stepmania/src/NoteDisplay.h @@ -11,13 +11,37 @@ struct HoldNoteResult; struct NoteMetricCache_t; struct PlayerState; +#define NOTE_COLOR_IMAGES 8 + +struct NoteColorActor +{ + NoteColorActor(); + ~NoteColorActor(); + void Load( bool bIsNoteColor, const CString &sNoteSkin, const CString &sButton, const CString &sElement ); + Actor* Get( NoteType nt ); +private: + Actor* m_p[NOTE_COLOR_IMAGES]; + bool m_bIsNoteColor; +}; + +struct NoteColorSprite +{ + NoteColorSprite(); + ~NoteColorSprite(); + void Load( bool bIsNoteColor, const CString &sNoteSkin, const CString &sButton, const CString &sElement ); + Sprite* Get( NoteType nt ); +private: + Sprite* m_p[NOTE_COLOR_IMAGES]; + bool m_bIsNoteColor; +}; + class NoteDisplay { public: NoteDisplay(); ~NoteDisplay(); - void Load( int iColNum, const PlayerState* pPlayerState, CString NoteSkin, float fYReverseOffsetPixels ); + void Load( int iColNum, const PlayerState* pPlayerState, const CString &sNoteSkin, float fYReverseOffsetPixels ); static void Update( float fDeltaTime ); @@ -48,21 +72,19 @@ protected: struct NoteMetricCache_t *cache; -#define NOTE_COLOR_IMAGES 8 - - Actor* m_pTapNote[NOTE_COLOR_IMAGES]; - Actor* m_pTapAddition[NOTE_COLOR_IMAGES]; - Actor* m_pTapMine[NOTE_COLOR_IMAGES]; - Actor* m_pHoldHeadActive[NOTE_COLOR_IMAGES]; - Actor* m_pHoldHeadInactive[NOTE_COLOR_IMAGES]; - Sprite* m_pHoldTopCapActive[NOTE_COLOR_IMAGES]; - Sprite* m_pHoldTopCapInactive[NOTE_COLOR_IMAGES]; - Sprite* m_pHoldBodyActive[NOTE_COLOR_IMAGES]; - Sprite* m_pHoldBodyInactive[NOTE_COLOR_IMAGES]; - Sprite* m_pHoldBottomCapActive[NOTE_COLOR_IMAGES]; - Sprite* m_pHoldBottomCapInactive[NOTE_COLOR_IMAGES]; - Actor* m_pHoldTailActive[NOTE_COLOR_IMAGES]; - Actor* m_pHoldTailInactive[NOTE_COLOR_IMAGES]; + NoteColorActor m_TapNote; + NoteColorActor m_TapAddition; + NoteColorActor m_TapMine; + NoteColorActor m_HoldHeadActive; + NoteColorActor m_HoldHeadInactive; + NoteColorSprite m_HoldTopCapActive; + NoteColorSprite m_HoldTopCapInactive; + NoteColorSprite m_HoldBodyActive; + NoteColorSprite m_HoldBodyInactive; + NoteColorSprite m_HoldBottomCapActive; + NoteColorSprite m_HoldBottomCapInactive; + NoteColorActor m_HoldTailActive; + NoteColorActor m_HoldTailInactive; float m_fYReverseOffsetPixels; }; diff --git a/stepmania/src/NoteTypes.cpp b/stepmania/src/NoteTypes.cpp index 5732e0e36f..e65e57239e 100644 --- a/stepmania/src/NoteTypes.cpp +++ b/stepmania/src/NoteTypes.cpp @@ -1,5 +1,6 @@ #include "global.h" #include "NoteTypes.h" +#include "RageUtil.h" TapNote TAP_EMPTY ( TapNote::empty, TapNote::original, "", 0, false, 0 ); TapNote TAP_ORIGINAL_TAP ( TapNote::tap, TapNote::original, "", 0, false, 0 ); @@ -10,6 +11,19 @@ TapNote TAP_ORIGINAL_AUTO_KEYSOUND ( TapNote::autoKeysound,TapNote::original, "" TapNote TAP_ADDITION_TAP ( TapNote::tap, TapNote::addition, "", 0, false, 0 ); TapNote TAP_ADDITION_MINE ( TapNote::mine, TapNote::addition, "", 0, false, 0 ); +static const CString NoteTypeNames[NUM_NOTE_TYPES] = { + "4th", + "8th", + "12th", + "16th", + "24th", + "32nd", + "48th", + "64th", + "192nd", +}; +XToString( NoteType, NUM_NOTE_TYPES ); + float NoteTypeToBeat( NoteType nt ) { switch( nt ) @@ -46,24 +60,6 @@ NoteType GetNoteType( int row ) else return NOTE_TYPE_INVALID; }; -CString NoteTypeToString( NoteType nt ) -{ - switch( nt ) - { - case NOTE_TYPE_4TH: return "4th"; - case NOTE_TYPE_8TH: return "8th"; - case NOTE_TYPE_12TH: return "12th"; - case NOTE_TYPE_16TH: return "16th"; - case NOTE_TYPE_24TH: return "24th"; - case NOTE_TYPE_32ND: return "32nd"; - case NOTE_TYPE_48TH: return "48th"; - case NOTE_TYPE_64TH: return "64th"; - case NOTE_TYPE_192ND: // fall through - case NOTE_TYPE_INVALID: return "192nd"; - default: ASSERT(0); return ""; - } -} - NoteType BeatToNoteType( float fBeat ) { return GetNoteType( BeatToNoteRow(fBeat) ); diff --git a/stepmania/src/NoteTypes.h b/stepmania/src/NoteTypes.h index 766b39ab33..5e9e6cdd7b 100644 --- a/stepmania/src/NoteTypes.h +++ b/stepmania/src/NoteTypes.h @@ -173,12 +173,11 @@ enum NoteType NUM_NOTE_TYPES, NOTE_TYPE_INVALID }; - +const CString& NoteTypeToString( NoteType nt ); float NoteTypeToBeat( NoteType nt ); NoteType GetNoteType( int row ); NoteType BeatToNoteType( float fBeat ); bool IsNoteOfType( int row, NoteType t ); -CString NoteTypeToString( NoteType nt ); /* This is more accurate: by computing the integer and fractional parts separately, we * can avoid storing very large numbers in a float and possibly losing precision. It's