Warning() public method

public Warning ( string format ) : void
format string
return void
Example #1
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="lexer"></param>
		/// <returns>A register index.</returns>
		private int ParseTerm(idLexer lexer)
		{
			idToken token = lexer.ReadToken();

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

			if(tokenValue == "(")
			{
				int a = ParseExpression(lexer);
				MatchToken(lexer, ")");

				return a;
			}

			ExpressionRegister tmpReg;

			if(Enum.TryParse<ExpressionRegister>(tokenValue, true, out tmpReg) == true)
			{
				_parsingData.RegistersAreConstant = false;
				return (int) tmpReg;
			}
			
			if(tokenLower == "fragmentPrograms")
			{
				return GetExpressionConstant(1.0f);
			}
			else if(tokenLower == "sound")
			{
				_parsingData.RegistersAreConstant = false;

				return EmitOp(0, 0, ExpressionOperationType.Sound);
			}
			// parse negative numbers
			else if(tokenLower == "-")
			{
				token = lexer.ReadToken();

				if((token.Type == TokenType.Number) || (token.ToString() == "."))
				{
					return GetExpressionConstant(-token.ToFloat());
				}

				lexer.Warning("Bad negative number '{0}'", token.ToString());
				this.MaterialFlag = MaterialFlags.Defaulted;

				return 0;
			}
			else if((token.Type == TokenType.Number) || (tokenValue == ".") || (tokenValue == "-"))
			{
				return GetExpressionConstant(token.ToFloat());
			}

			// see if it is a table name
			idDeclTable table = idE.DeclManager.FindType<idDeclTable>(DeclType.Table, tokenValue, false);

			if(table == null)
			{
				lexer.Warning("Bad term '{0}'", tokenValue);
				this.MaterialFlag = MaterialFlags.Defaulted;

				return 0;
			}

			// parse a table expression
			MatchToken(lexer, "[");

			int b = ParseExpression(lexer);

			MatchToken(lexer, "]");

			return EmitOp(table.Index, b, ExpressionOperationType.Table);
		}
Example #2
0
		public override bool Parse(string text)
		{
			if(this.Disposed == true)
			{
				throw new ObjectDisposedException(this.GetType().Name);
			}

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

			idToken token;
			idToken token2;
			string value;

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

				value = token.ToString();

				if(value == "}")
				{
					break;
				}

				if(token.Type != TokenType.String)
				{
					lexer.Warning("Expected quoted string, but found '{0}'", value);
					MakeDefault();

					return false;
				}

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

					return false;
				}

				if(_dict.ContainsKey(value) == true)
				{
					lexer.Warning("'{0}' already defined", value);
				}

				_dict.Set(value, token2.ToString());
			}

			// we always automatically set a "classname" key to our name
			_dict.Set("classname", this.Name);

			// "inherit" keys will cause all values from another entityDef to be copied into this one
			// if they don't conflict.  We can't have circular recursions, because each entityDef will
			// never be parsed more than once

			// find all of the dicts first, because copying inherited values will modify the dict
			List<idDeclEntity> defList = new List<idDeclEntity>();
			List<string> keysToRemove = new List<string>();

			foreach(KeyValuePair<string, string> kvp in _dict.MatchPrefix("inherit"))
			{
				idDeclEntity copy = idE.DeclManager.FindType<idDeclEntity>(DeclType.EntityDef, kvp.Value, false);

				if(copy == null)
				{
					lexer.Warning("Unknown entityDef '{0}' inherited by '{1}'", kvp.Value, this.Name);
				}
				else
				{
					defList.Add(copy);
				}

				// delete this key/value pair
				keysToRemove.Add(kvp.Key);
			}

			_dict.Remove(keysToRemove.ToArray());

			// now copy over the inherited key / value pairs
			foreach(idDeclEntity def in defList)
			{
				_dict.SetDefaults(def._dict);
			}

			// precache all referenced media
			// do this as long as we arent in modview
			idE.Game.CacheDictionaryMedia(_dict);
		
			return true;
		}
