Skip to content

Commit

Permalink
Fix scene audio mesh may play sound even when hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarabol committed Jan 3, 2025
1 parent 346d596 commit cb916a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ Rock Raiders Web is an experiment aimed at recreating Rock Raiders PC game (1999

### Cosmetics

- One can hear rockies snoring behind walls in Level17
- Add rotation speed to entities and play turnLeft, turnRight animations
- Advisor not shown in tutorials near icon panel
- Surface object pointer in tutorials removes surface highlight color as in original
Expand Down
13 changes: 11 additions & 2 deletions src/scene/SceneAudioMesh.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PositionalAudio } from 'three'
import { Object3D, PositionalAudio } from 'three'
import { SaveGameManager } from '../resource/SaveGameManager'
import { SoundManager } from '../audio/SoundManager'
import { SceneMesh } from './SceneMesh'
Expand All @@ -10,7 +10,7 @@ export class SceneAudioMesh extends SceneMesh {

update(elapsedMs: number) {
const sfxVolume = SaveGameManager.getSfxVolume()
if (sfxVolume <= 0) return
if (sfxVolume <= 0 || !this.isVisible()) return
const sfxName = this.userData.sfxNameAnimation || ''
if (!sfxName || (this.lastSfxName === sfxName && this.audioNode?.isPlaying)) return
this.lastSfxName = sfxName
Expand All @@ -31,6 +31,15 @@ export class SceneAudioMesh extends SceneMesh {
SoundManager.playingAudio.add(this.audioNode)
}

private isVisible(): boolean {
if (!this.visible) return false
let parent: Object3D = this.parent
while (parent?.visible) {
parent = parent.parent
}
return !!parent?.visible
}

dispose() {
SoundManager.stopAudio(this.audioNode)
this.lastSfxName = ''
Expand Down

1 comment on commit cb916a3

@Unrud
Copy link
Contributor

@Unrud Unrud commented on cb916a3 Jan 6, 2025

Choose a reason for hiding this comment

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

isVisible() always returns false. Either parent is null or parent.visible is false at the end.

Please sign in to comment.