Unstable 0.1500.0.0
This commit is contained in:
+15
-1
@@ -12,8 +12,10 @@ namespace Barotrauma.Items.Components
|
||||
public enum WaveType
|
||||
{
|
||||
Pulse,
|
||||
Sawtooth,
|
||||
Sine,
|
||||
Square,
|
||||
Triangle,
|
||||
}
|
||||
|
||||
private float frequency;
|
||||
@@ -22,8 +24,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
[InGameEditable, Serialize(WaveType.Pulse, true, description: "What kind of a signal the item outputs." +
|
||||
" Pulse: periodically sends out a signal of 1." +
|
||||
" Sawtooth: sends out a periodic wave that increases linearly from 0 to 1." +
|
||||
" Sine: sends out a sine wave oscillating between -1 and 1." +
|
||||
" Square: sends out a signal that alternates between 0 and 1.", alwaysUseInstanceValues: true)]
|
||||
" Square: sends out a signal that alternates between 0 and 1." +
|
||||
" Triangle: sends out a wave that alternates between increasing linearly from -1 to 1 and decreasing from 1 to -1.",
|
||||
alwaysUseInstanceValues: true)]
|
||||
public WaveType OutputType
|
||||
{
|
||||
get;
|
||||
@@ -63,6 +68,10 @@ namespace Barotrauma.Items.Components
|
||||
phase -= pulseInterval;
|
||||
}
|
||||
break;
|
||||
case WaveType.Sawtooth:
|
||||
phase = (phase + deltaTime * frequency) % 1.0f;
|
||||
item.SendSignal(phase.ToString(CultureInfo.InvariantCulture), "signal_out");
|
||||
break;
|
||||
case WaveType.Square:
|
||||
phase = (phase + deltaTime * frequency) % 1.0f;
|
||||
item.SendSignal(phase < 0.5f ? "0" : "1", "signal_out");
|
||||
@@ -71,6 +80,11 @@ namespace Barotrauma.Items.Components
|
||||
phase = (phase + deltaTime * frequency) % 1.0f;
|
||||
item.SendSignal(Math.Sin(phase * MathHelper.TwoPi).ToString(CultureInfo.InvariantCulture), "signal_out");
|
||||
break;
|
||||
case WaveType.Triangle:
|
||||
phase = (phase + deltaTime * frequency) % 1.0f;
|
||||
float output = 4.0f * MathF.Abs(MathUtils.PositiveModulo(phase - 0.25f, 1.0f) - 0.5f) - 1.0f;
|
||||
item.SendSignal(output.ToString(CultureInfo.InvariantCulture), "signal_out");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user