[Include] rBits [supports 16, 8, 4, 2 and 1-bit arrays]
#41

Yeah getting a error here:
Code:
rBits.inc(1) : error 010: invalid function or declaration
Can anyone pass me a old version of this include? May work.
Reply
#42

Quote:
Originally Posted by Lorenc_
View Post
Yeah getting a error here:
Code:
rBits.inc(1) : error 010: invalid function or declaration
Can anyone pass me a old version of this include? May work.
This is and was the only version untill now. What's on line 1?
Reply
#43

I've found my problem, problem is that I can't use Bit_Set, than eq. BitSet, why?
Reply
#44

This is just what I needed.
Reply
#45

Quote:
Originally Posted by RyDeR`
View Post
This is and was the only version untill now. What's on line 1?
Nothing, though I managed to ask TheKiller for his version of the Include, works perfectly now. Theres nothing in the include. It's completely clean and it gives the error.
Reply
#46

can I set negative values?

e.g: BitX_Set(array, id, -1);
Reply
#47

Quote:
Originally Posted by Gh0sT_
View Post
can I set negative values?

e.g: BitX_Set(array, id, -1);
Yes but no. When you set for example -1 at 4 bits, the value will become 15. If you do the same for -2 the value will becomw 14. Same way of working for other bit types.
Reply
#48

Just renamed most functions/defines so they don't conflict with YSI.

to anyone that wants it:
Code:
/*
	SA-MP "rBits" Include
	Copyright © 2011 RyDeR`
*/

#if defined _Included_rBits
	#endinput
#endif

#define _Included_rBits

#define BIT_TAGS \
	{ rBit1, rBit2, rBit4, rBit8, rBit16 }

enum e_Bits
{
	rBit1,
	rBit2,
	rBit4,
	rBit8,
	rBit16,
	rBit32
};

#define rBit1:%0<%1> \
	rBit1: %0[((%1) + 31) >>> _: rBit32]

#define	rBit1_Set(%0,%1,%2) \
	rBit_Set(%0, (%1), (%2), rBit1)

#define rBit1_Get(%0,%1) \
	rBit_Get(%0, (%1), rBit1)

#define rBit2:%0<%1> \
	rBit2: %0[((%1) + 15) >>> _: (rBit32 - rBit2)]

#define	rBit2_Set(%0,%1,%2) \
	rBit_Set(%0, (%1), (%2), rBit2)

#define rBit2_Get(%0,%1) \
	rBit_Get(%0, (%1), rBit2)

#define rBit4:%0<%1> \
	rBit4: %0[((%1) + 7) >>> _: (rBit32 - rBit4)]

#define	rBit4_Set(%0,%1,%2) \
	rBit_Set(%0, (%1), (%2), rBit4)

#define rBit4_Get(%0,%1) \
	rBit_Get(%0, (%1), rBit4)

#define rBit8:%0<%1> \
	rBit8: %0[(%1) char]

#define rBit8_Set(%0,%1,%2) \
	(_: %0{(%1)} = (%2))

#define rBit8_Get(%0,%1) \
	(_: %0{(%1)})

#define rBit16:%0<%1> \
	rBit16: %0[((%1) + 1) >>> _: (rBit32 - rBit16)]

#define	rBit16_Set(%0,%1,%2) \
	rBit_Set(%0, (%1), (%2), rBit16)

#define rBit16_Get(%0,%1) \
	rBit_Get(%0, (%1), rBit16)

stock rBit_Set(BIT_TAGS: bitArr[], arrIdx, value, e_Bits: bitShift, arrSize = sizeof(bitArr))
{
	new
		bitVar = ((arrIdx & ((1 << _: (rBit32 - bitShift)) - 1)) << _: bitShift),
		bitLim = ((1 << (1 << _: bitShift)) - 1)
	;
	if(!(0 <= (arrIdx >>>= _: (rBit32 - bitShift)) < arrSize))
		return 0;

	(_: bitArr[arrIdx]) &= ~(bitLim << bitVar);
	(_: bitArr[arrIdx]) |= ((bitLim & value) << bitVar);

	return 1;
}

