chiark / gitweb /
before throw away copy-without-segments-of-this-train
[trains.git] / hostside / safety.h
1 /**/
2
3 #ifndef SAFETY_H
4 #define SAFETY_H
5
6 typedef unsigned short TrainIx;
7 typedef unsigned short SegmentIx;
8 typedef unsigned short LocationIx;
9 typedef short Distance;
10 typedef char Speed; /* non-negative, units of 4mm/s */
11
12 typedef struct {
13   SegmentIx foredetect;
14   unsigned
15     justarrived:1, /* is stopped just after triggering foredetect segment */
16     reverse:1; /* train is moving backwards wrt its own front and back */
17   Speed speed;
18 } TrainState;
19
20 typedef struct {
21   unsigned
22     present_now:1, present_future:1, /* owning train is or will use space */
23     detectable_now:1, detectable_future:1, /* owning train draws current */
24     reverse:1, /* owning train's motion is (would be) backwards wrt track */
25     sideways:1, /* for segment with points, points are set to `alternative' */
26     autostop:1, /* owning train is slow and wants to stop on detection */
27     updated:1; /* for use by safety_train_changed etc.; otherwise 0 */
28   /*polarity?*/
29 } SegmentState;
30
31 typedef struct {
32   unsigned next_rev:1;
33   SegmentIx next;
34   SegmentIx clashing;
35   Distance dist;
36 } SegmentLink;
37
38 typedef struct {
39   SegmentLink backwards, forwards, sideways;
40 } SegmentInfo;
41
42 typedef struct {
43   Speed maxspeed;
44   Distance tail, detectable, head;
45 } TrainInfo;
46
47
48 typedef struct {
49   TrainState trasNUM_TRAINS];
50   SegmentState segs[NUM_SEGMENTS];
51 } State;
52
53 #endif /*SAFETY_H*/