@@ -1116,14 +1116,25 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
1116
1116
Positions [ i ] = i ;
1117
1117
}
1118
1118
1119
- // Check if eligible for filling
1119
+ // Possible that positions were defined in reverse, eg: 3DTrains Surfliner trains
1120
+ // Ensure positions are sorted from least to greatest before proceeding
1121
+ if ( Positions . Count > 0 && Positions [ 0 ] > Positions [ Positions . Count - 1 ] )
1122
+ {
1123
+ Reversed ^= true ;
1124
+ // Recalculate positions in reverse
1125
+ for ( int i = 0 ; i < Positions . Count ; i ++ )
1126
+ Positions [ i ] = ( FramesCount - 1 ) - Positions [ i ] ;
1127
+ }
1120
1128
1121
- if ( Positions . Count > 1 && Positions [ 0 ] != 0 ) CanFill = false ;
1129
+ // Check if eligible for filling
1130
+ if ( Positions . Count > 1 && Positions [ 0 ] != 0 )
1131
+ CanFill = false ;
1122
1132
else
1123
1133
{
1124
1134
for ( var iPos = 1 ; iPos <= Positions . Count - 1 ; iPos ++ )
1125
1135
{
1126
- if ( Positions [ iPos ] > Positions [ iPos - 1 ] ) continue ;
1136
+ if ( Positions [ iPos ] > Positions [ iPos - 1 ] )
1137
+ continue ;
1127
1138
CanFill = false ;
1128
1139
break ;
1129
1140
}
@@ -1258,42 +1269,47 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
1258
1269
// Fill empty Values
1259
1270
for ( int i = 0 ; i < ( FramesCount - 1 ) ; i ++ )
1260
1271
Values . Add ( 0 ) ;
1272
+ // Offset for min and max values to achieve equal frame spacing
1273
+ double offset = 1.0 / ( 2.0 * FramesCount ) ;
1261
1274
// Some dummy controls will have only one frame
1262
1275
if ( Values . Count > 0 )
1263
- Values [ 0 ] = MinValue ;
1276
+ Values [ 0 ] = MinValue + offset ;
1264
1277
else
1265
- Values . Add ( MinValue ) ;
1278
+ Values . Add ( MinValue + offset ) ;
1266
1279
1267
1280
// Add maximum value to the end
1268
- Values . Add ( MaxValue ) ;
1281
+ Values . Add ( MaxValue - offset ) ;
1269
1282
}
1270
1283
else if ( Values . Count == 2 && Values [ 0 ] == 0 && Values [ 1 ] < MaxValue && Positions [ 0 ] == 0 && Positions [ 1 ] == 1 && Values . Count < FramesCount )
1271
1284
{
1272
1285
//This if clause covers among others following cases:
1273
1286
// Case 1 (e.g. engine brake lever of gp38):
1274
- //NumFrames ( 18 2 9 )
1275
- //NumPositions ( 2 0 1 )
1276
- //NumValues ( 2 0 0.3 )
1277
- //Orientation ( 0 )
1278
- //DirIncrease ( 0 )
1279
- //ScaleRange ( 0 1 )
1287
+ //NumFrames ( 18 2 9 )
1288
+ //NumPositions ( 2 0 1 )
1289
+ //NumValues ( 2 0 0.3 )
1290
+ //Orientation ( 0 )
1291
+ //DirIncrease ( 0 )
1292
+ //ScaleRange ( 0 1 )
1293
+ // Add missing positions
1280
1294
Positions . Add ( FramesCount - 1 ) ;
1281
1295
// Fill empty Values
1282
1296
for ( int i = Values . Count ; i < ( FramesCount - 1 ) ; i ++ )
1283
- Values . Add ( Values [ 1 ] ) ;
1297
+ Values . Add ( 0 ) ;
1298
+ // Offset for min and max values to achieve equal frame spacing
1299
+ double offset = 1.0 / ( 2.0 * FramesCount ) ;
1284
1300
// Add maximum value to the end
1285
- Values . Add ( MaxValue ) ;
1301
+ Values . Add ( MaxValue - offset ) ;
1286
1302
}
1287
1303
else
1288
1304
{
1289
1305
//This if clause covers among others following cases:
1290
1306
// Case 1 (e.g. train brake lever of Acela):
1291
- //NumFrames ( 12 4 3 )
1292
- //NumPositions ( 5 0 1 9 10 11 )
1293
- //NumValues ( 5 0 0.2 0.85 0.9 0.95 )
1294
- //Orientation ( 1 )
1295
- //DirIncrease ( 1 )
1296
- //ScaleRange ( 0 1 )
1307
+ //NumFrames ( 12 4 3 )
1308
+ //NumPositions ( 5 0 1 9 10 11 )
1309
+ //NumValues ( 5 0 0.2 0.85 0.9 0.95 )
1310
+ //Orientation ( 1 )
1311
+ //DirIncrease ( 1 )
1312
+ //ScaleRange ( 0 1 )
1297
1313
//
1298
1314
// Fill empty Values
1299
1315
int iValues = 1 ;
@@ -1369,7 +1385,7 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
1369
1385
// Ensure resulting set of values has the correct format (sorted least to greatest) and resort
1370
1386
// Assume values have been entered in reverse order if final value is less than initial value
1371
1387
if ( Values . Count > 0 && Values [ 0 ] > Values [ Values . Count - 1 ] )
1372
- Reversed = true ;
1388
+ Reversed ^ = true ;
1373
1389
// Force sort values from least to greatest
1374
1390
Values . Sort ( ) ;
1375
1391
@@ -1424,9 +1440,8 @@ public CVCMultiStateDisplay(STFReader stf, string basepath)
1424
1440
; } ) ,
1425
1441
} ) ; } ) ,
1426
1442
} ) ;
1427
- if ( Values . Count > 0 ) MaxValue = Values . Last ( ) ;
1428
- for ( int i = Values . Count ; i < FramesCount ; i ++ )
1429
- Values . Add ( - 10000 ) ;
1443
+ if ( Values . Count > 0 )
1444
+ MaxValue = Values . Max ( ) ;
1430
1445
} ) ,
1431
1446
new STFReader . TokenProcessor ( "ortsdisplay" , ( ) => { ParseDisplay ( stf ) ; } ) ,
1432
1447
new STFReader . TokenProcessor ( "ortsscreenpage" , ( ) => { ParseScreen ( stf ) ; } ) ,
@@ -1436,7 +1451,10 @@ public CVCMultiStateDisplay(STFReader stf, string basepath)
1436
1451
// Ensure resulting set of values has the correct format (sorted least to greatest) and resort
1437
1452
// Assume values have been entered in reverse order if final value is less than initial value
1438
1453
if ( Values . Count > 0 && Values [ 0 ] > Values [ Values . Count - 1 ] )
1439
- Reversed = true ;
1454
+ Reversed ^= true ;
1455
+ // Fill in missing values
1456
+ for ( int i = Values . Count ; i < FramesCount ; i ++ )
1457
+ Values . Add ( Values [ Values . Count - 1 ] ) ;
1440
1458
// Force sort values from least to greatest
1441
1459
Values . Sort ( ) ;
1442
1460
}
@@ -1481,9 +1499,8 @@ public CVCAnimatedDisplay(STFReader stf, string basepath)
1481
1499
; } ) ,
1482
1500
} ) ; } ) ,
1483
1501
} ) ;
1484
- if ( Values . Count > 0 ) MaxValue = Values . Last ( ) ;
1485
- for ( int i = Values . Count ; i < FramesCount ; i ++ )
1486
- Values . Add ( - 10000 ) ;
1502
+ if ( Values . Count > 0 )
1503
+ MaxValue = Values . Max ( ) ;
1487
1504
} ) ,
1488
1505
new STFReader . TokenProcessor ( "ortsdisplay" , ( ) => { ParseDisplay ( stf ) ; } ) ,
1489
1506
new STFReader . TokenProcessor ( "ortsscreenpage" , ( ) => { ParseScreen ( stf ) ; } ) ,
@@ -1493,7 +1510,10 @@ public CVCAnimatedDisplay(STFReader stf, string basepath)
1493
1510
// Ensure resulting set of values has the correct format (sorted least to greatest) and resort
1494
1511
// Assume values have been entered in reverse order if final value is less than initial value
1495
1512
if ( Values . Count > 0 && Values [ 0 ] > Values [ Values . Count - 1 ] )
1496
- Reversed = true ;
1513
+ Reversed ^= true ;
1514
+ // Fill in missing values
1515
+ for ( int i = Values . Count ; i < FramesCount ; i ++ )
1516
+ Values . Add ( Values [ Values . Count - 1 ] ) ;
1497
1517
// Force sort values from least to greatest
1498
1518
Values . Sort ( ) ;
1499
1519
}
0 commit comments