Skip to content

Commit 157fd3f

Browse files
- call the update of the TrainCarOprationsWebpage only 4 times per second
- transferred some code from Viewer.cs to TrainCarOperationsWebpage.cs
1 parent 0f744b3 commit 157fd3f

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

Source/RunActivity/Viewer3D/Viewer.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -913,18 +913,9 @@ public void Update(RenderFrame frame, float elapsedRealTime)
913913

914914
SwitchPanelModule.SendSwitchPanelIfChanged();
915915

916-
try
917-
{
918-
if ((PlayerTrain != null) && (TrainCarOperationsWebpage != null))
919-
{
920-
TrainCarOperationsWebpage.handleReceiveAndSend();
921-
}
922-
}
923-
catch (Exception error)
916+
if (TrainCarOperationsWebpage != null)
924917
{
925-
// some timing error causes an exception sometimes
926-
// just silently ignore but log the exception
927-
Trace.TraceWarning(error.ToString());
918+
TrainCarOperationsWebpage.handleReceiveAndSend();
928919
}
929920
}
930921

Source/RunActivity/Viewer3D/WebServices/TrainCarOperationsWebpage.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,29 @@ public async Task BroadcastEvent(OperationsSend operationsSend)
202202
}
203203
}
204204

205+
double LastPrepareRealTime;
205206
public void handleReceiveAndSend()
206207
{
207-
if (Connections > 0)
208+
if ((Viewer.PlayerTrain != null))
208209
{
209-
handleReceive();
210-
handleSend();
210+
if (Connections > 0)
211+
{
212+
if (Viewer.RealTime - LastPrepareRealTime >= 0.25)
213+
{
214+
LastPrepareRealTime = Viewer.RealTime;
215+
try
216+
{
217+
handleReceive();
218+
handleSend();
219+
}
220+
catch (Exception error)
221+
{
222+
// some timing error causes an exception sometimes
223+
// just silently ignore but log the exception
224+
Trace.TraceWarning(error.ToString());
225+
}
226+
}
227+
}
211228
}
212229
}
213230

0 commit comments

Comments
 (0)