Skip to content

Commit c5bd8ed

Browse files
committed
Refactor extensions to not use closures to reduce GC allocations
1 parent afa744a commit c5bd8ed

File tree

98 files changed

+1268
-1048
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1268
-1048
lines changed

Runtime/Delegates.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
namespace Zigurous.Tweening
22
{
33
/// <summary>
4-
/// A function delegate that gets the current value of a parameter from a
5-
/// source object.
4+
/// A function delegate that gets the current value of a parameter from an
5+
/// object.
66
/// </summary>
7-
/// <typeparam name="S">The type of the source object.</typeparam>
8-
/// <typeparam name="T">The type of the parameter.</typeparam>
9-
/// <param name="source">The source object to get the value from.</param>
7+
/// <typeparam name="T">The type of object to get the parameter from.</typeparam>
8+
/// <typeparam name="U">The type of the parameter.</typeparam>
9+
/// <param name="target">The object to get the value from.</param>
1010
/// <returns>The current value of the parameter.</returns>
11-
public delegate T TweenGetter<S,T>(S source);
11+
public delegate U TweenGetter<T,U>(T target);
1212

1313
/// <summary>
14-
/// A function delegate that sets a new value of a parameter on a source
15-
/// object.
14+
/// A function delegate that sets a new value of a parameter on an object.
1615
/// </summary>
17-
/// <typeparam name="S">The type of the source object.</typeparam>
18-
/// <typeparam name="T">The type of the parameter.</typeparam>
19-
/// <param name="source">The source object to set the value on.</param>
16+
/// <typeparam name="T">The type of object to set the parameter on.</typeparam>
17+
/// <typeparam name="U">The type of the parameter.</typeparam>
18+
/// <param name="target">The object to set the value on.</param>
2019
/// <param name="value">The new value of the parameter.</param>
21-
public delegate void TweenSetter<S,T>(S source, T value);
20+
public delegate void TweenSetter<T,U>(T target, U value);
2221

2322
/// <summary>
2423
/// A function delegate that can be invoked during various tween events
25-
/// and/or state changes.
24+
/// and/or state changes, such as on complete.
2625
/// </summary>
2726
public delegate void TweenCallback();
2827

Runtime/Extensions/Audio/AudioChorusFilterTweens.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,32 @@ namespace Zigurous.Tweening
55
public static class AudioChorusFilterTweens
66
{
77
public static Tween TweenDelay(this AudioChorusFilter filter, float to, float duration) =>
8-
Tweening.To(filter, (source) => source.delay, (source, value) => source.delay = value, to, duration)
9-
.SetTarget(filter);
8+
Tweening.To(filter, (target) => target.delay, (target, value) => target.delay = value, to, duration)
9+
.SetReference(filter);
1010

1111
public static Tween TweenRate(this AudioChorusFilter filter, float to, float duration) =>
12-
Tweening.To(filter, (source) => source.rate, (source, value) => source.rate = value, to, duration)
13-
.SetTarget(filter);
12+
Tweening.To(filter, (target) => target.rate, (target, value) => target.rate = value, to, duration)
13+
.SetReference(filter);
1414

1515
public static Tween TweenDepth(this AudioChorusFilter filter, float to, float duration) =>
16-
Tweening.To(filter, (source) => source.depth, (source, value) => source.depth = value, to, duration)
17-
.SetTarget(filter);
16+
Tweening.To(filter, (target) => target.depth, (target, value) => target.depth = value, to, duration)
17+
.SetReference(filter);
1818

1919
public static Tween TweenDryMix(this AudioChorusFilter filter, float to, float duration) =>
20-
Tweening.To(filter, (source) => source.dryMix, (source, value) => source.dryMix = value, to, duration)
21-
.SetTarget(filter);
20+
Tweening.To(filter, (target) => target.dryMix, (target, value) => target.dryMix = value, to, duration)
21+
.SetReference(filter);
2222

2323
public static Tween TweenWetMix1(this AudioChorusFilter filter, float to, float duration) =>
24-
Tweening.To(filter, (source) => source.wetMix1, (source, value) => source.wetMix1 = value, to, duration)
25-
.SetTarget(filter);
24+
Tweening.To(filter, (target) => target.wetMix1, (target, value) => target.wetMix1 = value, to, duration)
25+
.SetReference(filter);
2626

2727
public static Tween TweenWetMix2(this AudioChorusFilter filter, float to, float duration) =>
28-
Tweening.To(filter, (source) => source.wetMix2, (source, value) => source.wetMix2 = value, to, duration)
29-
.SetTarget(filter);
28+
Tweening.To(filter, (target) => target.wetMix2, (target, value) => target.wetMix2 = value, to, duration)
29+
.SetReference(filter);
3030

3131
public static Tween TweenWetMix3(this AudioChorusFilter filter, float to, float duration) =>
32-
Tweening.To(filter, (source) => source.wetMix3, (source, value) => source.wetMix3 = value, to, duration)
33-
.SetTarget(filter);
32+
Tweening.To(filter, (target) => target.wetMix3, (target, value) => target.wetMix3 = value, to, duration)
33+
.SetReference(filter);
3434
}
3535

3636
}

