예제 #1
0
        private void ParseBrushes(idLexer lexer, CollisionModel model)
        {
            idToken             token = lexer.CheckTokenType(TokenType.Number, 0);
            int                 planeCount;
            CollisionModelBrush b;

            float[] tmp;

            lexer.ExpectTokenString("{");

            while (lexer.CheckTokenString("}") == false)
            {
                // parse brush
                planeCount = lexer.ParseInt();

                b          = new CollisionModelBrush();
                b.Contents = ContentFlags.All;
                b.Material = _traceModelMaterial;
                b.Planes   = new Plane[planeCount];

                lexer.ExpectTokenString("{");

                for (int i = 0; i < planeCount; i++)
                {
                    tmp = lexer.Parse1DMatrix(3);

                    b.Planes[i].Normal = new Vector3(tmp[0], tmp[1], tmp[2]);
                    b.Planes[i].D      = lexer.ParseFloat();
                }

                lexer.ExpectTokenString("}");

                tmp          = lexer.Parse1DMatrix(3);
                b.Bounds.Min = new Vector3(tmp[0], tmp[1], tmp[2]);

                tmp          = lexer.Parse1DMatrix(3);
                b.Bounds.Max = new Vector3(tmp[0], tmp[1], tmp[2]);

                token = lexer.ReadToken();

                if (token.Type == TokenType.Number)
                {
                    b.Contents = (ContentFlags)token.ToInt32();                      // old .cm files use a single integer
                }
                else
                {
                    b.Contents = ContentsFromString(token.ToString());
                }

                b.CheckCount     = 0;
                b.PrimitiveCount = 0;

                // filter brush into tree
                FilterBrushIntoTree(model, model.Node, b);
            }
        }
예제 #2
0
        private void ParsePolygons(idLexer lexer, CollisionModel model)
        {
            idToken token = lexer.CheckTokenType(TokenType.Number, 0);

            float[] tmp;
            Vector3 normal;

            lexer.ExpectTokenString("{");

            while (lexer.CheckTokenString("}") == false)
            {
                // parse polygon
                int edgeCount = lexer.ParseInt();

                CollisionModelPolygon p = new CollisionModelPolygon();
                p.Material = _traceModelMaterial;
                p.Contents = ContentFlags.All;
                p.Edges    = new int[edgeCount];

                lexer.ExpectTokenString("(");

                for (int i = 0; i < edgeCount; i++)
                {
                    p.Edges[i] = lexer.ParseInt();
                }

                lexer.ExpectTokenString(")");

                tmp    = lexer.Parse1DMatrix(3);
                normal = new Vector3(tmp[0], tmp[1], tmp[2]);

                p.Plane.Normal = normal;
                p.Plane.D      = lexer.ParseFloat();

                tmp          = lexer.Parse1DMatrix(3);
                p.Bounds.Min = new Vector3(tmp[0], tmp[1], tmp[2]);

                tmp          = lexer.Parse1DMatrix(3);
                p.Bounds.Max = new Vector3(tmp[0], tmp[1], tmp[2]);

                token = lexer.ExpectTokenType(TokenType.String, 0);

                // get material
                p.Material   = idE.DeclManager.FindMaterial(token.ToString());
                p.Contents   = p.Material.ContentFlags;
                p.CheckCount = 0;

                // filter polygon into tree
                FilterPolygonIntoTree(model, model.Node, p);
            }
        }
예제 #3
0
        private CollisionModelNode ParseNodes(idLexer lexer, CollisionModel model, CollisionModelNode parent)
        {
            model.NodeCount++;

            lexer.ExpectTokenString("(");

            CollisionModelNode node = new CollisionModelNode();

            node.Parent        = parent;
            node.PlaneType     = lexer.ParseInt();
            node.PlaneDistance = lexer.ParseFloat();

            lexer.ExpectTokenString(")");

            if (node.PlaneType != -1)
            {
                node.Children[0] = ParseNodes(lexer, model, node);
                node.Children[1] = ParseNodes(lexer, model, node);
            }

            return(node);
        }
예제 #4
0
        public void Parse(idLexer lexer, idJointMatrix[] joints)
        {
            lexer.ExpectTokenString("{");

            //
            // parse name
            //
            if (lexer.CheckTokenString("name") == true)
            {
                lexer.ReadToken();
            }

            //
            // parse shader
            //
            lexer.ExpectTokenString("shader");

            idToken token        = lexer.ReadToken();
            string  materialName = token.ToString();

            _material = idE.DeclManager.FindMaterial(materialName);

            //
            // parse texture coordinates
            //
            lexer.ExpectTokenString("numverts");
            int count = lexer.ParseInt();

            if (count < 0)
            {
                lexer.Error("Invalid size: {0}", token.ToString());
            }

            _texCoords = new Vector2[count];

            int[] firstWeightForVertex = new int[count];
            int[] weightCountForVertex = new int[count];
            int   maxWeight            = 0;
            int   coordCount           = _texCoords.Length;

            _weightCount = 0;

            for (int i = 0; i < coordCount; i++)
            {
                lexer.ExpectTokenString("vert");
                lexer.ParseInt();

                float[] tmp = lexer.Parse1DMatrix(2);

                _texCoords[i] = new Vector2(tmp[0], tmp[1]);

                firstWeightForVertex[i] = lexer.ParseInt();
                weightCountForVertex[i] = lexer.ParseInt();

                if (weightCountForVertex[i] == 0)
                {
                    lexer.Error("Vertex without any joint weights.");
                }

                _weightCount += weightCountForVertex[i];

                if ((weightCountForVertex[i] + firstWeightForVertex[i]) > maxWeight)
                {
                    maxWeight = weightCountForVertex[i] + firstWeightForVertex[i];
                }
            }

            //
            // parse tris
            //
            lexer.ExpectTokenString("numtris");
            _triangleCount = lexer.ParseInt();

            if (_triangleCount < 0)
            {
                lexer.Error("Invalid size: {0}", _triangleCount);
            }

            int[] tris = new int[_triangleCount * 3];

            for (int i = 0; i < _triangleCount; i++)
            {
                lexer.ExpectTokenString("tri");
                lexer.ParseInt();

                tris[i * 3 + 0] = lexer.ParseInt();
                tris[i * 3 + 1] = lexer.ParseInt();
                tris[i * 3 + 2] = lexer.ParseInt();
            }

            //
            // parse weights
            //
            lexer.ExpectTokenString("numweights");
            count = lexer.ParseInt();

            if (count < 0)
            {
                lexer.Error("Invalid size: {0}", count);
            }

            if (maxWeight > count)
            {
                lexer.Warning("Vertices reference out of range weights in model ({0} of {1} weights).", maxWeight, count);
            }

            VertexWeight[] tempWeights = new VertexWeight[count];

            for (int i = 0; i < count; i++)
            {
                lexer.ExpectTokenString("weight");
                lexer.ParseInt();

                int jointIndex = lexer.ParseInt();

                if ((jointIndex < 0) || (jointIndex >= joints.Length))
                {
                    lexer.Error("Joint index out of range({0}): {1}", joints.Length, jointIndex);
                }

                tempWeights[i].JointIndex  = jointIndex;
                tempWeights[i].JointWeight = lexer.ParseFloat();

                float[] tmp = lexer.Parse1DMatrix(3);

                tempWeights[i].Offset = new Vector3(tmp[0], tmp[1], tmp[2]);
            }

            // create pre-scaled weights and an index for the vertex/joint lookup
            _scaledWeights = new Vector4[_weightCount];
            _weightIndex   = new int[_weightCount * 2];

            count      = 0;
            coordCount = _texCoords.Length;

            for (int i = 0; i < coordCount; i++)
            {
                int num         = firstWeightForVertex[i];
                int weightCount = weightCountForVertex[i];

                for (int j = 0; j < weightCount; j++, num++, count++)
                {
                    Vector3 tmp = tempWeights[num].Offset * tempWeights[num].JointWeight;

                    _scaledWeights[count].X = tmp.X;
                    _scaledWeights[count].Y = tmp.Y;
                    _scaledWeights[count].Z = tmp.Z;
                    _scaledWeights[count].W = tempWeights[num].JointWeight;

                    _weightIndex[count * 2 + 0] = tempWeights[num].JointIndex;
                }

                _weightIndex[count * 2 - 1] = 1;
            }

            lexer.ExpectTokenString("}");

            // update counters
            idConsole.Warning("TODO: idRenderModel_MD5 update counters");

            /*c_numVerts += texCoords.Num();
             * c_numWeights += numWeights;
             * c_numWeightJoints++;
             * for ( i = 0; i < numWeights; i++ ) {
             *      c_numWeightJoints += weightIndex[i*2+1];
             * }*/

            //
            // build the information that will be common to all animations of this mesh:
            // silhouette edge connectivity and normal / tangent generation information
            //
            Vertex[] verts     = new Vertex[_texCoords.Length];
            int      vertCount = verts.Length;

            for (int i = 0; i < vertCount; i++)
            {
                verts[i].TextureCoordinates = _texCoords[i];
            }

            TransformVertices(verts, joints);

            idConsole.Warning("TODO: idMD5Mesh Deform");
            //_deformInfo = idE.RenderSystem.BuildDeformInformation(verts, tris, _material.UseUnsmoothedTangents);
        }
