reorganized a lot of stuff and modified mapgen and objects slightly while doing it
[oweals/minetest.git] / src / servermain.cpp
index 1c301d4f59af8dce1cd79d76a38c5e53aecb8798..146c548c506d4a16c9e40f2cc3cff7fb152274aa 100644 (file)
@@ -69,6 +69,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "materials.h"
 #include "config.h"
 #include "mineral.h"
+#include "filesys.h"
 
 /*
        Settings.
@@ -79,6 +80,9 @@ Settings g_settings;
 
 extern void set_default_settings();
 
+// Global profiler
+Profiler g_profiler;
+
 // A dummy thing
 ITextureSource *g_texturesource = NULL;
 
@@ -98,7 +102,6 @@ std::ostream *derr_server_ptr = &dstream;
 std::ostream *dout_client_ptr = &dstream;
 std::ostream *derr_client_ptr = &dstream;
 
-
 /*
        gettime.h implementation
 */
@@ -113,6 +116,15 @@ u32 getTimeMs()
 
 int main(int argc, char *argv[])
 {
+       /*
+               Initialization
+       */
+
+       // Set locale. This is for forcing '.' as the decimal point.
+       std::locale::global(std::locale("C"));
+       // This enables printing all characters in bitmap font
+       setlocale(LC_CTYPE, "en_US");
+
        /*
                Low-level initialization
        */
@@ -122,17 +134,31 @@ int main(int argc, char *argv[])
        disable_stderr = true;
 #endif
 
+       porting::signal_handler_init();
+       bool &kill = *porting::signal_handler_killstatus();
+       
+       // Initialize porting::path_data and porting::path_userdata
+       porting::initializePaths();
+
+       // Create user data directory
+       fs::CreateDir(porting::path_userdata);
+       
        // Initialize debug streams
-       debugstreams_init(disable_stderr, DEBUGFILE);
+#ifdef RUN_IN_PLACE
+       std::string debugfile = DEBUGFILE;
+#else
+       std::string debugfile = porting::path_userdata+"/"+DEBUGFILE;
+#endif
+       debugstreams_init(disable_stderr, debugfile.c_str());
        // Initialize debug stacks
        debug_stacks_init();
 
        DSTACK(__FUNCTION_NAME);
 
-       porting::initializePaths();
-
-       initializeMaterialProperties();
+       // Init material properties table
+       //initializeMaterialProperties();
 
+       // Debug handler
        BEGIN_DEBUG_EXCEPTION_HANDLER
 
        // Print startup message
@@ -197,19 +223,10 @@ int main(int argc, char *argv[])
        // Initialize default settings
        set_default_settings();
        
-       // Set locale. This is for forcing '.' as the decimal point.
-       std::locale::global(std::locale("C"));
-       // This enables printing all characters in bitmap font
-       setlocale(LC_CTYPE, "en_US");
-
        // Initialize sockets
        sockets_init();
        atexit(sockets_cleanup);
        
-       /*
-               Initialization
-       */
-
        /*
                Read config file
        */
@@ -251,6 +268,11 @@ int main(int argc, char *argv[])
        srand(time(0));
        mysrand(time(0));
 
+       // Initialize stuff
+       
+       init_mapnode();
+       init_mineral();
+
        /*
                Run unit tests
        */
@@ -260,11 +282,6 @@ int main(int argc, char *argv[])
                run_tests();
        }
 
-       // Initialize stuff
-       
-       init_mapnode();
-       init_mineral();
-
        /*
                Check parameters
        */
@@ -299,7 +316,7 @@ int main(int argc, char *argv[])
        }
        
        // Figure out path to map
-       std::string map_dir = porting::path_userdata+"/map";
+       std::string map_dir = porting::path_userdata+"/world";
        if(cmd_args.exists("map-dir"))
                map_dir = cmd_args.get("map-dir");
        else if(g_settings.exists("map-dir"))
@@ -308,9 +325,9 @@ int main(int argc, char *argv[])
        // Create server
        Server server(map_dir.c_str());
        server.start(port);
-       
+
        // Run server
-       dedicated_server_loop(server);
+       dedicated_server_loop(server, kill);
        
        } //try
        catch(con::PeerNotFoundException &e)