Browse Source

HL:Invasion Move music player to the client side

invasion^2
Roy Shapiro 2 years ago
parent
commit
3e62e6b719
  1. 5
      cl_dll/CMakeLists.txt
  2. 443
      cl_dll/clientmusic.cpp
  3. 26
      cl_dll/clientmusic.h
  4. 1
      cl_dll/hud.cpp
  5. 9
      cl_dll/hud.h
  6. 4
      dlls/CMakeLists.txt
  7. 419
      dlls/music.cpp
  8. 2
      dlls/player.cpp

5
cl_dll/CMakeLists.txt

@ -46,6 +46,10 @@ if (GOLDSOURCE_SUPPORT) @@ -46,6 +46,10 @@ if (GOLDSOURCE_SUPPORT)
add_definitions(-DGOLDSOURCE_SUPPORT)
endif()
if (DISABLE_MINIAUDIO)
add_definitions(-DDISABLE_MINIAUDIO)
endif()
if (USE_VGUI)
add_definitions(-DUSE_VGUI)
if (USE_NOVGUI_MOTD)
@ -73,6 +77,7 @@ set (CLDLL_SOURCES @@ -73,6 +77,7 @@ set (CLDLL_SOURCES
hudzoom.cpp
lensflare.cpp
nvg.cpp
clientmusic.cpp
particules.cpp
studio_util.cpp
StudioModelRenderer.cpp

443
cl_dll/clientmusic.cpp

@ -0,0 +1,443 @@ @@ -0,0 +1,443 @@
//-------------------------------------------------------------
//-------------------------------------------------------------
//-
//- clientmusic.cpp
//-
//-------------------------------------------------------------
//-------------------------------------------------------------
//- by Roy at suggestion by nekonomicon, based on code by JujU
//-------------------------------------------------------------
//- mp3 player code for HL mod
//-------------------------------------------------------------
//-
//- compatible with version 0.11.9 of Miniaudio
//- https://github.com/mackron/miniaudio
//-
//-------------------------------------------------------------
/*
Don't forget to update the miniaudio submodule.
Miniaudio 0.11.9 or better required.
Tested on Debian.
For playlist format see the bottom of the file.
*/
//---------------------------------------------------------
// inclusions
#include "hud.h"
#include "cl_util.h"
#include "const.h"
#include "parsemsg.h"
#ifndef DISABLE_MINIAUDIO //Use this to exclude the player in it's entirety. Will use empty "trigger_music" with no playback.
#include "clientmusic.h"
CMusic g_MusicPlayer; //Instantiate.
//These are just initial ones. If the actual track has different ones, they will be re-applied during Play().
#define SAMPLE_FORMAT ma_format_f32
#define CHANNEL_COUNT 2
#define SAMPLE_RATE 48000
//---------------------------------------------------------
// implementation CHudMusic class methods (defined in hud.h)
//CHudMusic is declared in hud.h and is needed to receive messages.
//hud.cpp also contains and Init function call.
//The implementation goes here:
#endif //The code above can be disabled if we don't actually use a music player, but this
//section here must be present anyway, since we need to implement things hud.h and hud.cpp
//expect us to implement.
DECLARE_MESSAGE(m_MusicPlayer, CMusicOpen );
int CHudMusic :: Init( void ){
HOOK_MESSAGE( CMusicOpen );
return 1;
}
int CHudMusic :: MsgFunc_CMusicOpen ( const char *pszName, int iSize, void *pbuf ){
char* fnString;
char filename[512];
int filetype = 0;
BEGIN_READ( pbuf, iSize );
filetype = READ_BYTE();
fnString = READ_STRING();
sprintf(filename,"%s",fnString);
#ifndef DISABLE_MINIAUDIO //This part must only be present if we actually have a music player.
//gEngfuncs.Con_Printf ( "MUSICPLAYER : Received message from server: File type is %d, file name is: %s\n", filetype, filename );
if(filetype != MUSIC_AUDIO_FILE)
g_MusicPlayer.OpenList ( filename );
else
g_MusicPlayer.OpenFile ( filename, 1 );
g_MusicPlayer.Play();
#else //Otherwise we do nothing here.
//gEngfuncs.Con_Printf ( "MUSICPLAYER : Received message, but player is disabled. Discarding.\n" );
#endif
return 1;
}
#ifndef DISABLE_MINIAUDIO //The code below can, once again, be disabled if we don't
//actually use a music player.
//Define callback, so we can use it during init. The implementation can be found below.
void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount);
//---------------------------------------------------------
// initialisation
void CMusic :: Init ( void )
{
if( m_bInit == true ){
return; //Do not re-init.
}
deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = SAMPLE_FORMAT;
deviceConfig.playback.channels = CHANNEL_COUNT;
deviceConfig.sampleRate = SAMPLE_RATE;
deviceConfig.dataCallback = CMusic_DecoderCallback; // this contains the callback that monitors the end of the song
deviceConfig.pUserData = NULL;
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
gEngfuncs.Con_Printf ( "MUSICPLAYER : unable to initialize\n" );
return;
}
m_bInit = true;
return;
}
//---------------------------------------------------------
// Callback being called during playback
void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
if(g_MusicPlayer.m_IsPlaying == false){
return; //We are paused or stopped, let's exit now.
}
ma_decoder* pDecoder = (ma_decoder*)&g_MusicPlayer.decoder;
if (pDecoder == NULL) {
return;
}
if(frameCount<=0) return;
ma_uint64 framesRead;
ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount, &framesRead);
if(framesRead < frameCount) //This happens when the song ends.
g_MusicPlayer.songEnd();
(void)pInput;
}
//---------------------------------------------------------
// playing an audio file
void CMusic :: OpenFile ( char *filename, int repeat )
{
audiofile_t *p = NULL;
p = new audiofile_t;
sprintf ( p->name, filename );
p->repeat = repeat;
p->next = m_pTrack;
m_pTrack = p;
}
//---------------------------------------------------------
// play a list of audio files
void CMusic :: OpenList ( char *filename )
{
// open text file
FILE *myfile = fopen ( filename, "r" );
if ( myfile == NULL )
{
gEngfuncs.Con_Printf ( "MUSICPLAYER : impossible to load %s\n", filename );
return;
}
// saving songs to the list
int total = 0;
if ( fscanf ( myfile, "%i", &total ) != EOF )
{
for ( int i=0; i<total; i++ )
{
char ctitle [128];
int irepeat;
// reading the title
if ( fscanf ( myfile, "%s", ctitle ) != EOF )
{
if ( fscanf ( myfile, "%i", &irepeat ) != EOF )
OpenFile ( ctitle, irepeat );
else
break;
}
else
break;
}
}
// close text file
fclose ( myfile );
}
//---------------------------------------------------------
// end of the song
void CMusic :: songEnd ( )
{
// end of the song
g_MusicPlayer.Stop ();
// search for the first song in the list
audiofile_t *p = NULL;
p = g_MusicPlayer.m_pTrack;
while ( p != NULL )
{
if ( p->next == NULL )
break;
else
p = p->next;
}
if ( p == NULL )
{
gEngfuncs.Con_Printf ( "MUSICPLAYER : no song in the list\n" );
return;
}
// decrease repeat count
p->repeat --;
// removal of songs whose repeats ran off
if ( p->repeat < 1 )
{
if ( g_MusicPlayer.m_pTrack == p )
{
delete g_MusicPlayer.m_pTrack;
g_MusicPlayer.m_pTrack = NULL;
}
else
{
audiofile_t *q = NULL;
q = g_MusicPlayer.m_pTrack;
while ( q->next != p )
q = q->next;
delete q->next;
q->next = NULL;
}
}
// close player if list is empty
if ( g_MusicPlayer.m_pTrack == NULL )
{
g_MusicPlayer.Reset();
}
// next track start
else
{
g_MusicPlayer.Play();
}
return;
}
//---------------------------------------------------------
// initiate playback
void CMusic :: Play ( void )
{
if ( m_IsPlaying == true )
return;
if ( m_bInit == false )
{
Init ();
if ( m_bInit == false )
{
gEngfuncs.Con_Printf ( "MUSICPLAYER : unable to initialize\n" );
return;
}
}
// search for the first song in the list
audiofile_t *p = NULL;
p = m_pTrack;
while ( p != NULL )
{
if ( p->next == NULL )
break;
else
p = p->next;
}
if ( p == NULL )
{
gEngfuncs.Con_Printf ( "MUSICPLAYER : no song in the list\n" );
return;
}
//Stop playback
m_IsPlaying = false; //Pause playback.
ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start.
// loading file
char payload [512];
sprintf(payload, "%s", p->name);
gEngfuncs.Con_Printf ( "MUSICPLAYER : Opening file %s.\n", payload );
result = ma_decoder_init_file(payload, NULL, &decoder);
if (result != MA_SUCCESS) {
gEngfuncs.Con_Printf ( "MUSICPLAYER : %s : can not load file\n", p->name );
return;
}
//If the new track has different properties to the previous one.
if(
deviceConfig.playback.format != decoder.outputFormat ||
deviceConfig.playback.channels != decoder.outputChannels ||
deviceConfig.sampleRate != decoder.outputSampleRate
){
deviceConfig.playback.format = decoder.outputFormat; //Change device settings
deviceConfig.playback.channels = decoder.outputChannels;
deviceConfig.sampleRate = decoder.outputSampleRate;
gEngfuncs.Con_Printf ( "MUSICPLAYER : Changing format to %d, channels to %d and sample rate to %d.\n", deviceConfig.playback.format, deviceConfig.playback.channels, deviceConfig.sampleRate);
//Now we need to recreate the device to apply.
ma_device_uninit(&device); //This is crucial, failing to do this results in segFault.
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { //Apply new config.
gEngfuncs.Con_Printf ( "MUSICPLAYER : Failed to change playback device configuration.\n" );
g_MusicPlayer.m_bInit = false; //We have been deinitialized. This is NOT ideal.
return;
}else
gEngfuncs.Con_Printf ( "MUSICPLAYER : New configuration applied successfully.\n");
}
// playback
if (ma_device_start(&device) != MA_SUCCESS) {
gEngfuncs.Con_Printf ( "MUSICPLAYER : Failed to start playback device.\n" );
m_IsPlaying = false; //Pause playback.
ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start.
return;
}else{
m_IsPlaying = true;
}
return;
}
void CMusic :: Stop ( void )
{
if ( m_IsPlaying == true )
{
m_IsPlaying = false; //Pause playback.
ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start.
}
}
void CMusic :: Reset ( void ) //Should instead be called "Next Track", but we keep Julien's naming.
{
//Reset the player.
if ( m_bInit == true )
gEngfuncs.Con_Printf ( "MUSICPLAYER : Player reset.\n" );
Stop();
audiofile_t *p = NULL;
while ( m_pTrack != NULL )
{
p = m_pTrack;
m_pTrack = p->next;
delete p;
}
}
void CMusic :: Terminate ( void ) //Cleanup and dereference
{
gEngfuncs.Con_Printf ( "MUSICPLAYER : Terminating and unloading.\n" );
ma_device_uninit(&device);
ma_decoder_uninit(&decoder);
g_MusicPlayer.m_bInit = false;
}
#endif //End if #ifndef DISABLE_MINIAUDIO
/*//---------------
Playlist contents
example: music01.txt file:
//
3
monmod/sound/mp3/music01_debut.mp3 1
monmod/sound/mp3/music01_boucle.mp3 3
monmod/sound/mp3/music01_fin.mp3 1
//
composition :
- total number of tracks
- path of the first music file
- times to repeat that file
- path of the second
- etc ...
*///---------------

