Skip to content

Commit 3ef10d8

Browse files
committed
Reorganized _engines._sound
Renamed Channels to Channel Renamed Attenuations to Attenuation Fixed Attenuation enum (its members are floats -- not ints)
1 parent af05817 commit 3ef10d8

File tree

3 files changed

+68
-28
lines changed

3 files changed

+68
-28
lines changed

Diff for: addons/source-python/packages/source-python/engines/sound.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# =============================================================================
88
# Python Imports
99
# Enum
10+
from enum import Enum
1011
from enum import IntEnum
1112

1213
# Source.Python Imports
@@ -28,7 +29,7 @@
2829
# =============================================================================
2930
# Source.Python Imports
3031
# Engines
31-
from _engines._sound import Channels
32+
from _engines._sound import Channel
3233
from _engines._sound import VOL_NORM
3334
from _engines._sound import ATTN_NONE
3435
from _engines._sound import ATTN_NORM
@@ -38,9 +39,7 @@
3839
from _engines._sound import ATTN_GUNFIRE
3940
from _engines._sound import MAX_ATTENUATION
4041
from _engines._sound import SoundFlags
41-
from _engines._sound import PITCH_NORM
42-
from _engines._sound import PITCH_LOW
43-
from _engines._sound import PITCH_HIGH
42+
from _engines._sound import Pitch
4443
from _engines._sound import SOUND_FROM_LOCAL_PLAYER
4544
from _engines._sound import SOUND_FROM_WORLD
4645
from _engines._sound import engine_sound
@@ -49,9 +48,9 @@
4948
# =============================================================================
5049
# >> ALL DECLARATION
5150
# =============================================================================
52-
__all__ = ('Attenuations',
53-
'Channels',
54-
'PitchTypes',
51+
__all__ = ('Attenuation',
52+
'Channel',
53+
'Pitch',
5554
'SOUND_FROM_LOCAL_PLAYER',
5655
'SOUND_FROM_WORLD',
5756
'Sound',
@@ -71,7 +70,7 @@
7170
# =============================================================================
7271
# >> ENUMERATORS
7372
# =============================================================================
74-
class Attenuations(IntEnum):
73+
class Attenuation(float, Enum):
7574
"""Attenuation values wrapper enumerator."""
7675

7776
NONE = ATTN_NONE
@@ -83,14 +82,9 @@ class Attenuations(IntEnum):
8382
MAXIMUM = MAX_ATTENUATION
8483

8584

86-
class PitchTypes(IntEnum):
87-
"""Pitch values wrapper enumerator."""
88-
89-
NORMAL = PITCH_NORM
90-
LOW = PITCH_LOW
91-
HIGH = PITCH_HIGH
92-
93-
85+
# =============================================================================
86+
# >> CLASSES
87+
# =============================================================================
9488
class Sound(AutoUnload):
9589
"""Class used to interact with a specific sound file."""
9690

@@ -100,8 +94,8 @@ class Sound(AutoUnload):
10094

10195
def __init__(
10296
self, recipients, index, sample, volume=VOL_NORM,
103-
attenuation=Attenuations.NONE, channel=Channels.AUTO,
104-
flags=0, pitch=PitchTypes.NORMAL, origin=NULL_VECTOR,
97+
attenuation=Attenuation.NONE, channel=Channel.AUTO,
98+
flags=0, pitch=Pitch.NORMAL, origin=NULL_VECTOR,
10599
direction=NULL_VECTOR, origins=(), update_positions=True,
106100
sound_time=0.0, speaker_entity=-1, download=False):
107101
"""Store all the given attributes and set the module for unloading."""

Diff for: src/core/modules/engines/engines_sound_wrap.cpp

+55-10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ extern IEngineSound* enginesound;
4747
// Forward declarations.
4848
//---------------------------------------------------------------------------------
4949
void export_engine_sound(scope);
50+
void export_channel(scope);
51+
void export_global_sound_variables(scope);
52+
void export_attenuation(scope);
53+
void export_sound_flags_t(scope);
54+
void export_pitch(scope);
5055

5156

5257
//---------------------------------------------------------------------------------
@@ -55,6 +60,11 @@ void export_engine_sound(scope);
5560
DECLARE_SP_SUBMODULE(_engines, _sound)
5661
{
5762
export_engine_sound(_sound);
63+
export_channel(_sound);
64+
export_global_sound_variables(_sound);
65+
export_attenuation(_sound);
66+
export_sound_flags_t(_sound);
67+
export_pitch(_sound);
5868
}
5969

6070

@@ -124,9 +134,15 @@ void export_engine_sound(scope _sound)
124134
) ADD_MEM_TOOLS(IEngineSound); // IEngineSound_Visitor
125135

126136
_sound.attr("engine_sound") = object(ptr(enginesound));
137+
}
138+
127139

