diff options
| -rw-r--r-- | advtrains/path.lua | 91 | ||||
| -rw-r--r-- | advtrains/trainlogic.lua | 3 |
2 files changed, 61 insertions, 33 deletions
diff --git a/advtrains/path.lua b/advtrains/path.lua index 825e59b..ff034c9 100644 --- a/advtrains/path.lua +++ b/advtrains/path.lua @@ -17,12 +17,18 @@ -- path_cn - Connid of the current node that points towards path[i+1] -- path_cp - Connid of the current node that points towards path[i-1] -- When the day comes on that path!=node, these will only be set if this index represents a transition between rail nodes --- path_dist - The distance (in meters) between this (path[i]) and the next (path[i+1]) item of the path +-- path_dist - The total distance of this path element from path element 0 -- path_dir - The direction of this path item's transition to the next path item, which is the angle of conns[path_cn[i]].c --Variables: -- path_ext_f/b - how far path[i] is set -- path_trk_f/b - how far the path extends along a track. beyond those values, paths are generated in a straight line. -- path_req_f/b - how far path items were requested in the last step +-- +--Distance and index: +-- There is an important difference between the path index and the actual distance on the track: The distance between two path items can be larger than 1, +-- but the corresponding index increment is still 1. +-- Indexes in advtrains can be fractional values. If they are, it means that the actual position is interpolated between the 2 adjacent path items. +-- If you need to proceed along the path by a specific actual distance, it does NOT work to simply add it to the index. You should use the path_get_index_by_offset() function. -- creates the path data structure, reconstructing the train from a position and a connid -- Important! train.drives_on must exist while calling this method @@ -40,7 +46,7 @@ function advtrains.path_create(train, pos, connid, rel_index) train.path = { [0] = { x=posr.x, y=posr.y+rhe, z=posr.z } } train.path_cn = { [0] = connid } train.path_cp = { [0] = mconnid } - train.path_dist = {} + train.path_dist = { [0] = 0 } train.path_dir = { [0] = advtrains.conn_angle_median(conns[mconnid].c, conns[connid].c) @@ -135,12 +141,12 @@ function advtrains.path_print(train, printf) printf("path_print: Path is invalidated/inexistant.") return end - printf("i: CP Position Dir CN ->Dist->") + printf("i: CP Position Dir CN Dist") for i = train.path_ext_b, train.path_ext_f do if i==train.path_trk_b then printf("--Back on-track border here--") end - printf(i,": ",train.path_cp[i]," ",train.path[i]," ",train.path_dir[i]," ",train.path_cn[i]," ->",train.path_dist[i],"->") + printf(i,": ",train.path_cp[i]," ",train.path[i]," ",tra
wield_position.Z = 65
The QUICKTUNE macros shouldn't generally be left in committed code.
*/
#ifndef QUICKTUNE_HEADER
#define QUICKTUNE_HEADER
#include <string>
#include <map>
#include <vector>
enum QuicktuneValueType{
QVT_NONE,
QVT_FLOAT
};
struct QuicktuneValue
{
QuicktuneValueType type;
union{
struct{
float current;
float min;
float max;
} value_QVT_FLOAT;
};
bool modified;
QuicktuneValue():
type(QVT_NONE),
modified(false)
{}
std::string getString();
void relativeAdd(float amount);
};
std::vector<std::string> getQuicktuneNames();
QuicktuneValue getQuicktuneValue(const std::string &name);
void setQuicktuneValue(const std::string &name, const QuicktuneValue &val);
void updateQuicktuneValue(const std::string &name, QuicktuneValue &val);
#ifndef NDEBUG
#define QUICKTUNE(type_, var, min_, max_, name){\
QuicktuneValue qv;\
qv.type = type_;\
qv.value_##type_.current = var;\
qv.value_##type_.min = min_;\
qv.value_##type_.max = max_;\
updateQuicktuneValue(name, qv);\
var = qv.value_##type_.current;\
}
#else // NDEBUG
#define QUICKTUNE(type, var, min_, max_, name){}
#endif
#define QUICKTUNE_AUTONAME(type_, var, min_, max_)\
QUICKTUNE(type_, var, min_, max_, #var)
#endif
|
