# 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
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
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
--config <path-to-file>
- If not given as a parameter, these are checked, in order:
../minetest.conf
- ../../minetest.conf
Command-line options:
- Use --help
OmitFramePointers="true"\r
WholeProgramOptimization="true"\r
AdditionalIncludeDirectories=""C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include";"..\jthread\jthread-1.2.1\src";"..\irrlicht\irrlicht-1.7.1\include";"..\zlib\zlib-1.2.5""\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
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
#include "debug.h"
#include <stdio.h>
#include <stdlib.h>
-#include "porting.h"
/*
Debug output
if(g_debugstreams[1])
fclose(g_debugstreams[1]);
- //sleep_ms(3000);
-
abort();
}
#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
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
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;
}
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()
{
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);
{
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);
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"
\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
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
#include "guiTextInputMenu.h"\r
#include "materials.h"\r
#include "guiMessageMenu.h"\r
+#include "filesys.h"\r
\r
IrrlichtWrapper *g_irrlicht;\r
\r
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
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
}\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
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
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
\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
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
*/\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
*/\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
= 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);
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;
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;
// 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;
// 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;
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;
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;
#include "mapnode.h"
#include "tile.h"
+#include "porting.h"
+#include <string>
/*
Face directions:
{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();
+ }
+}
+
};
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
// 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;
// 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;
--- /dev/null
+/*
+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
+
#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"
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.
} // namespace porting
-#endif
+#endif // PORTING_HEADER
float m_time_counter;
float m_time_of_day_send_timer;
- MutexedVariable<float> m_uptime;
+ MutexedVariable<double> m_uptime;
enum PeerChangeType
{
DSTACK(__FUNCTION_NAME);
+ porting.initializePaths();
+
initializeMaterialProperties();
BEGIN_DEBUG_EXCEPTION_HANDLER
}
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];
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");
*/
#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);
{
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;
} 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