Skip to content

Commit 52c1265

Browse files
author
Chris Jakeman
committed
Timetable loading bar added
1 parent af1b35a commit 52c1265

File tree

5 files changed

+75
-8
lines changed

5 files changed

+75
-8
lines changed

Source/Documentation/Manual/driving.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@ Game Loading
99

1010
Once you have pressed ``Start``, Open Rails loads and processes all the
1111
data needed to run the game. During this phase, the route's splash screen
12-
is shown. If the same session was loaded previously, a bar showing loading
13-
progress is shown at the bottom of the display. During loading, if logging
12+
is shown with an indicator bar at the bottom.
13+
14+
.. image:: images/loading_bars.png
15+
16+
The first time a session is loaded, an animated bar just shows activity.
17+
Subsequent loads of that session show the bar growing across the screen to indicate
18+
progress.
19+
20+
If a timetable has been selected, then the game also simulates the progress of the timetable
21+
from the first train in the timetable up to start time of the player's train.
22+
This is done at high speed, but may still take some time. A second bar appears
23+
above the first one to show the progress of this stage.
24+
25+
During loading, if logging
1426
is selected, the log file ``OpenRailsLog.txt`` will already begin storing
1527
data.
1628

Loading

Source/Orts.Simulation/Simulation/AIs/AI.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ private void PrerunAI(int playerTrainOriginalTrain, TTTrain.FormCommand playerTr
374374
bool activeTrains = false;
375375
for (double runTime = firstAITime; runTime < Simulator.ClockTime && !endPreRun; runTime += 5.0) // update with 5 secs interval
376376
{
377+
var loaderSpan = (float)playerTrain.StartTime - firstAITime;
378+
Simulator.TimetableLoadedFraction = ((float)clockTime - firstAITime) / loaderSpan;
379+
377380
int fullsec = Convert.ToInt32(runTime);
378381
if (fullsec % 3600 < 5) Trace.Write(" " + (fullsec / 3600).ToString("00") + ":00 ");
379382

Source/Orts.Simulation/Simulation/Simulator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ public QueryCarViewerLoadedEventArgs(TrainCar car)
252252
public event System.EventHandler<QueryCarViewerLoadedEventArgs> QueryCarViewerLoaded;
253253
public event System.EventHandler RequestTTDetachWindow;
254254

255+
public float TimetableLoadedFraction = 0.0f; // Set by AI.PrerunAI(), Get by GameStateRunActivity.Update()
256+
255257
public Simulator(UserSettings settings, string activityPath, bool useOpenRailsDirectory)
256258
{
257259
Catalog = new GettextResourceManager("Orts.Simulation");

Source/RunActivity/Viewer3D/Processes/GameStateRunActivity.cs

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct savedValues
7171
LoadingPrimitive Loading;
7272
LoadingScreenPrimitive LoadingScreen;
7373
LoadingBarPrimitive LoadingBar;
74+
TimetableLoadingBarPrimitive TimetableLoadingBar;
7475
Matrix LoadingMatrix = Matrix.Identity;
7576

7677
public GameStateRunActivity(string[] args)
@@ -83,6 +84,7 @@ internal override void Dispose()
8384
Loading.Dispose();
8485
LoadingScreen.Dispose();
8586
LoadingBar.Dispose();
87+
TimetableLoadingBar.Dispose();
8688
base.Dispose();
8789
}
8890

@@ -106,6 +108,14 @@ internal override void Update(RenderFrame frame, double totalRealSeconds)
106108
frame.AddPrimitive(LoadingBar.Material, LoadingBar, RenderPrimitiveGroup.Overlay, ref LoadingMatrix);
107109
}
108110

111+
if (Simulator != null && Simulator.TimetableMode && TimetableLoadingBar != null
112+
&& Simulator.TimetableLoadedFraction < 0.99f // 0.99 to hide loading bar at end of timetable pre-run
113+
)
114+
{
115+
TimetableLoadingBar.Material.Shader.LoadingPercent = Simulator.TimetableLoadedFraction;
116+
frame.AddPrimitive(TimetableLoadingBar.Material, TimetableLoadingBar, RenderPrimitiveGroup.Overlay, ref LoadingMatrix);
117+
}
118+
109119
base.Update(frame, totalRealSeconds);
110120
}
111121

