Exemplo n.º 1
0
        /// <summary>Renders a background</summary>
        /// <param name="Data">The background to render</param>
        /// <param name="Alpha">The alpha level</param>
        /// <param name="Scale">The scale</param>
        public void Render(BackgroundHandle Data, float Alpha, float Scale)
        {
            DynamicBackground dynamicBackground = Data as DynamicBackground;
            StaticBackground  staticBackground  = Data as StaticBackground;
            BackgroundObject  backgroundObject  = Data as BackgroundObject;

            if (dynamicBackground != null)
            {
                RenderDynamicBackground(dynamicBackground, Alpha, Scale);
            }

            if (staticBackground != null)
            {
                if (renderer.currentOptions.IsUseNewRenderer)
                {
                    RenderStaticBackground(staticBackground, Alpha, Scale);
                }
                else
                {
                    RenderStaticBackgroundImmediate(staticBackground, Alpha, Scale);
                }
            }

            if (backgroundObject != null)
            {
                RenderBackgroundObject(backgroundObject);
            }
        }
Exemplo n.º 2
0
        public CurrentRoute(HostInterface host, BaseRenderer renderer)
        {
            currentHost   = host;
            this.renderer = renderer;

            Tracks = new Dictionary <int, Track>();
            Track t = new Track()
            {
                Elements = new TrackElement[0]
            };

            Tracks.Add(0, t);
            Sections = new Section[0];
            Stations = new RouteStation[0];
            BogusPreTrainInstructions = new BogusPreTrainInstruction[0];
            PointsOfInterest          = new PointOfInterest[0];
            CurrentBackground         = new StaticBackground(null, 6, false);
            TargetBackground          = new StaticBackground(null, 6, false);
            NoFogStart                 = 800.0f;
            NoFogEnd                   = 1600.0f;
            PreviousFog                = new Fog(NoFogStart, NoFogEnd, Color24.Grey, 0.0);
            CurrentFog                 = new Fog(NoFogStart, NoFogEnd, Color24.Grey, 0.5);
            NextFog                    = new Fog(NoFogStart, NoFogEnd, Color24.Grey, 1.0);
            Atmosphere                 = new Atmosphere();
            SecondsSinceMidnight       = 0.0;
            Information                = new RouteInformation();
            Illustrations.CurrentRoute = this;
        }
Exemplo n.º 3
0
 public BackgroundChangeEvent(CurrentRoute CurrentRoute, double TrackPositionDelta, BackgroundHandle PreviousBackground, BackgroundHandle NextBackground) : base(TrackPositionDelta)
 {
     currentRoute       = CurrentRoute;
     DontTriggerAnymore = false;
     previousBackground = PreviousBackground;
     nextBackground     = NextBackground;
 }
Exemplo n.º 4
0
 internal BackgroundChangeEvent(double TrackPositionDelta, BackgroundHandle PreviousBackground, BackgroundHandle NextBackground)
 {
     this.TrackPositionDelta = TrackPositionDelta;
     this.DontTriggerAnymore = false;
     this.PreviousBackground = PreviousBackground;
     this.NextBackground     = NextBackground;
 }
Exemplo n.º 5
0
 public void BackgroundListensForModelDispositionTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     persister.SelectBy(Arg.Any<int>()).Returns(new UserConfiguration { ServerUrl = string.Empty });
     var target = new BackgroundHandle(null, path, null, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     target.Model.Dispose();
     Assert.That(target.FinalizedCalled, Is.True);
 }
Exemplo n.º 6
0
 public void BackgroundListensForConfigChangesTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     bool persisted = false;
     var config = new UserConfiguration();
     persister.When(x => x.Persist(config)).Do(p => persisted = true);
     var target = new BackgroundHandle(null, path, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     System.Threading.Thread.Sleep(100);
     target.Model.Configuration = config;
     Assert.That(persisted, Is.True);
 }
Exemplo n.º 7
0
        /// <summary>Renders a background</summary>
        /// <param name="Data">The background to render</param>
        /// <param name="Alpha">The alpha level</param>
        /// <param name="Scale">The scale</param>
        public void Render(BackgroundHandle Data, float Alpha, float Scale)
        {
            DynamicBackground dynamicBackground = Data as DynamicBackground;
            StaticBackground  staticBackground  = Data as StaticBackground;
            BackgroundObject  backgroundObject  = Data as BackgroundObject;

            if (dynamicBackground != null)
            {
                RenderDynamicBackground(dynamicBackground, Alpha, Scale);
            }

            if (staticBackground != null)
            {
                RenderStaticBackground(staticBackground, Alpha, Scale);
            }

            if (backgroundObject != null)
            {
                RenderBackgroundObject(backgroundObject);
            }
        }
Exemplo n.º 8
0
        public CurrentRoute(BaseRenderer renderer)
        {
            this.renderer = renderer;

            Tracks = new[] { new Track {
                                 Elements = new TrackElement[0]
                             } };
            Trains   = new AbstractTrain[0];
            Sections = new Section[0];
            Stations = new RouteStation[0];
            BogusPreTrainInstructions = new BogusPreTrainInstruction[0];
            PointsOfInterest          = new PointOfInterest[0];
            CurrentBackground         = new StaticBackground(null, 6, false);
            TargetBackground          = new StaticBackground(null, 6, false);
            NoFogStart           = 800.0f;
            NoFogEnd             = 1600.0f;
            PreviousFog          = new Fog(NoFogStart, NoFogEnd, Color24.Grey, 0.0);
            CurrentFog           = new Fog(NoFogStart, NoFogEnd, Color24.Grey, 0.5);
            NextFog              = new Fog(NoFogStart, NoFogEnd, Color24.Grey, 1.0);
            Atmosphere           = new Atmosphere();
            SecondsSinceMidnight = 0.0;
        }
Exemplo n.º 9
0
 public void BackgroundStartPopulatesModelPlaylistWhenUserConfigExistsTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var config = new UserConfiguration();
     config.ServerUrl = "test";
     config.User = "******";
     config.Password = "******";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     persister.SelectBy(Arg.Any<int>()).Returns(config);
     container.Register<IPersister<UserConfiguration>>().To(persister);
     var factory = Substitute.For<AmpacheSelectionFactory>();
     factory.AuthenticateToServer(config).Returns(x => (Authenticate)null);
     container.Register<IPersister<UserConfiguration>>();
     var target = new BackgroundHandle(config, path, factory, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     var exp = target.Model.Playlist;
     Assert.That(exp, Is.Not.Null);
 }
Exemplo n.º 10
0
        /// <summary>Updates the currently displayed background</summary>
        /// <param name="TimeElapsed">The time elapsed since the previous call to this function</param>
        /// <param name="GamePaused">Whether the game is currently paused</param>
        public void UpdateBackground(double TimeElapsed, bool GamePaused)
        {
            if (GamePaused)
            {
                //Don't update the transition whilst paused
                TimeElapsed = 0.0;
            }

            const float scale = 0.5f;

            // fog
            const float fogDistance = 600.0f;

            if (CurrentFog.Start < CurrentFog.End & CurrentFog.Start < fogDistance)
            {
                float ratio = (float)CurrentBackground.BackgroundImageDistance / fogDistance;

                renderer.OptionFog    = true;
                renderer.Fog.Start    = CurrentFog.Start * ratio * scale;
                renderer.Fog.End      = CurrentFog.End * ratio * scale;
                renderer.Fog.Color    = CurrentFog.Color;
                renderer.Fog.Density  = CurrentFog.Density;
                renderer.Fog.IsLinear = CurrentFog.IsLinear;
                if (!renderer.AvailableNewRenderer)
                {
                    renderer.Fog.SetForImmediateMode();
                }
            }
            else
            {
                renderer.OptionFog = false;
            }

            //Update the currently displayed background
            CurrentBackground.UpdateBackground(SecondsSinceMidnight, TimeElapsed, false);

            if (TargetBackground == null || TargetBackground == CurrentBackground)
            {
                //No target background, so call the render function
                renderer.Background.Render(CurrentBackground, scale);
                return;
            }

            //Update the target background
            if (TargetBackground is StaticBackground)
            {
                TargetBackground.Countdown += TimeElapsed;
            }

            TargetBackground.UpdateBackground(SecondsSinceMidnight, TimeElapsed, true);

            switch (TargetBackground.Mode)
            {
            //Render, switching on the transition mode
            case BackgroundTransitionMode.FadeIn:
                renderer.Background.Render(CurrentBackground, 1.0f, scale);
                renderer.Background.Render(TargetBackground, TargetBackground.CurrentAlpha, scale);
                break;

            case BackgroundTransitionMode.FadeOut:
                renderer.Background.Render(TargetBackground, 1.0f, scale);
                renderer.Background.Render(CurrentBackground, TargetBackground.CurrentAlpha, scale);
                break;
            }

            //If our target alpha is greater than or equal to 1.0f, the background is fully displayed
            if (TargetBackground.CurrentAlpha >= 1.0f)
            {
                //Set the current background to the target & reset target to null
                CurrentBackground = TargetBackground;
                TargetBackground  = null;
            }
        }
