Пример #1
0
/*
================
idDeclAF::ParseBody
================
*/
bool idDeclAF::ParseBody( idLexer &src ) {
	bool hasJoint = false;
	idToken token;
	idAFVector angles;
	idDeclAF_Body *body = new idDeclAF_Body;

	bodies.Alloc() = body;

	body->SetDefault( this );

	if ( !src.ExpectTokenType( TT_STRING, 0, &token ) ||
			!src.ExpectTokenString( "{" ) ) {
		return false;
	}

	body->name = token;
	if ( !body->name.Icmp( "origin" ) || !body->name.Icmp( "world" ) ) {
		src.Error( "a body may not be named \"origin\" or \"world\"" );
		return false;
	}

	while( src.ReadToken( &token ) ) {

		if ( !token.Icmp( "model" ) ) {
			if ( !src.ExpectTokenType( TT_NAME, 0, &token ) ) {
				return false;
			}
			if ( !token.Icmp( "box" ) ) {
				body->modelType = TRM_BOX;
				if ( !src.ExpectTokenString( "(" ) ||
					!body->v1.Parse( src ) ||
					!src.ExpectTokenString( "," ) ||
					!body->v2.Parse( src ) ||
					!src.ExpectTokenString( ")" ) ) {
					return false;
				}
			} else if ( !token.Icmp( "octahedron" ) ) {
				body->modelType = TRM_OCTAHEDRON;
				if ( !src.ExpectTokenString( "(" ) ||
					!body->v1.Parse( src ) ||
					!src.ExpectTokenString( "," ) ||
					!body->v2.Parse( src ) ||
					!src.ExpectTokenString( ")" ) ) {
					return false;
				}
			} else if ( !token.Icmp( "dodecahedron" ) ) {
				body->modelType = TRM_DODECAHEDRON;
				if ( !src.ExpectTokenString( "(" ) ||
					!body->v1.Parse( src ) ||
					!src.ExpectTokenString( "," ) ||
					!body->v2.Parse( src ) ||
					!src.ExpectTokenString( ")" ) ) {
					return false;
				}
			} else if ( !token.Icmp( "cylinder" ) ) {
				body->modelType = TRM_CYLINDER;
				if ( !src.ExpectTokenString( "(" ) ||
					!body->v1.Parse( src ) ||
					!src.ExpectTokenString( "," ) ||
					!body->v2.Parse( src ) ||
					!src.ExpectTokenString( "," ) ) {
					return false;
				}
				body->numSides = src.ParseInt();
				if ( !src.ExpectTokenString( ")" ) ) {
					return false;
				}
			} else if ( !token.Icmp( "cone" ) ) {
				body->modelType = TRM_CONE;
				if ( !src.ExpectTokenString( "(" ) ||
					!body->v1.Parse( src ) ||
					!src.ExpectTokenString( "," ) ||
					!body->v2.Parse( src ) ||
					!src.ExpectTokenString( "," ) ) {
					return false;
				}
				body->numSides = src.ParseInt();
				if ( !src.ExpectTokenString( ")" ) ) {
					return false;
				}
			} else if ( !token.Icmp( "bone" ) ) {
				body->modelType = TRM_BONE;
				if ( !src.ExpectTokenString( "(" ) ||
					!body->v1.Parse( src ) ||
					!src.ExpectTokenString( "," ) ||
					!body->v2.Parse( src ) ||
					!src.ExpectTokenString( "," ) ) {
					return false;
				}
				body->width = src.ParseFloat();
				if ( !src.ExpectTokenString( ")" ) ) {
					return false;
				}
			} else if ( !token.Icmp( "custom" ) ) {
				src.Error( "custom models not yet implemented" );
				return false;
			} else {
				src.Error( "unkown model type %s", token.c_str() );
				return false;
			}
		} else if ( !token.Icmp( "origin" ) ) {
			if ( !body->origin.Parse( src ) ) {
				return false;
			}
		} else if ( !token.Icmp( "angles" ) ) {
			if ( !angles.Parse( src ) ) {
				return false;
			}
			body->angles = idAngles( angles.ToVec3().x, angles.ToVec3().y, angles.ToVec3().z );
		} else if ( !token.Icmp( "joint" ) ) {
			if ( !src.ExpectTokenType( TT_STRING, 0, &token ) ) {
				return false;
			}
			body->jointName = token;
			hasJoint = true;
		} else if ( !token.Icmp( "mod" ) ) {
			if ( !src.ExpectAnyToken( &token ) ) {
				return false;
			}
			body->jointMod = JointModFromString( token.c_str() );
		} else if ( !token.Icmp( "density" ) ) {
			body->density = src.ParseFloat();
		} else if ( !token.Icmp( "inertiaScale" ) ) {
			src.Parse1DMatrix( 9, body->inertiaScale[0].ToFloatPtr() );
		} else if ( !token.Icmp( "friction" ) ) {
			body->linearFriction = src.ParseFloat();
			src.ExpectTokenString( "," );
			body->angularFriction = src.ParseFloat();
			src.ExpectTokenString( "," );
			body->contactFriction = src.ParseFloat();
		} else if ( !token.Icmp( "contents" ) ) {
			ParseContents( src, body->contents );
		} else if ( !token.Icmp( "clipMask" ) ) {
			ParseContents( src, body->clipMask );
		} else if ( !token.Icmp( "selfCollision" ) ) {
			body->selfCollision = src.ParseBool();
		} else if ( !token.Icmp( "containedjoints" ) ) {
			if ( !src.ExpectTokenType( TT_STRING, 0, &token ) ) {
				return false;
			}
			body->containedJoints = token;
		} else if ( !token.Icmp( "frictionDirection" ) ) {
			if ( !body->frictionDirection.Parse( src ) ) {
				return false;
			}
		} else if ( !token.Icmp( "contactMotorDirection" ) ) {
			if ( !body->contactMotorDirection.Parse( src ) ) {
				return false;
			}
		} else if ( token == "}" ) {
			break;
		} else {
			src.Error( "unknown token %s in body", token.c_str() );
			return false;
		}
	}

	if ( body->modelType == TRM_INVALID ) {
		src.Error( "no model set for body" );
		return false;
	}

	if ( !hasJoint ) {
		src.Error( "no joint set for body" );
		return false;
	}

	body->clipMask |= CONTENTS_MOVEABLECLIP;

	return true;
}
Пример #2
0
/*
===============
idSoundShader::ParseShader
===============
*/
bool idSoundShader::ParseShader( idLexer &src )
{
    int			i;
    idToken		token;

    parms.minDistance = 1;
    parms.maxDistance = 10;
    parms.volume = 1;
    parms.shakes = 0;
    parms.soundShaderFlags = 0;
    parms.soundClass = 0;

    speakerMask = 0;
    altSound = NULL;

    for( i = 0; i < SOUND_MAX_LIST_WAVS; i++ )
    {
        leadins[i] = NULL;
        entries[i] = NULL;
    }
    numEntries = 0;
    numLeadins = 0;

    int	maxSamples = idSoundSystemLocal::s_maxSoundsPerShader.GetInteger();
    if ( com_makingBuild.GetBool() || maxSamples <= 0 || maxSamples > SOUND_MAX_LIST_WAVS )
    {
        maxSamples = SOUND_MAX_LIST_WAVS;
    }

    while ( 1 )
    {
        if ( !src.ExpectAnyToken( &token ) )
        {
            return false;
        }
        // end of definition
        else if ( token == "}" )
        {
            break;
        }
        // minimum number of sounds
        else if ( !token.Icmp( "minSamples" ) )
        {
            maxSamples = idMath::ClampInt( src.ParseInt(), SOUND_MAX_LIST_WAVS, maxSamples );
        }
        // description
        else if ( !token.Icmp( "description" ) )
        {
            src.ReadTokenOnLine( &token );
            desc = token.c_str();
        }
        // mindistance
        else if ( !token.Icmp( "mindistance" ) )
        {
            parms.minDistance = src.ParseFloat();
        }
        // maxdistance
        else if ( !token.Icmp( "maxdistance" ) )
        {
            parms.maxDistance = src.ParseFloat();
        }
        // shakes screen
        else if ( !token.Icmp( "shakes" ) )
        {
            src.ExpectAnyToken( &token );
            if ( token.type == TT_NUMBER )
            {
                parms.shakes = token.GetFloatValue();
            }
            else
            {
                src.UnreadToken( &token );
                parms.shakes = 1.0f;
            }
        }
        // reverb
        else if ( !token.Icmp( "reverb" ) )
        {
            int reg0 = src.ParseFloat();
            if ( !src.ExpectTokenString( "," ) )
            {
                src.FreeSource();
                return false;
            }
            int reg1 = src.ParseFloat();
            // no longer supported
        }
        // volume
        else if ( !token.Icmp( "volume" ) )
        {
            parms.volume = src.ParseFloat();
        }
        // leadinVolume is used to allow light breaking leadin sounds to be much louder than the broken loop
        else if ( !token.Icmp( "leadinVolume" ) )
        {
            leadinVolume = src.ParseFloat();
        }
        // speaker mask
        else if ( !token.Icmp( "mask_center" ) )
        {
            speakerMask |= 1<<SPEAKER_CENTER;
        }
        // speaker mask
        else if ( !token.Icmp( "mask_left" ) )
        {
            speakerMask |= 1<<SPEAKER_LEFT;
        }
        // speaker mask
        else if ( !token.Icmp( "mask_right" ) )
        {
            speakerMask |= 1<<SPEAKER_RIGHT;
        }
        // speaker mask
        else if ( !token.Icmp( "mask_backright" ) )
        {
            speakerMask |= 1<<SPEAKER_BACKRIGHT;
        }
        // speaker mask
        else if ( !token.Icmp( "mask_backleft" ) )
        {
            speakerMask |= 1<<SPEAKER_BACKLEFT;
        }
        // speaker mask
        else if ( !token.Icmp( "mask_lfe" ) )
        {
            speakerMask |= 1<<SPEAKER_LFE;
        }
        // soundClass
        else if ( !token.Icmp( "soundClass" ) )
        {
            parms.soundClass = src.ParseInt();
            if ( parms.soundClass < 0 || parms.soundClass >= SOUND_MAX_CLASSES )
            {
                src.Warning( "SoundClass out of range" );
                return false;
            }
        }
        // altSound
        else if ( !token.Icmp( "altSound" ) )
        {
            if ( !src.ExpectAnyToken( &token ) )
            {
                return false;
            }
            altSound = declManager->FindSound( token.c_str() );
        }
        // ordered
        else if ( !token.Icmp( "ordered" ) )
        {
            // no longer supported
        }
        // no_dups
        else if ( !token.Icmp( "no_dups" ) )
        {
            parms.soundShaderFlags |= SSF_NO_DUPS;
        }
        // no_flicker
        else if ( !token.Icmp( "no_flicker" ) )
        {
            parms.soundShaderFlags |= SSF_NO_FLICKER;
        }
        // plain
        else if ( !token.Icmp( "plain" ) )
        {
            // no longer supported
        }
        // looping
        else if ( !token.Icmp( "looping" ) )
        {
            parms.soundShaderFlags |= SSF_LOOPING;
        }
        // no occlusion
        else if ( !token.Icmp( "no_occlusion" ) )
        {
            parms.soundShaderFlags |= SSF_NO_OCCLUSION;
        }
        // private
        else if ( !token.Icmp( "private" ) )
        {
            parms.soundShaderFlags |= SSF_PRIVATE_SOUND;
        }
        // antiPrivate
        else if ( !token.Icmp( "antiPrivate" ) )
        {
            parms.soundShaderFlags |= SSF_ANTI_PRIVATE_SOUND;
        }
        // once
        else if ( !token.Icmp( "playonce" ) )
        {
            parms.soundShaderFlags |= SSF_PLAY_ONCE;
        }
        // global
        else if ( !token.Icmp( "global" ) )
        {
            parms.soundShaderFlags |= SSF_GLOBAL;
        }
        // unclamped
        else if ( !token.Icmp( "unclamped" ) )
        {
            parms.soundShaderFlags |= SSF_UNCLAMPED;
        }
        // omnidirectional
        else if ( !token.Icmp( "omnidirectional" ) )
        {
            parms.soundShaderFlags |= SSF_OMNIDIRECTIONAL;
        }
        // onDemand can't be a parms, because we must track all references and overrides would confuse it
        else if ( !token.Icmp( "onDemand" ) )
        {
            // no longer loading sounds on demand
            //onDemand = true;
        }

        // the wave files
        else if ( !token.Icmp( "leadin" ) )
        {
            // add to the leadin list
            if ( !src.ReadToken( &token ) )
            {
                src.Warning( "Expected sound after leadin" );
                return false;
            }
            if ( soundSystemLocal.soundCache && numLeadins < maxSamples )
            {
                leadins[ numLeadins ] = soundSystemLocal.soundCache->FindSound( token.c_str(), onDemand );
                numLeadins++;
            }
        }
        else if ( token.Find( ".wav", false ) != -1 || token.Find( ".ogg", false ) != -1 )
        {
            // add to the wav list
            if ( soundSystemLocal.soundCache && numEntries < maxSamples )
            {
                token.BackSlashesToSlashes();
                idStr lang = cvarSystem->GetCVarString( "sys_lang" );
                if ( lang.Icmp( "english" ) != 0 && token.Find( "sound/vo/", false ) >= 0 )
                {
                    idStr work = token;
                    work.ToLower();
                    work.StripLeading( "sound/vo/" );
                    work = va( "sound/vo/%s/%s", lang.c_str(), work.c_str() );
                    if ( fileSystem->ReadFile( work, NULL, NULL ) > 0 )
                    {
                        token = work;
                    }
                    else
                    {
                        // also try to find it with the .ogg extension
                        work.SetFileExtension( ".ogg" );
                        if ( fileSystem->ReadFile( work, NULL, NULL ) > 0 )
                        {
                            token = work;
                        }
                    }
                }
                entries[ numEntries ] = soundSystemLocal.soundCache->FindSound( token.c_str(), onDemand );
                numEntries++;
            }
        }
        else
        {
            src.Warning( "unknown token '%s'", token.c_str() );
            return false;
        }
    }

    if ( parms.shakes > 0.0f )
    {
        CheckShakesAndOgg();
    }

    return true;
}
Пример #3
0
/*
===============
idSoundShader::ParseShader
===============
*/
bool idSoundShader::ParseShader( idLexer &src ) {
	idToken		token;

	parms.minDistance = 1;
	parms.maxDistance = 10;
	parms.volume = 1;
	parms.shakes = 0;
	parms.soundShaderFlags = 0;
	parms.soundClass = 0;

	speakerMask = 0;
	altSound = NULL;

	entries.Clear();

	while ( 1 ) {
		if ( !src.ExpectAnyToken( &token ) ) {
			return false;
		}
		// end of definition
		else if ( token == "}" ) {
			break;
		}
		// minimum number of sounds
		else if ( !token.Icmp( "minSamples" ) ) {
			src.ParseInt();
		}
		// description
		else if ( !token.Icmp( "description" ) ) {
			src.ReadTokenOnLine( &token );
		}
		// mindistance
		else if ( !token.Icmp( "mindistance" ) ) {
			parms.minDistance = src.ParseFloat();
		}
		// maxdistance
		else if ( !token.Icmp( "maxdistance" ) ) {
			parms.maxDistance = src.ParseFloat();
		}
		// shakes screen
		else if ( !token.Icmp( "shakes" ) ) {
			src.ExpectAnyToken( &token );
			if ( token.type == TT_NUMBER ) {
				parms.shakes = token.GetFloatValue();
			} else {
				src.UnreadToken( &token );
				parms.shakes = 1.0f;
			}
		}
		// reverb
		else if ( !token.Icmp( "reverb" ) ) {
			src.ParseFloat();
			if ( !src.ExpectTokenString( "," ) ) {
				src.FreeSource();
				return false;
			}
			src.ParseFloat();
			// no longer supported
		}
		// volume
		else if ( !token.Icmp( "volume" ) ) {
			parms.volume = src.ParseFloat();
		}
		// leadinVolume is used to allow light breaking leadin sounds to be much louder than the broken loop
		else if ( !token.Icmp( "leadinVolume" ) ) {
			leadinVolume = src.ParseFloat();
			leadin = true;
		}
		// speaker mask
		else if ( !token.Icmp( "mask_center" ) ) {
			speakerMask |= 1<<SPEAKER_CENTER;
		}
		// speaker mask
		else if ( !token.Icmp( "mask_left" ) ) {
			speakerMask |= 1<<SPEAKER_LEFT;
		}
		// speaker mask
		else if ( !token.Icmp( "mask_right" ) ) {
			speakerMask |= 1<<SPEAKER_RIGHT;
		}
		// speaker mask
		else if ( !token.Icmp( "mask_backright" ) ) {
			speakerMask |= 1<<SPEAKER_BACKRIGHT;
		}
		// speaker mask
		else if ( !token.Icmp( "mask_backleft" ) ) {
			speakerMask |= 1<<SPEAKER_BACKLEFT;
		}
		// speaker mask
		else if ( !token.Icmp( "mask_lfe" ) ) {
			speakerMask |= 1<<SPEAKER_LFE;
		}
		// soundClass
		else if ( !token.Icmp( "soundClass" ) ) {
			parms.soundClass = src.ParseInt();
			if ( parms.soundClass < 0 || parms.soundClass >= SOUND_MAX_CLASSES ) {
				src.Warning( "SoundClass out of range" );
				return false;
			}
		}
		// altSound
		else if ( !token.Icmp( "altSound" ) ) {
			if ( !src.ExpectAnyToken( &token ) ) {
				return false;
			}
			altSound = declManager->FindSound( token.c_str() );
		}
		// ordered
		else if ( !token.Icmp( "ordered" ) ) {
			// no longer supported
		}
		// no_dups
		else if ( !token.Icmp( "no_dups" ) ) {
			parms.soundShaderFlags |= SSF_NO_DUPS;
		}
		// no_flicker
		else if ( !token.Icmp( "no_flicker" ) ) {
			parms.soundShaderFlags |= SSF_NO_FLICKER;
		}
		// plain
		else if ( !token.Icmp( "plain" ) ) {	
			// no longer supported
		}
		// looping
		else if ( !token.Icmp( "looping" ) ) {
			parms.soundShaderFlags |= SSF_LOOPING;
		}
		// no occlusion
		else if ( !token.Icmp( "no_occlusion" ) ) {
			parms.soundShaderFlags |= SSF_NO_OCCLUSION;
		}
		// private
		else if ( !token.Icmp( "private" ) ) {
			parms.soundShaderFlags |= SSF_PRIVATE_SOUND;
		}
		// antiPrivate
		else if ( !token.Icmp( "antiPrivate" ) ) {
			parms.soundShaderFlags |= SSF_ANTI_PRIVATE_SOUND;
		}
		// once
		else if ( !token.Icmp( "playonce" ) ) {
			parms.soundShaderFlags |= SSF_PLAY_ONCE;
		}
		// global
		else if ( !token.Icmp( "global" ) ) {
			parms.soundShaderFlags |= SSF_GLOBAL;
		}
		// unclamped
		else if ( !token.Icmp( "unclamped" ) ) {
			parms.soundShaderFlags |= SSF_UNCLAMPED;
		}
		// omnidirectional
		else if ( !token.Icmp( "omnidirectional" ) ) {
			parms.soundShaderFlags |= SSF_OMNIDIRECTIONAL;
		}
		else if ( !token.Icmp( "onDemand" ) ) {
			// no longer loading sounds on demand
		}
		// the wave files
		else if ( !token.Icmp( "leadin" ) ) {
			leadin = true;
		} else if ( token.Find( ".wav", false ) != -1 || token.Find( ".ogg", false ) != -1 ) {
			if ( token.IcmpPrefixPath( "sound/vo/" ) == 0 || token.IcmpPrefixPath( "sound/guis/" ) == 0 ) {
				parms.soundShaderFlags |= SSF_VO;
			}
			if ( token.IcmpPrefixPath( "sound/musical/" ) == 0 ) {
				parms.soundShaderFlags |= SSF_MUSIC;
			}
			// add to the wav list
			if ( s_maxSamples.GetInteger() == 0 || ( s_maxSamples.GetInteger() > 0 && entries.Num() < s_maxSamples.GetInteger() ) ) {
				entries.Append( soundSystemLocal.LoadSample( token.c_str() ) );
			}
		} else {
			src.Warning( "unknown token '%s'", token.c_str() );
			return false;
		}
	}

	return true;
}