public static LocalBlendState ProcessAlphaBlendMode(ref List <ParticleEmitterToken> .Enumerator tokenIter)
        {
            if (tokenIter.Current.Type != TokenType.AlphaBlendMode)
            {
                throw new Exception("Expecting alpha blend mode (D3DBLEND_ZERO, D3DBLEND_ONE, etc.).");
            }

            LocalBlendState alphaBlendMode;

            for (int q = 0; q < NUMBLENDINGMODES; q++)
            {
                // careful here... must match on both string and size
                // (i.e., to differentiate between D3DBLEND_SRCALPHA and D3DBLEND_SRCALPHASAT).
                if (tokenIter.Current.StringValue.Contains(blendingModes[q].Name) &&
                    tokenIter.Current.StringValue.Length == blendingModes[q].Name.Length)
                {
                    alphaBlendMode = blendingModes[q].Mode;

                    ParticleEmitterTokenizer.NextToken(ref tokenIter);

                    return(alphaBlendMode);
                }
            }

            throw new Exception("Invalid alpha blending mode!");
        }
        public static MinMax <Vector3> ProcessVector(ref List <ParticleEmitterToken> .Enumerator tokenIter)
        {
            // this token needs to be a XYZ keyword.
            if (tokenIter.Current.Type != TokenType.KeywordXYZ)
            {
                throw new Exception("Expecting XYZ(...)!");
            }

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            if (tokenIter.Current.Type != TokenType.OpenParen)
            {
                throw new Exception("Expecting ( after XYZ!");
            }

            MinMax <float> x;
            MinMax <float> y;
            MinMax <float> z;

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            x = ProcessNumber(ref tokenIter);

            if (tokenIter.Current.Type != TokenType.Comma)
            {
                throw new Exception("Vector components must be seperated by a comma.");
            }

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            y = ProcessNumber(ref tokenIter);

            if (tokenIter.Current.Type != TokenType.Comma)
            {
                throw new Exception("Vector components must be seperated by a comma.");
            }

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            z = ProcessNumber(ref tokenIter);

            if (tokenIter.Current.Type != TokenType.CloseParen)
            {
                throw new Exception("Expecting ) to close vector.");
            }

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            MinMax <Vector3> v = new MinMax <Vector3>
            {
                Min = new Vector3(x.Min, y.Min, z.Min),
                Max = new Vector3(x.Max, y.Max, z.Max)
            };

            return(v);
        }
        public static MinMax <float> ProcessNumber(ref List <ParticleEmitterToken> .Enumerator tokenIter)
        {
            MinMax <float> number = new MinMax <float>();

            // the first token is either the random keyword, or it's an actual number.
            switch (tokenIter.Current.Type)
            {
            case TokenType.KeywordRandom:
                // parse random number into minmax
                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                if (tokenIter.Current.Type != TokenType.OpenParen)
                {
                    throw new Exception("Expecting opening paren after Random keyword.");
                }

                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                if (tokenIter.Current.Type != TokenType.RealNumber)
                {
                    throw new Exception("Expecting first number within Random(...).");
                }

                number.Min = float.Parse(tokenIter.Current.StringValue, CultureInfo.InvariantCulture.NumberFormat);

                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                if (tokenIter.Current.Type != TokenType.Comma)
                {
                    throw new Exception("Expecting comma within Random(...).");
                }

                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                if (tokenIter.Current.Type != TokenType.RealNumber)
                {
                    throw new Exception("Expecting second number within Random(...).");
                }

                number.Max = float.Parse(tokenIter.Current.StringValue, CultureInfo.InvariantCulture.NumberFormat);

                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                if (tokenIter.Current.Type != TokenType.CloseParen)
                {
                    throw new Exception("Missing close paren on Random(...).");
                }

                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                break;

            case TokenType.RealNumber:
                // min and max both equal realnumber
                if (tokenIter.Current.Type != TokenType.RealNumber)
                {
                    throw new Exception("Expecting number.");
                }

                number.Max = number.Min = float.Parse(tokenIter.Current.StringValue, CultureInfo.InvariantCulture.NumberFormat);

                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                break;

            default:
                throw new Exception("Expecting either Random(...) or a number value.");
            }

            return(number);
        }
        public static bool ProcessTime(ref MinMax <float> timeRange, ref bool isFade, float initialTime, float finalTime, ref List <ParticleEmitterToken> .Enumerator tokenIter)
        {
            // determine if this time specification is a fade directive
            if (tokenIter.Current.Type == TokenType.KeywordFade)
            {
                // it is... the next token must be "so"
                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                if (tokenIter.Current.Type != TokenType.KeywordSo)
                {
                    throw new Exception("Expecting \"so\" after \"fade\".");
                }

                // flip the fade flag on
                isFade = true;

                // move to next token (so that we land on "at" for the code below)
                ParticleEmitterTokenizer.NextToken(ref tokenIter);
            }
            else
            {
                isFade = false; // just to be safe
            }

            switch (tokenIter.Current.Type)
            {
            case TokenType.KeywordAt:
            {
                // easy, just grab the time
                ParticleEmitterTokenizer.NextToken(ref tokenIter);

                timeRange = ProcessNumber(ref tokenIter);
            }

            break;

            case TokenType.KeywordInitial:
            {
                // use initial time that was passed in.
                if (isFade)
                {
                    throw new Exception("Cannot use \"fade so\" modifier on \"initial\" times.");
                }

                timeRange.Min = initialTime;
                timeRange.Max = initialTime;

                ParticleEmitterTokenizer.NextToken(ref tokenIter);
            }

            break;

            case TokenType.KeywordFinal:
            {
                // use final time that was passed in.
                timeRange.Min = finalTime;
                timeRange.Max = finalTime;

                ParticleEmitterTokenizer.NextToken(ref tokenIter);
            }

            break;

            default:
                throw new Exception("Expected time specifier: \"[fade so] at\", \"initial\", or \"[fade so] final\"");
            }

            return(true);
        }
        public static MinMax <Color> ProcessColor(ref List <ParticleEmitterToken> .Enumerator tokenIter)
        {
            MinMax <Color> c = new MinMax <Color>();

            // this token needs to be a RGBA keyword.
            if (tokenIter.Current.Type != TokenType.KeywordColor)
            {
                throw new Exception("Expecting RGBA(...)!");
            }

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            if (tokenIter.Current.Type != TokenType.OpenParen)
            {
                throw new Exception("Expecting ( after RGBA!");
            }

            MinMax <float> r = new MinMax <float>();
            MinMax <float> g = new MinMax <float>();
            MinMax <float> b = new MinMax <float>();
            MinMax <float> a = new MinMax <float>();

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            r = ProcessNumber(ref tokenIter);

            if (tokenIter.Current.Type != TokenType.Comma)
            {
                throw new Exception("Color components must be seperated by a comma.");
            }

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            g = ProcessNumber(ref tokenIter);
            if (tokenIter.Current.Type != TokenType.Comma)
            {
                throw new Exception("Color components must be seperated by a comma.");
            }

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            b = ProcessNumber(ref tokenIter);
            if (tokenIter.Current.Type != TokenType.Comma)
            {
                throw new Exception("Color components must be seperated by a comma.");
            }

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            a = ProcessNumber(ref tokenIter);
            if (tokenIter.Current.Type != TokenType.CloseParen)
            {
                throw new Exception("Expecting ) to close vector.");
            }

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            c.Min = new Color(r.Min, g.Min, b.Min, a.Min);
            c.Max = new Color(r.Max, g.Max, b.Max, a.Max);

            return(c);
        }