Exemplo n.º 11
0
        /// <summary>Updates the currently displayed background</summary>
        /// <param name="TimeElapsed">The time elapsed since the previous call to this function</param>
        /// <param name="gamePaused">Whether the game is currently paused</param>
        public static void UpdateBackground(double TimeElapsed, bool gamePaused)
        {
            if (gamePaused)
            {
                //Don't update the transition whilst paused
                TimeElapsed = 0.0;
            }
            const float scale = 0.5f, inv255 = 1.0f / 255.0f;
            // fog
            const float fogdistance = 600.0f;

            if (CurrentFog.Start < CurrentFog.End & CurrentFog.Start < fogdistance)
            {
                float cr = inv255 * (float)CurrentFog.Color.R;
                float cg = inv255 * (float)CurrentFog.Color.G;
                float cb = inv255 * (float)CurrentFog.Color.B;
                if (!Renderer.FogEnabled)
                {
                    GL.Fog(FogParameter.FogMode, (int)FogMode.Linear);
                }
                float ratio = (float)Backgrounds.BackgroundImageDistance / fogdistance;
                GL.Fog(FogParameter.FogStart, CurrentFog.Start * ratio * scale);
                GL.Fog(FogParameter.FogEnd, CurrentFog.End * ratio * scale);
                GL.Fog(FogParameter.FogColor, new float[] { cr, cg, cb, 1.0f });
                if (!Renderer.FogEnabled)
                {
                    GL.Enable(EnableCap.Fog); Renderer.FogEnabled = true;
                }
            }
            else if (Renderer.FogEnabled)
            {
                GL.Disable(EnableCap.Fog); Renderer.FogEnabled = false;
            }
            //Update the currently displayed background
            CurrentBackground.UpdateBackground(TimeElapsed, false);
            if (TargetBackground == null || TargetBackground == CurrentBackground)
            {
                //No target background, so call the render function
                CurrentBackground.RenderBackground(scale);
                return;
            }
            //Update the target background
            if (TargetBackground is StaticBackground)
            {
                TargetBackground.Countdown += TimeElapsed;
            }
            TargetBackground.UpdateBackground(TimeElapsed, true);
            switch (TargetBackground.Mode)
            {
            //Render, switching on the transition mode
            case BackgroundTransitionMode.FadeIn:
                CurrentBackground.RenderBackground(1.0f, scale);
                Renderer.SetAlphaFunc(AlphaFunction.Greater, 0.0f);
                TargetBackground.RenderBackground(TargetBackground.CurrentAlpha, scale);
                break;

            case BackgroundTransitionMode.FadeOut:
                TargetBackground.RenderBackground(1.0f, scale);
                Renderer.SetAlphaFunc(AlphaFunction.Greater, 0.0f);
                CurrentBackground.RenderBackground(TargetBackground.CurrentAlpha, scale);
                break;
            }
            //If our target alpha is greater than or equal to 1.0f, the background is fully displayed
            if (TargetBackground.CurrentAlpha >= 1.0f)
            {
                //Set the current background to the target & reset target to null
                CurrentBackground = TargetBackground;
                TargetBackground  = null;
            }
        }
Exemplo n.º 12
0
 public void BackgroundListensForPlayingChangesAndStartsShutOffTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     persister.SelectBy(Arg.Any<int>()).Returns(new UserConfiguration { ServerUrl = string.Empty });
     var target = new BackgroundHandle(null, path, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     System.Threading.Thread.Sleep(100);
     target.Model.IsPlaying = true;
     Assert.That(target.StopShutOffCallCount, Is.EqualTo(1));
     target.Model.IsPlaying = false;
     Assert.That(target.AutoShutOffCallCount, Is.EqualTo(2));
 }
