Raised This Month: $12 Target: $400
 3% 

Bit - include file (formally Boolean)


Post New Thread Reply   
 
Thread Tools Display Modes
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-11-2010 , 01:58   Re: Boolean - include file
Reply With Quote #11

Quote:
Originally Posted by Lulu the hero View Post
What you are arguing about are CPU cycles.
I know. That was the purpose of me stating to use &31 in the first place.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-11-2010 , 09:45   Re: Boolean - include file
Reply With Quote #12

IMO, an include file for this type of thing is overkill. A thread containing the few macros (which already exists) would suffice.

Code:
#define player_to_flag(%1)		(1<<(%1-1))

Code:
#define player_to_flag(%1)		(1<<(%1 & 31))
Using ( id & 31 ) instead of ( id - 1 ) is more efficient and will simply change when a ( 1 << 0 ) shift is used.

id - 1:
PHP Code:
<< //player_to_flag(1)
<< //player_to_flag(2)
...
<< 30 //player_to_flag(31)
<< 31 //player_to_flag(32) 
id & 31:
PHP Code:
<< //player_to_flag(1)
<< //player_to_flag(2)
...
<< 31 //player_to_flag(31)
<< //player_to_flag(32) 
__________________

Last edited by Bugsy; 12-11-2010 at 09:58.
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-11-2010 , 18:51   Re: Boolean - include file
Reply With Quote #13

Quote:
Originally Posted by Bugsy View Post
Using ( id & 31 ) instead of ( id - 1 ) is more efficient and will simply change when a ( 1 << 0 ) shift is used.
I had already pointed that out but he seemed stubborn to change.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-11-2010 , 19:48   Re: Boolean - include file
Reply With Quote #14

Quote:
Originally Posted by Exolent[jNr] View Post
I had already pointed that out but he seemed stubborn to change.
Yea I know, I just wanted to show him the difference between the two.
__________________
Bugsy is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 12-20-2010 , 11:00   Re: Boolean - include file
Reply With Quote #15

Done, thanks for the tips, guys. I hope it will be usable. Please if you can, check it on a 64 bit server.
Lulu the hero is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-20-2010 , 17:24   Re: Boolean - include file
Reply With Quote #16

Quote:
Originally Posted by Lulu the hero View Post
Done, thanks for the tips, guys. I hope it will be usable. Please if you can, check it on a 64 bit server.
These macros are very simple and don't need to be tested.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-20-2010 , 20:22   Re: Boolean - include file
Reply With Quote #17

Code:
#if cellbits==32
	#define cellbytes	4
	#define flagmask	31
#else
	#define cellbytes	8
	#define flagmask	63
#endif

// Convert's id to a flag
#define player_to_flag(%1)		(1<<(%1&flagmask))
The number of players supported by HL1 will always be 32, regardless if the server is running on a 32 or 64 bit system. There is no need to change the mask for 32 & 64 bit systems if only 32 bits are going to be used in both cases. It would be best to make a separate macro using ( 1 << %1 ) for 64-bit systems and continue to use ( 1 << ( %1 & 31 ) ) for 32-bit.
Code:
#if cellbits==32
	#define cellbytes	4
	#define player_to_flag(%1)	(1<<(%1&31))
#else
	#define cellbytes	8
	#define player_to_flag(%1)	(1<<%1)
#endi
__________________

Last edited by Bugsy; 12-21-2010 at 08:07.
Bugsy is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 12-21-2010 , 23:24   Re: Boolean - include file
Reply With Quote #18

Done. What other functions should be inserted to the include file, that you think is related to the ones that are already in? I have a few ideas:
- convert a number to an any given dimension string( we currently have num_to_binstr and num_to_hexstr, but how about a something like: num_to_custom( num, dest[], len, dimension )? )
- get/set/clear/toggle a SPECIFIED bit in an integer, not only ID( would almost be the same )
- ROL, ROR and alike functions( ROL= ROtate Left and ROL = ROtate Right )
- Some kind of comparison for two booleans


Edit:
Added ROL and ROR stocks...

Last edited by Lulu the hero; 12-22-2010 at 00:08.
Lulu the hero is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 02-10-2011 , 14:04   Re: Boolean - include file
Reply With Quote #19

Added toggle_flag / clear_flag / set_flag / is_flag_set macros to make the include file usable for not just only players.

Warning! Got some bugs in num_to_bin/hexstr. I'm sorting it out now, gonna upload working version ASAP.

Edit : debugged it, works fine.

Last edited by Lulu the hero; 02-10-2011 at 15:05.
Lulu the hero is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 02-10-2011 , 20:24   Re: Boolean - include file
Reply With Quote #20

Quote:
Originally Posted by fysiks View Post
I don't see how your include has anything to do with booleans. ...
True. Renamed the include file to simply: bit

Corrected the num_to_hexstr ( I've forgot, that 0xF is 15, which is 0b1111, which is only 4 bits long, so it is not a byte, but a nibble ).

Added the zero_fill parameter to num_to_bin/hexstr functions( while removed the length parameter, do we really need that? ).

Added stocks:
- get_highest(integer, count_type) // count_type = COUNT_BIT(1) | COUNT_NIBBLE(4) - gives back the place of the most significant bit/nibble
- count_bits(integer) // counts the 1 bits in an integer
Lulu the hero is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:08.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode