Further refactored, Reverted Minecart change

Other small changes.
master
archshift 2014-04-26 09:21:49 -07:00
parent 80b97fd9dd
commit aef2c8ec62
11 changed files with 62 additions and 90 deletions

View File

@ -186,53 +186,31 @@ void cClientHandle::GenerateOfflineUUID(void)
AString cClientHandle::FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a_ChatPrefixS, AString m_Color1, AString m_Color2)
{
if (ShouldAppendChatPrefixes)
return Printf("%s%s %s", m_Color1.c_str(), a_ChatPrefixS.c_str(), m_Color2.c_str());
else
return Printf("%s", m_Color1.c_str());
}
AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString &a_AdditionalData)
{
switch (a_ChatPrefix)
{
case mtCustom: return AString();
case mtFailure:
{
if (ShouldAppendChatPrefixes)
return Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str());
else
return Printf("%s", cChatColor::Rose.c_str());
}
case mtInformation:
{
if (ShouldAppendChatPrefixes)
return Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str());
else
return Printf("%s", cChatColor::Yellow.c_str());
}
case mtSuccess:
{
if (ShouldAppendChatPrefixes)
return Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str());
else
return Printf("%s", cChatColor::Green.c_str());
}
case mtWarning:
{
if (ShouldAppendChatPrefixes)
return Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str());
else
return Printf("%s", cChatColor::Rose.c_str());
}
case mtFatal:
{
if (ShouldAppendChatPrefixes)
return Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str());
else
return Printf("%s", cChatColor::Red.c_str());
}
case mtDeath:
{
if (ShouldAppendChatPrefixes)
return Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str());
else
return Printf("%s", cChatColor::Gray.c_str());
}
case mtCustom: return AString();
case mtFailure: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Rose, cChatColor::White);
case mtInformation: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Yellow, cChatColor::White);
case mtSuccess: return FormatChatPrefix(ShouldAppendChatPrefixes, "[INFO]", cChatColor::Green, cChatColor::White);
case mtWarning: return FormatChatPrefix(ShouldAppendChatPrefixes, "[WARN]", cChatColor::Rose, cChatColor::White);
case mtFatal: return FormatChatPrefix(ShouldAppendChatPrefixes, "[FATAL]", cChatColor::Red, cChatColor::White);
case mtDeath: return FormatChatPrefix(ShouldAppendChatPrefixes, "[DEATH]", cChatColor::Gray, cChatColor::White);
case mtJoin: return FormatChatPrefix(ShouldAppendChatPrefixes, "[JOIN]", cChatColor::Yellow, cChatColor::White);
case mtLeave: return FormatChatPrefix(ShouldAppendChatPrefixes, "[LEAVE]", cChatColor::Yellow, cChatColor::White);
case mtPrivateMessage:
{
if (ShouldAppendChatPrefixes)
@ -240,20 +218,6 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage
else
return Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue.c_str());
}
case mtJoin:
{
if (ShouldAppendChatPrefixes)
return Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str());
else
return Printf("%s", cChatColor::Yellow.c_str());
}
case mtLeave:
{
if (ShouldAppendChatPrefixes)
return Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str());
else
return Printf("%s", cChatColor::Yellow.c_str());
}
}
ASSERT(!"Unhandled chat prefix type!");
}

View File

@ -78,8 +78,10 @@ public:
Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same. */
static AString GenerateOfflineUUID(const AString & a_Username); // tolua_export
// Formats the type of message with the proper color and prefix for sending to the client.
/** Formats the type of message with the proper color and prefix for sending to the client. **/
AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString & a_AdditionalData);
AString FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a_ChatPrefixS, AString m_Color1, AString m_Color2);
void Kick(const AString & a_Reason); // tolua_export
void Authenticate(const AString & a_Name, const AString & a_UUID); // Called by cAuthenticator when the user passes authentication

View File

@ -411,7 +411,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType)
return true;
}
}
ASSERT("Invalid damage type!");
ASSERT(!"Invalid damage type!");
}

View File

@ -270,7 +270,7 @@ public:
/// Returns the hitpoints that this pawn can deal to a_Receiver using its equipped items
virtual int GetRawDamageAgainst(const cEntity & a_Receiver);
// Returns whether armor will protect against the passed damage type
/** Returns whether armor will protect against the passed damage type **/
virtual bool ArmorCoversAgainst(eDamageType a_DamageType);
/// Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover

View File