Exemplo n.º 13
0
 public void BackgroundStartPopulatesModelFactoryWhenUserConfigExistsTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var config = new UserConfiguration();
     config.ServerUrl = "test";
     config.User = "******";
     config.Password = "******";
     var persister = Substitute.For<IPersister<AmpacheSong>>();
     container.Register<IPersister<AmpacheSong>>().To(persister);
     var configpersist = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(configpersist);
     configpersist.SelectBy(Arg.Any<int>()).Returns(config);
     var sngs = new List<AmpacheSong>();
     sngs.Add(new AmpacheSong(){Url = "http://test"});
     sngs.Add(new AmpacheSong(){Url = "http://test"});
     persister.SelectAll().Returns(sngs);
     var factory = Substitute.For<AmpacheSelectionFactory>();
     factory.AuthenticateToServer(config).Returns(x => (Authenticate)null);
     var mockHs = new MockHandShake();
     mockHs.Setup("test", "test");
     factory.Handshake.Returns(mockHs);
     var target = new BackgroundHandle(config, path, factory, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     System.Threading.Thread.Sleep(100);
     var exp = target.Model.Factory;
     Assert.That(exp, Is.Not.Null);
     var userMessage = target.Model.UserMessage;
     Assert.That(userMessage, Is.Not.Null);
     Assert.That(userMessage, Is.EqualTo(BackgroundHandle.SUCCESS_MESSAGE));
     Assert.That(target.Model.Playlist, Is.EquivalentTo(sngs));
 }
Exemplo n.º 14
0
 public void BackgroundStartPopulatesModelFactoryWhenNoUserConfigExistsTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     persister.SelectBy(Arg.Any<int>()).Returns(new UserConfiguration { ServerUrl = string.Empty });
     var target = new BackgroundHandle(null, path, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     var exp = target.Model.Factory;
     Assert.That(exp, Is.Not.Null);
 }
Exemplo n.º 15
0
 public void BackgroundStartInitializesModelConfigurationTest()
 {
     var container = new Athena.IoC.Container();
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     persister.SelectBy(Arg.Any<int>()).Returns(new UserConfiguration { ServerUrl = string.Empty });
     var target = new BackgroundHandle(null, null, new AmpacheModel(), container);
     var initial = target.Model;
     target.Start(new MemoryStream());
     var after = target.Model.Configuration;
     Assert.That(after, Is.Not.Null);
 }
Exemplo n.º 16
0
 public void BackgroundStartFailsWithNullParameterTest()
 {
     var target = new BackgroundHandle(null, null);
     target.Start(null);
     Assert.Fail();
 }
Exemplo n.º 17
0
 public void BackgroundStartBeginsAutoShutOffTest()
 {
     var container = new Athena.IoC.Container();
     string path = "myartpath";
     var persister = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(persister);
     persister.SelectBy(Arg.Any<int>()).Returns(new UserConfiguration { ServerUrl = string.Empty });
     var target = new BackgroundHandle(null, path, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     Assert.That(target.AutoShutOffCallCount, Is.EqualTo(1));
 }
Exemplo n.º 18
0
 public void BackgroundListensForPlaylistChangesTest()
 {
     var container = new Athena.IoC.Container();
     var persister = Substitute.For<IPersister<AmpacheSong>>();
     var sng = new AmpacheSong();
     container.Register<IPersister<AmpacheSong>>().To(persister);
     var usrp = Substitute.For<IPersister<UserConfiguration>>();
     container.Register<IPersister<UserConfiguration>>().To(usrp);
     bool persisted = false;
     persister.When(p => p.Persist(sng)).Do(p => persisted = true);
     string path = "myartpath";
     var target = new BackgroundHandle(null, path, new AmpacheModel(), container);
     target.Start(new MemoryStream());
     System.Threading.Thread.Sleep(100);
     var sngs = new List<AmpacheSong>();
     sngs.Add(sng);
     target.Model.Playlist = sngs;
     Assert.That(persisted, Is.True);
 }