Add pitstop audio cue, original explosions/smoke, authentic HUD, and Modern lighting/shadows
This commit is contained in:
1 parent
3a377b0534
commit
197bfbc973
21 files changed
+1927
-246
No files matched your search
@@ -106,6 +106,12 @@ bool AudioEngine::init(const Vfs& vfs, const GameConfig& cfg, bool open_device)
|
||||
engine_sample_ = sound_bank_.find_gameplay("ENGINE1.WAV");
|
||||
if (!engine_sample_) engine_sample_ = sound_bank_.find_gameplay("TESTENG3.WAV");
|
||||
scrape_sample_ = sound_bank_.find_gameplay("SCRAPE2.WAV");
|
||||
refuel_sample_ = sound_bank_.find_gameplay("REFUEL.WAV");
|
||||
refuel_pos_ = 0.0;
|
||||
refuel_env_ = 0.0f;
|
||||
pit_active_.store(false, std::memory_order_relaxed);
|
||||
pit_charging_.store(false, std::memory_order_relaxed);
|
||||
pit_fill_ratio_.store(1.0f, std::memory_order_relaxed);
|
||||
|
||||
active_backend_ = cfg.music_backend;
|
||||
requested_backend_ = cfg.music_backend;
|
||||
@@ -152,6 +158,11 @@ void AudioEngine::shutdown() {
|
||||
SDL_CloseAudioDevice(dev_id_);
|
||||
dev_id_ = 0;
|
||||
}
|
||||
pit_active_.store(false, std::memory_order_relaxed);
|
||||
pit_charging_.store(false, std::memory_order_relaxed);
|
||||
pit_fill_ratio_.store(1.0f, std::memory_order_relaxed);
|
||||
refuel_env_ = 0.0f;
|
||||
refuel_pos_ = 0.0;
|
||||
initialized_ = false;
|
||||
}
|
||||
|
||||
@@ -254,6 +265,12 @@ void AudioEngine::set_engine_state(bool active, float speed_ratio, bool boosting
|
||||
scrape_amount_.store(std::clamp(scrape_amount, 0.0f, 1.0f), std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void AudioEngine::set_pitstop_state(bool on_pad, bool charging, float fill_ratio) {
|
||||
pit_active_.store(on_pad, std::memory_order_relaxed);
|
||||
pit_charging_.store(charging, std::memory_order_relaxed);
|
||||
pit_fill_ratio_.store(std::clamp(fill_ratio, 0.0f, 1.0f), std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
const assets::XmiSequence& AudioEngine::xmi_sequence(MusicBackend b, MusicTrackId t) const {
|
||||
int slot = map_track_slot(t);
|
||||
return (b == MusicBackend::SoundFont) ? wt_seqs_[slot] : opl_seqs_[slot];
|
||||
@@ -492,6 +509,37 @@ void AudioEngine::render_internal(float* stereo_out, int frames) {
|
||||
}
|
||||
}
|
||||
|
||||
const bool pit_on = pit_active_.load(std::memory_order_relaxed);
|
||||
const bool pit_chg = pit_charging_.load(std::memory_order_relaxed);
|
||||
const float pit_fill = std::clamp(pit_fill_ratio_.load(std::memory_order_relaxed), 0.0f, 1.0f);
|
||||
const float target_pit_env = pit_on ? (pit_chg ? 1.0f : 0.45f) : 0.0f;
|
||||
if ((refuel_env_ > 0.001f || target_pit_env > 0.001f) && refuel_sample_ &&
|
||||
!refuel_sample_->pcm_mono.empty()) {
|
||||
const auto& pcm = refuel_sample_->pcm_mono;
|
||||
const size_t len = pcm.size();
|
||||
const double pitch = pit_chg ? (0.78 + 0.52 * static_cast<double>(pit_fill)) : 1.28;
|
||||
const double step = (static_cast<double>(refuel_sample_->sample_rate) / kSampleRate) * pitch;
|
||||
const float base_gain = 0.48f * svol;
|
||||
const float env_step = 1.0f / (0.030f * static_cast<float>(kSampleRate));
|
||||
for (int f = 0; f < cur; ++f) {
|
||||
if (refuel_env_ < target_pit_env) {
|
||||
refuel_env_ = std::min(target_pit_env, refuel_env_ + env_step);
|
||||
} else if (refuel_env_ > target_pit_env) {
|
||||
refuel_env_ = std::max(target_pit_env, refuel_env_ - env_step);
|
||||
}
|
||||
size_t i0 = static_cast<size_t>(refuel_pos_) % len;
|
||||
size_t i1 = (i0 + 1) % len;
|
||||
float frac = static_cast<float>(refuel_pos_ - std::floor(refuel_pos_));
|
||||
float s = (pcm[i0] + (pcm[i1] - pcm[i0]) * frac) * base_gain * refuel_env_;
|
||||
sfx_bus[f * 2 + 0] += s;
|
||||
sfx_bus[f * 2 + 1] += s;
|
||||
refuel_pos_ += step;
|
||||
if (refuel_pos_ >= static_cast<double>(len)) {
|
||||
refuel_pos_ -= static_cast<double>(len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < cur * 2; ++i) {
|
||||
out_ptr[i] += std::tanh(sfx_bus[i] * 1.1f) * 0.88f;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,9 @@ public:
|
||||
// Continuous player engine pitch/volume modulation
|
||||
void set_engine_state(bool active, float speed_ratio, bool boosting, float scrape_amount);
|
||||
|
||||
// Continuous pitstop pad hum / rising-pitch recharge cue
|
||||
void set_pitstop_state(bool on_pad, bool charging, float fill_ratio);
|
||||
|
||||
// Offline render hook for deterministic unit testing
|
||||
void mix_offline(float* stereo_out, int frames);
|
||||
|
||||
@@ -141,8 +144,11 @@ private:
|
||||
std::array<uint64_t, 64> last_play_sample_intro_{};
|
||||
const assets::SoundSample* engine_sample_ = nullptr;
|
||||
const assets::SoundSample* scrape_sample_ = nullptr;
|
||||
const assets::SoundSample* refuel_sample_ = nullptr;
|
||||
double engine_pos_ = 0.0;
|
||||
double scrape_pos_ = 0.0;
|
||||
double refuel_pos_ = 0.0;
|
||||
float refuel_env_ = 0.0f;
|
||||
|
||||
// Lock-free SPSC command ring buffer (game thread -> audio thread)
|
||||
std::array<AudioCommand, kCmdQueueSize> cmd_ring_{};
|
||||
@@ -158,6 +164,9 @@ private:
|
||||
std::atomic<float> engine_speed_ratio_{0.0f};
|
||||
std::atomic<bool> engine_boosting_{false};
|
||||
std::atomic<float> scrape_amount_{0.0f};
|
||||
std::atomic<bool> pit_active_{false};
|
||||
std::atomic<bool> pit_charging_{false};
|
||||
std::atomic<float> pit_fill_ratio_{1.0f};
|
||||
};
|
||||
|
||||
} // namespace top_octane::audio
|
||||
Reference in new issue
Block a user