(Xbox 1) RetroLaunch - complexity cleanups

This commit is contained in:
twinaphex 2012-07-24 17:00:24 +02:00
parent 53c5ff80ed
commit 2240e96b20
14 changed files with 164 additions and 389 deletions

View File

@ -34,16 +34,11 @@ Font::~Font(void)
}
bool Font::Create()
{ //Hardcoded
return Create("D:\\Media\\arial.ttf");
}
bool Font::Create(const string &szTTFFilename)
{
if (m_pFont)
m_pFont->Release();
word *wcPathBuf = StringToWChar(szTTFFilename);
word *wcPathBuf = StringToWChar("D:\\Media\\arial.ttf");
HRESULT g_hResult = XFONT_OpenTrueTypeFont(wcPathBuf, 256 * 1024, &m_pFont);
delete [] wcPathBuf;
@ -67,14 +62,10 @@ void Font::Render(const string &str, int x, int y, dword height, dword style, D3
delete [] wcBuf;
if (alignment == Center)
{
x -= (dwRequiredWidth / 2);
}
else if (alignment == Right)
{
x -= dwRequiredWidth;
}
}
texture.Render(x, y);
}
@ -102,13 +93,10 @@ void Font::RenderToTexture(CSurface &texture, const string &str, dword height, d
// because the textures are swizzled we make sure
// the dimensions are a power of two
for(dword wmask = 1; dwTextureWidth &(dwTextureWidth - 1); wmask = (wmask << 1 ) + 1)
{
dwTextureWidth = (dwTextureWidth + wmask) & ~wmask;
}
for(dword hmask = 1; dwTextureHeight &(dwTextureHeight - 1); hmask = (hmask << 1) + 1)
{
dwTextureHeight = ( dwTextureHeight + hmask ) & ~hmask;
}
// also enforce a minimum pitch of 64 bytes
dwTextureWidth = max(64 / XGBytesPerPixelFromFormat(D3DFMT_A8R8G8B8), dwTextureWidth);

View File

@ -35,7 +35,6 @@ public:
~Font(void);
bool Create();
bool Create(const string &szTTFFilename);
void Render(const string &str, int x, int y, dword height, dword style = XFONT_NORMAL, D3DXCOLOR color = D3DCOLOR_XRGB(0, 0, 0), int dwMaxWidth = -1, bool fade = false, Align alignment = Left);
void RenderToTexture(CSurface &texture, const string &str, dword height, dword style = XFONT_NORMAL, D3DXCOLOR color = D3DCOLOR_XRGB(0, 0, 0), int maxWidth = -1, bool fade = false);
@ -44,7 +43,6 @@ public:
int GetRequiredHeight(const string &str, dword height, dword style);
word *StringToWChar(const string &str);
private:
XFONT *m_pFont;
};

View File

@ -1,7 +1,6 @@
// IoSupport.cpp: implementation of the CIoSupport class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _XBOX
#include "iosupport.h"
#include "undocumented.h"
@ -189,73 +188,3 @@ HRESULT CIoSupport::Shutdown()
HalInitiateShutdown();
return S_OK;
}
HANDLE CIoSupport::CreateFile()
{
ANSI_STRING filename;
OBJECT_ATTRIBUTES attributes;
IO_STATUS_BLOCK status;
HANDLE hDevice;
NTSTATUS error;
RtlInitAnsiString(&filename, "\\Device\\Cdrom0");
InitializeObjectAttributes(&attributes, &filename, OBJ_CASE_INSENSITIVE, NULL);
if (!NT_SUCCESS(error = NtCreateFile(&hDevice, GENERIC_READ |
SYNCHRONIZE | FILE_READ_ATTRIBUTES, &attributes, &status, NULL, 0,
FILE_SHARE_READ, FILE_OPEN, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT)))
{
return NULL;
}
return hDevice;
}
BOOL CIoSupport::GetFirstFile(CHAR* szFilename)
{
ANSI_STRING filename;
OBJECT_ATTRIBUTES attributes;
IO_STATUS_BLOCK status;
HANDLE hDevice;
NTSTATUS error;
RtlInitAnsiString(&filename, "\\Device\\Cdrom0");
InitializeObjectAttributes(&attributes, &filename, OBJ_CASE_INSENSITIVE, NULL);
if (!NT_SUCCESS(error = NtCreateFile(&hDevice, GENERIC_READ |
SYNCHRONIZE | FILE_READ_ATTRIBUTES, &attributes, &status, NULL, 0,
FILE_SHARE_READ, FILE_OPEN, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT)))
{
OutputDebugString("Unable to open Cdrom0.\n");
return FALSE;
}
CHAR* szBuffer = new CHAR[2048];
DWORD dwRead = 0;
SetFilePointer(hDevice, 19 * 2048, NULL, FILE_BEGIN);
if (!ReadFile(hDevice, szBuffer, 2048, &dwRead, NULL))
{
OutputDebugString("Unable to read ISO9660 root directory.\n");
CloseHandle(hDevice);
return FALSE;
}
CloseHandle(hDevice);
szBuffer[2047] = 0;
int offset = 0;
while (szBuffer[offset] == 0x22) offset += 0x22;
offset += 33; // jump to start of filename
strcpy(szFilename, "#");
strcat(szFilename, &szBuffer[offset]);
if (szBuffer)
delete [] szBuffer;
return TRUE;
}
#endif

