Exemplo n.º 1
0
        public static idMapBrush Parse(idLexer lexer, Vector3 origin, bool newFormat = true, float version = idMapFile.CurrentMapVersion)
        {
            idToken               token;
            idMapBrushSide        side;
            List <idMapBrushSide> sides = new List <idMapBrushSide>();
            idDict dict = new idDict();

            Vector3[] planePoints = new Vector3[3];

            if (lexer.ExpectTokenString("{") == false)
            {
                return(null);
            }

            do
            {
                if ((token = lexer.ReadToken()) == null)
                {
                    lexer.Error("idMapBrush::Parse: unexpected EOF");
                    return(null);
                }

                if (token.ToString() == "}")
                {
                    break;
                }

                // here we may have to jump over brush epairs ( only used in editor )
                do
                {
                    // if token is a brace
                    if (token.ToString() == "(")
                    {
                        break;
                    }

                    // the token should be a key string for a key/value pair
                    if (token.Type != TokenType.String)
                    {
                        lexer.Error("idMapBrush::Parse: unexpected {0}, expected ( or epair key string", token.ToString());
                        return(null);
                    }


                    string key = token.ToString();

                    if (((token = lexer.ReadTokenOnLine()) == null) || (token.Type != TokenType.String))
                    {
                        lexer.Error("idMapBrush::Parse: expected epair value string not found");
                        return(null);
                    }

                    dict.Set(key, token.ToString());

                    // try to read the next key
                    if ((token = lexer.ReadToken()) == null)
                    {
                        lexer.Error("idMapBrush::Parse: unexpected EOF");
                        return(null);
                    }
                }while(true);

                lexer.UnreadToken = token;

                side = new idMapBrushSide();
                sides.Add(side);

                if (newFormat == true)
                {
                    float[] tmp = lexer.Parse1DMatrix(4);

                    if (tmp == null)
                    {
                        lexer.Error("idMapBrush::Parse: unable to read brush side plane definition");
                        return(null);
                    }
                    else
                    {
                        side.Plane = new Plane(tmp[0], tmp[1], tmp[2], tmp[3]);
                    }
                }
                else
                {
                    // read the three point plane definition
                    float[] tmp, tmp2, tmp3;

                    if (((tmp = lexer.Parse1DMatrix(3)) == null) ||
                        ((tmp2 = lexer.Parse1DMatrix(3)) == null) ||
                        ((tmp3 = lexer.Parse1DMatrix(3)) == null))
                    {
                        lexer.Error("idMapBrush::Parse: unable to read brush side plane definition");
                        return(null);
                    }

                    planePoints[0] = new Vector3(tmp[0], tmp[1], tmp[2]) - origin;
                    planePoints[1] = new Vector3(tmp2[0], tmp2[1], tmp2[2]) - origin;
                    planePoints[2] = new Vector3(tmp3[0], tmp3[1], tmp3[2]) - origin;

                    side.Plane.FromPoints(planePoints[0], planePoints[1], planePoints[2]);
                }

                // read the texture matrix
                // this is odd, because the texmat is 2D relative to default planar texture axis
                float[,] tmp5 = lexer.Parse2DMatrix(2, 3);

                if (tmp5 == null)
                {
                    lexer.Error("idMapBrush::Parse: unable to read brush side texture matrix");
                    return(null);
                }

                side.TextureMatrix[0] = new Vector3(tmp5[0, 0], tmp5[0, 1], tmp5[0, 2]);
                side.TextureMatrix[1] = new Vector3(tmp5[1, 0], tmp5[1, 1], tmp5[1, 2]);
                side.Origin           = origin;

                // read the material
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    lexer.Error("idMapBrush::Parse: unable to read brush side material");
                    return(null);
                }

                // we had an implicit 'textures/' in the old format...
                if (version < 2.0f)
                {
                    side.Material = "textures/" + token.ToString();
                }
                else
                {
                    side.Material = token.ToString();
                }

                // Q2 allowed override of default flags and values, but we don't any more
                if (lexer.ReadTokenOnLine() != null)
                {
                    if (lexer.ReadTokenOnLine() != null)
                    {
                        if (lexer.ReadTokenOnLine() != null)
                        {
                        }
                    }
                }
            }while(true);

            if (lexer.ExpectTokenString("}") == false)
            {
                return(null);
            }

            idMapBrush brush = new idMapBrush();

            foreach (idMapBrushSide s in sides)
            {
                brush.AddSide(s);
            }

            brush.Dict = dict;

            return(brush);
        }
