Skip to content

Commit eb1bc78

Browse files
committed
Revert "Fix: F9 reversal flickering."
This reverts commit 234becd.
1 parent 234becd commit eb1bc78

File tree

6 files changed

+47
-110
lines changed

6 files changed

+47
-110
lines changed

Source/RunActivity/Viewer3D/Cameras.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
using Orts.Simulation.Physics;
3030
using Orts.Simulation.RollingStocks;
3131
using Orts.Simulation.Signalling;
32-
using Orts.Viewer3D.Popups;
3332
using ORTS.Common;
3433
using ORTS.Common.Input;
3534
using ORTS.Settings;
@@ -130,10 +129,7 @@ public virtual void Reset()
130129
public void Activate()
131130
{
132131
ScreenChanged();
133-
if (!Viewer.IsFormationReversed)// Avoids flickering
134-
{
135-
OnActivate(Viewer.Camera == this);
136-
}
132+
OnActivate(Viewer.Camera == this);
137133
Viewer.Camera = this;
138134
Viewer.Simulator.PlayerIsInCab = Style == Styles.Cab || Style == Styles.ThreeDimCab;
139135
Update(ElapsedTime.Zero);

Source/RunActivity/Viewer3D/Popups/OSDCars.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,11 @@ public override void PrepareFrame(RenderFrame frame, ORTS.Common.ElapsedTime ela
7878
var newLabels = new Dictionary<TrainCar, LabelPrimitive>(labels.Count);
7979
var cars = Owner.Viewer.World.Trains.Cars;
8080
var cameraLocation = Owner.Viewer.Camera.CameraWorldLocation;
81-
81+
var carID = Owner.Viewer.TrainCarOperationsViewerWindow.CurrentCarID;
8282
//data from Webpage
8383
var trainCarWebpage = Owner.Viewer.TrainCarOperationsWebpage;
84-
var trainCarWebpageActive = trainCarWebpage != null && trainCarWebpage.Connections > 0 && trainCarWebpage.TrainCarSelected;
8584
var carIDWebpage = trainCarWebpage != null && trainCarWebpage.Connections > 0 ? trainCarWebpage.CurrentCarID : "";
86-
87-
//shows only one CarID label when traincaroperationsviewer is not visible
88-
var trainCarOperationsViewer = Owner.Viewer.TrainCarOperationsViewerWindow;
89-
var carID = Owner.Viewer.TrainCarOperationsViewerWindow.Visible? trainCarOperationsViewer.CurrentCarID: trainCarWebpageActive ? trainCarWebpage.CurrentCarID : Owner.Viewer.TrainCarOperationsViewerWindow.CurrentCarID;
90-
91-
bool isVisibleTrainCarViewerOrWebpage = (Owner.Viewer.TrainCarOperationsWindow.Visible && !trainCarOperationsViewer.Visible) || trainCarOperationsViewer.Visible || trainCarWebpageActive;
85+
bool isVisibleTrainCarViewerOrWebpage = (Owner.Viewer.TrainCarOperationsWindow.Visible && !Owner.Viewer.TrainCarOperationsViewerWindow.Visible) || Owner.Viewer.TrainCarOperationsViewerWindow.Visible || (trainCarWebpage != null && trainCarWebpage.Connections > 0 && Owner.Viewer.TrainCarOperationsWebpage.TrainCarSelected);
9286
foreach (var car in cars.Keys)
9387
{
9488
// Calculates distance between camera and platform label.

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsViewerWindow.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public struct ListLabel
143143

144144
Train PlayerTrain;
145145
bool LastPlayerLocomotiveFlippedState;
146+
public bool IsFormationReversed;// Required when reversal
146147
public bool UpdateTCOLayout;// Required when reversal
147148
int LastPlayerTrainCars;
148149
int OldCarPosition;
@@ -475,17 +476,18 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
475476
{
476477
var carOperations = Owner.Viewer.CarOperationsWindow;
477478
var trainCarOperations = Owner.Viewer.TrainCarOperationsWindow;
478-
var isFormationReversed = Owner.Viewer.IsFormationReversed;
479+
var trainInfo = Owner.Viewer.PlayerTrain.GetTrainInfo();
480+
IsFormationReversed = trainInfo.cabOrientation != 0;
479481

480482
if (CouplerChanged || PlayerTrain != Owner.Viewer.PlayerTrain || Owner.Viewer.PlayerTrain.Cars.Count != LastPlayerTrainCars || (Owner.Viewer.PlayerLocomotive != null &&
481-
LastPlayerLocomotiveFlippedState != isFormationReversed))
483+
LastPlayerLocomotiveFlippedState != IsFormationReversed))
482484
{
483485
CouplerChanged = false;
484486
PlayerTrain = Owner.Viewer.PlayerTrain;
485487

486488
LastPlayerTrainCars = Owner.Viewer.PlayerTrain.Cars.Count;
487489
CarPosition = CarPosition >= LastPlayerTrainCars ? LastPlayerTrainCars - 1 : CarPosition;
488-
if (Owner.Viewer.PlayerLocomotive != null) LastPlayerLocomotiveFlippedState = isFormationReversed;
490+
if (Owner.Viewer.PlayerLocomotive != null) LastPlayerLocomotiveFlippedState = IsFormationReversed;
489491

490492
Layout();
491493
UpdateWindowSize();

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsWindow.cs

Lines changed: 38 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
using System.Linq;
3333
using static Orts.Viewer3D.Popups.TrainCarOperationsWindow;
3434
using Orts.Simulation.RollingStocks.SubSystems.PowerSupplies;
35-
using Orts.Viewer3D.RollingStock;
36-
using Orts.MultiPlayer;
3735

3836
namespace Orts.Viewer3D.Popups
3937
{
@@ -125,6 +123,7 @@ public class TrainCarOperationsWindow : Window
125123
public static bool FontChanged;
126124
public static bool FontToBold;
127125
public string LastCarIDSelected;// Required when reversal
126+
public bool IsFormationReversed;// Required when reversal
128127
public int OldCarPosition;
129128

130129
//Electrical power
@@ -154,7 +153,7 @@ public struct ListLabel
154153

155154
Train PlayerTrain;
156155
int LastPlayerTrainCars;
157-
public bool LastPlayerLocomotiveFlippedState;
156+
bool LastPlayerLocomotiveFlippedState;
158157

159158
public TrainCarOperationsWindow(WindowManager owner)
160159
: base(owner, Window.DecorationSize.X + CarListPadding + (owner.TextFontDefault.Height * 15), Window.DecorationSize.Y + (owner.TextFontDefault.Height * 5), Viewer.Catalog.GetString("Train Car Operations"))
@@ -520,7 +519,7 @@ void AddSpace()
520519

521520
// Allows to resize the window according to the carPosition value.
522521
if (RowsCount > carPosition) RowsCount = carPosition;
523-
if (SeparatorCount > carPosition - 1) SeparatorCount = carPosition - 1;
522+
if (SeparatorCount > carPosition -1) SeparatorCount = carPosition - 1;
524523
}
525524
}
526525
return Vbox;
@@ -599,7 +598,8 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
599598
var trainCarViewer = Owner.Viewer.TrainCarOperationsViewerWindow;
600599
var carOperations = Owner.Viewer.CarOperationsWindow;
601600
var trainCarWebpage = Owner.Viewer.TrainCarOperationsWebpage;
602-
var isFormationReversed = Owner.Viewer.IsFormationReversed;
601+
var trainInfo = Owner.Viewer.PlayerTrain.GetTrainInfo();
602+
IsFormationReversed = trainInfo.cabOrientation != 0;
603603

604604
CabCameraEnabled = Owner.Viewer.Camera is CabCamera || Owner.Viewer.Camera == Owner.Viewer.ThreeDimCabCamera;
605605
if (CarIdClicked && !CabCameraEnabled && !trainCarViewer.Visible && (!FrontActive || !BackActive))
@@ -636,27 +636,18 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
636636
topCarPositionVisible();
637637
localScrollLayout(SelectedCarPosition);
638638
}
639-
// Restore LastCarIDSelected (F9) after returning from different camera views
640-
if (CarIdClicked && Owner.Viewer.Camera.AttachedCar.CarID != LastCarIDSelected)
641-
{
642-
trainCarViewer.CurrentCarID = LastCarIDSelected;
643-
trainCarViewer.CarPosition = CarPosition = PlayerTrain.Cars.TakeWhile(x => x.CarID != LastCarIDSelected).Count();
644-
SelectedCarPosition = CarPosition;
645-
trainCarViewer.TrainCarOperationsChanged = true;
646-
SetCameraView();
647-
}
648639

649640
UserCommand? controlDiesel = GetPressedKey(UserCommand.ControlDieselHelper, UserCommand.ControlDieselPlayer, UserCommand.ControlInitializeBrakes);
650641
if (controlDiesel == UserCommand.ControlDieselHelper || controlDiesel == UserCommand.ControlDieselPlayer || controlDiesel == UserCommand.ControlInitializeBrakes)
651642
{
652643
Layout();
653-
PowerSupplyStatus = Owner.Viewer.PlayerTrain.Cars[Owner.Viewer.PlayerTrain.Cars.Count > CarPosition ? CarPosition : CarPosition - 1].GetStatus();
644+
PowerSupplyStatus = Owner.Viewer.PlayerTrain.Cars[Owner.Viewer.PlayerTrain.Cars.Count > CarPosition? CarPosition : CarPosition - 1].GetStatus();
654645
ModifiedSetting = true;
655646
}
656647

657648
var carsCountChanged = Owner.Viewer.PlayerTrain.Cars.Count != LastPlayerTrainCars;
658649
if (PlayerTrain != Owner.Viewer.PlayerTrain || carsCountChanged || (Owner.Viewer.PlayerLocomotive != null &&
659-
LastPlayerLocomotiveFlippedState != isFormationReversed))
650+
LastPlayerLocomotiveFlippedState != IsFormationReversed))
660651
{
661652
PlayerTrain = Owner.Viewer.PlayerTrain;
662653
if (LastPlayerTrainCars != Owner.Viewer.PlayerTrain.Cars.Count)
@@ -690,7 +681,6 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
690681
}
691682
}
692683
}
693-
694684
if (trainCarViewer.TrainCarOperationsChanged || trainCarViewer.RearBrakeHoseChanged
695685
|| trainCarViewer.FrontBrakeHoseChanged || ModifiedSetting || CarIdClicked || carOperations.CarOperationChanged)
696686
{
@@ -703,22 +693,41 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
703693
carOperations.CarOperationChanged = carOperations.Visible && carOperations.CarOperationChanged;
704694
}
705695

