Skip to content

Conversation

@Retagin
Copy link
Contributor

@Retagin Retagin commented Aug 19, 2025

DRAFT PR DO NOT MERGE UNTIL UPDATED TO BE COMPATIBLE WITH MAIN

Purpose of change (The Why)

Game handles sound in a very calc intensive way if more than a few monsters or NPCs are inside the reality bubble.
Sounds are handled in tiles, and the way that the volume of explosions or high damage/range gun sounds are calced means that a .30-07 anywhere on the current z-level or a landmine going off anywhere within the reality bubble will automatically deafen any character.

Sound volume is very inconsistent, with several very different philosophies as to volume magnitude. Sometimes volume is sorta equivalent to real life dB, sometimes it is just a vauge tile amount. A huge explosion is counted as sound 15 and above, generic landmines put out 6000 sound, flashbangs have 14 sound, and hulks walking is something like 15? sound.

Sounds decay linearly with distance, and there is a significant increase in the number of calcs required for each sound added to inform monsters/npcs.

NPCs react to sounds every time the player takes an action, which includes making LOS checks to the player.
Monsters have code to let them attempt to follow sounds for more than one turn, but this is not effectively used. Monster wander_to positions are re-written potentially 10 times a turn, and whichever random sound was checked last is used.

Describe the solution (The How)

Complete overhaul of sound system to use consistent measurement (dB spl)

terrain sound absorbtion value put into map::level_cache, along with function to zero and generate it on game start and terrain update.
Sounds are "flood filled" to build out sound_caches, game stores a vector of these. Sound volume decreases with distance roughly following the inverse square law, with additional losses from terrain sound absorbtion as applicable.

Monsters, NPCs, and the player avatar all reference this vector to pull the tile specific volume of various sounds.
Monsters get fed the loudest valid sound in their tile, and check to see if it is more interesting than their current wander_to sound.
NPCs each get fed a filtered set of sounds, only react to sounds once per turn, and have a few optimizations in their code to hopefully improve performance.
The PC gets sounds as per normal.

sound_caches are culled twice per turn, and are valid for culling if they have been heard both by monsters and by the player. This is tracked with a pair of bools per cache.

Sound values for hard-coded functions updated to new system.

Describe alternatives you've considered

Just capping sound at something reasonable and getting my sleepless nights back.
Doing an equivalent to a lightcast but using the terrain absorption values with a straight line cast.
Using an adaptation of the old system moved to polar coordinates, with some math shenanagins to improve performance.

Testing

Updating to main, correcting bugs, then testing.

Additional context

This was all because I just wanted gun volume to not be wackadoodle and for silencers + subsonic ammo to actually do something.

Checklist

Mandatory

Does not include JSON updates/changes.
@github-actions github-actions bot added the src changes related to source code. label Aug 19, 2025
@scarf005 scarf005 requested a review from OrenAudeles August 20, 2025 00:15
src/sounds.h Outdated
Comment on lines 64 to 73
void sound( const tripoint &p, short vol, sound_t category, const std::string &description,
bool movement_noise = false, bool from_player = false, bool from_monster = false,
bool from_npc = false, const std::string &id = "",
const std::string &variant = "default", const faction_id faction = faction_id( "no_faction" ),
const mfaction_str_id monfaction = mfaction_str_id( "" ) );
void sound( const tripoint &p, short vol, sound_t category, const translation &description,
bool movement_noise = false, bool from_player = false, bool from_monster = false,
bool from_npc = false, const std::string &id = "",
const std::string &variant = "default", const faction_id faction = faction_id( "no_faction" ),
const mfaction_str_id monfaction = mfaction_str_id( "" ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is getting really large, i'd suggest making it just accept existing sound_event struct:

sound::sound({ .vol = 100, /* ... */  }); 

@autofix-ci
Copy link
Contributor

autofix-ci bot commented Aug 20, 2025

Autofix has formatted code style violation in this PR.

I edit commits locally (e.g: git, github desktop) and want to keep autofix
  1. Run git pull. this will merge the automated commit into your local copy of the PR branch.
  2. Continue working.
I do not want the automated commit
  1. Format your code locally, then commit it.
  2. Run git push --force to force push your branch. This will overwrite the automated commit on remote with your local one.
  3. Continue working.

If you don't do this, your following commits will be based on the old commit, and cause MERGE CONFLICT.

Should have been gitignored, but autofix screams into the void.
Updates sounds::sound to take a sound_event
Merged all sound methods to use this
A few minor bug fixes
@github-actions github-actions bot added the JSON related to game datas in JSON format. label Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

JSON related to game datas in JSON format. src changes related to source code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants