MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ReadAmbientData

Function ReadAmbientData

Descent3/ambient.cpp:210–284  ·  view source on GitHub ↗

Reads data from the ambient sound data file

Source from the content-addressed store, hash-verified

208
209// Reads data from the ambient sound data file
210void ReadAmbientData() {
211 CFILE *ifile;
212 char file_id[sizeof(AMBIENT_FILE_ID)];
213 int version;
214
215 // Get rid of any old data
216 FreeAmbientSoundData();
217
218 // Build filename
219 ifile = cfopen(AMBIENT_FILE_NAME, "rb");
220
221 if (!ifile) {
222 Int3();
223 return;
224 }
225
226 // Read file ID
227 cf_ReadBytes((uint8_t *)file_id, strlen(AMBIENT_FILE_ID), ifile);
228 if (strncmp(file_id, AMBIENT_FILE_ID, strlen(AMBIENT_FILE_ID)) != 0) {
229 Int3();
230 cfclose(ifile);
231 return;
232 }
233
234 // Read version
235 version = cf_ReadInt(ifile);
236
237 if (version > AMBIENT_FILE_VERSION) {
238 Int3();
239 cfclose(ifile);
240 return;
241 }
242
243 // Get the number of patterns
244 Num_ambient_sound_patterns = cf_ReadInt(ifile);
245
246 // Read the patterns
247 for (int p = 0; p < Num_ambient_sound_patterns; p++) {
248
249 asp *asp = &Ambient_sound_patterns[p];
250
251 cf_ReadString(asp->name, sizeof(asp->name), ifile);
252
253 asp->min_delay = cf_ReadFloat(ifile);
254 asp->max_delay = cf_ReadFloat(ifile);
255
256 asp->num_sounds = cf_ReadInt(ifile);
257
258 if (asp->num_sounds > 0)
259 asp->sounds = (ase *)mem_malloc(sizeof(*asp->sounds) * asp->num_sounds);
260 else
261 asp->sounds = NULL;
262
263 int prob = 0;
264 for (int s = 0; s < asp->num_sounds; s++) {
265 char tbuf[PAGENAME_LEN];
266
267 cf_ReadString(tbuf, sizeof(tbuf), ifile);

Callers 4

OnCancelMethod · 0.85
OnASPLockMethod · 0.85
OnASPUndoLockMethod · 0.85
InitAmbientSoundSystemFunction · 0.85

Calls 8

FreeAmbientSoundDataFunction · 0.85
cfopenFunction · 0.85
cf_ReadBytesFunction · 0.85
cfcloseFunction · 0.85
cf_ReadIntFunction · 0.85
cf_ReadStringFunction · 0.85
cf_ReadFloatFunction · 0.85
FindSoundNameFunction · 0.85

Tested by

no test coverage detected