summaryrefslogtreecommitdiff
path: root/src/linkgraph/demands.h
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2013-06-09 12:59:51 +0000
committerfonsinchen <fonsinchen@openttd.org>2013-06-09 12:59:51 +0000
commit6a46b5262fa9b5b2de220353eec72d58c7e4484d (patch)
tree1b71a1bda22791f1728654af830e9dcade960204 /src/linkgraph/demands.h
parentc32eea02dd2de11636f5182a38fc8d577ff1f457 (diff)
downloadopenttd-6a46b5262fa9b5b2de220353eec72d58c7e4484d.tar.xz
(svn r25355) -Add: demand handler for link graph
Diffstat (limited to 'src/linkgraph/demands.h')
-rw-r--r--src/linkgraph/demands.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/linkgraph/demands.h b/src/linkgraph/demands.h
new file mode 100644
index 000000000..c3d9dc7cd
--- /dev/null
+++ b/src/linkgraph/demands.h
@@ -0,0 +1,43 @@
+/** @file demands.h Declaration of demand calculating link graph handler. */
+
+#ifndef DEMANDS_H
+#define DEMANDS_H
+
+#include "linkgraphjob_base.h"
+
+/**
+ * Calculate the demands. This class has a state, but is recreated for each
+ * call to of DemandHandler::Run.
+ */
+class DemandCalculator {
+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.
+
+ template<class Tscaler>
+ void CalcDemand(LinkGraphJob &job, Tscaler scaler);
+};
+
+/**
+ * Stateless, thread safe demand hander. Doesn't do anything but call DemandCalculator.
+ */
+class DemandHandler : public ComponentHandler {
+public:
+
+ /**
+ * Call the demand calculator on the given component.
+ * @param graph Component to calculate the demands for.
+ */
+ virtual void Run(LinkGraphJob &job) const { DemandCalculator c(job); }
+
+ /**
+ * Virtual destructor has to be defined because of virtual Run().
+ */
+ virtual ~DemandHandler() {}
+};
+
+#endif /* DEMANDS_H */