Merge svn r27779

Conflicts:
	src/autoreplace_gui.cpp
	src/economy.cpp
	src/fios_gui.cpp
	src/lang/spanish_MX.txt
	src/network/network_gui.cpp
	src/rev.cpp.in
	src/road_gui.cpp
	src/toolbar_gui.cpp
	src/window.cpp
This commit is contained in:
Sergii Pylypenko
2017-03-17 23:14:41 +02:00
287 changed files with 6065 additions and 4082 deletions

View File

@@ -2,11 +2,11 @@
#include "../stdafx.h"
#include "demands.h"
#include <list>
#include <queue>
#include "../safeguards.h"
typedef std::list<NodeID> NodeList;
typedef std::queue<NodeID> NodeList;
/**
* Scale various things according to symmetric/asymmetric distribution.
@@ -172,11 +172,11 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
for (NodeID node = 0; node < job.Size(); node++) {
scaler.AddNode(job[node]);
if (job[node].Supply() > 0) {
supplies.push_back(node);
supplies.push(node);
num_supplies++;
}
if (job[node].Demand() > 0) {
demands.push_back(node);
demands.push(node);
num_demands++;
}
}
@@ -191,17 +191,17 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
while (!supplies.empty() && !demands.empty()) {
NodeID from_id = supplies.front();
supplies.pop_front();
supplies.pop();
for (uint i = 0; i < num_demands; ++i) {
assert(!demands.empty());
NodeID to_id = demands.front();
demands.pop_front();
demands.pop();
if (from_id == to_id) {
/* Only one node with supply and demand left */
if (demands.empty() && supplies.empty()) return;
demands.push_back(to_id);
demands.push(to_id);
continue;
}
@@ -236,7 +236,7 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
scaler.SetDemands(job, from_id, to_id, demand_forw);
if (scaler.HasDemandLeft(job[to_id])) {
demands.push_back(to_id);
demands.push(to_id);
} else {
num_demands--;
}
@@ -245,7 +245,7 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
}
if (job[from_id].UndeliveredSupply() != 0) {
supplies.push_back(from_id);
supplies.push(from_id);
} else {
num_supplies--;
}

View File

