Skip to content

Commit ded237e

Browse files
committed
Automatic merge of T1.5.1-1197-g092fac25e3 and 16 pull requests
- Pull request #959 at 2452cb0: Fix TrackViewer crash on big zoom value - Pull request #799 at dfc715e: Consolidated wind simulation - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #885 at 8f473ce: feat: Add notifications to Menu - Pull request #891 at 9a1d6b2: Auto save - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #952 at 8347095: Investigation - Pulsing graphics - Pull request #953 at a519452: Fix Lights Crash on Corrupt Shapes - Pull request #954 at e715fa4: Multiple Track Profiles & Superelevation Improvements - Pull request #962 at 46d0472: Fix pantographs on unpowered cars - Pull request #972 at e90a2aa: On Map window color changed switch or signal is not changed - Pull request #974 at 5faea6f: Bug fix for https://bugs.launchpad.net/or/+bug/2076034 Doors remain open in AI trains - Pull request #980 at a7406de: Downloading route content (Github, zip) second part - Pull request #900 at c27f32d: DMI updates - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #981 at c1f4301: Multiple type trainset lightglows
18 parents d89c006 + 092fac2 + 2452cb0 + dfc715e + d00beb9 + 8f473ce + 9a1d6b2 + 1f5ba4c + 8347095 + a519452 + e715fa4 + 46d0472 + e90a2aa + 5faea6f + a7406de + c27f32d + f92de76 + c1f4301 commit ded237e

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed

Source/Orts.Formats.Msts/LightCollection.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ public class Light
346346
public float FadeOut;
347347
public List<LightState> States = new List<LightState>();
348348
public List<LightCondition> Conditions = new List<LightCondition>();
349+
public string Graphic;
349350

350351
public Light(int index, STFReader stf)
351352
{
@@ -373,6 +374,7 @@ public Light(int index, STFReader stf)
373374
}),
374375
new STFReader.TokenProcessor("shapeindex", ()=>{ ShapeIndex = stf.ReadIntBlock(null); }),
375376
new STFReader.TokenProcessor("shapehierarchy", ()=>{ ShapeHierarchy = stf.ReadStringBlock(null).ToUpper(); }),
377+
new STFReader.TokenProcessor("ortsgraphic", ()=>{ Graphic = stf.ReadStringBlock(null).ToUpper(); }),
376378
});
377379
}
378380

