mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 10:09:43 +01:00
Added custom sound effect functionality to playef()
This commit is contained in:
parent
2ac85e6929
commit
b0eb97fa53
3 changed files with 50 additions and 1 deletions
|
@ -121,6 +121,7 @@ public:
|
||||||
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
|
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
|
||||||
format.cbSize = 0;
|
format.cbSize = 0;
|
||||||
valid = true;
|
valid = true;
|
||||||
|
name = std::string(SDL_strrchr(fileName, '/') + 1);
|
||||||
end:
|
end:
|
||||||
VVV_free(mem);
|
VVV_free(mem);
|
||||||
}
|
}
|
||||||
|
@ -244,6 +245,8 @@ end:
|
||||||
|
|
||||||
static FAudioSourceVoice** voices;
|
static FAudioSourceVoice** voices;
|
||||||
static float volume;
|
static float volume;
|
||||||
|
|
||||||
|
std::string name;
|
||||||
};
|
};
|
||||||
FAudioSourceVoice** SoundTrack::voices = NULL;
|
FAudioSourceVoice** SoundTrack::voices = NULL;
|
||||||
float SoundTrack::volume = 0.0f;
|
float SoundTrack::volume = 0.0f;
|
||||||
|
@ -657,6 +660,29 @@ void musicclass::init(void)
|
||||||
soundTracks.push_back(SoundTrack( "sounds/trophy.wav" ));
|
soundTracks.push_back(SoundTrack( "sounds/trophy.wav" ));
|
||||||
soundTracks.push_back(SoundTrack( "sounds/rescue.wav" ));
|
soundTracks.push_back(SoundTrack( "sounds/rescue.wav" ));
|
||||||
|
|
||||||
|
//Here's where we find all the custom sounds in a level's assets folder
|
||||||
|
EnumHandle handle = {};
|
||||||
|
const char* item;
|
||||||
|
while ((item = FILESYSTEM_enumerateAssets("sounds/", &handle)) != NULL)
|
||||||
|
{
|
||||||
|
const std::string str_item = item;
|
||||||
|
bool match;
|
||||||
|
for (int j = 0; j < soundTracks.size(); j++)
|
||||||
|
{
|
||||||
|
match = (str_item == soundTracks[j].name);
|
||||||
|
if (match)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!match)
|
||||||
|
{
|
||||||
|
soundTracks.push_back(SoundTrack( ("sounds/" + str_item).c_str() ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FILESYSTEM_freeEnumerate(&handle);
|
||||||
|
|
||||||
|
|
||||||
#ifdef VVV_COMPILEMUSIC
|
#ifdef VVV_COMPILEMUSIC
|
||||||
binaryBlob musicWriteBlob;
|
binaryBlob musicWriteBlob;
|
||||||
#define FOREACH_TRACK(blob, track_name) blob.AddFileToBinaryBlob("data/" track_name);
|
#define FOREACH_TRACK(blob, track_name) blob.AddFileToBinaryBlob("data/" track_name);
|
||||||
|
@ -1144,6 +1170,20 @@ void musicclass::playef(int t)
|
||||||
soundTracks[t].Play();
|
soundTracks[t].Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void musicclass::playef_name(std::string& t)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < soundTracks.size(); i++)
|
||||||
|
{
|
||||||
|
size_t lastindex = soundTracks[i].name.find_last_of('.');
|
||||||
|
std::string rawname = soundTracks[i].name.substr(0, lastindex);
|
||||||
|
if (t == rawname)
|
||||||
|
{
|
||||||
|
soundTracks[i].Play();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void musicclass::pauseef(void)
|
void musicclass::pauseef(void)
|
||||||
{
|
{
|
||||||
SoundTrack::Pause();
|
SoundTrack::Pause();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define MUSIC_H
|
#define MUSIC_H
|
||||||
|
|
||||||
#include "BinaryBlob.h"
|
#include "BinaryBlob.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#define musicroom(rx, ry) ((rx) + ((ry) * 20))
|
#define musicroom(rx, ry) ((rx) + ((ry) * 20))
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ public:
|
||||||
int currentsong;
|
int currentsong;
|
||||||
|
|
||||||
void playef(int t);
|
void playef(int t);
|
||||||
|
void playef_name(std::string& t);
|
||||||
void pauseef(void);
|
void pauseef(void);
|
||||||
void resumeef(void);
|
void resumeef(void);
|
||||||
|
|
||||||
|
|
|
@ -355,7 +355,14 @@ void scriptclass::run(void)
|
||||||
}
|
}
|
||||||
if (words[0] == "playef")
|
if (words[0] == "playef")
|
||||||
{
|
{
|
||||||
music.playef(ss_toi(words[1]));
|
if (words[1] != "0" && ss_toi(words[1]) == 0)
|
||||||
|
{
|
||||||
|
music.playef_name(raw_words[1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
music.playef(ss_toi(words[1]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (words[0] == "play")
|
if (words[0] == "play")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue