SoundThing.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // SoundThing.H
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 02/24/97 MJR Stole infrastructure from Jon's AnimThing.
  23. //
  24. // 03/07/97 JMI Added m_psndChannel member and ProcessMessages() and
  25. // m_state (with enums).
  26. //
  27. // 03/13/97 JMI Load now takes a version number.
  28. //
  29. // 07/17/97 JMI Changed RSnd*'s to SampleMaster::SoundInstances.
  30. // Now uses new SampleMaster interface for volume and play
  31. // instance reference.
  32. //
  33. // 07/18/97 JMI Got rid of bogus immitation PlaySample functions.
  34. // Now there is one PlaySample() function. Also, you now
  35. // MUST specify a category and you don't have to specify a
  36. // SoundInstance ptr to specify a volume.
  37. // Also, added user edittable member m_lVolumeHalfLife.
  38. //
  39. // 07/21/97 JMI Added GetX(), GetY(), and GetZ().
  40. //
  41. // 08/01/97 JMI Added looping parameters.
  42. //
  43. // 08/04/97 JMI Now defaults to enabled.
  44. //
  45. // 08/04/97 JMI Added m_sAmbient indicating whether or not this sound
  46. // is ambient (i.e., non-essential).
  47. // Also, implemented a special random number generator
  48. // strictly for sound things so they can be merry and random
  49. // and not de-synchronize.
  50. //
  51. // 08/11/97 JMI Added RelayVolume() and m_lCollectiveVolume so
  52. // CSoundRelays can update their CSoundThing parents.
  53. //
  54. // 09/24/97 JMI Now initializes bFemalePain member of m_id. This member
  55. // indicates whether the sample is of a female in pain which
  56. // some countries (so far just UK) don't want in the game.
  57. //
  58. // 10/07/97 JMI Changed bFemalePain to usDescFlags.
  59. //
  60. //////////////////////////////////////////////////////////////////////////////
  61. //
  62. // This CThing-derived class will play sounds with various options.
  63. //
  64. //////////////////////////////////////////////////////////////////////////////
  65. #ifndef SOUNDTHING_H
  66. #define SOUNDTHING_H
  67. #include "RSPiX.h"
  68. #include "realm.h"
  69. #include "SampleMaster.h"
  70. // This class has its own GetRandom() to keep it from de-synching the game.
  71. #ifdef GetRandom
  72. #undef GetRandom
  73. #endif
  74. #ifdef GetRand
  75. #undef GetRand
  76. #endif
  77. class CSoundThing : public CThing
  78. {
  79. //---------------------------------------------------------------------------
  80. // Types, enums, etc.
  81. //---------------------------------------------------------------------------
  82. public:
  83. typedef enum
  84. {
  85. State_Happy, // La, la, la.
  86. State_Delete // Delete self next chance.
  87. } State;
  88. //---------------------------------------------------------------------------
  89. // Variables
  90. //---------------------------------------------------------------------------
  91. public:
  92. bool m_bInitiallyEnabled;
  93. bool m_bInitiallyRepeats;
  94. long m_lMinTime[2];
  95. long m_lRndTime[2];
  96. char m_szResName[RSP_MAX_PATH]; // Resource name
  97. SampleMasterID m_id;
  98. RImage* m_pImage; // Pointer to only image (for editor only)
  99. CSprite2 m_sprite; // Sprite (for editor only)
  100. double m_dX; // x coord (for editor only)
  101. double m_dY; // y coord (for editor only)
  102. double m_dZ; // z coord (for editor only)
  103. SampleMaster::SoundInstance m_siChannel;
  104. long m_lLastStartTime;
  105. long m_lNextStartTime;
  106. short m_sWhichTime;
  107. bool m_bEnabled;
  108. bool m_bRepeats;
  109. short m_sUseLooping; // TRUE, to use looping parameters.
  110. long m_lStopLoopingTime; // Time that we stop looping the sample.
  111. long m_lNumLoopBacks; // Number of times to play loop area of sample.
  112. long m_lLoopBackTo; // Where to loop back to.
  113. long m_lLoopBackFrom; // Where to loop back from.
  114. short m_sSuspend; // Suspend flag
  115. State m_state; // Current state.
  116. long m_lVolumeHalfLife; // Half life of the current sound.
  117. short m_sPurgeSampleWhenDone; // TRUE, to purge sample when done.
  118. short m_sAmbient; // TRUE, if ambient (i.e., non-essential) sound.
  119. long m_lCollectiveVolume; // Collective volume from this object and
  120. // its child satellites.
  121. protected:
  122. static short ms_sFileCount; // File count.
  123. static long ms_lGetRandomSeed; // Seed for get random.
  124. //---------------------------------------------------------------------------
  125. // Constructor(s) / destructor
  126. //---------------------------------------------------------------------------
  127. public:
  128. // Constructor
  129. CSoundThing(CRealm* pRealm)
  130. : CThing(pRealm, CSoundThingID)
  131. {
  132. m_bInitiallyEnabled = true;
  133. m_bInitiallyRepeats = false;
  134. m_lMinTime[0] = 0;
  135. m_lMinTime[1] = 0;
  136. m_lRndTime[0] = 0;
  137. m_lRndTime[1] = 0;
  138. m_szResName[0] = 0;
  139. m_id.pszId = m_szResName;
  140. m_id.usDescFlags = SMDF_NO_DESCRIPT;
  141. m_pImage = 0;
  142. m_lLastStartTime = 0;
  143. m_lNextStartTime = 0;
  144. m_sWhichTime = -1;
  145. m_bEnabled = m_bInitiallyEnabled;
  146. m_bRepeats = m_bInitiallyRepeats;
  147. m_sSuspend = 0;
  148. m_siChannel = 0;
  149. m_state = State_Happy;
  150. m_lVolumeHalfLife = 1000;
  151. m_sUseLooping = FALSE;
  152. m_lStopLoopingTime = 0;
  153. m_lNumLoopBacks = 0;
  154. m_lLoopBackTo = 0;
  155. m_lLoopBackFrom = 0;
  156. m_sPurgeSampleWhenDone = FALSE;
  157. m_sAmbient = TRUE;
  158. m_lCollectiveVolume = 0;
  159. }
  160. public:
  161. // Destructor
  162. ~CSoundThing()
  163. {
  164. Kill();
  165. }
  166. //---------------------------------------------------------------------------
  167. // Required static functions
  168. //---------------------------------------------------------------------------
  169. public:
  170. // Construct object
  171. static short Construct( // Returns 0 if successfull, non-zero otherwise
  172. CRealm* pRealm, // In: Pointer to realm this object belongs to
  173. CThing** ppNew) // Out: Pointer to new object
  174. {
  175. short sResult = 0;
  176. *ppNew = new CSoundThing(pRealm);
  177. if (*ppNew == 0)
  178. {
  179. sResult = -1;
  180. TRACE("CExplode::Construct(): Couldn't construct CSoundThing (that's a bad thing)\n");
  181. }
  182. return sResult;
  183. }
  184. //---------------------------------------------------------------------------
  185. // Required virtual functions (implimenting them as inlines doesn't pay!)
  186. //---------------------------------------------------------------------------
  187. public:
  188. // Load object (should call base class version!)
  189. short Load( // Returns 0 if successfull, non-zero otherwise
  190. RFile* pFile, // In: File to load from
  191. bool bEditMode, // In: True for edit mode, false otherwise
  192. short sFileCount, // In: File count (unique per file, never 0)
  193. ULONG ulFileVersion); // In: Version of file format to load.
  194. // Save object (should call base class version!)
  195. short Save( // Returns 0 if successfull, non-zero otherwise
  196. RFile* pFile, // In: File to save to
  197. short sFileCount); // In: File count (unique per file, never 0)
  198. // Startup object
  199. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  200. // Shutdown object
  201. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  202. // Suspend object
  203. void Suspend(void);
  204. // Resume object
  205. void Resume(void);
  206. // Update object
  207. void Update(void);
  208. // Render object
  209. void Render(void);
  210. short Setup( // Returns 0 on success.
  211. short sX, // In: New x coord
  212. short sY, // In: New y coord
  213. short sZ); // In: New z coord
  214. // Called by editor to init new object at specified position
  215. short EditNew( // Returns 0 if successfull, non-zero otherwise
  216. short sX, // In: New x coord
  217. short sY, // In: New y coord
  218. short sZ); // In: New z coord
  219. // Called by editor to modify object
  220. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  221. // Called by editor to move object to specified position
  222. short EditMove( // Returns 0 if successfull, non-zero otherwise
  223. short sX, // In: New x coord
  224. short sY, // In: New y coord
  225. short sZ); // In: New z coord
  226. // Called by editor to get the clickable pos/area of an object in 2D.
  227. virtual // Overridden here.
  228. void EditRect( // Returns nothiing.
  229. RRect* prc); // Out: Clickable pos/area of object.
  230. // Called by editor to get the hotspot of an object in 2D.
  231. virtual // Overridden here.
  232. void EditHotSpot( // Returns nothiing.
  233. short* psX, // Out: X coord of 2D hotspot relative to
  234. // EditRect() pos.
  235. short* psY); // Out: Y coord of 2D hotspot relative to
  236. // EditRect() pos.
  237. // Called by editor to update object
  238. void EditUpdate(void);
  239. // Called by editor to render object
  240. void EditRender(void);
  241. // Get the coordinates of this thing.
  242. virtual // Overriden here.
  243. double GetX(void) { return m_dX; }
  244. virtual // Overriden here.
  245. double GetY(void) { return m_dY; }
  246. virtual // Overriden here.
  247. double GetZ(void) { return m_dZ; }
  248. //---------------------------------------------------------------------------
  249. // External functions
  250. //---------------------------------------------------------------------------
  251. public:
  252. // Relay the volume to add to this CSoundThing's collective volume.
  253. void RelayVolume( // Returns nothing.
  254. long lVolume); // In: Volume to relay.
  255. //---------------------------------------------------------------------------
  256. // Internal functions
  257. //---------------------------------------------------------------------------
  258. protected:
  259. // Init object
  260. short Init(void); // Returns 0 if successfull, non-zero otherwise
  261. // Kill object
  262. short Kill(void); // Returns 0 if successfull, non-zero otherwise
  263. // Process our message queue.
  264. void ProcessMessages(void);
  265. // Don't call this from outside of CSoundThing. It should affect only
  266. // CSoundThing stuff.
  267. static long GetRandom(void);
  268. static long GetRand(void)
  269. {
  270. return GetRandom();
  271. }
  272. };
  273. #endif // SOUNDTHING_H
  274. ////////////////////////////////////////////////////////////////////////////////
  275. // EOF
  276. ////////////////////////////////////////////////////////////////////////////////