use of io.xol.chunkstories.api.sound.SoundSource in project chunkstories by Hugobros3.
the class PacketSoundSource method process.
@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
String soundName = in.readUTF();
long UUID = in.readLong();
boolean hasPosition = in.readBoolean();
Vector3dc position = null;
if (hasPosition) {
position = new Vector3d(in.readFloat(), in.readFloat(), in.readFloat());
}
// boolean loop = in.readBoolean();
// boolean isAmbient = in.readBoolean();
// boolean buffered = in.readBoolean();
byte modeByte = in.readByte();
Mode mode = Mode.values()[modeByte];
boolean stopped = in.readBoolean();
float pitch = in.readFloat();
float gain = in.readFloat();
float attenuationStart = in.readFloat();
float attenuationEnd = in.readFloat();
if (!(processor instanceof ClientPacketsProcessor))
return;
ClientPacketsProcessor cpe = (ClientPacketsProcessor) processor;
SoundSource soundSource = cpe.getContext().getSoundManager().getSoundSourceByUUID(UUID);
// ALSoundSource soundSource = (ALSoundSource) Client.getInstance().getSoundManager().getSoundSourceByUUID(UUID);
if (soundSource == null && stopped)
return;
if (soundSource == null) {
soundSource = cpe.getContext().getSoundManager().replicateServerSoundSource(soundName, mode, position, pitch, gain, attenuationStart, attenuationEnd, UUID);
return;
}
if (stopped) {
soundSource.stop();
return;
}
// Update the soundSource with all we can
soundSource.setPosition(position);
soundSource.setPitch(pitch);
soundSource.setGain(gain);
soundSource.setAttenuationStart(attenuationStart);
soundSource.setAttenuationEnd(attenuationEnd);
}
use of io.xol.chunkstories.api.sound.SoundSource 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;
}
};
}
use of io.xol.chunkstories.api.sound.SoundSource in project chunkstories by Hugobros3.
the class ALSoundManager method removeUnplayingSources.
int removeUnplayingSources() {
int j = 0;
Iterator<ALSoundSource> i = playingSoundSources.iterator();
while (i.hasNext()) {
SoundSource soundSource = i.next();
if (soundSource.isDonePlaying()) {
soundSource.stop();
i.remove();
j++;
}
}
return j;
}
Aggregations