Skip to content

Commit 636134c

Browse files
authored
Merge pull request #481 from openrails/release/1.4
Merge pull request #476 from twpol/feature/update-from-anywhere
2 parents 1adf0ad + acd8383 commit 636134c

File tree

4 files changed

+51
-32
lines changed

4 files changed

+51
-32
lines changed

Source/ORTS.Updater/UpdateManager.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,16 @@ void ValidateLastUpdate()
222222
if (LastUpdate != null)
223223
{
224224
var uri = new Uri(LastUpdate.Url, UriKind.RelativeOrAbsolute);
225-
if (uri.IsAbsoluteUri)
226-
{
227-
LastUpdate = null;
228-
LastCheckError = new InvalidDataException("Update URL must be relative to channel URL.");
229-
}
225+
226+
// All relative URLs are valid
227+
if (!uri.IsAbsoluteUri) return;
228+
229+
// Official GitHub URLs are valid
230+
if (uri.Scheme == "https" && uri.Host == "github.com" && uri.AbsolutePath.StartsWith("/openrails/openrails/releases")) return;
231+
232+
// Everything else is invalid
233+
LastUpdate = null;
234+
LastCheckError = new InvalidDataException("Update URL must be relative to channel URL or from https://github.com/openrails/openrails/releases.");
230235
}
231236
}
232237

Source/RunActivity/Viewer3D/Materials.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
12071207

12081208
public class SolidColorMaterial : Material
12091209
{
1210-
static BasicEffect basicEffect;
1210+
BasicEffect basicEffect;
12111211

12121212
public SolidColorMaterial(Viewer viewer, float a, float r, float g, float b)
12131213
: base(viewer, null)

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ public CABViewControlTypes GetControlType()
14681468
/// Gets the requested Locomotive data and returns it as a fraction (from 0 to 1) of the range between Min and Max values.
14691469
/// </summary>
14701470
/// <returns>Data value as fraction (from 0 to 1) of the range between Min and Max values</returns>
1471-
public float GetRangeFraction()
1471+
public float GetRangeFraction(bool offsetFromZero = false)
14721472
{
14731473
var data = Locomotive.GetDataOf(Control);
14741474
if (data < Control.MinValue)
@@ -1479,7 +1479,7 @@ public float GetRangeFraction()
14791479
if (Control.MaxValue == Control.MinValue)
14801480
return 0;
14811481

1482-
return (float)((data - Control.MinValue) / (Control.MaxValue - Control.MinValue));
1482+
return (float)((data - (offsetFromZero && Control.MinValue < 0 ? 0 : Control.MinValue)) / (Control.MaxValue - Control.MinValue));
14831483
}
14841484

14851485
public CABViewControlStyles GetStyle()
@@ -1630,7 +1630,8 @@ public CabViewGaugeRenderer(Viewer viewer, MSTSLocomotive locomotive, CVCFirebox
16301630

16311631
public color GetColor(out bool positive)
16321632
{
1633-
if (Locomotive.GetDataOf(Control) < 0) { positive = false; return Gauge.NegativeColor; }
1633+
if (Locomotive.GetDataOf(Control) < 0)
1634+
{ positive = false; return Gauge.NegativeColor; }
16341635
else { positive = true; return Gauge.PositiveColor; }
16351636
}
16361637

@@ -2986,7 +2987,7 @@ public ThreeDimCabDigit(Viewer viewer, int iMatrix, string size, string aceFile,
29862987

29872988
//create the shape primitive
29882989
shapePrimitive = new MutableShapePrimitive(Material, NumVertices, NumIndices, new[] { -1 }, 0);
2989-
UpdateShapePrimitive();
2990+
UpdateShapePrimitive(Material);
29902991

29912992
}
29922993

@@ -2997,11 +2998,11 @@ Material FindMaterial(bool Alert)
29972998
CABViewControlTypes controltype = CVFR.GetControlType();
29982999
Material material = null;
29993000

3000-
if (AceFile != "")
3001+
if (Alert) { imageName = "alert.ace"; }
3002+
else if (AceFile != "")
30013003
{
30023004
imageName = AceFile;
30033005
}
3004-
else if (Alert) { imageName = "alert.ace"; }
30053006
else
30063007
{
30073008
switch (controltype)
@@ -3085,11 +3086,11 @@ public void UpdateDigit()
30853086
}
30863087

30873088
//update the shape primitive
3088-
UpdateShapePrimitive();
3089+
UpdateShapePrimitive(UsedMaterial);
30893090

30903091
}
30913092

3092-
private void UpdateShapePrimitive()
3093+
private void UpdateShapePrimitive(Material material)
30933094
{
30943095
var indexData = new short[NumIndices];
30953096
Array.Copy(TriangleListIndices, indexData, NumIndices);
@@ -3098,6 +3099,8 @@ private void UpdateShapePrimitive()
30983099
var vertexData = new VertexPositionNormalTexture[NumVertices];
30993100
Array.Copy(VertexList, vertexData, NumVertices);
31003101
shapePrimitive.SetVertexData(vertexData, 0, NumVertices, NumIndices / 3);
3102+
3103+
shapePrimitive.SetMaterial(material);
31013104
}
31023105

31033106
//ACE MAP:
@@ -3216,8 +3219,9 @@ public ThreeDimCabGaugeNative(Viewer viewer, int iMatrix, string size, string le
32163219

32173220

32183221
//create the shape primitive
3219-
shapePrimitive = new MutableShapePrimitive(FindMaterial(), NumVertices, NumIndices, new[] { -1 }, 0);
3220-
UpdateShapePrimitive();
3222+
var material = FindMaterial();
3223+
shapePrimitive = new MutableShapePrimitive(material, NumVertices, NumIndices, new[] { -1 }, 0);
3224+
UpdateShapePrimitive(material);
32213225

32223226
}
32233227

@@ -3229,13 +3233,14 @@ Material FindMaterial()
32293233
{
32303234
if (PositiveMaterial == null)
32313235
{
3232-
PositiveMaterial = new SolidColorMaterial(this.Viewer, 0f, c.R, c.G, c.B);
3236+
PositiveMaterial = new SolidColorMaterial(this.Viewer, c.A, c.R, c.G, c.B);
32333237
}
32343238
return PositiveMaterial;
32353239
}
32363240
else
32373241
{
3238-
if (NegativeMaterial == null) NegativeMaterial = new SolidColorMaterial(this.Viewer, c.A, c.R, c.G, c.B);
3242+
if (NegativeMaterial == null)
3243+
NegativeMaterial = new SolidColorMaterial(this.Viewer, c.A, c.R, c.G, c.B);
32393244
return NegativeMaterial;
32403245
}
32413246
}
@@ -3247,45 +3252,46 @@ public void UpdateDigit()
32473252

