diff --git a/stepmania/src/GhostArrow.cpp b/stepmania/src/GhostArrow.cpp index 4d7660d3fc..386cbf9400 100644 --- a/stepmania/src/GhostArrow.cpp +++ b/stepmania/src/GhostArrow.cpp @@ -7,7 +7,7 @@ GhostArrow::GhostArrow() { } -void GhostArrow::Load( CString sNoteSkin, CString sButton, CString sElement ) +void GhostArrow::Load( const CString &sButton, const CString &sElement ) { FOREACH_TapNoteScore( i ) { @@ -17,7 +17,7 @@ void GhostArrow::Load( CString sNoteSkin, CString sButton, CString sElement ) ASSERT( !m_spr[i].IsLoaded() ); // don't double-load - m_spr[i].Load( NOTESKIN->GetPathToFromNoteSkinAndButton(sNoteSkin, sButton, sFullElement) ); + m_spr[i].Load( NOTESKIN->GetPath(sButton, sFullElement) ); m_spr[i]->SetHidden( true ); this->AddChild( m_spr[i] ); } @@ -26,8 +26,7 @@ void GhostArrow::Load( CString sNoteSkin, CString sButton, CString sElement ) { CString sJudge = TapNoteScoreToString( i ); CString sCommand = Capitalize(sJudge)+"Command"; - apActorCommands p( new ActorCommands(NOTESKIN->GetMetric(sNoteSkin,m_sName,sCommand)) ); - m_acScoreCommand[i] = p; + m_acScoreCommand[i] = NOTESKIN->GetMetricA(m_sName,sCommand); } } diff --git a/stepmania/src/GhostArrow.h b/stepmania/src/GhostArrow.h index 50a1b7d90e..1c8a160b4f 100644 --- a/stepmania/src/GhostArrow.h +++ b/stepmania/src/GhostArrow.h @@ -14,7 +14,7 @@ class GhostArrow : public ActorFrame public: GhostArrow(); - void Load( CString sNoteSkin, CString sButton, CString sFile ); + void Load( const CString &sButton, const CString &sFile ); void Step( TapNoteScore score ); diff --git a/stepmania/src/GhostArrowRow.cpp b/stepmania/src/GhostArrowRow.cpp index 63ba0bda3f..68272e43fc 100644 --- a/stepmania/src/GhostArrowRow.cpp +++ b/stepmania/src/GhostArrowRow.cpp @@ -18,7 +18,7 @@ GhostArrowRow::GhostArrowRow() m_iNumCols = 0; } -void GhostArrowRow::Load( const PlayerState* pPlayerState, CString NoteSkin, float fYReverseOffset ) +void GhostArrowRow::Load( const PlayerState* pPlayerState, float fYReverseOffset ) { Unload(); @@ -32,7 +32,7 @@ void GhostArrowRow::Load( const PlayerState* pPlayerState, CString NoteSkin, flo // init arrows for( int c=0; cGetCurrentGame()->ColToButtonName( c ); + const CString &sButton = GAMESTATE->GetCurrentGame()->ColToButtonName( c ); m_GhostDim.push_back( new GhostArrow ); m_GhostBright.push_back( new GhostArrow ); @@ -42,9 +42,9 @@ void GhostArrowRow::Load( const PlayerState* pPlayerState, CString NoteSkin, flo m_GhostBright[c]->SetName( "GhostArrowBright" ); m_HoldGhost[c]->SetName( "HoldGhostArrow" ); - m_GhostDim[c]->Load( NoteSkin, Button, "tap explosion dim" ); - m_GhostBright[c]->Load( NoteSkin, Button, "tap explosion bright" ); - m_HoldGhost[c]->Load( NoteSkin, Button, "hold explosion" ); + m_GhostDim[c]->Load( sButton, "tap explosion dim" ); + m_GhostBright[c]->Load( sButton, "tap explosion bright" ); + m_HoldGhost[c]->Load( sButton, "hold explosion" ); } } diff --git a/stepmania/src/GhostArrowRow.h b/stepmania/src/GhostArrowRow.h index a7be2a53bd..1735621305 100644 --- a/stepmania/src/GhostArrowRow.h +++ b/stepmania/src/GhostArrowRow.h @@ -19,7 +19,7 @@ public: virtual void DrawPrimitives(); virtual void CopyTweening( const GhostArrowRow &from ); - void Load( const PlayerState* pPlayerState, CString NoteSkin, float fYReverseOffset ); + void Load( const PlayerState* pPlayerState, float fYReverseOffset ); void Unload(); void DidTapNote( int iCol, TapNoteScore score, bool bBright ); diff --git a/stepmania/src/HoldGhostArrow.cpp b/stepmania/src/HoldGhostArrow.cpp index aca8cbc803..262a24a604 100644 --- a/stepmania/src/HoldGhostArrow.cpp +++ b/stepmania/src/HoldGhostArrow.cpp @@ -2,15 +2,17 @@ #include "HoldGhostArrow.h" #include "NoteSkinManager.h" + + HoldGhostArrow::HoldGhostArrow() { m_bHoldIsActive = false; } -void HoldGhostArrow::Load( CString sNoteSkin, CString sButton, CString sElement ) +void HoldGhostArrow::Load( const CString &sButton, const CString &sElement ) { - Sprite::Load( NOTESKIN->GetPathToFromNoteSkinAndButton(sNoteSkin, sButton, sElement) ); // not optional - this->RunCommands( ActorCommands(NOTESKIN->GetMetric(sNoteSkin,"HoldGhostArrow","OnCommand")) ); + Sprite::Load( NOTESKIN->GetPath(sButton, sElement) ); // not optional + this->RunCommands( NOTESKIN->GetMetricA("HoldGhostArrow","OnCommand") ); } void HoldGhostArrow::Update( float fDeltaTime ) diff --git a/stepmania/src/HoldGhostArrow.h b/stepmania/src/HoldGhostArrow.h index e7261a90b0..29d947fc07 100644 --- a/stepmania/src/HoldGhostArrow.h +++ b/stepmania/src/HoldGhostArrow.h @@ -10,7 +10,7 @@ class HoldGhostArrow : public Sprite public: HoldGhostArrow(); - virtual void Load( CString sNoteSkin, CString sButton, CString sElement ); + virtual void Load( const CString &sButton, const CString &sElement ); virtual void Update( float fDeltaTime ); virtual bool EarlyAbortDraw() { return !m_bHoldIsActive; } diff --git a/stepmania/src/NoteDisplay.cpp b/stepmania/src/NoteDisplay.cpp index 38d2453516..cd8aee0b47 100644 --- a/stepmania/src/NoteDisplay.cpp +++ b/stepmania/src/NoteDisplay.cpp @@ -48,55 +48,72 @@ struct NoteMetricCache_t bool m_bHoldTailUseLighting; bool m_bFlipHeadAndTailWhenReverse; - void Load(CString skin, const CString &name); + void Load( const CString &sButton ); } *NoteMetricCache; -void NoteMetricCache_t::Load(CString skin, const CString &name) +void NoteMetricCache_t::Load( const CString &sButton ) { - m_bDrawHoldHeadForTapsOnSameRow = NOTESKIN->GetMetricB(skin,name,"DrawHoldHeadForTapsOnSameRow"); - m_fAnimationLengthInBeats[PART_TAP] = NOTESKIN->GetMetricF(skin,name,"TapNoteAnimationLengthInBeats"); - m_fAnimationLengthInBeats[PART_ADDITION] = NOTESKIN->GetMetricF(skin,name,"TapAdditionAnimationLengthInBeats"); - m_fAnimationLengthInBeats[PART_MINE] = NOTESKIN->GetMetricF(skin,name,"TapMineAnimationLengthInBeats"); - m_fAnimationLengthInBeats[PART_HOLD_HEAD] = NOTESKIN->GetMetricF(skin,name,"HoldHeadAnimationLengthInBeats"); - m_fAnimationLengthInBeats[PART_HOLD_TOP_CAP] = NOTESKIN->GetMetricF(skin,name,"HoldTopCapAnimationLengthInBeats"); - m_fAnimationLengthInBeats[PART_HOLD_BODY] = NOTESKIN->GetMetricF(skin,name,"HoldBodyAnimationLengthInBeats"); - m_fAnimationLengthInBeats[PART_HOLD_BOTTOM_CAP] = NOTESKIN->GetMetricF(skin,name,"HoldBottomCapAnimationLengthInBeats"); - m_fAnimationLengthInBeats[PART_HOLD_TAIL] = NOTESKIN->GetMetricF(skin,name,"HoldTailAnimationLengthInBeats"); - m_bAnimationIsVivid[PART_TAP] = NOTESKIN->GetMetricB(skin,name,"TapNoteAnimationIsVivid"); - m_bAnimationIsVivid[PART_ADDITION] = NOTESKIN->GetMetricB(skin,name,"TapAdditionAnimationIsVivid"); - m_bAnimationIsVivid[PART_MINE] = NOTESKIN->GetMetricB(skin,name,"TapMineAnimationIsVivid"); - m_bAnimationIsVivid[PART_HOLD_HEAD] = NOTESKIN->GetMetricB(skin,name,"HoldHeadAnimationIsVivid"); - m_bAnimationIsVivid[PART_HOLD_TOP_CAP] = NOTESKIN->GetMetricB(skin,name,"HoldTopCapAnimationIsVivid"); - m_bAnimationIsVivid[PART_HOLD_BODY] = NOTESKIN->GetMetricB(skin,name,"HoldBodyAnimationIsVivid"); - m_bAnimationIsVivid[PART_HOLD_BOTTOM_CAP] = NOTESKIN->GetMetricB(skin,name,"HoldBottomCapAnimationIsVivid"); - m_bAnimationIsVivid[PART_HOLD_TAIL] = NOTESKIN->GetMetricB(skin,name,"HoldTailAnimationIsVivid"); + m_bDrawHoldHeadForTapsOnSameRow = NOTESKIN->GetMetricB(sButton,"DrawHoldHeadForTapsOnSameRow"); + m_fAnimationLengthInBeats[PART_TAP] = NOTESKIN->GetMetricF(sButton,"TapNoteAnimationLengthInBeats"); + m_fAnimationLengthInBeats[PART_ADDITION] = NOTESKIN->GetMetricF(sButton,"TapAdditionAnimationLengthInBeats"); + m_fAnimationLengthInBeats[PART_MINE] = NOTESKIN->GetMetricF(sButton,"TapMineAnimationLengthInBeats"); + m_fAnimationLengthInBeats[PART_HOLD_HEAD] = NOTESKIN->GetMetricF(sButton,"HoldHeadAnimationLengthInBeats"); + m_fAnimationLengthInBeats[PART_HOLD_TOP_CAP] = NOTESKIN->GetMetricF(sButton,"HoldTopCapAnimationLengthInBeats"); + m_fAnimationLengthInBeats[PART_HOLD_BODY] = NOTESKIN->GetMetricF(sButton,"HoldBodyAnimationLengthInBeats"); + m_fAnimationLengthInBeats[PART_HOLD_BOTTOM_CAP]=NOTESKIN->GetMetricF(sButton,"HoldBottomCapAnimationLengthInBeats"); + m_fAnimationLengthInBeats[PART_HOLD_TAIL] = NOTESKIN->GetMetricF(sButton,"HoldTailAnimationLengthInBeats"); + m_bAnimationIsVivid[PART_TAP] = NOTESKIN->GetMetricB(sButton,"TapNoteAnimationIsVivid"); + m_bAnimationIsVivid[PART_ADDITION] = NOTESKIN->GetMetricB(sButton,"TapAdditionAnimationIsVivid"); + m_bAnimationIsVivid[PART_MINE] = NOTESKIN->GetMetricB(sButton,"TapMineAnimationIsVivid"); + m_bAnimationIsVivid[PART_HOLD_HEAD] = NOTESKIN->GetMetricB(sButton,"HoldHeadAnimationIsVivid"); + m_bAnimationIsVivid[PART_HOLD_TOP_CAP] = NOTESKIN->GetMetricB(sButton,"HoldTopCapAnimationIsVivid"); + m_bAnimationIsVivid[PART_HOLD_BODY] = NOTESKIN->GetMetricB(sButton,"HoldBodyAnimationIsVivid"); + m_bAnimationIsVivid[PART_HOLD_BOTTOM_CAP] = NOTESKIN->GetMetricB(sButton,"HoldBottomCapAnimationIsVivid"); + m_bAnimationIsVivid[PART_HOLD_TAIL] = NOTESKIN->GetMetricB(sButton,"HoldTailAnimationIsVivid"); - m_bAnimationIsNoteColor[PART_TAP] = NOTESKIN->GetMetricB(skin,name,"TapNoteAnimationIsNoteColor"); - m_bAnimationIsNoteColor[PART_ADDITION] = NOTESKIN->GetMetricB(skin,name,"TapAdditionAnimationIsNoteColor"); - m_bAnimationIsNoteColor[PART_MINE] = NOTESKIN->GetMetricB(skin,name,"TapMineAnimationIsNoteColor"); - m_bAnimationIsNoteColor[PART_HOLD_HEAD] = NOTESKIN->GetMetricB(skin,name,"HoldHeadAnimationIsNoteColor"); - m_bAnimationIsNoteColor[PART_HOLD_TOP_CAP] =NOTESKIN->GetMetricB(skin,name,"HoldTopCapAnimationIsNoteColor"); - m_bAnimationIsNoteColor[PART_HOLD_BODY] = NOTESKIN->GetMetricB(skin,name,"HoldBodyAnimationIsNoteColor"); - m_bAnimationIsNoteColor[PART_HOLD_BOTTOM_CAP] = NOTESKIN->GetMetricB(skin,name,"HoldBottomCapAnimationIsNoteColor"); - m_bAnimationIsNoteColor[PART_HOLD_TAIL] = NOTESKIN->GetMetricB(skin,name,"HoldTailAnimationIsNoteColor"); + m_bAnimationIsNoteColor[PART_TAP] = NOTESKIN->GetMetricB(sButton,"TapNoteAnimationIsNoteColor"); + m_bAnimationIsNoteColor[PART_ADDITION] = NOTESKIN->GetMetricB(sButton,"TapAdditionAnimationIsNoteColor"); + m_bAnimationIsNoteColor[PART_MINE] = NOTESKIN->GetMetricB(sButton,"TapMineAnimationIsNoteColor"); + m_bAnimationIsNoteColor[PART_HOLD_HEAD] = NOTESKIN->GetMetricB(sButton,"HoldHeadAnimationIsNoteColor"); + m_bAnimationIsNoteColor[PART_HOLD_TOP_CAP] = NOTESKIN->GetMetricB(sButton,"HoldTopCapAnimationIsNoteColor"); + m_bAnimationIsNoteColor[PART_HOLD_BODY] = NOTESKIN->GetMetricB(sButton,"HoldBodyAnimationIsNoteColor"); + m_bAnimationIsNoteColor[PART_HOLD_BOTTOM_CAP] = NOTESKIN->GetMetricB(sButton,"HoldBottomCapAnimationIsNoteColor"); + m_bAnimationIsNoteColor[PART_HOLD_TAIL] = NOTESKIN->GetMetricB(sButton,"HoldTailAnimationIsNoteColor"); - m_bHoldHeadIsAboveWavyParts = NOTESKIN->GetMetricB(skin,name,"HoldHeadIsAboveWavyParts"); - m_bHoldTailIsAboveWavyParts = NOTESKIN->GetMetricB(skin,name,"HoldTailIsAboveWavyParts"); - m_iStartDrawingHoldBodyOffsetFromHead = NOTESKIN->GetMetricI(skin,name,"StartDrawingHoldBodyOffsetFromHead"); - m_iStopDrawingHoldBodyOffsetFromTail = NOTESKIN->GetMetricI(skin,name,"StopDrawingHoldBodyOffsetFromTail"); - m_fHoldNGGrayPercent = NOTESKIN->GetMetricF(skin,name,"HoldNGGrayPercent"); - m_bTapNoteUseLighting = NOTESKIN->GetMetricB(skin,name,"TapNoteUseLighting"); - m_bTapAdditionUseLighting = NOTESKIN->GetMetricB(skin,name,"TapAdditionUseLighting"); - m_bTapMineUseLighting = NOTESKIN->GetMetricB(skin,name,"TapMineUseLighting"); - m_bHoldHeadUseLighting = NOTESKIN->GetMetricB(skin,name,"HoldHeadUseLighting"); - m_bHoldTailUseLighting = NOTESKIN->GetMetricB(skin,name,"HoldTailUseLighting"); - m_bFlipHeadAndTailWhenReverse = NOTESKIN->GetMetricB(skin,name,"FlipHeadAndTailWhenReverse"); + m_bHoldHeadIsAboveWavyParts = NOTESKIN->GetMetricB(sButton,"HoldHeadIsAboveWavyParts"); + m_bHoldTailIsAboveWavyParts = NOTESKIN->GetMetricB(sButton,"HoldTailIsAboveWavyParts"); + m_iStartDrawingHoldBodyOffsetFromHead = NOTESKIN->GetMetricI(sButton,"StartDrawingHoldBodyOffsetFromHead"); + m_iStopDrawingHoldBodyOffsetFromTail = NOTESKIN->GetMetricI(sButton,"StopDrawingHoldBodyOffsetFromTail"); + m_fHoldNGGrayPercent = NOTESKIN->GetMetricF(sButton,"HoldNGGrayPercent"); + m_bTapNoteUseLighting = NOTESKIN->GetMetricB(sButton,"TapNoteUseLighting"); + m_bTapAdditionUseLighting = NOTESKIN->GetMetricB(sButton,"TapAdditionUseLighting"); + m_bTapMineUseLighting = NOTESKIN->GetMetricB(sButton,"TapMineUseLighting"); + m_bHoldHeadUseLighting = NOTESKIN->GetMetricB(sButton,"HoldHeadUseLighting"); + m_bHoldTailUseLighting = NOTESKIN->GetMetricB(sButton,"HoldTailUseLighting"); + m_bFlipHeadAndTailWhenReverse = NOTESKIN->GetMetricB(sButton,"FlipHeadAndTailWhenReverse"); } +struct NoteSkinAndPath +{ + NoteSkinAndPath( const CString sNoteSkin_, const CString sPath_ ) { sNoteSkin = sNoteSkin_; sPath = sPath_; } + CString sNoteSkin; + CString sPath; + bool operator<( const NoteSkinAndPath &other ) const + { + switch( strcmp(sNoteSkin, other.sNoteSkin) ) + { + case -1: return true; + case 0: return sPath < other.sPath; + case 1: return false; + default: ASSERT(0); return false; + } + } +}; + struct NoteResource { - NoteResource( CString sPath ): m_sPath(sPath) + NoteResource( const NoteSkinAndPath &nsap ): m_nsap(nsap) { m_iRefCount = 0; m_pActor = NULL; @@ -107,33 +124,33 @@ struct NoteResource delete m_pActor; } - const CString m_sPath; /* should be refcounted along with g_NoteResource[] */ + const NoteSkinAndPath m_nsap; /* should be refcounted along with g_NoteResource[] */ int m_iRefCount; Actor *m_pActor; }; -static map g_NoteResource; +static map g_NoteResource; -static NoteResource *MakeNoteResource( const CString &sPath, bool bSpriteOnly ) +static NoteResource *MakeNoteResource( const NoteSkinAndPath &nsap, bool bSpriteOnly ) { - map::iterator it = g_NoteResource.find( sPath ); + map::iterator it = g_NoteResource.find( nsap ); if( it == g_NoteResource.end() ) { - NoteResource *pRes = new NoteResource( sPath ); + NoteResource *pRes = new NoteResource( nsap ); if( bSpriteOnly ) { Sprite *pSprite = new Sprite; - pSprite->Load( sPath ); + pSprite->Load( nsap.sPath ); pRes->m_pActor = pSprite; } else { - pRes->m_pActor = ActorUtil::MakeActor( sPath ); + pRes->m_pActor = ActorUtil::MakeActor( nsap.sPath ); ASSERT( pRes->m_pActor ); } - g_NoteResource[sPath] = pRes; - it = g_NoteResource.find( sPath ); + g_NoteResource[nsap] = pRes; + it = g_NoteResource.find( nsap ); } NoteResource *pRet = it->second; @@ -143,7 +160,7 @@ static NoteResource *MakeNoteResource( const CString &sPath, bool bSpriteOnly ) static NoteResource *FindNoteResource( const Actor *pActor ) { - map::iterator it; + map::iterator it; for( it = g_NoteResource.begin(); it != g_NoteResource.end(); ++it ) { NoteResource *pRes = it->second; @@ -167,19 +184,19 @@ static void DeleteNoteResource( const Actor *pActor ) if( pRes->m_iRefCount ) return; - g_NoteResource.erase( pRes->m_sPath ); + g_NoteResource.erase( pRes->m_nsap ); delete pRes; } -Actor *MakeRefcountedActor( const CString &sPath ) +Actor *MakeRefcountedActor( const NoteSkinAndPath &nsap ) { - NoteResource *pRes = MakeNoteResource( sPath, false ); + NoteResource *pRes = MakeNoteResource( nsap, false ); return pRes->m_pActor; } -Sprite *MakeRefcountedSprite( const CString &sPath ) +Sprite *MakeRefcountedSprite( const NoteSkinAndPath &nsap ) { - NoteResource *pRes = MakeNoteResource( sPath, true ); + NoteResource *pRes = MakeNoteResource( nsap, true ); return (Sprite *) pRes->m_pActor; /* XXX ick */ } @@ -197,17 +214,17 @@ NoteColorActor::~NoteColorActor() m_bIsNoteColor = false; } -void NoteColorActor::Load( bool bIsNoteColor, const CString &sNoteSkin, const CString &sButton, const CString &sElement ) +void NoteColorActor::Load( bool bIsNoteColor, const CString &sButton, const CString &sElement ) { m_bIsNoteColor = bIsNoteColor; if( m_bIsNoteColor ) { for( int i=0; iGetPathToFromNoteSkinAndButton(sNoteSkin, sButton, sElement+" "+NoteTypeToString((NoteType)i)) ); + m_p[i] = MakeRefcountedActor( NoteSkinAndPath( NOTESKIN->GetCurrentNoteSkin(), NOTESKIN->GetPath(sButton, sElement+" "+NoteTypeToString((NoteType)i)) ) ); } else { - m_p[0] = MakeRefcountedActor( NOTESKIN->GetPathToFromNoteSkinAndButton(sNoteSkin, sButton, sElement) ); + m_p[0] = MakeRefcountedActor( NoteSkinAndPath( NOTESKIN->GetCurrentNoteSkin(), NOTESKIN->GetPath(sButton, sElement) ) ); } } @@ -237,17 +254,17 @@ NoteColorSprite::~NoteColorSprite() m_bIsNoteColor = false; } -void NoteColorSprite::Load( bool bIsNoteColor, const CString &sNoteSkin, const CString &sButton, const CString &sElement ) +void NoteColorSprite::Load( bool bIsNoteColor, const CString &sButton, const CString &sElement ) { m_bIsNoteColor = bIsNoteColor; if( m_bIsNoteColor ) { for( int i=0; iGetPathToFromNoteSkinAndButton(sNoteSkin, sButton, sElement+" "+NoteTypeToString((NoteType)i)) ); + m_p[i] = MakeRefcountedSprite( NoteSkinAndPath( NOTESKIN->GetCurrentNoteSkin(), NOTESKIN->GetPath(sButton, sElement+" "+NoteTypeToString((NoteType)i)) ) ); } else { - m_p[0] = MakeRefcountedSprite( NOTESKIN->GetPathToFromNoteSkinAndButton(sNoteSkin, sButton, sElement) ); + m_p[0] = MakeRefcountedSprite( NoteSkinAndPath( NOTESKIN->GetCurrentNoteSkin(), NOTESKIN->GetPath(sButton, sElement) ) ); } } @@ -262,6 +279,20 @@ Sprite* NoteColorSprite::Get( NoteType nt ) } +static const CString HoldTypeNames[NUM_HOLD_TYPES] = { + "hold", + "roll", +}; +XToString( HoldType, NUM_HOLD_TYPES ); + +static const CString ActiveTypeNames[NUM_ACTIVE_TYPES] = { + "active", + "inactive", +}; +XToString( ActiveType, NUM_ACTIVE_TYPES ); + + + NoteDisplay::NoteDisplay() { cache = new NoteMetricCache_t; @@ -272,28 +303,30 @@ NoteDisplay::~NoteDisplay() delete cache; } -void NoteDisplay::Load( int iColNum, const PlayerState* pPlayerState, const CString &sNoteSkin, float fYReverseOffsetPixels ) +void NoteDisplay::Load( int iColNum, const PlayerState* pPlayerState, float fYReverseOffsetPixels ) { m_pPlayerState = pPlayerState; m_fYReverseOffsetPixels = fYReverseOffsetPixels; - CString sButton = GAMESTATE->GetCurrentGame()->ColToButtonName( iColNum ); + const CString &sButton = GAMESTATE->GetCurrentGame()->ColToButtonName( iColNum ); - cache->Load( sNoteSkin, sButton ); + cache->Load( sButton ); - 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" ); + m_TapNote.Load( cache->m_bAnimationIsNoteColor[PART_TAP], sButton, "tap note" ); + m_TapAddition.Load( cache->m_bAnimationIsNoteColor[PART_ADDITION], sButton, "tap addition" ); + m_TapMine.Load( cache->m_bAnimationIsNoteColor[PART_MINE], sButton, "tap mine" ); + + FOREACH_HoldType( ht ) + { + FOREACH_ActiveType( at ) + { + m_HoldHead[ht][at].Load( cache->m_bAnimationIsNoteColor[PART_HOLD_HEAD], sButton, HoldTypeToString(ht)+" head "+ActiveTypeToString(at) ); + m_HoldTopCap[ht][at].Load( cache->m_bAnimationIsNoteColor[PART_HOLD_TOP_CAP], sButton, HoldTypeToString(ht)+" topcap "+ActiveTypeToString(at) ); + m_HoldBody[ht][at].Load( cache->m_bAnimationIsNoteColor[PART_HOLD_BODY], sButton, HoldTypeToString(ht)+" body "+ActiveTypeToString(at) ); + m_HoldBottomCap[ht][at].Load( cache->m_bAnimationIsNoteColor[PART_HOLD_BOTTOM_CAP], sButton, HoldTypeToString(ht)+" bottomcap "+ActiveTypeToString(at) ); + m_HoldTail[ht][at].Load( cache->m_bAnimationIsNoteColor[PART_HOLD_TAIL], sButton, HoldTypeToString(ht)+" tail "+ActiveTypeToString(at) ); + } + } } bool NoteDisplay::DrawHoldHeadForTapsOnSameRow() const @@ -305,7 +338,7 @@ void NoteDisplay::Update( float fDeltaTime ) { /* This function is static: it's called once per game loop, not once per * NoteDisplay. Update each cached item exactly once. */ - map::iterator it; + map::iterator it; for( it = g_NoteResource.begin(); it != g_NoteResource.end(); ++it ) { NoteResource *pRes = it->second; @@ -390,10 +423,10 @@ Actor * NoteDisplay::GetTapMineActor( float fNoteBeat ) return pActorOut; } -Sprite * NoteDisplay::GetHoldTopCapSprite( float fNoteBeat, bool bIsBeingHeld ) +Sprite * NoteDisplay::GetHoldTopCapSprite( float fNoteBeat, bool bIsRoll, bool bIsBeingHeld ) { NoteType nt = BeatToNoteType( fNoteBeat ); - Sprite *pSpriteOut = (bIsBeingHeld ? m_HoldTopCapActive : m_HoldTopCapInactive).Get( nt ); + Sprite *pSpriteOut = m_HoldTopCap[bIsRoll ? roll:hold][bIsBeingHeld ? active:inactive].Get( nt ); SetActiveFrame( fNoteBeat, @@ -405,10 +438,10 @@ Sprite * NoteDisplay::GetHoldTopCapSprite( float fNoteBeat, bool bIsBeingHeld ) return pSpriteOut; } -Sprite * NoteDisplay::GetHoldBottomCapSprite( float fNoteBeat, bool bIsBeingHeld ) +Sprite * NoteDisplay::GetHoldBottomCapSprite( float fNoteBeat, bool bIsRoll, bool bIsBeingHeld ) { NoteType nt = BeatToNoteType( fNoteBeat ); - Sprite *pSpriteOut = (bIsBeingHeld ? m_HoldBottomCapActive : m_HoldBottomCapInactive).Get( nt ); + Sprite *pSpriteOut = m_HoldBottomCap[bIsRoll ? roll:hold][bIsBeingHeld ? active:inactive].Get( nt ); SetActiveFrame( fNoteBeat, @@ -421,10 +454,10 @@ Sprite * NoteDisplay::GetHoldBottomCapSprite( float fNoteBeat, bool bIsBeingHeld } -Actor* NoteDisplay::GetHoldHeadActor( float fNoteBeat, bool bIsBeingHeld ) +Actor* NoteDisplay::GetHoldHeadActor( float fNoteBeat, bool bIsRoll, bool bIsBeingHeld ) { NoteType nt = BeatToNoteType( fNoteBeat ); - Actor *pActorOut = (bIsBeingHeld ? m_HoldHeadActive : m_HoldHeadInactive).Get( nt ); + Actor *pActorOut = m_HoldHead[bIsRoll ? roll:hold][bIsBeingHeld ? active:inactive].Get( nt ); SetActiveFrame( fNoteBeat, @@ -436,10 +469,10 @@ Actor* NoteDisplay::GetHoldHeadActor( float fNoteBeat, bool bIsBeingHeld ) return pActorOut; } -Sprite *NoteDisplay::GetHoldBodySprite( float fNoteBeat, bool bIsBeingHeld ) +Sprite *NoteDisplay::GetHoldBodySprite( float fNoteBeat, bool bIsRoll, bool bIsBeingHeld ) { NoteType nt = BeatToNoteType( fNoteBeat ); - Sprite *pSpriteOut = (bIsBeingHeld ? m_HoldBodyActive : m_HoldBodyInactive).Get( nt ); + Sprite *pSpriteOut = m_HoldBody[bIsRoll ? roll:hold][bIsBeingHeld ? active:inactive].Get( nt ); SetActiveFrame( fNoteBeat, @@ -451,10 +484,10 @@ Sprite *NoteDisplay::GetHoldBodySprite( float fNoteBeat, bool bIsBeingHeld ) return pSpriteOut; } -Actor* NoteDisplay::GetHoldTailActor( float fNoteBeat, bool bIsBeingHeld ) +Actor* NoteDisplay::GetHoldTailActor( float fNoteBeat, bool bIsRoll, bool bIsBeingHeld ) { NoteType nt = BeatToNoteType( fNoteBeat ); - Actor *pActorOut = (bIsBeingHeld ? m_HoldTailActive : m_HoldTailInactive).Get( nt ); + Actor *pActorOut = m_HoldTail[bIsRoll ? roll:hold][bIsBeingHeld ? active:inactive].Get( nt ); SetActiveFrame( fNoteBeat, @@ -501,14 +534,14 @@ struct StripBuffer int Free() const { return size - Used(); } }; -void NoteDisplay::DrawHoldTopCap( const TapNote& tn, int iCol, int iRow, const bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) +void NoteDisplay::DrawHoldTopCap( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) { // // Draw the top cap (always wavy) // StripBuffer queue; - Sprite* pSprTopCap = GetHoldTopCapSprite( NoteRowToBeat(iRow), bIsBeingHeld ); + Sprite* pSprTopCap = GetHoldTopCapSprite( NoteRowToBeat(iRow), tn.bIsRoll, bIsBeingHeld ); pSprTopCap->SetZoom( ArrowEffects::GetZoom( m_pPlayerState ) ); @@ -589,7 +622,7 @@ void NoteDisplay::DrawHoldTopCap( const TapNote& tn, int iCol, int iRow, const b } -void NoteDisplay::DrawHoldBody( const TapNote& tn, int iCol, int iRow, const bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, +void NoteDisplay::DrawHoldBody( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) { // @@ -597,7 +630,7 @@ void NoteDisplay::DrawHoldBody( const TapNote& tn, int iCol, int iRow, const boo // StripBuffer queue; - Sprite* pSprBody = GetHoldBodySprite( NoteRowToBeat(iRow), bIsBeingHeld ); + Sprite* pSprBody = GetHoldBodySprite( NoteRowToBeat(iRow), tn.bIsRoll, bIsBeingHeld ); pSprBody->SetZoom( ArrowEffects::GetZoom( m_pPlayerState ) ); @@ -688,14 +721,14 @@ void NoteDisplay::DrawHoldBody( const TapNote& tn, int iCol, int iRow, const boo queue.Draw(); } -void NoteDisplay::DrawHoldBottomCap( const TapNote& tn, int iCol, int iRow, const bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) +void NoteDisplay::DrawHoldBottomCap( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) { // // Draw the bottom cap (always wavy) // StripBuffer queue; - Sprite* pBottomCap = GetHoldBottomCapSprite( NoteRowToBeat(iRow), bIsBeingHeld ); + Sprite* pBottomCap = GetHoldBottomCapSprite( NoteRowToBeat(iRow), tn.bIsRoll, bIsBeingHeld ); pBottomCap->SetZoom( ArrowEffects::GetZoom( m_pPlayerState ) ); @@ -772,12 +805,12 @@ void NoteDisplay::DrawHoldBottomCap( const TapNote& tn, int iCol, int iRow, cons queue.Draw(); } -void NoteDisplay::DrawHoldTail( const TapNote& tn, int iCol, int iRow, const bool bIsBeingHeld, float fYTail, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) +void NoteDisplay::DrawHoldTail( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYTail, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) { // // Draw the tail // - Actor* pSprTail = GetHoldTailActor( NoteRowToBeat(iRow), bIsBeingHeld ); + Actor* pSprTail = GetHoldTailActor( NoteRowToBeat(iRow), tn.bIsRoll, bIsBeingHeld ); pSprTail->SetZoom( ArrowEffects::GetZoom( m_pPlayerState ) ); @@ -826,12 +859,12 @@ void NoteDisplay::DrawHoldTail( const TapNote& tn, int iCol, int iRow, const boo } } -void NoteDisplay::DrawHoldHead( const TapNote& tn, int iCol, int iRow, const bool bIsBeingHeld, float fYHead, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) +void NoteDisplay::DrawHoldHead( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) { // // Draw the head // - Actor* pActor = GetHoldHeadActor( NoteRowToBeat(iRow), bIsBeingHeld ); + Actor* pActor = GetHoldHeadActor( NoteRowToBeat(iRow), tn.bIsRoll, bIsBeingHeld ); pActor->SetZoom( ArrowEffects::GetZoom( m_pPlayerState ) ); @@ -1014,7 +1047,7 @@ void NoteDisplay::DrawTap( int iCol, float fBeat, bool bOnSameRowAsHoldStart, bo } else if( bOnSameRowAsHoldStart && cache->m_bDrawHoldHeadForTapsOnSameRow ) { - pActor = GetHoldHeadActor( fBeat, false ); + pActor = GetHoldHeadActor( fBeat, false, false ); bUseLighting = cache->m_bHoldHeadUseLighting; } else diff --git a/stepmania/src/NoteDisplay.h b/stepmania/src/NoteDisplay.h index 1a1d62a3bc..99db81ff68 100644 --- a/stepmania/src/NoteDisplay.h +++ b/stepmania/src/NoteDisplay.h @@ -17,7 +17,7 @@ struct NoteColorActor { NoteColorActor(); ~NoteColorActor(); - void Load( bool bIsNoteColor, const CString &sNoteSkin, const CString &sButton, const CString &sElement ); + void Load( bool bIsNoteColor, const CString &sButton, const CString &sElement ); Actor* Get( NoteType nt ); private: Actor* m_p[NOTE_COLOR_IMAGES]; @@ -28,20 +28,29 @@ struct NoteColorSprite { NoteColorSprite(); ~NoteColorSprite(); - void Load( bool bIsNoteColor, const CString &sNoteSkin, const CString &sButton, const CString &sElement ); + void Load( bool bIsNoteColor, const CString &sButton, const CString &sElement ); Sprite* Get( NoteType nt ); private: Sprite* m_p[NOTE_COLOR_IMAGES]; bool m_bIsNoteColor; }; +enum HoldType { hold, roll, NUM_HOLD_TYPES }; +#define FOREACH_HoldType( i ) FOREACH_ENUM( HoldType, NUM_HOLD_TYPES, i ) +const CString &HoldTypeToString( HoldType ht ); + +enum ActiveType { active, inactive, NUM_ACTIVE_TYPES }; +#define FOREACH_ActiveType( i ) FOREACH_ENUM( ActiveType, NUM_ACTIVE_TYPES, i ) +const CString &ActiveTypeToString( ActiveType at ); + + class NoteDisplay { public: NoteDisplay(); ~NoteDisplay(); - void Load( int iColNum, const PlayerState* pPlayerState, const CString &sNoteSkin, float fYReverseOffsetPixels ); + void Load( int iColNum, const PlayerState* pPlayerState, float fYReverseOffsetPixels ); static void Update( float fDeltaTime ); @@ -56,17 +65,17 @@ protected: Actor *GetTapNoteActor( float fNoteBeat ); Actor *GetTapAdditionActor( float fNoteBeat ); Actor *GetTapMineActor( float fNoteBeat ); - Actor *GetHoldHeadActor( float fNoteBeat, bool bIsBeingHeld ); - Actor* GetHoldTailActor( float fNoteBeat, bool bIsBeingHeld ); - Sprite *GetHoldTopCapSprite( float fNoteBeat, bool bIsBeingHeld ); - Sprite *GetHoldBodySprite( float fNoteBeat, bool bIsBeingHeld ); - Sprite *GetHoldBottomCapSprite( float fNoteBeat, bool bIsBeingHeld ); + Actor *GetHoldHeadActor( float fNoteBeat, bool bIsRoll, bool bIsBeingHeld ); + Actor *GetHoldTailActor( float fNoteBeat, bool bIsRoll, bool bIsBeingHeld ); + Sprite *GetHoldTopCapSprite( float fNoteBeat, bool bIsRoll, bool bIsBeingHeld ); + Sprite *GetHoldBodySprite( float fNoteBeat, bool bIsRoll, bool bIsBeingHeld ); + Sprite *GetHoldBottomCapSprite( float fNoteBeat, bool bIsRoll, bool bIsBeingHeld ); - void DrawHoldBottomCap( const TapNote& tn, int iCol, int iRow, const bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ); - void DrawHoldTopCap( const TapNote& tn, int iCol, int iRow, const bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ); - void DrawHoldBody( const TapNote& tn, int iCol, int iRow, const bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ); - void DrawHoldTail( const TapNote& tn, int iCol, int iRow, const bool bIsBeingHeld, float fYTail, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ); - void DrawHoldHead( const TapNote& tn, int iCol, int iRow, const bool bIsBeingHeld, float fYHead, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ); + void DrawHoldBottomCap( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ); + void DrawHoldTopCap( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ); + void DrawHoldBody( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ); + void DrawHoldTail( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYTail, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ); + void DrawHoldHead( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ); const PlayerState* m_pPlayerState; // to look up PlayerOptions @@ -75,16 +84,11 @@ protected: 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; + NoteColorActor m_HoldHead[NUM_HOLD_TYPES][NUM_ACTIVE_TYPES]; + NoteColorSprite m_HoldTopCap[NUM_HOLD_TYPES][NUM_ACTIVE_TYPES]; + NoteColorSprite m_HoldBody[NUM_HOLD_TYPES][NUM_ACTIVE_TYPES]; + NoteColorSprite m_HoldBottomCap[NUM_HOLD_TYPES][NUM_ACTIVE_TYPES]; + NoteColorActor m_HoldTail[NUM_HOLD_TYPES][NUM_ACTIVE_TYPES]; float m_fYReverseOffsetPixels; }; diff --git a/stepmania/src/NoteField.cpp b/stepmania/src/NoteField.cpp index baa0ac74f4..a53af4c28e 100644 --- a/stepmania/src/NoteField.cpp +++ b/stepmania/src/NoteField.cpp @@ -52,21 +52,24 @@ void NoteField::Unload() LastDisplay = NULL; } -void NoteField::CacheNoteSkin( CString skin ) +void NoteField::CacheNoteSkin( const CString &sNoteSkin_ ) { - skin.ToLower(); + CString sNoteSkin = sNoteSkin_; + sNoteSkin.ToLower(); - if( m_NoteDisplays.find(skin) != m_NoteDisplays.end() ) + if( m_NoteDisplays.find(sNoteSkin) != m_NoteDisplays.end() ) return; - LOG->Trace("NoteField::CacheNoteSkin: cache %s", skin.c_str() ); + LockNoteSkin l( sNoteSkin ); + + LOG->Trace("NoteField::CacheNoteSkin: cache %s", sNoteSkin.c_str() ); NoteDisplayCols *nd = new NoteDisplayCols( GAMESTATE->GetCurrentStyle()->m_iColsPerPlayer ); for( int c=0; cGetCurrentStyle()->m_iColsPerPlayer; c++ ) - nd->display[c].Load( c, m_pPlayerState, skin, m_fYReverseOffsetPixels ); - nd->m_ReceptorArrowRow.Load( m_pPlayerState, skin, m_fYReverseOffsetPixels ); - nd->m_GhostArrowRow.Load( m_pPlayerState, skin, m_fYReverseOffsetPixels ); + nd->display[c].Load( c, m_pPlayerState, m_fYReverseOffsetPixels ); + nd->m_ReceptorArrowRow.Load( m_pPlayerState, m_fYReverseOffsetPixels ); + nd->m_GhostArrowRow.Load( m_pPlayerState, m_fYReverseOffsetPixels ); - m_NoteDisplays[ skin ] = nd; + m_NoteDisplays[ sNoteSkin ] = nd; } void NoteField::CacheAllUsedNoteSkins() diff --git a/stepmania/src/NoteField.h b/stepmania/src/NoteField.h index 21d943358a..613baf3e80 100644 --- a/stepmania/src/NoteField.h +++ b/stepmania/src/NoteField.h @@ -32,7 +32,7 @@ public: int m_iBeginMarker, m_iEndMarker; // only used with MODE_EDIT void FadeToFail(); - void CacheNoteSkin( CString skin ); + void CacheNoteSkin( const CString &sNoteSkin ); void Step( int iCol, TapNoteScore score ); void SetPressed( int iCol ); diff --git a/stepmania/src/NoteSkinManager.cpp b/stepmania/src/NoteSkinManager.cpp index 07d3147056..68e91ad01a 100644 --- a/stepmania/src/NoteSkinManager.cpp +++ b/stepmania/src/NoteSkinManager.cpp @@ -156,9 +156,10 @@ CString NoteSkinManager::GetNoteSkinDir( const CString &sSkinName ) return NOTESKINS_DIR + sGame + "/" + sSkinName + "/"; } -CString NoteSkinManager::GetMetric( const CString &_sNoteSkinName, const CString &sButtonName, const CString &sValue ) +CString NoteSkinManager::GetMetric( const CString &sButtonName, const CString &sValue ) { - CString sNoteSkinName = _sNoteSkinName; + ASSERT( !m_sCurrentNoteSkin.empty() ); + CString sNoteSkinName = m_sCurrentNoteSkin; sNoteSkinName.MakeLower(); map::const_iterator it = m_mapNameToData.find(sNoteSkinName); ASSERT_M( it != m_mapNameToData.end(), sNoteSkinName ); // this NoteSkin doesn't exist! @@ -173,68 +174,55 @@ CString NoteSkinManager::GetMetric( const CString &_sNoteSkinName, const CString return sReturn; } -int NoteSkinManager::GetMetricI( const CString &sNoteSkinName, const CString &sButtonName, const CString &sValueName ) +int NoteSkinManager::GetMetricI( const CString &sButtonName, const CString &sValueName ) { - return atoi( GetMetric(sNoteSkinName,sButtonName,sValueName) ); + return atoi( GetMetric(sButtonName,sValueName) ); } -float NoteSkinManager::GetMetricF( const CString &sNoteSkinName, const CString &sButtonName, const CString &sValueName ) +float NoteSkinManager::GetMetricF( const CString &sButtonName, const CString &sValueName ) { - return strtof( GetMetric(sNoteSkinName,sButtonName,sValueName), NULL ); + return strtof( GetMetric(sButtonName,sValueName), NULL ); } -bool NoteSkinManager::GetMetricB( const CString &sNoteSkinName, const CString &sButtonName, const CString &sValueName ) +bool NoteSkinManager::GetMetricB( const CString &sButtonName, const CString &sValueName ) { - return atoi( GetMetric(sNoteSkinName,sButtonName,sValueName) ) != 0; + return atoi( GetMetric(sButtonName,sValueName) ) != 0; } -RageColor NoteSkinManager::GetMetricC( const CString &sNoteSkinName, const CString &sButtonName, const CString &sValueName ) +apActorCommands NoteSkinManager::GetMetricA( const CString &sButtonName, const CString &sValueName ) { - RageColor c; - if( !c.FromString( GetMetric(sNoteSkinName,sButtonName,sValueName) ) ) - LOG->Warn( "The color value for NoteSkin metric '%s : %s : %s' is invalid.", sNoteSkinName.c_str(), sButtonName.c_str(), sValueName.c_str() ); - return c; + return apActorCommands( new ActorCommands( GetMetric(sButtonName,sValueName) ) ); } -Commands NoteSkinManager::GetMetricA( const CString &sNoteSkinName, const CString &sButtonName, const CString &sValueName ) -{ - return ParseCommands( GetMetric(sNoteSkinName,sButtonName,sValueName) ); -} - -CString NoteSkinManager::GetPathToFromNoteSkinAndButton( const CString &NoteSkin, const CString &sButtonName, const CString &sElement, bool bOptional ) +CString NoteSkinManager::GetPath( const CString &sButtonName, const CString &sElement ) { try_again: - - const CString CacheString = NoteSkin + "/" + sButtonName + "/" + sElement; + const CString CacheString = m_sCurrentNoteSkin + "/" + sButtonName + "/" + sElement; map::iterator it = g_PathCache.find( CacheString ); if( it != g_PathCache.end() ) return it->second; - const NoteSkinData &data = m_mapNameToData[NoteSkin]; + map::const_iterator iter = m_mapNameToData.find( m_sCurrentNoteSkin ); + ASSERT( iter != m_mapNameToData.end() ); + const NoteSkinData &data = iter->second; - CString sPath; + CString sPath; // fill this in below FOREACHD_CONST( CString, data.vsDirSearchOrder, iter ) { if( *iter == GLOBAL_BASE_NOTESKIN_DIR ) - sPath = GetPathToFromDir( *iter, "Fallback "+sElement ); + sPath = GetPathFromDirAndFile( *iter, "Fallback "+sElement ); else - sPath = GetPathToFromDir( *iter, sButtonName+" "+sElement ); + sPath = GetPathFromDirAndFile( *iter, sButtonName+" "+sElement ); if( !sPath.empty() ) break; // done searching } if( sPath.empty() ) { - if( bOptional ) - { - g_PathCache[CacheString] = sPath; - return sPath; - } - CString message = ssprintf( "The NoteSkin element '%s %s' could not be found in '%s', '%s', or '%s'.", sButtonName.c_str(), sElement.c_str(), - GetNoteSkinDir(NoteSkin).c_str(), + GetNoteSkinDir(m_sCurrentNoteSkin).c_str(), GetNoteSkinDir(GAME_BASE_NOTESKIN_NAME).c_str(), GLOBAL_BASE_NOTESKIN_DIR.c_str() ); @@ -255,7 +243,7 @@ try_again: FOREACHD_CONST( CString, data.vsDirSearchOrder, iter ) { - sRealPath = GetPathToFromDir( *iter, sNewFileName ); + sRealPath = GetPathFromDirAndFile( *iter, sNewFileName ); if( !sRealPath.empty() ) break; // done searching } @@ -284,7 +272,7 @@ try_again: return sPath; } -CString NoteSkinManager::GetPathToFromDir( const CString &sDir, const CString &sFileName ) +CString NoteSkinManager::GetPathFromDirAndFile( const CString &sDir, const CString &sFileName ) { CStringArray matches; // fill this with the possible files @@ -312,6 +300,37 @@ CString NoteSkinManager::GetPathToFromDir( const CString &sDir, const CString &s return matches[0]; } +// lua start +#include "LuaBinding.h" + +template +class LunaNoteSkinManager : public Luna +{ +public: + LunaNoteSkinManager() { LUA->Register( Register ); } + + static int GetPath( T* p, lua_State *L ) { lua_pushstring(L, p->GetPath(SArg(1),SArg(2)) ); return 1; } + + static void Register(lua_State *L) + { + ADD_METHOD( GetPath ) + Luna::Register( L ); + + // Add global singleton if constructed already. If it's not constructed yet, + // then we'll register it later when we reinit Lua just before + // initializing the display. + if( NOTESKIN ) + { + lua_pushstring(L, "NOTESKIN"); + NOTESKIN->PushSelf( LUA->L ); + lua_settable(L, LUA_GLOBALSINDEX); + } + } +}; + +LUA_REGISTER_CLASS( NoteSkinManager ) +// lua end + /* * (c) 2003-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/NoteSkinManager.h b/stepmania/src/NoteSkinManager.h index 38829b20fd..d88b9afba0 100644 --- a/stepmania/src/NoteSkinManager.h +++ b/stepmania/src/NoteSkinManager.h @@ -3,7 +3,7 @@ #ifndef NOTE_SKIN_MANAGER_H #define NOTE_SKIN_MANAGER_H -#include "Command.h" +#include "ActorCommands.h" #include "RageTypes.h" #include "PlayerNumber.h" #include "IniFile.h" @@ -21,21 +21,25 @@ public: void RefreshNoteSkinData( const Game* game ); void GetNoteSkinNames( const Game* game, CStringArray &AddTo, bool bFilterDefault=true ); void GetNoteSkinNames( CStringArray &AddTo ); // looks up current const Game* in GAMESTATE - bool DoesNoteSkinExist( const CString &sSkinName ); // looks up current const Game* in GAMESTATE + bool DoesNoteSkinExist( const CString &sNoteSkin ); // looks up current const Game* in GAMESTATE - CString GetPathToFromNoteSkinAndButton( const CString &sNoteSkin, const CString &sButtonName, const CString &sElement, bool bOptional=false ); + void SetCurrentNoteSkin( const CString &sNoteSkin ) { m_sCurrentNoteSkin = sNoteSkin; } + const CString &GetCurrentNoteSkin() { return m_sCurrentNoteSkin; } - CString GetMetric( const CString &sNoteSkinName, const CString &sButtonName, const CString &sValue ); - int GetMetricI( const CString &sNoteSkinName, const CString &sButtonName, const CString &sValueName ); - float GetMetricF( const CString &sNoteSkinName, const CString &sButtonName, const CString &sValueName ); - bool GetMetricB( const CString &sNoteSkinName, const CString &sButtonName, const CString &sValueName ); - RageColor GetMetricC( const CString &sNoteSkinName, const CString &sButtonName, const CString &sValueName ); - Commands GetMetricA( const CString &sNoteSkinName, const CString &sButtonName, const CString &sValueName ); + CString GetPath( const CString &sButtonName, const CString &sElement ); - CString GetNoteSkinDir( const CString &sSkinName ); + CString GetMetric( const CString &sButtonName, const CString &sValue ); + int GetMetricI( const CString &sButtonName, const CString &sValueName ); + float GetMetricF( const CString &sButtonName, const CString &sValueName ); + bool GetMetricB( const CString &sButtonName, const CString &sValueName ); + apActorCommands GetMetricA( const CString &sButtonName, const CString &sValueName ); + + // Lua + void PushSelf( lua_State *L ); protected: - CString GetPathToFromDir( const CString &sDir, const CString &sFileName ); + CString GetNoteSkinDir( const CString &sSkinName ); + CString GetPathFromDirAndFile( const CString &sDir, const CString &sFileName ); struct NoteSkinData { @@ -47,6 +51,7 @@ protected: }; void LoadNoteSkinData( const CString &sNoteSkinName, NoteSkinData& data_out ); void LoadNoteSkinDataRecursive( const CString &sNoteSkinName, NoteSkinData& data_out ); + CString m_sCurrentNoteSkin; map m_mapNameToData; const Game* m_pCurGame; }; @@ -55,6 +60,14 @@ protected: extern NoteSkinManager* NOTESKIN; // global and accessable from anywhere in our program +class LockNoteSkin +{ +public: + LockNoteSkin( const CString &sNoteSkin ) { ASSERT( NOTESKIN->GetCurrentNoteSkin().empty() ); NOTESKIN->SetCurrentNoteSkin( sNoteSkin ); } + ~LockNoteSkin() { NOTESKIN->SetCurrentNoteSkin( CString() ); } +}; + + #endif /* diff --git a/stepmania/src/ReceptorArrow.cpp b/stepmania/src/ReceptorArrow.cpp index 8061c405a8..285486ec9e 100644 --- a/stepmania/src/ReceptorArrow.cpp +++ b/stepmania/src/ReceptorArrow.cpp @@ -17,24 +17,23 @@ ReceptorArrow::ReceptorArrow() StopAnimating(); } -bool ReceptorArrow::Load( CString NoteSkin, const PlayerState* pPlayerState, int iColNo ) +bool ReceptorArrow::Load( const PlayerState* pPlayerState, int iColNo ) { m_pPlayerState = pPlayerState; m_iColNo = iColNo; CString sButton = GAMESTATE->GetCurrentGame()->ColToButtonName( iColNo ); - CString sPath; - m_pReceptorWaiting.Load( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin,sButton,"receptor waiting") ); - m_pReceptorGo.Load( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin,sButton,"receptor go") ); + m_pReceptorWaiting.Load( NOTESKIN->GetPath(sButton,"receptor waiting") ); + m_pReceptorGo.Load( NOTESKIN->GetPath(sButton,"receptor go") ); FOREACH_TapNoteScore( i ) { CString sJudge = TapNoteScoreToString( i ); CString sCommand = Capitalize(sJudge)+"Command"; - m_sScoreCommand[i] = apActorCommands( new ActorCommands(NOTESKIN->GetMetric(NoteSkin,m_sName,sCommand)) ); + m_sScoreCommand[i] = NOTESKIN->GetMetricA(m_sName,sCommand); } - m_pPressBlock.Load( NOTESKIN->GetPathToFromNoteSkinAndButton(NoteSkin,sButton,"KeypressBlock") ); + m_pPressBlock.Load( NOTESKIN->GetPath(sButton,"KeypressBlock") ); m_pReceptorWaiting->SetEffectClock( Actor::CLOCK_BGM_BEAT ); m_pReceptorGo->SetEffectClock( Actor::CLOCK_BGM_BEAT ); diff --git a/stepmania/src/ReceptorArrow.h b/stepmania/src/ReceptorArrow.h index 93ca022ce6..964c664d4a 100644 --- a/stepmania/src/ReceptorArrow.h +++ b/stepmania/src/ReceptorArrow.h @@ -14,7 +14,7 @@ class ReceptorArrow : public ActorFrame { public: ReceptorArrow(); - bool Load( CString NoteSkin, const PlayerState* pPlayerState, int iColNo ); + bool Load( const PlayerState* pPlayerState, int iColNo ); virtual void DrawPrimitives(); virtual void Update( float fDeltaTime ); diff --git a/stepmania/src/ReceptorArrowRow.cpp b/stepmania/src/ReceptorArrowRow.cpp index b2d418b2ef..7ef9c34843 100644 --- a/stepmania/src/ReceptorArrowRow.cpp +++ b/stepmania/src/ReceptorArrowRow.cpp @@ -16,7 +16,7 @@ ReceptorArrowRow::ReceptorArrowRow() m_iNumCols = 0; } -void ReceptorArrowRow::Load( const PlayerState* pPlayerState, CString NoteSkin, float fYReverseOffset ) +void ReceptorArrowRow::Load( const PlayerState* pPlayerState, float fYReverseOffset ) { m_pPlayerState = pPlayerState; m_fYReverseOffsetPixels = fYReverseOffset; @@ -28,7 +28,7 @@ void ReceptorArrowRow::Load( const PlayerState* pPlayerState, CString NoteSkin, for( int c=0; cGetCurrentStyle()->m_StyleType); - m_ReceptorArrowRow[p].Load( GAMESTATE->m_pPlayerState[p], GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.m_sNoteSkin, 0 ); - m_ReceptorArrowRow[p].SetX( fPlayerX ); - m_ReceptorArrowRow[p].SetY( SCREEN_TOP + 100 ); - this->AddChild( &m_ReceptorArrowRow[p] ); + { + LockNoteSkin l( GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.m_sNoteSkin ); + + m_ReceptorArrowRow[p].Load( GAMESTATE->m_pPlayerState[p], 0 ); + m_ReceptorArrowRow[p].SetX( fPlayerX ); + m_ReceptorArrowRow[p].SetY( SCREEN_TOP + 100 ); + this->AddChild( &m_ReceptorArrowRow[p] ); + } const Style* pStyle = GAMESTATE->GetCurrentStyle();