From 6e9987cc93f32ee2c75712d95a74d720b41f30ed Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 31 Jan 2020 00:20:00 +0100 Subject: [PATCH] Rename dsound and it nolonger reflects DirectSound --- CMakeLists.txt | 2 +- Source/sound.h | 6 +++--- SourceS/miniwin.h | 1 - SourceS/miniwin/com.h | 17 ----------------- SourceS/miniwin/misc_macro.h | 1 - SourceS/ssound.h | 18 ++++++++++++++++++ SourceX/miniwin/dsound.h | 21 --------------------- SourceX/sound.cpp | 7 +++---- SourceX/{miniwin/dsound.cpp => ssound.cpp} | 13 ++++++------- structs.h | 2 +- types.h | 1 + 11 files changed, 33 insertions(+), 56 deletions(-) delete mode 100644 SourceS/miniwin/com.h create mode 100644 SourceS/ssound.h delete mode 100644 SourceX/miniwin/dsound.h rename SourceX/{miniwin/dsound.cpp => ssound.cpp} (73%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed03c6d45..63ad5763f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,8 +255,8 @@ set(devilutionx_SRCS SourceX/miniwin/misc_msg.cpp SourceX/miniwin/rand.cpp SourceX/miniwin/thread.cpp - SourceX/miniwin/dsound.cpp SourceX/sound.cpp + SourceX/ssound.cpp SourceX/storm/storm.cpp SourceX/storm/storm_net.cpp SourceX/storm/storm_dx.cpp diff --git a/Source/sound.h b/Source/sound.h index b49669149..d7fe1c6ce 100644 --- a/Source/sound.h +++ b/Source/sound.h @@ -2,7 +2,7 @@ #ifndef __SOUND_H__ #define __SOUND_H__ -extern IDirectSoundBuffer *DSBs[8]; +extern SoundSample *DSBs[8]; extern BOOLEAN gbSndInited; extern HMODULE hDsound_dll; @@ -10,8 +10,8 @@ void snd_update(BOOL bStopAll); void snd_stop_snd(TSnd *pSnd); BOOL snd_playing(TSnd *pSnd); void snd_play_snd(TSnd *pSnd, int lVolume, int lPan); -IDirectSoundBuffer *sound_dup_channel(IDirectSoundBuffer *DSB); -BOOL sound_file_reload(TSnd *sound_file, IDirectSoundBuffer *DSB); +SoundSample *sound_dup_channel(SoundSample *DSB); +BOOL sound_file_reload(TSnd *sound_file, SoundSample *DSB); TSnd *sound_file_load(char *path); void sound_CreateSoundBuffer(TSnd *sound_file); void sound_file_cleanup(TSnd *sound_file); diff --git a/SourceS/miniwin.h b/SourceS/miniwin.h index 589831766..fc76a5746 100644 --- a/SourceS/miniwin.h +++ b/SourceS/miniwin.h @@ -22,7 +22,6 @@ #endif #include "miniwin/misc.h" -#include "miniwin/com.h" #include "miniwin/ui.h" #include "miniwin/thread.h" #include "miniwin/rand.h" diff --git a/SourceS/miniwin/com.h b/SourceS/miniwin/com.h deleted file mode 100644 index 9a52ea5b7..000000000 --- a/SourceS/miniwin/com.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -namespace dvl { - -struct IDirectSoundBuffer { - virtual void Release() = 0; - virtual bool IsPlaying() = 0; - virtual void Play(int lVolume, int lPan) = 0; - virtual void Stop() = 0; - virtual int SetChunk(BYTE *fileData, DWORD dwBytes) = 0; -}; - -typedef IDirectSoundBuffer *LPDIRECTSOUNDBUFFER; - -const auto DVL_ERROR_SUCCESS = 0L; - -} // namespace dvl diff --git a/SourceS/miniwin/misc_macro.h b/SourceS/miniwin/misc_macro.h index 6d2c1f55d..dc7226a8b 100644 --- a/SourceS/miniwin/misc_macro.h +++ b/SourceS/miniwin/misc_macro.h @@ -49,7 +49,6 @@ #define GENERIC_WRITE DVL_GENERIC_WRITE #define OPEN_EXISTING DVL_OPEN_EXISTING #define OPEN_ALWAYS 4 -#define ERROR_SUCCESS DVL_ERROR_SUCCESS #define FILE_ATTRIBUTE_NORMAL 128 #define OFS_MAXPATHNAME DVL_OFS_MAXPATHNAME diff --git a/SourceS/ssound.h b/SourceS/ssound.h new file mode 100644 index 000000000..4809ce0bd --- /dev/null +++ b/SourceS/ssound.h @@ -0,0 +1,18 @@ +#pragma once +#include + +namespace dvl { + +typedef struct SoundSample final { +public: + void Release() ; + bool IsPlaying() ; + void Play(int lVolume, int lPan) ; + void Stop() ; + int SetChunk(BYTE *fileData, DWORD dwBytes) ; + +private: + Mix_Chunk *chunk; +} SoundSample; + +} // namespace dvl diff --git a/SourceX/miniwin/dsound.h b/SourceX/miniwin/dsound.h deleted file mode 100644 index d67d2ae3d..000000000 --- a/SourceX/miniwin/dsound.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "devilution.h" - -#include - -namespace dvl { - -struct DirectSoundBuffer final : public IDirectSoundBuffer { -public: - void Release() override; - bool IsPlaying() override; - void Play(int lVolume, int lPan) override; - void Stop() override; - int SetChunk(BYTE *fileData, DWORD dwBytes) override; - -private: - Mix_Chunk *chunk; -}; - -} // namespace dvl diff --git a/SourceX/sound.cpp b/SourceX/sound.cpp index 9ca31d238..12016107c 100644 --- a/SourceX/sound.cpp +++ b/SourceX/sound.cpp @@ -1,5 +1,4 @@ #include "devilution.h" -#include "miniwin/dsound.h" #include "stubs.h" #include #include @@ -46,7 +45,7 @@ BOOL snd_playing(TSnd *pSnd) void snd_play_snd(TSnd *pSnd, int lVolume, int lPan) { - LPDIRECTSOUNDBUFFER DSB; + SoundSample *DSB; DWORD tc; if (!pSnd || !gbSoundOn) { @@ -91,7 +90,7 @@ TSnd *sound_file_load(char *path) wave_file = DiabloAllocPtr(dwBytes); SFileReadFile(file, wave_file, dwBytes, NULL, NULL); - pSnd->DSB = new DirectSoundBuffer(); + pSnd->DSB = new SoundSample(); error = pSnd->DSB->SetChunk(wave_file, dwBytes); WCloseFile(file); mem_free_dbg(wave_file); @@ -108,7 +107,7 @@ void sound_file_cleanup(TSnd *sound_file) if (sound_file->DSB) { sound_file->DSB->Stop(); sound_file->DSB->Release(); - delete static_cast(sound_file->DSB); + delete sound_file->DSB; sound_file->DSB = NULL; } diff --git a/SourceX/miniwin/dsound.cpp b/SourceX/ssound.cpp similarity index 73% rename from SourceX/miniwin/dsound.cpp rename to SourceX/ssound.cpp index db6baba37..836aa7927 100644 --- a/SourceX/miniwin/dsound.cpp +++ b/SourceX/ssound.cpp @@ -1,18 +1,17 @@ #include "devilution.h" -#include "miniwin/dsound.h" #include "stubs.h" #include namespace dvl { -///// DirectSoundBuffer ///// +///// SoundSample ///// -void DirectSoundBuffer::Release() +void SoundSample::Release() { Mix_FreeChunk(chunk); }; -bool DirectSoundBuffer::IsPlaying() +bool SoundSample::IsPlaying() { for (int i = 1; i < Mix_AllocateChannels(-1); i++) { if (Mix_GetChunk(i) == chunk && Mix_Playing(i)) { @@ -23,7 +22,7 @@ bool DirectSoundBuffer::IsPlaying() return false; }; -void DirectSoundBuffer::Play(int lVolume, int lPan) +void SoundSample::Play(int lVolume, int lPan) { int channel = Mix_PlayChannel(-1, chunk, 0); if (channel == -1) { @@ -36,7 +35,7 @@ void DirectSoundBuffer::Play(int lVolume, int lPan) Mix_SetPanning(channel, pan > 0 ? pan : 255, pan < 0 ? abs(pan) : 255); }; -void DirectSoundBuffer::Stop() +void SoundSample::Stop() { for (int i = 1; i < Mix_AllocateChannels(-1); i++) { if (Mix_GetChunk(i) != chunk) { @@ -47,7 +46,7 @@ void DirectSoundBuffer::Stop() } }; -int DirectSoundBuffer::SetChunk(BYTE *fileData, DWORD dwBytes) +int SoundSample::SetChunk(BYTE *fileData, DWORD dwBytes) { SDL_RWops *buf1 = SDL_RWFromConstMem(fileData, dwBytes); if (buf1 == NULL) { diff --git a/structs.h b/structs.h index 7c0d1dd7a..d890d23ce 100644 --- a/structs.h +++ b/structs.h @@ -451,7 +451,7 @@ typedef struct MissileStruct { typedef struct TSnd { char *sound_path; - LPDIRECTSOUNDBUFFER DSB; + SoundSample *DSB; int start_tc; } TSnd; diff --git a/types.h b/types.h index 83cf1709b..4a793198d 100644 --- a/types.h +++ b/types.h @@ -9,6 +9,7 @@ #define DEVILUTION_END_NAMESPACE } #include "miniwin.h" +#include "ssound.h" DEVILUTION_BEGIN_NAMESPACE