Skip to content

Commit

Permalink
Web: Periodic audio updates (10 Hz default)
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Mar 15, 2024
1 parent bbd0cf9 commit efe7af2
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 116 deletions.
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1353,11 +1353,13 @@ if(BUILD_FOR_WEB)
endif()

if(GENERATE_DEBUG_INFORMATION)
set(ADDITIONAL_WEB_FLAGS "${ADDITIONAL_WEB_FLAGS} -g")
set(ADDITIONAL_WEB_FLAGS "${ADDITIONAL_WEB_FLAGS} -g -gsource-map")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sSAFE_HEAP=1 -sSTACK_OVERFLOW_CHECK=2 -Wno-limited-postlink-optimizations")
set(STACK_SIZE "64MB")
set(STACK_SIZE "32MB")
set(INITIAL_MEMORY "1800MB")
else()
set(STACK_SIZE "16MB")
set(INITIAL_MEMORY "1024MB")
endif()

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sALLOW_BLOCKING_ON_MAIN_THREAD=1")
Expand All @@ -1366,7 +1368,7 @@ if(BUILD_FOR_WEB)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s STACK_SIZE=${STACK_SIZE}")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread -s USE_PTHREADS=1 -sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s INITIAL_MEMORY=1500MB")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s INITIAL_MEMORY=${INITIAL_MEMORY}")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mbulk-memory")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ADDITIONAL_WEB_FLAGS}")
Expand Down
8 changes: 6 additions & 2 deletions src/application/gui/settings_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,13 @@ void settings_gui_state::perform(
{
auto& scope_cfg = config.sound;

#if !IS_PRODUCTION_BUILD
revertable_enum_radio(SCOPE_CFG_NVP(processing_frequency));
#endif

if (scope_cfg.processing_frequency == sound_processing_frequency::PERIODIC) {
auto indent = scoped_indent();

revertable_slider("Hz", scope_cfg.custom_processing_frequency, 1, 60);
}

revertable_slider(SCOPE_CFG_NVP(max_simultaneous_bullet_trace_sounds), 0, 20);
revertable_slider(SCOPE_CFG_NVP(max_short_sounds), 0, static_cast<int>(SOUNDS_SOURCES_IN_POOL));
Expand Down
6 changes: 3 additions & 3 deletions src/game/stateless_systems/item_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void maybe_reload_akimbo(components::item_slot_transfers& transfers, const T& ca

auto& cosm = capability.get_cosmos();

LOG("Resetting akimbo in maybe_reload_akimbo");
RLD_LOG("Resetting akimbo in maybe_reload_akimbo");
akimbo = {};

if (ctx.alive(cosm)) {
Expand All @@ -123,11 +123,11 @@ void maybe_reload_akimbo(components::item_slot_transfers& transfers, const T& ca
LOG_NVPS(next_to_reload_idx, akimbo.next);
}
else {
LOG("No two guns found to consider for akimbo");
RLD_LOG("No two guns found to consider for akimbo");
}
}
else {
LOG("No context found to consider for akimbo extension");
RLD_LOG("No context found to consider for akimbo extension");
}
}

Expand Down
153 changes: 102 additions & 51 deletions src/view/audiovisual_state/audiovisual_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "game/detail/visible_entities.hpp"
#include "game/detail/sentience/sentience_getters.h"
#include "view/damage_indication_settings.h"
//#include "augs/log.h"

template <class E>
void interpolation_system::set_updated_interpolated_transform(
Expand Down Expand Up @@ -70,8 +71,8 @@ void audiovisual_state::advance(const audiovisual_advance_input input) {

auto scaled_state_dt = state_dt;

auto dt = frame_dt;
dt *= input.speed_multiplier;
auto scaled_frame_dt = frame_dt;
scaled_frame_dt *= input.speed_multiplier;

if (scaled_state_dt) {
*scaled_state_dt *= input.speed_multiplier;
Expand Down Expand Up @@ -102,14 +103,14 @@ void audiovisual_state::advance(const audiovisual_advance_input input) {
cone_for_explosion_particles,
cosm.get_common_assets(),
input.particle_effects,
dt,
scaled_frame_dt,
input.performance.special_effects.explosions,
particles
);
};

auto advance_attenuation_variations = [&]() {
get<light_system>().advance_attenuation_variations(rng, cosm, dt);
get<light_system>().advance_attenuation_variations(rng, cosm, scaled_frame_dt);
};

auto advance_world_hover_highlighter = [&]() {
Expand All @@ -118,15 +119,15 @@ void audiovisual_state::advance(const audiovisual_advance_input input) {
};

auto advance_thunders = [&]() {
thunders.advance(rng, cosm, queried_cone, input.particle_effects, dt, particles);
thunders.advance(rng, cosm, queried_cone, input.particle_effects, scaled_frame_dt, particles);
};

auto advance_damage_indication = [&]() {
damage_indication.advance(input.damage_indication, dt);
damage_indication.advance(input.damage_indication, scaled_frame_dt);
};

auto advance_highlights = [&]() {
highlights.advance(dt);
highlights.advance(scaled_frame_dt);
};

auto advance_visible_particle_streams = [&]() {
Expand All @@ -139,7 +140,7 @@ void audiovisual_state::advance(const audiovisual_advance_input input) {
cosm,
input.particle_effects,
anims,
dt,
scaled_frame_dt,
interp
);
};
Expand All @@ -158,15 +159,15 @@ void audiovisual_state::advance(const audiovisual_advance_input input) {

advance_damage_indication();

randomizing.advance(dt);
randomizing.advance(scaled_frame_dt);
};

auto launch_particle_jobs = [&]() {
auto scope = measure_scope(performance.integrate_particles);

particles.integrate_and_draw_all_particles({
cosm,
dt,
scaled_frame_dt,
interp,
input.game_images,
anims,
Expand Down Expand Up @@ -218,10 +219,10 @@ void audiovisual_state::advance(const audiovisual_advance_input input) {
[&](const auto typed_wandering_pixels) {
const auto wandering_id = typed_wandering_pixels.get_id();

auto job = [&cosm, &triangles, current_index, &wandering_pixels, &game_images, wandering_id, dt]() {
auto job = [&cosm, &triangles, current_index, &wandering_pixels, &game_images, wandering_id, scaled_frame_dt]() {
auto handle = cosm[wandering_id];

wandering_pixels.advance_for(handle, dt);
wandering_pixels.advance_for(handle, scaled_frame_dt);
draw_wandering_pixels_as_sprites(triangles, current_index, wandering_pixels, handle, game_images);
};

Expand Down Expand Up @@ -255,10 +256,10 @@ void audiovisual_state::advance(const audiovisual_advance_input input) {
[&](const auto typed_wandering_pixels) {
const auto wandering_id = typed_wandering_pixels.get_id();

auto job = [&cosm, &triangles, current_index, &wandering_pixels, &game_images, wandering_id, dt]() {
auto job = [&cosm, &triangles, current_index, &wandering_pixels, &game_images, wandering_id, scaled_frame_dt]() {
auto handle = cosm[wandering_id];

wandering_pixels.advance_for(handle, dt);
wandering_pixels.advance_for(handle, scaled_frame_dt);
draw_wandering_pixels_as_sprites(triangles, current_index, wandering_pixels, handle, game_images);
};

Expand All @@ -274,49 +275,38 @@ void audiovisual_state::advance(const audiovisual_advance_input input) {

const auto& sound_freq = input.sound_settings.processing_frequency;
const bool sound_every_step = sound_freq == sound_processing_frequency::EVERY_SIMULATION_STEP;
const bool sound_periodic = sound_freq == sound_processing_frequency::PERIODIC;
const auto sound_processing_frequency = std::max(1, input.sound_settings.custom_processing_frequency);

const auto chosen_update_dt = sound_every_step ? *scaled_state_dt : dt;
const auto periodic_dt = augs::delta::steps_per_second(sound_processing_frequency);
auto scaled_periodic_dt = periodic_dt;
scaled_periodic_dt *= input.speed_multiplier;

/* Fading should take the same amount of time regardless of audiovisual speed multiplier */
const auto chosen_fade_dt = sound_every_step ? *state_dt : frame_dt;

auto audio_job = [this, input, chosen_update_dt, chosen_fade_dt]() {
auto scope = measure_scope(performance.sound_logic);
const auto chosen_update_dt = [&]() {
if (sound_every_step) {
return *scaled_state_dt;
}

const auto viewed_character = input.camera.viewed_character;
auto& interpol = this->get<interpolation_system>();
if (sound_periodic) {
return scaled_periodic_dt;
}

auto& command_buffers = input.command_buffers;
return scaled_frame_dt;
}();

{
auto ear = input.camera;
/* Fading should take the same amount of time regardless of audiovisual speed multiplier */

if (viewed_character) {
ear.cone.eye.transform = viewed_character.get_viewing_transform(interpol);
}

this->get<sound_system>().update_sound_properties(
{
*input.audio_renderer,
this->get<sound_system>(),
input.audio_volume,
input.sound_settings,
input.sounds,
interpol,
ear,
ear.cone,
chosen_update_dt,
input.speed_multiplier,
input.inv_tickrate,
input.interpolation_ratio
}
);
const auto chosen_fade_dt = [&]() {
if (sound_every_step) {
return *state_dt;
}

this->get<sound_system>().fade_sources(*input.audio_renderer, chosen_fade_dt);
if (sound_periodic) {
return periodic_dt;
}

command_buffers.submit_write_buffer();
};
return frame_dt;
}();

synchronous_facade();

Expand All @@ -332,16 +322,74 @@ void audiovisual_state::advance(const audiovisual_advance_input input) {
return true;
}

if (sound_freq == sound_processing_frequency::PERIODIC) {
if (input.sound_settings.custom_processing_frequency <= 0) {
return false;
}

const auto interval = 1.0f / input.sound_settings.custom_processing_frequency;

if (periodic_audio_update_timer.get<std::chrono::seconds>() >= interval) {
periodic_audio_update_timer.reset();

return true;
}

return false;
}

if (sound_every_step) {
return input.new_state_delta.has_value();
}

return false;
}();

if (should_update_audio) {
input.pool.enqueue(audio_job);
}
auto audio_job = [this, should_update_audio, input, chosen_update_dt, chosen_fade_dt, scaled_frame_dt]() {
auto scope = measure_scope(performance.sound_logic);

if (should_update_audio) {
const auto viewed_character = input.camera.viewed_character;
auto& interpol = this->get<interpolation_system>();

{
auto ear = input.camera;

if (viewed_character) {
ear.cone.eye.transform = viewed_character.get_viewing_transform(interpol);
}

this->get<sound_system>().update_sound_properties(
{
*input.audio_renderer,
this->get<sound_system>(),
input.audio_volume,
input.sound_settings,
input.sounds,
interpol,
ear,
ear.cone,
chosen_update_dt,
input.speed_multiplier,
input.inv_tickrate,
input.interpolation_ratio
}
);
}

this->get<sound_system>().fade_sources(*input.audio_renderer, chosen_fade_dt);
}

this->get<sound_system>().update_elapsed_times(
scaled_frame_dt
);

if (input.audio_renderer != nullptr) {
input.command_buffers.submit_write_buffer();
}
};

input.pool.enqueue(audio_job);
}

void audiovisual_state::spread_past_infection(const const_logic_step step) {
Expand Down Expand Up @@ -481,6 +529,9 @@ void audiovisual_state::standard_post_solve(
}
);
}
else {
//LOG("NO AUDIO RENDERER!");
}
}


Expand Down
4 changes: 4 additions & 0 deletions src/view/audiovisual_state/audiovisual_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "view/audiovisual_state/particle_triangle_buffers.h"
#include "application/performance_settings.h"
#include "view/character_camera.h"
#include "augs/misc/timing/timer.h"

class cosmos;
class visible_entities;
Expand Down Expand Up @@ -103,6 +104,9 @@ struct audiovisual_state {
void reserve_caches_for_entities(const std::size_t);

private:

augs::timer periodic_audio_update_timer;

randomization& get_rng() {
return randomizing.rng;
}
Expand Down
Loading

0 comments on commit efe7af2

Please sign in to comment.