grsound.cpp: Use GfFileExists instead of fopen(3)

Opening a file only to check whether it exists is resource-consuming for
no reason, since GfFileExists can achieve the same effect without
requiring to open a file.
This commit is contained in:
Xavier Del Campo Romero 2025-01-19 08:41:06 +01:00
parent 5ecafc545a
commit 83bc8500ee
Signed by: xavi
GPG key ID: 84FF3612A9BF43F2

View file

@ -93,7 +93,6 @@ void grInitSound(tSituation* s, int ncars)
tCarElt *car = s->cars[i];
const char* param;
char filename[512];
FILE *file = NULL;
// ENGINE PARAMS
tdble rpm_scale;
@ -103,17 +102,12 @@ void grInitSound(tSituation* s, int ncars)
car->_carName,
(int)(sizeof(filename) - strlen(car->_carName) - strlen("cars/models//")),
param);
file = fopen(filename, "r");
if (!file)
if (!GfFileExists(filename))
{
sprintf(filename, "data/sound/%.*s",
(int)(sizeof(filename) - strlen(car->_carName) - strlen("data/sound/")),
param);
}
else
{
fclose(file);
}
car_sound_data[car->index] = new CarSoundData (car->index, sound_interface);
Sound* engine_sound = sound_interface->addSample(filename, ACTIVE_VOLUME | ACTIVE_PITCH | ACTIVE_LP_FILTER, true, false);