forked from mrkite/minutor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunkid.h
30 lines (23 loc) · 773 Bytes
/
chunkid.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef CHUNKID_H
#define CHUNKID_H
// ChunkID is the key used to identify entries in the Cache
// Chunks are identified by their coordinates (CX,CZ) but a single key is needed to access a map like structure
class ChunkID {
public:
ChunkID(int cx, int cz);
bool operator==(const ChunkID &) const;
friend unsigned int qHash(const ChunkID &);
int getX() const { return cx; }
int getZ() const { return cz; }
protected:
int cx, cz;
};
inline ChunkID::ChunkID(int cx, int cz) : cx(cx), cz(cz) {
}
inline bool ChunkID::operator==(const ChunkID &other) const {
return (other.cx == cx) && (other.cz == cz);
}
inline unsigned int qHash(const ChunkID &c) {
return (c.cx << 16) ^ (c.cz & 0xffff); // safe way to hash a pair of integers
}
#endif // CHUNKID_H