26
dlls/music.h → cl_dll/clientmusic.h

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
//-------------------------------------------------------------
//-------------------------------------------------------------
//-
//- music.h
//- clientmusic.h
//-
//-------------------------------------------------------------
//-------------------------------------------------------------
@ -15,8 +15,8 @@ @@ -15,8 +15,8 @@
//-
//-------------------------------------------------------------
#ifndef MUSIC_H
#define MUSIC_H
#ifndef CLIENTMUSIC_H
#define CLIENTMUSIC_H
#define MINIAUDIO_IMPLEMENTATION
#include "../miniaudio/miniaudio.h"
@ -41,14 +41,14 @@ struct audiofile_t @@ -41,14 +41,14 @@ struct audiofile_t
// reader class
class CMusic
class CMusic //: public CHudBase
{
public:
// reading functions
void OpenFile ( const char *filename, int repeat ); // open a single file
void OpenList ( const char *filename ); // opening a text file containing the files
void OpenFile ( char *filename, int repeat ); // open a single file
void OpenList ( char *filename ); // opening a text file containing the files
void Init ( void ); // initialization
@ -59,14 +59,14 @@ public: @@ -59,14 +59,14 @@ public:
// variables
BOOL m_IsPlaying; // monitors whether the music is played, used to pause the music
BOOL m_bInit; // checks if the player is initialized
bool m_IsPlaying; // monitors whether the music is played, used to pause the music
bool m_bInit; // checks if the player is initialized
audiofile_t *m_pTrack; // playlist items
// constructor / destructor
CMusic () { m_bInit = FALSE; m_IsPlaying = FALSE; m_pTrack = NULL; Reset(); };
CMusic () { m_bInit = false; m_IsPlaying = false; m_pTrack = NULL; Reset(); };
~CMusic () { Terminate(); };
// object instances
@ -76,8 +76,14 @@ public: @@ -76,8 +76,14 @@ public:
ma_device_config deviceConfig;
ma_device device;
// messages
int MsgFunc_CMusicOpen ( const char *pszName, int iSize, void *pbuf );
// monitoring functions
void songEnd();
};
extern CMusic g_MusicPlayer;
#endif // MUSIC_H
#endif // CLIENTMUSIC_H

