View difference between Paste ID: gqqV92MT and 5hr6mfMt
SHOW: | | - or go back to the newest paste.
1
/*
2-
	SA-MP rBits Include
2+
	SA-MP "rBits" Include
3-
	Copyright © 2011-2012 RyDeR`
3+
	Copyright © 2011 RyDeR`
4
*/
5
6
#if defined _Included_rBits
7
	#endinput
8-
#else
8+
9-
	#define _Included_rBits
9+
10
#define _Included_rBits
11
12
#define BIT_TAGS \
13
	{ Bit1, Bit2, Bit4, Bit8, Bit16 }
14-
		
14+
15-
enum e_Bits {
15+
enum e_Bits
16
{
17
	Bit1,
18
	Bit2,
19
	Bit4,
20
	Bit8,
21
	Bit16,
22
	Bit32
23
};
24
25
#define Bit1:%0<%1> \
26
	Bit1: %0[((%1) + 31) >>> _: Bit32]
27
	
28
#define	Bit1_Set(%0,%1,%2) \
29
	Bit_Set(%0, (%1), (%2), Bit1)
30
	
31
#define Bit1_Get(%0,%1) \
32
	Bit_Get(%0, (%1), Bit1)
33
34
#define Bit2:%0<%1> \
35
	Bit2: %0[((%1) + 15) >>> _: (Bit32 - Bit2)]
36
	
37
#define	Bit2_Set(%0,%1,%2) \
38
	Bit_Set(%0, (%1), (%2), Bit2)
39
	
40
#define Bit2_Get(%0,%1) \
41
	Bit_Get(%0, (%1), Bit2)
42
43
#define Bit4:%0<%1> \
44
	Bit4: %0[((%1) + 7) >>> _: (Bit32 - Bit4)]
45
	
46
#define	Bit4_Set(%0,%1,%2) \
47
	Bit_Set(%0, (%1), (%2), Bit4)
48
	
49
#define Bit4_Get(%0,%1) \
50
	Bit_Get(%0, (%1), Bit4)
51
52
#define Bit8:%0<%1> \
53
	Bit8: %0[(%1) char]
54
	
55
#define Bit8_Set(%0,%1,%2) \
56
	(_: %0{(%1)} = (%2))
57
	
58
#define Bit8_Get(%0,%1) \
59
	(_: %0{(%1)})
60
61
#define Bit16:%0<%1> \
62-
	Bit8: %0[((%1) + 3) >>> _: (Bit32 - Bit8)]
62+
63
	
64
#define	Bit16_Set(%0,%1,%2) \
65-
	Bit_Set(%0, (%1), (%2), Bit8)
65+
66
	
67
#define Bit16_Get(%0,%1) \
68-
	Bit_Get(%0, (%1), Bit8)
68+
69
	
70
stock Bit_Set(BIT_TAGS: bitArr[], arrIdx, value, e_Bits: bitShift, arrSize = sizeof(bitArr))
71
{
72
	new
73
		bitVar = ((arrIdx & ((1 << _: (Bit32 - bitShift)) - 1)) << _: bitShift),
74
		bitLim = ((1 << (1 << _: bitShift)) - 1)
75
	;
76
	if(!(0 <= (arrIdx >>>= _: (Bit32 - bitShift)) < arrSize))
77
		return 0;
78
	
79
	(_: bitArr[arrIdx]) &= ~(bitLim << bitVar);
80-
stock Bit_Set(BIT_TAGS: abArray[], iIdx, const iValue, const e_Bits: iShift, const iSize = sizeof(abArray)) {
80+
	(_: bitArr[arrIdx]) |= ((bitLim & value) << bitVar);
81
	
82-
		bVar = ((iIdx & ((1 << _: (Bit32 - iShift)) - 1)) << _: iShift),
82+
83-
		bLim = ((1 << (1 << _: iShift)) - 1)
83+
84
85-
	iIdx = (iIdx >>> _: (Bit32 - iShift));
85+
stock Bit_Get(BIT_TAGS: bitArr[], arrIdx, e_Bits: bitShift, arrSize = sizeof(bitArr))
86
{
87-
	if(!(-1 < iIdx < iSize)) {
87+
88
		bitVar = ((arrIdx & ((1 << _: (Bit32 - bitShift)) - 1)) << _: bitShift),
89-
	}
89+
		bitLim = ((1 << (1 << _: bitShift)) - 1)
90-
	(_: abArray[iIdx] &= ~(bLim << bVar));
90+
91-
	(_: abArray[iIdx] |= ((bLim & iValue) << bVar));
91+
	if(!(0 <= (arrIdx >>>= _: (Bit32 - bitShift)) < arrSize))
92
		return 0;
93
	
94
	return ((_: bitArr[arrIdx] >>> bitVar) & bitLim);
95
}