Runtime/Extensions/Audio/AudioDistortionFilterTweens.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace Zigurous.Tweening
55
public static class AudioDistortionFilterTweens
66
{
77
public static Tween TweenDistortionLevel(this AudioDistortionFilter filter, float to, float duration) =>
8-
Tweening.To(filter, (source) => source.distortionLevel, (source, value) => source.distortionLevel = value, to, duration)
9-
.SetTarget(filter);
8+
Tweening.To(filter, (target) => target.distortionLevel, (target, value) => target.distortionLevel = value, to, duration)
9+
.SetReference(filter);
1010
}
1111

1212
}

Runtime/Extensions/Audio/AudioEchoFilterTweens.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ namespace Zigurous.Tweening
55
public static class AudioEchoFilterTweens
66
{
77
public static Tween TweenDelay(this AudioEchoFilter filter, float to, float duration) =>
8-
Tweening.To(filter, (source) => source.delay, (source, value) => source.delay = value, to, duration)
9-
.SetTarget(filter);
8+
Tweening.To(filter, (target) => target.delay, (target, value) => target.delay = value, to, duration)
9+
.SetReference(filter);
1010

1111
public static Tween TweenDecayRatio(this AudioEchoFilter filter, float to, float duration) =>
12-
Tweening.To(filter, (source) => source.decayRatio, (source, value) => source.decayRatio = value, to, duration)
13-
.SetTarget(filter);
12+
Tweening.To(filter, (target) => target.decayRatio, (target, value) => target.decayRatio = value, to, duration)
13+
.SetReference(filter);
1414

1515
public static Tween TweenDryMix(this AudioEchoFilter filter, float to, float duration) =>
16-
Tweening.To(filter, (source) => source.dryMix, (source, value) => source.dryMix = value, to, duration)
17-
.SetTarget(filter);
16+
Tweening.To(filter, (target) => target.dryMix, (target, value) => target.dryMix = value, to, duration)
17+
.SetReference(filter);
1818

1919
public static Tween TweenWetMix(this AudioEchoFilter filter, float to, float duration) =>
20-
Tweening.To(filter, (source) => source.wetMix, (source, value) => source.wetMix = value, to, duration)
21-
.SetTarget(filter);
20+
Tweening.To(filter, (target) => target.wetMix, (target, value) => target.wetMix = value, to, duration)
21+
.SetReference(filter);
2222
}
2323

2424
}

