Standardize setters in NativeAudioSource.

These setters now: (1) start by checking if anything changed, (2) use the new value in calculations, and (3) perform the assignment only at the end.
This commit is contained in:
player-03
2022-01-07 19:02:43 -05:00
committed by GitHub
parent 809ba2fd0c
commit f46ed3dc7e

View File

@@ -386,6 +386,11 @@ class NativeAudioSource
public function setCurrentTime(value:Int):Int
{
if (value == getCurrentTime())
{
return value;
}
if (handle != null)
{
if (stream)
@@ -424,7 +429,7 @@ class NativeAudioSource
timer.stop();
}
var timeRemaining = Std.int((getLength() - getCurrentTime()) / getPitch());
var timeRemaining = Std.int((getLength() - value) / getPitch());
if (timeRemaining > 0)
{
@@ -483,7 +488,7 @@ class NativeAudioSource
timer.stop();
}
var timeRemaining = Std.int((getLength() - getCurrentTime()) / getPitch());
var timeRemaining = Std.int((value - getCurrentTime()) / getPitch());
if (timeRemaining > 0)
{
@@ -512,16 +517,14 @@ class NativeAudioSource
public function setPitch(value:Float):Float
{
AL.sourcef(handle, AL.PITCH, value);
if (playing)
if (playing && value != getPitch())
{
if (timer != null)
{
timer.stop();
}
var timeRemaining = Std.int((getLength() - getCurrentTime()) / getPitch());
var timeRemaining = Std.int((getLength() - getCurrentTime()) / value);
if (timeRemaining > 0)
{
@@ -530,7 +533,9 @@ class NativeAudioSource
}
}
return getPitch();
AL.sourcef(handle, AL.PITCH, value);
return value;
}
public function getPosition():Vector4