Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSDHacked [SOUNDS] support #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ci/ubuntu-buildgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ set -x
sudo apt update
if [[ -z ${USE_SDL12:-} ]]; then
sudo apt install ninja-build libsdl2-dev libsdl2-mixer-dev \
libcurl4-openssl-dev libwxgtk3.2-dev deutex
libcurl4-openssl-dev libpng-dev libwxgtk3.2-dev deutex
else
sudo apt install ninja-build libsdl1.2-dev libsdl-mixer1.2-dev \
libcurl4-openssl-dev libwxgtk3.2-dev deutex
libcurl4-openssl-dev libpng-dev libwxgtk3.2-dev deutex
fi

# Generate build
Expand Down
1 change: 1 addition & 0 deletions client/src/d_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ void D_DoomMain()
D_Initialize_States(boomstates, ::NUMSTATES);
D_Initialize_Mobjinfo(doom_mobjinfo, ::NUMMOBJTYPES);
D_Initialize_sprnames(doom_sprnames, ::NUMSPRITES, SPR_TROO);
D_Initialize_SoundMap(doom_SoundMap, ARRAY_LENGTH(doom_SoundMap));
// Initialize all extra frames
D_Init_Nightmare_Flags();
// Initialize the odamex specific objects
Expand Down
121 changes: 100 additions & 21 deletions common/d_dehacked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ struct Key

static int PatchThing(int);
static int PatchSound(int);
static int PatchSounds(int);
static int PatchFrame(int);
static int PatchSprite(int);
static int PatchSprites(int);
Expand Down Expand Up @@ -443,12 +444,31 @@ static const struct
{"[STRINGS]", PatchStrings},
{"[PARS]", PatchPars},
{"[CODEPTR]", PatchCodePtrs},
{"[SPRITES]", PatchSprites},
// Eternity engine added a few more features to BEX
{"[MUSIC]", PatchMusic},
// DSDHacked BEX additions
{"[SPRITES]", PatchSprites},
{"[SOUNDS]", PatchSounds},
{NULL, NULL},
};

DoomObjectContainer<const char*> SoundMap(ARRAY_LENGTH(doom_SoundMap));
electricbrass marked this conversation as resolved.
Show resolved Hide resolved

void D_Initialize_SoundMap(const char** source, int count)
{
SoundMap.clear();
if (source)
{
for (int i = 0; i < count; i++)
{
SoundMap.insert(source[i] ? strdup(source[i]) : NULL, i);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the id24spec, sfx has a soundnum that is int32_t. We should add those for all sounds if possible so we can reference them directly by index. This is similar to how mobjinfo and state_t have their own indices.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though looking at PatchSounds DoomObjectContainer does have the ability to store and find the given index that a sound is stored with. Does this map resolve to an sfx struct somewhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the sound structs are stored in S_sfx, a vector that is mostly only modified and accessed by functions from s_sound.cpp

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making a note here (not necessary to implement right now): the struct channel_t in s_sound.cpp is similar to the id24spec struct sfxinfo_s. That's where we can do id24 work later on.

}
}
#if defined _DEBUG
Printf(PRINT_HIGH, "D_Allocate_sounds:: allocated %d sounds.\n", count);
#endif
}

static int HandleMode(const char* mode, int num);
static BOOL HandleKey(const struct Key* keys, void* structure, const char* key, int value,
const int structsize = 0);
Expand Down Expand Up @@ -530,6 +550,7 @@ typedef struct
DoomObjectContainer<state_t> backupStates; // boomstates
DoomObjectContainer<mobjinfo_t> backupMobjInfo; // doom_mobjinfo
DoomObjectContainer<const char*> backupSprnames; // doom_sprnames
DoomObjectContainer<const char*> backupSoundMap; // doom_SoundMap
weaponinfo_t backupWeaponInfo[NUMWEAPONS + 1];
int backupMaxAmmo[NUMAMMO];
int backupClipAmmo[NUMAMMO];
Expand All @@ -542,6 +563,7 @@ DoomBackup doomBackup;
typedef DoomObjectContainer<state_t*, int32_t>::const_iterator StatesIterator;
typedef DoomObjectContainer<mobjinfo_t*, int32_t>::const_iterator MobjIterator;
typedef DoomObjectContainer<const char*, int32_t>::const_iterator SpriteNamesIterator;
typedef DoomObjectContainer<const char*, int32_t>::const_iterator SoundMapIterator;

