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
5152extern IVEngineServer* engine;
53+ extern IEngineSound* enginesound;
5254
5355// ---------------------------------------------------------------------------------
5456// Exposes the engine module.
5557// ---------------------------------------------------------------------------------
5658void export_engine_interface ();
59+ void export_engine_sound ();
5760
5861DECLARE_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+ }
0 commit comments