706-
if ((!trainCarViewer.Visible || trainCarViewer.UpdateTCOLayout) && (CarIdClicked || (LastPlayerLocomotiveFlippedState != isFormationReversed)))
707-
{ // Apply the reveral point to layout
708-
_ = new FormationReversed(Owner.Viewer, PlayerTrain);
709-
}
710-
711-
if (trainCarViewer.TrainCarOperationsChanged || trainCarViewer.RearBrakeHoseChanged
712-
|| trainCarViewer.FrontBrakeHoseChanged || ModifiedSetting || CarIdClicked || carOperations.CarOperationChanged)
696+
if ((!trainCarViewer.Visible || trainCarViewer.UpdateTCOLayout) && (CarIdClicked || (LastPlayerLocomotiveFlippedState != IsFormationReversed)))
713697
{
698+
var currentCameraCarID = Owner.Viewer.Camera.AttachedCar.CarID;
699+
700+
trainCarViewer.CurrentCarID = LastCarIDSelected;
701+
trainCarViewer.CarPosition = CarPosition = PlayerTrain.Cars.TakeWhile(x => x.CarID != LastCarIDSelected).Count();
702+
703+
if (CabCameraEnabled)// Displays camera 1
704+
{ // Setting the camera view
705+
CabCameraEnabled = false;
706+
}
707+
else if (OldCarPosition != SelectedCarPosition || (CarIdClicked && CarPosition == 0))
708+
{
709+
SetCameraView();
710+
OldCarPosition = SelectedCarPosition;
711+
}
712+
if (PlayerTrain.Cars.Count > CarPosition)
713+
{
714+
trainCarViewer.CarPosition = SelectedCarPosition = CarPosition = PlayerTrain.Cars.TakeWhile(x => x.CarID != LastCarIDSelected).Count();
715+
}
716+
else
717+
{
718+
trainCarViewer.CarPosition = SelectedCarPosition = CarPosition = 0;
719+
trainCarViewer.CurrentCarID = PlayerTrain.Cars[0].CarID;
720+
}
721+
722+
// Scroll LabelTop
723+
LabelTop = LabelPositionTop[SelectedCarPosition];
724+
Owner.Viewer.FrontCamera.IsCameraFront = Owner.Viewer.FrontCamera.AttachedCar != null;
725+
LastPlayerLocomotiveFlippedState = IsFormationReversed;
714726
Layout();
715727
localScrollLayout(SelectedCarPosition);
716728
updateLayoutSize();
717-
ModifiedSetting = false;
718-
// Avoids bug
719-
trainCarViewer.TrainCarOperationsChanged = WarningEnabled;
720-
carOperations.CarOperationChanged = carOperations.Visible && carOperations.CarOperationChanged;
721729
CarIdClicked = false;
730+
trainCarViewer.UpdateTCOLayout = false;
722731
}
723732

