Ejemplo n.º 1
0
 public LightState(STFReader stf)
 {
     stf.MustMatch("(");
     stf.ParseBlock(new[] {
         new STFReader.TokenProcessor("duration", () => { Duration = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
         new STFReader.TokenProcessor("lightcolour", () => { Color = stf.ReadHexBlock(null); }),
         new STFReader.TokenProcessor("position", () => { Position = stf.ReadVector3Block(STFReader.UNITS.None, Vector3.Zero); }),
         new STFReader.TokenProcessor("radius", () => { Radius = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); }),
         new STFReader.TokenProcessor("azimuth", () => { Azimuth = stf.ReadVector3Block(STFReader.UNITS.None, Vector3.Zero); }),
         new STFReader.TokenProcessor("elevation", () => { Elevation = stf.ReadVector3Block(STFReader.UNITS.None, Vector3.Zero); }),
         new STFReader.TokenProcessor("transition", () => { Transition = 1 <= stf.ReadFloatBlock(STFReader.UNITS.None, 0); }),
         new STFReader.TokenProcessor("angle", () => { Angle = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
     });
 }
Ejemplo n.º 2
0
 public Camera(STFReader stf)
 {
     stf.MustMatchBlockStart();
     stf.ParseBlock(new STFReader.TokenProcessor[] {
         new STFReader.TokenProcessor("camtype", () => { CameraType = stf.ReadStringBlock(null); CameraControl = stf.ReadStringBlock(null); }),
         new STFReader.TokenProcessor("cameraoffset", () => { stf.ReadVector3Block(STFReader.Units.None, ref cameraOffset); }),
         new STFReader.TokenProcessor("direction", () => { stf.ReadVector3Block(STFReader.Units.None, ref direction); }),
         new STFReader.TokenProcessor("objectoffset", () => { stf.ReadVector3Block(STFReader.Units.None, ref objectOffset); }),
         new STFReader.TokenProcessor("rotationlimit", () => { stf.ReadVector3Block(STFReader.Units.None, ref rotationLimit); }),
         new STFReader.TokenProcessor("description", () => { Description = stf.ReadStringBlock(null); }),
         new STFReader.TokenProcessor("fov", () => { Fov = stf.ReadFloatBlock(STFReader.Units.None, null); }),
         new STFReader.TokenProcessor("zclip", () => { ZClip = stf.ReadFloatBlock(STFReader.Units.None, null); }),
         new STFReader.TokenProcessor("wagonnum", () => { WagonNumber = stf.ReadIntBlock(null); }),
     });
 }
Ejemplo n.º 3
0
 public Camera(STFReader stf)
 {
     stf.MustMatch("(");
     stf.ParseBlock(new STFReader.TokenProcessor[] {
         new STFReader.TokenProcessor("camtype", () => { CamType = stf.ReadStringBlock(null); CamControl = stf.ReadStringBlock(null); }),
         new STFReader.TokenProcessor("cameraoffset", () => { CameraOffset = stf.ReadVector3Block(STFReader.UNITS.None, CameraOffset); }),
         new STFReader.TokenProcessor("direction", () => { Direction = stf.ReadVector3Block(STFReader.UNITS.None, Direction); }),
         new STFReader.TokenProcessor("objectoffset", () => { ObjectOffset = stf.ReadVector3Block(STFReader.UNITS.None, ObjectOffset); }),
         new STFReader.TokenProcessor("rotationlimit", () => { RotationLimit = stf.ReadVector3Block(STFReader.UNITS.None, RotationLimit); }),
         new STFReader.TokenProcessor("description", () => { Description = stf.ReadStringBlock(null); }),
         new STFReader.TokenProcessor("fov", () => { Fov = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
         new STFReader.TokenProcessor("zclip", () => { ZClip = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
         new STFReader.TokenProcessor("wagonnum", () => { WagonNum = stf.ReadIntBlock(null); }),
     });
 }
Ejemplo n.º 4
0
 internal WorldSoundSource(STFReader stf)
 {
     stf.MustMatchBlockStart();
     stf.ParseBlock(new STFReader.TokenProcessor[] {
         new STFReader.TokenProcessor("filename", () => { FileName = stf.ReadStringBlock(null); }),
         new STFReader.TokenProcessor("position", () => {
             stf.MustMatchBlockStart();
             stf.ReadVector3Block(STFReader.Units.None, ref position);
             stf.SkipRestOfBlock();
         }),
     });
 }
Ejemplo n.º 5
0
 public LightState(STFReader stf)
 {
     stf.MustMatch("(");
     stf.ParseBlock(new[] {
         new STFReader.TokenProcessor("duration", () => { Duration = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
         new STFReader.TokenProcessor("lightcolour", () => { Color = stf.ReadHexBlock(null); }),
         new STFReader.TokenProcessor("position", () => { Position = stf.ReadVector3Block(STFReader.UNITS.None, Vector3.Zero); }),
         new STFReader.TokenProcessor("radius", () => { Radius = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); }),
         new STFReader.TokenProcessor("azimuth", () => { Azimuth = stf.ReadVector3Block(STFReader.UNITS.None, Vector3.Zero); }),
         new STFReader.TokenProcessor("elevation", () => { Elevation = stf.ReadVector3Block(STFReader.UNITS.None, Vector3.Zero); }),
         new STFReader.TokenProcessor("transition", () => { Transition = 1 <= stf.ReadFloatBlock(STFReader.UNITS.None, 0); }),
         new STFReader.TokenProcessor("angle", () => { Angle = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
     });
     // Color byte order changed in XNA 4 from BGRA to RGBA
     Color = new Color()
     {
         B = (byte)(Color),
         G = (byte)(Color >> 8),
         R = (byte)(Color >> 16),
         A = (byte)(Color >> 24)
     }.PackedValue;
 }
Ejemplo n.º 6
0
        public AttributeProcessor(object setWhom, FieldInfo fi, STFReader stf, object defaultValue)
        {
            _fi = fi;

            P = () =>
            {
                switch (_fi.FieldType.Name.ToLower())
                {
                case "int":
                case "int32":
                {
                    int?i = defaultValue as int?;
                    _fi.SetValue(setWhom,
                                 stf.ReadIntBlock(i));
                    break;
                }

                case "bool":
                case "boolean":
                {
                    bool?b = defaultValue as bool?;
                    _fi.SetValue(setWhom,
                                 stf.ReadBoolBlock(b.Value));
                    break;
                }

                case "string":
                {
                    string s = defaultValue as string;
                    _fi.SetValue(setWhom,
                                 stf.ReadStringBlock(s));
                    break;
                }

                case "float":
                case "single":
                {
                    float?f = defaultValue as float?;
                    _fi.SetValue(setWhom,
                                 stf.ReadFloatBlock(STFReader.Units.Any, f));
                    break;
                }

                case "double":
                {
                    double?d = defaultValue as double?;
                    _fi.SetValue(setWhom,
                                 stf.ReadDoubleBlock(d));
                    break;
                }

                case "vector3":
                {
                    Vector3 v3 = (defaultValue as string).ParseVector3();
                    {
                        _fi.SetValue(setWhom,
                                     stf.ReadVector3Block(STFReader.Units.Any, v3));
                    }
                    break;
                }

                case "vector4":
                {
                    Vector4 v4 = (defaultValue as string).ParseVector4();
                    {
                        stf.ReadVector4Block(STFReader.Units.Any, ref v4);
                        _fi.SetValue(setWhom, v4);
                    }
                    break;
                }

                case "color":
                {
                    Color c = (defaultValue as string).ParseColor();
                    {
                        Vector4 v4 = new Vector4(-1);
                        stf.ReadVector4Block(STFReader.Units.Any, ref v4);
                        if (v4.W == -1)
                        {
                            c.A = 255;
                            c.R = v4.X == -1 ? c.R : (byte)v4.X;
                            c.G = v4.Y == -1 ? c.G : (byte)v4.Y;
                            c.B = v4.Z == -1 ? c.B : (byte)v4.Z;
                        }
                        else
                        {
                            c.A = v4.X == -1 ? c.A : (byte)v4.X;
                            c.R = v4.Y == -1 ? c.R : (byte)v4.Y;
                            c.G = v4.Z == -1 ? c.G : (byte)v4.Z;
                            c.B = v4.W == -1 ? c.B : (byte)v4.W;
                        }
                        _fi.SetValue(setWhom, c);
                    }
                    break;
                }
                }
            };
        }
Ejemplo n.º 7
0
        public CabViewFile(string basePath, string fileName)
        {
            using (STFReader stf = new STFReader(Path.GetFullPath(Path.Combine(basePath, fileName)), false))
                stf.ParseFile(new STFReader.TokenProcessor[] {
                    new STFReader.TokenProcessor("tr_cabviewfile", () => { stf.MustMatchBlockStart(); stf.ParseBlock(new STFReader.TokenProcessor[] {
                            new STFReader.TokenProcessor("position", () => { Locations.Add(stf.ReadVector3Block(STFReader.Units.None, new Vector3())); }),
                            new STFReader.TokenProcessor("direction", () => { Directions.Add(stf.ReadVector3Block(STFReader.Units.None, new Vector3())); }),
                            new STFReader.TokenProcessor("cabviewfile", () => {
                                string cvfileName = stf.ReadStringBlock(null);
                                string path       = Path.Combine(basePath, Path.GetDirectoryName(cvfileName));
                                string name       = Path.GetFileName(cvfileName);

                                // Use *Frnt1024.ace if available
                                if (!Path.GetFileNameWithoutExtension(cvfileName).EndsWith("1024", StringComparison.OrdinalIgnoreCase))
                                {
                                    string name1024 = Path.GetFileNameWithoutExtension(cvfileName) + "1024" + Path.GetExtension(cvfileName);
                                    if (File.Exists(Path.Combine(path, name1024)))
                                    {
                                        name = name1024;
                                    }
                                }

                                Views2D.Add(Path.Combine(path, name));
                                ViewsNight.Add(Path.Combine(path, "NIGHT", name));
                                ViewsLight.Add(Path.Combine(path, "CABLIGHT", name));
                            }),
                            new STFReader.TokenProcessor("cabviewcontrols", () => { CabViewControls = new CabViewControls(stf, basePath); }),
                        }); }),
                });
        }
Ejemplo n.º 8
0
        public CabViewControls CabViewControls;                  // Controls in CAB - by GeorgeS

        public CabViewFile(string filePath, string basePath)
        {
            using (STFReader stf = new STFReader(filePath, false))
                stf.ParseFile(new STFReader.TokenProcessor[] {
                    new STFReader.TokenProcessor("tr_cabviewfile", () => { stf.MustMatch("("); stf.ParseBlock(new STFReader.TokenProcessor[] {
                            new STFReader.TokenProcessor("position", () => { Locations.Add(stf.ReadVector3Block(STFReader.UNITS.None, new Vector3())); }),
                            new STFReader.TokenProcessor("direction", () => { Directions.Add(stf.ReadVector3Block(STFReader.UNITS.None, new Vector3())); }),
                            new STFReader.TokenProcessor("cabviewfile", () => {
                                var fileName = stf.ReadStringBlock(null);
                                var path     = Path.Combine(basePath, Path.GetDirectoryName(fileName));
                                var name     = Path.GetFileName(fileName);

                                // Use *Frnt1024.ace if available
                                string s            = name;
                                string[] nameParts  = s.Split('.');
                                string name1024     = nameParts[0] + "1024." + nameParts[1];
                                var tstFileName1024 = Path.Combine(path, name1024);
                                if (File.Exists(tstFileName1024))
                                {
                                    name = name1024;
                                }

                                TwoDViews.Add(Path.Combine(path, name));
                                NightViews.Add(Path.Combine(path, Path.Combine("NIGHT", name)));
                                LightViews.Add(Path.Combine(path, Path.Combine("CABLIGHT", name)));
                            }),
                            new STFReader.TokenProcessor("cabviewcontrols", () => { CabViewControls = new CabViewControls(stf, basePath); }),
                        }); }),
                });
        }
Ejemplo n.º 9
0
        static SortedList <double, string> GetList(Simulator simulator, char type)
        {
            string ending = "*.eng";

            if (type == 'w')
            {
                ending = "*.wag";
            }
            string[]      filePaths = Directory.GetFiles(simulator.BasePath + "\\trains\\trainset", ending, SearchOption.AllDirectories);
            string        temp;
            List <string> allEngines            = new List <string>();
            SortedList <double, string> carList = new SortedList <double, string>();

            for (var i = 0; i < filePaths.Length; i++)
            {
                int index = filePaths[i].LastIndexOf("\\trains\\trainset\\");
                temp = filePaths[i].Substring(index + 17);
                if (!temp.Contains("\\"))
                {
                    continue;
                }
                allEngines.Add(temp);
            }
            foreach (string name in allEngines)
            {
                double len = 0.0f;
                Microsoft.Xna.Framework.Vector3 def = new Microsoft.Xna.Framework.Vector3();

                try
                {
                    using (var stf = new STFReader(simulator.BasePath + "\\trains\\trainset\\" + name, false))
                        stf.ParseFile(new STFReader.TokenProcessor[] {
                            new STFReader.TokenProcessor("wagon", () => {
                                stf.ReadString();
                                stf.ParseBlock(new STFReader.TokenProcessor[] {
                                    new STFReader.TokenProcessor("size", () => { def = stf.ReadVector3Block(STFReader.UNITS.Distance, def); }),
                                });
                            }),
                        });

                    len = def.Z;
                    carList.Add(len + MPManager.Random.NextDouble() / 10.0f, name);
                }
                catch { }
            }
            return(carList);
        }
Ejemplo n.º 10
0
        public AttributeProcessor(object setWhom, FieldInfo fi, STFReader stf, object defaultValue)
        {
            fieldInfo = fi;

            Processor = () =>
            {
                switch (fieldInfo.FieldType.Name.ToUpperInvariant())
                {
                case "INT":
                case "INT32":
                {
                    int?i = defaultValue as int?;
                    fieldInfo.SetValue(setWhom,
                                       stf.ReadIntBlock(i));
                    break;
                }

                case "BOOL":
                case "BOOLEAN":
                {
                    bool?b = defaultValue as bool?;
                    fieldInfo.SetValue(setWhom,
                                       stf.ReadBoolBlock(b.Value));
                    break;
                }

                case "STRING":
                {
                    string s = defaultValue as string;
                    fieldInfo.SetValue(setWhom,
                                       stf.ReadStringBlock(s));
                    break;
                }

                case "FLOAT":
                case "SINGLE":
                {
                    float?f = defaultValue as float?;
                    fieldInfo.SetValue(setWhom,
                                       stf.ReadFloatBlock(STFReader.Units.Any, f));
                    break;
                }

                case "DOUBLE":
                {
                    double?d = defaultValue as double?;
                    fieldInfo.SetValue(setWhom,
                                       stf.ReadDoubleBlock(d));
                    break;
                }

                case "VECTOR3":
                {
                    Vector3 v3 = (defaultValue as string).ParseVector3();
                    {
                        fieldInfo.SetValue(setWhom,
                                           stf.ReadVector3Block(STFReader.Units.Any, v3));
                    }
                    break;
                }

                case "VECTOR4":
                {
                    Vector4 v4 = (defaultValue as string).ParseVector4();
                    {
                        stf.ReadVector4Block(STFReader.Units.Any, ref v4);
                        fieldInfo.SetValue(setWhom, v4);
                    }
                    break;
                }

                case "COLOR":
                {
                    Color c = (defaultValue as string).ParseColor();
                    {
                        Vector4 v4 = new Vector4(-1);
                        stf.ReadVector4Block(STFReader.Units.Any, ref v4);
                        if (v4.W == -1)
                        {
                            c.A = 255;
                            c.R = v4.X == -1 ? c.R : (byte)v4.X;
                            c.G = v4.Y == -1 ? c.G : (byte)v4.Y;
                            c.B = v4.Z == -1 ? c.B : (byte)v4.Z;
                        }
                        else
                        {
                            c.A = v4.X == -1 ? c.A : (byte)v4.X;
                            c.R = v4.Y == -1 ? c.R : (byte)v4.Y;
                            c.G = v4.Z == -1 ? c.G : (byte)v4.Z;
                            c.B = v4.W == -1 ? c.B : (byte)v4.W;
                        }
                        fieldInfo.SetValue(setWhom, c);
                    }
                    break;
                }
                }
            };
        }