From 52d99fef31daa60903053bc565b6b9d3a31a2bc8 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 11 Feb 2011 19:55:42 +0200 Subject: [PATCH] fully working i guess --- minetest.conf.example | 1 + src/defaultsettings.cpp | 1 + src/main.cpp | 28 ++-- src/main.h | 2 +- src/map.cpp | 309 ++++++++++++++++++++++++++++++++++------ src/map.h | 7 +- src/mapblock.cpp | 43 ++---- src/mapchunk.h | 24 ++-- src/materials.cpp | 2 +- src/mineral.cpp | 4 +- src/mineral.h | 3 +- src/servermain.cpp | 8 +- src/socket.h | 2 +- src/tile.h | 20 ++- src/utility.h | 16 +++ src/voxel.h | 6 +- 16 files changed, 356 insertions(+), 120 deletions(-) diff --git a/minetest.conf.example b/minetest.conf.example index 92fe68b5f..264d77e5a 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -25,6 +25,7 @@ #enable_fog = true #new_style_water = true #new_style_leaves = true +#frametime_graph = false # Server side stuff diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index e3ecf55f9..de825ff0a 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -41,6 +41,7 @@ void set_default_settings() g_settings.setDefault("enable_fog", "true"); g_settings.setDefault("new_style_water", "true"); g_settings.setDefault("new_style_leaves", "true"); + g_settings.setDefault("frametime_graph", "false"); g_settings.setDefault("free_move", "false"); g_settings.setDefault("continuous_forward", "false"); diff --git a/src/main.cpp b/src/main.cpp index 105acedf7..c37a35cdb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -267,15 +267,6 @@ Doing now (most important at the top): # maybe done * not done -=== Immediate stuff -* Combine meshes to bigger ones in ClientMap and set them EHM_STATIC - -=== Making it more portable -* MinGW: Switch away from swprintf; mingw has a bad version of it. - Use snprintf + narrow_to_wide or (w)ostringstream -* Some MSVC: std::sto* are defined without a namespace and collide - with the ones in utility.h - === Stuff to do before release * Save the new mapgen stuff - map/meta.txt, which should contain only plain text, something like this: @@ -291,7 +282,15 @@ Doing now (most important at the top): * only_from_disk might not work anymore - check and fix it. * Check the fixmes in the list above +=== Making it more portable +* MinGW: Switch away from swprintf; mingw has a bad version of it. + Use snprintf + narrow_to_wide or (w)ostringstream +* Some MSVC: std::sto* are defined without a namespace and collide + with the ones in utility.h + === Stuff to do after release +* Move digging property stuff from material.{h,cpp} to mapnode.cpp... + - Or maybe move content_features to material.{h,cpp}? * Add some kind of erosion and other stuff that now is possible * Make client to fetch stuff asynchronously - Needs method SyncProcessData @@ -308,6 +307,7 @@ Doing now (most important at the top): is generated. Fix it. * Make a small history check to transformLiquids to detect and log continuous oscillations, in such detail that they can be fixed. +* Combine meshes to bigger ones in ClientMap and set them EHM_STATIC ====================================================================== @@ -381,7 +381,7 @@ Doing now (most important at the top): IrrlichtWrapper *g_irrlicht = NULL; // This makes textures -TextureSource *g_texturesource = NULL; +ITextureSource *g_texturesource = NULL; MapDrawControl draw_control; @@ -1659,7 +1659,8 @@ int main(int argc, char *argv[]) g_device = device; g_irrlicht = new IrrlichtWrapper(device); - g_texturesource = new TextureSource(device); + TextureSource *texturesource = new TextureSource(device); + g_texturesource = texturesource; /* Speed tests (done after irrlicht is loaded to get timer) @@ -1722,7 +1723,7 @@ int main(int argc, char *argv[]) init_content_inventory_texture_paths(); init_mapnode(); // Second call with g_texturesource set - init_mineral(g_irrlicht); + init_mineral(); /* GUI stuff @@ -2084,7 +2085,7 @@ int main(int argc, char *argv[]) /* Process TextureSource's queue */ - g_texturesource->processQueue(); + texturesource->processQueue(); /* Random calculations @@ -3006,6 +3007,7 @@ int main(int argc, char *argv[]) /* Frametime log */ + if(g_settings.getBool("frametime_graph") == true) { s32 x = 10; for(core::list::Iterator diff --git a/src/main.h b/src/main.h index 9978c537a..b951ab5b0 100644 --- a/src/main.h +++ b/src/main.h @@ -32,7 +32,7 @@ extern IrrlichtWrapper *g_irrlicht; // This makes and maps textures #include "tile.h" -extern TextureSource *g_texturesource; +extern ITextureSource *g_texturesource; // Debug streams diff --git a/src/map.cpp b/src/map.cpp index e4992618d..ba958d148 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1741,10 +1741,10 @@ ServerMap::ServerMap(std::string savedir): //m_chunksize = 2; // TODO: Save to and load from a file - m_seed = (((u64)myrand()<<0)%0x7fff) - + (((u64)myrand()<<16)%0x7fff) - + (((u64)myrand()<<32)%0x7fff) - + (((u64)myrand()<<48)%0x7fff); + m_seed = (((u64)(myrand()%0xffff)<<0) + + ((u64)(myrand()%0xffff)<<16) + + ((u64)(myrand()%0xffff)<<32) + + ((u64)(myrand()%0xffff)<<48)); /* Experimental and debug stuff @@ -1774,16 +1774,24 @@ ServerMap::ServerMap(std::string savedir): } else { - // Load master heightmap - loadMasterHeightmap(); + // Load map metadata (seed, chunksize) + loadMapMeta(); - // Load sector (0,0) and throw and exception on fail + // Load chunk metadata + loadChunkMeta(); + + /*// Load sector (0,0) and throw and exception on fail if(loadSectorFull(v2s16(0,0)) == false) - throw LoadError("Failed to load sector (0,0)"); + throw LoadError("Failed to load sector (0,0)");*/ - dstream<setIsVolatile(false); chunk->setGenLevel(GENERATED_FULLY); - // Return it + + /* + Save changed parts of map + */ + save(true); + + /* + Return central chunk (which was requested) + */ return chunk; } @@ -4543,7 +4606,8 @@ void ServerMap::save(bool only_changed) dstream< list = fs::GetDirListing(m_savedir+"/sectors/"); @@ -4657,6 +4722,7 @@ void ServerMap::loadAll() dstream<::Iterator + i = m_chunks.getIterator(); + i.atEnd()==false; i++) + { + v2s16 p = i.getNode()->getKey(); + MapChunk *chunk = i.getNode()->getValue(); + // Write position + writeV2S16(buf, p); + os.write((char*)buf, 4); + // Write chunk data + chunk->serialize(os, version); + } +} + +void ServerMap::loadChunkMeta() +{ + DSTACK(__FUNCTION_NAME); + + dstream<<"INFO: ServerMap::loadChunkMeta(): Loading chunk metadata" + <deSerialize(is, version); + m_chunks.insert(p, chunk); + } +} void ServerMap::saveSectorMeta(ServerMapSector *sector) { diff --git a/src/map.h b/src/map.h index d18278834..fb0555824 100644 --- a/src/map.h +++ b/src/map.h @@ -475,18 +475,13 @@ public: void save(bool only_changed); void loadAll(); - // TODO + // Saves map seed and possibly other stuff void saveMapMeta(); void loadMapMeta(); - // TODO void saveChunkMeta(); void loadChunkMeta(); - // DEPRECATED - void saveMasterHeightmap(); - void loadMasterHeightmap(); - // The sector mutex should be locked when calling most of these // This only saves sector-specific data such as the heightmap diff --git a/src/mapblock.cpp b/src/mapblock.cpp index e0b8965b4..bff366add 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -148,25 +148,6 @@ u8 MapBlock::getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2, v3s16 face_dir) { try{ - // DEBUG - /*{ - if(n.d == CONTENT_WATER) - { - u8 l = n.param2*2; - if(l > LIGHT_MAX) - l = LIGHT_MAX; - return l; - } - if(n2.d == CONTENT_WATER) - { - u8 l = n2.param2*2; - if(l > LIGHT_MAX) - l = LIGHT_MAX; - return l; - } - }*/ - - u8 light; u8 l1 = n.getLightBlend(daynight_ratio); u8 l2 = n2.getLightBlend(daynight_ratio); @@ -177,11 +158,13 @@ u8 MapBlock::getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2, // Make some nice difference to different sides + // This makes light come from a corner /*if(face_dir.X == 1 || face_dir.Z == 1 || face_dir.Y == -1) light = diminish_light(diminish_light(light)); else if(face_dir.X == -1 || face_dir.Z == -1) light = diminish_light(light);*/ - + + // All neighboring faces have different shade (like in minecraft) if(face_dir.X == 1 || face_dir.X == -1 || face_dir.Y == -1) light = diminish_light(diminish_light(light)); else if(face_dir.Z == 1 || face_dir.Z == -1) @@ -791,7 +774,7 @@ void MapBlock::updateMesh(u32 daynight_ratio) // Flowing water material video::SMaterial material_water1; material_water1.setFlag(video::EMF_LIGHTING, false); - material_water1.setFlag(video::EMF_BACK_FACE_CULLING, false); + //material_water1.setFlag(video::EMF_BACK_FACE_CULLING, false); material_water1.setFlag(video::EMF_BILINEAR_FILTER, false); material_water1.setFlag(video::EMF_FOG_ENABLE, true); material_water1.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; @@ -1040,9 +1023,9 @@ void MapBlock::updateMesh(u32 daynight_ratio) video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1), video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0), video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/ - video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, + video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, pa_water1.x0(), pa_water1.y1()), - video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, + video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, pa_water1.x1(), pa_water1.y1()), video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, pa_water1.x1(), pa_water1.y0()), @@ -1118,21 +1101,25 @@ void MapBlock::updateMesh(u32 daynight_ratio) video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,1), video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0), video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/ - video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, + video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, pa_water1.x0(), pa_water1.y1()), - video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, - pa_water1.x1(), pa_water1.y1()), video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, + pa_water1.x1(), pa_water1.y1()), + video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, pa_water1.x1(), pa_water1.y0()), - video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, + video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, pa_water1.x0(), pa_water1.y0()), }; + + // This fixes a strange bug + s32 corner_resolve[4] = {3,2,1,0}; for(s32 i=0; i<4; i++) { //vertices[i].Pos.Y += water_level; //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)]; - vertices[i].Pos.Y += corner_levels[i]; + s32 j = corner_resolve[i]; + vertices[i].Pos.Y += corner_levels[j]; vertices[i].Pos += intToFloat(p + getPosRelative()); } diff --git a/src/mapchunk.h b/src/mapchunk.h index 1f89b38a7..1819fa13e 100644 --- a/src/mapchunk.h +++ b/src/mapchunk.h @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., some MapSectors. (something like 16x16) */ +// These should fit in 8 bits, as they are saved as such. enum{ GENERATED_FULLY = 0, GENERATED_PARTLY = 10, @@ -35,21 +36,10 @@ class MapChunk { public: MapChunk(): - //m_is_volatile(true) m_generation_level(GENERATED_NOT) { } - /* - If is_volatile is true, chunk can be modified when - neighboring chunks are generated. - - It is set to false when all the 8 neighboring chunks have - been generated. - */ - /*bool getIsVolatile(){ return m_is_volatile; } - void setIsVolatile(bool is){ m_is_volatile = is; }*/ - /* Generation level. Possible values: GENERATED_FULLY = 0 = fully generated @@ -59,9 +49,17 @@ public: u16 getGenLevel(){ return m_generation_level; } void setGenLevel(u16 lev){ m_generation_level = lev; } + void serialize(std::ostream &os, u8 version) + { + os.write((char*)&m_generation_level, 1); + } + void deSerialize(std::istream &is, u8 version) + { + is.read((char*)&m_generation_level, 1); + } + private: - //bool m_is_volatile; - u16 m_generation_level; + u8 m_generation_level; }; #endif diff --git a/src/materials.cpp b/src/materials.cpp index 00d212c63..f56b024b2 100644 --- a/src/materials.cpp +++ b/src/materials.cpp @@ -58,7 +58,7 @@ void initializeMaterialProperties() DiggingProperties(true, 1.0, 0)); g_material_properties[CONTENT_SAND].setDiggingProperties("", - DiggingProperties(true, 0.5, 0)); + DiggingProperties(true, 0.4, 0)); /* Add MesePick to everything diff --git a/src/mineral.cpp b/src/mineral.cpp index 905f6497c..e61c25c1e 100644 --- a/src/mineral.cpp +++ b/src/mineral.cpp @@ -30,14 +30,12 @@ const char *mineral_filenames[MINERAL_COUNT] = //textureid_t mineral_textures[MINERAL_COUNT] = {0}; std::string mineral_textures[MINERAL_COUNT]; -void init_mineral(IIrrlichtWrapper *irrlicht) +void init_mineral() { for(u32 i=0; igetTextureId(mineral_filenames[i]); - //mineral_textures[i] = 0; mineral_textures[i] = mineral_filenames[i]; } } diff --git a/src/mineral.h b/src/mineral.h index a181b89de..fcc1bd123 100644 --- a/src/mineral.h +++ b/src/mineral.h @@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "inventory.h" #include "texture.h" -#include "iirrlichtwrapper.h" /* Minerals @@ -32,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ // Caches textures -void init_mineral(IIrrlichtWrapper *irrlicht); +void init_mineral(); #define MINERAL_NONE 0 #define MINERAL_COAL 1 diff --git a/src/servermain.cpp b/src/servermain.cpp index 7ec397ace..1c301d4f5 100644 --- a/src/servermain.cpp +++ b/src/servermain.cpp @@ -79,6 +79,9 @@ Settings g_settings; extern void set_default_settings(); +// A dummy thing +ITextureSource *g_texturesource = NULL; + /* Debug streams */ @@ -259,9 +262,8 @@ int main(int argc, char *argv[]) // Initialize stuff - IIrrlichtWrapper irrlicht; // Dummy - init_mapnode(&irrlicht); - init_mineral(&irrlicht); + init_mapnode(); + init_mineral(); /* Check parameters diff --git a/src/socket.h b/src/socket.h index 10bcdefee..6b7a2462e 100644 --- a/src/socket.h +++ b/src/socket.h @@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #ifdef _MSC_VER - #pragma comment(lib, "wsock32.lib") + #pragma comment(lib, "ws2_32.lib") #endif typedef SOCKET socket_t; typedef int socklen_t; diff --git a/src/tile.h b/src/tile.h index 2a342313d..1e339806f 100644 --- a/src/tile.h +++ b/src/tile.h @@ -103,10 +103,28 @@ struct SourceAtlasPointer } }; +/* + Implementation (to be used as a no-op on the server) +*/ +class ITextureSource +{ +public: + ITextureSource(){} + virtual ~ITextureSource(){} + virtual u32 getTextureId(const std::string &name){return 0;} + virtual u32 getTextureIdDirect(const std::string &name){return 0;} + virtual std::string getTextureName(u32 id){return "";} + virtual AtlasPointer getTexture(u32 id){return AtlasPointer(0);} + virtual AtlasPointer getTexture(const std::string &name) + {return AtlasPointer(0);} + virtual video::ITexture* getTextureRaw(const std::string &name) + {return NULL;} +}; + /* Creates and caches textures. */ -class TextureSource +class TextureSource : public ITextureSource { public: TextureSource(IrrlichtDevice *device); diff --git a/src/utility.h b/src/utility.h index deaa78d90..9e47a5dac 100644 --- a/src/utility.h +++ b/src/utility.h @@ -1201,6 +1201,15 @@ public: return value; } + u64 getU64(std::string name) + { + u64 value = 0; + std::string s = get(name); + std::istringstream ss(s); + ss>>value; + return value; + } + void setS32(std::string name, s32 value) { set(name, itos(value)); @@ -1218,6 +1227,13 @@ public: set(name, os.str()); } + void setU64(std::string name, u64 value) + { + std::ostringstream os; + os<