static void BackupData(void)
{
Expand Down Expand Up @@ -593,6 +615,15 @@ static void BackupData(void)
doomBackup.backupSprnames.insert(spr, it.first);
}

// sounds
doomBackup.backupSoundMap.resize(ARRAY_LENGTH(doom_SoundMap));
doomBackup.backupSoundMap.clear();
for(const std::pair<int32_t, const char*> & it : SoundMap)
{
const char* sound = strdup(it.second);
doomBackup.backupSoundMap.insert(sound, it.first);
}

std::copy(weaponinfo, weaponinfo + ::NUMWEAPONS + 1, doomBackup.backupWeaponInfo);
std::copy(clipammo, clipammo + ::NUMAMMO, doomBackup.backupClipAmmo);
std::copy(maxammo, maxammo + ::NUMAMMO, doomBackup.backupMaxAmmo);
Expand Down Expand Up @@ -626,7 +657,8 @@ void D_UndoDehPatch()
D_Initialize_sprnames(doomBackup.backupSprnames.data(), ::NUMSPRITES, SPR_TROO);
D_Initialize_States(doomBackup.backupStates.data(), ::NUMSTATES);
D_Initialize_Mobjinfo(doomBackup.backupMobjInfo.data(), ::NUMMOBJTYPES);

D_Initialize_SoundMap(doomBackup.backupSoundMap.data(), ARRAY_LENGTH(doom_SoundMap));

extern bool isFast;
isFast = false;

Expand Down Expand Up @@ -1034,7 +1066,6 @@ static int PatchThing(int thingy)
m.meleerange = MELEERANGE;
m.translucency = 0x10000;
m.altspeed = NO_ALTSPEED;
m.ripsound = "";
return m;
};
mobjinfo_t* mobj = (mobjinfo_t*) M_Calloc(1, sizeof(mobjinfo_t));
Expand All @@ -1052,13 +1083,6 @@ static int PatchThing(int thingy)

