From d10627a77fe022263e2319be282fbec68e713545 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 29 Nov 2010 17:55:07 +0200 Subject: Windows bug fixes --- Makefile | 8 ++-- minetest.vcproj | 5 +- src/constants.h | 5 +- src/debug.cpp | 11 ++--- src/main.cpp | 14 +++++- src/map.cpp | 26 ++++++++-- src/map.h | 11 ++++- src/mapblock.cpp | 5 +- src/mapblockobject.cpp | 125 ++++++++++++++++++++++++++++++++----------------- src/mapblockobject.h | 1 + src/server.cpp | 27 ++--------- src/server.h | 2 + src/socket.cpp | 8 +++- 13 files changed, 160 insertions(+), 88 deletions(-) diff --git a/Makefile b/Makefile index 979631fc0..2b4e8dda3 100644 --- a/Makefile +++ b/Makefile @@ -21,8 +21,8 @@ CXXFLAGS = -O2 -ffast-math -Wall -g -pipe #CXXFLAGS = -O3 -ffast-math -Wall -g #CXXFLAGS = -O2 -ffast-math -Wall -g -#FASTCXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686 -FASTCXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686 -fwhole-program +FASTCXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686 +#FASTCXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686 -fwhole-program #Default target @@ -53,9 +53,9 @@ all_linux all_win32: $(DESTPATH) fast_linux: $(FASTDESTPATH) $(FASTDESTPATH): $(SOURCES) - @#$(CXX) -o $(FASTDESTPATH) $(SOURCES) $(CPPFLAGS) $(FASTCXXFLAGS) $(LDFLAGS) -DUNITTEST_DISABLE + $(CXX) -o $(FASTDESTPATH) $(SOURCES) $(CPPFLAGS) $(FASTCXXFLAGS) $(LDFLAGS) -DUNITTEST_DISABLE @# Errno doesn't work ("error: ‘__errno_location’ was not declared in this scope") - cat $(SOURCES) | $(CXX) -o $(FASTDESTPATH) -x c++ - -Isrc/ $(CPPFLAGS) $(FASTCXXFLAGS) $(LDFLAGS) -DUNITTEST_DISABLE -DDISABLE_ERRNO + @#cat $(SOURCES) | $(CXX) -o $(FASTDESTPATH) -x c++ - -Isrc/ $(CPPFLAGS) $(FASTCXXFLAGS) $(LDFLAGS) -DUNITTEST_DISABLE -DDISABLE_ERRNO $(DESTPATH): $(OBJECTS) $(CXX) -o $@ $(OBJECTS) $(LDFLAGS) diff --git a/minetest.vcproj b/minetest.vcproj index 0401e2a04..6ebfaee7f 100644 --- a/minetest.vcproj +++ b/minetest.vcproj @@ -41,6 +41,7 @@ Name="VCCLCompilerTool" 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"" PreprocessorDefinitions="WIN32" + BufferSecurityCheck="true" EnableEnhancedInstructionSet="1" FloatingPointModel="2" DebugInformationFormat="1" @@ -117,10 +118,11 @@ 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"" - PreprocessorDefinitions="WIN32;_HAS_ITERATOR_DEBUGGING=0,UNITTEST_DISABLE" + PreprocessorDefinitions="WIN32;_HAS_ITERATOR_DEBUGGING=0,UNITTEST_DISABLE,_CRT_SECURE_NO_DEPRECATE" BufferSecurityCheck="false" EnableEnhancedInstructionSet="1" FloatingPointModel="2" + DebugInformationFormat="0" /> createBlankBlockNoInsert(p3d.Y); created_new = true; } - + + // deserialize block data block->deSerialize(is, version); /* @@ -2509,6 +2521,14 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSecto // We just loaded it from the disk, so it's up-to-date. block->resetChangedFlag(); + + } + catch(SerializationError &e) + { + dstream<<"WARNING: Invalid block data on disk " + "(SerializationError). Ignoring." + < 0); @@ -127,6 +131,8 @@ public: // If this is the last one, release the cache lock if(m_count == 0) m_cache_mutex.Unlock(); + + dstream<<"cacheRemoved() end"< - scene::IMeshBuffer *buf = new scene::SMeshBuffer(); + scene::SMeshBuffer *buf = new scene::SMeshBuffer(); // Set material - ((scene::SMeshBuffer*)buf)->Material = p.material; + buf->Material = p.material; + //((scene::SMeshBuffer*)buf)->Material = p.material; // Use VBO //buf->setHardwareMappingHint(scene::EHM_STATIC); // Add to mesh diff --git a/src/mapblockobject.cpp b/src/mapblockobject.cpp index 985a01dc1..df070265c 100644 --- a/src/mapblockobject.cpp +++ b/src/mapblockobject.cpp @@ -33,8 +33,16 @@ void MapBlockObject::setBlockChanged() */ void MovingObject::move(float dtime, v3f acceleration) { - //m_pos += dtime * 3.0; - + DSTACK("%s: typeid=%i, pos=(%f,%f,%f), speed=(%f,%f,%f)" + ", dtime=%f, acc=(%f,%f,%f)", + __FUNCTION_NAME, + getTypeId(), + m_pos.X, m_pos.Y, m_pos.Z, + m_speed.X, m_speed.Y, m_speed.Z, + dtime, + acceleration.X, acceleration.Y, acceleration.Z + ); + v3s16 oldpos_i = floatToInt(m_pos); if(m_block->isValidPosition(oldpos_i) == false) @@ -50,6 +58,16 @@ void MovingObject::move(float dtime, v3f acceleration) m_pos += m_speed * dtime; return; } + + // Set insane speed to zero + // Otherwise there will be divides by zero and other silly stuff + if(m_speed.getLength() > 1000.0*BS) + m_speed = v3f(0,0,0); + + // Limit speed to a reasonable value + float speed_limit = 20.0*BS; + if(m_speed.getLength() > speed_limit) + m_speed = m_speed * (speed_limit / m_speed.getLength()); v3f position = m_pos; v3f oldpos = position; @@ -471,40 +489,53 @@ MapBlockObject * MapBlockObjectList::get(s16 id) void MapBlockObjectList::step(float dtime, bool server) { + DSTACK(__FUNCTION_NAME); + JMutexAutoLock lock(m_mutex); - + core::map ids_to_delete; - for(core::map::Iterator - i = m_objects.getIterator(); - i.atEnd() == false; i++) { - MapBlockObject *obj = i.getNode()->getValue(); - - if(server) - { - bool to_delete = obj->serverStep(dtime); + DSTACK("%s: stepping objects", __FUNCTION_NAME); - if(to_delete) - ids_to_delete.insert(obj->m_id, true); - } - else + for(core::map::Iterator + i = m_objects.getIterator(); + i.atEnd() == false; i++) { - obj->clientStep(dtime); + MapBlockObject *obj = i.getNode()->getValue(); + + DSTACK("%s: stepping object type %i", __FUNCTION_NAME, + obj->getTypeId()); + + if(server) + { + bool to_delete = obj->serverStep(dtime); + + if(to_delete) + ids_to_delete.insert(obj->m_id, true); + } + else + { + obj->clientStep(dtime); + } } } - // Delete objects in delete queue - for(core::map::Iterator - i = ids_to_delete.getIterator(); - i.atEnd() == false; i++) { - s16 id = i.getNode()->getKey(); + DSTACK("%s: deleting objects", __FUNCTION_NAME); - MapBlockObject *obj = m_objects[id]; - obj->removeFromScene(); - delete obj; - m_objects.remove(id); + // Delete objects in delete queue + for(core::map::Iterator + i = ids_to_delete.getIterator(); + i.atEnd() == false; i++) + { + s16 id = i.getNode()->getKey(); + + MapBlockObject *obj = m_objects[id]; + obj->removeFromScene(); + delete obj; + m_objects.remove(id); + } } /* @@ -513,36 +544,42 @@ void MapBlockObjectList::step(float dtime, bool server) if(server == false) return; - - for(core::map::Iterator - i = m_objects.getIterator(); - i.atEnd() == false; i++) + { - MapBlockObject *obj = i.getNode()->getValue(); - - v3s16 pos_i = floatToInt(obj->m_pos); + DSTACK("%s: object wrap loop", __FUNCTION_NAME); - if(m_block->isValidPosition(pos_i)) + for(core::map::Iterator + i = m_objects.getIterator(); + i.atEnd() == false; i++) { - // No wrap - continue; - } + MapBlockObject *obj = i.getNode()->getValue(); - bool impossible = wrapObject(obj); + v3s16 pos_i = floatToInt(obj->m_pos); - if(impossible) - { - // No wrap - continue; - } + if(m_block->isValidPosition(pos_i)) + { + // No wrap + continue; + } - // Restart find - i = m_objects.getIterator(); + bool impossible = wrapObject(obj); + + if(impossible) + { + // No wrap + continue; + } + + // Restart find + i = m_objects.getIterator(); + } } } bool MapBlockObjectList::wrapObject(MapBlockObject *object) { + DSTACK(__FUNCTION_NAME); + // No lock here; this is called so that the lock is already locked. //JMutexAutoLock lock(m_mutex); diff --git a/src/mapblockobject.h b/src/mapblockobject.h index 15409bbd7..ea0293a6f 100644 --- a/src/mapblockobject.h +++ b/src/mapblockobject.h @@ -11,6 +11,7 @@ #include "serialization.h" #include "mapnode.h" #include "constants.h" +#include "debug.h" enum { diff --git a/src/server.cpp b/src/server.cpp index 16f6611ca..a40352847 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -670,7 +670,9 @@ void RemoteClient::SendObjectData( s32 sum = (s32)os.tellp() + 2 + (s32)bos.tellp(); // break out if data too big if(sum > MAX_OBJECTDATA_SIZE) - d = d_max+1; + { + goto skip_subsequent; + } } //try catch(InvalidPositionException &e) @@ -692,28 +694,7 @@ void RemoteClient::SendObjectData( } } -#if 0 - /* - Write objects - */ - - // Write block count - writeU16(buf, blockcount); - os.write((char*)buf, 2); - - for(core::map::Iterator - i = blocks.getIterator(); - i.atEnd() == false; i++) - { - v3s16 p = i.getNode()->getKey(); - // Write blockpos - writeV3S16(buf, p); - os.write((char*)buf, 6); - // Write objects - MapBlock *block = i.getNode()->getValue(); - block->serializeObjects(os, serialization_version); - } -#endif +skip_subsequent: // Write block count writeU16(buf, blockcount); diff --git a/src/server.h b/src/server.h index 79cdf052d..9c5850bff 100644 --- a/src/server.h +++ b/src/server.h @@ -53,6 +53,8 @@ public: */ void addBlock(u16 peer_id, v3s16 pos, u8 flags) { + DSTACK(__FUNCTION_NAME); + JMutexAutoLock lock(m_mutex); if(peer_id != 0) diff --git a/src/socket.cpp b/src/socket.cpp index 88ba78c6a..dddc8f36a 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -297,7 +297,13 @@ bool UDPSocket::WaitData(int timeout_ms) dstream<<(int)m_handle<<": Select failed: "<