@@ -300,16 +300,16 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, const std::vector<bool> &re
|
||||
continue;
|
||||
}
|
||||
|
||||
int32 supply = scaler.EffectiveSupply(job[from_id], job[to_id]);
|
||||
int32_t supply = scaler.EffectiveSupply(job[from_id], job[to_id]);
|
||||
assert(supply > 0);
|
||||
|
||||
/* Scale the distance by mod_dist around max_distance */
|
||||
int32 distance = this->max_distance - (this->max_distance -
|
||||
(int32)DistanceMaxPlusManhattan(job[from_id].XY(), job[to_id].XY())) *
|
||||
int32_t distance = this->max_distance - (this->max_distance -
|
||||
(int32_t)DistanceMaxPlusManhattan(job[from_id].XY(), job[to_id].XY())) *
|
||||
this->mod_dist / 100;
|
||||
|
||||
/* Scale the accuracy by distance around accuracy / 2 */
|
||||
int32 divisor = this->accuracy * (this->mod_dist - 50) / 100 +
|
||||
int32_t divisor = this->accuracy * (this->mod_dist - 50) / 100 +
|
||||
this->accuracy * distance / this->max_distance + 1;
|
||||
|
||||
assert(divisor > 0);
|
||||
|
@@ -15,9 +15,9 @@ public:
|
||||
DemandCalculator(LinkGraphJob &job);
|
||||
|
||||
private:
|
||||
int32 max_distance; ///< Maximum distance possible on the map.
|
||||
int32 mod_dist; ///< Distance modifier, determines how much demands decrease with distance.
|
||||
int32 accuracy; ///< Accuracy of the calculation.
|
||||
int32_t max_distance; ///< Maximum distance possible on the map.
|
||||
int32_t mod_dist; ///< Distance modifier, determines how much demands decrease with distance.
|
||||
int32_t accuracy; ///< Accuracy of the calculation.
|
||||
|
||||
template<class Tscaler>
|
||||
void CalcDemand(LinkGraphJob &job, const std::vector<bool> &reachable_nodes, Tscaler scaler);
|
||||
|
@@ -65,7 +65,7 @@ void LinkGraph::Compress()
|
||||
if (edge.capacity < (1 << 16)) {
|
||||
edge.travel_time_sum = edge.travel_time_sum * new_capacity / edge.capacity;
|
||||
} else if (edge.travel_time_sum != 0) {
|
||||
edge.travel_time_sum = std::max<uint64>(1, edge.travel_time_sum / 2);
|
||||
edge.travel_time_sum = std::max<uint64_t>(1, edge.travel_time_sum / 2);
|
||||
}
|
||||
edge.capacity = new_capacity;
|
||||
edge.usage /= 2;
|
||||
@@ -79,8 +79,8 @@ void LinkGraph::Compress()
|
||||
*/
|
||||
void LinkGraph::Merge(LinkGraph *other)
|
||||
{
|
||||
uint32 age = ClampTo<uint32>(CeilDivT<int64>(_scaled_date_ticks.base() - this->last_compression.base() + 1, DAY_TICKS));
|
||||
uint32 other_age = ClampTo<uint32>(CeilDivT<int64>(_scaled_date_ticks.base() - other->last_compression.base() + 1, DAY_TICKS));
|
||||
uint32_t age = ClampTo<uint32_t>(CeilDivT<int64_t>(_scaled_date_ticks.base() - this->last_compression.base() + 1, DAY_TICKS));
|
||||
uint32_t other_age = ClampTo<uint32_t>(CeilDivT<int64_t>(_scaled_date_ticks.base() - other->last_compression.base() + 1, DAY_TICKS));
|
||||
NodeID first = this->Size();
|
||||
this->nodes.reserve(first + other->Size());
|
||||
for (NodeID node1 = 0; node1 < other->Size(); ++node1) {
|
||||
@@ -167,11 +167,11 @@ NodeID LinkGraph::AddNode(const Station *st)
|
||||
* @param usage Usage to be added.
|
||||
* @param mode Update mode to be used.
|
||||
*/
|
||||
static void AddEdge(LinkGraph::BaseEdge &edge, uint capacity, uint usage, uint32 travel_time, EdgeUpdateMode mode)
|
||||
static void AddEdge(LinkGraph::BaseEdge &edge, uint capacity, uint usage, uint32_t travel_time, EdgeUpdateMode mode)
|
||||
{
|
||||
edge.capacity = capacity;
|
||||
edge.usage = usage;
|
||||
edge.travel_time_sum = static_cast<uint64>(travel_time) * capacity;
|
||||
edge.travel_time_sum = static_cast<uint64_t>(travel_time) * capacity;
|
||||
if (mode & EUM_UNRESTRICTED) edge.last_unrestricted_update = _date;
|
||||
if (mode & EUM_RESTRICTED) edge.last_restricted_update = _date;
|
||||
if (mode & EUM_AIRCRAFT) edge.last_aircraft_update = _date;
|
||||
@@ -185,7 +185,7 @@ static void AddEdge(LinkGraph::BaseEdge &edge, uint capacity, uint usage, uint32
|
||||
* @param usage Usage to be added.
|
||||
* @param mode Update mode to be used.
|
||||
*/
|
||||
void LinkGraph::UpdateEdge(NodeID from, NodeID to, uint capacity, uint usage, uint32 travel_time, EdgeUpdateMode mode)
|
||||
void LinkGraph::UpdateEdge(NodeID from, NodeID to, uint capacity, uint usage, uint32_t travel_time, EdgeUpdateMode mode)
|
||||
{
|
||||
assert(capacity > 0);
|
||||
assert(usage <= capacity);
|
||||
@@ -219,7 +219,7 @@ void LinkGraph::RemoveEdge(NodeID from, NodeID to)
|
||||
* @param travel_time Travel time to be added, in ticks.
|
||||
* @param mode Update mode to be applied.
|
||||
*/
|
||||
void LinkGraph::Edge::Update(uint capacity, uint usage, uint32 travel_time, EdgeUpdateMode mode)
|
||||
void LinkGraph::Edge::Update(uint capacity, uint usage, uint32_t travel_time, EdgeUpdateMode mode)
|
||||
{
|
||||
BaseEdge &edge = *(this->edge);
|
||||
assert(edge.capacity > 0);
|
||||
@@ -227,11 +227,11 @@ void LinkGraph::Edge::Update(uint capacity, uint usage, uint32 travel_time, Edge
|
||||
|
||||
if (mode & EUM_INCREASE) {
|
||||
if (edge.travel_time_sum == 0) {
|
||||
edge.travel_time_sum = static_cast<uint64>(edge.capacity + capacity) * travel_time;
|
||||
edge.travel_time_sum = static_cast<uint64_t>(edge.capacity + capacity) * travel_time;
|
||||
} else if (travel_time == 0) {
|
||||
edge.travel_time_sum += (edge.travel_time_sum / edge.capacity) * capacity;
|
||||
} else {
|
||||
edge.travel_time_sum += static_cast<uint64>(travel_time) * capacity;
|
||||
edge.travel_time_sum += static_cast<uint64_t>(travel_time) * capacity;
|
||||
}
|
||||
edge.capacity += capacity;
|
||||
edge.usage += usage;
|
||||
@@ -240,13 +240,13 @@ void LinkGraph::Edge::Update(uint capacity, uint usage, uint32 travel_time, Edge
|
||||
* the capacity increase. */
|
||||
if (capacity > edge.capacity) {
|
||||
if (travel_time == 0) {
|
||||
edge.travel_time_sum = static_cast<uint64>(edge.travel_time_sum / edge.capacity) * capacity;
|
||||
edge.travel_time_sum = static_cast<uint64_t>(edge.travel_time_sum / edge.capacity) * capacity;
|
||||
} else {
|
||||
edge.travel_time_sum += static_cast<uint64>(capacity - edge.capacity) * travel_time;
|
||||
edge.travel_time_sum += static_cast<uint64_t>(capacity - edge.capacity) * travel_time;
|
||||
}
|
||||
edge.capacity = capacity;
|
||||
} else if (edge.travel_time_sum == 0) {
|
||||
edge.travel_time_sum = static_cast<uint64>(travel_time) * edge.capacity;
|
||||
edge.travel_time_sum = static_cast<uint64_t>(travel_time) * edge.capacity;
|
||||
}
|
||||
edge.usage = std::max(edge.usage, usage);
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ public:
|
||||
struct BaseEdge {
|
||||
uint capacity; ///< Capacity of the link.
|
||||
uint usage; ///< Usage of the link.
|
||||
uint64 travel_time_sum; ///< Sum of the travel times of the link, in ticks.
|
||||
uint64_t travel_time_sum; ///< Sum of the travel times of the link, in ticks.
|
||||
Date last_unrestricted_update; ///< When the unrestricted part of the link was last updated.
|
||||
Date last_restricted_update; ///< When the restricted part of the link was last updated.
|
||||
Date last_aircraft_update; ///< When aircraft capacity of the link was last updated.
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
* Get edge's average travel time.
|
||||
* @return Travel time, in ticks.
|
||||
*/
|
||||
uint32 TravelTime() const { return this->edge->travel_time_sum / this->edge->capacity; }
|
||||
uint32_t TravelTime() const { return this->edge->travel_time_sum / this->edge->capacity; }
|
||||
|
||||
/**
|
||||
* Get the date of the last update to the edge's unrestricted capacity.
|
||||
@@ -218,7 +218,7 @@ public:
|
||||
* @param edge Edge to be wrapped.
|
||||
*/
|
||||
Edge(BaseEdge &edge) : EdgeWrapper<BaseEdge>(edge) {}
|
||||
void Update(uint capacity, uint usage, uint32 time, EdgeUpdateMode mode);
|
||||
void Update(uint capacity, uint usage, uint32_t time, EdgeUpdateMode mode);
|
||||
void Restrict() { this->edge->last_unrestricted_update = INVALID_DATE; }
|
||||
void Release() { this->edge->last_restricted_update = INVALID_DATE; }
|
||||
void ClearAircraft() { this->edge->last_aircraft_update = INVALID_DATE; }
|
||||
@@ -365,17 +365,17 @@ public:
|
||||
*/
|
||||
inline uint Monthly(uint base) const
|
||||
{
|
||||
return (static_cast<uint64>(base) * 30 * DAY_TICKS * _settings_game.economy.day_length_factor) / std::max<uint64>((_scaled_date_ticks - this->last_compression).base(), DAY_TICKS);
|
||||
return (static_cast<uint64_t>(base) * 30 * DAY_TICKS * _settings_game.economy.day_length_factor) / std::max<uint64_t>((_scaled_date_ticks - this->last_compression).base(), DAY_TICKS);
|
||||
}
|
||||
|
||||
NodeID AddNode(const Station *st);
|
||||
void RemoveNode(NodeID id);
|
||||
|
||||
void UpdateEdge(NodeID from, NodeID to, uint capacity, uint usage, uint32 time, EdgeUpdateMode mode);
|
||||
void UpdateEdge(NodeID from, NodeID to, uint capacity, uint usage, uint32_t time, EdgeUpdateMode mode);
|
||||
void RemoveEdge(NodeID from, NodeID to);
|
||||
|
||||
inline uint64 CalculateCostEstimate() const {
|
||||
uint64 size_squared = (uint32)this->Size() * (uint32)this->Size();
|
||||
inline uint64_t CalculateCostEstimate() const {
|
||||
uint64_t size_squared = (uint32_t)this->Size() * (uint32_t)this->Size();
|
||||
return size_squared * FindLastBit(size_squared * size_squared); // N^2 * 4log_2(N)
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,7 @@
|
||||
* Colours for the various "load" states of links. Ordered from "unused" to
|
||||
* "overloaded".
|
||||
*/
|
||||
const uint8 LinkGraphOverlay::LINK_COLOURS[][12] = {
|
||||
const uint8_t LinkGraphOverlay::LINK_COLOURS[][12] = {
|
||||
{
|
||||
0x0f, 0xd1, 0xd0, 0x57,
|
||||
0x55, 0x53, 0xbf, 0xbd,
|
||||
@@ -285,11 +285,11 @@ inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixe
|
||||
* See: https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm
|
||||
*/
|
||||
|
||||
const uint8 INSIDE = 0; // 0000
|
||||
const uint8 LEFT = 1; // 0001
|
||||
const uint8 RIGHT = 2; // 0010
|
||||
const uint8 BOTTOM = 4; // 0100
|
||||
const uint8 TOP = 8; // 1000
|
||||
const uint8_t INSIDE = 0; // 0000
|
||||
const uint8_t LEFT = 1; // 0001
|
||||
const uint8_t RIGHT = 2; // 0010
|
||||
const uint8_t BOTTOM = 4; // 0100
|
||||
const uint8_t TOP = 8; // 1000
|
||||
|
||||
int x0 = pta.x;
|
||||
int y0 = pta.y;
|
||||
@@ -297,7 +297,7 @@ inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixe
|
||||
int y1 = ptb.y;
|
||||
|
||||
auto out_code = [&](int x, int y) -> unsigned char {
|
||||
uint8 out = INSIDE;
|
||||
uint8_t out = INSIDE;
|
||||
if (x < left) {
|
||||
out |= LEFT;
|
||||
} else if (x > right) {
|
||||
@@ -311,24 +311,24 @@ inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixe
|
||||
return out;
|
||||
};
|
||||
|
||||
uint8 c0 = out_code(x0, y0);
|
||||
uint8 c1 = out_code(x1, y1);
|
||||
uint8_t c0 = out_code(x0, y0);
|
||||
uint8_t c1 = out_code(x1, y1);
|
||||
|
||||
while (true) {
|
||||
if (c0 == 0 || c1 == 0) return true;
|
||||
if ((c0 & c1) != 0) return false;
|
||||
|
||||
if (c0 & TOP) { // point 0 is above the clip window
|
||||
x0 = x0 + (int)(((int64) (x1 - x0)) * ((int64) (top - y0)) / ((int64) (y1 - y0)));
|
||||
x0 = x0 + (int)(((int64_t) (x1 - x0)) * ((int64_t) (top - y0)) / ((int64_t) (y1 - y0)));
|
||||
y0 = top;
|
||||
} else if (c0 & BOTTOM) { // point 0 is below the clip window
|
||||
x0 = x0 + (int)(((int64) (x1 - x0)) * ((int64) (bottom - y0)) / ((int64) (y1 - y0)));
|
||||
x0 = x0 + (int)(((int64_t) (x1 - x0)) * ((int64_t) (bottom - y0)) / ((int64_t) (y1 - y0)));
|
||||
y0 = bottom;
|
||||
} else if (c0 & RIGHT) { // point 0 is to the right of clip window
|
||||
y0 = y0 + (int)(((int64) (y1 - y0)) * ((int64) (right - x0)) / ((int64) (x1 - x0)));
|
||||
y0 = y0 + (int)(((int64_t) (y1 - y0)) * ((int64_t) (right - x0)) / ((int64_t) (x1 - x0)));
|
||||
x0 = right;
|
||||
} else if (c0 & LEFT) { // point 0 is to the left of clip window
|
||||
y0 = y0 + (int)(((int64) (y1 - y0)) * ((int64) (left - x0)) / ((int64) (x1 - x0)));
|
||||
y0 = y0 + (int)(((int64_t) (y1 - y0)) * ((int64_t) (left - x0)) / ((int64_t) (x1 - x0)));
|
||||
x0 = left;
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixe
|
||||
* @param new_shared If the new link is shared.
|
||||
* @param cargo LinkProperties to write the information to.
|
||||
*/
|
||||
/* static */ void LinkGraphOverlay::AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_plan, uint32 time, bool new_shared, LinkProperties &cargo)
|
||||
/* static */ void LinkGraphOverlay::AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_plan, uint32_t time, bool new_shared, LinkProperties &cargo)
|
||||
{
|
||||
/* multiply the numbers by 32 in order to avoid comparing to 0 too often. */
|
||||
if (cargo.capacity == 0 ||
|
||||
@@ -505,8 +505,8 @@ bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond)
|
||||
|
||||
/* Check the distance from the cursor to the line defined by the two stations. */
|
||||
auto check_distance = [&]() -> bool {
|
||||
int64 a = ((int64)(ptb.x - pta.x) * (int64)(pta.y - pt.y) - (int64)(pta.x - pt.x) * (int64)(ptb.y - pta.y));
|
||||
int64 b = ((int64)(ptb.x - pta.x) * (int64)(ptb.x - pta.x) + (int64)(ptb.y - pta.y) * (int64)(ptb.y - pta.y));
|
||||
int64_t a = ((int64_t)(ptb.x - pta.x) * (int64_t)(pta.y - pt.y) - (int64_t)(pta.x - pt.x) * (int64_t)(ptb.y - pta.y));
|
||||
int64_t b = ((int64_t)(ptb.x - pta.x) * (int64_t)(ptb.x - pta.x) + (int64_t)(ptb.y - pta.y) * (int64_t)(ptb.y - pta.y));
|
||||
if (b == 0) return false;
|
||||
return ((a * a) / b) <= 16;
|
||||
};
|
||||
@@ -522,7 +522,7 @@ bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond)
|
||||
StringBuilder builder(buf);
|
||||
buf[0] = 0;
|
||||
|
||||
auto add_travel_time = [&](uint32 time) {
|
||||
auto add_travel_time = [&](uint32_t time) {
|
||||
if (time > 0) {
|
||||
if (_settings_time.time_in_minutes) {
|
||||
SetDParam(0, STR_TIMETABLE_MINUTES);
|
||||
@@ -556,7 +556,7 @@ bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond)
|
||||
}
|
||||
|
||||
/* Fill buf with more information if this is a bidirectional link. */
|
||||
uint32 back_time = 0;
|
||||
uint32_t back_time = 0;
|
||||
for (LinkList::const_reverse_iterator j = std::next(i); j != this->cached_links.rend(); ++j) {
|
||||
if (j->from_id == i->to_id && j->to_id == i->from_id) {
|
||||
back_time = j->prop.time;
|
||||
@@ -586,7 +586,7 @@ bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond)
|
||||
uint dx = Delta(TileX(t0), TileX(t1));
|
||||
uint dy = Delta(TileY(t0), TileY(t1));
|
||||
SetDParam(0, DistanceManhattan(t0, t1));
|
||||
SetDParam(1, IntSqrt64(((uint64)dx * (uint64)dx) + ((uint64)dy * (uint64)dy))); // Avoid overflow in DistanceSquare
|
||||
SetDParam(1, IntSqrt64(((uint64_t)dx * (uint64_t)dx) + ((uint64_t)dy * (uint64_t)dy))); // Avoid overflow in DistanceSquare
|
||||
GetString(builder, STR_LINKGRAPH_STATS_TOOLTIP_DISTANCE);
|
||||
}
|
||||
|
||||
@@ -807,7 +807,7 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, WidgetID widget) const
|
||||
DrawCompanyIcon(cid, CenterBounds(br.left, br.right, sprite_size.width), CenterBounds(br.top, br.bottom, sprite_size.height));
|
||||
}
|
||||
if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) {
|
||||
uint8 colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][widget - WID_LGL_SATURATION_FIRST];
|
||||
uint8_t colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][widget - WID_LGL_SATURATION_FIRST];
|
||||
GfxFillRect(br, colour);
|
||||
StringID str = STR_NULL;
|
||||
if (widget == WID_LGL_SATURATION_FIRST) {
|
||||
@@ -854,7 +854,7 @@ bool LinkGraphLegendWindow::OnTooltip([[maybe_unused]] Point, WidgetID widget, T
|
||||
*/
|
||||
void LinkGraphLegendWindow::UpdateOverlayCompanies()
|
||||
{
|
||||
uint32 mask = 0;
|
||||
uint32_t mask = 0;
|
||||
for (uint c = 0; c < MAX_COMPANIES; c++) {
|
||||
if (this->IsWidgetDisabled(c + WID_LGL_COMPANY_FIRST)) continue;
|
||||
if (!this->IsWidgetLowered(c + WID_LGL_COMPANY_FIRST)) continue;
|
||||
|
@@ -32,7 +32,7 @@ struct LinkProperties {
|
||||
uint usage; ///< Actual usage of the link.
|
||||
uint planned; ///< Planned usage of the link.
|
||||
CargoID cargo; ///< Cargo type of the link.
|
||||
uint32 time; ///< Travel time of the link.
|
||||
uint32_t time; ///< Travel time of the link.
|
||||
bool shared; ///< If this is a shared link to be drawn dashed.
|
||||
};
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
typedef std::vector<StationSupplyInfo> StationSupplyList;
|
||||
typedef std::vector<LinkInfo> LinkList;
|
||||
|
||||
static const uint8 LINK_COLOURS[][12];
|
||||
static const uint8_t LINK_COLOURS[][12];
|
||||
|
||||
/**
|
||||
* Create a link graph overlay for the specified window.
|
||||
@@ -102,7 +102,7 @@ protected:
|
||||
Rect cached_region; ///< Region covered by cached_links and cached_stations.
|
||||
uint scale; ///< Width of link lines.
|
||||
bool dirty; ///< Set if overlay should be rebuilt.
|
||||
uint64 last_update_number = 0; ///< Last window update number
|
||||
uint64_t last_update_number = 0; ///< Last window update number
|
||||
|
||||
Point GetStationMiddle(const Station *st) const;
|
||||
|
||||
@@ -114,7 +114,7 @@ protected:
|
||||
bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const;
|
||||
void GetWidgetDpi(DrawPixelInfo *dpi, uint margin = 0) const;
|
||||
|
||||
static void AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_plan, uint32 time, bool new_shared, LinkProperties &cargo);
|
||||
static void AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_plan, uint32_t time, bool new_shared, LinkProperties &cargo);
|
||||
static void DrawVertex(const DrawPixelInfo *dpi, int x, int y, int size, int colour, int border_colour);
|
||||
};
|
||||
|
||||
|
@@ -10,13 +10,13 @@
|
||||
#ifndef LINKGRAPH_TYPE_H
|
||||
#define LINKGRAPH_TYPE_H
|
||||
|
||||
typedef uint16 LinkGraphID;
|
||||
typedef uint16_t LinkGraphID;
|
||||
static const LinkGraphID INVALID_LINK_GRAPH = UINT16_MAX;
|
||||
|
||||
typedef uint16 LinkGraphJobID;
|
||||
typedef uint16_t LinkGraphJobID;
|
||||
static const LinkGraphJobID INVALID_LINK_GRAPH_JOB = UINT16_MAX;
|
||||
|
||||
typedef uint16 NodeID;
|
||||
typedef uint16_t NodeID;
|
||||
static const NodeID INVALID_NODE = UINT16_MAX;
|
||||
|
||||
enum DistributionType : byte {
|
||||
|
@@ -100,7 +100,7 @@ void LinkGraphJob::FinaliseJob()
|
||||
/* Link graph has been merged into another one. */
|
||||
if (!LinkGraph::IsValidID(this->link_graph.index)) return;
|
||||
|
||||
uint16 size = this->Size();
|
||||
uint16_t size = this->Size();
|
||||
for (NodeID node_id = 0; node_id < size; ++node_id) {
|
||||
Node from = (*this)[node_id];
|
||||
|
||||
@@ -203,7 +203,7 @@ void LinkGraphJob::Init()
|
||||
* and the shortest route for other classes of cargo.
|
||||
* In-between stops are punished with a 1 tile or 1 day penalty. */
|
||||
const bool express = IsLinkGraphCargoExpress(this->Cargo());
|
||||
const uint16 aircraft_link_scale = this->Settings().aircraft_link_scale;
|
||||
const uint16_t aircraft_link_scale = this->Settings().aircraft_link_scale;
|
||||
|
||||
size_t edge_count = 0;
|
||||
for (auto &it : this->link_graph.GetEdges()) {
|
||||
|
@@ -50,7 +50,7 @@ void LinkGraphSchedule::SpawnNext()
|
||||
if (this->schedule.empty()) return;
|
||||
|
||||
GraphList schedule_to_back;
|
||||
uint64 total_cost = 0;
|
||||
uint64_t total_cost = 0;
|
||||
for (auto iter = this->schedule.begin(); iter != this->schedule.end();) {
|
||||
auto current = iter;
|
||||
++iter;
|
||||
@@ -65,17 +65,17 @@ void LinkGraphSchedule::SpawnNext()
|
||||
for (auto &it : this->running) {
|
||||
total_cost += it->Graph().CalculateCostEstimate();
|
||||
}
|
||||
uint64 clamped_total_cost = std::min<uint64>(total_cost, 1 << 25);
|
||||
uint64_t clamped_total_cost = std::min<uint64_t>(total_cost, 1 << 25);
|
||||
uint log2_clamped_total_cost = FindLastBit(clamped_total_cost);
|
||||
uint scaling = log2_clamped_total_cost > 13 ? log2_clamped_total_cost - 12 : 1;
|
||||
uint64 cost_budget = clamped_total_cost / scaling;
|
||||
uint64 used_budget = 0;
|
||||
uint64_t cost_budget = clamped_total_cost / scaling;
|
||||
uint64_t used_budget = 0;
|
||||
std::vector<LinkGraphJobGroup::JobInfo> jobs_to_execute;
|
||||
while (used_budget < cost_budget && !this->schedule.empty()) {
|
||||
LinkGraph *lg = this->schedule.front();
|
||||
assert(lg == LinkGraph::Get(lg->index));
|
||||
this->schedule.pop_front();
|
||||
uint64 cost = lg->CalculateCostEstimate();
|
||||
uint64_t cost = lg->CalculateCostEstimate();
|
||||
used_budget += cost;
|
||||
if (LinkGraphJob::CanAllocateItem()) {
|
||||
uint duration_multiplier = CeilDivT<uint64_t>(lg->Size(), 75);
|
||||
|
@@ -517,7 +517,7 @@ bool MCF1stPass::EliminateCycles(PathVector &path, NodeID origin_id, NodeID next
|
||||
bool MCF1stPass::EliminateCycles()
|
||||
{
|
||||
bool cycles_found = false;
|
||||
uint16 size = this->job.Size();
|
||||
uint16_t size = this->job.Size();
|
||||
PathVector path(size, nullptr);
|
||||
for (NodeID node = 0; node < size; ++node) {
|
||||
/* Starting at each node in the graph find all cycles involving this
|
||||
@@ -535,7 +535,7 @@ bool MCF1stPass::EliminateCycles()
|
||||
MCF1stPass::MCF1stPass(LinkGraphJob &job) : MultiCommodityFlow(job)
|
||||
{
|
||||
PathVector paths;
|
||||
uint16 size = job.Size();
|
||||
uint16_t size = job.Size();
|
||||
uint accuracy = job.Settings().accuracy;
|
||||
bool more_loops;
|
||||
std::vector<bool> finished_sources(size);
|
||||
@@ -543,7 +543,7 @@ MCF1stPass::MCF1stPass(LinkGraphJob &job) : MultiCommodityFlow(job)
|
||||
uint min_step_size = 1;
|
||||
const uint adjust_threshold = 50;
|
||||
if (size >= adjust_threshold) {
|
||||
uint64 total_demand = 0;
|
||||
uint64_t total_demand = 0;
|
||||
uint demand_count = 0;
|
||||
for (NodeID source = 0; source < size; ++source) {
|
||||
const Node &node = job[source];
|
||||
@@ -603,7 +603,7 @@ MCF2ndPass::MCF2ndPass(LinkGraphJob &job) : MultiCommodityFlow(job)
|
||||
{
|
||||
this->max_saturation = UINT_MAX; // disable artificial cap on saturation
|
||||
PathVector paths;
|
||||
uint16 size = job.Size();
|
||||
uint16_t size = job.Size();
|
||||
uint accuracy = job.Settings().accuracy;
|
||||
bool demand_left = true;
|
||||
std::vector<bool> finished_sources(size);
|
||||
|
@@ -55,7 +55,7 @@
|
||||
HopSet seen_hops;
|
||||
LinkRefresher refresher(v, &seen_hops, allow_merge, is_full_loading, iter_cargo_mask);
|
||||
|
||||
uint8 flags = 0;
|
||||
uint8_t flags = 0;
|
||||
if (iter_cargo_mask & have_cargo_mask) flags |= 1 << HAS_CARGO;
|
||||
if (v->type == VEH_AIRCRAFT) flags |= 1 << AIRCRAFT;
|
||||
refresher.RefreshLinks(first, first, { 0, TTT_NO_WAIT_TIME }, flags);
|
||||
@@ -116,7 +116,7 @@ bool LinkRefresher::HandleRefit(CargoID refit_cargo)
|
||||
v->cargo_subtype = GetBestFittingSubType(v, v, this->cargo);
|
||||
}
|
||||
|
||||
uint16 mail_capacity = 0;
|
||||
uint16_t mail_capacity = 0;
|
||||
uint amount = e->DetermineCapacity(v, &mail_capacity);
|
||||
|
||||
/* Restore the original cargo type */
|
||||
@@ -228,7 +228,7 @@ LinkRefresher::TimetableTravelTime LinkRefresher::UpdateTimetableTravelSoFar(con
|
||||
* @param num_hops Number of hops already taken by recursive calls to this method.
|
||||
* @return new next Order, and travel time so far.
|
||||
*/
|
||||
std::pair<const Order *, LinkRefresher::TimetableTravelTime> LinkRefresher::PredictNextOrder(const Order *cur, const Order *next, LinkRefresher::TimetableTravelTime travel, uint8 flags, uint num_hops)
|
||||
std::pair<const Order *, LinkRefresher::TimetableTravelTime> LinkRefresher::PredictNextOrder(const Order *cur, const Order *next, LinkRefresher::TimetableTravelTime travel, uint8_t flags, uint num_hops)
|
||||
{
|
||||
/* 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
|
||||
@@ -298,7 +298,7 @@ std::pair<const Order *, LinkRefresher::TimetableTravelTime> LinkRefresher::Pred
|
||||
* @param travel_estimate Estimated travel time, only valid if non-zero.
|
||||
* @param flags RefreshFlags to give hints about the previous link and state carried over from that.
|
||||
*/
|
||||
void LinkRefresher::RefreshStats(const Order *cur, const Order *next, uint32 travel_estimate, uint8 flags)
|
||||
void LinkRefresher::RefreshStats(const Order *cur, const Order *next, uint32_t travel_estimate, uint8_t flags)
|
||||
{
|
||||
StationID next_station = next->GetDestination();
|
||||
Station *st = Station::GetIfValid(cur->GetDestination());
|
||||
@@ -326,13 +326,13 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next, uint32 tra
|
||||
/* This estimates the travel time of the link as the time needed
|
||||
* to travel between the stations at half the max speed of the consist.
|
||||
* The result is in tiles/tick (= 2048 km-ish/h). */
|
||||
uint32 time_estimate = DistanceManhattan(st->xy, st_to->xy) * 4096U / this->vehicle->GetDisplayMaxSpeed();
|
||||
uint32_t time_estimate = DistanceManhattan(st->xy, st_to->xy) * 4096U / this->vehicle->GetDisplayMaxSpeed();
|
||||
|
||||
if (travel_estimate > 0) {
|
||||
/* If a timetable-based time is available, use that, clamping it to be in the range (estimate / 3, estimate * 2)
|
||||
* of the distance/speed based estimate.
|
||||
* This is effectively clamping it to be within the estimated speed range: (max_speed / 4, max_speed * 1.5). */
|
||||
time_estimate = Clamp<uint32>(travel_estimate, time_estimate / 3, time_estimate * 2);
|
||||
time_estimate = Clamp<uint32_t>(travel_estimate, time_estimate / 3, time_estimate * 2);
|
||||
}
|
||||
|
||||
if (HasBit(flags, AIRCRAFT)) restricted_mode |= EUM_AIRCRAFT;
|
||||
@@ -375,7 +375,7 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next, uint32 tra
|
||||
* @param flags RefreshFlags to give hints about the previous link and state carried over from that.
|
||||
* @param num_hops Number of hops already taken by recursive calls to this method.
|
||||
*/
|
||||
void LinkRefresher::RefreshLinks(const Order *cur, const Order *next, TimetableTravelTime travel, uint8 flags, uint num_hops)
|
||||
void LinkRefresher::RefreshLinks(const Order *cur, const Order *next, TimetableTravelTime travel, uint8_t flags, uint num_hops)
|
||||
{
|
||||
while (next != nullptr) {
|
||||
|
||||
@@ -429,7 +429,7 @@ void LinkRefresher::RefreshLinks(const Order *cur, const Order *next, TimetableT
|
||||
if (cur->IsType(OT_GOTO_STATION) || cur->IsType(OT_IMPLICIT)) {
|
||||
if (cur->CanLeaveWithCargo(HasBit(flags, HAS_CARGO), FindFirstBit(this->cargo_mask))) {
|
||||
SetBit(flags, HAS_CARGO);
|
||||
this->RefreshStats(cur, next, ((travel.flags & TTT_INVALID) == 0 && travel.time_so_far > 0) ? (uint32)travel.time_so_far : 0, flags);
|
||||
this->RefreshStats(cur, next, ((travel.flags & TTT_INVALID) == 0 && travel.time_so_far > 0) ? (uint32_t)travel.time_so_far : 0, flags);
|
||||
} else {
|
||||
ClrBit(flags, HAS_CARGO);
|
||||
}
|
||||
|
@@ -41,10 +41,10 @@ protected:
|
||||
* Simulated cargo type and capacity for prediction of future links.
|
||||
*/
|
||||
struct RefitDesc {
|
||||
CargoID cargo; ///< Cargo type the vehicle will be carrying.
|
||||
uint16 capacity; ///< Capacity the vehicle will have.
|
||||
uint16 remaining; ///< Capacity remaining from before the previous refit.
|
||||
RefitDesc(CargoID cargo, uint16 capacity, uint16 remaining) :
|
||||
CargoID cargo; ///< Cargo type the vehicle will be carrying.
|
||||
uint16_t capacity; ///< Capacity the vehicle will have.
|
||||
uint16_t remaining; ///< Capacity remaining from before the previous refit.
|
||||
RefitDesc(CargoID cargo, uint16_t capacity, uint16_t remaining) :
|
||||
cargo(cargo), capacity(capacity), remaining(remaining) {}
|
||||
};
|
||||
|
||||
@@ -61,7 +61,7 @@ protected:
|
||||
OrderID from; ///< Last order where vehicle could interact with cargo or absolute first order.
|
||||
OrderID to; ///< Next order to be processed.
|
||||
CargoID cargo; ///< Cargo the consist is probably carrying or CT_INVALID if unknown.
|
||||
uint8 flags; ///< Flags, for branches
|
||||
uint8_t flags; ///< Flags, for branches
|
||||
|
||||
/**
|
||||
* Default constructor should not be called but has to be visible for
|
||||
@@ -75,7 +75,7 @@ protected:
|
||||
* @param to Second order of the hop.
|
||||
* @param cargo Cargo the consist is probably carrying when passing the hop.
|
||||
*/
|
||||
Hop(OrderID from, OrderID to, CargoID cargo, uint8 flags = 0) : from(from), to(to), cargo(cargo), flags(flags) {}
|
||||
Hop(OrderID from, OrderID to, CargoID cargo, uint8_t flags = 0) : from(from), to(to), cargo(cargo), flags(flags) {}
|
||||
bool operator<(const Hop &other) const { return std::tie(this->from, this->to, this->cargo, this->flags) < std::tie(other.from, other.to, other.cargo, other.flags); }
|
||||
bool operator==(const Hop &other) const { return std::tie(this->from, this->to, this->cargo, this->flags) == std::tie(other.from, other.to, other.cargo, other.flags); }
|
||||
bool operator!=(const Hop &other) const { return !(*this == other); }
|
||||
@@ -110,11 +110,11 @@ protected:
|
||||
|
||||
bool HandleRefit(CargoID refit_cargo);
|
||||
void ResetRefit();
|
||||
void RefreshStats(const Order *cur, const Order *next,uint32 travel_estimate, uint8 flags);
|
||||
void RefreshStats(const Order *cur, const Order *next,uint32_t travel_estimate, uint8_t flags);
|
||||
TimetableTravelTime UpdateTimetableTravelSoFar(const Order *from, const Order *to, TimetableTravelTime travel);
|
||||
std::pair<const Order *, TimetableTravelTime> PredictNextOrder(const Order *cur, const Order *next, TimetableTravelTime travel, uint8 flags, uint num_hops = 0);
|
||||
std::pair<const Order *, TimetableTravelTime> PredictNextOrder(const Order *cur, const Order *next, TimetableTravelTime travel, uint8_t flags, uint num_hops = 0);
|
||||
|
||||
void RefreshLinks(const Order *cur, const Order *next, TimetableTravelTime travel, uint8 flags, uint num_hops = 0);
|
||||
void RefreshLinks(const Order *cur, const Order *next, TimetableTravelTime travel, uint8_t flags, uint num_hops = 0);
|
||||
};
|
||||
|
||||
#endif /* REFRESH_H */
|
||||
|
Reference in New Issue
Block a user