Add RepeatingSoundEffect class to allow easy creation and handling of looping sound effects ingame. Add rock breaking, rock toss cast, pillar rise, dig sound effects. Fix typo on Hawk Feather item description key name. Placeholder item icons added. Add sound effects to Stone Elemental's attacks. Release Build 9656.

This commit is contained in:
2024-06-18 11:38:03 -05:00
parent cd1a734b19
commit a740d6eb01
28 changed files with 132 additions and 16 deletions
+41 -12
View File
@@ -48,6 +48,15 @@ INCLUDE_game
std::multimap<EventName,SoundEffect>SoundEffect::SOUND_EFFECTS;
const vf2d SoundEffect::CENTERED={-8419.f,-3289.f};
std::unordered_set<size_t>RepeatingSoundEffect::playingSoundEffects;
void RepeatingSoundEffect::StopAllSounds(){
for(auto&id:playingSoundEffects){
Audio::Engine().Stop(id);
Audio::Engine().UnloadSound(id);
}
playingSoundEffects.clear();
}
SoundEffect::SoundEffect(const std::string_view filename,const float&vol,const float&minPitch,const float&maxPitch,const bool combatSound)
:filename(filename),vol(vol),minPitch(minPitch),maxPitch(maxPitch),combatSound(combatSound){
@@ -79,18 +88,7 @@ void SoundEffect::Initialize(){
void SoundEffect::PlaySFX(const std::string_view eventName,const vf2d&pos){
if(eventName.length()==0)return;
auto itr=SOUND_EFFECTS.equal_range(std::string(eventName));
size_t soundCount=std::distance(itr.first,itr.second);
if(soundCount==0)ERR("WARNING! Sound Effect "<<std::quoted(eventName)<<" does not have any sound effects loaded/doesn't exist!")
size_t soundEffectChoice=util::random()%soundCount;
int counter=0;
auto it=itr.first;
while(counter!=soundEffectChoice){
++counter;
++it;
}
const SoundEffect&sfx=(*it).second;
const SoundEffect&sfx=GetRandomSFXFromFile(eventName);
if(GameState::STATE==GameState::states[States::MAIN_MENU]&&sfx.combatSound)return; //Do not play combat sounds on the main menu.
@@ -112,4 +110,35 @@ void SoundEffect::PlaySFX(const std::string_view eventName,const vf2d&pos){
Audio::Engine().Play(operator""_SFX(sfx.filename.c_str(),sfx.filename.length()),vol,pan,pitch);
}
}
}
size_t SoundEffect::PlayLoopingSFX(const std::string_view eventName,const vf2d&pos){
const SoundEffect&sfx=GetRandomSFXFromFile(eventName);
const size_t id=Audio::Engine().LoadSound(operator""_SFX(sfx.filename.c_str(),sfx.filename.length()));
RepeatingSoundEffect::playingSoundEffects.insert(id);
Audio::Engine().Play(id,true);
return id;
}
void SoundEffect::StopLoopingSFX(const int id){
if(!RepeatingSoundEffect::playingSoundEffects.count(id))return; //Prevent crashes from stopping a sound more than once. Called by accident probably.
Audio::Engine().Stop(id);
Audio::Engine().UnloadSound(id);
RepeatingSoundEffect::playingSoundEffects.erase(id);
}
SoundEffect&SoundEffect::GetRandomSFXFromFile(const std::string_view eventName){
auto itr=SOUND_EFFECTS.equal_range(std::string(eventName));
size_t soundCount=std::distance(itr.first,itr.second);
if(soundCount==0)ERR("WARNING! Sound Effect "<<std::quoted(eventName)<<" does not have any sound effects loaded/doesn't exist!")
size_t soundEffectChoice=util::random()%soundCount;
int counter=0;
auto it=itr.first;
while(counter!=soundEffectChoice){
++counter;
++it;
}
return (*it).second;
}