/***************************************************************/ /* */ /* PBSOUNDS.PKG */ /* */ /* plug-in PhotoPaintBall */ /* client - sounds management */ /* */ /* version 5 : Loïc Berthelot, dec 2000 */ /* */ /* nouvelle version 4.5 : Loïc Berthelot nov 2000 */ /* */ /* Photo3 Plugin - DMS - march 00 - by Sylvain HUET */ /* */ /***************************************************************/ /***************************************************************/ /* */ /* */ /* DATA STRUCTS : */ /* struct SndEl */ /* struct SndItems */ /* typeof soundsLib : tab SndEl */ /* var soundsLibSize : I */ /* typeof soundsItems : SndItems */ /* */ /* */ /* INTERNAL BODY : */ /* sounds_getWav : fun [S] [S I I I I] */ /* sounds_startSndItems : fun [] I */ /* sounds_load : fun [I] I */ /* sounds_start2 : fun [] I */ /* sounds_playBuffer : fun [DSBuffer] I */ /* sounds_free : fun [I] I */ /* sounds_destroySndItems : fun [] I */ /* */ /* */ /* EXTERNAL BODY : */ /* sounds_reload : fun [I] I */ /* sounds_shoot : fun [I] I */ /* sounds_hurt : fun [I] I */ /* sounds_life : fun [] I */ /* sounds_spinachDamage : fun [] I */ /* sounds_destroy : fun [] I */ /* sounds_start : fun [] I */ /* */ /* */ /***************************************************************/ /******************************************************************************/ /* */ /* D A T A S T R U C T S */ /* */ /******************************************************************************/ struct SndEl = [ /* reload sound filename */ reloadFln_SndEl : S, /* reload sound buffer */ reload_SndEl : DSBuffer, /* shoot sound filename */ shootFln_SndEl : S, /* shoot sound buffer */ shoot_SndEl : DSBuffer, /* impact sound filename */ hurtFln_SndEl : S, /* impact sound buffer */ hurt_SndEl : DSBuffer ] mkSndEl;; struct SndItems = [ /* life item sound filename */ lifeFln_SndITM : S, /* buffer */ life_SndITM : DSBuffer, /* spinachDamage item sound filename */ spinachDamageFln_SndITM : S, /* buffer */ spinachDamage_SndITM : DSBuffer ] mkSndItems;; typeof soundsLib = tab SndEl;; var soundsLibSize = 10;; typeof soundsItems = SndItems;; /******************************************************************************/ /* */ /* I N T E R N A L B O D Y */ /* */ /******************************************************************************/ /******************************************/ /* sounds_getWav [S] [S I I I I] */ /* */ /* return informations about the wav file */ /******************************************/ fun _getWav (filename) = let _checkpack filename -> file in if (file == nil) then nil else ( let _GETwaveInfo file -> [size chns freq bits] in let _GETwaveData file -> data in [data size chns freq bits]; ) ;; /******************************************/ /* sounds_startSndItems [] I */ /* */ /* set the items sound buffers */ /******************************************/ fun sounds_startSndItems() = let strcatn pbItemsPath::"life/"::pbDefault.lifeSndFln_PBD::nil -> lifeFln in let strcatn pbItemsPath::"life/"::pbDefault.spinachDamageSndFln_PBD::nil -> spinachDamageFln in let _checkpack lifeFln -> file1 in let _checkpack spinachDamageFln -> file2 in let if (file1 == nil) then lifeFln else if (file2 == nil) then spinachDamageFln else nil -> filenameNil in if (filenameNil != nil) then defines_fofError "photoSounds.pkg sounds_start2 () " filenameNil else let _getWav lifeFln -> [data size chns freq bits] in let _CRSoundBuffer DMSds chns freq bits size 1|2 -> bf in let _SETSoundBuffer bf data 0 -> sndBf in let set soundsItems.life_SndITM = sndBf -> tmp in let set soundsItems.lifeFln_SndITM = lifeFln -> tmp in let _getWav spinachDamageFln -> [data size chns freq bits] in let _CRSoundBuffer DMSds chns freq bits size 1|2 -> bf in let _SETSoundBuffer bf data 0 -> sndBf in ( set soundsItems.spinachDamageFln_SndITM = spinachDamageFln; set soundsItems.spinachDamage_SndITM = sndBf; 1; ) ;; /******************************************/ /* sounds_load [I] I */ /* */ /* load sounds from index */ /******************************************/ fun sounds_load (i) = let _getWav soundsLib.(i).reloadFln_SndEl -> [data size chns freq bits] in ( let _CRSoundBuffer DMSds chns freq bits size 1|2 -> bf in let _SETSoundBuffer bf data 0 -> sndBf in set soundsLib.(i).reload_SndEl = sndBf; ); let _getWav soundsLib.(i).shootFln_SndEl -> [data size chns freq bits] in ( let _CRSoundBuffer DMSds chns freq bits size 1|2 -> bf in let _SETSoundBuffer bf data 0 -> sndBf in set soundsLib.(i).shoot_SndEl = sndBf; ); let _getWav soundsLib.(i).hurtFln_SndEl -> [data size chns freq bits] in ( let _CRSoundBuffer DMSds chns freq bits size 1|2 -> bf in let _SETSoundBuffer bf data 0 -> sndBf in set soundsLib.(i).hurt_SndEl = sndBf; ); 1 ;; /******************************************/ /* sounds_start2 [] I */ /* */ /* constr the sound lib */ /******************************************/ fun sounds_start2() = sounds_startSndItems; let 0 -> i in while (i < soundsLibSize) do ( let strcatn pbItemsPath::(itoa i)::"/"::pbDefault.reloadSndFln_PBD::nil -> filename1 in let strcatn pbItemsPath::(itoa i)::"/"::pbDefault.shootSndFln_PBD::nil -> filename2 in let strcatn pbItemsPath::(itoa i)::"/"::pbDefault.hurtSndFln_PBD::nil -> filename3 in let _checkpack filename1 -> file1 in let _checkpack filename2 -> file2 in let _checkpack filename3 -> file3 in let if (file1 == nil) then filename1 else if (file2 == nil) then filename2 else if (file3 == nil) then filename3 else nil -> filenameNil in if (filenameNil != nil) then defines_fofError "photoSounds.pkg sounds_start2 () " filenameNil else ( set soundsLib.(i) = mkSndEl [filename1 nil filename2 nil filename3 nil]; 1; ); sounds_load i; set i = i+1; ); pbFlags_set "sounds"; 1 ;; /******************************************/ /* sounds_playBuffer [DSBuffer] I */ /* */ /* play sound buffer */ /******************************************/ fun sounds_playBuffer (bf) = _STOPSoundBuffer bf; _SETPlayPosition bf 0; _PLAYSoundBuffer bf 0; 1 ;; /************************************/ /* sounds_free [I] I */ /* */ /* free sounds ressources, */ /* identified by index */ /************************************/ fun sounds_free (index) = _DSSoundBuffer soundsLib.(index).reload_SndEl; _DSSoundBuffer soundsLib.(index).shoot_SndEl; _DSSoundBuffer soundsLib.(index).hurt_SndEl; 1 ;; fun sounds_destroySndItems () = _DSSoundBuffer soundsItems.life_SndITM; _DSSoundBuffer soundsItems.spinachDamage_SndITM; 1 ;; /******************************************************************************/ /* */ /* E X T E R N A L B O D Y */ /* */ /******************************************************************************/ /******************************************/ /* sounds_reload [I] I */ /* */ /* play reload sound */ /******************************************/ fun sounds_reload (index) = let soundsLib.(index).reload_SndEl -> bf in sounds_playBuffer bf ;; /******************************************/ /* sounds_shoot [I] I */ /* */ /* play shoot sound */ /******************************************/ fun sounds_shoot (index) = let soundsLib.(index).shoot_SndEl -> bf in sounds_playBuffer bf ;; /******************************************/ /* sounds_hurt [I] I */ /* */ /* play hurt sound */ /******************************************/ fun sounds_hurt (index) = let soundsLib.(index).hurt_SndEl -> bf in sounds_playBuffer bf ;; fun sounds_life () = sounds_playBuffer soundsItems.life_SndITM ;; fun sounds_spinachDamage () = sounds_playBuffer soundsItems.spinachDamage_SndITM ;; /******************************************/ /* sounds_destroy [] I */ /* */ /* destroy the sounds lib */ /******************************************/ fun sounds_destroy() = sounds_destroySndItems; let 0 -> i in while (i < soundsLibSize) do ( sounds_free i; set i = i+1; ); 1 ;; /******************************************/ /* sounds_start [] I */ /* */ /* construct the sounds lib */ /******************************************/ fun sounds_start () = DMSinitDirectSound 2 44100 16 DSSCL_PRIORITY; set soundsLib = mktab soundsLibSize nil; set soundsItems = mkSndItems [nil nil nil nil]; sounds_start2; 1 ;;