Mercurial > hg > openttd
changeset 13848:a47ef53cafb4 draft
(svn r18377) -Codechange: add 'cache' of the tile area of truck and bus stops.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 02 Dec 2009 16:20:44 +0000 |
parents | 701d8d247a50 |
children | d66e7acda8fa |
files | src/saveload/station_sl.cpp src/station.cpp src/station_base.h src/station_cmd.cpp src/station_type.h |
diffstat | 5 files changed, 75 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -98,6 +98,12 @@ st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx, NULL); } + if (Station::IsExpected(st)) { + Station *sta = Station::From(st); + for (const RoadStop *rs = sta->bus_stops; rs != NULL; rs = rs->next) sta->bus_station.Add(rs->xy); + for (const RoadStop *rs = sta->truck_stops; rs != NULL; rs = rs->next) sta->truck_station.Add(rs->xy); + } + StationUpdateAnimTriggers(st); } }
--- a/src/station.cpp +++ b/src/station.cpp @@ -38,6 +38,8 @@ Station::Station(TileIndex tile) : SpecializedStation<Station, false>(tile), + bus_station(INVALID_TILE, 0, 0), + truck_station(INVALID_TILE, 0, 0), airport_tile(INVALID_TILE), dock_tile(INVALID_TILE), indtype(IT_INVALID), @@ -511,6 +513,33 @@ this->h = ey - sy + 1; } +void TileArea::Add(TileIndex to_add) +{ + if (this->tile == INVALID_TILE) { + this->tile = to_add; + this->w = 1; + this->h = 1; + return; + } + + uint sx = TileX(this->tile); + uint sy = TileY(this->tile); + uint ex = sx + this->w - 1; + uint ey = sy + this->h - 1; + + uint ax = TileX(to_add); + uint ay = TileY(to_add); + + sx = min(ax, sx); + sy = min(ay, sy); + ex = max(ax, ex); + ey = max(ay, ey); + + this->tile = TileXY(sx, sy); + this->w = ex - sx + 1; + this->h = ey - sy + 1; +} + void InitializeStations() {
--- a/src/station_base.h +++ b/src/station_base.h @@ -67,7 +67,10 @@ } RoadStop *bus_stops; ///< All the road stops + TileArea bus_station; ///< Tile area the bus 'station' part covers RoadStop *truck_stops; ///< All the truck stops + TileArea truck_station; ///< Tile area the truck 'station' part covers + TileIndex airport_tile; ///< The location of the airport TileIndex dock_tile; ///< The location of the dock
--- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -397,12 +397,12 @@ return; case STATION_TRUCK: - ta->tile = this->truck_stops != NULL ? this->truck_stops->xy : INVALID_TILE; - break; + *ta = this->truck_station; + return; case STATION_BUS: - ta->tile = this->bus_stops != NULL ? this->bus_stops->xy : INVALID_TILE; - break; + *ta = this->bus_station; + return; case STATION_DOCK: case STATION_OILRIG: @@ -1212,7 +1212,7 @@ } } } else { - ta.tile = INVALID_TILE; + ta.Clear(); } st->train_station = ta; @@ -1427,9 +1427,7 @@ if (flags & DC_EXEC) { st->rect.AfterRemoveRect(st, st->train_station.tile, st->train_station.w, st->train_station.h); - st->train_station.tile = INVALID_TILE; - st->train_station.w = 0; - st->train_station.h = 0; + st->train_station.Clear(); st->facilities &= ~FACIL_TRAIN; @@ -1626,6 +1624,12 @@ RoadStop **currstop = FindRoadStopSpot(type, st); *currstop = road_stop; + if (type) { + st->truck_station.Add(tile); + } else { + st->bus_station.Add(tile); + } + /* initialize an empty station */ st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, tile); @@ -1735,6 +1739,15 @@ st->UpdateVirtCoord(); st->RecomputeIndustriesNear(); DeleteStationIfEmpty(st); + + /* Update the tile area of the truck/bus stop */ + if (is_truck) { + st->truck_station.Clear(); + for (const RoadStop *rs = st->truck_stops; rs != NULL; rs = rs->next) st->truck_station.Add(rs->xy); + } else { + st->bus_station.Clear(); + for (const RoadStop *rs = st->bus_stops; rs != NULL; rs = rs->next) st->bus_station.Add(rs->xy); + } } return CommandCost(EXPENSES_CONSTRUCTION, _price[is_truck ? PR_CLEAR_STATION_TRUCK : PR_CLEAR_STATION_BUS]);
--- a/src/station_type.h +++ b/src/station_type.h @@ -114,6 +114,22 @@ TileIndex tile; ///< The base tile of the area uint8 w; ///< The width of the area uint8 h; ///< The height of the area + + /** + * Add a single tile to a tile area; enlarge if needed. + * @param to_add The tile to add + */ + void Add(TileIndex to_add); + + /** + * Clears the 'tile area', i.e. make the tile invalid. + */ + void Clear() + { + this->tile = INVALID_TILE; + this->w = 0; + this->h = 0; + } }; /** List of stations */