# Amuse: include/amuse/Engine.hpp Source File

Engine.hpp
#ifndef __AMUSE_ENGINE_HPP__
#define __AMUSE_ENGINE_HPP__
#include <memory>
#include <list>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include "Emitter.hpp"
#include "AudioGroupSampleDirectory.hpp"
#include "Sequencer.hpp"
namespace amuse
{
class IBackendVoiceAllocator;
class Voice;
class Submix;
class Emitter;
class AudioGroup;
class AudioGroupData;
class Engine
{
friend class Voice;
friend class Emitter;
friend class Sequencer;
friend class Sequencer::ChannelState;
IBackendVoiceAllocator& m_backend;
std::unordered_map<const AudioGroupData*, std::unique_ptr<AudioGroup>> m_audioGroups;
std::list<std::shared_ptr<Voice>> m_activeVoices;
std::list<std::shared_ptr<Emitter>> m_activeEmitters;
std::list<std::shared_ptr<Sequencer>> m_activeSequencers;
std::list<Submix> m_activeSubmixes;
std::unordered_map<uint16_t, std::tuple<AudioGroup*, int, const SFXGroupIndex::SFXEntry*>> m_sfxLookup;
std::linear_congruential_engine<uint32_t, 0x41c64e6d, 0x3039, UINT32_MAX> m_random;
int m_nextVid = 0;
std::pair<AudioGroup*, const SongGroupIndex*> _findSongGroup(int groupId) const;
std::pair<AudioGroup*, const SFXGroupIndex*> _findSFXGroup(int groupId) const;
std::shared_ptr<Voice> _allocateVoice(const AudioGroup& group, int groupId, double sampleRate,
bool dynamicPitch, bool emitter, Submix* smx);
std::shared_ptr<Sequencer> _allocateSequencer(const AudioGroup& group, int groupId,
int setupId, Submix* smx);
Submix* _allocateSubmix(Submix* smx);
std::list<std::shared_ptr<Voice>>::iterator _destroyVoice(Voice* voice);
std::list<std::shared_ptr<Sequencer>>::iterator _destroySequencer(Sequencer* sequencer);
std::list<Submix>::iterator _destroySubmix(Submix* smx);
std::list<Submix>::iterator _removeSubmix(Submix* smx);
void _bringOutYourDead();
public:
~Engine();
Engine(IBackendVoiceAllocator& backend);
IBackendVoiceAllocator& getBackend() {return m_backend;}
void pumpEngine(double dt);
const AudioGroup* addAudioGroup(const AudioGroupData& data);
void removeAudioGroup(const AudioGroupData& data);
Submix* addSubmix(Submix* parent=nullptr);
void removeSubmix(Submix* smx);
std::shared_ptr<Voice> fxStart(int sfxId, float vol, float pan, Submix* smx=nullptr);
std::shared_ptr<Emitter> addEmitter(const Vector3f& pos, const Vector3f& dir, float maxDist,
float falloff, int sfxId, float minVol, float maxVol,
Submix* smx=nullptr);
std::shared_ptr<Sequencer> seqPlay(int groupId, int songId, const unsigned char* arrData,
Submix* smx=nullptr);
std::shared_ptr<Voice> findVoice(int vid);
void killKeygroup(uint8_t kg, bool now);
void sendMacroMessage(ObjectId macroId, int32_t val);
uint32_t nextRandom() {return m_random();}
};
}
#endif // __AMUSE_ENGINE_HPP__
amuse::Engine::addAudioGroup
const AudioGroup * addAudioGroup(const AudioGroupData &data)
amuse::AudioGroupData
Definition: AudioGroupData.hpp:8
amuse::Engine::killKeygroup
void killKeygroup(uint8_t kg, bool now)
amuse::Engine::nextRandom
uint32_t nextRandom()
Definition: Engine.hpp:97
amuse::Engine::fxStart
std::shared_ptr< Voice > fxStart(int sfxId, float vol, float pan, Submix *smx=nullptr)
amuse::Engine::addSubmix
Submix * addSubmix(Submix *parent=nullptr)
amuse::Engine::pumpEngine
void pumpEngine(double dt)
amuse::AudioGroup
Definition: AudioGroup.hpp:16
amuse
Definition: AudioGroup.hpp:8
amuse::Engine::sendMacroMessage
void sendMacroMessage(ObjectId macroId, int32_t val)
amuse::Voice
Definition: Voice.hpp:30
amuse::Submix
Definition: Submix.hpp:20
amuse::Emitter
Definition: Emitter.hpp:14
amuse::Engine
Definition: Engine.hpp:23
amuse::Engine::seqPlay
std::shared_ptr< Sequencer > seqPlay(int groupId, int songId, const unsigned char *arrData, Submix *smx=nullptr)
amuse::Engine::addEmitter
std::shared_ptr< Emitter > addEmitter(const Vector3f &pos, const Vector3f &dir, float maxDist, float falloff, int sfxId, float minVol, float maxVol, Submix *smx=nullptr)
amuse::IBackendVoiceAllocator
Definition: IBackendVoiceAllocator.hpp:24
amuse::Engine::removeAudioGroup
void removeAudioGroup(const AudioGroupData &data)
amuse::Engine::getBackend
IBackendVoiceAllocator & getBackend()
Definition: Engine.hpp:58
amuse::Sequencer
Definition: Sequencer.hpp:27
amuse::Engine::findVoice
std::shared_ptr< Voice > findVoice(int vid)
amuse::Engine::removeSubmix
void removeSubmix(Submix *smx)