From 8dcf132b0c0c1708e14b9796465ad23afda77362 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Wed, 15 Feb 2012 18:57:29 +0100 Subject: [PATCH 01/12] (360) Updated 360 port too --- 360/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/360/main.c b/360/main.c index 96853610bb..44ae4cbb70 100644 --- a/360/main.c +++ b/360/main.c @@ -193,7 +193,7 @@ static void set_default_settings (void) static void init_settings (void) { - if(!filepath_exists(SYS_CONFIG_FILE)) + if(!path_file_exists(SYS_CONFIG_FILE)) { SSNES_ERR("Config file \"%s\" desn't exist. Creating...\n", "game:\\ssnes.cfg"); FILE * f; @@ -219,7 +219,7 @@ static void init_settings (void) static void save_settings (void) { - if(!filepath_exists(SYS_CONFIG_FILE)) + if(!path_file_exists(SYS_CONFIG_FILE)) { FILE * f; f = fopen(SYS_CONFIG_FILE, "w"); @@ -363,7 +363,7 @@ begin_loop: goto begin_loop; begin_shutdown: - if(filepath_exists(SYS_CONFIG_FILE)) + if(path_file_exists(SYS_CONFIG_FILE)) save_settings(); xdk360_video_deinit(); } From 878e6125841090fe90ac8a46da43acc19768f266 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Wed, 15 Feb 2012 18:57:36 +0100 Subject: [PATCH 02/12] (PS3) Use new public save slot increment/decrement functions --- ps3/menu.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/ps3/menu.c b/ps3/menu.c index b7596af4ac..75dddeecd2 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -1650,21 +1650,14 @@ static void ingame_menu(uint32_t menu_id) } if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state)) { - if(g_extern.state_slot > 0) - { - char msg[512]; - g_extern.state_slot--; - snprintf(msg, sizeof(msg), "Save state slot changed to: #%d", g_extern.state_slot); - set_text_message(msg, 30); - } + ssnes_state_slot_decrease(); + set_text_message("", 30); blocking = 0; } if(CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state)) { - char msg[512]; - g_extern.state_slot++; - snprintf(msg, sizeof(msg), "Save state slot changed to: #%d", g_extern.state_slot); - set_text_message(msg, 30); + ssnes_state_slot_increase(); + set_text_message("", 30); blocking = 0; } @@ -1678,21 +1671,14 @@ static void ingame_menu(uint32_t menu_id) } if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state)) { - if(g_extern.state_slot > 0) - { - char msg[512]; - g_extern.state_slot--; - snprintf(msg, sizeof(msg), "Save state slot changed to: #%d", g_extern.state_slot); - set_text_message(msg, 30); - } + ssnes_state_slot_decrease(); + set_text_message("", 30); blocking = 0; } if(CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state)) { - char msg[512]; - g_extern.state_slot++; - snprintf(msg, sizeof(msg), "Save state slot changed to: #%d", g_extern.state_slot); - set_text_message(msg, 30); + ssnes_state_slot_increase(); + set_text_message("", 30); blocking = 0; } From 441cd2b82a74c76a22be624674b4cd5fc2acb594 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 03:36:40 +0100 Subject: [PATCH 03/12] (PS3) Some cleanups in ps3_video_psgl.c --- ps3/ps3_video_psgl.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 4ce1a219b2..bf3135fa57 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -418,17 +418,6 @@ static inline void gl_compute_fbo_geometry(gl_t *gl, unsigned width, unsigned he gl->render_to_tex = true; \ set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true); -static inline unsigned get_alignment(unsigned pitch) -{ - if (pitch & 1) - return 1; - if (pitch & 2) - return 2; - if (pitch & 4) - return 4; - return 8; -} - static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full) { uint32_t m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; @@ -496,7 +485,7 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_f } } -static inline void set_lut_texture_coords(const GLfloat *coords) +static void set_lut_texture_coords(const GLfloat *coords) { // For texture images. pglClientActiveTexture(GL_TEXTURE1); @@ -505,13 +494,11 @@ static inline void set_lut_texture_coords(const GLfloat *coords) pglClientActiveTexture(GL_TEXTURE0); } -static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yamt) -{ - coords[1] = yamt; - coords[4] = xamt; - coords[6] = xamt; +#define set_texture_coords(coords, xamt, yamt) \ + coords[1] = yamt; \ + coords[4] = xamt; \ + coords[6] = xamt; \ coords[7] = yamt; -} void gl_frame_menu (void) { @@ -1293,7 +1280,7 @@ void ps3graphics_set_aspect_ratio(uint32_t aspectratio_index) strlcpy(g_console.aspect_ratio_name, "8:7", sizeof(g_console.aspect_ratio_name)); break; case ASPECT_RATIO_16_9: - g_settings.video.aspect_ratio = 1.77777777777; + g_settings.video.aspect_ratio = 1.777778; strlcpy(g_console.aspect_ratio_name, "16:9", sizeof(g_console.aspect_ratio_name)); break; case ASPECT_RATIO_16_10: From 2760b5b0c22623540c030f824e17c583914be202 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 03:49:13 +0100 Subject: [PATCH 04/12] (Core) Don't create 'can't load XML memory map' if HAVE_XML is not defined for the port --- file.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/file.c b/file.c index d9181f45d9..95f9533c19 100644 --- a/file.c +++ b/file.c @@ -550,6 +550,7 @@ void save_ram_file(const char *path, int type) } } +#ifdef HAVE_XML static char *load_xml_map(const char *path) { char *xml_buf = NULL; @@ -563,6 +564,9 @@ static char *load_xml_map(const char *path) return xml_buf; } +#else +#define load_xml_map(xml_name) (NULL) +#endif static bool load_sgb_rom(void) { From 3585e046de72e18c8ff1852a168a67a0f19ac0e6 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 03:55:22 +0100 Subject: [PATCH 05/12] (Core) Add some more HAVE_XML ifdefs --- ssnes.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ssnes.c b/ssnes.c index 389e767512..cbf22d6acf 100644 --- a/ssnes.c +++ b/ssnes.c @@ -419,7 +419,9 @@ 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"); @@ -510,7 +512,9 @@ 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"); } @@ -657,7 +661,9 @@ 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 } @@ -850,10 +856,11 @@ 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) @@ -1485,8 +1492,10 @@ 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 668aa9a9acfd6334ae368724e41c7b880ef0326c Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 16 Feb 2012 15:27:51 +0100 Subject: [PATCH 06/12] (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 07/12] (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 08/12] (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 09/12] (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 10/12] (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 11/12] (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 12/12] 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)) {