while ((result = GetLine()) == 1)
{
size_t sndmap = atoi(Line2);

if (sndmap >= ARRAY_LENGTH(SoundMap))
{
sndmap = 0;
}

size_t val = atoi(Line2);
int linelen = strlen(Line1);

Expand Down Expand Up @@ -1103,12 +1127,17 @@ static int PatchThing(int thingy)
{
char* snd;

if (val == 0 || val >= ARRAY_LENGTH(SoundMap))
// If sound is not yet in SoundMap, store the index to be used in PatchSounds
auto soundIt = SoundMap.find(val);
if (soundIt == SoundMap.end())
{
val = 0;
snd = Line2;
stripwhite(snd);
}
else
{
snd = (char*)soundIt->second;
}

snd = (char*)SoundMap[val];

if (!strnicmp(Line1, "Alert", 5))
{
Expand Down Expand Up @@ -1572,7 +1601,7 @@ static int PatchFrame(int frameNum)
{NULL, 0}};
int result;
state_t *info, dummy;

static const struct
{
short Bit;
Expand Down Expand Up @@ -1814,6 +1843,56 @@ static int PatchSprites(int dummy)
return result;
}

void IdxToSoundName(const char* sound)
{
if (sound && sound[0] && IsNum(sound))
{
auto soundIt = SoundMap.find(atoi(sound));
sound = soundIt == SoundMap.end() ? nullptr : (char*)soundIt->second;
}
}

static int PatchSounds(int dummy)
{
int result;
#if defined _DEBUG
DPrintf("[Sounds]\n");
#endif
while ((result = GetLine()) == 1)
{
char* newname = Line2;
stripwhite(newname);
OLumpName newnameds = fmt::sprintf("DS%s", newname);

if (IsNum(Line1))
{
int32_t soundIdx = atoi(Line1);
SoundMap.insert(strdup(newname), soundIdx);
S_AddSound(newname, newnameds.c_str());
}
else
{
int lumpnum = W_CheckNumForName(fmt::sprintf("DS%s", Line1).c_str());
int sndIdx = S_FindSoundByLump(lumpnum);
if (sndIdx == -1)
I_Error("Sound %s not found.", Line1);
S_AddSound(S_sfx[sndIdx].name, newnameds.c_str());
}
}
for (auto& pair : mobjinfo)
{
auto& info = pair.second;
IdxToSoundName(info->seesound);
IdxToSoundName(info->attacksound);
IdxToSoundName(info->painsound);
IdxToSoundName(info->deathsound);
IdxToSoundName(info->activesound);
IdxToSoundName(info->ripsound);
}
S_HashSounds();
return result;
}

static int PatchAmmo(int ammoNum)
{
extern int clipammo[NUMAMMO];
Expand Down Expand Up @@ -2704,7 +2783,7 @@ bool CheckIfDehActorDefined(const mobjtype_t mobjtype)
if (mobj.doomednum == -1 &&
mobj.spawnstate == S_TNT1 &&
mobj.spawnhealth == 0 &&
mobj.gibhealth == 0 &&
mobj.gibhealth == 0 &&
mobj.seestate == S_NULL &&
mobj.seesound == NULL &&
mobj.reactiontime == 0 &&
Expand Down Expand Up @@ -2782,7 +2861,7 @@ static void PrintMobjinfo(int index)
{
return;
}

mobjinfo_t* mob = it->second;
std::stringstream ss;
ss << "%4d | ";
Expand Down Expand Up @@ -2815,15 +2894,15 @@ BEGIN_COMMAND(mobinfo)
Printf("Must pass one or two mobjinfo indexes. (0 to %d)\n", ::num_mobjinfo_types() - 1);
return;
}

int index1 = atoi(argv[1]);
if (mobjinfo.find(index1) == mobjinfo.end())
{
Printf("Index 1: Not a valid index.\n");
return;
}
int index2 = index1;

if (argc == 3)
{
index2 = atoi(argv[2]);
Expand All @@ -2833,12 +2912,12 @@ BEGIN_COMMAND(mobinfo)
return;
}
}

if (index2 < index1)
{
std::swap(index1, index2);
}

for(int i = index1; i <= index2; i++)
{
PrintMobjinfo(i);
Expand Down
5 changes: 4 additions & 1 deletion common/d_dehacked.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

// Sound equivalences. When a patch tries to change a sound,
// use these sound names.
static const char* SoundMap[] = { NULL,
static const char* doom_SoundMap[] = {NULL,
"weapons/pistol",
"weapons/shotgf",
"weapons/shotgr",
Expand Down Expand Up @@ -223,7 +223,10 @@ static const char* SoundMap[] = { NULL,
// ZDOOM-Specific sounds
"misc/teamchat"};

extern DoomObjectContainer<const char*> SoundMap;
electricbrass marked this conversation as resolved.
Show resolved Hide resolved

void D_UndoDehPatch();
void D_PostProcessDeh();
bool D_DoDehPatch(const OResFile* patchfile, const int lump);
bool CheckIfDehActorDefined(const mobjtype_t mobjtype);
void D_Initialize_SoundMap(const char** source, int count);
12 changes: 9 additions & 3 deletions common/p_enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3103,14 +3103,20 @@ void A_PlaySound(AActor* mo)
// Play the sound from the SoundMap

int sndmap = mo->state->misc1;
char* snd;

if (sndmap >= static_cast<int>(ARRAY_LENGTH(SoundMap)))
auto soundIt = SoundMap.find(sndmap);
if (soundIt == SoundMap.end())
{
DPrintf("Warning: Sound ID is beyond the array of the Sound Map!\n");
sndmap = 0;
snd = nullptr;
}
else
{
snd = (char*)soundIt->second;
}

S_Sound(mo, CHAN_BODY, SoundMap[sndmap], 1,
S_Sound(mo, CHAN_BODY, snd, 1,
(mo->state->misc2 ? ATTN_NONE : ATTN_NORM));
}

Expand Down
27 changes: 20 additions & 7 deletions common/p_pspr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,10 +1091,17 @@ void A_WeaponMeleeAttack(AActor* mo)
hitsound = psp->state->args[3];
range = psp->state->args[4];

if (hitsound >= static_cast<int>(ARRAY_LENGTH(SoundMap)))
char* snd;

auto soundIt = SoundMap.find(hitsound);
if (soundIt == SoundMap.end())
{
DPrintf("Warning: Weapon Melee Hitsound ID is beyond the array of the Sound Map!\n");
hitsound = 0;
snd = nullptr;
}
else
{
snd = (char*)soundIt->second;
}

if (range <= 0)
Expand Down Expand Up @@ -1123,7 +1130,7 @@ void A_WeaponMeleeAttack(AActor* mo)
return;

// un-missed!
UV_SoundAvoidPlayer(player->mo, CHAN_WEAPON, SoundMap[hitsound],
UV_SoundAvoidPlayer(player->mo, CHAN_WEAPON, snd,
ATTN_NORM);

// turn to face target
Expand All @@ -1146,14 +1153,20 @@ void A_WeaponSound(AActor *mo)
return;

int sndmap = psp->state->args[0];
char* snd;

if (sndmap >= static_cast<int>(ARRAY_LENGTH(SoundMap)))
auto soundIt = SoundMap.find(sndmap);
if (soundIt == SoundMap.end())
{
DPrintf("Warning: Weapon sound ID is beyond the array of the Sound Map!\n");
snd = nullptr;
}
else
{
DPrintf("Warning: Weapon Sound ID is beyond the array of the Sound Map!\n");
sndmap = 0;
snd = (char*)soundIt->second;
}

UV_SoundAvoidPlayer(player->mo, CHAN_WEAPON, SoundMap[sndmap],
UV_SoundAvoidPlayer(player->mo, CHAN_WEAPON, snd,
(psp->state->args[1] ? ATTN_NONE : ATTN_NORM));
}

Expand Down
7 changes: 4 additions & 3 deletions server/src/d_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void STACK_ARGS D_Shutdown()

// stop sound effects and music
S_Stop();

DThinker::DestroyAllThinkers();

D_UndoDehPatch();
Expand All @@ -217,7 +217,7 @@ void STACK_ARGS D_Shutdown()

// [AM] Level is now invalid due to torching zone memory.
g_ValidLevel = false;

// [AM] All of our dyncolormaps are freed, tidy up so we
// don't follow wild pointers.
NormalLight.next = NULL;
Expand All @@ -244,6 +244,7 @@ void D_DoomMain()
D_Initialize_States(boomstates, ::NUMSTATES);
D_Initialize_Mobjinfo(doom_mobjinfo, ::NUMMOBJTYPES);
D_Initialize_sprnames(doom_sprnames, ::NUMSPRITES, SPR_TROO);
D_Initialize_SoundMap(doom_SoundMap, ARRAY_LENGTH(doom_SoundMap));
// Initialize all extra frames
D_Init_Nightmare_Flags();
// Initialize the odamex specific objects
Expand Down Expand Up @@ -387,7 +388,7 @@ void D_DoomMain()
startmap = Args.GetArg(p + 1);
((char*)Args.GetArg(p))[0] = '-';
}

level.mapname = startmap;

G_ChangeMap();
Expand Down
Loading