From dd9e82f5bc2982abab436afdd68df799c6fdd857 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 8 Feb 2011 01:12:55 +0200 Subject: bug-fixin' --- src/CMakeLists.txt | 4 +- src/client.cpp | 5 ++- src/defaultsettings.cpp | 5 ++- src/environment.cpp | 43 +++++++++--------- src/guiMainMenu.cpp | 6 +-- src/guiMessageMenu.cpp | 2 +- src/guiPauseMenu.cpp | 7 +-- src/guiTextInputMenu.cpp | 6 ++- src/main.cpp | 47 +++++-------------- src/map.cpp | 62 ++++++++++++++++---------- src/mapblock.cpp | 114 +++++++++++++++++++++++++++++++++++++++-------- src/mapnode.cpp | 44 ++++++++++++++---- src/mapnode.h | 36 ++++++++++----- src/modalMenu.h | 5 ++- src/player.cpp | 25 +++++++++-- src/player.h | 3 ++ src/porting.cpp | 6 ++- src/server.cpp | 7 +-- src/tile.h | 76 +++++++++++++++++++------------ src/utility.h | 2 + 20 files changed, 336 insertions(+), 169 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8325024ee..de8e93e04 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,7 +30,9 @@ else() endif(BUILD_CLIENT) find_package(ZLIB REQUIRED) set(PLATFORM_LIBS -lpthread) - set(CLIENT_PLATFORM_LIBS -lXxf86vm) + #set(CLIENT_PLATFORM_LIBS -lXxf86vm) + find_library(XXF86VM_LIBRARY, Xxf86vm) + set(CLIENT_PLATFORM_LIBS ${XXF86VM_LIBRARY}) endif() configure_file( diff --git a/src/client.cpp b/src/client.cpp index 915c745b7..4febdd4f7 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -279,10 +279,11 @@ void Client::step(float dtime) // [0] u16 TOSERVER_INIT // [2] u8 SER_FMT_VER_HIGHEST // [3] u8[20] player_name - SharedBuffer data(2+1+20); + SharedBuffer data(2+1+PLAYERNAME_SIZE); writeU16(&data[0], TOSERVER_INIT); writeU8(&data[2], SER_FMT_VER_HIGHEST); - memcpy(&data[3], myplayer->getName(), 20); + memset((char*)&data[3], 0, PLAYERNAME_SIZE); + snprintf((char*)&data[3], PLAYERNAME_SIZE, "%s", myplayer->getName()); // Send as unreliable Send(0, data, false); } diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 714703b08..e3ecf55f9 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -23,6 +23,9 @@ extern Settings g_settings; void set_default_settings() { + // Client and server + g_settings.setDefault("footprints", "false"); + // Client stuff g_settings.setDefault("wanted_fps", "30"); g_settings.setDefault("fps_max", "60"); @@ -37,7 +40,7 @@ void set_default_settings() g_settings.setDefault("client_delete_unused_sectors_timeout", "1200"); g_settings.setDefault("enable_fog", "true"); g_settings.setDefault("new_style_water", "true"); - g_settings.setDefault("terrain_viewer", "false"); + g_settings.setDefault("new_style_leaves", "true"); g_settings.setDefault("free_move", "false"); g_settings.setDefault("continuous_forward", "false"); diff --git a/src/environment.cpp b/src/environment.cpp index b1722ee3f..e8a01a4a1 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -118,9 +118,9 @@ void Environment::step(float dtime) /* Apply water resistance */ - if(player->in_water) + if(player->in_water_stable) { - f32 max_down = 1.0*BS; + f32 max_down = 1.5*BS; if(speed.Y < -max_down) speed.Y = -max_down; f32 max = 2.5*BS; @@ -155,27 +155,30 @@ void Environment::step(float dtime) /* Add footsteps to grass */ - // Get node that is at BS/4 under player - v3s16 bottompos = floatToInt(playerpos + v3f(0,-BS/4,0)); - try{ - MapNode n = m_map->getNode(bottompos); - if(n.d == CONTENT_GRASS) - { - n.d = CONTENT_GRASS_FOOTSTEPS; - m_map->setNode(bottompos, n); -#ifndef SERVER - // Update mesh on client - if(m_map->mapType() == MAPTYPE_CLIENT) + if(g_settings.getBool("footprints")) + { + // Get node that is at BS/4 under player + v3s16 bottompos = floatToInt(playerpos + v3f(0,-BS/4,0)); + try{ + MapNode n = m_map->getNode(bottompos); + if(n.d == CONTENT_GRASS) { - v3s16 p_blocks = getNodeBlockPos(bottompos); - MapBlock *b = m_map->getBlockNoCreate(p_blocks); - b->updateMesh(m_daynight_ratio); - } + n.d = CONTENT_GRASS_FOOTSTEPS; + m_map->setNode(bottompos, n); +#ifndef SERVER + // Update mesh on client + if(m_map->mapType() == MAPTYPE_CLIENT) + { + v3s16 p_blocks = getNodeBlockPos(bottompos); + MapBlock *b = m_map->getBlockNoCreate(p_blocks); + b->updateMesh(m_daynight_ratio); + } #endif + } + } + catch(InvalidPositionException &e) + { } - } - catch(InvalidPositionException &e) - { } } } diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index 2d02c0295..6c5d6553c 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -261,13 +261,13 @@ bool GUIMainMenu::OnEvent(const SEvent& event) case 257: // Start game acceptInput(); quitMenu(); - break; + return true; case 260: // Delete map // Don't accept input data, just set deletion request m_data->delete_map = true; m_accepted = true; quitMenu(); - break; + return true; } } if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER) @@ -277,7 +277,7 @@ bool GUIMainMenu::OnEvent(const SEvent& event) case 256: case 257: case 258: acceptInput(); quitMenu(); - break; + return true; } } } diff --git a/src/guiMessageMenu.cpp b/src/guiMessageMenu.cpp index 7102ddd83..192911355 100644 --- a/src/guiMessageMenu.cpp +++ b/src/guiMessageMenu.cpp @@ -142,7 +142,7 @@ bool GUIMessageMenu::OnEvent(const SEvent& event) case 257: m_status = true; quitMenu(); - break; + return true; } } } diff --git a/src/guiPauseMenu.cpp b/src/guiPauseMenu.cpp index bcf4070c9..486e4107d 100644 --- a/src/guiPauseMenu.cpp +++ b/src/guiPauseMenu.cpp @@ -193,15 +193,16 @@ bool GUIPauseMenu::OnEvent(const SEvent& event) { case 256: // continue quitMenu(); - break; + // ALWAYS return immediately after quitMenu() + return true; case 260: // disconnect m_gamecallback->disconnect(); quitMenu(); - break; + return true; case 257: // exit m_gamecallback->exitToOS(); quitMenu(); - break; + return true; } } } diff --git a/src/guiTextInputMenu.cpp b/src/guiTextInputMenu.cpp index 38985cfa0..2cb8cae62 100644 --- a/src/guiTextInputMenu.cpp +++ b/src/guiTextInputMenu.cpp @@ -172,7 +172,8 @@ bool GUITextInputMenu::OnEvent(const SEvent& event) case 257: acceptInput(); quitMenu(); - break; + // quitMenu deallocates menu + return true; } } if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER) @@ -182,7 +183,8 @@ bool GUITextInputMenu::OnEvent(const SEvent& event) case 256: acceptInput(); quitMenu(); - break; + // quitMenu deallocates menu + return true; } } } diff --git a/src/main.cpp b/src/main.cpp index 24f3664f6..17d481cac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -112,19 +112,12 @@ Documentation: Build system / running: ----------------------- -NOTE: The following fixme is not apparently valid, and it does work. -FIXME: Graphical mode seems to segfault with Irrlicht 1.7.1 on 64-bit - systems. (Ubuntu) - - http://pastebin.no/32bo - - Might be just a bad build, too - - Doesn't affect Irrlicht 1.7.2 or 32-bit 1.7.1. (Arch/Debian) - - A similar error occurs when getTexture is called from a thread - when the texture has not been already loaded from disk: - http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?p=68830 - FIXME: Some network errors on Windows that cause local game to not work - See siggjen's emails. - Is this the famous "windows 7 problem"? + - Apparently there might be other errors too + - There is some problem with the menu system, something like the + .Parent of guiPauseMenu to end up being 0xfeeefeee Networking and serialization: ----------------------------- @@ -254,26 +247,10 @@ TODO: Flowing water to actually contain flow direction information TODO: Remove duplicate lighting implementation from Map (leave VoxelManipulator, which is faster) -FEATURE: Map generator version 2 - - Create a system that allows a huge amount of different "map - generator modules/filters" - -FEATURE: The map could be generated procedually: - - This would need the map to be generated in larger pieces - - How large? How do they connect to each other? - - It has to be split vertically also - - Lighting would not have to be necessarily calculated until - the blocks are actually needed - it would be quite fast - - Something like 64*64*16 MapBlocks? - - No, MapSectors. And as much as it is efficient to do, - 64x64 might be too much. - - FIXME: This is currently halfway done and the generator is - fairly broken - * Make the stone level with a heightmap - * Carve out stuff in the stone - * Dump dirt all around, and simulate it falling off steep - places - * Erosion simulation at map generation time +FEATURE: Create a system that allows a huge amount of different "map + generator modules/filters" + +FEATURE: Erosion simulation at map generation time - Simulate water flows, which would carve out dirt fast and then turn stone into gravel and sand and relocate it. - How about relocating minerals, too? Coal and gold in @@ -294,8 +271,7 @@ Doing now (most important at the top): - map/meta.txt, which should contain only plain text, something like this: seed = 7ff1bafcd7118800 chunksize = 8 - - map/chunks.dat -* Save chunk metadata on disk + - map/chunks.dat: chunk positions and flags in binary format * Make server find the spawning place from the real map data, not from the heightmap - But the changing borders of chunk have to be avoided, because @@ -306,7 +282,6 @@ Doing now (most important at the top): * Check the fixmes in the list above === Stuff to do after release -* Set backface culling on, especially for water * Add some kind of erosion and other stuff that now is possible * Make client to fetch stuff asynchronously - Needs method SyncProcessData @@ -316,7 +291,7 @@ Doing now (most important at the top): * Water doesn't start flowing after map generation like it should - Are there still problems? * Better water generation (spread it to underwater caverns but don't - fill dungeons that don't touch outside air) + fill dungeons that don't touch big water masses) * When generating a chunk and the neighboring chunk doesn't have mud and stuff yet and the ground is fairly flat, the mud will flow to the other chunk making nasty straight walls when the other chunk @@ -1943,7 +1918,9 @@ int main(int argc, char *argv[]) continue; } - std::cout< & modified_blocks) u32 loopcount = 0; u32 initial_size = m_transforming_liquid.size(); - if(initial_size != 0) - dstream<<"transformLiquids(): initial_size="<getTexture("water.png")); + 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_BILINEAR_FILTER, false); + material_water1.setFlag(video::EMF_FOG_ENABLE, true); + material_water1.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; + material_water1.setTexture(0, g_irrlicht->getTexture("water.png")); + + // New-style leaves material + video::SMaterial material_leaves1; + material_leaves1.setFlag(video::EMF_LIGHTING, false); + //material_leaves1.setFlag(video::EMF_BACK_FACE_CULLING, false); + material_leaves1.setFlag(video::EMF_BILINEAR_FILTER, false); + material_leaves1.setFlag(video::EMF_FOG_ENABLE, true); + material_leaves1.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; + material_leaves1.setTexture(0, g_irrlicht->getTexture("leaves.png")); for(s16 z=0; zsetAllTextures(irrlicht->getTextureId("leaves.png")); - f->param_type = CPT_MINERAL; + f->light_propagates = true; + //f->param_type = CPT_MINERAL; + f->param_type = CPT_LIGHT; f->is_ground_content = true; + if(new_style_leaves) + { + f->solidness = 0; // drawn separately, makes no faces + } + else + { + f->setAllTextures(irrlicht->getTextureId("leaves.png")); + } + /*{ + TileSpec t; + t.spec = TextureSpec(irrlicht->getTextureId("leaves.png")); + //t.material_type = MATERIAL_ALPHA_SIMPLE; + //t.material_flags |= MATERIAL_FLAG_BACKFACE_CULLING; + f->setAllTiles(t); + }*/ i = CONTENT_COALSTONE; f = &g_content_features[i]; @@ -141,17 +160,26 @@ void init_mapnode(IIrrlichtWrapper *irrlicht) f->buildable_to = true; f->liquid_type = LIQUID_FLOWING; - bool new_style_water = g_settings.getBool("new_style_water"); - i = CONTENT_WATERSOURCE; f = &g_content_features[i]; - //f->setTexture(0, irrlicht->getTextureId("water.png"), WATER_ALPHA); - if(new_style_water == false) - f->setAllTextures(irrlicht->getTextureId("water.png"), WATER_ALPHA); f->setInventoryTexture(irrlicht->getTextureId("water.png")); + if(new_style_water) + { + f->solidness = 0; // drawn separately, makes no faces + } + else // old style + { + f->setAllTextures(irrlicht->getTextureId("water.png"), WATER_ALPHA); + TileSpec t; + t.spec = TextureSpec(irrlicht->getTextureId("water.png")); + t.alpha = WATER_ALPHA; + t.material_type = MATERIAL_ALPHA_VERTEX; + t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING; + f->setAllTiles(t); + f->solidness = 1; + } f->param_type = CPT_LIGHT; f->light_propagates = true; - f->solidness = 1; f->walkable = false; f->pointable = false; f->diggable = false; diff --git a/src/mapnode.h b/src/mapnode.h index fcbb80fd1..0aaa4dc78 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -167,25 +167,38 @@ struct ContentFeatures ~ContentFeatures(); + // Quickhands for simple materials + void setTexture(u16 i, const TextureSpec &spec, u8 alpha=255) + { + tiles[i].spec = spec; + if(alpha != 255) + { + tiles[i].alpha = alpha; + tiles[i].material_type = MATERIAL_ALPHA_VERTEX; + } + } void setAllTextures(const TextureSpec &spec, u8 alpha=255) { for(u16 i=0; i<6; i++) { - tiles[i].spec = spec; - tiles[i].alpha = alpha; + setTexture(i, spec, alpha); } // Set this too so it can be left as is most times - /*if(inventory_image_path == "") - inventory_image_path = porting::getDataPath(imgname.c_str());*/ - if(inventory_texture.empty()) inventory_texture = spec; } - void setTexture(u16 i, const TextureSpec &spec, u8 alpha=255) + + void setTile(u16 i, const TileSpec &tile) { - tiles[i].spec = spec; - tiles[i].alpha = alpha; + tiles[i] = tile; + } + void setAllTiles(const TileSpec &tile) + { + for(u16 i=0; i<6; i++) + { + setTile(i, tile); + } } void setInventoryTexture(const TextureSpec &spec) @@ -417,12 +430,11 @@ struct MapNode union { - u8 param2; - /* - Direction for torches and other stuff. - Format is freeform. e.g. packDir or encode_dirs can be used. + The second parameter. Initialized to 0. + Direction for torches and flowing water. */ + u8 param2; u8 dir; }; diff --git a/src/modalMenu.h b/src/modalMenu.h index 2323a7e42..ebbb06cfe 100644 --- a/src/modalMenu.h +++ b/src/modalMenu.h @@ -86,7 +86,10 @@ public: } /* - This should be called when the menu wants to quit + This should be called when the menu wants to quit. + + WARNING: THIS DEALLOCATES THE MENU FROM MEMORY. Return + immediately if you call this from the menu itself. */ void quitMenu() { diff --git a/src/player.cpp b/src/player.cpp index 9817d590d..4619e870f 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -30,7 +30,11 @@ with this program; if not, write to the Free Software Foundation, Inc., Player::Player(): touching_ground(false), in_water(false), + in_water_stable(false), + swimming_up(false), peer_id(PEER_ID_INEXISTENT), + m_pitch(0), + m_yaw(0), m_speed(0,0,0), m_position(0,0,0) { @@ -275,11 +279,10 @@ void LocalPlayer::move(f32 dtime, Map &map) position += m_speed * dtime; bool free_move = g_settings.getBool("free_move"); - bool terrain_viewer = g_settings.getBool("terrain_viewer"); // Skip collision detection if player is non-local or // a special movement mode is used - if(isLocal() == false || free_move || terrain_viewer) + if(isLocal() == false || free_move) { setPosition(position); return; @@ -292,7 +295,7 @@ void LocalPlayer::move(f32 dtime, Map &map) v3s16 pos_i = floatToInt(position); /* - Check if player is in water + Check if player is in water (the oscillating value) */ try{ if(in_water) @@ -311,6 +314,18 @@ void LocalPlayer::move(f32 dtime, Map &map) in_water = false; } + /* + Check if player is in water (the stable value) + */ + try{ + v3s16 pp = floatToInt(position + v3f(0,0,0)); + in_water_stable = content_liquid(map.getNode(pp).d); + } + catch(InvalidPositionException &e) + { + in_water_stable = false; + } + // The frame length is limited to the player going 0.1*BS per call f32 d = (float)BS * 0.15; @@ -526,10 +541,12 @@ void LocalPlayer::applyControl(float dtime) speed.Y = 6.5*BS; setSpeed(speed); } + // Use the oscillating value for getting out of water + // (so that the player doesn't fly on the surface) else if(in_water) { v3f speed = getSpeed(); - speed.Y = 2.0*BS; + speed.Y = 1.5*BS; setSpeed(speed); swimming_up = true; } diff --git a/src/player.h b/src/player.h index 3bbb4034d..51e2320bc 100644 --- a/src/player.h +++ b/src/player.h @@ -114,7 +114,10 @@ public: void deSerialize(std::istream &is); bool touching_ground; + // This oscillates so that the player jumps a bit above the surface bool in_water; + // This is more stable and defines the maximum speed of the player + bool in_water_stable; bool swimming_up; Inventory inventory; diff --git a/src/porting.cpp b/src/porting.cpp index a1e6fd02d..592636336 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -81,8 +81,9 @@ void initializePaths() #include char buf[BUFSIZ]; + memset(buf, 0, BUFSIZ); // Get path to executable - readlink("/proc/self/exe", buf, BUFSIZ); + readlink("/proc/self/exe", buf, BUFSIZ-1); pathRemoveFile(buf, '/'); @@ -144,8 +145,9 @@ void initializePaths() #include char buf[BUFSIZ]; + memset(buf, 0, BUFSIZ); // Get path to executable - readlink("/proc/self/exe", buf, BUFSIZ); + readlink("/proc/self/exe", buf, BUFSIZ-1); pathRemoveFile(buf, '/'); diff --git a/src/server.cpp b/src/server.cpp index 71a094e14..59d9acee4 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -962,8 +962,8 @@ void PlayerInfo::PrintLine(std::ostream *s) { (*s)<getName()); start += 2+PLAYERNAME_SIZE; } @@ -3204,7 +3205,7 @@ Player *Server::emergePlayer(const char *name, const char *password, #if 1 player->setPosition(intToFloat(v3s16( 0, - 40, //64, + 45, //64, 0 ))); #endif diff --git a/src/tile.h b/src/tile.h index ff495abc4..a68731f55 100644 --- a/src/tile.h +++ b/src/tile.h @@ -25,51 +25,69 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "texture.h" #include +enum MaterialType{ + MATERIAL_ALPHA_NONE, + MATERIAL_ALPHA_VERTEX, + MATERIAL_ALPHA_SIMPLE, // >127 = opaque + MATERIAL_ALPHA_BLEND, +}; + +// Material flags +#define MATERIAL_FLAG_BACKFACE_CULLING 0x01 + +/* + This fully defines the looks of a tile. + The SMaterial of a tile is constructed according to this. +*/ struct TileSpec { TileSpec(): - alpha(255) + alpha(255), + material_type(MATERIAL_ALPHA_NONE), + material_flags( + MATERIAL_FLAG_BACKFACE_CULLING + ) { } bool operator==(TileSpec &other) { - return (spec == other.spec && alpha == other.alpha); + return ( + spec == other.spec && + alpha == other.alpha && + material_type == other.material_type && + material_flags == other.material_flags + ); } - TextureSpec spec; - u8 alpha; -}; - -#if 0 -struct TileSpec -{ - TileSpec(): - alpha(255) + // Sets everything else except the texture in the material + void applyMaterialOptions(video::SMaterial &material) { - } + if(alpha != 255 && material_type != MATERIAL_ALPHA_VERTEX) + dstream<<"WARNING: TileSpec: alpha != 255 " + "but not MATERIAL_ALPHA_VERTEX" + <