예제 #1
0
			/// <summary>Creates a new static background</summary>
			/// <param name="Texture">The texture to apply</param>
			/// <param name="Repetition">The number of times the texture should be repeated around the viewing frustrum</param>
			/// <param name="KeepAspectRatio">Whether the aspect ratio of the texture should be preseved</param>
			/// <param name="transitionTime">The time taken in seconds for the fade-in transition to occur</param>
			/// <param name="Mode">The transition mode</param>
			/// <param name="Time">The time at which this background is to be displayed, expressed as the number of seconds since midnight</param>
			internal StaticBackground(Textures.Texture Texture, double Repetition, bool KeepAspectRatio, double transitionTime, BackgroundTransitionMode Mode, double Time)
			{
				this.Texture = Texture;
				this.Repetition = Repetition;
				this.KeepAspectRatio = KeepAspectRatio;
				this.TransitionTime = transitionTime;
				this.Mode = Mode;
				this.Time = Time;
			}
예제 #2
0
        /// <summary>Renders a dynamic frustrum based background</summary>
        /// <param name="Data">The background to render</param>
        /// <param name="scale">The scale</param>
        public static void RenderBackground(dynamic Data, float scale)
        {
            if (Data.PreviousBackgroundIndex == Data.CurrentBackgroundIndex)
            {
                RenderBackground(Data.Backgrounds[Data.CurrentBackgroundIndex], 1.0f, scale);
                return;
            }
            Renderer.SetAlphaFunc(AlphaFunction.Greater, 0.0f);
            BackgroundTransitionMode Mode = Data.Backgrounds[Data.CurrentBackgroundIndex].Mode;             //Must do this to make the switch work correctly using a dynamic

            switch (Mode)
            {
            case BackgroundTransitionMode.FadeIn:
                RenderBackground(Data.Backgrounds[Data.PreviousBackgroundIndex], 1.0f, scale);
                RenderBackground(Data.Backgrounds[Data.CurrentBackgroundIndex], Data.CurrentAlpha, scale);
                break;

            case BackgroundTransitionMode.FadeOut:
                RenderBackground(Data.Backgrounds[Data.CurrentBackgroundIndex], 1.0f, scale);
                RenderBackground(Data.Backgrounds[Data.PreviousBackgroundIndex], Data.CurrentAlpha, scale);
                break;
            }
        }
예제 #3
0
 /// <summary>Creates a new static background</summary>
 /// <param name="Texture">The texture to apply</param>
 /// <param name="Repetition">The number of times the texture should be repeated around the viewing frustrum</param>
 /// <param name="KeepAspectRatio">Whether the aspect ratio of the texture should be preseved</param>
 /// <param name="transitionTime">The time taken in seconds for the fade-in transition to occur</param>
 /// <param name="Mode">The transition mode</param>
 /// <param name="Time">The time at which this background is to be displayed, expressed as the number of seconds since midnight</param>
 internal StaticBackground(Texture Texture, double Repetition, bool KeepAspectRatio, double transitionTime, BackgroundTransitionMode Mode, double Time)
 {
     this.Texture         = Texture;
     this.Repetition      = Repetition;
     this.KeepAspectRatio = KeepAspectRatio;
     this.TransitionTime  = transitionTime;
     this.Mode            = Mode;
     this.Time            = Time;
 }
