summaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-11-01 20:04:43 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-11-01 20:04:43 +0100
commit38f7cd9a9a49dc91b1c2e69b48308bd16d4b5aad (patch)
tree81d0e898790264114683cca9cfd3355bea114415 /src/client.cpp
parentc5e341f7b5f5e4efcabd09e00e177bb873db8097 (diff)
parent1f69108501c4bf51f3adac9ffbf7a7631fb12b9a (diff)
downloadmana-38f7cd9a9a49dc91b1c2e69b48308bd16d4b5aad.tar.gz
mana-38f7cd9a9a49dc91b1c2e69b48308bd16d4b5aad.tar.bz2
mana-38f7cd9a9a49dc91b1c2e69b48308bd16d4b5aad.tar.xz
mana-38f7cd9a9a49dc91b1c2e69b48308bd16d4b5aad.zip
Merge branch '0.5' of gitorious.org:mana/mana
Conflicts: src/being.cpp src/client.cpp src/commandhandler.cpp src/gui/setup_video.cpp src/gui/socialwindow.cpp src/gui/viewport.cpp src/gui/widgets/browserbox.cpp src/gui/widgets/itemcontainer.cpp src/imageparticle.cpp src/localplayer.cpp src/localplayer.h src/map.cpp src/net/tmwa/beinghandler.cpp src/particle.cpp src/particle.h src/player.cpp src/player.h
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp100
1 files changed, 77 insertions, 23 deletions
diff --git a/src/client.cpp b/src/client.cpp
index ae9af8de..66a1f28c 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -201,6 +201,7 @@ Client *Client::mInstance = 0;
Client::Client(const Options &options):
mOptions(options),
+ mRootDir(""),
mCurrentDialog(0),
mQuitDialog(0),
mDesktop(0),
@@ -224,6 +225,7 @@ Client::Client(const Options &options):
branding.setDefaultValues(getBrandingDefaults());
}
+ initRootDir();
initHomeDir();
initConfiguration();
@@ -264,6 +266,8 @@ Client::Client(const Options &options):
"Exiting.", mLocalDataDir.c_str()));
}
+ Image::SDLsetEnableAlphaCache(config.getValue("alphaCache", true));
+
#if defined __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
@@ -326,9 +330,14 @@ Client::Client(const Options &options):
}
#endif
-#ifdef USE_OPENGL
bool useOpenGL = !mOptions.noOpenGL && (config.getValue("opengl", 0) == 1);
+ // Set up the transparency option for low CPU when not using OpenGL.
+ if (!useOpenGL && (config.getValue("disableTransparency", 0) == 1))
+ Image::SDLdisableTransparency();
+
+#ifdef USE_OPENGL
+
// Setup image loading for the right image format
Image::setLoadAsOpenGL(useOpenGL);
@@ -546,12 +555,7 @@ int Client::exec()
Net::getLoginHandler()->disconnect();
}
else if (mState == STATE_CONNECT_SERVER &&
- mOldState == STATE_CHOOSE_SERVER)
- {
- Net::connectToServer(mCurrentServer);
- }
- else if (mState == STATE_CONNECT_SERVER &&
- mOldState != STATE_CHOOSE_SERVER &&
+ mOldState == STATE_CONNECT_SERVER &&
Net::getLoginHandler()->isConnected())
{
mState = STATE_LOGIN;
@@ -647,6 +651,9 @@ int Client::exec()
case STATE_CONNECT_SERVER:
logger->log("State: CONNECT SERVER");
+
+ Net::connectToServer(mCurrentServer);
+
mCurrentDialog = new ConnectionDialog(
_("Connecting to server"), STATE_SWITCH_SERVER);
break;
@@ -945,9 +952,9 @@ int Client::exec()
case STATE_SWITCH_LOGIN:
logger->log("State: SWITCH LOGIN");
- Net::getLoginHandler()->logout();
+ Net::getLoginHandler()->disconnect();
- mState = STATE_LOGIN;
+ mState = STATE_CONNECT_SERVER;
break;
case STATE_SWITCH_CHARACTER:
@@ -1022,6 +1029,57 @@ void Client::action(const gcn::ActionEvent &event)
}
}
+void Client::initRootDir()
+{
+ mRootDir = PHYSFS_getBaseDir();
+#ifdef WIN32
+ std::string portableName = mRootDir + "portable.xml";
+ struct stat statbuf;
+
+ if (!stat(portableName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode))
+ {
+ std::string dir;
+ Configuration portable;
+ portable.init(portableName);
+
+ logger->log("Portable file: %s", portableName.c_str());
+
+ if (mOptions.localDataDir.empty())
+ {
+ dir = portable.getValue("dataDir", "");
+ if (!dir.empty())
+ {
+ mOptions.localDataDir = mRootDir + dir;
+ logger->log("Portable data dir: %s",
+ mOptions.localDataDir.c_str());
+ }
+ }
+
+ if (mOptions.configDir.empty())
+ {
+ dir = portable.getValue("configDir", "");
+ if (!dir.empty())
+ {
+ mOptions.configDir = mRootDir + dir;
+ logger->log("Portable config dir: %s",
+ mOptions.configDir.c_str());
+ }
+ }
+
+ if (mOptions.screenshotDir.empty())
+ {
+ dir = portable.getValue("screenshotDir", "");
+ if (!dir.empty())
+ {
+ mOptions.screenshotDir = mRootDir + dir;
+ logger->log("Portable screenshot dir: %s",
+ mOptions.screenshotDir.c_str());
+ }
+ }
+ }
+#endif
+}
+
/**
* Initializes the home directory. On UNIX and FreeBSD, ~/.mana is used. On
* Windows and other systems we use the current working directory.
@@ -1083,7 +1141,8 @@ void Client::initHomeDir()
{
std::string oldConfigFile = std::string(PHYSFS_getUserDir()) +
"/.tmw/config.xml";
- if (!stat(oldConfigFile.c_str(), &statbuf) && S_ISREG(statbuf.st_mode))
+ if (mRootDir.empty() && !stat(oldConfigFile.c_str(), &statbuf)
+ && S_ISREG(statbuf.st_mode))
{
std::ifstream oldConfig;
std::ofstream newConfig;
@@ -1128,6 +1187,7 @@ void Client::initConfiguration()
config.setValue("customcursor", true);
config.setValue("useScreenshotDirectorySuffix", true);
config.setValue("ChatLogLength", 128);
+ config.setValue("disableTransparency", false);
// Checking if the configuration file exists... otherwise create it with
// default options.
@@ -1241,24 +1301,18 @@ void Client::initUpdatesDir()
void Client::initScreenshotDir()
{
if (!mOptions.screenshotDir.empty())
+ {
mScreenshotDir = mOptions.screenshotDir;
- else
+ }
+ else if (mScreenshotDir.empty())
{
- std::string configScreenshotDir =
- config.getStringValue("screenshotDirectory");
- if (!configScreenshotDir.empty())
- mScreenshotDir = configScreenshotDir;
- else
- {
#ifdef WIN32
- mScreenshotDir = getSpecialFolderLocation(CSIDL_MYPICTURES);
- if (mScreenshotDir.empty())
- mScreenshotDir = getSpecialFolderLocation(CSIDL_DESKTOP);
+ mScreenshotDir = getSpecialFolderLocation(CSIDL_MYPICTURES);
+ if (mScreenshotDir.empty())
+ mScreenshotDir = getSpecialFolderLocation(CSIDL_DESKTOP);
#else
- mScreenshotDir = std::string(PHYSFS_getUserDir()) + "Desktop";
+ mScreenshotDir = std::string(PHYSFS_getUserDir()) + "Desktop";
#endif
- }
- config.setValue("screenshotDirectory", mScreenshotDir);
if (config.getBoolValue("useScreenshotDirectorySuffix"))
{