Mercurial > hg > openttd
changeset 8784:6280c0d48a6d draft
(svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 30 Mar 2008 23:24:18 +0000 (2008-03-30) |
parents | c50f7ac6de22 |
children | 2a8950a812dc |
files | src/ai/default/default.cpp src/ai/trolly/trolly.cpp src/aircraft_cmd.cpp src/aircraft_gui.cpp src/airport_gui.cpp src/autoreplace_cmd.cpp src/depot.cpp src/depot_gui.cpp src/group_cmd.cpp src/newgrf_text.cpp src/order.h src/order_base.h src/order_cmd.cpp src/order_func.h src/order_gui.cpp src/roadveh_cmd.cpp src/roadveh_gui.cpp src/ship_cmd.cpp src/ship_gui.cpp src/sound/win32_s.cpp src/station.cpp src/train_cmd.cpp src/train_gui.cpp src/vehicle.cpp src/vehicle_base.h src/vehicle_gui.cpp src/waypoint.cpp |
diffstat | 27 files changed, 194 insertions(+), 171 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -32,6 +32,7 @@ #include "../../settings_type.h" #include "default.h" #include "../../tunnelbridge.h" +#include "../../order_func.h" #include "../../table/ai_rail.h"
--- a/src/ai/trolly/trolly.cpp +++ b/src/ai/trolly/trolly.cpp @@ -34,7 +34,6 @@ #include "../../vehicle_func.h" #include "../../date_func.h" #include "../ai.h" -#include "../../order.h" #include "../../player_base.h" #include "../../player_func.h"
--- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -36,6 +36,7 @@ #include "gfx_func.h" #include "player_func.h" #include "settings_type.h" +#include "order_func.h" #include "table/strings.h" #include "table/sprites.h"
--- a/src/aircraft_gui.cpp +++ b/src/aircraft_gui.cpp @@ -14,6 +14,7 @@ #include "strings_func.h" #include "vehicle_func.h" #include "gfx_func.h" +#include "order_func.h" #include "table/sprites.h" #include "table/strings.h"
--- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -18,6 +18,7 @@ #include "viewport_func.h" #include "gfx_func.h" #include "player_func.h" +#include "order_func.h" #include "table/sprites.h" #include "table/strings.h"
--- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -14,7 +14,6 @@ #include "aircraft.h" #include "cargotype.h" #include "group.h" -#include "order.h" #include "strings_func.h" #include "command_func.h" #include "vehicle_func.h"
--- a/src/depot.cpp +++ b/src/depot.cpp @@ -7,7 +7,7 @@ #include "depot.h" #include "landscape.h" #include "saveload.h" -#include "order.h" +#include "order_func.h" #include "window_func.h" #include "table/strings.h"
--- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -22,6 +22,7 @@ #include "window_func.h" #include "vehicle_func.h" #include "player_func.h" +#include "order_func.h" #include "table/strings.h" #include "table/sprites.h"
--- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -21,6 +21,7 @@ #include "autoreplace_func.h" #include "string_func.h" #include "player_func.h" +#include "order_func.h" #include "table/strings.h"
--- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -642,7 +642,7 @@ case SCC_NEWGRF_PRINT_SIGNED_WORD: case SCC_NEWGRF_PRINT_SIGNED_BYTE: case SCC_NEWGRF_PRINT_UNSIGNED_WORD: - return SCC_NUM; + return SCC_COMMA; case SCC_NEWGRF_PRINT_DWORD_CURRENCY: case SCC_NEWGRF_PRINT_QWORD_CURRENCY:
deleted file mode 100644 --- a/src/order.h +++ /dev/null @@ -1,161 +0,0 @@ -/* $Id$ */ - -/** @file order.h */ - -#ifndef ORDER_H -#define ORDER_H - -#include "order_type.h" -#include "oldpool.h" -#include "core/bitmath_func.hpp" -#include "cargo_type.h" -#include "vehicle_type.h" -#include "tile_type.h" -#include "date_type.h" -#include "group_type.h" - -DECLARE_OLD_POOL(Order, Order, 6, 1000) - -/* If you change this, keep in mind that it is saved on 3 places: - * - Load_ORDR, all the global orders - * - Vehicle -> current_order - * - REF_ORDER (all REFs are currently limited to 16 bits!!) - */ -struct Order : PoolItem<Order, OrderID, &_Order_pool> { - Order *next; ///< Pointer to next order. If NULL, end of list - - OrderTypeByte type; - uint8 flags; - DestinationID dest; ///< The destionation of the order. - - CargoID refit_cargo; // Refit CargoID - byte refit_subtype; // Refit subtype - - uint16 wait_time; ///< How long in ticks to wait at the destination. - uint16 travel_time; ///< How long in ticks the journey to this destination should take. - - Order() : refit_cargo(CT_NO_REFIT) {} - ~Order() { this->type = OT_NOTHING; } - - /** - * Check if a Order really exists. - */ - inline bool IsValid() const { return this->type != OT_NOTHING; } - - void Free(); - void FreeChain(); -}; - -struct BackuppedOrders { - BackuppedOrders() : order(NULL), name(NULL) { } - ~BackuppedOrders() { free(order); free(name); } - - VehicleID clone; - VehicleOrderID orderindex; - GroupID group; - Order *order; - uint16 service_interval; - char *name; -}; - -extern TileIndex _backup_orders_tile; -extern BackuppedOrders _backup_orders_data; - -static inline VehicleOrderID GetMaxOrderIndex() -{ - /* TODO - This isn't the real content of the function, but - * with the new pool-system this will be replaced with one that - * _really_ returns the highest index. Now it just returns - * the next safe value we are sure about everything is below. - */ - return GetOrderPoolSize() - 1; -} - -static inline VehicleOrderID GetNumOrders() -{ - return GetOrderPoolSize(); -} - -inline void Order::Free() -{ - this->type = OT_NOTHING; - this->flags = 0; - this->dest = 0; - this->next = NULL; -} - -inline void Order::FreeChain() -{ - if (next != NULL) next->FreeChain(); - delete this; -} - -#define FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) if (order->IsValid()) -#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0) - - -#define FOR_VEHICLE_ORDERS(v, order) for (order = v->orders; order != NULL; order = order->next) - -static inline bool HasOrderPoolFree(uint amount) -{ - const Order *order; - - /* There is always room if not all blocks in the pool are reserved */ - if (_Order_pool.CanAllocateMoreBlocks()) return true; - - FOR_ALL_ORDERS(order) if (!order->IsValid() && --amount == 0) return true; - - return false; -} - - -/* Pack and unpack routines */ - -static inline uint32 PackOrder(const Order *order) -{ - return order->dest << 16 | order->flags << 8 | order->type; -} - -static inline Order UnpackOrder(uint32 packed) -{ - Order order; - order.type = (OrderType)GB(packed, 0, 8); - order.flags = GB(packed, 8, 8); - order.dest = GB(packed, 16, 16); - order.next = NULL; - order.index = 0; // avoid compiler warning - order.refit_cargo = CT_NO_REFIT; - order.refit_subtype = 0; - order.wait_time = 0; - order.travel_time = 0; - return order; -} - -/* Functions */ -void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order = &_backup_orders_data); -void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *order = &_backup_orders_data); -void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination); -void InvalidateVehicleOrder(const Vehicle *v); -bool VehicleHasDepotOrders(const Vehicle *v); -void CheckOrders(const Vehicle*); -void DeleteVehicleOrders(Vehicle *v); -void AssignOrder(Order *order, Order data); -bool CheckForValidOrders(const Vehicle* v); - -Order UnpackOldOrder(uint16 packed); - -#define MIN_SERVINT_PERCENT 5 -#define MAX_SERVINT_PERCENT 90 -#define MIN_SERVINT_DAYS 30 -#define MAX_SERVINT_DAYS 800 - -/** - * Get the service interval domain. - * Get the new proposed service interval for the vehicle is indeed, clamped - * within the given bounds. @see MIN_SERVINT_PERCENT ,etc. - * @param index proposed service interval - * @return service interval - */ -Date GetServiceIntervalClamped(uint index); - -#endif /* ORDER_H */
new file mode 100644 --- /dev/null +++ b/src/order_base.h @@ -0,0 +1,118 @@ +/* $Id$ */ + +/** @file order_base.h */ + +#ifndef ORDER_BASE_H +#define ORDER_BASE_H + +#include "order_type.h" +#include "oldpool.h" +#include "core/bitmath_func.hpp" +#include "cargo_type.h" + +DECLARE_OLD_POOL(Order, Order, 6, 1000) + +/* If you change this, keep in mind that it is saved on 3 places: + * - Load_ORDR, all the global orders + * - Vehicle -> current_order + * - REF_ORDER (all REFs are currently limited to 16 bits!!) + */ +struct Order : PoolItem<Order, OrderID, &_Order_pool> { + Order *next; ///< Pointer to next order. If NULL, end of list + + OrderTypeByte type; + uint8 flags; + DestinationID dest; ///< The destionation of the order. + + CargoID refit_cargo; // Refit CargoID + byte refit_subtype; // Refit subtype + + uint16 wait_time; ///< How long in ticks to wait at the destination. + uint16 travel_time; ///< How long in ticks the journey to this destination should take. + + Order() : refit_cargo(CT_NO_REFIT) {} + ~Order() { this->type = OT_NOTHING; } + + /** + * Check if a Order really exists. + */ + inline bool IsValid() const { return this->type != OT_NOTHING; } + + void Free(); + void FreeChain(); +}; + +static inline VehicleOrderID GetMaxOrderIndex() +{ + /* TODO - This isn't the real content of the function, but + * with the new pool-system this will be replaced with one that + * _really_ returns the highest index. Now it just returns + * the next safe value we are sure about everything is below. + */ + return GetOrderPoolSize() - 1; +} + +static inline VehicleOrderID GetNumOrders() +{ + return GetOrderPoolSize(); +} + +inline void Order::Free() +{ + this->type = OT_NOTHING; + this->flags = 0; + this->dest = 0; + this->next = NULL; +} + +inline void Order::FreeChain() +{ + if (next != NULL) next->FreeChain(); + delete this; +} + +#define FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) if (order->IsValid()) +#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0) + + +#define FOR_VEHICLE_ORDERS(v, order) for (order = v->orders; order != NULL; order = order->next) + +static inline bool HasOrderPoolFree(uint amount) +{ + const Order *order; + + /* There is always room if not all blocks in the pool are reserved */ + if (_Order_pool.CanAllocateMoreBlocks()) return true; + + FOR_ALL_ORDERS(order) if (!order->IsValid() && --amount == 0) return true; + + return false; +} + + +/* Pack and unpack routines */ + +static inline uint32 PackOrder(const Order *order) +{ + return order->dest << 16 | order->flags << 8 | order->type; +} + +static inline Order UnpackOrder(uint32 packed) +{ + Order order; + order.type = (OrderType)GB(packed, 0, 8); + order.flags = GB(packed, 8, 8); + order.dest = GB(packed, 16, 16); + order.next = NULL; + order.index = 0; // avoid compiler warning + order.refit_cargo = CT_NO_REFIT; + order.refit_subtype = 0; + order.wait_time = 0; + order.travel_time = 0; + return order; +} + +void AssignOrder(Order *order, Order data); +Order UnpackOldOrder(uint16 packed); + +#endif /* ORDER_H */
--- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -4,7 +4,8 @@ #include "stdafx.h" #include "openttd.h" -#include "order.h" +#include "order_base.h" +#include "order_func.h" #include "airport.h" #include "depot.h" #include "waypoint.h"
new file mode 100644 --- /dev/null +++ b/src/order_func.h @@ -0,0 +1,54 @@ +/* $Id$ */ + +/** @file order_func.h Functions related to orders. */ + +#ifndef ORDER_FUNC_H +#define ORDER_FUNC_H + +#include "order_type.h" +#include "vehicle_type.h" +#include "tile_type.h" +#include "group_type.h" +#include "date_type.h" + +struct BackuppedOrders { + BackuppedOrders() : order(NULL), name(NULL) { } + ~BackuppedOrders() { free(order); free(name); } + + VehicleID clone; + VehicleOrderID orderindex; + GroupID group; + Order *order; + uint16 service_interval; + char *name; +}; + +extern TileIndex _backup_orders_tile; +extern BackuppedOrders _backup_orders_data; + +void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order = &_backup_orders_data); +void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *order = &_backup_orders_data); + +/* Functions */ +void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination); +void InvalidateVehicleOrder(const Vehicle *v); +bool VehicleHasDepotOrders(const Vehicle *v); +void CheckOrders(const Vehicle*); +void DeleteVehicleOrders(Vehicle *v); +bool CheckForValidOrders(const Vehicle* v); + +#define MIN_SERVINT_PERCENT 5 +#define MAX_SERVINT_PERCENT 90 +#define MIN_SERVINT_DAYS 30 +#define MAX_SERVINT_DAYS 800 + +/** + * Get the service interval domain. + * Get the new proposed service interval for the vehicle is indeed, clamped + * within the given bounds. @see MIN_SERVINT_PERCENT ,etc. + * @param index proposed service interval + * @return service interval + */ +Date GetServiceIntervalClamped(uint index); + +#endif /* ORDER_FUNC_H */
--- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -20,7 +20,6 @@ #include "vehicle_gui.h" #include "timetable.h" #include "cargotype.h" -#include "order.h" #include "strings_func.h" #include "window_func.h" #include "vehicle_func.h"
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -42,6 +42,7 @@ #include "autoreplace_gui.h" #include "gfx_func.h" #include "settings_type.h" +#include "order_func.h" #include "table/strings.h"
--- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -17,6 +17,7 @@ #include "strings_func.h" #include "vehicle_func.h" #include "string_func.h" +#include "order_func.h" #include "table/sprites.h" #include "table/strings.h"
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -38,6 +38,7 @@ #include "autoreplace_gui.h" #include "gfx_func.h" #include "settings_type.h" +#include "order_func.h" #include "table/strings.h"
--- a/src/ship_gui.cpp +++ b/src/ship_gui.cpp @@ -15,6 +15,7 @@ #include "newgrf_engine.h" #include "strings_func.h" #include "vehicle_func.h" +#include "order_func.h" #include "table/strings.h" #include "table/sprites.h"
--- a/src/sound/win32_s.cpp +++ b/src/sound/win32_s.cpp @@ -59,7 +59,7 @@ wfex.nBlockAlign = (wfex.nChannels * wfex.wBitsPerSample) / 8; wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign; - _bufsize = GetDriverParamInt(parm, "bufsize", 1024); + _bufsize = GetDriverParamInt(parm, "bufsize", 2048); if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD_PTR)&waveOutProc, 0, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) return "waveOutOpen failed";
--- a/src/station.cpp +++ b/src/station.cpp @@ -30,6 +30,7 @@ #include "variables.h" #include "settings_type.h" #include "command_func.h" +#include "order_func.h" #include "table/sprites.h" #include "table/strings.h"
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -47,6 +47,7 @@ #include "autoreplace_gui.h" #include "gfx_func.h" #include "settings_type.h" +#include "order_func.h" #include "table/strings.h" #include "table/train_cmd.h"
--- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -16,6 +16,7 @@ #include "strings_func.h" #include "vehicle_func.h" #include "settings_type.h" +#include "order_func.h" #include "table/sprites.h" #include "table/strings.h"
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -34,7 +34,7 @@ #include "newgrf_engine.h" #include "newgrf_sound.h" #include "group.h" -#include "order.h" +#include "order_func.h" #include "strings_func.h" #include "zoom_func.h" #include "functions.h"
--- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -17,7 +17,7 @@ #include "date_type.h" #include "player_type.h" #include "oldpool.h" -#include "order.h" +#include "order_base.h" #include "cargopacket.h" #include "texteff.hpp" #include "group_type.h"