Exemplo n.º 2
0
        public static idMapBrush ParseQ3(idLexer lexer, Vector3 origin)
        {
            int rotate;

            int[]   shift = new int[2];
            float[] scale = new float[2];

            Vector3[]             planePoints = new Vector3[3];
            List <idMapBrushSide> sides       = new List <idMapBrushSide>();
            idMapBrushSide        side;
            idToken token;

            do
            {
                if (lexer.CheckTokenString("}") == true)
                {
                    break;
                }

                side = new idMapBrushSide();
                sides.Add(side);

                // read the three point plane definition
                float[] tmp  = lexer.Parse1DMatrix(3);
                float[] tmp2 = lexer.Parse1DMatrix(3);
                float[] tmp3 = lexer.Parse1DMatrix(3);

                if ((tmp == null) || (tmp2 == null) || (tmp3 == null))
                {
                    lexer.Error("idMapBrush::ParseQ3: unable to read brush side plane definition");
                    return(null);
                }

                planePoints[0] = new Vector3(tmp[0], tmp[1], tmp[2]) - origin;
                planePoints[1] = new Vector3(tmp2[0], tmp2[1], tmp2[2]) - origin;
                planePoints[2] = new Vector3(tmp3[0], tmp3[1], tmp3[2]) - origin;

                side.Plane.FromPoints(planePoints[0], planePoints[1], planePoints[2]);

                // read the material
                token = lexer.ReadTokenOnLine();

                if (token == null)
                {
                    lexer.Error("idMapBrush::ParseQ3: unable to read brush side material");
                    return(null);
                }

                // we have an implicit 'textures/' in the old format
                side.Material = "textures/" + token.ToString();

                // read the texture shift, rotate and scale
                shift[0] = lexer.ParseInt();
                shift[1] = lexer.ParseInt();

                rotate = lexer.ParseInt();

                scale[0] = lexer.ParseFloat();
                scale[1] = lexer.ParseFloat();

                side.TextureMatrix[0] = new Vector3(0.03125f, 0.0f, 0.0f);
                side.TextureMatrix[1] = new Vector3(0.0f, 0.03125f, 0.0f);

                side.Origin = origin;

                // Q2 allowed override of default flags and values, but we don't any more
                if (lexer.ReadTokenOnLine() != null)
                {
                    if (lexer.ReadTokenOnLine() != null)
                    {
                        if (lexer.ReadTokenOnLine() != null)
                        {
                        }
                    }
                }
            }while(true);

            idMapBrush brush = new idMapBrush();

            for (int i = 0; i < sides.Count; i++)
            {
                brush.AddSide(sides[i]);
            }

            brush.Dict = new idDict();

            return(brush);
        }
