@@ -493,9 +493,20 @@ public static WorldLocation UidLocation(UiD uid)
493
493
public class SoundSource : SoundSourceBase
494
494
{
495
495
/// <summary>
496
- /// Squeared cutoff distance. No sound is audible above that
496
+ /// Squared cutoff distance. No sound is audible above that, except for the actual player train,
497
+ /// where cutoff occurs at a distance wich is higher than the train length plus offset to
498
+ /// approximately take into account distance from camera to car
497
499
/// </summary>
498
- private const int CUTOFFDISTANCE = 4000000 ;
500
+ private int CutOffDistanceM2
501
+ {
502
+ get
503
+ {
504
+ const int staticDistanceM2 = 4000000 ;
505
+ var isPlayer = Car ? . Train ? . IsActualPlayerTrain ?? false ;
506
+ var correctedLength = isPlayer ? Car . Train . Length + 50 : 0 ;
507
+ return ( int ) Math . Max ( staticDistanceM2 , correctedLength * correctedLength ) ;
508
+ }
509
+ }
499
510
/// <summary>
500
511
/// Max distance for OpenAL inverse distance model. Equals to Math.Sqrt(CUTOFFDISTANCE)
501
512
/// </summary>
@@ -659,9 +670,9 @@ public override void Uninitialize()
659
670
public bool MstsMonoTreatment ;
660
671
661
672
/// <summary>
662
- /// Current distance to camera, squared meter. Is used for comparision to <see cref="CUTOFFDISTANCE "/>, to determine if is out-of-scope
673
+ /// Current distance to camera, squared meter. Is used for comparision to <see cref="CutOffDistanceM2 "/>, to determine if is out-of-scope
663
674
/// </summary>
664
- public float DistanceSquared = CUTOFFDISTANCE + 1 ;
675
+ public float DistanceSquared = float . MaxValue ;
665
676
/// <summary>
666
677
/// Out-of-scope state in previous <see cref="Update"/> loop
667
678
/// </summary>
@@ -994,7 +1005,7 @@ public override bool Update()
994
1005
} // Update
995
1006
996
1007
/// <summary>
997
- /// Calculate current distance to camera, and compare it to <see cref="CUTOFFDISTANCE "/>
1008
+ /// Calculate current distance to camera, and compare it to <see cref="CutOffDistanceM2 "/>
998
1009
/// </summary>
999
1010
/// <returns>True, if is now out-of-scope</returns>
1000
1011
public bool isOutOfDistance ( )
@@ -1009,13 +1020,13 @@ public bool isOutOfDistance()
1009
1020
float . IsNaN ( WorldLocation . Location . Y ) ||
1010
1021
float . IsNaN ( WorldLocation . Location . Z ) )
1011
1022
{
1012
- DistanceSquared = CUTOFFDISTANCE + 1 ;
1023
+ DistanceSquared = float . MaxValue ;
1013
1024
return true ;
1014
1025
}
1015
1026
1016
1027
DistanceSquared = WorldLocation . GetDistanceSquared ( WorldLocation , Viewer . Camera . CameraWorldLocation ) ;
1017
1028
1018
- return DistanceSquared > CUTOFFDISTANCE ;
1029
+ return DistanceSquared > CutOffDistanceM2 ;
1019
1030
}
1020
1031
1021
1032
/// <summary>
@@ -1034,7 +1045,7 @@ public bool Activate()
1034
1045
{
1035
1046
// (ActivationConditions.Distance == 0) means distance checking disabled
1036
1047
if ( ( ActivationConditions . Distance == 0 || DistanceSquared < ActivationConditions . Distance * ActivationConditions . Distance ) &&
1037
- DistanceSquared < CUTOFFDISTANCE )
1048
+ DistanceSquared < CutOffDistanceM2 )
1038
1049
return true ;
1039
1050
}
1040
1051
else
@@ -1059,7 +1070,7 @@ public bool DeActivate()
1059
1070
if ( WorldLocation != WorldLocation . None )
1060
1071
{
1061
1072
if ( DeactivationConditions . Distance != 0 && DistanceSquared > DeactivationConditions . Distance * DeactivationConditions . Distance ||
1062
- DistanceSquared > CUTOFFDISTANCE )
1073
+ DistanceSquared > CutOffDistanceM2 )
1063
1074
return true ;
1064
1075
}
1065
1076
0 commit comments