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.
KILL_FIRST_BIT and FIND_FIRST_BIT
Moderator: OpenTTD Developers
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]
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.
Who is online
Users browsing this forum: No registered users and 39 guests