Skip to content

Commit

Permalink
Add MUSINFO support
Browse files Browse the repository at this point in the history
Based on prboom-plus support.
However, unlike prboom-plus this will also support the music files
configured in prboom.cfg, if configured to do so.

Another difference is that the doom id 14165 is used for changing the
music to the default level track. Which is what ZDoom does.
See: https://zdoom.org/wiki/Classes:MusicChanger

Also, support for 14100 was added too since crispy/doom retro do that.
See: https://zdoom.org/wiki/MUSINFO
  • Loading branch information
Ferk committed Oct 12, 2019
1 parent 7fb1058 commit 3a332d9
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 69 deletions.
3 changes: 2 additions & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ SOURCES_C += $(CORE_DIR)/am_map.c \
$(CORE_DIR)/flplayer.c \
$(CORE_DIR)/midifile.c \
$(CORE_DIR)/madplayer.c \
$(CORE_DIR)/u_mapinfo.c \
$(CORE_DIR)/u_scanner.c \
$(CORE_DIR)/u_mapinfo.c \
$(CORE_DIR)/u_musinfo.c \


ifeq ($(WANT_FLUIDSYNTH), 1)
Expand Down
32 changes: 32 additions & 0 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -5526,4 +5526,36 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = {
0, // maxattackrange
200, // minmissilechance
},

// Will change music according to MUSINFO lump
{ // MT_MUSICCHANGER
"MusicChanger", // actorname
14165, // doomednum // 14100-14164 should also be reserved
S_TNT1, // spawnstate
1000, // spawnhealth
S_NULL, // seestate
sfx_None, // seesound
8, // reactiontime
sfx_None, // attacksound
S_NULL, // painstate
0, // painchance
sfx_None, // painsound
S_NULL, // meleestate
S_NULL, // missilestate
S_NULL, // deathstate
S_NULL, // xdeathstate
sfx_None, // deathsound
MT_NULL, // droppeditem
0, // speed
16, // radius
16, // height
100, // mass
0, // damage
sfx_None, // activesound
MF_NOBLOCKMAP, // flags
S_NULL, // raisestate
0, // meleethreshold
0, // maxattackrange
200, // minmissilechance
},
};
2 changes: 2 additions & 0 deletions src/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,8 @@ typedef enum {
MT_PUSH, /* controls push source - phares */
MT_PULL, /* controls pull source - phares 3/20/98 */

MT_MUSICCHANGER, /* MUSINFO Music Changer thing */

/* proff 11/22/98: Andy Baker's stealth monsters (next 12)
* cph - moved below the MBF stuff, no need to displace them */
MT_STEALTHBABY,
Expand Down
148 changes: 83 additions & 65 deletions src/p_mobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "p_inter.h"
#include "lprintf.h"
#include "r_demo.h"
#include "u_musinfo.h"

//
// P_SetMobjState
Expand Down Expand Up @@ -729,55 +730,60 @@ void P_MobjThinker (mobj_t* mobj)
// removed old code which looked at target references
// (we use pointer reference counting now)

if (mobj->type == MT_MUSICCHANGER)
{
P_MusInfoMobjThinker(mobj);
return;
}

mobj->PrevX = mobj->x;
mobj->PrevY = mobj->y;
mobj->PrevZ = mobj->z;

// momentum movement
if (mobj->momx | mobj->momy || mobj->flags & MF_SKULLFLY)
{
P_XYMovement(mobj);
if (mobj->thinker.function != P_MobjThinker) // cph - Must've been removed
return; // killough - mobj was removed
}
{
P_XYMovement(mobj);
if (mobj->thinker.function != P_MobjThinker) // cph - Must've been removed
return; // killough - mobj was removed
}

if (mobj->z != mobj->floorz || mobj->momz)
{
P_ZMovement(mobj);
if (mobj->thinker.function != P_MobjThinker) // cph - Must've been removed
return; // killough - mobj was removed
}
else
if (!(mobj->momx | mobj->momy) && !sentient(mobj))
{ // non-sentient objects at rest
mobj->intflags |= MIF_ARMED; // arm a mine which has come to rest
{
P_ZMovement(mobj);
if (mobj->thinker.function != P_MobjThinker) // cph - Must've been removed
return; // killough - mobj was removed
}
else if (!(mobj->momx | mobj->momy) && !sentient(mobj))
{ // non-sentient objects at rest
mobj->intflags |= MIF_ARMED; // arm a mine which has come to rest

// killough 9/12/98: objects fall off ledges if they are hanging off
// slightly push off of ledge if hanging more than halfway off
// killough 9/12/98: objects fall off ledges if they are hanging off
// slightly push off of ledge if hanging more than halfway off

if (mobj->z > mobj->dropoffz && // Only objects contacting dropoff
!(mobj->flags & MF_NOGRAVITY) && // Only objects which fall
!comp[comp_falloff]) // Not in old demos
P_ApplyTorque(mobj); // Apply torque
else
mobj->intflags &= ~MIF_FALLING, mobj->gear = 0; // Reset torque
}
if (mobj->z > mobj->dropoffz && // Only objects contacting dropoff
!(mobj->flags & MF_NOGRAVITY) && // Only objects which fall
!comp[comp_falloff]) // Not in old demos
P_ApplyTorque(mobj); // Apply torque
else
mobj->intflags &= ~MIF_FALLING, mobj->gear = 0; // Reset torque
}

// cycle through states,
// calling action functions at transitions

if (mobj->tics != -1)
{
{
mobj->tics--;

// you can cycle through multiple states in a tic

if (!mobj->tics)
if (!P_SetMobjState (mobj, mobj->state->nextstate) )
return; // freed itself
}
}
else
{
{

// check for nightmare respawn

Expand All @@ -799,7 +805,7 @@ void P_MobjThinker (mobj_t* mobj)
return;

P_NightmareRespawn (mobj);
}
}

}

