Exemplo n.º 1
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.º 2
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;
            }
        }