@@ -99,6 +99,21 @@ protected override void OnRenderFrame(FrameEventArgs e)
99
99
//If the load is not complete, then we shouldn't be running the mainloop
100
100
return ;
101
101
}
102
+
103
+ if ( Program . Renderer . RenderThreadJobWaiting )
104
+ {
105
+ while ( ! Program . Renderer . RenderThreadJobs . IsEmpty )
106
+ {
107
+ Program . Renderer . RenderThreadJobs . TryDequeue ( out ThreadStart currentJob ) ;
108
+ currentJob ( ) ;
109
+ lock ( currentJob )
110
+ {
111
+ Monitor . Pulse ( currentJob ) ;
112
+ }
113
+ }
114
+ }
115
+
116
+ Program . Renderer . RenderThreadJobWaiting = false ;
102
117
double TimeElapsed = RenderTimeElapsed ;
103
118
double RealTimeElapsed = RenderRealTimeElapsed ;
104
119
@@ -395,7 +410,7 @@ protected override void OnLoad(EventArgs e)
395
410
}
396
411
Program . FileSystem . AppendToLogFile ( "Game window initialised successfully." ) ;
397
412
//Initialise the loader thread queues
398
- jobs = new ConcurrentQueue < ThreadStart > ( ) ;
413
+ Program . Renderer . RenderThreadJobs = new ConcurrentQueue < ThreadStart > ( ) ;
399
414
Program . Renderer . Initialize ( ) ;
400
415
Program . Renderer . DetermineMaxAFLevel ( ) ;
401
416
Interface . CurrentOptions . Save ( OpenBveApi . Path . CombineFile ( Program . FileSystem . SettingsFolder , "1.5.0/options.cfg" ) ) ;
@@ -1078,16 +1093,21 @@ private void SetupSimulation()
1078
1093
}
1079
1094
}
1080
1095
}
1096
+
1097
+ simulationSetup = true ;
1081
1098
}
1082
1099
1100
+ private Thread setupThread ;
1101
+ private bool simulationSetup = false ;
1102
+
1083
1103
public void LoadingScreenLoop ( )
1084
1104
{
1085
1105
Program . Renderer . PushMatrix ( MatrixMode . Projection ) ;
1086
1106
Matrix4D . CreateOrthographicOffCenter ( 0.0f , Program . Renderer . Screen . Width , Program . Renderer . Screen . Height , 0.0f , - 1.0f , 1.0f , out Program . Renderer . CurrentProjectionMatrix ) ;
1087
1107
Program . Renderer . PushMatrix ( MatrixMode . Modelview ) ;
1088
1108
Program . Renderer . CurrentViewMatrix = Matrix4D . Identity ;
1089
1109
1090
- while ( ! Loading . Complete && ! Loading . Cancel )
1110
+ while ( ! Loading . Complete && ! Loading . Cancel && ! simulationSetup )
1091
1111
{
1092
1112
CPreciseTimer . GetElapsedTime ( ) ;
1093
1113
this . ProcessEvents ( ) ;
@@ -1124,19 +1144,19 @@ public void LoadingScreenLoop()
1124
1144
Program . Renderer . Loading . DrawLoadingScreen ( Program . Renderer . Fonts . SmallFont , routeProgress , finalTrainProgress ) ;
1125
1145
SwapBuffers ( ) ;
1126
1146
1127
- if ( Loading . JobAvailable )
1147
+ if ( Program . Renderer . RenderThreadJobWaiting )
1128
1148
{
1129
- while ( ! jobs . IsEmpty )
1149
+ while ( ! Program . Renderer . RenderThreadJobs . IsEmpty )
1130
1150
{
1131
- jobs . TryDequeue ( out ThreadStart currentJob ) ;
1151
+ Program . Renderer . RenderThreadJobs . TryDequeue ( out ThreadStart currentJob ) ;
1132
1152
currentJob ( ) ;
1133
1153
lock ( currentJob )
1134
1154
{
1135
1155
Monitor . Pulse ( currentJob ) ;
1136
1156
}
1137
1157
1138
1158
}
1139
- Loading . JobAvailable = false ;
1159
+ Program . Renderer . RenderThreadJobWaiting = false ;
1140
1160
}
1141
1161
double time = CPreciseTimer . GetElapsedTime ( ) ;
1142
1162
double wait = 1000.0 / 60.0 - time * 1000 - 50 ;
@@ -1153,22 +1173,6 @@ public void LoadingScreenLoop()
1153
1173
}
1154
1174
}
1155
1175
1156
- private static ConcurrentQueue < ThreadStart > jobs ;
1157
1176
1158
- /// <summary>This method is used during loading to run commands requiring an OpenGL context in the main render loop</summary>
1159
- /// <param name="job">The OpenGL command</param>
1160
- /// <param name="timeout">The timeout</param>
1161
- internal static void RunInRenderThread ( ThreadStart job , int timeout )
1162
- {
1163
- jobs . Enqueue ( job ) ;
1164
- //Don't set the job to available until after it's been loaded into the queue
1165
- Loading . JobAvailable = true ;
1166
- //Failsafe: If our job has taken more than the timeout, stop waiting for it
1167
- //A missing texture is probably better than an infinite loadscreen
1168
- lock ( job )
1169
- {
1170
- Monitor . Wait ( job , timeout ) ;
1171
- }
1172
- }
1173
1177
}
1174
1178
}
0 commit comments