mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-02-01 09:12:35 +00:00
(360) xdk360_video_console no longer class-based
This commit is contained in:
parent
8ec0cb4f6c
commit
356d565ce6
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
Console::~Console()
|
||||
{
|
||||
Destroy();
|
||||
m_Font.End();
|
||||
}
|
||||
|
||||
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
|
||||
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 );
|
||||
|
||||
|
@ -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
|
||||
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 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_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
|
||||
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)
|
||||
} video_console_t;
|
||||
|
||||
// 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user