-fixed last game you played was not selected

-fixed random codedumps when wiiflow loads a game banner
-gave the cover loader a higher priority
This commit is contained in:
fix94.1 2012-11-04 14:13:42 +00:00
parent 484b8f3909
commit 6b47640bfb
8 changed files with 98 additions and 100 deletions

View File

@ -655,8 +655,7 @@ void CCoverFlow::startCoverLoader(void)
m_loadingCovers = true; m_loadingCovers = true;
m_moved = true; m_moved = true;
unsigned int stack_size = (unsigned int)8192; LWP_CreateThread(&coverLoaderThread, (void*(*)(void*))CCoverFlow::_coverLoader, (void*)this, NULL, 0, 30);
LWP_CreateThread(&coverLoaderThread, (void *(*)(void *))CCoverFlow::_coverLoader, (void *)this, 0, stack_size, 20);
//gprintf("Coverflow started!\n"); //gprintf("Coverflow started!\n");
} }

View File

@ -127,7 +127,7 @@ CMenu::CMenu()
m_mutex = 0; m_mutex = 0;
m_showtimer = 0; m_showtimer = 0;
m_gameSoundThread = LWP_THREAD_NULL; m_gameSoundThread = LWP_THREAD_NULL;
m_gameSoundHdr = NULL; m_soundThrdBusy = false;
m_numCFVersions = 0; m_numCFVersions = 0;
m_bgCrossFade = 0; m_bgCrossFade = 0;
m_bnrSndVol = 0; m_bnrSndVol = 0;
@ -498,7 +498,6 @@ void CMenu::cleanup()
_Theme_Cleanup(); _Theme_Cleanup();
MusicPlayer.Cleanup(); MusicPlayer.Cleanup();
m_gameSound.FreeMemory(); m_gameSound.FreeMemory();
ClearGameSoundThreadStack();
SoundHandle.Cleanup(); SoundHandle.Cleanup();
soundDeinit(); soundDeinit();
@ -648,10 +647,10 @@ void CMenu::_loadCFCfg()
m_cf.setBufferSize(m_cfg.getInt("GENERAL", "cover_buffer", 20)); m_cf.setBufferSize(m_cfg.getInt("GENERAL", "cover_buffer", 20));
// Coverflow Sounds // Coverflow Sounds
m_cf.setSounds( m_cf.setSounds(
new GuiSound(sfmt("%s/%s", m_themeDataDir.c_str(), m_theme.getString(domain, "sound_flip").c_str())), new GuiSound(fmt("%s/%s", m_themeDataDir.c_str(), m_theme.getString(domain, "sound_flip").c_str())),
_sound(theme.soundSet, domain, "sound_hover", hover_wav, hover_wav_size, string("default_btn_hover"), false), _sound(theme.soundSet, domain, "sound_hover", hover_wav, hover_wav_size, "default_btn_hover", false),
_sound(theme.soundSet, domain, "sound_select", click_wav, click_wav_size, string("default_btn_click"), false), _sound(theme.soundSet, domain, "sound_select", click_wav, click_wav_size, "default_btn_click", false),
new GuiSound(sfmt("%s/%s", m_themeDataDir.c_str(), m_theme.getString(domain, "sound_cancel").c_str())) new GuiSound(fmt("%s/%s", m_themeDataDir.c_str(), m_theme.getString(domain, "sound_cancel").c_str()))
); );
// Textures // Textures
string texLoading = sfmt("%s/%s", m_themeDataDir.c_str(), m_theme.getString(domain, "loading_cover_box").c_str()); string texLoading = sfmt("%s/%s", m_themeDataDir.c_str(), m_theme.getString(domain, "loading_cover_box").c_str());
@ -956,9 +955,9 @@ void CMenu::_buildMenus(void)
theme.selubtnFontColor = m_theme.getColor("GENERAL", "selubtn_font_color", 0xD0BFDFFF); theme.selubtnFontColor = m_theme.getColor("GENERAL", "selubtn_font_color", 0xD0BFDFFF);
// Default Sounds // Default Sounds
theme.clickSound = _sound(theme.soundSet, "GENERAL", "click_sound", click_wav, click_wav_size, string("default_btn_click"), false); theme.clickSound = _sound(theme.soundSet, "GENERAL", "click_sound", click_wav, click_wav_size, "default_btn_click", false);
theme.hoverSound = _sound(theme.soundSet, "GENERAL", "hover_sound", hover_wav, hover_wav_size, string("default_btn_hover"), false); theme.hoverSound = _sound(theme.soundSet, "GENERAL", "hover_sound", hover_wav, hover_wav_size, "default_btn_hover", false);
theme.cameraSound = _sound(theme.soundSet, "GENERAL", "camera_sound", camera_wav, camera_wav_size, string("default_camera"), false); theme.cameraSound = _sound(theme.soundSet, "GENERAL", "camera_sound", camera_wav, camera_wav_size, "default_camera", false);
// Default textures // Default textures
theme.btnTexL.fromPNG(butleft_png); theme.btnTexL.fromPNG(butleft_png);
@ -1284,39 +1283,40 @@ STexture CMenu::_texture(const char *domain, const char *key, STexture &def, boo
} }
// Only for loading defaults and GENERAL domains!! // Only for loading defaults and GENERAL domains!!
GuiSound *CMenu::_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const u8 * snd, u32 len, string name, bool isAllocated) GuiSound *CMenu::_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const u8 * snd, u32 len, const char *name, bool isAllocated)
{ {
string filename = m_theme.getString(domain, key, ""); const char *filename = m_theme.getString(domain, key, "").c_str();
if (filename.empty()) filename = name; if(filename == NULL)
filename = name;
CMenu::SoundSet::iterator i = soundSet.find(upperCase(filename.c_str())); CMenu::SoundSet::iterator i = soundSet.find(upperCase(filename));
if (i == soundSet.end()) if(i == soundSet.end())
{ {
if(strncmp(filename.c_str(), name.c_str(), name.size()) != 0) if(strncmp(filename, name, strlen(name) != 0))
soundSet[upperCase(filename.c_str())] = new GuiSound(fmt("%s/%s", m_themeDataDir.c_str(), filename.c_str())); soundSet[upperCase(filename)] = new GuiSound(fmt("%s/%s", m_themeDataDir.c_str(), filename));
else else
soundSet[upperCase(filename.c_str())] = new GuiSound(snd, len, filename, isAllocated); soundSet[upperCase(filename)] = new GuiSound(snd, len, filename, isAllocated);
return soundSet[upperCase(filename.c_str())]; return soundSet[upperCase(filename)];
} }
return i->second; return i->second;
} }
//For buttons and labels only!! //For buttons and labels only!!
GuiSound *CMenu::_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, string name) GuiSound *CMenu::_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const char *name)
{ {
string filename = m_theme.getString(domain, key); const char *filename = m_theme.getString(domain, key).c_str();
if (filename.empty()) if(filename == NULL)
{ {
if(name.find_last_of('/') != string::npos) if(strrchr(name, '/') != NULL)
name = name.substr(name.find_last_of('/')+1); name = strrchr(name, '/') + 1;
return soundSet[upperCase(name.c_str())]; // General/Default are already cached! return soundSet[upperCase(name)]; // General/Default are already cached!
} }
SoundSet::iterator i = soundSet.find(upperCase(filename.c_str())); SoundSet::iterator i = soundSet.find(upperCase(filename));
if (i == soundSet.end()) if(i == soundSet.end())
{ {
soundSet[upperCase(filename.c_str())] = new GuiSound(fmt("%s/%s", m_themeDataDir.c_str(), filename.c_str())); soundSet[upperCase(filename)] = new GuiSound(fmt("%s/%s", m_themeDataDir.c_str(), filename));
return soundSet[upperCase(filename.c_str())]; return soundSet[upperCase(filename)];
} }
return i->second; return i->second;
} }
@ -1907,9 +1907,10 @@ void CMenu::_initCF(void)
m_cf.setBufferSize(m_cfg.getInt("GENERAL", "cover_buffer", 20)); m_cf.setBufferSize(m_cfg.getInt("GENERAL", "cover_buffer", 20));
m_cf.setSorting((Sorting)m_cfg.getInt(domain, "sort", 0)); m_cf.setSorting((Sorting)m_cfg.getInt(domain, "sort", 0));
m_cf.setHQcover(m_cfg.getBool("GENERAL", "cover_use_hq", false)); m_cf.setHQcover(m_cfg.getBool("GENERAL", "cover_use_hq", false));
m_cf.start();
if (m_curGameId.empty() || !m_cf.findId(m_curGameId.c_str(), true)) if (m_curGameId.empty() || !m_cf.findId(m_curGameId.c_str(), true))
m_cf.findId(m_cfg.getString(domain, "current_item").c_str(), true); m_cf.findId(m_cfg.getString(domain, "current_item").c_str(), true);
m_cf.start();
} }
void CMenu::_mainLoopCommon(bool withCF, bool adjusting) void CMenu::_mainLoopCommon(bool withCF, bool adjusting)
@ -1975,7 +1976,7 @@ void CMenu::_mainLoopCommon(bool withCF, bool adjusting)
if(Sys_Exiting()) if(Sys_Exiting())
exitHandler(BUTTON_CALLBACK); exitHandler(BUTTON_CALLBACK);
if(withCF && m_gameSelected && m_gamesound_changed && (m_gameSoundHdr == NULL) && !m_gameSound.IsPlaying() && MusicPlayer.GetVolume() == 0) if(withCF && m_gameSelected && m_gamesound_changed && !m_soundThrdBusy && !m_gameSound.IsPlaying() && MusicPlayer.GetVolume() == 0)
{ {
CheckGameSoundThread(); CheckGameSoundThread();
m_gameSound.Play(m_bnrSndVol); m_gameSound.Play(m_bnrSndVol);

View File

@ -63,7 +63,6 @@ private:
Config m_theme; Config m_theme;
Config m_titles; Config m_titles;
Config m_version; Config m_version;
Plugin m_plugin;
vector<string> m_homebrewArgs; vector<string> m_homebrewArgs;
u8 *m_base_font; u8 *m_base_font;
u32 m_base_font_size; u32 m_base_font_size;
@ -661,7 +660,7 @@ private:
volatile bool m_thrdMessageAdded; volatile bool m_thrdMessageAdded;
volatile bool m_gameSelected; volatile bool m_gameSelected;
GuiSound m_gameSound; GuiSound m_gameSound;
dir_discHdr *m_gameSoundHdr; volatile bool m_soundThrdBusy;
lwp_t m_gameSoundThread; lwp_t m_gameSoundThread;
bool m_gamesound_changed; bool m_gamesound_changed;
u8 m_bnrSndVol; u8 m_bnrSndVol;
@ -1004,8 +1003,8 @@ public:
void _hideWaitMessage(); void _hideWaitMessage();
bool m_Emulator_boot; bool m_Emulator_boot;
private: private:
GuiSound *_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const u8 * snd, u32 len, string name, bool isAllocated); GuiSound *_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const u8 * snd, u32 len, const char *name, bool isAllocated);
GuiSound *_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, string name); GuiSound *_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const char *name);
u16 _textStyle(const char *domain, const char *key, u16 def); u16 _textStyle(const char *domain, const char *key, u16 def);
s16 _addButton(const char *domain, SFont font, const wstringEx &text, int x, int y, u32 width, u32 height, const CColor &color); s16 _addButton(const char *domain, SFont font, const wstringEx &text, int x, int y, u32 width, u32 height, const CColor &color);
s16 _addSelButton(const char *domain, SFont font, const wstringEx &text, int x, int y, u32 width, u32 height, const CColor &color); s16 _addSelButton(const char *domain, SFont font, const wstringEx &text, int x, int y, u32 width, u32 height, const CColor &color);
@ -1065,7 +1064,6 @@ private:
void _playGameSound(void); void _playGameSound(void);
void CheckGameSoundThread(void); void CheckGameSoundThread(void);
void ClearGameSoundThreadStack(void);
static void _gameSoundThread(CMenu *m); static void _gameSoundThread(CMenu *m);
static void _load_installed_cioses(); static void _load_installed_cioses();

