Added a more flexible path system (and fixed some minor stuff)
authorPerttu Ahola <celeron55@gmail.com>
Fri, 7 Jan 2011 17:39:27 +0000 (19:39 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Fri, 7 Jan 2011 17:39:27 +0000 (19:39 +0200)
22 files changed:
Makefile
doc/README.txt
minetest.vcproj
src/constants.h
src/debug.cpp
src/guiPauseMenu.cpp
src/inventory.cpp
src/inventory.h
src/irrlichtwrapper.cpp
src/main.cpp
src/mapblock.cpp
src/mapblockobject.cpp
src/mapblockobject.h
src/mapnode.cpp
src/mapnode.h
src/player.cpp
src/porting.cpp [new file with mode: 0644]
src/porting.h
src/server.h
src/servermain.cpp
src/tile.cpp
src/tile.h

index 5f4195f96fa074c314ed9ddf35aaa0e00ca93be0..8b92f72f72000f536147492966e3bb2be2ba00d3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 # Makefile for Irrlicht Examples\r
 # It's usually sufficient to change just the target name and source file list\r
 # and be sure that CXX is set to a valid compiler\r
-SOURCE_FILES = guiMessageMenu.cpp materials.cpp guiTextInputMenu.cpp guiInventoryMenu.cpp irrlichtwrapper.cpp guiPauseMenu.cpp defaultsettings.cpp mapnode.cpp tile.cpp voxel.cpp mapblockobject.cpp inventory.cpp debug.cpp serialization.cpp light.cpp filesys.cpp connection.cpp environment.cpp client.cpp server.cpp socket.cpp mapblock.cpp mapsector.cpp heightmap.cpp map.cpp player.cpp utility.cpp main.cpp test.cpp\r
+SOURCE_FILES = porting.cpp guiMessageMenu.cpp materials.cpp guiTextInputMenu.cpp guiInventoryMenu.cpp irrlichtwrapper.cpp guiPauseMenu.cpp defaultsettings.cpp mapnode.cpp tile.cpp voxel.cpp mapblockobject.cpp inventory.cpp debug.cpp serialization.cpp light.cpp filesys.cpp connection.cpp environment.cpp client.cpp server.cpp socket.cpp mapblock.cpp mapsector.cpp heightmap.cpp map.cpp player.cpp utility.cpp main.cpp test.cpp\r
 \r
 DEBUG_TARGET = debugtest\r
 DEBUG_SOURCES = $(addprefix src/, $(SOURCE_FILES))\r
@@ -22,10 +22,6 @@ SERVER_OBJECTS = $(addprefix $(SERVER_BUILD_DIR)/, $(SERVER_SOURCE_FILES:.cpp=.o
 IRRLICHTPATH = ../irrlicht/irrlicht-1.7.1\r
 JTHREADPATH = ../jthread/jthread-1.2.1\r
 \r
-#CXXFLAGS = -O2 -ffast-math -Wall -fomit-frame-pointer -pipe\r
-#CXXFLAGS = -O2 -ffast-math -Wall -g -pipe\r
-#CXXFLAGS = -O1 -ffast-math -Wall -g\r
-CXXFLAGS = -Wall -g -O1\r
 \r
 all: fast\r
 \r
@@ -33,13 +29,17 @@ ifeq ($(HOSTTYPE), x86_64)
 LIBSELECT=64\r
 endif\r
 \r
-debug fast: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L$(IRRLICHTPATH)/lib/Linux -L$(JTHREADPATH)/src/.libs -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -ljthread -lz\r
-debug: CPPFLAGS = -I$(IRRLICHTPATH)/include -I/usr/X11R6/include -I$(JTHREADPATH)/src -DDEBUG\r
+debug: CXXFLAGS = -Wall -g -O1\r
+debug: CPPFLAGS = -I$(IRRLICHTPATH)/include -I/usr/X11R6/include -I$(JTHREADPATH)/src -DDEBUG -DRUN_IN_PLACE\r
+debug: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L$(IRRLICHTPATH)/lib/Linux -L$(JTHREADPATH)/src/.libs -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -ljthread -lz\r
+\r
+fast: CXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686\r
 fast: CPPFLAGS = -I$(IRRLICHTPATH)/include -I/usr/X11R6/include -I$(JTHREADPATH)/src -DUNITTEST_DISABLE\r
-fast server: CXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686\r
-server: LDFLAGS = -L$(JTHREADPATH)/src/.libs -ljthread -lz -lpthread\r
+fast: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L$(IRRLICHTPATH)/lib/Linux -L$(JTHREADPATH)/src/.libs -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -ljthread -lz\r
+\r
+server: CXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686\r
 server: CPPFLAGS = -I$(IRRLICHTPATH)/include -I/usr/X11R6/include -I$(JTHREADPATH)/src -DSERVER -DUNITTEST_DISABLE\r
-debug fast clean_debug: SYSTEM=Linux\r
+server: LDFLAGS = -L$(JTHREADPATH)/src/.libs -ljthread -lz -lpthread\r
 \r
 DEBUG_DESTPATH = bin/$(DEBUG_TARGET)\r
 FAST_DESTPATH = bin/$(FAST_TARGET)\r
index 7f6afcce7c085c995272b85372dbb02efeb1f992..8cfddb2b64de6de442ac6fdd40d555afdedb08d4 100644 (file)
@@ -29,7 +29,6 @@ Configuration file:
        --config <path-to-file>
 - If not given as a parameter, these are checked, in order:
        ../minetest.conf
-       ../../minetest.conf
 
 Command-line options:
 - Use --help
index c244b4370253b828aecd8579061993a85e57cf99..a4e6cf9fd473620e02320adc42c60bede0a63fd3 100644 (file)
                                OmitFramePointers="true"\r
                                WholeProgramOptimization="true"\r
                                AdditionalIncludeDirectories="&quot;C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include&quot;;&quot;..\jthread\jthread-1.2.1\src&quot;;&quot;..\irrlicht\irrlicht-1.7.1\include&quot;;&quot;..\zlib\zlib-1.2.5&quot;"\r
-                               PreprocessorDefinitions="WIN32;_HAS_ITERATOR_DEBUGGING=0,UNITTEST_DISABLE,_CRT_SECURE_NO_DEPRECATE"\r
+                               PreprocessorDefinitions="WIN32;_HAS_ITERATOR_DEBUGGING=0;UNITTEST_DISABLE;_CRT_SECURE_NO_DEPRECATE;RUN_IN_PLACE"\r
                                ExceptionHandling="2"\r
                                BufferSecurityCheck="false"\r
                                EnableEnhancedInstructionSet="1"\r
                                RelativePath=".\src\player.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\src\porting.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\src\serialization.cpp"\r
                                >\r
index b6b09b50bb6c3c98b42e13848d8831116d58841f..cfb340bf94a414eaf4ef2b75fb3834ab1fca6777 100644 (file)
@@ -17,17 +17,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#ifndef CONSTANTS_HEADER
+#define CONSTANTS_HEADER
+
 /*
-(c) 2010 Perttu Ahola <celeron55@gmail.com>
+       All kinds of constants.
+
+       Cross-platform compatibility crap should go in porting.h.
 */
 
-#ifndef CONSTANTS_HEADER
-#define CONSTANTS_HEADER
+#define APPNAME "minetest"
 
 #define DEBUGFILE "debug.txt"
 
-// Define for simulating the quirks of sending through internet
-// WARNING: This disables unit testing of socket and connection
+// Define for simulating the quirks of sending through internet.
+// Causes the socket class to deliberately drop random packets.
+// This disables unit testing of socket and connection.
 #define INTERNET_SIMULATOR 0
 
 #define CONNECTION_TIMEOUT 30
index 9fbdf7a396491d9c8d2304c44ad737ea41188268..ca49c9b770f831b008e899af1f36d1cf46ddcd0e 100644 (file)
@@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "debug.h"
 #include <stdio.h>
 #include <stdlib.h>
-#include "porting.h"
 
 /*
        Debug output
@@ -74,8 +73,6 @@ void assert_fail(const char *assertion, const char *file,
        if(g_debugstreams[1])
                fclose(g_debugstreams[1]);
 
-       //sleep_ms(3000);
-
        abort();
 }
 
index ede42bb1e36b5ec7bead96fc7b49127afa86afb6..46bb799e68c28ac1531ee572a5e06476884e80ad 100644 (file)
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "guiPauseMenu.h"\r
 #include "debug.h"\r
 #include "serialization.h"\r
+#include "porting.h"\r
 \r
 GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,\r
                gui::IGUIElement* parent, s32 id,\r
@@ -127,11 +128,11 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize)
                                L"by Perttu Ahola\n"\r
                                L"celeron55@gmail.com\n\n"\r
                                L"SER_FMT_VER_HIGHEST=%i\n"\r
-                               L"max_texture_size=\n(%i,%i)\n"\r
+                               L"userdata path = \n"\r
+                               SWPRINTF_CHARSTRING\r
                                ,\r
                                (int)SER_FMT_VER_HIGHEST,\r
-                               max_texture_size.X,\r
-                               max_texture_size.Y\r
+                               porting::path_userdata.c_str()\r
                );\r
        \r
                Environment->addStaticText(text, rect, false, true, this, 259);\r
index a2aba311b23402c344425506386078ab6b3666d0..713adefdf70ec416ce1e53f445015b486f0e5700 100644 (file)
@@ -97,12 +97,12 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
 video::ITexture * MapBlockObjectItem::getImage()
 {
        if(m_inventorystring.substr(0,3) == "Rat")
-               //return g_device->getVideoDriver()->getTexture("../data/rat.png");
-               return g_irrlicht->getTexture("../data/rat.png");
+               //return g_device->getVideoDriver()->getTexture(porting::getDataPath("rat.png").c_str());
+               return g_irrlicht->getTexture(porting::getDataPath("rat.png").c_str());
        
        if(m_inventorystring.substr(0,4) == "Sign")
-               //return g_device->getVideoDriver()->getTexture("../data/sign.png");
-               return g_irrlicht->getTexture("../data/sign.png");
+               //return g_device->getVideoDriver()->getTexture(porting::getDataPath("sign.png").c_str());
+               return g_irrlicht->getTexture(porting::getDataPath("sign.png").c_str());
 
        return NULL;
 }
index 97eacef5b4e9ea719557103c8c0ff442a5292b94..84ccd5bd6306c19007a515f50a1f0f473ae49422 100644 (file)
@@ -131,7 +131,7 @@ public:
                if(m_content >= USEFUL_CONTENT_COUNT)
                        return NULL;
                        
-               return g_irrlicht->getTexture(g_content_inventory_textures[m_content]);
+               return g_irrlicht->getTexture(g_content_inventory_texture_paths[m_content]);
        }
 #endif
        std::string getText()
@@ -258,7 +258,7 @@ public:
        {
                std::string basename;
                if(m_subname == "Stick")
-                       basename = "../data/stick.png";
+                       basename = porting::getDataPath("stick.png").c_str();
                // Default to cloud texture
                else
                        basename = tile_texture_path_get(TILE_CLOUD);
@@ -333,11 +333,11 @@ public:
        {
                std::string basename;
                if(m_toolname == "WPick")
-                       basename = "../data/tool_wpick.png";
+                       basename = porting::getDataPath("tool_wpick.png").c_str();
                else if(m_toolname == "STPick")
-                       basename = "../data/tool_stpick.png";
+                       basename = porting::getDataPath("tool_stpick.png").c_str();
                else if(m_toolname == "MesePick")
-                       basename = "../data/tool_mesepick.png";
+                       basename = porting::getDataPath("tool_mesepick.png").c_str();
                // Default to cloud texture
                else
                        basename = tile_texture_path_get(TILE_CLOUD);
index e48e328e3cdce3a42f40df1e32320f684da346cf..fe4ff27712051b75e1163c2e89eb3a8579f51ef4 100644 (file)
@@ -124,11 +124,11 @@ video::ITexture * CrackTextureMod::make(video::ITexture *original,
        video::IImage *baseimage = driver->createImage(original, pos_base, dim);
        assert(baseimage);
 
-       video::IImage *crackimage = driver->createImageFromFile("../data/crack.png");
+       video::IImage *crackimage = driver->createImageFromFile(porting::getDataPath("crack.png").c_str());
        assert(crackimage);
        
 #if 0
-       video::ITexture *other = driver->getTexture("../data/crack.png");
+       video::ITexture *other = driver->getTexture(porting::getDataPath("crack.png").c_str());
        
        dstream<<__FUNCTION_NAME<<": crack texture size is "
                        <<other->getSize().Width<<"x"
index e3fb9b87736aa17a636b89646e7cc1da4d1d09a2..9ec49feb3eddab8a41287743ecfb5e58d2c23a76 100644 (file)
@@ -177,6 +177,8 @@ TODO: When server sees that client is removing an inexistent block or
 \r
 TODO: When player dies, throw items on map\r
 \r
+TODO: Use porting::path_userdata for configuration file\r
+\r
 TODO: Optimize day/night mesh updating somehow\r
       - create copies of all textures for all lighting values and only\r
            change texture for material?\r
@@ -187,12 +189,11 @@ TODO: Optimize day/night mesh updating somehow
 TODO: Map generator version 2\r
        - Create surface areas based on central points; a given point's\r
          area type is given by the nearest central point\r
+         - Separate points for heightmap, caves, plants and minerals?\r
+         - Flat land, mountains, forest, jungle\r
     - Cliffs, arcs\r
 \r
-TODO: A Constant for the "../data/" path (differs on Mac and on proper\r
-      linux installations)\r
-\r
-TODO: Add defined(__APPLE__) to filesys.cpp\r
+TODO: Add gui option to remove map\r
 \r
 Doing now:\r
 ======================================================================\r
@@ -257,6 +258,7 @@ Doing now:
 #include "guiTextInputMenu.h"\r
 #include "materials.h"\r
 #include "guiMessageMenu.h"\r
+#include "filesys.h"\r
 \r
 IrrlichtWrapper *g_irrlicht;\r
 \r
@@ -1099,7 +1101,11 @@ int main(int argc, char *argv[])
        debug_stacks_init();\r
 \r
        DSTACK(__FUNCTION_NAME);\r
-       \r
+\r
+       porting::initializePaths();\r
+       // Create user data directory\r
+       fs::CreateDir(porting::path_userdata);\r
+\r
        initializeMaterialProperties();\r
 \r
        BEGIN_DEBUG_EXCEPTION_HANDLER\r
@@ -1123,6 +1129,7 @@ int main(int argc, char *argv[])
        allowed_options.insert("random-input", ValueSpec(VALUETYPE_FLAG));\r
        allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));\r
        allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));\r
+       allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));\r
 \r
        Settings cmd_args;\r
        \r
@@ -1202,15 +1209,12 @@ int main(int argc, char *argv[])
        }\r
        else\r
        {\r
-               const char *filenames[2] =\r
-               {\r
-                       "../minetest.conf",\r
-                       "../../minetest.conf"\r
-               };\r
+               core::array<std::string> filenames;\r
+               filenames.push_back(porting::path_userdata + "/minetest.conf");\r
 \r
-               for(u32 i=0; i<2; i++)\r
+               for(u32 i=0; i<filenames.size(); i++)\r
                {\r
-                       bool r = g_settings.readConfigFile(filenames[i]);\r
+                       bool r = g_settings.readConfigFile(filenames[i].c_str());\r
                        if(r)\r
                        {\r
                                configpath = filenames[i];\r
@@ -1274,6 +1278,11 @@ int main(int argc, char *argv[])
                std::cout<<"-> "<<port<<std::endl;\r
        }\r
        \r
+       //Map directory\r
+       std::string map_dir = porting::path_userdata+"/map";\r
+       if(cmd_args.exists("map-dir"))\r
+               map_dir = cmd_args.get("map-dir");\r
+       \r
        if(cmd_args.getFlag("server"))\r
        {\r
                DSTACK("Dedicated server branch");\r
@@ -1284,7 +1293,7 @@ int main(int argc, char *argv[])
                std::cout<<"========================"<<std::endl;\r
                std::cout<<std::endl;\r
 \r
-               Server server("../map", hm_params, map_params);\r
+               Server server(map_dir, hm_params, map_params);\r
                server.start(port);\r
        \r
                for(;;)\r
@@ -1422,7 +1431,7 @@ int main(int argc, char *argv[])
        \r
        guienv = device->getGUIEnvironment();\r
        gui::IGUISkin* skin = guienv->getSkin();\r
-       gui::IGUIFont* font = guienv->getFont("../data/fontlucida.png");\r
+       gui::IGUIFont* font = guienv->getFont(porting::getDataPath("fontlucida.png").c_str());\r
        if(font)\r
                skin->setFont(font);\r
        \r
@@ -1453,6 +1462,8 @@ int main(int argc, char *argv[])
                Preload some textures\r
        */\r
 \r
+       init_content_inventory_texture_paths();\r
+       init_tile_texture_paths();\r
        tile_materials_preload(g_irrlicht);\r
 \r
        /*\r
@@ -1468,7 +1479,7 @@ int main(int argc, char *argv[])
        */\r
        SharedPtr<Server> server;\r
        if(hosting){\r
-               server = new Server("../map", hm_params, map_params);\r
+               server = new Server(map_dir, hm_params, map_params);\r
                server->start(port);\r
        }\r
        \r
@@ -1514,12 +1525,12 @@ int main(int argc, char *argv[])
        */\r
        /*scene::ISceneNode* skybox;\r
        skybox = smgr->addSkyBoxSceneNode(\r
-               driver->getTexture("../data/skybox2.png"),\r
-               driver->getTexture("../data/skybox3.png"),\r
-               driver->getTexture("../data/skybox1.png"),\r
-               driver->getTexture("../data/skybox1.png"),\r
-               driver->getTexture("../data/skybox1.png"),\r
-               driver->getTexture("../data/skybox1.png"));*/\r
+               driver->getTexture(porting::getDataPath("skybox2.png").c_str()),\r
+               driver->getTexture(porting::getDataPath("skybox3.png").c_str()),\r
+               driver->getTexture(porting::getDataPath("skybox1.png").c_str()),\r
+               driver->getTexture(porting::getDataPath("skybox1.png").c_str()),\r
+               driver->getTexture(porting::getDataPath("skybox1.png").c_str()),\r
+               driver->getTexture(porting::getDataPath("skybox1.png").c_str()));*/\r
        \r
        /*\r
                Create the camera node\r
index 1f8faee6fe32ae6196abbc307e6c01fe03be7548..90ff05bd1468434066d23e51baa06dfe69b73ed6 100644 (file)
@@ -757,17 +757,17 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                        = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
                        if(dir == v3s16(0,-1,0))
                                buf->getMaterial().setTexture(0,
-                                               g_irrlicht->getTexture("../data/torch_on_floor.png"));
+                                               g_irrlicht->getTexture(porting::getDataPath("torch_on_floor.png").c_str()));
                        else if(dir == v3s16(0,1,0))
                                buf->getMaterial().setTexture(0,
-                                               g_irrlicht->getTexture("../data/torch_on_ceiling.png"));
+                                               g_irrlicht->getTexture(porting::getDataPath("torch_on_ceiling.png").c_str()));
                        // For backwards compatibility
                        else if(dir == v3s16(0,0,0))
                                buf->getMaterial().setTexture(0,
-                                               g_irrlicht->getTexture("../data/torch_on_floor.png"));
+                                               g_irrlicht->getTexture(porting::getDataPath("torch_on_floor.png").c_str()));
                        else
                                buf->getMaterial().setTexture(0, 
-                                               g_irrlicht->getTexture("../data/torch.png"));
+                                               g_irrlicht->getTexture(porting::getDataPath("torch.png").c_str()));
 
                        // Add to mesh
                        mesh_new->addMeshBuffer(buf);
index 653dbc332b230309883c972e8e25fcfe86ab5a83..ab12afc8e12a75aad035c6524668ea843551167c 100644 (file)
@@ -282,7 +282,7 @@ void RatObject::addToScene(scene::ISceneManager *smgr)
        buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
        buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
        buf->getMaterial().setTexture
-                       (0, driver->getTexture("../data/rat.png"));
+                       (0, driver->getTexture(porting::getDataPath("rat.png").c_str()));
        buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
        buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
        buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
@@ -360,7 +360,7 @@ video::ITexture * ItemObject::getItemImage()
        if(item)
                texture = item->getImage();
        /*else
-               texture = g_irrlicht->getTexture("../data/cloud.png");*/
+               texture = g_irrlicht->getTexture(porting::getDataPath("cloud.png").c_str());*/
        if(item)
                delete item;
        return texture;
@@ -414,7 +414,7 @@ void PlayerObject::addToScene(scene::ISceneManager *smgr)
        // Set material
        buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
        //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
-       buf->getMaterial().setTexture(0, driver->getTexture("../data/player.png"));
+       buf->getMaterial().setTexture(0, driver->getTexture(porting::getDataPath("player.png").c_str()));
        buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
        buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
        //buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
@@ -438,7 +438,7 @@ void PlayerObject::addToScene(scene::ISceneManager *smgr)
        // Set material
        buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
        //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
-       buf->getMaterial().setTexture(0, driver->getTexture("../data/player_back.png"));
+       buf->getMaterial().setTexture(0, driver->getTexture(porting::getDataPath("player_back.png").c_str()));
        buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
        buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
        buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
index aee41f3ba1620cb7e48eb7f08015932ab8f59958..d157162ec0b4c0b778f22912aef60036272e268f 100644 (file)
@@ -430,7 +430,7 @@ public:
                buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
                //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
                buf->getMaterial().setTexture
-                               (0, driver->getTexture("../data/sign.png"));
+                               (0, driver->getTexture(porting::getDataPath("sign.png").c_str()));
                buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
                buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
                buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
@@ -454,7 +454,7 @@ public:
                buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
                //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
                buf->getMaterial().setTexture
-                               (0, driver->getTexture("../data/sign_back.png"));
+                               (0, driver->getTexture(porting::getDataPath("sign_back.png").c_str()));
                buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
                buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
                buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
index 3dae653edef9f8460e2a916ad2d6a77a235a3687..f9997ddbe7e0915a0af0db8d0c9c28f00a655646 100644 (file)
@@ -19,6 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "mapnode.h"
 #include "tile.h"
+#include "porting.h"
+#include <string>
 
 /*
        Face directions:
@@ -46,20 +48,33 @@ u16 g_content_tiles[USEFUL_CONTENT_COUNT][6] =
        {TILE_WOOD,TILE_WOOD,TILE_WOOD,TILE_WOOD,TILE_WOOD,TILE_WOOD},
 };
 
-const char * g_content_inventory_textures[USEFUL_CONTENT_COUNT] =
+std::string g_content_inventory_texture_strings[USEFUL_CONTENT_COUNT];
+// Pointers to c_str()s of the above
+const char * g_content_inventory_texture_paths[USEFUL_CONTENT_COUNT] = {0};
+
+const char * g_content_inventory_texture_paths_base[USEFUL_CONTENT_COUNT] =
 {
-       "../data/stone.png",
-       "../data/grass.png",
-       "../data/water.png",
-       "../data/torch_on_floor.png",
-       "../data/tree_top.png",
-       "../data/leaves.png",
-       "../data/grass_footsteps.png",
-       "../data/mese.png",
-       "../data/mud.png",
-       "../data/water.png",
-       "../data/cloud.png",
-       "../data/coalstone.png",
-       "../data/wood.png",
+       "stone.png",
+       "grass.png",
+       "water.png",
+       "torch_on_floor.png",
+       "tree_top.png",
+       "leaves.png",
+       "grass_footsteps.png",
+       "mese.png",
+       "mud.png",
+       "water.png",
+       "cloud.png",
+       "coalstone.png",
+       "wood.png",
 };
 
+void init_content_inventory_texture_paths()
+{
+       for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
+       {
+               g_content_inventory_texture_strings[i] = porting::getDataPath(g_content_inventory_texture_paths_base[i]);
+               g_content_inventory_texture_paths[i] = g_content_inventory_texture_strings[i].c_str();
+       }
+}
+
index c6173292271c7d96db7ab2b3b7db6479b573331e..6a2199b49b864215fbbb5e602df61ff6cc8a27a5 100644 (file)
@@ -84,7 +84,9 @@ enum Content
 };
 
 extern u16 g_content_tiles[USEFUL_CONTENT_COUNT][6];
-extern const char * g_content_inventory_textures[USEFUL_CONTENT_COUNT];
+extern const char * g_content_inventory_texture_paths[USEFUL_CONTENT_COUNT];
+// Initializes g_content_inventory_texture_paths
+void init_content_inventory_texture_paths();
 
 /*
        If true, the material allows light propagation and brightness is stored
index d5d122bd643227937c77303bf4c9d30e4660b70c..c0dad697daa2bb35a6ee011fc8fd8f9505e05d83 100644 (file)
@@ -110,7 +110,7 @@ RemotePlayer::RemotePlayer(
                // Set material
                buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
                //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
-               buf->getMaterial().setTexture(0, driver->getTexture("../data/player.png"));
+               buf->getMaterial().setTexture(0, driver->getTexture(porting::getDataPath("player.png").c_str()));
                buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
                buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
                //buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
@@ -134,7 +134,7 @@ RemotePlayer::RemotePlayer(
                // Set material
                buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
                //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
-               buf->getMaterial().setTexture(0, driver->getTexture("../data/player_back.png"));
+               buf->getMaterial().setTexture(0, driver->getTexture(porting::getDataPath("player_back.png").c_str()));
                buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
                buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
                buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
diff --git a/src/porting.cpp b/src/porting.cpp
new file mode 100644 (file)
index 0000000..bff865c
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+/*
+       Random portability stuff
+
+       See comments in porting.h
+*/
+
+#include "porting.h"
+
+namespace porting
+{
+
+std::string path_data = "../data";
+std::string path_userdata = "../";
+
+void pathRemoveFile(char *path, char delim)
+{
+       // Remove filename and path delimiter
+       int i;
+       for(i = strlen(path)-1; i>=0; i--)
+       {
+               if(path[i] == delim)
+                       break;
+       }
+       path[i] = 0;
+}
+
+void initializePaths()
+{
+#ifdef RUN_IN_PLACE
+       /*
+               Use relative paths if RUN_IN_PLACE
+       */
+
+       dstream<<"Using relative paths (RUN_IN_PLACE)"<<std::endl;
+
+       /*
+               Windows
+       */
+       #if defined(_WIN32)
+               #include <windows.h>
+
+       const DWORD buflen = 1000;
+       char buf[buflen];
+       DWORD len;
+       
+       // Find path of executable and set path_data relative to it
+       len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen);
+       assert(len < buflen);
+       pathRemoveFile(buf, '\\');
+
+       // Use "./bin/../data"
+       path_data = std::string(buf) + "/../data";
+               
+       // Use "./bin/../"
+       path_userdata = std::string(buf) + "/../";
+
+       /*
+               Linux
+       */
+       #elif defined(linux)
+               #include <unistd.h>
+       
+       char buf[BUFSIZ];
+       // Get path to executable
+       readlink("/proc/self/exe", buf, BUFSIZ);
+       
+       pathRemoveFile(buf, '/');
+
+       // Use "./bin/../data"
+       path_data = std::string(buf) + "/../data";
+               
+       // Use "./bin/../"
+       path_userdata = std::string(buf) + "/../";
+       
+       /*
+               OS X
+       */
+       #elif defined(__APPLE__)
+       
+       //TODO: Get path of executable. This assumes working directory is bin/
+       dstream<<"WARNING: Relative path not properly supported on OS X"
+                       <<std::endl;
+       path_data = std::string("../data");
+       path_userdata = std::string("../");
+
+       #endif
+#else
+       /*
+               Use platform-specific paths otherwise
+       */
+
+       dstream<<"Using system-wide paths (NOT RUN_IN_PLACE)"<<std::endl;
+
+       /*
+               Windows
+       */
+       #if defined(_WIN32)
+               #include <windows.h>
+
+       const DWORD buflen = 1000;
+       char buf[buflen];
+       DWORD len;
+       
+       // Find path of executable and set path_data relative to it
+       len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen);
+       assert(len < buflen);
+       pathRemoveFile(buf, '\\');
+       
+       // Use "./bin/../data"
+       path_data = std::string(buf) + "/../data";
+               
+       // Use "C:\Documents and Settings\user\Application Data\<APPNAME>"
+       len = GetEnvironmentVariable("APPDATA", buf, buflen);
+       assert(len < buflen);
+       path_userdata = std::string(buf) + "/" + APPNAME;
+
+       /*
+               Linux
+       */
+       #elif defined(linux)
+       
+       path_userdata = std::string("~/.") + APPNAME;
+       path_data = std::string("/usr/share/") + APPNAME;
+       
+       /*
+               OS X
+       */
+       #elif defined(__APPLE__)
+
+       path_userdata = std::string("~/Library/Application Support/") + APPNAME;
+       path_data = std::string("minetest-mac.app/Contents/Resources/data/");
+
+       #endif
+#endif
+
+       dstream<<"path_data = "<<path_data<<std::endl;
+       dstream<<"path_userdata = "<<path_userdata<<std::endl;
+}
+
+} //namespace porting
+
index 19ac5c6bb920f7ff8c69b163e7e62b46e02ed550..71891de399e72ae2b696afd5b3e1fdb02d702601 100644 (file)
@@ -24,8 +24,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef PORTING_HEADER
 #define PORTING_HEADER
 
