check the status of music records in DEH to support replacing the same string (#1127)

For example PL2.wad. We don't have support for BEX music blocks and I'm not sure
if it's needed (no PWAD with it in the wild?).
This commit is contained in:
Roman Fomin 2023-07-04 15:51:38 +07:00 committed by GitHub
parent f721de4e06
commit e3201c1b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 15 deletions

View File

@ -2837,21 +2837,15 @@ void deh_procText(DEHFILE *fpin, FILE* fpout, char *line)
}
if (!found) // not yet
{
// Try music name entries - see sounds.c
for (i=1; i<NUMMUSIC; i++)
i = dsdh_GetDehMusicIndex(inbuffer, fromlen);
if (i >= 0)
{
// avoid short prefix erroneous match
if (strlen(S_music[i].name) != fromlen) continue;
if (!strncasecmp(S_music[i].name,inbuffer,fromlen))
{
if (fpout) fprintf(fpout,
"Changing name of music from %s to %*s\n",
S_music[i].name,usedlen,&inbuffer[fromlen]);
if (fpout) fprintf(fpout,
"Changing name of music from %s to %*s\n",
S_music[i].name,usedlen,&inbuffer[fromlen]);
S_music[i].name = strdup(&inbuffer[fromlen]);
found = true;
break; // only one matches, quit early
}
S_music[i].name = strdup(&inbuffer[fromlen]);
found = true;
}
} // end !found test
}

View File

@ -324,6 +324,46 @@ int dsdh_GetOriginalSFXIndex(const char* key)
return i;
}
//
// Music
//
musicinfo_t *S_music;
int num_music;
static byte *music_state;
static void InitMusic(void)
{
S_music = original_S_music;
num_music = NUMMUSIC;
music_state = calloc(num_music, sizeof(*music_state));
}
int dsdh_GetDehMusicIndex(const char* key, int length)
{
int i;
for (i = 1; i < num_music; ++i)
{
if (S_music[i].name &&
strlen(S_music[i].name) == length &&
!strncasecmp(S_music[i].name, key, length) &&
!music_state[i])
{
music_state[i] = true; // music has been edited
return i;
}
}
return -1;
}
static void FreeMusic(void)
{
free(music_state);
}
//
// Things
//
@ -380,6 +420,7 @@ void dsdh_InitTables(void)
InitStates();
InitSprites();
InitSFX();
InitMusic();
InitMobjInfo();
}
@ -388,4 +429,5 @@ void dsdh_FreeTables(void)
FreeStates();
FreeSprites();
FreeSFX();
FreeMusic();
}

View File

@ -26,6 +26,7 @@ void dsdh_EnsureMobjInfoCapacity(int limit);
int dsdh_GetDehSpriteIndex(const char* key);
int dsdh_GetOriginalSpriteIndex(const char* key);
int dsdh_GetDehSFXIndex(const char* key, size_t length);
int dsdh_GetDehMusicIndex(const char* key, int length);
int dsdh_GetOriginalSFXIndex(const char* key);
#endif

View File

@ -28,7 +28,7 @@
// Information about all the music
//
musicinfo_t S_music[] = {
musicinfo_t original_S_music[] = {
{ 0 },
{ "e1m1", 0 },
{ "e1m2", 0 },

View File

@ -86,7 +86,7 @@ typedef struct {
extern sfxinfo_t original_S_sfx[];
// the complete set of music
extern musicinfo_t S_music[];
extern musicinfo_t original_S_music[];
//
// Identifiers for all music in game.
@ -174,6 +174,10 @@ typedef enum {
mus_musinfo
} musicenum_t;
// DSDHacked
extern musicinfo_t *S_music;
extern int num_music;
//
// Identifiers for all sfx in game.
//