@@ -116,7 +126,8 @@ internal override void Load()
116126
Loading = new LoadingPrimitive(Game);
117127
if (LoadingBar == null)
118128
LoadingBar = new LoadingBarPrimitive(Game);
119-
129+
if (TimetableLoadingBar == null)
130+
TimetableLoadingBar = new TimetableLoadingBarPrimitive(Game);
120131
var args = Arguments;
121132

122133
// Look for an action to perform.
@@ -1329,7 +1340,7 @@ protected override VertexPositionTexture[] GetVerticies(Game game)
13291340

13301341
class LoadingBarPrimitive : LoadingPrimitive
13311342
{
1332-
public LoadingBarPrimitive(Game game)
1343+
public LoadingBarPrimitive(Game game )
13331344
: base(game)
13341345
{
13351346
}
@@ -1341,17 +1352,42 @@ protected override LoadingMaterial GetMaterial(Game game)
13411352

13421353
protected override VertexPositionTexture[] GetVerticies(Game game)
13431354
{
1344-
var w = game.RenderProcess.DisplaySize.X;
1345-
var h = 10;
1346-
var x = -w / 2 - 0.5f;
1347-
var y = game.RenderProcess.DisplaySize.Y / 2 - h - 0.5f;
1355+
GetLoadingBarSize(game, out int w, out int h, out float x, out float y);
1356+
return GetLoadingBarCoords(w, h, x, y);
1357+
}
1358+
1359+
protected VertexPositionTexture[] GetLoadingBarCoords(int w, int h, float x, float y)
1360+
{
13481361
return new[] {
13491362
new VertexPositionTexture(new Vector3(x + 0, -y - 0, -1), new Vector2(0, 0)),
13501363
new VertexPositionTexture(new Vector3(x + w, -y - 0, -1), new Vector2(1, 0)),
13511364
new VertexPositionTexture(new Vector3(x + 0, -y - h, -1), new Vector2(0, 1)),
13521365
new VertexPositionTexture(new Vector3(x + w, -y - h, -1), new Vector2(1, 1)),
13531366
};
13541367
}
1368+
1369+
protected static void GetLoadingBarSize(Game game, out int w, out int h, out float x, out float y)
1370+
{
1371+
w = game.RenderProcess.DisplaySize.X;
1372+
h = 10;
1373+
x = -w / 2 - 0.5f;
1374+
y = game.RenderProcess.DisplaySize.Y / 2 - h - 0.5f;
1375+
}
1376+
}
1377+
1378+
class TimetableLoadingBarPrimitive : LoadingBarPrimitive
1379+
{
1380+
public TimetableLoadingBarPrimitive(Game game)
1381+
: base(game)
1382+
{
1383+
}
1384+
1385+
protected override VertexPositionTexture[] GetVerticies(Game game)
1386+
{
1387+
GetLoadingBarSize(game, out int w, out int h, out float x, out float y);
1388+
y -= h + 1; // Allow for second bar and 1 pixel gap between
1389+
return GetLoadingBarCoords(w, h, x, y);
1390+
}
13551391
}
13561392

13571393
class LoadingMaterial : Material, IDisposable
@@ -1481,6 +1517,20 @@ public override void SetState(GraphicsDevice graphicsDevice, Material previousMa
14811517
}
14821518
}
14831519

1520+
class TimetableLoadingBarMaterial : LoadingMaterial
1521+
{
1522+
public TimetableLoadingBarMaterial(Game game)
1523+
: base(game)
1524+
{
1525+
}
1526+
1527+
public override void SetState(GraphicsDevice graphicsDevice, Material previousMaterial)
1528+
{
1529+
base.SetState(graphicsDevice, previousMaterial);
1530+
Shader.CurrentTechnique = Shader.Techniques["LoadingBar"];
1531+
}
1532+
}
1533+
14841534
class LoadingShader : Shader
14851535
{
14861536
readonly EffectParameter worldViewProjection;

0 commit comments

Comments
 (0)