1
cl_dll/hud.cpp

@ -469,6 +469,7 @@ void CHud::Init( void ) @@ -469,6 +469,7 @@ void CHud::Init( void )
m_Particules.Init();
m_Sniper.Init();
m_NVG.Init();
m_MusicPlayer.Init(); //modif de Roy, we need to initialize the music player's message receiver (see hud.h)
m_RPG.Init();
m_Fog.Init();
m_LFlammes.Init();

9
cl_dll/hud.h

@ -801,7 +801,13 @@ public: @@ -801,7 +801,13 @@ public:
};
// modif de Roy
class CHudMusic : public CHudBase // This class is simply a message receiver for the music player
{
public: //The methods are implemented in clientmusic.cpp
int Init( void ); //This gets called from hud.cpp
int MsgFunc_CMusicOpen ( const char *pszName, int iSize, void *pbuf );
};
// modif de Julien
//
@ -1078,6 +1084,7 @@ public: @@ -1078,6 +1084,7 @@ public:
CHudParticules m_Particules;
CHudSniper m_Sniper;
CHudNVG m_NVG;
CHudMusic m_MusicPlayer; //modif de Roy, we need an instance of the music player's message receiver
CHudRPG m_RPG;
CHudFog m_Fog;
CHudLFlammes m_LFlammes;