stock rBit_Get(BIT_TAGS: bitArr[], arrIdx, e_Bits: bitShift, arrSize = sizeof(bitArr))
{
	new
		bitVar = ((arrIdx & ((1 << _: (rBit32 - bitShift)) - 1)) << _: bitShift),
		bitLim = ((1 << (1 << _: bitShift)) - 1)
	;
	if(!(0 <= (arrIdx >>>= _: (rBit32 - bitShift)) < arrSize))
		return 0;

	return ((_: bitArr[arrIdx] >>> bitVar) & bitLim);
}
You just need to add a 'r' next to your function(s).
Reply
#49

thanks lorenc *_____*
Reply
#50

Ne İse Yaradıgını Anlamadım İngilizcem Kotudur

Thanks
Reply
#51

Amazing work RyDeR`. The way the .amx size decreases is awesome.
I want to use it, although I have two questions.

How can I use it on Money. I have enum with money init but the value can be more than one billion.
Is there any way to use it with Bit, or to make the enum as normal and use rBits only a the Global Variables.

Also, about password with whirlpool Bit8: is fine?

Regards,
Reply
#52

Quote:
Originally Posted by Dwane
View Post
How can I use it on Money.
If the value goes over billions, just use a normal, 32-bit, variable.

Quote:
Originally Posted by Dwane
View Post
Also, about password with whirlpool Bit8: is fine?
No, this include only supports integers. However, to answer your question, you can just use char arrays with strpack and strunpack.
Reply
#53

Oh, my bad. Well, I will use it then to those variables (integers with value less 65535).
Thank you!

Edit: The result is amazing.

pawn Code:
First GameMode: .pwn ( 133KB ) || .amx ( 312KB )
Second GameMode: .pwn ( 150KB ) || .amx ( 315KB ) [ Uses rBits ]
I added more at my second GM and the amx size is only 3KB more than the first GameMode!
Reply
#54

Quote:
Originally Posted by Dwane
View Post
Oh, my bad. Well, I will use it then to those variables (integers with value less 65535).
Thank you!

Edit: The result is amazing.

pawn Code:
First GameMode: .pwn ( 133KB ) || .amx ( 312KB )
Second GameMode: .pwn ( 150KB ) || .amx ( 315KB ) [ Uses rBits ]
I added more at my second GM and the amx size is only 3KB more than the first GameMode!
Glad to see you're using it pretty well!

This post is just to let you know I updated the topic and the include itself. Nothing really changed as I only changed the style of the include so it's not necessary to update if you don't want to.
Reply
#55

Quote:
Originally Posted by RyDeR`
View Post
Glad to see you're using it pretty well!

This post is just to let you know I updated the topic and the include itself. Nothing really changed as I only changed the style of the include so it's not necessary to update if you don't want to.
Thanks. I updated! Moreover, I am using about 30 variables with rBits and I have new result.
pawn Code:
First GameMode: .pwn ( 133KB ) || .amx ( 312KB )
Second GameMode: .pwn ( 168KB ) || .amx ( 288KB ) [ Uses rBits ]
It's lower than the first Gamemode that it doesn't use rBits.

Excellent work RyDeR`.
Reply
#56

Look at "Integer Limits" in the first post.

4 bits can store 0-15.
Reply
#57

ryder poderia dispinibilizar ela ja em arquivo inc pf ?
Reply
#58

What If someone already using YSI stuffs, I think that is not compatible.
Reply
#59

Quote:
Originally Posted by justice96
Посмотреть сообщение
What If someone already using YSI stuffs, I think that is not compatible.
Why don't you use Bit Functions, is faster.
https://sampforum.blast.hk/showthread.php?tid=591223
Reply
#60

It's only for numbers?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)