Added a more flexible path system (and fixed some minor stuff)

This commit is contained in:
Perttu Ahola 2011-01-07 19:39:27 +02:00
parent dc414091e7
commit 6b6c2d37ea
22 changed files with 356 additions and 111 deletions

@ -1,7 +1,7 @@
# Makefile for Irrlicht Examples # Makefile for Irrlicht Examples
# It's usually sufficient to change just the target name and source file list # 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 # 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_TARGET = debugtest
DEBUG_SOURCES = $(addprefix src/, $(SOURCE_FILES)) 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 IRRLICHTPATH = ../irrlicht/irrlicht-1.7.1
JTHREADPATH = ../jthread/jthread-1.2.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 all: fast
@ -33,13 +29,17 @@ ifeq ($(HOSTTYPE), x86_64)
LIBSELECT=64 LIBSELECT=64
endif 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: CXXFLAGS = -Wall -g -O1
debug: CPPFLAGS = -I$(IRRLICHTPATH)/include -I/usr/X11R6/include -I$(JTHREADPATH)/src -DDEBUG 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: 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 fast: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L$(IRRLICHTPATH)/lib/Linux -L$(JTHREADPATH)/src/.libs -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -ljthread -lz
server: LDFLAGS = -L$(JTHREADPATH)/src/.libs -ljthread -lz -lpthread
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 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) DEBUG_DESTPATH = bin/$(DEBUG_TARGET)
FAST_DESTPATH = bin/$(FAST_TARGET) FAST_DESTPATH = bin/$(FAST_TARGET)

@ -29,7 +29,6 @@ Configuration file:
--config <path-to-file> --config <path-to-file>
- If not given as a parameter, these are checked, in order: - If not given as a parameter, these are checked, in order:
../minetest.conf ../minetest.conf
../../minetest.conf
Command-line options: Command-line options:
- Use --help - Use --help

@ -118,7 +118,7 @@
OmitFramePointers="true" OmitFramePointers="true"
WholeProgramOptimization="true" WholeProgramOptimization="true"
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;" 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;"
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" ExceptionHandling="2"
BufferSecurityCheck="false" BufferSecurityCheck="false"
EnableEnhancedInstructionSet="1" EnableEnhancedInstructionSet="1"
@ -263,6 +263,10 @@
RelativePath=".\src\player.cpp" RelativePath=".\src\player.cpp"
> >
</File> </File>
<File
RelativePath=".\src\porting.cpp"
>
</File>
<File <File
RelativePath=".\src\serialization.cpp" RelativePath=".\src\serialization.cpp"
> >

@ -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. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
/*
(c) 2010 Perttu Ahola <celeron55@gmail.com>
*/
#ifndef CONSTANTS_HEADER #ifndef CONSTANTS_HEADER
#define CONSTANTS_HEADER #define CONSTANTS_HEADER
/*
All kinds of constants.
Cross-platform compatibility crap should go in porting.h.
*/
#define APPNAME "minetest"
#define DEBUGFILE "debug.txt" #define DEBUGFILE "debug.txt"
// Define for simulating the quirks of sending through internet // Define for simulating the quirks of sending through internet.
// WARNING: This disables unit testing of socket and connection // Causes the socket class to deliberately drop random packets.
// This disables unit testing of socket and connection.
#define INTERNET_SIMULATOR 0 #define INTERNET_SIMULATOR 0
#define CONNECTION_TIMEOUT 30 #define CONNECTION_TIMEOUT 30

