- added a cache and thread for loading of native language names to improve speed
This commit is contained in:
parent
6028ff30a6
commit
25fa436318
|
@ -564,14 +564,25 @@ string Lang::getLanguageFile(string uselanguage) {
|
||||||
|
|
||||||
string Lang::getNativeLanguageName(string uselanguage, string testLanguageFile) {
|
string Lang::getNativeLanguageName(string uselanguage, string testLanguageFile) {
|
||||||
string result = uselanguage;
|
string result = uselanguage;
|
||||||
Properties stringsTest;
|
|
||||||
stringsTest.load(testLanguageFile);
|
|
||||||
|
|
||||||
try {
|
static map<string,string> cachedNativeLanguageNames;
|
||||||
result = stringsTest.getString("NativeLanguageName");
|
if(cachedNativeLanguageNames.find(testLanguageFile) != cachedNativeLanguageNames.end()) {
|
||||||
|
result = cachedNativeLanguageNames[testLanguageFile];
|
||||||
}
|
}
|
||||||
//catch(const exception &ex) {
|
else {
|
||||||
catch(...) {
|
Properties stringsTest;
|
||||||
|
stringsTest.load(testLanguageFile);
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = stringsTest.getString("NativeLanguageName");
|
||||||
|
cachedNativeLanguageNames[testLanguageFile] = result;
|
||||||
|
|
||||||
|
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Caching native language name for [%s] = [%s]\n",testLanguageFile.c_str(),result.c_str());
|
||||||
|
printf("Caching native language name for [%s] = [%s]\n",testLanguageFile.c_str(),result.c_str());
|
||||||
|
}
|
||||||
|
//catch(const exception &ex) {
|
||||||
|
catch(...) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -111,6 +111,13 @@ static FileCRCPreCacheThread *preCacheThread = NULL;
|
||||||
static string runtimeErrorMsg = "";
|
static string runtimeErrorMsg = "";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class NavtiveLanguageNameListCacheGenerator : public SimpleTaskCallbackInterface {
|
||||||
|
virtual void simpleTask(BaseThread *callingThread) {
|
||||||
|
Lang &lang = Lang::getInstance();
|
||||||
|
lang.getDiscoveredLanguageList(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void cleanupCRCThread() {
|
void cleanupCRCThread() {
|
||||||
if(preCacheThread != NULL) {
|
if(preCacheThread != NULL) {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
@ -4662,6 +4669,18 @@ int glestMain(int argc, char** argv) {
|
||||||
preCacheThread->start();
|
preCacheThread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::auto_ptr<NavtiveLanguageNameListCacheGenerator> lngCacheGen;
|
||||||
|
std::auto_ptr<SimpleTaskThread> languageCacheGen;
|
||||||
|
|
||||||
|
bool startNativeLanguageNamesPrecacheThread = config.getBool("PreCacheNativeLanguageNamesThread","true");
|
||||||
|
if(startNativeLanguageNamesPrecacheThread == true &&
|
||||||
|
GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) {
|
||||||
|
lngCacheGen.reset(new NavtiveLanguageNameListCacheGenerator());
|
||||||
|
languageCacheGen.reset(new SimpleTaskThread(lngCacheGen.get(),1));
|
||||||
|
|
||||||
|
languageCacheGen->start();
|
||||||
|
}
|
||||||
|
|
||||||
// test
|
// test
|
||||||
//Shared::Platform::MessageBox(NULL,"Mark's test.","Test",0);
|
//Shared::Platform::MessageBox(NULL,"Mark's test.","Test",0);
|
||||||
//throw megaglest_runtime_error("test!");
|
//throw megaglest_runtime_error("test!");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user