FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_bitBank.inl
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17namespace fge
18{
19
20template<std::size_t TNbytes>
22{
23 for (std::size_t i = 0; i < TNbytes; ++i)
24 {
25 this->g_data[i] = 0;
26 }
27}
28
29template<std::size_t TNbytes>
30void BitBank<TNbytes>::set(std::size_t index, bool flag)
31{
32 if (index < TNbytes * 8)
33 {
34 this->g_data[index / 8] = static_cast<uint8_t>(flag) << (index % 8);
35 }
36}
37template<std::size_t TNbytes>
38bool BitBank<TNbytes>::get(std::size_t index) const
39{
40 if (index < TNbytes * 8)
41 {
42 return this->g_data[index / 8] & (0x01 << (index % 8));
43 }
44 return false;
45}
46template<std::size_t TNbytes>
47uint8_t BitBank<TNbytes>::getByte(std::size_t index) const
48{
49 if (index < TNbytes)
50 {
51 return this->g_data[index];
52 }
53 return 0;
54}
55
56template<std::size_t TNbytes>
57std::size_t BitBank<TNbytes>::getSize() const
58{
59 return TNbytes;
60}
61
62template<std::size_t TNbytes>
64{
65 pck.append(&this->g_data, TNbytes);
66}
67template<std::size_t TNbytes>
69{
70 pck.read(&this->g_data, TNbytes);
71}
72
73} // namespace fge
bool get(std::size_t index) const
Get the value of a bit.
Definition C_bitBank.inl:38
void unpack(fge::net::Packet &pck)
Unpack the bank data from the packet.
Definition C_bitBank.inl:68
void pack(fge::net::Packet &pck)
Pack the bank data into the packet.
Definition C_bitBank.inl:63
std::size_t getSize() const
Get the number of bytes in the bank.
Definition C_bitBank.inl:57
void set(std::size_t index, bool flag)
Set a bit to 1 or 0.
Definition C_bitBank.inl:30
uint8_t getByte(std::size_t index) const
Get the specified byte.
Definition C_bitBank.inl:47
void clear()
Clear the bank.
Definition C_bitBank.inl:21
Definition C_packet.hpp:70