]> git.lizzy.rs Git - minetest.git/blobdiff - src/main.cpp
Tool definition transfer to client
[minetest.git] / src / main.cpp
index 37ee035f89627b717c0829c8ae0cc10a4b8de5ac..c94e903a55840b0a1108c908b62c5bea6d586a11 100644 (file)
@@ -365,11 +365,6 @@ SUGG: Restart irrlicht completely when coming back to main menu from game.
 
 TODO: Merge bahamada's audio stuff (clean patch available)
 
-TODO: Move content_features to mapnode_content_features.{h,cpp} or so
-
-TODO: Fix item use() stuff; dropping a stack of cooked rats and eating
-      it gives 3 hearts and consumes all the rats.
-
 Making it more portable:
 ------------------------
  
@@ -390,11 +385,11 @@ Doing currently:
 */
 
 #ifdef NDEBUG
-       #ifdef _WIN32
+       /*#ifdef _WIN32
                #pragma message ("Disabling unit tests")
        #else
                #warning "Disabling unit tests"
-       #endif
+       #endif*/
        // Disable unit tests
        #define ENABLE_TESTS 0
 #else
@@ -438,9 +433,9 @@ Doing currently:
 #include "gettext.h"
 #include "settings.h"
 #include "profiler.h"
-
-// This makes textures
-ITextureSource *g_texturesource = NULL;
+#include "log.h"
+#include "nodedef.h" // For init_contentfeatures
+#include "content_mapnode.h" // For content_mapnode_init
 
 /*
        Settings.
@@ -479,19 +474,17 @@ MainGameCallback *g_gamecallback = NULL;
 
 // Connection
 std::ostream *dout_con_ptr = &dummyout;
-std::ostream *derr_con_ptr = &dstream_no_stderr;
-//std::ostream *dout_con_ptr = &dstream_no_stderr;
-//std::ostream *derr_con_ptr = &dstream_no_stderr;
-//std::ostream *dout_con_ptr = &dstream;
-//std::ostream *derr_con_ptr = &dstream;
+std::ostream *derr_con_ptr = &verbosestream;
+//std::ostream *dout_con_ptr = &infostream;
+//std::ostream *derr_con_ptr = &errorstream;
 
 // Server
-std::ostream *dout_server_ptr = &dstream;
-std::ostream *derr_server_ptr = &dstream;
+std::ostream *dout_server_ptr = &infostream;
+std::ostream *derr_server_ptr = &errorstream;
 
 // Client
-std::ostream *dout_client_ptr = &dstream;
-std::ostream *derr_client_ptr = &dstream;
+std::ostream *dout_client_ptr = &infostream;
+std::ostream *derr_client_ptr = &errorstream;
 
 /*
        gettime.h implementation
@@ -583,7 +576,6 @@ class MyEventReceiver : public IEventReceiver
                        }
                        else
                        {
-                               //dstream<<"MyEventReceiver: mouse input"<<std::endl;
                                left_active = event.MouseInput.isLeftPressed();
                                middle_active = event.MouseInput.isMiddlePressed();
                                right_active = event.MouseInput.isRightPressed();
@@ -1026,7 +1018,7 @@ void SpeedTests()
 
                u32 dtime = timer.stop();
                u32 per_ms = n / dtime;
-               std::cout<<"Done. "<<dtime<<"ms, "
+               dstream<<"Done. "<<dtime<<"ms, "
                                <<per_ms<<"/ms"<<std::endl;
        }
 }
@@ -1078,12 +1070,37 @@ void drawMenuBackground(video::IVideoDriver* driver)
        }
 }
 
+class StderrLogOutput: public ILogOutput
+{
+public:
+       /* line: Full line with timestamp, level and thread */
+       void printLog(const std::string &line)
+       {
+               std::cerr<<line<<std::endl;
+       }
+} main_stderr_log_out;
+
+class DstreamNoStderrLogOutput: public ILogOutput
+{
+public:
+       /* line: Full line with timestamp, level and thread */
+       void printLog(const std::string &line)
+       {
+               dstream_no_stderr<<line<<std::endl;
+       }
+} main_dstream_no_stderr_log_out;
+
 int main(int argc, char *argv[])
 {
        /*
                Initialization
        */
 
+       log_add_output_maxlev(&main_stderr_log_out, LMT_ACTION);
+       log_add_output_all_levs(&main_dstream_no_stderr_log_out);
+
+       log_register_thread("main");
+
        // Set locale. This is for forcing '.' as the decimal point.
        std::locale::global(std::locale("C"));
        // This enables printing all characters in bitmap font
@@ -1110,6 +1127,7 @@ int main(int argc, char *argv[])
        allowed_options.insert("dstream-on-stderr", ValueSpec(VALUETYPE_FLAG));
 #endif
        allowed_options.insert("speedtests", ValueSpec(VALUETYPE_FLAG));
+       allowed_options.insert("info-on-stderr", ValueSpec(VALUETYPE_FLAG));
 
        Settings cmd_args;
        
@@ -1151,6 +1169,9 @@ int main(int argc, char *argv[])
        if(cmd_args.getFlag("dstream-on-stderr") == false)
                disable_stderr = true;
 #endif
+       
+       if(cmd_args.getFlag("info-on-stderr"))
+               log_add_output(&main_stderr_log_out, LMT_INFO);
 
        porting::signal_handler_init();
        bool &kill = *porting::signal_handler_killstatus();
@@ -1161,13 +1182,13 @@ int main(int argc, char *argv[])
        // Create user data directory
        fs::CreateDir(porting::path_userdata);
 
-       init_gettext((porting::path_data+"/../locale").c_str());
+       init_gettext((porting::path_data+DIR_DELIM+".."+DIR_DELIM+"locale").c_str());
        
        // Initialize debug streams
 #ifdef RUN_IN_PLACE
        std::string debugfile = DEBUGFILE;
 #else
-       std::string debugfile = porting::path_userdata+"/"+DEBUGFILE;
+       std::string debugfile = porting::path_userdata+DIR_DELIM+DEBUGFILE;
 #endif
        debugstreams_init(disable_stderr, debugfile.c_str());
        // Initialize debug stacks
@@ -1182,7 +1203,7 @@ int main(int argc, char *argv[])
        BEGIN_DEBUG_EXCEPTION_HANDLER
 
        // Print startup message
-       dstream<<DTIME<<PROJECT_NAME
+       actionstream<<PROJECT_NAME<<
                        " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
                        <<", "<<BUILD_INFO
                        <<std::endl;
@@ -1210,7 +1231,7 @@ int main(int argc, char *argv[])
                bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
                if(r == false)
                {
-                       dstream<<"Could not read configuration from \""
+                       errorstream<<"Could not read configuration from \""
                                        <<cmd_args.get("config")<<"\""<<std::endl;
                        return 1;
                }
@@ -1219,9 +1240,11 @@ int main(int argc, char *argv[])
        else
        {
                core::array<std::string> filenames;
-               filenames.push_back(porting::path_userdata + "/minetest.conf");
+               filenames.push_back(porting::path_userdata +
+                               DIR_DELIM + "minetest.conf");
 #ifdef RUN_IN_PLACE
-               filenames.push_back(porting::path_userdata + "/../minetest.conf");
+               filenames.push_back(porting::path_userdata +
+                               DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
 #endif
 
                for(u32 i=0; i<filenames.size(); i++)
@@ -1249,8 +1272,9 @@ int main(int argc, char *argv[])
                These are needed for unit tests at least.
        */
        
-       // Initial call with g_texturesource not set.
-       init_mapnode();
+       // Must be called before texturesource is created
+       // (for texture atlas making)
+       init_mineral();
 
        /*
                Run unit tests
@@ -1283,7 +1307,7 @@ int main(int argc, char *argv[])
                port = 30000;
        
        // Map directory
-       std::string map_dir = porting::path_userdata+"/world";
+       std::string map_dir = porting::path_userdata+DIR_DELIM+"world";
        if(cmd_args.exists("map-dir"))
                map_dir = cmd_args.get("map-dir");
        else if(g_settings->exists("map-dir"))
@@ -1356,7 +1380,7 @@ int main(int argc, char *argv[])
                driverType = video::EDT_OPENGL;
        else
        {
-               dstream<<"WARNING: Invalid video_driver specified; defaulting "
+               errorstream<<"WARNING: Invalid video_driver specified; defaulting "
                                "to opengl"<<std::endl;
                driverType = video::EDT_OPENGL;
        }
@@ -1375,6 +1399,21 @@ int main(int argc, char *argv[])
        if (device == 0)
                return 1; // could not create selected driver.
        
+       /*
+               Continue initialization
+       */
+
+       video::IVideoDriver* driver = device->getVideoDriver();
+
+       // Disable mipmaps (because some of them look ugly)
+       driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
+
+       /*
+               This changes the minimum allowed number of vertices in a VBO.
+               Default is 500.
+       */
+       //driver->setMinHardwareBufferVertexCount(50);
+
        // Set the window caption
        device->setWindowCaption(L"Minetest [Main Menu]");
        
@@ -1384,9 +1423,6 @@ int main(int argc, char *argv[])
        // Create game callback for menus
        g_gamecallback = new MainGameCallback(device);
        
-       // Create texture source
-       g_texturesource = new TextureSource(device);
-
        /*
                Speed tests (done after irrlicht is loaded to get timer)
        */
@@ -1407,18 +1443,6 @@ int main(int argc, char *argv[])
        else
                input = new RealInputHandler(device, &receiver);
        
-       /*
-               Continue initialization
-       */
-
-       //video::IVideoDriver* driver = device->getVideoDriver();
-
-       /*
-               This changes the minimum allowed number of vertices in a VBO.
-               Default is 500.
-       */
-       //driver->setMinHardwareBufferVertexCount(50);
-
        scene::ISceneManager* smgr = device->getSceneManager();
 
        guienv = device->getGUIEnvironment();
@@ -1427,14 +1451,14 @@ int main(int argc, char *argv[])
        if(font)
                skin->setFont(font);
        else
-               dstream<<"WARNING: Font file was not found."
+               errorstream<<"WARNING: Font file was not found."
                                " Using default font."<<std::endl;
        // If font was not found, this will get us one
        font = skin->getFont();
        assert(font);
        
        u32 text_height = font->getDimension(L"Hello, world!").Height;
-       dstream<<"text_height="<<text_height<<std::endl;
+       infostream<<"text_height="<<text_height<<std::endl;
 
        //skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,0,0,0));
        skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,255,255,255));
@@ -1443,13 +1467,6 @@ int main(int argc, char *argv[])
        skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255,0,0,0));
        skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255,0,0,0));
        
