mirror of
https://github.com/vcmi/vcmi.git
synced 2026-06-19 22:57:37 +02:00
Many quoted local includes had an incorrect ../ depth and resolved to
non-existent files from the including file's directory.
This was easy to miss because normal target include directories and PCH
usage masked some failures, and several stale paths lived in files that
are only compiled in optional test configurations. As a result, the
problem mostly surfaced in stricter or broader fresh builds.
Audit all C++ and header local includes, keep them relative, and adjust
paths so each include resolves to an existing in-tree header. For
headers that were renamed or moved, update includes to their current
relative location instead of switching to include-root form.
A few legacy ERM tests also used dynamic_ptr_cast at call sites where we
had to replace stale headers. The helper/header path they relied on is
no longer present after 81af66d35b, so
those downcasts are now explicit dynamic_cast calls with the same intent.
97 lines
3.0 KiB
C++
97 lines
3.0 KiB
C++
/*
|
|
* CSoundHandler.h, part of VCMI engine
|
|
*
|
|
* Authors: listed in file AUTHORS in main folder
|
|
*
|
|
* License: GNU General Public License v2.0 or later
|
|
* Full text of license available in license.txt file, in main folder
|
|
*
|
|
*/
|
|
#pragma once
|
|
|
|
#include "CAudioBase.h"
|
|
#include "ISoundPlayer.h"
|
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
struct Mix_Chunk;
|
|
|
|
class CSoundHandler final : public CAudioBase, public ISoundPlayer
|
|
{
|
|
private:
|
|
struct MixChunkDeleter
|
|
{
|
|
void operator ()(Mix_Chunk *);
|
|
};
|
|
using MixChunkPtr = std::unique_ptr<Mix_Chunk, MixChunkDeleter>;
|
|
|
|
//update volume on configuration change
|
|
SettingsListener listener;
|
|
void onVolumeChange(const JsonNode & volumeNode);
|
|
|
|
using CachedChunk = std::pair<MixChunkPtr, std::unique_ptr<ui8[]>>;
|
|
|
|
/// List of all permanently cached sound chunks
|
|
std::map<AudioPath, CachedChunk> soundChunks;
|
|
|
|
/// List of all currently playing chunks that are currently playing
|
|
/// and should be deallocated once channel playback is over
|
|
/// indexed by channel ID
|
|
std::map<int, MixChunkPtr> uncachedPlayingChunks;
|
|
|
|
MixChunkPtr getSoundChunk(const AudioPath & sound);
|
|
Mix_Chunk * getSoundChunkCached(const AudioPath & sound);
|
|
MixChunkPtr getSoundChunk(std::pair<std::unique_ptr<ui8[]>, si64> & data);
|
|
|
|
/// have entry for every currently active channel
|
|
/// vector will be empty if callback was not set
|
|
std::map<int, std::vector<std::function<void()>>> callbacks;
|
|
|
|
/// Protects access to callbacks member to avoid data races:
|
|
/// SDL calls sound finished callbacks from audio thread
|
|
std::mutex mutexCallbacks;
|
|
|
|
int ambientDistToVolume(int distance) const;
|
|
void ambientStopSound(const AudioPath & soundId);
|
|
void updateChannelVolume(int channel);
|
|
|
|
const JsonNode ambientConfig;
|
|
|
|
std::mutex mutex;
|
|
std::map<AudioPath, int> ambientChannels;
|
|
std::map<int, int> channelVolumes;
|
|
int volume = 0;
|
|
|
|
void initCallback(int channel, const std::function<void()> & function);
|
|
void initCallback(int channel);
|
|
void storeChunk(int channel, MixChunkPtr chunk);
|
|
int playSoundImpl(const AudioPath & sound, int repeats, bool useCache);
|
|
|
|
public:
|
|
CSoundHandler();
|
|
~CSoundHandler();
|
|
|
|
ui32 getVolume() const final;
|
|
void setVolume(ui32 percent) final;
|
|
void setChannelVolume(int channel, ui32 percent);
|
|
|
|
// Sounds
|
|
uint32_t getSoundDurationMilliseconds(const AudioPath & sound) final;
|
|
int playSound(soundBase::soundID soundID) final;
|
|
int playSound(const AudioPath & sound) final;
|
|
int playSoundLooped(const AudioPath & sound) final;
|
|
int playSound(std::pair<std::unique_ptr<ui8[]>, si64> & data) final;
|
|
int playSoundFromSet(std::vector<soundBase::soundID> & sound_vec) final;
|
|
void stopSound(int handler) final;
|
|
void pauseSound(int handler) final;
|
|
void resumeSound(int handler) final;
|
|
|
|
void setCallback(int channel, std::function<void()> function) final;
|
|
void resetCallback(int channel) final;
|
|
void soundFinishedCallback(int channel) final;
|
|
|
|
int ambientGetRange() const final;
|
|
void ambientUpdateChannels(std::map<AudioPath, int> currentSounds) final;
|
|
void ambientStopAllChannels() final;
|
|
};
|