View File

@ -421,7 +421,6 @@ void CMenu::_game(bool launch)
{ {
m_gameSound.FreeMemory(); m_gameSound.FreeMemory();
CheckGameSoundThread(); CheckGameSoundThread();
ClearGameSoundThreadStack();
m_banner.DeleteBanner(); m_banner.DeleteBanner();
break; break;
} }
@ -509,7 +508,6 @@ void CMenu::_game(bool launch)
{ {
m_gameSound.FreeMemory(); m_gameSound.FreeMemory();
CheckGameSoundThread(); CheckGameSoundThread();
ClearGameSoundThreadStack();
m_banner.DeleteBanner(); m_banner.DeleteBanner();
break; break;
} }
@ -527,7 +525,6 @@ void CMenu::_game(bool launch)
{ {
m_gameSound.FreeMemory(); m_gameSound.FreeMemory();
CheckGameSoundThread(); CheckGameSoundThread();
ClearGameSoundThreadStack();
m_banner.DeleteBanner(); m_banner.DeleteBanner();
break; break;
} }
@ -556,7 +553,6 @@ void CMenu::_game(bool launch)
MusicPlayer.Stop(); MusicPlayer.Stop();
m_gameSound.FreeMemory(); m_gameSound.FreeMemory();
CheckGameSoundThread(); CheckGameSoundThread();
ClearGameSoundThreadStack();
m_banner.DeleteBanner(); m_banner.DeleteBanner();
dir_discHdr *hdr = m_cf.getHdr(); dir_discHdr *hdr = m_cf.getHdr();
m_gcfg2.load(fmt("%s/" GAME_SETTINGS2_FILENAME, m_settingsDir.c_str())); m_gcfg2.load(fmt("%s/" GAME_SETTINGS2_FILENAME, m_settingsDir.c_str()));
@ -1466,19 +1462,20 @@ struct IMD5Header
u8 crypto[16]; u8 crypto[16];
} __attribute__((packed)); } __attribute__((packed));
u8 *gameSoundThreadStack;
u32 gameSoundThreadStackSize = (u32)32768;
void CMenu::_gameSoundThread(CMenu *m) void CMenu::_gameSoundThread(CMenu *m)
{ {
CurrentBanner.ClearBanner(); m->m_soundThrdBusy = true;
m->m_gameSoundHdr = m->m_cf.getHdr();
m->m_gamesound_changed = false; m->m_gamesound_changed = false;
if(m->m_cf.getHdr()->type == TYPE_PLUGIN) CurrentBanner.ClearBanner();
dir_discHdr *GameHdr = m->m_cf.getHdr();
if(GameHdr->type == TYPE_PLUGIN)
{ {
m_banner.DeleteBanner(); m_banner.DeleteBanner();
m->m_gameSound.Load(m->m_plugin.GetBannerSound(m->m_cf.getHdr()->settings[0]), m->m_plugin.GetBannerSoundSize()); m->m_gameSound.Load(m_plugin.GetBannerSound(GameHdr->settings[0]), m_plugin.GetBannerSoundSize());
m->m_gamesound_changed = true; if(m->m_gameSound.IsLoaded())
m->m_gameSoundHdr = NULL; m->m_gamesound_changed = true;
m->m_soundThrdBusy = false;
return; return;
} }
bool custom = false; bool custom = false;
@ -1491,7 +1488,7 @@ void CMenu::_gameSoundThread(CMenu *m)
char cached_banner[256]; char cached_banner[256];
cached_banner[255] = '\0'; cached_banner[255] = '\0';
strncpy(cached_banner, fmt("%s/%.6s.bnr", m->m_bnrCacheDir.c_str(), m->m_cf.getHdr()->id), 255); strncpy(cached_banner, fmt("%s/%.6s.bnr", m->m_bnrCacheDir.c_str(), GameHdr->id), 255);
FILE *fp = fopen(cached_banner, "rb"); FILE *fp = fopen(cached_banner, "rb");
if(fp) if(fp)
{ {
@ -1504,7 +1501,7 @@ void CMenu::_gameSoundThread(CMenu *m)
{ {
m->m_gameSound.FreeMemory(); m->m_gameSound.FreeMemory();
m_banner.DeleteBanner(); m_banner.DeleteBanner();
m->m_gameSoundHdr = NULL; m->m_soundThrdBusy = false;
return; return;
} }
fread(cached_bnr_file, 1, cached_bnr_size, fp); fread(cached_bnr_file, 1, cached_bnr_size, fp);
@ -1514,11 +1511,11 @@ void CMenu::_gameSoundThread(CMenu *m)
{ {
char custom_banner[256]; char custom_banner[256];
custom_banner[255] = '\0'; custom_banner[255] = '\0';
strncpy(custom_banner, fmt("%s/%.6s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id), 255); strncpy(custom_banner, fmt("%s/%.6s.bnr", m->m_customBnrDir.c_str(), GameHdr->id), 255);
FILE *fp = fopen(custom_banner, "rb"); FILE *fp = fopen(custom_banner, "rb");
if(!fp) if(!fp)
{ {
strncpy(custom_banner, fmt("%s/%.3s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id), 255); strncpy(custom_banner, fmt("%s/%.3s.bnr", m->m_customBnrDir.c_str(), GameHdr->id), 255);
fp = fopen(custom_banner, "rb"); fp = fopen(custom_banner, "rb");
} }
if(fp) if(fp)
@ -1532,23 +1529,25 @@ void CMenu::_gameSoundThread(CMenu *m)
{ {
m->m_gameSound.FreeMemory(); m->m_gameSound.FreeMemory();
m_banner.DeleteBanner(); m_banner.DeleteBanner();
m->m_gameSoundHdr = NULL; m->m_soundThrdBusy = false;
return; return;
} }
fread(custom_bnr_file, 1, custom_bnr_size, fp); fread(custom_bnr_file, 1, custom_bnr_size, fp);
fclose(fp); fclose(fp);
} }
if(!fp && m->m_cf.getHdr()->type == TYPE_GC_GAME) if(!fp && GameHdr->type == TYPE_GC_GAME)
{ {
GC_Disc disc; GC_Disc disc;
disc.init(m->m_cf.getHdr()->path); disc.init(GameHdr->path);
u8 *opening_bnr = disc.GetGameCubeBanner(); u8 *opening_bnr = disc.GetGameCubeBanner();
if(opening_bnr != NULL) if(opening_bnr != NULL)
m_banner.CreateGCBanner(opening_bnr, m->m_wbf1_font, m->m_wbf2_font, m->m_cf.getHdr()->title); m_banner.CreateGCBanner(opening_bnr, m->m_wbf1_font, m->m_wbf2_font, GameHdr->title);
m->m_gameSound.Load(gc_ogg, gc_ogg_size, false);
m->m_gamesound_changed = true;
m->m_gameSoundHdr = NULL;
disc.clear(); disc.clear();
m->m_gameSound.Load(gc_ogg, gc_ogg_size, false);
if(m->m_gameSound.IsLoaded())
m->m_gamesound_changed = true;
m->m_soundThrdBusy = false;
return; return;
} }
} }
@ -1559,17 +1558,17 @@ void CMenu::_gameSoundThread(CMenu *m)
CurrentBanner.SetBanner(cached_bnr_file, cached_bnr_size); CurrentBanner.SetBanner(cached_bnr_file, cached_bnr_size);
else if(custom) else if(custom)
CurrentBanner.SetBanner(custom_bnr_file, custom_bnr_size, 0, true); CurrentBanner.SetBanner(custom_bnr_file, custom_bnr_size, 0, true);
else if(m->m_gameSoundHdr->type == TYPE_WII_GAME) else if(GameHdr->type == TYPE_WII_GAME)
_extractBnr(m->m_gameSoundHdr); _extractBnr(GameHdr);
else if(m->m_gameSoundHdr->type == TYPE_CHANNEL) else if(GameHdr->type == TYPE_CHANNEL)
_extractChannelBnr(TITLE_ID(m->m_gameSoundHdr->settings[0], _extractChannelBnr(TITLE_ID(GameHdr->settings[0],
m->m_gameSoundHdr->settings[1])); GameHdr->settings[1]));
if(!CurrentBanner.IsValid()) if(!CurrentBanner.IsValid())
{ {
m->m_gameSound.FreeMemory(); m->m_gameSound.FreeMemory();
m_banner.DeleteBanner(); m_banner.DeleteBanner();
m->m_gameSoundHdr = NULL;
CurrentBanner.ClearBanner(); CurrentBanner.ClearBanner();
m->m_soundThrdBusy = false;
return; return;
} }
if(!custom && !cached && CurrentBanner.GetBannerFileSize() > 0) if(!custom && !cached && CurrentBanner.GetBannerFileSize() > 0)
@ -1592,7 +1591,7 @@ void CMenu::_gameSoundThread(CMenu *m)
{ {
m->m_gameSound.FreeMemory(); m->m_gameSound.FreeMemory();
m_banner.DeleteBanner(); m_banner.DeleteBanner();
m->m_gameSoundHdr = NULL; m->m_soundThrdBusy = false;
return; return;
} }
free(soundBin); free(soundBin);
@ -1614,7 +1613,7 @@ void CMenu::_gameSoundThread(CMenu *m)
m->m_gamesound_changed = true; m->m_gamesound_changed = true;
m->m_gameSound.FreeMemory(); m->m_gameSound.FreeMemory();
} }
m->m_gameSoundHdr = NULL; m->m_soundThrdBusy = false;
} }
void CMenu::_playGameSound(void) void CMenu::_playGameSound(void)
@ -1625,9 +1624,7 @@ void CMenu::_playGameSound(void)
if(m_gameSoundThread != LWP_THREAD_NULL) if(m_gameSoundThread != LWP_THREAD_NULL)
CheckGameSoundThread(); CheckGameSoundThread();
if(gameSoundThreadStack == NULL) LWP_CreateThread(&m_gameSoundThread, (void *(*)(void *))CMenu::_gameSoundThread, (void *)this, NULL, 0, 60);
gameSoundThreadStack = (u8*)MEM2_alloc(gameSoundThreadStackSize);
LWP_CreateThread(&m_gameSoundThread, (void *(*)(void *))CMenu::_gameSoundThread, (void *)this, gameSoundThreadStack, gameSoundThreadStackSize, 60);
} }
void CMenu::CheckGameSoundThread() void CMenu::CheckGameSoundThread()
@ -1638,18 +1635,9 @@ void CMenu::CheckGameSoundThread()
if(LWP_ThreadIsSuspended(m_gameSoundThread)) if(LWP_ThreadIsSuspended(m_gameSoundThread))
LWP_ResumeThread(m_gameSoundThread); LWP_ResumeThread(m_gameSoundThread);
while(m_gameSoundHdr != NULL) while(m_soundThrdBusy)
usleep(50); usleep(50);
LWP_JoinThread(m_gameSoundThread, NULL); LWP_JoinThread(m_gameSoundThread, NULL);
m_gameSoundThread = LWP_THREAD_NULL; m_gameSoundThread = LWP_THREAD_NULL;
} }
void CMenu::ClearGameSoundThreadStack()
{
if(gameSoundThreadStack != NULL)
{
free(gameSoundThreadStack);
gameSoundThreadStack = NULL;
}
}

