Example #1
0
        private void PreRender()
        {
            if (_needsRender == true)
            {
                _world.InitFromMap(null);

                idDict spawnArgs = new idDict();
                spawnArgs.Set("classname", "light");
                spawnArgs.Set("name", "light_1");
                spawnArgs.Set("origin", _lightOrigin);
                spawnArgs.Set("_color", _lightColor);

                idConsole.Warning("TODO: lighting");

                /*gameEdit->ParseSpawnArgsToRenderLight(&spawnArgs, &rLight);
                 * lightDef = world->AddLightDef(&rLight);
                 * if(!modelName[0])
                 * {
                 *      common->Warning("Window '%s' in gui '%s': no model set", GetName(), GetGui()->GetSourceFile());
                 * }*/

                spawnArgs.Clear();
                spawnArgs.Set("classname", "func_static");
                spawnArgs.Set("model", _modelName);
                spawnArgs.Set("origin", _modelOrigin);

                _worldEntity = idE.GameEdit.ParseSpawnArgsToRenderEntity(spawnArgs);

                if (_worldEntity.Model != null)
                {
                    Vector3 v = _modelRotate.ToVector3();

                    _worldEntity.Axis = v.ToMatrix();
                    _worldEntity.MaterialParameters[0] = 1;
                    _worldEntity.MaterialParameters[0] = 1;
                    _worldEntity.MaterialParameters[0] = 1;
                    _worldEntity.MaterialParameters[0] = 1;

                    _renderEntity = _world.AddEntityDefinition(_worldEntity);
                }

                _needsRender.Set(false);
            }
        }
Example #2
0
		public override void SpawnPlayer(int clientIndex)
		{
			idConsole.WriteLine("SpawnPlayer: {0}", clientIndex);

			idDict args = new idDict();
			args.Set("spawn_entnum", clientIndex);
			args.Set("name", string.Format("player{0}", clientIndex + 1));

			// TODO: refactor in to idGameRules
			args.Set("classname", (this.IsMultiplayer == true) ? "player_doommarine_mp" : "player_doommarine");

			idEntity ent = SpawnEntityDef(args);

			if((ent == null) || (_entities[clientIndex] == null))
			{
				idConsole.Error("Failed to spawn player as {0}", args.GetString("classname"));
			}

			// make sure it's a compatible class
			if((ent is idPlayer) == false)
			{
				idConsole.Error("'{0}' spawn the player as a '{1}'.  Player spawnclass must be a subclass of Player.", args.GetString("classname"), ent.ClassName);
			}

			if(clientIndex >= _clientCount)
			{
				_clientCount++;
			}

			this.Rules.SpawnPlayer(clientIndex);
		}
Example #3
0
		public static idMapBrush Parse(idLexer lexer, Vector3 origin, bool newFormat = true, float version = idMapFile.CurrentMapVersion)
		{
			idToken token;
			idMapBrushSide side;
			List<idMapBrushSide> sides = new List<idMapBrushSide>();
			idDict dict = new idDict();
			Vector3[] planePoints = new Vector3[3];

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

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

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

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

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


					string key = token.ToString();

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

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

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

				lexer.UnreadToken = token;

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

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

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

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

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

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

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

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

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

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

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

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

						}
					}
				}
			}
			while(true);

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

			idMapBrush brush = new idMapBrush();

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

			brush.Dict = dict;

			return brush;
		}
