2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2009-06-05 13:41:20 +00:00
|
|
|
* Copyright (c) 1998-2000 Matthes Bender
|
|
|
|
* Copyright (c) 2001, 2005, 2008 Sven Eberhardt
|
|
|
|
* Copyright (c) 2004 Peter Wortmann
|
|
|
|
* Copyright (c) 2005 Günther Brammer
|
2009-05-08 13:28:41 +00:00
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
|
|
|
|
*
|
|
|
|
* Portions might be copyrighted by other authors who have contributed
|
|
|
|
* to OpenClonk.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
* See isc_license.txt for full license and disclaimer.
|
|
|
|
*
|
|
|
|
* "Clonk" is a registered trademark of Matthes Bender.
|
|
|
|
* See clonk_trademark_license.txt for full license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Handles the sound bank and plays effects using FMOD */
|
|
|
|
|
|
|
|
#ifndef INC_C4SoundSystem
|
|
|
|
#define INC_C4SoundSystem
|
|
|
|
|
|
|
|
#include <C4Group.h>
|
|
|
|
|
2009-11-02 13:18:47 +00:00
|
|
|
#ifdef HAVE_FMOD
|
2009-05-08 13:28:41 +00:00
|
|
|
#include <fmod.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBSDL_MIXER
|
|
|
|
#define USE_RWOPS
|
|
|
|
#include <SDL_mixer.h>
|
|
|
|
#undef USE_RWOPS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const int32_t C4MaxSoundName=100,
|
2010-03-28 17:58:21 +00:00
|
|
|
C4MaxSoundInstances=20,
|
|
|
|
C4NearSoundRadius=50,
|
|
|
|
C4AudibilityRadius=700;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-09-21 04:01:55 +00:00
|
|
|
class C4Object;
|
2009-05-08 13:28:41 +00:00
|
|
|
class C4SoundInstance;
|
|
|
|
|
|
|
|
class C4SoundEffect
|
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
friend class C4SoundInstance;
|
2009-05-08 13:28:41 +00:00
|
|
|
public:
|
2010-03-27 16:05:02 +00:00
|
|
|
C4SoundEffect();
|
|
|
|
~C4SoundEffect();
|
2009-05-08 13:28:41 +00:00
|
|
|
public:
|
2010-03-27 16:05:02 +00:00
|
|
|
char Name[C4MaxSoundName+1];
|
|
|
|
int32_t UsageTime, Instances;
|
|
|
|
int32_t SampleRate, Length;
|
2009-08-15 18:50:32 +00:00
|
|
|
bool Static;
|
2009-11-02 13:18:47 +00:00
|
|
|
#ifdef HAVE_FMOD
|
2009-05-08 13:28:41 +00:00
|
|
|
FSOUND_SAMPLE *pSample;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBSDL_MIXER
|
|
|
|
Mix_Chunk * pSample;
|
|
|
|
#endif
|
2010-03-27 16:05:02 +00:00
|
|
|
C4SoundInstance *FirstInst;
|
|
|
|
C4SoundEffect *Next;
|
2009-05-08 13:28:41 +00:00
|
|
|
public:
|
2010-03-27 16:05:02 +00:00
|
|
|
void Clear();
|
|
|
|
bool Load(const char *szFileName, C4Group &hGroup, bool fStatic);
|
2009-08-15 18:50:32 +00:00
|
|
|
bool Load(BYTE *pData, size_t iDataLen, bool fStatic, bool fRaw=false); // load directly from memory
|
2010-03-27 16:05:02 +00:00
|
|
|
void Execute();
|
|
|
|
C4SoundInstance *New(bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = NULL, int32_t iCustomFalloffDistance = 0);
|
|
|
|
C4SoundInstance *GetInstance(C4Object *pObj);
|
|
|
|
void ClearPointers(C4Object *pObj);
|
|
|
|
int32_t GetStartedInstanceCount(int32_t iX, int32_t iY, int32_t iRad); // local
|
|
|
|
int32_t GetStartedInstanceCount(); // global
|
2009-05-08 13:28:41 +00:00
|
|
|
protected:
|
2010-03-27 16:05:02 +00:00
|
|
|
void AddInst(C4SoundInstance *pInst);
|
|
|
|
void RemoveInst(C4SoundInstance *pInst);
|
2009-05-08 13:28:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class C4SoundInstance
|
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
friend class C4SoundEffect;
|
2009-05-08 13:28:41 +00:00
|
|
|
protected:
|
2010-03-27 16:05:02 +00:00
|
|
|
C4SoundInstance();
|
2009-05-08 13:28:41 +00:00
|
|
|
public:
|
2010-03-27 16:05:02 +00:00
|
|
|
~C4SoundInstance();
|
2009-05-08 13:28:41 +00:00
|
|
|
protected:
|
2010-03-27 16:05:02 +00:00
|
|
|
C4SoundEffect *pEffect;
|
|
|
|
int32_t iVolume, iPan, iChannel;
|
|
|
|
unsigned long iStarted;
|
|
|
|
int32_t iNearInstanceMax;
|
|
|
|
bool fLooping;
|
|
|
|
C4Object *pObj;
|
2009-05-08 13:28:41 +00:00
|
|
|
int32_t iFalloffDistance;
|
2010-03-27 16:05:02 +00:00
|
|
|
C4SoundInstance *pNext;
|
2009-05-08 13:28:41 +00:00
|
|
|
public:
|
2010-03-27 16:05:02 +00:00
|
|
|
C4Object *getObj() const { return pObj; }
|
|
|
|
bool isStarted() const { return iChannel != -1; }
|
|
|
|
void Clear();
|
|
|
|
bool Create(C4SoundEffect *pEffect, bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = NULL, int32_t iNearInstanceMax = 0, int32_t iFalloffDistance = 0);
|
|
|
|
bool CheckStart();
|
|
|
|
bool Start();
|
|
|
|
bool Stop();
|
|
|
|
bool Playing();
|
|
|
|
void Execute();
|
|
|
|
void SetVolume(int32_t inVolume) { iVolume = inVolume; }
|
|
|
|
void SetPan(int32_t inPan) { iPan = inPan; }
|
|
|
|
void SetVolumeByPos(int32_t x, int32_t y);
|
|
|
|
void SetObj(C4Object *pnObj) { pObj = pnObj; }
|
|
|
|
void ClearPointers(C4Object *pObj);
|
|
|
|
bool Inside(int32_t iX, int32_t iY, int32_t iRad);
|
2009-05-08 13:28:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const int32_t SoundUnloadTime=60, SoundMaxUnloadSize=100000;
|
|
|
|
|
|
|
|
class C4SoundSystem
|
2010-03-28 17:58:21 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
C4SoundSystem();
|
|
|
|
~C4SoundSystem();
|
|
|
|
void Clear();
|
|
|
|
void Execute();
|
|
|
|
int32_t LoadEffects(C4Group &hGroup, bool fStatic = true);
|
|
|
|
C4SoundInstance *NewEffect(const char *szSound, bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = NULL, int32_t iCustomFalloffDistance = 0);
|
|
|
|
C4SoundInstance *FindInstance(const char *szSound, C4Object *pObj);
|
|
|
|
bool Init();
|
|
|
|
void ClearPointers(C4Object *pObj);
|
|
|
|
protected:
|
|
|
|
C4Group SoundFile;
|
|
|
|
C4SoundEffect *FirstSound;
|
|
|
|
void ClearEffects();
|
|
|
|
C4SoundEffect* GetEffect(const char *szSound);
|
|
|
|
C4SoundEffect* AddEffect(const char *szSound);
|
|
|
|
int32_t RemoveEffect(const char *szFilename);
|
|
|
|
int32_t EffectInBank(const char *szSound);
|
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-06-12 18:52:21 +00:00
|
|
|
class C4SoundInstance *StartSoundEffect(const char *szSndName, bool fLoop = false, int32_t iVolume = 100, C4Object *pObj=NULL, int32_t iCustomFalloffDistance=0);
|
|
|
|
class C4SoundInstance *StartSoundEffectAt(const char *szSndName, int32_t iX, int32_t iY, bool fLoop = false, int32_t iVolume = 100);
|
|
|
|
class C4SoundInstance *GetSoundInstance(const char *szSndName, C4Object *pObj);
|
|
|
|
void StopSoundEffect(const char *szSndName, C4Object *pObj);
|
|
|
|
void SoundLevel(const char *szSndName, C4Object *pObj, int32_t iLevel);
|
|
|
|
void SoundPan(const char *szSndName, C4Object *pObj, int32_t iPan);
|
|
|
|
|
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
#endif
|