Exemplo n.º 3
0
        public static idMapEntity Parse(idLexer lexer, bool isWordSpawn = false, float version = idMapFile.CurrentMapVersion)
        {
            idToken token;

            if ((token = lexer.ReadToken()) == null)
            {
                return(null);
            }

            if (token.ToString() != "{")
            {
                lexer.Error("idMapEntity.Parse: {{ not found, found {0}", token.ToString());
                return(null);
            }

            idMapEntity mapEnt   = new idMapEntity();
            idMapBrush  mapBrush = null;
            idMapPatch  mapPatch = null;
            Vector3     origin   = Vector3.Zero;
            bool        worldEnt = false;
            string      tokenValue;

            do
            {
                if ((token = lexer.ReadToken()) == null)
                {
                    lexer.Error("idMapEntity.Parse: EOF without closing brace");
                    return(null);
                }

                if (token.ToString() == "}")
                {
                    break;
                }

                if (token.ToString() == "{")
                {
                    // parse a brush or patch
                    if ((token = lexer.ReadToken()) == null)
                    {
                        lexer.Error("idMapEntity.Parse: unexpected EOF");
                        return(null);
                    }

                    if (worldEnt == true)
                    {
                        origin = Vector3.Zero;
                    }

                    tokenValue = token.ToString();

                    // if is it a brush: brush, brushDef, brushDef2, brushDef3
                    if (tokenValue.StartsWith("brush", StringComparison.OrdinalIgnoreCase) == true)
                    {
                        mapBrush = idMapBrush.Parse(lexer, origin, (tokenValue.Equals("brushDef2", StringComparison.OrdinalIgnoreCase) || tokenValue.Equals("brushDef3", StringComparison.OrdinalIgnoreCase)), version);

                        if (mapBrush == null)
                        {
                            return(null);
                        }

                        mapEnt.AddPrimitive(mapBrush);
                    }
                    // if is it a patch: patchDef2, patchDef3
                    else if (tokenValue.StartsWith("patch", StringComparison.OrdinalIgnoreCase) == true)
                    {
                        mapPatch = idMapPatch.Parse(lexer, origin, tokenValue.Equals("patchDef3", StringComparison.OrdinalIgnoreCase), version);

                        if (mapPatch == null)
                        {
                            return(null);
                        }

                        mapEnt.AddPrimitive(mapPatch);
                    }
                    // assume it's a brush in Q3 or older style
                    else
                    {
                        lexer.UnreadToken = token;

                        mapBrush = idMapBrush.ParseQ3(lexer, origin);

                        if (mapBrush == null)
                        {
                            return(null);
                        }

                        mapEnt.AddPrimitive(mapBrush);
                    }
                }
                else
                {
                    // parse a key / value pair
                    string key = token.ToString();
                    token = lexer.ReadTokenOnLine();
                    string value = token.ToString();

                    // strip trailing spaces that sometimes get accidentally added in the editor
                    value = value.Trim();
                    key   = key.Trim();

                    mapEnt.Dict.Set(key, value);

                    if (key.Equals("origin", StringComparison.OrdinalIgnoreCase) == true)
                    {
                        // scanf into doubles, then assign, so it is idVec size independent
                        string[] parts = value.Split(' ');

                        float.TryParse(parts[0], out origin.X);
                        float.TryParse(parts[1], out origin.Y);
                        float.TryParse(parts[2], out origin.Z);
                    }
                    else if ((key.Equals("classname", StringComparison.OrdinalIgnoreCase) == true) && (value.Equals("worldspawn", StringComparison.OrdinalIgnoreCase) == true))
                    {
                        worldEnt = true;
                    }
                }
            }while(true);

            return(mapEnt);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks>
        /// Normally this will use a .reg file instead of a .map file if it exists,
        /// which is what the game and dmap want, but the editor will want to always
        /// load a .map file.
        /// </remarks>
        /// <param name="fileName">Does not require an extension.</param>
        /// <param name="ignoreRegion"></param>
        /// <param name="osPath"></param>
        /// <returns></returns>
        public bool Parse(string fileName, bool ignoreRegion = false, bool osPath = false)
        {
            if (this.Disposed == true)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            _hasPrimitiveData = false;
            _name             = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName));

            string fullName = _name;

            // no string concatenation for epairs and allow path names for materials
            idLexer     lexer = new idLexer(LexerOptions.NoStringConcatination | LexerOptions.NoStringEscapeCharacters | LexerOptions.AllowPathNames);
            idMapEntity mapEnt;

            if (ignoreRegion == false)
            {
                // try loading a .reg file first
                lexer.LoadFile(fullName + ".reg", osPath);
            }

            if (lexer.IsLoaded == false)
            {
                // now try a .map file
                lexer.LoadFile(fullName + ".map", osPath);

                if (lexer.IsLoaded == false)
                {
                    // didn't get anything at all
                    return(false);
                }
            }

            _version  = idMapFile.OldMapVersion;
            _fileTime = lexer.FileTime;
            _entities.Clear();

            if (lexer.CheckTokenString("Version") == true)
            {
                _version = lexer.ReadTokenOnLine().ToFloat();
            }

            while (true)
            {
                if ((mapEnt = idMapEntity.Parse(lexer, (_entities.Count == 0), _version)) == null)
                {
                    break;
                }

                _entities.Add(mapEnt);
            }

            idConsole.Warning("TODO: SetGeometryCRC();");

            // if the map has a worldspawn
            if (_entities.Count > 0)
            {
                // "removeEntities" "classname" can be set in the worldspawn to remove all entities with the given classname
                foreach (KeyValuePair <string, string> removeEntities in _entities[0].Dict.MatchPrefix("removeEntities"))
                {
                    RemoveEntities(removeEntities.Value);
                }

                // "overrideMaterial" "material" can be set in the worldspawn to reset all materials
                string material;
                int    entityCount    = _entities.Count;
                int    primitiveCount = 0;
                int    sideCount      = 0;

                if ((material = (_entities[0].Dict.GetString("overrideMaterial", ""))) != string.Empty)
                {
                    for (int i = 0; i < entityCount; i++)
                    {
                        mapEnt         = _entities[i];
                        primitiveCount = mapEnt.Primitives.Count;

                        for (int j = 0; j < primitiveCount; j++)
                        {
                            idMapPrimitive mapPrimitive = mapEnt.GetPrimitive(j);

                            switch (mapPrimitive.Type)
                            {
                            case MapPrimitiveType.Brush:
                                idMapBrush mapBrush = (idMapBrush)mapPrimitive;
                                sideCount = mapBrush.SideCount;

                                for (int k = 0; k < sideCount; k++)
                                {
                                    mapBrush.GetSide(k).Material = material;
                                }
                                break;

                            case MapPrimitiveType.Patch:
                                idConsole.Warning("TODO: PATCH");
                                // TODO: ((idMapPatch) mapPrimitive).Material = material;
                                break;
                            }
                        }
                    }
                }

                // force all entities to have a name key/value pair
                if (_entities[0].Dict.GetBool("forceEntityNames") == true)
                {
                    for (int i = 1; i < entityCount; i++)
                    {
                        mapEnt = _entities[i];

                        if (mapEnt.Dict.ContainsKey("name") == false)
                        {
                            mapEnt.Dict.Set("name", string.Format("{0}{1}", mapEnt.Dict.GetString("classname", "forcedName"), i));
                        }
                    }
                }

                // move the primitives of any func_group entities to the worldspawn
                if (_entities[0].Dict.GetBool("moveFuncGroups") == true)
                {
                    for (int i = 1; i < entityCount; i++)
                    {
                        mapEnt = _entities[i];

                        if (mapEnt.Dict.GetString("classname").ToLower() == "func_group")
                        {
                            _entities[0].Primitives.AddRange(mapEnt.Primitives);
                            mapEnt.Primitives.Clear();
                        }
                    }
                }
            }

            _hasPrimitiveData = true;

            return(true);
        }
Exemplo n.º 5
0
        private bool ParseAnimation(idLexer lexer, int defaultAnimCount)
        {
            List <idMD5Anim> md5anims = new List <idMD5Anim>();
            idMD5Anim        md5anim;
            idAnim           anim;
            AnimationFlags   flags = new AnimationFlags();

            idToken token;
            idToken realName = lexer.ReadToken();

            if (realName == null)
            {
                lexer.Warning("Unexpected end of file");
                MakeDefault();

                return(false);
            }

            string alias = realName.ToString();
            int    i;
            int    count = _anims.Count;

            for (i = 0; i < count; i++)
            {
                if (_anims[i].FullName.Equals(alias, StringComparison.OrdinalIgnoreCase) == true)
                {
                    break;
                }
            }

            if ((i < count) && (i >= defaultAnimCount))
            {
                lexer.Warning("Duplicate anim '{0}'", realName);
                MakeDefault();

                return(false);
            }

            if (i < defaultAnimCount)
            {
                anim = _anims[i];
            }
            else
            {
                // create the alias associated with this animation
                anim = new idAnim();
                _anims.Add(anim);
            }

            // random anims end with a number.  find the numeric suffix of the animation.
            int len = alias.Length;

            for (i = len - 1; i > 0; i--)
            {
                if (Char.IsNumber(alias[i]) == false)
                {
                    break;
                }
            }

            // check for zero length name, or a purely numeric name
            if (i <= 0)
            {
                lexer.Warning("Invalid animation name '{0}'", alias);
                MakeDefault();

                return(false);
            }

            // remove the numeric suffix
            alias = alias.Substring(0, i + 1);

            // parse the anims from the string
            do
            {
                if ((token = lexer.ReadToken()) == null)
                {
                    lexer.Warning("Unexpected end of file");
                    MakeDefault();

                    return(false);
                }

                // lookup the animation
                md5anim = idR.AnimManager.GetAnimation(token.ToString());

                if (md5anim == null)
                {
                    lexer.Warning("Couldn't load anim '{0}'", token);
                    return(false);
                }

                md5anim.CheckModelHierarchy(_model);

                if (md5anims.Count > 0)
                {
                    // make sure it's the same length as the other anims
                    if (md5anim.Length != md5anims[0].Length)
                    {
                        lexer.Warning("Anim '{0}' does not match length of anim '{1}'", md5anim.Name, md5anims[0].Name);
                        MakeDefault();

                        return(false);
                    }
                }

                // add it to our list
                md5anims.Add(md5anim);
            }while(lexer.CheckTokenString(",") == true);

            if (md5anims.Count == 0)
            {
                lexer.Warning("No animation specified");
                MakeDefault();

                return(false);
            }

            anim.SetAnimation(this, realName.ToString(), alias, md5anims.ToArray());

            // parse any frame commands or animflags
            if (lexer.CheckTokenString("{") == true)
            {
                while (true)
                {
                    if ((token = lexer.ReadToken()) == null)
                    {
                        lexer.Warning("Unexpected end of file");
                        MakeDefault();

                        return(false);
                    }

                    string tokenValue = token.ToString();

                    if (tokenValue == "}")
                    {
                        break;
                    }
                    else if (tokenValue == "prevent_idle_override")
                    {
                        flags.PreventIdleOverride = true;
                    }
                    else if (tokenValue == "random_cycle_start")
                    {
                        flags.RandomCycleStart = true;
                    }
                    else if (tokenValue == "ai_no_turn")
                    {
                        flags.AINoTurn = true;
                    }
                    else if (tokenValue == "anim_turn")
                    {
                        flags.AnimationTurn = true;
                    }
                    else if (tokenValue == "frame")
                    {
                        // create a frame command
                        int    frameIndex;
                        string err;

                        // make sure we don't have any line breaks while reading the frame command so the error line # will be correct
                        if ((token = lexer.ReadTokenOnLine()) == null)
                        {
                            lexer.Warning("Missing frame # after 'frame'");
                            MakeDefault();

                            return(false);
                        }
                        else if ((token.Type == TokenType.Punctuation) && (token.ToString() == "-"))
                        {
                            lexer.Warning("Invalid frame # after 'frame'");
                            MakeDefault();

                            return(false);
                        }
                        else if ((token.Type != TokenType.Number) || (token.SubType == TokenSubType.Float))
                        {
                            lexer.Error("expected integer value, found '{0}'", token);
                        }

                        // get the frame number
                        frameIndex = token.ToInt32();

                        // put the command on the specified frame of the animation
                        if ((err = anim.AddFrameCommand(this, frameIndex, lexer, null)) != null)
                        {
                            lexer.Warning(err.ToString());
                            MakeDefault();

                            return(false);
                        }
                    }
                    else
                    {
                        lexer.Warning("Unknown command '{0}'", token);
                        MakeDefault();

                        return(false);
                    }
                }
            }

            // set the flags
            anim.Flags = flags;

            return(true);
        }
