/* * @brief Loads the music by the specified name. */ s_music_t *S_LoadMusic(const char *name) { char key[MAX_QPATH]; s_music_t *music; StripExtension(name, key); if (!(music = (s_music_t *) S_FindMedia(key))) { void *buffer; SDL_RWops *rw; Mix_Music *mus; if (S_LoadMusicFile(key, &buffer, &rw, &mus)) { music = (s_music_t *) S_AllocMedia(key, sizeof(s_music_t)); music->media.Retain = S_RetainMusic; music->media.Free = S_FreeMusic; music->buffer = buffer; music->rw = rw; music->music = mus; S_RegisterMedia((s_media_t *) music); } else { Com_Debug("S_LoadMusic: Couldn't load %s\n", key); music = NULL; } } if (music) { s_music_state.playlist = g_list_append(s_music_state.playlist, music); } return music; }
/* * @brief */ s_sample_t *S_LoadSample(const char *name) { char key[MAX_QPATH]; s_sample_t *sample; if (!s_env.initialized) return NULL; if (!name || !name[0]) { Com_Error(ERR_DROP, "NULL name\n"); } StripExtension(name, key); if (!(sample = (s_sample_t *) S_FindMedia(key))) { sample = (s_sample_t *) S_AllocMedia(key, sizeof(s_sample_t)); sample->media.Free = S_FreeSample; S_LoadSampleChunk(sample); S_RegisterMedia((s_media_t *) sample); } return sample; }
/* * @brief */ s_sample_t *S_LoadModelSample(entity_state_t *ent, const char *name) { char model[MAX_QPATH]; char path[MAX_QPATH]; char alias[MAX_QPATH]; s_sample_t *sample; if (!s_env.initialized) return NULL; // determine what model the client is using memset(model, 0, sizeof(model)); if (ent->number - 1 >= MAX_CLIENTS) { Com_Warn("Invalid client entity: %d\n", ent->number - 1); return NULL; } uint16_t n = CS_CLIENTS + ent->number - 1; if (cl.config_strings[n][0]) { char *p = strchr(cl.config_strings[n], '\\'); if (p) { p += 1; strcpy(model, p); p = strchr(model, '/'); if (p) *p = 0; } } // if we can't figure it out, use common if (*model == '\0') strcpy(model, "common"); // see if we already know of the model-specific sound g_snprintf(alias, sizeof(path), "#players/%s/%s", model, name + 1); sample = (s_sample_t *) S_FindMedia(alias); if (sample) return sample; // we don't, try it sample = S_LoadSample(alias); if (sample->chunk) return sample; // that didn't work, so load the common one and alias it // the media subsystem will free the previous sample for us g_snprintf(path, sizeof(path), "#players/common/%s", name + 1); sample = S_LoadSample(path); if (sample->chunk) return S_AliasSample(sample, alias); Com_Warn("Failed to load %s\n", alias); return NULL; }