From 1090eeb159ca86a2e82955798895d5049e684af0 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Sun, 12 Feb 2012 17:13:13 +0100 Subject: [PATCH] (360) Some cleanups --- 360/xdk360_video.cpp | 3 +- 360/xdk360_video_console.cpp | 50 ++++++++++----------------------- 360/xdk360_video_console.h | 29 +++++++++++-------- 360/xdk360_video_debugfonts.cpp | 48 +++++++++++++++---------------- 360/xdk360_video_debugfonts.h | 4 +-- 360/xdk360_video_resources.cpp | 9 ------ 360/xdk360_video_resources.h | 11 +++----- 7 files changed, 61 insertions(+), 93 deletions(-) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 0075b1fb05..ecac2019db 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -279,8 +279,7 @@ static bool xdk360_gfx_frame(void *data, const void *frame, { if(IS_TIMER_EXPIRED() || g_first_msg) { - g_screen_console.Clear(); - g_screen_console.Format(msg); + g_screen_console.Format(true, msg); g_first_msg = 0; SET_TIMER_EXPIRATION(60); } diff --git a/360/xdk360_video_console.cpp b/360/xdk360_video_console.cpp index da33be1f46..a872f693c5 100644 --- a/360/xdk360_video_console.cpp +++ b/360/xdk360_video_console.cpp @@ -23,9 +23,6 @@ #include "xdk360_video_debugfonts.h" #include "../general.h" -// Ignore warning about "unused" pD3D variable -#pragma warning( disable: 4189 ) - Console::Console() { first_message = true; @@ -85,38 +82,11 @@ HRESULT Console::Create( LPCSTR strFontFileName, D3DCOLOR colBackColor, for( unsigned int i = 0; i < m_cScreenHeightVirtual; i++ ) m_Lines[ i ] = m_Buffer + ( m_cScreenWidth + 1 ) * i; - // Clear the screen - Clear(); + CLEAR_SCREEN(); return hr; } - -//-------------------------------------------------------------------------------------- -// Name: Clear() -// Desc: Clear the screen -//-------------------------------------------------------------------------------------- -VOID Console::Clear() -{ - m_nCurLine = 0; - m_cCurLineLength = 0; - memset( m_Buffer, 0, m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - - Render(); -} - - -//-------------------------------------------------------------------------------------- -// Name: IncrementLine() -// Desc: Skip to the next line -//-------------------------------------------------------------------------------------- -VOID Console::IncrementLine() -{ - m_nCurLine = ( m_nCurLine + 1 ) % m_cScreenHeightVirtual; - m_cCurLineLength = 0; - memset( m_Lines[m_nCurLine], 0, ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); -} - //-------------------------------------------------------------------------------------- // Name: Destroy() // Desc: Tear everything down @@ -198,7 +168,7 @@ void Console::Add( wchar_t wch ) // If this is a newline, just increment lines and move on if( wch == L'\n' ) { - IncrementLine(); + INCREMENT_LINE(); return; } @@ -222,7 +192,7 @@ void Console::Add( wchar_t wch ) // If we need to skip to the next line, do so if( bIncrementLine ) { - IncrementLine(); + INCREMENT_LINE(); m_Lines[ m_nCurLine ][0] = wch; } @@ -235,8 +205,13 @@ void Console::Add( wchar_t wch ) // Name: Format() // Desc: Output a variable argument list using a format string //-------------------------------------------------------------------------------------- -void Console::Format( _In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) +void Console::Format(int clear_screen, _In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) { + if(clear_screen) + { + CLEAR_SCREEN(); + } + va_list pArgList; va_start( pArgList, strFormat ); FormatV( strFormat, pArgList ); @@ -246,8 +221,13 @@ void Console::Format( _In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) Render(); } -void Console::Format( _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) +void Console::Format(int clear_screen, _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) { + if(clear_screen) + { + CLEAR_SCREEN(); + } + va_list pArgList; va_start( pArgList, wstrFormat ); FormatV( wstrFormat, pArgList ); diff --git a/360/xdk360_video_console.h b/360/xdk360_video_console.h index dcc815a1e2..e0a6c0bb08 100644 --- a/360/xdk360_video_console.h +++ b/360/xdk360_video_console.h @@ -17,8 +17,8 @@ */ #pragma once -#ifndef ATGCONSOLE_H -#define ATGCONSOLE_H +#ifndef SSNES360_CONSOLE_H +#define SSNES360_CONSOLE_H #include #include "xdk360_video_debugfonts.h" @@ -32,6 +32,17 @@ #define SAFE_AREA_PCT_4x3 85 #define SAFE_AREA_PCT_HDTV 90 +#define INCREMENT_LINE() \ + m_nCurLine = ( m_nCurLine + 1 ) % m_cScreenHeightVirtual; \ + m_cCurLineLength = 0; \ + memset( m_Lines[m_nCurLine], 0, ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + +#define CLEAR_SCREEN() \ + m_nCurLine = 0; \ + m_cCurLineLength = 0; \ + memset( m_Buffer, 0, m_cScreenHeightVirtual * ( m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); \ + Render(); + //-------------------------------------------------------------------------------------- // Name: class Console // Desc: Class to implement the console. @@ -39,8 +50,8 @@ class Console { public: - Console(); - ~Console(); + Console(); + ~Console(); // Initialization HRESULT Create( LPCSTR strFontFileName, @@ -50,12 +61,9 @@ public: void Destroy(); - // Clear the screen - void Clear(); - // Console output - void Format( _In_z_ _Printf_format_string_ LPCSTR strFormat, ... ); - void Format( _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); + 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 FormatV( _In_z_ _Printf_format_string_ LPCSTR strFormat, va_list pArgList ); void FormatV( _In_z_ _Printf_format_string_ LPCWSTR wstrFormat, va_list pArgList ); @@ -92,9 +100,6 @@ private: // Add a character to the current line void Add( char ch ); void Add( wchar_t wch ); - - // Increment to the next line - void IncrementLine(); }; #endif diff --git a/360/xdk360_video_debugfonts.cpp b/360/xdk360_video_debugfonts.cpp index 4269e8c65f..f18e6a59bb 100644 --- a/360/xdk360_video_debugfonts.cpp +++ b/360/xdk360_video_debugfonts.cpp @@ -22,10 +22,8 @@ #include "xdk360_video_debugfonts.h" #include "../general.h" -// Font description - -#define ATGCALCFONTFILEHEADERSIZE(x) ( sizeof(DWORD) + (sizeof(FLOAT)*4) + sizeof(WORD) + (sizeof(WCHAR)*(x)) ) -#define ATGFONTFILEVERSION 5 +#define CALCFONTFILEHEADERSIZE(x) ( sizeof(unsigned long) + (sizeof(float)* 4) + sizeof(unsigned short) + (sizeof(wchar_t)*(x)) ) +#define FONTFILEVERSION 5 typedef struct FontFileHeaderImage_t { unsigned long m_dwFileVersion; // Version of the font file (Must match FONTFILEVERSION) @@ -155,8 +153,8 @@ HRESULT XdkFont::CreateFontShaders() { // Use the do {} while(0); trick for a fake goto // It simplies tear down on error conditions. - - do { + do + { // Step #1, create my vertex array with 16 bytes per entry // Floats for the position, @@ -192,9 +190,7 @@ HRESULT XdkFont::CreateFontShaders() if( SUCCEEDED( Result ) ) { - // Step #3, create my pixel shader - Result = D3DXCompileShader( g_strFontShader, sizeof(g_strFontShader)-1 , NULL, NULL, "FontPixelShader", "ps.2.0", 0,&pShaderCode, NULL, NULL ); if ( SUCCEEDED( Result ) ) @@ -206,7 +202,7 @@ HRESULT XdkFont::CreateFontShaders() if ( SUCCEEDED( Result ) ) { - Result = S_OK; // I'm good. + Result = S_OK; break; // Skip the teardown code } } @@ -222,7 +218,7 @@ HRESULT XdkFont::CreateFontShaders() } // Ensure this pointer is NULL s_AtgFontLocals.m_pFontVertexDecl = NULL; - } while (0); // Exit point for the break command. + }while(0); // Exit point for the break command. return Result; } else @@ -234,7 +230,7 @@ HRESULT XdkFont::CreateFontShaders() s_AtgFontLocals.m_pFontVertexDecl->AddRef(); s_AtgFontLocals.m_pFontVertexShader->AddRef(); s_AtgFontLocals.m_pFontPixelShader->AddRef(); - Result = S_OK; // Everything is fine + Result = S_OK; } return Result; // Return the error code if any } @@ -317,7 +313,7 @@ HRESULT XdkFont::Create( const char * strFontFileName ) const unsigned char * pData = static_cast(pFontData); unsigned long dwFileVersion = reinterpret_cast(pData)->m_dwFileVersion; - if( dwFileVersion == ATGFONTFILEVERSION ) + if( dwFileVersion == FONTFILEVERSION ) { m_fFontHeight = reinterpret_cast(pData)->m_fFontHeight; m_fFontTopPadding = reinterpret_cast(pData)->m_fFontTopPadding; @@ -329,7 +325,7 @@ HRESULT XdkFont::Create( const char * strFontFileName ) m_TranslatorTable = const_cast(reinterpret_cast(pData))->m_TranslatorTable; - pData += ATGCALCFONTFILEHEADERSIZE( m_cMaxGlyph + 1 ); + pData += CALCFONTFILEHEADERSIZE( m_cMaxGlyph + 1 ); // Read the glyph attributes from the file m_dwNumGlyphs = reinterpret_cast(pData)->m_dwNumGlyphs; @@ -381,7 +377,7 @@ void XdkFont::Destroy() // Safely release shaders ReleaseFontShaders(); - if( m_xprResource.Initialized() ) + if( m_xprResource.m_bInitialized) m_xprResource.Destroy(); } @@ -772,11 +768,11 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, } // Translate unprintable characters - const GLYPH_ATTR* pGlyph = &m_Glyphs[ ( letter <= m_cMaxGlyph ) ? m_TranslatorTable[letter] : 0 ]; + const GLYPH_ATTR * pGlyph = &m_Glyphs[ ( letter <= m_cMaxGlyph ) ? 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 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; if( 0 == dwNumEllipsesToDraw ) @@ -846,20 +842,20 @@ VOID XdkFont::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, pVertex[0] = X1; pVertex[1] = Y1; - reinterpret_cast(pVertex)[2] = (tu1<<16)|tv1; // Merged using big endian rules - reinterpret_cast(pVertex)[3] = dwChannelSelector; + reinterpret_cast(pVertex)[2] = (tu1<<16)|tv1; // Merged using big endian rules + reinterpret_cast(pVertex)[3] = dwChannelSelector; pVertex[4] = X2; pVertex[5] = Y2; - reinterpret_cast(pVertex)[6] = (tu2<<16)|tv1; // Merged using big endian rules - reinterpret_cast(pVertex)[7] = dwChannelSelector; + reinterpret_cast(pVertex)[6] = (tu2<<16)|tv1; // Merged using big endian rules + reinterpret_cast(pVertex)[7] = dwChannelSelector; pVertex[8] = X3; pVertex[9] = Y3; - reinterpret_cast(pVertex)[10] = (tu2<<16)|tv2; // Merged using big endian rules - reinterpret_cast(pVertex)[11] = dwChannelSelector; + reinterpret_cast(pVertex)[10] = (tu2<<16)|tv2; // Merged using big endian rules + reinterpret_cast(pVertex)[11] = dwChannelSelector; pVertex[12] = X4; pVertex[13] = Y4; - reinterpret_cast(pVertex)[14] = (tu1<<16)|tv2; // Merged using big endian rules - reinterpret_cast(pVertex)[15] = dwChannelSelector; + reinterpret_cast(pVertex)[14] = (tu1<<16)|tv2; // Merged using big endian rules + reinterpret_cast(pVertex)[15] = dwChannelSelector; pVertex+=16; // If drawing ellipses, exit when they're all drawn diff --git a/360/xdk360_video_debugfonts.h b/360/xdk360_video_debugfonts.h index bf7b710bd7..7459c8279f 100644 --- a/360/xdk360_video_debugfonts.h +++ b/360/xdk360_video_debugfonts.h @@ -16,8 +16,8 @@ * If not, see . */ -#ifndef _XDK360_DEBUG_FONTS_H -#define _XDK360_DEBUG_FONTS_H +#ifndef _SSNES360_DEBUG_FONTS_H +#define _SSNES360_DEBUG_FONTS_H #include "xdk360_video_resources.h" diff --git a/360/xdk360_video_resources.cpp b/360/xdk360_video_resources.cpp index f9594f8964..3f2c4e7040 100644 --- a/360/xdk360_video_resources.cpp +++ b/360/xdk360_video_resources.cpp @@ -210,12 +210,3 @@ void PackedResource::Destroy() m_bInitialized = FALSE; } - -//-------------------------------------------------------------------------------------- -// Name: Initialized -// Desc: Indicates whether the packed resource has been successfully initialized -//-------------------------------------------------------------------------------------- -BOOL PackedResource::Initialized() const -{ - return m_bInitialized; -} diff --git a/360/xdk360_video_resources.h b/360/xdk360_video_resources.h index 01e80e6983..25a3cffaa8 100644 --- a/360/xdk360_video_resources.h +++ b/360/xdk360_video_resources.h @@ -18,8 +18,8 @@ #pragma once -#ifndef ATGRESOURCE_H -#define ATGRESOURCE_H +#ifndef SSNES360_RESOURCES_H +#define SSNES360_RESOURCES_H //-------------------------------------------------------------------------------------- // Name tag for resources. An app may initialize this structure, and pass @@ -62,16 +62,13 @@ protected: RESOURCE* m_pResourceTags; // Tags to associate names with the resources unsigned long m_dwNumResourceTags; // Number of resource tags - int m_bInitialized; // Resource is fully initialized - public: + int m_bInitialized; // Resource is fully initialized // Loads the resources out of the specified bundle HRESULT Create( const char * strFilename ); void Destroy(); - BOOL Initialized() const; - // Retrieves the resource tags void GetResourceTags( unsigned long * pdwNumResourceTags, RESOURCE** ppResourceTags ) const; @@ -155,4 +152,4 @@ public: ~PackedResource(); }; -#endif // ATGRESOURCE_H +#endif