4
dlls/CMakeLists.txt

@ -37,10 +37,6 @@ else() @@ -37,10 +37,6 @@ else()
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
endif()
if (DISABLE_MINIAUDIO)
add_definitions(-DDISABLE_MINIAUDIO)
endif()
set (SVDLL_SOURCES
aflock.cpp
agrunt.cpp

419
dlls/music.cpp

@ -7,366 +7,27 @@ @@ -7,366 +7,27 @@
//-------------------------------------------------------------
//- by Roy at suggestion by nekonomicon, based on code by JujU
//-------------------------------------------------------------
//- mp3 player code for HL mod
//- mp3 player code for HL mod; trigger_music implementation
//-------------------------------------------------------------
//-
//- compatible with version 0.11.9 of Miniaudio
//- https://github.com/mackron/miniaudio
//- This is the server-side code.
//- It implements trigger_music, which simply informs the
//- client when and what music needs to be played.
//- No actual playback happens here.
//- We just send a message containing file type and filename.
//-
//-------------------------------------------------------------
/*
Don't forget to update the miniaudio submodule.
Miniaudio 0.11.9 or better required.
Tested on Debian.
For playlist format see the bottom of the file.
*/
//---------------------------------------------------------
// inclusions
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "gamerules.h" //We need g_pGameRules to determine if we're in multiplayer.
#ifndef DISABLE_MINIAUDIO //Use this to exclude the player in it's entirety. Will use empty "trigger_music" with no playback.
#include "music.h"
//These are just initial ones. If the actual track has different ones, they will be re-applied during Play().
#define SAMPLE_FORMAT ma_format_f32
#define CHANNEL_COUNT 2
#define SAMPLE_RATE 48000
CMusic g_MusicPlayer;
void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount);
//---------------------------------------------------------
// initialisation
void CMusic :: Init ( void )
{
if( m_bInit == TRUE ){
return; //Do not re-init.
}
deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = SAMPLE_FORMAT;
deviceConfig.playback.channels = CHANNEL_COUNT;
deviceConfig.sampleRate = SAMPLE_RATE;
deviceConfig.dataCallback = CMusic_DecoderCallback; // this contains the callback that monitors the end of the song
deviceConfig.pUserData = NULL;
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
ALERT ( at_console, "MUSICPLAYER : unable to initialize\n" );
return;
}
m_bInit = TRUE;
}
//---------------------------------------------------------
// Callback being called during playback
void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
if(g_MusicPlayer.m_IsPlaying == FALSE){
return; //We are paused or stopped, let's exit now.
}
ma_decoder* pDecoder = (ma_decoder*)&g_MusicPlayer.decoder;
if (pDecoder == NULL) {
return;
}
if(frameCount<=0) return;
ma_uint64 framesRead;
ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount, &framesRead);
if(framesRead < frameCount) //This happens when the song ends.
g_MusicPlayer.songEnd();
(void)pInput;
}
//---------------------------------------------------------
// playing an audio file
void CMusic :: OpenFile ( const char *filename, int repeat )
{
audiofile_t *p = NULL;
p = new audiofile_t;
sprintf ( p->name, filename );
p->repeat = repeat;
p->next = m_pTrack;
m_pTrack = p;
}
//---------------------------------------------------------
// play a list of audio files
void CMusic :: OpenList ( const char *filename )
{
// open text file
FILE *myfile = fopen ( filename, "r" );
if ( myfile == NULL )
{
ALERT ( at_console, "MUSICPLAYER : impossible to load %s\n", filename );
return;
}
// saving songs to the list
int total = 0;
if ( fscanf ( myfile, "%i", &total ) != EOF )
{
for ( int i=0; i<total; i++ )
{
char ctitle [128];
int irepeat;
// reading the title
if ( fscanf ( myfile, "%s", ctitle ) != EOF )
{
if ( fscanf ( myfile, "%i", &irepeat ) != EOF )
OpenFile ( ctitle, irepeat );
else
break;
}
else
break;
}
}
// close text file
fclose ( myfile );
}
//---------------------------------------------------------
// end of the song
void CMusic :: songEnd ( )
{
// end of the song
g_MusicPlayer.Stop ();
// search for the first song in the list
audiofile_t *p = NULL;
p = g_MusicPlayer.m_pTrack;
while ( p != NULL )
{
if ( p->next == NULL )
break;
else
p = p->next;
}
if ( p == NULL )
{
ALERT ( at_console, "MUSICPLAYER : no song in the list\n" );
return;
}
// decrease repeat count
p->repeat --;
// removal of songs whose repeats ran off
if ( p->repeat < 1 )
{
if ( g_MusicPlayer.m_pTrack == p )
{
delete g_MusicPlayer.m_pTrack;
g_MusicPlayer.m_pTrack = NULL;
}
else
{
audiofile_t *q = NULL;
q = g_MusicPlayer.m_pTrack;
while ( q->next != p )
q = q->next;
delete q->next;
q->next = NULL;
}
}
// close player if list is empty
if ( g_MusicPlayer.m_pTrack == NULL )
{
g_MusicPlayer.Reset();
}
// next track start
else
{
g_MusicPlayer.Play();
}
return;
}
//---------------------------------------------------------
// initiate playback
void CMusic :: Play ( void )
{
if ( m_IsPlaying == TRUE )
return;
if ( m_bInit == FALSE )
{
Init ();
if ( m_bInit == FALSE )
{
ALERT ( at_console, "MUSICPLAYER : unable to initialize\n" );
return;
}
}
// search for the first song in the list
audiofile_t *p = NULL;
p = m_pTrack;
while ( p != NULL )
{
if ( p->next == NULL )
break;
else
p = p->next;
}
if ( p == NULL )
{
ALERT ( at_console, "MUSICPLAYER : no song in the list\n" );
return;
}
//Stop playback
m_IsPlaying = FALSE; //Pause playback.
ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start.
// loading file
char payload [512];
sprintf(payload, "%s", p->name);
ALERT ( at_console, "MUSICPLAYER : Opening file %s.\n", payload );
result = ma_decoder_init_file(payload, NULL, &decoder);
if (result != MA_SUCCESS) {
ALERT ( at_console, "MUSICPLAYER : %s : can not load file\n", p->name );
return;
}
//If the new track has different properties to the previous one.
if(
deviceConfig.playback.format != decoder.outputFormat ||
deviceConfig.playback.channels != decoder.outputChannels ||
deviceConfig.sampleRate != decoder.outputSampleRate
){
deviceConfig.playback.format = decoder.outputFormat; //Change device settings
deviceConfig.playback.channels = decoder.outputChannels;
deviceConfig.sampleRate = decoder.outputSampleRate;
ALERT ( at_console, "MUSICPLAYER : Changing format to %d, channels to %d and sample rate to %d.\n", deviceConfig.playback.format, deviceConfig.playback.channels, deviceConfig.sampleRate);
//Now we need to recreate the device to apply.
ma_device_uninit(&device); //This is crucial, failing to do this results in segFault.
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { //Apply new config.
ALERT ( at_console, "MUSICPLAYER : Failed to change playback device configuration.\n" );
g_MusicPlayer.m_bInit = FALSE; //We have been deinitialized. This is NOT ideal.
return;
}else
ALERT ( at_console, "MUSICPLAYER : New configuration applied successfully.\n");
}
// playback
if (ma_device_start(&device) != MA_SUCCESS) {
ALERT ( at_console, "MUSICPLAYER : Failed to start playback device.\n" );
m_IsPlaying = FALSE; //Pause playback.
ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start.
return;
}else{
m_IsPlaying = TRUE;
}
return;
}
extern int gmsgCMusicMessage; //This is simply a "handle" for the message. It's defined in player.cpp, can be defined here, but we'll follow the conventions.
void CMusic :: Stop ( void )
{
if ( m_IsPlaying == TRUE )
{
m_IsPlaying = FALSE; //Pause playback.
ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start.
}
}
void CMusic :: Reset ( void ) //Should instead be called "Next Track", but we keep Julien's naming.
{
//Reset the player.
if ( m_bInit == TRUE )
ALERT ( at_console, "MUSICPLAYER : Player reset.\n" );
Stop();
audiofile_t *p = NULL;
while ( m_pTrack != NULL )
{
p = m_pTrack;
m_pTrack = p->next;
delete p;
}
}
void CMusic :: Terminate ( void ) //Cleanup and dereference
{
ALERT ( at_console, "MUSICPLAYER : Terminating and unloading.\n" );
ma_device_uninit(&device);
ma_decoder_uninit(&decoder);
g_MusicPlayer.m_bInit = FALSE;
}
#endif //End if #ifndef DISABLE_MINIAUDIO
//---------------------------------------------------------
// entity class
@ -410,14 +71,8 @@ IMPLEMENT_SAVERESTORE( CTriggerMusic, CPointEntity ); @@ -410,14 +71,8 @@ IMPLEMENT_SAVERESTORE( CTriggerMusic, CPointEntity );
void CTriggerMusic :: Spawn( void )
{
if( g_pGameRules->IsDeathmatch() ) //Do not spawn in multiplayer.
{
REMOVE_ENTITY( ENT( pev ) );
return;
}
pev->solid = SOLID_NOT;
pev->effects = EF_NODRAW;
}
void CTriggerMusic :: KeyValue( KeyValueData *pkvd )
@ -438,36 +93,14 @@ void CTriggerMusic :: KeyValue( KeyValueData *pkvd ) @@ -438,36 +93,14 @@ void CTriggerMusic :: KeyValue( KeyValueData *pkvd )
void CTriggerMusic :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
if( g_pGameRules->IsMultiplayer() ) //Do not activate / do anything in multiplayer.
return;
#ifndef DISABLE_MINIAUDIO
if ( g_MusicPlayer.m_IsPlaying == TRUE )
return;
if ( m_iFileType == MUSIC_AUDIO_FILE )
{
g_MusicPlayer.OpenFile ( STRING(m_iFileName), 1 );
}
else
{
g_MusicPlayer.OpenList ( STRING(m_iFileName) );
}
g_MusicPlayer.Play();
#else
return; //Do nothing, we have neither g_MusicPlayer, nor miniaudio.
#endif
MESSAGE_BEGIN( MSG_ALL, gmsgCMusicMessage, NULL ); //Inform the client side, we have some music to play.
WRITE_BYTE( m_iFileType ); //Send file type.
WRITE_STRING( STRING(m_iFileName) ); //Send file name.
MESSAGE_END();
}
/*
code
FGD file entity code
@PointClass base( Targetname ) = trigger_music : "Trigger Music"
@ -480,30 +113,4 @@ code @@ -480,30 +113,4 @@ code
filename(string) : "Name (mod/folder/file.extension)"
]
*/
/*//---------------
Playlist contents
example: music01.txt file:
//
3
monmod/sound/mp3/music01_debut.mp3 1
monmod/sound/mp3/music01_boucle.mp3 3
monmod/sound/mp3/music01_fin.mp3 1
//
composition :
- total number of tracks
- path of the first music file
- times to repeat that file
- path of the second
- etc ...
*///---------------
*/

2
dlls/player.cpp

@ -234,6 +234,7 @@ int gmsgTankView = 0; @@ -234,6 +234,7 @@ int gmsgTankView = 0;
int gmsgRadioMsg = 0;
int gmsgKeypad = 0;
int gmsgConveyor = 0;
int gmsgCMusicMessage = 0; //modif de Roy, Used by the music player to send filenames to the client side.
void LinkUserMessages( void )
@ -321,6 +322,7 @@ void LinkUserMessages( void ) @@ -321,6 +322,7 @@ void LinkUserMessages( void )
gmsgKeypad = REG_USER_MSG( "Keypad", -1);
gmsgConveyor = REG_USER_MSG( "Conveyor", -1);
//fin de modifs de Julien
gmsgCMusicMessage = REG_USER_MSG( "CMusicOpen", -1 ); //modif de Roy, Used by the music player to send filenames to the client side.
gmsgTeamNames = REG_USER_MSG( "TeamNames", -1 );
gmsgBhopcap = REG_USER_MSG( "Bhopcap", 1 );

Loading…
Cancel
Save