From aef2c8ec628aa2522364da1333bc5158e55ac6a2 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 09:21:49 -0700 Subject: Further refactored, Reverted Minecart change Other small changes. --- src/ClientHandle.cpp | 78 +++++++++------------------------ src/ClientHandle.h | 4 +- src/Entities/Entity.cpp | 2 +- src/Entities/Entity.h | 2 +- src/Entities/FallingBlock.cpp | 2 +- src/Entities/Minecart.cpp | 34 ++++++++------ src/MCLogger.cpp | 14 +++--- src/MCLogger.h | 2 +- src/Mobs/AggressiveMonster.cpp | 4 +- src/Mobs/AggressiveMonster.h | 2 +- src/WorldStorage/NBTChunkSerializer.cpp | 8 ++-- 11 files changed, 62 insertions(+), 90 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 7bfae9ca7..78402d4d3 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -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!"); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index e2b44ce8a..9f8d44129 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -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 diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 49e7e45e2..961caf493 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -411,7 +411,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) return true; } } - ASSERT("Invalid damage type!"); + ASSERT(!"Invalid damage type!"); } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index db40f12ed..9b8011b55 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -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 diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index f48fb156b..50140de67 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -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(); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index ceaa713bb..db55eb058 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -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) - { - // Going SOUTH, slow down - AddSpeedZ(-0.1); - } - else if (GetSpeedZ() < 0) + if (GetSpeedZ() != 0) // Don't do anything if cart is stationary { - // 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) - { - AddSpeedX(-0.1); - } - else if (GetSpeedX() < 0) + if (GetSpeedX() != 0) { - AddSpeedX(0.1); + if (GetSpeedX() > 0) + { + AddSpeedX(-0.1); + } + else + { + AddSpeedX(0.1); + } } break; } diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index ca47b29db..d56c1a5a8 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -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; } diff --git a/src/MCLogger.h b/src/MCLogger.h index 34955ea16..114210f63 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -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) diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index cafa7ee74..3e5f72dbf 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -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; diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h index c66452360..d70ff04a3 100644 --- a/src/Mobs/AggressiveMonster.h +++ b/src/Mobs/AggressiveMonster.h @@ -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(); } ; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 27631eded..773954f73 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -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; } } -- cgit v1.2.3