summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-07-25 21:36:37 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-07-25 21:36:37 +0000
commite6d8d2dd8eff63c23f0ffad25c5e2529bde93485 (patch)
treecce9c591350ce1d29c67df3339c526b182e8763e /src/main.cpp
parent33e19fb0822308a630ca6e1122b9b97882a120a7 (diff)
downloadmana-client-e6d8d2dd8eff63c23f0ffad25c5e2529bde93485.tar.gz
mana-client-e6d8d2dd8eff63c23f0ffad25c5e2529bde93485.tar.bz2
mana-client-e6d8d2dd8eff63c23f0ffad25c5e2529bde93485.tar.xz
mana-client-e6d8d2dd8eff63c23f0ffad25c5e2529bde93485.zip
Added support for writing log to standard output.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp137
1 files changed, 77 insertions, 60 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 0c75c653..ca70b0dc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -93,6 +93,7 @@ SERVER_INFO **server_info;
unsigned char state;
std::string errorMessage;
+std::string homeDir;
unsigned char screen_mode;
Sound sound;
@@ -109,24 +110,12 @@ namespace {
}
/**
- * Do all initialization stuff
+ * Initializes the home directory. On UNIX and FreeBSD, ~/.tmw is used. On
+ * Windows and other systems we use the current working directory.
*/
-void init_engine()
+void initHomeDir()
{
- // Initialize SDL
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
- std::cerr << "Could not initialize SDL: " <<
- SDL_GetError() << std::endl;
- exit(1);
- }
- atexit(SDL_Quit);
-
- SDL_EnableUNICODE(1);
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-
- std::string homeDir = "";
#if !(defined __USE_UNIX98 || defined __FreeBSD__)
- // In Windows and other systems we currently store data next to executable.
homeDir = ".";
#else
homeDir = std::string(PHYSFS_getUserDir()) + "/.tmw";
@@ -141,35 +130,13 @@ void init_engine()
exit(1);
}
#endif
+}
- // Set log file
- logger->setLogFile(homeDir + std::string("/tmw.log"));
-
- ResourceManager *resman = ResourceManager::getInstance();
-
- if (!resman->setWriteDir(homeDir)) {
- std::cout << homeDir
- << " couldn't be set as home directory! Exitting."
- << std::endl;
- exit(1);
- }
-
- // Add the user's homedir to PhysicsFS search path
- resman->addToSearchPath(homeDir, false);
- // Creating and checking the updates folder existence and rights.
- if (!resman->isDirectory("/updates")) {
- if (!resman->mkdir("/updates")) {
- std::cout << homeDir << "/updates "
- << "can't be made, but it doesn't exist! Exitting."
- << std::endl;
- exit(1);
- }
- }
-
- // Add the main data directory to our PhysicsFS search path
- resman->addToSearchPath("data", true);
- resman->addToSearchPath(TMW_DATADIR "data", true);
-
+/**
+ * Initialize configuration.
+ */
+void initConfiguration()
+{
// Fill configuration with defaults
config.setValue("host", "animesites.de");
config.setValue("port", 9601);
@@ -185,13 +152,13 @@ void init_engine()
config.setValue("remember", 1);
config.setValue("sfxVolume", 100);
config.setValue("musicVolume", 60);
- config.setValue("fpslimit", 50);
+ config.setValue("fpslimit", 0);
config.setValue("updatehost", "http://themanaworld.org/files");
config.setValue("customcursor", 1);
config.setValue("homeDir", homeDir);
- // Checking if the configuration file exists... otherwise creates it with
- // default options !
+ // Checking if the configuration file exists... otherwise create it with
+ // default options.
FILE *tmwFile = 0;
std::string configPath = homeDir + "/config.xml";
tmwFile = fopen(configPath.c_str(), "r");
@@ -203,15 +170,57 @@ void init_engine()
}
if (tmwFile == NULL) {
std::cout << "Can't create " << configPath << ". "
- "Using Defaults." << std::endl;
+ << "Using Defaults." << std::endl;
} else {
fclose(tmwFile);
config.init(configPath);
}
+}
+
+/**
+ * Do all initialization stuff
+ */
+void init_engine()
+{
+ // Initialize SDL
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
+ std::cerr << "Could not initialize SDL: " <<
+ SDL_GetError() << std::endl;
+ exit(1);
+ }
+ atexit(SDL_Quit);
+
+ SDL_EnableUNICODE(1);
+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
SDL_WM_SetCaption("The Mana World", NULL);
SDL_WM_SetIcon(IMG_Load(TMW_DATADIR "data/icons/tmw-icon.png"), NULL);
+ ResourceManager *resman = ResourceManager::getInstance();
+
+ if (!resman->setWriteDir(homeDir)) {
+ std::cout << homeDir
+ << " couldn't be set as home directory! Exitting."
+ << std::endl;
+ exit(1);
+ }
+
+ // Add the user's homedir to PhysicsFS search path
+ resman->addToSearchPath(homeDir, false);
+ // Creating and checking the updates folder existence and rights.
+ if (!resman->isDirectory("/updates")) {
+ if (!resman->mkdir("/updates")) {
+ std::cout << homeDir << "/updates "
+ << "can't be made, but it doesn't exist! Exitting."
+ << std::endl;
+ exit(1);
+ }
+ }
+
+ // Add the main data directory to our PhysicsFS search path
+ resman->addToSearchPath("data", true);
+ resman->addToSearchPath(TMW_DATADIR "data", true);
+
int width, height, bpp;
bool fullscreen, hwaccel;
@@ -238,12 +247,12 @@ void init_engine()
graphics = new Graphics();
#endif
-
// Try to set the desired video mode
if (!graphics->setVideoMode(width, height, bpp, fullscreen, hwaccel))
{
- std::cerr << "Couldn't set " << width << "x" << height << "x" <<
- bpp << " video mode: " << SDL_GetError() << std::endl;
+ std::cerr << "Couldn't set "
+ << width << "x" << height << "x" << bpp << " video mode: "
+ << SDL_GetError() << std::endl;
exit(1);
}
@@ -258,7 +267,7 @@ void init_engine()
if (!playerset[1]) logger->error("Couldn't load female player spriteset!");
- for (int i=0; i < NR_HAIR_STYLES; i++)
+ for (int i = 0; i < NR_HAIR_STYLES; i++)
{
Spriteset *tmp = ResourceManager::getInstance()->getSpriteset(
"graphics/sprites/hairstyle" + toString(i + 1) + ".png",
@@ -312,7 +321,6 @@ void exit_engine()
sound.close();
ResourceManager::deleteInstance();
- delete logger;
}
/**
@@ -486,20 +494,30 @@ int main(int argc, char *argv[])
#ifdef PACKAGE_VERSION
std::cout << "The Mana World v" << PACKAGE_VERSION << std::endl;
#endif
- logger = new Logger();
+ // Parse command line options
Options options;
-
parseOptions(argc, argv, options);
-
if (options.printHelp)
{
printHelp();
return 0;
}
+ // Initialize PhysicsFS
+ PHYSFS_init(argv[0]);
+
+ initHomeDir();
+ initConfiguration();
+
+ // Configure logger
+ logger = new Logger();
+ logger->setLogFile(homeDir + std::string("/tmw.log"));
+ logger->setLogToStandardOut(config.getValue("logToStandardOut", 0));
+
// Initialize libxml2 and check for potential ABI mismatches between
// compiled version and the shared library actually used.
+ logger->log("Initializing libxml2...");
xmlInitParser();
LIBXML_TEST_VERSION;
@@ -507,13 +525,8 @@ int main(int argc, char *argv[])
FILE *nullFile = fopen("/dev/null", "w");
xmlSetGenericErrorFunc(nullFile, NULL);
- // Initialize PhysicsFS
- PHYSFS_init(argv[0]);
-
init_engine();
- SDL_Event event;
-
if (options.skipUpdate && state != ERROR_STATE) {
state = LOGIN_STATE;
}
@@ -547,6 +560,9 @@ int main(int argc, char *argv[])
logger->error("An error occurred while initializing ENet.");
}
Network *network = new Network();
+
+ SDL_Event event;
+
while (state != EXIT_STATE)
{
// Handle SDL events
@@ -712,5 +728,6 @@ int main(int argc, char *argv[])
logger->log("State: EXIT");
exit_engine();
PHYSFS_deinit();
+ delete logger;
return 0;
}