예제 #5
0
		public override bool Parse(string text)
		{
			if(this.Disposed == true)
			{
				throw new ObjectDisposedException("idDeclTable");
			}

			idLexer lexer = new idLexer(idDeclFile.LexerOptions);
			lexer.LoadMemory(text, this.FileName, this.LineNumber);
			lexer.SkipUntilString("{");

			idToken token;
			List<float> values = new List<float>();

			string tokenLower;
			string tokenValue;

			while(true)
			{
				if((token = lexer.ReadToken()) == null)
				{
					break;
				}

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

				if(tokenLower == "}")
				{
					break;
				}
				else if(tokenLower == "snap")
				{
					_snap = true;
				}
				else if(tokenLower == "clamp")
				{
					_clamp = true;
				}
				else if(tokenLower == "{")
				{
					while(true)
					{
						bool errorFlag;
						float v = lexer.ParseFloat(out errorFlag);

						if(errorFlag == true)
						{
							// we got something non-numeric
							MakeDefault();
							return false;
						}

						values.Add(v);

						token = lexer.ReadToken();
						tokenValue = token.ToString();

						if(tokenValue == "}")
						{
							break;
						}
						else if(tokenValue == ",")
						{
							continue;
						}

						lexer.Warning("expected comma or brace");
						MakeDefault();

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

					return false;
				}
			}

			// copy the 0 element to the end, so lerping doesn't
			// need to worry about the wrap case
			float val = values[0];
			values.Add(val);

			_values = values.ToArray();

			return true;
		}
예제 #6
0
        public bool LoadAnimation(string fileName)
        {
            idToken token;
            idLexer lexer = new idLexer(LexerOptions.AllowPathNames | LexerOptions.NoStringEscapeCharacters | LexerOptions.NoStringConcatination);

            if (lexer.LoadFile(fileName) == false)
            {
                return(false);
            }

            Clear();

            _name = fileName;

            lexer.ExpectTokenString(idRenderModel_MD5.VersionString);
            int version = lexer.ParseInt();

            if (version != idRenderModel_MD5.Version)
            {
                lexer.Error("Invalid version {0}.  Should be version {1}", version, idRenderModel_MD5.Version);
            }

            // skip the commandline
            lexer.ExpectTokenString("commandline");
            lexer.ReadToken();

            // parse num frames
            lexer.ExpectTokenString("numFrames");
            int frameCount = lexer.ParseInt();

            if (frameCount <= 0)
            {
                lexer.Error("Invalid number of frames: {0}", frameCount);
            }

            // parse num joints
            lexer.ExpectTokenString("numJoints");
            int jointCount = lexer.ParseInt();

            if (jointCount <= 0)
            {
                lexer.Error("Invalid number of joints: {0}", jointCount);
            }

            // parse frame rate
            lexer.ExpectTokenString("frameRate");
            _frameRate = lexer.ParseInt();

            if (_frameRate < 0)
            {
                lexer.Error("Invalid frame rate: {0}", _frameRate);
            }

            // parse number of animated components
            lexer.ExpectTokenString("numAnimatedComponents");
            _animatedComponentCount = lexer.ParseInt();

            if ((_animatedComponentCount < 0) || (_animatedComponentCount > (jointCount * 6)))
            {
                lexer.Error("Invalid number of animated components: {0}", _animatedComponentCount);
            }

            // parse the hierarchy
            _jointInfo = new JointAnimationInfo[jointCount];

            lexer.ExpectTokenString("hierarchy");
            lexer.ExpectTokenString("{");

            for (int i = 0; i < jointCount; i++)
            {
                token = lexer.ReadToken();

                _jointInfo[i]           = new JointAnimationInfo();
                _jointInfo[i].NameIndex = idR.AnimManager.GetJointIndex(token.ToString());

                // parse parent num
                _jointInfo[i].ParentIndex = lexer.ParseInt();

                if (_jointInfo[i].ParentIndex >= i)
                {
                    lexer.Error("Invalid parent num: {0}", _jointInfo[i].ParentIndex);
                }

                if ((i != 0) && (_jointInfo[i].ParentIndex < 0))
                {
                    lexer.Error("Animations may have only one root joint");
                }

                // parse anim bits
                _jointInfo[i].AnimationBits = (AnimationBits)lexer.ParseInt();

                if (((int)_jointInfo[i].AnimationBits & ~63) != 0)
                {
                    lexer.Error("Invalid anim bits: {0}", _jointInfo[i].AnimationBits);
                }

                // parse first component
                _jointInfo[i].FirstComponent = lexer.ParseInt();

                if ((_animatedComponentCount > 0) && ((_jointInfo[i].FirstComponent < 0) || (_jointInfo[i].FirstComponent >= _animatedComponentCount)))
                {
                    lexer.Error("Invalid first component: {0}", _jointInfo[i].FirstComponent);
                }
            }

            lexer.ExpectTokenString("}");

            // parse bounds
            lexer.ExpectTokenString("bounds");
            lexer.ExpectTokenString("{");

            _bounds = new idBounds[frameCount];

            for (int i = 0; i < frameCount; i++)
            {
                float[] tmp  = lexer.Parse1DMatrix(3);
                float[] tmp2 = lexer.Parse1DMatrix(3);

                _bounds[i] = new idBounds(
                    new Vector3(tmp[0], tmp[1], tmp[2]),
                    new Vector3(tmp2[0], tmp2[1], tmp2[2])
                    );
            }

            lexer.ExpectTokenString("}");

            // parse base frame
            _baseFrame = new idJointQuaternion[jointCount];

            lexer.ExpectTokenString("baseframe");
            lexer.ExpectTokenString("{");

            for (int i = 0; i < jointCount; i++)
            {
                float[] tmp  = lexer.Parse1DMatrix(3);
                float[] tmp2 = lexer.Parse1DMatrix(3);

                idCompressedQuaternion q = new idCompressedQuaternion(tmp2[0], tmp2[1], tmp2[2]);


                _baseFrame[i]             = new idJointQuaternion();
                _baseFrame[i].Translation = new Vector3(tmp[0], tmp[1], tmp[2]);
                _baseFrame[i].Quaternion  = q.ToQuaternion();
            }

            lexer.ExpectTokenString("}");

            // parse frames
            _componentFrames = new float[_animatedComponentCount * frameCount];
            int frameOffset = 0;

            for (int i = 0; i < frameCount; i++)
            {
                lexer.ExpectTokenString("frame");
                int count = lexer.ParseInt();

                if (count != i)
                {
                    lexer.Error("Expected frame number {0}", i);
                }

                lexer.ExpectTokenString("{");

                for (int j = 0; j < _animatedComponentCount; j++, frameOffset++)
                {
                    _componentFrames[frameOffset] = lexer.ParseFloat();
                }

                lexer.ExpectTokenString("}");
            }

            // get total move delta
            if (_animatedComponentCount == 0)
            {
                _totalDelta = Vector3.Zero;
            }
            else
            {
                int componentOffset = _jointInfo[0].FirstComponent;

                if ((_jointInfo[0].AnimationBits & AnimationBits.TranslationX) == AnimationBits.TranslationX)
                {
                    for (int i = 0; i < frameCount; i++)
                    {
                        _componentFrames[componentOffset + (_animatedComponentCount * i)] -= _baseFrame[0].Translation.X;
                    }

                    _totalDelta.X = _componentFrames[componentOffset + (_animatedComponentCount * (frameCount - 1))];
                    componentOffset++;
                }
                else
                {
                    _totalDelta.X = 0;
                }

                if ((_jointInfo[0].AnimationBits & AnimationBits.TranslationY) == AnimationBits.TranslationY)
                {
                    for (int i = 0; i < frameCount; i++)
                    {
                        _componentFrames[componentOffset + (_animatedComponentCount * i)] -= _baseFrame[0].Translation.Y;
                    }

                    _totalDelta.Y = _componentFrames[componentOffset + (_animatedComponentCount * (frameCount - 1))];
                    componentOffset++;
                }
                else
                {
                    _totalDelta.Y = 0;
                }

                if ((_jointInfo[0].AnimationBits & AnimationBits.TranslationZ) == AnimationBits.TranslationZ)
                {
                    for (int i = 0; i < frameCount; i++)
                    {
                        _componentFrames[componentOffset + (_animatedComponentCount * i)] -= _baseFrame[0].Translation.Z;
                    }

                    _totalDelta.Z = _componentFrames[componentOffset + (_animatedComponentCount * (frameCount - 1))];
                }
                else
                {
                    _totalDelta.Z = 0;
                }
            }

            _baseFrame[0].Translation = Vector3.Zero;

            // we don't count last frame because it would cause a 1 frame pause at the end
            _animLength = ((frameCount - 1) * 1000 + _frameRate - 1) / _frameRate;

            // done
            return(true);
        }
예제 #7
0
        public override bool Parse(string text)
        {
            if (this.Disposed == true)
            {
                throw new ObjectDisposedException("idDeclTable");
            }

            idLexer lexer = new idLexer(idDeclFile.LexerOptions);

            lexer.LoadMemory(text, this.FileName, this.LineNumber);
            lexer.SkipUntilString("{");

            idToken      token;
            List <float> values = new List <float>();

            string tokenLower;
            string tokenValue;

            while (true)
            {
                if ((token = lexer.ReadToken()) == null)
                {
                    break;
                }

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

                if (tokenLower == "}")
                {
                    break;
                }
                else if (tokenLower == "snap")
                {
                    _snap = true;
                }
                else if (tokenLower == "clamp")
                {
                    _clamp = true;
                }
                else if (tokenLower == "{")
                {
                    while (true)
                    {
                        bool  errorFlag;
                        float v = lexer.ParseFloat(out errorFlag);

                        if (errorFlag == true)
                        {
                            // we got something non-numeric
                            MakeDefault();
                            return(false);
                        }

                        values.Add(v);

                        token      = lexer.ReadToken();
                        tokenValue = token.ToString();

                        if (tokenValue == "}")
                        {
                            break;
                        }
                        else if (tokenValue == ",")
                        {
                            continue;
                        }

                        lexer.Warning("expected comma or brace");
                        MakeDefault();

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

                    return(false);
                }
            }

            // copy the 0 element to the end, so lerping doesn't
            // need to worry about the wrap case
            float val = values[0];

            values.Add(val);

            _values = values.ToArray();

            return(true);
        }
예제 #8
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);
        }
