Skip to content

Commit 254945c

Browse files
author
nitrocaster
committed
Merge sound engine initialization stages.
1 parent 9a02223 commit 254945c

File tree

9 files changed

+40
-91
lines changed

9 files changed

+40
-91
lines changed

src/xrEngine/main.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,9 @@ void destroyInput()
118118
xr_delete(pInput);
119119
}
120120

121-
void InitSound1()
121+
void InitSound()
122122
{
123-
CSound_manager_interface::_create(0);
124-
}
125-
126-
void InitSound2()
127-
{
128-
CSound_manager_interface::_create(1);
123+
CSound_manager_interface::_create();
129124
}
130125

131126
void destroySound()
@@ -184,9 +179,8 @@ void CheckPrivilegySlowdown()
184179

185180
void Startup()
186181
{
187-
InitSound1();
188182
execUserScript();
189-
InitSound2();
183+
InitSound();
190184
// ...command line for auto start
191185
const char *startArgs = strstr(Core.Params, "-start ");
192186
if (startArgs)

src/xrEngine/xrSASH.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ void xrSASH::EndBenchmark()
255255
void InitInput();
256256
void destroyInput();
257257
void InitEngine();
258-
void InitSound1();
259-
void InitSound2();
258+
void InitSound();
260259
void destroySound();
261260
void destroyEngine();
262261

@@ -488,10 +487,7 @@ void xrSASH::TryInitEngine(bool bNoRun)
488487
InitInput();
489488

490489
Engine.External.Initialize();
491-
492-
if (bNoRun)
493-
InitSound1();
494-
490+
495491
Console->Execute("unbindall");
496492
Console->ExecuteScript(Console->ConfigFile);
497493
if (m_bOpenAutomate)
@@ -503,7 +499,7 @@ void xrSASH::TryInitEngine(bool bNoRun)
503499

504500
if (bNoRun)
505501
{
506-
InitSound2();
502+
InitSound();
507503
Device.Create();
508504
}
509505

src/xrEngine/xr_ioc_cmd.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ class CCC_SND_Restart : public IConsole_Command
469469
CCC_SND_Restart(LPCSTR N) : IConsole_Command(N) { bEmptyArgsHandled = TRUE; };
470470
virtual void Execute(LPCSTR args)
471471
{
472-
Sound->_restart();
472+
if (Sound)
473+
Sound->_restart();
473474
}
474475
};
475476

src/xrSound/Sound.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class MODEL;
244244
/// definition (Sound Manager Interface)
245245
class XRSOUND_API CSound_manager_interface
246246
{
247-
virtual void _initialize (int stage) = 0;
247+
virtual void _initialize () = 0;
248248
virtual void _clear ( ) = 0;
249249

250250
protected:
@@ -254,7 +254,7 @@ class XRSOUND_API CSound_manager_interface
254254
public:
255255
virtual ~CSound_manager_interface(){}
256256

257-
static void _create (int stage);
257+
static void _create ();
258258
static void _destroy ( );
259259

260260
virtual void _restart ( ) = 0;

src/xrSound/SoundRender_Core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ CSoundRender_Core::~CSoundRender_Core()
5959
#endif
6060
}
6161

