Browse Source

PlaySFX_priv, stream_play (#371)

* PlaySFX_priv, stream_play

* Fix build warnings in player.cpp

* Clean up FreeMonsterSnd

* Added more enums and defines for sound and effects.
pull/4/head
Anders Jenbo 8 years ago committed by Robin Eklind
parent
commit
f269f4561b
  1. 149
      Source/effects.cpp
  2. 2
      Source/effects.h
  3. 39
      Source/gamemenu.cpp
  4. 6
      Source/player.cpp
  5. 22
      Source/sound.cpp
  6. 3
      defs.h
  7. 13
      enums.h

149
Source/effects.cpp

@ -894,7 +894,7 @@ BOOL __fastcall effect_is_playing(int nSFX)
v2 = v1->pSnd;
if ( v2 )
return snd_playing(v2);
if ( v1->bFlags & 1 )
if ( v1->bFlags & SFX_STREAM )
return v1 == sfx_data_cur;
return FALSE;
}
@ -1011,50 +1011,35 @@ void __fastcall PlaySFX(int psfx)
PlaySFX_priv(&sgSFX[v1], 0, 0, 0);
}
void __fastcall PlaySFX_priv(TSFX *pSFX, char loc, int x, int y)
void __fastcall PlaySFX_priv(TSFX *pSFX, BOOL loc, int x, int y)
{
int v4; // edi
TSFX *v5; // esi
TSnd *v6; // ecx
//int v7; // eax
TSnd *v8; // ecx
int volume_delta; // [esp+Ch] [ebp-8h]
int pan; // [esp+10h] [ebp-4h]
if ( plr[myplr].pLvlLoad && gbMaxPlayers != 1 ) {
return;
}
if ( !gbSndInited || !gbSoundOn || gbBufferMsgs ) {
return;
}
v4 = loc;
v5 = pSFX;
if ( !plr[myplr].pLvlLoad || gbMaxPlayers == 1 )
{
if ( gbSndInited )
{
if ( gbSoundOn )
{
if ( !gbBufferMsgs )
{
if ( pSFX->bFlags & 3 || (v6 = pSFX->pSnd) == 0 || !snd_playing(v6) )
{
pan = 0;
volume_delta = 0;
if ( !v4 || calc_snd_position(x, y, &volume_delta, &pan) )
{
if ( v5->bFlags & 1 )
{
stream_play(v5, volume_delta, pan);
}
else
{
if ( !v5->pSnd )
v5->pSnd = sound_file_load(v5->pszName);
v8 = v5->pSnd;
if ( v8 )
snd_play_snd(v8, volume_delta, pan);
}
}
}
}
}
}
if ( !(pSFX->bFlags & (SFX_STREAM | SFX_MISC)) && pSFX->pSnd != 0 && snd_playing(pSFX->pSnd) ) {
return;
}
int lPan = 0;
int lVolume = 0;
if ( loc && !calc_snd_position(x, y, &lVolume, &lPan) ) {
return;
}
if ( pSFX->bFlags & SFX_STREAM ) {
stream_play(pSFX, lVolume, lPan);
return;
}
if ( !pSFX->pSnd )
pSFX->pSnd = sound_file_load(pSFX->pszName);
if ( pSFX->pSnd )
snd_play_snd(pSFX->pSnd, lVolume, lPan);
}
// 4A22D5: using guessed type char gbSoundOn;
// 676194: using guessed type char gbBufferMsgs;
@ -1062,32 +1047,18 @@ void __fastcall PlaySFX_priv(TSFX *pSFX, char loc, int x, int y)
void __fastcall stream_play(TSFX *pSFX, int lVolume, int lPan)
{
int v3; // esi
TSFX *v4; // edi
int v5; // esi
//int v6; // eax
//int v7; // eax
v3 = lVolume;
v4 = pSFX;
sfx_stop();
v5 = sound_get_or_set_sound_volume(1) + v3;
if ( v5 >= -1600 )
{
if ( v5 > 0 )
v5 = 0;
//_LOBYTE(v6) = SFileOpenFile(v4->pszName, &sfx_stream);
if ( SFileOpenFile(v4->pszName, &sfx_stream) )
{
//_LOBYTE(v7) = SFileDdaBeginEx(sfx_stream, 0x40000, 0, 0, v5, lPan, 0);
if ( SFileDdaBeginEx(sfx_stream, 0x40000, 0, 0, v5, lPan, 0) )
sfx_data_cur = v4;
else
sfx_stop();
}
else
{
lVolume += sound_get_or_set_sound_volume(1);
if ( lVolume >= VOLUME_MIN ) {
if ( lVolume > VOLUME_MAX )
lVolume = VOLUME_MAX;
if ( !SFileOpenFile(pSFX->pszName, &sfx_stream) ) {
sfx_stream = 0;
} else {
if ( !SFileDdaBeginEx(sfx_stream, 0x40000, 0, 0, lVolume, lPan, 0) )
sfx_stop();
else
sfx_data_cur = pSFX;
}
}
}
@ -1144,40 +1115,17 @@ void __fastcall PlaySfxLoc(int psfx, int x, int y)
void __cdecl FreeMonsterSnd()
{
TSnd **v0; // esi
signed int v1; // ebx
signed int v2; // edi
int v3; // [esp+0h] [ebp-8h]
TSnd **v4; // [esp+4h] [ebp-4h]
snd_update(1);
snd_update(TRUE);
sfx_stop();
sound_stop();
v3 = 0;
if ( nummtypes > 0 )
{
v4 = Monsters[0].Snds[0];
do
{
v0 = v4;
v1 = 4;
do
{
v2 = 2;
do
{
snd_stop_snd(*v0);
++v0;
--v2;
}
while ( v2 );
--v1;
for ( int i = 0; i < nummtypes; i++ ) {
for ( int j = 0; j < 4; j++ ) {
for ( int k = 0; k < 2; k++ ) {
snd_stop_snd(Monsters[i].Snds[j][k]);
}
while ( v1 );
++v3;
v4 += 82;
}
while ( v3 < nummtypes );
}
}
@ -1286,10 +1234,13 @@ void __fastcall priv_sound_init(int bLoadMask)
TSnd *v5; // eax
unsigned char v6; // [esp+0h] [ebp-4h]
if ( gbSndInited )
{
v1 = bLoadMask & 0x70;
v2 = bLoadMask & 0x70 ^ bLoadMask;
v1 = bLoadMask & (SFX_ROGUE | SFX_WARRIOR | SFX_SORCEROR);
v2 = bLoadMask & (SFX_ROGUE | SFX_WARRIOR | SFX_SORCEROR) ^ bLoadMask;
v3 = 0;
v6 = v2;
do
@ -1297,7 +1248,7 @@ void __fastcall priv_sound_init(int bLoadMask)
if ( !sgSFX[v3].pSnd )
{
v4 = sgSFX[v3].bFlags;
if ( !(v4 & 1) && (!v2 || v4 & v2) && (!(v4 & 0x70) || v4 & v1) )
if ( !(v4 & SFX_STREAM) && (!v2 || v4 & v2) && (!(v4 & (SFX_ROGUE | SFX_WARRIOR | SFX_SORCEROR)) || v4 & v1) )
{
v5 = sound_file_load(sgSFX[v3].pszName);
v2 = v6;

2
Source/effects.h

@ -16,7 +16,7 @@ void __cdecl FreeEffects();
void __fastcall PlayEffect(int i, int mode);
BOOL __fastcall calc_snd_position(int x, int y, int *plVolume, int *plPan);
void __fastcall PlaySFX(int psfx);
void __fastcall PlaySFX_priv(TSFX *pSFX, char loc, int x, int y);
void __fastcall PlaySFX_priv(TSFX *pSFX, BOOL loc, int x, int y);
void __fastcall stream_play(TSFX *pSFX, int lVolume, int lPan);
int __fastcall RndSFX(int psfx);
void __fastcall PlaySfxLoc(int psfx, int x, int y);

39
Source/gamemenu.cpp

@ -185,7 +185,7 @@ void __fastcall gamemenu_sound_music_toggle(char **names, TMenuItem *menu_item,
menu_item->dwFlags |= 0xC0000000;
menu_item->pszStr = *names;
gmenu_slider_3(menu_item, 17);
gmenu_slider_1(menu_item, -1600, 0, gamma);
gmenu_slider_1(menu_item, VOLUME_MIN, VOLUME_MAX, gamma);
}
else
{
@ -220,18 +220,18 @@ void __fastcall gamemenu_music_volume(int a1)
{
gbMusicOn = 0;
music_stop();
sound_get_or_set_music_volume(-1600);
sound_get_or_set_music_volume(VOLUME_MIN);
goto LABEL_11;
}
gbMusicOn = 1;
sound_get_or_set_music_volume(0);
sound_get_or_set_music_volume(VOLUME_MAX);
LABEL_10:
music_start((unsigned char)leveltype);
goto LABEL_11;
}
v1 = gamemenu_slider_music_sound(sgOptionMenu);
sound_get_or_set_music_volume(v1);
if ( v1 != -1600 )
if ( v1 != VOLUME_MIN )
{
if ( gbMusicOn )
goto LABEL_11;
@ -251,7 +251,7 @@ LABEL_11:
int __fastcall gamemenu_slider_music_sound(TMenuItem *menu_item)
{
return gmenu_slider_get(menu_item, -1600, 0);
return gmenu_slider_get(menu_item, VOLUME_MIN, VOLUME_MAX);
}
void __fastcall gamemenu_sound_volume(int a1)
@ -259,35 +259,24 @@ void __fastcall gamemenu_sound_volume(int a1)
int v1; // ecx
int v2; // esi
if ( a1 )
{
if ( gbSoundOn )
{
if ( a1 ) {
if ( gbSoundOn ) {
gbSoundOn = 0;
FreeMonsterSnd();
v1 = -1600;
}
else
{
v1 = VOLUME_MIN;
} else {
gbSoundOn = 1;
v1 = 0;
}
sound_get_or_set_sound_volume(v1);
}
else
{
sound_get_or_set_sound_volume(VOLUME_MAX);
} else {
v2 = gamemenu_slider_music_sound(&sgOptionMenu[1]);
sound_get_or_set_sound_volume(v2);
if ( v2 == -1600 )
{
if ( gbSoundOn )
{
if ( v2 == VOLUME_MIN ) {
if ( gbSoundOn ) {
gbSoundOn = 0;
FreeMonsterSnd();
}
}
else if ( !gbSoundOn )
{
} else if ( !gbSoundOn ) {
gbSoundOn = 1;
}
}

6
Source/player.cpp

@ -606,11 +606,11 @@ void __fastcall CreatePlayer(int pnum, char c)
plr[pnum]._pInfraFlag = 0;
if ( c == PC_WARRIOR ) {
plr[pnum]._pAblSpells64 = (__int64)1 << SPL_REPAIR - 1;
plr[pnum]._pAblSpells64 = (__int64)1 << (SPL_REPAIR - 1);
} else if ( c == PC_ROGUE ) {
plr[pnum]._pAblSpells64 = (__int64)1 << SPL_DISARM - 1;
plr[pnum]._pAblSpells64 = (__int64)1 << (SPL_DISARM - 1);
} else if ( c == PC_SORCERER ) {
plr[pnum]._pAblSpells64 = (__int64)1 << SPL_RECHARGE - 1;
plr[pnum]._pAblSpells64 = (__int64)1 << (SPL_RECHARGE - 1);
}
if ( c == PC_SORCERER) {

22
Source/sound.cpp

@ -110,10 +110,10 @@ void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
}
lVolume += sglSoundVolume;
if ( lVolume < -1600 ) {
lVolume = -1600;
} else if ( lVolume > 0 ) {
lVolume = 0;
if ( lVolume < VOLUME_MIN ) {
lVolume = VOLUME_MIN;
} else if ( lVolume > VOLUME_MAX ) {
lVolume = VOLUME_MAX;
}
DSB->SetVolume(lVolume);
@ -246,10 +246,10 @@ void __fastcall sound_file_cleanup(TSnd *sound_file)
void __fastcall snd_init(HWND hWnd)
{
sound_load_volume("Sound Volume", &sglSoundVolume);
gbSoundOn = sglSoundVolume > -1600;
gbSoundOn = sglSoundVolume > VOLUME_MIN;
sound_load_volume("Music Volume", &sglMusicVolume);
gbMusicOn = sglMusicVolume > -1600;
gbMusicOn = sglMusicVolume > VOLUME_MIN;
if ( sound_DirectSoundCreate(NULL, &sglpDS, NULL) != DS_OK )
sglpDS = NULL;
@ -269,14 +269,14 @@ void __fastcall sound_load_volume(char *value_name, int *value)
{
int v = *value;
if ( !SRegLoadValue("Diablo", value_name, 0, &v) ) {
v = 0;
v = VOLUME_MAX;
}
*value = v;
if ( *value < -1600 ) {
*value = -1600;
} else if ( *value > 0 ) {
*value = 0;
if ( *value < VOLUME_MIN ) {
*value = VOLUME_MIN;
} else if ( *value > VOLUME_MAX ) {
*value = VOLUME_MAX;
}
*value -= *value % 100;
}

3
defs.h

@ -38,6 +38,9 @@
// Item indestructible durability
#define DUR_INDESTRUCTIBLE 255
#define VOLUME_MIN -1600
#define VOLUME_MAX 0
// todo: enums
#define NUM_SFX 858
#define NUMLEVELS 17

13
enums.h

@ -1129,6 +1129,17 @@ enum _sfx_id
USFX_DIABLOD = 0x359,
};
enum sfx_flag {
SFX_STREAM = 0x01,
SFX_MISC = 0x02,
SFX_UI = 0x04,
SFX_08 = 0x08,
SFX_ROGUE = 0x10,
SFX_WARRIOR = 0x20,
SFX_SORCEROR = 0x40,
SFX_LOADED = 0x80,
};
enum item_equip_type
{
ILOC_NONE = 0x0,
@ -2573,7 +2584,7 @@ enum _walk_path
WALK_E = 0x6,
WALK_S = 0x7,
WALK_W = 0x8,
WALK_NONE = 0xFFFFFFFF,
WALK_NONE = -1,
};
enum item_class {

Loading…
Cancel
Save