Example #3
0
		private void ParseSort(idLexer lexer)
		{
			idToken token = lexer.ReadTokenOnLine();

			if(token == null)
			{
				lexer.Warning("missing sort parameter");
				this.MaterialFlag = MaterialFlags.Defaulted;

				return;
			}

			try
			{
				_sort = (int) Enum.Parse(typeof(MaterialSort), token.ToString(), true);
			}
			catch(Exception)
			{
				float.TryParse(token.ToString(), out _sort);
			}
		}
Example #4
0
		private void ParseDeform(idLexer lexer)
		{
			idToken token = lexer.ExpectAnyToken();

			if(token == null)
			{
				return;
			}

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

			if(tokenLower == "sprite")
			{
				_deformType = DeformType.Sprite;
				_cullType = CullType.TwoSided;

				this.MaterialFlag = MaterialFlags.NoShadows;
			}
			else if(tokenLower == "tube")
			{
				_deformType = DeformType.Tube;
				_cullType = CullType.TwoSided;

				this.MaterialFlag = MaterialFlags.NoShadows;
			}
			else if(tokenLower == "flare")
			{
				_deformType = DeformType.Flare;
				_cullType = CullType.TwoSided;
				_deformRegisters[0] = ParseExpression(lexer);

				this.MaterialFlag = MaterialFlags.NoShadows;
			}
			else if(tokenLower == "expand")
			{
				_deformType = DeformType.Expand;
				_deformRegisters[0] = ParseExpression(lexer);
			}
			else if(tokenLower == "move")
			{
				_deformType = DeformType.Move;
				_deformRegisters[0] = ParseExpression(lexer);
			}
			else if(tokenLower == "turbulent")
			{
				_deformType = DeformType.Turbulent;

				if((token = lexer.ExpectAnyToken()) == null)
				{
					lexer.Warning("deform particle missing particle name");
					this.MaterialFlag = MaterialFlags.Defaulted;
				}
				else
				{
					_deformDecl = idE.DeclManager.FindType(DeclType.Table, token.ToString(), true);

					_deformRegisters[0] = ParseExpression(lexer);
					_deformRegisters[1] = ParseExpression(lexer);
					_deformRegisters[2] = ParseExpression(lexer);
				}
			}
			else if(tokenLower == "eyeball")
			{
				_deformType = DeformType.Eyeball;
			}
			else if(tokenLower == "particle")
			{
				_deformType = DeformType.Particle;

				if((token = lexer.ExpectAnyToken()) == null)
				{
					lexer.Warning("deform particle missing particle name");
					this.MaterialFlag = MaterialFlags.Defaulted;
				}
				else
				{
					_deformDecl = idE.DeclManager.FindType(DeclType.Particle, token.ToString(), true);
				}
			}
			else if(tokenLower == "particle2")
			{
				_deformType = DeformType.Particle2;

				if((token = lexer.ExpectAnyToken()) == null)
				{
					lexer.Warning("deform particle missing particle name");
					this.MaterialFlag = MaterialFlags.Defaulted;
				}
				else
				{
					_deformDecl = idE.DeclManager.FindType(DeclType.Table, token.ToString(), true);

					_deformRegisters[0] = ParseExpression(lexer);
					_deformRegisters[1] = ParseExpression(lexer);
					_deformRegisters[2] = ParseExpression(lexer);
				}
			}
			else
			{
				lexer.Warning("Bad deform type '{0}'", tokenValue);
				this.MaterialFlag = MaterialFlags.Defaulted;
			}
		}
		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);
		}