예제 #9
0
		private void ParseSingleAction(idLexer lexer /*idFXSingleAction& FXAction*/) 
		{
			idToken token;
			string tokenValue;
			
			/*FXAction.type = -1;
			FXAction.sibling = -1;

			FXAction.data = "<none>";
			FXAction.name = "<none>";
			FXAction.fire = "<none>";

			FXAction.delay = 0.0f;
			FXAction.duration = 0.0f;
			FXAction.restart = 0.0f;
			FXAction.size = 0.0f;
			FXAction.fadeInTime = 0.0f;
			FXAction.fadeOutTime = 0.0f;
			FXAction.shakeTime = 0.0f;
			FXAction.shakeAmplitude = 0.0f;
			FXAction.shakeDistance = 0.0f;
			FXAction.shakeFalloff = false;
			FXAction.shakeImpulse = 0.0f;
			FXAction.shakeIgnoreMaster = false;
			FXAction.lightRadius = 0.0f;
			FXAction.rotate = 0.0f;
			FXAction.random1 = 0.0f;
			FXAction.random2 = 0.0f;

			FXAction.lightColor = vec3_origin;
			FXAction.offset = vec3_origin;
			FXAction.axis = mat3_identity;

			FXAction.bindParticles = false;
			FXAction.explicitAxis = false;
			FXAction.noshadows = false;
			FXAction.particleTrackVelocity = false;
			FXAction.trackOrigin = false;
			FXAction.soundStarted = false;*/

			while(true)
			{
				if((token = lexer.ReadToken()) == null)
				{
					break;
				}

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

				if(tokenValue == "}")
				{
					break;
				}
				else if(tokenValue == "shake")
				{
					/*FXAction.type = FX_SHAKE;*/
					/*FXAction.shakeTime = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*FXAction.shakeAmplitude = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*FXAction.shakeDistance = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*FXAction.shakeFalloff = */lexer.ParseBool();
					lexer.ExpectTokenString(",");
					/*FXAction.shakeImpulse = */lexer.ParseFloat();
				}
				else if(tokenValue == "noshadows")
				{
					// TODO: FXAction.noshadows = true;
				}
				else if(tokenValue == "name")
				{
					token = lexer.ReadToken();
					// TODO: FXAction.name = token;
				}
				else if(tokenValue == "fire")
				{
					token = lexer.ReadToken();
					// TODO: FXAction.fire = token;
				}
				else if(tokenValue == "random")
				{
					/*FXAction.random1 = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*FXAction.random2 = */lexer.ParseFloat();
					// FXAction.delay = 0.0f;		// check random
				}
				else if(tokenValue == "delay")
				{
					/*FXAction.delay = */lexer.ParseFloat();
				}
				else if(tokenValue == "rotate")
				{
					/*FXAction.rotate = */lexer.ParseFloat();
				}
				else if(tokenValue == "duration")
				{
					/*FXAction.duration = */lexer.ParseFloat();
				}
				else if(tokenValue == "trackorigin")
				{
					/*FXAction.trackOrigin = */lexer.ParseBool();
				}
				else if(tokenValue == "restart")
				{
					/*FXAction.restart = */lexer.ParseFloat();
				}
				else if(tokenValue == "fadein")
				{
					/*FXAction.fadeInTime = */lexer.ParseFloat();
				}
				else if(tokenValue == "fadeout")
				{
					/*FXAction.fadeOutTime = */lexer.ParseFloat();
				}
				else if(tokenValue == "size")
				{
					/*FXAction.size = */lexer.ParseFloat();
				}
				else if(tokenValue == "offset")
				{
					/*FXAction.offset.x = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*FXAction.offset.y = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*FXAction.offset.z = */lexer.ParseFloat();
				}
				else if(tokenValue == "axis")
				{
					/*idVec3 v;*/
					/*v.x = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*v.y = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*v.z = */lexer.ParseFloat();
					/*v.Normalize();
					FXAction.axis = v.ToMat3();
					FXAction.explicitAxis = true;*/
				}
				else if(tokenValue == "angle")
				{
					/*idAngles a;*/
					/*a[0] = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*a[1] = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*a[2] = */lexer.ParseFloat();
					/*FXAction.axis = a.ToMat3();
					FXAction.explicitAxis = true;*/
				}
				else if(tokenValue == "uselight")
				{
					token = lexer.ReadToken();
			
					/*FXAction.data = token;
					for( int i = 0; i < events.Num(); i++ ) {
						if ( events[i].name.Icmp( FXAction.data ) == 0 ) {
							FXAction.sibling = i;
							FXAction.lightColor = events[i].lightColor;
							FXAction.lightRadius = events[i].lightRadius;
						}
					}
					FXAction.type = FX_LIGHT;

					// precache the light material
					declManager->FindMaterial( FXAction.data );*/	
				}
				else if(tokenValue == "attachlight")
				{
					token = lexer.ReadToken();

					/*FXAction.data = token;
					FXAction.type = FX_ATTACHLIGHT;

					// precache it
					declManager->FindMaterial( FXAction.data );*/
				}
				else if(tokenValue == "attachentity")
				{
					token = lexer.ReadToken();

					/*FXAction.data = token;
					FXAction.type = FX_ATTACHENTITY;

					// precache the model
					renderModelManager->FindModel( FXAction.data );*/
				}
				else if(tokenValue == "launch")
				{
					token = lexer.ReadToken();

					/*FXAction.data = token;
					FXAction.type = FX_LAUNCH;

					// precache the entity def
					declManager->FindType( DECL_ENTITYDEF, FXAction.data );*/
				}
				else if(tokenValue == "usemodel")
				{
					token = lexer.ReadToken();

					/*FXAction.data = token;
					for( int i = 0; i < events.Num(); i++ ) {
						if ( events[i].name.Icmp( FXAction.data ) == 0 ) {
							FXAction.sibling = i;
						}
					}
					FXAction.type = FX_MODEL;

					// precache the model
					renderModelManager->FindModel( FXAction.data );*/
				}
				else if(tokenValue == "light")
				{
					token = lexer.ReadToken();
					
					/*FXAction.data = token;*/
					lexer.ExpectTokenString(",");
					/*FXAction.lightColor[0] = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*FXAction.lightColor[1] = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*FXAction.lightColor[2] = */lexer.ParseFloat();
					lexer.ExpectTokenString(",");
					/*FXAction.lightRadius = */lexer.ParseFloat();
					/*FXAction.type = FX_LIGHT;

					// precache the light material
					declManager->FindMaterial( FXAction.data );*/
				}
				else if(tokenValue == "model")
				{
					token = lexer.ReadToken();

					/*FXAction.data = token;
					FXAction.type = FX_MODEL;

					// precache it
					renderModelManager->FindModel( FXAction.data );*/
				}
				else if(tokenValue == "particle") // FIXME: now the same as model
				{
					token = lexer.ReadToken();

					/*FXAction.data = token;
					FXAction.type = FX_PARTICLE;

					// precache it
					renderModelManager->FindModel( FXAction.data );*/
				}
				else if(tokenValue == "decal")
				{
					token = lexer.ReadToken();

					/*FXAction.data = token;
					FXAction.type = FX_DECAL;

					// precache it
					declManager->FindMaterial( FXAction.data );*/
				}
				else if(tokenValue == "particletrackvelocity")
				{
					// TODO: FXAction.particleTrackVelocity = true;
				}
				else if(tokenValue == "sound")
				{
					token = lexer.ReadToken();

					/*FXAction.data = token;
					FXAction.type = FX_SOUND;

					// precache it
					declManager->FindSound( FXAction.data );*/
				}
				else if(tokenValue == "ignoremaster")
				{
					/*FXAction.shakeIgnoreMaster = true;*/
				}
				else if(tokenValue == "shockwave")
				{
					token = lexer.ReadToken();

					/*FXAction.data = token;
					FXAction.type = FX_SHOCKWAVE;

					// precache the entity def
					declManager->FindType( DECL_ENTITYDEF, FXAction.data );*/
				}
				else
				{
					lexer.Warning("FX File: bad token");
				}
			}
		}
