Skip to content

Commit 168418c

Browse files
committed
Exposed IEngineSound in engine_c
- Removed _EngineServer.index_of_edict() and _EngineServer.edict_of_index(). Use conversions_c functions instead. - Fixed passing a subclass of IRecipientFilter to a function that requires a IRecipientFilter instance by exposing IRecipientFilter
1 parent 5673342 commit 168418c

File tree

5 files changed

+185
-21
lines changed

5 files changed

+185
-21
lines changed

src/core/modules/engine/engine1/engine_wrap_python.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,12 @@
2525
*/
2626

2727
#include "eiface.h"
28+
#include "engine/IEngineSound.h"
2829

2930
template<class T>
3031
void IVEngineServer_Visitor(T cls)
3132
{
3233
cls
33-
.def("index_of_edict",
34-
&IVEngineServer::IndexOfEdict,
35-
"Returns the edict's index",
36-
args("edict")
37-
)
38-
39-
.def("edict_of_index",
40-
&IVEngineServer::PEntityOfEntIndex,
41-
"Returns the corresponding edict for the given index.",
42-
args("index"),
43-
reference_existing_object_policy()
44-
)
45-
4634
.def("user_message_begin",
4735
&IVEngineServer::UserMessageBegin,
4836
"Begins a user message from the server to the client .dll.",
@@ -81,3 +69,21 @@ void IVEngineServer_Visitor(T cls)
8169
*/
8270
;
8371
}
72+
73+
inline void IEngineSound_EmitSound(IEngineSound* pEngineSound, IRecipientFilter& filter, int iEntIndex, int iChannel, const char *pSample,
74+
float flVolume, float flAttenuation, int iFlags = 0, int iPitch = PITCH_NORM, const Vector *pOrigin = NULL, const Vector *pDirection = NULL,
75+
tuple origins = tuple(), bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1)
76+
{
77+
CUtlVector< Vector >* pUtlVecOrigins = NULL;
78+
for(int i=0; i < len(origins); i++)
79+
{
80+
pUtlVecOrigins->AddToTail(extract<Vector>(origins[i]));
81+
}
82+
83+
pEngineSound->EmitSound(filter, iEntIndex, iChannel, pSample, flVolume, flAttenuation, iFlags, iPitch, 0, pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity);
84+
}
85+
86+
template<class T>
87+
void IEngineSound_Visitor(T cls)
88+
{
89+
}

src/core/modules/engine/engine2/engine_wrap_python.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@
2727
template<class T>
2828
void IVEngineServer_Visitor(T cls)
2929
{
30+
}
31+
32+
template<class T>
33+
void IEngineSound_Visitor(T cls)
34+
{
3035
}

src/core/modules/engine/engine3/engine_wrap_python.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "eiface.h"
2828
#include "ispsharedmemory.h"
2929
#include "modules/usermessage/usermessage.h"
30+
#include "engine/IEngineSound.h"
3031

3132
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(get_single_player_shared_memory_space_overload, GetSinglePlayerSharedMemorySpace, 1, 2);
3233

@@ -247,3 +248,28 @@ void IVEngineServer_Visitor(T cls)
247248
*/
248249
;
249250
}
251+
252+
inline void IEngineSound_EmitSound(IEngineSound* pEngineSound, IRecipientFilter& filter, int iEntIndex, int iChannel, const char *pSample,
253+
float flVolume, float flAttenuation, int iFlags = 0, int iPitch = PITCH_NORM, const Vector *pOrigin = NULL, const Vector *pDirection = NULL,
254+
tuple origins = tuple(), bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1)
255+
{
256+
CUtlVector< Vector >* pUtlVecOrigins = NULL;
257+
for(int i=0; i < len(origins); i++)
258+
{
259+
pUtlVecOrigins->AddToTail(extract<Vector>(origins[i]));
260+
}
261+
262+
pEngineSound->EmitSound(filter, iEntIndex, iChannel, pSample, -1, pSample, flVolume, flAttenuation, 0, iFlags, iPitch, pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity);
263+
}
264+
265+
template<class T>
266+
void IEngineSound_Visitor(T cls)
267+
{
268+
cls
269+
.def("is_looping_sound",
270+
&IEngineSound::IsLoopingSound,
271+
args("sample"),
272+
"Returns True if the given sample is looping."
273+
)
274+
;
275+
}

