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

You can sort enums by bit type (Bit8 example):
pawn Код:
enum e_Bit8_pData
{
    e_AdminLevel,
    e_Rank
};

new
    Bit8: pData_8Bit[e_Bit8_pData] <MAX_PLAYERS>
;
pawn Код:
Bit8_Set(e_Bit8_pData[e_AdminLevel], playerid, someLevel);
Bit8_Set(e_Bit8_pData[e_Rank], playerid, someRank);
Get in the same way.

Increment like this (Bit16 example):
pawn Код:
new
    Bit16: numPlayerObjects <MAX_PLAYERS>
;
Bit16_Set(numPlayerObjects, playerid, Bit16_Get(numPlayerObjects, playerid) + 1);
Reply
#22

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
You can sort enums by bit type like for example for 8 bits data:
pawn Код:
enum e_pData_8Bit
{
    e_AdminLevel,
    e_Rank
};

new
    Bit8: pData_8Bit[e_pData_8Bit] <MAX_PLAYERS>
;
pawn Код:
Bit8_Set(pData_8Bit[e_AdminLevel], playerid, someLevel);
Bit8_Set(pData_8Bit[e_Rank], playerid, someRank);
Get in the same way.

Increment like this:
pawn Код:
new
    Bit16: numPlayerObjects <MAX_PLAYERS>
;
Bit16_Set(numPlayerObjects, playerid, Bit16_Get(numPlayerObjects, playerid) + 1);
Thanks for the tips, oh well, then if I stick to non-enum variables I'll be fine I guess?
Reply
#23

Quote:
Originally Posted by Zh3r0
Посмотреть сообщение
I mean, I have an enum, and want to use the enum.
@Edit, How do I increment or decrease a value?
Ah, nevermind, I use bitx_get() + 1. Right?
lol i try to make something like macro fnc for that here it is

pawn Код:
#define BitSetEx%0(%1, %2, %3, %4) %0_Set(%1, %2, %0_Get(%1, %2) %3 %4)
I didn't test but i think it won't work :P

pawn Код:
BitSetEx Bit4 ( iVar, id, + , 5 );
// Bit1 support only true/false
Reply
#24

Quote:
Originally Posted by OUL
Посмотреть сообщение
lol i try to make something like macro fnc for that here it is

pawn Код:
#define BitSetEx%0(%1, %2, %3, %4) %0_Set(%1, %2, %0_Get(%1, %2) %3 %4)
I didn't test but i think it won't work :P

pawn Код:
BitSetEx Bit4 ( iVar, id, + , 5 );
// Bit1 support only true/false
Oh well, I made these xD
pawn Код:
stock TogglePlayerIntro(playerid, toggle)
    return  Bit1_Set(PlayingIntro, playerid, toggle);
   
stock IsPlayingIntro(playerid)
    return  Bit1_Get(PlayingIntro, playerid);
   
stock GetPlayerDeaths(playerid)
    return Bit16_Get(Deaths, playerid);

stock GetPlayerKills(playerid)
    return Bit16_Get(Deaths, playerid);
   
stock SetPlayerDeaths(playerid, deaths)
    return Bit16_Set(Deaths, playerid, deaths);
   
stock SetPlayerKills(playerid, kills)
    return Bit16_Set(Deaths, playerid, kills);
   
stock IncreasePlayerDeaths(playerid)
    return Bit16_Set(Deaths, playerid, Bit16_Get(Deaths, playerid) + 1);
   
stock IncreasePlayerKills(playerid)
    return Bit16_Set(Kills, playerid, Bit16_Get(Kills, playerid) + 1);
   
stock SetWrongPasswords(playerid, passes)
    return Bit4_Set(WrongPassword, playerid, passes);
   
stock GetWrongPasswords(playerid)
    return Bit4_Get(WrongPassword, playerid);
   
stock WrongPasswordIncrease(playerid)
    return Bit4_Set(WrongPassword, playerid, Bit4_Get(WrongPassword, playerid) + 1);
   
stock GetPlayerVip(playerid)
    return Bit4_Get(Vip, playerid);

stock SetPlayerVip(playerid, vip)
    return Bit4_Set(Vip, playerid, vip);
   
stock GetPlayerLevel(playerid)
    return Bit4_Get(Admin, playerid);

stock SetPlayerLevel(playerid, level)
    return Bit4_Set(Admin, playerid, level);
   
