GearDown sound trigger no longer played since rev #2039

Bug #1313386 reported by BB25187
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Open Rails
Fix Released
Low
BB25187

Bug Description

I also described this issue in a post on the forum: http://www.elvastower.com/forums/index.php?/topic/24200-geardown-sound-trigger-no-longer-played-since-rev-2039/

I adapted one of my railcars so it makes use of the GearUp/GearDown sound triggers (101/102). I am using revision #2194.
 I noticed that the GearDown trigger has no effect: the corresponding sound is never played. The GearUp trigger works fine. I tested former versions of ORTS, and found out that the problem was introduced by revision #2039. I also identified the code in GearBox.cs which causes this issue.
 Before revision #2039, we had:

            if ((clutch <= 0.05) || (clutch >= 1f))
            {
                if (currentGearIndex < nextGearIndex) DieselEngine.locomotive.SignalEvent(Event.GearUp);
                if (currentGearIndex > nextGearIndex) DieselEngine.locomotive.SignalEvent(Event.GearDown);
                currentGearIndex = nextGearIndex;
            }

 This code was changed as follows at revision #2039:

            if ((clutch <= 0.05) || (clutch >= 1f))
            {
                if (currentGearIndex < nextGearIndex) DieselEngine.locomotive.SignalEvent(Event.GearUp);
                currentGearIndex = nextGearIndex;
            }
            if ((clutch <= 0.05) || (clutch >= 0.5f))
            {
                if (currentGearIndex > nextGearIndex) DieselEngine.locomotive.SignalEvent(Event.GearDown);
                currentGearIndex = nextGearIndex;
            }

 If I just change the order of the two conditional blocks (handling GearDown event before GearUp one), then I observe the opposite effect: the GearDown sound is played, whereas the GearUp one dosn't work anymore! The problem is caused by the modification of the gear index in the first block, which is performed even if the condition on its current value is not met. This modifies the initial conditions for the second block.
 I fixed the problem as follows (the modification of the gear index is placed in the same conditional block as the event Handler):

            if ((clutch <= 0.05) || (clutch >= 1f))
            {
                if (currentGearIndex < nextGearIndex)
                {
                    DieselEngine.locomotive.SignalEvent(Event.GearUp);
                    currentGearIndex = nextGearIndex;
                }
            }
            if ((clutch <= 0.05) || (clutch >= 0.5f))
            {
                if (currentGearIndex > nextGearIndex)
                {
                    DieselEngine.locomotive.SignalEvent(Event.GearDown);
                    currentGearIndex = nextGearIndex;
                }
            }

 A SVN patch (applies to GearBox.cs) is attached.

Tags: sounds gearbox
Revision history for this message
BB25187 (bb25187) wrote :
Revision history for this message
Carlo Santucci (carlosanit1) wrote :

I can confirm the bug and also that the patch is OK.

Revision history for this message
Peter Gulyas (pzgulyas) wrote :

Fixed in r2229.

Changed in or:
status: New → Fix Committed
James Ross (twpol)
Changed in or:
assignee: nobody → BB25187 (bb25187)
milestone: none → 1.0
importance: Undecided → Low
Revision history for this message
BB25187 (bb25187) wrote :

Thanks for having committed the fix!

James Ross (twpol)
Changed in or:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.