Merge branch 'origin/master' commit 'a499e9acdd385b57dd43caf88af3a6f7f53716ba'
This commit is contained in:
@@ -23,7 +23,7 @@ private:
|
||||
};
|
||||
|
||||
/**
|
||||
* Stateless, thread safe demand hander. Doesn't do anything but call DemandCalculator.
|
||||
* Stateless, thread safe demand handler. Doesn't do anything but call DemandCalculator.
|
||||
*/
|
||||
class DemandHandler : public ComponentHandler {
|
||||
public:
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "linkgraphjob_base.h"
|
||||
|
||||
/**
|
||||
* Stateless, thread safe initialization hander. Initializes node and edge
|
||||
* Stateless, thread safe initialization handler. Initializes node and edge
|
||||
* annotations.
|
||||
*/
|
||||
class InitHandler : public ComponentHandler {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
@@ -139,7 +137,10 @@ void LinkGraph::RemoveNode(NodeID id)
|
||||
node_edges[id] = node_edges[last_node];
|
||||
}
|
||||
Station::Get(this->nodes[last_node].station)->goods[this->cargo].node = id;
|
||||
this->nodes.Erase(this->nodes.Get(id));
|
||||
/* Erase node by swapping with the last element. Node index is referenced
|
||||
* directly from station goods entries so the order and position must remain. */
|
||||
this->nodes[id] = this->nodes.back();
|
||||
this->nodes.pop_back();
|
||||
this->edges.EraseColumn(id);
|
||||
/* Not doing EraseRow here, as having the extra invalid row doesn't hurt
|
||||
* and removing it would trigger a lot of memmove. The data has already
|
||||
@@ -159,7 +160,7 @@ NodeID LinkGraph::AddNode(const Station *st)
|
||||
const GoodsEntry &good = st->goods[this->cargo];
|
||||
|
||||
NodeID new_node = this->Size();
|
||||
this->nodes.Append();
|
||||
this->nodes.emplace_back();
|
||||
/* Avoid reducing the height of the matrix as that is expensive and we
|
||||
* most likely will increase it again later which is again expensive. */
|
||||
this->edges.Resize(new_node + 1U,
|
||||
@@ -281,7 +282,7 @@ void LinkGraph::Init(uint size)
|
||||
{
|
||||
assert(this->Size() == 0);
|
||||
this->edges.Resize(size, size);
|
||||
this->nodes.Resize(size);
|
||||
this->nodes.resize(size);
|
||||
|
||||
for (uint i = 0; i < size; ++i) {
|
||||
this->nodes[i].Init();
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
@@ -435,7 +433,7 @@ public:
|
||||
void RemoveEdge(NodeID to);
|
||||
};
|
||||
|
||||
typedef SmallVector<BaseNode, 16> NodeVector;
|
||||
typedef std::vector<BaseNode> NodeVector;
|
||||
typedef SmallMatrix<BaseEdge> EdgeMatrix;
|
||||
|
||||
/** Minimum effective distance for timeout calculation. */
|
||||
@@ -496,7 +494,7 @@ public:
|
||||
* Get the current size of the component.
|
||||
* @return Size.
|
||||
*/
|
||||
inline uint Size() const { return this->nodes.Length(); }
|
||||
inline uint Size() const { return (uint)this->nodes.size(); }
|
||||
|
||||
/**
|
||||
* Get date of last compression.
|
||||
@@ -536,6 +534,4 @@ protected:
|
||||
EdgeMatrix edges; ///< Edges in the component.
|
||||
};
|
||||
|
||||
#define FOR_ALL_LINK_GRAPHS(var) FOR_ALL_ITEMS_FROM(LinkGraph, link_graph_index, var, 0)
|
||||
|
||||
#endif /* LINKGRAPH_H */
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
@@ -58,8 +56,7 @@ void LinkGraphOverlay::RebuildCache()
|
||||
DrawPixelInfo dpi;
|
||||
this->GetWidgetDpi(&dpi);
|
||||
|
||||
const Station *sta;
|
||||
FOR_ALL_STATIONS(sta) {
|
||||
for (const Station *sta : Station::Iterate()) {
|
||||
if (sta->rect.IsEmpty()) continue;
|
||||
|
||||
Point pta = this->GetStationMiddle(sta);
|
||||
@@ -301,7 +298,7 @@ void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const
|
||||
{
|
||||
for (StationSupplyList::const_iterator i(this->cached_stations.begin()); i != this->cached_stations.end(); ++i) {
|
||||
const Station *st = Station::GetIfValid(i->first);
|
||||
if (st == NULL) continue;
|
||||
if (st == nullptr) continue;
|
||||
Point pt = this->GetStationMiddle(st);
|
||||
if (!this->IsPointVisible(pt, dpi, 3 * this->scale)) continue;
|
||||
|
||||
@@ -345,7 +342,7 @@ void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const
|
||||
*/
|
||||
Point LinkGraphOverlay::GetStationMiddle(const Station *st) const
|
||||
{
|
||||
if (this->window->viewport != NULL) {
|
||||
if (this->window->viewport != nullptr) {
|
||||
return GetViewportStationMiddle(this->window->viewport, st);
|
||||
} else {
|
||||
/* assume this is a smallmap */
|
||||
@@ -399,7 +396,7 @@ NWidgetBase *MakeCargoesLegendLinkGraphGUI(int *biggest_index)
|
||||
{
|
||||
static const uint ENTRIES_PER_ROW = CeilDiv(NUM_CARGO, 5);
|
||||
NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE);
|
||||
NWidgetHorizontal *row = NULL;
|
||||
NWidgetHorizontal *row = nullptr;
|
||||
for (uint i = 0; i < NUM_CARGO; ++i) {
|
||||
if (i % ENTRIES_PER_ROW == 0) {
|
||||
if (row) panel->Add(row);
|
||||
@@ -564,7 +561,7 @@ bool LinkGraphLegendWindow::OnTooltip(Point pt, int widget, TooltipCloseConditio
|
||||
{
|
||||
if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
|
||||
if (this->IsWidgetDisabled(widget)) {
|
||||
GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES, 0, NULL, close_cond);
|
||||
GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES, 0, nullptr, close_cond);
|
||||
} else {
|
||||
uint64 params[2];
|
||||
CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
@@ -104,11 +102,11 @@ public:
|
||||
LinkGraphLegendWindow(WindowDesc *desc, int window_number);
|
||||
void SetOverlay(LinkGraphOverlay *overlay);
|
||||
|
||||
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize);
|
||||
virtual void DrawWidget(const Rect &r, int widget) const;
|
||||
virtual bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond);
|
||||
virtual void OnClick(Point pt, int widget, int click_count);
|
||||
virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
|
||||
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override;
|
||||
void DrawWidget(const Rect &r, int widget) const override;
|
||||
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override;
|
||||
void OnClick(Point pt, int widget, int click_count) override;
|
||||
void OnInvalidateData(int data = 0, bool gui_scope = true) override;
|
||||
|
||||
private:
|
||||
LinkGraphOverlay *overlay;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
@@ -21,7 +19,7 @@ static const LinkGraphID INVALID_LINK_GRAPH_JOB = UINT16_MAX;
|
||||
typedef uint16 NodeID;
|
||||
static const NodeID INVALID_NODE = UINT16_MAX;
|
||||
|
||||
enum DistributionType {
|
||||
enum DistributionType : byte {
|
||||
DT_BEGIN = 0,
|
||||
DT_MIN = 0,
|
||||
DT_MANUAL = 0, ///< Manual distribution. No link graph calculations are run.
|
||||
@@ -37,7 +35,6 @@ enum DistributionType {
|
||||
* Define basic enum properties
|
||||
*/
|
||||
template <> struct EnumPropsT<DistributionType> : MakeEnumPropsT<DistributionType, byte, DT_BEGIN, DT_END, DT_NUM> {};
|
||||
typedef TinyEnumT<DistributionType> DistributionTypeByte; // typedefing-enumification of DistributionType
|
||||
|
||||
/**
|
||||
* Special modes for updating links. 'Restricted' means that vehicles with
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
@@ -39,7 +37,6 @@ LinkGraphJob::LinkGraphJob(const LinkGraph &orig) :
|
||||
* This is on purpose. */
|
||||
link_graph(orig),
|
||||
settings(_settings_game.linkgraph),
|
||||
thread(NULL),
|
||||
join_date(_date + _settings_game.linkgraph.recalc_time)
|
||||
{
|
||||
}
|
||||
@@ -61,10 +58,9 @@ void LinkGraphJob::EraseFlows(NodeID from)
|
||||
*/
|
||||
void LinkGraphJob::SpawnThread()
|
||||
{
|
||||
if (!ThreadObject::New(&(LinkGraphSchedule::Run), this, &this->thread, "ottd:linkgraph")) {
|
||||
this->thread = NULL;
|
||||
if (!StartNewThread(&this->thread, "ottd:linkgraph", &(LinkGraphSchedule::Run), this)) {
|
||||
/* Of course this will hang a bit.
|
||||
* On the other hand, if you want to play games which make this hang noticably
|
||||
* On the other hand, if you want to play games which make this hang noticeably
|
||||
* on a platform without threads then you'll probably get other problems first.
|
||||
* OK:
|
||||
* If someone comes and tells me that this hangs for him/her, I'll implement a
|
||||
@@ -79,10 +75,8 @@ void LinkGraphJob::SpawnThread()
|
||||
*/
|
||||
void LinkGraphJob::JoinThread()
|
||||
{
|
||||
if (this->thread != NULL) {
|
||||
this->thread->Join();
|
||||
delete this->thread;
|
||||
this->thread = NULL;
|
||||
if (this->thread.joinable()) {
|
||||
this->thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +100,7 @@ LinkGraphJob::~LinkGraphJob()
|
||||
|
||||
/* The station can have been deleted. Remove all flows originating from it then. */
|
||||
Station *st = Station::GetIfValid(from.Station());
|
||||
if (st == NULL) {
|
||||
if (st == nullptr) {
|
||||
this->EraseFlows(node_id);
|
||||
continue;
|
||||
}
|
||||
@@ -126,7 +120,7 @@ LinkGraphJob::~LinkGraphJob()
|
||||
if (from[it->first].Flow() == 0) continue;
|
||||
StationID to = (*this)[it->first].Station();
|
||||
Station *st2 = Station::GetIfValid(to);
|
||||
if (st2 == NULL || st2->goods[this->Cargo()].link_graph != this->link_graph.index ||
|
||||
if (st2 == nullptr || st2->goods[this->Cargo()].link_graph != this->link_graph.index ||
|
||||
st2->goods[this->Cargo()].node != it->first ||
|
||||
(*lg)[node_id][it->first].LastUpdate() == INVALID_DATE) {
|
||||
/* Edge has been removed. Delete flows. */
|
||||
@@ -179,7 +173,7 @@ LinkGraphJob::~LinkGraphJob()
|
||||
void LinkGraphJob::Init()
|
||||
{
|
||||
uint size = this->Size();
|
||||
this->nodes.Resize(size);
|
||||
this->nodes.resize(size);
|
||||
this->edges.Resize(size, size);
|
||||
for (uint i = 0; i < size; ++i) {
|
||||
this->nodes[i].Init(this->link_graph[i].Supply());
|
||||
@@ -244,7 +238,7 @@ void Path::Fork(Path *base, uint cap, int free_cap, uint dist)
|
||||
*/
|
||||
uint Path::AddFlow(uint new_flow, LinkGraphJob &job, uint max_saturation)
|
||||
{
|
||||
if (this->parent != NULL) {
|
||||
if (this->parent != nullptr) {
|
||||
LinkGraphJob::Edge edge = job[this->parent->node][this->node];
|
||||
if (max_saturation != UINT_MAX) {
|
||||
uint usable_cap = edge.Capacity() * max_saturation / 100;
|
||||
@@ -274,6 +268,6 @@ Path::Path(NodeID n, bool source) :
|
||||
capacity(source ? UINT_MAX : 0),
|
||||
free_capacity(source ? INT_MAX : INT_MIN),
|
||||
flow(0), node(n), origin(source ? n : INVALID_NODE),
|
||||
num_children(0), parent(NULL)
|
||||
num_children(0), parent(nullptr)
|
||||
{}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
@@ -12,7 +10,7 @@
|
||||
#ifndef LINKGRAPHJOB_H
|
||||
#define LINKGRAPHJOB_H
|
||||
|
||||
#include "../thread/thread.h"
|
||||
#include "../thread.h"
|
||||
#include "linkgraph.h"
|
||||
#include <list>
|
||||
|
||||
@@ -50,7 +48,7 @@ private:
|
||||
void Init(uint supply);
|
||||
};
|
||||
|
||||
typedef SmallVector<NodeAnnotation, 16> NodeAnnotationVector;
|
||||
typedef std::vector<NodeAnnotation> NodeAnnotationVector;
|
||||
typedef SmallMatrix<EdgeAnnotation> EdgeAnnotationMatrix;
|
||||
|
||||
friend const SaveLoad *GetLinkGraphJobDesc();
|
||||
@@ -59,7 +57,7 @@ private:
|
||||
protected:
|
||||
const LinkGraph link_graph; ///< Link graph to by analyzed. Is copied when job is started and mustn't be modified later.
|
||||
const LinkGraphSettings settings; ///< Copy of _settings_game.linkgraph at spawn time.
|
||||
ThreadObject *thread; ///< Thread the job is running in or NULL if it's running in the main thread.
|
||||
std::thread thread; ///< Thread the job is running in or a default-constructed thread if it's running in the main thread.
|
||||
Date join_date; ///< Date when the job is to be joined.
|
||||
NodeAnnotationVector nodes; ///< Extra node data necessary for link graph calculation.
|
||||
EdgeAnnotationMatrix edges; ///< Extra edge data necessary for link graph calculation.
|
||||
@@ -266,7 +264,7 @@ public:
|
||||
* Bare constructor, only for save/load. link_graph, join_date and actually
|
||||
* settings have to be brutally const-casted in order to populate them.
|
||||
*/
|
||||
LinkGraphJob() : settings(_settings_game.linkgraph), thread(NULL),
|
||||
LinkGraphJob() : settings(_settings_game.linkgraph),
|
||||
join_date(INVALID_DATE) {}
|
||||
|
||||
LinkGraphJob(const LinkGraph &orig);
|
||||
@@ -336,8 +334,6 @@ public:
|
||||
inline const LinkGraph &Graph() const { return this->link_graph; }
|
||||
};
|
||||
|
||||
#define FOR_ALL_LINK_GRAPH_JOBS(var) FOR_ALL_ITEMS_FROM(LinkGraphJob, link_graph_job_index, var, 0)
|
||||
|
||||
/**
|
||||
* A leg of a path in the link graph. Paths can form trees by being "forked".
|
||||
*/
|
||||
@@ -403,9 +399,9 @@ public:
|
||||
*/
|
||||
inline void Detach()
|
||||
{
|
||||
if (this->parent != NULL) {
|
||||
if (this->parent != nullptr) {
|
||||
this->parent->num_children--;
|
||||
this->parent = NULL;
|
||||
this->parent = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,7 +411,7 @@ public:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Some boundaries to clamp agains in order to avoid integer overflows.
|
||||
* Some boundaries to clamp against in order to avoid integer overflows.
|
||||
*/
|
||||
enum PathCapacityBoundaries {
|
||||
PATH_CAP_MULTIPLIER = 16,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
@@ -69,13 +67,11 @@ void LinkGraphSchedule::JoinNext()
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all handlers for the given Job. This method is tailored to
|
||||
* ThreadObject::New.
|
||||
* @param j Pointer to a link graph job.
|
||||
* Run all handlers for the given Job.
|
||||
* @param job Pointer to a link graph job.
|
||||
*/
|
||||
/* static */ void LinkGraphSchedule::Run(void *j)
|
||||
/* static */ void LinkGraphSchedule::Run(LinkGraphJob *job)
|
||||
{
|
||||
LinkGraphJob *job = (LinkGraphJob *)j;
|
||||
for (uint i = 0; i < lengthof(instance.handlers); ++i) {
|
||||
instance.handlers[i]->Run(*job);
|
||||
}
|
||||
@@ -111,10 +107,8 @@ void LinkGraphSchedule::SpawnAll()
|
||||
*/
|
||||
void LinkGraphSchedule::ShiftDates(int interval)
|
||||
{
|
||||
LinkGraph *lg;
|
||||
FOR_ALL_LINK_GRAPHS(lg) lg->ShiftDates(interval);
|
||||
LinkGraphJob *lgj;
|
||||
FOR_ALL_LINK_GRAPH_JOBS(lgj) lgj->ShiftJoinDate(interval);
|
||||
for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(interval);
|
||||
for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) lgj->ShiftJoinDate(interval);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
@@ -53,7 +51,7 @@ public:
|
||||
static const uint SPAWN_JOIN_TICK = 21; ///< Tick when jobs are spawned or joined every day.
|
||||
static LinkGraphSchedule instance;
|
||||
|
||||
static void Run(void *j);
|
||||
static void Run(LinkGraphJob *job);
|
||||
static void Clear();
|
||||
|
||||
void SpawnNext();
|
||||
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
* @param job Job to iterate on.
|
||||
*/
|
||||
GraphEdgeIterator(LinkGraphJob &job) : job(job),
|
||||
i(NULL, NULL, INVALID_NODE), end(NULL, NULL, INVALID_NODE)
|
||||
i(nullptr, nullptr, INVALID_NODE), end(nullptr, nullptr, INVALID_NODE)
|
||||
{}
|
||||
|
||||
/**
|
||||
@@ -262,7 +262,7 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
|
||||
Tedge_iterator iter(this->job);
|
||||
uint size = this->job.Size();
|
||||
AnnoSet annos;
|
||||
paths.resize(size, NULL);
|
||||
paths.resize(size, nullptr);
|
||||
for (NodeID node = 0; node < size; ++node) {
|
||||
Tannotation *anno = new Tannotation(node, node == source_node);
|
||||
anno->UpdateAnnotation();
|
||||
@@ -305,16 +305,16 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
|
||||
void MultiCommodityFlow::CleanupPaths(NodeID source_id, PathVector &paths)
|
||||
{
|
||||
Path *source = paths[source_id];
|
||||
paths[source_id] = NULL;
|
||||
paths[source_id] = nullptr;
|
||||
for (PathVector::iterator i = paths.begin(); i != paths.end(); ++i) {
|
||||
Path *path = *i;
|
||||
if (path == NULL) continue;
|
||||
if (path == nullptr) continue;
|
||||
if (path->GetParent() == source) path->Detach();
|
||||
while (path != source && path != NULL && path->GetFlow() == 0) {
|
||||
while (path != source && path != nullptr && path->GetFlow() == 0) {
|
||||
Path *parent = path->GetParent();
|
||||
path->Detach();
|
||||
if (path->GetNumChildren() == 0) {
|
||||
paths[path->GetNode()] = NULL;
|
||||
paths[path->GetNode()] = nullptr;
|
||||
delete path;
|
||||
}
|
||||
path = parent;
|
||||
@@ -404,7 +404,7 @@ bool MCF1stPass::EliminateCycles(PathVector &path, NodeID origin_id, NodeID next
|
||||
/* this node has already been searched */
|
||||
if (at_next_pos == Path::invalid_path) return false;
|
||||
|
||||
if (at_next_pos == NULL) {
|
||||
if (at_next_pos == nullptr) {
|
||||
/* Summarize paths; add up the paths with the same source and next hop
|
||||
* in one path each. */
|
||||
PathList &paths = this->job[next_id].Paths();
|
||||
@@ -450,7 +450,7 @@ bool MCF1stPass::EliminateCycles(PathVector &path, NodeID origin_id, NodeID next
|
||||
* could be found in this branch, thus it has to be searched again next
|
||||
* time we spot it.
|
||||
*/
|
||||
path[next_id] = found ? NULL : Path::invalid_path;
|
||||
path[next_id] = found ? nullptr : Path::invalid_path;
|
||||
return found;
|
||||
}
|
||||
|
||||
@@ -474,11 +474,11 @@ bool MCF1stPass::EliminateCycles()
|
||||
{
|
||||
bool cycles_found = false;
|
||||
uint size = this->job.Size();
|
||||
PathVector path(size, NULL);
|
||||
PathVector path(size, nullptr);
|
||||
for (NodeID node = 0; node < size; ++node) {
|
||||
/* Starting at each node in the graph find all cycles involving this
|
||||
* node. */
|
||||
std::fill(path.begin(), path.end(), (Path *)NULL);
|
||||
std::fill(path.begin(), path.end(), (Path *)nullptr);
|
||||
cycles_found |= this->EliminateCycles(path, node, node);
|
||||
}
|
||||
return cycles_found;
|
||||
@@ -494,18 +494,22 @@ MCF1stPass::MCF1stPass(LinkGraphJob &job) : MultiCommodityFlow(job)
|
||||
uint size = job.Size();
|
||||
uint accuracy = job.Settings().accuracy;
|
||||
bool more_loops;
|
||||
std::vector<bool> finished_sources(size);
|
||||
|
||||
do {
|
||||
more_loops = false;
|
||||
for (NodeID source = 0; source < size; ++source) {
|
||||
if (finished_sources[source]) continue;
|
||||
|
||||
/* First saturate the shortest paths. */
|
||||
this->Dijkstra<DistanceAnnotation, GraphEdgeIterator>(source, paths);
|
||||
|
||||
bool source_demand_left = false;
|
||||
for (NodeID dest = 0; dest < size; ++dest) {
|
||||
Edge edge = job[source][dest];
|
||||
if (edge.UnsatisfiedDemand() > 0) {
|
||||
Path *path = paths[dest];
|
||||
assert(path != NULL);
|
||||
assert(path != nullptr);
|
||||
/* Generally only allow paths that don't exceed the
|
||||
* available capacity. But if no demand has been assigned
|
||||
* yet, make an exception and allow any valid path *once*. */
|
||||
@@ -518,8 +522,10 @@ MCF1stPass::MCF1stPass(LinkGraphJob &job) : MultiCommodityFlow(job)
|
||||
path->GetFreeCapacity() > INT_MIN) {
|
||||
this->PushFlow(edge, path, accuracy, UINT_MAX);
|
||||
}
|
||||
if (edge.UnsatisfiedDemand() > 0) source_demand_left = true;
|
||||
}
|
||||
}
|
||||
finished_sources[source] = !source_demand_left;
|
||||
this->CleanupPaths(source, paths);
|
||||
}
|
||||
} while (more_loops || this->EliminateCycles());
|
||||
@@ -537,18 +543,27 @@ MCF2ndPass::MCF2ndPass(LinkGraphJob &job) : MultiCommodityFlow(job)
|
||||
uint size = job.Size();
|
||||
uint accuracy = job.Settings().accuracy;
|
||||
bool demand_left = true;
|
||||
std::vector<bool> finished_sources(size);
|
||||
while (demand_left) {
|
||||
demand_left = false;
|
||||
for (NodeID source = 0; source < size; ++source) {
|
||||
if (finished_sources[source]) continue;
|
||||
|
||||
this->Dijkstra<CapacityAnnotation, FlowEdgeIterator>(source, paths);
|
||||
|
||||
bool source_demand_left = false;
|
||||
for (NodeID dest = 0; dest < size; ++dest) {
|
||||
Edge edge = this->job[source][dest];
|
||||
Path *path = paths[dest];
|
||||
if (edge.UnsatisfiedDemand() > 0 && path->GetFreeCapacity() > INT_MIN) {
|
||||
this->PushFlow(edge, path, accuracy, UINT_MAX);
|
||||
if (edge.UnsatisfiedDemand() > 0) demand_left = true;
|
||||
if (edge.UnsatisfiedDemand() > 0) {
|
||||
demand_left = true;
|
||||
source_demand_left = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
finished_sources[source] = !source_demand_left;
|
||||
this->CleanupPaths(source, paths);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
@@ -28,11 +26,11 @@
|
||||
/* static */ void LinkRefresher::Run(Vehicle *v, bool allow_merge, bool is_full_loading)
|
||||
{
|
||||
/* If there are no orders we can't predict anything.*/
|
||||
if (v->orders.list == NULL) return;
|
||||
if (v->orders.list == nullptr) return;
|
||||
|
||||
/* Make sure the first order is a useful order. */
|
||||
const Order *first = v->orders.list->GetNextDecisionNode(v->GetOrder(v->cur_implicit_order_index), 0);
|
||||
if (first == NULL) return;
|
||||
if (first == nullptr) return;
|
||||
|
||||
HopSet seen_hops;
|
||||
LinkRefresher refresher(v, &seen_hops, allow_merge, is_full_loading);
|
||||
@@ -75,7 +73,7 @@ LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_mer
|
||||
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()) {
|
||||
for (Vehicle *v = this->vehicle; v != nullptr; v = v->Next()) {
|
||||
this->refit_capacities.push_back(RefitDesc(v->cargo_type, v->cargo_cap, v->refit_cap));
|
||||
if (v->refit_cap > 0) {
|
||||
assert(v->cargo_type < NUM_CARGO);
|
||||
@@ -94,7 +92,7 @@ bool LinkRefresher::HandleRefit(CargoID refit_cargo)
|
||||
this->cargo = refit_cargo;
|
||||
RefitList::iterator refit_it = this->refit_capacities.begin();
|
||||
bool any_refit = false;
|
||||
for (Vehicle *v = this->vehicle; v != NULL; v = v->Next()) {
|
||||
for (Vehicle *v = this->vehicle; v != nullptr; v = v->Next()) {
|
||||
const Engine *e = Engine::Get(v->engine_type);
|
||||
if (!HasBit(e->info.refit_mask, this->cargo)) {
|
||||
++refit_it;
|
||||
@@ -164,10 +162,10 @@ void LinkRefresher::ResetRefit()
|
||||
*/
|
||||
const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next, uint8 flags, uint num_hops)
|
||||
{
|
||||
/* next is good if it's either NULL (then the caller will stop the
|
||||
/* next is good if it's either nullptr (then the caller will stop the
|
||||
* evaluation) or if it's not conditional and the caller allows it to be
|
||||
* chosen (by setting USE_NEXT). */
|
||||
while (next != NULL && (!HasBit(flags, USE_NEXT) || next->IsType(OT_CONDITIONAL))) {
|
||||
while (next != nullptr && (!HasBit(flags, USE_NEXT) || next->IsType(OT_CONDITIONAL))) {
|
||||
|
||||
/* After the first step any further non-conditional order is good,
|
||||
* regardless of previous USE_NEXT settings. The case of cur and next or
|
||||
@@ -177,7 +175,7 @@ const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next
|
||||
if (next->IsType(OT_CONDITIONAL)) {
|
||||
const Order *skip_to = this->vehicle->orders.list->GetNextDecisionNode(
|
||||
this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops);
|
||||
if (skip_to != NULL && num_hops < this->vehicle->orders.list->GetNumOrders()) {
|
||||
if (skip_to != nullptr && num_hops < this->vehicle->orders.list->GetNumOrders()) {
|
||||
/* Make copies of capacity tracking lists. There is potential
|
||||
* for optimization here: If the vehicle never refits we don't
|
||||
* need to copy anything. Also, if we've seen the branched link
|
||||
@@ -204,7 +202,7 @@ 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) {
|
||||
if (st != nullptr && next_station != INVALID_STATION && next_station != st->index) {
|
||||
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
||||
/* Refresh the link and give it a minimum capacity. */
|
||||
|
||||
@@ -226,7 +224,7 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
|
||||
* loading. Don't do that if the vehicle has been waiting for longer than the entire
|
||||
* order list is supposed to take, though. If that is the case the total duration is
|
||||
* probably far off and we'd greatly overestimate the capacity by increasing.*/
|
||||
if (this->is_full_loading && this->vehicle->orders.list != NULL &&
|
||||
if (this->is_full_loading && this->vehicle->orders.list != nullptr &&
|
||||
st->index == vehicle->last_station_visited &&
|
||||
this->vehicle->orders.list->GetTotalDuration() >
|
||||
(Ticks)this->vehicle->current_order_time) {
|
||||
@@ -250,7 +248,7 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
|
||||
/**
|
||||
* Iterate over orders starting at \a cur and \a next and refresh links
|
||||
* associated with them. \a cur and \a next can be equal. If they're not they
|
||||
* must be "neigbours" in their order list, which means \a next must be directly
|
||||
* must be "neighbours" in their order list, which means \a next must be directly
|
||||
* reachable from \a cur without passing any further OT_GOTO_STATION or
|
||||
* OT_IMPLICIT orders in between.
|
||||
* @param cur Current order being evaluated.
|
||||
@@ -260,7 +258,7 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
|
||||
*/
|
||||
void LinkRefresher::RefreshLinks(const Order *cur, const Order *next, uint8 flags, uint num_hops)
|
||||
{
|
||||
while (next != NULL) {
|
||||
while (next != nullptr) {
|
||||
|
||||
if ((next->IsType(OT_GOTO_DEPOT) || next->IsType(OT_GOTO_STATION)) && next->IsRefit()) {
|
||||
SetBit(flags, WAS_REFIT);
|
||||
@@ -288,7 +286,7 @@ void LinkRefresher::RefreshLinks(const Order *cur, const Order *next, uint8 flag
|
||||
}
|
||||
|
||||
next = this->PredictNextOrder(cur, next, flags, num_hops);
|
||||
if (next == NULL) break;
|
||||
if (next == nullptr) break;
|
||||
Hop hop(cur->index, next->index, this->cargo);
|
||||
if (this->seen_hops->find(hop) != this->seen_hops->end()) {
|
||||
break;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
|
||||
Reference in New Issue
Block a user