-       /*
-               Preload some textures and stuff
-       */
-
-       init_mapnode(); // Second call with g_texturesource set
-       init_mineral();
-
        /*
                GUI stuff
        */
@@ -1512,6 +1529,8 @@ int main(int argc, char *argv[])
                                menudata.port = narrow_to_wide(itos(port));
                                menudata.fancy_trees = g_settings->getBool("new_style_leaves");
                                menudata.smooth_lighting = g_settings->getBool("smooth_lighting");
+                               menudata.clouds_3d = g_settings->getBool("enable_3d_clouds");
+                               menudata.opaque_water = g_settings->getBool("opaque_water");
                                menudata.creative_mode = g_settings->getBool("creative_mode");
                                menudata.enable_damage = g_settings->getBool("enable_damage");
 
@@ -1522,7 +1541,7 @@ int main(int argc, char *argv[])
 
                                if(error_message != L"")
                                {
-                                       dstream<<"WARNING: error_message = "
+                                       errorstream<<"error_message = "
                                                        <<wide_to_narrow(error_message)<<std::endl;
 
                                        GUIMessageMenu *menu2 =
@@ -1534,7 +1553,7 @@ int main(int argc, char *argv[])
 
                                video::IVideoDriver* driver = device->getVideoDriver();
                                
-                               dstream<<"Created main menu"<<std::endl;
+                               infostream<<"Created main menu"<<std::endl;
 
                                while(device->run() && kill == false)
                                {
@@ -1559,7 +1578,7 @@ int main(int argc, char *argv[])
                                if(device->run() == false || kill == true)
                                        break;
                                
-                               dstream<<"Dropping main menu"<<std::endl;
+                               infostream<<"Dropping main menu"<<std::endl;
 
                                menu->drop();
                                
@@ -1576,7 +1595,7 @@ int main(int argc, char *argv[])
 
                                password = translatePassword(playername, menudata.password);
 
-                               //dstream<<"Main: password hash: '"<<password<<"'"<<std::endl;
+                               //infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
 
                                address = wide_to_narrow(menudata.address);
                                int newport = stoi(wide_to_narrow(menudata.port));
@@ -1584,6 +1603,8 @@ int main(int argc, char *argv[])
                                        port = newport;
                                g_settings->set("new_style_leaves", itos(menudata.fancy_trees));
                                g_settings->set("smooth_lighting", itos(menudata.smooth_lighting));
+                               g_settings->set("enable_3d_clouds", itos(menudata.clouds_3d));
+                               g_settings->set("opaque_water", itos(menudata.opaque_water));
                                g_settings->set("creative_mode", itos(menudata.creative_mode));
                                g_settings->set("enable_damage", itos(menudata.enable_damage));
                                
@@ -1619,9 +1640,6 @@ int main(int argc, char *argv[])
                        if(device->run() == false)
                                break;
                        
-                       // Initialize mapnode again to enable changed graphics settings
-                       init_mapnode();
-
                        /*
                                Run game
                        */
@@ -1643,12 +1661,12 @@ int main(int argc, char *argv[])
                } //try
                catch(con::PeerNotFoundException &e)
                {
-                       dstream<<DTIME<<"Connection error (timed out?)"<<std::endl;
+                       errorstream<<"Connection error (timed out?)"<<std::endl;
                        error_message = L"Connection error (timed out?)";
                }
                catch(SocketException &e)
                {
-                       dstream<<DTIME<<"Socket error (port already in use?)"<<std::endl;
+                       errorstream<<"Socket error (port already in use?)"<<std::endl;
                        error_message = L"Socket error (port already in use?)";
                }
 #ifdef NDEBUG
@@ -1657,7 +1675,7 @@ int main(int argc, char *argv[])
                        std::string narrow_message = "Some exception, what()=\"";
                        narrow_message += e.what();
                        narrow_message += "\"";
-                       dstream<<DTIME<<narrow_message<<std::endl;
+                       errorstream<<narrow_message<<std::endl;
                        error_message = narrow_to_wide(narrow_message);
                }
 #endif
@@ -1671,7 +1689,7 @@ int main(int argc, char *argv[])
        */
        device->drop();
        
-       END_DEBUG_EXCEPTION_HANDLER
+       END_DEBUG_EXCEPTION_HANDLER(errorstream)
        
        debugstreams_deinit();