Big net::msg conversion
This commit is contained in:
+43
-43
@@ -35,11 +35,11 @@
|
||||
#define CDRIPTYPE(x) (((x) & CDRIP_TYPES) != 0)
|
||||
|
||||
namespace music {
|
||||
bool bgmloop;
|
||||
convar bgm_extmusic{"bgm_extmusic", "1", {.archive = true}};
|
||||
bool looping;
|
||||
convar extmusic{"bgm_extmusic", "1", {.archive = true}};
|
||||
|
||||
namespace {
|
||||
snd_stream_t *bgmstream = nullptr;
|
||||
snd_stream_t *stream = nullptr;
|
||||
bool no_extmusic = false;
|
||||
float old_volume = -1.0f;
|
||||
|
||||
@@ -125,17 +125,17 @@ namespace music {
|
||||
if (command::argc() == 2) {
|
||||
if (q_strcasecmp(command::argv(1)->c_str(), "0") == 0 ||
|
||||
q_strcasecmp(command::argv(1)->c_str(), "off") == 0)
|
||||
bgmloop = false;
|
||||
looping = false;
|
||||
else if (q_strcasecmp(command::argv(1)->c_str(), "1") == 0 ||
|
||||
q_strcasecmp(command::argv(1)->c_str(), "on") == 0)
|
||||
bgmloop = true;
|
||||
looping = true;
|
||||
else if (q_strcasecmp(command::argv(1)->c_str(), "toggle") == 0)
|
||||
bgmloop = !bgmloop;
|
||||
looping = !looping;
|
||||
|
||||
if (bgmstream) bgmstream->loop = bgmloop;
|
||||
if (stream) stream->loop = looping;
|
||||
}
|
||||
|
||||
if (bgmloop)
|
||||
if (looping)
|
||||
console::info("Music will be looped\n");
|
||||
else
|
||||
console::info("Music will not be looped\n");
|
||||
@@ -148,8 +148,8 @@ namespace music {
|
||||
void _jump() {
|
||||
if (command::argc() != 2) {
|
||||
console::info("music_jump <ordernum>\n");
|
||||
} else if (bgmstream) {
|
||||
S_CodecJumpToOrder(bgmstream, static_cast<int>(std::strtol(command::argv(1)->c_str(), nullptr, 10)));
|
||||
} else if (stream) {
|
||||
S_CodecJumpToOrder(stream, static_cast<int>(std::strtol(command::argv(1)->c_str(), nullptr, 10)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,8 +170,8 @@ namespace music {
|
||||
/* not supported in quake */
|
||||
break;
|
||||
case player_kind::streamer:
|
||||
bgmstream = S_CodecOpenStreamType(tmp, handler.type, bgmloop);
|
||||
if (bgmstream)
|
||||
stream = S_CodecOpenStreamType(tmp, handler.type, looping);
|
||||
if (stream)
|
||||
return; /* success */
|
||||
break;
|
||||
case player_kind::none:
|
||||
@@ -191,7 +191,7 @@ namespace music {
|
||||
int fileBytes;
|
||||
byte raw[16384];
|
||||
|
||||
if (bgmstream->status != STREAM_PLAY) {
|
||||
if (stream->status != STREAM_PLAY) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -209,42 +209,42 @@ namespace music {
|
||||
bufferSamples = MAX_RAW_SAMPLES - (s_rawend - paintedtime);
|
||||
|
||||
/* decide how much data needs to be read from the file */
|
||||
fileSamples = bufferSamples * bgmstream->info.rate / shm->speed;
|
||||
fileSamples = bufferSamples * stream->info.rate / shm->speed;
|
||||
if (!fileSamples)
|
||||
return;
|
||||
|
||||
/* our max buffer size */
|
||||
fileBytes = fileSamples * (bgmstream->info.width * bgmstream->info.channels);
|
||||
fileBytes = fileSamples * (stream->info.width * stream->info.channels);
|
||||
if (fileBytes > (int) sizeof(raw)) {
|
||||
fileBytes = (int) sizeof(raw);
|
||||
fileSamples = fileBytes /
|
||||
(bgmstream->info.width * bgmstream->info.channels);
|
||||
(stream->info.width * stream->info.channels);
|
||||
}
|
||||
|
||||
/* Read */
|
||||
res = S_CodecReadStream(bgmstream, fileBytes, raw);
|
||||
res = S_CodecReadStream(stream, fileBytes, raw);
|
||||
if (res < fileBytes) {
|
||||
fileBytes = res;
|
||||
fileSamples = res / (bgmstream->info.width * bgmstream->info.channels);
|
||||
fileSamples = res / (stream->info.width * stream->info.channels);
|
||||
}
|
||||
|
||||
if (res > 0) /* data: add to raw buffer */
|
||||
{
|
||||
S_RawSamples(fileSamples, bgmstream->info.rate,
|
||||
bgmstream->info.width,
|
||||
bgmstream->info.channels,
|
||||
S_RawSamples(fileSamples, stream->info.rate,
|
||||
stream->info.width,
|
||||
stream->info.channels,
|
||||
raw, bgmvolume.value);
|
||||
did_rewind = false;
|
||||
} else if (res == 0) /* EOF */
|
||||
{
|
||||
if (bgmloop) {
|
||||
if (looping) {
|
||||
if (did_rewind) {
|
||||
console::info("Stream keeps returning EOF.\n");
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
|
||||
res = S_CodecRewindStream(bgmstream);
|
||||
res = S_CodecRewindStream(stream);
|
||||
if (res != 0) {
|
||||
console::info("Stream seek error (%i), stopping.\n", res);
|
||||
stop();
|
||||
@@ -266,7 +266,7 @@ namespace music {
|
||||
}
|
||||
|
||||
void init() {
|
||||
bgm_extmusic.inscribe();
|
||||
extmusic.inscribe();
|
||||
command::add("music", _play);
|
||||
command::add("music_pause", _pause);
|
||||
command::add("music_resume", _resume);
|
||||
@@ -277,7 +277,7 @@ namespace music {
|
||||
if (common::check_param("-noextmusic").has_value())
|
||||
no_extmusic = true;
|
||||
|
||||
bgmloop = true;
|
||||
looping = true;
|
||||
|
||||
for (auto i = 0; wanted_handlers[i].type != CODECTYPE_NONE; i++) {
|
||||
switch (wanted_handlers[i].player) {
|
||||
@@ -341,8 +341,8 @@ namespace music {
|
||||
/* not supported in quake */
|
||||
break;
|
||||
case player_kind::streamer:
|
||||
bgmstream = S_CodecOpenStreamType(tmp, chosen->type, bgmloop);
|
||||
if (bgmstream)
|
||||
stream = S_CodecOpenStreamType(tmp, chosen->type, looping);
|
||||
if (stream)
|
||||
return; /* success */
|
||||
break;
|
||||
case player_kind::none:
|
||||
@@ -354,10 +354,10 @@ namespace music {
|
||||
}
|
||||
|
||||
void stop() {
|
||||
if (bgmstream) {
|
||||
bgmstream->status = STREAM_NONE;
|
||||
S_CodecCloseStream(bgmstream);
|
||||
bgmstream = nullptr;
|
||||
if (stream) {
|
||||
stream->status = STREAM_NONE;
|
||||
S_CodecCloseStream(stream);
|
||||
stream = nullptr;
|
||||
s_rawend = 0;
|
||||
}
|
||||
}
|
||||
@@ -370,25 +370,25 @@ namespace music {
|
||||
bgmvolume.set("1");
|
||||
old_volume = bgmvolume.value;
|
||||
}
|
||||
if (bgmstream)
|
||||
if (stream)
|
||||
update_stream();
|
||||
}
|
||||
|
||||
void pause() {
|
||||
if (bgmstream) {
|
||||
if (bgmstream->status == STREAM_PLAY)
|
||||
bgmstream->status = STREAM_PAUSE;
|
||||
if (stream) {
|
||||
if (stream->status == STREAM_PLAY)
|
||||
stream->status = STREAM_PAUSE;
|
||||
}
|
||||
}
|
||||
|
||||
void resume() {
|
||||
if (bgmstream) {
|
||||
if (bgmstream->status == STREAM_PAUSE)
|
||||
bgmstream->status = STREAM_PLAY;
|
||||
if (stream) {
|
||||
if (stream->status == STREAM_PAUSE)
|
||||
stream->status = STREAM_PLAY;
|
||||
}
|
||||
}
|
||||
|
||||
void play_cd_track(const byte track, const bool looping) {
|
||||
void play_cd_track(const byte track, const bool should_loop) {
|
||||
/* instead of searching by the order of music_handlers, do so by
|
||||
* the order of searchpath priority: the file from the searchpath
|
||||
* with the highest path_id is most likely from our own gamedir
|
||||
@@ -400,14 +400,14 @@ namespace music {
|
||||
unsigned int path_id;
|
||||
|
||||
stop();
|
||||
if (CDAudio_Play(track, looping) == 0) {
|
||||
if (CDAudio_Play(track, should_loop) == 0) {
|
||||
return; /* success */
|
||||
}
|
||||
|
||||
if (active_handlers.empty())
|
||||
return; // We obviously can't play anything without handlers.
|
||||
|
||||
if (no_extmusic || bgm_extmusic.value == 0.0)
|
||||
if (no_extmusic || extmusic.value == 0.0)
|
||||
return;
|
||||
|
||||
unsigned int prev_id = 0;
|
||||
@@ -437,8 +437,8 @@ namespace music {
|
||||
else {
|
||||
q_snprintf(tmp, sizeof(tmp), "%s/track%02d.%s",
|
||||
MUSIC_DIRNAME, static_cast<int>(track), ext);
|
||||
bgmstream = S_CodecOpenStreamType(tmp, type, bgmloop);
|
||||
if (!bgmstream)
|
||||
stream = S_CodecOpenStreamType(tmp, type, should_loop);
|
||||
if (!stream)
|
||||
console::info("Couldn't handle music file %s\n", tmp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user