Expand Down Expand Up @@ -1156,19 +1162,21 @@ void P_SpawnMapThing (const mapthing_t* mthing)
fixed_t y;
fixed_t z;
int options = mthing->options; /* cph 2001/07/07 - make writable copy */
short thingtype = mthing->type;
int iden_num = 0;

// killough 2/26/98: Ignore type-0 things as NOPs
// phares 5/14/98: Ignore Player 5-8 starts (for now)

switch(mthing->type)
{
case 0:
case DEN_PLAYER5:
case DEN_PLAYER6:
case DEN_PLAYER7:
case DEN_PLAYER8:
return;
}
switch(thingtype)
{
case 0:
case DEN_PLAYER5:
case DEN_PLAYER6:
case DEN_PLAYER7:
case DEN_PLAYER8:
return;
}

// killough 11/98: clear flags unused by Doom
//
Expand All @@ -1183,54 +1191,54 @@ void P_SpawnMapThing (const mapthing_t* mthing)
options & MTF_RESERVED)) {
if (!demo_compatibility) // cph - Add warning about bad thing flags
lprintf(LO_WARN, "P_SpawnMapThing: correcting bad flags (%u) (thing type %d)\n",
options, mthing->type);
options, thingtype);
options &= MTF_EASY|MTF_NORMAL|MTF_HARD|MTF_AMBUSH|MTF_NOTSINGLE;
}

// count deathmatch start positions

