AMXX-BG.INFO bits.inc Raw include

bits.inc

Original include source with line numbers.

Back Download .inc
1 #if defined _bits_included
2 #endinput
3 #endif
4 #define _bits_included
5 /*
6 Bits manipulation Zefir<[email protected]>
7 developed for Cerberus project
8 http://cerberus.cstrike.in.ua/
9 spring 2008 (c) Zefir
10
11 */
12
13 /*
14 bits manipulation
15 predefine bit numbers as:
16
17 enum e_flags {
18 FLAG_1,
19 FLAG_2,
20 FLAG_3,
21 FLAG_4
22 }
23
24 and use as:
25
26 new flag
27 set_bit(flag, FLAG_2)
28 get_bit(flag, FLAG_3)
29 */
30 #define set_bit(%1,%2) (%1 |= (1<<%2))
31 #define get_bit(%1,%2) (%1 & (1<<%2))
32 #define clr_bit(%1,%2) (%1 &= ~(1<<%2))
33
34 /*
35 bitmask manipulation
36 predefine bits as:
37
38 #define CLIENT_FLAG_1 (1<<0)
39 #define CLIENT_FLAG_2 (1<<1)
40 #define CLIENT_FLAG_3 (1<<2)
41 #define CLIENT_FLAG_4 (1<<3)
42
43 and use it:
44
45 new flag[32]
46 //set both flags
47 set_bits(flag[1], CLIENT_FLAG_1 | CLIENT_FLAG_3)
48 // clear bits
49 clr_bits(flag[1], CLIENT_FLAG_1 | CLIENT_FLAG_4 | CLIENT_FLAG_2)
50 */
51 #define set_bits(%1,%2) (%1 |= %2)
52 #define get_bits(%1,%2) (%1 & %2)
53 #define clr_bits(%1,%2) (%1 &= ~%2)
54
55 /*
56 big count bits manipulation
57 define bits container as array
58 new flags[4]
59 possible 4 * 32 = 128 bit stored
60
61 Big thanks ConnorMcLeod for optimization
62 */
63 #define set_big_bit(%1,%2) (%1[%2>>5] |= 1<<(%2 & 31))
64 #define get_big_bit(%1,%2) (%1[%2>>5] & 1<<(%2 & 31))
65 #define clr_big_bit(%1,%2) (%1[%2>>5] &= ~(1 << (%2 & 31)))