From 764010b3ab8d60fb9a3117d622b728004fad5867 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Fri, 25 Aug 2023 07:53:09 -0400 Subject: [PATCH] Implement talk sounds We're in Undertale --- src/acs/call-funcs.cpp | 15 ++++++++++++--- src/deh_tables.c | 1 + src/k_dialogue.cpp | 40 ++++++++++++++++++++++++++++++++++------ src/k_dialogue.hpp | 5 ++++- src/sounds.c | 1 + src/sounds.h | 2 ++ 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/acs/call-funcs.cpp b/src/acs/call-funcs.cpp index c688778bd..f93946a94 100644 --- a/src/acs/call-funcs.cpp +++ b/src/acs/call-funcs.cpp @@ -1943,12 +1943,17 @@ bool CallFunc_DialogueSetCustomSpeaker(ACSVM::Thread *thread, const ACSVM::Word ACSVM::String *patchStr = nullptr; const char *patchName = nullptr; + patch_t *patch = nullptr; ACSVM::String *colorStr = nullptr; const char *colorName = nullptr; skincolornum_t colorID = SKINCOLOR_NONE; UINT8 *colormap = nullptr; + ACSVM::String *voiceStr = nullptr; + const char *voiceName = nullptr; + sfxenum_t voiceID = sfx_None; + (void)argC; map = thread->scopeMap; @@ -1958,16 +1963,20 @@ bool CallFunc_DialogueSetCustomSpeaker(ACSVM::Thread *thread, const ACSVM::Word patchStr = map->getString(argV[1]); patchName = patchStr->str; + patch = static_cast( W_CachePatchName(patchName, PU_CACHE) ); - colorStr = map->getString(argV[1]); + colorStr = map->getString(argV[2]); colorName = colorStr->str; - if (ACS_GetColorFromString(colorName, &colorID) == true) { colormap = R_GetTranslationColormap(TC_DEFAULT, colorID, GTC_CACHE); } - g_dialogue.SetSpeaker(nametag, patchName, colormap); + voiceStr = map->getString(argV[3]); + voiceName = voiceStr->str; + ACS_GetSFXFromString(voiceName, &voiceID); + + g_dialogue.SetSpeaker(nametag, patch, colormap, voiceID); return false; } diff --git a/src/deh_tables.c b/src/deh_tables.c index 0196e2086..e234782a7 100644 --- a/src/deh_tables.c +++ b/src/deh_tables.c @@ -6677,6 +6677,7 @@ struct int_const_s const INT_CONST[] = { {"SKSKSLOW",SKSKSLOW}, // Overtake taunt {"SKSKHITM",SKSKHITM}, // Hit confirm taunt {"SKSKPOWR",SKSKPOWR}, // Power item taunt + {"SKSKTALK",SKSKTALK}, // Dialogue // 3D Floor/Fake Floor/FOF/whatever flags {"FOF_EXISTS",FOF_EXISTS}, ///< Always set, to check for validity. diff --git a/src/k_dialogue.cpp b/src/k_dialogue.cpp index b8190281b..c579daea2 100644 --- a/src/k_dialogue.cpp +++ b/src/k_dialogue.cpp @@ -18,11 +18,13 @@ #include #include "info.h" +#include "sounds.h" #include "g_game.h" #include "v_video.h" #include "r_draw.h" #include "m_easing.h" #include "r_skins.h" +#include "s_sound.h" #include "z_zone.h" #include "v_draw.hpp" @@ -35,14 +37,18 @@ void Dialogue::Init(void) { active = true; dismissable = false; + syllable = true; } void Dialogue::SetSpeaker(void) { // Unset speaker speaker.clear(); + portrait = nullptr; portraitColormap = nullptr; + + voiceSfx = sfx_None; } void Dialogue::SetSpeaker(std::string skinName, int portraitID) @@ -69,8 +75,11 @@ void Dialogue::SetSpeaker(std::string skinName, int portraitID) const spriteframe_t *sprframe = &sprdef->spriteframes[portraitID]; speaker = skin->realname; + portrait = static_cast( W_CachePatchNum(sprframe->lumppat[0], PU_CACHE) ); portraitColormap = R_GetTranslationColormap(skinID, static_cast(skin->prefcolor), GTC_CACHE); + + voiceSfx = skin->soundsid[ S_sfx[sfx_ktalk].skinsound ]; } else { @@ -78,22 +87,25 @@ void Dialogue::SetSpeaker(std::string skinName, int portraitID) } } -void Dialogue::SetSpeaker(std::string customName, std::string customPatch, UINT8 *customColormap) +void Dialogue::SetSpeaker(std::string name, patch_t *patch, UINT8 *colormap, sfxenum_t voice) { Init(); // Set custom speaker - speaker = customName; + speaker = name; if (speaker.empty()) { portrait = nullptr; portraitColormap = nullptr; + voiceSfx = sfx_None; return; } - portrait = static_cast( W_CachePatchName(customPatch.c_str(), PU_CACHE) ); - portraitColormap = customColormap; + portrait = patch; + portraitColormap = colormap; + + voiceSfx = voice; } void Dialogue::NewText(std::string newText) @@ -106,7 +118,7 @@ void Dialogue::NewText(std::string newText) 0, HU_FONT, newText.c_str() ); - + text.clear(); textDest = newText; @@ -139,6 +151,8 @@ void Dialogue::SetDismissable(bool value) void Dialogue::WriteText(void) { + bool voicePlayed = false; + textTimer -= textSpeed; while (textTimer <= 0 && !textDest.empty()) @@ -146,7 +160,21 @@ void Dialogue::WriteText(void) char c = textDest.back(); text.push_back(c); - if (c == '.' || c == '!' || c == '?') + if (voicePlayed == false + && std::isprint(c) + && c != ' ') + { + if (syllable) + { + S_StopSoundByNum(voiceSfx); + S_StartSound(nullptr, voiceSfx); + } + + syllable = !syllable; + voicePlayed = true; + } + + if (c == '.' || c == ',' || c == ';' || c == '!' || c == '?') { // slow down for punctuation textTimer += kTextPunctPause; diff --git a/src/k_dialogue.hpp b/src/k_dialogue.hpp index 02289fc29..553d2827f 100644 --- a/src/k_dialogue.hpp +++ b/src/k_dialogue.hpp @@ -19,6 +19,7 @@ #include "doomdef.h" #include "doomtype.h" #include "typedef.h" +#include "sounds.h" #include "v_video.h" namespace srb2 @@ -33,6 +34,7 @@ private: std::string speaker; patch_t *portrait; UINT8 *portraitColormap; + sfxenum_t voiceSfx; std::string text; std::string textDest; @@ -43,6 +45,7 @@ private: fixed_t textTimer; fixed_t textSpeed; bool textDone; + bool syllable; bool dismissable; @@ -59,7 +62,7 @@ public: void SetSpeaker(void); void SetSpeaker(std::string skinName, int portraitID); - void SetSpeaker(std::string customName, std::string customPatch, UINT8 *customColormap); + void SetSpeaker(std::string name, patch_t *patch, UINT8 *colormap, sfxenum_t voice); void NewText(std::string newText); diff --git a/src/sounds.c b/src/sounds.c index 7e8560eb2..8b1ff2a84 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -1439,6 +1439,7 @@ sfxinfo_t S_sfx[NUMSFX] = {"kslow", false, 64, 32, -1, NULL, 0, SKSKSLOW, -1, LUMPERROR, ""}, {"khitem", false, 128, 32, -1, NULL, 0, SKSKHITM, -1, LUMPERROR, ""}, {"kgloat", false, 64, 48, -1, NULL, 0, SKSKPOWR, -1, LUMPERROR, ""}, + {"ktalk", false, 64, 48, -1, NULL, 0, SKSKTALK, -1, LUMPERROR, ""}, // skin sounds free slots to add sounds at run time (Boris HACK!!!) // initialized to NULL diff --git a/src/sounds.h b/src/sounds.h index 324066ac9..176dfc541 100644 --- a/src/sounds.h +++ b/src/sounds.h @@ -56,6 +56,7 @@ typedef enum SKSKSLOW, // Overtake taunt SKSKHITM, // Hit confirm taunt SKSKPOWR, // Power item taunt + SKSKTALK, NUMSKINSOUNDS } skinsound_t; @@ -1506,6 +1507,7 @@ typedef enum sfx_kslow, sfx_khitem, sfx_kgloat, + sfx_ktalk, // free slots for S_AddSoundFx() at run-time -------------------- sfx_freeslot0,