src/core/modules/engine/engine_wrap_python.cpp

Lines changed: 127 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,24 @@
4444
#include "steam/steamclientpublic.h"
4545
#include "inetchannelinfo.h"
4646
#include "eiface.h"
47+
#include "engine/IEngineSound.h"
4748

4849
#include ENGINE_INCLUDE_PATH(engine_wrap_python.h)
4950

5051

5152
extern IVEngineServer* engine;
53+
extern IEngineSound* enginesound;
5254

5355
//---------------------------------------------------------------------------------
5456
// Exposes the engine module.
5557
//---------------------------------------------------------------------------------
5658
void export_engine_interface();
59+
void export_engine_sound();
5760

5861
DECLARE_SP_MODULE(engine_c)
5962
{
6063
export_engine_interface();
64+
export_engine_sound();
6165
}
6266

6367

@@ -700,8 +704,6 @@ void export_engine_interface()
700704
)
701705

702706
// OB specific methods
703-
.NOT_IMPLEMENTED("index_of_edict")
704-
.NOT_IMPLEMENTED("edict_of_index")
705707
.NOT_IMPLEMENTED("user_message_begin")
706708
.NOT_IMPLEMENTED("get_time")
707709
.NOT_IMPLEMENTED("multiplayer_end_game")
@@ -754,3 +756,126 @@ void export_engine_interface()
754756

755757
scope().attr("EngineServer") = object(ptr(engine));
756758
}
759+
760+
761+
//---------------------------------------------------------------------------------
762+
// Exposes IEngineSound.
763+
//---------------------------------------------------------------------------------
764+
// Overloads
765+
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(precache_sound_overload, PrecacheSound, 1, 3);
766+
BOOST_PYTHON_FUNCTION_OVERLOADS(emit_sound_overload, IEngineSound_EmitSound, 7, 15);
767+
768+
void export_engine_sound()
769+
{
770+
// Call engine specific implementation function
771+
IEngineSound_Visitor(
772+
773+
class_<IEngineSound, boost::noncopyable>("_EngineSound", no_init)
774+
775+
.def("precache_sound",
776+
&IEngineSound::PrecacheSound,
777+
precache_sound_overload(
778+
args("sample", "preload", "is_ui_sound"),
779+
"Precaches a particular sample."
780+
)
781+
)
782+
783+
.def("is_sound_precached",
784+
&IEngineSound::IsSoundPrecached,
785+
args("sample"),
786+
"Returns True if the given sound is precached."
787+
)
788+
789+
.def("prefetch_sound",
790+
&IEngineSound::PrefetchSound,
791+
args("sample"),
792+
"Prefetches a sample."
793+
)
794+
795+
.def("get_sound_duration",
796+
&IEngineSound::GetSoundDuration,
797+
args("sample"),
798+
"Returns the sound duration."
799+
)
800+
801+
.def("emit_sound",
802+
&IEngineSound_EmitSound,
803+
emit_sound_overload(
804+
args("filter", "entity_index", "channel", "sample", "volume", "attenuation", "flags", "pitch", "origin", "direction", "origins", "update_positions", "sound_time", "speaker_entity"),
805+
"Emits a sound from an entity."
806+
)
807+
)
808+
809+
// TODO: Can we use IVEngineServer::SentenceNameFromIndex() and then call IEngineSound::EmitSound()?
810+
.NOT_IMPLEMENTED("emit_sentence_by_index")
811+
812+
.def("stop_sound",
813+
&IEngineSound::StopSound,
814+
args("entity_index", "channel", "sample"),
815+
"Stops a sound from being emitted from an entity."
816+
)
817+
818+
// TODO: StopAllSounds, SetRoomType, SetPlayerDSP. Are they really just client only?
819+
820+
.def("get_dist_gain_from_sound_level",
821+
&IEngineSound::GetDistGainFromSoundLevel,
822+
args("sound_level", "distance"),
823+
"Returns the distance gain value from a sound level"
824+
)
825+
826+
// Only available for CS:GO
827+
.NOT_IMPLEMENTED("is_looping_sound")
828+
829+
); // IEngineSound_Visitor
830+
831+
scope().attr("EngineSound") = object(ptr(enginesound));
832+
833+
// Channels
834+
enum_<int>("Channels")
835+
.value("REPLACE", CHAN_REPLACE)
836+
.value("AUTO", CHAN_AUTO)
837+
.value("WEAPON", CHAN_WEAPON)
838+
.value("VOICE", CHAN_VOICE)
839+
.value("ITEM", CHAN_ITEM)
840+
.value("BODY", CHAN_BODY)
841+
.value("STREAM", CHAN_STREAM)
842+
.value("STATIC", CHAN_STATIC)
843+
.value("VOICE_BASE", CHAN_VOICE_BASE)
844+
.value("USER_BASE", CHAN_USER_BASE)
845+
;
846+
847+
// Common volume values
848+
scope().attr("VOL_NORM") = VOL_NORM;
849+
850+
// Common attenuation values
851+
scope().attr("ATTN_NONE") = ATTN_NONE;
852+
scope().attr("ATTN_NORM") = ATTN_NORM;
853+
scope().attr("ATTN_IDLE") = ATTN_IDLE;
854+
scope().attr("ATTN_STATIC") = ATTN_STATIC;
855+
scope().attr("ATTN_RICOCHET") = ATTN_RICOCHET;
856+
scope().attr("ATTN_GUNFIRE") = ATTN_GUNFIRE;
857+
scope().attr("MAX_ATTENUATION") = MAX_ATTENUATION;
858+
859+
// Flags for iFlags fields
860+
enum_<SoundFlags_t>("SoundFlags")
861+
.value("NOFLAGS", SND_NOFLAGS)
862+
.value("CHANGE_VOL", SND_CHANGE_VOL)
863+
.value("CHANGE_PITCH", SND_CHANGE_PITCH)
864+
.value("STOP", SND_STOP)
865+
.value("SPAWNING", SND_SPAWNING)
866+
.value("DELAY", SND_DELAY)
867+
.value("STOP_LOOPING", SND_STOP_LOOPING)
868+
.value("SPEAKER", SND_SPEAKER)
869+
.value("SHOULDPAUSE", SND_SHOULDPAUSE)
870+
.value("IGNORE_PHONEMES", SND_IGNORE_PHONEMES)
871+
.value("IGNORE_NAME", SND_IGNORE_NAME)
872+
;
873+
874+
// Common pitch values
875+
scope().attr("PITCH_NORM") = PITCH_NORM;
876+
scope().attr("PITCH_LOW") = PITCH_LOW;
877+
scope().attr("PITCH_HIGH") = PITCH_HIGH;
878+
879+
scope().attr("SOUND_FROM_LOCAL_PLAYER") = SOUND_FROM_LOCAL_PLAYER;
880+
scope().attr("SOUND_FROM_WORLD") = SOUND_FROM_WORLD;
881+
}

