1
0

Fixed explosions bug

* Fixed bug where explosions would sometimes never be sent
This commit is contained in:
Tiger Wang 2014-02-04 23:40:58 +00:00
parent ea2ce1595f
commit 94c343fe07
3 changed files with 13 additions and 32 deletions

View File

@ -1839,7 +1839,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
bbTNT.Expand(ExplosionSizeInt * 2, ExplosionSizeInt * 2, ExplosionSizeInt * 2); bbTNT.Expand(ExplosionSizeInt * 2, ExplosionSizeInt * 2, ExplosionSizeInt * 2);
cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), a_ExplosionSizeInt, ExplosionSizeSq); cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), ExplosionSizeInt, ExplosionSizeSq);
ForEachEntity(TNTDamageCallback); ForEachEntity(TNTDamageCallback);
// Wake up all simulators for the area, so that water and lava flows and sand falls into the blasted holes (FS #391): // Wake up all simulators for the area, so that water and lava flows and sand falls into the blasted holes (FS #391):

View File

@ -44,16 +44,13 @@
/// If the number of queued outgoing packets reaches this, the client will be kicked /** If the number of queued outgoing packets reaches this, the client will be kicked */
#define MAX_OUTGOING_PACKETS 2000 #define MAX_OUTGOING_PACKETS 2000
/// How many explosions per single game tick are allowed /** Maximum number of explosions to send this tick, server will start dropping if exceeded */
static const int MAX_EXPLOSIONS_PER_TICK = 100; #define MAX_EXPLOSIONS_PER_TICK 100
/// How many explosions in the recent history are allowed /** How many ticks before the socket is closed after the client is destroyed (#31) */
static const int MAX_RUNNING_SUM_EXPLOSIONS = cClientHandle::NUM_CHECK_EXPLOSIONS_TICKS * MAX_EXPLOSIONS_PER_TICK / 8;
/// How many ticks before the socket is closed after the client is destroyed (#31)
static const int TICKS_BEFORE_CLOSE = 20; static const int TICKS_BEFORE_CLOSE = 20;
@ -95,8 +92,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) :
m_TicksSinceDestruction(0), m_TicksSinceDestruction(0),
m_State(csConnected), m_State(csConnected),
m_ShouldCheckDownloaded(false), m_ShouldCheckDownloaded(false),
m_CurrentExplosionTick(0), m_NumExplosionsThisTick(0),
m_RunningSumExplosions(0),
m_UniqueID(0), m_UniqueID(0),
m_HasSentPlayerChunk(false) m_HasSentPlayerChunk(false)
{ {
@ -1637,10 +1633,8 @@ void cClientHandle::Tick(float a_Dt)
} }
} }
// Update the explosion statistics: // Reset explosion counter:
m_CurrentExplosionTick = (m_CurrentExplosionTick + 1) % ARRAYCOUNT(m_NumExplosionsPerTick); m_NumExplosionsThisTick = 0;
m_RunningSumExplosions -= m_NumExplosionsPerTick[m_CurrentExplosionTick];
m_NumExplosionsPerTick[m_CurrentExplosionTick] = 0;
} }
@ -1920,18 +1914,14 @@ void cClientHandle::SendEntityVelocity(const cEntity & a_Entity)
void cClientHandle::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) void cClientHandle::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion)
{ {
if ( if (m_NumExplosionsThisTick > MAX_EXPLOSIONS_PER_TICK)
(m_NumExplosionsPerTick[m_CurrentExplosionTick] > MAX_EXPLOSIONS_PER_TICK) || // Too many explosions in this tick
(m_RunningSumExplosions > MAX_RUNNING_SUM_EXPLOSIONS) // Too many explosions in the recent history
)
{ {
LOGD("Dropped %u explosions", a_BlocksAffected.size()); LOGD("Dropped an explosion!");
return; return;
} }
// Update the statistics: // Update the statistics:
m_NumExplosionsPerTick[m_CurrentExplosionTick] += a_BlocksAffected.size(); m_NumExplosionsThisTick += 1;
m_RunningSumExplosions += a_BlocksAffected.size();
m_Protocol->SendExplosion(a_BlockX, a_BlockY, a_BlockZ, a_Radius, a_BlocksAffected, a_PlayerMotion); m_Protocol->SendExplosion(a_BlockX, a_BlockY, a_BlockZ, a_Radius, a_BlocksAffected, a_PlayerMotion);
} }

View File

@ -53,9 +53,6 @@ public:
static const int MAX_VIEW_DISTANCE = 15; static const int MAX_VIEW_DISTANCE = 15;
static const int MIN_VIEW_DISTANCE = 3; static const int MIN_VIEW_DISTANCE = 3;
/// How many ticks should be checked for a running average of explosions, for limiting purposes
static const int NUM_CHECK_EXPLOSIONS_TICKS = 20;
cClientHandle(const cSocket * a_Socket, int a_ViewDistance); cClientHandle(const cSocket * a_Socket, int a_ViewDistance);
virtual ~cClientHandle(); virtual ~cClientHandle();
@ -301,14 +298,8 @@ private:
/// If set to true during csDownloadingWorld, the tick thread calls CheckIfWorldDownloaded() /// If set to true during csDownloadingWorld, the tick thread calls CheckIfWorldDownloaded()
bool m_ShouldCheckDownloaded; bool m_ShouldCheckDownloaded;
/// Stores the recent history of the number of explosions per tick /** Number of explosions sent this tick */
int m_NumExplosionsPerTick[NUM_CHECK_EXPLOSIONS_TICKS]; int m_NumExplosionsThisTick;
/// Points to the current tick in the m_NumExplosionsPerTick[] array
int m_CurrentExplosionTick;
/// Running sum of m_NumExplosionsPerTick[]
int m_RunningSumExplosions;
static int s_ClientCount; static int s_ClientCount;
int m_UniqueID; int m_UniqueID;