Runtime/Extensions/Audio/AudioHighPassFilterTweens.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace Zigurous.Tweening
55
public static class AudioHighPassFilterTweens
66
{
77
public static Tween TweenCutoffFrequency(this AudioHighPassFilter filter, float to, float duration) =>
8-
Tweening.To(filter, (source) => source.cutoffFrequency, (source, value) => source.cutoffFrequency = value, to, duration)
9-
.SetTarget(filter);
8+
Tweening.To(filter, (target) => target.cutoffFrequency, (target, value) => target.cutoffFrequency = value, to, duration)
9+
.SetReference(filter);
1010

1111
public static Tween TweenHighpassResonanceQ(this AudioHighPassFilter filter, float to, float duration) =>
12-
Tweening.To(filter, (source) => source.highpassResonanceQ, (source, value) => source.highpassResonanceQ = value, to, duration)
13-
.SetTarget(filter);
12+
Tweening.To(filter, (target) => target.highpassResonanceQ, (target, value) => target.highpassResonanceQ = value, to, duration)
13+
.SetReference(filter);
1414
}
1515

1616
}

Runtime/Extensions/Audio/AudioListenerTweens.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public static class AudioListenerTweens
66
{
77
public static Tween TweenVolume(this AudioListener listener, float to, float duration) =>
88
Tweening.To(listener, (source) => AudioListener.volume, (source, value) => AudioListener.volume = value, to, duration)
9-
.SetTarget(listener);
9+
.SetReference(listener);
1010
}
1111

1212
}

Runtime/Extensions/Audio/AudioLowPassFilterTweens.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace Zigurous.Tweening
55
public static class AudioLowPassFilterTweens
66
{
77
public static Tween TweenCutoffFrequency(this AudioLowPassFilter filter, float to, float duration) =>
8-
Tweening.To(filter, (source) => source.cutoffFrequency, (source, value) => source.cutoffFrequency = value, to, duration)
9-
.SetTarget(filter);
8+
Tweening.To(filter, (target) => target.cutoffFrequency, (target, value) => target.cutoffFrequency = value, to, duration)
9+
.SetReference(filter);
1010

1111
public static Tween TweenLowpassResonanceQ(this AudioLowPassFilter filter, float to, float duration) =>
12-
Tweening.To(filter, (source) => source.lowpassResonanceQ, (source, value) => source.lowpassResonanceQ = value, to, duration)
13-
.SetTarget(filter);
12+
Tweening.To(filter, (target) => target.lowpassResonanceQ, (target, value) => target.lowpassResonanceQ = value, to, duration)
13+
.SetReference(filter);
1414
}
1515

1616
}