724733
if (CarPositionChanged || (trainCarWebpage != null && CarPosition != trainCarViewer.CarPosition && trainCarWebpage.Connections > 0))
@@ -741,7 +750,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
741750
}
742751
}
743752
}
744-
public void SetCameraView()
753+
private void SetCameraView()
745754
{
746755
if (Owner.Viewer.FrontCamera.AttachedCar != null)
747756
{
@@ -768,57 +777,6 @@ public void updateWarningCarPosition(int carPosition, Texture2D texture, Texture
768777
.Where((UserCommand key) => UserInput.IsDown(key))
769778
.FirstOrDefault();
770779
}
771-
772-
class FormationReversed
773-
{
774-
readonly Viewer Viewer;
775-
readonly TrainCarOperationsWindow TrainCar;
776-
readonly TrainCarOperationsViewerWindow TrainCarViewer;
777-
public FormationReversed(Viewer viewer, Train PlayerTrain)
778-
{
779-
Viewer = viewer;
780-
TrainCar = Viewer.TrainCarOperationsWindow;
781-
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
782-
var currentCameraCarID = Viewer.Camera.AttachedCar.CarID;
783-
784-
TrainCarViewer.CurrentCarID = TrainCar.LastCarIDSelected;
785-
TrainCarViewer.CarPosition = TrainCar.CarPosition = PlayerTrain.Cars.TakeWhile(x => x.CarID != TrainCar.LastCarIDSelected).Count();
786-
787-
if (TrainCar.CabCameraEnabled)// Displays camera 1
788-
{ // Setting the camera view
789-
TrainCar.CabCameraEnabled = false;
790-
}
791-
else if (TrainCar.OldCarPosition != TrainCar.SelectedCarPosition || (TrainCar.CarIdClicked && TrainCar.CarPosition == 0))
792-
{
793-
TrainCar.SetCameraView();
794-
TrainCar.OldCarPosition = TrainCar.SelectedCarPosition;
795-
}
796-
797-
if (PlayerTrain.Cars.Count > TrainCar.CarPosition)
798-
{
799-
TrainCarViewer.CarPosition = TrainCar.SelectedCarPosition = TrainCar.CarPosition = PlayerTrain.Cars.TakeWhile(x => x.CarID != TrainCar.LastCarIDSelected).Count();
800-
}
801-
else
802-
{
803-
TrainCarViewer.CarPosition = TrainCar.SelectedCarPosition = TrainCar.CarPosition = 0;
804-
TrainCarViewer.CurrentCarID = PlayerTrain.Cars[0].CarID;
805-
}
806-
807-
// Scroll LabelTop
808-
TrainCar.LabelTop = TrainCar.LabelPositionTop[TrainCar.SelectedCarPosition];
809-
Viewer.FrontCamera.IsCameraFront = Viewer.FrontCamera.AttachedCar != null;
810-
TrainCar.Layout();
811-
TrainCar.localScrollLayout(TrainCar.SelectedCarPosition);
812-
TrainCar.updateLayoutSize();
813-
814-
// Reset
815-
Viewer.IsFormationReversed = false;
816-
TrainCar.LastPlayerLocomotiveFlippedState = Viewer.IsFormationReversed;
817-
TrainCar.CarIdClicked = false;
818-
TrainCarViewer.UpdateTCOLayout = false;
819-
}
820-
}
821-
822780
class buttonArrowRight : Image
823781
{
824782
readonly Viewer Viewer;

Source/RunActivity/Viewer3D/Viewer.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,8 @@ public bool IsBeforeNoon
268268
public Camera SuspendedCamera { get; private set; }
269269

270270
public static double DbfEvalAutoPilotTimeS = 0;//Debrief eval
271-
public static double DbfEvalIniAutoPilotTimeS = 0;//Debrief eval
271+
public static double DbfEvalIniAutoPilotTimeS = 0;//Debrief eval
272272
public static bool DbfEvalAutoPilot = false;//DebriefEval
273-
public bool IsFormationReversed; //Avoid flickering when reversal using TrainCarOperations window
274273

275274
/// <summary>
276275
/// Finds time of last entry to set ReplayEndsAt and provide the Replay started message.
@@ -796,7 +795,6 @@ public void Update(RenderFrame frame, float elapsedRealTime)
796795
// We need to do it also here, because passing from manual to auto a ReverseFormation may be needed
797796
if (Camera is TrackingCamera && Camera.AttachedCar != null && Camera.AttachedCar.Train != null && Camera.AttachedCar.Train.FormationReversed)
798797
{
799-
IsFormationReversed = TrainCarOperationsWindow.Visible || TrainCarOperationsWebpage.Connections > 0;
800798
Camera.AttachedCar.Train.FormationReversed = false;
801799
(Camera as TrackingCamera).SwapCameras();
802800
}
@@ -852,7 +850,6 @@ public void Update(RenderFrame frame, float elapsedRealTime)
852850
// Check if you need to swap camera
853851
if (Camera is TrackingCamera && Camera.AttachedCar != null && Camera.AttachedCar.Train != null && Camera.AttachedCar.Train.FormationReversed)
854852
{
855-
IsFormationReversed = TrainCarOperationsWindow.Visible || TrainCarOperationsWebpage.Connections > 0;
856853
Camera.AttachedCar.Train.FormationReversed = false;
857854
(Camera as TrackingCamera).SwapCameras();
858855
}

Source/RunActivity/Viewer3D/WebServices/TrainCarOperationsWebpage.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
using Orts.Simulation.RollingStocks.SubSystems.Brakes.MSTS;
3232
using ORTS.Scripting.Api;
3333
using System.IO;
34-
using Orts.Simulation.Physics;
3534

3635
namespace Orts.Viewer3D.WebServices
3736
{
@@ -277,14 +276,6 @@ private void handleSend()
277276

278277
private void fillStatus(OperationsStatus operationStatus)
279278
{
280-
// Apply reveral point when TrainCarOperations/Viewer windows are not visibles
281-
// Makes this Webpage version, more autonoumus
282-
if (!Viewer.TrainCarOperationsWindow.Visible && !Viewer.TrainCarOperationsViewerWindow.Visible && Viewer.IsFormationReversed)
283-
{
284-
_ = new FormationReversed(Viewer, Viewer.PlayerTrain);
285-
Viewer.IsFormationReversed = false;
286-
}
287-
288279
int carPosition = 0;
289280

290281
foreach (TrainCar trainCar in Viewer.PlayerTrain.Cars)
@@ -516,7 +507,6 @@ private void fillStatusArrowLeft(int carPosition)
516507
if (TrainCarSelected && (carPosition == TrainCarSelectedPosition))
517508
{
518509
filename = "TrainOperationsArrowRight32.png";
519-
CurrentCarID = Viewer.PlayerTrain.Cars[carPosition].CarID;// Requiered by OSDCars.cs
520510
}
521511
else
522512
{

0 commit comments

Comments
 (0)