RingRacers/src/menus/extras-wrong.c
James R 39f46a0f20 Replace music handling
(This commit does not compile. Sound test and tunes
command code needs to be ported after this.)

This is a big one. Here's the rundown:

The old music system was very direct, much of the time
just a proxy to the real sound API in i_sound.h.

You could change the music on command, but there wasn't
a consistent way to prevent some music from playing over
others. P_RestoreMusic is one example of needing to
address this problem. The jingles system was intended as
another solution. Furthermore, sound test (Stereo) has its
own needs.

I am removing all of that. Music handling in general is
now a very deliberate system, kind of similar to jingles.

In the new system, "tunes" are registered. The tune stores
info such as whether it should loop or fade out. Most of
the configuration is intended to be initialized only ONCE.
Tunes can be mapped to an actual music lump. They can be
remapped at any time too.

Tunes are also configured with a priority number. This
determines which tune is heard, if multiple are supposed
to be playing at a time. You can even tell a tune how long
it should play, so it's unnecessary to track this with
bespoke timers.
2023-08-06 17:31:45 -07:00

155 lines
2.7 KiB
C

/// \file menus/extras-wrong.c
/// \brief Wrongwarp
#include "../k_menu.h"
#include "../s_sound.h"
#include "../m_random.h"
#include "../music.h"
#include "../r_skins.h"
struct wrongwarp_s wrongwarp;
static menuitem_t MISC_WrongWarpMenu[] =
{
{IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0},
};
void M_WrongWarp(INT32 choice)
{
(void)choice;
wrongwarp.ticker = 0;
M_SetupNextMenu(&MISC_WrongWarpDef, false);
// Done here to avoid immediate music credit
Music_Remap("menu_nocred", "YEAWAY");
Music_Play("menu_nocred");
}
static void M_WrongWarpTick(void)
{
static boolean firsteggman = true;
static boolean antitailgate = false;
UINT8 i, j;
wrongwarp.ticker++;
if (wrongwarp.ticker < 2*TICRATE)
return;
if (wrongwarp.ticker == 2*TICRATE)
{
S_ShowMusicCredit();
for (i = 0; i < MAXWRONGPLAYER; i++)
wrongwarp.wrongplayers[i].skin = MAXSKINS;
firsteggman = true;
}
// SMK title screen recreation!?
for (i = 0; i < MAXWRONGPLAYER; i++)
{
if (wrongwarp.wrongplayers[i].skin == MAXSKINS)
continue;
wrongwarp.wrongplayers[i].across += 5;
if (wrongwarp.wrongplayers[i].across < BASEVIDWIDTH + WRONGPLAYEROFFSCREEN)
continue;
wrongwarp.wrongplayers[i].skin = MAXSKINS;
}
if (wrongwarp.delaytowrongplayer)
{
wrongwarp.delaytowrongplayer--;
return;
}
wrongwarp.delaytowrongplayer = M_RandomRange(TICRATE/3, 2*TICRATE/3);
if (wrongwarp.ticker == 2*TICRATE)
return;
UINT32 rskin = 0;
if (firsteggman == true)
{
// Eggman always leads the pack. It's not Sonic's game anymore...
firsteggman = false;
i = 0;
wrongwarp.wrongplayers[i].spinout = false;
}
else
{
rskin = R_GetLocalRandomSkin();
for (i = 0; i < MAXWRONGPLAYER; i++)
{
// Already in use.
if (wrongwarp.wrongplayers[i].skin == rskin)
return;
// Prevent tailgating.
if (antitailgate == !!(i & 1))
continue;
// Slot isn't free.
if (wrongwarp.wrongplayers[i].skin != MAXSKINS)
continue;
break;
}
// No free slots.
if (i == MAXWRONGPLAYER)
return;
// Check to see if any later entry uses the skin too
for (j = i+1; j < MAXWRONGPLAYER; j++)
{
if (wrongwarp.wrongplayers[j].skin != rskin)
continue;
return;
}
wrongwarp.wrongplayers[i].spinout = M_RandomChance(FRACUNIT/11);
}
// Add the new character!
wrongwarp.wrongplayers[i].skin = rskin;
wrongwarp.wrongplayers[i].across = -WRONGPLAYEROFFSCREEN;
antitailgate = !!(i & 1);
}
static boolean M_WrongWarpInputs(INT32 ch)
{
(void)ch;
if (wrongwarp.ticker < TICRATE/2)
return true;
return false;
}
menu_t MISC_WrongWarpDef = {
sizeof (MISC_WrongWarpMenu)/sizeof (menuitem_t),
NULL,
0,
MISC_WrongWarpMenu,
0, 0,
0, 0,
MBF_SOUNDLESS,
".",
98, 0,
M_DrawWrongWarp,
M_WrongWarpTick,
NULL,
NULL,
M_WrongWarpInputs,
};