Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SoundPlayer.cs
Go to the documentation of this file.
1
using
System.Collections.Generic
;
2
using
Microsoft.Xna.Framework
;
3
using
ReLogic.Utilities
;
4
5
namespace
Terraria.Audio
;
6
7
public
class
SoundPlayer
8
{
9
private
readonly
SlotVector<ActiveSound>
_trackedSounds
=
new
SlotVector<ActiveSound>
(4096);
10
11
public
SlotId
Play
(
SoundStyle
style,
Vector2
position)
12
{
13
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
14
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
15
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
16
if
(
Main
.
dedServ
|| style ==
null
|| !style.
IsTrackable
)
17
{
18
return
SlotId
.
Invalid
;
19
}
20
if
(
Vector2
.
DistanceSquared
(
Main
.
screenPosition
+
new
Vector2
(
Main
.
screenWidth
/ 2,
Main
.
screenHeight
/ 2), position) > 100000000f)
21
{
22
return
SlotId
.
Invalid
;
23
}
24
ActiveSound
activeSound
=
new
ActiveSound
(style, position);
25
return
_trackedSounds
.
Add
(
activeSound
);
26
}
27
28
public
SlotId
PlayLooped
(
SoundStyle
style,
Vector2
position,
ActiveSound
.
LoopedPlayCondition
loopingCondition
)
29
{
30
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
31
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
32
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
33
if
(
Main
.
dedServ
|| style ==
null
|| !style.
IsTrackable
)
34
{
35
return
SlotId
.
Invalid
;
36
}
37
if
(
Vector2
.
DistanceSquared
(
Main
.
screenPosition
+
new
Vector2
(
Main
.
screenWidth
/ 2,
Main
.
screenHeight
/ 2), position) > 100000000f)
38
{
39
return
SlotId
.
Invalid
;
40
}
41
ActiveSound
activeSound
=
new
ActiveSound
(style, position,
loopingCondition
);
42
return
_trackedSounds
.
Add
(
activeSound
);
43
}
44
45
public
void
Reload
()
46
{
47
StopAll
();
48
}
49
50
public
SlotId
Play
(
SoundStyle
style)
51
{
52
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
53
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
54
if
(
Main
.
dedServ
|| style ==
null
|| !style.
IsTrackable
)
55
{
56
return
SlotId
.
Invalid
;
57
}
58
ActiveSound
activeSound
=
new
ActiveSound
(style);
59
return
_trackedSounds
.
Add
(
activeSound
);
60
}
61
62
public
ActiveSound
GetActiveSound
(
SlotId
id
)
63
{
64
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
65
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
66
if
(!
_trackedSounds
.Has(
id
))
67
{
68
return
null
;
69
}
70
return
_trackedSounds
[id];
71
}
72
73
public
void
PauseAll
()
74
{
75
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
76
foreach
(
ItemPair<ActiveSound>
item
in
(
IEnumerable
<
ItemPair<ActiveSound>
>)
_trackedSounds
)
77
{
78
item.Value.Pause();
79
}
80
}
81
82
public
void
ResumeAll
()
83
{
84
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
85
foreach
(
ItemPair<ActiveSound>
item
in
(
IEnumerable
<
ItemPair<ActiveSound>
>)
_trackedSounds
)
86
{
87
item.Value.Resume();
88
}
89
}
90
91
public
void
StopAll
()
92
{
93
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
94
foreach
(
ItemPair<ActiveSound>
item
in
(
IEnumerable
<
ItemPair<ActiveSound>
>)
_trackedSounds
)
95
{
96
item.Value.Stop();
97
}
98
_trackedSounds
.
Clear
();
99
}
100
101
public
void
Update
()
102
{
103
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
104
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
105
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
106
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
107
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
108
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
109
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
110
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
111
foreach
(
ItemPair<ActiveSound>
item
in
(
IEnumerable
<
ItemPair<ActiveSound>
>)
_trackedSounds
)
112
{
113
try
114
{
115
item.Value.Update();
116
if
(!item.Value.IsPlaying)
117
{
118
_trackedSounds
.
Remove
(item.Id);
119
}
120
}
121
catch
122
{
123
_trackedSounds
.
Remove
(item.Id);
124
}
125
}
126
}
127
128
public
ActiveSound
FindActiveSound
(
SoundStyle
style)
129
{
130
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
131
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
132
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
133
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
134
foreach
(
ItemPair<ActiveSound>
item
in
(
IEnumerable
<
ItemPair<ActiveSound>
>)
_trackedSounds
)
135
{
136
if
(item.Value.Style == style)
137
{
138
return
item.Value;
139
}
140
}
141
return
null
;
142
}
143
}
System.Collections.Generic.Dictionary.Remove
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
Definition
Dictionary.cs:893
System.Collections.Generic.Dictionary.Clear
void Clear()
Definition
Dictionary.cs:904
System.Collections.Generic.Dictionary.Add
void Add(TKey key, TValue value)
Definition
Dictionary.cs:873
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
Terraria.Audio.ActiveSound.LoopedPlayCondition
delegate bool LoopedPlayCondition()
Terraria.Audio.ActiveSound
Definition
ActiveSound.cs:7
Terraria.Audio.SoundPlayer.PauseAll
void PauseAll()
Definition
SoundPlayer.cs:73
Terraria.Audio.SoundPlayer.FindActiveSound
ActiveSound FindActiveSound(SoundStyle style)
Definition
SoundPlayer.cs:128
Terraria.Audio.SoundPlayer.Update
void Update()
Definition
SoundPlayer.cs:101
Terraria.Audio.SoundPlayer.Play
SlotId Play(SoundStyle style, Vector2 position)
Definition
SoundPlayer.cs:11
Terraria.Audio.SoundPlayer.Play
SlotId Play(SoundStyle style)
Definition
SoundPlayer.cs:50
Terraria.Audio.SoundPlayer.Reload
void Reload()
Definition
SoundPlayer.cs:45
Terraria.Audio.SoundPlayer.PlayLooped
SlotId PlayLooped(SoundStyle style, Vector2 position, ActiveSound.LoopedPlayCondition loopingCondition)
Definition
SoundPlayer.cs:28
Terraria.Audio.SoundPlayer.ResumeAll
void ResumeAll()
Definition
SoundPlayer.cs:82
Terraria.Audio.SoundPlayer.StopAll
void StopAll()
Definition
SoundPlayer.cs:91
Terraria.Audio.SoundPlayer._trackedSounds
readonly SlotVector< ActiveSound > _trackedSounds
Definition
SoundPlayer.cs:9
Terraria.Audio.SoundPlayer.GetActiveSound
ActiveSound GetActiveSound(SlotId id)
Definition
SoundPlayer.cs:62
Terraria.Audio.SoundPlayer
Definition
SoundPlayer.cs:8
Terraria.Audio.SoundStyle.IsTrackable
bool IsTrackable
Definition
SoundStyle.cs:22
Terraria.Audio.SoundStyle
Definition
SoundStyle.cs:7
Terraria.Main.dedServ
static bool dedServ
Definition
Main.cs:1226
Terraria.Main.screenHeight
static int screenHeight
Definition
Main.cs:1721
Terraria.Main.screenPosition
static Vector2 screenPosition
Definition
Main.cs:1715
Terraria.Main.screenWidth
static int screenWidth
Definition
Main.cs:1719
Terraria.Main
Definition
Main.cs:79
System.Collections.Generic.IEnumerable
Definition
IEnumerable.cs:4
Microsoft.Xna.Framework
Definition
AlphaTestEffect.cs:1
ReLogic.Utilities
Definition
AttributeUtilities.cs:5
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
Terraria.Audio
Definition
ActiveSound.cs:4
Microsoft.Xna.Framework.Vector2.DistanceSquared
static float DistanceSquared(Vector2 value1, Vector2 value2)
Definition
Vector2.cs:107
Microsoft.Xna.Framework.Vector2
Definition
Vector2.cs:12
ReLogic.Utilities.SlotId.Invalid
static readonly SlotId Invalid
Definition
SlotId.cs:5
ReLogic.Utilities.SlotId
Definition
SlotId.cs:4
source
Terraria.Audio
SoundPlayer.cs
Generated by
1.10.0