src/core/modules/recipientfilter/recipientfilter_wrap_python.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,31 @@ DECLARE_SP_MODULE(recipientfilter_c)
4848
//-----------------------------------------------------------------------------
4949
void export_mrecipientfilter()
5050
{
51-
// TODO: Rename class
52-
class_<MRecipientFilter, boost::noncopyable>("CMRecipientFilter")
51+
class_<IRecipientFilter, boost::noncopyable>("_RecipientFilter", no_init)
5352
.def("is_reliable",
54-
&MRecipientFilter::IsReliable,
53+
&IRecipientFilter::IsReliable,
5554
"Whether this recipient filter will be network reliable (sent in-order)"
5655
)
5756

5857
.def("is_init_message",
59-
&MRecipientFilter::IsInitMessage,
58+
&IRecipientFilter::IsInitMessage,
6059
"Whether the message has been initialised?"
6160
)
6261

6362
.def("get_recipient_count",
64-
&MRecipientFilter::GetRecipientCount,
63+
&IRecipientFilter::GetRecipientCount,
6564
"Obtain the amount of clients in this filter"
6665
)
6766

6867
.def("get_recipient_index",
69-
&MRecipientFilter::GetRecipientIndex,
68+
&IRecipientFilter::GetRecipientIndex,
7069
"Obtains the player index at the slot in the filter",
7170
args("slot")
7271
)
72+
;
7373

74+
// TODO: Rename class
75+
class_<MRecipientFilter, bases<IRecipientFilter>, boost::noncopyable >("CMRecipientFilter")
7476
.def("add_all_players",
7577
&MRecipientFilter::AddAllPlayers,
7678
"Adds all the players on the server to the filter"

0 commit comments

Comments
 (0)