@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "debug.h" #include "debug.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "porting.h"
/* /*
Debug output Debug output
@ -74,8 +73,6 @@ void assert_fail(const char *assertion, const char *file,
if(g_debugstreams[1]) if(g_debugstreams[1])
fclose(g_debugstreams[1]); fclose(g_debugstreams[1]);
//sleep_ms(3000);
abort(); abort();
} }

@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiPauseMenu.h" #include "guiPauseMenu.h"
#include "debug.h" #include "debug.h"
#include "serialization.h" #include "serialization.h"
#include "porting.h"
GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env, GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id, gui::IGUIElement* parent, s32 id,
@ -127,11 +128,11 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize)
L"by Perttu Ahola\n" L"by Perttu Ahola\n"
L"celeron55@gmail.com\n\n" L"celeron55@gmail.com\n\n"
L"SER_FMT_VER_HIGHEST=%i\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, (int)SER_FMT_VER_HIGHEST,
max_texture_size.X, porting::path_userdata.c_str()
max_texture_size.Y
); );
Environment->addStaticText(text, rect, false, true, this, 259); Environment->addStaticText(text, rect, false, true, this, 259);

@ -97,12 +97,12 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
video::ITexture * MapBlockObjectItem::getImage() video::ITexture * MapBlockObjectItem::getImage()
{ {
if(m_inventorystring.substr(0,3) == "Rat") if(m_inventorystring.substr(0,3) == "Rat")
//return g_device->getVideoDriver()->getTexture("../data/rat.png"); //return g_device->getVideoDriver()->getTexture(porting::getDataPath("rat.png").c_str());
return g_irrlicht->getTexture("../data/rat.png"); return g_irrlicht->getTexture(porting::getDataPath("rat.png").c_str());
if(m_inventorystring.substr(0,4) == "Sign") if(m_inventorystring.substr(0,4) == "Sign")
//return g_device->getVideoDriver()->getTexture("../data/sign.png"); //return g_device->getVideoDriver()->getTexture(porting::getDataPath("sign.png").c_str());
return g_irrlicht->getTexture("../data/sign.png"); return g_irrlicht->getTexture(porting::getDataPath("sign.png").c_str());
return NULL; return NULL;
} }

@ -131,7 +131,7 @@ public:
if(m_content >= USEFUL_CONTENT_COUNT) if(m_content >= USEFUL_CONTENT_COUNT)
return NULL; return NULL;
return g_irrlicht->getTexture(g_content_inventory_textures[m_content]); return g_irrlicht->getTexture(g_content_inventory_texture_paths[m_content]);
} }
#endif #endif
std::string getText() std::string getText()
@ -258,7 +258,7 @@ public:
{ {
std::string basename; std::string basename;
if(m_subname == "Stick") if(m_subname == "Stick")
basename = "../data/stick.png"; basename = porting::getDataPath("stick.png").c_str();
// Default to cloud texture // Default to cloud texture
else else
basename = tile_texture_path_get(TILE_CLOUD); basename = tile_texture_path_get(TILE_CLOUD);
@ -333,11 +333,11 @@ public:
{ {
std::string basename; std::string basename;
if(m_toolname == "WPick") if(m_toolname == "WPick")
basename = "../data/tool_wpick.png"; basename = porting::getDataPath("tool_wpick.png").c_str();
else if(m_toolname == "STPick") else if(m_toolname == "STPick")
basename = "../data/tool_stpick.png"; basename = porting::getDataPath("tool_stpick.png").c_str();
else if(m_toolname == "MesePick") else if(m_toolname == "MesePick")
basename = "../data/tool_mesepick.png"; basename = porting::getDataPath("tool_mesepick.png").c_str();
// Default to cloud texture // Default to cloud texture
else else
basename = tile_texture_path_get(TILE_CLOUD); basename = tile_texture_path_get(TILE_CLOUD);

@ -124,11 +124,11 @@ video::ITexture * CrackTextureMod::make(video::ITexture *original,
video::IImage *baseimage = driver->createImage(original, pos_base, dim); video::IImage *baseimage = driver->createImage(original, pos_base, dim);
assert(baseimage); assert(baseimage);
video::IImage *crackimage = driver->createImageFromFile("../data/crack.png"); video::IImage *crackimage = driver->createImageFromFile(porting::getDataPath("crack.png").c_str());
assert(crackimage); assert(crackimage);
#if 0 #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 " dstream<<__FUNCTION_NAME<<": crack texture size is "
<<other->getSize().Width<<"x" <<other->getSize().Width<<"x"

@ -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: When player dies, throw items on map
TODO: Use porting::path_userdata for configuration file
TODO: Optimize day/night mesh updating somehow TODO: Optimize day/night mesh updating somehow
- create copies of all textures for all lighting values and only - create copies of all textures for all lighting values and only
change texture for material? change texture for material?
@ -187,12 +189,11 @@ TODO: Optimize day/night mesh updating somehow
TODO: Map generator version 2 TODO: Map generator version 2
- Create surface areas based on central points; a given point's - Create surface areas based on central points; a given point's
area type is given by the nearest central point area type is given by the nearest central point
- Separate points for heightmap, caves, plants and minerals?
- Flat land, mountains, forest, jungle
- Cliffs, arcs - Cliffs, arcs
TODO: A Constant for the "../data/" path (differs on Mac and on proper TODO: Add gui option to remove map
linux installations)
TODO: Add defined(__APPLE__) to filesys.cpp
Doing now: Doing now:
====================================================================== ======================================================================
@ -257,6 +258,7 @@ Doing now:
#include "guiTextInputMenu.h" #include "guiTextInputMenu.h"
#include "materials.h" #include "materials.h"
#include "guiMessageMenu.h" #include "guiMessageMenu.h"
#include "filesys.h"
IrrlichtWrapper *g_irrlicht; IrrlichtWrapper *g_irrlicht;
@ -1099,7 +1101,11 @@ int main(int argc, char *argv[])
debug_stacks_init(); debug_stacks_init();
DSTACK(__FUNCTION_NAME); DSTACK(__FUNCTION_NAME);
porting::initializePaths();
// Create user data directory
fs::CreateDir(porting::path_userdata);
initializeMaterialProperties(); initializeMaterialProperties();
BEGIN_DEBUG_EXCEPTION_HANDLER 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("random-input", ValueSpec(VALUETYPE_FLAG));
allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG)); allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG));
allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG)); allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG));
allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING));
Settings cmd_args; Settings cmd_args;
@ -1202,15 +1209,12 @@ int main(int argc, char *argv[])
} }
else else
{ {
const char *filenames[2] = core::array<std::string> filenames;
{ filenames.push_back(porting::path_userdata + "/minetest.conf");
"../minetest.conf",
"../../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) if(r)
{ {
configpath = filenames[i]; configpath = filenames[i];
@ -1274,6 +1278,11 @@ int main(int argc, char *argv[])
std::cout<<"-> "<<port<<std::endl; 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")) if(cmd_args.getFlag("server"))
{ {
DSTACK("Dedicated server branch"); DSTACK("Dedicated server branch");
@ -1284,7 +1293,7 @@ int main(int argc, char *argv[])
std::cout<<"========================"<<std::endl; std::cout<<"========================"<<std::endl;
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); server.start(port);
for(;;) for(;;)
@ -1422,7 +1431,7 @@ int main(int argc, char *argv[])
guienv = device->getGUIEnvironment(); guienv = device->getGUIEnvironment();
gui::IGUISkin* skin = guienv->getSkin(); 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) if(font)
skin->setFont(font); skin->setFont(font);
@ -1453,6 +1462,8 @@ int main(int argc, char *argv[])
Preload some textures Preload some textures
*/ */
init_content_inventory_texture_paths();
init_tile_texture_paths();
tile_materials_preload(g_irrlicht); tile_materials_preload(g_irrlicht);
/* /*
@ -1468,7 +1479,7 @@ int main(int argc, char *argv[])
*/ */
SharedPtr<Server> server; SharedPtr<Server> server;
if(hosting){ if(hosting){
server = new Server("../map", hm_params, map_params); server = new Server(map_dir, hm_params, map_params);
server->start(port); server->start(port);
} }
@ -1514,12 +1525,12 @@ int main(int argc, char *argv[])
*/ */
/*scene::ISceneNode* skybox; /*scene::ISceneNode* skybox;
skybox = smgr->addSkyBoxSceneNode( skybox = smgr->addSkyBoxSceneNode(
driver->getTexture("../data/skybox2.png"), driver->getTexture(porting::getDataPath("skybox2.png").c_str()),
driver->getTexture("../data/skybox3.png"), driver->getTexture(porting::getDataPath("skybox3.png").c_str()),
driver->getTexture("../data/skybox1.png"), driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
driver->getTexture("../data/skybox1.png"), driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
driver->getTexture("../data/skybox1.png"), driver->getTexture(porting::getDataPath("skybox1.png").c_str()),
driver->getTexture("../data/skybox1.png"));*/ driver->getTexture(porting::getDataPath("skybox1.png").c_str()));*/
/* /*
Create the camera node Create the camera node

@ -757,17 +757,17 @@ void MapBlock::updateMesh(u32 daynight_ratio)
= video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
if(dir == v3s16(0,-1,0)) if(dir == v3s16(0,-1,0))
buf->getMaterial().setTexture(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)) else if(dir == v3s16(0,1,0))
buf->getMaterial().setTexture(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 // For backwards compatibility
else if(dir == v3s16(0,0,0)) else if(dir == v3s16(0,0,0))
buf->getMaterial().setTexture(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 else
buf->getMaterial().setTexture(0, buf->getMaterial().setTexture(0,
g_irrlicht->getTexture("../data/torch.png")); g_irrlicht->getTexture(porting::getDataPath("torch.png").c_str()));
// Add to mesh // Add to mesh
mesh_new->addMeshBuffer(buf); mesh_new->addMeshBuffer(buf);

@ -282,7 +282,7 @@ void RatObject::addToScene(scene::ISceneManager *smgr)
buf->getMaterial().setFlag(video::EMF_LIGHTING, false); buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false); buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
buf->getMaterial().setTexture 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_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true); buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
@ -360,7 +360,7 @@ video::ITexture * ItemObject::getItemImage()
if(item) if(item)
texture = item->getImage(); texture = item->getImage();
/*else /*else
texture = g_irrlicht->getTexture("../data/cloud.png");*/ texture = g_irrlicht->getTexture(porting::getDataPath("cloud.png").c_str());*/
if(item) if(item)
delete item; delete item;
return texture; return texture;
@ -414,7 +414,7 @@ void PlayerObject::addToScene(scene::ISceneManager *smgr)
// Set material // Set material
buf->getMaterial().setFlag(video::EMF_LIGHTING, false); buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, 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_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true); buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
//buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; //buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
@ -438,7 +438,7 @@ void PlayerObject::addToScene(scene::ISceneManager *smgr)
// Set material // Set material
buf->getMaterial().setFlag(video::EMF_LIGHTING, false); buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, 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_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true); buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;

