root/trunk/src/game/UpdateMask.h @ 169

Revision 102, 3.6 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef __UPDATEMASK_H
22#define __UPDATEMASK_H
23
24#include "UpdateFields.h"
25#include "Errors.h"
26
27class UpdateMask
28{
29    public:
30        UpdateMask( ) : mCount( 0 ), mBlocks( 0 ), mUpdateMask( 0 ) { }
31        UpdateMask( const UpdateMask& mask ) : mUpdateMask( 0 ) { *this = mask; }
32
33        ~UpdateMask( )
34        {
35            if(mUpdateMask)
36                delete [] mUpdateMask;
37        }
38
39        inline void SetBit (uint32 index)
40        {
41            ( (uint8 *)mUpdateMask )[ index >> 3 ] |= 1 << ( index & 0x7 );
42        }
43
44        inline void UnsetBit (uint32 index)
45        {
46            ( (uint8 *)mUpdateMask )[ index >> 3 ] &= (0xff ^ (1 <<  ( index & 0x7 ) ) );
47        }
48
49        inline bool GetBit (uint32 index)
50        {
51            return ( ( (uint8 *)mUpdateMask)[ index >> 3 ] & ( 1 << ( index & 0x7 ) )) != 0;
52        }
53
54        inline uint32 GetBlockCount() { return mBlocks; }
55        inline uint32 GetLength() { return mBlocks << 2; }
56        inline uint32 GetCount() { return mCount; }
57        inline uint8* GetMask() { return (uint8*)mUpdateMask; }
58
59        inline void SetCount (uint32 valuesCount)
60        {
61            if(mUpdateMask)
62                delete [] mUpdateMask;
63
64            mCount = valuesCount;
65            mBlocks = (valuesCount + 31) / 32;
66
67            mUpdateMask = new uint32[mBlocks];
68            memset(mUpdateMask, 0, mBlocks << 2);
69        }
70
71        inline void Clear()
72        {
73            if (mUpdateMask)
74                memset(mUpdateMask, 0, mBlocks << 2);
75        }
76
77        inline UpdateMask& operator = ( const UpdateMask& mask )
78        {
79            SetCount(mask.mCount);
80            memcpy(mUpdateMask, mask.mUpdateMask, mBlocks << 2);
81
82            return *this;
83        }
84
85        inline void operator &= ( const UpdateMask& mask )
86        {
87            ASSERT(mask.mCount <= mCount);
88            for (uint32 i = 0; i < mBlocks; i++)
89                mUpdateMask[i] &= mask.mUpdateMask[i];
90        }
91
92        inline void operator |= ( const UpdateMask& mask )
93        {
94            ASSERT(mask.mCount <= mCount);
95            for (uint32 i = 0; i < mBlocks; i++)
96                mUpdateMask[i] |= mask.mUpdateMask[i];
97        }
98
99        inline UpdateMask operator & ( const UpdateMask& mask ) const
100        {
101            ASSERT(mask.mCount <= mCount);
102
103            UpdateMask newmask;
104            newmask = *this;
105            newmask &= mask;
106
107            return newmask;
108        }
109
110        inline UpdateMask operator | ( const UpdateMask& mask ) const
111        {
112            ASSERT(mask.mCount <= mCount);
113
114            UpdateMask newmask;
115            newmask = *this;
116            newmask |= mask;
117
118            return newmask;
119        }
120
121    private:
122        uint32 mCount;
123        uint32 mBlocks;
124        uint32 *mUpdateMask;
125};
126#endif
Note: See TracBrowser for help on using the browser.