From 668aa9a9acfd6334ae368724e41c7b880ef0326c Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 15:27:51 +0100 Subject: [PATCH 01/15] (360) removed some unused code in console/debug fonts --- 360/xdk360_video_console.cpp | 6 +- 360/xdk360_video_console.h | 8 +-- 360/xdk360_video_debugfonts.cpp | 104 ++++++++------------------------ 360/xdk360_video_debugfonts.h | 6 +- 4 files changed, 34 insertions(+), 90 deletions(-) diff --git a/360/xdk360_video_console.cpp b/360/xdk360_video_console.cpp index ee075f0877..2516906f3a 100644 --- a/360/xdk360_video_console.cpp +++ b/360/xdk360_video_console.cpp @@ -37,7 +37,7 @@ Console::~Console() } HRESULT Console::Create( LPCSTR strFontFileName, unsigned long colBackColor, - unsigned long colTextColor, unsigned int nLines ) + unsigned long colTextColor) { xdk360_video_t *vid = (xdk360_video_t*)g_d3d; D3DDevice *m_pd3dDevice = vid->xdk360_render_device; @@ -71,7 +71,7 @@ HRESULT Console::Create( LPCSTR strFontFileName, unsigned long colBackColor, m_cScreenHeight = (unsigned int)( m_cySafeArea / fCharHeight ); m_cScreenWidth = (unsigned int)( m_cxSafeArea / fCharWidth ); - m_cScreenHeightVirtual = max( m_cScreenHeight, nLines ); + m_cScreenHeightVirtual = m_cScreenHeight; m_fLineHeight = fCharHeight; @@ -119,7 +119,7 @@ void Console::Destroy() // Name: Render() // Desc: Render the console to the screen //-------------------------------------------------------------------------------------- -void Console::Render() +void Console::Render (void) { xdk360_video_t *vid = (xdk360_video_t*)g_d3d; D3DDevice *m_pd3dDevice = vid->xdk360_render_device; diff --git a/360/xdk360_video_console.h b/360/xdk360_video_console.h index a436b23677..54f00532c5 100644 --- a/360/xdk360_video_console.h +++ b/360/xdk360_video_console.h @@ -43,11 +43,7 @@ public: ~Console(); // Initialization - HRESULT Create( LPCSTR strFontFileName, - D3DCOLOR colBackColor, - D3DCOLOR colTextColor, - unsigned int nLines = 0 ); - + HRESULT Create( LPCSTR strFontFileName, D3DCOLOR colBackColor, D3DCOLOR colTextColor); void Destroy(); // Console output @@ -77,7 +73,7 @@ private: unsigned int m_cScreenHeight; // height in lines of screen area unsigned int m_cScreenHeightVirtual; // height in lines of text storage buffer unsigned int m_cScreenWidth; // width in characters - float m_fLineHeight; // height of a single line in pixels + float m_fLineHeight; // height of a single line in pixels wchar_t * m_Buffer; // buffer big enough to hold a full screen wchar_t ** m_Lines; // pointers to individual lines diff --git a/360/xdk360_video_debugfonts.cpp b/360/xdk360_video_debugfonts.cpp index e9e02e1f0d..e924f3da3c 100644 --- a/360/xdk360_video_debugfonts.cpp +++ b/360/xdk360_video_debugfonts.cpp @@ -600,9 +600,9 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, // Set the starting screen position if( ( fOriginX < 0.0f ) || ( ( dwFlags & FONT_RIGHT ) && ( fOriginX <= 0.0f ) ) ) - fOriginX += ( m_rcWindow.x2 - m_rcWindow.x1 ); + fOriginX += m_rcWindow.x2; if( fOriginY < 0.0f ) - fOriginY += ( m_rcWindow.y2 - m_rcWindow.y1 ); + fOriginY += m_rcWindow.y2; m_fCursorX = floorf( fOriginX ); m_fCursorY = floorf( fOriginY ); @@ -610,25 +610,6 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, // Adjust for padding fOriginY -= m_fFontTopPadding; - float fEllipsesPixelWidth = m_fXScaleFactor * 3.0f * ( m_Glyphs[m_TranslatorTable[L'.']].wOffset + - m_Glyphs[m_TranslatorTable[L'.']].wAdvance ); - - if( dwFlags & FONT_TRUNCATED ) - { - // Check if we will really need to truncate the string - if( fMaxPixelWidth <= 0.0f ) - dwFlags &= ( ~FONT_TRUNCATED ); - else - { - float w, h; - GetTextExtent( strText, &w, &h, TRUE ); - - // If not, then clear the flag - if( w <= fMaxPixelWidth ) - dwFlags &= ( ~FONT_TRUNCATED ); - } - } - // If vertically centered, offset the starting m_fCursorY value if( dwFlags & FONT_CENTER_Y ) { @@ -638,8 +619,8 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, } // Add window offsets - float Winx = static_cast(m_rcWindow.x1); - float Winy = static_cast(m_rcWindow.y1); + float Winx = 0.0f; + float Winy = 0.0f; fOriginX += Winx; fOriginY += Winy; m_fCursorX += Winx; @@ -648,8 +629,6 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, // Set a flag so we can determine initial justification effects BOOL bStartingNewLine = TRUE; - unsigned long dwNumEllipsesToDraw = 0; - // Begin drawing the vertices // Declared as volatile to force writing in ascending @@ -673,44 +652,34 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, { wchar_t letter; - if( dwNumEllipsesToDraw ) - letter = L'.'; - else + // If starting text on a new line, determine justification effects + if( bStartingNewLine ) { - // If starting text on a new line, determine justification effects - if( bStartingNewLine ) + if( dwFlags & ( FONT_RIGHT | FONT_CENTER_X ) ) { - if( dwFlags & ( FONT_RIGHT | FONT_CENTER_X ) ) - { - // Get the extent of this line - float w, h; - GetTextExtent( strText, &w, &h, TRUE ); + // Get the extent of this line + float w, h; + GetTextExtent( strText, &w, &h, TRUE ); - // Offset this line's starting m_fCursorX value - if( dwFlags & FONT_RIGHT ) - m_fCursorX = floorf( fOriginX - w ); - if( dwFlags & FONT_CENTER_X ) - m_fCursorX = floorf( fOriginX - w * 0.5f ); - } - bStartingNewLine = FALSE; + // Offset this line's starting m_fCursorX value + if( dwFlags & FONT_RIGHT ) + m_fCursorX = floorf( fOriginX - w ); + if( dwFlags & FONT_CENTER_X ) + m_fCursorX = floorf( fOriginX - w * 0.5f ); } + bStartingNewLine = FALSE; + } - // Get the current letter in the string - letter = *strText++; + // Get the current letter in the string + letter = *strText++; - // Handle the newline character - if( letter == L'\n' ) - { - m_fCursorX = fOriginX; - m_fCursorY += m_fFontYAdvance * m_fYScaleFactor; - bStartingNewLine = TRUE; - continue; - } - - // Handle carriage return characters by ignoring them. This helps when - // displaying text from a file. - if( letter == L'\r' ) - continue; + // Handle the newline character + if( letter == L'\n' ) + { + m_fCursorX = fOriginX; + m_fCursorY += m_fFontYAdvance * m_fYScaleFactor; + bStartingNewLine = TRUE; + continue; } // Translate unprintable characters @@ -721,20 +690,6 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, float fWidth = m_fXScaleFactor * (float)pGlyph->wWidth; float fHeight = m_fYScaleFactor * m_fFontHeight; - if( 0 == dwNumEllipsesToDraw ) - { - if( dwFlags & FONT_TRUNCATED ) - { - // Check if we will be exceeded the max allowed width - if( m_fCursorX + fOffset + fWidth + fEllipsesPixelWidth > fOriginX + fMaxPixelWidth ) - { - // Yup, draw the three ellipses dots instead - dwNumEllipsesToDraw = 3; - continue; - } - } - } - // Setup the screen coordinates m_fCursorX += fOffset; float X4 = m_fCursorX; @@ -795,13 +750,6 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, reinterpret_cast(pVertex)[15] = dwChannelSelector; pVertex+=16; - // If drawing ellipses, exit when they're all drawn - if( dwNumEllipsesToDraw ) - { - if( --dwNumEllipsesToDraw == 0 ) - break; - } - dwNumChars--; } diff --git a/360/xdk360_video_debugfonts.h b/360/xdk360_video_debugfonts.h index df0370e9e5..32e5b024f6 100644 --- a/360/xdk360_video_debugfonts.h +++ b/360/xdk360_video_debugfonts.h @@ -72,17 +72,17 @@ public: float m_fXScaleFactor; // Scaling constants float m_fYScaleFactor; - D3DRECT m_rcWindow; // Bounds rect if the text window, modify via accessors only! + D3DRECT m_rcWindow; // Bounds rect of the text window, modify via accessors only! float m_fCursorX; // Current text cursor float m_fCursorY; // Translator table for supporting unicode ranges unsigned long m_cMaxGlyph; // Number of entries in the translator table - wchar_t * m_TranslatorTable; // ASCII to glyph lookup table + wchar_t * m_TranslatorTable; // ASCII to glyph lookup table // Glyph data for the font unsigned long m_dwNumGlyphs; // Number of valid glyphs - const GLYPH_ATTR* m_Glyphs; // Array of glyphs + const GLYPH_ATTR* m_Glyphs; // Array of glyphs // D3D rendering objects D3DTexture* m_pFontTexture; From 1373ba167df46015f8fb5dc7233022c98087a293 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 15:43:15 +0100 Subject: [PATCH 02/15] (360) Remove font centering/alignment code --- 360/xdk360_video_debugfonts.cpp | 46 +++++---------------------------- 360/xdk360_video_debugfonts.h | 12 +++------ 2 files changed, 9 insertions(+), 49 deletions(-) diff --git a/360/xdk360_video_debugfonts.cpp b/360/xdk360_video_debugfonts.cpp index e924f3da3c..ff65ee94aa 100644 --- a/360/xdk360_video_debugfonts.cpp +++ b/360/xdk360_video_debugfonts.cpp @@ -555,9 +555,9 @@ VOID XdkFont::Begin() // Desc: Draws text as textured polygons //-------------------------------------------------------------------------------------- VOID XdkFont::DrawText( unsigned long dwColor, const wchar_t * strText, - unsigned long dwFlags, float fMaxPixelWidth ) + float fMaxPixelWidth ) { - DrawText( m_fCursorX, m_fCursorY, dwColor, strText, dwFlags, fMaxPixelWidth ); + DrawText( m_fCursorX, m_fCursorY, dwColor, strText, fMaxPixelWidth ); } @@ -568,11 +568,9 @@ VOID XdkFont::DrawText( unsigned long dwColor, const wchar_t * strText, // becomes available. //-------------------------------------------------------------------------------------- VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, - const wchar_t * strText, unsigned long dwFlags, float fMaxPixelWidth ) + const wchar_t * strText, float fMaxPixelWidth ) { - if( strText == NULL ) - return; - if( L'\0' == strText[0] ) + if( strText == NULL || strText[0] == L'\0') return; xdk360_video_t *vid = (xdk360_video_t*)g_d3d; @@ -599,7 +597,7 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, pd3dDevice->SetVertexShaderConstantF( 1, vColor, 1 ); // Set the starting screen position - if( ( fOriginX < 0.0f ) || ( ( dwFlags & FONT_RIGHT ) && ( fOriginX <= 0.0f ) ) ) + if((fOriginX < 0.0f)) fOriginX += m_rcWindow.x2; if( fOriginY < 0.0f ) fOriginY += m_rcWindow.y2; @@ -610,14 +608,6 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, // Adjust for padding fOriginY -= m_fFontTopPadding; - // If vertically centered, offset the starting m_fCursorY value - if( dwFlags & FONT_CENTER_Y ) - { - float w, h; - GetTextExtent( strText, &w, &h ); - m_fCursorY = floorf( m_fCursorY - (h * 0.5f) ); - } - // Add window offsets float Winx = 0.0f; float Winy = 0.0f; @@ -626,9 +616,6 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, m_fCursorX += Winx; m_fCursorY += Winy; - // Set a flag so we can determine initial justification effects - BOOL bStartingNewLine = TRUE; - // Begin drawing the vertices // Declared as volatile to force writing in ascending @@ -637,7 +624,7 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, volatile float * pVertex; - unsigned long dwNumChars = wcslen( strText ) + ( dwFlags & FONT_TRUNCATED ? 3 : 0 ); + unsigned long dwNumChars = wcslen(strText); HRESULT hr = pd3dDevice->BeginVertices( D3DPT_QUADLIST, 4 * dwNumChars, sizeof( XMFLOAT4 ) , ( VOID** )&pVertex ); // The ring buffer may run out of space when tiling, doing z-prepasses, @@ -645,31 +632,11 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, if( FAILED( hr ) ) SSNES_ERR( "Ring buffer out of memory.\n" ); - bStartingNewLine = TRUE; - // Draw four vertices for each glyph while( *strText ) { wchar_t letter; - // If starting text on a new line, determine justification effects - if( bStartingNewLine ) - { - if( dwFlags & ( FONT_RIGHT | FONT_CENTER_X ) ) - { - // Get the extent of this line - float w, h; - GetTextExtent( strText, &w, &h, TRUE ); - - // Offset this line's starting m_fCursorX value - if( dwFlags & FONT_RIGHT ) - m_fCursorX = floorf( fOriginX - w ); - if( dwFlags & FONT_CENTER_X ) - m_fCursorX = floorf( fOriginX - w * 0.5f ); - } - bStartingNewLine = FALSE; - } - // Get the current letter in the string letter = *strText++; @@ -678,7 +645,6 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, { m_fCursorX = fOriginX; m_fCursorY += m_fFontYAdvance * m_fYScaleFactor; - bStartingNewLine = TRUE; continue; } diff --git a/360/xdk360_video_debugfonts.h b/360/xdk360_video_debugfonts.h index 32e5b024f6..2aeeab4743 100644 --- a/360/xdk360_video_debugfonts.h +++ b/360/xdk360_video_debugfonts.h @@ -30,12 +30,6 @@ typedef struct GLYPH_ATTR unsigned short wMask; // Channel mask } GLYPH_ATTR; -#define FONT_LEFT 0x00000000 -#define FONT_RIGHT 0x00000001 -#define FONT_CENTER_X 0x00000002 -#define FONT_CENTER_Y 0x00000004 -#define FONT_TRUNCATED 0x00000008 - enum SavedStates { SAVEDSTATE_D3DRS_ALPHABLENDENABLE, @@ -110,10 +104,10 @@ public: // performance, they should batch multiple calls together, bracketed by calls to // Begin() and End(). void Begin(); - void DrawText( unsigned long dwColor, const wchar_t * strText, unsigned long dwFlags=0L, + void DrawText( unsigned long dwColor, const wchar_t * strText, float fMaxPixelWidth = 0.0f ); - void DrawText( float sx, float sy, unsigned long dwColor, const wchar_t * strText, - unsigned long dwFlags=0L, float fMaxPixelWidth = 0.0f ); + void DrawText( float sx, float sy, unsigned long dwColor, + const wchar_t * strText, float fMaxPixelWidth = 0.0f ); void End(); private: From 52402d02c5f08e133838a22279c31a0ae916ff5f Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 16:14:31 +0100 Subject: [PATCH 03/15] (360) Some improvements to font rendering --- 360/xdk360_video.cpp | 5 +++-- 360/xdk360_video_console.cpp | 31 +++++++++---------------------- 360/xdk360_video_console.h | 4 ++-- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index c10776607f..d695cb8e70 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -22,6 +22,7 @@ #include "xdk360_video.h" #include "../general.h" +#include "../message.h" #ifdef HAVE_CONFIG_H #include "config.h" @@ -283,9 +284,9 @@ static bool xdk360_gfx_frame(void *data, const void *frame, { if(IS_TIMER_EXPIRED() || g_first_msg) { - g_screen_console.Format(true, msg); + g_screen_console.Format(msg); g_first_msg = 0; - SET_TIMER_EXPIRATION(60); + SET_TIMER_EXPIRATION(30); } g_screen_console.Render(); diff --git a/360/xdk360_video_console.cpp b/360/xdk360_video_console.cpp index 2516906f3a..d503c34846 100644 --- a/360/xdk360_video_console.cpp +++ b/360/xdk360_video_console.cpp @@ -204,8 +204,7 @@ void Console::Add( wchar_t wch ) m_Lines[ m_nCurLine ][0] = wch; } - if(IS_TIMER_EXPIRED()) - m_cCurLineLength++; + m_cCurLineLength++; } @@ -213,40 +212,28 @@ void Console::Add( wchar_t wch ) // Name: Format() // Desc: Output a variable argument list using a format string //-------------------------------------------------------------------------------------- -void Console::Format(int clear_screen, _In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) +void Console::Format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) { - if(clear_screen) - { - m_nCurLine = 0; - m_cCurLineLength = 0; - memset( m_Buffer, 0, m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - } + m_nCurLine = 0; + m_cCurLineLength = 0; + memset( m_Buffer, 0, m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); va_list pArgList; va_start( pArgList, strFormat ); FormatV( strFormat, pArgList ); va_end( pArgList ); - - // Render the output - Render(); } -void Console::Format(int clear_screen, _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) +void Console::Format(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) { - if(clear_screen) - { - m_nCurLine = 0; - m_cCurLineLength = 0; - memset( m_Buffer, 0, m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - } + m_nCurLine = 0; + m_cCurLineLength = 0; + memset( m_Buffer, 0, m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); va_list pArgList; va_start( pArgList, wstrFormat ); FormatV( wstrFormat, pArgList ); va_end( pArgList ); - - // Render the output - Render(); } diff --git a/360/xdk360_video_console.h b/360/xdk360_video_console.h index 54f00532c5..83d4207876 100644 --- a/360/xdk360_video_console.h +++ b/360/xdk360_video_console.h @@ -47,8 +47,8 @@ public: void Destroy(); // Console output - void Format(int clear_screen, _In_z_ _Printf_format_string_ LPCSTR strFormat, ... ); - void Format(int clear_screen, _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); + void Format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ); + void Format(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); void FormatV( _In_z_ _Printf_format_string_ LPCSTR strFormat, va_list pArgList ); void FormatV( _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, va_list pArgList ); From fd9f020afa2996b9a3549813cdf85e0ef4bc8dda Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 16:28:31 +0100 Subject: [PATCH 04/15] (360) Remove PIX calls --- 360/xdk360_video_debugfonts.cpp | 15 --------------- 360/xdk360_video_resources.cpp | 3 --- 2 files changed, 18 deletions(-) diff --git a/360/xdk360_video_debugfonts.cpp b/360/xdk360_video_debugfonts.cpp index ff65ee94aa..2f25a01f82 100644 --- a/360/xdk360_video_debugfonts.cpp +++ b/360/xdk360_video_debugfonts.cpp @@ -471,8 +471,6 @@ float XdkFont::GetTextWidth( const wchar_t * strText ) const //-------------------------------------------------------------------------------------- VOID XdkFont::Begin() { - PIXBeginNamedEvent( 0, "Text Rendering" ); - // Set state on the first call if( m_dwNestedBeginCount == 0 ) { @@ -575,11 +573,6 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, xdk360_video_t *vid = (xdk360_video_t*)g_d3d; D3DDevice *pd3dDevice = vid->xdk360_render_device; - - // Create a PIX user-defined event that encapsulates all of the text draw calls. - // This makes DrawText calls easier to recognize in PIX captures, and it makes - // them take up fewer entries in the event list. - PIXBeginNamedEvent( dwColor, "DrawText: %S", strText ); // Set the color as a vertex shader constant float vColor[4]; @@ -752,9 +745,6 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, // Call End() to complete the begin/end pair for drawing text End(); - - // Close off the user-defined event opened with PIXBeginNamedEvent. - PIXEndNamedEvent(); } @@ -765,10 +755,7 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, VOID XdkFont::End() { if( --m_dwNestedBeginCount > 0 ) - { - PIXEndNamedEvent(); return; - } // Restore state if( m_bSaveState ) @@ -798,6 +785,4 @@ VOID XdkFont::End() pD3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSU ] ); pD3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSV ] ); } - - PIXEndNamedEvent(); } \ No newline at end of file diff --git a/360/xdk360_video_resources.cpp b/360/xdk360_video_resources.cpp index 104058f575..e65b098ab9 100644 --- a/360/xdk360_video_resources.cpp +++ b/360/xdk360_video_resources.cpp @@ -160,9 +160,6 @@ HRESULT PackedResource::Create( const char * strFilename ) D3DTexture* pTexture = ( D3DTexture* )&m_pSysMemData[m_pResourceTags[i].dwOffset]; // Adjust Base address according to where memory was allocated XGOffsetBaseTextureAddress( pTexture, m_pVidMemData, m_pVidMemData ); - - // Let PIX know the name of the texture - PIXSetTextureName(pTexture, m_pResourceTags[i].strName); } } From 8ec0cb4f6c241e6a2953482328542642ed06ebdc Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 17:45:11 +0100 Subject: [PATCH 05/15] (360) Simplified video console --- 360/xdk360_video_console.cpp | 73 ++++++++++++------------------------ 360/xdk360_video_console.h | 5 +-- 2 files changed, 26 insertions(+), 52 deletions(-) diff --git a/360/xdk360_video_console.cpp b/360/xdk360_video_console.cpp index d503c34846..c96ee0f389 100644 --- a/360/xdk360_video_console.cpp +++ b/360/xdk360_video_console.cpp @@ -142,27 +142,6 @@ void Console::Render (void) m_Font.End(); } - -//-------------------------------------------------------------------------------------- -// Name: Add( CHAR ) -// Desc: Convert ANSI to WCHAR and add to the current line -//-------------------------------------------------------------------------------------- -void Console::Add( char ch ) -{ - wchar_t wch; - - int ret = MultiByteToWideChar( CP_ACP, // ANSI code page - 0, // No flags - &ch, // Character to convert - 1, // Convert one byte - &wch, // Target wide character buffer - 1 ); // One wide character - - Add( wch ); -} - - - //-------------------------------------------------------------------------------------- // Name: Add( WCHAR ) // Desc: Add a wide character to the current line @@ -220,30 +199,8 @@ void Console::Format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) va_list pArgList; va_start( pArgList, strFormat ); - FormatV( strFormat, pArgList ); - va_end( pArgList ); -} -void Console::Format(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) -{ - m_nCurLine = 0; - m_cCurLineLength = 0; - memset( m_Buffer, 0, m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - - va_list pArgList; - va_start( pArgList, wstrFormat ); - FormatV( wstrFormat, pArgList ); - va_end( pArgList ); -} - - -//-------------------------------------------------------------------------------------- -// Name: FormatV() -// Desc: Output a va_list using a format string -//-------------------------------------------------------------------------------------- -void Console::FormatV( _In_z_ _Printf_format_string_ LPCSTR strFormat, va_list pArgList ) -{ - // Count the required length of the string + // Count the required length of the string unsigned long dwStrLen = _vscprintf( strFormat, pArgList ) + 1; // +1 = null terminator char * strMessage = ( char * )_malloca( dwStrLen ); vsprintf_s( strMessage, dwStrLen, strFormat, pArgList ); @@ -251,14 +208,32 @@ void Console::FormatV( _In_z_ _Printf_format_string_ LPCSTR strFormat, va_list p // Output the string to the console unsigned long uStringLength = strlen( strMessage ); for( unsigned long i = 0; i < uStringLength; i++ ) - Add( strMessage[i] ); + { + wchar_t wch; + int ret = MultiByteToWideChar( CP_ACP, // ANSI code page + 0, // No flags + &strMessage[i], // Character to convert + 1, // Convert one byte + &wch, // Target wide character buffer + 1 ); // One wide character + Add( wch ); + } _freea( strMessage ); + + va_end( pArgList ); } -void Console::FormatV( _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, va_list pArgList ) +void Console::FormatW(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) { - // Count the required length of the string + m_nCurLine = 0; + m_cCurLineLength = 0; + memset( m_Buffer, 0, m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + + va_list pArgList; + va_start( pArgList, wstrFormat ); + + // Count the required length of the string unsigned long dwStrLen = _vscwprintf( wstrFormat, pArgList ) + 1; // +1 = null terminator wchar_t * strMessage = ( wchar_t * )_malloca( dwStrLen * sizeof( wchar_t ) ); vswprintf_s( strMessage, dwStrLen, wstrFormat, pArgList ); @@ -269,4 +244,6 @@ void Console::FormatV( _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, va_list Add( strMessage[i] ); _freea( strMessage ); -} + + va_end( pArgList ); +} \ No newline at end of file diff --git a/360/xdk360_video_console.h b/360/xdk360_video_console.h index 83d4207876..b136c05af2 100644 --- a/360/xdk360_video_console.h +++ b/360/xdk360_video_console.h @@ -48,9 +48,7 @@ public: // Console output void Format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ); - void Format(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); - void FormatV( _In_z_ _Printf_format_string_ LPCSTR strFormat, va_list pArgList ); - void FormatV( _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, va_list pArgList ); + void FormatW(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); // method for rendering the console void Render(); @@ -82,7 +80,6 @@ private: int m_nScrollOffset; // offset to display text (in lines) // Add a character to the current line - void Add( char ch ); void Add( wchar_t wch ); }; From 356d565ce64952e30c1c656cf8a4637f0834936e Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 18:19:22 +0100 Subject: [PATCH 06/15] (360) xdk360_video_console no longer class-based --- 360/xdk360_video.cpp | 8 +- 360/xdk360_video.h | 1 - 360/xdk360_video_console.cpp | 198 +++++++++++++++++------------------ 360/xdk360_video_console.h | 59 +++-------- 4 files changed, 116 insertions(+), 150 deletions(-) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index d695cb8e70..048ccd6e6b 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -72,7 +72,6 @@ static bool g_quitting; static bool g_first_msg; unsigned g_frame_count; void *g_d3d; -Console g_screen_console; static void xdk360_gfx_free(void * data) { @@ -284,12 +283,12 @@ static bool xdk360_gfx_frame(void *data, const void *frame, { if(IS_TIMER_EXPIRED() || g_first_msg) { - g_screen_console.Format(msg); + xdk360_console_format(msg); g_first_msg = 0; SET_TIMER_EXPIRATION(30); } - g_screen_console.Render(); + xdk360_console_draw(); } if(!vid->block_swap) @@ -364,7 +363,7 @@ void xdk360_video_init(void) g_first_msg = true; - HRESULT hr = g_screen_console.Create("game:\\media\\Arial_12.xpr", + HRESULT hr = xdk360_console_init("game:\\media\\Arial_12.xpr", 0xff000000, 0xffffffff ); if(FAILED(hr)) { @@ -376,6 +375,7 @@ void xdk360_video_deinit(void) { void *data = g_d3d; g_d3d = NULL; + xdk360_console_deinit(); xdk360_gfx_free(data); } diff --git a/360/xdk360_video.h b/360/xdk360_video.h index 8e0fec84b1..af4857f809 100644 --- a/360/xdk360_video.h +++ b/360/xdk360_video.h @@ -58,7 +58,6 @@ void xdk360_video_init(void); void xdk360_video_deinit(void); void xdk360_video_set_vsync(bool vsync); -extern Console g_screen_console; extern unsigned g_frame_count; extern void *g_d3d; diff --git a/360/xdk360_video_console.cpp b/360/xdk360_video_console.cpp index c96ee0f389..46c636fc5b 100644 --- a/360/xdk360_video_console.cpp +++ b/360/xdk360_video_console.cpp @@ -23,34 +23,56 @@ #include "xdk360_video_debugfonts.h" #include "../general.h" -Console::Console() +static video_console_t video_console; +static XdkFont m_Font; + +void xdk360_console_draw(void) { - first_message = true; - m_Buffer = NULL; - m_Lines = NULL; - m_nScrollOffset = 0; + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + D3DDevice *m_pd3dDevice = vid->xdk360_render_device; + + // The top line + unsigned int nTextLine = ( video_console.m_nCurLine - + video_console.m_cScreenHeight + video_console.m_cScreenHeightVirtual - + video_console.m_nScrollOffset + 1 ) + % video_console.m_cScreenHeightVirtual; + + m_Font.Begin(); + + for( unsigned int nScreenLine = 0; nScreenLine < video_console.m_cScreenHeight; nScreenLine++ ) + { + m_Font.DrawText( (float)( video_console.m_cxSafeAreaOffset ), + (float)( video_console.m_cySafeAreaOffset + + video_console.m_fLineHeight * nScreenLine ), + video_console.m_colTextColor, + video_console.m_Lines[nTextLine] ); + + nTextLine = ( nTextLine + 1 ) % video_console.m_cScreenHeightVirtual; + } + + m_Font.End(); } -Console::~Console() -{ - Destroy(); -} - -HRESULT Console::Create( LPCSTR strFontFileName, unsigned long colBackColor, +HRESULT xdk360_console_init( LPCSTR strFontFileName, unsigned long colBackColor, unsigned long colTextColor) { xdk360_video_t *vid = (xdk360_video_t*)g_d3d; D3DDevice *m_pd3dDevice = vid->xdk360_render_device; + video_console.first_message = true; + video_console.m_Buffer = NULL; + video_console.m_Lines = NULL; + video_console.m_nScrollOffset = 0; + // Calculate the safe area unsigned int uiSafeAreaPct = vid->video_mode.fIsHiDef ? SAFE_AREA_PCT_HDTV : SAFE_AREA_PCT_4x3; - m_cxSafeArea = ( vid->d3dpp.BackBufferWidth * uiSafeAreaPct ) / 100; - m_cySafeArea = ( vid->d3dpp.BackBufferHeight * uiSafeAreaPct ) / 100; + video_console.m_cxSafeArea = ( vid->d3dpp.BackBufferWidth * uiSafeAreaPct ) / 100; + video_console.m_cySafeArea = ( vid->d3dpp.BackBufferHeight * uiSafeAreaPct ) / 100; - m_cxSafeAreaOffset = ( vid->d3dpp.BackBufferWidth - m_cxSafeArea ) / 2; - m_cySafeAreaOffset = ( vid->d3dpp.BackBufferHeight - m_cySafeArea ) / 2; + video_console.m_cxSafeAreaOffset = ( vid->d3dpp.BackBufferWidth - video_console.m_cxSafeArea ) / 2; + video_console.m_cySafeAreaOffset = ( vid->d3dpp.BackBufferHeight - video_console.m_cySafeArea ) / 2; // Create the font HRESULT hr = m_Font.Create( strFontFileName ); @@ -61,115 +83,84 @@ HRESULT Console::Create( LPCSTR strFontFileName, unsigned long colBackColor, } // Save the colors - m_colBackColor = colBackColor; - m_colTextColor = colTextColor; + video_console.m_colBackColor = colBackColor; + video_console.m_colTextColor = colTextColor; // Calculate the number of lines on the screen float fCharWidth, fCharHeight; m_Font.GetTextExtent( L"i", &fCharWidth, &fCharHeight, FALSE ); - m_cScreenHeight = (unsigned int)( m_cySafeArea / fCharHeight ); - m_cScreenWidth = (unsigned int)( m_cxSafeArea / fCharWidth ); + video_console.m_cScreenHeight = (unsigned int)( video_console.m_cySafeArea / fCharHeight ); + video_console.m_cScreenWidth = (unsigned int)( video_console.m_cxSafeArea / fCharWidth ); - m_cScreenHeightVirtual = m_cScreenHeight; + video_console.m_cScreenHeightVirtual = video_console.m_cScreenHeight; - m_fLineHeight = fCharHeight; + video_console.m_fLineHeight = fCharHeight; // Allocate memory to hold the lines - m_Buffer = new wchar_t[ m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) ]; - m_Lines = new wchar_t *[ m_cScreenHeightVirtual ]; + video_console.m_Buffer = new wchar_t[ video_console.m_cScreenHeightVirtual * ( video_console.m_cScreenWidth + 1 ) ]; + video_console.m_Lines = new wchar_t *[ video_console.m_cScreenHeightVirtual ]; // Set the line pointers as indexes into the buffer - for( unsigned int i = 0; i < m_cScreenHeightVirtual; i++ ) - m_Lines[ i ] = m_Buffer + ( m_cScreenWidth + 1 ) * i; + for( unsigned int i = 0; i < video_console.m_cScreenHeightVirtual; i++ ) + video_console.m_Lines[ i ] = video_console.m_Buffer + ( video_console.m_cScreenWidth + 1 ) * i; - m_nCurLine = 0; - m_cCurLineLength = 0; - memset( m_Buffer, 0, m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - Render(); + video_console.m_nCurLine = 0; + video_console.m_cCurLineLength = 0; + memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual * ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + xdk360_console_draw(); return hr; } -//-------------------------------------------------------------------------------------- -// Name: Destroy() -// Desc: Tear everything down -//-------------------------------------------------------------------------------------- -void Console::Destroy() +void xdk360_console_deinit() { // Delete the memory we've allocated - if( m_Lines ) + if(video_console.m_Lines) { - delete[] m_Lines; - m_Lines = NULL; + delete[] video_console.m_Lines; + video_console.m_Lines = NULL; } - if( m_Buffer ) + if(video_console.m_Buffer) { - delete[] m_Buffer; - m_Buffer = NULL; + delete[] video_console.m_Buffer; + video_console.m_Buffer = NULL; } // Destroy the font m_Font.Destroy(); } - -//-------------------------------------------------------------------------------------- -// Name: Render() -// Desc: Render the console to the screen -//-------------------------------------------------------------------------------------- -void Console::Render (void) -{ - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *m_pd3dDevice = vid->xdk360_render_device; - - // The top line - unsigned int nTextLine = ( m_nCurLine - m_cScreenHeight + m_cScreenHeightVirtual - m_nScrollOffset + 1 ) - % m_cScreenHeightVirtual; - - m_Font.Begin(); - - for( unsigned int nScreenLine = 0; nScreenLine < m_cScreenHeight; nScreenLine++ ) - { - m_Font.DrawText( (float)( m_cxSafeAreaOffset ), - (float)( m_cySafeAreaOffset + m_fLineHeight * nScreenLine ), - m_colTextColor, m_Lines[nTextLine] ); - - nTextLine = ( nTextLine + 1 ) % m_cScreenHeightVirtual; - } - - m_Font.End(); -} - -//-------------------------------------------------------------------------------------- -// Name: Add( WCHAR ) -// Desc: Add a wide character to the current line -//-------------------------------------------------------------------------------------- -void Console::Add( wchar_t wch ) +void xdk360_console_add( wchar_t wch ) { // If this is a newline, just increment lines and move on if( wch == L'\n' ) { - m_nCurLine = ( m_nCurLine + 1 ) % m_cScreenHeightVirtual; - m_cCurLineLength = 0; - memset( m_Lines[m_nCurLine], 0, ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + video_console.m_nCurLine = ( video_console.m_nCurLine + 1 ) + % video_console.m_cScreenHeightVirtual; + video_console.m_cCurLineLength = 0; + memset(video_console.m_Lines[video_console.m_nCurLine], 0, + ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); return; } int bIncrementLine = FALSE; // Whether to wrap to the next line - if( m_cCurLineLength == m_cScreenWidth ) + if( video_console.m_cCurLineLength == video_console.m_cScreenWidth ) bIncrementLine = TRUE; else { // Try to append the character to the line - m_Lines[ m_nCurLine ][ m_cCurLineLength ] = wch; + video_console.m_Lines[ video_console.m_nCurLine ] + [ video_console.m_cCurLineLength ] = wch; - if( m_Font.GetTextWidth( m_Lines[ m_nCurLine ] ) > m_cxSafeArea ) + if( m_Font.GetTextWidth( video_console.m_Lines + [ video_console.m_nCurLine ] ) > video_console.m_cxSafeArea ) { // The line is too long, we need to wrap the character to the next line - m_Lines[ m_nCurLine][ m_cCurLineLength ] = L'\0'; + video_console.m_Lines[video_console.m_nCurLine] + [ video_console.m_cCurLineLength ] = L'\0'; bIncrementLine = TRUE; } } @@ -177,31 +168,31 @@ void Console::Add( wchar_t wch ) // If we need to skip to the next line, do so if( bIncrementLine ) { - m_nCurLine = ( m_nCurLine + 1 ) % m_cScreenHeightVirtual; - m_cCurLineLength = 0; - memset( m_Lines[m_nCurLine], 0, ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - m_Lines[ m_nCurLine ][0] = wch; + video_console.m_nCurLine = ( video_console.m_nCurLine + 1 ) + % video_console.m_cScreenHeightVirtual; + video_console.m_cCurLineLength = 0; + memset( video_console.m_Lines[video_console.m_nCurLine], + 0, ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + video_console.m_Lines[video_console.m_nCurLine ][0] = wch; } - m_cCurLineLength++; + video_console.m_cCurLineLength++; } - -//-------------------------------------------------------------------------------------- -// Name: Format() -// Desc: Output a variable argument list using a format string -//-------------------------------------------------------------------------------------- -void Console::Format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) +void xdk360_console_format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) { - m_nCurLine = 0; - m_cCurLineLength = 0; - memset( m_Buffer, 0, m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + video_console.m_nCurLine = 0; + video_console.m_cCurLineLength = 0; + memset( video_console.m_Buffer, 0, + video_console.m_cScreenHeightVirtual * + ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); va_list pArgList; va_start( pArgList, strFormat ); - - // Count the required length of the string - unsigned long dwStrLen = _vscprintf( strFormat, pArgList ) + 1; // +1 = null terminator + + // Count the required length of the string + unsigned long dwStrLen = _vscprintf( strFormat, pArgList ) + 1; + // +1 = null terminator char * strMessage = ( char * )_malloca( dwStrLen ); vsprintf_s( strMessage, dwStrLen, strFormat, pArgList ); @@ -216,7 +207,7 @@ void Console::Format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) 1, // Convert one byte &wch, // Target wide character buffer 1 ); // One wide character - Add( wch ); + xdk360_console_add( wch ); } _freea( strMessage ); @@ -224,11 +215,12 @@ void Console::Format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) va_end( pArgList ); } -void Console::FormatW(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) +void xdk360_console_format_w(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) { - m_nCurLine = 0; - m_cCurLineLength = 0; - memset( m_Buffer, 0, m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + video_console.m_nCurLine = 0; + video_console.m_cCurLineLength = 0; + memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual + * ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); va_list pArgList; va_start( pArgList, wstrFormat ); @@ -241,7 +233,7 @@ void Console::FormatW(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) // Output the string to the console unsigned long uStringLength = wcslen( strMessage ); for( unsigned long i = 0; i < uStringLength; i++ ) - Add( strMessage[i] ); + xdk360_console_add( strMessage[i] ); _freea( strMessage ); diff --git a/360/xdk360_video_console.h b/360/xdk360_video_console.h index b136c05af2..d3173f740b 100644 --- a/360/xdk360_video_console.h +++ b/360/xdk360_video_console.h @@ -32,55 +32,30 @@ #define SAFE_AREA_PCT_4x3 85 #define SAFE_AREA_PCT_HDTV 90 -//-------------------------------------------------------------------------------------- -// Name: class Console -// Desc: Class to implement the console. -//-------------------------------------------------------------------------------------- -class Console +typedef struct { -public: - Console(); - ~Console(); - - // Initialization - HRESULT Create( LPCSTR strFontFileName, D3DCOLOR colBackColor, D3DCOLOR colTextColor); - void Destroy(); - - // Console output - void Format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ); - void FormatW(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); - - // method for rendering the console - void Render(); - // Font for rendering text - XdkFont m_Font; -private: - int first_message; - // Safe area dimensions - unsigned int m_cxSafeArea; + float m_fLineHeight; // height of a single line in pixels + unsigned int m_nScrollOffset; // offset to display text (in lines) + unsigned int first_message; + unsigned int m_cxSafeArea; unsigned int m_cySafeArea; - unsigned int m_cxSafeAreaOffset; unsigned int m_cySafeAreaOffset; - - // Colors - unsigned long m_colBackColor; + unsigned int m_nCurLine; // index of current line being written to + unsigned int m_cCurLineLength; // length of the current line + unsigned long m_colBackColor; unsigned long m_colTextColor; - - // Text Buffers - unsigned int m_cScreenHeight; // height in lines of screen area + unsigned int m_cScreenHeight; // height in lines of screen area unsigned int m_cScreenHeightVirtual; // height in lines of text storage buffer unsigned int m_cScreenWidth; // width in characters - float m_fLineHeight; // height of a single line in pixels + wchar_t * m_Buffer; // buffer big enough to hold a full screen + wchar_t ** m_Lines; // pointers to individual lines +} video_console_t; - wchar_t * m_Buffer; // buffer big enough to hold a full screen - wchar_t ** m_Lines; // pointers to individual lines - unsigned int m_nCurLine; // index of current line being written to - unsigned int m_cCurLineLength; // length of the current line - int m_nScrollOffset; // offset to display text (in lines) - - // Add a character to the current line - void Add( wchar_t wch ); -}; +HRESULT xdk360_console_init ( LPCSTR strFontFileName, D3DCOLOR colBackColor, D3DCOLOR colTextColor); +void xdk360_console_deinit (void); +void xdk360_console_format (_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ); +void xdk360_console_format_w (_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); +void xdk360_console_draw (void); #endif From 6d1ab7ebfdf612df05d0cd9a3bc8584f9a894633 Mon Sep 17 00:00:00 2001 From: Themaister Date: Thu, 16 Feb 2012 20:22:58 +0100 Subject: [PATCH 07/15] Revert changes with HAVE_XML. The XML read for memory map are not parsed in any way by SSNES and does not depend on libxml2. Also keep removal of log where XML map is not found (very likely anyways). --- file.c | 8 +------- ssnes.c | 11 +---------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/file.c b/file.c index 95f9533c19..12ce830781 100644 --- a/file.c +++ b/file.c @@ -550,23 +550,17 @@ void save_ram_file(const char *path, int type) } } -#ifdef HAVE_XML static char *load_xml_map(const char *path) { char *xml_buf = NULL; if (*path) { - if (!read_file_string(path, &xml_buf)) - SSNES_LOG("Did not find XML memory map in \"%s\"\n", path); - else + if (read_file_string(path, &xml_buf)) SSNES_LOG("Found XML memory map in \"%s\"\n", path); } return xml_buf; } -#else -#define load_xml_map(xml_name) (NULL) -#endif static bool load_sgb_rom(void) { diff --git a/ssnes.c b/ssnes.c index cbf22d6acf..389e767512 100644 --- a/ssnes.c +++ b/ssnes.c @@ -419,9 +419,7 @@ static void print_features(void) _PSUPP(al, "OpenAL", "audio driver"); _PSUPP(dylib, "External", "External filter and driver support"); _PSUPP(cg, "Cg", "Cg pixel shaders"); -#ifdef HAVE_XML _PSUPP(xml, "XML", "bSNES XML pixel shaders"); -#endif _PSUPP(sdl_image, "SDL_image", "SDL_image image loading"); _PSUPP(fbo, "FBO", "OpenGL render-to-texture (multi-pass shaders)"); _PSUPP(dynamic, "Dynamic", "Dynamic run-time loading of libsnes library"); @@ -512,9 +510,7 @@ static void print_help(void) puts("\t-v/--verbose: Verbose logging."); puts("\t-U/--ups: Specifies path for UPS patch that will be applied to ROM."); puts("\t--bps: Specifies path for BPS patch that will be applied to ROM."); -#ifdef HAVE_XML puts("\t-X/--xml: Specifies path to XML memory map."); -#endif puts("\t-D/--detach: Detach SSNES from the running console. Not relevant for all platforms.\n"); } @@ -661,9 +657,7 @@ static void parse_input(int argc, char *argv[]) #endif { "ups", 1, NULL, 'U' }, { "bps", 1, &val, 'B' }, -#ifdef HAVE_XML { "xml", 1, NULL, 'X' }, -#endif { "detach", 0, NULL, 'D' }, { "features", 0, &val, 'f' }, { NULL, 0, NULL, 0 } @@ -856,11 +850,10 @@ static void parse_input(int argc, char *argv[]) strlcpy(g_extern.ups_name, optarg, sizeof(g_extern.ups_name)); g_extern.ups_pref = true; break; -#ifdef HAVE_XML + case 'X': strlcpy(g_extern.xml_name, optarg, sizeof(g_extern.xml_name)); break; -#endif case 'D': #if defined(_WIN32) && !defined(_XBOX) @@ -1492,10 +1485,8 @@ static void fill_pathnames(void) if (!(*g_extern.bps_name)) fill_pathname_noext(g_extern.bps_name, g_extern.basename, ".bps", sizeof(g_extern.bps_name)); -#ifdef HAVE_XML if (!(*g_extern.xml_name)) fill_pathname_noext(g_extern.xml_name, g_extern.basename, ".xml", sizeof(g_extern.xml_name)); -#endif if (!(*g_settings.screenshot_directory)) { From f2f09ce2ed00087e894a2c3cec40803c186faf98 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 22:10:54 +0100 Subject: [PATCH 08/15] (360) xdk360_video_debugfonts is no longer class-based --- 360/xdk360_video_console.cpp | 21 +- 360/xdk360_video_debugfonts.cpp | 339 +++++++++++++------------------- 360/xdk360_video_debugfonts.h | 74 ++----- 3 files changed, 165 insertions(+), 269 deletions(-) diff --git a/360/xdk360_video_console.cpp b/360/xdk360_video_console.cpp index 46c636fc5b..c7e797b2da 100644 --- a/360/xdk360_video_console.cpp +++ b/360/xdk360_video_console.cpp @@ -24,7 +24,7 @@ #include "../general.h" static video_console_t video_console; -static XdkFont m_Font; +static xdk360_video_font_t m_Font; void xdk360_console_draw(void) { @@ -37,20 +37,20 @@ void xdk360_console_draw(void) video_console.m_nScrollOffset + 1 ) % video_console.m_cScreenHeightVirtual; - m_Font.Begin(); + xdk360_video_font_begin(&m_Font); for( unsigned int nScreenLine = 0; nScreenLine < video_console.m_cScreenHeight; nScreenLine++ ) { - m_Font.DrawText( (float)( video_console.m_cxSafeAreaOffset ), + xdk360_video_font_draw_text(&m_Font, (float)( video_console.m_cxSafeAreaOffset ), (float)( video_console.m_cySafeAreaOffset + video_console.m_fLineHeight * nScreenLine ), video_console.m_colTextColor, - video_console.m_Lines[nTextLine] ); + video_console.m_Lines[nTextLine], 0.0f ); nTextLine = ( nTextLine + 1 ) % video_console.m_cScreenHeightVirtual; } - m_Font.End(); + xdk360_video_font_end(&m_Font); } HRESULT xdk360_console_init( LPCSTR strFontFileName, unsigned long colBackColor, @@ -75,7 +75,7 @@ HRESULT xdk360_console_init( LPCSTR strFontFileName, unsigned long colBackColor, video_console.m_cySafeAreaOffset = ( vid->d3dpp.BackBufferHeight - video_console.m_cySafeArea ) / 2; // Create the font - HRESULT hr = m_Font.Create( strFontFileName ); + HRESULT hr = xdk360_video_font_init(&m_Font, strFontFileName ); if( FAILED( hr ) ) { SSNES_ERR( "Could not create font.\n" ); @@ -88,7 +88,7 @@ HRESULT xdk360_console_init( LPCSTR strFontFileName, unsigned long colBackColor, // Calculate the number of lines on the screen float fCharWidth, fCharHeight; - m_Font.GetTextExtent( L"i", &fCharWidth, &fCharHeight, FALSE ); + xdk360_video_font_get_text_width(&m_Font, L"i", &fCharWidth, &fCharHeight, FALSE); video_console.m_cScreenHeight = (unsigned int)( video_console.m_cySafeArea / fCharHeight ); video_console.m_cScreenWidth = (unsigned int)( video_console.m_cxSafeArea / fCharWidth ); @@ -129,7 +129,7 @@ void xdk360_console_deinit() } // Destroy the font - m_Font.Destroy(); + xdk360_video_font_deinit(&m_Font); } void xdk360_console_add( wchar_t wch ) @@ -155,8 +155,9 @@ void xdk360_console_add( wchar_t wch ) video_console.m_Lines[ video_console.m_nCurLine ] [ video_console.m_cCurLineLength ] = wch; - if( m_Font.GetTextWidth( video_console.m_Lines - [ video_console.m_nCurLine ] ) > video_console.m_cxSafeArea ) + float fTextWidth, fTextHeight; + xdk360_video_font_get_text_width(&m_Font, video_console.m_Lines[ video_console.m_nCurLine ], &fTextWidth, &fTextHeight, 0); + if( fTextHeight > video_console.m_cxSafeArea ) { // The line is too long, we need to wrap the character to the next line video_console.m_Lines[video_console.m_nCurLine] diff --git a/360/xdk360_video_debugfonts.cpp b/360/xdk360_video_debugfonts.cpp index 2f25a01f82..3ba71fac5e 100644 --- a/360/xdk360_video_debugfonts.cpp +++ b/360/xdk360_video_debugfonts.cpp @@ -44,6 +44,8 @@ typedef struct FontFileStrikesImage_t { GLYPH_ATTR m_Glyphs[1]; // Array of font strike uv's etc... NOTE: It's m_dwNumGlyphs in size } FontFileStrikesImage_t; +static PackedResource m_xprResource; + //-------------------------------------------------------------------------------------- // Vertex and pixel shaders for font rendering // Please note the removal of comment or dead lines... @@ -130,12 +132,7 @@ typedef struct AtgFont_Locals_t { // All elements are defaulted to NULL static AtgFont_Locals_t s_AtgFontLocals; // Global static instance -//-------------------------------------------------------------------------------------- -// Name: CreateFontShaders() -// Desc: Creates the global font shaders -//-------------------------------------------------------------------------------------- - -HRESULT XdkFont::CreateFontShaders() +static HRESULT xdk360_video_font_create_shaders (xdk360_video_font_t * font) { // // There are only two states the globals could be in, @@ -232,53 +229,26 @@ HRESULT XdkFont::CreateFontShaders() return hr; // Return the error code if any } -//-------------------------------------------------------------------------------------- -// Name: Font() -// Desc: Constructor -//-------------------------------------------------------------------------------------- -XdkFont::XdkFont() +void xdk360_video_font_set_size(xdk360_video_font_t * font, float x, float y) { - m_pFontTexture = NULL; - - m_dwNumGlyphs = 0L; - m_Glyphs = NULL; - - m_fCursorX = 0.0f; - m_fCursorY = 0.0f; - - m_fXScaleFactor = 2.0f; - m_fYScaleFactor = 2.0f; - - m_cMaxGlyph = 0; - m_TranslatorTable = NULL; - - m_dwNestedBeginCount = 0L; + font->m_fXScaleFactor = x; + font->m_fYScaleFactor = y; } - -//-------------------------------------------------------------------------------------- -// Name: ~Font() -// Desc: Destructor -//-------------------------------------------------------------------------------------- -XdkFont::~XdkFont() +HRESULT xdk360_video_font_init(xdk360_video_font_t * font, const char * strFontFileName) { - Destroy(); -} - -void XdkFont::SetFontSize(float x, float y) -{ - m_fXScaleFactor = x; - m_fYScaleFactor = y; -} - -//-------------------------------------------------------------------------------------- -// Name: Create() -// Desc: Create the font's internal objects (texture and array of glyph info) -// using the XPR packed resource file -//-------------------------------------------------------------------------------------- -HRESULT XdkFont::Create( const char * strFontFileName ) -{ - // Create the font + font->m_pFontTexture = NULL; + font->m_dwNumGlyphs = 0L; + font->m_Glyphs = NULL; + font->m_fCursorX = 0.0f; + font->m_fCursorY = 0.0f; + font->m_fXScaleFactor = 2.0f; + font->m_fYScaleFactor = 2.0f; + font->m_cMaxGlyph = 0; + font->m_TranslatorTable = NULL; + font->m_dwNestedBeginCount = 0L; + + // Create the font if( FAILED( m_xprResource.Create( strFontFileName ) ) ) return E_FAIL; @@ -286,7 +256,7 @@ HRESULT XdkFont::Create( const char * strFontFileName ) const void * pFontData = m_xprResource.GetData( "FontData"); // Save a copy of the texture - m_pFontTexture = pFontTexture; + font->m_pFontTexture = pFontTexture; // Check version of file (to make sure it matches up with the FontMaker tool) const unsigned char * pData = static_cast(pFontData); @@ -294,21 +264,21 @@ HRESULT XdkFont::Create( const char * strFontFileName ) if( dwFileVersion == FONTFILEVERSION ) { - m_fFontHeight = reinterpret_cast(pData)->m_fFontHeight; - m_fFontTopPadding = reinterpret_cast(pData)->m_fFontTopPadding; - m_fFontBottomPadding = reinterpret_cast(pData)->m_fFontBottomPadding; - m_fFontYAdvance = reinterpret_cast(pData)->m_fFontYAdvance; + font->m_fFontHeight = reinterpret_cast(pData)->m_fFontHeight; + font->m_fFontTopPadding = reinterpret_cast(pData)->m_fFontTopPadding; + font->m_fFontBottomPadding = reinterpret_cast(pData)->m_fFontBottomPadding; + font->m_fFontYAdvance = reinterpret_cast(pData)->m_fFontYAdvance; // Point to the translator string which immediately follows the 4 floats - m_cMaxGlyph = reinterpret_cast(pData)->m_cMaxGlyph; + font->m_cMaxGlyph = reinterpret_cast(pData)->m_cMaxGlyph; - m_TranslatorTable = const_cast(reinterpret_cast(pData))->m_TranslatorTable; + font->m_TranslatorTable = const_cast(reinterpret_cast(pData))->m_TranslatorTable; - pData += CALCFONTFILEHEADERSIZE( m_cMaxGlyph + 1 ); + pData += CALCFONTFILEHEADERSIZE( font->m_cMaxGlyph + 1 ); // Read the glyph attributes from the file - m_dwNumGlyphs = reinterpret_cast(pData)->m_dwNumGlyphs; - m_Glyphs = reinterpret_cast(pData)->m_Glyphs; // Pointer + font->m_dwNumGlyphs = reinterpret_cast(pData)->m_dwNumGlyphs; + font->m_Glyphs = reinterpret_cast(pData)->m_Glyphs; // Pointer } else { @@ -317,7 +287,7 @@ HRESULT XdkFont::Create( const char * strFontFileName ) } // Create the vertex and pixel shaders for rendering the font - if( FAILED( CreateFontShaders() ) ) + if( FAILED( xdk360_video_font_create_shaders(font) ) ) { SSNES_ERR( "Could not create font shaders.\n" ); return E_FAIL; @@ -329,29 +299,25 @@ HRESULT XdkFont::Create( const char * strFontFileName ) // Initialize the window D3DDISPLAYMODE DisplayMode; pd3dDevice->GetDisplayMode( 0, &DisplayMode ); - m_rcWindow.x1 = 0; - m_rcWindow.y1 = 0; - m_rcWindow.x2 = DisplayMode.Width; - m_rcWindow.y2 = DisplayMode.Height; + font->m_rcWindow.x1 = 0; + font->m_rcWindow.y1 = 0; + font->m_rcWindow.x2 = DisplayMode.Width; + font->m_rcWindow.y2 = DisplayMode.Height; // Determine whether we should save/restore state - m_bSaveState = TRUE; + font->m_bSaveState = TRUE; return S_OK; } -//-------------------------------------------------------------------------------------- -// Name: Destroy() -// Desc: Destroy the font object -//-------------------------------------------------------------------------------------- -void XdkFont::Destroy() +void xdk360_video_font_deinit(xdk360_video_font_t * font) { - m_pFontTexture = NULL; - m_dwNumGlyphs = 0L; - m_Glyphs = NULL; - m_cMaxGlyph = 0; - m_TranslatorTable = NULL; - m_dwNestedBeginCount = 0L; + font->m_pFontTexture = NULL; + font->m_dwNumGlyphs = 0L; + font->m_Glyphs = NULL; + font->m_cMaxGlyph = 0; + font->m_TranslatorTable = NULL; + font->m_dwNestedBeginCount = 0L; // Safely release shaders // NOTE: They are released in reverse order of creation @@ -368,25 +334,15 @@ void XdkFont::Destroy() m_xprResource.Destroy(); } -//-------------------------------------------------------------------------------------- -// Name: SetCursorPosition() -// Desc: Sets the cursor position for drawing text -//-------------------------------------------------------------------------------------- -void XdkFont::SetCursorPosition( float fCursorX, float fCursorY ) +void xdk360_video_font_set_cursor_position(xdk360_video_font_t *font, float fCursorX, float fCursorY ) { - m_fCursorX = floorf( fCursorX ); - m_fCursorY = floorf( fCursorY ); + font->m_fCursorX = floorf( fCursorX ); + font->m_fCursorY = floorf( fCursorY ); } -//-------------------------------------------------------------------------------------- -// Name: GetTextExtent() -// Desc: Get the dimensions of a text string -//-------------------------------------------------------------------------------------- - -void XdkFont::GetTextExtent( const wchar_t * strText, float * pWidth, - float * pHeight, int bFirstLineOnly ) const +void xdk360_video_font_get_text_width(xdk360_video_font_t * font, const wchar_t * strText, float * pWidth, float * pHeight, int bFirstLineOnly) { - // Set default text extent in output parameters + // Set default text extent in output parameters int iWidth = 0; float fHeight = 0.0f; @@ -394,7 +350,7 @@ void XdkFont::GetTextExtent( const wchar_t * strText, float * pWidth, { // Initialize counters that keep track of text extent int ix = 0; - float fy = m_fFontHeight; // One character high to start + float fy = font->m_fFontHeight; // One character high to start if( fy > fHeight ) fHeight = fy; @@ -410,7 +366,7 @@ void XdkFont::GetTextExtent( const wchar_t * strText, float * pWidth, if( bFirstLineOnly ) break; ix = 0; - fy += m_fFontYAdvance; + fy += font->m_fFontYAdvance; // since the height has changed, test against the height extent if( fy > fHeight ) fHeight = fy; @@ -424,12 +380,12 @@ void XdkFont::GetTextExtent( const wchar_t * strText, float * pWidth, // Translate unprintable characters const GLYPH_ATTR* pGlyph; - if( letter > m_cMaxGlyph ) + if( letter > font->m_cMaxGlyph ) letter = 0; // Out of bounds? else - letter = m_TranslatorTable[letter]; // Remap ASCII to glyph + letter = font->m_TranslatorTable[letter]; // Remap ASCII to glyph - pGlyph = &m_Glyphs[letter]; // Get the requested glyph + pGlyph = &font->m_Glyphs[letter]; // Get the requested glyph // Get text extent for this character's glyph ix += pGlyph->wOffset; @@ -445,70 +401,54 @@ void XdkFont::GetTextExtent( const wchar_t * strText, float * pWidth, // Convert the width to a float here, load/hit/store. :( float fWidth = static_cast(iWidth); // Delay the use if fWidth to reduce LHS pain // Apply the scale factor to the result - fHeight *= m_fYScaleFactor; + fHeight *= font->m_fYScaleFactor; // Store the final results *pHeight = fHeight; - fWidth *= m_fXScaleFactor; + fWidth *= font->m_fXScaleFactor; *pWidth = fWidth; } -//-------------------------------------------------------------------------------------- -// Name: GetTextWidth() -// Desc: Returns the width in pixels of a text string -//-------------------------------------------------------------------------------------- -float XdkFont::GetTextWidth( const wchar_t * strText ) const -{ - float fTextWidth, fTextHeight; - GetTextExtent( strText, &fTextWidth, &fTextHeight ); - return fTextWidth; -} - - -//-------------------------------------------------------------------------------------- -// Name: Begin() -// Desc: Prepares the font vertex buffers for rendering. -//-------------------------------------------------------------------------------------- -VOID XdkFont::Begin() +void xdk360_video_font_begin (xdk360_video_font_t * font) { // Set state on the first call - if( m_dwNestedBeginCount == 0 ) + if( font->m_dwNestedBeginCount == 0 ) { // Cache the global pointer into a register xdk360_video_t *vid = (xdk360_video_t*)g_d3d; D3DDevice *pD3dDevice = vid->xdk360_render_device; // Save state - if( m_bSaveState ) + if( font->m_bSaveState ) { // Note, we are not saving the texture, vertex, or pixel shader, // since it's not worth the performance. We're more interested // in saving state that would cause hard to find problems. pD3dDevice->GetRenderState( D3DRS_ALPHABLENDENABLE, - &m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHABLENDENABLE ] ); - pD3dDevice->GetRenderState( D3DRS_SRCBLEND, &m_dwSavedState[ SAVEDSTATE_D3DRS_SRCBLEND ] ); - pD3dDevice->GetRenderState( D3DRS_DESTBLEND, &m_dwSavedState[ SAVEDSTATE_D3DRS_DESTBLEND ] ); - pD3dDevice->GetRenderState( D3DRS_BLENDOP, &m_dwSavedState[ SAVEDSTATE_D3DRS_BLENDOP ] ); - pD3dDevice->GetRenderState( D3DRS_ALPHATESTENABLE, &m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHATESTENABLE ] ); - pD3dDevice->GetRenderState( D3DRS_ALPHAREF, &m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAREF ] ); - pD3dDevice->GetRenderState( D3DRS_ALPHAFUNC, &m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAFUNC ] ); - pD3dDevice->GetRenderState( D3DRS_FILLMODE, &m_dwSavedState[ SAVEDSTATE_D3DRS_FILLMODE ] ); - pD3dDevice->GetRenderState( D3DRS_CULLMODE, &m_dwSavedState[ SAVEDSTATE_D3DRS_CULLMODE ] ); - pD3dDevice->GetRenderState( D3DRS_ZENABLE, &m_dwSavedState[ SAVEDSTATE_D3DRS_ZENABLE ] ); - pD3dDevice->GetRenderState( D3DRS_STENCILENABLE, &m_dwSavedState[ SAVEDSTATE_D3DRS_STENCILENABLE ] ); - pD3dDevice->GetRenderState( D3DRS_VIEWPORTENABLE, &m_dwSavedState[ SAVEDSTATE_D3DRS_VIEWPORTENABLE ] ); - pD3dDevice->GetSamplerState( 0, D3DSAMP_MINFILTER, &m_dwSavedState[ SAVEDSTATE_D3DSAMP_MINFILTER ] ); - pD3dDevice->GetSamplerState( 0, D3DSAMP_MAGFILTER, &m_dwSavedState[ SAVEDSTATE_D3DSAMP_MAGFILTER ] ); - pD3dDevice->GetSamplerState( 0, D3DSAMP_ADDRESSU, &m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSU ] ); - pD3dDevice->GetSamplerState( 0, D3DSAMP_ADDRESSV, &m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSV ] ); + &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHABLENDENABLE ] ); + pD3dDevice->GetRenderState( D3DRS_SRCBLEND, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_SRCBLEND ] ); + pD3dDevice->GetRenderState( D3DRS_DESTBLEND, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_DESTBLEND ] ); + pD3dDevice->GetRenderState( D3DRS_BLENDOP, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_BLENDOP ] ); + pD3dDevice->GetRenderState( D3DRS_ALPHATESTENABLE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHATESTENABLE ] ); + pD3dDevice->GetRenderState( D3DRS_ALPHAREF, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAREF ] ); + pD3dDevice->GetRenderState( D3DRS_ALPHAFUNC, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAFUNC ] ); + pD3dDevice->GetRenderState( D3DRS_FILLMODE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_FILLMODE ] ); + pD3dDevice->GetRenderState( D3DRS_CULLMODE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_CULLMODE ] ); + pD3dDevice->GetRenderState( D3DRS_ZENABLE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ZENABLE ] ); + pD3dDevice->GetRenderState( D3DRS_STENCILENABLE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_STENCILENABLE ] ); + pD3dDevice->GetRenderState( D3DRS_VIEWPORTENABLE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_VIEWPORTENABLE ] ); + pD3dDevice->GetSamplerState( 0, D3DSAMP_MINFILTER, &font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MINFILTER ] ); + pD3dDevice->GetSamplerState( 0, D3DSAMP_MAGFILTER, &font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MAGFILTER ] ); + pD3dDevice->GetSamplerState( 0, D3DSAMP_ADDRESSU, &font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSU ] ); + pD3dDevice->GetSamplerState( 0, D3DSAMP_ADDRESSV, &font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSV ] ); } // Set the texture scaling factor as a vertex shader constant D3DSURFACE_DESC TextureDesc; - m_pFontTexture->GetLevelDesc( 0, &TextureDesc ); // Get the description + font->m_pFontTexture->GetLevelDesc( 0, &TextureDesc ); // Get the description // Set render state - pD3dDevice->SetTexture( 0, m_pFontTexture ); + pD3dDevice->SetTexture( 0, font->m_pFontTexture ); // Read the TextureDesc here to ensure no load/hit/store from GetLevelDesc() float vTexScale[4]; @@ -544,20 +484,47 @@ VOID XdkFont::Begin() } // Keep track of the nested begin/end calls. - m_dwNestedBeginCount++; + font->m_dwNestedBeginCount++; } - //-------------------------------------------------------------------------------------- -// Name: DrawText() -// Desc: Draws text as textured polygons +// Name: End() +// Desc: Paired call that restores state set in the Begin() call. //-------------------------------------------------------------------------------------- -VOID XdkFont::DrawText( unsigned long dwColor, const wchar_t * strText, - float fMaxPixelWidth ) +void xdk360_video_font_end(xdk360_video_font_t * font) { - DrawText( m_fCursorX, m_fCursorY, dwColor, strText, fMaxPixelWidth ); -} + if( --font->m_dwNestedBeginCount > 0 ) + return; + // Restore state + if( font->m_bSaveState ) + { + // Cache the global pointer into a register + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + D3DDevice *pD3dDevice = vid->xdk360_render_device; + + pD3dDevice->SetTexture( 0, NULL ); + pD3dDevice->SetVertexDeclaration( NULL ); + pD3dDevice->SetVertexShader( NULL ); + pD3dDevice->SetPixelShader( NULL ); + pD3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHABLENDENABLE ] ); + pD3dDevice->SetRenderState( D3DRS_SRCBLEND, font->m_dwSavedState[ SAVEDSTATE_D3DRS_SRCBLEND ] ); + pD3dDevice->SetRenderState( D3DRS_DESTBLEND, font->m_dwSavedState[ SAVEDSTATE_D3DRS_DESTBLEND ] ); + pD3dDevice->SetRenderState( D3DRS_BLENDOP, font->m_dwSavedState[ SAVEDSTATE_D3DRS_BLENDOP ] ); + pD3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHATESTENABLE ] ); + pD3dDevice->SetRenderState( D3DRS_ALPHAREF, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAREF ] ); + pD3dDevice->SetRenderState( D3DRS_ALPHAFUNC, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAFUNC ] ); + pD3dDevice->SetRenderState( D3DRS_FILLMODE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_FILLMODE ] ); + pD3dDevice->SetRenderState( D3DRS_CULLMODE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_CULLMODE ] ); + pD3dDevice->SetRenderState( D3DRS_ZENABLE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ZENABLE ] ); + pD3dDevice->SetRenderState( D3DRS_STENCILENABLE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_STENCILENABLE ] ); + pD3dDevice->SetRenderState( D3DRS_VIEWPORTENABLE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_VIEWPORTENABLE ] ); + pD3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MINFILTER ] ); + pD3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MAGFILTER ] ); + pD3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSU ] ); + pD3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSV ] ); + } +} //-------------------------------------------------------------------------------------- // Name: DrawText() @@ -565,7 +532,7 @@ VOID XdkFont::DrawText( unsigned long dwColor, const wchar_t * strText, // TODO: This function should use the Begin/SetVertexData/End() API when it // becomes available. //-------------------------------------------------------------------------------------- -VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, +void xdk360_video_font_draw_text(xdk360_video_font_t * font, float fOriginX, float fOriginY, unsigned long dwColor, const wchar_t * strText, float fMaxPixelWidth ) { if( strText == NULL || strText[0] == L'\0') @@ -582,7 +549,7 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, vColor[3] = ( ( dwColor & 0xff000000 ) >> 24L ) / 255.0F; // Set up stuff to prepare for drawing text - Begin(); + xdk360_video_font_begin(font); // Perform the actual storing of the color constant here to prevent // a load-hit-store by inserting work between the store and the use of @@ -591,23 +558,23 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, // Set the starting screen position if((fOriginX < 0.0f)) - fOriginX += m_rcWindow.x2; + fOriginX += font->m_rcWindow.x2; if( fOriginY < 0.0f ) - fOriginY += m_rcWindow.y2; + fOriginY += font->m_rcWindow.y2; - m_fCursorX = floorf( fOriginX ); - m_fCursorY = floorf( fOriginY ); + font->m_fCursorX = floorf( fOriginX ); + font->m_fCursorY = floorf( fOriginY ); // Adjust for padding - fOriginY -= m_fFontTopPadding; + fOriginY -= font->m_fFontTopPadding; // Add window offsets float Winx = 0.0f; float Winy = 0.0f; fOriginX += Winx; fOriginY += Winy; - m_fCursorX += Winx; - m_fCursorY += Winy; + font->m_fCursorX += Winx; + font->m_fCursorY += Winy; // Begin drawing the vertices @@ -636,31 +603,31 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, // Handle the newline character if( letter == L'\n' ) { - m_fCursorX = fOriginX; - m_fCursorY += m_fFontYAdvance * m_fYScaleFactor; + font->m_fCursorX = fOriginX; + font->m_fCursorY += font->m_fFontYAdvance * font->m_fYScaleFactor; continue; } // Translate unprintable characters - const GLYPH_ATTR * pGlyph = &m_Glyphs[ ( letter <= m_cMaxGlyph ) ? m_TranslatorTable[letter] : 0 ]; + const GLYPH_ATTR * pGlyph = &font->m_Glyphs[ ( letter <= font->m_cMaxGlyph ) ? font->m_TranslatorTable[letter] : 0 ]; - float fOffset = m_fXScaleFactor * (float)pGlyph->wOffset; - float fAdvance = m_fXScaleFactor * (float)pGlyph->wAdvance; - float fWidth = m_fXScaleFactor * (float)pGlyph->wWidth; - float fHeight = m_fYScaleFactor * m_fFontHeight; + float fOffset = font->m_fXScaleFactor * (float)pGlyph->wOffset; + float fAdvance = font->m_fXScaleFactor * (float)pGlyph->wAdvance; + float fWidth = font->m_fXScaleFactor * (float)pGlyph->wWidth; + float fHeight = font->m_fYScaleFactor * font->m_fFontHeight; // Setup the screen coordinates - m_fCursorX += fOffset; - float X4 = m_fCursorX; + font->m_fCursorX += fOffset; + float X4 = font->m_fCursorX; float X1 = X4; float X3 = X4 + fWidth; float X2 = X1 + fWidth; - float Y1 = m_fCursorY; + float Y1 = font->m_fCursorY; float Y3 = Y1 + fHeight; float Y2 = Y1; float Y4 = Y3; - m_fCursorX += fAdvance; + font->m_fCursorX += fAdvance; // Select the RGBA channel that the compressed glyph is stored in // Takes a 4 bit per pixel ARGB value and expand it to an 8 bit per pixel ARGB value @@ -740,49 +707,9 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, pd3dDevice->EndVertices(); // Undo window offsets - m_fCursorX -= Winx; - m_fCursorY -= Winy; + font->m_fCursorX -= Winx; + font->m_fCursorY -= Winy; // Call End() to complete the begin/end pair for drawing text - End(); -} - - -//-------------------------------------------------------------------------------------- -// Name: End() -// Desc: Paired call that restores state set in the Begin() call. -//-------------------------------------------------------------------------------------- -VOID XdkFont::End() -{ - if( --m_dwNestedBeginCount > 0 ) - return; - - // Restore state - if( m_bSaveState ) - { - // Cache the global pointer into a register - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *pD3dDevice = vid->xdk360_render_device; - - pD3dDevice->SetTexture( 0, NULL ); - pD3dDevice->SetVertexDeclaration( NULL ); - pD3dDevice->SetVertexShader( NULL ); - pD3dDevice->SetPixelShader( NULL ); - pD3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHABLENDENABLE ] ); - pD3dDevice->SetRenderState( D3DRS_SRCBLEND, m_dwSavedState[ SAVEDSTATE_D3DRS_SRCBLEND ] ); - pD3dDevice->SetRenderState( D3DRS_DESTBLEND, m_dwSavedState[ SAVEDSTATE_D3DRS_DESTBLEND ] ); - pD3dDevice->SetRenderState( D3DRS_BLENDOP, m_dwSavedState[ SAVEDSTATE_D3DRS_BLENDOP ] ); - pD3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHATESTENABLE ] ); - pD3dDevice->SetRenderState( D3DRS_ALPHAREF, m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAREF ] ); - pD3dDevice->SetRenderState( D3DRS_ALPHAFUNC, m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAFUNC ] ); - pD3dDevice->SetRenderState( D3DRS_FILLMODE, m_dwSavedState[ SAVEDSTATE_D3DRS_FILLMODE ] ); - pD3dDevice->SetRenderState( D3DRS_CULLMODE, m_dwSavedState[ SAVEDSTATE_D3DRS_CULLMODE ] ); - pD3dDevice->SetRenderState( D3DRS_ZENABLE, m_dwSavedState[ SAVEDSTATE_D3DRS_ZENABLE ] ); - pD3dDevice->SetRenderState( D3DRS_STENCILENABLE, m_dwSavedState[ SAVEDSTATE_D3DRS_STENCILENABLE ] ); - pD3dDevice->SetRenderState( D3DRS_VIEWPORTENABLE, m_dwSavedState[ SAVEDSTATE_D3DRS_VIEWPORTENABLE ] ); - pD3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, m_dwSavedState[ SAVEDSTATE_D3DSAMP_MINFILTER ] ); - pD3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, m_dwSavedState[ SAVEDSTATE_D3DSAMP_MAGFILTER ] ); - pD3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSU ] ); - pD3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSV ] ); - } + xdk360_video_font_end(font); } \ No newline at end of file diff --git a/360/xdk360_video_debugfonts.h b/360/xdk360_video_debugfonts.h index 2aeeab4743..b9a9f0207d 100644 --- a/360/xdk360_video_debugfonts.h +++ b/360/xdk360_video_debugfonts.h @@ -52,67 +52,35 @@ enum SavedStates SAVEDSTATE_COUNT }; -class XdkFont +typedef struct { -public: - PackedResource m_xprResource; - - // Font vertical dimensions taken from the font file + unsigned int m_bSaveState; + unsigned long m_dwSavedState[ SAVEDSTATE_COUNT ]; + unsigned long m_dwNestedBeginCount; + unsigned long m_cMaxGlyph; // Number of entries in the translator table + unsigned long m_dwNumGlyphs; // Number of valid glyphs float m_fFontHeight; // Height of the font strike in pixels float m_fFontTopPadding; // Padding above the strike zone float m_fFontBottomPadding; // Padding below the strike zone float m_fFontYAdvance; // Number of pixels to move the cursor for a line feed - float m_fXScaleFactor; // Scaling constants float m_fYScaleFactor; - - D3DRECT m_rcWindow; // Bounds rect of the text window, modify via accessors only! - float m_fCursorX; // Current text cursor + float m_fCursorX; // Current text cursor float m_fCursorY; + D3DRECT m_rcWindow; // Bounds rect of the text window, modify via accessors only! + wchar_t * m_TranslatorTable; // ASCII to glyph lookup table + D3DTexture* m_pFontTexture; + const GLYPH_ATTR* m_Glyphs; // Array of glyphs +} xdk360_video_font_t; - // Translator table for supporting unicode ranges - unsigned long m_cMaxGlyph; // Number of entries in the translator table - wchar_t * m_TranslatorTable; // ASCII to glyph lookup table - - // Glyph data for the font - unsigned long m_dwNumGlyphs; // Number of valid glyphs - const GLYPH_ATTR* m_Glyphs; // Array of glyphs - - // D3D rendering objects - D3DTexture* m_pFontTexture; - - // Saved state for rendering (if not using a pure device) - unsigned long m_dwSavedState[ SAVEDSTATE_COUNT ]; - unsigned long m_dwNestedBeginCount; - int m_bSaveState; -public: - XdkFont(); - ~XdkFont(); - - // Functions to create and destroy the internal objects - HRESULT Create( const char * strFontFileName ); - void Destroy(); - - // Returns the dimensions of a text string - void GetTextExtent( const wchar_t * strText, float * pWidth, - float * pHeight, int bFirstLineOnly=FALSE ) const; - float GetTextWidth( const wchar_t * strText ) const; - void SetCursorPosition( float fCursorX, float fCursorY ); - void SetFontSize(float x, float y); - - // Public calls to render text. Callers can simply call DrawText(), but for - // performance, they should batch multiple calls together, bracketed by calls to - // Begin() and End(). - void Begin(); - void DrawText( unsigned long dwColor, const wchar_t * strText, - float fMaxPixelWidth = 0.0f ); - void DrawText( float sx, float sy, unsigned long dwColor, - const wchar_t * strText, float fMaxPixelWidth = 0.0f ); - void End(); - -private: - // Internal helper functions - HRESULT CreateFontShaders(); -}; +HRESULT xdk360_video_font_init(xdk360_video_font_t * font, const char * strFontFileName); +void xdk360_video_font_get_text_width(xdk360_video_font_t * font, const wchar_t * strText, float * pWidth, float * pHeight, int bFirstLineOnly); +void xdk360_video_font_deinit(xdk360_video_font_t * font); +void xdk360_video_font_set_cursor_position(xdk360_video_font_t *font, float fCursorX, float fCursorY ); +void xdk360_video_font_begin (xdk360_video_font_t * font); +void xdk360_video_font_end (xdk360_video_font_t * font); +void xdk360_video_font_set_size(float x, float y); +void xdk360_video_font_draw_text(xdk360_video_font_t * font, float fOriginX, float fOriginY, unsigned long dwColor, + const wchar_t * strText, float fMaxPixelWidth ); #endif \ No newline at end of file From f9ab3711eb5c72302c79197f388e6666e2b5577e Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 22:34:19 +0100 Subject: [PATCH 09/15] (360) Remove some comments --- 360/xdk360_video_debugfonts.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/360/xdk360_video_debugfonts.cpp b/360/xdk360_video_debugfonts.cpp index 3ba71fac5e..b16b83a745 100644 --- a/360/xdk360_video_debugfonts.cpp +++ b/360/xdk360_video_debugfonts.cpp @@ -46,11 +46,6 @@ typedef struct FontFileStrikesImage_t { static PackedResource m_xprResource; -//-------------------------------------------------------------------------------------- -// Vertex and pixel shaders for font rendering -// Please note the removal of comment or dead lines... -// They are commented out because the shader compiler has no use for them. -//-------------------------------------------------------------------------------------- static const char g_strFontShader[] = "struct VS_IN\n" "{\n" @@ -487,10 +482,6 @@ void xdk360_video_font_begin (xdk360_video_font_t * font) font->m_dwNestedBeginCount++; } -//-------------------------------------------------------------------------------------- -// Name: End() -// Desc: Paired call that restores state set in the Begin() call. -//-------------------------------------------------------------------------------------- void xdk360_video_font_end(xdk360_video_font_t * font) { if( --font->m_dwNestedBeginCount > 0 ) @@ -526,12 +517,6 @@ void xdk360_video_font_end(xdk360_video_font_t * font) } } -//-------------------------------------------------------------------------------------- -// Name: DrawText() -// Desc: Draws text as textured polygons -// TODO: This function should use the Begin/SetVertexData/End() API when it -// becomes available. -//-------------------------------------------------------------------------------------- void xdk360_video_font_draw_text(xdk360_video_font_t * font, float fOriginX, float fOriginY, unsigned long dwColor, const wchar_t * strText, float fMaxPixelWidth ) { From 8e8f56b5e851728cd417b9ae032fdacf1aacc91a Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Fri, 17 Feb 2012 19:35:51 +0100 Subject: [PATCH 10/15] (360) Combined console and font code into one file --- ...{xdk360_video_debugfonts.cpp => fonts.cpp} | 247 ++++++++++++++++-- 360/{xdk360_video_debugfonts.h => fonts.h} | 41 ++- 360/xdk360_video.h | 2 +- 360/xdk360_video_console.cpp | 242 ----------------- 360/xdk360_video_console.h | 61 ----- 360/xdk360_video_resources.cpp | 5 +- msvc-360/SSNES-360/SSNES-360.vcxproj | 3 +- msvc-360/SSNES-360/SSNES-360.vcxproj.filters | 5 +- 8 files changed, 263 insertions(+), 343 deletions(-) rename 360/{xdk360_video_debugfonts.cpp => fonts.cpp} (78%) rename 360/{xdk360_video_debugfonts.h => fonts.h} (71%) delete mode 100644 360/xdk360_video_console.cpp delete mode 100644 360/xdk360_video_console.h diff --git a/360/xdk360_video_debugfonts.cpp b/360/fonts.cpp similarity index 78% rename from 360/xdk360_video_debugfonts.cpp rename to 360/fonts.cpp index b16b83a745..d307894534 100644 --- a/360/xdk360_video_debugfonts.cpp +++ b/360/fonts.cpp @@ -17,11 +17,229 @@ */ #include -#include +#include #include "xdk360_video.h" -#include "xdk360_video_debugfonts.h" +#include "fonts.h" #include "../general.h" +static video_console_t video_console; +static xdk360_video_font_t m_Font; + +void xdk360_console_draw(void) +{ + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + D3DDevice *m_pd3dDevice = vid->xdk360_render_device; + + // The top line + unsigned int nTextLine = ( video_console.m_nCurLine - + video_console.m_cScreenHeight + video_console.m_cScreenHeightVirtual - + video_console.m_nScrollOffset + 1 ) + % video_console.m_cScreenHeightVirtual; + + xdk360_video_font_begin(&m_Font); + + for( unsigned int nScreenLine = 0; nScreenLine < video_console.m_cScreenHeight; nScreenLine++ ) + { + xdk360_video_font_draw_text(&m_Font, (float)( video_console.m_cxSafeAreaOffset ), + (float)( video_console.m_cySafeAreaOffset + + video_console.m_fLineHeight * nScreenLine ), + video_console.m_colTextColor, + video_console.m_Lines[nTextLine], 0.0f ); + + nTextLine = ( nTextLine + 1 ) % video_console.m_cScreenHeightVirtual; + } + + xdk360_video_font_end(&m_Font); +} + +HRESULT xdk360_console_init( LPCSTR strFontFileName, unsigned long colBackColor, + unsigned long colTextColor) +{ + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + D3DDevice *m_pd3dDevice = vid->xdk360_render_device; + + video_console.first_message = true; + video_console.m_Buffer = NULL; + video_console.m_Lines = NULL; + video_console.m_nScrollOffset = 0; + + // Calculate the safe area + unsigned int uiSafeAreaPct = vid->video_mode.fIsHiDef ? SAFE_AREA_PCT_HDTV + : SAFE_AREA_PCT_4x3; + + video_console.m_cxSafeArea = ( vid->d3dpp.BackBufferWidth * uiSafeAreaPct ) / 100; + video_console.m_cySafeArea = ( vid->d3dpp.BackBufferHeight * uiSafeAreaPct ) / 100; + + video_console.m_cxSafeAreaOffset = ( vid->d3dpp.BackBufferWidth - video_console.m_cxSafeArea ) / 2; + video_console.m_cySafeAreaOffset = ( vid->d3dpp.BackBufferHeight - video_console.m_cySafeArea ) / 2; + + // Create the font + HRESULT hr = xdk360_video_font_init(&m_Font, strFontFileName ); + if( FAILED( hr ) ) + { + SSNES_ERR( "Could not create font.\n" ); + return -1; + } + + // Save the colors + video_console.m_colBackColor = colBackColor; + video_console.m_colTextColor = colTextColor; + + // Calculate the number of lines on the screen + float fCharWidth, fCharHeight; + xdk360_video_font_get_text_width(&m_Font, L"i", &fCharWidth, &fCharHeight, FALSE); + + video_console.m_cScreenHeight = (unsigned int)( video_console.m_cySafeArea / fCharHeight ); + video_console.m_cScreenWidth = (unsigned int)( video_console.m_cxSafeArea / fCharWidth ); + + video_console.m_cScreenHeightVirtual = video_console.m_cScreenHeight; + + video_console.m_fLineHeight = fCharHeight; + + // Allocate memory to hold the lines + video_console.m_Buffer = new wchar_t[ video_console.m_cScreenHeightVirtual * ( video_console.m_cScreenWidth + 1 ) ]; + video_console.m_Lines = new wchar_t *[ video_console.m_cScreenHeightVirtual ]; + + // Set the line pointers as indexes into the buffer + for( unsigned int i = 0; i < video_console.m_cScreenHeightVirtual; i++ ) + video_console.m_Lines[ i ] = video_console.m_Buffer + ( video_console.m_cScreenWidth + 1 ) * i; + + video_console.m_nCurLine = 0; + video_console.m_cCurLineLength = 0; + memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual * ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + xdk360_console_draw(); + + return hr; +} + +void xdk360_console_deinit() +{ + // Delete the memory we've allocated + if(video_console.m_Lines) + { + delete[] video_console.m_Lines; + video_console.m_Lines = NULL; + } + + if(video_console.m_Buffer) + { + delete[] video_console.m_Buffer; + video_console.m_Buffer = NULL; + } + + // Destroy the font + xdk360_video_font_deinit(&m_Font); +} + +void xdk360_console_add( wchar_t wch ) +{ + // If this is a newline, just increment lines and move on + if( wch == L'\n' ) + { + video_console.m_nCurLine = ( video_console.m_nCurLine + 1 ) + % video_console.m_cScreenHeightVirtual; + video_console.m_cCurLineLength = 0; + memset(video_console.m_Lines[video_console.m_nCurLine], 0, + ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + return; + } + + int bIncrementLine = FALSE; // Whether to wrap to the next line + + if( video_console.m_cCurLineLength == video_console.m_cScreenWidth ) + bIncrementLine = TRUE; + else + { + // Try to append the character to the line + video_console.m_Lines[ video_console.m_nCurLine ] + [ video_console.m_cCurLineLength ] = wch; + + float fTextWidth, fTextHeight; + xdk360_video_font_get_text_width(&m_Font, video_console.m_Lines[ video_console.m_nCurLine ], &fTextWidth, &fTextHeight, 0); + if( fTextHeight > video_console.m_cxSafeArea ) + { + // The line is too long, we need to wrap the character to the next line + video_console.m_Lines[video_console.m_nCurLine] + [ video_console.m_cCurLineLength ] = L'\0'; + bIncrementLine = TRUE; + } + } + + // If we need to skip to the next line, do so + if( bIncrementLine ) + { + video_console.m_nCurLine = ( video_console.m_nCurLine + 1 ) + % video_console.m_cScreenHeightVirtual; + video_console.m_cCurLineLength = 0; + memset( video_console.m_Lines[video_console.m_nCurLine], + 0, ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + video_console.m_Lines[video_console.m_nCurLine ][0] = wch; + } + + video_console.m_cCurLineLength++; +} + +void xdk360_console_format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) +{ + video_console.m_nCurLine = 0; + video_console.m_cCurLineLength = 0; + memset( video_console.m_Buffer, 0, + video_console.m_cScreenHeightVirtual * + ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + + va_list pArgList; + va_start( pArgList, strFormat ); + + // Count the required length of the string + unsigned long dwStrLen = _vscprintf( strFormat, pArgList ) + 1; + // +1 = null terminator + char * strMessage = ( char * )_malloca( dwStrLen ); + vsprintf_s( strMessage, dwStrLen, strFormat, pArgList ); + + // Output the string to the console + unsigned long uStringLength = strlen( strMessage ); + for( unsigned long i = 0; i < uStringLength; i++ ) + { + wchar_t wch; + int ret = MultiByteToWideChar( CP_ACP, // ANSI code page + 0, // No flags + &strMessage[i], // Character to convert + 1, // Convert one byte + &wch, // Target wide character buffer + 1 ); // One wide character + xdk360_console_add( wch ); + } + + _freea( strMessage ); + + va_end( pArgList ); +} + +void xdk360_console_format_w(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) +{ + video_console.m_nCurLine = 0; + video_console.m_cCurLineLength = 0; + memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual + * ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + + va_list pArgList; + va_start( pArgList, wstrFormat ); + + // Count the required length of the string + unsigned long dwStrLen = _vscwprintf( wstrFormat, pArgList ) + 1; // +1 = null terminator + wchar_t * strMessage = ( wchar_t * )_malloca( dwStrLen * sizeof( wchar_t ) ); + vswprintf_s( strMessage, dwStrLen, wstrFormat, pArgList ); + + // Output the string to the console + unsigned long uStringLength = wcslen( strMessage ); + for( unsigned long i = 0; i < uStringLength; i++ ) + xdk360_console_add( strMessage[i] ); + + _freea( strMessage ); + + va_end( pArgList ); +} + #define CALCFONTFILEHEADERSIZE(x) ( sizeof(unsigned long) + (sizeof(float)* 4) + sizeof(unsigned short) + (sizeof(wchar_t)*(x)) ) #define FONTFILEVERSION 5 @@ -53,7 +271,6 @@ static const char g_strFontShader[] = "float2 Tex : TEXCOORD0;\n" "float4 ChannelSelector : TEXCOORD1;\n" "};\n" -// "\n" "struct VS_OUT\n" "{\n" "float4 Position : POSITION;\n" @@ -61,12 +278,9 @@ static const char g_strFontShader[] = "float2 TexCoord0 : TEXCOORD0;\n" "float4 ChannelSelector : TEXCOORD1;\n" "};\n" -// "\n" "uniform float4 Color : register(c1);\n" "uniform float2 TexScale : register(c2);\n" -// "\n" "sampler FontTexture : register(s0);\n" -// "\n" "VS_OUT FontVertexShader( VS_IN In )\n" "{\n" "VS_OUT Out;\n" @@ -80,36 +294,15 @@ static const char g_strFontShader[] = "Out.ChannelSelector = In.ChannelSelector;\n" "return Out;\n" "}\n" - // "\n" "float4 FontPixelShader( VS_OUT In ) : COLOR0\n" "{\n" -// "// Fetch a texel from the font texture\n" "float4 FontTexel = tex2D( FontTexture, In.TexCoord0 );\n" -// "\n" "if( dot( In.ChannelSelector, float4(1,1,1,1) ) )\n" "{\n" -// "// Select the color from the channel\n" "float value = dot( FontTexel, In.ChannelSelector );\n" -// "\n" -// "// For white pixels, the high bit is 1 and the low\n" -// "// bits are luminance, so r0.a will be > 0.5. For the\n" -// "// RGB channel, we want to lop off the msb and shift\n" -// "// the lower bits up one bit. This is simple to do\n" -// "// with the _bx2 modifier. Since these pixels are\n" -// "// opaque, we emit a 1 for the alpha channel (which\n" -// "// is 0.5 x2 ).\n" -// "\n" -// "// For black pixels, the high bit is 0 and the low\n" -// "// bits are alpha, so r0.a will be < 0.5. For the RGB\n" -// "// channel, we emit zero. For the alpha channel, we\n" -// "// just use the x2 modifier to scale up the low bits\n" -// "// of the alpha.\n" "float4 Color;\n" "Color.rgb = ( value > 0.5f ? 2*value-1 : 0.0f );\n" "Color.a = 2 * ( value > 0.5f ? 1.0f : value );\n" -// "\n" -// "// Return the texture color modulated with the vertex\n" -// "// color\n" "return Color * In.Diffuse;\n" "}\n" "else\n" diff --git a/360/xdk360_video_debugfonts.h b/360/fonts.h similarity index 71% rename from 360/xdk360_video_debugfonts.h rename to 360/fonts.h index b9a9f0207d..c4f1e7b780 100644 --- a/360/xdk360_video_debugfonts.h +++ b/360/fonts.h @@ -16,11 +16,40 @@ * If not, see . */ -#ifndef _SSNES360_DEBUG_FONTS_H -#define _SSNES360_DEBUG_FONTS_H +#ifndef SSNES_360_FONTS_H +#define SSNES_360_FONTS_H #include "xdk360_video_resources.h" +#define PAGE_UP (255) +#define PAGE_DOWN (-255) + +#define SCREEN_SIZE_X_DEFAULT 640 +#define SCREEN_SIZE_Y_DEFAULT 480 + +#define SAFE_AREA_PCT_4x3 85 +#define SAFE_AREA_PCT_HDTV 90 + +typedef struct +{ + float m_fLineHeight; // height of a single line in pixels + unsigned int m_nScrollOffset; // offset to display text (in lines) + unsigned int first_message; + unsigned int m_cxSafeArea; + unsigned int m_cySafeArea; + unsigned int m_cxSafeAreaOffset; + unsigned int m_cySafeAreaOffset; + unsigned int m_nCurLine; // index of current line being written to + unsigned int m_cCurLineLength; // length of the current line + unsigned long m_colBackColor; + unsigned long m_colTextColor; + unsigned int m_cScreenHeight; // height in lines of screen area + unsigned int m_cScreenHeightVirtual; // height in lines of text storage buffer + unsigned int m_cScreenWidth; // width in characters + wchar_t * m_Buffer; // buffer big enough to hold a full screen + wchar_t ** m_Lines; // pointers to individual lines +} video_console_t; + typedef struct GLYPH_ATTR { unsigned short tu1, tv1, tu2, tv2; // Texture coordinates for the image @@ -73,6 +102,12 @@ typedef struct const GLYPH_ATTR* m_Glyphs; // Array of glyphs } xdk360_video_font_t; +HRESULT xdk360_console_init ( LPCSTR strFontFileName, D3DCOLOR colBackColor, D3DCOLOR colTextColor); +void xdk360_console_deinit (void); +void xdk360_console_format (_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ); +void xdk360_console_format_w (_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); +void xdk360_console_draw (void); + HRESULT xdk360_video_font_init(xdk360_video_font_t * font, const char * strFontFileName); void xdk360_video_font_get_text_width(xdk360_video_font_t * font, const wchar_t * strText, float * pWidth, float * pHeight, int bFirstLineOnly); void xdk360_video_font_deinit(xdk360_video_font_t * font); @@ -83,4 +118,4 @@ void xdk360_video_font_set_size(float x, float y); void xdk360_video_font_draw_text(xdk360_video_font_t * font, float fOriginX, float fOriginY, unsigned long dwColor, const wchar_t * strText, float fMaxPixelWidth ); -#endif \ No newline at end of file +#endif diff --git a/360/xdk360_video.h b/360/xdk360_video.h index af4857f809..89af5bb764 100644 --- a/360/xdk360_video.h +++ b/360/xdk360_video.h @@ -19,7 +19,7 @@ #ifndef _XDK360_VIDEO_H #define _XDK360_VIDEO_H -#include "xdk360_video_console.h" +#include "fonts.h" typedef struct { float x; diff --git a/360/xdk360_video_console.cpp b/360/xdk360_video_console.cpp deleted file mode 100644 index c7e797b2da..0000000000 --- a/360/xdk360_video_console.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. - * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * Copyright (C) 2011-2012 - Daniel De Matteis - * - * Some code herein may be based on code found in BSNES. - * - * SSNES is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with SSNES. - * If not, see . - */ - -#include -#include -#include "xdk360_video.h" -#include "xdk360_video_console.h" -#include "xdk360_video_debugfonts.h" -#include "../general.h" - -static video_console_t video_console; -static xdk360_video_font_t m_Font; - -void xdk360_console_draw(void) -{ - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *m_pd3dDevice = vid->xdk360_render_device; - - // The top line - unsigned int nTextLine = ( video_console.m_nCurLine - - video_console.m_cScreenHeight + video_console.m_cScreenHeightVirtual - - video_console.m_nScrollOffset + 1 ) - % video_console.m_cScreenHeightVirtual; - - xdk360_video_font_begin(&m_Font); - - for( unsigned int nScreenLine = 0; nScreenLine < video_console.m_cScreenHeight; nScreenLine++ ) - { - xdk360_video_font_draw_text(&m_Font, (float)( video_console.m_cxSafeAreaOffset ), - (float)( video_console.m_cySafeAreaOffset + - video_console.m_fLineHeight * nScreenLine ), - video_console.m_colTextColor, - video_console.m_Lines[nTextLine], 0.0f ); - - nTextLine = ( nTextLine + 1 ) % video_console.m_cScreenHeightVirtual; - } - - xdk360_video_font_end(&m_Font); -} - -HRESULT xdk360_console_init( LPCSTR strFontFileName, unsigned long colBackColor, - unsigned long colTextColor) -{ - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *m_pd3dDevice = vid->xdk360_render_device; - - video_console.first_message = true; - video_console.m_Buffer = NULL; - video_console.m_Lines = NULL; - video_console.m_nScrollOffset = 0; - - // Calculate the safe area - unsigned int uiSafeAreaPct = vid->video_mode.fIsHiDef ? SAFE_AREA_PCT_HDTV - : SAFE_AREA_PCT_4x3; - - video_console.m_cxSafeArea = ( vid->d3dpp.BackBufferWidth * uiSafeAreaPct ) / 100; - video_console.m_cySafeArea = ( vid->d3dpp.BackBufferHeight * uiSafeAreaPct ) / 100; - - video_console.m_cxSafeAreaOffset = ( vid->d3dpp.BackBufferWidth - video_console.m_cxSafeArea ) / 2; - video_console.m_cySafeAreaOffset = ( vid->d3dpp.BackBufferHeight - video_console.m_cySafeArea ) / 2; - - // Create the font - HRESULT hr = xdk360_video_font_init(&m_Font, strFontFileName ); - if( FAILED( hr ) ) - { - SSNES_ERR( "Could not create font.\n" ); - return -1; - } - - // Save the colors - video_console.m_colBackColor = colBackColor; - video_console.m_colTextColor = colTextColor; - - // Calculate the number of lines on the screen - float fCharWidth, fCharHeight; - xdk360_video_font_get_text_width(&m_Font, L"i", &fCharWidth, &fCharHeight, FALSE); - - video_console.m_cScreenHeight = (unsigned int)( video_console.m_cySafeArea / fCharHeight ); - video_console.m_cScreenWidth = (unsigned int)( video_console.m_cxSafeArea / fCharWidth ); - - video_console.m_cScreenHeightVirtual = video_console.m_cScreenHeight; - - video_console.m_fLineHeight = fCharHeight; - - // Allocate memory to hold the lines - video_console.m_Buffer = new wchar_t[ video_console.m_cScreenHeightVirtual * ( video_console.m_cScreenWidth + 1 ) ]; - video_console.m_Lines = new wchar_t *[ video_console.m_cScreenHeightVirtual ]; - - // Set the line pointers as indexes into the buffer - for( unsigned int i = 0; i < video_console.m_cScreenHeightVirtual; i++ ) - video_console.m_Lines[ i ] = video_console.m_Buffer + ( video_console.m_cScreenWidth + 1 ) * i; - - video_console.m_nCurLine = 0; - video_console.m_cCurLineLength = 0; - memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual * ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - xdk360_console_draw(); - - return hr; -} - -void xdk360_console_deinit() -{ - // Delete the memory we've allocated - if(video_console.m_Lines) - { - delete[] video_console.m_Lines; - video_console.m_Lines = NULL; - } - - if(video_console.m_Buffer) - { - delete[] video_console.m_Buffer; - video_console.m_Buffer = NULL; - } - - // Destroy the font - xdk360_video_font_deinit(&m_Font); -} - -void xdk360_console_add( wchar_t wch ) -{ - // If this is a newline, just increment lines and move on - if( wch == L'\n' ) - { - video_console.m_nCurLine = ( video_console.m_nCurLine + 1 ) - % video_console.m_cScreenHeightVirtual; - video_console.m_cCurLineLength = 0; - memset(video_console.m_Lines[video_console.m_nCurLine], 0, - ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - return; - } - - int bIncrementLine = FALSE; // Whether to wrap to the next line - - if( video_console.m_cCurLineLength == video_console.m_cScreenWidth ) - bIncrementLine = TRUE; - else - { - // Try to append the character to the line - video_console.m_Lines[ video_console.m_nCurLine ] - [ video_console.m_cCurLineLength ] = wch; - - float fTextWidth, fTextHeight; - xdk360_video_font_get_text_width(&m_Font, video_console.m_Lines[ video_console.m_nCurLine ], &fTextWidth, &fTextHeight, 0); - if( fTextHeight > video_console.m_cxSafeArea ) - { - // The line is too long, we need to wrap the character to the next line - video_console.m_Lines[video_console.m_nCurLine] - [ video_console.m_cCurLineLength ] = L'\0'; - bIncrementLine = TRUE; - } - } - - // If we need to skip to the next line, do so - if( bIncrementLine ) - { - video_console.m_nCurLine = ( video_console.m_nCurLine + 1 ) - % video_console.m_cScreenHeightVirtual; - video_console.m_cCurLineLength = 0; - memset( video_console.m_Lines[video_console.m_nCurLine], - 0, ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - video_console.m_Lines[video_console.m_nCurLine ][0] = wch; - } - - video_console.m_cCurLineLength++; -} - -void xdk360_console_format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) -{ - video_console.m_nCurLine = 0; - video_console.m_cCurLineLength = 0; - memset( video_console.m_Buffer, 0, - video_console.m_cScreenHeightVirtual * - ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - - va_list pArgList; - va_start( pArgList, strFormat ); - - // Count the required length of the string - unsigned long dwStrLen = _vscprintf( strFormat, pArgList ) + 1; - // +1 = null terminator - char * strMessage = ( char * )_malloca( dwStrLen ); - vsprintf_s( strMessage, dwStrLen, strFormat, pArgList ); - - // Output the string to the console - unsigned long uStringLength = strlen( strMessage ); - for( unsigned long i = 0; i < uStringLength; i++ ) - { - wchar_t wch; - int ret = MultiByteToWideChar( CP_ACP, // ANSI code page - 0, // No flags - &strMessage[i], // Character to convert - 1, // Convert one byte - &wch, // Target wide character buffer - 1 ); // One wide character - xdk360_console_add( wch ); - } - - _freea( strMessage ); - - va_end( pArgList ); -} - -void xdk360_console_format_w(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) -{ - video_console.m_nCurLine = 0; - video_console.m_cCurLineLength = 0; - memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual - * ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - - va_list pArgList; - va_start( pArgList, wstrFormat ); - - // Count the required length of the string - unsigned long dwStrLen = _vscwprintf( wstrFormat, pArgList ) + 1; // +1 = null terminator - wchar_t * strMessage = ( wchar_t * )_malloca( dwStrLen * sizeof( wchar_t ) ); - vswprintf_s( strMessage, dwStrLen, wstrFormat, pArgList ); - - // Output the string to the console - unsigned long uStringLength = wcslen( strMessage ); - for( unsigned long i = 0; i < uStringLength; i++ ) - xdk360_console_add( strMessage[i] ); - - _freea( strMessage ); - - va_end( pArgList ); -} \ No newline at end of file diff --git a/360/xdk360_video_console.h b/360/xdk360_video_console.h deleted file mode 100644 index d3173f740b..0000000000 --- a/360/xdk360_video_console.h +++ /dev/null @@ -1,61 +0,0 @@ -/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. - * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * Copyright (C) 2011-2012 - Daniel De Matteis - * - * Some code herein may be based on code found in BSNES. - * - * SSNES is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with SSNES. - * If not, see . - */ - -#pragma once -#ifndef SSNES360_CONSOLE_H -#define SSNES360_CONSOLE_H - -#include -#include "xdk360_video_debugfonts.h" - -#define PAGE_UP (255) -#define PAGE_DOWN (-255) - -#define SCREEN_SIZE_X_DEFAULT 640 -#define SCREEN_SIZE_Y_DEFAULT 480 - -#define SAFE_AREA_PCT_4x3 85 -#define SAFE_AREA_PCT_HDTV 90 - -typedef struct -{ - float m_fLineHeight; // height of a single line in pixels - unsigned int m_nScrollOffset; // offset to display text (in lines) - unsigned int first_message; - unsigned int m_cxSafeArea; - unsigned int m_cySafeArea; - unsigned int m_cxSafeAreaOffset; - unsigned int m_cySafeAreaOffset; - unsigned int m_nCurLine; // index of current line being written to - unsigned int m_cCurLineLength; // length of the current line - unsigned long m_colBackColor; - unsigned long m_colTextColor; - unsigned int m_cScreenHeight; // height in lines of screen area - unsigned int m_cScreenHeightVirtual; // height in lines of text storage buffer - unsigned int m_cScreenWidth; // width in characters - wchar_t * m_Buffer; // buffer big enough to hold a full screen - wchar_t ** m_Lines; // pointers to individual lines -} video_console_t; - -HRESULT xdk360_console_init ( LPCSTR strFontFileName, D3DCOLOR colBackColor, D3DCOLOR colTextColor); -void xdk360_console_deinit (void); -void xdk360_console_format (_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ); -void xdk360_console_format_w (_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); -void xdk360_console_draw (void); - -#endif diff --git a/360/xdk360_video_resources.cpp b/360/xdk360_video_resources.cpp index e65b098ab9..e518caab08 100644 --- a/360/xdk360_video_resources.cpp +++ b/360/xdk360_video_resources.cpp @@ -33,7 +33,6 @@ struct XPR_HEADER }; #define XPR2_MAGIC_VALUE (0x58505232) -#define eXALLOCAllocatorId_AtgResource eXALLOCAllocatorId_GameMax //-------------------------------------------------------------------------------------- // Name: PackedResource @@ -120,7 +119,7 @@ HRESULT PackedResource::Create( const char * strFilename ) m_dwSysMemDataSize = 0; return E_FAIL; } - m_pVidMemData = ( BYTE* )XMemAlloc( m_dwVidMemDataSize, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_AtgResource, + m_pVidMemData = ( BYTE* )XMemAlloc( m_dwVidMemDataSize, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_GameMax, XALLOC_PHYSICAL_ALIGNMENT_4K, XALLOC_MEMPROTECT_WRITECOMBINE, 0, XALLOC_MEMTYPE_PHYSICAL ) ); if( m_pVidMemData == NULL ) @@ -179,7 +178,7 @@ void PackedResource::Destroy() m_dwSysMemDataSize = 0L; if( m_pVidMemData != NULL ) - XMemFree( m_pVidMemData, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_AtgResource, + XMemFree( m_pVidMemData, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_GameMax, 0, 0, 0, XALLOC_MEMTYPE_PHYSICAL ) ); m_pVidMemData = NULL; diff --git a/msvc-360/SSNES-360/SSNES-360.vcxproj b/msvc-360/SSNES-360/SSNES-360.vcxproj index 7e325822d7..d78cfd81a6 100644 --- a/msvc-360/SSNES-360/SSNES-360.vcxproj +++ b/msvc-360/SSNES-360/SSNES-360.vcxproj @@ -283,13 +283,12 @@ + - - diff --git a/msvc-360/SSNES-360/SSNES-360.vcxproj.filters b/msvc-360/SSNES-360/SSNES-360.vcxproj.filters index 3ac3d35f3b..16aa724cae 100644 --- a/msvc-360/SSNES-360/SSNES-360.vcxproj.filters +++ b/msvc-360/SSNES-360/SSNES-360.vcxproj.filters @@ -131,13 +131,10 @@ Source Files\console - - Source Files\360 - Source Files\360 - + Source Files\360 From 471dfcd478f4ba74c86bac10fe4ee1b4e1f87450 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Fri, 17 Feb 2012 21:28:23 +0100 Subject: [PATCH 11/15] (360) Filebrowser can now load ROMs from subdir --- 360/file_browser.c | 29 +++++++++++++++++++++++++++++ 360/file_browser.h | 14 ++++++++++++-- 360/menu.cpp | 13 ++++++++----- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/360/file_browser.c b/360/file_browser.c index 716a9c4c47..baae8e60ba 100644 --- a/360/file_browser.c +++ b/360/file_browser.c @@ -30,6 +30,16 @@ static const char * filebrowser_get_extension(const char * filename) return ""; } +static void filebrowser_clear_current_entries(filebrowser_t * filebrowser) +{ + for(uint32_t i = 0; i < MAX_FILE_LIMIT; i++) + { + filebrowser->cur[filebrowser->file_count].d_type = 0; + filebrowser->cur[filebrowser->file_count].d_namlen = 0; + strcpy(filebrowser->cur[filebrowser->file_count].d_name, "\0"); + } +} + void filebrowser_parse_directory(filebrowser_t * filebrowser, const char * path, const char *extensions) { int error = FALSE; @@ -60,6 +70,7 @@ void filebrowser_parse_directory(filebrowser_t * filebrowser, const char * path, do { + strcpy(filebrowser->dir[filebrowser->directory_stack_size], path); bool found_dir = false; if(!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { @@ -100,4 +111,22 @@ error: SSNES_ERR("Failed to open directory: \"%s\"\n", path); } FindClose(hFind); +} + +void filebrowser_new(filebrowser_t * filebrowser, const char * start_dir, const char * extensions) +{ + filebrowser_clear_current_entries(filebrowser); + filebrowser->directory_stack_size = 0; + strcpy(filebrowser->extensions, extensions); + + filebrowser_parse_directory(filebrowser, start_dir, filebrowser->extensions); +} + +void filebrowser_push_directory(filebrowser_t * filebrowser, const char * path, bool with_extension) +{ + filebrowser->directory_stack_size++; + if(with_extension) + filebrowser_parse_directory(filebrowser, path, filebrowser->extensions); + else + filebrowser_parse_directory(filebrowser, path, "empty"); } \ No newline at end of file diff --git a/360/file_browser.h b/360/file_browser.h index 70f251c5e3..6d3afcd6d2 100644 --- a/360/file_browser.h +++ b/360/file_browser.h @@ -16,18 +16,28 @@ * If not, see . */ +#include + #define FATX_MAX_FILE_LIMIT 4096 +#define MAX_FILE_LIMIT FATX_MAX_FILE_LIMIT typedef struct { unsigned d_type; + unsigned d_namlen; CHAR d_name[MAX_PATH]; } DirectoryEntry; typedef struct { unsigned file_count; // amount of files in current directory unsigned currently_selected; // currently selected browser entry - DirectoryEntry cur[FATX_MAX_FILE_LIMIT]; // current file listing + uint32_t directory_stack_size; + char dir[128][2048]; /* info on the current directory */ + DirectoryEntry cur[MAX_FILE_LIMIT]; // current file listing char extensions[512]; // allowed file extensions } filebrowser_t; -void filebrowser_parse_directory(filebrowser_t * filebrowser, const char * path, const char *extensions); \ No newline at end of file +void filebrowser_new(filebrowser_t * filebrowser, const char * start_dir, const char * extensions); +void filebrowser_parse_directory(filebrowser_t * filebrowser, const char * path, const char *extensions); +void filebrowser_push_directory(filebrowser_t * filebrowser, const char * path, bool with_extension); + +#define FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(filebrowser) (filebrowser.dir[filebrowser.directory_stack_size]) \ No newline at end of file diff --git a/360/menu.cpp b/360/menu.cpp index 023d588932..7fdde89560 100644 --- a/360/menu.cpp +++ b/360/menu.cpp @@ -69,7 +69,7 @@ HRESULT CSSNES::UnregisterXuiClasses (void) static void filebrowser_fetch_directory_entries(const char *path, CXuiList * romlist, CXuiTextElement * rompath_title) { - filebrowser_parse_directory(&browser, path, ssnes_console_get_rom_ext()); + filebrowser_push_directory(&browser, path, true); unsigned long dwNum_rompath = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0); wchar_t * rompath_name = new wchar_t[dwNum_rompath]; @@ -232,6 +232,8 @@ HRESULT CSSNESMain::OnInit(XUIMessageInit * pInitData, BOOL& bHandled) HRESULT CSSNESFileBrowser::OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandled ) { + char path[MAX_PATH_LENGTH]; + if(hObjPressed == m_romlist) { int index = m_romlist.GetCurSel(); @@ -240,7 +242,7 @@ HRESULT CSSNESFileBrowser::OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandled ) memset(strbuffer, 0, sizeof(strbuffer)); wcstombs(strbuffer, (const wchar_t *)m_romlist.GetText(index), sizeof(strbuffer)); memset(g_console.rom_path, 0, sizeof(g_console.rom_path)); - sprintf(g_console.rom_path, "%s%s", g_console.default_rom_startup_dir, strbuffer); + sprintf(g_console.rom_path, "%s%s", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(browser), strbuffer); return_to_game(); g_console.initialize_ssnes_enable = 1; @@ -249,9 +251,8 @@ HRESULT CSSNESFileBrowser::OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandled ) { memset(strbuffer, 0, sizeof(strbuffer)); wcstombs(strbuffer, (const wchar_t *)m_romlist.GetText(index), sizeof(strbuffer)); - char strbuf[512]; - snprintf(strbuf, sizeof(strbuf), "%s%s", g_console.default_rom_startup_dir, strbuffer); - filebrowser_fetch_directory_entries(strbuf, &m_romlist, &m_rompathtitle); + snprintf(path, sizeof(path), "%s%s\\", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(browser), strbuffer); + filebrowser_fetch_directory_entries(path, &m_romlist, &m_rompathtitle); } } else if(hObjPressed == m_back) @@ -358,6 +359,8 @@ int menu_init (void) XuiSceneNavigateFirst(app.GetRootObj(), app.hMainScene, XUSER_INDEX_FOCUS); + filebrowser_new(&browser, g_console.default_rom_startup_dir, ssnes_console_get_rom_ext()); + return 0; } From 3fd630e06233364822c5074f9e33464dad56cf5d Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 18 Feb 2012 11:59:55 +0100 Subject: [PATCH 12/15] Log anatomy of input device. --- input/sdl_input.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/input/sdl_input.c b/input/sdl_input.c index 3ce051f393..b4d6b9135a 100644 --- a/input/sdl_input.c +++ b/input/sdl_input.c @@ -163,9 +163,12 @@ static void *sdl_input_init(void) SSNES_LOG("Opened Joystick: %s #%u on port %u\n", SDL_JoystickName(g_settings.input.joypad_map[i]), g_settings.input.joypad_map[i], i + 1); + sdl->num_axes[i] = SDL_JoystickNumAxes(sdl->joysticks[i]); sdl->num_buttons[i] = SDL_JoystickNumButtons(sdl->joysticks[i]); sdl->num_hats[i] = SDL_JoystickNumHats(sdl->joysticks[i]); + SSNES_LOG("Joypad has: %u axes, %u buttons, %u hats.\n", + sdl->num_axes[i], sdl->num_buttons[i], sdl->num_hats[i]); } } #endif From 947d2a3514d8d2d57fd80c510ffc51bda7f3d8d9 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 18 Feb 2012 12:09:20 +0100 Subject: [PATCH 13/15] Fixed joypad index lookup. --- input/sdl_input.c | 38 ++++++++++++++++++++------------------ settings.c | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/input/sdl_input.c b/input/sdl_input.c index b4d6b9135a..abfd407608 100644 --- a/input/sdl_input.c +++ b/input/sdl_input.c @@ -150,26 +150,28 @@ static void *sdl_input_init(void) if (g_settings.input.joypad_map[i] < 0) continue; - if (sdl->num_joysticks > (unsigned)g_settings.input.joypad_map[i]) + unsigned port = g_settings.input.joypad_map[i]; + + if (sdl->num_joysticks <= port) + continue; + + sdl->joysticks[i] = SDL_JoystickOpen(port); + if (!sdl->joysticks[i]) { - sdl->joysticks[i] = SDL_JoystickOpen(g_settings.input.joypad_map[i]); - if (!sdl->joysticks[i]) - { - SSNES_ERR("Couldn't open SDL joystick #%u on SNES port %u\n", g_settings.input.joypad_map[i], i + 1); - free(sdl); - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); - return NULL; - } - - SSNES_LOG("Opened Joystick: %s #%u on port %u\n", - SDL_JoystickName(g_settings.input.joypad_map[i]), g_settings.input.joypad_map[i], i + 1); - - sdl->num_axes[i] = SDL_JoystickNumAxes(sdl->joysticks[i]); - sdl->num_buttons[i] = SDL_JoystickNumButtons(sdl->joysticks[i]); - sdl->num_hats[i] = SDL_JoystickNumHats(sdl->joysticks[i]); - SSNES_LOG("Joypad has: %u axes, %u buttons, %u hats.\n", - sdl->num_axes[i], sdl->num_buttons[i], sdl->num_hats[i]); + SSNES_ERR("Couldn't open SDL joystick #%u on SNES port %u\n", port, i + 1); + free(sdl); + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + return NULL; } + + SSNES_LOG("Opened Joystick: %s (#%u) on port %u\n", + SDL_JoystickName(port), port, i + 1); + + sdl->num_axes[i] = SDL_JoystickNumAxes(sdl->joysticks[i]); + sdl->num_buttons[i] = SDL_JoystickNumButtons(sdl->joysticks[i]); + sdl->num_hats[i] = SDL_JoystickNumHats(sdl->joysticks[i]); + SSNES_LOG("Joypad has: %u axes, %u buttons, %u hats.\n", + sdl->num_axes[i], sdl->num_buttons[i], sdl->num_hats[i]); } #endif diff --git a/settings.c b/settings.c index 5980071922..92abd0a3e0 100644 --- a/settings.c +++ b/settings.c @@ -418,7 +418,7 @@ bool config_load_file(const char *path) for (unsigned i = 0; i < MAX_PLAYERS; i++) { char buf[64]; - snprintf(buf, sizeof(buf), "input_player%u_joypad_index", i); + snprintf(buf, sizeof(buf), "input_player%u_joypad_index", i + 1); CONFIG_GET_INT(input.joypad_map[i], buf); } From aac253307569fce01bc436cb50461f245d4a201c Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 18 Feb 2012 12:32:49 +0100 Subject: [PATCH 14/15] Streamline hat lookup. --- input/sdl_input.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/input/sdl_input.c b/input/sdl_input.c index abfd407608..3cb38b828e 100644 --- a/input/sdl_input.c +++ b/input/sdl_input.c @@ -193,39 +193,32 @@ static bool sdl_joykey_pressed(sdl_input_t *sdl, int port_num, uint16_t joykey) // Check hat. if (GET_HAT_DIR(joykey)) { - int hat = GET_HAT(joykey); - if (hat < (int)sdl->num_hats[port_num]) + uint16_t hat = GET_HAT(joykey); + if (hat >= sdl->num_hats[port_num]) + return false; + + Uint8 dir = SDL_JoystickGetHat(sdl->joysticks[port_num], hat); + switch (GET_HAT_DIR(joykey)) { - Uint8 dir = SDL_JoystickGetHat(sdl->joysticks[port_num], hat); - switch (GET_HAT_DIR(joykey)) - { - case HAT_UP_MASK: - if (dir & SDL_HAT_UP) - return true; - break; - case HAT_DOWN_MASK: - if (dir & SDL_HAT_DOWN) - return true; - break; - case HAT_LEFT_MASK: - if (dir & SDL_HAT_LEFT) - return true; - break; - case HAT_RIGHT_MASK: - if (dir & SDL_HAT_RIGHT) - return true; - break; - default: - break; - } + case HAT_UP_MASK: + return dir & SDL_HAT_UP; + case HAT_DOWN_MASK: + return dir & SDL_HAT_DOWN; + case HAT_LEFT_MASK: + return dir & SDL_HAT_LEFT; + case HAT_RIGHT_MASK: + return dir & SDL_HAT_RIGHT; + default: + return false; } } else // Check the button { if (joykey < sdl->num_buttons[port_num] && SDL_JoystickGetButton(sdl->joysticks[port_num], joykey)) return true; + + return false; } - return false; } static bool sdl_axis_pressed(sdl_input_t *sdl, int port_num, uint32_t joyaxis) From 2ef54a7e018c10b62327075266991adfbffbfe29 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 18 Feb 2012 13:00:14 +0100 Subject: [PATCH 15/15] Might fix hat lookup. --- settings.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/settings.c b/settings.c index 92abd0a3e0..fc39b0c408 100644 --- a/settings.c +++ b/settings.c @@ -697,27 +697,30 @@ static void read_keybinds_keyboard(config_file_t *conf, unsigned player, unsigne static void parse_hat(struct snes_keybind *bind, const char *str) { - if (isdigit(*str)) + if (!isdigit(*str)) + return; + + char *dir = NULL; + uint16_t hat = strtoul(str, &dir, 0); + uint16_t hat_dir = 0; + + if (!dir) { - char *dir = NULL; - int hat = strtol(str, &dir, 0); - int hat_dir = 0; - - if (dir) - { - if (strcasecmp(str, "up") == 0) - hat_dir = HAT_UP_MASK; - else if (strcasecmp(str, "down") == 0) - hat_dir = HAT_DOWN_MASK; - else if (strcasecmp(str, "left") == 0) - hat_dir = HAT_LEFT_MASK; - else if (strcasecmp(str, "right") == 0) - hat_dir = HAT_RIGHT_MASK; - - if (hat_dir) - bind->joykey = HAT_MAP(hat, hat_dir); - } + SSNES_WARN("Found invalid hat in config!\n"); + return; } + + if (strcasecmp(dir, "up") == 0) + hat_dir = HAT_UP_MASK; + else if (strcasecmp(dir, "down") == 0) + hat_dir = HAT_DOWN_MASK; + else if (strcasecmp(dir, "left") == 0) + hat_dir = HAT_LEFT_MASK; + else if (strcasecmp(dir, "right") == 0) + hat_dir = HAT_RIGHT_MASK; + + if (hat_dir) + bind->joykey = HAT_MAP(hat, hat_dir); } static void read_keybinds_button(config_file_t *conf, unsigned player, unsigned index, struct snes_keybind *bind)