Celestar, I'm just adopting the
order list rewrite for the cargodest branch and have a question about code in
CmdInsertOrder starting at
order_cmd.cpp:619:
Code:
if (order == NULL && GetVehicleOrder(v, sel_ord) != NULL) {
/* There is no previous item, so we are altering v->orders itself
But because the orders can be shared, we copy the info over
the v->orders, so we don't have to change the pointers of
all vehicles */
uint32 mask = v->GetCargoForSharedVehicles();
RoutingBase_t::ProcessOrder(&RoutingBase_t::ProcessOrderListRemoval, v->orders, v->type, mask);
SwapOrders(v->orders, new_o);
/* Now update the next pointers */
v->orders->next = new_o;
new_o->prev = v->orders;
if (new_o->next != NULL) new_o->next->prev = new_o;
RoutingBase_t::ProcessOrder(&RoutingBase_t::ProcessNewOrderList, v->orders, v->type, mask);
} else if (order == NULL) {
/* 'sel' is a non-existing order, add him to the end */
order = GetLastVehicleOrder(v);
order->next = new_o;
new_o->prev = order;
uint32 mask = v->GetCargoForSharedVehicles();
RoutingBase_t::ProcessOrder(&RoutingBase_t::ProcessOrderInsertion, new_o, v->type, mask);
} else {
/* Put the new order in between */
new_o->next = order->next;
if (order->next != NULL) new_o->next->prev = new_o;
order->next = new_o;
new_o->prev = order;
uint32 mask = v->GetCargoForSharedVehicles();
RoutingBase_t::ProcessOrder(&RoutingBase_t::ProcessOrderInsertion, new_o, v->type, mask);
}
In the first case you use a pair of the following:
Code:
RoutingBase_t::ProcessOrder(&RoutingBase_t::ProcessOrderListRemoval, v->orders, v->type, mask);
RoutingBase_t::ProcessOrder(&RoutingBase_t::ProcessNewOrderList, v->orders, v->type, mask);
In the other cases you use only that:
Code:
RoutingBase_t::ProcessOrder(&RoutingBase_t::ProcessOrderInsertion, new_o, v->type, mask);
Due to my patch the swapping is no longer necessary, so can I just use
RoutingBase_t::ProcessOrderInsertion? I don't even understand why the removing/re-adding the full list is needed in your original code. The swapping is just a way to insert a new order at the list head without changing the address of the head.
Do I run into trouble somewhere (maybe caching?) if the address of the first order of the chain changes? If so, I would try to replace references to the first order by references to OrderList.
Thanks in advance for your help.