KILL_FIRST_BIT and FIND_FIRST_BIT

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
User avatar
tmesisbob
Engineer
Engineer
Posts: 79
Joined: 26 Mar 2004 19:17

KILL_FIRST_BIT and FIND_FIRST_BIT

Post by tmesisbob »

Hi,

I am trying to get 8 way road path finding working corectly. I have managed to work out what most of the code / varaibles do / are for, however I can not fathom out the meaning of the KILL_FIRST_BIT and FIND_FIRST_BIT defines, and of the _ffb_64 array.

Any light shedding would be appreciated.
matthijs
Engineer
Engineer
Posts: 76
Joined: 25 Jun 2004 15:20
Location: Enschede, Netherlands
Contact:

Post by matthijs »

I have already written some documentation about this, it is included with my new detour patch. I repeat here, hope it works. I'll elaborate a little if needed when I have more time:

Code: Select all

/* Returns the position of the first bit that is not zero, counted from the
 * left. Ie, 10110100 returns 2, 00000001 returns 0, etc. When x == 0 returns
 * 0.
 */
 #define FIND_FIRST_BIT(x) _ffb_64[(x)]
/* Returns x with the first bit that is not zero, counted from the left, set
 * to zero. So, 10110100 returns 10110000, 00000001 returns 00000000, etc.
 */
 #define KILL_FIRST_BIT(x) _ffb_64[(x)+64]
 
msalters
Engineer
Engineer
Posts: 34
Joined: 16 Jun 2004 19:21

Post by msalters »

I'm wondering if there is any data structure that stores a rail direction (0..5) in a 3 bit entry somewhere. I noticed that most variables that hold such a direction are temporaries. Usually, a bitmask is used. Now, if these directions (0..5) are really rare, we could benefit from a profitable space-time tradeoff by replacing these by powers of two (1<<0 - 1<<5). The advantage of this approach is that the conversions to and from bitmasks become a whole lot chaper.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 39 guests