32483253
Material UsedMaterial = FindMaterial();
32493254

3250-
float length = CVFR.GetRangeFraction();
3255+
float length = CVFR.GetRangeFraction(true);
32513256

32523257
CVCGauge gauge = CVFR.GetGauge();
32533258

32543259
var len = maxLen * length;
3260+
var absLen = Math.Abs(len);
32553261
Vertex v1, v2, v3, v4;
32563262

32573263
//the left-bottom vertex if ori=0;dir=0, right-bottom if ori=0,dir=1; left-top if ori=1,dir=0; left-bottom if ori=1,dir=1;
32583264
v1 = new Vertex(0f, 0f, 0.002f, 0, 0, -1, 0f, 0f);
32593265

32603266
if (Orientation == 0)
32613267
{
3262-
if (Direction == 0)//moving right
3268+
if (Direction == 0 ^ len < 0)//moving right
32633269
{
32643270
//other vertices
32653271
v2 = new Vertex(0f, width, 0.002f, 0, 0, 1, 0f, 0f);
3266-
v3 = new Vertex(len, width, 0.002f, 0, 0, 1, 0f, 0f);
3267-
v4 = new Vertex(len, 0f, 0.002f, 0, 0, 1, 0f, 0f);
3272+
v3 = new Vertex(absLen, width, 0.002f, 0, 0, 1, 0f, 0f);
3273+
v4 = new Vertex(absLen, 0f, 0.002f, 0, 0, 1, 0f, 0f);
32683274
}
32693275
else //moving left
32703276
{
32713277
v4 = new Vertex(0f, width, 0.002f, 0, 0, 1, 0f, 0f);
3272-
v3 = new Vertex(-len, width, 0.002f, 0, 0, 1, 0f, 0f);
3273-
v2 = new Vertex(-len, 0f, 0.002f, 0, 0, 1, 0f, 0f);
3278+
v3 = new Vertex(-absLen, width, 0.002f, 0, 0, 1, 0f, 0f);
3279+
v2 = new Vertex(-absLen, 0f, 0.002f, 0, 0, 1, 0f, 0f);
32743280
}
32753281
}
32763282
else
32773283
{
3278-
if (Direction == 1)//up
3284+
if (Direction == 1 ^ len < 0)//up
32793285
{
32803286
//other vertices
3281-
v2 = new Vertex(0f, len, 0.002f, 0, 0, 1, 0f, 0f);
3282-
v3 = new Vertex(width, len, 0.002f, 0, 0, 1, 0f, 0f);
3287+
v2 = new Vertex(0f, absLen, 0.002f, 0, 0, 1, 0f, 0f);
3288+
v3 = new Vertex(width, absLen, 0.002f, 0, 0, 1, 0f, 0f);
32833289
v4 = new Vertex(width, 0f, 0.002f, 0, 0, 1, 0f, 0f);
32843290
}
32853291
else //moving down
32863292
{
3287-
v4 = new Vertex(0f, -len, 0.002f, 0, 0, 1, 0f, 0f);
3288-
v3 = new Vertex(width, -len, 0.002f, 0, 0, 1, 0f, 0f);
3293+
v4 = new Vertex(0f, -absLen, 0.002f, 0, 0, 1, 0f, 0f);
3294+
v3 = new Vertex(width, -absLen, 0.002f, 0, 0, 1, 0f, 0f);
32893295
v2 = new Vertex(width, 0, 0.002f, 0, 0, 1, 0f, 0f);
32903296
}
32913297
}
@@ -3298,7 +3304,7 @@ public void UpdateDigit()
32983304
NumVertices += 4;
32993305

