summaryrefslogtreecommitdiff
path: root/src/station.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-02 08:47:56 +0000
committerrubidium <rubidium@openttd.org>2007-08-02 08:47:56 +0000
commit9378e5fd3845935b0ec00be40a2de8a0748ab7d0 (patch)
tree3e62b54a68ddd881fdf9a38f773673dd2d809a09 /src/station.cpp
parentaa78685c99dc1cd2fe28a05ba55eb719e12f4029 (diff)
downloadopenttd-9378e5fd3845935b0ec00be40a2de8a0748ab7d0.tar.xz
(svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
Diffstat (limited to 'src/station.cpp')
-rw-r--r--src/station.cpp105
1 files changed, 2 insertions, 103 deletions
diff --git a/src/station.cpp b/src/station.cpp
index 0f7db16ff..4633f1d18 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -91,29 +91,6 @@ void Station::QuickFree()
free(this->speclist);
}
-void *Station::operator new(size_t size)
-{
- Station *st = AllocateRaw();
- return st;
-}
-
-void *Station::operator new(size_t size, int st_idx)
-{
- if (!AddBlockIfNeeded(&_Station_pool, st_idx))
- error("Stations: failed loading savegame: too many stations");
-
- Station *st = GetStation(st_idx);
- return st;
-}
-
-void Station::operator delete(void *p)
-{
-}
-
-void Station::operator delete(void *p, int st_idx)
-{
-}
-
/** Called when new facility is built on the station. If it is the first facility
* it initializes also 'xy' and 'random_bits' members */
void Station::AddFacility(byte new_facility_bit, TileIndex facil_xy)
@@ -176,30 +153,6 @@ bool Station::TileBelongsToRailStation(TileIndex tile) const
return IsTileType(tile, MP_STATION) && GetStationIndex(tile) == index && IsRailwayStation(tile);
}
-/*static*/ Station *Station::AllocateRaw()
-{
- Station *st = NULL;
-
- /* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
- * TODO - This is just a temporary stage, this will be removed. */
- for (st = GetStation(0); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) {
- if (!st->IsValid()) {
- StationID index = st->index;
-
- memset(st, 0, sizeof(Station));
- st->index = index;
- return st;
- }
- }
-
- /* Check if we can add a block to the pool */
- if (AddBlockToPool(&_Station_pool)) return AllocateRaw();
-
- _error_message = STR_3008_TOO_MANY_STATIONS_LOADING;
- return NULL;
-}
-
-
/** Obtain the length of a platform
* @pre tile must be a railway station tile
* @param tile A tile that contains the platform in question
@@ -426,36 +379,6 @@ StationRect& StationRect::operator = (Rect src)
/* RoadStop implementation */
/************************************************************************/
-/** Allocates a new RoadStop onto the pool, or recycles an unsed one
- * @return a pointer to the new roadstop
- */
-void *RoadStop::operator new(size_t size)
-{
- RoadStop *rs = AllocateRaw();
- return rs;
-}
-
-/** Gets a RoadStop with a given index and allocates it when needed
- * @return a pointer to the roadstop
- */
-void *RoadStop::operator new(size_t size, int index)
-{
- if (!AddBlockIfNeeded(&_RoadStop_pool, index)) {
- error("RoadStops: failed loading savegame: too many RoadStops");
- }
-
- RoadStop *rs = GetRoadStop(index);
- return rs;
-}
-
-void RoadStop::operator delete(void *p)
-{
-}
-
-void RoadStop::operator delete(void *p, int index)
-{
-}
-
/** Initializes a RoadStop */
RoadStop::RoadStop(TileIndex tile) :
xy(tile),
@@ -483,37 +406,13 @@ RoadStop::~RoadStop()
DEBUG(ms, cDebugCtorLevel , "I- at %d[0x%x]", xy, xy);
- xy = INVALID_TILE;
-}
-
-/** Low-level function for allocating a RoadStop on the pool */
-RoadStop *RoadStop::AllocateRaw()
-{
- RoadStop *rs;
-
- /* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
- * TODO - This is just a temporary stage, this will be removed. */
- for (rs = GetRoadStop(0); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) {
- if (!rs->IsValid()) {
- RoadStopID index = rs->index;
-
- memset(rs, 0, sizeof(*rs));
- rs->index = index;
-
- return rs;
- }
- }
-
- /* Check if we can add a block to the pool */
- if (AddBlockToPool(&_RoadStop_pool)) return AllocateRaw();
-
- return NULL;
+ xy = 0;
}
/** Determines whether a RoadStop is a valid (i.e. existing) one */
bool RoadStop::IsValid() const
{
- return xy != INVALID_TILE;
+ return xy != 0;
}
/** Checks whether there is a free bay in this road stop */