Search in sources :

Example 1 with SoundSourceVirtual

use of io.xol.chunkstories.sound.source.SoundSourceVirtual in project chunkstories by Hugobros3.

the class VirtualSoundManager method playSoundEffect.

@Override
public SoundSource playSoundEffect(String soundEffect, Mode mode, Vector3dc position, float pitch, float gain, float attStart, float attEnd) {
    SoundSourceVirtual soundSource = new SoundSourceVirtual(VirtualSoundManager.this, soundEffect, mode, position, pitch, gain, attStart, attEnd);
    // Play the sound effect for everyone
    addSourceToEveryone(soundSource, null);
    return soundSource;
}
Also used : SoundSourceVirtual(io.xol.chunkstories.sound.source.SoundSourceVirtual)

Example 2 with SoundSourceVirtual

use of io.xol.chunkstories.sound.source.SoundSourceVirtual in project chunkstories by Hugobros3.

the class VirtualSoundManager method addSourceToEveryone.

private void addSourceToEveryone(SoundSourceVirtual soundSource, ServerPlayerVirtualSoundManager exceptHim) {
    // Create the sound creation packet
    PacketSoundSource packet = new PacketSoundSource(worldServer, soundSource);
    Iterator<ServerPlayerVirtualSoundManager> i = playersSoundManagers.iterator();
    while (i.hasNext()) {
        ServerPlayerVirtualSoundManager playerSoundManager = i.next();
        // Send it to all players than could hear it
        if (exceptHim == null || !playerSoundManager.equals(exceptHim)) {
            if (!playerSoundManager.couldHearSource(soundSource))
                continue;
            // Creates the soundSource and adds it weakly to the player's list
            playerSoundManager.serverPlayer.pushPacket(packet);
            // TODO maybe not relevant since for updating we iterate over all players then do a distance check
            playerSoundManager.addSourceToPlayer(soundSource);
        }
    }
    allPlayingSoundSources.add(new WeakReference<SoundSourceVirtual>(soundSource));
}
Also used : PacketSoundSource(io.xol.chunkstories.net.packets.PacketSoundSource) SoundSourceVirtual(io.xol.chunkstories.sound.source.SoundSourceVirtual)

Example 3 with SoundSourceVirtual

use of io.xol.chunkstories.sound.source.SoundSourceVirtual in project chunkstories by Hugobros3.

the class VirtualSoundManager method getAllPlayingSounds.

@Override
public Iterator<SoundSource> getAllPlayingSounds() {
    return new Iterator<SoundSource>() {

        Iterator<WeakReference<SoundSourceVirtual>> iterator = allPlayingSoundSources.iterator();

        SoundSource next = null;

        @Override
        public boolean hasNext() {
            if (next != null)
                return true;
            while (iterator.hasNext() && next == null) {
                WeakReference<SoundSourceVirtual> weakReference = iterator.next();
                SoundSourceVirtual soundSource = weakReference.get();
                if (soundSource == null || soundSource.isDonePlaying()) {
                    iterator.remove();
                    continue;
                }
                next = soundSource;
            }
            return false;
        }

        @Override
        public SoundSource next() {
            if (next == null)
                hasNext();
            SoundSource oldNext = next;
            next = null;
            return oldNext;
        }
    };
}
Also used : PacketSoundSource(io.xol.chunkstories.net.packets.PacketSoundSource) SoundSource(io.xol.chunkstories.api.sound.SoundSource) SoundSourceVirtual(io.xol.chunkstories.sound.source.SoundSourceVirtual) Iterator(java.util.Iterator)

Aggregations

SoundSourceVirtual (io.xol.chunkstories.sound.source.SoundSourceVirtual)3 PacketSoundSource (io.xol.chunkstories.net.packets.PacketSoundSource)2 SoundSource (io.xol.chunkstories.api.sound.SoundSource)1 Iterator (java.util.Iterator)1