Files
TCPlayerbotCore/src/game/UpdateMask.h
T

128 lines
3.5 KiB
C++
Raw Normal View History

2008-10-02 16:23:55 -05:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* 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
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* 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
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#ifndef __UPDATEMASK_H
#define __UPDATEMASK_H
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "UpdateFields.h"
#include "Errors.h"
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
class UpdateMask
{
public:
2010-04-07 22:59:46 +02:00
UpdateMask() : mCount(0), mBlocks(0), mUpdateMask(0) { }
UpdateMask(const UpdateMask& mask) : mUpdateMask(0) { *this = mask; }
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
~UpdateMask()
2008-10-02 16:23:55 -05:00
{
2010-04-07 19:14:10 +02:00
if (mUpdateMask)
2008-10-02 16:23:55 -05:00
delete [] mUpdateMask;
}
2009-10-17 15:51:44 -07:00
2009-01-20 19:59:43 -06:00
void SetBit (uint32 index)
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
((uint8 *)mUpdateMask)[ index >> 3 ] |= 1 << (index & 0x7);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2009-01-20 19:59:43 -06:00
void UnsetBit (uint32 index)
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
((uint8 *)mUpdateMask)[ index >> 3 ] &= (0xff ^ (1 << (index & 0x7)));
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2009-01-20 19:59:43 -06:00
bool GetBit (uint32 index) const
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
return (((uint8 *)mUpdateMask)[ index >> 3 ] & (1 << (index & 0x7))) != 0;
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2009-01-20 19:59:43 -06:00
uint32 GetBlockCount() const { return mBlocks; }
uint32 GetLength() const { return mBlocks << 2; }
uint32 GetCount() const { return mCount; }
uint8* GetMask() { return (uint8*)mUpdateMask; }
2009-10-17 15:51:44 -07:00
2009-01-20 19:59:43 -06:00
void SetCount (uint32 valuesCount)
2008-10-02 16:23:55 -05:00
{
2010-04-07 19:14:10 +02:00
if (mUpdateMask)
2008-10-02 16:23:55 -05:00
delete [] mUpdateMask;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
mCount = valuesCount;
mBlocks = (valuesCount + 31) / 32;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
mUpdateMask = new uint32[mBlocks];
memset(mUpdateMask, 0, mBlocks << 2);
}
2009-10-17 15:51:44 -07:00
2009-01-20 19:59:43 -06:00
void Clear()
2008-10-02 16:23:55 -05:00
{
if (mUpdateMask)
memset(mUpdateMask, 0, mBlocks << 2);
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
UpdateMask& operator = (const UpdateMask& mask)
2008-10-02 16:23:55 -05:00
{
SetCount(mask.mCount);
memcpy(mUpdateMask, mask.mUpdateMask, mBlocks << 2);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return *this;
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void operator &= (const UpdateMask& mask)
2008-10-02 16:23:55 -05:00
{
ASSERT(mask.mCount <= mCount);
for (uint32 i = 0; i < mBlocks; ++i)
2008-10-02 16:23:55 -05:00
mUpdateMask[i] &= mask.mUpdateMask[i];
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void operator |= (const UpdateMask& mask)
2008-10-02 16:23:55 -05:00
{
ASSERT(mask.mCount <= mCount);
for (uint32 i = 0; i < mBlocks; ++i)
2008-10-02 16:23:55 -05:00
mUpdateMask[i] |= mask.mUpdateMask[i];
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
UpdateMask operator & (const UpdateMask& mask) const
2008-10-02 16:23:55 -05:00
{
ASSERT(mask.mCount <= mCount);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
UpdateMask newmask;
newmask = *this;
newmask &= mask;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return newmask;
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
UpdateMask operator | (const UpdateMask& mask) const
2008-10-02 16:23:55 -05:00
{
ASSERT(mask.mCount <= mCount);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
UpdateMask newmask;
newmask = *this;
newmask |= mask;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return newmask;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
private:
uint32 mCount;
uint32 mBlocks;
uint32 *mUpdateMask;
};
#endif
2009-02-17 20:07:49 -06:00