2025-08-10 10:59:02 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2009-04-18 10:00:33 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-04-18 10:00:33 -07:00
|
|
|
* 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.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-04-18 10:00:33 -07:00
|
|
|
* 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
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-18 10:00:33 -07:00
|
|
|
*/
|
|
|
|
|
|
2012-08-14 17:10:44 -07:00
|
|
|
#ifndef INCLUDED_SOUNDGROUP_H
|
|
|
|
|
#define INCLUDED_SOUNDGROUP_H
|
2009-04-11 10:00:39 -07:00
|
|
|
|
2025-08-10 10:59:02 -07:00
|
|
|
#include "lib/code_annotation.h"
|
2012-08-31 12:08:41 -07:00
|
|
|
#include "lib/config2.h"
|
2009-11-03 13:46:35 -08:00
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
2019-04-25 15:37:15 -07:00
|
|
|
#include "lib/types.h"
|
2013-03-01 06:22:28 -08:00
|
|
|
#include "simulation2/system/Entity.h"
|
2009-04-11 10:00:39 -07:00
|
|
|
|
2025-08-10 10:59:02 -07:00
|
|
|
#include <cstddef>
|
|
|
|
|
#include <string>
|
2009-04-11 10:00:39 -07:00
|
|
|
#include <vector>
|
|
|
|
|
|
2025-08-10 10:59:02 -07:00
|
|
|
class CSoundData;
|
2012-08-14 17:10:44 -07:00
|
|
|
class CVector3D;
|
|
|
|
|
|
2009-04-11 10:00:39 -07:00
|
|
|
enum eSndGrpFlags
|
|
|
|
|
{
|
2019-01-02 14:31:46 -08:00
|
|
|
eRandOrder = 0x01,
|
|
|
|
|
eRandGain = 0x02,
|
|
|
|
|
eRandPitch = 0x04,
|
|
|
|
|
eLoop = 0x08,
|
|
|
|
|
eOmnipresent = 0x10,
|
|
|
|
|
eDistanceless = 0x20,
|
2013-06-16 19:30:40 -07:00
|
|
|
eOwnerOnly = 0x40
|
2009-04-11 10:00:39 -07:00
|
|
|
};
|
|
|
|
|
|
2019-01-02 14:31:46 -08:00
|
|
|
// Loads up a group of sound files with shared properties,
|
|
|
|
|
// and provides a simple interface for playing them.
|
2009-04-11 10:00:39 -07:00
|
|
|
class CSoundGroup
|
|
|
|
|
{
|
2010-04-04 14:24:39 -07:00
|
|
|
NONCOPYABLE(CSoundGroup);
|
2009-04-11 10:00:39 -07:00
|
|
|
public:
|
2009-11-03 13:46:35 -08:00
|
|
|
CSoundGroup(const VfsPath& pathnameXML);
|
2012-08-14 17:10:44 -07:00
|
|
|
CSoundGroup();
|
2025-10-10 11:49:37 -07:00
|
|
|
~CSoundGroup();
|
2009-04-11 10:00:39 -07:00
|
|
|
|
|
|
|
|
// Play next sound in group
|
|
|
|
|
// @param position world position of the entity generating the sound
|
|
|
|
|
// (ignored if the eOmnipresent flag is set)
|
2013-03-01 06:22:28 -08:00
|
|
|
void PlayNext(const CVector3D& position, entity_id_t source);
|
2009-04-11 10:00:39 -07:00
|
|
|
|
2012-08-14 17:10:44 -07:00
|
|
|
float RadiansOffCenter(const CVector3D& position, bool& onScreen, float& itemRollOff);
|
|
|
|
|
|
2009-04-11 10:00:39 -07:00
|
|
|
// Load a group
|
2009-11-03 13:46:35 -08:00
|
|
|
bool LoadSoundGroup(const VfsPath& pathnameXML);
|
2009-04-11 10:00:39 -07:00
|
|
|
|
|
|
|
|
void Reload();
|
|
|
|
|
|
2025-10-10 11:49:37 -07:00
|
|
|
// Release all remaining loaded handles
|
|
|
|
|
void ReleaseGroup();
|
|
|
|
|
|
2009-04-11 10:00:39 -07:00
|
|
|
// Update SoundGroup, remove dead sounds from intensity count
|
|
|
|
|
void Update(float TimeSinceLastFrame);
|
|
|
|
|
|
|
|
|
|
// Set a flag using a value from eSndGrpFlags
|
2011-08-16 04:18:32 -07:00
|
|
|
inline void SetFlag(int flag) { m_Flags = (unsigned char)(m_Flags | flag); }
|
2009-04-11 10:00:39 -07:00
|
|
|
|
|
|
|
|
// Test flag, returns true if flag is set.
|
2010-04-04 14:24:39 -07:00
|
|
|
inline bool TestFlag(int flag) { return (m_Flags & flag) != 0; }
|
2015-12-31 03:45:13 -08:00
|
|
|
|
2009-04-11 10:00:39 -07:00
|
|
|
private:
|
|
|
|
|
void SetGain(float gain);
|
2013-03-01 06:22:28 -08:00
|
|
|
|
2013-03-13 09:23:27 -07:00
|
|
|
void UploadPropertiesAndPlay(size_t theIndex, const CVector3D& position, entity_id_t source);
|
2013-03-01 06:22:28 -08:00
|
|
|
|
2009-04-11 10:00:39 -07:00
|
|
|
void SetDefaultValues();
|
2012-08-31 12:08:41 -07:00
|
|
|
#if CONFIG2_AUDIO
|
2019-01-02 14:31:46 -08:00
|
|
|
// We store the handles so we can load now and play later
|
2025-10-10 11:49:37 -07:00
|
|
|
std::vector<CSoundData*> m_SoundGroups;
|
2012-08-31 12:08:41 -07:00
|
|
|
#endif
|
2020-10-02 00:35:59 -07:00
|
|
|
u32 m_Seed;
|
2019-01-02 14:31:46 -08:00
|
|
|
// We need the filenames so we can reload when necessary.
|
|
|
|
|
std::vector<std::wstring> m_Filenames;
|
|
|
|
|
// The file path for the list of sound file resources
|
|
|
|
|
VfsPath m_Filepath;
|
|
|
|
|
size_t m_CurrentSoundIndex;
|
|
|
|
|
float m_ConeInnerAngle;
|
|
|
|
|
float m_ConeOuterAngle;
|
|
|
|
|
float m_ConeOuterGain;
|
|
|
|
|
// Time elapsed since soundgroup was created
|
|
|
|
|
float m_CurTime;
|
2015-12-31 03:45:13 -08:00
|
|
|
float m_Decay;
|
|
|
|
|
float m_Gain;
|
2009-04-11 10:00:39 -07:00
|
|
|
float m_GainUpper;
|
|
|
|
|
float m_GainLower;
|
Tweak sound distance attenuation & add configurability
Following D3108 / 876f6d5e50, sounds are attenuated by their actual
distance. However, as noted by players on A24, the dropoff is stark and,
when zoomed out, can easily result in not hearing things that are
happening in the middle of the screen.
The new default settings almost double the max-range, change the minimum
range to have greater dynamic range, and reduce the stereo depth
slightly to better match the default camera FOV.
These are stored per sound-grounp, possibly allowing future tweaks on a
per-soundgroup basis, and are configurable.
Tested by: Imarok
Discussed over mail with: Samulis, Porru
Differential Revision: https://code.wildfiregames.com/D3612
This was SVN commit r25547.
2021-05-24 23:19:25 -07:00
|
|
|
// Distance attenuation settings
|
|
|
|
|
float m_MinDist;
|
|
|
|
|
float m_MaxDist;
|
|
|
|
|
// How much stereo separation to apply to sounds based on L-R position relative to the camera.
|
|
|
|
|
float m_MaxStereoAngle;
|
2019-01-02 14:31:46 -08:00
|
|
|
// The allowable intensity before a sound switch
|
|
|
|
|
float m_IntensityThreshold;
|
|
|
|
|
float m_Pitch;
|
|
|
|
|
float m_PitchLower;
|
|
|
|
|
float m_PitchUpper;
|
|
|
|
|
float m_Priority;
|
|
|
|
|
// Up to eight individual parameters, use with eSndGrpFlags.
|
2019-04-25 15:37:15 -07:00
|
|
|
u8 m_Flags;
|
2009-04-11 10:00:39 -07:00
|
|
|
};
|
|
|
|
|
|
2012-08-14 17:10:44 -07:00
|
|
|
#endif //#ifndef INCLUDED_SOUNDGROUP_H
|