@ -88,7 +88,7 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk)
AddPosition(GetSpeed() * MilliDt);
//If not static (One billionth precision) broadcast movement.
float epsilon = 0.000000001;
static const float epsilon = 0.000000001;
if ((fabs(GetSpeedX()) > epsilon) || (fabs(GetSpeedZ()) > epsilon))
{
BroadcastMovementUpdate();

View File

@ -234,15 +234,18 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt)
bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta);
if (EntCol || BlckCol) return;
if (GetSpeedZ() > 0)
if (GetSpeedZ() != 0) // Don't do anything if cart is stationary
{
// Going SOUTH, slow down
AddSpeedZ(-0.1);
}
else if (GetSpeedZ() < 0)
{
// Going NORTH, slow down
AddSpeedZ(0.1);
if (GetSpeedZ() > 0)
{
// Going SOUTH, slow down
AddSpeedZ(-0.1);
}
else
{
// Going NORTH, slow down
AddSpeedZ(0.1);
}
}
break;
}
@ -256,13 +259,16 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt)
bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta);
if (EntCol || BlckCol) return;
if (GetSpeedX() > 0)
if (GetSpeedX() != 0)
{
AddSpeedX(-0.1);
}
else if (GetSpeedX() < 0)
{
AddSpeedX(0.1);
if (GetSpeedX() > 0)
{
AddSpeedX(-0.1);
}
else
{
AddSpeedX(0.1);
}
}
break;
}

View File

@ -33,7 +33,7 @@ cMCLogger * cMCLogger::GetInstance(void)
cMCLogger::cMCLogger(void):
g_ShouldColorOutput(false)
m_ShouldColorOutput(false)
{
AString FileName;
Printf(FileName, "LOG_%d.txt", (int)time(NULL));
@ -76,15 +76,15 @@ void cMCLogger::InitLog(const AString & a_FileName)
#ifdef _WIN32
// See whether we are writing to a console the default console attrib:
g_ShouldColorOutput = (_isatty(_fileno(stdin)) != 0);
if (g_ShouldColorOutput)
m_ShouldColorOutput = (_isatty(_fileno(stdin)) != 0);
if (m_ShouldColorOutput)
{
CONSOLE_SCREEN_BUFFER_INFO sbi;
GetConsoleScreenBufferInfo(g_Console, &sbi);
g_DefaultConsoleAttrib = sbi.wAttributes;
m_DefaultConsoleAttrib = sbi.wAttributes;
}
#elif defined (__linux) && !defined(ANDROID_NDK)
g_ShouldColorOutput = isatty(fileno(stdout));
m_ShouldColorOutput = isatty(fileno(stdout));
// TODO: Check if the terminal supports colors, somehow?
#endif
}
@ -178,7 +178,7 @@ void cMCLogger::Error(const char * a_Format, va_list a_ArgList)
void cMCLogger::SetColor(eColorScheme a_Scheme)
{
if (!g_ShouldColorOutput)
if (!m_ShouldColorOutput)
{
return;
}
@ -211,7 +211,7 @@ void cMCLogger::SetColor(eColorScheme a_Scheme)
void cMCLogger::ResetColor(void)
{
if (!g_ShouldColorOutput)
if (!m_ShouldColorOutput)
{
return;
}

View File

@ -52,7 +52,7 @@ private:
cCriticalSection m_CriticalSection;
cLog * m_Log;
static cMCLogger * s_MCLogger;
bool g_ShouldColorOutput;
bool m_ShouldColorOutput;
/// Sets the specified color scheme in the terminal (TODO: if coloring available)

View File

@ -109,12 +109,12 @@ void cAggressiveMonster::Attack(float a_Dt)
bool cAggressiveMonster::IsMovingToTargetPosition()
{
float epsilon = 0.000000000001;
//Difference between destination x and target x is negligable (to 10^-12 precision)
// Difference between destination x and target x is negligible (to 10^-12 precision)
if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon)
{
return false;
}
//Difference between destination z and target z is negligable (to 10^-12 precision)
// Difference between destination z and target z is negligible (to 10^-12 precision)
else if (fabsf(m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon)
{
return false;

View File

@ -23,7 +23,7 @@ public:
virtual void Attack(float a_Dt);
protected:
/* Whether this mob's destination is the same as its target's position. */
/** Whether this mob's destination is the same as its target's position. */
bool IsMovingToTargetPosition();
} ;

View File

@ -621,10 +621,10 @@ void cNBTChunkSerializer::AddHangingEntity(cHangingEntity * a_Hanging)
m_Writer.AddInt("TileZ", a_Hanging->GetTileZ());
switch (a_Hanging->GetDirection())
{
case BLOCK_FACE_YM: m_Writer.AddByte("Dir", (unsigned char)2); break;
case BLOCK_FACE_YP: m_Writer.AddByte("Dir", (unsigned char)1); break;
case BLOCK_FACE_ZM: m_Writer.AddByte("Dir", (unsigned char)0); break;
case BLOCK_FACE_ZP: m_Writer.AddByte("Dir", (unsigned char)3); break;
case BLOCK_FACE_YM: m_Writer.AddByte("Dir", (unsigned char)2); break;
case BLOCK_FACE_YP: m_Writer.AddByte("Dir", (unsigned char)1); break;
case BLOCK_FACE_ZM: m_Writer.AddByte("Dir", (unsigned char)0); break;
case BLOCK_FACE_ZP: m_Writer.AddByte("Dir", (unsigned char)3); break;
}
}