@@ -42,6 +42,11 @@ public class Transfertable : MovingTable
42
42
{
43
43
public float Span ; // horizontal or vertical
44
44
public List < float > Offsets = new List < float > ( ) ;
45
+ private bool VerticalTransfer = false ;
46
+ public float CenterOffsetComponent
47
+ {
48
+ get => VerticalTransfer ? CenterOffset . Y : CenterOffset . X ;
49
+ }
45
50
// Dynamic data
46
51
public bool Forward ; // forward motion on
47
52
public bool Reverse ; // reverse motion on
@@ -53,49 +58,32 @@ public class Transfertable : MovingTable
53
58
54
59
public Signals signalRef { get ; protected set ; }
55
60
56
- public virtual float CenterOffsetComponent { get => CenterOffset . X ; }
57
-
58
- protected Transfertable ( STFReader stf , Simulator simulator ) : base ( stf , simulator ) { }
59
-
60
- public static Transfertable CreateFrom ( STFReader stf , Simulator simulator )
61
+ public Transfertable ( STFReader stf , Simulator simulator ) : base ( stf , simulator )
61
62
{
62
- var worldPosition = new WorldPosition ( ) ;
63
- worldPosition . XNAMatrix . M44 = 100000000 ; //WorlPosition not yet defined, will be loaded when loading related tile
64
- var wFile = "" ;
65
- var uid = - 1 ;
66
- var animations = new List < string > ( ) ;
67
- var isVertical = false ;
68
- var length = 0f ;
69
- var centerOffset = new Vector3 ( ) ;
70
- var trackShapeIndex = - 1 ;
71
-
63
+ signalRef = Simulator . Signals ;
64
+ string animation ;
65
+ WorldPosition . XNAMatrix . M44 = 100000000 ; //WorlPosition not yet defined, will be loaded when loading related tile
72
66
stf . MustMatch ( "(" ) ;
73
67
stf . ParseBlock ( new [ ] {
74
68
new STFReader . TokenProcessor ( "wfile" , ( ) => {
75
- wFile = stf . ReadStringBlock ( null ) ;
76
- worldPosition . TileX = int . Parse ( wFile . Substring ( 1 , 7 ) ) ;
77
- worldPosition . TileZ = int . Parse ( wFile . Substring ( 8 , 7 ) ) ;
69
+ WFile = stf . ReadStringBlock ( null ) ;
70
+ WorldPosition . TileX = int . Parse ( WFile . Substring ( 1 , 7 ) ) ;
71
+ WorldPosition . TileZ = int . Parse ( WFile . Substring ( 8 , 7 ) ) ;
72
+ } ) ,
73
+ new STFReader . TokenProcessor ( "uid" , ( ) => { UID = stf . ReadIntBlock ( - 1 ) ; } ) ,
74
+ new STFReader . TokenProcessor ( "animation" , ( ) => { animation = stf . ReadStringBlock ( null ) ;
75
+ Animations . Add ( animation . ToLower ( ) ) ; } ) ,
76
+ new STFReader . TokenProcessor ( "verticaltransfer" , ( ) => { VerticalTransfer = stf . ReadBoolBlock ( false ) ; } ) ,
77
+ new STFReader . TokenProcessor ( "length" , ( ) => { Length = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
78
+ new STFReader . TokenProcessor ( "xoffset" , ( ) => { CenterOffset . X = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
79
+ new STFReader . TokenProcessor ( "zoffset" , ( ) => { CenterOffset . Z = - stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
80
+ new STFReader . TokenProcessor ( "yoffset" , ( ) => { CenterOffset . Y = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
81
+ new STFReader . TokenProcessor ( "trackshapeindex" , ( ) =>
82
+ {
83
+ TrackShapeIndex = stf . ReadIntBlock ( - 1 ) ;
84
+ InitializeOffsetsAndTrackNodes ( ) ;
78
85
} ) ,
79
- new STFReader . TokenProcessor ( "uid" , ( ) => { uid = stf . ReadIntBlock ( null ) ; } ) ,
80
- new STFReader . TokenProcessor ( "animation" , ( ) => { var animation = stf . ReadStringBlock ( null ) ;
81
- animations . Add ( animation . ToLower ( ) ) ; } ) ,
82
- new STFReader . TokenProcessor ( "verticaltransfer" , ( ) => { isVertical = stf . ReadBoolBlock ( isVertical ) ; } ) ,
83
- new STFReader . TokenProcessor ( "length" , ( ) => { length = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
84
- new STFReader . TokenProcessor ( "xoffset" , ( ) => { centerOffset . X = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
85
- new STFReader . TokenProcessor ( "zoffset" , ( ) => { centerOffset . Z = - stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
86
- new STFReader . TokenProcessor ( "yoffset" , ( ) => { centerOffset . Y = stf . ReadFloatBlock ( STFReader . UNITS . None , null ) ; } ) ,
87
- new STFReader . TokenProcessor ( "trackshapeindex" , ( ) => { trackShapeIndex = stf . ReadIntBlock ( null ) ; } ) ,
88
86
} ) ;
89
-
90
- var table = isVertical ? new VerticalTransfertable ( null , simulator ) : new Transfertable ( null , simulator ) ;
91
- table . signalRef = table . Simulator . Signals ;
92
- table . WorldPosition = worldPosition ;
93
- table . UID = uid ;
94
- table . Animations . AddRange ( animations ) ;
95
- table . CenterOffset = centerOffset ;
96
- table . TrackShapeIndex = trackShapeIndex ;
97
- table . InitializeOffsetsAndTrackNodes ( ) ;
98
- return table ;
99
87
}
100
88
101
89
/// <summary>
@@ -131,7 +119,7 @@ public override void Restore(BinaryReader inf, Simulator simulator)
131
119
TargetOffset = inf . ReadSingle ( ) ;
132
120
}
133
121
134
- protected virtual void InitializeOffsetsAndTrackNodes ( )
122
+ protected void InitializeOffsetsAndTrackNodes ( )
135
123
{
136
124
var trackShape = Simulator . TSectionDat . TrackShapes . Get ( ( uint ) TrackShapeIndex ) ;
137
125
var nSections = trackShape . SectionIdxs [ 0 ] . NoSections ;
@@ -141,7 +129,7 @@ protected virtual void InitializeOffsetsAndTrackNodes()
141
129
var iMyTrackNodes = 0 ;
142
130
foreach ( var sectionIdx in trackShape . SectionIdxs )
143
131
{
144
- Offsets . Add ( ( float ) sectionIdx . X ) ;
132
+ Offsets . Add ( VerticalTransfer ? ( float ) sectionIdx . Y : ( float ) sectionIdx . X ) ;
145
133
MyTrackNodesIndex [ iMyTrackNodes ] = - 1 ;
146
134
MyTrVectorSectionsIndex [ iMyTrackNodes ] = - 1 ;
147
135
iMyTrackNodes ++ ;
@@ -167,9 +155,16 @@ protected virtual void InitializeOffsetsAndTrackNodes()
167
155
}
168
156
}
169
157
}
170
- OffsetPos = CenterOffset . X ;
171
- // Compute width of transfer table
172
- Span = ( float ) ( trackShape . SectionIdxs [ trackShape . SectionIdxs . Length - 1 ] . X - trackShape . SectionIdxs [ 0 ] . X ) ;
158
+ if ( VerticalTransfer )
159
+ {
160
+ OffsetPos = CenterOffset . Y ;
161
+ Span = ( float ) ( trackShape . SectionIdxs [ trackShape . SectionIdxs . Length - 1 ] . Y - trackShape . SectionIdxs [ 0 ] . Y ) ;
162
+ }
163
+ else
164
+ {
165
+ OffsetPos = CenterOffset . X ;
166
+ Span = ( float ) ( trackShape . SectionIdxs [ trackShape . SectionIdxs . Length - 1 ] . X - trackShape . SectionIdxs [ 0 ] . X ) ;
167
+ }
173
168
}
174
169
175
170
/// <summary>
@@ -308,10 +303,13 @@ public override void StartContinuous(bool isForward)
308
303
Continuous = true ;
309
304
}
310
305
311
- public virtual void ComputeCenter ( WorldPosition worldPosition )
306
+ public void ComputeCenter ( WorldPosition worldPosition )
312
307
{
313
308
Vector3 movingCenterOffset = CenterOffset ;
314
- movingCenterOffset . X = OffsetPos ;
309
+ if ( VerticalTransfer )
310
+ movingCenterOffset . Y = OffsetPos ;
311
+ else
312
+ movingCenterOffset . X = OffsetPos ;
315
313
Vector3 originCoordinates ;
316
314
Vector3 . Transform ( ref movingCenterOffset , ref worldPosition . XNAMatrix , out originCoordinates ) ;
317
315
WorldPosition = new WorldPosition ( worldPosition ) ;
@@ -440,67 +438,4 @@ public void PerformUpdateActions ( Matrix absAnimationMatrix, WorldPosition worl
440
438
}
441
439
}
442
440
443
- /// <summary>
444
- /// A transfer table that moves vertically.
445
- /// </summary>
446
- public class VerticalTransfertable : Transfertable
447
- {
448
- public override float CenterOffsetComponent { get => CenterOffset . Y ; }
449
-
450
- internal VerticalTransfertable ( STFReader stf , Simulator simulator ) : base ( stf , simulator ) { }
451
-
452
- protected override void InitializeOffsetsAndTrackNodes ( )
453
- {
454
- var trackShape = Simulator . TSectionDat . TrackShapes . Get ( ( uint ) TrackShapeIndex ) ;
455
- var nSections = trackShape . SectionIdxs [ 0 ] . NoSections ;
456
- MyTrackNodesIndex = new int [ trackShape . SectionIdxs . Length ] ;
457
- MyTrackNodesOrientation = new bool [ MyTrackNodesIndex . Length ] ;
458
- MyTrVectorSectionsIndex = new int [ MyTrackNodesIndex . Length ] ;
459
- var iMyTrackNodes = 0 ;
460
- foreach ( var sectionIdx in trackShape . SectionIdxs )
461
- {
462
- Offsets . Add ( ( float ) sectionIdx . Y ) ;
463
- MyTrackNodesIndex [ iMyTrackNodes ] = - 1 ;
464
- MyTrVectorSectionsIndex [ iMyTrackNodes ] = - 1 ;
465
- iMyTrackNodes ++ ;
466
- }
467
- var trackNodes = Simulator . TDB . TrackDB . TrackNodes ;
468
- int iTrackNode = 0 ;
469
- for ( iTrackNode = 1 ; iTrackNode < trackNodes . Length ; iTrackNode ++ )
470
- {
471
- if ( trackNodes [ iTrackNode ] . TrVectorNode != null && trackNodes [ iTrackNode ] . TrVectorNode . TrVectorSections != null )
472
- {
473
- var iTrVectorSection = Array . FindIndex ( trackNodes [ iTrackNode ] . TrVectorNode . TrVectorSections , trVectorSection =>
474
- ( trVectorSection . WFNameX == WorldPosition . TileX && trVectorSection . WFNameZ == WorldPosition . TileZ && trVectorSection . WorldFileUiD == UID ) ) ;
475
- if ( iTrVectorSection >= 0 )
476
- {
477
- if ( trackNodes [ iTrackNode ] . TrVectorNode . TrVectorSections . Length > ( int ) nSections )
478
- {
479
- iMyTrackNodes = trackNodes [ iTrackNode ] . TrVectorNode . TrVectorSections [ iTrVectorSection ] . Flag1 / 2 ;
480
- MyTrackNodesIndex [ iMyTrackNodes ] = iTrackNode ;
481
- MyTrVectorSectionsIndex [ iMyTrackNodes ] = iTrVectorSection ;
482
- MyTrackNodesOrientation [ iMyTrackNodes ] = trackNodes [ iTrackNode ] . TrVectorNode . TrVectorSections [ iTrVectorSection ] . Flag1 % 2 == 0 ? true : false ;
483
-
484
- }
485
- }
486
- }
487
- }
488
- OffsetPos = CenterOffset . Y ;
489
- // Compute height of transfer table
490
- Span = ( float ) ( trackShape . SectionIdxs [ trackShape . SectionIdxs . Length - 1 ] . Y - trackShape . SectionIdxs [ 0 ] . Y ) ;
491
- }
492
-
493
- public override void ComputeCenter ( WorldPosition worldPosition )
494
- {
495
- Vector3 movingCenterOffset = CenterOffset ;
496
- movingCenterOffset . Y = OffsetPos ;
497
- Vector3 originCoordinates ;
498
- Vector3 . Transform ( ref movingCenterOffset , ref worldPosition . XNAMatrix , out originCoordinates ) ;
499
- WorldPosition = new WorldPosition ( worldPosition ) ;
500
- WorldPosition . XNAMatrix . M41 = originCoordinates . X ;
501
- WorldPosition . XNAMatrix . M42 = originCoordinates . Y ;
502
- WorldPosition . XNAMatrix . M43 = originCoordinates . Z ;
503
- }
504
- }
505
-
506
441
}
0 commit comments