Core: Optimized compile time after recent changes

This commit is contained in:
Shauren
2012-08-23 01:55:49 +02:00
parent 7c86714895
commit fa546654c3
3 changed files with 47 additions and 36 deletions

View File

@@ -422,7 +422,6 @@ void WorldSession::HandleMovementOpcodes(WorldPacket& recvPacket)
void WorldSession::HandleForceSpeedChangeAck(WorldPacket &recvData)
{
uint32 opcode = recvData.GetOpcode();
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Recvd %s (%u, 0x%X) opcode", LookupOpcodeName(Opcodes(opcode)), opcode, opcode);
/* extract packet */
uint64 guid;

View File

@@ -16,30 +16,41 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
\ingroup u2w
*/
#include "Opcodes.h"
#include "WorldSession.h"
OpcodeHandler* opcodeTable[NUM_OPCODE_HANDLERS] = { };
template<bool isInValidRange, bool isNonZero>
inline void ValidateAndSetOpcode(uint16 opcode, char const* name, SessionStatus status, PacketProcessing processing, pOpcodeHandler handler)
{
if (opcodeTable[opcode] != NULL)
{
sLog->outError(LOG_FILTER_NETWORKIO, "Tried to override handler of %s with %s (opcode %u)", opcodeTable[opcode]->name, name, opcode);
return;
}
opcodeTable[opcode] = new OpcodeHandler(name, status, processing, handler);
}
template<>
void ValidateAndSetOpcode<false, true>(uint16 opcode, char const* /*name*/, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
{
sLog->outError(LOG_FILTER_NETWORKIO, "Tried to set handler for an invalid opcode %d", opcode);
}
template<>
void ValidateAndSetOpcode<false, false>(uint16 /*opcode*/, char const* name, SessionStatus /*status*/, PacketProcessing /*processing*/, pOpcodeHandler /*handler*/)
{
sLog->outError(LOG_FILTER_NETWORKIO, "Opcode %s got value 0", name);
}
#define DEFINE_OPCODE_HANDLER(opcode, status, processing, handler) \
ValidateAndSetOpcode<(opcode < NUM_OPCODE_HANDLERS), (opcode != 0)>(opcode, #opcode, status, processing, handler);
/// Correspondence between opcodes and their names
void InitOpcodes()
{
#define DEFINE_OPCODE_HANDLER(opcode, status, processing, handler) \
if (opcode == 0) \
sLog->outError(LOG_FILTER_NETWORKIO, "Opcode %s got value 0", #opcode); \
if (opcode < NUM_OPCODE_HANDLERS) { \
if (opcodeTable[opcode] != NULL) \
{ \
sLog->outError(LOG_FILTER_NETWORKIO, "Tried to override handler of %s with %s (opcode %u)", \
opcodeTable[opcode]->name, #opcode, opcode); \
} \
else opcodeTable[opcode] = new OpcodeHandler(#opcode, #opcode "_COMPRESSED", status, processing, handler); \
}
memset(opcodeTable, 0, sizeof(opcodeTable));
DEFINE_OPCODE_HANDLER(CMSG_ACCEPT_LEVEL_GRANT, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleAcceptGrantLevel );

View File

@@ -1431,11 +1431,10 @@ typedef void(WorldSession::*pOpcodeHandler)(WorldPacket& recvPacket);
struct OpcodeHandler
{
OpcodeHandler() {}
OpcodeHandler(char const* _name, char const* _compressedName, SessionStatus _status, PacketProcessing _processing, pOpcodeHandler _handler)
: name(_name), compressedName(_compressedName), status(_status), packetProcessing(_processing), handler(_handler) {}
OpcodeHandler(char const* _name, SessionStatus _status, PacketProcessing _processing, pOpcodeHandler _handler)
: name(_name), status(_status), packetProcessing(_processing), handler(_handler) {}
char const* name;
char const* compressedName;
SessionStatus status;
PacketProcessing packetProcessing;
pOpcodeHandler handler;
@@ -1445,26 +1444,28 @@ extern OpcodeHandler* opcodeTable[NUM_OPCODE_HANDLERS];
void InitOpcodes();
/// Lookup opcode name for human understandable logging
inline const char* LookupOpcodeName(Opcodes id)
{
if (id < UNKNOWN_OPCODE)
{
bool isCompressed = uint32(id) & COMPRESSED_OPCODE_MASK;
if (OpcodeHandler* handler = opcodeTable[uint32(id) & 0x7FFF])
return isCompressed ? handler->compressedName : handler->name;
return "UNKNOWN OPCODE";
}
return "INVALID OPCODE";
}
inline std::string GetOpcodeNameForLogging(Opcodes id)
{
uint32 opcode = uint32(id);
std::ostringstream ss;
ss << '[' << LookupOpcodeName(id) << " 0x" << std::hex << std::uppercase << opcode << std::nouppercase << " (" << std::dec << opcode << ")]";
return ss.str().c_str();
ss << '[';
if (id < UNKNOWN_OPCODE)
{
if (OpcodeHandler* handler = opcodeTable[uint32(id) & 0x7FFF])
{
ss << handler->name;
if (opcode & COMPRESSED_OPCODE_MASK)
ss << "_COMPRESSED";
}
else
ss << "UNKNOWN OPCODE";
}
else
ss << "INVALID OPCODE";
ss << " 0x" << std::hex << std::uppercase << opcode << std::nouppercase << " (" << std::dec << opcode << ")]";
return ss.str();
}
#endif