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;
}
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));
}
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;
}
};
}
Aggregations