stock SetLastON(playerid)
    LastON[playerid] = GetDate();

stock GetLastON(playerid)
    return LastON[playerid];
   
stock SetScore(playerid, score)
    return Score{playerid} = score;

stock GetScore(playerid)
    return Score{playerid};
   
stock SetMoney(playerid, money)
    return Money{playerid} = money;

stock GetMoney(playerid)
    return Money{playerid};
   
stock ToggleLogged(playerid, toggle)
    return Bit1_Set(Logged, playerid, toggle);
   
stock IsLogged(playerid)
    return Bit1_Get(Logged, playerid);
   
stock GetPlayerIntroPart(playerid)
    return Bit4_Get(pIntroPart, playerid);
   
stock SetPlayerIntroPart(playerid, part)
    return Bit4_Set(pIntroPart, playerid, part);
Reply
#25

lol away better way is mine but like i say 'didn't tested'

you shoud do thaton this way too

pawn Код:
stock SetBitEx(biteType, iVar, playerid = INVALID_PLAYER_ID, bool:plus, value) {
     switch(biteType) {   case 2: {
            if(value == true) return Bit2_Set(iVar, playerid, Bit2_Get(iVar, playerid) + value); // +
            else Bit2_Set(iVar, playerid, Bit2_Get(iVar, playerid) - value); // -
         } case 4: {
            if(value == true) return Bit4_Set(iVar, playerid, Bit4_Get(iVar, playerid) + value); // +
            else Bit4_Set(iVar, playerid, Bit4_Get(iVar, playerid) - value); // -
         } case 8: {
            if(value == true) return Bit8_Set(iVar, playerid, Bit8_Get(iVar, playerid) + value); // +
            else Bit8_Set(iVar, playerid, Bit8_Get(iVar, playerid) - value); // -
         } case 16: {
            if(value == true) return Bit16_Set(iVar, playerid, Bit16_Get(iVar, playerid) + value); // +
            else Bit16_Set(iVar, playerid, Bit16_Get(iVar, playerid) - value); // -
         } } }
hmmm but i still think this won't work beacause of 'bit[]'

pawn Код:
SetBitEx((2,4,8,16), Variable, playerid, true, 5); // Added +5
SetBitEx((2,4,8,16), Variable, playerid, false, 5); // Taked -5
Reply
#26

Quote:
Originally Posted by OUL
Посмотреть сообщение
lol away better way is mine but like i say 'didn't tested'
I don't want to get too complicated But thanks for the tip.
Reply
#27

Great release.

You wouldn't happen to have a mirror would you? Pastebin seems to be down for me. Also checked isup.me, and it says it seems to be down from there too.
Reply
#28

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
What do you exactly mean by that? The examples are just examples on how to use it, don't get confused by that please.
what i mean is:
if i make put this:
pawn Код:
g_VehiclePrice[vehicleid] = random(65535);
to make a random price of any vehicle thet can be buyable
with the max number: 65535
BUT i dont want thet the vehicle price will be smaller then 10,000
so how i make minimum vehicle random price(number)?
Reply
#29

Since you have made the Bit_Set/Get functions general, how about making the whole syntax general?
pawn Код:
#define Bit<%0>:%1<%2> \
    Bit%0: %1[((%2) + (32 / (Bit%0 + 1)) - 1) >>> _: (Bit32 - Bit%0)]

#define SetBit<%0>(%1,%2,%3) \
    Bit_Set(%1, (%2), %3, Bit%0)

#define GetBit<%0>(%1,%2) \
    Bit_Get(%1, (%2), Bit%0)
However, I'm not sure if it works^^
Reply
#30

Quote:
Originally Posted by Gh0sT_
Посмотреть сообщение
bumpppp
Sorry, no clue why that should happen. Maybe retry from the beginning. Also be sure you call Bit1_Set!

Quote:
Originally Posted by Double-O-Seven
Посмотреть сообщение
Since you have made the Bit_Set/Get functions general, how about making the whole syntax general?
pawn Код:
#define Bit<%0>:%1<%2> \
    Bit%0: %1[((%2) + (32 / (Bit%0 + 1)) - 1) >>> _: (Bit32 - Bit%0)]

#define SetBit<%0>(%1,%2,%3) \
    Bit_Set(%1, (%2), %3, Bit%0)

#define GetBit<%0>(%1,%2) \
    Bit_Get(%1, (%2), Bit%0)
