*Moved wii.spiffy360.com url in theme downloader a bit down (wasn't shown on some TVs)

*Moved font cache to mem2 (seems to fix the font issues)
*Moved thread start of free space getting out of the constructor (caused a few freezes on start up)
*Added destroy of sound handler when closing app
This commit is contained in:
dimok321 2011-01-02 13:56:24 +00:00
parent 2ea5a823e0
commit 9480208373
10 changed files with 374 additions and 382 deletions

View File

@ -146,7 +146,7 @@ extern "C" bool CheckFile(const char * filepath)
char dirnoslash[strlen(filepath)+2];
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
if(dirnoslash[strlen(dirnoslash)-1] == '/')
while(dirnoslash[strlen(dirnoslash)-1] == '/')
dirnoslash[strlen(dirnoslash)-1] = '\0';
char * notRoot = strrchr(dirnoslash, '/');

View File

@ -21,6 +21,7 @@
*/
#include "FreeTypeGX.h"
#include "memory/mem2.h"
using namespace std;
@ -228,7 +229,7 @@ void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
{
int length = ((((charData->textureWidth + 3) >> 2) * ((charData->textureHeight + 3) >> 2) * 32 * 2 + 31) & ~31);
uint8_t * glyphData = (uint8_t *) memalign(32, length);
uint8_t * glyphData = (uint8_t *) MEM2_alloc(length);
if (!glyphData) return;
memset(glyphData, 0x00, length);

View File

@ -24,7 +24,6 @@ GuiBGM::~GuiBGM()
ClearList();
}
;
void GuiBGM::SetLoop(u8 l)
{

View File

@ -1,3 +1,4 @@
#include "mem2.h"
#include "mem2alloc.hpp"
@ -5,6 +6,7 @@
#include <string.h>
#define MEM2_PRIORITY_SIZE 2097152 //2MB
// Forbid the use of MEM2 through malloc
u32 MALLOC_MEM2 = 0;
@ -68,15 +70,13 @@ extern "C"
if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)
{
p = MEM2_alloc(size);
if (p != 0)
{
if (p != 0) {
return p;
}
return __real_malloc(size);
}
p = __real_malloc(size);
if (p != 0)
{
if (p != 0) {
return p;
}
return MEM2_alloc(size);
@ -96,13 +96,11 @@ extern "C"
return __real_calloc(n, size);
}
p = __real_calloc(n, size);
if (p != 0)
{
if (p != 0) {
return p;
}
p = MEM2_alloc(n * size);
if (p != 0)
{
if (p != 0) {
memset(p, 0, n * size);
}
return p;
@ -116,16 +114,14 @@ extern "C"
if (a <= 32 && 32 % a == 0)
{
p = MEM2_alloc(size);
if (p != 0)
{
if (p != 0) {
return p;
}
}
return __real_memalign(a, size);
}
p = __real_memalign(a, size);
if (p != 0 || a > 32 || 32 % a != 0)
{
if (p != 0 || a > 32 || 32 % a != 0) {
return p;
}
@ -134,7 +130,8 @@ extern "C"
void __wrap_free(void *p)
{
if (!p) return;
if(!p)
return;
if (((u32)p & 0x10000000) != 0)
{
@ -153,13 +150,11 @@ extern "C"
if (((u32)p & 0x10000000) != 0 || (p == 0 && g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE))
{
n = MEM2_realloc(p, size);
if (n != 0)
{
if (n != 0) {
return n;
}
n = __real_malloc(size);
if (n == 0)
{
if (n == 0) {
return 0;
}
if (p != 0)
@ -171,13 +166,11 @@ extern "C"
}
// ptr from malloc
n = __real_realloc(p, size);
if (n != 0)
{
if (n != 0) {
return n;
}
n = MEM2_alloc(size);
if (n == 0)
{
if (n == 0) {
return 0;
}
if (p != 0)
@ -190,7 +183,8 @@ extern "C"
size_t __wrap_malloc_usable_size(void *p)
{
if (((u32) p & 0x10000000) != 0) return MEM2_usableSize(p);
if (((u32)p & 0x10000000) != 0)
return MEM2_usableSize(p);
return __real_malloc_usable_size(p);
}

View File

@ -5,12 +5,9 @@
#define __MEM2_H_
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#include <gctypes.h>
void MEM2_init(unsigned int mem2Size);
void MEM2_cleanup(void);
void MEM2_takeBigOnes(bool b);

View File

@ -1,22 +1,17 @@
#include "mem2alloc.hpp"
#include <ogc/system.h>
#include <algorithm>
#include <string.h>
class LockMutex
{
mutex_t &m_mutex;
public:
LockMutex(mutex_t &m) :
m_mutex(m)
{
LWP_MutexLock(m_mutex);
}
~LockMutex(void)
{
LWP_MutexUnlock(m_mutex);
}
LockMutex(mutex_t &m) : m_mutex(m) { LWP_MutexLock(m_mutex); }
~LockMutex(void) { LWP_MutexUnlock(m_mutex); }
};
void CMEM2Alloc::init(unsigned int size)
@ -42,7 +37,8 @@ void CMEM2Alloc::cleanup(void)
m_mutex = 0;
m_first = 0;
// Try to release the range we took through SYS functions
if (SYS_GetArena2Lo() == m_endAddress) SYS_SetArena2Lo(m_baseAddress);
if (SYS_GetArena2Lo() == m_endAddress)
SYS_SetArena2Lo(m_baseAddress);
m_baseAddress = 0;
m_endAddress = 0;
}
@ -60,7 +56,8 @@ unsigned int CMEM2Alloc::usableSize(void *p)
void *CMEM2Alloc::allocate(unsigned int s)
{
if (s == 0) s = 1;
if (s == 0)
s = 1;
//
LockMutex lock(m_mutex);
//
@ -68,7 +65,8 @@ void *CMEM2Alloc::allocate(unsigned int s)
// First block
if (m_first == 0)
{
if (m_baseAddress + s + 1 >= m_endAddress) return 0;
if (m_baseAddress + s + 1 >= m_endAddress)
return 0;
m_first = m_baseAddress;
m_first->next = 0;
m_first->prev = 0;
@ -81,14 +79,16 @@ void *CMEM2Alloc::allocate(unsigned int s)
SBlock *j;
for (i = m_first; i != 0; i = i->next)
{
if (i->f && i->s >= s) break;
if (i->f && i->s >= s)
break;
j = i;
}
// Create a new block
if (i == 0)
{
i = j + j->s + 1;
if (i + s + 1 >= m_endAddress) return 0;
if (i + s + 1 >= m_endAddress)
return 0;
j->next = i;
i->prev = j;
i->next = 0;
@ -108,14 +108,16 @@ void *CMEM2Alloc::allocate(unsigned int s)
j->next = i->next;
j->prev = i;
i->next = j;
if (j->next != 0) j->next->prev = j;
if (j->next != 0)
j->next->prev = j;
}
return (void *)(i + 1);
}
void CMEM2Alloc::release(void *p)
{
if (p == 0) return;
if (p == 0)
return;
LockMutex lock(m_mutex);
SBlock *i = (SBlock *)p - 1;
@ -123,7 +125,8 @@ void CMEM2Alloc::release(void *p)
// If there are no other blocks following yet,
// set the remaining size to free size. - Dimok
if (i->next == 0) i->s = m_endAddress - i - 1;
if(i->next == 0)
i->s = m_endAddress - i - 1;
// Merge with previous block
if (i->prev != 0 && i->prev->f)
@ -131,14 +134,16 @@ void CMEM2Alloc::release(void *p)
i = i->prev;
i->s += i->next->s + 1;
i->next = i->next->next;
if (i->next != 0) i->next->prev = i;
if (i->next != 0)
i->next->prev = i;
}
// Merge with next block
if (i->next != 0 && i->next->f)
{
i->s += i->next->s + 1;
i->next = i->next->next;
if (i->next != 0) i->next->prev = i;
if (i->next != 0)
i->next->prev = i;
}
}
@ -148,8 +153,10 @@ void *CMEM2Alloc::reallocate(void *p, unsigned int s)
SBlock *j;
void *n;
if (s == 0) s = 1;
if (p == 0) return allocate(s);
if (s == 0)
s = 1;
if (p == 0)
return allocate(s);
i = (SBlock *)p - 1;
s = (s - 1) / sizeof (SBlock) + 1;
@ -174,7 +181,8 @@ void *CMEM2Alloc::reallocate(void *p, unsigned int s)
// Merge
i->s += i->next->s + 1;
i->next = i->next->next;
if (i->next != 0) i->next->prev = i;
if (i->next != 0)
i->next->prev = i;
}
// Size <= current size
if (i->s >= s)
@ -189,14 +197,16 @@ void *CMEM2Alloc::reallocate(void *p, unsigned int s)
j->next = i->next;
j->prev = i;
i->next = j;
if (j->next != 0) j->next->prev = j;
if (j->next != 0)
j->next->prev = j;
}
return p;
}
}
// Size > current size
n = allocate(s * sizeof (SBlock));
if (n == 0) return 0;
if (n == 0)
return 0;
memcpy(n, p, i->s * sizeof (SBlock));
release(p);
return n;
@ -206,7 +216,8 @@ unsigned int CMEM2Alloc::FreeSize()
{
LockMutex lock(m_mutex);
if (m_first == 0) return (const char *) m_endAddress - (const char *) m_baseAddress;
if (m_first == 0)
return (const char *) m_endAddress - (const char *) m_baseAddress;
SBlock *i;
unsigned int size = 0;
@ -219,7 +230,8 @@ unsigned int CMEM2Alloc::FreeSize()
else if(i->f && i->next == 0)
size += m_endAddress - i - 1;
else if (!i->f && i->next == 0) size += m_endAddress - i - i->s - 1;
else if(!i->f && i->next == 0)
size += m_endAddress - i - i->s - 1;
}
return size*sizeof(SBlock);

View File

@ -17,25 +17,12 @@ class CMEM2Alloc
void cleanup(void);
void clear(void);
static unsigned int usableSize(void *p);
void forceEndAddress(void *newAddr)
{
m_endAddress = (SBlock *) newAddr;
}
void *getEndAddress(void) const
{
return m_endAddress;
}
void info(void *&address, unsigned int &size) const
{
address = m_baseAddress;
size = (const char *) m_endAddress - (const char *) m_baseAddress;
}
void forceEndAddress(void *newAddr) { m_endAddress = (SBlock *)newAddr; }
void *getEndAddress(void) const { return m_endAddress; }
void info(void *&address, unsigned int &size) const { address = m_baseAddress; size = (const char *)m_endAddress - (const char *)m_baseAddress; }
unsigned int FreeSize();
//
CMEM2Alloc(void) :
m_baseAddress(0), m_endAddress(0), m_first(0), m_mutex(0)
{
}
CMEM2Alloc(void) : m_baseAddress(0), m_endAddress(0), m_first(0), m_mutex(0) { }
private:
struct SBlock
{

View File

@ -108,13 +108,6 @@ GameBrowseMenu::GameBrowseMenu()
usedSpaceTxt->SetAlignment(thAlign("center - hdd info align hor"), thAlign("top - hdd info align ver"));
usedSpaceTxt->SetPosition(thInt("0 - hdd info pos x"), thInt("400 - hdd info pos y"));
if(Settings.ShowFreeSpace)
{
HDDSizeCallback.SetCallback(this, &GameBrowseMenu::UpdateFreeSpace);
ThreadedTask::Instance()->AddCallback(&HDDSizeCallback);
ThreadedTask::Instance()->Execute();
}
gamecntTxt = new GuiText((char *) NULL, 18, thColor("r=55 g=190 b=237 a=255 - game count color"));
gamecntBtn = new GuiButton(100, 18);
gamecntBtn->SetAlignment(thAlign("center - game count align hor"), thAlign("top - game count align ver"));
@ -716,6 +709,13 @@ int GameBrowseMenu::Show()
{
int menu = MENU_NONE;
if(Settings.ShowFreeSpace)
{
HDDSizeCallback.SetCallback(this, &GameBrowseMenu::UpdateFreeSpace);
ThreadedTask::Instance()->AddCallback(&HDDSizeCallback);
ThreadedTask::Instance()->Execute();
}
while(menu == MENU_NONE)
{
usleep(100);

View File

@ -13,6 +13,7 @@
#include "usbloader/playlog.h"
#include "usbloader/wbfs.h"
#include "themes/CTheme.h"
#include "SoundOperations/SoundHandler.hpp"
#include "utils/ThreadedTask.hpp"
#include "audio.h"
#include "lstub.h"
@ -67,11 +68,12 @@ void AppCleanUp(void)
Settings.Save();
ExitGUIThreads();
StopGX();
delete bgMusic;
delete btnSoundClick;
delete btnSoundOver;
delete btnSoundClick2;
delete bgMusic;
delete background;
delete bgImg;
delete mainWindow;
@ -83,9 +85,9 @@ void AppCleanUp(void)
Theme::CleanUp();
NewTitles::DestroyInstance();
ThreadedTask::DestroyInstance();
SoundHandler::DestroyInstance();
DeinitNetwork();
StopGX();
ShutdownAudio();
ResourceManager::DestroyInstance();

View File

@ -47,7 +47,7 @@ ThemeDownloader::ThemeDownloader()
urlTxt = new GuiText(tr( "Themes by www.spiffy360.com" ), 22, (GXColor) {255, 255, 255, 255});
urlTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
urlTxt->SetPosition(350, 3);
urlTxt->SetPosition(350, 12);
Append(urlTxt);
for(int i = 0; i < 4; ++i)