128-
// Channels
129-
enum_<int>("Channels")
140+
//---------------------------------------------------------------------------------
141+
// Exports Channel.
142+
//---------------------------------------------------------------------------------
143+
void export_channel(scope _sound)
144+
{
145+
enum_<int>("Channel")
130146
.value("REPLACE", CHAN_REPLACE)
131147
.value("AUTO", CHAN_AUTO)
132148
.value("WEAPON", CHAN_WEAPON)
@@ -138,20 +154,42 @@ void export_engine_sound(scope _sound)
138154
.value("VOICE_BASE", CHAN_VOICE_BASE)
139155
.value("USER_BASE", CHAN_USER_BASE)
140156
;
157+
}
141158

159+
160+
//---------------------------------------------------------------------------------
161+
// Exports volume values.
162+
//---------------------------------------------------------------------------------
163+
void export_global_sound_variables(scope _sound)
164+
{
142165
// Common volume values
143166
_sound.attr("VOL_NORM") = VOL_NORM;
144167

145-
// Common attenuation values
168+
_sound.attr("SOUND_FROM_LOCAL_PLAYER") = SOUND_FROM_LOCAL_PLAYER;
169+
_sound.attr("SOUND_FROM_WORLD") = SOUND_FROM_WORLD;
170+
}
171+
172+
173+
//---------------------------------------------------------------------------------
174+
// Exports attenuation values.
175+
//---------------------------------------------------------------------------------
176+
void export_attenuation(scope _sound)
177+
{
146178
_sound.attr("ATTN_NONE") = ATTN_NONE;
147179
_sound.attr("ATTN_NORM") = ATTN_NORM;
148180
_sound.attr("ATTN_IDLE") = ATTN_IDLE;
149181
_sound.attr("ATTN_STATIC") = ATTN_STATIC;
150182
_sound.attr("ATTN_RICOCHET") = ATTN_RICOCHET;
151183
_sound.attr("ATTN_GUNFIRE") = ATTN_GUNFIRE;
152184
_sound.attr("MAX_ATTENUATION") = MAX_ATTENUATION;
185+
}
186+
153187

154-
// Flags for iFlags fields
188+
//---------------------------------------------------------------------------------
189+
// Exports SoundFlags_t.
190+
//---------------------------------------------------------------------------------
191+
void export_sound_flags_t(scope _sound)
192+
{
155193
enum_<SoundFlags_t>("SoundFlags")
156194
.value("NOFLAGS", SND_NOFLAGS)
157195
.value("CHANGE_VOL", SND_CHANGE_VOL)
@@ -165,12 +203,19 @@ void export_engine_sound(scope _sound)
165203
.value("IGNORE_PHONEMES", SND_IGNORE_PHONEMES)
166204
.value("IGNORE_NAME", SND_IGNORE_NAME)
167205
;
206+
}
168207

169-
// Common pitch values
170-
_sound.attr("PITCH_NORM") = PITCH_NORM;
171-
_sound.attr("PITCH_LOW") = PITCH_LOW;
172-
_sound.attr("PITCH_HIGH") = PITCH_HIGH;
173208

174-
_sound.attr("SOUND_FROM_LOCAL_PLAYER") = SOUND_FROM_LOCAL_PLAYER;
175-
_sound.attr("SOUND_FROM_WORLD") = SOUND_FROM_WORLD;
209+
//---------------------------------------------------------------------------------
210+
// Exports pitch values.
211+
//---------------------------------------------------------------------------------
212+
void export_pitch(scope _sound)
213+
{
214+
enum Pitch {};
215+
216+
enum_<Pitch> _Pitch("Pitch");
217+
218+
_Pitch.value("NORMAL", (Pitch) PITCH_NORM);
219+
_Pitch.value("LOW", (Pitch) PITCH_LOW);
220+
_Pitch.value("HIGH", (Pitch) PITCH_HIGH);
176221
}

Diff for: src/core/modules/engines/engines_trace_wrap.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void export_content_flags(scope);
6161
void export_content_masks(scope);
6262
void export_surface_flags(scope);
6363

64+
6465
//---------------------------------------------------------------------------------
6566
// Declare the _trace module.
6667
//---------------------------------------------------------------------------------

0 commit comments

Comments
 (0)