| 896 | //----------------------------------------------------------------------------- |
| 897 | |
| 898 | void SFXSystem::_assignVoices() |
| 899 | { |
| 900 | AssertFatal( getNumListeners() == 1, "SFXSystem::_assignVoices() - must only have a single listener" ); |
| 901 | PROFILE_SCOPE( SFXSystem_AssignVoices ); |
| 902 | |
| 903 | mStatNumVoices = 0; |
| 904 | mStatNumCulled = 0; |
| 905 | |
| 906 | if( !mDevice ) |
| 907 | return; |
| 908 | |
| 909 | // Sort the sources in the SFX source set by priority. This also |
| 910 | // updates each soures effective volume first. |
| 911 | |
| 912 | _sortSounds( getListener() ); |
| 913 | |
| 914 | // We now make sure that the sources closest to the |
| 915 | // listener, the ones at the top of the source list, |
| 916 | // have a device buffer to play thru. |
| 917 | |
| 918 | mStatNumCulled = 0; |
| 919 | for( SFXSoundVector::iterator iter = mSounds.begin(); iter != mSounds.end(); ++ iter ) |
| 920 | { |
| 921 | SFXSound* sound = *iter; |
| 922 | |
| 923 | // Non playing sources (paused or stopped) are at the |
| 924 | // end of the vector, so when i encounter one i know |
| 925 | // that nothing else in the vector needs buffer assignment. |
| 926 | |
| 927 | if( !sound->isPlaying() ) |
| 928 | break; |
| 929 | |
| 930 | // If the source is outside it's max range we can |
| 931 | // skip it as well, so that we don't waste cycles |
| 932 | // setting up a buffer for something we won't hear. |
| 933 | |
| 934 | if( sound->getAttenuatedVolume() <= 0.0f ) |
| 935 | { |
| 936 | ++ mStatNumCulled; |
| 937 | continue; |
| 938 | } |
| 939 | |
| 940 | // If the source has a voice then we can skip it. |
| 941 | |
| 942 | if( sound->hasVoice() ) |
| 943 | continue; |
| 944 | |
| 945 | // Ok let the device try to assign a new voice for |
| 946 | // this source... this may fail if we're out of voices. |
| 947 | |
| 948 | if( sound->_allocVoice( mDevice ) ) |
| 949 | continue; |
| 950 | |
| 951 | // The device couldn't assign a new voice, so we go through |
| 952 | // local priority sounds and try to steal a voice. |
| 953 | |
| 954 | for( SFXSoundVector::iterator hijack = mSounds.end() - 1; hijack != iter; -- hijack ) |
| 955 | { |
nothing calls this directly
no test coverage detected