예제 #10
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);
        }
예제 #11
0
        private idParticleStage ParseParticleStage(idLexer lexer)
        {
            idToken token;
            string  tokenLower;

            idParticleStage stage = new idParticleStage();

            stage.Default();

            while (true)
            {
                if (lexer.HadError == true)
                {
                    break;
                }
                else if ((token = lexer.ReadToken()) == null)
                {
                    break;
                }
                else
                {
                    tokenLower = token.ToString().ToLower();

                    if (tokenLower == "}")
                    {
                        break;
                    }
                    else if (tokenLower == "material")
                    {
                        token          = lexer.ReadToken();
                        stage.Material = idE.DeclManager.FindMaterial(token.ToString());
                    }
                    else if (tokenLower == "count")
                    {
                        stage.TotalParticles = lexer.ParseInt();
                    }
                    else if (tokenLower == "time")
                    {
                        stage.ParticleLife = lexer.ParseFloat();
                    }
                    else if (tokenLower == "cycles")
                    {
                        stage.Cycles = lexer.ParseFloat();
                    }
                    else if (tokenLower == "timeoffset")
                    {
                        stage.TimeOffset = lexer.ParseFloat();
                    }
                    else if (tokenLower == "deadtime")
                    {
                        stage.DeadTime = lexer.ParseFloat();
                    }
                    else if (tokenLower == "randomdistribution")
                    {
                        stage.RandomDistribution = lexer.ParseBool();
                    }
                    else if (tokenLower == "bunching")
                    {
                        stage.SpawnBunching = lexer.ParseFloat();
                    }
                    else if (tokenLower == "distribution")
                    {
                        token      = lexer.ReadToken();
                        tokenLower = token.ToString().ToLower();

                        if (tokenLower == "rect")
                        {
                            stage.Distribution = ParticleDistribution.Rectangle;
                        }
                        else if (tokenLower == "cyclinder")
                        {
                            stage.Distribution = ParticleDistribution.Cyclinder;
                        }
                        else if (tokenLower == "sphere")
                        {
                            stage.Distribution = ParticleDistribution.Sphere;
                        }
                        else
                        {
                            lexer.Error("bad distribution type: {0}", token.ToString());
                        }

                        stage.DistributionParameters = ParseParams(lexer, stage.DistributionParameters.Length);
                    }
                    else if (tokenLower == "direction")
                    {
                        token      = lexer.ReadToken();
                        tokenLower = token.ToString().ToLower();

                        if (tokenLower == "cone")
                        {
                            stage.Direction = ParticleDirection.Cone;
                        }
                        else if (tokenLower == "outward")
                        {
                            stage.Direction = ParticleDirection.Outward;
                        }
                        else
                        {
                            lexer.Error("bad direction type: {0}", token.ToString());
                        }

                        stage.DirectionParameters = ParseParams(lexer, stage.DirectionParameters.Length);
                    }
                    else if (tokenLower == "orientation")
                    {
                        token      = lexer.ReadToken();
                        tokenLower = token.ToString().ToLower();

                        if (tokenLower == "view")
                        {
                            stage.Orientation = ParticleOrientation.View;
                        }
                        else if (tokenLower == "aimed")
                        {
                            stage.Orientation = ParticleOrientation.Aimed;
                        }
                        else if (tokenLower == "x")
                        {
                            stage.Orientation = ParticleOrientation.X;
                        }
                        else if (tokenLower == "y")
                        {
                            stage.Orientation = ParticleOrientation.Y;
                        }
                        else if (tokenLower == "z")
                        {
                            stage.Orientation = ParticleOrientation.Z;
                        }
                        else
                        {
                            lexer.Error("bad orientation type: {0}", token.ToString());
                        }

                        stage.OrientationParameters = ParseParams(lexer, stage.OrientationParameters.Length);
                    }
                    else if (tokenLower == "custompath")
                    {
                        token      = lexer.ReadToken();
                        tokenLower = tokenLower.ToLower().ToLower();

                        if (tokenLower == "standard")
                        {
                            stage.CustomPath = ParticleCustomPath.Standard;
                        }
                        else if (tokenLower == "helix")
                        {
                            stage.CustomPath = ParticleCustomPath.Helix;
                        }
                        else if (tokenLower == "flies")
                        {
                            stage.CustomPath = ParticleCustomPath.Flies;
                        }
                        else if (tokenLower == "spherical")
                        {
                            stage.CustomPath = ParticleCustomPath.Orbit;
                        }
                        else
                        {
                            lexer.Error("bad path type: {0}", token.ToString());
                        }

                        stage.CustomPathParameters = ParseParams(lexer, stage.CustomPathParameters.Length);
                    }
                    else if (tokenLower == "speed")
                    {
                        ParseParametric(lexer, stage.Speed);
                    }
                    else if (tokenLower == "rotation")
                    {
                        ParseParametric(lexer, stage.RotationSpeed);
                    }
                    else if (tokenLower == "angle")
                    {
                        stage.InitialAngle = lexer.ParseFloat();
                    }
                    else if (tokenLower == "entitycolor")
                    {
                        stage.EntityColor = lexer.ParseBool();
                    }
                    else if (tokenLower == "size")
                    {
                        ParseParametric(lexer, stage.Size);
                    }
                    else if (tokenLower == "aspect")
                    {
                        ParseParametric(lexer, stage.Aspect);
                    }
                    else if (tokenLower == "fadein")
                    {
                        stage.FadeInFraction = lexer.ParseFloat();
                    }
                    else if (tokenLower == "fadeout")
                    {
                        stage.FadeOutFraction = lexer.ParseFloat();
                    }
                    else if (tokenLower == "fadeindex")
                    {
                        stage.FadeIndexFraction = lexer.ParseFloat();
                    }
                    else if (tokenLower == "color")
                    {
                        stage.Color = new Vector4(lexer.ParseFloat(), lexer.ParseFloat(), lexer.ParseFloat(), lexer.ParseFloat());
                    }
                    else if (tokenLower == "fadecolor")
                    {
                        stage.FadeColor = new Vector4(lexer.ParseFloat(), lexer.ParseFloat(), lexer.ParseFloat(), lexer.ParseFloat());
                    }
                    else if (tokenLower == "offset")
                    {
                        stage.Offset = new Vector3(lexer.ParseFloat(), lexer.ParseFloat(), lexer.ParseFloat());
                    }
                    else if (tokenLower == "animationframes")
                    {
                        stage.AnimationFrames = lexer.ParseInt();
                    }
                    else if (tokenLower == "animationrate")
                    {
                        stage.AnimationRate = lexer.ParseFloat();
                    }
                    else if (tokenLower == "boundsexpansion")
                    {
                        stage.BoundsExpansion = lexer.ParseFloat();
                    }
                    else if (tokenLower == "gravity")
                    {
                        token      = lexer.ReadToken();
                        tokenLower = token.ToString().ToLower();

                        if (tokenLower == "world")
                        {
                            stage.WorldGravity = true;
                        }
                        else
                        {
                            lexer.UnreadToken = token;
                        }

                        stage.Gravity = lexer.ParseFloat();
                    }
                    else
                    {
                        lexer.Error("unknown token {0}", token.ToString());
                    }
                }
            }

            // derive values.
            stage.CycleTime = (int)(stage.ParticleLife + stage.DeadTime) * 1000;

            return(stage);
        }
