2020-01-01 21:29:24 +01:00
|
|
|
#include <SDL.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "Music.h"
|
|
|
|
#include "BinaryBlob.h"
|
2020-04-04 00:37:59 +02:00
|
|
|
#include "Map.h"
|
2020-01-01 21:29:24 +01:00
|
|
|
|
Allow using help/graphics/music/game/key/map/obj everywhere
This commit makes `help`, `graphics`, `music`, `game`, `key`, `map`, and
`obj` essentially static global objects that can be used everywhere.
This is useful in case we ever need to add a new function in the future,
so we don't have to bother with passing a new argument in which means we
have to pass a new argument in to the function that calls that function
which means having to pass a new argument into the function that calls
THAT function, etc. which is a real headache when working on fan mods of
the source code.
Note that this changes NONE of the existing function signatures, it
merely just makes those variables accessible everywhere in the same way
`script` and `ed` are.
Also note that some classes had to be initialized after the filesystem
was initialized, but C++ would keep initializing them before the
filesystem got initialized, because I *had* to put them at the top of
`main.cpp`, or else they wouldn't be global variables.
The only way to work around this was to use entityclass's initialization
style (which I'm pretty sure entityclass of all things doesn't need to
be initialized this way), where you actually initialize the class in an
`init()` function, and so then you do `graphics.init()` after the
filesystem initialization, AFTER doing `Graphics graphics` up at the
top.
I've had to do this for `graphics` (but only because its child
GraphicsResources `grphx` needs to be initialized this way), `music`,
and `game`. I don't think this will affect anything. Other than that,
`help`, `key`, and `map` are still using the C++-intended method of
having ClassName::ClassName() functions.
2020-01-29 08:35:03 +01:00
|
|
|
void musicclass::init()
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
2020-06-07 22:11:48 +02:00
|
|
|
for (size_t i = 0; i < soundTracks.size(); ++i) {
|
|
|
|
Mix_FreeChunk(soundTracks[i].sound);
|
|
|
|
}
|
2020-01-30 15:50:19 +01:00
|
|
|
soundTracks.clear();
|
2020-06-07 22:11:48 +02:00
|
|
|
for (size_t i = 0; i < musicTracks.size(); ++i) {
|
|
|
|
Mix_FreeMusic(musicTracks[i].m_music);
|
|
|
|
}
|
2020-01-30 15:50:19 +01:00
|
|
|
musicTracks.clear();
|
|
|
|
|
2020-06-07 22:11:35 +02:00
|
|
|
musicReadBlob.clear();
|
|
|
|
|
2020-06-07 21:49:18 +02:00
|
|
|
soundTracks.push_back(SoundTrack( "sounds/jump.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/jump2.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/hurt.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/souleyeminijingle.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/coin.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/save.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/crumble.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/vanish.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/blip.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/preteleport.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/teleport.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/crew1.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/crew2.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/crew3.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/crew4.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/crew5.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/crew6.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/terminal.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/gamesaved.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/crashing.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/blip2.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/countdown.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/go.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/crash.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/combine.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/newrecord.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/trophy.wav" ));
|
|
|
|
soundTracks.push_back(SoundTrack( "sounds/rescue.wav" ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
#ifdef VVV_COMPILEMUSIC
|
|
|
|
binaryBlob musicWriteBlob;
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/0levelcomplete.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/1pushingonwards.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/2positiveforce.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/3potentialforanything.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/4passionforexploring.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/5intermission.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/6presentingvvvvvv.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/7gamecomplete.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/8predestinedfate.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/9positiveforcereversed.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/10popularpotpourri.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/11pipedream.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/12pressurecooker.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/13pacedenergy.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/14piercingthesky.ogg");
|
|
|
|
musicWriteBlob.AddFileToBinaryBlob("data/music/predestinedfatefinallevel.ogg");
|
|
|
|
|
|
|
|
musicWriteBlob.writeBinaryBlob("data/BinaryMusic.vvv");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!musicReadBlob.unPackBinary("mmmmmm.vvv"))
|
|
|
|
{
|
|
|
|
mmmmmm = false;
|
|
|
|
usingmmmmmm=false;
|
|
|
|
bool ohCrap = musicReadBlob.unPackBinary("vvvvvvmusic.vvv");
|
|
|
|
SDL_assert(ohCrap && "Music not found!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mmmmmm = true;
|
|
|
|
usingmmmmmm = true;
|
|
|
|
int index = musicReadBlob.getIndex("data/music/0levelcomplete.ogg");
|
|
|
|
SDL_RWops *rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/1pushingonwards.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/2positiveforce.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/3potentialforanything.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/4passionforexploring.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/5intermission.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/6presentingvvvvvv.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/7gamecomplete.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/8predestinedfate.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/9positiveforcereversed.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/10popularpotpourri.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/11pipedream.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/12pressurecooker.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/13pacedenergy.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/14piercingthesky.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/predestinedfatefinallevel.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
bool ohCrap = musicReadBlob.unPackBinary("vvvvvvmusic.vvv");
|
|
|
|
SDL_assert(ohCrap && "Music not found!");
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = musicReadBlob.getIndex("data/music/0levelcomplete.ogg");
|
|
|
|
SDL_RWops *rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/1pushingonwards.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/2positiveforce.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/3potentialforanything.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/4passionforexploring.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/5intermission.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/6presentingvvvvvv.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/7gamecomplete.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/8predestinedfate.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/9positiveforcereversed.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/10popularpotpourri.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/11pipedream.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/12pressurecooker.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/13pacedenergy.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/14piercingthesky.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
index = musicReadBlob.getIndex("data/music/predestinedfatefinallevel.ogg");
|
|
|
|
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index));
|
2020-06-07 21:49:18 +02:00
|
|
|
musicTracks.push_back(MusicTrack( rw ));
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
safeToProcessMusic= false;
|
|
|
|
m_doFadeInVol = false;
|
|
|
|
musicVolume = 128;
|
|
|
|
FadeVolAmountPerFrame = 0;
|
|
|
|
|
|
|
|
custompd = false;
|
2020-01-11 01:37:23 +01:00
|
|
|
|
|
|
|
currentsong = 0;
|
|
|
|
musicfade = 0;
|
|
|
|
musicfadein = 0;
|
|
|
|
nicechange = 0;
|
|
|
|
nicefade = 0;
|
|
|
|
resumesong = 0;
|
|
|
|
volume = 0.0f;
|
2020-01-13 04:33:58 +01:00
|
|
|
fadeoutqueuesong = -1;
|
|
|
|
dontquickfade = false;
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void musicclass::play(int t)
|
|
|
|
{
|
2020-04-02 23:28:10 +02:00
|
|
|
t = (t % 16);
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
if(mmmmmm)
|
|
|
|
{
|
|
|
|
if(!usingmmmmmm)
|
|
|
|
{
|
|
|
|
t += 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
safeToProcessMusic = true;
|
|
|
|
Mix_VolumeMusic(128);
|
|
|
|
if (currentsong !=t)
|
|
|
|
{
|
|
|
|
if (t != -1)
|
|
|
|
{
|
|
|
|
currentsong = t;
|
2020-04-04 00:37:59 +02:00
|
|
|
if (currentsong == 0 || currentsong == 7 || (!map.custommode && (currentsong == 16 || currentsong == 23)))
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
|
|
|
// Level Complete theme, no fade in or repeat
|
|
|
|
if(Mix_FadeInMusic(musicTracks[t].m_music, 0, 0)==-1)
|
|
|
|
{
|
|
|
|
printf("Mix_PlayMusic: %s\n", Mix_GetError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-13 04:33:58 +01:00
|
|
|
if (Mix_FadingMusic() == MIX_FADING_OUT) {
|
|
|
|
// We're already fading out
|
|
|
|
fadeoutqueuesong = t;
|
|
|
|
currentsong = -1;
|
|
|
|
if (!dontquickfade)
|
|
|
|
Mix_FadeOutMusic(500); // fade out quicker
|
|
|
|
else
|
|
|
|
dontquickfade = false;
|
|
|
|
}
|
|
|
|
else if(Mix_FadeInMusic(musicTracks[t].m_music, -1, 3000)==-1)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
|
|
|
printf("Mix_FadeInMusic: %s\n", Mix_GetError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentsong = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void musicclass::haltdasmusik()
|
|
|
|
{
|
|
|
|
Mix_HaltMusic();
|
|
|
|
currentsong = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void musicclass::silencedasmusik()
|
|
|
|
{
|
|
|
|
Mix_VolumeMusic(0) ;
|
|
|
|
musicVolume = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void musicclass::fadeMusicVolumeIn(int ms)
|
|
|
|
{
|
|
|
|
m_doFadeInVol = true;
|
|
|
|
FadeVolAmountPerFrame = MIX_MAX_VOLUME / (ms / 33);
|
|
|
|
}
|
|
|
|
|
|
|
|
void musicclass::fadeout()
|
|
|
|
{
|
|
|
|
Mix_FadeOutMusic(2000);
|
|
|
|
currentsong = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void musicclass::processmusicfadein()
|
|
|
|
{
|
|
|
|
musicVolume += FadeVolAmountPerFrame;
|
|
|
|
Mix_VolumeMusic(musicVolume);
|
|
|
|
if (musicVolume >= MIX_MAX_VOLUME)
|
|
|
|
{
|
|
|
|
m_doFadeInVol = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void musicclass::processmusic()
|
|
|
|
{
|
|
|
|
if(!safeToProcessMusic)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-13 04:33:58 +01:00
|
|
|
if (fadeoutqueuesong != -1 && Mix_PlayingMusic() == 0) {
|
|
|
|
play(fadeoutqueuesong);
|
|
|
|
fadeoutqueuesong = -1;
|
|
|
|
}
|
|
|
|
|
2020-01-01 21:29:24 +01:00
|
|
|
if (nicefade == 1 && Mix_PlayingMusic() == 0)
|
|
|
|
{
|
|
|
|
play(nicechange);
|
|
|
|
nicechange = -1; nicefade = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_doFadeInVol)
|
|
|
|
{
|
|
|
|
processmusicfadein();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void musicclass::niceplay(int t)
|
|
|
|
{
|
|
|
|
// important: do nothing if the correct song is playing!
|
2020-02-12 22:00:54 +01:00
|
|
|
if((!mmmmmm && currentsong!=t) || (mmmmmm && usingmmmmmm && currentsong!=t) || (mmmmmm && !usingmmmmmm && currentsong!=t+16))
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
2020-01-23 01:26:29 +01:00
|
|
|
if(currentsong!=-1)
|
|
|
|
{
|
|
|
|
dontquickfade = true;
|
|
|
|
fadeout();
|
|
|
|
}
|
2020-01-01 21:29:24 +01:00
|
|
|
nicefade = 1;
|
|
|
|
nicechange = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void musicclass::changemusicarea(int x, int y)
|
|
|
|
{
|
|
|
|
switch(musicroom(x, y))
|
|
|
|
{
|
|
|
|
case musicroom(11, 4):
|
|
|
|
niceplay(2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case musicroom(2, 4):
|
|
|
|
case musicroom(7, 15):
|
|
|
|
niceplay(3);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case musicroom(18, 1):
|
|
|
|
case musicroom(15, 0):
|
|
|
|
niceplay(12);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case musicroom(0, 0):
|
|
|
|
case musicroom(0, 16):
|
|
|
|
case musicroom(2, 11):
|
|
|
|
case musicroom(7, 9):
|
|
|
|
case musicroom(8, 11):
|
|
|
|
case musicroom(13, 2):
|
|
|
|
case musicroom(17, 12):
|
|
|
|
case musicroom(14, 19):
|
|
|
|
case musicroom(17, 17):
|
|
|
|
niceplay(4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
niceplay(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-02 01:36:35 +02:00
|
|
|
void musicclass::playef(int t)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
Add bounds checks to script commands that didn't have them
Continuing from #280, another potential source of out-of-bounds indexing
(and thus, Undefined Behavior badness) comes from script commands. A
majority of them don't do any input validation at all, which means the
potential for out-of-bounds indexing and segfaulting in custom levels.
So it's always good to add bounds checks to them.
Interesting note, the only existing command that has bounds checks is
the flag() command. That means you can't turn out-of-bounds flags on or
off. But there's no bounds checks for ifflag(), or customifflag(), which
means you CAN index out-of-bounds with those commands! That's a bit bad
to do, so.
Also, I decided to add the bounds checks for playef() at the
musicclass::playef() level, instead of just the level of the playef()
command. I don't know of any other cases outside of the command where
musicclass::playef() will index out of bounds, but musicclass is the one
containing the indexed vector anyway, I wanted to cover more cases, and
it's better to be safe than sorry.
2020-06-13 06:55:41 +02:00
|
|
|
if (t < 0 || t >= (int) soundTracks.size())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-01-01 21:29:24 +01:00
|
|
|
int channel;
|
|
|
|
|
|
|
|
channel = Mix_PlayChannel(-1, soundTracks[t].sound, 0);
|
|
|
|
if(channel == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unable to play WAV file: %s\n", Mix_GetError());
|
|
|
|
}
|
|
|
|
}
|