2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-04-11 19:00:39 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : SoundGroup.h
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : Loads up a group of sound files with shared properties,
|
|
|
|
* and provides a simple interface for playing them.
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2010-04-06 17:17:06 +02:00
|
|
|
Example usage:
|
2009-04-11 19:00:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
Example SoundGroup.xml
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<SoundGroup>
|
|
|
|
<Gain>1.0</Gain>
|
|
|
|
<Looping>0</Looping>
|
|
|
|
<Pitch>1.0</Pitch>
|
|
|
|
<Priority>100</Priority>
|
|
|
|
<RandOrder>0</RandOrder>
|
|
|
|
<RandGain>0</RandGain>
|
|
|
|
<RandPitch>0</RandPitch>
|
|
|
|
<ConeGain>1.0</ConeGain>
|
|
|
|
<ConeInner>360</ConeInner>
|
|
|
|
<ConeOuter>360</ConeOuter>
|
|
|
|
<Sound>audio/voice/hellenes/soldier/Attack_Attackx.ogg</Sound>
|
|
|
|
<Sound>audio/voice/hellenes/soldier/Attack_Chargex.ogg</Sound>
|
|
|
|
<Sound>audio/voice/hellenes/soldier/Attack_Engagex.ogg</Sound>
|
|
|
|
<Sound>audio/voice/hellenes/soldier/Attack_ForMyFamily.ogg</Sound>
|
|
|
|
</SoundGroup>
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_SOUNDGROUP
|
|
|
|
#define INCLUDED_SOUNDGROUP
|
|
|
|
|
|
|
|
#include "lib/res/handle.h"
|
2009-11-03 22:46:35 +01:00
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
2009-04-11 19:00:39 +02:00
|
|
|
#include "ps/CStr.h"
|
|
|
|
#include "maths/Vector3D.h"
|
|
|
|
#include "lib/res/sound/snd_mgr.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
enum eSndGrpFlags
|
|
|
|
{
|
|
|
|
eRandOrder = 0x01,
|
|
|
|
eRandGain = 0x02,
|
|
|
|
eRandPitch = 0x04,
|
|
|
|
eLoop = 0x08,
|
2010-04-04 23:24:39 +02:00
|
|
|
eOmnipresent = 0x10
|
2009-04-11 19:00:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CSoundGroup
|
|
|
|
{
|
2010-04-04 23:24:39 +02:00
|
|
|
NONCOPYABLE(CSoundGroup);
|
2009-04-11 19:00:39 +02:00
|
|
|
public:
|
2009-11-03 22:46:35 +01:00
|
|
|
CSoundGroup(const VfsPath& pathnameXML);
|
2009-04-11 19:00:39 +02:00
|
|
|
CSoundGroup(void);
|
|
|
|
~CSoundGroup(void);
|
|
|
|
|
|
|
|
// Play next sound in group
|
|
|
|
// @param position world position of the entity generating the sound
|
|
|
|
// (ignored if the eOmnipresent flag is set)
|
|
|
|
void PlayNext(const CVector3D& position);
|
|
|
|
|
|
|
|
// Load a group
|
2009-11-03 22:46:35 +01:00
|
|
|
bool LoadSoundGroup(const VfsPath& pathnameXML);
|
2009-04-11 19:00:39 +02:00
|
|
|
|
|
|
|
void Reload();
|
|
|
|
|
|
|
|
// Release all remaining loaded handles
|
|
|
|
void ReleaseGroup();
|
|
|
|
|
|
|
|
// Update SoundGroup, remove dead sounds from intensity count
|
|
|
|
void Update(float TimeSinceLastFrame);
|
|
|
|
|
|
|
|
// Set a flag using a value from eSndGrpFlags
|
2010-04-04 23:24:39 +02:00
|
|
|
inline void SetFlag(int flag) { m_Flags |= flag; }
|
2009-04-11 19:00:39 +02:00
|
|
|
|
|
|
|
// Test flag, returns true if flag is set.
|
2010-04-04 23:24:39 +02:00
|
|
|
inline bool TestFlag(int flag) { return (m_Flags & flag) != 0; }
|
2009-04-11 19:00:39 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void SetGain(float gain);
|
|
|
|
void UploadPropertiesAndPlay(Handle hSound, const CVector3D& position);
|
|
|
|
void SetDefaultValues();
|
|
|
|
|
|
|
|
size_t m_index; // index of the next sound to play
|
|
|
|
|
|
|
|
Handle m_hReplacement;
|
|
|
|
|
|
|
|
std::vector<Handle> snd_group; // we store the handles so we can load now and play later
|
2009-11-03 22:46:35 +01:00
|
|
|
std::vector<std::wstring> filenames; // we need the filenames so we can reload when necessary.
|
2009-04-11 19:00:39 +02:00
|
|
|
std::vector<float> playtimes; // it would be better to store this in with the Handles perhaps?
|
2009-11-03 22:46:35 +01:00
|
|
|
VfsPath m_filepath; // the file path for the list of sound file resources
|
|
|
|
std::wstring m_intensity_file; // the replacement aggregate 'intense' sound
|
2009-04-11 19:00:39 +02:00
|
|
|
|
|
|
|
float m_CurTime; // Time elapsed since soundgroup was created
|
|
|
|
float m_TimeWindow; // The Intensity Threshold Window
|
|
|
|
size_t m_IntensityThreshold; // the allowable intensity before a sound switch
|
|
|
|
size_t m_Intensity; // our current intensity(number of sounds played since m_CurTime - m_TimeWindow)
|
|
|
|
float m_Decay; //
|
|
|
|
unsigned char m_Flags; // up to eight individual parameters, use with eSndGrpFlags.
|
|
|
|
|
|
|
|
float m_Gain;
|
|
|
|
float m_Pitch;
|
|
|
|
float m_Priority;
|
|
|
|
float m_ConeOuterGain;
|
|
|
|
float m_PitchUpper;
|
|
|
|
float m_PitchLower;
|
|
|
|
float m_GainUpper;
|
|
|
|
float m_GainLower;
|
|
|
|
float m_ConeInnerAngle;
|
|
|
|
float m_ConeOuterAngle;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //#ifndef INCLUDED_SOUNDGROUP
|