33003306
//update the shape primitive
3301-
UpdateShapePrimitive();
3307+
UpdateShapePrimitive(UsedMaterial);
33023308

33033309
}
33043310

@@ -3330,7 +3336,7 @@ static float GetTextureCoordY(char c)
33303336
return 1.0f;
33313337
}
33323338

3333-
private void UpdateShapePrimitive()
3339+
private void UpdateShapePrimitive(Material material)
33343340
{
33353341
var indexData = new short[NumIndices];
33363342
Array.Copy(TriangleListIndices, indexData, NumIndices);
@@ -3339,6 +3345,8 @@ private void UpdateShapePrimitive()
33393345
var vertexData = new VertexPositionNormalTexture[NumVertices];
33403346
Array.Copy(VertexList, vertexData, NumVertices);
33413347
shapePrimitive.SetVertexData(vertexData, 0, NumVertices, NumIndices / 3);
3348+
3349+
shapePrimitive.SetMaterial(material);
33423350
}
33433351

33443352
public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)

Source/RunActivity/Viewer3D/Shapes.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,8 @@ public virtual void Mark()
13921392
}
13931393

13941394
/// <summary>
1395-
/// A <c>ShapePrimitive</c> that permits manipulation of the vertex and index buffers to change geometry efficiently.
1395+
/// A <c>ShapePrimitive</c> that permits manipulation of vertex and index buffers to change geometry efficiently.
1396+
/// It permits also change of material
13961397
/// </summary>
13971398
public class MutableShapePrimitive : ShapePrimitive
13981399
{
@@ -1418,6 +1419,11 @@ public void SetIndexData(short[] data)
14181419
{
14191420
IndexBuffer.SetData(data);
14201421
}
1422+
1423+
public void SetMaterial(Material material)
1424+
{
1425+
Material = material;
1426+
}
14211427
}
14221428

14231429
struct ShapeInstanceData

0 commit comments

Comments
 (0)