summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-11-07 15:57:18 +0300
committerAndrei Karas <akaras@inbox.ru>2013-11-07 15:58:39 +0300
commitcf77bdc4baa273d8750175411cb59af3ca3c07ac (patch)
tree1acc38a0c860096d2ed96451933c1c16dacee0ac
parentc8639374e4ca2c50440b0885e902a0b428836e40 (diff)
downloadmanaverse-cf77bdc4baa273d8750175411cb59af3ca3c07ac.tar.gz
manaverse-cf77bdc4baa273d8750175411cb59af3ca3c07ac.tar.bz2
manaverse-cf77bdc4baa273d8750175411cb59af3ca3c07ac.tar.xz
manaverse-cf77bdc4baa273d8750175411cb59af3ca3c07ac.zip
Split init in client.cpp into separate methods.
-rw-r--r--src/client.cpp503
-rw-r--r--src/client.h18
2 files changed, 289 insertions, 232 deletions
diff --git a/src/client.cpp b/src/client.cpp
index f170946c8..461ce03c8 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -309,92 +309,8 @@ void Client::gameInit()
"Exiting.", mLocalDataDir.c_str()));
}
-#ifdef ANDROID
-#ifdef USE_SDL2
- extractAssets();
-
- const std::string zipName = std::string(getenv(
- "APPDIR")).append("/data.zip");
- const std::string dirName = std::string(getenv(
- "APPDIR")).append("/data");
- Files::extractZip(zipName, "data", dirName);
- Files::extractLocale();
-#endif
-#endif
-
-#if defined __native_client__
-
- const std::string dirName = _nacl_dir.append("/data");
- Files::extractZip("/http/data.zip", "data", dirName);
-#endif
-
-#ifdef ENABLE_NLS
- std::string lang = config.getStringValue("lang");
-#ifdef WIN32
- if (lang.empty())
- lang = std::string(_nl_locale_name_default());
-
- putenv(const_cast<char*>(("LANG=" + lang).c_str()));
- putenv(const_cast<char*>(("LANGUAGE=" + lang).c_str()));
- // mingw doesn't like LOCALEDIR to be defined for some reason
- if (lang != "C")
- bindTextDomain("manaplus", "translations/");
-#else
- if (!lang.empty())
- {
- setEnv("LANG", lang.c_str());
- setEnv("LANGUAGE", lang.c_str());
- }
-#ifdef ANDROID
-#ifdef USE_SDL2
- bindTextDomain("manaplus", (std::string(getenv("APPDIR")).append(
- "/locale")).c_str());
-#else
- bindTextDomain("manaplus", (std::string(PhysFs::getBaseDir())
- .append("/locale")).c_str());
-#endif
-#else
-#ifdef ENABLE_PORTABLE
- bindTextDomain("manaplus", (std::string(PhysFs::getBaseDir())
- .append("../locale/")).c_str());
-#else
-#ifdef __APPLE__
- bindTextDomain("manaplus", (std::string(PhysFs::getBaseDir())
- .append("ManaPlus.app/Contents/Resources/locale/")).c_str());
-#else
- bindTextDomain("manaplus", LOCALEDIR);
-#endif
-#endif
-#endif
-#endif
- char *locale = setlocale(LC_MESSAGES, lang.c_str());
- if (locale)
- {
- logger->log("locale: %s", locale);
- }
- else
- {
- locale = setlocale(LC_MESSAGES, (lang + ".utf8").c_str());
- if (locale)
- logger->log("locale: %s", locale);
- else
- logger->log("locale empty");
- }
- bind_textdomain_codeset("manaplus", "UTF-8");
- textdomain("manaplus");
-#endif
-
-#if defined(WIN32) || defined(__APPLE__)
- if (config.getBoolValue("centerwindow"))
- setEnv("SDL_VIDEO_CENTERED", "1");
- else
- setEnv("SDL_VIDEO_CENTERED", "0");
-#endif
-
- if (config.getBoolValue("allowscreensaver"))
- setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "1");
- else
- setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "0");
+ extractDataDir();
+ initLang();
chatLogger = new ChatLogger;
if (mOptions.chatLogDir.empty())
@@ -432,77 +348,7 @@ void Client::gameInit()
SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
- if (mOptions.test.empty())
- {
- mCaption = strprintf("%s %s",
- branding.getStringValue("appName").c_str(),
- SMALL_VERSION);
- }
- else
- {
- mCaption = strprintf(
- "Please wait - VIDEO MODE TEST - %s %s - Please wait",
- branding.getStringValue("appName").c_str(),
- SMALL_VERSION);
- }
-
- resman->addToSearchPath(PKG_DATADIR "data/perserver/default", false);
- resman->addToSearchPath("data/perserver/default", false);
-
-#if defined __APPLE__
- CFBundleRef mainBundle = CFBundleGetMainBundle();
- CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
- char path[PATH_MAX];
- if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (uint8_t*)path,
- PATH_MAX))
- {
- fprintf(stderr, "Can't find Resources directory\n");
- }
- CFRelease(resourcesURL);
- // possible crash
- strncat(path, "/data", PATH_MAX - 1);
- resman->addToSearchPath(path, false);
-// possible this need for support run client from dmg images.
-// mPackageDir = path;
-#endif
- resman->addToSearchPath(PKG_DATADIR "data", false);
- setPackageDir(PKG_DATADIR "data");
- resman->addToSearchPath("data", false);
-
-#ifdef ANDROID
-#ifdef USE_SDL2
- if (getenv("APPDIR"))
- {
- const std::string appDir = getenv("APPDIR");
- resman->addToSearchPath(appDir + "/data", false);
- resman->addToSearchPath(appDir + "/data/perserver/default", false);
- }
-#endif
-#endif
-
-#if defined __native_client__
- resman->addToSearchPath(_nacl_dir.append("/data"), false);
-#endif
-
- // Add branding/data to PhysFS search path
- if (!mOptions.brandingPath.empty())
- {
- std::string path = mOptions.brandingPath;
-
- // Strip blah.mana from the path
-#ifdef WIN32
- const int loc1 = path.find_last_of('/');
- const int loc2 = path.find_last_of('\\');
- const int loc = static_cast<int>(std::max(loc1, loc2));
-#else
- const int loc = static_cast<int>(path.find_last_of('/'));
-#endif
- if (loc > 0)
- {
- resman->addToSearchPath(path.substr(
- 0, loc + 1).append("data"), false);
- }
- }
+ mountDataDir();
if (mOptions.dataPath.empty()
&& !branding.getStringValue("dataPath").empty())
@@ -527,42 +373,8 @@ void Client::gameInit()
resman->addToSearchPath(mLocalDataDir, false);
TranslationManager::loadCurrentLang();
-#if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__APPLE__)
- if (!mOptions.safeMode && mOptions.test.empty()
- && !config.getBoolValue("videodetected"))
- {
- graphicsManager.detectVideoSettings();
- }
-#endif
-
- openGLMode = intToRenderType(config.getIntValue("opengl"));
-#ifdef USE_OPENGL
- OpenGLImageHelper::setBlur(config.getBoolValue("blur"));
- SurfaceImageHelper::SDLSetEnableAlphaCache(
- config.getBoolValue("alphaCache") && !openGLMode);
- ImageHelper::setEnableAlpha(config.getFloatValue("guialpha") != 1.0F
- || openGLMode);
-#else
- SurfaceImageHelper::SDLSetEnableAlphaCache(
- config.getBoolValue("alphaCache"));
- ImageHelper::setEnableAlpha(config.getFloatValue("guialpha") != 1.0F);
-#endif
- logVars();
- Cpu::detect();
- graphicsManager.initGraphics(mOptions.noOpenGL);
- graphicsManager.detectPixelSize();
- runCounters = config.getBoolValue("packetcounters");
- applyVSync();
- graphicsManager.setVideoMode();
- checkConfigVersion();
- getConfigDefaults2(config.getDefaultValues());
- applyGrabMode();
- applyGamma();
-
- SDL::SetWindowTitle(mainGraphics->getWindow(), mCaption.c_str());
- setIcon();
-
- mainGraphics->_beginDraw();
+ initGraphics();
+ initTitle();
Theme::selectSkin();
touchManager.init();
@@ -576,22 +388,7 @@ void Client::gameInit()
gui = new Gui();
gui->postInit(mainGraphics);
- // Initialize sound engine
- try
- {
- if (config.getBoolValue("sound"))
- soundManager.init();
-
- soundManager.setSfxVolume(config.getIntValue("sfxVolume"));
- soundManager.setMusicVolume(config.getIntValue("musicVolume"));
- }
- catch (const char *const err)
- {
- mState = STATE_ERROR;
- errorMessage = err;
- logger->log("Warning: %s", err);
- }
-
+ initSoundManager();
eventsManager.init();
// Initialize keyboard
@@ -600,18 +397,8 @@ void Client::gameInit()
// Initialise player relations
player_relations.init();
-
Joystick::init();
-
- userPalette = new UserPalette;
- setupWindow = new Setup;
- setupWindow->postInit();
- helpWindow = new HelpWindow;
- didYouKnowWindow = new DidYouKnowWindow;
- didYouKnowWindow->postInit();
-
- soundManager.playMusic(branding.getValue(
- "loginMusic", "Magick - Real.ogg"));
+ createWindows();
// Initialize default server
mCurrentServer.hostname = mOptions.serverName;
@@ -653,15 +440,8 @@ void Client::gameInit()
SDL_initFramerate(&mFpsManager);
setFramerate(fpsLimit);
- config.addListener("fpslimit", this);
- config.addListener("guialpha", this);
- config.addListener("gamma", this);
- config.addListener("enableGamma", this);
- config.addListener("particleEmitterSkip", this);
- config.addListener("vsync", this);
- config.addListener("repeateDelay", this);
- config.addListener("repeateInterval", this);
- config.addListener("logInput", this);
+ initConfigListeners();
+
setGuiAlpha(config.getFloatValue("guialpha"));
optionChanged("fpslimit");
@@ -685,10 +465,271 @@ Client::~Client()
CHECKLISTENERS
}
-void Client::bindTextDomain(const char *const name, const char *const path)
+void Client::initConfigListeners()
+{
+ config.addListener("fpslimit", this);
+ config.addListener("guialpha", this);
+ config.addListener("gamma", this);
+ config.addListener("enableGamma", this);
+ config.addListener("particleEmitterSkip", this);
+ config.addListener("vsync", this);
+ config.addListener("repeateDelay", this);
+ config.addListener("repeateInterval", this);
+ config.addListener("logInput", this);
+}
+
+void Client::initSoundManager()
+{
+ // Initialize sound engine
+ try
+ {
+ if (config.getBoolValue("sound"))
+ soundManager.init();
+
+ soundManager.setSfxVolume(config.getIntValue("sfxVolume"));
+ soundManager.setMusicVolume(config.getIntValue("musicVolume"));
+ }
+ catch (const char *const err)
+ {
+ mState = STATE_ERROR;
+ errorMessage = err;
+ logger->log("Warning: %s", err);
+ }
+ soundManager.playMusic(branding.getValue(
+ "loginMusic", "Magick - Real.ogg"));
+}
+
+void Client::createWindows()
+{
+ userPalette = new UserPalette;
+ setupWindow = new Setup;
+ setupWindow->postInit();
+ helpWindow = new HelpWindow;
+ didYouKnowWindow = new DidYouKnowWindow;
+ didYouKnowWindow->postInit();
+}
+
+void Client::initGraphics()
+{
+#if defined(USE_OPENGL)
+#if !defined(ANDROID) && !defined(__APPLE__) && !defined(__native_client__)
+ if (!mOptions.safeMode && mOptions.test.empty()
+ && !config.getBoolValue("videodetected"))
+ {
+ graphicsManager.detectVideoSettings();
+ }
+#endif
+#endif
+
+#if defined(WIN32) || defined(__APPLE__)
+ if (config.getBoolValue("centerwindow"))
+ setEnv("SDL_VIDEO_CENTERED", "1");
+ else
+ setEnv("SDL_VIDEO_CENTERED", "0");
+#endif
+
+ if (config.getBoolValue("allowscreensaver"))
+ setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "1");
+ else
+ setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "0");
+
+ openGLMode = intToRenderType(config.getIntValue("opengl"));
+#ifdef USE_OPENGL
+ OpenGLImageHelper::setBlur(config.getBoolValue("blur"));
+ SurfaceImageHelper::SDLSetEnableAlphaCache(
+ config.getBoolValue("alphaCache") && !openGLMode);
+ ImageHelper::setEnableAlpha(config.getFloatValue("guialpha") != 1.0F
+ || openGLMode);
+#else
+ SurfaceImageHelper::SDLSetEnableAlphaCache(
+ config.getBoolValue("alphaCache"));
+ ImageHelper::setEnableAlpha(config.getFloatValue("guialpha") != 1.0F);
+#endif
+ logVars();
+ Cpu::detect();
+ graphicsManager.initGraphics(mOptions.noOpenGL);
+ graphicsManager.detectPixelSize();
+ runCounters = config.getBoolValue("packetcounters");
+ applyVSync();
+ graphicsManager.setVideoMode();
+ checkConfigVersion();
+ getConfigDefaults2(config.getDefaultValues());
+ applyGrabMode();
+ applyGamma();
+
+ mainGraphics->_beginDraw();
+}
+
+void Client::initTitle()
+{
+ if (mOptions.test.empty())
+ {
+ mCaption = strprintf("%s %s",
+ branding.getStringValue("appName").c_str(),
+ SMALL_VERSION);
+ }
+ else
+ {
+ mCaption = strprintf(
+ "Please wait - VIDEO MODE TEST - %s %s - Please wait",
+ branding.getStringValue("appName").c_str(),
+ SMALL_VERSION);
+ }
+
+ SDL::SetWindowTitle(mainGraphics->getWindow(), mCaption.c_str());
+ setIcon();
+}
+
+void Client::extractDataDir()
+{
+#ifdef ANDROID
+#ifdef USE_SDL2
+ extractAssets();
+
+ const std::string zipName = std::string(getenv(
+ "APPDIR")).append("/data.zip");
+ const std::string dirName = std::string(getenv(
+ "APPDIR")).append("/data");
+ Files::extractZip(zipName, "data", dirName);
+ Files::extractLocale();
+#endif
+#endif
+
+#if defined __native_client__
+ const std::string dirName = _nacl_dir.append("/data");
+ Files::extractZip("/http/data.zip", "data", dirName);
+#endif
+}
+
+void Client::mountDataDir()
+{
+ const ResourceManager *const resman = ResourceManager::getInstance();
+ resman->addToSearchPath(PKG_DATADIR "data/perserver/default", false);
+ resman->addToSearchPath("data/perserver/default", false);
+
+#if defined __APPLE__
+ CFBundleRef mainBundle = CFBundleGetMainBundle();
+ CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
+ char path[PATH_MAX];
+ if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (uint8_t*)path,
+ PATH_MAX))
+ {
+ fprintf(stderr, "Can't find Resources directory\n");
+ }
+ CFRelease(resourcesURL);
+ // possible crash
+ strncat(path, "/data", PATH_MAX - 1);
+ resman->addToSearchPath(path, false);
+// possible this need for support run client from dmg images.
+// mPackageDir = path;
+#endif
+ resman->addToSearchPath(PKG_DATADIR "data", false);
+ setPackageDir(PKG_DATADIR "data");
+ resman->addToSearchPath("data", false);
+
+#ifdef ANDROID
+#ifdef USE_SDL2
+ if (getenv("APPDIR"))
+ {
+ const std::string appDir = getenv("APPDIR");
+ resman->addToSearchPath(appDir + "/data", false);
+ resman->addToSearchPath(appDir + "/data/perserver/default", false);
+ }
+#endif
+#endif
+
+#if defined __native_client__
+ resman->addToSearchPath(_nacl_dir.append("/data"), false);
+#endif
+
+ // Add branding/data to PhysFS search path
+ if (!mOptions.brandingPath.empty())
+ {
+ std::string path = mOptions.brandingPath;
+
+ // Strip blah.manaplus from the path
+#ifdef WIN32
+ const int loc1 = path.find_last_of('/');
+ const int loc2 = path.find_last_of('\\');
+ const int loc = static_cast<int>(std::max(loc1, loc2));
+#else
+ const int loc = static_cast<int>(path.find_last_of('/'));
+#endif
+ if (loc > 0)
+ {
+ resman->addToSearchPath(path.substr(
+ 0, loc + 1).append("data"), false);
+ }
+ }
+}
+
+void Client::initLang()
+{
+#ifdef ENABLE_NLS
+ std::string lang = config.getStringValue("lang");
+#ifdef WIN32
+ if (lang.empty())
+ lang = std::string(_nl_locale_name_default());
+
+ putenv(const_cast<char*>(("LANG=" + lang).c_str()));
+ putenv(const_cast<char*>(("LANGUAGE=" + lang).c_str()));
+ // mingw doesn't like LOCALEDIR to be defined for some reason
+ if (lang != "C")
+ bindTextDomain("translations/");
+#else // WIN32
+
+ if (!lang.empty())
+ {
+ setEnv("LANG", lang.c_str());
+ setEnv("LANGUAGE", lang.c_str());
+ }
+#ifdef ANDROID
+#ifdef USE_SDL2
+ bindTextDomain((std::string(getenv("APPDIR")).append("/locale")).c_str());
+#else // USE_SDL2
+
+ bindTextDomain((std::string(PhysFs::getBaseDir()).append(
+ "/locale")).c_str());
+#endif // USE_SDL2
+#else // ANDROID
+#ifdef ENABLE_PORTABLE
+ bindTextDomain((std::string(PhysFs::getBaseDir()).append(
+ "../locale/")).c_str());
+#else // ENABLE_PORTABLE
+#ifdef __APPLE__
+ bindTextDomain((std::string(PhysFs::getBaseDir())
+ .append("ManaPlus.app/Contents/Resources/locale/")).c_str());
+#else // __APPLE__
+
+ bindTextDomain(LOCALEDIR);
+#endif // __APPLE__
+#endif // ENABLE_PORTABLE
+#endif // ANDROID
+#endif // WIN32
+
+ char *locale = setlocale(LC_MESSAGES, lang.c_str());
+ if (locale)
+ {
+ logger->log("locale: %s", locale);
+ }
+ else
+ {
+ locale = setlocale(LC_MESSAGES, (lang + ".utf8").c_str());
+ if (locale)
+ logger->log("locale: %s", locale);
+ else
+ logger->log("locale empty");
+ }
+ bind_textdomain_codeset("manaplus", "UTF-8");
+ textdomain("manaplus");
+#endif // ENABLE_NLS
+
+}
+
+void Client::bindTextDomain(const char *const path)
{
#ifdef ENABLE_NLS
- const char *const dir = bindtextdomain(name, path);
+ const char *const dir = bindtextdomain("manaplus", path);
if (dir)
logger->log("bindtextdomain: %s", dir);
else
diff --git a/src/client.h b/src/client.h
index 1607a73ab..dcf761847 100644
--- a/src/client.h
+++ b/src/client.h
@@ -326,6 +326,22 @@ public:
const bool modal);
private:
+ void createWindows();
+
+ void initLang();
+
+ void initSoundManager();
+
+ void initConfigListeners();
+
+ void initGraphics();
+
+ void initTitle();
+
+ void extractDataDir();
+
+ void mountDataDir();
+
void initRootDir();
void initHomeDir();
@@ -362,7 +378,7 @@ private:
static Client *mInstance;
- static void bindTextDomain(const char *const name, const char *const path);
+ static void bindTextDomain(const char *const path);
static void setEnv(const char *const name, const char *const value);