Skip to content

Commit a4b1aa5

Browse files
committed
Changed to be configured via the cvf file
1 parent fb94fb5 commit a4b1aa5

File tree

3 files changed

+33
-63
lines changed

3 files changed

+33
-63
lines changed

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3389,44 +3389,20 @@ public ThreeDimentionCabViewer(Viewer viewer, MSTSLocomotive car, MSTSLocomotive
33893389
}
33903390
}
33913391

3392-
var screens = TrainCarShape?.SharedShape?.LodControls?.FirstOrDefault()?.DistanceLevels?.FirstOrDefault()?
3393-
.SubObjects?.SelectMany(s => s.ShapePrimitives).Select(p => p.Material).Where(m => m is ScreenMaterial);
3394-
foreach (var screen in screens)
3392+
// Find the animated textures, like screens
3393+
if (locoViewer.ThreeDimentionCabRenderer.ControlMap.Values.FirstOrDefault(c => c is DriverMachineInterfaceRenderer) is DriverMachineInterfaceRenderer cvcr
3394+
&& cvcr.Control?.ACEFile is var textureName && textureName != null)
33953395
{
3396-
var material = screen as ScreenMaterial;
3397-
if (!int.TryParse(material.Key.Split(':').LastOrDefault(), out var id))
3398-
id = 0;
3399-
var des = material.Key.AsSpan();
3400-
var parameters = new Dictionary<string, string> { { "type", des.Slice(0, des.IndexOf(',')).ToString() } };
3401-
des = des.Slice(des.IndexOf(',') + 1);
3402-
while (des.IndexOf(',') is var c && c != -1)
3396+
textureName = Path.GetFileName(textureName).ToLower();
3397+
if (TrainCarShape?.SharedShape?.LodControls?.FirstOrDefault()?.DistanceLevels?.FirstOrDefault()?
3398+
.SubObjects?.SelectMany(s => s.ShapePrimitives).Where(p => p.Material.Key.Contains(textureName)).FirstOrDefault() is var primitive && primitive != null)
34033399
{
3404-
if (des.IndexOf('=') is var e && e != -1)
3405-
{
3406-
var key = des.Slice(0, e).ToString();
3407-
if (!parameters.ContainsKey(key))
3408-
parameters.Add(key, des.Slice(e + 1, c - e - 1).ToString());
3409-
}
3410-
des = des.Slice(c + 1);
3411-
}
3412-
3413-
var control = new CVCScreen()
3414-
{
3415-
CustomParameters = { { "texture3d", "1" } },
3416-
Units = parameters.TryGetValue("units", out var units) && units == "mph" ? CABViewControlUnits.MILES_PER_HOUR : CABViewControlUnits.KM_PER_HOUR,
3417-
};
3418-
foreach (var p in parameters.Keys)
3419-
if (!control.CustomParameters.ContainsKey(p))
3420-
control.CustomParameters.Add(p, parameters[p]);
3421-
3422-
if (parameters.TryGetValue("type", out var type) && type == "screens/etcs_dmi")
3423-
{
3424-
// Usage: in s file e.g.: image ( screens/etcs_dmi,maxspeed=280,maxvisiblespeed=280,units=kmph,displayunits=0 )
3425-
3426-
var renderer = new DriverMachineInterfaceRenderer(Viewer, Locomotive, control, Viewer.MaterialManager.CabShader);
3427-
material.Set2DRenderer(renderer);
3428-
var sd3d = new ThreeDimCabScreen(Viewer, material.HierarchyIndex, TrainCarShape, renderer);
3429-
ScreenDisplays3D.Add((new CabViewControlType(CABViewControlTypes.ORTS_ETCS), id), sd3d);
3400+
cvcr.SetTexture3D();
3401+
var material = Viewer.MaterialManager.Load("Screen", TrainCarShape.SharedShape.ReferencePath + cvcr.Control.ACEFile, primitive.HierarchyIndex) as ScreenMaterial;
3402+
material.Set2DRenderer(cvcr);
3403+
primitive.SetMaterial(material);
3404+
ScreenDisplays3D.Add((new CabViewControlType(CABViewControlTypes.ORTS_ETCS), 0),
3405+
new ThreeDimCabScreen(Viewer, material.HierarchyIndex, TrainCarShape, cvcr));
34303406
}
34313407
}
34323408
}

Source/RunActivity/Viewer3D/RollingStock/SubSystems/ETCS/DriverMachineInterface.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public enum DMIMode
9595
public bool IsSoftLayout;
9696
public DMIWindow ActiveWindow;
9797
DMIButton ActiveButton;
98-
public readonly bool IsTexture3D;
9998