Example #6
0
		/// <summary>
		/// This is used during both the initial load, and any reloads.
		/// </summary>
		/// <returns></returns>
		public int LoadAndParse()
		{
			// load the text
			idConsole.DeveloperWriteLine("...loading '{0}'", this.FileName);

			byte[] data = idE.FileSystem.ReadFile(this.FileName);
			
			if(data == null)
			{
				idConsole.FatalError("couldn't load {0}", this.FileName);
				return 0;
			}

			string content = UTF8Encoding.UTF8.GetString(data);
			idLexer lexer = new idLexer();
			lexer.Options = LexerOptions;

			if(lexer.LoadMemory(content, this.FileName) == false)
			{
				idConsole.Error("Couldn't parse {0}", this.FileName);
				return 0;
			}
			
			// mark all the defs that were from the last reload of this file
			foreach(idDecl decl in _decls)
			{
				decl.RedefinedInReload = false;
			}

			// TODO: checksum = MD5_BlockChecksum( buffer, length );

			_fileSize = content.Length;

			int startMarker, sourceLine;
			int size;
			string name;
			bool reparse;
			idToken token;
			idDecl newDecl;
			DeclType identifiedType;

			string tokenValue;
		
			// scan through, identifying each individual declaration
			while(true)
			{
				startMarker = lexer.FileOffset;
				sourceLine = lexer.LineNumber;

				// parse the decl type name
				if((token = lexer.ReadToken()) == null)
				{
					break;
				}

				tokenValue = token.ToString();

				// get the decl type from the type name
				identifiedType = idE.DeclManager.GetDeclTypeFromName(tokenValue);
				
				if(identifiedType == DeclType.Unknown)
				{
					if(tokenValue == "{")
					{
						// if we ever see an open brace, we somehow missed the [type] <name> prefix
						lexer.Warning("Missing decl name");
						lexer.SkipBracedSection(false);

						continue;
					}
					else
					{
						if(this.DefaultType == DeclType.Unknown)
						{
							lexer.Warning("No type");
							continue;
						}

						lexer.UnreadToken = token;

						// use the default type
						identifiedType = this.DefaultType;
					}
				}
				
				// now parse the name
				if((token = lexer.ReadToken()) == null)
				{
					lexer.Warning("Type without definition at the end of file");
					break;
				}

				tokenValue = token.ToString();

				if(tokenValue == "{")
				{
					// if we ever see an open brace, we somehow missed the [type] <name> prefix
					lexer.Warning("Missing decl name");
					lexer.SkipBracedSection(false);

					continue;
				}

				// FIXME: export decls are only used by the model exporter, they are skipped here for now
				if(identifiedType == DeclType.ModelExport)
				{
					lexer.SkipBracedSection();
					continue;
				}

				name = tokenValue;

				// make sure there's a '{'
				if((token = lexer.ReadToken()) == null)
				{
					lexer.Warning("Type without definition at end of file");
					break;
				}

				tokenValue = token.ToString();
				
				if(tokenValue != "{")
				{
					lexer.Warning("Expecting '{{' but found '{0}'", tokenValue);
					continue;
				}

				lexer.UnreadToken = token;

				// now take everything until a matched closing brace
				lexer.SkipBracedSection();
				size = lexer.FileOffset - startMarker;

				// look it up, possibly getting a newly created default decl
				reparse = false;
				newDecl = idE.DeclManager.FindTypeWithoutParsing(identifiedType, name, false);

				if(newDecl != null)
				{
					// update the existing copy
					if((newDecl.SourceFile != this) || (newDecl.RedefinedInReload == true))
					{
						lexer.Warning("{0} '{1}' previously defined at {2}:{3}", identifiedType.ToString().ToLower(), name, newDecl.FileName, newDecl.LineNumber);
						continue;
					}

					if(newDecl.State != DeclState.Unparsed)
					{
						reparse = true;
					}
				}
				else
				{
					// allow it to be created as a default, then add it to the per-file list
					newDecl = idE.DeclManager.FindTypeWithoutParsing(identifiedType, name, true);

					if(newDecl == null)
					{
						lexer.Warning("could not instanciate decl '{0}' with name '{1}'", identifiedType.ToString().ToLower(), name);
						continue;
					}

					_decls.Add(newDecl);
				}

				newDecl.RedefinedInReload = true;
				newDecl.SourceText = content.Substring(startMarker, size);
				newDecl.SourceFile = this;
				newDecl.SourceTextOffset = startMarker;
				newDecl.SourceTextLength = size;
				newDecl.SourceLine = sourceLine;
				newDecl.State = DeclState.Unparsed;

				// if it is currently in use, reparse it immedaitely
				if(reparse)
				{
					newDecl.ParseLocal();
				}
			}

			_lineCount = lexer.LineNumber;

			// any defs that weren't redefinedInReload should now be defaulted
			foreach(idDecl decl in _decls)
			{
				if(decl.RedefinedInReload == false)
				{
					decl.MakeDefault();
					decl.SourceTextOffset = decl.SourceFile.FileSize;
					decl.SourceTextLength = 0;
					decl.SourceLine = decl.SourceFile.LineCount;
				}
			}

			return _checksum;
		}
