mirror of https://github.com/OpenTTD/OpenTTD
(svn r6980) Use the pool macros for the Order pool
parent
4cb479e083
commit
c61e0963e0
|
@ -497,7 +497,7 @@ static const OldChunks order_chunk[] = {
|
||||||
|
|
||||||
static bool LoadOldOrder(LoadgameState *ls, int num)
|
static bool LoadOldOrder(LoadgameState *ls, int num)
|
||||||
{
|
{
|
||||||
if (!AddBlockIfNeeded(&_order_pool, num))
|
if (!AddBlockIfNeeded(&_Order_pool, num))
|
||||||
error("Orders: failed loading savegame: too many orders");
|
error("Orders: failed loading savegame: too many orders");
|
||||||
|
|
||||||
if (!LoadChunk(ls, NULL, order_chunk)) return false;
|
if (!LoadChunk(ls, NULL, order_chunk)) return false;
|
||||||
|
|
|
@ -259,7 +259,7 @@ static void UnInitializeDynamicVariables(void)
|
||||||
CleanPool(&_station_pool);
|
CleanPool(&_station_pool);
|
||||||
CleanPool(&_Vehicle_pool);
|
CleanPool(&_Vehicle_pool);
|
||||||
CleanPool(&_sign_pool);
|
CleanPool(&_sign_pool);
|
||||||
CleanPool(&_order_pool);
|
CleanPool(&_Order_pool);
|
||||||
|
|
||||||
free((void*)_town_sort);
|
free((void*)_town_sort);
|
||||||
free((void*)_industry_sort);
|
free((void*)_industry_sort);
|
||||||
|
|
22
order.h
22
order.h
|
@ -107,23 +107,7 @@ typedef struct {
|
||||||
VARDEF TileIndex _backup_orders_tile;
|
VARDEF TileIndex _backup_orders_tile;
|
||||||
VARDEF BackuppedOrders _backup_orders_data[1];
|
VARDEF BackuppedOrders _backup_orders_data[1];
|
||||||
|
|
||||||
extern MemoryPool _order_pool;
|
DECLARE_POOL(Order, Order, 6, 1000)
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the pointer to the order with index 'index'
|
|
||||||
*/
|
|
||||||
static inline Order *GetOrder(OrderID index)
|
|
||||||
{
|
|
||||||
return (Order*)GetItemFromPool(&_order_pool, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current size of the OrderPool
|
|
||||||
*/
|
|
||||||
static inline uint16 GetOrderPoolSize(void)
|
|
||||||
{
|
|
||||||
return _order_pool.total_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline VehicleOrderID GetOrderArraySize(void)
|
static inline VehicleOrderID GetOrderArraySize(void)
|
||||||
{
|
{
|
||||||
|
@ -149,7 +133,7 @@ static inline void DeleteOrder(Order *o)
|
||||||
o->next = NULL;
|
o->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1 < GetOrderPoolSize()) ? GetOrder(order->index + 1) : NULL) if (IsValidOrder(order))
|
#define FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) if (IsValidOrder(order))
|
||||||
#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0)
|
#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,7 +144,7 @@ static inline bool HasOrderPoolFree(uint amount)
|
||||||
const Order *order;
|
const Order *order;
|
||||||
|
|
||||||
/* There is always room if not all blocks in the pool are reserved */
|
/* There is always room if not all blocks in the pool are reserved */
|
||||||
if (_order_pool.current_blocks < _order_pool.max_blocks)
|
if (_Order_pool.current_blocks < _Order_pool.max_blocks)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
FOR_ALL_ORDERS(order)
|
FOR_ALL_ORDERS(order)
|
||||||
|
|
19
order_cmd.c
19
order_cmd.c
|
@ -31,11 +31,10 @@ static void OrderPoolNewBlock(uint start_item)
|
||||||
|
|
||||||
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
||||||
* TODO - This is just a temporary stage, this will be removed. */
|
* TODO - This is just a temporary stage, this will be removed. */
|
||||||
for (order = GetOrder(start_item); order != NULL; order = (order->index + 1 < GetOrderPoolSize()) ? GetOrder(order->index + 1) : NULL) order->index = start_item++;
|
for (order = GetOrder(start_item); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) order->index = start_item++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the order-pool */
|
DEFINE_POOL(Order, Order, OrderPoolNewBlock, NULL)
|
||||||
MemoryPool _order_pool = { "Orders", ORDER_POOL_MAX_BLOCKS, ORDER_POOL_BLOCK_SIZE_BITS, sizeof(Order), &OrderPoolNewBlock, NULL, 0, 0, NULL };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -122,7 +121,7 @@ static Order *AllocateOrder(void)
|
||||||
|
|
||||||
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
||||||
* TODO - This is just a temporary stage, this will be removed. */
|
* TODO - This is just a temporary stage, this will be removed. */
|
||||||
for (order = GetOrder(0); order != NULL; order = (order->index + 1 < GetOrderPoolSize()) ? GetOrder(order->index + 1) : NULL) {
|
for (order = GetOrder(0); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) {
|
||||||
if (!IsValidOrder(order)) {
|
if (!IsValidOrder(order)) {
|
||||||
OrderID index = order->index;
|
OrderID index = order->index;
|
||||||
|
|
||||||
|
@ -137,7 +136,7 @@ static Order *AllocateOrder(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we can add a block to the pool */
|
/* Check if we can add a block to the pool */
|
||||||
if (AddBlockToPool(&_order_pool)) return AllocateOrder();
|
if (AddBlockToPool(&_Order_pool)) return AllocateOrder();
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1178,8 +1177,8 @@ bool CheckForValidOrders(const Vehicle* v)
|
||||||
|
|
||||||
void InitializeOrders(void)
|
void InitializeOrders(void)
|
||||||
{
|
{
|
||||||
CleanPool(&_order_pool);
|
CleanPool(&_Order_pool);
|
||||||
AddBlockToPool(&_order_pool);
|
AddBlockToPool(&_Order_pool);
|
||||||
|
|
||||||
_backup_orders_tile = 0;
|
_backup_orders_tile = 0;
|
||||||
}
|
}
|
||||||
|
@ -1227,7 +1226,7 @@ static void Load_ORDR(void)
|
||||||
SlArray(orders, len, SLE_UINT16);
|
SlArray(orders, len, SLE_UINT16);
|
||||||
|
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
if (!AddBlockIfNeeded(&_order_pool, i))
|
if (!AddBlockIfNeeded(&_Order_pool, i))
|
||||||
error("Orders: failed loading savegame: too many orders");
|
error("Orders: failed loading savegame: too many orders");
|
||||||
|
|
||||||
AssignOrder(GetOrder(i), UnpackVersion4Order(orders[i]));
|
AssignOrder(GetOrder(i), UnpackVersion4Order(orders[i]));
|
||||||
|
@ -1241,7 +1240,7 @@ static void Load_ORDR(void)
|
||||||
SlArray(orders, len, SLE_UINT32);
|
SlArray(orders, len, SLE_UINT32);
|
||||||
|
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
if (!AddBlockIfNeeded(&_order_pool, i))
|
if (!AddBlockIfNeeded(&_Order_pool, i))
|
||||||
error("Orders: failed loading savegame: too many orders");
|
error("Orders: failed loading savegame: too many orders");
|
||||||
|
|
||||||
AssignOrder(GetOrder(i), UnpackOrder(orders[i]));
|
AssignOrder(GetOrder(i), UnpackOrder(orders[i]));
|
||||||
|
@ -1262,7 +1261,7 @@ static void Load_ORDR(void)
|
||||||
while ((index = SlIterateArray()) != -1) {
|
while ((index = SlIterateArray()) != -1) {
|
||||||
Order *order;
|
Order *order;
|
||||||
|
|
||||||
if (!AddBlockIfNeeded(&_order_pool, index))
|
if (!AddBlockIfNeeded(&_Order_pool, index))
|
||||||
error("Orders: failed loading savegame: too many orders");
|
error("Orders: failed loading savegame: too many orders");
|
||||||
|
|
||||||
order = GetOrder(index);
|
order = GetOrder(index);
|
||||||
|
|
|
@ -1248,7 +1248,7 @@ static void *IntToReference(uint index, SLRefType rt)
|
||||||
|
|
||||||
switch (rt) {
|
switch (rt) {
|
||||||
case REF_ORDER: {
|
case REF_ORDER: {
|
||||||
if (!AddBlockIfNeeded(&_order_pool, index))
|
if (!AddBlockIfNeeded(&_Order_pool, index))
|
||||||
error("Orders: failed loading savegame: too many orders");
|
error("Orders: failed loading savegame: too many orders");
|
||||||
return GetOrder(index);
|
return GetOrder(index);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue