예제 #1
0
/*
==================
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;
}
예제 #2
0
/*
==================
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;
}
예제 #3
0
파일: dma.c 프로젝트: icanhas/yantar
/* 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;
}