Chunnel: Increase tunnel pool size, make tunnel IDs 32 bit.

Add lookup mechanism for tunnel IDs which don't fit in 16 bits in M2.
This commit is contained in:
Jonathan G Rennison
2017-03-04 23:49:55 +00:00
parent 87142ed840
commit afd8c6b867
4 changed files with 54 additions and 6 deletions

View File

@@ -13,6 +13,7 @@
#include "tunnelbridge_map.h"
#include "core/pool_func.hpp"
#include <unordered_map>
#include "safeguards.h"
@@ -20,12 +21,45 @@
TunnelPool _tunnel_pool("Tunnel");
INSTANTIATE_POOL_METHODS(Tunnel)
static std::unordered_map<TileIndex, TunnelID> tunnel_tile_index_map;
/**
* Clean up a tunnel tile
*/
Tunnel::~Tunnel()
{
if (CleaningPool()) return;
if (this->index >= TUNNEL_ID_MAP_LOOKUP) {
tunnel_tile_index_map.erase(this->tile_n);
tunnel_tile_index_map.erase(this->tile_s);
}
}
/**
* Update tunnel indexes
*/
void Tunnel::UpdateIndexes()
{
if (this->index >= TUNNEL_ID_MAP_LOOKUP) {
tunnel_tile_index_map[this->tile_n] = this->index;
tunnel_tile_index_map[this->tile_s] = this->index;
}
}
/**
* Tunnel pool is about to be cleaned
*/
void Tunnel::PreCleanPool()
{
tunnel_tile_index_map.clear();
}
TunnelID GetTunnelIndexByLookup(TileIndex t)
{
auto iter = tunnel_tile_index_map.find(t);
assert_msg(iter != tunnel_tile_index_map.end(), "tile: 0x%X", t);
return iter->second;
}
/**