/* ================== S_FindName Will allocate a new sfx if it isn't found ================== */ static sfx_t *S_FindName( const char *name ) { int i; int hash; sfx_t *sfx; if (!name) { Com_Error(ERR_FATAL, "Sound name is NULL"); } if (!name[0]) { Com_Printf( S_COLOR_YELLOW "WARNING: Sound name is empty\n" ); return NULL; } if (strlen(name) >= MAX_QPATH) { Com_Printf( S_COLOR_YELLOW "WARNING: Sound name is too long: %s\n", name ); return NULL; } if (name[0] == '*') { Com_Printf( S_COLOR_YELLOW "WARNING: Tried to load player sound directly: %s\n", name ); return NULL; } hash = S_HashSFXName(name); sfx = sfxHash[hash]; // see if already loaded while (sfx) { if (!Q_stricmp(sfx->soundName, name) ) { return sfx; } sfx = sfx->next; } // find a free sfx for (i=0 ; i < s_numSfx ; i++) { if (!s_knownSfx[i].soundName[0]) { break; } } if (i == s_numSfx) { if (s_numSfx == MAX_SFX) { Com_Error (ERR_FATAL, "S_FindName: out of sfx_t"); } s_numSfx++; } sfx = &s_knownSfx[i]; Com_Memset (sfx, 0, sizeof(*sfx)); strcpy (sfx->soundName, name); sfx->next = sfxHash[hash]; sfxHash[hash] = sfx; return sfx; }
/* ================== S_FindName Will allocate a new sfx if it isn't found ================== */ static sfx_t *S_FindName( const char *name ) { int i; int hash; sfx_t *sfx; if (!name) { Com_Error (ERR_FATAL, "S_FindName: NULL"); } if (!name[0]) { Com_Error (ERR_FATAL, "S_FindName: empty name"); } if (strlen(name) >= MAX_QPATH) { Com_Error (ERR_FATAL, "Sound name too long: %s", name); } hash = S_HashSFXName(name); sfx = sfxHash[hash]; // see if already loaded while (sfx) { if (!Q_stricmp(sfx->soundName, name) ) { return sfx; } sfx = sfx->next; } // find a free sfx for (i=0 ; i < s_numSfx ; i++) { if (!s_knownSfx[i].soundName[0]) { break; } } if (i == s_numSfx) { if (s_numSfx == MAX_SFX) { Com_Error (ERR_FATAL, "S_FindName: out of sfx_t"); } s_numSfx++; } sfx = &s_knownSfx[i]; Com_Memset (sfx, 0, sizeof(*sfx)); strcpy (sfx->soundName, name); sfx->next = sfxHash[hash]; sfxHash[hash] = sfx; return sfx; }
/* Will allocate a new sfx if it isn't found */ static Sfx * S_FindName(const char *name) { int i; int hash; Sfx *sfx; if(!name) comerrorf (ERR_FATAL, "S_FindName: NULL"); if(!name[0]) comerrorf (ERR_FATAL, "S_FindName: empty name"); if(strlen(name) >= MAX_QPATH) comerrorf (ERR_FATAL, "Sound name too long: %s", name); hash = S_HashSFXName(name); sfx = sfxHash[hash]; /* see if already loaded */ while(sfx) { if(!Q_stricmp(sfx->soundName, name)) return sfx; sfx = sfx->next; } /* find a free sfx */ for(i=0; i < s_numSfx; i++) if(!s_knownSfx[i].soundName[0]) break; if(i == s_numSfx) { if(s_numSfx == MAX_SFX) comerrorf (ERR_FATAL, "S_FindName: out of Sfx"); s_numSfx++; } sfx = &s_knownSfx[i]; Q_Memset(sfx, 0, sizeof(*sfx)); strcpy(sfx->soundName, name); sfx->next = sfxHash[hash]; sfxHash[hash] = sfx; return sfx; }