Skip to content

Commit 878fbe8

Browse files
committed
Merge branch 'master' into release
2 parents 3377d02 + 5df67f5 commit 878fbe8

File tree

123 files changed

+967
-873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+967
-873
lines changed

.github/ISSUE_TEMPLATE.md .github/ISSUE_TEMPLATE/bug_report.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
---
2+
name: Bug report
3+
about: Reporting a bug
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
110
### Description
211

312
Please describe the issue you are experiencing.

source/AssimpParser/AssimpParser.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
</PropertyGroup>
4848
<ItemGroup>
4949
<Reference Include="DotNetZip, Version=1.17.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
50-
<HintPath>..\..\packages\DotNetZip.OpenBVE.1.17.0\lib\net40\DotNetZip.dll</HintPath>
50+
<HintPath>..\..\packages\DotNetZip.OpenBVE.1.17.2\lib\net40\DotNetZip.dll</HintPath>
5151
</Reference>
5252
<Reference Include="System" />
5353
<Reference Include="System.Core" />

source/AssimpParser/Wavefront/ObjFileData.cs

-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ public class Mesh
228228
public uint[] UVCoordinates = Enumerable.Repeat(0u, (int)AI_MAX_NUMBER_OF_TEXTURECOORDS).ToArray();
229229
/// Material index.
230230
public uint MaterialIndex = NoMaterial;
231-
/// True, if normals are stored.
232-
public bool HasNormals = false;
233231
/// True, if vertex colors are stored.
234232
#pragma warning disable 169
235233
bool HasVertexColors;

source/AssimpParser/Wavefront/ObjFileParser.cs

-5
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ protected void GetFace(PrimitiveType type)
405405
}
406406

407407
Face face = new Face(type);
408-
bool hasNormal = false;
409408

410409
int vSize = Model.Vertices.Count;
411410
int vtSize = Model.TextureCoord.Count;
@@ -536,10 +535,6 @@ protected void GetFace(PrimitiveType type)
536535
Model.CurrentMesh.Faces.Add(face);
537536
Model.CurrentMesh.NumIndices += (uint)face.Vertices.Count;
538537
Model.CurrentMesh.UVCoordinates[0] += (uint)face.TexturCoords.Count;
539-
if (!Model.CurrentMesh.HasNormals && hasNormal)
540-
{
541-
Model.CurrentMesh.HasNormals = true;
542-
}
543538
// Skip the rest of the line
544539
DataIt = SkipLine(DataIt, DataEnd, ref Line);
545540
}

source/AssimpParser/packages.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="DotNetZip.OpenBVE" version="1.17.0" targetFramework="net461" />
3+
<package id="DotNetZip.OpenBVE" version="1.17.2" targetFramework="net461" />
44
</packages>

source/InputDevicePlugins/SanYingInput/ConfigForm.cs

+2-9
Original file line numberDiff line numberDiff line change
@@ -475,18 +475,11 @@ private void timer1_Tick(object sender, EventArgs e)
475475

476476
if (_notchPosition > 0)
477477
{
478-
notchPositionString = string.Format("P{0}", _notchPosition);
478+
notchPositionString = $"P{_notchPosition}";
479479
}
480480
else if (_notchPosition < 0)
481481
{
482-
if (_notchPosition > -9)
483-
{
484-
notchPositionString = string.Format("B{0}", _notchPosition);
485-
}
486-
else
487-
{
488-
notchPositionString = "EB";
489-
}
482+
notchPositionString = _notchPosition > -9 ? $"B{_notchPosition}" : "EB";
490483
}
491484
else
492485
{

source/LibRender2/Backgrounds/Background.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private void RenderBackgroundObject(BackgroundObject data)
319319

320320
if (data.Object.Mesh.VAO == null)
321321
{
322-
VAOExtensions.CreateVAO(ref data.Object.Mesh, false, renderer.DefaultShader.VertexLayout, renderer);
322+
VAOExtensions.CreateVAO(data.Object.Mesh, false, renderer.DefaultShader.VertexLayout, renderer);
323323
}
324324
}
325325

source/LibRender2/BaseRenderer.cs

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.IO;
@@ -76,6 +77,8 @@ public abstract class BaseRenderer
7677
/// <summary>The track follower for the main camera</summary>
7778
public TrackFollower CameraTrackFollower;
7879

