Fix intro FLIC brightness, 120/9 fps A/V sync, and authentic INTRO.EXE audio script
This commit is contained in:
1 parent
7673e25883
commit
5c2ac8e70f
9 files changed
+259
-33
No files matched your search
+19
-4
@@ -64,18 +64,30 @@ bool FlicPlayer::open(const Vfs& vfs, const std::string& path) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
first_frame_offset_ = first_off;
|
||||||
|
vga6_palette_ = (hdr_len == 12);
|
||||||
|
if (hdr_len == 12) {
|
||||||
|
fps_ = 120.0f / 9.0f; // INTRO.EXE script 'A 8': 9 ticks @ 120 Hz
|
||||||
|
} else if (hdr_len >= 128 && file_data_.size() >= 20) {
|
||||||
|
uint32_t speed_ms = read_le32(file_data_.data() + 16);
|
||||||
|
fps_ = (speed_ms > 0) ? (1000.0f / static_cast<float>(speed_ms)) : 15.0f;
|
||||||
|
} else {
|
||||||
|
fps_ = 15.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
palette_.fill({0, 0, 0, 255});
|
||||||
indexed_.assign(static_cast<size_t>(width_) * height_, 0);
|
indexed_.assign(static_cast<size_t>(width_) * height_, 0);
|
||||||
rgba_.assign(static_cast<size_t>(width_) * height_ * 4u, 0);
|
rgba_.assign(static_cast<size_t>(width_) * height_ * 4u, 0);
|
||||||
next_frame_offset_ = first_off;
|
next_frame_offset_ = first_frame_offset_;
|
||||||
frame_index_ = 0;
|
frame_index_ = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlicPlayer::reset() {
|
void FlicPlayer::reset() {
|
||||||
if (file_data_.size() < 16) return;
|
if (file_data_.size() < 16) return;
|
||||||
uint32_t hdr_len = read_le32(file_data_.data() + 0);
|
next_frame_offset_ = first_frame_offset_;
|
||||||
next_frame_offset_ = hdr_len;
|
|
||||||
frame_index_ = 0;
|
frame_index_ = 0;
|
||||||
|
palette_.fill({0, 0, 0, 255});
|
||||||
std::fill(indexed_.begin(), indexed_.end(), 0);
|
std::fill(indexed_.begin(), indexed_.end(), 0);
|
||||||
std::fill(rgba_.begin(), rgba_.end(), 0);
|
std::fill(rgba_.begin(), rgba_.end(), 0);
|
||||||
}
|
}
|
||||||
@@ -135,7 +147,10 @@ bool FlicPlayer::decode_chunk_frame(size_t offset) {
|
|||||||
if (cnt == 0) cnt = 256;
|
if (cnt == 0) cnt = 256;
|
||||||
for (int k = 0; k < cnt && cp + 3 <= cdata_len && idx < 256; ++k, ++idx) {
|
for (int k = 0; k < cnt && cp + 3 <= cdata_len && idx < 256; ++k, ++idx) {
|
||||||
uint8_t r = cd[cp++], g = cd[cp++], b = cd[cp++];
|
uint8_t r = cd[cp++], g = cd[cp++], b = cd[cp++];
|
||||||
if (ctype == 11) {
|
if (ctype == 11 || vga6_palette_) {
|
||||||
|
r = std::min<uint8_t>(r, 63);
|
||||||
|
g = std::min<uint8_t>(g, 63);
|
||||||
|
b = std::min<uint8_t>(b, 63);
|
||||||
r = static_cast<uint8_t>((r << 2) | (r >> 4));
|
r = static_cast<uint8_t>((r << 2) | (r >> 4));
|
||||||
g = static_cast<uint8_t>((g << 2) | (g >> 4));
|
g = static_cast<uint8_t>((g << 2) | (g >> 4));
|
||||||
b = static_cast<uint8_t>((b << 2) | (b >> 4));
|
b = static_cast<uint8_t>((b << 2) | (b >> 4));
|
||||||
|
|||||||
+3
-1
@@ -31,8 +31,10 @@ private:
|
|||||||
int height_ = 200;
|
int height_ = 200;
|
||||||
int num_frames_ = 0;
|
int num_frames_ = 0;
|
||||||
int frame_index_ = 0;
|
int frame_index_ = 0;
|
||||||
|
size_t first_frame_offset_ = 0;
|
||||||
size_t next_frame_offset_ = 0;
|
size_t next_frame_offset_ = 0;
|
||||||
float fps_ = 15.0f;
|
float fps_ = 120.0f / 9.0f;
|
||||||
|
bool vga6_palette_ = false;
|
||||||
|
|
||||||
std::array<Rgba8, 256> palette_{};
|
std::array<Rgba8, 256> palette_{};
|
||||||
std::vector<uint8_t> indexed_;
|
std::vector<uint8_t> indexed_;
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ void AudioEngine::shutdown() {
|
|||||||
pit_fill_ratio_.store(1.0f, std::memory_order_relaxed);
|
pit_fill_ratio_.store(1.0f, std::memory_order_relaxed);
|
||||||
refuel_env_ = 0.0f;
|
refuel_env_ = 0.0f;
|
||||||
refuel_pos_ = 0.0;
|
refuel_pos_ = 0.0;
|
||||||
|
for (auto& v : sfx_voices_) v = SfxVoice{};
|
||||||
initialized_ = false;
|
initialized_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,6 +259,32 @@ void AudioEngine::play_sfx_3d(const std::string& wav_name, const Vec3& src_pos,
|
|||||||
play_sfx(wav_name, gain * atten, pitch, pan, false, min_interval_sec);
|
play_sfx(wav_name, gain * atten, pitch, pan, false, min_interval_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioEngine::play_intro_sfx(int sample_index_0based, float gain, bool loop) {
|
||||||
|
if (sample_index_0based < 0 ||
|
||||||
|
static_cast<size_t>(sample_index_0based) >= sound_bank_.intro_sfx.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioCommand cmd;
|
||||||
|
cmd.type = CmdType::PlaySfx;
|
||||||
|
cmd.sample_idx = sample_index_0based;
|
||||||
|
cmd.intro_bank = true;
|
||||||
|
cmd.gain = std::clamp(gain, 0.0f, 2.0f);
|
||||||
|
cmd.pitch = 1.0f;
|
||||||
|
cmd.pan = 0.0f;
|
||||||
|
cmd.min_interval_sec = 0.0f;
|
||||||
|
cmd.sfx_loop = loop;
|
||||||
|
push_command(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioEngine::stop_intro_sfx(int sample_index_0based) {
|
||||||
|
AudioCommand cmd;
|
||||||
|
cmd.type = CmdType::StopSfx;
|
||||||
|
cmd.intro_bank = true;
|
||||||
|
cmd.sample_idx = sample_index_0based;
|
||||||
|
push_command(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
void AudioEngine::set_engine_state(bool active, float speed_ratio, bool boosting, float scrape_amount) {
|
void AudioEngine::set_engine_state(bool active, float speed_ratio, bool boosting, float scrape_amount) {
|
||||||
engine_active_.store(active, std::memory_order_relaxed);
|
engine_active_.store(active, std::memory_order_relaxed);
|
||||||
engine_speed_ratio_.store(std::clamp(speed_ratio, 0.0f, 1.5f), std::memory_order_relaxed);
|
engine_speed_ratio_.store(std::clamp(speed_ratio, 0.0f, 1.5f), std::memory_order_relaxed);
|
||||||
@@ -320,7 +347,7 @@ void AudioEngine::drain_commands() {
|
|||||||
if (smp->pcm_mono.empty()) break;
|
if (smp->pcm_mono.empty()) break;
|
||||||
|
|
||||||
auto& last_arr = cmd.intro_bank ? last_play_sample_intro_ : last_play_sample_gameplay_;
|
auto& last_arr = cmd.intro_bank ? last_play_sample_intro_ : last_play_sample_gameplay_;
|
||||||
if (static_cast<size_t>(cmd.sample_idx) < last_arr.size()) {
|
if (cmd.min_interval_sec > 0.0f && static_cast<size_t>(cmd.sample_idx) < last_arr.size()) {
|
||||||
uint64_t min_samples = static_cast<uint64_t>(cmd.min_interval_sec * static_cast<float>(kSampleRate));
|
uint64_t min_samples = static_cast<uint64_t>(cmd.min_interval_sec * static_cast<float>(kSampleRate));
|
||||||
if (mix_sample_clock_ - last_arr[cmd.sample_idx] < min_samples) {
|
if (mix_sample_clock_ - last_arr[cmd.sample_idx] < min_samples) {
|
||||||
break;
|
break;
|
||||||
@@ -328,6 +355,7 @@ void AudioEngine::drain_commands() {
|
|||||||
last_arr[cmd.sample_idx] = mix_sample_clock_;
|
last_arr[cmd.sample_idx] = mix_sample_clock_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SfxVoice* matching_loop = nullptr;
|
||||||
int same_count = 0;
|
int same_count = 0;
|
||||||
SfxVoice* oldest_same = nullptr;
|
SfxVoice* oldest_same = nullptr;
|
||||||
SfxVoice* free_slot = nullptr;
|
SfxVoice* free_slot = nullptr;
|
||||||
@@ -341,6 +369,9 @@ void AudioEngine::drain_commands() {
|
|||||||
oldest_any = &v;
|
oldest_any = &v;
|
||||||
}
|
}
|
||||||
if (v.sample_idx == cmd.sample_idx && v.intro_bank == cmd.intro_bank) {
|
if (v.sample_idx == cmd.sample_idx && v.intro_bank == cmd.intro_bank) {
|
||||||
|
if (cmd.sfx_loop && v.loop && !matching_loop) {
|
||||||
|
matching_loop = &v;
|
||||||
|
}
|
||||||
++same_count;
|
++same_count;
|
||||||
if (!oldest_same || v.start_seq < oldest_same->start_seq) {
|
if (!oldest_same || v.start_seq < oldest_same->start_seq) {
|
||||||
oldest_same = &v;
|
oldest_same = &v;
|
||||||
@@ -348,14 +379,17 @@ void AudioEngine::drain_commands() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SfxVoice* target = (same_count >= kMaxSameSampleVoices && oldest_same)
|
SfxVoice* target = matching_loop
|
||||||
|
? matching_loop
|
||||||
|
: ((same_count >= kMaxSameSampleVoices && oldest_same)
|
||||||
? oldest_same
|
? oldest_same
|
||||||
: (free_slot ? free_slot : oldest_any);
|
: (free_slot ? free_slot : oldest_any));
|
||||||
if (target) {
|
if (target) {
|
||||||
target->active = true;
|
target->active = true;
|
||||||
target->sample = smp;
|
target->sample = smp;
|
||||||
target->sample_idx = cmd.sample_idx;
|
target->sample_idx = cmd.sample_idx;
|
||||||
target->intro_bank = cmd.intro_bank;
|
target->intro_bank = cmd.intro_bank;
|
||||||
|
target->loop = cmd.sfx_loop;
|
||||||
target->start_seq = ++voice_seq_;
|
target->start_seq = ++voice_seq_;
|
||||||
target->pos = 0.0;
|
target->pos = 0.0;
|
||||||
target->step = (static_cast<double>(smp->sample_rate) / kSampleRate) * cmd.pitch;
|
target->step = (static_cast<double>(smp->sample_rate) / kSampleRate) * cmd.pitch;
|
||||||
@@ -365,6 +399,16 @@ void AudioEngine::drain_commands() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CmdType::StopSfx: {
|
||||||
|
for (auto& v : sfx_voices_) {
|
||||||
|
if (v.active && v.intro_bank == cmd.intro_bank &&
|
||||||
|
(cmd.sample_idx < 0 || v.sample_idx == cmd.sample_idx)) {
|
||||||
|
v.active = false;
|
||||||
|
v.loop = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case CmdType::PlayMusic: {
|
case CmdType::PlayMusic: {
|
||||||
active_track_ = cmd.track;
|
active_track_ = cmd.track;
|
||||||
active_loop_ = cmd.loop;
|
active_loop_ = cmd.loop;
|
||||||
@@ -455,14 +499,31 @@ void AudioEngine::render_internal(float* stereo_out, int frames) {
|
|||||||
for (auto& v : sfx_voices_) {
|
for (auto& v : sfx_voices_) {
|
||||||
if (!v.active || !v.sample) continue;
|
if (!v.active || !v.sample) continue;
|
||||||
const auto& pcm = v.sample->pcm_mono;
|
const auto& pcm = v.sample->pcm_mono;
|
||||||
|
const size_t len = pcm.size();
|
||||||
|
if (len < 2) {
|
||||||
|
v.active = false;
|
||||||
|
v.loop = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (int f = 0; f < cur; ++f) {
|
for (int f = 0; f < cur; ++f) {
|
||||||
size_t i0 = static_cast<size_t>(v.pos);
|
size_t i0 = 0;
|
||||||
if (i0 + 1 >= pcm.size()) {
|
size_t i1 = 0;
|
||||||
|
if (v.loop) {
|
||||||
|
while (v.pos >= static_cast<double>(len)) {
|
||||||
|
v.pos -= static_cast<double>(len);
|
||||||
|
}
|
||||||
|
i0 = static_cast<size_t>(v.pos);
|
||||||
|
i1 = (i0 + 1 < len) ? (i0 + 1) : 0;
|
||||||
|
} else {
|
||||||
|
i0 = static_cast<size_t>(v.pos);
|
||||||
|
if (i0 + 1 >= len) {
|
||||||
v.active = false;
|
v.active = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
i1 = i0 + 1;
|
||||||
|
}
|
||||||
float frac = static_cast<float>(v.pos - static_cast<double>(i0));
|
float frac = static_cast<float>(v.pos - static_cast<double>(i0));
|
||||||
float s = (pcm[i0] + (pcm[i0 + 1] - pcm[i0]) * frac) * svol;
|
float s = (pcm[i0] + (pcm[i1] - pcm[i0]) * frac) * svol;
|
||||||
sfx_bus[f * 2 + 0] += s * v.gain_l;
|
sfx_bus[f * 2 + 0] += s * v.gain_l;
|
||||||
sfx_bus[f * 2 + 1] += s * v.gain_r;
|
sfx_bus[f * 2 + 1] += s * v.gain_r;
|
||||||
v.pos += v.step;
|
v.pos += v.step;
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ public:
|
|||||||
void play_sfx_3d(const std::string& wav_name, const Vec3& src_pos,
|
void play_sfx_3d(const std::string& wav_name, const Vec3& src_pos,
|
||||||
const Vec3& listener_pos, const Vec3& listener_right,
|
const Vec3& listener_pos, const Vec3& listener_right,
|
||||||
float gain = 1.0f, float pitch = 1.0f, float min_interval_sec = 0.05f);
|
float gain = 1.0f, float pitch = 1.0f, float min_interval_sec = 0.05f);
|
||||||
|
void play_intro_sfx(int sample_index_0based, float gain = 0.85f, bool loop = false);
|
||||||
|
void stop_intro_sfx(int sample_index_0based = -1); // -1 stops all intro SFX voices
|
||||||
|
|
||||||
// Continuous player engine pitch/volume modulation
|
// Continuous player engine pitch/volume modulation
|
||||||
void set_engine_state(bool active, float speed_ratio, bool boosting, float scrape_amount);
|
void set_engine_state(bool active, float speed_ratio, bool boosting, float scrape_amount);
|
||||||
@@ -73,6 +75,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
enum class CmdType : uint8_t {
|
enum class CmdType : uint8_t {
|
||||||
PlaySfx = 0,
|
PlaySfx = 0,
|
||||||
|
StopSfx,
|
||||||
PlayMusic,
|
PlayMusic,
|
||||||
StopMusic,
|
StopMusic,
|
||||||
SetBackend,
|
SetBackend,
|
||||||
@@ -86,6 +89,7 @@ private:
|
|||||||
float pitch = 1.0f;
|
float pitch = 1.0f;
|
||||||
float pan = 0.0f;
|
float pan = 0.0f;
|
||||||
float min_interval_sec = 0.05f;
|
float min_interval_sec = 0.05f;
|
||||||
|
bool sfx_loop = false;
|
||||||
MusicTrackId track = MusicTrackId::Game1;
|
MusicTrackId track = MusicTrackId::Game1;
|
||||||
bool loop = true;
|
bool loop = true;
|
||||||
MusicBackend backend = MusicBackend::Opl3;
|
MusicBackend backend = MusicBackend::Opl3;
|
||||||
@@ -96,6 +100,7 @@ private:
|
|||||||
const assets::SoundSample* sample = nullptr;
|
const assets::SoundSample* sample = nullptr;
|
||||||
int sample_idx = -1;
|
int sample_idx = -1;
|
||||||
bool intro_bank = false;
|
bool intro_bank = false;
|
||||||
|
bool loop = false;
|
||||||
uint64_t start_seq = 0;
|
uint64_t start_seq = 0;
|
||||||
double pos = 0.0;
|
double pos = 0.0;
|
||||||
double step = 1.0;
|
double step = 1.0;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public:
|
|||||||
last_counter_ = now_counter;
|
last_counter_ = now_counter;
|
||||||
freq_ = freq ? freq : 1;
|
freq_ = freq ? freq : 1;
|
||||||
accumulator_ = 0.0;
|
accumulator_ = 0.0;
|
||||||
|
last_dt_ = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns number of fixed simulation steps to execute this frame
|
// Returns number of fixed simulation steps to execute this frame
|
||||||
@@ -21,6 +22,7 @@ public:
|
|||||||
double dt = static_cast<double>(now_counter - last_counter_) / static_cast<double>(freq_);
|
double dt = static_cast<double>(now_counter - last_counter_) / static_cast<double>(freq_);
|
||||||
last_counter_ = now_counter;
|
last_counter_ = now_counter;
|
||||||
dt = std::clamp(dt, 0.0, kMaxFrameDt);
|
dt = std::clamp(dt, 0.0, kMaxFrameDt);
|
||||||
|
last_dt_ = dt;
|
||||||
accumulator_ += dt;
|
accumulator_ += dt;
|
||||||
int steps = 0;
|
int steps = 0;
|
||||||
while (accumulator_ >= kFixedDt) {
|
while (accumulator_ >= kFixedDt) {
|
||||||
@@ -30,6 +32,7 @@ public:
|
|||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double last_frame_dt() const { return last_dt_; }
|
||||||
double alpha() const { return accumulator_ / kFixedDt; }
|
double alpha() const { return accumulator_ / kFixedDt; }
|
||||||
static constexpr double fixed_dt() { return kFixedDt; }
|
static constexpr double fixed_dt() { return kFixedDt; }
|
||||||
|
|
||||||
@@ -37,6 +40,7 @@ private:
|
|||||||
uint64_t last_counter_ = 0;
|
uint64_t last_counter_ = 0;
|
||||||
uint64_t freq_ = 1;
|
uint64_t freq_ = 1;
|
||||||
double accumulator_ = 0.0;
|
double accumulator_ = 0.0;
|
||||||
|
double last_dt_ = 0.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace top_octane
|
} // namespace top_octane
|
||||||
+105
-18
@@ -9,11 +9,66 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
namespace top_octane::game {
|
namespace top_octane::game {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
struct IntroCue {
|
||||||
|
int frame;
|
||||||
|
char op; // 'R'=loop sfx, 'S'=one-shot sfx, 'T'=stop sfx, 'M'=start music, 'X'=stop music
|
||||||
|
int param; // 1-based Bank-9 sample index (1..14) or music track (4=TINTRO2)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Authentic audio & music script extracted from Bullfrog EXEC/INTRO.EXE
|
||||||
|
constexpr IntroCue kIntroScript[] = {
|
||||||
|
{ 1, 'R', 8}, // loop FIRE.WAV
|
||||||
|
{ 13, 'M', 4}, // start TINTRO2
|
||||||
|
{ 50, 'S', 11}, // PAST.WAV
|
||||||
|
{ 51, 'S', 6}, // HELEHIT.WAV
|
||||||
|
{ 64, 'S', 11}, // PAST.WAV
|
||||||
|
{ 96, 'T', 8}, // stop FIRE.WAV
|
||||||
|
{ 96, 'R', 13}, // loop SMALLCAR.WAV
|
||||||
|
{104, 'S', 2}, // MINIGUN.WAV
|
||||||
|
{107, 'S', 1}, // RICCOS.WAV
|
||||||
|
{113, 'T', 2}, // stop MINIGUN.WAV
|
||||||
|
{113, 'S', 2}, // restart MINIGUN.WAV
|
||||||
|
{127, 'T', 2}, // stop MINIGUN.WAV
|
||||||
|
{129, 'T', 1}, // stop RICCOS.WAV
|
||||||
|
{129, 'S', 3}, // TURBO.WAV
|
||||||
|
{138, 'T', 3}, // stop TURBO.WAV
|
||||||
|
{138, 'S', 9}, // BOOSTER.WAV
|
||||||
|
{140, 'T', 13}, // stop SMALLCAR.WAV
|
||||||
|
{140, 'R', 14}, // loop LARGECAR.WAV
|
||||||
|
{141, 'S', 5}, // MISSILE.WAV
|
||||||
|
{162, 'T', 14}, // stop LARGECAR.WAV
|
||||||
|
{162, 'R', 13}, // loop SMALLCAR.WAV
|
||||||
|
{170, 'S', 7}, // FIREPAST.WAV
|
||||||
|
{174, 'T', 7}, // stop FIREPAST.WAV
|
||||||
|
{174, 'S', 4}, // EXPLODE.WAV
|
||||||
|
{192, 'T', 13}, // stop SMALLCAR.WAV
|
||||||
|
{205, 'S', 11}, // PAST.WAV
|
||||||
|
{234, 'R', 13}, // loop SMALLCAR.WAV
|
||||||
|
{257, 'S', 3}, // TURBO.WAV
|
||||||
|
{270, 'T', 3}, // stop TURBO.WAV
|
||||||
|
{270, 'S', 9}, // BOOSTER.WAV
|
||||||
|
{275, 'S', 11}, // PAST.WAV
|
||||||
|
{277, 'T', 13}, // stop SMALLCAR.WAV
|
||||||
|
{300, 'S', 12}, // SCRAPE2.WAV
|
||||||
|
{330, 'T', 12}, // stop SCRAPE2.WAV
|
||||||
|
{349, 'S', 4}, // EXPLODE.WAV
|
||||||
|
{355, 'S', 11}, // PAST.WAV
|
||||||
|
{404, 'R', 8}, // loop FIRE.WAV
|
||||||
|
{460, 'S', 3}, // TURBO.WAV
|
||||||
|
{470, 'T', 3}, // stop TURBO.WAV
|
||||||
|
{470, 'S', 9}, // BOOSTER.WAV
|
||||||
|
{477, 'S', 11}, // PAST.WAV
|
||||||
|
{480, 'T', 8}, // stop FIRE.WAV
|
||||||
|
{532, 'X', 4}, // stop TINTRO2
|
||||||
|
{532, 'S', 10}, // CURTAIN.WAV
|
||||||
|
};
|
||||||
|
|
||||||
std::string format_time(float sec) {
|
std::string format_time(float sec) {
|
||||||
if (sec <= 0.0f) return "--:--.--";
|
if (sec <= 0.0f) return "--:--.--";
|
||||||
int total_cs = std::clamp(static_cast<int>(std::lround(sec * 100.0f)), 1, 599999);
|
int total_cs = std::clamp(static_cast<int>(std::lround(sec * 100.0f)), 1, 599999);
|
||||||
@@ -287,6 +342,9 @@ bool GameApp::init(const LaunchOptions& opts) {
|
|||||||
else if (opts.smoke_menu == "vehicle") enter_state(ScreenState::VehicleSelect);
|
else if (opts.smoke_menu == "vehicle") enter_state(ScreenState::VehicleSelect);
|
||||||
else if (opts.smoke_menu == "options") enter_state(ScreenState::Options);
|
else if (opts.smoke_menu == "options") enter_state(ScreenState::Options);
|
||||||
else if (opts.smoke_menu == "highscores") enter_state(ScreenState::Highscores);
|
else if (opts.smoke_menu == "highscores") enter_state(ScreenState::Highscores);
|
||||||
|
else if (opts.smoke_menu == "intro" && vfs_.exists("DATA/INTRO.DAT") && flic_.open(vfs_)) {
|
||||||
|
enter_state(ScreenState::Intro);
|
||||||
|
}
|
||||||
else enter_state(ScreenState::MainMenu);
|
else enter_state(ScreenState::MainMenu);
|
||||||
} else if (opts.track_viewer && opts.start_track >= 1 && opts.start_track <= available_tracks_) {
|
} else if (opts.track_viewer && opts.start_track >= 1 && opts.start_track <= available_tracks_) {
|
||||||
enter_track_viewer(opts.start_track);
|
enter_track_viewer(opts.start_track);
|
||||||
@@ -359,6 +417,37 @@ void GameApp::ensure_music(audio::MusicTrackId track, bool loop, bool force_rest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameApp::dispatch_intro_cues(int frame) {
|
||||||
|
while (intro_cue_cursor_ < std::size(kIntroScript) &&
|
||||||
|
kIntroScript[intro_cue_cursor_].frame <= frame) {
|
||||||
|
const IntroCue& cue = kIntroScript[intro_cue_cursor_++];
|
||||||
|
switch (cue.op) {
|
||||||
|
case 'R':
|
||||||
|
audio_.play_intro_sfx(cue.param - 1, 0.62f, true);
|
||||||
|
break;
|
||||||
|
case 'S':
|
||||||
|
if (cue.param == 0) {
|
||||||
|
audio_.stop_intro_sfx(-1);
|
||||||
|
} else {
|
||||||
|
audio_.play_intro_sfx(cue.param - 1, 0.88f, false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'T':
|
||||||
|
audio_.stop_intro_sfx(cue.param == 0 ? -1 : cue.param - 1);
|
||||||
|
break;
|
||||||
|
case 'M':
|
||||||
|
ensure_music(audio::MusicTrackId::TitleIntro, false, true);
|
||||||
|
break;
|
||||||
|
case 'X':
|
||||||
|
audio_.stop_music();
|
||||||
|
active_music_track_ = -1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GameApp::begin_name_edit(int target) {
|
void GameApp::begin_name_edit(int target) {
|
||||||
editing_name_target_ = (target == 2) ? 2 : 1;
|
editing_name_target_ = (target == 2) ? 2 : 1;
|
||||||
name_edit_buf_ = (editing_name_target_ == 2) ? cfg_.player2_name : cfg_.player_name;
|
name_edit_buf_ = (editing_name_target_ == 2) ? cfg_.player2_name : cfg_.player_name;
|
||||||
@@ -423,32 +512,36 @@ void GameApp::enter_state(ScreenState s) {
|
|||||||
in_race_session_ = false;
|
in_race_session_ = false;
|
||||||
flic_.reset();
|
flic_.reset();
|
||||||
intro_accum_ = 0.0;
|
intro_accum_ = 0.0;
|
||||||
intro_turbo_played_ = false;
|
intro_cue_cursor_ = 0;
|
||||||
intro_explode_played_ = false;
|
|
||||||
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
audio_.set_pitstop_state(false, false, 1.0f);
|
audio_.set_pitstop_state(false, false, 1.0f);
|
||||||
ensure_music(audio::MusicTrackId::TitleIntro, true, true);
|
audio_.stop_intro_sfx(-1);
|
||||||
|
audio_.stop_music();
|
||||||
|
active_music_track_ = -1;
|
||||||
|
if (flic_.step_frame()) {
|
||||||
|
ui_ren_.update_stream_rgba(flic_.width(), flic_.height(), flic_.rgba().data());
|
||||||
|
dispatch_intro_cues(flic_.current_frame());
|
||||||
|
}
|
||||||
} else if (s == ScreenState::Title || s == ScreenState::MainMenu ||
|
} else if (s == ScreenState::Title || s == ScreenState::MainMenu ||
|
||||||
s == ScreenState::ChampionshipMenu || s == ScreenState::TrackSelect ||
|
s == ScreenState::ChampionshipMenu || s == ScreenState::TrackSelect ||
|
||||||
s == ScreenState::VehicleSelect || s == ScreenState::Highscores) {
|
s == ScreenState::VehicleSelect || s == ScreenState::Highscores) {
|
||||||
in_race_session_ = false;
|
in_race_session_ = false;
|
||||||
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
audio_.set_pitstop_state(false, false, 1.0f);
|
audio_.set_pitstop_state(false, false, 1.0f);
|
||||||
if (active_music_track_ != static_cast<int>(audio::MusicTrackId::TitleIntro)) {
|
audio_.stop_intro_sfx(-1);
|
||||||
ensure_music(audio::MusicTrackId::Menu, true, false);
|
ensure_music(audio::MusicTrackId::Menu, true, false);
|
||||||
}
|
|
||||||
} else if (s == ScreenState::Options) {
|
} else if (s == ScreenState::Options) {
|
||||||
if (!in_race_session_) {
|
if (!in_race_session_) {
|
||||||
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
audio_.set_pitstop_state(false, false, 1.0f);
|
audio_.set_pitstop_state(false, false, 1.0f);
|
||||||
if (active_music_track_ != static_cast<int>(audio::MusicTrackId::TitleIntro)) {
|
audio_.stop_intro_sfx(-1);
|
||||||
ensure_music(audio::MusicTrackId::Menu, true, false);
|
ensure_music(audio::MusicTrackId::Menu, true, false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if (s == ScreenState::PostRace) {
|
} else if (s == ScreenState::PostRace) {
|
||||||
in_race_session_ = false;
|
in_race_session_ = false;
|
||||||
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
audio_.set_pitstop_state(false, false, 1.0f);
|
audio_.set_pitstop_state(false, false, 1.0f);
|
||||||
|
audio_.stop_intro_sfx(-1);
|
||||||
ensure_music(audio::MusicTrackId::Menu, true, false);
|
ensure_music(audio::MusicTrackId::Menu, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -694,7 +787,7 @@ void GameApp::update_menu(float dt) {
|
|||||||
const MenuInput& m = input_.menu_input();
|
const MenuInput& m = input_.menu_input();
|
||||||
|
|
||||||
if (state_ == ScreenState::Intro) {
|
if (state_ == ScreenState::Intro) {
|
||||||
intro_accum_ += dt * flic_.fps();
|
intro_accum_ += static_cast<double>(dt) * static_cast<double>(flic_.fps());
|
||||||
while (intro_accum_ >= 1.0) {
|
while (intro_accum_ >= 1.0) {
|
||||||
intro_accum_ -= 1.0;
|
intro_accum_ -= 1.0;
|
||||||
if (!flic_.step_frame()) {
|
if (!flic_.step_frame()) {
|
||||||
@@ -702,16 +795,10 @@ void GameApp::update_menu(float dt) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ui_ren_.update_stream_rgba(flic_.width(), flic_.height(), flic_.rgba().data());
|
ui_ren_.update_stream_rgba(flic_.width(), flic_.height(), flic_.rgba().data());
|
||||||
if (!intro_turbo_played_ && flic_.current_frame() >= 60) {
|
dispatch_intro_cues(flic_.current_frame());
|
||||||
intro_turbo_played_ = true;
|
|
||||||
audio_.play_sfx("TURBO.WAV", 0.55f, 1.0f, 0.0f, true);
|
|
||||||
}
|
|
||||||
if (!intro_explode_played_ && flic_.current_frame() >= 250) {
|
|
||||||
intro_explode_played_ = true;
|
|
||||||
audio_.play_sfx("EXPLODE.WAV", 0.55f, 1.0f, 0.0f, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (m.any_pressed) {
|
if (m.any_pressed) {
|
||||||
|
audio_.stop_intro_sfx(-1);
|
||||||
audio_.play_sfx("SELECT.WAV", 0.38f);
|
audio_.play_sfx("SELECT.WAV", 0.38f);
|
||||||
enter_state(ScreenState::Title);
|
enter_state(ScreenState::Title);
|
||||||
}
|
}
|
||||||
@@ -1175,9 +1262,9 @@ int GameApp::run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (state_ == ScreenState::TrackViewer) {
|
} else if (state_ == ScreenState::TrackViewer) {
|
||||||
update_track_viewer(static_cast<float>(steps) * static_cast<float>(FixedStepClock::kFixedDt));
|
update_track_viewer(static_cast<float>(clock_.last_frame_dt()));
|
||||||
} else {
|
} else {
|
||||||
update_menu(std::max(1, steps) * static_cast<float>(FixedStepClock::kFixedDt));
|
update_menu(static_cast<float>(clock_.last_frame_dt()));
|
||||||
}
|
}
|
||||||
|
|
||||||
render_frame(static_cast<float>(clock_.alpha()));
|
render_frame(static_cast<float>(clock_.alpha()));
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ private:
|
|||||||
void toggle_fullscreen();
|
void toggle_fullscreen();
|
||||||
void save_all_user_data();
|
void save_all_user_data();
|
||||||
void ensure_music(audio::MusicTrackId track, bool loop = true, bool force_restart = false);
|
void ensure_music(audio::MusicTrackId track, bool loop = true, bool force_restart = false);
|
||||||
|
void dispatch_intro_cues(int frame);
|
||||||
void begin_name_edit(int target);
|
void begin_name_edit(int target);
|
||||||
void cancel_name_edit();
|
void cancel_name_edit();
|
||||||
void update_name_edit();
|
void update_name_edit();
|
||||||
@@ -146,8 +147,7 @@ private:
|
|||||||
double ui_time_ = 0.0;
|
double ui_time_ = 0.0;
|
||||||
std::array<std::string, 2> hud_banner_{};
|
std::array<std::string, 2> hud_banner_{};
|
||||||
std::array<float, 2> hud_banner_timer_{0.0f, 0.0f};
|
std::array<float, 2> hud_banner_timer_{0.0f, 0.0f};
|
||||||
bool intro_turbo_played_ = false;
|
size_t intro_cue_cursor_ = 0;
|
||||||
bool intro_explode_played_ = false;
|
|
||||||
|
|
||||||
// Music & player name / HUD / options state
|
// Music & player name / HUD / options state
|
||||||
int active_music_track_ = -1;
|
int active_music_track_ = -1;
|
||||||
|
|||||||
+19
-2
@@ -11,6 +11,7 @@
|
|||||||
#include "core/vfs.hpp"
|
#include "core/vfs.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
@@ -263,12 +264,28 @@ int main() {
|
|||||||
CHECK(flic.open(vfs));
|
CHECK(flic.open(vfs));
|
||||||
CHECK(flic.width() == 320 && flic.height() == 200);
|
CHECK(flic.width() == 320 && flic.height() == 200);
|
||||||
CHECK(flic.num_frames() == 548);
|
CHECK(flic.num_frames() == 548);
|
||||||
int decoded_frames = 0;
|
CHECK(std::abs(flic.fps() - (120.0f / 9.0f)) < 1e-4f);
|
||||||
|
|
||||||
|
CHECK(flic.step_frame());
|
||||||
|
const std::vector<uint8_t> frame1_rgba = flic.rgba();
|
||||||
|
uint8_t max_rgb = 0;
|
||||||
|
for (size_t i = 0; i + 3 < frame1_rgba.size(); i += 4) {
|
||||||
|
max_rgb = std::max({max_rgb, frame1_rgba[i], frame1_rgba[i + 1], frame1_rgba[i + 2]});
|
||||||
|
}
|
||||||
|
CHECK(max_rgb >= 200);
|
||||||
|
|
||||||
|
int decoded_frames = 1;
|
||||||
while (flic.step_frame()) {
|
while (flic.step_frame()) {
|
||||||
++decoded_frames;
|
++decoded_frames;
|
||||||
}
|
}
|
||||||
CHECK(decoded_frames == 548);
|
CHECK(decoded_frames == 548);
|
||||||
std::cout << "[PASS] Intro FLIC decoded all " << decoded_frames << " frames\n";
|
|
||||||
|
flic.reset();
|
||||||
|
CHECK(flic.step_frame());
|
||||||
|
CHECK(flic.current_frame() == 1);
|
||||||
|
CHECK(flic.rgba() == frame1_rgba);
|
||||||
|
std::cout << "[PASS] Intro FLIC decoded all " << decoded_frames
|
||||||
|
<< " frames (fps=" << flic.fps() << ", max_rgb=" << int(max_rgb) << ")\n";
|
||||||
} else {
|
} else {
|
||||||
std::cout << "[INFO] Optional DATA/INTRO.DAT not present; skipping intro FLIC check\n";
|
std::cout << "[INFO] Optional DATA/INTRO.DAT not present; skipping intro FLIC check\n";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -299,6 +299,41 @@ int main() {
|
|||||||
CHECK(off_st.finite_ok && off_st.rms < 0.001f);
|
CHECK(off_st.finite_ok && off_st.rms < 0.001f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 8. Intro SFX looping & targeted stop commands
|
||||||
|
{
|
||||||
|
eng.stop_music();
|
||||||
|
eng.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
|
eng.set_pitstop_state(false, false, 1.0f);
|
||||||
|
std::vector<float> settle(12000 * 2, 0.0f);
|
||||||
|
eng.mix_offline(settle.data(), 12000);
|
||||||
|
|
||||||
|
// HELEHIT.WAV (0-based idx 5, 0.702s) looped should still sound after 1.0s
|
||||||
|
eng.play_intro_sfx(5, 0.85f, true);
|
||||||
|
std::vector<float> first_sec(48000 * 2, 0.0f);
|
||||||
|
eng.mix_offline(first_sec.data(), 48000);
|
||||||
|
std::vector<float> quarter_sec(12000 * 2, 0.0f);
|
||||||
|
eng.mix_offline(quarter_sec.data(), 12000);
|
||||||
|
BufferStats loop_st = measure_buffer(quarter_sec, "Intro SFX looped (past sample end)");
|
||||||
|
CHECK(loop_st.finite_ok && loop_st.rms > 0.01f);
|
||||||
|
|
||||||
|
eng.stop_intro_sfx(5);
|
||||||
|
std::vector<float> silence_buf(4800 * 2, 0.0f);
|
||||||
|
eng.mix_offline(silence_buf.data(), 4800);
|
||||||
|
BufferStats stop_st = measure_buffer(silence_buf, "Intro SFX targeted stop");
|
||||||
|
CHECK(stop_st.finite_ok && stop_st.peak == 0.0f);
|
||||||
|
|
||||||
|
eng.play_intro_sfx(7, 0.62f, true); // FIRE.WAV
|
||||||
|
eng.play_intro_sfx(12, 0.62f, true); // SMALLCAR.WAV
|
||||||
|
eng.mix_offline(quarter_sec.data(), 12000);
|
||||||
|
BufferStats multi_st = measure_buffer(quarter_sec, "Intro SFX multi-voice loop");
|
||||||
|
CHECK(multi_st.finite_ok && multi_st.rms > 0.01f);
|
||||||
|
|
||||||
|
eng.stop_intro_sfx(-1);
|
||||||
|
eng.mix_offline(silence_buf.data(), 4800);
|
||||||
|
BufferStats stop_all_st = measure_buffer(silence_buf, "Intro SFX stop all");
|
||||||
|
CHECK(stop_all_st.finite_ok && stop_all_st.peak == 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "[PASS] AudioEngine, OPL3 FM, SoundFont SBK, Normalization & Limiter validated\n";
|
std::cout << "[PASS] AudioEngine, OPL3 FM, SoundFont SBK, Normalization & Limiter validated\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user