convert line ends
[canaan.git] / prj / cam / src / sound / psndinst.h
blob25e2ae4628c24f06c7280b60d46be015afc83bba
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/src/sound/psndinst.h,v 1.22 2000/01/29 13:41:46 adurant Exp $
8 //
9 // Sound propagation instance header
11 #pragma once
13 #ifndef __PSNDINST_H
14 #define __PSNDINST_H
16 #include <matrixs.h>
18 #include <dynarray.h>
19 #include <hashpp.h>
21 #include <appsfx.h>
22 #include <roomsys.h>
23 #include <roompa.h>
25 #include <psndinfo.h>
27 F_DECLARE_INTERFACE(IAIManager);
29 ////////////////////////////////////////
31 // Max active sounds.
32 const int kMaxActiveSounds = 32;
34 ////////////////////////////////////////////////////////////////////////////////
36 EXTERN void EndSampleCallback(int hSound, void *ptr);
37 EXTERN void LoopSampleCallback(int hSound, void *ptr);
39 ////////////////////////////////////////////////////////////////////////////////
41 typedef cHashTableFunctions<ObjID> ObjIDHashFunctions;
43 typedef cHashTable<ObjID, cSoundInfoList *, ObjIDHashFunctions> cSoundInfoTable;
44 typedef cHashTable<ObjID, mxs_real, ObjIDHashFunctions> cSoundPropTable;
46 typedef cDynArray<ObjID> cSoundObjectList;
48 typedef cDynArray<const cRoomPortal *> cPortalStack;
50 typedef struct
52 mxs_vector pos;
53 BOOL valid;
54 } sAnchorPt;
56 ////////////////////
57 enum PrioritizationResult
59 PRIORITY_RES_OK,
60 PRIORITY_RES_FAIL,
61 PRIORITY_RES_DEFERRED
64 enum eDeferredHaltType
66 kDH_Kill,
67 kDH_Silence,
70 typedef struct
72 int sfx_handle;
73 int type;
74 } sDeferredHalt;
77 ////////////////////////////////////////////////////////////////////////////////
79 class cPropSndInst : public cRoomPAFuncs
81 public:
83 /////////////////
85 // Constructor / Destructor
87 cPropSndInst();
88 ~cPropSndInst();
90 void Init(int handle, ObjID objID, const mxs_vector &loc, ObjID schemaID, const char *sampleName,
91 int flags, float atten_factor, sfx_parm *parms, void *data);
92 void Cleanup();
94 void ApplySoundInfo();
95 void ClearSoundInfo();
97 cPlayerSoundList *GeneratePlayerSoundList(int handle);
99 void AddDeferredHalt(int sfx_handle, int type);
100 void ApplyDeferredHaltList();
102 void AddActiveSound(cSoundInfo *pSoundInfo);
103 void EndActiveSound(cSoundInfo *pSoundInfo);
105 void BumpActiveSound(cPlayerSoundList *pPlayerList);
107 void SetupPlayerSoundListCallbacks (cPlayerSoundList* pCurPlayerList);
108 BOOL PlaySoundList (cPlayerSoundList* pCurPlayerList);
110 #ifndef SHIP
111 void SetDrawSoundPath(BOOL state) { m_DrawSoundPath = state; };
113 void DrawActiveSounds();
114 void SpewActiveSounds();
115 #endif
117 protected:
119 ////////////////////////////
121 mxs_real m_MaxDistance; // Maximum distance the sound can be heard
122 mxs_real m_ScaleDistance; // Forces max distance for sound
124 ObjID m_SrcObject; // ID of object making sound (-1 if not applicable)
125 mxs_vector m_SrcPoint; // Coordinates of sound source
127 const char *m_SampleName; // Name of sample being propagated
128 sfx_parm *m_pParms; // Parameters from schema system
130 ObjID m_SchemaID; // ObjID of the schema
132 void *m_Data; // Any data that wants to be propagated too
134 int m_Handle; // Sound propagation handle
136 int m_Flags; // Sound info flags
138 ////////////////////////////
140 cSoundInfoTable m_InfoTable; // Hash by objid to list sounds heard this frame
141 cSoundObjectList m_InfoList; // List of objects that have heard a sound this frame
143 cSoundInfo *m_ActiveSound[kMaxActiveSounds];
144 ObjID m_ActiveObject[kMaxActiveSounds];
145 int m_nActiveSoundObjects;
147 cDynArray<sDeferredHalt> m_deferredHaltList;
149 short m_roomNoBlock1;
150 short m_roomNoBlock2;
152 float m_attenFactor;
154 #ifndef SHIP
155 BOOL m_DrawSoundPath;
157 BOOL m_SoundSpew;
158 BOOL m_SoundFullSpew;
159 BOOL m_SoundGhostSpew;
160 BOOL m_SoundFullAISpew;
161 BOOL m_SoundPathSpew;
162 BOOL m_SoundHearSpew;
163 #endif
165 void FindSoundPath(const mxs_vector &src_pt, const mxs_vector &hear_pt, const cBFRoomInfo *room_table, int end_room,
166 mxs_real *dist, mxs_vector *position, mxs_real *realDist, mxs_real *blockingFactor);
167 void BackCastPath(sAnchorPt *anchor_list, cRoomPortal **portal_list, int i, const mxs_vector &L, const mxs_vector &src_pt);
169 private:
171 BOOL MergeSounds(cSoundInfoList *pSoundInfoList);
173 BOOL ActiveSound(cSoundInfo *pSoundInfo);
175 void ResolveActiveSounds(ObjID hearingObj);
176 void UpdateActiveSounds();
178 void ResolveDeferredSounds(ObjID hearingObj);
179 void UpdateDeferredSounds();
181 IAIManager * m_pAIManager;
184 ////////////////////////////////////////////////////////////////////////////////
186 class cPropSndInstHigh : public cPropSndInst
188 public:
190 /////////////////
192 // Callbacks
194 BOOL EnterCallback(const cRoom *room, const cRoomPortal *enterPortal, const mxs_vector &enterPt, mxs_real dist);
195 void ExitCallback(const cRoom *room);
196 mxs_real PortalsCallback(const cRoomPortal *enterPortal, const cRoomPortal *exitPortal, mxs_real dist);
199 ////////////////////////////////////////////////////////////////////////////////
201 #endif