80+
public bool RenderThreadJobWaiting;
81+
7982
/// <summary>Holds a reference to the current interface type of the game (Used by the renderer)</summary>
8083
public InterfaceType CurrentInterface
8184
{
@@ -315,6 +318,7 @@ protected BaseRenderer(HostInterface CurrentHost, BaseOptions CurrentOptions, Fi
315318
Fonts = new Fonts(currentHost, currentOptions.Font);
316319
VisibilityThread = new Thread(vt);
317320
VisibilityThread.Start();
321+
RenderThreadJobs = new ConcurrentQueue<ThreadStart>();
318322
}
319323

320324
~BaseRenderer()
@@ -687,15 +691,15 @@ public void InitializeVisibility()
687691
{
688692
for (int i = 0; i < StaticObjectStates.Count; i++)
689693
{
690-
VAOExtensions.CreateVAO(ref StaticObjectStates[i].Prototype.Mesh, false, DefaultShader.VertexLayout, this);
694+
VAOExtensions.CreateVAO(StaticObjectStates[i].Prototype.Mesh, false, DefaultShader.VertexLayout, this);
691695
if (StaticObjectStates[i].Matricies != null)
692696
{
693697
GL.CreateBuffers(1, out StaticObjectStates[i].MatrixBufferIndex);
694698
}
695699
}
696700
for (int i = 0; i < DynamicObjectStates.Count; i++)
697701
{
698-
VAOExtensions.CreateVAO(ref DynamicObjectStates[i].Prototype.Mesh, false, DefaultShader.VertexLayout, this);
702+
VAOExtensions.CreateVAO(DynamicObjectStates[i].Prototype.Mesh, false, DefaultShader.VertexLayout, this);
699703
if (DynamicObjectStates[i].Matricies != null)
700704
{
701705
GL.CreateBuffers(1, out DynamicObjectStates[i].MatrixBufferIndex);
@@ -1051,7 +1055,7 @@ public void ResetShader(Shader Shader)
10511055

10521056
if (lastError != ErrorCode.NoError)
10531057
{
1054-
throw new InvalidOperationException($"OpenGL Error: {lastError}");
1058+
// throw new InvalidOperationException($"OpenGL Error: {lastError}");
10551059
}
10561060
}
10571061
#endif
@@ -1736,7 +1740,7 @@ public void SetCursor(OpenTK.MouseCursor newCursor)
17361740

17371741
/// <summary>Sets the window state</summary>
17381742
/// <param name="windowState">The new window state</param>
1739-
public void SetWindowState(OpenTK.WindowState windowState)
1743+
public void SetWindowState(WindowState windowState)
17401744
{
17411745
GameWindow.WindowState = windowState;
17421746
if (windowState == WindowState.Fullscreen)
@@ -1762,5 +1766,23 @@ public void SetWindowSize(int width, int height)
17621766
SetWindowState(WindowState.Maximized);
17631767
}
17641768
}
1769+
1770+
public ConcurrentQueue<ThreadStart> RenderThreadJobs;
1771+
1772+
/// <summary>This method is used during loading to run commands requiring an OpenGL context in the main render loop</summary>
1773+
/// <param name="job">The OpenGL command</param>
1774+
/// <param name="timeout">The timeout</param>
1775+
public void RunInRenderThread(ThreadStart job, int timeout)
1776+
{
1777+
RenderThreadJobs.Enqueue(job);
1778+
//Don't set the job to available until after it's been loaded into the queue
1779+
RenderThreadJobWaiting = true;
1780+
//Failsafe: If our job has taken more than the timeout, stop waiting for it
1781+
//A missing texture is probably better than an infinite loadscreen
1782+
lock (job)
1783+
{
1784+
Monitor.Wait(job, timeout);
1785+
}
1786+
}
17651787
}
17661788
}

source/LibRender2/Objects/FaceState.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public FaceState(ObjectState _object, MeshFace face, BaseRenderer renderer)
1919
Renderer = renderer;
2020
if (Object.Prototype.Mesh.VAO == null && !Renderer.ForceLegacyOpenGL)
2121
{
22-
VAOExtensions.CreateVAO(ref Object.Prototype.Mesh, Object.Prototype.Dynamic, Renderer.DefaultShader.VertexLayout, Renderer);
22+
VAOExtensions.CreateVAO(Object.Prototype.Mesh, Object.Prototype.Dynamic, Renderer.DefaultShader.VertexLayout, Renderer);
2323
}
2424
}
2525

source/LibRender2/Text/Fonts.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Drawing;
22
using System.IO;
33
using OpenBveApi.Hosts;
4-
using OpenTK;
54

