Skip to content
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

Vehicles hear exterior audio #4815

Merged
merged 2 commits into from
Nov 6, 2023

Conversation

Doubleumc
Copy link
Contributor

@Doubleumc Doubleumc commented Oct 31, 2023

About the pull request

As described in issue #4777 while vehicle interiors are intended to hear external sounds, it is largely nonfunctional. Sounds are either not heard or are inaudibly quiet. This is due to several smaller issues working together.

First, interiors are not detected as interiors. In commit 0808500 the types stored in the used_turfs list were changed to weakrefs, but the is_interior() function still checked for the old type, causing it to always return FALSE:

var/datum/turf_reservation/interior/reservation = SSmapping.used_turfs[loc]
if(!istype(reservation))
return FALSE
return TRUE

Fixed by checking for the correct type.

Second, the get_interior_by_coords() function returned an object on success, but returned FALSE on failure - which still counted as an object. Since shuttles add turfs to used_turfs but don't have actual interiors, they would pass is_interior() but fail get_interior_by_coords(). The sound code expected any object received at this point to be valid, but using FALSE would thrown an error:

if(SSinterior.in_interior(turf_source))
var/datum/interior/VI = SSinterior.get_interior_by_coords(turf_source.x, turf_source.y, turf_source.z)
if(VI?.ready)

Fixed by returning null on failure.

Third, the audio was now playing but in the wrong part of the interior. It was offset to the top-right corner because get_middle_coords() got the difference between the bounds, but never actually averaged them:

return list(Floor(min[1] + (max[1] - min[1])), Floor(min[2] + (max[2] - min[2])), min[3])

Fixed by dividing the difference by two.

Fourth, the sound playback zone was oriented incorrectly because the width and height were transposed when creating the zone. Rectangles were defined as width then height, but the sound subsystem was passing height then width:

hearers |= SSquadtree.players_in_range(RECT(bounds[1], bounds[2], VI.map_template.height, VI.map_template.width), bounds[3])

Fixed by passing width then height.

Explain why it's good for the game

Vehicle interiors were intended to hear external sounds. This restores that functionality.

Testing Photographs and Procedure

Screenshots & Videos

Put screenshots and videos here with an empty line between the screenshots and the <details> tags.

Changelog

🆑
fix: vehicle interiors can hear exterior noises
/:cl:

@Doubleumc Doubleumc requested a review from fira as a code owner October 31, 2023 21:56
@github-actions github-actions bot added the Fix Fix one bug, make ten more label Oct 31, 2023
@fira
Copy link
Member

fira commented Nov 1, 2023

What do you mean by "FALSE is still counted as an object" ? FALSE is literally 0 which is falsey, this shouldn't change anything for the purposes of what's done here

@Zonespace27 Zonespace27 added the Testmerge Candidate we'll test this while you're asleep and the server has 10 players label Nov 1, 2023
@Doubleumc
Copy link
Contributor Author

I might be using the wrong words here. What I mean is the sound code takes the return of get_interior_by_coords() (VI), checks if it exists (VI?), and uses the ready var from it (VI?.ready):

var/datum/interior/VI = SSinterior.get_interior_by_coords(turf_source.x, turf_source.y, turf_source.z)
if(VI?.ready)

It doesn't check if its TRUE or FALSE, it checks if it exists or not. And FALSE/0 exists, but can't be used in this way:
image

Copy link
Member

@harryob harryob left a comment

Choose a reason for hiding this comment

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

works for me, thanks for the fix

code/controllers/subsystem/interior.dm Outdated Show resolved Hide resolved
@harryob harryob added this pull request to the merge queue Nov 6, 2023
Merged via the queue into cmss13-devs:master with commit 8e7909d Nov 6, 2023
26 checks passed
cm13-github added a commit that referenced this pull request Nov 6, 2023
@Doubleumc Doubleumc deleted the vehicle-exterior-audio branch November 6, 2023 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Fix one bug, make ten more Testmerge Candidate we'll test this while you're asleep and the server has 10 players
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants