Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
UpdateMask.h
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#ifndef SF_UPDATEMASK_H
7
#define SF_UPDATEMASK_H
8
9
#include "
ByteBuffer.h
"
10
#include "
Errors.h
"
11
#include "
UpdateFields.h
"
12
13
class
UpdateMask
14
{
15
public
:
17
typedef
uint32
ClientUpdateMaskType
;
18
19
enum
UpdateMaskCount
20
{
21
CLIENT_UPDATE_MASK_BITS
=
sizeof
(
ClientUpdateMaskType
) * 8,
22
};
23
24
UpdateMask
() :
_fieldCount
(0),
_blockCount
(0),
_bits
(NULL) { }
25
26
UpdateMask
(
UpdateMask
const
& right) :
_bits
(NULL)
27
{
28
SetCount
(right.
GetCount
());
29
memcpy(
_bits
, right.
_bits
,
sizeof
(
uint8
) *
_blockCount
* 32);
30
}
31
32
~UpdateMask
() {
delete
[]
_bits
; }
33
34
void
SetBit
(
uint32
index) {
_bits
[index] = 1; }
35
void
UnsetBit
(
uint32
index) {
_bits
[index] = 0; }
36
bool
GetBit
(
uint32
index)
const
{
return
_bits
[index] != 0; }
37
38
void
AppendToPacket
(
ByteBuffer
* data)
39
{
40
for
(
uint32
i = 0; i <
GetBlockCount
(); ++i)
41
{
42
ClientUpdateMaskType
maskPart = 0;
43
for
(
uint32
j = 0; j <
CLIENT_UPDATE_MASK_BITS
; ++j)
44
if
(
_bits
[
CLIENT_UPDATE_MASK_BITS
* i + j])
45
maskPart |= 1 << j;
46
47
*data << maskPart;
48
}
49
}
50
51
uint32
GetBlockCount
()
const
{
return
_blockCount
; }
52
uint32
GetCount
()
const
{
return
_fieldCount
; }
53
54
void
SetCount
(
uint32
valuesCount)
55
{
56
delete
[]
_bits
;
57
58
_fieldCount
= valuesCount;
59
_blockCount
= (valuesCount +
CLIENT_UPDATE_MASK_BITS
- 1) /
CLIENT_UPDATE_MASK_BITS
;
60
61
_bits
=
new
uint8
[
_blockCount
*
CLIENT_UPDATE_MASK_BITS
];
62
memset(
_bits
, 0,
sizeof
(
uint8
) *
_blockCount
*
CLIENT_UPDATE_MASK_BITS
);
63
}
64
65
void
Clear
()
66
{
67
if
(
_bits
)
68
memset(
_bits
, 0,
sizeof
(
uint8
) *
_blockCount
*
CLIENT_UPDATE_MASK_BITS
);
69
}
70
71
UpdateMask
&
operator=
(
UpdateMask
const
& right)
72
{
73
if
(
this
== &right)
74
return
*
this
;
75
76
SetCount
(right.
GetCount
());
77
memcpy(
_bits
, right.
_bits
,
sizeof
(
uint8
) *
_blockCount
*
CLIENT_UPDATE_MASK_BITS
);
78
return
*
this
;
79
}
80
81
UpdateMask
&
operator&=
(
UpdateMask
const
& right)
82
{
83
ASSERT
(right.
GetCount
() <=
GetCount
());
84
for
(
uint32
i = 0; i <
_fieldCount
; ++i)
85
_bits
[i] &= right.
_bits
[i];
86
87
return
*
this
;
88
}
89
90
UpdateMask
&
operator|=
(
UpdateMask
const
& right)
91
{
92
ASSERT
(right.
GetCount
() <=
GetCount
());
93
for
(
uint32
i = 0; i <
_fieldCount
; ++i)
94
_bits
[i] |= right.
_bits
[i];
95
96
return
*
this
;
97
}
98
99
UpdateMask
operator|
(
UpdateMask
const
& right)
100
{
101
UpdateMask
ret(*
this
);
102
ret |= right;
103
return
ret;
104
}
105
106
private
:
107
uint32
_fieldCount
;
108
uint32
_blockCount
;
109
uint8
*
_bits
;
110
};
111
112
#endif
ByteBuffer.h
uint8
std::uint8_t uint8
Definition
Define.h:79
uint32
std::uint32_t uint32
Definition
Define.h:77
Errors.h
ASSERT
#define ASSERT
Definition
Errors.h:29
UpdateFields.h
ByteBuffer
Definition
ByteBuffer.h:120
UpdateMask::GetCount
uint32 GetCount() const
Definition
UpdateMask.h:52
UpdateMask::Clear
void Clear()
Definition
UpdateMask.h:65
UpdateMask::operator=
UpdateMask & operator=(UpdateMask const &right)
Definition
UpdateMask.h:71
UpdateMask::operator|
UpdateMask operator|(UpdateMask const &right)
Definition
UpdateMask.h:99
UpdateMask::GetBlockCount
uint32 GetBlockCount() const
Definition
UpdateMask.h:51
UpdateMask::UpdateMaskCount
UpdateMaskCount
Definition
UpdateMask.h:20
UpdateMask::CLIENT_UPDATE_MASK_BITS
@ CLIENT_UPDATE_MASK_BITS
Definition
UpdateMask.h:21
UpdateMask::GetBit
bool GetBit(uint32 index) const
Definition
UpdateMask.h:36
UpdateMask::_fieldCount
uint32 _fieldCount
Definition
UpdateMask.h:107
UpdateMask::ClientUpdateMaskType
uint32 ClientUpdateMaskType
Type representing how client reads update mask.
Definition
UpdateMask.h:17
UpdateMask::operator|=
UpdateMask & operator|=(UpdateMask const &right)
Definition
UpdateMask.h:90
UpdateMask::UpdateMask
UpdateMask()
Definition
UpdateMask.h:24
UpdateMask::~UpdateMask
~UpdateMask()
Definition
UpdateMask.h:32
UpdateMask::UnsetBit
void UnsetBit(uint32 index)
Definition
UpdateMask.h:35
UpdateMask::_bits
uint8 * _bits
Definition
UpdateMask.h:109
UpdateMask::_blockCount
uint32 _blockCount
Definition
UpdateMask.h:108
UpdateMask::SetCount
void SetCount(uint32 valuesCount)
Definition
UpdateMask.h:54
UpdateMask::UpdateMask
UpdateMask(UpdateMask const &right)
Definition
UpdateMask.h:26
UpdateMask::operator&=
UpdateMask & operator&=(UpdateMask const &right)
Definition
UpdateMask.h:81
UpdateMask::SetBit
void SetBit(uint32 index)
Definition
UpdateMask.h:34
UpdateMask::AppendToPacket
void AppendToPacket(ByteBuffer *data)
Definition
UpdateMask.h:38
src
server
game
Entities
Object
Updates
UpdateMask.h
Generated on
for Project SkyFire Core by
1.17.0