65
namespace LibRender2.Text
76
{

source/LibRender2/Trains/CarSection.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using OpenBveApi.Hosts;
22
using OpenBveApi.Objects;
3+
using OpenBveApi.Trains;
34

45
namespace LibRender2.Trains
56
{
@@ -17,7 +18,7 @@ public class CarSection
1718
/// <summary>Whether this is to be shown in overlay mode (e.g. panel)</summary>
1819
public readonly ObjectType Type;
1920

20-
public CarSection(HostInterface Host, ObjectType ObjectType, bool visibleFromInterior, UnifiedObject Object = null)
21+
public CarSection(HostInterface Host, ObjectType ObjectType, bool visibleFromInterior, AbstractCar baseCar = null, UnifiedObject Object = null)
2122
{
2223
currentHost = Host;
2324
Groups = new ElementsGroup[1];
@@ -46,6 +47,7 @@ public CarSection(HostInterface Host, ObjectType ObjectType, bool visibleFromInt
4647
}
4748
else if (Object is KeyframeAnimatedObject k)
4849
{
50+
k.BaseCar = baseCar;
4951
Groups[0].Keyframes = k;
5052
for (int h = 0; h < Groups[0].Keyframes.Objects.Length; h++)
5153
{

source/LibRender2/openGL/VertexArrayObject.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,23 @@ public static class VAOExtensions
167167
/// <param name="isDynamic">Whether the mesh is dynamic (e.g. part of an animated object / train)</param>
168168
/// <param name="vertexLayout">The vertex layout to use</param>
169169
/// <param name="renderer">A reference to the base renderer</param>
170-
public static void CreateVAO(ref Mesh mesh, bool isDynamic, VertexLayout vertexLayout, BaseRenderer renderer)
170+
public static void CreateVAO(Mesh mesh, bool isDynamic, VertexLayout vertexLayout, BaseRenderer renderer)
171+
{
172+
if (!renderer.GameWindow.Context.IsCurrent)
173+
{
174+
renderer.RunInRenderThread(() =>
175+
{
176+
createVAO(mesh, isDynamic, vertexLayout, renderer);
177+
}, 2000);
178+
}
179+
else
180+
{
181+
createVAO(mesh, isDynamic, vertexLayout, renderer);
182+
}
183+
}
184+
185+
186+
private static void createVAO(Mesh mesh, bool isDynamic, VertexLayout vertexLayout, BaseRenderer renderer)
171187
{
172188
try
173189
{

source/ObjectViewer/FunctionScripts.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,9 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
12231223
case Instructions.WiperPosition:
12241224
Function.Stack[s] = 1.0;
12251225
s++; break;
1226+
case Instructions.WiperState:
1227+
Function.Stack[s] = 0.0; //Not part of player train, so irrelevant
1228+
s++; break;
12261229
case Instructions.FrontCoupler:
12271230
if (Train != null)
12281231
{

source/ObjectViewer/Game/Menu.SingleMenu.cs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using OpenBveApi.Textures;
66
using System;
77
using System.IO;
8-
using OpenBveApi.Math;
98
using Path = OpenBveApi.Path;
109

1110
namespace ObjectViewer

source/ObjectViewer/Options.cs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Formats.OpenBve;
77
using ObjectViewer.Graphics;
88
using OpenBveApi;
9-
using OpenBveApi.Graphics;
109
using OpenBveApi.Input;
1110
using Path = OpenBveApi.Path;
1211

source/ObjectViewer/System/GameWindow.cs

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel;
3+
using System.Threading;
34
using ObjectViewer.Trains;
45
using OpenBveApi;
56
using OpenTK;
@@ -37,6 +38,19 @@ public ObjectViewer(int width, int height, GraphicsMode currentGraphicsMode, str
3738

3839
protected override void OnRenderFrame(FrameEventArgs e)
3940
{
41+
if (Program.Renderer.RenderThreadJobWaiting)
42+
{
43+
while (!Program.Renderer.RenderThreadJobs.IsEmpty)
44+
{
45+
Program.Renderer.RenderThreadJobs.TryDequeue(out ThreadStart currentJob);
46+
currentJob();
47+
lock (currentJob)
48+
{
49+
Monitor.Pulse(currentJob);
50+
}
51+
}
52+
Program.Renderer.RenderThreadJobWaiting = false;
53+
}
4054
double timeElapsed = RenderRealTimeElapsed;
4155

4256
// Use the OpenTK frame rate as this is much more accurate

source/ObjectViewer/Trains/NearestTrain.cs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using TrainManager.BrakeSystems;
66
using TrainManager.Car;
77
using TrainManager.Handles;
8-
using TrainManager.Power;
98
using TrainManager.Trains;
109

1110
namespace ObjectViewer.Trains

source/ObjectViewer/Trains/NearestTrainStatus.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Linq;
2-
using OpenBveApi.Runtime;
32
using TrainManager.Car;
43
using TrainManager.Handles;
54
using TrainManager.Trains;

source/OpenBVE/Game/Menu/Menu.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ public override void ProcessCommand(Translations.Command cmd, double timeElapsed
766766
case MenuTag.ViewLog:
767767
try
768768
{
769-
var file = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "log.txt");
769+
var file = Path.CombineFile(Program.FileSystem.SettingsFolder, "log.txt");
770770

771771
if (File.Exists(file))
772772
{

source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs

+10
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,16 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
15011501
Function.Stack[s] = Train.Cars[Train.DriverCar].Windscreen.Wipers.CurrentPosition;
15021502
}
15031503
s++; break;
1504+
case Instructions.WiperState:
1505+
if (Train == null || !Train.IsPlayerTrain)
1506+
{
1507+
Function.Stack[s] = 0.0; //Not part of player train, so irrelevant
1508+
}
1509+
else
1510+
{
1511+
Function.Stack[s] = (int)Train.Cars[Train.DriverCar].Windscreen.Wipers.CurrentSpeed;
1512+
}
1513+
s++; break;
15041514
case Instructions.BrightnessOfCar:
15051515
if (Train == null) {
15061516
Function.Stack[s - 1] = 0.0;

0 commit comments

Comments
 (0)