View File

@ -38,10 +38,6 @@ public:
HRESULT EjectTray();
HRESULT CloseTray();
HRESULT Shutdown();
HANDLE CreateFile();
BOOL GetFirstFile(CHAR* szFilename);
private:
DWORD m_dwTrayState;
DWORD m_dwTrayCount;

View File

@ -33,21 +33,13 @@ CMenuMain::CMenuMain()
if (stateFile.is_open())
{
int baseIndex;
int romListMode;
stateFile >> baseIndex;
stateFile >> romListMode;
stateFile >> m_displayMode;
g_romList.SetRomListMode(romListMode);
g_romList.m_iBaseIndex = baseIndex;
stateFile.close();
}
else
{
m_displayMode = List;
}
}
CMenuMain::~CMenuMain()
@ -56,8 +48,6 @@ CMenuMain::~CMenuMain()
stateFile.open("T:\\RomlistState.dat");
stateFile << g_romList.GetBaseIndex() << endl;
stateFile << g_romList.GetRomListMode() << endl;
stateFile << m_displayMode << endl;
stateFile.close();
}
@ -102,9 +92,7 @@ bool CMenuMain::Create()
m_romListOffset = 0;
if(m_romListEndRender > g_romList.GetRomListSize() - 1)
{
m_romListEndRender = g_romList.GetRomListSize() - 1;
}
//Generate the rom list textures only once
vector<Rom *>::iterator i;
@ -121,8 +109,6 @@ bool CMenuMain::Create()
void CMenuMain::Render()
{
//CheckRomListState();
//Render background image
m_menuMainBG.Render(m_menuMainBG_x, m_menuMainBG_y);
@ -161,7 +147,6 @@ void CMenuMain::ProcessInput()
{
if(m_romListSelectedRom < g_romList.GetRomListSize())
{
if(m_menuMainRomSelectPanel_y < (m_menuMainRomListPos_y + (m_menuMainRomListSpacing * m_romListEndRender)))
{
m_menuMainRomSelectPanel_y += m_menuMainRomListSpacing;
@ -174,14 +159,12 @@ void CMenuMain::ProcessInput()
m_menuMainRomSelectPanel_y -= m_menuMainRomListSpacing;
m_romListSelectedRom++;
if(m_romListSelectedRom > g_romList.GetRomListSize() - 1)
{
m_romListSelectedRom = g_romList.GetRomListSize() - 1;
}
RARCH_LOG("SELECTED ROM AFTER CORRECTION: %d.\n", m_romListSelectedRom);
if(m_romListSelectedRom < g_romList.GetRomListSize() - 1 && m_romListOffset < g_romList.GetRomListSize() - 1 - m_romListEndRender - 1) {
if(m_romListSelectedRom < g_romList.GetRomListSize() - 1 && m_romListOffset < g_romList.GetRomListSize() - 1 - m_romListEndRender - 1)
{
m_romListOffset++;
RARCH_LOG("OFFSET: %d.\n", m_romListOffset);
}
@ -205,14 +188,12 @@ void CMenuMain::ProcessInput()
m_menuMainRomSelectPanel_y += m_menuMainRomListSpacing;
m_romListSelectedRom--;
if(m_romListSelectedRom < 0)
{
m_romListSelectedRom = 0;
}
RARCH_LOG("SELECTED ROM AFTER CORRECTION: %d.\n", m_romListSelectedRom);
if(m_romListSelectedRom > 0 && m_romListOffset > 0) {
if(m_romListSelectedRom > 0 && m_romListOffset > 0)
{
m_romListOffset--;
RARCH_LOG("OFFSET: %d.\n", m_romListOffset);
}
@ -221,10 +202,8 @@ void CMenuMain::ProcessInput()
}
// Press A to launch, selected rom filename is saved into T:\\tmp.retro
if(trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_B) || trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_START))
{
if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_B) || trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_START))
rarch_console_load_game(g_romList.GetRomAt(m_romListSelectedRom)->GetFileName().c_str());
}
if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_R3))
{

View File

@ -17,12 +17,6 @@
#include "Global.h"
#include "Surface.h"
enum DisplayMode
{
Box,
List
};
class CMenuMain
{
public:
@ -69,21 +63,6 @@ int m_menuMainRomListPos_x;
int m_menuMainRomListPos_y;
int m_menuMainRomListSpacing;
/**
* The Rom List menu buttons. The size can be variable so we use a list
*/
//list<MenuButton *> m_romListButtons;//list<Texture *>
//no menu buttons, we will use plain textures
list<CSurface *> m_romListButtons;
/**
* The current mode the rom list is in
*/
int m_displayMode;
/**
* The current loaded state the rom list is in
*/

View File

@ -42,7 +42,8 @@ bool CMenuManager::SetMenuState(int nMenuID)
{
m_pMenuID = nMenuID;
switch (m_pMenuID) {
switch (m_pMenuID)
{
case MENU_MAIN:
//Create the Main Menu
g_menuMain.Create();
@ -53,20 +54,15 @@ bool CMenuManager::SetMenuState(int nMenuID)
void CMenuManager::Update()
{
//Process overall input
ProcessInput();
switch (m_pMenuID) {
switch (m_pMenuID)
{
case MENU_MAIN:
// Process menu specific input
g_menuMain.ProcessInput();
// Render the Main Menu
g_menuMain.Render();
break;
}
}
@ -74,8 +70,6 @@ void CMenuManager::ProcessInput()
{
}
int CMenuManager::GetMenuState()
{
return m_pMenuID;

View File

@ -27,7 +27,6 @@ enum eMenuState
MENU_LAUNCHER
};
class CMenuManager
{
public:

View File

@ -14,7 +14,6 @@
*/
#include "Rom.h"
//#include "BoxArtTable.h"
Rom::Rom()
{
@ -25,28 +24,21 @@ Rom::~Rom(void)
{
}
bool Rom::Load(const string &szFilename)
bool Rom::Load(const char *szFilename)
{
if (m_bLoaded)
return true;
m_szFilename = szFilename;
// get the filename for the box art image
//FIXME: Add BoxArtTable.cpp/h, open iso file, grab header, extract ID ie. T-6003G, use for boxartfilename
{
m_szBoxArtFilename = "D:\\boxart\\default.jpg"; //g_boxArtTable.GetBoxArtFilename(m_dwCrc1);
}
m_bLoaded = true;
return true;
}
bool Rom::LoadFromCache(const string &szFilename, const string &szBoxArtFilename)
bool Rom::LoadFromCache(const string &szFilename)
{
m_szFilename = szFilename;
m_szBoxArtFilename = szBoxArtFilename;
m_bLoaded = true;
@ -58,11 +50,6 @@ string Rom::GetFileName()
return m_szFilename;
}
string Rom::GetBoxArtFilename()
{
return m_szBoxArtFilename;
}
string Rom::GetComments()
{
//return string(m_iniEntry->szComments);

View File

@ -24,20 +24,14 @@ public:
Rom();
~Rom();
bool Load(const string &szFilename);
bool LoadFromCache(const string &szFilename, const string &szBoxArtFilename);
bool Load(const char *szFilename);
bool LoadFromCache(const string &szFilename);
string GetFileName();
string GetBoxArtFilename();
string GetComments();
CSurface &GetTexture();
private:
string m_szFilename;
string m_szBoxArtFilename;
bool m_bLoaded;
CSurface m_texture;
};

View File

@ -24,7 +24,6 @@ bool RLessThan(Rom *elem1, Rom *elem2)
RomList::RomList(void)
{
m_romListMode = All;
m_iBaseIndex = 0;
m_bLoaded = false;
m_szRomPath = "D:\\";
@ -51,14 +50,12 @@ void RomList::Load()
while (!cacheFile.eof())
{
string szFilename;
string szBoxArtFilename;
getline(cacheFile, szFilename);
getline(cacheFile, szBoxArtFilename);
Rom *rom = new Rom();
bool bSuccess = rom->LoadFromCache(szFilename, szBoxArtFilename);
bool bSuccess = rom->LoadFromCache(szFilename);
if (bSuccess)
m_romList.push_back(rom);
@ -85,7 +82,6 @@ void RomList::Save()
Rom *rom = *i;
cacheFile << rom->GetFileName() << endl;
cacheFile << rom->GetBoxArtFilename() << endl;
}
cacheFile.close();
@ -103,29 +99,11 @@ bool RomList::IsLoaded()
return m_bLoaded;
}
void RomList::SetRomListMode(int mode)
{
m_iBaseIndex = 0;
m_romListMode = mode;
}
int RomList::GetRomListMode()
{
return m_romListMode;
}
void RomList::AddRomToList(Rom *rom, int mode)
{
vector<Rom *> *pList;
switch (mode)
{
case All:
pList = &m_romList;
break;
default:
return;
}
// look to see if the rom is already in the list, we dont want duplicates
for (int i = 0; i < static_cast<int>(pList->size()); i++)
@ -142,14 +120,7 @@ void RomList::RemoveRomFromList(Rom *rom, int mode)
{
vector<Rom *> *pList;
switch (mode)
{
case All:
pList = &m_romList;
break;
default:
return;
}
vector<Rom *>::iterator i;
@ -186,38 +157,19 @@ void RomList::SetBaseIndex(int index)
int RomList::GetRomListSize()
{
switch (m_romListMode)
{
case All:
return m_romList.size();
}
return 0;
}
Rom *RomList::GetRomAt(int index)
{
switch (m_romListMode)
{
case All:
return m_romList[index];
}
return 0;
}
int RomList::FindRom(Rom *rom, int mode)
{
vector<Rom *> *pList;
switch (mode)
{
case All:
pList = &m_romList;
break;
default:
return -1;
}
for (int i = 0; i < static_cast<int>(pList->size()); i++)
{

View File

@ -18,11 +18,6 @@
#include "Global.h"
#include "Rom.h"
enum RomListMode
{
All
};
class RomList
{
public:
@ -35,9 +30,6 @@ public:
bool IsLoaded();
void SetRomListMode(int mode);
int GetRomListMode();
void AddRomToList(Rom *rom, int mode);
void RemoveRomFromList(Rom *rom, int mode);
@ -61,11 +53,7 @@ private:
void Destroy();
private:
bool m_bLoaded;
int m_romListMode;
string m_szRomPath;
};

View File

@ -215,13 +215,6 @@ void CSurface::SetOpacity(byte opacity)
m_byOpacity = opacity;
}
void CSurface::SetTint(byte r, byte g, byte b)
{
m_byR = r;
m_byG = g;
m_byB = b;
}
void CSurface::MoveTo(int x, int y)
{
m_x = x;

View File

@ -43,7 +43,6 @@ public:
* Set functions
*/
void SetOpacity(byte opacity);
void SetTint(byte r, byte g, byte b);
void MoveTo(int x, int y);