@@ -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,6 @@ 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 > ( ) ;
399
413
Program . Renderer . Initialize ( ) ;
400
414
Program . Renderer . DetermineMaxAFLevel ( ) ;
401
415
Interface . CurrentOptions . Save ( OpenBveApi . Path . CombineFile ( Program . FileSystem . SettingsFolder , "1.5.0/options.cfg" ) ) ;
@@ -1078,16 +1092,21 @@ private void SetupSimulation()
1078
1092
}
1079
1093
}
1080
1094
}
1095
+
1096
+ simulationSetup = true ;
1081
1097
}
1082
1098
1099
+ private Thread setupThread ;
1100
+ private bool simulationSetup = false ;
1101
+
1083
1102
public void LoadingScreenLoop ( )
1084
1103
{
1085
1104
Program . Renderer . PushMatrix ( MatrixMode . Projection ) ;
1086
1105
Matrix4D . CreateOrthographicOffCenter ( 0.0f , Program . Renderer . Screen . Width , Program . Renderer . Screen . Height , 0.0f , - 1.0f , 1.0f , out Program . Renderer . CurrentProjectionMatrix ) ;
1087
1106
Program . Renderer . PushMatrix ( MatrixMode . Modelview ) ;
1088
1107
Program . Renderer . CurrentViewMatrix = Matrix4D . Identity ;
1089
1108
1090
- while ( ! Loading . Complete && ! Loading . Cancel )
1109
+ while ( ! Loading . Complete && ! Loading . Cancel && ! simulationSetup )
1091
1110
{
1092
1111
CPreciseTimer . GetElapsedTime ( ) ;
1093
1112
this . ProcessEvents ( ) ;
@@ -1124,19 +1143,19 @@ public void LoadingScreenLoop()
1124
1143
Program . Renderer . Loading . DrawLoadingScreen ( Program . Renderer . Fonts . SmallFont , routeProgress , finalTrainProgress ) ;
1125
1144
SwapBuffers ( ) ;
1126
1145
1127
- if ( Loading . JobAvailable )
1146
+ if ( Program . Renderer . RenderThreadJobWaiting )
1128
1147
{
1129
- while ( ! jobs . IsEmpty )
1148
+ while ( ! Program . Renderer . RenderThreadJobs . IsEmpty )
1130
1149
{
1131
- jobs . TryDequeue ( out ThreadStart currentJob ) ;
1150
+ Program . Renderer . RenderThreadJobs . TryDequeue ( out ThreadStart currentJob ) ;
1132
1151
currentJob ( ) ;
1133
1152
lock ( currentJob )
1134
1153
{
1135
1154
Monitor . Pulse ( currentJob ) ;
1136
1155
}
1137
1156
1138
1157
}
1139
- Loading . JobAvailable = false ;
1158
+ Program . Renderer . RenderThreadJobWaiting = false ;
1140
1159
}
1141
1160
double time = CPreciseTimer . GetElapsedTime ( ) ;
1142
1161
double wait = 1000.0 / 60.0 - time * 1000 - 50 ;
@@ -1153,22 +1172,6 @@ public void LoadingScreenLoop()
1153
1172
}
1154
1173
}
1155
1174
1156
- private static ConcurrentQueue < ThreadStart > jobs ;
1157
1175
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
1176
}
1174
1177
}
0 commit comments