aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/constants.h15
-rw-r--r--src/debug.cpp3
-rw-r--r--src/guiPauseMenu.cpp7
-rw-r--r--src/inventory.cpp8
-rw-r--r--src/inventory.h10
-rw-r--r--src/irrlichtwrapper.cpp4
-rw-r--r--src/main.cpp53
-rw-r--r--src/mapblock.cpp8
-rw-r--r--src/mapblockobject.cpp8
-rw-r--r--src/mapblockobject.h4
-rw-r--r--src/mapnode.cpp43
-rw-r--r--src/mapnode.h4
-rw-r--r--src/player.cpp4
-rw-r--r--src/porting.cpp160
-rw-r--r--src/porting.h32
-rw-r--r--src/server.h2
-rw-r--r--src/servermain.cpp15
-rw-r--r--src/tile.cpp53
-rw-r--r--src/tile.h5
19 files changed, 340 insertions, 98 deletions
diff --git a/src/constants.h b/src/constants.h
index b6b09b50b..cfb340bf9 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -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
diff --git a/src/debug.cpp b/src/debug.cpp
index 9fbdf7a39..ca49c9b77 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -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();
}
diff --git a/src/guiPauseMenu.cpp b/src/guiPauseMenu.cpp
index ede42bb1e..46bb799e6 100644
--- a/src/guiPauseMenu.cpp
+++ b/src/guiPauseMenu.cpp
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiPauseMenu.h"
#include "debug.h"
#include "serialization.h"
+#include "porting.h"
GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
@@ -127,11 +128,11 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize)
L"by Perttu Ahola\n"
L"celeron55@gmail.com\n\n"
L"SER_FMT_VER_HIGHEST=%i\n"
- L"max_texture_size=\n(%i,%i)\n"
+ L"userdata path = \n"
+ SWPRINTF_CHARSTRING
,
(int)SER_FMT_VER_HIGHEST,
- max_texture_size.X,
- max_texture_size.Y
+ porting::path_userdata.c_str()
);
Environment->addStaticText(text, rect, false, true, this, 259);
diff --git a/src/inventory.cpp b/src/inventory.cpp
index a2aba311b..713adefdf 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -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;
}
diff --git a/src/inventory.h b/src/inventory.h
index 97eacef5b..84ccd5bd6 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -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);
diff --git a/src/irrlichtwrapper.cpp b/src/irrlichtwrapper.cpp
index e48e328e3..fe4ff2771 100644
--- a/src/irrlichtwrapper.cpp
+++ b/src/irrlichtwrapper.cpp
@@ -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"
diff --git a/src/main.cpp b/src/main.cpp
index e3fb9b877..9ec49feb3 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -177,6 +177,8 @@ TODO: When server sees that client is removing an inexistent block or
TODO: When player dies, throw items on map
+TODO: Use porting::path_userdata for configuration file
+
TODO: Optimize day/night mesh updating somehow
- create copies of all textures for all lighting values and only
change texture for material?
@@ -187,12 +189,11 @@ TODO: Optimize day/night mesh updating somehow
TODO: Map generator version 2
- Create surface areas based on central points; a given point's
area type is given by the nearest central point
+ - Separate points for heightmap, caves, plants and minerals?
+ - Flat land, mountains, forest, jungle
- Cliffs, arcs
-TODO: A Constant for the "../data/" path (differs on Mac and on proper
- linux installations)
-
-TODO: Add defined(__APPLE__) to filesys.cpp
+TODO: Add gui option to remove map
Doing now:
======================================================================
@@ -257,6 +258,7 @@ Doing now:
#include "guiTextInputMenu.h"
#include "materials.h"
#include "guiMessageMenu.h"
+#include "filesys.h"
IrrlichtWrapper *g_irrlicht;
@@ -1099,7 +1101,11 @@ int main(int argc, char *argv[])
debug_stacks_init();
DSTACK(__FUNCTION_NAME);
-
+
+ porting::initializePaths();
+ // Create user data directory
+ fs::CreateDir(porting::path_userdata);
+
initializeMaterialProperties();
BEGIN_DEBUG_EXCEPTION_HANDLER
@@ -1123,6 +1129,7 @@ int main(int argc, char *argv[])
allowed_options.insert("random-input", ValueSpec(VALUETYPE_FLAG));
allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));
allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));
+ allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));
Settings cmd_args;
@@ -1202,15 +1209,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];
@@ -1274,6 +1278,11 @@ int main(int argc, char *argv[])
std::cout<<"-> "<<port<<std::endl;
}
+ //Map directory
+ std::string map_dir = porting::path_userdata+"/map";
+ if(cmd_args.exists("map-dir"))
+ map_dir = cmd_args.get("map-dir");
+
if(cmd_args.getFlag("server"))
{
DSTACK("Dedicated server branch");
@@ -1284,7 +1293,7 @@ int main(int argc, char *argv[])
std::cout<<"========================"<<std::endl;
std::cout<<std::endl;
- Server server("../map", hm_params, map_params);
+ Server server(map_dir, hm_params, map_params);
server.start(port);
for(;;)
@@ -1422,7 +1431,7 @@ int main(int argc, char *argv[])
guienv = device->getGUIEnvironment();
gui::IGUISkin* skin = guienv->getSkin();
- gui::IGUIFont* font = guienv->getFont("../data/fontlucida.png");
+ gui::IGUIFont* font = guienv->getFont(porting::getDataPath("fontlucida.png").c_str());
if(font)
skin->setFont(font);
@@ -1453,6 +1462,8 @@ int main(int argc, char *argv[])
Preload some textures
*/
+ init_content_inventory_texture_paths();
+ init_tile_texture_paths();
tile_materials_preload(g_irrlicht);
/*
@@ -1468,7 +1479,7 @@ int main(int argc, char *argv[])
*/
SharedPtr<Server> server;
if(hosting){
- server = new Server("../map", hm_params, map_params);
+ server = new Server(map_dir, hm_params, map_params);
server->start(port);
}
@@ -1514,12 +1525,12 @@ int main(int argc, char *argv[])
*/
/*scene::ISceneNode* skybox;
skybox = smgr->addSkyBoxSceneNode(
- driver->getTexture("../data/skybox2.png"),
- driver->getTexture("../data/skybox3.png"),
- driver->getTexture("../data/skybox1.png"),
- driver->getTexture("../data/skybox1.png"),
- driver->getTexture("../data/skybox1.png"),
- driver->getTexture("../data/skybox1.png"));*/
+ driver->getTexture(porting::getDataPath("skybox2.png").c_str()),
+ driver->getTexture(porting::getDataPath("skybox3.png").c_str()),
+ driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
+ driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
+ driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
+ driver->getTexture(porting::getDataPath("skybox1.png").c_str()));*/
/*
Create the camera node
diff --git a/src/mapblock.cpp b/src/mapblock.cpp
index 1f8faee6f..90ff05bd1 100644
--- a/src/mapblock.cpp
+++ b/src/mapblock.cpp
@@ -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);
diff --git a/src/mapblockobject.cpp b/src/mapblockobject.cpp
index 653dbc332..ab12afc8e 100644
--- a/src/mapblockobject.cpp
+++ b/src/mapblockobject.cpp
@@ -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;
diff --git a/src/mapblockobject.h b/src/mapblockobject.h
index aee41f3ba..d157162ec 100644
--- a/src/mapblockobject.h
+++ b/src/mapblockobject.h
@@ -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;
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index 3dae653ed..f9997ddbe 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -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();
+ }
+}
+
diff --git a/src/mapnode.h b/src/mapnode.h
index c61732922..6a2199b49 100644
--- a/src/mapnode.h
+++ b/src/mapnode.h
@@ -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
diff --git a/src/player.cpp b/src/player.cpp
index d5d122bd6..c0dad697d 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -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
index 000000000..bff865c53
--- /dev/null
+++ b/src/porting.cpp
@@ -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
+
diff --git a/src/porting.h b/src/porting.h
index 19ac5c6bb..71891de39 100644
--- a/src/porting.h
+++ b/src/porting.h
@@ -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"
@@ -45,6 +48,33 @@ 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.
Overflow can occur at any value higher than 10000000.
@@ -67,5 +97,5 @@ namespace porting
} // namespace porting
-#endif
+#endif // PORTING_HEADER
diff --git a/src/server.h b/src/server.h
index cd6f78c62..b716a7df1 100644
--- a/src/server.h
+++ b/src/server.h
@@ -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
{
diff --git a/src/servermain.cpp b/src/servermain.cpp
index 01919a7df..7dcc304a0 100644
--- a/src/servermain.cpp
+++ b/src/servermain.cpp
@@ -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");
diff --git a/src/tile.cpp b/src/tile.cpp
index a9470dc8e..90de11642 100644
--- a/src/tile.cpp
+++ b/src/tile.cpp
@@ -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;
diff --git a/src/tile.h b/src/tile.h
index c35c27e64..b6dcb249a 100644
--- a/src/tile.h
+++ b/src/tile.h
@@ -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