Example #7
0
		private bool ParseMaterial(idLexer lexer)
		{
			_parameters.MinDistance = 1;
			_parameters.MaxDistance = 10;
			_parameters.Volume = 1;

			_speakerMask = 0;
			_altSound = null;

			idToken token;
			string tokenValue;
			int sampleCount = 0;

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

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

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

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

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

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

					idConsole.Warning("TODO: leadin");

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

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

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

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

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

			int defaultAnimationCount = 0;
			idToken token;
			idToken token2;
			string tokenValue;
			string fileName;
			string extension;
			int count;
			idMD5Joint[] md5Joints;

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

				tokenValue = token.ToString();

				if(tokenValue == "}")
				{
					break;
				}

				if(tokenValue == "inherit")
				{
					idConsole.WriteLine("TODO: inherit");

					/*if( !src.ReadToken( &token2 ) ) {
						src.Warning( "Unexpected end of file" );
						MakeDefault();
						return false;
					}
			
					const idDeclModelDef *copy = static_cast<const idDeclModelDef *>( declManager->FindType( DECL_MODELDEF, token2, false ) );
					if ( !copy ) {
						common->Warning( "Unknown model definition '%s'", token2.c_str() );
					} else if ( copy->GetState() == DS_DEFAULTED ) {
						common->Warning( "inherited model definition '%s' defaulted", token2.c_str() );
						MakeDefault();
						return false;
					} else {
						CopyDecl( copy );
						numDefaultAnims = anims.Num();
					}*/
				} 
				else if(tokenValue == "skin") 
				{
					if((token2 = lexer.ReadToken()) == null)
					{
						lexer.Warning("Unexpected end of file");
						MakeDefault();

						return false;
					}

					_skin = idE.DeclManager.FindSkin(token2.ToString());

					if(_skin == null)
					{
						lexer.Warning("Skin '{0}' not found", token2.ToString());
						MakeDefault();

						return false;
					}
				} 
				else if(tokenValue == "mesh")
				{
					if((token2 = lexer.ReadToken()) == null)
					{
						lexer.Warning("Unexpected end of file");
						MakeDefault();

						return false;
					}

					fileName = token2.ToString();
					extension = Path.GetExtension(fileName);

					if(extension != idRenderModel_MD5.MeshExtension)
					{
						lexer.Warning("Invalid model for MD5 mesh");
						MakeDefault();

						return false;
					}

					_model = idE.RenderModelManager.FindModel(fileName);

					if(_model == null)
					{
						lexer.Warning("Model '{0}' not found", fileName);
						MakeDefault();

						return false;
					}
					else if(_model.IsDefault == true)
					{
						lexer.Warning("Model '{0}' defaulted", fileName);
						MakeDefault();

						return false;
					}

					// get the number of joints
					count = _model.JointCount;

					if(count == 0)
					{
						lexer.Warning("Model '{0}' has no joints", fileName);
					}

					// set up the joint hierarchy
					md5Joints = _model.Joints;

					_joints = new JointInfo[count];
					_jointParents = new int[count];
					_channelJoints = new int[(int) AnimationChannel.Count][];
					_channelJoints[0] = new int[count];

					for(int i = 0; i < count; i++)
					{
						_joints[i] = new JointInfo();
						_joints[i].Channel = AnimationChannel.All;
						_joints[i].Index = i;

						if(md5Joints[i].Parent != null)
						{
							_joints[i].ParentIndex = _model.GetJointIndex(md5Joints[i].Parent);
						}
						else
						{
							_joints[i].ParentIndex = -1;
						}

						_jointParents[i] = _joints[i].ParentIndex;
						_channelJoints[0][i] = i;
					}
				}
				else if(tokenValue == "remove")
				{
					idConsole.Warning("TODO: remove");

					// removes any anims whos name matches
					/*if( !src.ReadToken( &token2 ) ) {
						src.Warning( "Unexpected end of file" );
						MakeDefault();
						return false;
					}
					num = 0;
					for( i = 0; i < anims.Num(); i++ ) {
						if ( ( token2 == anims[ i ]->Name() ) || ( token2 == anims[ i ]->FullName() ) ) {
							delete anims[ i ];
							anims.RemoveIndex( i );
							if ( i >= numDefaultAnims ) {
								src.Warning( "Anim '%s' was not inherited.  Anim should be removed from the model def.", token2.c_str() );
								MakeDefault();
								return false;
							}
							i--;
							numDefaultAnims--;
							num++;
							continue;
						}
					}
					if ( !num ) {
						src.Warning( "Couldn't find anim '%s' to remove", token2.c_str() );
						MakeDefault();
						return false;
					}*/
				} 
				else if(tokenValue == "anim") 
				{
					if(_model == null)
					{
						lexer.Warning("Must specify mesh before defining anims");
						MakeDefault();

						return false;
					}
					else if(ParseAnimation(lexer, defaultAnimationCount) == false)
					{
						MakeDefault();

						return false;
					}
				} 
				else if(tokenValue == "offset") 
				{
					float[] tmp = lexer.Parse1DMatrix(3);

					if(tmp == null)
					{
						lexer.Warning("Expected vector following 'offset'");
						MakeDefault();
						return false;
					}

					_offset = new Vector3(tmp[0], tmp[1], tmp[2]);
				} 
				else if(tokenValue == "channel") 
				{
					if(_model == null)
					{
						lexer.Warning("Must specify mesh before defining channels");
						MakeDefault();

						return false;
					}

					// set the channel for a group of joints
					if((token2 = lexer.ReadToken()) == null)
					{
						lexer.Warning("Unexpected end of file");
						MakeDefault();

						return false;
					}

					if(lexer.CheckTokenString("(") == false)
					{
						lexer.Warning("Expected { after '{0}'", token2.ToString());
						MakeDefault();

						return false;
					}

					int i;
					int channelCount = (int) AnimationChannel.Count;

					for(i = (int) AnimationChannel.All + 1; i < channelCount; i++)
					{
						if(ChannelNames[i].Equals(token2.ToString(), StringComparison.OrdinalIgnoreCase) == true)
						{
							break;
						}
					}

					if(i >= channelCount)
					{
						lexer.Warning("Unknown channel '{0}'", token2.ToString());
						MakeDefault();

						return false;
					}

					int channel = i;
					StringBuilder jointNames = new StringBuilder();
					string token2Value;

					while(lexer.CheckTokenString(")") == false)
					{
						if((token2 = lexer.ReadToken()) == null)
						{
							lexer.Warning("Unexpected end of file");
							MakeDefault();

							return false;
						}

						token2Value = token2.ToString();
						jointNames.Append(token2Value);

						if((token2Value != "*") && (token2Value != "-"))
						{
							jointNames.Append(" ");
						}
					}

					int[] jointList = GetJointList(jointNames.ToString());
					int jointLength = jointList.Length;

					List<int> channelJoints = new List<int>();
					
					for(count = i = 0; i < jointLength; i++)
					{
						int jointIndex = jointList[i];

						if(_joints[jointIndex].Channel != AnimationChannel.All)
						{
							lexer.Warning("Join '{0}' assigned to multiple channels", _model.GetJointName(jointIndex));
							continue;
						}

						_joints[jointIndex].Channel = (AnimationChannel) channel;
						channelJoints.Add(jointIndex);
					}

					_channelJoints[channel] = channelJoints.ToArray();
				}
				else
				{
					lexer.Warning("unknown token '{0}'", token.ToString());
					MakeDefault();

					return false;
				}
			}
		
			return true;
		}
Example #9
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;
		}