Ejemplo n.º 1
0
        public void SetAnimation(idDeclModel modelDef, string sourceName, string animName, idMD5Anim[] md5anims)
        {
            _modelDef = modelDef;
            _anims    = md5anims;

            _realName  = sourceName;
            _name      = animName;
            _animFlags = new AnimationFlags();
            _frameCommands.Clear();
            _frameLookups.Clear();
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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;
		}
Ejemplo n.º 4
0
		public void SetAnimation(idDeclModel modelDef, string sourceName, string animName, idMD5Anim[] md5anims)
		{
			_modelDef = modelDef;
			_anims = md5anims;
			
			_realName = sourceName;
			_name = animName;
			_animFlags = new AnimationFlags();
			_frameCommands.Clear();
			_frameLookups.Clear();
		}