Fix sounds sometimes not playing when they should, if it's the same sound that played earlier.

This commit is contained in:
2015-07-15 22:33:22 -04:00
parent 65128ab6c8
commit c7e9e3ca6c
3 changed files with 9 additions and 25 deletions

View File

@@ -658,18 +658,19 @@ char get_fluid_trim(location where,ter_num_t ter_type) {
}
// Sees if party has seen a monster of this sort, gives special messages as necessary
void check_if_monst_seen(unsigned short m_num, location at) {\
void check_if_monst_seen(unsigned short m_num, location at) {
// Give special messages if necessary
if(m_num < 10000 && !univ.party.m_seen.count(m_num)) {
univ.party.m_seen.insert(m_num);
play_see_monster_str(m_num, at);
}
// Make the monster vocalize if applicable
snd_num_t sound;
snd_num_t sound = -1;
if(m_num >= 10000)
sound = univ.party.summons[m_num - 10000].ambient_sound;
else sound = univ.scenario.scen_monsters[m_num].ambient_sound;
if(get_ran(1,1,100) < 10) play_sound(-sound);
if(sound < std::numeric_limits<snd_num_t>::max() && get_ran(1,1,100) < 10)
play_sound(-sound);
}
void play_ambient_sound(){ // TODO: Maybe add a system for in-town ambient sounds

View File

@@ -135,7 +135,6 @@ void cMonster::append(legacy::monster_record_type& old){
picture_num = old.picture_num;
if(picture_num == 122) picture_num = 119;
see_spec = -1;
ambient_sound = 0;
}
std::map<eMonstAbil,uAbility>::iterator cMonster::addAbil(eMonstAbilTemplate what, int param) {
@@ -386,7 +385,7 @@ cMonster::cMonster(){
speed = 4;
default_facial_pic = 0;
default_attitude = eAttitude::DOCILE;
ambient_sound = 0;
ambient_sound = -1;
corpse_item = corpse_item_chance = treasure = 0;
mu = cl = 0;
summon_type = 0;

View File

@@ -17,10 +17,9 @@
#include "restypes.hpp"
#include "mathutil.hpp"
std::shared_ptr<sf::SoundBuffer> sound_handles[NUM_SOUNDS];
sf::Sound chan[4];
const char numchannel = 4;
char channel;
const int numchannel = 4;
int channel;
short snd_played[4];
bool play_sounds = true;
@@ -33,14 +32,6 @@ std::unordered_set<int> always_async = {
78,79,80,81,82,
83,85,91
};
std::unordered_set<int> load_on_init = {
0,1,6,10,11,
12,14,27,34,37,
47,48,49,50,55,
61,69,70,71,72,
73,74,75,85,86,
87,88,89,99
};
std::unordered_map<int,int> sound_delay = {
{24,25},{25,25},{34,8},{37,8},{43,10},
{44,20},{61,13}
@@ -52,7 +43,7 @@ static bool sound_going(snd_num_t which_s) {
for(i = 0; i < 4; i++)
if(snd_played[i] == which_s)
return true;
return chan[i].getStatus() == sf::Sound::Playing;
return false;
}
@@ -64,12 +55,6 @@ static std::string sound_to_fname_map(snd_num_t snd_num) {
void init_snd_tool(){
ResMgr::setIdMapFn<SoundRsrc>(sound_to_fname_map);
// TODO: Might need sound 0, not sure
for(int i : load_on_init) {
if(i == 0) continue;
sound_handles[i] = ResMgr::get<SoundRsrc>(i);
}
}
void play_sound(short which, short how_many_times) { // if < 0, play asynch
@@ -91,9 +76,8 @@ void play_sound(short which, short how_many_times) { // if < 0, play asynch
if(channel >= numchannel) channel = 0;
if(!sound_going(abs(which)) && load_on_init.find(abs(which)) == load_on_init.end())
if(!sound_going(abs(which)))
sndhandle = ResMgr::get<SoundRsrc>(abs(which));
else sndhandle = sound_handles[abs(which)];
if(which > 0)
if(always_async.find(which) != always_async.end())