However, I'm not sure if it works^^
I though about that while writing the syntax but unfortunately we can't just use a macros parameter after an alphanumeric character in the define itself (I tested this a several times but it didn't work for me) you have to use a different symbol (like you use < > for it) but that doesn't look good and most users are already common with the current syntax. If you know a shorter way (keeping the same syntax), please let me know - that'd be great.
Reply
#31

Do booleans use 64 bits? Asking, I thought I saw someone say this, I'm wondering if it's true.
Reply
#32

Nice include Ryder!
Reply
#33

please put this in .pwn 'cause I got errors when I complie my script with this, I really want this

good job
Reply
#34

Quote:
Originally Posted by System64
View Post
please put this in .pwn 'cause I got errors when I complie my script with this, I really want this

good job
Don't copy paste than, you probably copied stuff from pastebin too. There's a clickable label above called "Download", click on it and save it as "rBits.inc".

I have added a FAQ section below the first post - please read before posting any questions.
Reply
#35

Thanks RyDeR, it works!
Reply
#36

Still doesn't work, I got this errors
pawn Code:
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(1) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(70) : error 025: function heading differs from prototype
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(70) : error 025: function heading differs from prototype
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(71) : error 021: symbol already defined: "Bit_Set"
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(85) : error 001: expected token: "-identifier-", but found "("
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(91) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(92) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(94) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\gamemodes\iStunt.pwn(3902) : warning 203: symbol is never used: "bitLim"
D:\Private\A lot of shit\iStunt\gamemodes\iStunt.pwn(3902) : warning 203: symbol is never used: "bitVar"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


8 Errors.
Reply
#37

Quote:
Originally Posted by System64
View Post
Still doesn't work, I got this errors
pawn Code:
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(1) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(70) : error 025: function heading differs from prototype
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(70) : error 025: function heading differs from prototype
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(71) : error 021: symbol already defined: "Bit_Set"
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(85) : error 001: expected token: "-identifier-", but found "("
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(91) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(92) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\pawno\include\rBits.inc(94) : error 010: invalid function or declaration
D:\Private\A lot of shit\iStunt\gamemodes\iStunt.pwn(3902) : warning 203: symbol is never used: "bitLim"
D:\Private\A lot of shit\iStunt\gamemodes\iStunt.pwn(3902) : warning 203: symbol is never used: "bitVar"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


8 Errors.
Show me the include you have please.
Reply
#38

pawn Code:
/*
    SA-MP "rBits" Include
    Copyright © 2011 RyDeR`
*/


#if defined _Included_rBits
    #endinput
#endif

#define _Included_rBits

#define BIT_TAGS \
    { Bit1, Bit2, Bit4, Bit8, Bit16 }
   
enum e_Bits
{
    Bit1,
    Bit2,
    Bit4,
    Bit8,
    Bit16,
    Bit32
};

#define Bit1:%0<%1> \
    Bit1: %0[((%1) + 31) >>> _: Bit32]
   
#define Bit1_Set(%0,%1,%2) \
    Bit_Set(%0, (%1), (%2), Bit1)
   
#define Bit1_Get(%0,%1) \
    Bit_Get(%0, (%1), Bit1)

#define Bit2:%0<%1> \
    Bit2: %0[((%1) + 15) >>> _: (Bit32 - Bit2)]
   
#define Bit2_Set(%0,%1,%2) \
    Bit_Set(%0, (%1), (%2), Bit2)
   
#define Bit2_Get(%0,%1) \
    Bit_Get(%0, (%1), Bit2)

#define Bit4:%0<%1> \
    Bit4: %0[((%1) + 7) >>> _: (Bit32 - Bit4)]
   
#define Bit4_Set(%0,%1,%2) \
    Bit_Set(%0, (%1), (%2), Bit4)
   
#define Bit4_Get(%0,%1) \
    Bit_Get(%0, (%1), Bit4)

#define Bit8:%0<%1> \
    Bit8: %0[(%1) char]
   
#define Bit8_Set(%0,%1,%2) \
    (_: %0{(%1)} = (%2))
   
#define Bit8_Get(%0,%1) \
    (_: %0{(%1)})

#define Bit16:%0<%1> \
    Bit16: %0[((%1) + 1) >>> _: (Bit32 - Bit16)]
   
