예제 #1
0
 public static void checkDistanceAndPlayIfNeeded(DateTime now, float previousDistanceRoundTrack, float currentDistanceRoundTrack, AudioPlayer audioPlayer)
 {
     if (isPlayingPaceNotes && !isRecordingPaceNotes && DriverTrainingService.recordingMetaData != null)
     {
         foreach (MetaDataEntry entry in DriverTrainingService.recordingMetaData.entries)
         {
             if (previousDistanceRoundTrack < entry.distanceRoundTrack && currentDistanceRoundTrack > entry.distanceRoundTrack)
             {
                 if (entry.description != null && !entry.description.Equals(""))
                 {
                     Console.WriteLine("Playing entry at distance " + entry.distanceRoundTrack + " with description " + entry.description);
                 }
                 else
                 {
                     Console.WriteLine("Playing entry at distance " + entry.distanceRoundTrack);
                 }
                 QueuedMessage message = new QueuedMessage(entry.getRandomRecordingName(), 1, type: SoundType.CRITICAL_MESSAGE, priority: 0);
                 audioPlayer.playMessageImmediately(message);
             }
         }
     }
 }
        private void playNextMessage(int carsOnLeftCount, int carsOnRightCount, DateTime now)
        {
            if (nextMessageType != NextMessageType.none && now > nextMessageDue)
            {
                if (messageIsValid(nextMessageType, carsOnLeftCount, carsOnRightCount))
                {
                    switch (nextMessageType)
                    {
                    case NextMessageType.threeWide:
                        audioPlayer.removeImmediateMessages(new String[] { folderStillThere, folderCarLeft, folderCarRight, folderClearAllRound, folderClearLeft, folderClearRight });
                        QueuedMessage inTheMiddleMessage = new QueuedMessage(folderInTheMiddle, 0, null);
                        inTheMiddleMessage.expiryTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + inTheMiddleMessageExpiresAfter;
                        audioPlayer.playSpotterMessage(inTheMiddleMessage, true);
                        nextMessageType      = NextMessageType.stillThere;
                        nextMessageDue       = now.Add(repeatHoldFrequency);
                        reportedOverlapLeft  = true;
                        reportedOverlapRight = true;
                        wasInMiddle          = true;
                        break;

                    case NextMessageType.carLeft:
                        audioPlayer.removeImmediateMessages(new String[] { folderStillThere, folderInTheMiddle, folderCarRight, folderClearAllRound, folderClearLeft, folderClearRight });
                        QueuedMessage carLeftMessage = new QueuedMessage(folderCarLeft, 0, null);
                        carLeftMessage.expiryTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + holdMessageExpiresAfter;
                        audioPlayer.playSpotterMessage(carLeftMessage, true);
                        nextMessageType     = NextMessageType.stillThere;
                        nextMessageDue      = now.Add(repeatHoldFrequency);
                        reportedOverlapLeft = true;
                        break;

                    case NextMessageType.carRight:
                        audioPlayer.removeImmediateMessages(new String[] { folderStillThere, folderCarLeft, folderInTheMiddle, folderClearAllRound, folderClearLeft, folderClearRight });
                        QueuedMessage carRightMessage = new QueuedMessage(folderCarRight, 0, null);
                        carRightMessage.expiryTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + holdMessageExpiresAfter;
                        audioPlayer.playSpotterMessage(carRightMessage, true);
                        nextMessageType      = NextMessageType.stillThere;
                        nextMessageDue       = now.Add(repeatHoldFrequency);
                        reportedOverlapRight = true;
                        break;

                    case NextMessageType.clearAllRound:
                        if (reportedOverlapLeft || reportedOverlapRight)
                        {
                            QueuedMessage clearAllRoundMessage = new QueuedMessage(folderClearAllRound, 0, null);
                            clearAllRoundMessage.expiryTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + clearAllRoundMessageExpiresAfter;
                            audioPlayer.removeImmediateMessages(new String[] { folderCarLeft, folderStillThere, folderCarRight, folderInTheMiddle, folderClearLeft, folderClearRight });
                            audioPlayer.playSpotterMessage(clearAllRoundMessage, false);
                            nextMessageType = NextMessageType.none;
                        }

                        reportedOverlapLeft  = false;
                        reportedOverlapRight = false;
                        wasInMiddle          = false;
                        break;

                    case NextMessageType.clearLeft:
                        if (reportedOverlapLeft)
                        {
                            if (carsOnRightCount == 0 && wasInMiddle)
                            {
                                QueuedMessage clearAllRoundMessage = new QueuedMessage(folderClearAllRound, 0, null);
                                clearAllRoundMessage.expiryTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + clearMessageExpiresAfter;
                                audioPlayer.removeImmediateMessages(new String[] { folderCarLeft, folderStillThere, folderCarRight, folderInTheMiddle, folderClearRight, folderClearLeft });
                                audioPlayer.playSpotterMessage(clearAllRoundMessage, false);
                                nextMessageType = NextMessageType.none;

                                reportedOverlapRight = false;
                                wasInMiddle          = false;
                            }
                            else
                            {
                                QueuedMessage clearLeftMessage = new QueuedMessage(folderClearLeft, 0, null);
                                clearLeftMessage.expiryTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + clearMessageExpiresAfter;
                                audioPlayer.removeImmediateMessages(new String[] { folderCarLeft, folderStillThere, folderCarRight, folderInTheMiddle, folderClearRight, folderClearAllRound });
                                if (wasInMiddle)
                                {
                                    audioPlayer.playSpotterMessage(clearLeftMessage, true);
                                    nextMessageType = NextMessageType.carRight;
                                    nextMessageDue  = now.Add(repeatHoldFrequency);
                                }
                                else
                                {
                                    audioPlayer.playSpotterMessage(clearLeftMessage, false);
                                    nextMessageType = NextMessageType.none;
                                }
                            }
                        }
                        reportedOverlapLeft = false;
                        break;

                    case NextMessageType.clearRight:
                        if (reportedOverlapRight)
                        {
                            if (carsOnLeftCount == 0 && wasInMiddle)
                            {
                                QueuedMessage clearAllRoundMessage = new QueuedMessage(folderClearAllRound, 0, null);
                                clearAllRoundMessage.expiryTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + clearMessageExpiresAfter;
                                audioPlayer.removeImmediateMessages(new String[] { folderCarLeft, folderStillThere, folderCarRight, folderInTheMiddle, folderClearLeft, folderClearRight });
                                audioPlayer.playSpotterMessage(clearAllRoundMessage, false);
                                nextMessageType = NextMessageType.none;

                                reportedOverlapLeft = false;
                                wasInMiddle         = false;
                            }
                            else
                            {
                                QueuedMessage clearRightMessage = new QueuedMessage(folderClearRight, 0, null);
                                clearRightMessage.expiryTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + clearMessageExpiresAfter;
                                audioPlayer.removeImmediateMessages(new String[] { folderCarLeft, folderStillThere, folderCarRight, folderInTheMiddle, folderClearLeft, folderClearAllRound });
                                if (wasInMiddle)
                                {
                                    audioPlayer.playSpotterMessage(clearRightMessage, true);
                                    nextMessageType = NextMessageType.carLeft;
                                    nextMessageDue  = now.Add(repeatHoldFrequency);
                                }
                                else
                                {
                                    audioPlayer.playSpotterMessage(clearRightMessage, false);
                                    nextMessageType = NextMessageType.none;
                                }
                            }
                        }
                        reportedOverlapRight = false;
                        break;

                    case NextMessageType.stillThere:
                        if (reportedOverlapLeft || reportedOverlapRight)
                        {
                            QueuedMessage holdYourLineMessage = new QueuedMessage(folderStillThere, 0, null);
                            holdYourLineMessage.expiryTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + holdMessageExpiresAfter;
                            audioPlayer.removeImmediateMessages(new String[] { folderClearRight, folderClearLeft, folderClearAllRound });
                            audioPlayer.playSpotterMessage(holdYourLineMessage, true);
                            nextMessageType = NextMessageType.stillThere;
                            nextMessageDue  = now.Add(repeatHoldFrequency);
                        }
                        break;

                    case NextMessageType.none:
                        break;
                    }
                }
                else
                {
                    reportedOverlapLeft  = false;
                    reportedOverlapRight = false;
                }
            }
        }