Skip to content

Commit ab80503

Browse files
committed
Refactor xrSound
Code cleanup and formatting LPCSTR to pcstr BOOL to bool and others...
1 parent de46442 commit ab80503

30 files changed

+489
-519
lines changed

src/xrGame/CarSound.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void CCar::SCarSound::Init()
2727

2828
snd_engine.create(ini->r_string("car_sound", "snd_name"), st_Effect, sg_SourceType); //
2929
snd_engine_start.create(READ_IF_EXISTS(ini, r_string, "car_sound", "engine_start", "car\\test_car_start"),
30-
st_Effect, sg_SourceType);
30+
st_Effect, sg_SourceType);
3131
snd_engine_stop.create(
3232
READ_IF_EXISTS(ini, r_string, "car_sound", "engine_stop", "car\\test_car_stop"), st_Effect, sg_SourceType);
3333
float fengine_start_delay = READ_IF_EXISTS(ini, r_float, "car_sound", "engine_sound_start_dellay", 0.25f);

src/xrMisc/Sound.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ ref_sound_data::ref_sound_data() throw() :
1616
g_object(0)
1717
{}
1818

19-
ref_sound_data::ref_sound_data(LPCSTR fName, esound_type sound_type, int game_type)
19+
ref_sound_data::ref_sound_data(pcstr fName, esound_type sound_type, int game_type)
2020
{ ::Sound->_create_data(*this, fName, sound_type, game_type); }
2121

2222
ref_sound_data::~ref_sound_data()
2323
{ ::Sound->_destroy_data(*this); }
2424

25-
void ref_sound::create(LPCSTR name, esound_type sound_type, int game_type)
25+
void ref_sound::create(pcstr name, esound_type sound_type, int game_type)
2626
{
2727
VerSndUnlocked();
2828
::Sound->create(*this, name, sound_type, game_type);
2929
}
3030

