diff options
author | rubidium <rubidium@openttd.org> | 2008-10-14 12:07:14 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-10-14 12:07:14 +0000 |
commit | 03bef3fb5b1c25cc887d51e13fd81c7c5129028b (patch) | |
tree | d4d5851792beaab1e19c2a4398a024d44769acf1 /src | |
parent | e9f5a19544f43962135caa54edac0e6364318ea2 (diff) | |
download | openttd-03bef3fb5b1c25cc887d51e13fd81c7c5129028b.tar.xz |
(svn r14463) -Fix [FS#2348]: small possible chance of desync due to sorting on pointer instead of by (station) index (PhilSophus)
Diffstat (limited to 'src')
-rw-r--r-- | src/oldpool.h | 17 | ||||
-rw-r--r-- | src/station_func.h | 3 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/oldpool.h b/src/oldpool.h index d66a3a576..457e5327d 100644 --- a/src/oldpool.h +++ b/src/oldpool.h @@ -155,6 +155,23 @@ static void PoolCleanBlock(uint start_item, uint end_item) } } +/** + * Template providing a predicate to allow STL containers of + * pointers to pool items to be sorted by index. + */ +template <typename T> +struct PoolItemIndexLess { + /** + * The actual comparator. + * @param lhs the left hand side of the comparison. + * @param rhs the right hand side of the comparison. + * @return true if lhs' index is less than rhs' index. + */ + bool operator()(const T *lhs, const T *rhs) const + { + return lhs->index < rhs->index; + } +}; /** * Generalization for all pool items that are saved in the savegame. diff --git a/src/station_func.h b/src/station_func.h index 5493f4e5a..12f045d15 100644 --- a/src/station_func.h +++ b/src/station_func.h @@ -7,6 +7,7 @@ #include "station_type.h" #include "sprite.h" +#include "oldpool.h" #include "rail_type.h" #include "road_type.h" #include "tile_type.h" @@ -17,7 +18,7 @@ void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint radius); /** A set of stations (\c const \c Station* ) */ -typedef std::set<Station*> StationSet; +typedef std::set<Station*, PoolItemIndexLess<Station> > StationSet; StationSet FindStationsAroundIndustryTile(TileIndex tile, int w, int h); |