- fixed sfx issues on the psp
- removed a few debug strings
This commit is contained in:
wagic.the.homebrew
2008-11-26 14:29:43 +00:00
parent 9b04331415
commit b9e2980952
7 changed files with 193 additions and 217 deletions

View File

@@ -126,22 +126,40 @@ SampleCache * SampleCache::GetInstance(){
}
JSample * SampleCache::getSample(string filename){
map<string,JSample *>::iterator it = cache.find(filename);
map<string,SampleCached *>::iterator it = cache.find(filename);
if (it == cache.end()){
if (cache.size() >10) cleanCache(); //Poor man's limit
if (cache.size() >10) cleanOldest(); //Poor man's limit
JSample * sample = JSoundSystem::GetInstance()->LoadSample(filename.c_str());
if (!sample && fileExists(filename.c_str())){ //Out of Ram ??
cleanCache();
sample = JSoundSystem::GetInstance()->LoadSample(filename.c_str());
}
lastTime++;
cache[filename] = NEW SampleCached(lastTime, sample);
return sample;
}else{
return (it->second);
return (it->second->sample);
}
}
void SampleCache::cleanOldest(){
int smallest = lastTime;
map<string,SampleCached *>::iterator found = cache.end();
map<string,SampleCached *>::iterator it;
for (it = cache.begin(); it != cache.end(); it++){
if(it->second->lastTime <= smallest){
smallest = it->second->lastTime;
found = it;
}
}
if (found != cache.end()){
delete (found->second);
cache.erase(found);
}
}
void SampleCache::cleanCache(){
map<string,JSample *>::iterator it;
map<string,SampleCached *>::iterator it;
for (it = cache.begin(); it != cache.end(); it++){
delete(it->second);
}