10099
public static readonly Dictionary<DMIMode, (int Width, int Height)> ScreenSizes = new Dictionary<DMIMode, (int, int)>
101100
{
@@ -108,24 +107,13 @@ public enum DMIMode
108107
public DriverMachineInterface(MSTSLocomotive locomotive, Viewer viewer, CabViewControl control)
109108
{
110109
if (!(control is CVCScreen cvcScreen))
111-
{
112110
CurrentDMIMode = DMIMode.GaugeOnly;
113-
}
114-
else
115-
{
116-
if (!(cvcScreen.CustomParameters.TryGetValue("mode", out var mode) && Enum.TryParse(mode, ignoreCase: true, out CurrentDMIMode)))
117-
CurrentDMIMode = DMIMode.FullSize;
118-
IsTexture3D = cvcScreen.CustomParameters.TryGetValue("texture3d", out var texture3d) && texture3d == "1";
119-
}
111+
else if (!(cvcScreen.CustomParameters.TryGetValue("mode", out var mode) && Enum.TryParse(mode, ignoreCase: true, out CurrentDMIMode)))
112+
CurrentDMIMode = DMIMode.FullSize;
120113

121114
Width = ScreenSizes[CurrentDMIMode].Width;
122115
Height = ScreenSizes[CurrentDMIMode].Height;
123116

124-
if (IsTexture3D)
125-
{
126-
control.Width = Width;
127-
control.Height = Height;
128-
}
129117
SizeTo((float)control.Width, (float)control.Height);
130118

131119
Viewer = viewer;
@@ -175,7 +163,7 @@ public void PrepareFrame(float elapsedSeconds)
175163
}
176164
public void SizeTo(float width, float height)
177165
{
178-
Scale = Math.Min(width / Width, height / Height);
166+
Scale = width != 0 && height != 0 ? Math.Min(width / Width, height / Height) : 1;
179167

180168
if (Math.Abs(1f - PrevScale / Scale) > 0.1f)
181169
{
@@ -779,6 +767,8 @@ public class DriverMachineInterfaceRenderer : CabViewControlRenderer, ICabViewMo
779767
DriverMachineInterface DMI;
780768
bool Zoomed = false;
781769
protected Rectangle DrawPosition;
770+
bool IsTexture3D;
771+
782772
[CallOnThread("Loader")]
783773
public DriverMachineInterfaceRenderer(Viewer viewer, MSTSLocomotive locomotive, CVCScreen control, CabShader shader)
784774
: base(viewer, locomotive, control, shader)
@@ -799,7 +789,7 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
799789
if (!IsPowered && Control.HideIfDisabled)
800790
return;
801791

802-
if (!DMI.IsTexture3D)
792+
if (!IsTexture3D)
803793
{
804794
base.PrepareFrame(frame, elapsedTime);
805795
var xScale = (float)Viewer.CabWidthPixels / 640;
@@ -858,6 +848,15 @@ public string GetControlName()
858848
return "";
859849
}
860850
public string ControlLabel => GetControlName();
851+
852+
public void SetTexture3D()
853+
{
854+
IsTexture3D = true;
855+
Control.Width = DMI.Width;
856+
Control.Height = DMI.Height;
857+
DMI.SizeTo(DMI.Width, DMI.Height);
858+
}
859+
861860
public override void Draw(GraphicsDevice graphicsDevice)
862861
{
863862
DMI.Draw(ControlView.SpriteBatch, new Point(DrawPosition.X, DrawPosition.Y));

Source/RunActivity/Viewer3D/Shapes.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,11 @@ public override void Draw(GraphicsDevice graphicsDevice)
17901790
}
17911791
}
17921792

1793+
public void SetMaterial(Material material)
1794+
{
1795+
Material = material;
1796+
}
1797+
17931798
[CallOnThread("Loader")]
17941799
public virtual void Mark()
17951800
{
@@ -1832,11 +1837,6 @@ public void SetIndexData(short[] data)
18321837
{
18331838
IndexBuffer.SetData(data);
18341839
}
1835-
1836-
public void SetMaterial(Material material)
1837-
{
1838-
Material = material;
1839-
}
18401840
}
18411841

18421842
struct ShapeInstanceData
@@ -2283,12 +2283,7 @@ public SubObject(sub_object sub_object, ref int totalPrimitiveIndex, int[] hiera
22832283
if (String.IsNullOrEmpty(sharedShape.ReferencePath))
22842284
material = sharedShape.Viewer.MaterialManager.Load("Scenery", Helpers.GetRouteTextureFile(sharedShape.Viewer.Simulator, textureFlags, imageName), (int)options, texture.MipMapLODBias);
22852285
else
2286-
{
2287-
if (imageName.ToLower().StartsWith("screens/"))
2288-
material = sharedShape.Viewer.MaterialManager.Load("Screen", imageName + "," + Guid.NewGuid(), vertexState.imatrix);
2289-
else
2290-
material = sharedShape.Viewer.MaterialManager.Load("Scenery", Helpers.GetTextureFile(sharedShape.Viewer.Simulator, textureFlags, sharedShape.ReferencePath, imageName), (int)options, texture.MipMapLODBias);
2291-
}
2286+
material = sharedShape.Viewer.MaterialManager.Load("Scenery", Helpers.GetTextureFile(sharedShape.Viewer.Simulator, textureFlags, sharedShape.ReferencePath, imageName), (int)options, texture.MipMapLODBias);
22922287
}
22932288
else
22942289
{

0 commit comments

Comments
 (0)