@@ -401,6 +403,7 @@ public Light(Light light, bool reverse)
401403
public class LightCollection
402404
{
403405
public List<Light> Lights = new List<Light>();
406+
public string GeneralLightGlowGraphic = "LightGlow.png";
404407

405408
// Array of bools, one per type of condition in the same order as presented in the 'LightCondition' class
406409
// A 'true' indicates all lights in this set ignore the corresponding condition, so we don't need to waste time thinking about it
@@ -411,7 +414,8 @@ public LightCollection(STFReader stf)
411414
{
412415
stf.MustMatch("(");
413416
stf.ReadInt(null); // count; ignore this because its not always correct
414-
stf.ParseBlock(new[] {
417+
stf.ParseBlock(new[]{
418+
new STFReader.TokenProcessor("ortsgraphic", ()=>{ GeneralLightGlowGraphic = stf.ReadStringBlock("Lightglow.png").ToUpper(); }),
415419
new STFReader.TokenProcessor("light", ()=>{ Lights.Add(new Light(Lights.Count, stf)); }),
416420
});
417421
if (Lights.Count == 0)
-27.2 KB
Loading
35.3 KB
Loading

Source/RunActivity/RunActivity.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@
462462
<Content Include="Content\LightGlow.png">
463463
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
464464
</Content>
465+
<Content Include="Content\ORTSLightGlow.png">
466+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
467+
</Content>
465468
<Content Include="Content\Loading.png">
466469
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
467470
</Content>

Source/RunActivity/Viewer3D/Lights.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
using System;
3737
using System.Collections.Generic;
3838
using System.Diagnostics;
39+
using System.IO;
3940
using System.Linq;
4041

4142
namespace Orts.Viewer3D
@@ -89,8 +90,8 @@ public LightViewer(Viewer viewer, TrainCar car, TrainCarViewer carViewer)
8990
Viewer = viewer;
9091
Car = car;
9192
CarViewer = carViewer;
92-
93-
LightGlowMaterial = viewer.MaterialManager.Load("LightGlow");
93+
94+
LightGlowMaterial = viewer.MaterialManager.Load("LightGlow", DefineFullTexturePath(Car.Lights.GeneralLightGlowGraphic));
9495
LightConeMaterial = viewer.MaterialManager.Load("LightCone");
9596

9697
UpdateState();
@@ -102,6 +103,8 @@ public LightViewer(Viewer viewer, TrainCar car, TrainCarViewer carViewer)
102103
{
103104
case LightType.Glow:
104105
LightPrimitives.Add(new LightGlowPrimitive(this, Viewer.RenderProcess, light));
106+
if (light.Graphic != null)
107+
(LightPrimitives.Last() as LightGlowPrimitive).SpecificGlowMaterial = viewer.MaterialManager.Load("LightGlow", DefineFullTexturePath(light.Graphic));
105108
break;
106109
case LightType.Cone:
107110
LightPrimitives.Add(new LightConePrimitive(this, Viewer.RenderProcess, light));
@@ -149,6 +152,15 @@ public LightViewer(Viewer viewer, TrainCar car, TrainCarViewer carViewer)
149152
UpdateActiveLightCone();
150153
}
151154

155+
string DefineFullTexturePath(string textureName)
156+
{
157+
if (File.Exists(Path.Combine(Path.GetDirectoryName(Car.WagFilePath), textureName)))
158+
return Path.Combine(Path.GetDirectoryName(Car.WagFilePath), textureName);
159+
if (File.Exists(Path.Combine(Viewer.ContentPath, textureName)))
160+
return Path.Combine(Viewer.ContentPath, textureName);
161+
return Path.Combine(Viewer.ContentPath, "LightGlow.png");
162+
}
163+
152164
void UpdateActiveLightCone()
153165
{
154166
var newLightCone = (LightConePrimitive)LightPrimitives.FirstOrDefault(lm => lm is LightConePrimitive && lm.Enabled);
@@ -220,9 +232,9 @@ public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
220232
if ((lightPrimitive.Enabled || lightPrimitive.FadeOut) && lightPrimitive is LightGlowPrimitive)
221233
{
222234
if (ShapeXNATranslations.TryGetValue(lightPrimitive.Light.ShapeIndex, out Matrix lightMatrix))
223-
frame.AddPrimitive(LightGlowMaterial, lightPrimitive, RenderPrimitiveGroup.Lights, ref lightMatrix);
235+
frame.AddPrimitive(lightPrimitive.Light.Graphic != null ? (lightPrimitive as LightGlowPrimitive).SpecificGlowMaterial : LightGlowMaterial, lightPrimitive, RenderPrimitiveGroup.Lights, ref lightMatrix);
224236
else
225-
frame.AddPrimitive(LightGlowMaterial, lightPrimitive, RenderPrimitiveGroup.Lights, ref xnaDTileTranslation);
237+
frame.AddPrimitive(lightPrimitive.Light.Graphic != null ? (lightPrimitive as LightGlowPrimitive).SpecificGlowMaterial : LightGlowMaterial, lightPrimitive, RenderPrimitiveGroup.Lights, ref xnaDTileTranslation);
226238
}
227239

228240
#if DEBUG_LIGHT_CONE
@@ -252,6 +264,11 @@ public void Mark()
252264
{
253265
LightGlowMaterial.Mark();
254266
LightConeMaterial.Mark();
267+
foreach (var lightPrimitive in LightPrimitives)
268+
if (lightPrimitive is LightGlowPrimitive && lightPrimitive.Light.Graphic != null)
269+
{
270+
(lightPrimitive as LightGlowPrimitive).SpecificGlowMaterial.Mark();
271+
}
255272
}
256273

257274
public static void CalculateLightCone(LightState lightState, out Vector3 position, out Vector3 direction, out float angle, out float radius, out float distance, out Vector4 color)
@@ -680,6 +697,7 @@ public class LightGlowPrimitive : LightPrimitive
680697
static VertexDeclaration VertexDeclaration;
681698
VertexBuffer VertexBuffer;
682699
static IndexBuffer IndexBuffer;
700+
public Material SpecificGlowMaterial;
683701

684702
public LightGlowPrimitive(LightViewer lightViewer, RenderProcess renderProcess, Light light)
685703
: base(light)
@@ -932,11 +950,11 @@ public class LightGlowMaterial : Material
932950
{
933951
readonly Texture2D LightGlowTexture;
934952

935-
public LightGlowMaterial(Viewer viewer)
936-
: base(viewer, null)
953+
public LightGlowMaterial(Viewer viewer, string textureName)
954+
: base(viewer, textureName)
937955
{
938956
// TODO: This should happen on the loader thread.
939-
LightGlowTexture = SharedTextureManager.Get(Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Viewer.ContentPath, "Lightglow.png"));
957+
LightGlowTexture = SharedTextureManager.Get(Viewer.RenderProcess.GraphicsDevice, textureName);
940958
}
941959

942960
public override void SetState(GraphicsDevice graphicsDevice, Material previousMaterial)

Source/RunActivity/Viewer3D/Materials.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public Material Load(string materialName, string textureName = null, int options
360360
Materials[materialKey] = new LightConeMaterial(Viewer);
361361
break;
362362
case "LightGlow":
363-
Materials[materialKey] = new LightGlowMaterial(Viewer);
363+
Materials[materialKey] = new LightGlowMaterial(Viewer, textureName);
364364
break;
365365
case "PopupWindow":
366366
Materials[materialKey] = new PopupWindowMaterial(Viewer);

0 commit comments

Comments
 (0)