From 339e9de36a4677bf4dbb5b936b7bd46f9eaefd6e Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 8 Aug 2006 02:27:59 +0000 Subject: [PATCH] clamp to 8 different note colors so that NoteSkins can implement colors efficiently in power-of-2 texture sizes --- stepmania/src/NoteDisplay.cpp | 23 +++++++++++++++-------- stepmania/src/RageUtil.h | 7 +++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/stepmania/src/NoteDisplay.cpp b/stepmania/src/NoteDisplay.cpp index 4b3bab8ef4..07f20d35ae 100644 --- a/stepmania/src/NoteDisplay.cpp +++ b/stepmania/src/NoteDisplay.cpp @@ -5,7 +5,6 @@ #include "ArrowEffects.h" #include "RageLog.h" #include "RageDisplay.h" -#include "NoteTypes.h" #include "ActorUtil.h" #include "Game.h" #include "PlayerState.h" @@ -28,6 +27,11 @@ XToString( NotePart, NUM_NotePart ); static const RageVector2 g_emptyVector = RageVector2( 0, 0 ); +// Don't require that NoteSkins have more than 8 colors. Using 9 colors to display 192nd notes +// would double the number of texture memory needed for many NoteSkin graphics versus just having +// 8 colors. +static const NoteType MAX_DISPLAY_NOTE_TYPE = (NoteType)7; + // cache struct NoteMetricCache_t { @@ -738,15 +742,15 @@ void NoteDisplay::DrawHoldTail( const TapNote& tn, int iCol, int iRow, bool bIsB pSprTail->SetZoom( ArrowEffects::GetZoom( m_pPlayerState ) ); - const float fY = fYTail; - const float fYOffset = ArrowEffects::GetYOffsetFromYPos( m_pPlayerState, iCol, fY, m_fYReverseOffsetPixels ); + const float fY = fYTail; + const float fYOffset = ArrowEffects::GetYOffsetFromYPos( m_pPlayerState, iCol, fY, m_fYReverseOffsetPixels ); if( fYOffset < fYStartOffset || fYOffset > fYEndOffset ) return; - const float fX = ArrowEffects::GetXPos( m_pPlayerState, iCol, fYOffset ); - const float fZ = ArrowEffects::GetZPos( m_pPlayerState, iCol, fYOffset ); - const float fAlpha = ArrowEffects::GetAlpha( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels ); - const float fGlow = ArrowEffects::GetGlow( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels ); - const RageColor colorDiffuse= RageColor(fColorScale,fColorScale,fColorScale,fAlpha); + const float fX = ArrowEffects::GetXPos( m_pPlayerState, iCol, fYOffset ); + const float fZ = ArrowEffects::GetZPos( m_pPlayerState, iCol, fYOffset ); + const float fAlpha = ArrowEffects::GetAlpha( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels ); + const float fGlow = ArrowEffects::GetGlow( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels ); + const RageColor colorDiffuse = RageColor(fColorScale,fColorScale,fColorScale,fAlpha); const RageColor colorGlow = RageColor(1,1,1,fGlow); pSprTail->SetXY( fX, fY ); @@ -756,6 +760,7 @@ void NoteDisplay::DrawHoldTail( const TapNote& tn, int iCol, int iRow, bool bIsB { DISPLAY->TexturePushMatrix(); NoteType nt = GetNoteType( iRow ); + ENUM_CLAMP( nt, (NoteType)0, MAX_DISPLAY_NOTE_TYPE ); DISPLAY->TextureTranslate( cache->m_fNoteColorTextureCoordSpacing[NotePart_HoldTail]*(float)nt ); } @@ -824,6 +829,7 @@ void NoteDisplay::DrawHoldHead( const TapNote& tn, int iCol, int iRow, bool bIsB { DISPLAY->TexturePushMatrix(); NoteType nt = GetNoteType( iRow ); + ENUM_CLAMP( nt, (NoteType)0, MAX_DISPLAY_NOTE_TYPE ); DISPLAY->TextureTranslate( cache->m_fNoteColorTextureCoordSpacing[NotePart_HoldHead]*(float)nt ); } @@ -963,6 +969,7 @@ void NoteDisplay::DrawActor( Actor* pActor, int iCol, float fBeat, float fPercen { DISPLAY->TexturePushMatrix(); NoteType nt = BeatToNoteType( fBeat ); + ENUM_CLAMP( nt, (NoteType)0, MAX_DISPLAY_NOTE_TYPE ); DISPLAY->TextureTranslate( cache->m_fNoteColorTextureCoordSpacing[part]*(float)nt ); } diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index e01a25c03b..3072e0d871 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -59,6 +59,13 @@ inline bool CLAMP( float &x, float l, float h ) else if (x < l) { x = l; return true; } return false; } +template +inline bool ENUM_CLAMP( T &x, T l, T h ) +{ + if (x > h) { x = h; return true; } + else if (x < l) { x = l; return true; } + return false; +} inline void wrap( int &x, int n ) {