View File

@ -82,19 +82,25 @@ GuiSound::GuiSound()
Init(); Init();
} }
GuiSound::GuiSound(string filepath, int v) GuiSound::GuiSound(const char *path, int v)
{ {
if(path == NULL)
return;
this->voice = v; this->voice = v;
Init(); Init();
Load(filepath.c_str()); Load(path);
} }
GuiSound::GuiSound(const u8 * snd, u32 len, string name, bool isallocated, int v) GuiSound::GuiSound(const u8 * snd, u32 len, const char *name, bool isallocated, int v)
{ {
this->voice = v; this->voice = v;
Init(); Init();
Load(snd, len, isallocated); Load(snd, len, isallocated);
this->filepath = name; if(name != NULL)
{
strncpy(this->filepath, name, 255);
this->filepath[255] = '\0';
}
} }
GuiSound::GuiSound(GuiSound *g) GuiSound::GuiSound(GuiSound *g)
@ -112,7 +118,7 @@ GuiSound::GuiSound(GuiSound *g)
Load(snd, g->length, true); Load(snd, g->length, true);
} }
else else
Load(g->filepath.c_str()); Load(g->filepath);
} }
GuiSound::~GuiSound() GuiSound::~GuiSound()
@ -123,6 +129,7 @@ GuiSound::~GuiSound()
void GuiSound::Init() void GuiSound::Init()
{ {
memset(this->filepath, 0, 256);
sound = NULL; sound = NULL;
length = 0; length = 0;
@ -148,29 +155,29 @@ void GuiSound::FreeMemory()
if(allocated && sound != NULL) if(allocated && sound != NULL)
free(sound); free(sound);
allocated = false; allocated = false;
memset(this->filepath, 0, 256);
sound = NULL; sound = NULL;
length = 0; length = 0;
filepath = "";
SoundEffectLength = 0; SoundEffectLength = 0;
} }
bool GuiSound::Load(const char * filepath) bool GuiSound::Load(const char *path)
{ {
FreeMemory(); FreeMemory();
if(!filepath || filepath[strlen(filepath)-1] == '/' || strlen(filepath) < 4) if(path == NULL || path[strlen(path)-1] == '/')
return false; return false;
FILE * f = fopen(filepath, "rb"); FILE *f = fopen(path, "rb");
if(!f) if(!f)
{ {
gprintf("gui_sound.cpp: Failed to load file %s!!\n", filepath); gprintf("gui_sound.cpp: Failed to load file %s!!\n", path);
return false; return false;
} }
SoundHandle.AddDecoder(this->voice, filepath); SoundHandle.AddDecoder(this->voice, path);
//gprintf("gui_sound.cpp: Loading %s using voice %d\n", filepath, this->voice); //gprintf("gui_sound.cpp: Loading %s using voice %d\n", path, this->voice);
SoundDecoder *decoder = SoundHandle.Decoder(this->voice); SoundDecoder *decoder = SoundHandle.Decoder(this->voice);
if(!decoder) if(!decoder)
{ {
@ -185,13 +192,14 @@ bool GuiSound::Load(const char * filepath)
return false; return false;
} }
this->filepath = filepath; strncpy(this->filepath, path, 255);
this->filepath[255] = '\0'; SetLoop(loop);
SetLoop(loop); SetLoop(loop);
return true; return true;
} }
bool GuiSound::Load(const u8 * snd, u32 len, bool isallocated) bool GuiSound::Load(const u8 *snd, u32 len, bool isallocated)
{ {
FreeMemory(); FreeMemory();

View File

@ -40,14 +40,14 @@ public:
//!Constructor //!Constructor
//!\param sound Pointer to the sound data //!\param sound Pointer to the sound data
//!\param filesize Length of sound data //!\param filesize Length of sound data
GuiSound(std::string filepath, int voice = -1); GuiSound(const char *path, int voice = -1);
GuiSound(const u8 * snd, u32 len, std::string name, bool allocated = false, int voice = -1); GuiSound(const u8 * snd, u32 len, const char *name, bool allocated = false, int voice = -1);
//!Stops sound and frees all memory/closes files //!Stops sound and frees all memory/closes files
void FreeMemory(); void FreeMemory();
//!Destructor //!Destructor
~GuiSound(); ~GuiSound();
//!Load a file and replace the old one //!Load a file and replace the old one
bool Load(const char * filepath); bool Load(const char *path);
//!Load a file and replace the old one //!Load a file and replace the old one
bool Load(const u8 * snd, u32 len, bool allocated = true); bool Load(const u8 * snd, u32 len, bool allocated = true);
//!For quick playback of the internal soundeffects //!For quick playback of the internal soundeffects
@ -67,7 +67,7 @@ public:
bool IsLoaded() { return sound != NULL; }; bool IsLoaded() { return sound != NULL; };
//!Get the filepath for finding sounds which already have an instance. //!Get the filepath for finding sounds which already have an instance.
//!\return the current instance's filepath //!\return the current instance's filepath
std::string GetName() { return filepath; }; const char *GetName() { return filepath; };
//!Checks if the sound is currently playing //!Checks if the sound is currently playing
//!\return true if sound is playing, false otherwise //!\return true if sound is playing, false otherwise
bool IsPlaying(); bool IsPlaying();
@ -89,7 +89,7 @@ private:
//!Initializes the GuiSound object by setting the default values //!Initializes the GuiSound object by setting the default values
void Init(); void Init();
protected: protected:
std::string filepath; char filepath[256];
u8 *sound; //!< Pointer to the sound data u8 *sound; //!< Pointer to the sound data
u32 length; //!< Length of sound data u32 length; //!< Length of sound data
s8 voice; //!< Currently assigned ASND voice channel s8 voice; //!< Currently assigned ASND voice channel

View File

@ -28,6 +28,7 @@
#include "types.h" #include "types.h"
#include "crc32.h" #include "crc32.h"
Plugin m_plugin;
void Plugin::init(const string& m_pluginsDir) void Plugin::init(const string& m_pluginsDir)
{ {
PluginMagicWord[8] = '\0'; PluginMagicWord[8] = '\0';

View File

@ -79,4 +79,7 @@ private:
string pluginsDir; string pluginsDir;
bool adding; bool adding;
}; };
extern Plugin m_plugin;
#endif #endif