62-
void CSoundRender_Core::_initialize(int stage)
62+
void CSoundRender_Core::_initialize()
6363
{
6464
Log ("* sound: EAX 2.0 extension:",bEAX?"present":"absent");
6565
Log ("* sound: EAX 2.0 deferred:",bDeferredEAX?"present":"absent");

src/xrSound/SoundRender_Core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class CSoundRender_Core : public CSound_manager_interface
7878
virtual ~CSoundRender_Core ();
7979

8080
// General
81-
virtual void _initialize (int stage)=0;
81+
virtual void _initialize () = 0;
8282
virtual void _clear ( )=0;
8383
virtual void _restart ( );
8484

src/xrSound/SoundRender_CoreA.cpp

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -47,46 +47,17 @@ BOOL CSoundRender_CoreA::EAXTestSupport (BOOL bDeferred)
4747
void CSoundRender_CoreA::_restart()
4848
{
4949
inherited::_restart();
50-
/*
51-
CSoundRender_Target* T = 0;
52-
for (u32 tit=0; tit<s_targets.size(); tit++)
53-
{
54-
T = s_targets[tit];
55-
T->_destroy ();
56-
}
57-
58-
// Reset the current context to NULL.
59-
alcMakeContextCurrent (NULL);
60-
// Release the context and the device.
61-
alcDestroyContext (pContext);
62-
pContext = NULL;
63-
alcCloseDevice (pDevice);
64-
pDevice = NULL;
65-
66-
_initialize (2);
67-
68-
for (u32 tit=0; tit<s_targets.size(); tit++)
69-
{
70-
T = s_targets[tit];
71-
T->_initialize ();
72-
}
73-
*/
7450
}
7551

76-
void CSoundRender_CoreA::_initialize(int stage)
52+
void CSoundRender_CoreA::_initialize()
7753
{
78-
if(stage==0)
79-
{
80-
pDeviceList = xr_new<ALDeviceList>();
54+
pDeviceList = xr_new<ALDeviceList>();
8155

82-
if (0==pDeviceList->GetNumDevices())
83-
{
84-
CHECK_OR_EXIT (0,"OpenAL: Can't create sound device.");
85-
xr_delete (pDeviceList);
86-
}
87-
return;
56+
if (0==pDeviceList->GetNumDevices())
57+
{
58+
CHECK_OR_EXIT (0,"OpenAL: Can't create sound device.");
59+
xr_delete (pDeviceList);
8860
}
89-
9061
pDeviceList->SelectBestDevice ();
9162
R_ASSERT (snd_device_id>=0 && snd_device_id<pDeviceList->GetNumDevices());
9263
const ALDeviceDesc& deviceDesc = pDeviceList->GetDeviceDesc(snd_device_id);
@@ -140,25 +111,22 @@ void CSoundRender_CoreA::_initialize(int stage)
140111
bEAX = EAXTestSupport(FALSE);
141112
}
142113

143-
inherited::_initialize (stage);
114+
inherited::_initialize ();
144115

145-
if(stage==1)//first initialize
116+
// Pre-create targets
117+
CSoundRender_Target* T = 0;
118+
for (u32 tit=0; tit<u32(psSoundTargets); tit++)
146119
{
147-
// Pre-create targets
148-
CSoundRender_Target* T = 0;
149-
for (u32 tit=0; tit<u32(psSoundTargets); tit++)
120+
T = xr_new<CSoundRender_TargetA>();
121+
if (T->_initialize())
122+
{
123+
s_targets.push_back (T);
124+
}else
150125
{
151-
T = xr_new<CSoundRender_TargetA>();
152-
if (T->_initialize())
153-
{
154-
s_targets.push_back (T);
155-
}else
156-
{
157-
Log ("! SOUND: OpenAL: Max targets - ",tit);
158-
T->_destroy ();
159-
xr_delete (T);
160-
break;
161-
}
126+
Log ("! SOUND: OpenAL: Max targets - ",tit);
127+
T->_destroy ();
128+
xr_delete (T);
129+
break;
162130
}
163131
}
164132
}

src/xrSound/SoundRender_CoreA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CSoundRender_CoreA: public CSoundRender_Core
4040
CSoundRender_CoreA ();
4141
virtual ~CSoundRender_CoreA ();
4242

43-
virtual void _initialize (int stage);
43+
virtual void _initialize ();
4444
virtual void _clear ( );
4545
virtual void _restart ( );
4646

src/xrSound/sound.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,15 @@
55

66
XRSOUND_API xr_token* snd_devices_token = NULL;
77
XRSOUND_API u32 snd_device_id = u32(-1);
8-
void CSound_manager_interface::_create(int stage)
8+
void CSound_manager_interface::_create()
99
{
10-
if(stage==0)
11-
{
12-
SoundRenderA = xr_new<CSoundRender_CoreA>();
13-
SoundRender = SoundRenderA;
14-
Sound = SoundRender;
15-
16-
if (strstr ( Core.Params,"-nosound"))
17-
{
18-
SoundRender->bPresent = FALSE;
19-
return;
20-
}else
21-
SoundRender->bPresent = TRUE;
22-
23-
}
24-
25-
if(!SoundRender->bPresent) return;
26-
Sound->_initialize (stage);
10+
SoundRenderA = xr_new<CSoundRender_CoreA>();
11+
SoundRender = SoundRenderA;
12+
Sound = SoundRender;
13+
SoundRender->bPresent = strstr(Core.Params, "-nosound")==nullptr;
14+
if (!SoundRender->bPresent)
15+
return;
16+
Sound->_initialize();
2717
}
2818

2919
void CSound_manager_interface::_destroy ()

0 commit comments

Comments
 (0)