@@ -17,7 +17,7 @@
#include "../widget_type.h"
#include "linkgraph_base.h"
#include <map>
#include <list>
#include <vector>
/**
* Properties of a link between two stations.
@@ -39,7 +39,7 @@ class LinkGraphOverlay {
public:
typedef std::map<StationID, LinkProperties> StationLinkMap;
typedef std::map<StationID, StationLinkMap> LinkMap;
typedef std::list<std::pair<StationID, uint> > StationSupplyList;
typedef std::vector<std::pair<StationID, uint> > StationSupplyList;
static const uint8 LINK_COLOURS[];

View File

@@ -61,7 +61,7 @@ void LinkGraphJob::EraseFlows(NodeID from)
*/
void LinkGraphJob::SpawnThread()
{
if (!ThreadObject::New(&(LinkGraphSchedule::Run), this, &this->thread)) {
if (!ThreadObject::New(&(LinkGraphSchedule::Run), this, &this->thread, "ottd:linkgraph")) {
this->thread = NULL;
/* Of course this will hang a bit.
* On the other hand, if you want to play games which make this hang noticably

View File

@@ -32,6 +32,11 @@ public:
*/
inline uint GetAnnotation() const { return this->distance; }
/**
* Update the cached annotation value
*/
inline void UpdateAnnotation() { }
/**
* Comparator for std containers.
*/
@@ -47,6 +52,8 @@ public:
* can only decrease or stay the same if you add more edges.
*/
class CapacityAnnotation : public Path {
int cached_annotation;
public:
/**
@@ -62,7 +69,15 @@ public:
* Return the actual value of the annotation, in this case the capacity.
* @return Capacity.
*/
inline int GetAnnotation() const { return this->GetCapacityRatio(); }
inline int GetAnnotation() const { return this->cached_annotation; }
/**
* Update the cached annotation value
*/
inline void UpdateAnnotation()
{
this->cached_annotation = this->GetCapacityRatio();
}
/**
* Comparator for std containers.
@@ -121,7 +136,7 @@ private:
LinkGraphJob &job; ///< Link graph job we're working with.
/** Lookup table for getting NodeIDs from StationIDs. */
std::map<StationID, NodeID> station_to_node;
std::vector<NodeID> station_to_node;
/** Current iterator in the shares map. */
FlowStat::SharesMap::const_iterator it;
@@ -137,7 +152,11 @@ public:
FlowEdgeIterator(LinkGraphJob &job) : job(job)
{
for (NodeID i = 0; i < job.Size(); ++i) {
this->station_to_node[job[i].Station()] = i;
StationID st = job[i].Station();
if (st >= this->station_to_node.size()) {
this->station_to_node.resize(st + 1);
}
this->station_to_node[st] = i;
}
}
@@ -246,6 +265,7 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
paths.resize(size, NULL);
for (NodeID node = 0; node < size; ++node) {
Tannotation *anno = new Tannotation(node, node == source_node);
anno->UpdateAnnotation();
annos.insert(anno);
paths[node] = anno;
}
@@ -270,6 +290,7 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
if (dest->IsBetter(source, capacity, capacity - edge.Flow(), distance)) {
annos.erase(dest);
dest->Fork(source, capacity, capacity - edge.Flow(), distance);
dest->UpdateAnnotation();
annos.insert(dest);
}
}

View File

@@ -72,10 +72,15 @@ LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_mer
vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID), allow_merge(allow_merge),
is_full_loading(is_full_loading)
{
memset(this->capacities, 0, sizeof(this->capacities));
/* Assemble list of capacities and set last loading stations to 0. */
for (Vehicle *v = this->vehicle; v != NULL; v = v->Next()) {
this->refit_capacities.push_back(RefitDesc(v->cargo_type, v->cargo_cap, v->refit_cap));
if (v->refit_cap > 0) this->capacities[v->cargo_type] += v->refit_cap;
if (v->refit_cap > 0) {
assert(v->cargo_type < NUM_CARGO);
this->capacities[v->cargo_type] += v->refit_cap;
}
}
}
@@ -200,11 +205,11 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
StationID next_station = next->GetDestination();
Station *st = Station::GetIfValid(cur->GetDestination());
if (st != NULL && next_station != INVALID_STATION && next_station != st->index) {
for (CapacitiesMap::const_iterator i = this->capacities.begin(); i != this->capacities.end(); ++i) {
for (CargoID c = 0; c < NUM_CARGO; c++) {
/* Refresh the link and give it a minimum capacity. */
if (i->second == 0) continue;
CargoID c = i->first;
uint cargo_quantity = this->capacities[c];
if (cargo_quantity == 0) continue;
/* If not allowed to merge link graphs, make sure the stations are
* already in the same link graph. */
@@ -225,7 +230,7 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
st->index == vehicle->last_station_visited &&
this->vehicle->orders.list->GetTotalDuration() >
(Ticks)this->vehicle->current_order_time) {
uint effective_capacity = i->second * this->vehicle->load_unload_ticks;
uint effective_capacity = cargo_quantity * this->vehicle->load_unload_ticks;
if (effective_capacity > (uint)this->vehicle->orders.list->GetTotalDuration()) {
IncreaseStats(st, c, next_station, effective_capacity /
this->vehicle->orders.list->GetTotalDuration(), 0,
@@ -233,10 +238,10 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
} else if (RandomRange(this->vehicle->orders.list->GetTotalDuration()) < effective_capacity) {
IncreaseStats(st, c, next_station, 1, 0, EUM_INCREASE | restricted_mode);
} else {
IncreaseStats(st, c, next_station, i->second, 0, EUM_REFRESH | restricted_mode);
IncreaseStats(st, c, next_station, cargo_quantity, 0, EUM_REFRESH | restricted_mode);
}
} else {
IncreaseStats(st, c, next_station, i->second, 0, EUM_REFRESH | restricted_mode);
IncreaseStats(st, c, next_station, cargo_quantity, 0, EUM_REFRESH | restricted_mode);
}
}
}

View File

@@ -14,7 +14,7 @@
#include "../cargo_type.h"
#include "../vehicle_base.h"
#include <list>
#include <vector>
#include <map>
#include <set>
@@ -79,12 +79,11 @@ protected:
bool operator<(const Hop &other) const;
};
typedef std::list<RefitDesc> RefitList;
typedef std::map<CargoID, uint> CapacitiesMap;
typedef std::vector<RefitDesc> RefitList;
typedef std::set<Hop> HopSet;
Vehicle *vehicle; ///< Vehicle for which the links should be refreshed.
CapacitiesMap capacities; ///< Current added capacities per cargo ID in the consist.
uint capacities[NUM_CARGO]; ///< Current added capacities per cargo ID in the consist.
RefitList refit_capacities; ///< Current state of capacity remaining from previous refits versus overall capacity per vehicle in the consist.
HopSet *seen_hops; ///< Hops already seen. If the same hop is seen twice we stop the algorithm. This is shared between all Refreshers of the same run.
CargoID cargo; ///< Cargo given in last refit order.