@ -430,7 +430,7 @@ public:
buf->getMaterial().setFlag(video::EMF_LIGHTING, false); buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false); //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
buf->getMaterial().setTexture 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_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true); buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; 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_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false); //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
buf->getMaterial().setTexture 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_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true); buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;

@ -19,6 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapnode.h" #include "mapnode.h"
#include "tile.h" #include "tile.h"
#include "porting.h"
#include <string>
/* /*
Face directions: 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}, {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", "stone.png",
"../data/grass.png", "grass.png",
"../data/water.png", "water.png",
"../data/torch_on_floor.png", "torch_on_floor.png",
"../data/tree_top.png", "tree_top.png",
"../data/leaves.png", "leaves.png",
"../data/grass_footsteps.png", "grass_footsteps.png",
"../data/mese.png", "mese.png",
"../data/mud.png", "mud.png",
"../data/water.png", "water.png",
"../data/cloud.png", "cloud.png",
"../data/coalstone.png", "coalstone.png",
"../data/wood.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();
}
}

@ -84,7 +84,9 @@ enum Content
}; };
extern u16 g_content_tiles[USEFUL_CONTENT_COUNT][6]; 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 If true, the material allows light propagation and brightness is stored

@ -110,7 +110,7 @@ RemotePlayer::RemotePlayer(
// Set material // Set material
buf->getMaterial().setFlag(video::EMF_LIGHTING, false); buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, 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_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true); buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
//buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; //buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
@ -134,7 +134,7 @@ RemotePlayer::RemotePlayer(
// Set material // Set material
buf->getMaterial().setFlag(video::EMF_LIGHTING, false); buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
//buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, 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_BILINEAR_FILTER, false);
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true); buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;

160
src/porting.cpp Normal file

@ -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

@ -24,8 +24,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef PORTING_HEADER #ifndef PORTING_HEADER
#define PORTING_HEADER #define PORTING_HEADER
#include <string>
// Included for u64 and such // Included for u64 and such
#include "common_irrlicht.h" #include "common_irrlicht.h"
#include "debug.h"
#include "constants.h"
#ifdef _WIN32 #ifdef _WIN32
#define SWPRINTF_CHARSTRING L"%S" #define SWPRINTF_CHARSTRING L"%S"
@ -44,6 +47,33 @@ with this program; if not, write to the Free Software Foundation, Inc.,
namespace porting 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. Resolution is 10-20ms.
Remember to check for overflows. Remember to check for overflows.
@ -67,5 +97,5 @@ namespace porting
} // namespace porting } // namespace porting
#endif #endif // PORTING_HEADER

@ -471,7 +471,7 @@ private:
float m_time_counter; float m_time_counter;
float m_time_of_day_send_timer; float m_time_of_day_send_timer;
MutexedVariable<float> m_uptime; MutexedVariable<double> m_uptime;
enum PeerChangeType enum PeerChangeType
{ {

@ -123,6 +123,8 @@ int main(int argc, char *argv[])
DSTACK(__FUNCTION_NAME); DSTACK(__FUNCTION_NAME);
porting.initializePaths();
initializeMaterialProperties(); initializeMaterialProperties();
BEGIN_DEBUG_EXCEPTION_HANDLER BEGIN_DEBUG_EXCEPTION_HANDLER
@ -222,15 +224,12 @@ int main(int argc, char *argv[])
} }
else else
{ {
const char *filenames[2] = core::array<std::string> filenames;
{ filenames.push_back(porting::path_userdata + "/minetest.conf");
"../minetest.conf",
"../../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) if(r)
{ {
configpath = filenames[i]; configpath = filenames[i];
@ -306,7 +305,7 @@ int main(int argc, char *argv[])
std::cout<<std::endl; std::cout<<std::endl;
// Figure out path to map // Figure out path to map
std::string map_dir = "../map"; std::string map_dir = porting::path_userdata+"/map";
if(cmd_args.exists("map-dir")) if(cmd_args.exists("map-dir"))
map_dir = cmd_args.get("map-dir"); map_dir = cmd_args.get("map-dir");

@ -18,27 +18,50 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/ */
#include "tile.h" #include "tile.h"
#include "porting.h"
// For IrrlichtWrapper
#include "main.h" #include "main.h"
#include <string>
// A mapping from tiles to paths of textures // 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, NULL,
"../data/stone.png", "stone.png",
"../data/water.png", "water.png",
"../data/grass.png", "grass.png",
"../data/tree.png", "tree.png",
"../data/leaves.png", "leaves.png",
"../data/grass_footsteps.png", "grass_footsteps.png",
"../data/mese.png", "mese.png",
"../data/mud.png", "mud.png",
"../data/tree_top.png", "tree_top.png",
"../data/mud_with_grass.png", "mud_with_grass.png",
"../data/cloud.png", "cloud.png",
"../data/coalstone.png", "coalstone.png",
"../data/wood.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) const char * tile_texture_path_get(u32 i)
{ {
assert(i < TILES_COUNT); assert(i < TILES_COUNT);
@ -54,7 +77,7 @@ void tile_materials_preload(IrrlichtWrapper *irrlicht)
{ {
for(s32 i=0; i<TILES_COUNT; i++) 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; video::ITexture *t = NULL;

@ -95,13 +95,12 @@ struct TileSpec
} param; } param;
}; };
/*extern const char * g_tile_texture_paths[TILES_COUNT];
extern video::SMaterial g_tile_materials[TILES_COUNT];*/
/* /*
Functions Functions
*/ */
void init_tile_texture_paths();
const char * tile_texture_path_get(u32 i); const char * tile_texture_path_get(u32 i);
// Initializes g_tile_materials // Initializes g_tile_materials