#CXXFLAGS = -O3 -ffast-math -Wall -g\r
#CXXFLAGS = -O2 -ffast-math -Wall -g\r
\r
-#FASTCXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686\r
-FASTCXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686 -fwhole-program\r
+FASTCXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686\r
+#FASTCXXFLAGS = -O3 -ffast-math -Wall -fomit-frame-pointer -pipe -funroll-loops -mtune=i686 -fwhole-program\r
\r
#Default target\r
\r
fast_linux: $(FASTDESTPATH)\r
\r
$(FASTDESTPATH): $(SOURCES)\r
- @#$(CXX) -o $(FASTDESTPATH) $(SOURCES) $(CPPFLAGS) $(FASTCXXFLAGS) $(LDFLAGS) -DUNITTEST_DISABLE\r
+ $(CXX) -o $(FASTDESTPATH) $(SOURCES) $(CPPFLAGS) $(FASTCXXFLAGS) $(LDFLAGS) -DUNITTEST_DISABLE\r
@# Errno doesn't work ("error: ‘__errno_location’ was not declared in this scope")\r
- cat $(SOURCES) | $(CXX) -o $(FASTDESTPATH) -x c++ - -Isrc/ $(CPPFLAGS) $(FASTCXXFLAGS) $(LDFLAGS) -DUNITTEST_DISABLE -DDISABLE_ERRNO\r
+ @#cat $(SOURCES) | $(CXX) -o $(FASTDESTPATH) -x c++ - -Isrc/ $(CPPFLAGS) $(FASTCXXFLAGS) $(LDFLAGS) -DUNITTEST_DISABLE -DDISABLE_ERRNO\r
\r
$(DESTPATH): $(OBJECTS)\r
$(CXX) -o $@ $(OBJECTS) $(LDFLAGS)\r
Name="VCCLCompilerTool"\r
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""\r
PreprocessorDefinitions="WIN32"\r
+ BufferSecurityCheck="true"\r
EnableEnhancedInstructionSet="1"\r
FloatingPointModel="2"\r
DebugInformationFormat="1"\r
OmitFramePointers="true"\r
WholeProgramOptimization="true"\r
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""\r
- PreprocessorDefinitions="WIN32;_HAS_ITERATOR_DEBUGGING=0,UNITTEST_DISABLE"\r
+ PreprocessorDefinitions="WIN32;_HAS_ITERATOR_DEBUGGING=0,UNITTEST_DISABLE,_CRT_SECURE_NO_DEPRECATE"\r
BufferSecurityCheck="false"\r
EnableEnhancedInstructionSet="1"\r
FloatingPointModel="2"\r
+ DebugInformationFormat="0"\r
/>\r
<Tool\r
Name="VCManagedResourceCompilerTool"\r
Name="VCLinkerTool"\r
AdditionalLibraryDirectories=""C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib";"..\jthread\jthread-1.2.1\Release";"..\irrlicht\irrlicht-1.7.1\lib\Win32-visualstudio""\r
IgnoreDefaultLibraryNames="libcmtd.lib"\r
+ GenerateDebugInformation="false"\r
LinkTimeCodeGeneration="1"\r
/>\r
<Tool\r
// The distance of how far objects will be sent to client
//#define ACTIVE_OBJECT_D_BLOCKS 2
-// Wether to catch all std::exceptions
-#define CATCH_UNHANDLED_EXCEPTIONS 0
+// Wether to catch all std::exceptions.
+// Assert will be called on such an event.
+#define CATCH_UNHANDLED_EXCEPTIONS 1
/*
Collecting active blocks is stopped after object data
void DebugStack::print(FILE *file, bool everything)
{
- fprintf(file, "BEGIN STACK: Debug stack for thread %x:\n",
+ fprintf(file, "DEBUG STACK FOR THREAD %x:\n",
(unsigned int)threadid);
for(int i=0; i<stack_max_i; i++)
if(i == stack_i && everything == false)
continue;
- if(everything == true && i == stack_i)
- fprintf(file, "END OF STACK.\n"
- "! Continuing beyond stack end:\n");
-
- fprintf(file, "#%d %s\n", i, stack[i]);
+ if(i < stack_i)
+ fprintf(file, "#%d %s\n", i, stack[i]);
+ else
+ fprintf(file, "(Leftover data: #%d %s)\n", i, stack[i]);
}
if(stack_i == DEBUG_STACK_SIZE)
dstream<<DTIME<<"Enabled full viewing range"<<std::endl;\r
}\r
}\r
+\r
+ // Print debug stacks\r
+ if(event.KeyInput.Key == irr::KEY_KEY_P\r
+ && g_game_focused)\r
+ {\r
+ dstream<<"-----------------------------------------"\r
+ <<std::endl;\r
+ dstream<<DTIME<<"Printing debug stacks:"<<std::endl;\r
+ dstream<<"-----------------------------------------"\r
+ <<std::endl;\r
+ debug_stacks_print();\r
+ }\r
}\r
}\r
\r
{\r
dstream<<DTIME<<"Connection timed out."<<std::endl;\r
}\r
-#if CATCH_EXCEPTIONS\r
+#if CATCH_UNHANDLED_EXCEPTIONS\r
/*\r
This is what has to be done in every thread to get suitable debug info\r
*/\r
*/
if(m_params.ravines_amount != 0)
{
- if(rand()%(s32)(10.0 / m_params.ravines_amount) == 0)
+ if(rand()%(s32)(20.0 / m_params.ravines_amount) == 0)
{
s16 s = 6;
s16 x = rand()%(MAP_BLOCKSIZE-s*2-1)+s;
for(s16 x0=0; x0<MAP_BLOCKSIZE; x0++)
{
//dstream<<"emergeBlock: x0="<<x0<<", z0="<<z0<<std::endl;
+
float surface_y_f = sector->getGroundHeight(v2s16(x0,z0));
- assert(surface_y_f > GROUNDHEIGHT_VALID_MINVALUE);
+ //assert(surface_y_f > GROUNDHEIGHT_VALID_MINVALUE);
+ if(surface_y_f < GROUNDHEIGHT_VALID_MINVALUE)
+ {
+ dstream<<"WARNING: Surface height not found in sector "
+ "for block that is being emerged"<<std::endl;
+ surface_y_f = 0.0;
+ }
+
s16 surface_y = surface_y_f;
//avg_ground_y += surface_y;
if(surface_y < lowest_ground_y)
void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSector *sector)
{
DSTACK(__FUNCTION_NAME);
+
+ try{
+
// Block file is map/sectors/xxxxxxxx/xxxx
std::string fullpath = m_savedir+"/sectors/"+sectordir+"/"+blockfile;
std::ifstream is(fullpath.c_str(), std::ios_base::binary);
block = sector->createBlankBlockNoInsert(p3d.Y);
created_new = true;
}
-
+
+ // deserialize block data
block->deSerialize(is, version);
/*
// 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."
+ <<std::endl;
+ }
}
// Gets from master heightmap
void cacheCreated()
{
+ dstream<<"cacheCreated() begin"<<std::endl;
JMutexAutoLock waitcachelock(m_waitcache_mutex);
JMutexAutoLock countlock(m_count_mutex);
m_cache_mutex.Lock();
m_count++;
+
+ dstream<<"cacheCreated() end"<<std::endl;
}
void cacheRemoved()
{
+ dstream<<"cacheRemoved() begin"<<std::endl;
JMutexAutoLock countlock(m_count_mutex);
assert(m_count > 0);
// If this is the last one, release the cache lock
if(m_count == 0)
m_cache_mutex.Unlock();
+
+ dstream<<"cacheRemoved() end"<<std::endl;
}
/*
*/
JMutexAutoLock * waitCaches()
{
+ dstream<<"waitCaches() begin"<<std::endl;
JMutexAutoLock waitcachelock(m_waitcache_mutex);
- return new JMutexAutoLock(m_cache_mutex);
+ JMutexAutoLock *lock = new JMutexAutoLock(m_cache_mutex);
+ dstream<<"waitCaches() end"<<std::endl;
+ return lock;
}
private:
// This is a "Standard MeshBuffer",
// it's a typedeffed CMeshBuffer<video::S3DVertex>
- 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
*/
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)
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;
void MapBlockObjectList::step(float dtime, bool server)
{
+ DSTACK(__FUNCTION_NAME);
+
JMutexAutoLock lock(m_mutex);
-
+
core::map<s16, bool> ids_to_delete;
- for(core::map<s16, MapBlockObject*>::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<s16, MapBlockObject*>::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<s16, bool>::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<s16, bool>::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);
+ }
}
/*
if(server == false)
return;
-
- for(core::map<s16, MapBlockObject*>::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<s16, MapBlockObject*>::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);
#include "serialization.h"
#include "mapnode.h"
#include "constants.h"
+#include "debug.h"
enum
{
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)
}
}
-#if 0
- /*
- Write objects
- */
-
- // Write block count
- writeU16(buf, blockcount);
- os.write((char*)buf, 2);
-
- for(core::map<v3s16, MapBlock*>::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);
*/
void addBlock(u16 peer_id, v3s16 pos, u8 flags)
{
+ DSTACK(__FUNCTION_NAME);
+
JMutexAutoLock lock(m_mutex);
if(peer_id != 0)
dstream<<(int)m_handle<<": Select failed: "<<strerror(errno)<<std::endl;
#endif
#ifdef _WIN32
- dstream<<(int)m_handle<<": WSAGetLastError()="<<WSAGetLastError()<<std::endl;
+ int e = WSAGetLastError();
+ dstream<<(int)m_handle<<": WSAGetLastError()="<<e<<std::endl;
+ if(e == 10004 /*=WSAEINTR*/)
+ {
+ dstream<<"WARNING: Ignoring WSAEINTR."<<std::endl;
+ return false;
+ }
#endif
throw SocketException("Select failed");
}