Example #4
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 #5
0
        public bool InitFromFile(string path, bool rebuild = true, bool cache = true)
        {
            if (this.Disposed == true)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            if (path == string.Empty)
            {
                return(false);
            }

            _loading = true;

            if ((rebuild == true) || (_desktop == null))
            {
                _desktop = new idWindow(this, idE.UIManager.Context);
            }

            _sourceFile = path;
            _state.Set("text", "Test Text!");

            // load the timestamp so reload guis will work correctly
            byte[]         data    = idE.FileSystem.ReadFile(path, out _timeStamp);
            string         content = UTF8Encoding.UTF8.GetString(data);
            idScriptParser parser  = null;

            if (content != null)
            {
                parser = new idScriptParser(LexerOptions.NoFatalErrors | LexerOptions.NoStringConcatination | LexerOptions.AllowMultiCharacterLiterals | LexerOptions.AllowBackslashStringConcatination);
                parser.LoadMemory(content, path);
            }

            if ((parser != null) && (parser.IsLoaded == true))
            {
                idToken token;

                while ((token = parser.ReadToken()) != null)
                {
                    if (token.ToString().Equals("windowDef", StringComparison.OrdinalIgnoreCase) == true)
                    {
                        if (_desktop.Parse(parser, rebuild) == true)
                        {
                            _desktop.Flags = WindowFlags.Desktop;
                            _desktop.FixupParameters();
                        }
                    }
                }

                _state.Set("name", path);
            }
            else
            {
                _desktop.Name          = "Desktop";
                _desktop.Flags         = WindowFlags.Desktop;
                _desktop.Text          = string.Format("Invalid GUI: {0}", path);
                _desktop.Rectangle     = new idRectangle(0, 0, 640, 480);
                _desktop.DrawRectangle = _desktop.Rectangle;
                _desktop.ForeColor     = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                _desktop.BackColor     = new Vector4(0.0f, 0.0f, 0.0f, 1.0f);
                _desktop.SetupFromState();

                idConsole.Warning("Couldn't load gui: '{0}'", path);
            }

            _interactive = _desktop.IsInteractive;

            if (idE.UIManager.FindInternalInterface(this) == null)
            {
                idE.UIManager.AddInternalInterface(this);
            }

            _loading = false;

            return(true);
        }
Example #6
0
        public static idMapBrush Parse(idLexer lexer, Vector3 origin, bool newFormat = true, float version = idMapFile.CurrentMapVersion)
        {
            idToken               token;
            idMapBrushSide        side;
            List <idMapBrushSide> sides = new List <idMapBrushSide>();
            idDict dict = new idDict();

            Vector3[] planePoints = new Vector3[3];

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

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

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

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

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


                    string key = token.ToString();

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

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

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

                lexer.UnreadToken = token;

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

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

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

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

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

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

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

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

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

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

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

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

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

            idMapBrush brush = new idMapBrush();

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

            brush.Dict = dict;

            return(brush);
        }
Example #7
0
		private void PreRender()
		{
			if(_needsRender == true)
			{
				_world.InitFromMap(null);

				idDict spawnArgs = new idDict();
				spawnArgs.Set("classname", "light");
				spawnArgs.Set("name", "light_1");
				spawnArgs.Set("origin", _lightOrigin);
				spawnArgs.Set("_color", _lightColor);

				idConsole.Warning("TODO: lighting");
			
				/*gameEdit->ParseSpawnArgsToRenderLight(&spawnArgs, &rLight);
				lightDef = world->AddLightDef(&rLight);
				if(!modelName[0])
				{
					common->Warning("Window '%s' in gui '%s': no model set", GetName(), GetGui()->GetSourceFile());
				}*/

				spawnArgs.Clear();
				spawnArgs.Set("classname", "func_static");
				spawnArgs.Set("model", _modelName);
				spawnArgs.Set("origin", _modelOrigin);

				_worldEntity = idE.GameEdit.ParseSpawnArgsToRenderEntity(spawnArgs);

				if(_worldEntity.Model != null)
				{
					Vector3 v = _modelRotate.ToVector3();

					_worldEntity.Axis = v.ToMatrix();
					_worldEntity.MaterialParameters[0] = 1;
					_worldEntity.MaterialParameters[0] = 1;
					_worldEntity.MaterialParameters[0] = 1;
					_worldEntity.MaterialParameters[0] = 1;

					_renderEntity = _world.AddEntityDefinition(_worldEntity);
				}

				_needsRender.Set(false);
			}
		}