summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 40b30899..7c48e728 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -126,6 +126,12 @@
#include <sys/stat.h>
#endif
+#ifdef TWMSERV_SUPPORT
+#define DEFAULT_PORT 9601
+#else
+#define DEFAULT_PORT 6901
+#endif
+
namespace
{
struct SetupListener : public gcn::ActionListener
@@ -159,8 +165,9 @@ extern Net::Connection *accountServerConnection;
#endif
Graphics *graphics;
+Game *game = 0;
-unsigned char state;
+State state = STATE_NULL;
std::string errorMessage;
Sound sound;
@@ -214,6 +221,7 @@ struct Options
std::string configPath;
std::string updateHost;
std::string dataPath;
+ std::string homeDir;
std::string serverName;
short serverPort;
@@ -302,11 +310,16 @@ static void setUpdatesDir()
* Initializes the home directory. On UNIX and FreeBSD, ~/.tmw is used. On
* Windows and other systems we use the current working directory.
*/
-static void initHomeDir()
+static void initHomeDir(const Options &options)
{
- homeDir = std::string(PHYSFS_getUserDir()) +
- "/." +
- branding.getValue("appShort", "tmw");
+ homeDir = options.homeDir;
+
+ if (homeDir.empty())
+ {
+ homeDir = std::string(PHYSFS_getUserDir()) +
+ "/." +
+ branding.getValue("appShort", "tmw");
+ }
#if defined WIN32
if (!CreateDirectory(homeDir.c_str(), 0) &&
GetLastError() != ERROR_ALREADY_EXISTS)
@@ -340,11 +353,7 @@ static void initConfiguration(const Options &options)
std::string defaultHost = branding.getValue("defaultServer",
"server.themanaworld.org");
config.setValue("host", defaultHost);
-#ifdef TWMSERV_SUPPORT
- int defaultPort = (int)branding.getValue("defaultPort", 9601);
-#else
- int defaultPort = (int)branding.getValue("defaultPort", 6901);
-#endif
+ int defaultPort = (int)branding.getValue("defaultPort", DEFAULT_PORT);
config.setValue("port", defaultPort);
config.setValue("hwaccel", false);
#if (defined __APPLE__ || defined WIN32) && defined USE_OPENGL
@@ -659,7 +668,7 @@ static void parseOptions(int argc, char *argv[], Options &options)
options.printVersion = true;
break;
case 'S':
- homeDir = optarg;
+ options.homeDir = optarg;
break;
case 'O':
options.noOpenGL = true;
@@ -893,7 +902,7 @@ int main(int argc, char *argv[])
// Load branding information
branding.init("data/branding.xml");
- initHomeDir();
+ initHomeDir(options);
// Configure logger
logger = new Logger;
@@ -910,7 +919,6 @@ int main(int argc, char *argv[])
// Needs to be created in main, as the updater uses it
guiPalette = new Palette;
- Game *game = NULL;
Window *currentDialog = NULL;
#ifdef TMWSERV_SUPPORT
QuitDialog* quitDialog = NULL;
@@ -947,7 +955,7 @@ int main(int argc, char *argv[])
"server.themanaworld.org").c_str();
}
if (options.serverPort == 0) {
- loginData.port = (short) branding.getValue("defaultPort", 9601);
+ loginData.port = (short) branding.getValue("defaultPort", DEFAULT_PORT);
}
if (loginData.username.empty() && loginData.remember) {
loginData.username = config.getValue("username", "");
@@ -969,7 +977,7 @@ int main(int argc, char *argv[])
desktop->setSize(screenWidth, screenHeight);
- unsigned int oldstate = !state; // We start with a status change.
+ State oldstate = STATE_EXIT; // We start with a status change
SDL_Event event;
@@ -1290,6 +1298,7 @@ int main(int argc, char *argv[])
game = new Game;
game->logic();
delete game;
+ game = 0;
state = STATE_EXIT;
@@ -1422,9 +1431,9 @@ int main(int argc, char *argv[])
}
else
{
- int nextState = STATE_UPDATE;
+ State nextState = STATE_UPDATE;
currentDialog = new ServerSelectDialog(&loginData,
- nextState);
+ nextState);
positionDialog(currentDialog, screenWidth,
screenHeight);
if (options.chooseDefault)
@@ -1467,9 +1476,9 @@ int main(int argc, char *argv[])
desktop = NULL;
logger->log("State: GAME");
- game = new Game;
game->logic();
delete game;
+ game = 0;
state = STATE_EXIT;
break;