NLS Engine  v0.1
The Next Logical Step in game engine design.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
SoundModule.h
Go to the documentation of this file.
00001 
00011 #pragma once
00012 
00013 // System Library Includes
00014 #include <set>
00015 #include <string>
00016 #include <xact3.h>
00017 
00018 // Application Library Includes
00019 #include <threading.h>
00020 
00021 // Local Includes
00022 #include "../sharedbase/ModuleInterface.h"
00023 #include "../sharedbase/Envelope_fwd.h"
00024 
00025 // Forward Declarations
00026 
00027 // Typedefs
00029 namespace Sound {
00030   typedef std::map<std::string,  IXACT3WaveBank*>  wavebank_map;
00031   typedef std::pair<std::string, IXACT3WaveBank*>  wavebank_pair;
00032   typedef std::map<std::string,  IXACT3SoundBank*> soundbank_map;
00033   typedef std::pair<std::string, IXACT3SoundBank*> soundbank_pair;
00034 }
00035 
00036 // DLL Interface
00037 extern "C" {
00038   __declspec(dllexport) ModuleInterface* ModuleFactory(PropertyMap*, MessageRouter*, EntityList*, EventLogger*);
00039 }
00040 
00041 // Classes
00042 namespace Sound {
00043   class SoundModule: public ModuleInterface {
00044     friend void WINAPI XACTNotificationCallback(const XACT_NOTIFICATION*);
00045     
00046   public:
00047     static SoundModule* GetModuleInstance() {
00048       return SoundModule::moduleInstance;
00049     }
00050     
00051   private:
00052     static SoundModule* moduleInstance;
00053   
00054   public:
00055     SoundModule(PropertyMap*, MessageRouter*, EntityList*);
00056     ~SoundModule(void);
00057     
00058     XACTINDEX GetCueIndex(const std::string& bank, const std::string& cueName);
00059     
00060   private: // Inherited methods
00061     void Update(double dt);
00062     void CreateComponent(std::string, std::map<std::string, boost::any> &, EntitySPTR) {}
00063     WHO_DELETES::TYPE RemoveComponent(ComponentInterface*) { return WHO_DELETES::CALLEE; }
00064     
00065   private: // Member methods
00067     void RegisterMessageHandlers();
00068     
00069     // Message handlers
00070     void HandlerStartup(EnvelopeSPTR);
00071     
00072     void HandlerBasic(EnvelopeSPTR);
00073     
00074     EnvelopeSPTR HandlerDirectedGetCueIndex(EnvelopeSPTR);
00075     
00076     // XACT operations
00077     void LoadXACTSettingsBuffer(std::string file);
00078     void LoadInMemoryWavebank(std::string file);
00079     void LoadStreamingWavebank(std::string file);
00080     void LoadSoundbank(std::string file);
00081     
00082     void RegisterNotification(XACTNOTIFICATIONTYPE, BYTE, PVOID = NULL);
00083     
00084   private: // Member data
00085     double deltaAccumulator; 
00086     float updateDelay;
00087     
00088     Threading::ReadWriteMutex engineMutex;
00089     bool engineInitialized;
00090     IXACT3Engine* engine;
00091     
00092     Threading::ReadWriteMutex waveBanksMutex;
00093     wavebank_map waveBanks;
00094     
00095     Threading::ReadWriteMutex soundBanksMutex;
00096     soundbank_map soundBanks;
00097     
00098     Threading::ReadWriteMutex preparedCuesMutex;
00099     std::map< std::pair<std::string, int>, IXACT3Cue*> preparedCues; // key is {bank, cueIndex}
00100   };
00101 }