Remove unused hash functions and start the road building from the map center
This commit is contained in:

committed by
Jonathan G Rennison

parent
4542410b41
commit
8d584990aa
@@ -1241,17 +1241,6 @@ static void River_FoundEndNode(AyStar *aystar, OpenListNode *current)
|
|||||||
|
|
||||||
static const uint RIVER_HASH_SIZE = 8; ///< The number of bits the hash for river finding should have.
|
static const uint RIVER_HASH_SIZE = 8; ///< The number of bits the hash for river finding should have.
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple hash function for river tiles to be used by AyStar.
|
|
||||||
* @param tile The tile to hash.
|
|
||||||
* @param dir The unused direction.
|
|
||||||
* @return The hash for the tile.
|
|
||||||
*/
|
|
||||||
static uint River_Hash(uint tile, uint dir)
|
|
||||||
{
|
|
||||||
return GB(TileHash(TileX(tile), TileY(tile)), 0, RIVER_HASH_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actually build the river between the begin and end tiles using AyStar.
|
* Actually build the river between the begin and end tiles using AyStar.
|
||||||
* @param begin The begin of the river.
|
* @param begin The begin of the river.
|
||||||
@@ -1267,7 +1256,7 @@ static void BuildRiver(TileIndex begin, TileIndex end)
|
|||||||
finder.FoundEndNode = River_FoundEndNode;
|
finder.FoundEndNode = River_FoundEndNode;
|
||||||
finder.user_target = &end;
|
finder.user_target = &end;
|
||||||
|
|
||||||
finder.Init(River_Hash, 1 << RIVER_HASH_SIZE);
|
finder.Init(1 << RIVER_HASH_SIZE);
|
||||||
|
|
||||||
AyStarNode start;
|
AyStarNode start;
|
||||||
start.tile = begin;
|
start.tile = begin;
|
||||||
|
@@ -310,7 +310,7 @@ void AyStar::AddStartNode(AyStarNode *start_node, uint g)
|
|||||||
* Initialize an #AyStar. You should fill all appropriate fields before
|
* Initialize an #AyStar. You should fill all appropriate fields before
|
||||||
* calling #Init (see the declaration of #AyStar for which fields are internal).
|
* calling #Init (see the declaration of #AyStar for which fields are internal).
|
||||||
*/
|
*/
|
||||||
void AyStar::Init(Hash_HashProc hash, uint num_buckets)
|
void AyStar::Init(uint num_buckets)
|
||||||
{
|
{
|
||||||
MemSetT(&neighbours, 0);
|
MemSetT(&neighbours, 0);
|
||||||
MemSetT(&openlist_queue, 0);
|
MemSetT(&openlist_queue, 0);
|
||||||
|
@@ -156,7 +156,7 @@ struct AyStar {
|
|||||||
AyStarNode neighbours[12];
|
AyStarNode neighbours[12];
|
||||||
byte num_neighbours;
|
byte num_neighbours;
|
||||||
|
|
||||||
void Init(Hash_HashProc hash, uint num_buckets);
|
void Init(uint num_buckets);
|
||||||
|
|
||||||
/* These will contain the methods for manipulating the AyStar. Only
|
/* These will contain the methods for manipulating the AyStar. Only
|
||||||
* Main() should be called externally */
|
* Main() should be called externally */
|
||||||
|
@@ -131,24 +131,6 @@ static uint NPFDistanceTrack(TileIndex t0, TileIndex t1)
|
|||||||
return diagTracks * NPF_TILE_LENGTH + straightTracks * NPF_TILE_LENGTH * STRAIGHT_TRACK_LENGTH;
|
return diagTracks * NPF_TILE_LENGTH + straightTracks * NPF_TILE_LENGTH * STRAIGHT_TRACK_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates a hash value for use in the NPF.
|
|
||||||
* @param key1 The TileIndex of the tile to hash
|
|
||||||
* @param key2 The Trackdir of the track on the tile.
|
|
||||||
*
|
|
||||||
* @todo Think of a better hash.
|
|
||||||
*/
|
|
||||||
static 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;
|
|
||||||
|
|
||||||
assert(IsValidTrackdir((Trackdir)key2));
|
|
||||||
assert(IsValidTile(key1));
|
|
||||||
return ((part1 << NPF_HASH_HALFBITS | part2) + (NPF_HASH_SIZE * key2 / TRACKDIR_END)) % NPF_HASH_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32 NPFCalcZero(AyStar *as, AyStarNode *current, OpenListNode *parent)
|
static int32 NPFCalcZero(AyStar *as, AyStarNode *current, OpenListNode *parent)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1127,7 +1109,7 @@ void InitializeNPF()
|
|||||||
static bool first_init = true;
|
static bool first_init = true;
|
||||||
if (first_init) {
|
if (first_init) {
|
||||||
first_init = false;
|
first_init = false;
|
||||||
_npf_aystar.Init(NPFHash, NPF_HASH_SIZE);
|
_npf_aystar.Init(NPF_HASH_SIZE);
|
||||||
} else {
|
} else {
|
||||||
_npf_aystar.Clear();
|
_npf_aystar.Clear();
|
||||||
}
|
}
|
||||||
|
15
src/road.cpp
15
src/road.cpp
@@ -252,17 +252,6 @@ static bool _has_tunnel_in_path;
|
|||||||
static RoadType _public_road_type;
|
static RoadType _public_road_type;
|
||||||
static const uint _public_road_hash_size = 8U; ///< The number of bits the hash for river finding should have.
|
static const uint _public_road_hash_size = 8U; ///< The number of bits the hash for river finding should have.
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple hash function for public road tiles to be used by AyStar.
|
|
||||||
* @param tile The tile to hash.
|
|
||||||
* @param dir The unused direction.
|
|
||||||
* @return The hash for the tile.
|
|
||||||
*/
|
|
||||||
static uint PublicRoad_Hash(uint tile, uint dir)
|
|
||||||
{
|
|
||||||
return GB(TileHash(TileX(tile), TileY(tile)), 0, _public_road_hash_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int32 BASE_COST = 1; // Cost for utilizing an existing road, bridge, or tunnel.
|
static const int32 BASE_COST = 1; // Cost for utilizing an existing road, bridge, or tunnel.
|
||||||
static const int32 COST_FOR_NEW_ROAD = 10; // Cost for building a new road.
|
static const int32 COST_FOR_NEW_ROAD = 10; // Cost for building a new road.
|
||||||
static const int32 COST_FOR_SLOPE = 5; // Additional cost if the road heads up or down a slope.
|
static const int32 COST_FOR_SLOPE = 5; // Additional cost if the road heads up or down a slope.
|
||||||
@@ -722,7 +711,7 @@ bool FindPath(AyStar& finder, const TileIndex from, TileIndex to)
|
|||||||
finder.user_target = &(to);
|
finder.user_target = &(to);
|
||||||
finder.max_search_nodes = 1 << 20; // 1,048,576
|
finder.max_search_nodes = 1 << 20; // 1,048,576
|
||||||
|
|
||||||
finder.Init(PublicRoad_Hash, 1 << _public_road_hash_size);
|
finder.Init(1 << _public_road_hash_size);
|
||||||
|
|
||||||
_has_tunnel_in_path = false;
|
_has_tunnel_in_path = false;
|
||||||
|
|
||||||
@@ -773,6 +762,8 @@ void GeneratePublicRoads()
|
|||||||
vector<pair<uint, shared_ptr<vector<TileIndex>>>> town_networks;
|
vector<pair<uint, shared_ptr<vector<TileIndex>>>> town_networks;
|
||||||
unordered_map<TileIndex, shared_ptr<vector<TileIndex>>> towns_reachable_networks;
|
unordered_map<TileIndex, shared_ptr<vector<TileIndex>>> towns_reachable_networks;
|
||||||
|
|
||||||
|
sort(towns.begin(), towns.end(), [&](auto a, auto b) { return DistanceFromEdge(a) > DistanceFromEdge(b); });
|
||||||
|
|
||||||
TileIndex main_town = *towns.begin();
|
TileIndex main_town = *towns.begin();
|
||||||
towns.erase(towns.begin());
|
towns.erase(towns.begin());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user