25 #ifndef PEGASUS_UTIL_H 26 #define PEGASUS_UTIL_H 28 #include "common/stream.h" 30 #include "pegasus/types.h" 43 int32 getObjectID()
const;
49 #define NUM_FLAGS (sizeof(Unit) * 8) 50 #define BIT_INDEX_SHIFT (sizeof(Unit) + 2 - (sizeof(Unit)) / 3) 51 #define BIT_INDEX_MASK (NUM_FLAGS - 1) 53 template <
typename Unit, u
int32 kNumFlags>
57 void clearAllFlags() { memset(_flags, 0,
sizeof(_flags)); }
58 void setAllFlags() { memset(_flags, ~((Unit)0),
sizeof(_flags)); }
59 void setFlag(uint32 flag) { _flags[flag >> BIT_INDEX_SHIFT] |= 1 << (flag & BIT_INDEX_MASK); }
60 void clearFlag(uint32 flag) { _flags[flag >> BIT_INDEX_SHIFT] &= ~(1 << (flag & BIT_INDEX_MASK)); }
61 void setFlag(uint32 flag,
bool val) {
if (val) setFlag(flag);
else clearFlag(flag); }
62 bool getFlag(uint32 flag) {
return (_flags[flag >> BIT_INDEX_SHIFT] & (1 << (flag & BIT_INDEX_MASK))) != 0; }
64 for (uint32 i = 0; i <
sizeof(_flags); i++)
72 if (
sizeof(Unit) == 1) {
73 stream->
read(_flags,
sizeof(_flags));
77 for (uint32 i = 0; i <
ARRAYSIZE(_flags); i++) {
78 if (
sizeof(Unit) == 2)
87 if (
sizeof(Unit) == 1) {
88 stream->
write(_flags,
sizeof(_flags));
92 for (uint32 i = 0; i <
ARRAYSIZE(_flags); i++) {
93 if (
sizeof(Unit) == 2)
101 Unit _flags[(kNumFlags - 1) / NUM_FLAGS + 1];
105 #undef BIT_INDEX_SHIFT 106 #undef BIT_INDEX_MASK 108 int32 linearInterp(
const int32 start1,
const int32 stop1,
const int32 current1,
const int32 start2,
const int32 stop2);
110 int32 pegasusRound(
const int32 a,
const int32 b);
#define ARRAYSIZE(x)
Definition: util.h:91
void writeUint16BE(uint16 value)
Definition: stream.h:173
void writeUint32BE(uint32 value)
Definition: stream.h:180
Definition: algorithm.h:29
uint32 readUint32BE()
Definition: stream.h:515
uint16 readUint16BE()
Definition: stream.h:501
virtual uint32 write(const void *dataPtr, uint32 dataSize)=0
Definition: ai_action.h:33
virtual uint32 read(void *dataPtr, uint32 dataSize)=0