예제 #12
0
        public override bool Parse(string text)
        {
            if (this.Disposed == true)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            idToken token;
            string  tokenLower;

            idLexer lexer = new idLexer(idDeclFile.LexerOptions);

            lexer.LoadMemory(text, this.FileName, this.LineNumber);
            lexer.SkipUntilString("{");

            List <idParticleStage> stages = new List <idParticleStage>();

            _depthHack = 0.0f;

            while (true)
            {
                if ((token = lexer.ReadToken()) == null)
                {
                    break;
                }

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

                if (tokenLower == "}")
                {
                    break;
                }
                else if (tokenLower == "{")
                {
                    idParticleStage stage = ParseParticleStage(lexer);

                    if (stage == null)
                    {
                        lexer.Warning("Particle stage parse failed");
                        MakeDefault();

                        return(false);
                    }

                    stages.Add(stage);
                }
                else if (tokenLower == "depthhack")
                {
                    _depthHack = lexer.ParseFloat();
                }
                else
                {
                    lexer.Warning("bad token {0}", token.ToString());
                    MakeDefault();

                    return(false);
                }
            }

            _stages = stages.ToArray();

            //
            // calculate the bounds
            //
            _bounds.Clear();

            int count = _stages.Length;

            for (int i = 0; i < count; i++)
            {
                idConsole.Warning("TODO: GetStageBounds");
                // TODO: GetStageBounds(stages[i]);
                _bounds += _stages[i].Bounds;
            }

            if (_bounds.Volume <= 0.1f)
            {
                _bounds = idBounds.Expand(idBounds.Zero, 8.0f);
            }

            return(true);
        }