// doom2.exe has at most 10 deathmatch starts
if (mthing->type == 11)
{
if (thingtype == 11)
{
if (!(!compatibility || deathmatch_p-deathmatchstarts < 10)) {
return;
} else {
// 1/11/98 killough -- new code removes limit on deathmatch starts:
return;
} else {
// 1/11/98 killough -- new code removes limit on deathmatch starts:

size_t offset = deathmatch_p - deathmatchstarts;
size_t offset = deathmatch_p - deathmatchstarts;

if (offset >= num_deathmatchstarts)
if (offset >= num_deathmatchstarts)
{
num_deathmatchstarts = num_deathmatchstarts ?
num_deathmatchstarts = num_deathmatchstarts ?
num_deathmatchstarts*2 : 16;
deathmatchstarts = realloc(deathmatchstarts,
deathmatchstarts = realloc(deathmatchstarts,
num_deathmatchstarts *
sizeof(*deathmatchstarts));
deathmatch_p = deathmatchstarts + offset;
deathmatch_p = deathmatchstarts + offset;
}
memcpy(deathmatch_p++, mthing, sizeof(*mthing));
(deathmatch_p-1)->options = 1;
return;
}
memcpy(deathmatch_p++, mthing, sizeof(*mthing));
(deathmatch_p-1)->options = 1;
return;
}
}

// check for players specially

if (mthing->type <= 4 && mthing->type > 0) // killough 2/26/98 -- fix crashes
{
if (thingtype <= 4 && thingtype > 0) // killough 2/26/98 -- fix crashes
{

// save spots for respawning in coop games
playerstarts[mthing->type-1] = *mthing;
playerstarts[thingtype-1] = *mthing;
/* cph 2006/07/24 - use the otherwise-unused options field to flag that
* this start is present (so we know which elements of the array are filled
* in, in effect). Also note that the call below to P_SpawnPlayer must use
* the playerstarts version with this field set */
playerstarts[mthing->type-1].options = 1;
playerstarts[thingtype-1].options = 1;

if (!deathmatch)
P_SpawnPlayer (mthing->type-1, &playerstarts[mthing->type-1]);
P_SpawnPlayer (thingtype-1, &playerstarts[thingtype-1]);
return;
}
}

// check for apropriate skill level

Expand All @@ -1257,18 +1265,27 @@ void P_SpawnMapThing (const mapthing_t* mthing)

// find which type to spawn

// killough 8/23/98: use table for faster lookup
i = P_FindDoomedNum(mthing->type);
// Thing types from 14100 to 14164 are used for MUSINFO entities
// this means they are actually the same MusicChanger thingtype but
// each different type should have a different ambient music id.
// -- See https://doomwiki.org/wiki/MUSINFO --
if (thingtype >= 14100 && thingtype <= 14164)
{
iden_num = thingtype - 14100; // Ambient music to change
i = MT_MUSICCHANGER;
}
else // killough 8/23/98: use table for faster lookup
i = P_FindDoomedNum(thingtype);

// phares 5/16/98:
// Do not abort because of an unknown thing. Ignore it, but post a
// warning message for the player.

if (i == NUMMOBJTYPES)
{
{
doom_printf("Unknown Thing type %i at (%i, %i)",mthing->type,mthing->x,mthing->y);
return;
}
}

// don't spawn keycards and players in deathmatch

Expand All @@ -1292,17 +1309,18 @@ void P_SpawnMapThing (const mapthing_t* mthing)

mobj = P_SpawnMobj (x,y,z, i);
mobj->spawnpoint = *mthing;
mobj->iden_num = iden_num;

if (mobj->tics > 0)
mobj->tics = 1 + (P_Random (pr_spawnthing) % mobj->tics);

if (!(mobj->flags & MF_FRIEND) &&
options & MTF_FRIEND &&
mbf_features)
{
mobj->flags |= MF_FRIEND; // killough 10/98:
P_UpdateThinker(&mobj->thinker); // transfer friendliness flag
}
{
mobj->flags |= MF_FRIEND; // killough 10/98:
P_UpdateThinker(&mobj->thinker); // transfer friendliness flag
}

/* killough 7/20/98: exclude friends */
if (!((mobj->flags ^ MF_COUNTKILL) & (MF_FRIEND | MF_COUNTKILL)))
Expand Down
5 changes: 4 additions & 1 deletion src/p_mobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ typedef struct mobj_s

int tics; // state tic counter
state_t* state;
uint64_t flags;
uint64_t flags;
int intflags; // killough 9/15/98: internal flags
int health;

Expand Down Expand Up @@ -380,6 +380,9 @@ typedef struct mobj_s
fixed_t PrevY;
fixed_t PrevZ;

// Extra id based on thing type that's used in MUSINFO
short iden_num;

fixed_t pad; // cph - needed so I can get the size unambiguously on amd64

// SEE WARNING ABOVE ABOUT POINTER FIELDS!!!
Expand Down
4 changes: 4 additions & 0 deletions src/p_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "v_video.h"
#include "r_demo.h"
#include "r_fps.h"
#include "u_musinfo.h"

//
// MAP related Lookup tables.
Expand Down Expand Up @@ -1880,6 +1881,9 @@ void P_SetupLevel(int episode, int map, int playermask, skill_t skill)
if (gamemode==commercial)
P_SpawnBrainTargets();

// load MUSINFO from the map, if it exists
U_ParseMusInfo(lumpname);

// clear special respawning que
iquehead = iquetail = 0;

Expand Down
4 changes: 4 additions & 0 deletions src/p_tick.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "p_tick.h"
#include "p_map.h"
#include "r_fps.h"
#include "u_musinfo.h"

int leveltime;

Expand Down Expand Up @@ -261,6 +262,9 @@ static void P_RunThinkers (void)
currentthinker->function(currentthinker);
}
newthinkerpresent = FALSE;

// Dedicated thinkers
P_MapMusicThinker();
}

/*
Expand Down
1 change: 0 additions & 1 deletion src/s_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ int S_AdjustSoundParams(mobj_t *listener, mobj_t *source,
int *vol, int *sep, int *pitch);

static int S_getChannel(void *origin, sfxinfo_t *sfxinfo, int is_pickup);
static void S_ChangeMusicByName(char* lumpname, int looping);

// Initializes sound stuff, including volume
// Sets channels, SFX and music volume,
Expand Down
1 change: 1 addition & 0 deletions src/s_sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void S_StartMusic(int music_id);

// Start music using <music_id> from sounds.h, and set whether looping
void S_ChangeMusic(int music_id, int looping);
void S_ChangeMusicByName(char* lumpname, int looping);

// Stops the music fer sure.
void S_StopMusic(void);
Expand Down
Loading

0 comments on commit 3a332d9

Please sign in to comment.