77 lines
2 KiB
C++
77 lines
2 KiB
C++
#include "sound_effects.hpp"
|
|
|
|
#include "sound.hpp"
|
|
|
|
namespace sound {
|
|
#if 0
|
|
class MissileFlySoundEffect : public SoundEffect {
|
|
MissileFlySoundEffect(const game::Missile *missile)
|
|
: m_missileId(missile->id)
|
|
, m_handle(sound::playSound(sound::playFrequency(440, 0.3))
|
|
{
|
|
}
|
|
|
|
~MissileFlySoundEffect()
|
|
{
|
|
delete(m_handle);
|
|
}
|
|
|
|
bool advance(float dt)
|
|
{
|
|
for (const game::StateUpdateEvent *event : updates) {
|
|
handleUpdateEvent(event);
|
|
}
|
|
|
|
// TODO: add event if sth. comes into life or dies in a state
|
|
// cycle.. delete objects that died last cycle in the current cycle
|
|
// so pointers don't get invalid.
|
|
|
|
bool keep = false;
|
|
for (const game::Missile *missile : state->missiles) {
|
|
if (missile->id == m_missileId) {
|
|
keep = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!keep) {
|
|
sound::stopSound(m_handle);
|
|
sound::deleteSound(m_handle);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
SoundHandle *m_handle;
|
|
size_t m_missileId;
|
|
};
|
|
|
|
void SoundEffects::advance(float dt, const std::list<game::StateUpdateEvent*> &updates)
|
|
{
|
|
//StateUpdateEvent::LifeCycle::Create,
|
|
//StateUpdateEvent::Type::Explosion
|
|
|
|
std::vector<SoundEffect*> rm;
|
|
|
|
for (SoundEffect *effect : m_effects) {
|
|
bool keep = effect->advance(dt, m_gameState);
|
|
if (!keep) {
|
|
rm.push_back(effect);
|
|
}
|
|
}
|
|
|
|
for (SoundEffect *effect : rm) {
|
|
m_effects.remove(rm);
|
|
delete(rm);
|
|
}
|
|
|
|
// spawn new sounds
|
|
//for (const game::Missile *missile : state->missiles) {
|
|
// for (SoundEffect
|
|
// if (missile->
|
|
//}
|
|
}
|
|
#endif
|
|
}
|