예제 #13
0
		private idParticleStage ParseParticleStage(idLexer lexer)
		{
			idToken token;
			string tokenLower;
			
			idParticleStage stage = new idParticleStage();
			stage.Default();

			while(true)
			{
				if(lexer.HadError == true)
				{
					break;
				}
				else if((token = lexer.ReadToken()) == null)
				{
					break;
				}
				else
				{
					tokenLower = token.ToString().ToLower();

					if(tokenLower == "}")
					{
						break;
					}
					else if(tokenLower == "material")
					{
						token = lexer.ReadToken();
						stage.Material = idE.DeclManager.FindMaterial(token.ToString());
					}
					else if(tokenLower == "count")
					{
						stage.TotalParticles = lexer.ParseInt();
					}
					else if(tokenLower == "time")
					{
						stage.ParticleLife = lexer.ParseFloat();
					}
					else if(tokenLower == "cycles")
					{
						stage.Cycles = lexer.ParseFloat();
					}
					else if(tokenLower == "timeoffset")
					{
						stage.TimeOffset = lexer.ParseFloat();
					}
					else if(tokenLower == "deadtime")
					{
						stage.DeadTime = lexer.ParseFloat();
					}
					else if(tokenLower == "randomdistribution")
					{
						stage.RandomDistribution = lexer.ParseBool();
					}
					else if(tokenLower == "bunching")
					{
						stage.SpawnBunching = lexer.ParseFloat();
					}
					else if(tokenLower == "distribution")
					{
						token = lexer.ReadToken();
						tokenLower = token.ToString().ToLower();

						if(tokenLower == "rect")
						{
							stage.Distribution = ParticleDistribution.Rectangle;
						}
						else if(tokenLower == "cyclinder")
						{
							stage.Distribution = ParticleDistribution.Cyclinder;
						}
						else if(tokenLower == "sphere")
						{
							stage.Distribution = ParticleDistribution.Sphere;
						}
						else
						{
							lexer.Error("bad distribution type: {0}", token.ToString());
						}

						stage.DistributionParameters = ParseParams(lexer, stage.DistributionParameters.Length);
					}
					else if(tokenLower == "direction")
					{
						token = lexer.ReadToken();
						tokenLower = token.ToString().ToLower();

						if(tokenLower == "cone")
						{
							stage.Direction = ParticleDirection.Cone;
						}
						else if(tokenLower == "outward")
						{
							stage.Direction = ParticleDirection.Outward;
						}
						else
						{
							lexer.Error("bad direction type: {0}", token.ToString());
						}

						stage.DirectionParameters = ParseParams(lexer, stage.DirectionParameters.Length);
					}
					else if(tokenLower == "orientation")
					{
						token = lexer.ReadToken();
						tokenLower = token.ToString().ToLower();

						if(tokenLower == "view")
						{
							stage.Orientation = ParticleOrientation.View;
						}
						else if(tokenLower == "aimed")
						{
							stage.Orientation = ParticleOrientation.Aimed;
						}
						else if(tokenLower == "x")
						{
							stage.Orientation = ParticleOrientation.X;
						}
						else if(tokenLower == "y")
						{
							stage.Orientation = ParticleOrientation.Y;
						}
						else if(tokenLower == "z")
						{
							stage.Orientation = ParticleOrientation.Z;
						}
						else 
						{
							lexer.Error("bad orientation type: {0}", token.ToString());
						}

						stage.OrientationParameters = ParseParams(lexer, stage.OrientationParameters.Length);
					}
					else if(tokenLower == "custompath")
					{
						token = lexer.ReadToken();
						tokenLower = tokenLower.ToLower().ToLower();

						if(tokenLower == "standard")
						{
							stage.CustomPath = ParticleCustomPath.Standard;
						}
						else if(tokenLower == "helix")
						{
							stage.CustomPath = ParticleCustomPath.Helix;
						}
						else if(tokenLower == "flies")
						{
							stage.CustomPath = ParticleCustomPath.Flies;
						}
						else if(tokenLower == "spherical")
						{
							stage.CustomPath = ParticleCustomPath.Orbit;
						}
						else
						{
							lexer.Error("bad path type: {0}", token.ToString());
						}

						stage.CustomPathParameters = ParseParams(lexer, stage.CustomPathParameters.Length);
					}
					else if(tokenLower == "speed")
					{					
						ParseParametric(lexer, stage.Speed);
					}
					else if(tokenLower == "rotation")
					{
						ParseParametric(lexer, stage.RotationSpeed);
					}
					else if(tokenLower == "angle")
					{
						stage.InitialAngle = lexer.ParseFloat();
					}
					else if(tokenLower == "entitycolor")
					{
						stage.EntityColor = lexer.ParseBool();
					}
					else if(tokenLower == "size")
					{
						ParseParametric(lexer, stage.Size);
					}
					else if(tokenLower == "aspect")
					{
						ParseParametric(lexer, stage.Aspect);
					}
					else if(tokenLower == "fadein")
					{
						stage.FadeInFraction = lexer.ParseFloat();
					}
					else if(tokenLower == "fadeout")
					{
						stage.FadeOutFraction = lexer.ParseFloat();
					}
					else if(tokenLower == "fadeindex")
					{
						stage.FadeIndexFraction = lexer.ParseFloat();
					}
					else if(tokenLower == "color")
					{
						stage.Color = new Vector4(lexer.ParseFloat(), lexer.ParseFloat(), lexer.ParseFloat(), lexer.ParseFloat());
					}
					else if(tokenLower == "fadecolor")
					{
						stage.FadeColor = new Vector4(lexer.ParseFloat(), lexer.ParseFloat(), lexer.ParseFloat(), lexer.ParseFloat());
					}
					else if(tokenLower == "offset")
					{
						stage.Offset = new Vector3(lexer.ParseFloat(), lexer.ParseFloat(), lexer.ParseFloat());
					}
					else if(tokenLower == "animationframes")
					{
						stage.AnimationFrames = lexer.ParseInt();
					}
					else if(tokenLower == "animationrate")
					{
						stage.AnimationRate = lexer.ParseFloat();
					}
					else if(tokenLower == "boundsexpansion")
					{
						stage.BoundsExpansion = lexer.ParseFloat();
					}
					else if(tokenLower == "gravity")
					{
						token = lexer.ReadToken();
						tokenLower = token.ToString().ToLower();

						if(tokenLower == "world")
						{
							stage.WorldGravity = true;
						}
						else
						{
							lexer.UnreadToken = token;
						}

						stage.Gravity = lexer.ParseFloat();
					}
					else
					{
						lexer.Error("unknown token {0}", token.ToString());
					}
				}
			}

			// derive values.
			stage.CycleTime = (int) (stage.ParticleLife + stage.DeadTime) * 1000;

			return stage;
		}
