*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;
@ -15,75 +17,73 @@ static bool g_bigGoesToMem2 = false;
extern "C"
{
void MEM2_takeBigOnes(bool b)
{
void MEM2_takeBigOnes(bool b)
{
g_bigGoesToMem2 = b;
}
}
void MEM2_init(unsigned int mem2Size)
{
void MEM2_init(unsigned int mem2Size)
{
g_mem2gp.init(mem2Size);
}
}
void MEM2_cleanup(void)
{
void MEM2_cleanup(void)
{
g_mem2gp.cleanup();
}
}
void *MEM2_alloc(unsigned int s)
{
void *MEM2_alloc(unsigned int s)
{
return g_mem2gp.allocate(s);
}
}
void MEM2_free(void *p)
{
void MEM2_free(void *p)
{
g_mem2gp.release(p);
}
}
void *MEM2_realloc(void *p, unsigned int s)
{
void *MEM2_realloc(void *p, unsigned int s)
{
return g_mem2gp.reallocate(p, s);
}
}
unsigned int MEM2_usableSize(void *p)
{
unsigned int MEM2_usableSize(void *p)
{
return CMEM2Alloc::usableSize(p);
}
}
unsigned int MEM2_freesize()
{
unsigned int MEM2_freesize()
{
return g_mem2gp.FreeSize();
}
}
extern __typeof( malloc ) __real_malloc;
extern __typeof( calloc ) __real_calloc;
extern __typeof( realloc ) __real_realloc;
extern __typeof( memalign ) __real_memalign;
extern __typeof( free ) __real_free;
extern __typeof( malloc_usable_size ) __real_malloc_usable_size;
extern __typeof(malloc) __real_malloc;
extern __typeof(calloc) __real_calloc;
extern __typeof(realloc) __real_realloc;
extern __typeof(memalign) __real_memalign;
extern __typeof(free) __real_free;
extern __typeof(malloc_usable_size) __real_malloc_usable_size;
void *__wrap_malloc(size_t size)
{
void *__wrap_malloc(size_t size)
{
void *p;
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);
}
}
void *__wrap_calloc(size_t n, size_t size)
{
void *__wrap_calloc(size_t n, size_t size)
{
void *p;
if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)
{
@ -96,47 +96,44 @@ 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;
}
}
void *__wrap_memalign(size_t a, size_t size)
{
void *__wrap_memalign(size_t a, size_t size)
{
void *p;
if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)
{
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;
}
return MEM2_alloc(size);
}
}
void __wrap_free(void *p)
{
if (!p) return;
void __wrap_free(void *p)
{
if(!p)
return;
if (((u32) p & 0x10000000) != 0)
if (((u32)p & 0x10000000) != 0)
{
MEM2_free(p);
}
@ -144,22 +141,20 @@ extern "C"
{
__real_free(p);
}
}
}
void *__wrap_realloc(void *p, size_t size)
{
void *__wrap_realloc(void *p, size_t size)
{
void *n;
// ptr from mem2
if (((u32) p & 0x10000000) != 0 || (p == 0 && g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE))
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)
@ -186,12 +179,13 @@ extern "C"
__real_free(p);
}
return n;
}
}
size_t __wrap_malloc_usable_size(void *p)
{
if (((u32) p & 0x10000000) != 0) return MEM2_usableSize(p);
size_t __wrap_malloc_usable_size(void *p)
{
if (((u32)p & 0x10000000) != 0)
return MEM2_usableSize(p);
return __real_malloc_usable_size(p);
}
}
} ///extern "C"

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,28 +1,23 @@
#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);
}
public:
LockMutex(mutex_t &m) : m_mutex(m) { LWP_MutexLock(m_mutex); }
~LockMutex(void) { LWP_MutexUnlock(m_mutex); }
};
void CMEM2Alloc::init(unsigned int size)
{
m_baseAddress = (SBlock *) (((u32) SYS_GetArena2Lo() + 31) & ~31);
m_endAddress = (SBlock *) ((char *) m_baseAddress + std::min(size * 0x100000, SYS_GetArena2Size() & ~31));
m_baseAddress = (SBlock *) (((u32)SYS_GetArena2Lo() + 31) & ~31);
m_endAddress = (SBlock *) ((char *)m_baseAddress + std::min(size * 0x100000, SYS_GetArena2Size() & ~31));
if (m_endAddress > (SBlock *) 0x93300000) //rest is reserved for usb/usb2/network and other stuff... (0xE0000 bytes)
m_endAddress = (SBlock *) 0x93300000;
SYS_SetArena2Lo(m_endAddress);
@ -31,8 +26,8 @@ void CMEM2Alloc::init(unsigned int size)
void CMEM2Alloc::init(void *addr, void *end)
{
m_baseAddress = (SBlock *) (((u32) addr + 31) & ~31);
m_endAddress = (SBlock *) ((u32) end & ~31);
m_baseAddress = (SBlock *)(((u32)addr + 31) & ~31);
m_endAddress = (SBlock *)((u32)end & ~31);
LWP_MutexInit(&m_mutex, 0);
}
@ -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;
}
@ -50,51 +46,55 @@ void CMEM2Alloc::cleanup(void)
void CMEM2Alloc::clear(void)
{
m_first = 0;
memset(m_baseAddress, 0, (u8 *) m_endAddress - (u8 *) m_endAddress);
memset(m_baseAddress, 0, (u8 *)m_endAddress - (u8 *)m_endAddress);
}
unsigned int CMEM2Alloc::usableSize(void *p)
{
return p == 0 ? 0 : ((SBlock *) p - 1)->s * sizeof(SBlock);
return p == 0 ? 0 : ((SBlock *)p - 1)->s * sizeof (SBlock);
}
void *CMEM2Alloc::allocate(unsigned int s)
{
if (s == 0) s = 1;
if (s == 0)
s = 1;
//
LockMutex lock(m_mutex);
//
s = (s - 1) / sizeof(SBlock) + 1;
s = (s - 1) / sizeof (SBlock) + 1;
// 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;
m_first->s = s;
m_first->f = false;
return (void *) (m_first + 1);
return (void *)(m_first + 1);
}
// Search for a free block
SBlock *i;
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;
i->s = s;
i->f = false;
return (void *) (i + 1);
return (void *)(i + 1);
}
// Reuse a free block
i->f = false;
@ -108,22 +108,25 @@ 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);
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;
SBlock *i = (SBlock *)p - 1;
i->f = true;
// 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,11 +153,13 @@ 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;
i = (SBlock *)p - 1;
s = (s - 1) / sizeof (SBlock) + 1;
{
LockMutex lock(m_mutex);
@ -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,15 +197,17 @@ 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;
memcpy(n, p, i->s * sizeof(SBlock));
n = allocate(s * sizeof (SBlock));
if (n == 0)
return 0;
memcpy(n, p, i->s * sizeof (SBlock));
release(p);
return n;
}
@ -206,21 +216,23 @@ 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;
for (i = m_first; i != 0; i = i->next)
for(i = m_first; i != 0; i = i->next)
{
if (i->f && i->next != 0)
if(i->f && i->next != 0)
size += i->s;
else if (i->f && i->next == 0)
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);
return size*sizeof(SBlock);
}

View File

@ -8,7 +8,7 @@
class CMEM2Alloc
{
public:
public:
void *allocate(unsigned int s);
void release(void *p);
void *reallocate(void *p, unsigned int s);
@ -17,38 +17,25 @@ 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)
{
}
private:
CMEM2Alloc(void) : m_baseAddress(0), m_endAddress(0), m_first(0), m_mutex(0) { }
private:
struct SBlock
{
unsigned int s;
SBlock *next;
SBlock *prev;
bool f;
}__attribute__((aligned(32)));
} __attribute__((aligned(32)));
SBlock *m_baseAddress;
SBlock *m_endAddress;
SBlock *m_first;
mutex_t m_mutex;
private:
private:
CMEM2Alloc(const CMEM2Alloc &);
};

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)