#define Bit16_Set(%0,%1,%2) \
    Bit_Set(%0, (%1), (%2), Bit16)
   
#define Bit16_Get(%0,%1) \
    Bit_Get(%0, (%1), Bit16)
   
stock Bit_Set(BIT_TAGS: bitArr[], arrIdx, value, e_Bits: bitShift, arrSize = sizeof(bitArr))
{
    new
        bitVar = ((arrIdx & ((1 << _: (Bit32 - bitShift)) - 1)) << _: bitShift),
        bitLim = ((1 << (1 << _: bitShift)) - 1)
    ;
    if(!(0 <= (arrIdx >>>= _: (Bit32 - bitShift)) < arrSize))
        return 0;
   
    (_: bitArr[arrIdx]) &= ~(bitLim << bitVar);
    (_: bitArr[arrIdx]) |= ((bitLim & value) << bitVar);
   
    return 1;
}

stock Bit_Get(BIT_TAGS: bitArr[], arrIdx, e_Bits: bitShift, arrSize = sizeof(bitArr))
{
    new
        bitVar = ((arrIdx & ((1 << _: (Bit32 - bitShift)) - 1)) << _: bitShift),
        bitLim = ((1 << (1 << _: bitShift)) - 1)
    ;
    if(!(0 <= (arrIdx >>>= _: (Bit32 - bitShift)) < arrSize))
        return 0;
   
    return ((_: bitArr[arrIdx] >>> bitVar) & bitLim);
}
I tried on grandlarc but the same!
Reply
#39

Looks fine to me. I don't think I can help you further with this, sorry.

@System64:

y_bit and rBits have same function names, rename either rBits' or y_bit's Bit_Set and Bit_Get function and the problem will be solved.
Reply
#40

pawn Code:
new
    g_iBit1_pData[eBit1_pData] <MAX_PLAYERS>
;
Change to

pawn Code:
new
    Bit1:g_iBit1_pData[eBit1_pData] <MAX_PLAYERS>
;
Because people will start crying if get errors again. I fixed it and now testing is that really good as it is.

Question:
Bit1 - using only for variables what setting 0 or 1? yes? (false/true)
Bit2 - ? i don't know other because i'm from Poland and i need to explain it clearly, sorry. Maybe i will find some help on ****** with Eng maybe.

By the way nice include.

edit://
Nice with Bit1. I tested pSpawned with enum on standard way and Bit1. Results:

Code:
rBits - 410bytes
Normal way - 1,69 kilobyte.
I think i will start to change my GameMode.. but for the first i need to learn other Bit values. But there's an errors when i put this in.

Code:
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\YSI\y_bit.inc(245) : warning 209: function "Bit_Set" should return a value
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\YSI\y_bit.inc(248) : warning 209: function "Bit_Set" should return a value
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(70) : error 025: function heading differs from prototype
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(70) : error 025: function heading differs from prototype
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(71) : error 021: symbol already defined: "Bit_Set"
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(73) : warning 219: local variable "bitVar" shadows a variable at a preceding level
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(74) : warning 219: local variable "bitLim" shadows a variable at a preceding level
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(85) : error 001: expected token: "-identifier-", but found "("
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(91) : error 010: invalid function or declaration
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(92) : error 010: invalid function or declaration
C:\Documents and Settings\Kakarotto\Pulpit\Serwery\Live\pawno\include\rBits.inc(94) : error 010: invalid function or declaration
C:\Documents and Settings\Kakarotto\Pulpit\LiveFor3Run.pwn(2299) : warning 203: symbol is never used: "bitLim"
C:\Documents and Settings\Kakarotto\Pulpit\LiveFor3Run.pwn(2299) : warning 203: symbol is never used: "bitVar"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


7 Errors.
Using includes:
pawn Code:
#include                                    "a_samp"
#include                                    "streamer"
#include                                    "sscanf"
#include                                    "zcmd"
//#include                                  "audio"

#include                                    "live_textdraws"

#include                                    "YSI\y_ini"
#include                                    "YSI\y_groups"
#include                                    "YSI\y_classes"

#include                                    "rBits"
I think just ****** included somewhere his y_bit include into one of above includes what i included. I will try to solve it..

edit2://
Solved. Just changed names of Bit to rBits in your include.

Question:
In the future we will be able to set Bit into 'non-player' var? example for ServerInfo enum count ConnectedPlayers. It doesn't need <MAX_PLAYERS>.
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)