예제 #14
0
		public override bool Parse(string text)
		{
			if(this.Disposed == true)
			{
				throw new ObjectDisposedException(this.GetType().Name);
			}

			idToken token;
			string tokenLower;

			idLexer lexer = new idLexer(idDeclFile.LexerOptions);
			lexer.LoadMemory(text, this.FileName, this.LineNumber);
			lexer.SkipUntilString("{");

			List<idParticleStage> stages = new List<idParticleStage>();

			_depthHack = 0.0f;

			while(true)
			{
				if((token = lexer.ReadToken()) == null)
				{
					break;
				}

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

				if(tokenLower == "}")
				{
					break;
				}
				else if(tokenLower == "{")
				{
					idParticleStage stage = ParseParticleStage(lexer);

					if(stage == null)
					{
						lexer.Warning("Particle stage parse failed");
						MakeDefault();

						return false;
					}

					stages.Add(stage);
				}
				else if(tokenLower == "depthhack")
				{
					_depthHack = lexer.ParseFloat();
				}
				else
				{
					lexer.Warning("bad token {0}", token.ToString());
					MakeDefault();

					return false;
				}
			}

			_stages = stages.ToArray();

			//
			// calculate the bounds
			//
			_bounds.Clear();

			int count = _stages.Length;

			for(int i = 0; i < count; i++)
			{
				idConsole.Warning("TODO: GetStageBounds");
				// TODO: GetStageBounds(stages[i]);
				_bounds += _stages[i].Bounds;
			}

			if(_bounds.Volume <= 0.1f)
			{
				_bounds = idBounds.Expand(idBounds.Zero, 8.0f);
			}

			return true;
		}
