From 8d996ff2bdfc3520abf91cd8d1d62fdc8cfa631f Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Mon, 15 Jan 2024 11:24:50 +0100 Subject: [PATCH 1/3] Bit media SFX Bit Media SFX --- src/bit-systems/media-loading.ts | 6 ++-- src/bit-systems/sfx-media-system.ts | 46 +++++++++++++++++++++++++++++ src/systems/hubs-systems.ts | 2 ++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/bit-systems/sfx-media-system.ts diff --git a/src/bit-systems/media-loading.ts b/src/bit-systems/media-loading.ts index da30d8806f..57c86b8bfb 100644 --- a/src/bit-systems/media-loading.ts +++ b/src/bit-systems/media-loading.ts @@ -162,10 +162,10 @@ export function* animateScale(world: HubsWorld, mediaLoaderEid: EntityID) { } function* finish(world: HubsWorld, mediaLoaderEid: EntityID) { + if (entityExists(world, mediaLoaderEid) && MediaLoader.flags[mediaLoaderEid] & MEDIA_LOADER_FLAGS.ANIMATE_LOAD) { + yield* animateScale(world, mediaLoaderEid); + } if (entityExists(world, mediaLoaderEid)) { - if (MediaLoader.flags[mediaLoaderEid] & MEDIA_LOADER_FLAGS.ANIMATE_LOAD) { - yield* animateScale(world, mediaLoaderEid); - } inflatePhysicsShape(world, mediaLoaderEid, { type: Shape.HULL, minHalfExtent: 0.04 diff --git a/src/bit-systems/sfx-media-system.ts b/src/bit-systems/sfx-media-system.ts new file mode 100644 index 0000000000..a615944151 --- /dev/null +++ b/src/bit-systems/sfx-media-system.ts @@ -0,0 +1,46 @@ +import { Not, defineQuery, enterQuery, exitQuery } from "bitecs"; +import { HubsWorld } from "../app"; +import { Deleting, MediaLoaded, MediaLoader, MediaLoading, Networked } from "../bit-components"; +import { SOUND_MEDIA_LOADED, SOUND_MEDIA_LOADING } from "../systems/sound-effects-system"; + +const loadingSounds = new Map(); +const mediaLoadingQuery = defineQuery([Networked, MediaLoader, MediaLoading, Not(Deleting)]); +const mediaLoadingEnterQuery = enterQuery(mediaLoadingQuery); +const mediaLoadingExitQuery = exitQuery(mediaLoadingQuery); +const mediaLoadedQuery = defineQuery([MediaLoaded]); +const mediaLoadedEnterQuery = enterQuery(mediaLoadedQuery); +const mediaLoadedExitQuery = exitQuery(mediaLoadedQuery); +export function sfxMediaSystem(world: HubsWorld, sfxSystem: any) { + mediaLoadingExitQuery(world).forEach(eid => { + if (loadingSounds.has(eid)) { + sfxSystem.stopPositionalAudio(loadingSounds.get(eid)); + loadingSounds.delete(eid); + } + }); + mediaLoadingEnterQuery(world).forEach(eid => { + if (loadingSounds.has(eid)) { + sfxSystem.stopPositionalAudio(loadingSounds.get(eid)); + loadingSounds.delete(eid); + } + if (Networked.owner[eid] === APP.getSid(NAF.clientId)) { + const obj = world.eid2obj.get(eid); + const audio = sfxSystem.playPositionalSoundFollowing(SOUND_MEDIA_LOADING, obj, true); + loadingSounds.set(eid, audio); + } + }); + mediaLoadedExitQuery(world).forEach(eid => { + if (loadingSounds.has(eid)) { + sfxSystem.stopPositionalAudio(loadingSounds.get(eid)); + loadingSounds.delete(eid); + } + }); + mediaLoadedEnterQuery(world).forEach(eid => { + if (loadingSounds.has(eid)) { + sfxSystem.stopPositionalAudio(loadingSounds.get(eid)); + loadingSounds.delete(eid); + } + const obj = world.eid2obj.get(eid); + const audio = sfxSystem.playPositionalSoundFollowing(SOUND_MEDIA_LOADED, obj, false); + loadingSounds.set(eid, audio); + }); +} diff --git a/src/systems/hubs-systems.ts b/src/systems/hubs-systems.ts index be7fc64c07..6f95ea6a02 100644 --- a/src/systems/hubs-systems.ts +++ b/src/systems/hubs-systems.ts @@ -82,6 +82,7 @@ import { loopAnimationSystem } from "../bit-systems/loop-animation"; import { linkSystem } from "../bit-systems/link-system"; import { objectMenuTransformSystem } from "../bit-systems/object-menu-transform-system"; import { bitPenCompatSystem } from "./bit-pen-system"; +import { sfxMediaSystem } from "../bit-systems/sfx-media-system"; declare global { interface Window { @@ -191,6 +192,7 @@ export function mainTick(xrFrame: XRFrame, renderer: WebGLRenderer, scene: Scene onOwnershipLost(world); sceneLoadingSystem(world, hubsSystems.environmentSystem, hubsSystems.characterController); mediaLoadingSystem(world); + sfxMediaSystem(world, aframeSystems["hubs-systems"].soundEffectsSystem); networkedTransformSystem(world); From e9ac511fb2d29d432285da5c95b9af7f2f9811ac Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Mon, 15 Jan 2024 11:29:06 +0100 Subject: [PATCH 2/3] Bit button SFX --- src/bit-systems/sfx-button-system.ts | 42 ++++++++++++++++++++++++++++ src/systems/hubs-systems.ts | 2 ++ 2 files changed, 44 insertions(+) create mode 100644 src/bit-systems/sfx-button-system.ts diff --git a/src/bit-systems/sfx-button-system.ts b/src/bit-systems/sfx-button-system.ts new file mode 100644 index 0000000000..b3050db7ee --- /dev/null +++ b/src/bit-systems/sfx-button-system.ts @@ -0,0 +1,42 @@ +import { defineQuery, enterQuery } from "bitecs"; +import { HubsWorld } from "../app"; +import { + HeldHandLeft, + HeldHandRight, + HeldRemoteLeft, + HeldRemoteRight, + HoldableButton, + HoverButton, + HoveredHandLeft, + HoveredHandRight, + HoveredRemoteLeft, + HoveredRemoteRight +} from "../bit-components"; +import { SOUND_HOVER_OR_GRAB } from "../systems/sound-effects-system"; + +const hoveredRemoteRightQuery = defineQuery([HoverButton, HoveredRemoteRight]); +const hoveredRemoteRightEnterQuery = enterQuery(hoveredRemoteRightQuery); +const hoveredRemoteLeftQuery = defineQuery([HoverButton, HoveredRemoteLeft]); +const hoveredRemoteLeftEnterQuery = enterQuery(hoveredRemoteLeftQuery); +const hoveredHandRightQuery = defineQuery([HoverButton, HoveredHandRight]); +const hoveredHandRightEnterQuery = enterQuery(hoveredHandRightQuery); +const hoveredHandLeftQuery = defineQuery([HoverButton, HoveredHandLeft]); +const hoveredHandLeftEnterQuery = enterQuery(hoveredHandLeftQuery); +const heldRemoteRightQuery = defineQuery([HoldableButton, HeldRemoteRight]); +const heldRemoteRightEnterQuery = enterQuery(heldRemoteRightQuery); +const heldRemoteLeftQuery = defineQuery([HoldableButton, HeldRemoteLeft]); +const heldRemoteLeftEnterQuery = enterQuery(heldRemoteLeftQuery); +const heldHandRightQuery = defineQuery([HoldableButton, HeldHandRight]); +const heldHandRightEnterQuery = enterQuery(heldHandRightQuery); +const heldHandLeftQuery = defineQuery([HoldableButton, HeldHandLeft]); +const heldHandLeftEnterQuery = enterQuery(heldHandLeftQuery); +export function sfxButtonSystem(world: HubsWorld, sfxSystem: any) { + hoveredRemoteRightEnterQuery(world).forEach(() => sfxSystem.playSoundOneShot(SOUND_HOVER_OR_GRAB)); + hoveredRemoteLeftEnterQuery(world).forEach(() => sfxSystem.playSoundOneShot(SOUND_HOVER_OR_GRAB)); + hoveredHandRightEnterQuery(world).forEach(() => sfxSystem.playSoundOneShot(SOUND_HOVER_OR_GRAB)); + hoveredHandLeftEnterQuery(world).forEach(() => sfxSystem.playSoundOneShot(SOUND_HOVER_OR_GRAB)); + heldRemoteRightEnterQuery(world).forEach(() => sfxSystem.playSoundOneShot(SOUND_HOVER_OR_GRAB)); + heldRemoteLeftEnterQuery(world).forEach(() => sfxSystem.playSoundOneShot(SOUND_HOVER_OR_GRAB)); + heldHandRightEnterQuery(world).forEach(() => sfxSystem.playSoundOneShot(SOUND_HOVER_OR_GRAB)); + heldHandLeftEnterQuery(world).forEach(() => sfxSystem.playSoundOneShot(SOUND_HOVER_OR_GRAB)); +} diff --git a/src/systems/hubs-systems.ts b/src/systems/hubs-systems.ts index 6f95ea6a02..3080057bcb 100644 --- a/src/systems/hubs-systems.ts +++ b/src/systems/hubs-systems.ts @@ -82,6 +82,7 @@ import { loopAnimationSystem } from "../bit-systems/loop-animation"; import { linkSystem } from "../bit-systems/link-system"; import { objectMenuTransformSystem } from "../bit-systems/object-menu-transform-system"; import { bitPenCompatSystem } from "./bit-pen-system"; +import { sfxButtonSystem } from "../bit-systems/sfx-button-system"; import { sfxMediaSystem } from "../bit-systems/sfx-media-system"; declare global { @@ -201,6 +202,7 @@ export function mainTick(xrFrame: XRFrame, renderer: WebGLRenderer, scene: Scene interactionSystem(world, hubsSystems.cursorTargettingSystem, t, aframeSystems); buttonSystems(world); + sfxButtonSystem(world, aframeSystems["hubs-systems"].soundEffectsSystem); physicsCompatSystem(world, hubsSystems.physicsSystem); hubsSystems.physicsSystem.tick(dt); From c3ed1289b8225c66ca33f4ee7af906d7ecf050e2 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Mon, 15 Jan 2024 11:29:18 +0100 Subject: [PATCH 3/3] Mic toggle SFX --- src/react-components/room/hooks/useMicrophoneStatus.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/react-components/room/hooks/useMicrophoneStatus.js b/src/react-components/room/hooks/useMicrophoneStatus.js index 11692bf643..74e77b2b34 100644 --- a/src/react-components/room/hooks/useMicrophoneStatus.js +++ b/src/react-components/room/hooks/useMicrophoneStatus.js @@ -1,5 +1,6 @@ import { useState, useEffect, useCallback } from "react"; import { MediaDevices, MediaDevicesEvents } from "../../../utils/media-devices-utils"; +import { SOUND_TOGGLE_MIC } from "../../../systems/sound-effects-system"; export function useMicrophoneStatus(scene) { const mediaDevicesManager = APP.mediaDevicesManager; @@ -45,7 +46,8 @@ export function useMicrophoneStatus(scene) { } else { mediaDevicesManager.startMicShare({ unmute: true }); } - }, [mediaDevicesManager]); + scene.systems["hubs-systems"].soundEffectsSystem.playSoundOneShot(SOUND_TOGGLE_MIC); + }, [mediaDevicesManager, scene]); return { isMicMuted,