summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-30 12:10:32 +0000
committerrubidium <rubidium@openttd.org>2007-08-30 12:10:32 +0000
commitac5fde61fb03059daee4b505dcaad84f21b93857 (patch)
treec8679d0c316bba5d975c7330ede11fe6356b4cb6 /src
parenta407d53d1b2a329a5ae747ea83d4652427cc6c8a (diff)
downloadopenttd-ac5fde61fb03059daee4b505dcaad84f21b93857.tar.xz
(svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
Diffstat (limited to 'src')
-rw-r--r--src/cargopacket.cpp10
-rw-r--r--src/cargopacket.h18
-rw-r--r--src/station_cmd.cpp43
3 files changed, 25 insertions, 46 deletions
diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp
index 94adb4eaf..a09a978a1 100644
--- a/src/cargopacket.cpp
+++ b/src/cargopacket.cpp
@@ -16,9 +16,6 @@ void InitializeCargoPackets()
/* Clean the cargo packet pool and create 1 block in it */
_CargoPacket_pool.CleanPool();
_CargoPacket_pool.AddBlockToPool();
-
- /* Check whether our &cargolist == &cargolist.packets "hack" works */
- CargoList::AssertOnWrongPacketOffset();
}
CargoPacket::CargoPacket(StationID source, uint16 count)
@@ -87,13 +84,6 @@ extern const ChunkHandler _cargopacket_chunk_handlers[] = {
*
*/
-/* static */ void CargoList::AssertOnWrongPacketOffset()
-{
- CargoList cl;
- if ((void*)&cl != (void*)cl.Packets()) NOT_REACHED();
-}
-
-
CargoList::~CargoList()
{
while (!packets.empty()) {
diff --git a/src/cargopacket.h b/src/cargopacket.h
index c7948b579..2dacb7bc2 100644
--- a/src/cargopacket.h
+++ b/src/cargopacket.h
@@ -67,6 +67,8 @@ struct CargoPacket : PoolItem<CargoPacket, CargoPacketID, &_CargoPacket_pool> {
*/
#define FOR_ALL_CARGOPACKETS(cp) FOR_ALL_CARGOPACKETS_FROM(cp, 0)
+extern void SaveLoad_STNS(Station *st);
+
/**
* Simple collection class for a list of cargo packets
*/
@@ -93,21 +95,7 @@ private:
uint days_in_transit; ///< Cache for the number of days in transit
public:
- /**
- * Needed for an ugly hack:
- * - vehicles and stations need to store cargo lists, so they use CargoList as container
- * - this internals of the container should be protected, e.g. private (or protected) by C++
- * - for saving/loading we need to pass pointer to objects
- * -> so *if* the pointer to the cargo list is the same as the pointer to the packet list
- * encapsulated in the CargoList, we can just pass the CargoList as "offset".
- * Normally we would then just add the offset of the packets variable within the cargo list
- * but that is not possible because the variable is private. Furthermore we are not sure
- * that this works on all platforms, we need to check whether the offset is actually 0.
- * This cannot be done compile time, because the variable is private. So we need to write
- * a function that does actually check the offset runtime and call it somewhere where it
- * is always called but it should not be called often.
- */
- static void AssertOnWrongPacketOffset();
+ friend void SaveLoad_STNS(Station *st);
/** Create the cargo list */
CargoList() { this->InvalidateCache(); }
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index d27e7a667..44bf64bf1 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2977,25 +2977,6 @@ static uint32 _cargo_source_xy;
static uint16 _cargo_days;
static Money _cargo_feeder_share;
-static const SaveLoad _goods_desc[] = {
- SLEG_CONDVAR( _waiting_acceptance, SLE_UINT16, 0, 67),
- SLE_CONDVAR(GoodsEntry, acceptance_pickup, SLE_UINT8, 68, SL_MAX_VERSION),
- SLE_CONDNULL(2, 51, 67),
- SLE_VAR(GoodsEntry, days_since_pickup, SLE_UINT8),
- SLE_VAR(GoodsEntry, rating, SLE_UINT8),
- SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6),
- SLEG_CONDVAR( _cargo_source, SLE_UINT16, 7, 67),
- SLEG_CONDVAR( _cargo_source_xy, SLE_UINT32, 44, 67),
- SLEG_CONDVAR( _cargo_days, SLE_UINT8, 0, 67),
- SLE_VAR(GoodsEntry, last_speed, SLE_UINT8),
- SLE_VAR(GoodsEntry, last_age, SLE_UINT8),
- SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, 14, 64),
- SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, 65, 67),
- SLE_CONDLST(GoodsEntry, cargo, REF_CARGO_PACKET, 68, SL_MAX_VERSION),
-
- SLE_END()
-};
-
static const SaveLoad _station_speclist_desc[] = {
SLE_CONDVAR(StationSpecList, grfid, SLE_UINT32, 27, SL_MAX_VERSION),
SLE_CONDVAR(StationSpecList, localidx, SLE_UINT8, 27, SL_MAX_VERSION),
@@ -3004,8 +2985,28 @@ static const SaveLoad _station_speclist_desc[] = {
};
-static void SaveLoad_STNS(Station *st)
-{
+void SaveLoad_STNS(Station *st)
+{
+ static const SaveLoad _goods_desc[] = {
+ SLEG_CONDVAR( _waiting_acceptance, SLE_UINT16, 0, 67),
+ SLE_CONDVAR(GoodsEntry, acceptance_pickup, SLE_UINT8, 68, SL_MAX_VERSION),
+ SLE_CONDNULL(2, 51, 67),
+ SLE_VAR(GoodsEntry, days_since_pickup, SLE_UINT8),
+ SLE_VAR(GoodsEntry, rating, SLE_UINT8),
+ SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6),
+ SLEG_CONDVAR( _cargo_source, SLE_UINT16, 7, 67),
+ SLEG_CONDVAR( _cargo_source_xy, SLE_UINT32, 44, 67),
+ SLEG_CONDVAR( _cargo_days, SLE_UINT8, 0, 67),
+ SLE_VAR(GoodsEntry, last_speed, SLE_UINT8),
+ SLE_VAR(GoodsEntry, last_age, SLE_UINT8),
+ SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, 14, 64),
+ SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, 65, 67),
+ SLE_CONDLST(GoodsEntry, cargo.packets, REF_CARGO_PACKET, 68, SL_MAX_VERSION),
+
+ SLE_END()
+};
+
+
SlObject(st, _station_desc);
_waiting_acceptance = 0;