예제 #15
0
        private void ParseSingleAction(idLexer lexer /*idFXSingleAction& FXAction*/)
        {
            idToken token;
            string  tokenValue;

            /*FXAction.type = -1;
             * FXAction.sibling = -1;
             *
             * FXAction.data = "<none>";
             * FXAction.name = "<none>";
             * FXAction.fire = "<none>";
             *
             * FXAction.delay = 0.0f;
             * FXAction.duration = 0.0f;
             * FXAction.restart = 0.0f;
             * FXAction.size = 0.0f;
             * FXAction.fadeInTime = 0.0f;
             * FXAction.fadeOutTime = 0.0f;
             * FXAction.shakeTime = 0.0f;
             * FXAction.shakeAmplitude = 0.0f;
             * FXAction.shakeDistance = 0.0f;
             * FXAction.shakeFalloff = false;
             * FXAction.shakeImpulse = 0.0f;
             * FXAction.shakeIgnoreMaster = false;
             * FXAction.lightRadius = 0.0f;
             * FXAction.rotate = 0.0f;
             * FXAction.random1 = 0.0f;
             * FXAction.random2 = 0.0f;
             *
             * FXAction.lightColor = vec3_origin;
             * FXAction.offset = vec3_origin;
             * FXAction.axis = mat3_identity;
             *
             * FXAction.bindParticles = false;
             * FXAction.explicitAxis = false;
             * FXAction.noshadows = false;
             * FXAction.particleTrackVelocity = false;
             * FXAction.trackOrigin = false;
             * FXAction.soundStarted = false;*/

            while (true)
            {
                if ((token = lexer.ReadToken()) == null)
                {
                    break;
                }

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

                if (tokenValue == "}")
                {
                    break;
                }
                else if (tokenValue == "shake")
                {
                    /*FXAction.type = FX_SHAKE;*/
                    /*FXAction.shakeTime = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*FXAction.shakeAmplitude = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*FXAction.shakeDistance = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*FXAction.shakeFalloff = */ lexer.ParseBool();
                    lexer.ExpectTokenString(",");
                    /*FXAction.shakeImpulse = */ lexer.ParseFloat();
                }
                else if (tokenValue == "noshadows")
                {
                    // TODO: FXAction.noshadows = true;
                }
                else if (tokenValue == "name")
                {
                    token = lexer.ReadToken();
                    // TODO: FXAction.name = token;
                }
                else if (tokenValue == "fire")
                {
                    token = lexer.ReadToken();
                    // TODO: FXAction.fire = token;
                }
                else if (tokenValue == "random")
                {
                    /*FXAction.random1 = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*FXAction.random2 = */ lexer.ParseFloat();
                    // FXAction.delay = 0.0f;		// check random
                }
                else if (tokenValue == "delay")
                {
                    /*FXAction.delay = */ lexer.ParseFloat();
                }
                else if (tokenValue == "rotate")
                {
                    /*FXAction.rotate = */ lexer.ParseFloat();
                }
                else if (tokenValue == "duration")
                {
                    /*FXAction.duration = */ lexer.ParseFloat();
                }
                else if (tokenValue == "trackorigin")
                {
                    /*FXAction.trackOrigin = */ lexer.ParseBool();
                }
                else if (tokenValue == "restart")
                {
                    /*FXAction.restart = */ lexer.ParseFloat();
                }
                else if (tokenValue == "fadein")
                {
                    /*FXAction.fadeInTime = */ lexer.ParseFloat();
                }
                else if (tokenValue == "fadeout")
                {
                    /*FXAction.fadeOutTime = */ lexer.ParseFloat();
                }
                else if (tokenValue == "size")
                {
                    /*FXAction.size = */ lexer.ParseFloat();
                }
                else if (tokenValue == "offset")
                {
                    /*FXAction.offset.x = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*FXAction.offset.y = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*FXAction.offset.z = */ lexer.ParseFloat();
                }
                else if (tokenValue == "axis")
                {
                    /*idVec3 v;*/
                    /*v.x = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*v.y = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*v.z = */ lexer.ParseFloat();

                    /*v.Normalize();
                     * FXAction.axis = v.ToMat3();
                     * FXAction.explicitAxis = true;*/
                }
                else if (tokenValue == "angle")
                {
                    /*idAngles a;*/
                    /*a[0] = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*a[1] = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*a[2] = */ lexer.ParseFloat();

                    /*FXAction.axis = a.ToMat3();
                     * FXAction.explicitAxis = true;*/
                }
                else if (tokenValue == "uselight")
                {
                    token = lexer.ReadToken();

                    /*FXAction.data = token;
                     * for( int i = 0; i < events.Num(); i++ ) {
                     *      if ( events[i].name.Icmp( FXAction.data ) == 0 ) {
                     *              FXAction.sibling = i;
                     *              FXAction.lightColor = events[i].lightColor;
                     *              FXAction.lightRadius = events[i].lightRadius;
                     *      }
                     * }
                     * FXAction.type = FX_LIGHT;
                     *
                     * // precache the light material
                     * declManager->FindMaterial( FXAction.data );*/
                }
                else if (tokenValue == "attachlight")
                {
                    token = lexer.ReadToken();

                    /*FXAction.data = token;
                     * FXAction.type = FX_ATTACHLIGHT;
                     *
                     * // precache it
                     * declManager->FindMaterial( FXAction.data );*/
                }
                else if (tokenValue == "attachentity")
                {
                    token = lexer.ReadToken();

                    /*FXAction.data = token;
                     * FXAction.type = FX_ATTACHENTITY;
                     *
                     * // precache the model
                     * renderModelManager->FindModel( FXAction.data );*/
                }
                else if (tokenValue == "launch")
                {
                    token = lexer.ReadToken();

                    /*FXAction.data = token;
                     * FXAction.type = FX_LAUNCH;
                     *
                     * // precache the entity def
                     * declManager->FindType( DECL_ENTITYDEF, FXAction.data );*/
                }
                else if (tokenValue == "usemodel")
                {
                    token = lexer.ReadToken();

                    /*FXAction.data = token;
                     * for( int i = 0; i < events.Num(); i++ ) {
                     *      if ( events[i].name.Icmp( FXAction.data ) == 0 ) {
                     *              FXAction.sibling = i;
                     *      }
                     * }
                     * FXAction.type = FX_MODEL;
                     *
                     * // precache the model
                     * renderModelManager->FindModel( FXAction.data );*/
                }
                else if (tokenValue == "light")
                {
                    token = lexer.ReadToken();

                    /*FXAction.data = token;*/
                    lexer.ExpectTokenString(",");
                    /*FXAction.lightColor[0] = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*FXAction.lightColor[1] = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*FXAction.lightColor[2] = */ lexer.ParseFloat();
                    lexer.ExpectTokenString(",");
                    /*FXAction.lightRadius = */ lexer.ParseFloat();

                    /*FXAction.type = FX_LIGHT;
                     *
                     * // precache the light material
                     * declManager->FindMaterial( FXAction.data );*/
                }
                else if (tokenValue == "model")
                {
                    token = lexer.ReadToken();

                    /*FXAction.data = token;
                     * FXAction.type = FX_MODEL;
                     *
                     * // precache it
                     * renderModelManager->FindModel( FXAction.data );*/
                }
                else if (tokenValue == "particle")                // FIXME: now the same as model
                {
                    token = lexer.ReadToken();

                    /*FXAction.data = token;
                     * FXAction.type = FX_PARTICLE;
                     *
                     * // precache it
                     * renderModelManager->FindModel( FXAction.data );*/
                }
                else if (tokenValue == "decal")
                {
                    token = lexer.ReadToken();

                    /*FXAction.data = token;
                     * FXAction.type = FX_DECAL;
                     *
                     * // precache it
                     * declManager->FindMaterial( FXAction.data );*/
                }
                else if (tokenValue == "particletrackvelocity")
                {
                    // TODO: FXAction.particleTrackVelocity = true;
                }
                else if (tokenValue == "sound")
                {
                    token = lexer.ReadToken();

                    /*FXAction.data = token;
                     * FXAction.type = FX_SOUND;
                     *
                     * // precache it
                     * declManager->FindSound( FXAction.data );*/
                }
                else if (tokenValue == "ignoremaster")
                {
                    /*FXAction.shakeIgnoreMaster = true;*/
                }
                else if (tokenValue == "shockwave")
                {
                    token = lexer.ReadToken();

                    /*FXAction.data = token;
                     * FXAction.type = FX_SHOCKWAVE;
                     *
                     * // precache the entity def
                     * declManager->FindType( DECL_ENTITYDEF, FXAction.data );*/
                }
                else
                {
                    lexer.Warning("FX File: bad token");
                }
            }
        }