5151// Debug for Steam Cylinder Events
5252//#define DEBUG_STEAM_CYLINDER_EVENTS
5353
54+ // Debug for Steam Cylinder Events
55+ //#define DEBUG_STEAM_EXHAUST_EVENTS
56+
5457/* STEAM LOCOMOTIVE CLASSES
5558 *
5659 * The Locomotive is represented by two classes:
8083using Orts.Simulation;
8184using Orts.Simulation.Simulation.RollingStocks.SubSystems.PowerSupplies;
8285using Orts.Simulation.RollingStocks.SubSystems.PowerTransmissions;
86+ using SharpDX.Direct3D9;
8387
8488namespace Orts.Simulation.RollingStocks
8589{
@@ -713,6 +717,8 @@ public float TenderCoalMassKG // Decreased by firing and increased
713717 public float BoosterCylinderSteamExhaust02SteamVelocityMpS;
714718 public float BoosterCylinderSteamExhaust02SteamVolumeM3pS;
715719
720+ float SteamExhaustDebugTimerS;
721+
716722 float BoosterCylinderSteamExhaustTimerS = 0.0f;
717723 bool BoosterCylinderSteamExhaust01On = false;
718724 bool BoosterCylinderSteamExhaust02On = false;
@@ -2574,12 +2580,22 @@ public override void Update(float elapsedClockSeconds)
25742580 private void UpdateFX(float elapsedClockSeconds)
25752581 {
25762582 // This section updates the various steam effects for the steam locomotive. It uses the particle drawer which has the following inputs.
2577- // Stack - steam velocity, steam volume, particle duration, colour, whislts all other effects use these inputs only, non-Stack - steam velocity, steam volume, particle duration
2583+ // Stack - steam velocity, steam volume, particle duration, colour, whislts all other effects use these inputs only, non-Stack -
2584+ // steam velocity, steam volume, particle duration.
2585+ //
25782586 // The steam effects have been adjust based upon their "look and feel", as the particle drawer has a number of different multipliers in it.
2587+ // Steam effects will turn on at the point where the cylinder exhausts in the stroke, and then off at the end of the stroke. Note that each cylinder
2588+ // has a forward and reverse stroke in each wheel revolution.
2589+ //
25792590 // Steam Velocity - increasing this value increases how far the steam jets out of the orifice, steam volume adjust volume, particle duration adjusts the "decay' time of the steam
25802591 // The duration time is reduced with speed to reduce the steam trail behind the locomotive when running at speed.
25812592 // Any of the steam effects can be disabled by not defining them in the ENG file, and thus they will not be displayed in the viewer.
25822593
2594+
2595+ float[] ExhaustnormalisedCrankAngleRad = new float[3];
2596+ float[] ExhaustexhaustCrankAngleRad = new float[3];
2597+
2598+
25832599 // Cylinder steam cock effects
25842600 if (CylinderAdvancedSteamEffects) // For advanced steam effects process each cylinder individually -
25852601 // - all ENG files will need to be changed.
@@ -2602,19 +2618,37 @@ private void UpdateFX(float elapsedClockSeconds)
26022618 float normalisedCrankAngleRad = NormalisedCrankAngle(0, i, crankAngleDiffRad);
26032619
26042620 // Exhaust crank angle
2605- float exhaustCrankAngleRad = 0;
2621+ float exhaustCrankAngleRadFor = 0;
2622+ float exhaustCrankAngleRadRev = 0;
2623+
26062624 if (normalisedCrankAngleRad <= MathHelper.Pi)
26072625 {
2608- exhaustCrankAngleRad = CylinderExhaustOpenFactor * (float)Math.PI;
2626+ exhaustCrankAngleRadFor = CylinderExhaustOpenFactor * (float)Math.PI;
26092627 }
26102628 else
26112629 {
2612- exhaustCrankAngleRad = CylinderExhaustOpenFactor * (float)Math.PI + (float)Math.PI;
2630+ exhaustCrankAngleRadFor = CylinderExhaustOpenFactor * (float)Math.PI + (float)Math.PI;
2631+ }
2632+
2633+ if (exhaustCrankAngleRadFor > 2 * (float)Math.PI)
2634+ {
2635+ exhaustCrankAngleRadFor -= 2 * (float)Math.PI;
26132636 }
26142637
2638+ exhaustCrankAngleRadRev = exhaustCrankAngleRadFor + (float)Math.PI;
2639+
2640+ if (exhaustCrankAngleRadRev > 2 * (float)Math.PI)
2641+ {
2642+ exhaustCrankAngleRadRev -= 2 * (float)Math.PI;
2643+ }
2644+
2645+ ExhaustnormalisedCrankAngleRad[i] = normalisedCrankAngleRad;
2646+ ExhaustexhaustCrankAngleRad[i] = exhaustCrankAngleRadFor;
2647+
2648+
26152649 if (absSpeedMpS > 0.001)
26162650 {
2617- if (i == 0 && ((normalisedCrankAngleRad <= MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad ) || (normalisedCrankAngleRad < 2 * MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad )))
2651+ if (i == 0 && ((normalisedCrankAngleRad >= exhaustCrankAngleRadFor && normalisedCrankAngleRad <= MathHelper.Pi ) || (normalisedCrankAngleRad >= exhaustCrankAngleRadRev && normalisedCrankAngleRad < 2 * MathHelper.Pi )))
26182652 {
26192653 CylinderSteamExhaust1On = true;
26202654 }
@@ -2623,15 +2657,15 @@ private void UpdateFX(float elapsedClockSeconds)
26232657 CylinderSteamExhaust1On = false;
26242658 }
26252659
2626- else if (i == 1 && ((normalisedCrankAngleRad <= MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad ) || (normalisedCrankAngleRad < 2 * MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad )))
2660+ else if (i == 1 && ((normalisedCrankAngleRad >= exhaustCrankAngleRadFor && normalisedCrankAngleRad <= MathHelper.Pi ) || (normalisedCrankAngleRad >= exhaustCrankAngleRadRev && normalisedCrankAngleRad < 2 * MathHelper.Pi)))
26272661 {
26282662 CylinderSteamExhaust2On = true;
26292663 }
26302664 else if (i == 1)
26312665 {
26322666 CylinderSteamExhaust2On = false;
26332667 }
2634- else if (i == 2 && ((normalisedCrankAngleRad <= MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad ) || (normalisedCrankAngleRad < 2 * MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad )))
2668+ else if (i == 2 && ((normalisedCrankAngleRad >= exhaustCrankAngleRadFor && normalisedCrankAngleRad <= MathHelper.Pi ) || (normalisedCrankAngleRad >= exhaustCrankAngleRadRev && normalisedCrankAngleRad < 2 * MathHelper.Pi)))
26352669 {
26362670 CylinderSteamExhaust3On = true;
26372671 }
@@ -2640,7 +2674,7 @@ private void UpdateFX(float elapsedClockSeconds)
26402674 CylinderSteamExhaust3On = false;
26412675 }
26422676
2643- else if (i == 3 && ((normalisedCrankAngleRad <= MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad ) || (normalisedCrankAngleRad < 2 * MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad )))
2677+ else if (i == 3 && ((normalisedCrankAngleRad >= exhaustCrankAngleRadFor && normalisedCrankAngleRad <= MathHelper.Pi ) || (normalisedCrankAngleRad >= exhaustCrankAngleRadRev && normalisedCrankAngleRad < 2 * MathHelper.Pi)))
26442678 {
26452679 CylinderSteamExhaust4On = true;
26462680 }
@@ -2818,26 +2852,41 @@ private void UpdateFX(float elapsedClockSeconds)
28182852 float normalisedCrankAngleRad = NormalisedCrankAngle(1,i, crankAngleDiffRad);
28192853
28202854 // Exhaust crank angle
2821- float exhaustCrankAngleRad = 0;
2855+ float exhaustCrankAngleRadFor = 0;
2856+ float exhaustCrankAngleRadRev = 0;
2857+
28222858 if (normalisedCrankAngleRad <= MathHelper.Pi)
28232859 {
2824- exhaustCrankAngleRad = CylinderExhaustOpenFactor * (float)Math.PI;
2860+ exhaustCrankAngleRadFor = CylinderExhaustOpenFactor * (float)Math.PI;
28252861 }
28262862 else
28272863 {
2828- exhaustCrankAngleRad = CylinderExhaustOpenFactor * (float)Math.PI + (float)Math.PI;
2864+ exhaustCrankAngleRadFor = CylinderExhaustOpenFactor * (float)Math.PI + (float)Math.PI;
28292865 }
2866+
2867+ if (exhaustCrankAngleRadFor > 2 * (float)Math.PI)
2868+ {
2869+ exhaustCrankAngleRadFor -= 2 * (float)Math.PI;
2870+ }
2871+
2872+ exhaustCrankAngleRadRev = exhaustCrankAngleRadFor + (float)Math.PI;
2873+
2874+ if (exhaustCrankAngleRadRev > 2 * (float)Math.PI)
2875+ {
2876+ exhaustCrankAngleRadRev -= 2 * (float)Math.PI;
2877+ }
2878+
28302879 if (absSpeedMpS > 0.001)
28312880 {
2832- if (i == 0 && ((normalisedCrankAngleRad <= MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad ) || (normalisedCrankAngleRad < 2 * MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad )))
2881+ if (i == 0 && ((normalisedCrankAngleRad >= exhaustCrankAngleRadFor && normalisedCrankAngleRad <= MathHelper.Pi ) || (normalisedCrankAngleRad >= exhaustCrankAngleRadRev && normalisedCrankAngleRad < 2 * MathHelper.Pi)))
28332882 {
28342883 CylinderSteamExhaust2_1On = true;
28352884 }
28362885 else if (i == 0)
28372886 {
28382887 CylinderSteamExhaust2_1On = false;
28392888 }
2840- else if (i == 1 && ((normalisedCrankAngleRad <= MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad ) || (normalisedCrankAngleRad < 2 * MathHelper.Pi && normalisedCrankAngleRad >= exhaustCrankAngleRad )))
2889+ else if (i == 1 && ((normalisedCrankAngleRad >= exhaustCrankAngleRadFor && normalisedCrankAngleRad <= MathHelper.Pi ) || (normalisedCrankAngleRad >= exhaustCrankAngleRadRev && normalisedCrankAngleRad < 2 * MathHelper.Pi)))
28412890 {
28422891 CylinderSteamExhaust2_2On = true;
28432892 }
@@ -3080,6 +3129,36 @@ private void UpdateFX(float elapsedClockSeconds)
30803129
30813130 BoosterCylinderCockParticleDurationS = 1.0f;
30823131
3132+ #if DEBUG_STEAM_EXHAUST_EVENTS
3133+
3134+ if (DrvWheelRevRpS > 0 && DrvWheelRevRpS < 1.01)
3135+ {
3136+ Trace.TraceInformation("======================================== Steam Effects Debug =======================================");
3137+ Trace.TraceInformation("Engine #1 RevpS {0} RevpM {1} Speed {2} Elapsed Time {3}", DrvWheelRevRpS, pS.TopM(DrvWheelRevRpS), absSpeedMpS, SteamExhaustDebugTimerS);
3138+
3139+ Trace.TraceInformation("Exhaust #1 - Exhaust1On {0} Crank {1} ExhaustAng {2}", CylinderSteamExhaust1On, MathHelper.ToDegrees(ExhaustnormalisedCrankAngleRad[0]), MathHelper.ToDegrees(ExhaustexhaustCrankAngleRad[0]));
3140+
3141+ Trace.TraceInformation("Exhaust #2 - Exhaust2On {0} Crank {1} ExhaustAng {2}", CylinderSteamExhaust2On, MathHelper.ToDegrees(ExhaustnormalisedCrankAngleRad[1]), MathHelper.ToDegrees(ExhaustexhaustCrankAngleRad[1]));
3142+
3143+ Trace.TraceInformation("Cylinder #1 - Cylinder11On {0} Crank {1} Cylinder12On {2}", CylinderCock11On, MathHelper.ToDegrees(ExhaustnormalisedCrankAngleRad[0]), CylinderCock11On);
3144+
3145+ Trace.TraceInformation("Cylinder #2 - Cylinder21On {0} Crank {1} Cylinder22On {2}", CylinderCock21On, MathHelper.ToDegrees(ExhaustnormalisedCrankAngleRad[1]), CylinderCock22On);
3146+
3147+ Trace.TraceInformation("===============================================================================");
3148+ /* Trace.TraceInformation("Engine #2 RevpS {0} Speed {1}", DrvWheelRevRpS, absSpeedMpS);
3149+
3150+
3151+ Trace.TraceInformation("===============================================================================");
3152+ Trace.TraceInformation("Engine Booster RevpS {0} Speed {1}", DrvWheelRevRpS, absSpeedMpS);
3153+ */
3154+
3155+ SteamExhaustDebugTimerS += elapsedClockSeconds;
3156+
3157+ }
3158+
3159+ #endif
3160+
3161+
30833162 // Blowdown Steam Effects
30843163 BlowdownSteamVolumeM3pS = (BlowdownValveOpen && BlowdownSteamUsageLBpS > 0.0 ? (10.0f * SteamEffectsFactor) : 0.0f);
30853164 BlowdownSteamVelocityMpS = 350.0f;
0 commit comments