Exemplo n.º 6
0
        public string AddFrameCommand(idDeclModel modelDef, int frameIndex, idLexer lexer, idDict def)
        {
            // make sure we're within bounds
            if ((frameIndex < 1) || (frameIndex > _anims[0].FrameCount))
            {
                return(string.Format("Frame {0} out of range", frameIndex));
            }

            // frame numbers are 1 based in .def files, but 0 based internally
            frameIndex--;

            idToken token;
            AnimationFrameCommand frameCommand = new AnimationFrameCommand();

            if ((token = lexer.ReadTokenOnLine()) == null)
            {
                return("Unexpected end of line");
            }

            string tokenValue = token.ToString();

            if (tokenValue == "call")
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                tokenValue        = token.ToString();
                frameCommand.Type = AnimationFrameCommandType.ScriptFunction;
                idConsole.Warning("TODO: fc.function = gameLocal.program.FindFunction( token );");

                if (frameCommand.Function == null)
                {
                    return(string.Format("Function '{0}' not found", tokenValue));
                }
            }
            else if (tokenValue == "object_call")
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                tokenValue          = token.ToString();
                frameCommand.Type   = AnimationFrameCommandType.ScriptFunctionObject;
                frameCommand.String = tokenValue;
            }
            else if (tokenValue == "event")
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                tokenValue        = token.ToString();
                frameCommand.Type = AnimationFrameCommandType.EventFunction;

                idConsole.Warning("TODO: idAnim Event");

                /*const idEventDef *ev = idEventDef::FindEvent( token );
                 * if ( !ev ) {
                 *      return va( "Event '%s' not found", token.c_str() );
                 * }
                 * if ( ev->GetNumArgs() != 0 ) {
                 *      return va( "Event '%s' has arguments", token.c_str() );
                 * }*/

                frameCommand.String = tokenValue;
            }
            else if ((tokenValue == "sound") ||
                     (tokenValue == "sound_voice") ||
                     (tokenValue == "sound_voice2") ||
                     (tokenValue == "sound_body") ||
                     (tokenValue == "sound_body2") ||
                     (tokenValue == "sound_body3") ||
                     (tokenValue == "sound_weapon") ||
                     (tokenValue == "sound_global") ||
                     (tokenValue == "sound_item") ||
                     (tokenValue == "sound_chatter"))
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                switch (tokenValue)
                {
                case "sound":
                    frameCommand.Type = AnimationFrameCommandType.Sound;
                    break;

                case "sound_voice":
                    frameCommand.Type = AnimationFrameCommandType.SoundVoice;
                    break;

                case "sound_voice2":
                    frameCommand.Type = AnimationFrameCommandType.SoundVoice2;
                    break;

                case "sound_body":
                    frameCommand.Type = AnimationFrameCommandType.SoundBody;
                    break;

                case "sound_body2":
                    frameCommand.Type = AnimationFrameCommandType.SoundBody2;
                    break;

                case "sound_body3":
                    frameCommand.Type = AnimationFrameCommandType.SoundBody3;
                    break;

                case "sound_weapon":
                    frameCommand.Type = AnimationFrameCommandType.SoundWeapon;
                    break;

                case "sound_global":
                    frameCommand.Type = AnimationFrameCommandType.SoundGlobal;
                    break;

                case "sound_item":
                    frameCommand.Type = AnimationFrameCommandType.SoundItem;
                    break;

                case "sound_chatter":
                    frameCommand.Type = AnimationFrameCommandType.SoundChatter;
                    break;
                }

                tokenValue = token.ToString();

                if (tokenValue.StartsWith("snd_") == true)
                {
                    frameCommand.String = tokenValue;
                }
                else
                {
                    frameCommand.SoundMaterial = idE.DeclManager.FindSound(tokenValue);

                    if (frameCommand.SoundMaterial.State == DeclState.Defaulted)
                    {
                        idConsole.Warning("Sound '{0}' not found", tokenValue);
                    }
                }
            }
            else if (tokenValue == "skin")
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                tokenValue        = token.ToString();
                frameCommand.Type = AnimationFrameCommandType.Skin;

                if (tokenValue == "none")
                {
                    frameCommand.Skin = null;
                }
                else
                {
                    frameCommand.Skin = idE.DeclManager.FindSkin(tokenValue);

                    if (frameCommand.Skin == null)
                    {
                        return(string.Format("Skin '{0}' not found", tokenValue));
                    }
                }
            }
            else if (tokenValue == "fx")
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                tokenValue        = token.ToString();
                frameCommand.Type = AnimationFrameCommandType.Fx;

                if (idE.DeclManager.FindType(DeclType.Fx, tokenValue) == null)
                {
                    return(string.Format("fx '{0}' not found", tokenValue));
                }

                frameCommand.String = tokenValue;
            }
            else if (tokenValue == "trigger")
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                tokenValue          = token.ToString();
                frameCommand.Type   = AnimationFrameCommandType.Trigger;
                frameCommand.String = tokenValue;
            }
            else if (tokenValue == "triggerSmokeParticle")
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                tokenValue          = token.ToString();
                frameCommand.Type   = AnimationFrameCommandType.TriggerSmokeParticle;
                frameCommand.String = tokenValue;
            }
            else if ((tokenValue == "melee") ||
                     (tokenValue == "direct_damage") ||
                     (tokenValue == "attack_begin"))
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                switch (tokenValue)
                {
                case "melee":
                    frameCommand.Type = AnimationFrameCommandType.Melee;
                    break;

                case "direct_damage":
                    frameCommand.Type = AnimationFrameCommandType.DirectDamage;
                    break;

                case "attack_begin":
                    frameCommand.Type = AnimationFrameCommandType.BeginAttack;
                    break;
                }

                tokenValue = token.ToString();

                if (idR.Game.FindEntityDef(tokenValue, false) == null)
                {
                    return(string.Format("Unknown entityDef '{0}'", tokenValue));
                }

                frameCommand.String = tokenValue;
            }
            else if (tokenValue == "attack_end")
            {
                frameCommand.Type = AnimationFrameCommandType.EndAttack;
            }
            else if (tokenValue == "muzzle_flash")
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                tokenValue = token.ToString();

                if ((tokenValue != string.Empty) && (modelDef.FindJoint(tokenValue) == null))
                {
                    return(string.Format("Joint '{0}' not found", tokenValue));
                }

                frameCommand.Type   = AnimationFrameCommandType.MuzzleFlash;
                frameCommand.String = tokenValue;
            }
            else if ((tokenValue == "create_missile") ||
                     (tokenValue == "launch_missile"))
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                switch (tokenValue)
                {
                case "create_missile":
                    frameCommand.Type = AnimationFrameCommandType.CreateMissile;
                    break;

                case "launch_missile":
                    frameCommand.Type = AnimationFrameCommandType.LaunchMissile;
                    break;
                }

                tokenValue          = token.ToString();
                frameCommand.String = tokenValue;

                if (modelDef.FindJoint(tokenValue) == null)
                {
                    return(string.Format("Joint '{0}' not found", tokenValue));
                }
            }
            else if (tokenValue == "fire_missile_at_target")
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                JointInfo jointInfo = modelDef.FindJoint(token.ToString());

                if (jointInfo == null)
                {
                    return(string.Format("Joint '{0}' not found", token.ToString()));
                }

                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of line");
                }

                frameCommand.Type   = AnimationFrameCommandType.FireMissileAtTarget;
                frameCommand.String = token.ToString();
                frameCommand.Index  = jointInfo.Index;
            }
            else if (tokenValue == "footstep")
            {
                frameCommand.Type = AnimationFrameCommandType.Footstep;
            }
            else if (tokenValue == "leftfoot")
            {
                frameCommand.Type = AnimationFrameCommandType.LeftFoot;
            }
            else if (tokenValue == "rightfoot")
            {
                frameCommand.Type = AnimationFrameCommandType.RightFoot;
            }
            else if (tokenValue == "enableEyeFocus")
            {
                frameCommand.Type = AnimationFrameCommandType.EnableEyeFocus;
            }
            else if (tokenValue == "disableEyeFocus")
            {
                frameCommand.Type = AnimationFrameCommandType.DisableEyeFocus;
            }
            else if (tokenValue == "disableGravity")
            {
                frameCommand.Type = AnimationFrameCommandType.DisableGravity;
            }
            else if (tokenValue == "enableGravity")
            {
                frameCommand.Type = AnimationFrameCommandType.EnableGravity;
            }
            else if (tokenValue == "jump")
            {
                frameCommand.Type = AnimationFrameCommandType.Jump;
            }
            else if (tokenValue == "enableClip")
            {
                frameCommand.Type = AnimationFrameCommandType.EnableClip;
            }
            else if (tokenValue == "disableClip")
            {
                frameCommand.Type = AnimationFrameCommandType.DisableClip;
            }
            else if (tokenValue == "enableWalkIK")
            {
                frameCommand.Type = AnimationFrameCommandType.EnableWalkIk;
            }
            else if (tokenValue == "disableWalkIK")
            {
                frameCommand.Type = AnimationFrameCommandType.DisableWalkIk;
            }
            else if (tokenValue == "enableLegIK")
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of file");
                }

                frameCommand.Type  = AnimationFrameCommandType.EnableLegIk;
                frameCommand.Index = int.Parse(token.ToString());
            }
            else if (tokenValue == "disableLegIK")
            {
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    return("Unexpected end of file");
                }

                frameCommand.Type  = AnimationFrameCommandType.DisableLegIk;
                frameCommand.Index = int.Parse(token.ToString());
            }
            else if (tokenValue == "recordDemo")
            {
                frameCommand.Type = AnimationFrameCommandType.RecordDemo;

                if ((token = lexer.ReadTokenOnLine()) != null)
                {
                    frameCommand.String = token.ToString();
                }
            }
            else if (tokenValue == "aviGame")
            {
                frameCommand.Type = AnimationFrameCommandType.AviGame;

                if ((token = lexer.ReadTokenOnLine()) != null)
                {
                    frameCommand.String = token.ToString();
                }
            }
            else
            {
                return(string.Format("Unknown command '{0}'", tokenValue));
            }

            // check if we've initialized the frame lookup table
            if (_frameLookups.Count == 0)
            {
                // we haven't, so allocate the table and initialize it

                for (int i = 0; i < _anims[0].FrameCount; i++)
                {
                    _frameLookups.Add(new AnimationFrameLookup());
                }
            }

            // calculate the index of the new command
            int index = _frameLookups[frameIndex].FirstCommand + _frameLookups[frameIndex].Index;
            int count = _frameLookups.Count;

            _frameCommands.Insert(index, frameCommand);

            // fix the indices of any later frames to account for the inserted command
            for (int i = frameIndex + 1; i < count; i++)
            {
                _frameLookups[i].FirstCommand++;
            }

            // increase the number of commands on this frame
            _frameLookups[frameIndex].Index++;

            // return with no error
            return(null);
        }
