@@ -22,8 +22,8 @@ constexpr pcstr SNDENV_FILENAME = "sEnvironment.xr";
2222
2323// refs
2424class IGameObject ;
25- class ref_sound ;
26- class ref_sound_data ;
25+ class CSound ;
26+ struct resptrcode_sound ;
2727class XRSOUND_API CSound_params;
2828class XRSOUND_API CSound_source;
2929class XRSOUND_API CSound_emitter;
@@ -190,10 +190,10 @@ class XRSOUND_API CSound_stats
190190 u32 _events;
191191};
192192
193- typedef resptr_core<ref_sound_data, resptr_base<ref_sound_data>> ref_sound_data_ptr ;
193+ using ref_sound = resptr_core<CSound, resptrcode_sound> ;
194194
195195// / definition (Sound Callback)
196- typedef void sound_event (const ref_sound_data_ptr & S, float range);
196+ typedef void sound_event (const ref_sound & S, float range);
197197
198198namespace CDB
199199{
@@ -204,31 +204,30 @@ namespace CDB
204204class XRSOUND_API XR_NOVTABLE ISoundManager
205205{
206206protected:
207- friend class ref_sound_data ;
208- virtual bool _create_data (ref_sound_data& S, pcstr fName , esound_type sound_type, int game_type, bool replaceWithNoSound = true ) = 0;
209- virtual void _destroy_data (ref_sound_data& S) = 0;
207+ friend class CSound ;
208+ friend struct resptrcode_sound ;
209+
210+ virtual CSound* create (pcstr fName , esound_type sound_type, int game_type, bool replaceWithNoSound = true ) = 0;
211+ virtual void destroy (CSound& S) = 0;
212+
213+ virtual void attach_tail (CSound& S, pcstr fName ) = 0;
214+
215+ virtual void play (ref_sound& S, IGameObject* O, u32 flags = 0 , float delay = 0 .f) = 0;
216+ virtual void play_at_pos (ref_sound& S, IGameObject* O, const Fvector& pos, u32 flags = 0 , float delay = 0 .f) = 0;
217+ virtual void play_no_feedback (ref_sound& S, IGameObject* O, u32 flags = 0 , float delay = 0 .f, Fvector* pos = nullptr ,
218+ float * vol = nullptr , float * freq = nullptr , Fvector2* range = nullptr ) = 0;
210219
211220public:
212221 virtual ~ISoundManager () = default ;
213222
214223 virtual void _restart () = 0;
215224 virtual bool i_locked () = 0;
216225
217- virtual bool create (ref_sound& S, pcstr fName , esound_type sound_type, int game_type, bool replaceWithNoSound = true ) = 0;
218- virtual void attach_tail (ref_sound& S, pcstr fName ) = 0;
219- virtual void clone (ref_sound& S, const ref_sound& from, esound_type sound_type, int game_type) = 0;
220- virtual void destroy (ref_sound& S) = 0;
221-
222226 virtual void prefetch () = 0;
223227
224228 virtual void stop_emitters () = 0;
225229 virtual int pause_emitters (bool val) = 0;
226230
227- virtual void play (ref_sound& S, IGameObject* O, u32 flags = 0 , float delay = 0 .f) = 0;
228- virtual void play_at_pos (ref_sound& S, IGameObject* O, const Fvector& pos, u32 flags = 0 , float delay = 0 .f) = 0;
229- virtual void play_no_feedback (ref_sound& S, IGameObject* O, u32 flags = 0 , float delay = 0 .f, Fvector* pos = nullptr ,
230- float * vol = nullptr , float * freq = nullptr , Fvector2* range = nullptr ) = 0;
231-
232231 virtual void set_master_volume (float f = 1 .f) = 0;
233232 virtual void set_geometry_env (IReader* I) = 0;
234233 virtual void set_geometry_som (IReader* I) = 0;
@@ -284,100 +283,129 @@ class CSound_UserData : public xr_resource
284283
285284using CSound_UserDataPtr = resptr_core<CSound_UserData, resptr_base<CSound_UserData>>;
286285
287- class ref_sound_data : public xr_resource
286+ class CSound : public xr_resource
288287{
289288public:
290289 // shared_str nm;
291- CSound_source* handle; // !< Pointer to wave-source interface
292- CSound_emitter* feedback; // !< Pointer to emitter, automatically clears on emitter-stop
293- esound_type s_type;
294- int g_type; // !< Sound type, usually for AI
295- IGameObject* g_object; // !< Game object that emits ref_sound
296- CSound_UserDataPtr g_userdata;
297- shared_str fn_attached[2 ];
290+ CSound_source* handle{}; // !< Pointer to wave-source interface
291+ CSound_emitter* feedback{}; // !< Pointer to emitter, automatically clears on emitter-stop
298292
299- u32 dwBytesTotal ;
300- float fTimeTotal ;
293+ esound_type s_type{ st_Effect } ;
294+ int g_type{}; // !< Sound type, usually for AI
301295
302- ref_sound_data () noexcept
303- : handle(0 ), feedback(0 ), s_type(st_Effect), g_type(0 ), g_object(0 ), dwBytesTotal(0 ), fTimeTotal (0 )
304- {
305- }
296+ IGameObject* g_object{}; // !< Game object that emits ref_sound
297+ CSound_UserDataPtr g_userdata{};
298+ shared_str fn_attached[2 ];
306299
307- ref_sound_data (pcstr fName , esound_type sound_type, int game_type, bool replaceWithNoSound = true )
308- {
309- GEnv.Sound ->_create_data (*this , fName , sound_type, game_type, replaceWithNoSound);
310- }
300+ u32 dwBytesTotal{};
301+ float fTimeTotal {};
311302
312- virtual ~ref_sound_data () { GEnv.Sound ->_destroy_data (*this ); }
303+ ~CSound () override { GEnv.Sound ->destroy (*this ); }
313304 float get_length_sec () const { return fTimeTotal ; }
314305};
315306
316- inline void VerSndUnlocked () { VERIFY (!GEnv.Sound ->i_locked ()); }
317307/* ! \class ref_sound
318308\brief Sound source + control
319309
320310The main class representing source/emitter interface
321311This class in fact just hides internals and redirect calls to
322312specific sub-systems
323313*/
324- class ref_sound
314+ struct resptrcode_sound : public resptr_base <CSound>
325315{
326- public:
327- ref_sound_data_ptr _p;
316+ [[nodiscard]]
317+ ICF CSound_source* _handle () const { return p_ ? p_->handle : nullptr ; }
318+
319+ [[nodiscard]]
320+ ICF CSound_emitter* _feedback () const { return p_ ? p_->feedback : nullptr ; }
321+
322+ [[nodiscard]]
323+ ICF IGameObject* _g_object () const { VERIFY (p_); return p_ ? p_->g_object : nullptr ; }
328324
329- ref_sound () = default ;
330- ~ref_sound () = default ;
325+ [[nodiscard]]
326+ ICF int _g_type () const { VERIFY (p_); return p_ ? p_->g_type : 0 ; }
327+
328+ [[nodiscard]]
329+ ICF esound_type _sound_type () const { VERIFY (p_); return p_ ? p_->s_type : st_Effect; }
330+
331+ [[nodiscard]]
332+ ICF CSound_UserDataPtr _g_userdata () const { VERIFY (p_); return p_ ? p_->g_userdata : nullptr ; }
331333
332- CSound_source* _handle () const { return _p ? _p->handle : nullptr ; }
333- CSound_emitter* _feedback () const { return _p ? _p->feedback : nullptr ; }
334- IGameObject* _g_object () { VERIFY (_p); return _p->g_object ; }
335- int _g_type () { VERIFY (_p); return _p->g_type ; }
336- esound_type _sound_type () { VERIFY (_p); return _p->s_type ; }
337- CSound_UserDataPtr _g_userdata () { VERIFY (_p); return _p->g_userdata ; }
338334
339335 bool create (pcstr name, esound_type sound_type, int game_type, bool replaceWithNoSound = true )
340- { VerSndUnlocked (); return GEnv.Sound ->create (*this , name, sound_type, game_type, replaceWithNoSound); }
336+ {
337+ VerSndUnlocked ();
338+ _set (GEnv.Sound ->create (name, sound_type, game_type, replaceWithNoSound));
339+ return _get ();
340+ }
341341
342- void attach_tail (pcstr name)
343- { VerSndUnlocked (); GEnv.Sound ->attach_tail (*this , name); }
342+ ICF void destroy ()
343+ {
344+ VerSndUnlocked ();
345+ _set (nullptr );
346+ }
344347
345- void clone (const ref_sound& from, esound_type sound_type, int game_type)
346- { VerSndUnlocked (); GEnv.Sound ->clone (*this , from, sound_type, game_type); }
348+ void attach_tail (pcstr name) const
349+ {
350+ VerSndUnlocked ();
351+ if (!p_)
352+ return ;
353+ GEnv.Sound ->attach_tail (*p_, name);
354+ }
347355
348- void destroy ()
349- { VerSndUnlocked (); GEnv.Sound ->destroy (*this ); }
356+ void clone (const ref_sound& from, esound_type sound_type, int game_type)
357+ {
358+ if (!from._get ())
359+ return ;
360+ _set (xr_new<CSound>());
361+ p_->handle = from->handle ;
362+ p_->dwBytesTotal = from->dwBytesTotal ;
363+ p_->fTimeTotal = from->fTimeTotal ;
364+ p_->fn_attached [0 ] = from->fn_attached [0 ];
365+ p_->fn_attached [1 ] = from->fn_attached [1 ];
366+ p_->g_type = (game_type == sg_SourceType) ? p_->handle ->game_type () : game_type;
367+ p_->s_type = sound_type;
368+ }
350369
351370 void play (IGameObject* O, u32 flags = 0 , float delay = 0 .f)
352- { VerSndUnlocked (); GEnv.Sound ->play (*this , O, flags, delay); }
371+ {
372+ VerSndUnlocked ();
373+ GEnv.Sound ->play (static_cast <ref_sound&>(*this ), O, flags, delay);
374+ }
353375
354376 void play_at_pos (IGameObject* O, const Fvector& pos, u32 flags = 0 , float delay = 0 .f)
355- { VerSndUnlocked (); GEnv.Sound ->play_at_pos (*this , O, pos, flags, delay); }
377+ {
378+ VerSndUnlocked ();
379+ GEnv.Sound ->play_at_pos (static_cast <ref_sound&>(*this ), O, pos, flags, delay);
380+ }
356381
357382 void play_no_feedback (IGameObject* O, u32 flags = 0 , float delay = 0 .f, Fvector* pos = nullptr , float * vol = nullptr , float * freq = nullptr , Fvector2* range = nullptr )
358- { VerSndUnlocked (); GEnv.Sound ->play_no_feedback (*this , O, flags, delay, pos, vol, freq, range); }
383+ {
384+ VerSndUnlocked ();
385+ GEnv.Sound ->play_no_feedback (static_cast <ref_sound&>(*this ), O, flags, delay, pos, vol, freq, range);
386+ }
359387
360- void stop () { VerSndUnlocked (); if (_feedback ()) _feedback ()->stop (false ); }
361- void stop_deferred () { VerSndUnlocked (); if (_feedback ()) _feedback ()->stop (true ); }
388+ ICF void stop () const { VerSndUnlocked (); if (_feedback ()) _feedback ()->stop (false ); }
389+ ICF void stop_deferred () const { VerSndUnlocked (); if (_feedback ()) _feedback ()->stop (true ); }
362390
363- void set_position (const Fvector& pos) { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_position (pos); }
364- void set_frequency (float freq) { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_frequency (freq); }
365- void set_range (float min, float max) { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_range (min, max); }
366- void set_volume (float vol) { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_volume (vol); }
367- void set_priority (float p) { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_priority (p); }
368- void set_time (float t) { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_time (t); }; // --#SM+#--
391+ ICF void set_position (const Fvector& pos) const { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_position (pos); }
392+ ICF void set_frequency (float freq) const { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_frequency (freq); }
393+ ICF void set_range (float min, float max) const { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_range (min, max); }
394+ ICF void set_volume (float vol) const { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_volume (vol); }
395+ ICF void set_priority (float p) const { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_priority (p); }
396+ ICF void set_time (float t) const { VerSndUnlocked (); if (_feedback ()) _feedback ()->set_time (t); }; // --#SM+#--
369397
370- const CSound_params* get_params ()
398+ [[nodiscard]]
399+ ICF const CSound_params* get_params () const
371400 {
372401 VerSndUnlocked ();
373- return _feedback () ? _feedback ()->get_params () : 0 ;
402+ return _feedback () ? _feedback ()->get_params () : nullptr ;
374403 }
375404
376- void set_params (CSound_params* p)
405+ void set_params (CSound_params* p) const
377406 {
378407 VerSndUnlocked ();
379- CSound_emitter* const feedback = _feedback ();
380- if (feedback)
408+ if (CSound_emitter* const feedback = _feedback ())
381409 {
382410 feedback->set_position (p->position );
383411 feedback->set_frequency (p->freq );
@@ -386,7 +414,13 @@ class ref_sound
386414 }
387415 }
388416
389- float get_length_sec () const { return _p ? _p->get_length_sec () : 0 .0f ; }
417+ [[nodiscard]]
418+ ICF float get_length_sec () const { return p_ ? p_->get_length_sec () : 0 .0f ; }
419+
420+ IC static void VerSndUnlocked ()
421+ {
422+ VERIFY (!GEnv.Sound ->i_locked ());
423+ }
390424};
391425
392426class XRSOUND_API CSound_stats_ext
0 commit comments