I remembered a plugin for the half-life engine using this method for using a single number for complex 'user access' to several different permissions. It is a bit more complex in code but a lot more simple for database/binary file structure. I figured I would share the example for carebear giggles.
Edit blitzmax/mod/brl.mod/retro.mod/retro.bmx
insert at bottom:
and rebuild brl.retro
The above gives you the ability to shorten the amount of permissions in your single integer access; shorten the binary version of the number.
ByteBin - 8
ShortBin - 16
Bin - 32
LongBin - 64
In the example, I use shortbin:
By adding the values of certain permissions, and using the single integer from the result, you can get a lot more information by using several booleans within a numbers binary information.
Not that much of a saver, but nifty anyways.
Time
Edit blitzmax/mod/brl.mod/retro.mod/retro.bmx
insert at bottom:
Function ShortBin$( val ) Local buf:Short[16] For Local k=15 To 0 Step -1 buf[k]=(val&1)+Asc("0") val:Shr 1 Next Return String.FromShorts( buf,16 ) End Function Function ByteBin$( val ) Local buf:Short[8] For Local k=7 To 0 Step -1 buf[k]=(val&1)+Asc("0") val:Shr 1 Next Return String.FromShorts( buf,8 ) End Function
and rebuild brl.retro
The above gives you the ability to shorten the amount of permissions in your single integer access; shorten the binary version of the number.
ByteBin - 8
ShortBin - 16
Bin - 32
LongBin - 64
In the example, I use shortbin:
Const MappingAccess :Byte=1 'Binary 1 Const BanAccess :Byte=2 'Binary 2 Const KickAccess :Byte=3 'Binary 4 'Const etc... :byte=4 'Binary 8 'Const etc... :byte=5 'Binary 16 'Const etc... :byte=6 'Binary 32 Global AccessLevel:Int = 5 '(Mapping access + kick access) in binary = 1+4 = 5. 'Looks like this in binary: 0000000000000101 Print "Access to Mapping: " + HasAccess(AccessLevel,MappingAccess) Print "Access to Banning: " + HasAccess(AccessLevel,BanAccess) Print "Access to Kicking: " + HasAccess(AccessLevel,KickAccess) Function HasAccess:Int(Level:Int,Tier:Int) If Tier <=0 Then Return 0 Local TmpAC:String = shortbin$(Level) Return TmpAC[TmpAc.Length-tier]-48 End Function
By adding the values of certain permissions, and using the single integer from the result, you can get a lot more information by using several booleans within a numbers binary information.
Not that much of a saver, but nifty anyways.
Time