-
Notifications
You must be signed in to change notification settings - Fork 340
feat(balance): Sound handling overhaul #7028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Retagin
wants to merge
12
commits into
cataclysmbnteam:main
Choose a base branch
from
Retagin:Sound-overhaul-testing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+4,235
−1,404
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Does not include JSON updates/changes.
4 tasks
scarf005
reviewed
Aug 20, 2025
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( "" ) ); |
There was a problem hiding this comment.
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 has formatted code style violation in this PR. I edit commits locally (e.g: git, github desktop) and want to keep autofix
I do not want the automated commit
If you don't do this, your following commits will be based on the old commit, and cause MERGE CONFLICT. |
scarf005
reviewed
Aug 20, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
closes #1234in Summary of the PR so it can be closed automatically.mainso it won't cause conflict when updatingmainbranch later.