diff options
author | matthijs <matthijs@openttd.org> | 2005-04-07 19:19:16 +0000 |
---|---|---|
committer | matthijs <matthijs@openttd.org> | 2005-04-07 19:19:16 +0000 |
commit | da3621c1804e6da9cefd712da9d0dd48fff61add (patch) | |
tree | 034da873c7ef2d41762a674839ff36339133a41e /npf.c | |
parent | 9c3813e21374c71da7c1c49cf52d68546815c1b0 (diff) | |
download | openttd-da3621c1804e6da9cefd712da9d0dd48fff61add.tar.xz |
(svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
- Codechange: [NPF] Improved the NPF hash calculation slightly.
- Codechange: [NPF] Increased hash size, should speed up somewhat.
Diffstat (limited to 'npf.c')
-rw-r--r-- | npf.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -102,9 +102,19 @@ static const uint _trackdir_length[14] = { uint NTPHash(uint key1, uint key2) { + /* This function uses the old hash, which is fixed on 10 bits (1024 buckets) */ return PATHFIND_HASH_TILE(key1); } +uint NPFHash(uint key1, uint key2) +{ + /* TODO: think of a better hash? */ + uint part1 = TileX(key1) & NPF_HASH_HALFMASK; + uint part2 = TileY(key1) & NPF_HASH_HALFMASK; + /* The value of 14 below is based on the maximum value of key2 (13) */ + return ((((part1 << NPF_HASH_HALFBITS) | part2)) + (NPF_HASH_SIZE * key2 / 14)) % NPF_HASH_SIZE; +} + int32 NPFCalcZero(AyStar* as, AyStarNode* current, OpenListNode* parent) { return 0; } @@ -809,7 +819,7 @@ NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, byte trackdir, Tran void InitializeNPF(void) { - init_AyStar(&_npf_aystar, NTPHash, 1024); + init_AyStar(&_npf_aystar, NPFHash, NPF_HASH_SIZE); _npf_aystar.loops_per_tick = 0; _npf_aystar.max_path_cost = 0; _npf_aystar.max_search_nodes = 0; |