MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / Sound_GetFreeSlot

Function Sound_GetFreeSlot

TombEngine/Sound/sound.cpp:747–773  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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
747int 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
775int Sound_TrackIsPlaying(const std::string& fileName, std::optional<SoundTrackType> type)
776{

Callers 1

SoundEffectFunction · 0.85

Calls 5

TENLogFunction · 0.85
to_stringFunction · 0.85
Sound_FreeSlotFunction · 0.85
Vector3Function · 0.50
LengthMethod · 0.45

Tested by

no test coverage detected