Get first free (non-playing) sound slot. If no free slots found, now try to hijack slot which is as far from listener as possible
| 745 | // Get first free (non-playing) sound slot. |
| 746 | // If no free slots found, now try to hijack slot which is as far from listener as possible |
| 747 | int Sound_GetFreeSlot() |
| 748 | { |
| 749 | for (int i = 0; i < SOUND_MAX_CHANNELS; i++) |
| 750 | { |
| 751 | if (SoundSlot[i].Channel == NULL || !BASS_ChannelIsActive(SoundSlot[i].Channel)) |
| 752 | return i; |
| 753 | } |
| 754 | |
| 755 | // No free slots, hijack now. |
| 756 | |
| 757 | float minDistance = 0; |
| 758 | int farSlot = SOUND_NO_CHANNEL; |
| 759 | |
| 760 | for (int i = 0; i < SOUND_MAX_CHANNELS; i++) |
| 761 | { |
| 762 | float distance = Vector3(SoundSlot[i].Origin - Vector3(Camera.mikePos.x, Camera.mikePos.y, Camera.mikePos.z)).Length(); |
| 763 | if (distance > minDistance) |
| 764 | { |
| 765 | minDistance = distance; |
| 766 | farSlot = i; |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | TENLog("Hijacking sound effect slot " + std::to_string(farSlot), LogLevel::Info); |
| 771 | Sound_FreeSlot(farSlot, SOUND_XFADETIME_HIJACKSOUND); |
| 772 | return farSlot; |
| 773 | } |
| 774 | |
| 775 | int Sound_TrackIsPlaying(const std::string& fileName, std::optional<SoundTrackType> type) |
| 776 | { |
no test coverage detected