From 6b6c2d37ea1f9075c4fbf0d7e2d52e527e1f86aa Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 7 Jan 2011 19:39:27 +0200 Subject: [PATCH] Added a more flexible path system (and fixed some minor stuff) --- Makefile | 20 ++--- doc/README.txt | 1 - minetest.vcproj | 6 +- src/constants.h | 15 ++-- src/debug.cpp | 3 - src/guiPauseMenu.cpp | 7 +- src/inventory.cpp | 8 +- src/inventory.h | 10 +-- src/irrlichtwrapper.cpp | 4 +- src/main.cpp | 53 +++++++------ src/mapblock.cpp | 8 +- src/mapblockobject.cpp | 8 +- src/mapblockobject.h | 4 +- src/mapnode.cpp | 43 +++++++---- src/mapnode.h | 4 +- src/player.cpp | 4 +- src/porting.cpp | 160 ++++++++++++++++++++++++++++++++++++++++ src/porting.h | 32 +++++++- src/server.h | 2 +- src/servermain.cpp | 15 ++-- src/tile.cpp | 53 +++++++++---- src/tile.h | 5 +- 22 files changed, 355 insertions(+), 110 deletions(-) create mode 100644 src/porting.cpp diff --git a/Makefile b/Makefile index 5f4195f96..8b92f72f7 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Makefile for Irrlicht Examples # It's usually sufficient to change just the target name and source file list # and be sure that CXX is set to a valid compiler -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 +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 DEBUG_TARGET = debugtest DEBUG_SOURCES = $(addprefix src/, $(SOURCE_FILES)) @@ -22,10 +22,6 @@ SERVER_OBJECTS = $(addprefix $(SERVER_BUILD_DIR)/, $(SERVER_SOURCE_FILES:.cpp=.o IRRLICHTPATH = ../irrlicht/irrlicht-1.7.1 JTHREADPATH = ../jthread/jthread-1.2.1 -#CXXFLAGS = -O2 -ffast-math -Wall -fomit-frame-pointer -pipe -#CXXFLAGS = -O2 -ffast-math -Wall -g -pipe -#CXXFLAGS = -O1 -ffast-math -Wall -g -CXXFLAGS = -Wall -g -O1 all: fast @@ -33,13 +29,17 @@ ifeq ($(HOSTTYPE), x86_64) LIBSELECT=64 endif -debug fast: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L$(IRRLICHTPATH)/lib/Linux -L$(JTHREADPATH)/src/.libs -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -ljthread -lz -debug: CPPFLAGS = -I$(IRRLICHTPATH)/include -I/usr/X11R6/include -I$(JTHREADPATH)/src -DDEBUG +debug: CXXFLAGS = -Wall -g -O1 +debug: CPPFLAGS = -I$(IRRLICHTPATH)/include -I/usr/X11R6/include -I$(JTHREADPATH)/src -DDEBUG -DRUN_IN_PLACE +debug: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L$(IRRLICHTPATH)/lib/Linux -L$(JTHREADPATH)/src/.libs -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -ljthread -lz + +fast: CXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686 fast: CPPFLAGS = -I$(IRRLICHTPATH)/include -I/usr/X11R6/include -I$(JTHREADPATH)/src -DUNITTEST_DISABLE -fast server: CXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686 -server: LDFLAGS = -L$(JTHREADPATH)/src/.libs -ljthread -lz -lpthread +fast: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L$(IRRLICHTPATH)/lib/Linux -L$(JTHREADPATH)/src/.libs -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -ljthread -lz + +server: CXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686 server: CPPFLAGS = -I$(IRRLICHTPATH)/include -I/usr/X11R6/include -I$(JTHREADPATH)/src -DSERVER -DUNITTEST_DISABLE -debug fast clean_debug: SYSTEM=Linux +server: LDFLAGS = -L$(JTHREADPATH)/src/.libs -ljthread -lz -lpthread DEBUG_DESTPATH = bin/$(DEBUG_TARGET) FAST_DESTPATH = bin/$(FAST_TARGET) diff --git a/doc/README.txt b/doc/README.txt index 7f6afcce7..8cfddb2b6 100644 --- a/doc/README.txt +++ b/doc/README.txt @@ -29,7 +29,6 @@ Configuration file: --config - If not given as a parameter, these are checked, in order: ../minetest.conf - ../../minetest.conf Command-line options: - Use --help diff --git a/minetest.vcproj b/minetest.vcproj index c244b4370..a4e6cf9fd 100644 --- a/minetest.vcproj +++ b/minetest.vcproj @@ -118,7 +118,7 @@ OmitFramePointers="true" WholeProgramOptimization="true" 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"" - PreprocessorDefinitions="WIN32;_HAS_ITERATOR_DEBUGGING=0,UNITTEST_DISABLE,_CRT_SECURE_NO_DEPRECATE" + PreprocessorDefinitions="WIN32;_HAS_ITERATOR_DEBUGGING=0;UNITTEST_DISABLE;_CRT_SECURE_NO_DEPRECATE;RUN_IN_PLACE" ExceptionHandling="2" BufferSecurityCheck="false" EnableEnhancedInstructionSet="1" @@ -263,6 +263,10 @@ RelativePath=".\src\player.cpp" > + + 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 + 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 #include -#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 " <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 filenames; + filenames.push_back(porting::path_userdata + "/minetest.conf"); - for(u32 i=0; i<2; i++) + for(u32 i=0; i "<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; 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 /* 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; igetMaterial().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 + +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)"< + + 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 + + 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" + < + + 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\" + 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 = "<" + Linux: "~/." + Mac: "~/Library/Application Support/" +*/ +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 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 m_uptime; + MutexedVariable 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 filenames; + filenames.push_back(porting::path_userdata + "/minetest.conf"); - for(u32 i=0; i<2; i++) + for(u32 i=0; i // 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