mirror of
https://github.com/fabiangreffrath/woof.git
synced 2025-09-29 08:04:21 -04:00
TRAKINFO: don't exit if lump is not found, refactoring (#2239)
This commit is contained in:
parent
6db48e1506
commit
742e091534
@ -718,16 +718,9 @@ void S_ChangeMusic(int musicnum, int looping)
|
||||
|
||||
// load & register it
|
||||
music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC);
|
||||
if (extra_music && trakinfo_found)
|
||||
if (extra_music)
|
||||
{
|
||||
const char *extra =
|
||||
S_GetExtra(music->data, W_LumpLength(music->lumpnum), extra_music);
|
||||
if (extra)
|
||||
{
|
||||
music->lumpnum = W_GetNumForName(extra);
|
||||
Z_Free(music->data);
|
||||
music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC);
|
||||
}
|
||||
S_GetExtra(music, extra_music);
|
||||
}
|
||||
// julian: added lump length
|
||||
music->handle = I_RegisterSong(music->data, W_LumpLength(music->lumpnum));
|
||||
@ -782,16 +775,9 @@ void S_ChangeMusInfoMusic(int lumpnum, int looping)
|
||||
music->lumpnum = lumpnum;
|
||||
|
||||
music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC);
|
||||
if (extra_music && trakinfo_found)
|
||||
if (extra_music)
|
||||
{
|
||||
const char *extra =
|
||||
S_GetExtra(music->data, W_LumpLength(music->lumpnum), extra_music);
|
||||
if (extra)
|
||||
{
|
||||
music->lumpnum = W_GetNumForName(extra);
|
||||
Z_Free(music->data);
|
||||
music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC);
|
||||
}
|
||||
S_GetExtra(music, extra_music);
|
||||
}
|
||||
music->handle = I_RegisterSong(music->data, W_LumpLength(music->lumpnum));
|
||||
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include "m_json.h"
|
||||
#include "m_misc.h"
|
||||
#include "sha1.h"
|
||||
#include "sounds.h"
|
||||
#include "w_wad.h"
|
||||
|
||||
boolean trakinfo_found;
|
||||
|
||||
@ -70,15 +72,21 @@ void S_ParseTrakInfo(int lumpnum)
|
||||
trakinfo_found = true;
|
||||
}
|
||||
|
||||
const char *S_GetExtra(byte *data, int length, extra_music_t type)
|
||||
void S_GetExtra(musicinfo_t *music, extra_music_t type)
|
||||
{
|
||||
if (!trakinfo_found)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sha1_context_t sha1_context;
|
||||
sha1_digest_t digest;
|
||||
|
||||
SHA1_Init(&sha1_context);
|
||||
SHA1_Update(&sha1_context, data, length);
|
||||
SHA1_Update(&sha1_context, music->data, W_LumpLength(music->lumpnum));
|
||||
SHA1_Final(digest, &sha1_context);
|
||||
|
||||
const char *extra = NULL;
|
||||
trakinfo_t *trak;
|
||||
array_foreach(trak, trakinfo)
|
||||
{
|
||||
@ -86,13 +94,28 @@ const char *S_GetExtra(byte *data, int length, extra_music_t type)
|
||||
{
|
||||
if (type == EXMUS_REMIX)
|
||||
{
|
||||
return trak->remix;
|
||||
extra = trak->remix;
|
||||
}
|
||||
else
|
||||
{
|
||||
return trak->midi;
|
||||
extra = trak->midi;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
if (!extra)
|
||||
{
|
||||
I_Printf(VB_DEBUG, "TRAKINFO: extra track is not found");
|
||||
return;
|
||||
}
|
||||
|
||||
int lumpnum = W_GetNumForName(extra);
|
||||
if (lumpnum < 0)
|
||||
{
|
||||
I_Printf(VB_ERROR, "TRAKINFO: lump '%s' is not found", extra);
|
||||
return;
|
||||
}
|
||||
music->lumpnum = lumpnum;
|
||||
Z_Free(music->data);
|
||||
music->data = W_CacheLumpNum(music->lumpnum, PU_STATIC);
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ typedef enum
|
||||
EXMUS_ORIGINAL
|
||||
} extra_music_t;
|
||||
|
||||
const char *S_GetExtra(byte *data, int length, extra_music_t type);
|
||||
struct musicinfo_s;
|
||||
|
||||
void S_GetExtra(struct musicinfo_s *music, extra_music_t type);
|
||||
|
||||
#endif
|
||||
|
@ -81,7 +81,8 @@ typedef struct sfxinfo_s
|
||||
// MusicInfo struct.
|
||||
//
|
||||
|
||||
typedef struct {
|
||||
typedef struct musicinfo_s
|
||||
{
|
||||
// up to 6-character name
|
||||
char *name;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user