[6953] Cleanup packed guids write/read code.

* Remove unused function writeGUID and move function readGUID (with some changes) to ByteBuffer class.
* Remove now empty Tools.cpp/Tools.h from project.
This commit is contained in:
VladimirMangos 2008-12-27 17:23:00 +03:00
parent cc4b43c65d
commit 9c5dab1248
10 changed files with 32 additions and 172 deletions

View file

@ -232,8 +232,6 @@ libmangosgame_a_SOURCES = \
TaxiHandler.cpp \
TemporarySummon.cpp \
TemporarySummon.h \
tools.cpp \
Tools.h \
TotemAI.cpp \
TotemAI.h \
Totem.cpp \

View file

@ -41,7 +41,6 @@
#include "SpellAuras.h"
#include "Pet.h"
#include "SocialMgr.h"
#include "Tools.h"
void WorldSession::HandleRepopRequestOpcode( WorldPacket & /*recv_data*/ )
{
@ -1649,7 +1648,7 @@ void WorldSession::HandleInspectAchievements( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data, 1);
uint64 guid;
if(!readGUID(recv_data, guid))
if(!recv_data.readPackGUID(guid))
return;
Player *player = objmgr.GetPlayer(guid);

View file

@ -41,7 +41,6 @@
#include "CellImpl.h"
#include "Policies/SingletonImp.h"
#include "SharedDefines.h"
#include "Tools.h"
#include "LootMgr.h"
#include "VMapFactory.h"
#include "BattleGround.h"
@ -167,15 +166,15 @@ bool SpellCastTargets::read ( WorldPacket * data, Unit *caster )
// TARGET_FLAG_UNK2 is used for non-combat pets, maybe other?
if( m_targetMask & ( TARGET_FLAG_UNIT | TARGET_FLAG_UNK2 ))
if(!readGUID(*data, m_unitTargetGUID))
if(!data->readPackGUID(m_unitTargetGUID))
return false;
if( m_targetMask & ( TARGET_FLAG_OBJECT | TARGET_FLAG_OBJECT_UNK ))
if(!readGUID(*data, m_GOTargetGUID))
if(!data->readPackGUID(m_GOTargetGUID))
return false;
if(( m_targetMask & ( TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM )) && caster->GetTypeId() == TYPEID_PLAYER)
if(!readGUID(*data, m_itemTargetGUID))
if(!data->readPackGUID(m_itemTargetGUID))
return false;
if( m_targetMask & TARGET_FLAG_SOURCE_LOCATION )
@ -207,7 +206,7 @@ bool SpellCastTargets::read ( WorldPacket * data, Unit *caster )
}
if( m_targetMask & (TARGET_FLAG_CORPSE | TARGET_FLAG_PVP_CORPSE ) )
if(!readGUID(*data, m_CorpseTargetGUID))
if(!data->readPackGUID(m_CorpseTargetGUID))
return false;
// find real units/GOs

View file

@ -1,26 +0,0 @@
/*
* Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MANGOS_TOOLS_H
#define MANGOS_TOOLS_H
#include "Common.h"
#include "WorldPacket.h"
bool readGUID(WorldPacket & data, uint64& guid);
void writeGUID(WorldPacket & data, uint64 & guid);
#endif

View file

@ -1,114 +0,0 @@
/*
* Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Tools.h"
// THIS CAN BE A LOT FASTER
bool readGUID(WorldPacket & data, uint64& guid)
{
if(data.rpos()+1 > data.size())
return false;
uint8 guidmark=0;
uint8 bit;
uint8 shiftdata=0x1;
uint64 Temp=0;
guid = 0;
data >> guidmark;
for(int i=0;i<8;i++)
{
if(guidmark & shiftdata)
{
Temp = 0;
if(data.rpos()+1 > data.size())
return false;
data >> bit;
Temp = bit;
Temp <<= i*8;
guid |= Temp;
}
shiftdata=shiftdata<<1;
}
return true;
}
void writeGUID(WorldPacket & data, uint64 & guid)
{
uint8 RAWmask = 0;
uint8 PackedGuid[8] = {0,0,0,0,0,0,0,0};
int j = 1;
uint8 * test = (uint8*)&guid;
if (*test)
{
PackedGuid[j] = *test;
RAWmask |= 1;
++j;
}
if (*(test+1))
{
PackedGuid[j] = *(test+1);
RAWmask |= 2;
++j;
}
if (*(test+2))
{
PackedGuid[j] = *(test+2);
RAWmask |= 4;
++j;
}
if (*(test+3))
{
PackedGuid[j] = *(test+3);
RAWmask |= 8;
++j;
}
if (*(test+4))
{
PackedGuid[j] = *(test+4);
RAWmask |= 16;
++j;
}
if (*(test+5))
{
PackedGuid[j] = *(test+5);
RAWmask |= 32;
++j;
}
if (*(test+6))
{
PackedGuid[j] = *(test+6);
RAWmask |= 64;
++j;
}
if (*(test+7))
{
PackedGuid[j] = *(test+7);
RAWmask |= 128;
++j;
}
PackedGuid[0] = RAWmask;
data.append(PackedGuid,j);
}

View file

@ -241,6 +241,32 @@ class ByteBuffer
_rpos += len;
}
bool readPackGUID(uint64& guid)
{
if(rpos()+1 > size())
return false;
guid = 0;
uint8 guidmark=0;
(*this) >> guidmark;
for(int i=0;i<8;i++)
{
if(guidmark & (uint8(1) << i))
{
if(rpos()+1 > size())
return false;
uint8 bit;
(*this) >> bit;
guid |= (uint64(bit) << (i*8));
}
}
return true;
}
const uint8 *contents() const { return &_storage[0]; }
size_t size() const { return _storage.size(); }

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "6952"
#define REVISION_NR "6953"
#endif // __REVISION_NR_H__

View file

@ -842,12 +842,6 @@
<File
RelativePath="..\..\src\game\PlayerDump.h">
</File>
<File
RelativePath="..\..\src\game\tools.cpp">
</File>
<File
RelativePath="..\..\src\game\Tools.h">
</File>
</Filter>
<Filter
Name="References"

View file

@ -1294,14 +1294,6 @@
RelativePath="..\..\src\game\PlayerDump.h"
>
</File>
<File
RelativePath="..\..\src\game\tools.cpp"
>
</File>
<File
RelativePath="..\..\src\game\Tools.h"
>
</File>
</Filter>
<Filter
Name="References"

View file

@ -1296,14 +1296,6 @@
RelativePath="..\..\src\game\PlayerDump.h"
>
</File>
<File
RelativePath="..\..\src\game\tools.cpp"
>
</File>
<File
RelativePath="..\..\src\game\Tools.h"
>
</File>
</Filter>
<Filter
Name="References"