+#include <string>
 // Included for u64 and such
 #include "common_irrlicht.h"
+#include "debug.h"
+#include "constants.h"
 
 #ifdef _WIN32
        #define SWPRINTF_CHARSTRING L"%S"
@@ -44,6 +47,33 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 namespace porting
 {
 
+/*
+       Path of static data directory.
+*/
+extern std::string path_data;
+
+/*
+       Directory for storing user data. Examples:
+       Windows: "C:\Documents and Settings\user\Application Data\<APPNAME>"
+       Linux: "~/.<APPNAME>"
+       Mac: "~/Library/Application Support/<APPNAME>"
+*/
+extern std::string path_userdata;
+
+/*
+       Get full path of stuff in data directory.
+       Example: "stone.png" -> "../data/stone.png"
+*/
+inline std::string getDataPath(const char *subpath)
+{
+       return path_data + "/" + subpath;
+}
+
+/*
+       Initialize path_data and path_userdata.
+*/
+void initializePaths();
+
 /*
        Resolution is 10-20ms.
        Remember to check for overflows.
@@ -67,5 +97,5 @@ namespace porting
 
 } // namespace porting
 
-#endif
+#endif // PORTING_HEADER
 
index cd6f78c628cb704678fb2f4e1fd675df5b390a55..b716a7df1d0d21570d2ad5e824b5461712f75520 100644 (file)
@@ -471,7 +471,7 @@ private:
        float m_time_counter;
        float m_time_of_day_send_timer;
        
-       MutexedVariable<float> m_uptime;
+       MutexedVariable<double> m_uptime;
 
        enum PeerChangeType
        {
index 01919a7dfb5f25d70044b86d91ba9f805ddd4c45..7dcc304a014e585f8c1bac0c95bc5aa7756ba872 100644 (file)
@@ -123,6 +123,8 @@ int main(int argc, char *argv[])
 
        DSTACK(__FUNCTION_NAME);
 
+       porting.initializePaths();
+
        initializeMaterialProperties();
 
        BEGIN_DEBUG_EXCEPTION_HANDLER
@@ -222,15 +224,12 @@ int main(int argc, char *argv[])
        }
        else
        {
-               const char *filenames[2] =
-               {
-                       "../minetest.conf",
-                       "../../minetest.conf"
-               };
+               core::array<std::string> filenames;
+               filenames.push_back(porting::path_userdata + "/minetest.conf");
 
-               for(u32 i=0; i<2; i++)
+               for(u32 i=0; i<filenames.size(); i++)
                {
-                       bool r = g_settings.readConfigFile(filenames[i]);
+                       bool r = g_settings.readConfigFile(filenames[i].c_str());
                        if(r)
                        {
                                configpath = filenames[i];
@@ -306,7 +305,7 @@ int main(int argc, char *argv[])
        std::cout<<std::endl;
        
        // Figure out path to map
-       std::string map_dir = "../map";
+       std::string map_dir = porting::path_userdata+"/map";
        if(cmd_args.exists("map-dir"))
                map_dir = cmd_args.get("map-dir");
        
index a9470dc8e2d4915149f48e99a52ca3a6b15797d2..90de1164227d362d51d6f5aa0fd5aa4454067673 100644 (file)
@@ -18,27 +18,50 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "tile.h"
+#include "porting.h"
+// For IrrlichtWrapper
 #include "main.h"
+#include <string>
 
 // A mapping from tiles to paths of textures
-const char * g_tile_texture_paths[TILES_COUNT] =
+
+const char * g_tile_texture_filenames[TILES_COUNT] =
 {
        NULL,
-       "../data/stone.png",
-       "../data/water.png",
-       "../data/grass.png",
-       "../data/tree.png",
-       "../data/leaves.png",
-       "../data/grass_footsteps.png",
-       "../data/mese.png",
-       "../data/mud.png",
-       "../data/tree_top.png",
-       "../data/mud_with_grass.png",
-       "../data/cloud.png",
-       "../data/coalstone.png",
-       "../data/wood.png",
+       "stone.png",
+       "water.png",
+       "grass.png",
+       "tree.png",
+       "leaves.png",
+       "grass_footsteps.png",
+       "mese.png",
+       "mud.png",
+       "tree_top.png",
+       "mud_with_grass.png",
+       "cloud.png",
+       "coalstone.png",
+       "wood.png",
 };
 
+std::string g_tile_texture_path_strings[TILES_COUNT];
+const char * g_tile_texture_paths[TILES_COUNT] = {0};
+
+void init_tile_texture_paths()
+{
+       for(s32 i=0; i<TILES_COUNT; i++)
+       {
+               const char *filename = g_tile_texture_filenames[i];
+
+               if(filename != NULL)
+               {
+                       g_tile_texture_path_strings[i] =
+                                       porting::getDataPath(filename);
+                       g_tile_texture_paths[i] =
+                                       g_tile_texture_path_strings[i].c_str();
+               }
+       }
+}
+
 const char * tile_texture_path_get(u32 i)
 {
        assert(i < TILES_COUNT);
@@ -54,7 +77,7 @@ void tile_materials_preload(IrrlichtWrapper *irrlicht)
 {
        for(s32 i=0; i<TILES_COUNT; i++)
        {
-               const char *path = g_tile_texture_paths[i];
+               const char *path = tile_texture_path_get(i);
 
                video::ITexture *t = NULL;
 
index c35c27e6457257f5240abd02871a48437b64d2bd..b6dcb249acee73ff7f2254bbc9de996e86c7273c 100644 (file)
@@ -95,13 +95,12 @@ struct TileSpec
        } param;
 };
 
-/*extern const char * g_tile_texture_paths[TILES_COUNT];
-extern video::SMaterial g_tile_materials[TILES_COUNT];*/
-
 /*
        Functions
 */
 
+void init_tile_texture_paths();
+
 const char * tile_texture_path_get(u32 i);
 
 // Initializes g_tile_materials