Runtime/Extensions/Audio/AudioReverbFilterTweens.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,60 @@ namespace Zigurous.Tweening
55
public static class AudioReverbFilterTweens
66
{
77
public static Tween TweenDensity(this AudioReverbFilter filter, float to, float duration) =>
8-
Tweening.To(filter, (source) => source.density, (source, value) => source.density = value, to, duration)
9-
.SetTarget(filter);
8+
Tweening.To(filter, (target) => target.density, (target, value) => target.density = value, to, duration)
9+
.SetReference(filter);
1010

1111
public static Tween TweenDiffusion(this AudioReverbFilter filter, float to, float duration) =>
12-
Tweening.To(filter, (source) => source.diffusion, (source, value) => source.diffusion = value, to, duration)
13-
.SetTarget(filter);
12+
Tweening.To(filter, (target) => target.diffusion, (target, value) => target.diffusion = value, to, duration)
13+
.SetReference(filter);
1414

1515
public static Tween TweenReverbDelay(this AudioReverbFilter filter, float to, float duration) =>
16-
Tweening.To(filter, (source) => source.reverbDelay, (source, value) => source.reverbDelay = value, to, duration)
17-
.SetTarget(filter);
16+
Tweening.To(filter, (target) => target.reverbDelay, (target, value) => target.reverbDelay = value, to, duration)
17+
.SetReference(filter);
1818

1919
public static Tween TweenReverbLevel(this AudioReverbFilter filter, float to, float duration) =>
20-
Tweening.To(filter, (source) => source.reverbLevel, (source, value) => source.reverbLevel = value, to, duration)
21-
.SetTarget(filter);
20+
Tweening.To(filter, (target) => target.reverbLevel, (target, value) => target.reverbLevel = value, to, duration)
21+
.SetReference(filter);
2222

2323
public static Tween TweenReflectionsDelay(this AudioReverbFilter filter, float to, float duration) =>
24-
Tweening.To(filter, (source) => source.reflectionsDelay, (source, value) => source.reflectionsDelay = value, to, duration)
25-
.SetTarget(filter);
24+
Tweening.To(filter, (target) => target.reflectionsDelay, (target, value) => target.reflectionsDelay = value, to, duration)
25+
.SetReference(filter);
2626

2727
public static Tween TweenReflectionsLevel(this AudioReverbFilter filter, float to, float duration) =>
28-
Tweening.To(filter, (source) => source.reflectionsLevel, (source, value) => source.reflectionsLevel = value, to, duration)
29-
.SetTarget(filter);
28+
Tweening.To(filter, (target) => target.reflectionsLevel, (target, value) => target.reflectionsLevel = value, to, duration)
29+
.SetReference(filter);
3030

3131
public static Tween TweenDecayHFRatio(this AudioReverbFilter filter, float to, float duration) =>
32-
Tweening.To(filter, (source) => source.decayHFRatio, (source, value) => source.decayHFRatio = value, to, duration)
33-
.SetTarget(filter);
32+
Tweening.To(filter, (target) => target.decayHFRatio, (target, value) => target.decayHFRatio = value, to, duration)
33+
.SetReference(filter);
3434

3535
public static Tween TweenDecayTime(this AudioReverbFilter filter, float to, float duration) =>
36-
Tweening.To(filter, (source) => source.decayTime, (source, value) => source.decayTime = value, to, duration)
37-
.SetTarget(filter);
36+
Tweening.To(filter, (target) => target.decayTime, (target, value) => target.decayTime = value, to, duration)
37+
.SetReference(filter);
3838

3939
public static Tween TweenRoom(this AudioReverbFilter filter, float to, float duration) =>
40-
Tweening.To(filter, (source) => source.room, (source, value) => source.room = value, to, duration)
41-
.SetTarget(filter);
40+
Tweening.To(filter, (target) => target.room, (target, value) => target.room = value, to, duration)
41+
.SetReference(filter);
4242

4343
public static Tween TweenRoomHF(this AudioReverbFilter filter, float to, float duration) =>
44-
Tweening.To(filter, (source) => source.roomHF, (source, value) => source.roomHF = value, to, duration)
45-
.SetTarget(filter);
44+
Tweening.To(filter, (target) => target.roomHF, (target, value) => target.roomHF = value, to, duration)
45+
.SetReference(filter);
4646

4747
public static Tween TweenRoomLF(this AudioReverbFilter filter, float to, float duration) =>
48-
Tweening.To(filter, (source) => source.roomLF, (source, value) => source.roomLF = value, to, duration)
49-
.SetTarget(filter);
48+
Tweening.To(filter, (target) => target.roomLF, (target, value) => target.roomLF = value, to, duration)
49+
.SetReference(filter);
5050

5151
public static Tween TweenDryLevel(this AudioReverbFilter filter, float to, float duration) =>
52-
Tweening.To(filter, (source) => source.dryLevel, (source, value) => source.dryLevel = value, to, duration)
53-
.SetTarget(filter);
52+
Tweening.To(filter, (target) => target.dryLevel, (target, value) => target.dryLevel = value, to, duration)
53+
.SetReference(filter);
5454

5555
public static Tween TweenHFReference(this AudioReverbFilter filter, float to, float duration) =>
56-
Tweening.To(filter, (source) => source.hfReference, (source, value) => source.hfReference = value, to, duration)
57-
.SetTarget(filter);
56+
Tweening.To(filter, (target) => target.hfReference, (target, value) => target.hfReference = value, to, duration)
57+
.SetReference(filter);
5858

5959
public static Tween TweenLFReference(this AudioReverbFilter filter, float to, float duration) =>
60-
Tweening.To(filter, (source) => source.lfReference, (source, value) => source.lfReference = value, to, duration)
61-
.SetTarget(filter);
60+
Tweening.To(filter, (target) => target.lfReference, (target, value) => target.lfReference = value, to, duration)
61+
.SetReference(filter);
6262
}
6363

6464
}

0 commit comments

Comments
 (0)