v0.8.2a: adjusted sync checks in Sample to fix hitching
This commit is contained in:
@@ -116,7 +116,7 @@ public enum Sample {
|
|||||||
float pitch;
|
float pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashSet<DelayedSoundEffect> delayedSFX = new HashSet<>();
|
private static final HashSet<DelayedSoundEffect> delayedSFX = new HashSet<>();
|
||||||
|
|
||||||
public void playDelayed( Object id, float delay ){
|
public void playDelayed( Object id, float delay ){
|
||||||
playDelayed( id, delay, 1 );
|
playDelayed( id, delay, 1 );
|
||||||
@@ -130,7 +130,7 @@ public enum Sample {
|
|||||||
playDelayed( id, delay, volume, volume, pitch );
|
playDelayed( id, delay, volume, volume, pitch );
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void playDelayed( Object id, float delay, float leftVolume, float rightVolume, float pitch ) {
|
public void playDelayed( Object id, float delay, float leftVolume, float rightVolume, float pitch ) {
|
||||||
if (delay <= 0) {
|
if (delay <= 0) {
|
||||||
play(id, leftVolume, rightVolume, pitch);
|
play(id, leftVolume, rightVolume, pitch);
|
||||||
return;
|
return;
|
||||||
@@ -141,10 +141,13 @@ public enum Sample {
|
|||||||
sfx.leftVol = leftVolume;
|
sfx.leftVol = leftVolume;
|
||||||
sfx.rightVol = rightVolume;
|
sfx.rightVol = rightVolume;
|
||||||
sfx.pitch = pitch;
|
sfx.pitch = pitch;
|
||||||
|
synchronized (delayedSFX) {
|
||||||
delayedSFX.add(sfx);
|
delayedSFX.add(sfx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void update(){
|
public void update(){
|
||||||
|
synchronized (delayedSFX) {
|
||||||
if (delayedSFX.isEmpty()) return;
|
if (delayedSFX.isEmpty()) return;
|
||||||
for (DelayedSoundEffect sfx : delayedSFX.toArray(new DelayedSoundEffect[0])) {
|
for (DelayedSoundEffect sfx : delayedSFX.toArray(new DelayedSoundEffect[0])) {
|
||||||
sfx.delay -= Game.elapsed;
|
sfx.delay -= Game.elapsed;
|
||||||
@@ -154,6 +157,7 @@ public enum Sample {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void enable( boolean value ) {
|
public void enable( boolean value ) {
|
||||||
enabled = value;
|
enabled = value;
|
||||||
|
|||||||
Reference in New Issue
Block a user