-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKeyBitFlag.h
More file actions
66 lines (53 loc) · 1.26 KB
/
Copy pathKeyBitFlag.h
File metadata and controls
66 lines (53 loc) · 1.26 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once
#include "BitFlag.h"
struct KeyBitFlag
{
static constexpr size_t BITS = 256;
static constexpr size_t CHUNKS = BITS / 32;
BitFlag chunks[CHUNKS]{};
void Set(uint8 key) noexcept
{
chunks[key / 32].Set(key % 32);
}
void Clear(uint8 key) noexcept
{
chunks[key / 32].Clear(key % 32);
}
bool Test(uint8 key) const noexcept
{
return chunks[key / 32].Test(key % 32);
}
void Reset()
{
for (auto& chunk : chunks)
chunk = 0;
}
};
struct MouseBitFlag
{
flag m_flag = 0; // 32ºñÆ® Áß 3ºñÆ®¸¸ »ç¿ë
void Set(uint8 btn) noexcept
{
m_flag |= (1U << static_cast<flag>(btn));
}
void Clear(uint8 btn) noexcept
{
m_flag &= ~(1U << static_cast<flag>(btn));
}
bool Test(uint8 btn) const noexcept
{
return (m_flag & (1U << static_cast<flag>(btn))) != 0;
}
void Reset() noexcept
{
m_flag = 0;
}
};
struct GamePadBitFlag
{
flag m_flag = 0;
void Set(size_t index) noexcept { m_flag |= (1U << index); }
void Clear(size_t index) noexcept { m_flag &= ~(1U << index); }
bool Test(size_t index) const { return (m_flag & (1U << index)) != 0; }
void Reset() noexcept { m_flag = 0; }
};