예제 #4
0
        //Parses an XML background definition
        public static BackgroundHandle ReadBackgroundXML(string fileName)
        {
            List <StaticBackground> Backgrounds = new List <StaticBackground>();
            //The current XML file to load
            XmlDocument currentXML = new XmlDocument();

            //Load the object's XML file
            currentXML.Load(fileName);
            string Path = System.IO.Path.GetDirectoryName(fileName);

            double[] UnitOfLength = { 1.0 };
            //Check for null
            if (currentXML.DocumentElement != null)
            {
                XmlNodeList DocumentNodes = currentXML.DocumentElement.SelectNodes("/openBVE/Background");
                //Check this file actually contains OpenBVE light definition nodes
                if (DocumentNodes != null)
                {
                    foreach (XmlNode n in DocumentNodes)
                    {
                        if (n.ChildNodes.OfType <XmlElement>().Any())
                        {
                            double DisplayTime = -1;
                            //The time to transition between backgrounds in seconds
                            double TransitionTime = 0.8;
                            //The texture to use (if static)
                            Texture t = null;
                            //The object to use (if object based)
                            StaticObject o = null;
                            //The transition mode between backgrounds
                            BackgroundTransitionMode mode = BackgroundTransitionMode.FadeIn;
                            //The number of times the texture is repeated around the viewing frustrum (if appropriate)
                            double repetitions = 6;
                            foreach (XmlNode c in n.ChildNodes)
                            {
                                string[] Arguments = c.InnerText.Split(',');
                                switch (c.Name.ToLowerInvariant())
                                {
                                case "mode":
                                    switch (c.InnerText.ToLowerInvariant())
                                    {
                                    case "fadein":
                                        mode = BackgroundTransitionMode.FadeIn;
                                        break;

                                    case "fadeout":
                                        mode = BackgroundTransitionMode.FadeOut;
                                        break;

                                    case "none":
                                        mode = BackgroundTransitionMode.None;
                                        break;

                                    default:
                                        Interface.AddMessage(MessageType.Error, true, c.InnerText + "is not a valid background fade mode in file " + fileName);
                                        break;
                                    }
                                    break;

                                case "object":
                                    string f;
                                    try
                                    {
                                        f = OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(fileName), c.InnerText);
                                    }
                                    catch
                                    {
                                        Interface.AddMessage(MessageType.Error, true, "BackgroundObject FileName is malformed in file " + fileName);
                                        break;
                                    }
                                    if (!System.IO.File.Exists(f))
                                    {
                                        Interface.AddMessage(MessageType.Error, true, "FileName " + f + " not found in file " + fileName);
                                    }
                                    else
                                    {
                                        UnifiedObject b = ObjectManager.LoadObject(f, System.Text.Encoding.Default, false);
                                        o = (StaticObject)b;
                                    }
                                    break;

                                case "repetitions":
                                    if (!NumberFormats.TryParseDoubleVb6(Arguments[0], UnitOfLength, out repetitions))
                                    {
                                        Interface.AddMessage(MessageType.Error, false, c.InnerText + " does not parse to a valid number of repetitions in " + fileName);
                                    }
                                    break;

                                case "texture":
                                    string file;
                                    try
                                    {
                                        file = OpenBveApi.Path.CombineFile(Path, c.InnerText);
                                    }
                                    catch
                                    {
                                        Interface.AddMessage(MessageType.Error, true, "BackgroundTexture FileName is malformed in file " + fileName);
                                        break;
                                    }
                                    if (!System.IO.File.Exists(file))
                                    {
                                        Interface.AddMessage(MessageType.Error, false, "The background texture file " + c.InnerText + " does not exist in " + fileName);
                                    }
                                    else
                                    {
                                        Program.CurrentHost.RegisterTexture(file, new TextureParameters(null, null), out t);
                                    }
                                    break;

                                case "time":
                                    if (!Interface.TryParseTime(Arguments[0].Trim(), out DisplayTime))
                                    {
                                        Interface.AddMessage(MessageType.Error, false, c.InnerText + " does not parse to a valid time in file " + fileName);
                                    }
                                    break;

                                case "transitiontime":
                                    if (!NumberFormats.TryParseDoubleVb6(Arguments[0], UnitOfLength, out TransitionTime))
                                    {
                                        Interface.AddMessage(MessageType.Error, false, c.InnerText + " is not a valid background transition time in " + fileName);
                                    }
                                    break;
                                }
                            }
                            //Create background if texture is not null
                            if (t != null && o == null)
                            {
                                Backgrounds.Add(new StaticBackground(t, repetitions, false, TransitionTime, mode, DisplayTime));
                            }
                            if (t == null && o != null)
                            {
                                //All other parameters are ignored if an object has been defined
                                //TODO: Error message stating they have been ignored
                                return(new BackgroundObject(o));
                            }
                        }
                    }
                    if (Backgrounds.Count == 1)
                    {
                        return(Backgrounds[0]);
                    }
                    if (Backgrounds.Count > 1)
                    {
                        //Sort list- Not worried about when they start or end, so use simple LINQ
                        Backgrounds = Backgrounds.OrderBy(o => o.Time).ToList();
                        //If more than 2 backgrounds, convert to array and return a new dynamic background
                        return(new DynamicBackground(Backgrounds.ToArray()));
                    }
                }
            }
            //We couldn't find any valid XML, so return false
            throw new InvalidDataException();
        }
예제 #5
0
 /// <summary>Creates a new static background</summary>
 /// <param name="Texture">The texture to apply</param>
 /// <param name="Repetition">The number of times the texture should be repeated around the viewing frustrum</param>
 /// <param name="KeepAspectRatio">Whether the aspect ratio of the texture should be preseved</param>
 /// <param name="transitionTime">The time taken in seconds for the fade-in transition to occur</param>
 /// <param name="Mode">The transition mode</param>
 public StaticBackground(Texture Texture, double Repetition, bool KeepAspectRatio, double transitionTime, BackgroundTransitionMode Mode) : this(Texture, Repetition, KeepAspectRatio, 0.8, BackgroundTransitionMode.FadeIn, -1.0)
 {
 }