Exemplo n.º 7
0
        private bool ParseMaterial(idLexer lexer)
        {
            _parameters.MinDistance = 1;
            _parameters.MaxDistance = 10;
            _parameters.Volume      = 1;

            _speakerMask = 0;
            _altSound    = null;

            idToken token;
            string  tokenValue;
            int     sampleCount = 0;

            while (true)
            {
                if ((token = lexer.ExpectAnyToken()) == null)
                {
                    return(false);
                }

                tokenValue = token.ToString().ToLower();

                if (tokenValue == "}")
                {
                    break;
                }
                // minimum number of sounds
                else if (tokenValue == "minsamples")
                {
                    sampleCount = lexer.ParseInt();
                }
                else if (tokenValue == "description")
                {
                    _description = lexer.ReadTokenOnLine().ToString();
                }
                else if (tokenValue == "mindistance")
                {
                    _parameters.MinDistance = lexer.ParseFloat();
                }
                else if (tokenValue == "maxdistance")
                {
                    _parameters.MaxDistance = lexer.ParseFloat();
                }
                else if (tokenValue == "shakes")
                {
                    token = lexer.ExpectAnyToken();

                    if (token.Type == TokenType.Number)
                    {
                        _parameters.Shakes = token.ToFloat();
                    }
                    else
                    {
                        lexer.UnreadToken  = token;
                        _parameters.Shakes = 1.0f;
                    }
                }
                else if (tokenValue == "reverb")
                {
                    float reg0 = lexer.ParseFloat();

                    if (lexer.ExpectTokenString(",") == false)
                    {
                        return(false);
                    }

                    float reg1 = lexer.ParseFloat();
                    // no longer supported
                }
                else if (tokenValue == "volume")
                {
                    _parameters.Volume = lexer.ParseFloat();
                }
                // leadinVolume is used to allow light breaking leadin sounds to be much louder than the broken loop
                else if (tokenValue == "leadinvolume")
                {
                    _leadInVolume = lexer.ParseFloat();
                }
                else if (tokenValue == "mask_center")
                {
                    _speakerMask |= 1 << (int)Speakers.Center;
                }
                else if (tokenValue == "mask_left")
                {
                    _speakerMask |= 1 << (int)Speakers.Left;
                }
                else if (tokenValue == "mask_right")
                {
                    _speakerMask |= 1 << (int)Speakers.Right;
                }
                else if (tokenValue == "mask_backright")
                {
                    _speakerMask |= 1 << (int)Speakers.BackRight;
                }
                else if (tokenValue == "mask_backleft")
                {
                    _speakerMask |= 1 << (int)Speakers.BackLeft;
                }
                else if (tokenValue == "mask_lfe")
                {
                    _speakerMask |= 1 << (int)Speakers.Lfe;
                }
                else if (tokenValue == "soundclass")
                {
                    _parameters.SoundClass = lexer.ParseInt();

                    if (_parameters.SoundClass < 0)
                    {
                        lexer.Warning("SoundClass out of range");
                        return(false);
                    }
                }
                else if (tokenValue == "altsound")
                {
                    if ((token = lexer.ExpectAnyToken()) == null)
                    {
                        return(false);
                    }

                    _altSound = idE.DeclManager.FindSound(token.ToString());
                }
                else if (tokenValue == "ordered")
                {
                    // no longer supported
                }
                else if (tokenValue == "no_dups")
                {
                    _parameters.Flags |= SoundMaterialFlags.NoDuplicates;
                }
                else if (tokenValue == "no_flicker")
                {
                    _parameters.Flags |= SoundMaterialFlags.NoFlicker;
                }
                else if (tokenValue == "plain")
                {
                    // no longer supported
                }
                else if (tokenValue == "looping")
                {
                    _parameters.Flags |= SoundMaterialFlags.Looping;
                }
                else if (tokenValue == "no_occlusion")
                {
                    _parameters.Flags |= SoundMaterialFlags.NoOcclusion;
                }
                else if (tokenValue == "private")
                {
                    _parameters.Flags |= SoundMaterialFlags.PrivateSound;
                }
                else if (tokenValue == "antiprivate")
                {
                    _parameters.Flags |= SoundMaterialFlags.AntiPrivateSound;
                }
                else if (tokenValue == "playonce")
                {
                    _parameters.Flags |= SoundMaterialFlags.PlayOnce;
                }
                else if (tokenValue == "global")
                {
                    _parameters.Flags |= SoundMaterialFlags.Global;
                }
                else if (tokenValue == "unclamped")
                {
                    _parameters.Flags |= SoundMaterialFlags.Unclamped;
                }
                else if (tokenValue == "omnidirectional")
                {
                    _parameters.Flags |= SoundMaterialFlags.OmniDirectional;
                }
                // onDemand can't be a parms, because we must track all references and overrides would confuse it
                else if (tokenValue == "ondemand")
                {
                    // no longer loading sounds on demand
                    // _onDemand = true;
                }
                // the wave files
                else if (tokenValue == "leadin")
                {
                    // add to the leadin list
                    if ((token = lexer.ReadToken()) == null)
                    {
                        lexer.Warning("Expected sound after leadin");
                        return(false);
                    }

                    idConsole.Warning("TODO: leadin");

                    /*if(soundSystemLocal.soundCache && numLeadins < maxSamples)
                     * {
                     *      leadins[numLeadins] = soundSystemLocal.soundCache->FindSound(token.c_str(), onDemand);
                     *      numLeadins++;
                     * }*/
                }
                else if ((tokenValue.EndsWith(".wav") == true) || (tokenValue.EndsWith(".ogg") == true))
                {
                    idConsole.Warning("TODO: .wav|.ogg");

                    /*// 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
                {
                    lexer.Warning("unknown token '{0}'", token.ToString());
                    return(false);
                }
            }

            if (_parameters.Shakes > 0.0f)
            {
                idConsole.Warning("TODO: CheckShakesAndOgg()");
            }

            return(true);
        }