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