31-
void ref_sound::attach_tail(LPCSTR name)
31+
void ref_sound::attach_tail(pcstr name)
3232
{
3333
VerSndUnlocked();
3434
::Sound->attach_tail(*this, name);
@@ -132,14 +132,14 @@ void ref_sound::stop()
132132
{
133133
VerSndUnlocked();
134134
if (_feedback())
135-
_feedback()->stop(FALSE);
135+
_feedback()->stop(false);
136136
}
137137

138138
void ref_sound::stop_deferred()
139139
{
140140
VerSndUnlocked();
141141
if (_feedback())
142-
_feedback()->stop(TRUE);
142+
_feedback()->stop(true);
143143
}
144144

145145
const CSound_params* ref_sound::get_params()

src/xrSound/OpenALDeviceList.cpp

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
#pragma warning(pop)
3232

3333
#ifdef _EDITOR
34-
log_fn_ptr_type* pLog = NULL;
34+
log_fn_ptr_type* pLog = nullptr;
3535
#endif
3636

3737
void __cdecl al_log(char* msg) { Log(msg); }
3838
ALDeviceList::ALDeviceList()
3939
{
4040
pLog = al_log;
41-
snd_device_id = u32(-1);
41+
snd_device_id = (u32)-1;
4242
Enumerate();
4343
}
4444

@@ -48,18 +48,17 @@ ALDeviceList::ALDeviceList()
4848
ALDeviceList::~ALDeviceList()
4949
{
5050
for (int i = 0; snd_devices_token[i].name; i++)
51-
{
5251
xr_free(snd_devices_token[i].name);
53-
}
52+
5453
xr_free(snd_devices_token);
55-
snd_devices_token = NULL;
54+
snd_devices_token = nullptr;
5655
}
5756

5857
void ALDeviceList::Enumerate()
5958
{
60-
char* devices;
59+
pstr devices;
6160
int major, minor, index;
62-
LPCSTR actualDeviceName;
61+
pcstr actualDeviceName;
6362

6463
Msg("SOUND: OpenAL: enumerate devices...");
6564
// have a set of vectors storing the device list, selection status, spec version #, and XRAM support status
@@ -68,13 +67,13 @@ void ALDeviceList::Enumerate()
6867

6968
CoUninitialize();
7069
// grab function pointers for 1.0-API functions, and if successful proceed to enumerate all devices
71-
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
70+
if (alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
7271
{
7372
Msg("SOUND: OpenAL: EnumerationExtension Present");
7473

75-
devices = (char*)alcGetString(NULL, ALC_DEVICE_SPECIFIER);
74+
devices = (pstr)alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
7675
Msg("devices %s", devices);
77-
xr_strcpy(m_defaultDeviceName, (char*)alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
76+
xr_strcpy(m_defaultDeviceName, (pstr)alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER));
7877
Msg("SOUND: OpenAL: system default SndDevice name is %s", m_defaultDeviceName);
7978

8079
// ManowaR
@@ -99,14 +98,14 @@ void ALDeviceList::Enumerate()
9998
ALCdevice* device = alcOpenDevice(devices);
10099
if (device)
101100
{
102-
ALCcontext* context = alcCreateContext(device, NULL);
101+
ALCcontext* context = alcCreateContext(device, nullptr);
103102
if (context)
104103
{
105104
alcMakeContextCurrent(context);
106105
// if new actual device name isn't already in the list, then add it...
107106
actualDeviceName = alcGetString(device, ALC_DEVICE_SPECIFIER);
108107

109-
if ((actualDeviceName != NULL) && xr_strlen(actualDeviceName) > 0)
108+
if (actualDeviceName != nullptr && xr_strlen(actualDeviceName) > 0)
110109
{
111110
alcGetIntegerv(device, ALC_MAJOR_VERSION, sizeof(int), &major);
112111
alcGetIntegerv(device, ALC_MINOR_VERSION, sizeof(int), &minor);
@@ -121,26 +120,22 @@ void ALDeviceList::Enumerate()
121120
if (alIsExtensionPresent("EAX5.0"))
122121
m_devices.back().props.eax = 5;
123122

124-
m_devices.back().props.efx = (alIsExtensionPresent("ALC_EXT_EFX") == TRUE);
125-
m_devices.back().props.xram = (alIsExtensionPresent("EAX_RAM") == TRUE);
123+
m_devices.back().props.efx = alIsExtensionPresent("ALC_EXT_EFX") == true;
124+
m_devices.back().props.xram = alIsExtensionPresent("EAX_RAM") == true;
126125

127126
m_devices.back().props.eax_unwanted =
128-
((0 == xr_strcmp(actualDeviceName, AL_GENERIC_HARDWARE)) ||
129-
(0 == xr_strcmp(actualDeviceName, AL_GENERIC_SOFTWARE)));
127+
0 == xr_strcmp(actualDeviceName, AL_GENERIC_HARDWARE) ||
128+
0 == xr_strcmp(actualDeviceName, AL_GENERIC_SOFTWARE);
130129
++index;
131130
}
132131
alcDestroyContext(context);
133132
}
134133
else
135-
{
136134
Msg("SOUND: OpenAL: cant create context for %s", device);
137-
}
138135
alcCloseDevice(device);
139136
}
140137
else
141-
{
142138
Msg("SOUND: OpenAL: cant open device %s", devices);
143-
}
144139

145140
devices += xr_strlen(devices) + 1;
146141
}
@@ -152,7 +147,7 @@ void ALDeviceList::Enumerate()
152147
u32 _cnt = GetNumDevices();
153148
snd_devices_token = xr_alloc<xr_token>(_cnt + 1);
154149
snd_devices_token[_cnt].id = -1;
155-
snd_devices_token[_cnt].name = NULL;
150+
snd_devices_token[_cnt].name = nullptr;
156151
for (u32 i = 0; i < _cnt; ++i)
157152
{
158153
snd_devices_token[i].id = i;
@@ -169,23 +164,23 @@ void ALDeviceList::Enumerate()
169164
{
170165
GetDeviceVersion(j, &majorVersion, &minorVersion);
171166
Msg("%d. %s, Spec Version %d.%d %s eax[%d] efx[%s] xram[%s]", j + 1, GetDeviceName(j), majorVersion,
172-
minorVersion, (_stricmp(GetDeviceName(j), m_defaultDeviceName) == 0) ? "(default)" : "",
167+
minorVersion, _stricmp(GetDeviceName(j), m_defaultDeviceName) == 0 ? "(default)" : "",
173168
GetDeviceDesc(j).props.eax, GetDeviceDesc(j).props.efx ? "yes" : "no",
174169
GetDeviceDesc(j).props.xram ? "yes" : "no");
175170
}
176171
if (!strstr(GetCommandLine(), "-editor"))
177-
CoInitializeEx(NULL, COINIT_MULTITHREADED);
172+
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
178173
}
179174

180-
LPCSTR ALDeviceList::GetDeviceName(u32 index) { return snd_devices_token[index].name; }
175+
pcstr ALDeviceList::GetDeviceName(u32 index) const { return snd_devices_token[index].name; }
181176
void ALDeviceList::SelectBestDevice()
182177
{
183178
int best_majorVersion = -1;
184179
int best_minorVersion = -1;
185180
int majorVersion;
186181
int minorVersion;
187182

188-
if (snd_device_id == u32(-1))
183+
if (snd_device_id == (u32)-1)
189184
{
190185
// select best
191186
u32 new_device_id = snd_device_id;
@@ -195,19 +190,19 @@ void ALDeviceList::SelectBestDevice()
195190
continue;
196191

197192
GetDeviceVersion(i, &majorVersion, &minorVersion);
198-
if ((majorVersion > best_majorVersion) ||
199-
(majorVersion == best_majorVersion && minorVersion > best_minorVersion))
193+
if (majorVersion > best_majorVersion ||
194+
majorVersion == best_majorVersion && minorVersion > best_minorVersion)
200195
{
201196
best_majorVersion = majorVersion;
202197
best_minorVersion = minorVersion;
203198
new_device_id = i;
204199
}
205200
}
206-
if (new_device_id == u32(-1))
201+
if (new_device_id == (u32)-1)
207202
{
208203
R_ASSERT(GetNumDevices() != 0);
209204
new_device_id = 0; // first
210-
};
205+
}
211206
snd_device_id = new_device_id;
212207
}
213208
if (GetNumDevices() == 0)
@@ -223,5 +218,4 @@ void ALDeviceList::GetDeviceVersion(u32 index, int* major, int* minor)
223218
{
224219
*major = m_devices[index].major_ver;
225220
*minor = m_devices[index].minor_ver;
226-
return;
227221
}

src/xrSound/OpenALDeviceList.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
#pragma once
12
#ifndef ALDEVICELIST_H
23
#define ALDEVICELIST_H
34

45
#include "openal/al.h"
56
#include "openal/alc.h"
67

7-
#define AL_GENERIC_HARDWARE "Generic Hardware"
8-
#define AL_GENERIC_SOFTWARE "Generic Software"
8+
constexpr pcstr AL_GENERIC_HARDWARE = "Generic Hardware";
9+
constexpr pcstr AL_GENERIC_SOFTWARE = "Generic Software";
910

1011
struct ALDeviceDesc
1112
{
@@ -27,7 +28,7 @@ struct ALDeviceDesc
2728
u16 storage;
2829
};
2930
ESndProps props;
30-
ALDeviceDesc(LPCSTR nm, int mn, int mj)
31+
ALDeviceDesc(pcstr nm, int mn, int mj)
3132
{
3233
xr_strcpy(name, nm);
3334
minor_ver = mn;
@@ -39,18 +40,17 @@ struct ALDeviceDesc
3940

4041
class ALDeviceList
4142
{
42-
private:
4343
xr_vector<ALDeviceDesc> m_devices;
4444
string256 m_defaultDeviceName;
4545
void Enumerate();
46-
46+
4747
public:
4848
ALDeviceList();
4949
~ALDeviceList();
5050

51-
u32 GetNumDevices() { return m_devices.size(); }
51+
u32 GetNumDevices() const { return m_devices.size(); }
5252
const ALDeviceDesc& GetDeviceDesc(u32 index) { return m_devices[index]; }
53-
LPCSTR GetDeviceName(u32 index);
53+
pcstr GetDeviceName(u32 index) const;
5454
void GetDeviceVersion(u32 index, int* major, int* minor);
5555
void SelectBestDevice();
5656
};

0 commit comments

Comments
 (0)