Beispiel #1
0
        public void Updated(int value, int count)
        {
            RenderTarget2D renderTarget = Display.RenderTarget;

            Display.RenderTarget = m_renderTarget;
            Display.Clear(Color.Transparent);
            try
            {
                string numstr  = count.ToString();
                int    usedw   = numstr.Length * 16;
                int    padding = (256 - usedw) / 2;
                //base x 128 base y 384 efont 16 all w 256
                //base x 4 y 12
                FontBatch2D fontBatch = primitivesRenderer2D.FontBatch(ILibrary.m_font, 1, DepthStencilState.None, null, BlendState.Opaque, SamplerState.PointClamp);
                fontBatch.QueueText($"{numstr}", new Vector2(128 + padding, 384), 0f, Color.White, TextAnchor.HorizontalCenter, new Vector2(4, 4), Vector2.Zero);                //不是纹理坐标
                PrimitivesRenderer3D mprimitivesRenderer3D = new PrimitivesRenderer3D();
                int   id    = Terrain.ExtractContents(value);
                Block block = BlocksManager.Blocks[id];
                DrawBlockEnvironmentData blockEnvironmentData = new DrawBlockEnvironmentData();
                Matrix m2 = Matrix.CreateLookAt(block.GetIconViewOffset(value, blockEnvironmentData), Vector3.Zero, Vector3.UnitY);
                m2 *= Matrix.CreateOrthographic(3.6f, 3.6f, -10f - 1f * 1f, 10f - 1f * 1f);
                m2 *= Matrix.CreateTranslation(0, 0.2f, 0);
                Matrix matrix = Matrix.Identity;
                blockEnvironmentData.ViewProjectionMatrix = m2;
                block.DrawBlock(mprimitivesRenderer3D, value, Color.White, 0.8f, ref matrix, blockEnvironmentData);
                mprimitivesRenderer3D.Flush(matrix);
                primitivesRenderer2D.Flush();
                Display.RenderTarget = renderTarget;
            }
            catch (Exception e) {
                Log.Information("error display" + e.ToString());
            }
        }
Beispiel #2
0
        public override void Update(float dt)
        {
            dt = MathUtils.Min(dt, 0.1f);
            Vector3 zero = Vector3.Zero;

            if (Keyboard.IsKeyDown(Key.A))
            {
                zero.X = -1f;
            }
            if (Keyboard.IsKeyDown(Key.D))
            {
                zero.X = 1f;
            }
            if (Keyboard.IsKeyDown(Key.W))
            {
                zero.Z = 1f;
            }
            if (Keyboard.IsKeyDown(Key.S))
            {
                zero.Z = -1f;
            }
            Vector2 vector    = 0.03f * new Vector2(Mouse.MouseMovement.X, -Mouse.MouseMovement.Y);
            bool    num       = Keyboard.IsKeyDown(Key.Shift);
            bool    flag      = Keyboard.IsKeyDown(Key.Control);
            Vector3 direction = m_direction;
            Vector3 unitY     = Vector3.UnitY;
            Vector3 vector2   = Vector3.Normalize(Vector3.Cross(direction, unitY));
            float   num2      = 8f;

            if (num)
            {
                num2 *= 10f;
            }
            if (flag)
            {
                num2 /= 10f;
            }
            Vector3 zero2 = Vector3.Zero;

            zero2      += num2 * zero.X * vector2;
            zero2      += num2 * zero.Y * unitY;
            zero2      += num2 * zero.Z * direction;
            m_position += zero2 * dt;
            m_direction = Vector3.Transform(m_direction, Matrix.CreateFromAxisAngle(unitY, -4f * vector.X * dt));
            m_direction = Vector3.Transform(m_direction, Matrix.CreateFromAxisAngle(vector2, 4f * vector.Y * dt));
            SetupPerspectiveCamera(m_position, m_direction, Vector3.UnitY);
            Vector2     v           = ViewportSize / 2f;
            FlatBatch2D flatBatch2D = PrimitivesRenderer2D.FlatBatch(0, DepthStencilState.None);
            int         count       = flatBatch2D.LineVertices.Count;

            flatBatch2D.QueueLine(v - new Vector2(5f, 0f), v + new Vector2(5f, 0f), 0f, Color.White);
            flatBatch2D.QueueLine(v - new Vector2(0f, 5f), v + new Vector2(0f, 5f), 0f, Color.White);
            flatBatch2D.TransformLines(ViewportMatrix, count);
            PrimitivesRenderer2D.Flush();
        }
        public static void Draw()
        {
            Vector2  scale    = new Vector2(MathUtils.Round(MathUtils.Clamp(ScreensManager.RootWidget.GlobalScale, 1f, 4f)));
            Viewport viewport = Display.Viewport;

            if (SettingsManager.DisplayFpsCounter)
            {
                if (Time.PeriodicEvent(1.0, 0.0))
                {
                    m_statsString = $"CPUMEM {(float)TotalMemoryUsed / 1024f / 1024f:0}MB, GPUMEM {(float)TotalGpuMemoryUsed / 1024f / 1024f:0}MB, CPU {AverageCpuFrameTime / AverageFrameTime * 100f:0}%, FPS {1f / AverageFrameTime:0.0}";
                }
                m_primitivesRenderer.FontBatch(BitmapFont.DebugFont, 0, null, null, null, SamplerState.PointClamp).QueueText(m_statsString, new Vector2(viewport.Width, 0f), 0f, Color.White, TextAnchor.Right, scale, Vector2.Zero);
            }
            if (SettingsManager.DisplayFpsRibbon)
            {
                float num  = ((float)viewport.Width / scale.X > 480f) ? (scale.X * 2f) : scale.X;
                float num2 = (float)viewport.Height / -0.1f;
                float num3 = viewport.Height - 1;
                float s    = 0.5f;
                int   num4 = MathUtils.Max((int)((float)viewport.Width / num), 1);
                if (m_frameData == null || m_frameData.Length != num4)
                {
                    m_frameData      = new FrameData[num4];
                    m_frameDataIndex = 0;
                }
                m_frameData[m_frameDataIndex] = new FrameData
                {
                    CpuTime   = Program.LastCpuFrameTime,
                    TotalTime = Program.LastFrameTime
                };
                m_frameDataIndex = (m_frameDataIndex + 1) % m_frameData.Length;
                FlatBatch2D flatBatch2D = m_primitivesRenderer.FlatBatch();
                Color       color       = Color.Orange * s;
                Color       color2      = Color.Red * s;
                for (int num5 = m_frameData.Length - 1; num5 >= 0; num5--)
                {
                    int       num6      = (num5 - m_frameData.Length + 1 + m_frameDataIndex + m_frameData.Length) % m_frameData.Length;
                    FrameData frameData = m_frameData[num6];
                    float     x         = (float)num5 * num;
                    float     x2        = (float)(num5 + 1) * num;
                    flatBatch2D.QueueQuad(new Vector2(x, num3), new Vector2(x2, num3 + frameData.CpuTime * num2), 0f, color);
                    flatBatch2D.QueueQuad(new Vector2(x, num3 + frameData.CpuTime * num2), new Vector2(x2, num3 + frameData.TotalTime * num2), 0f, color2);
                }
                flatBatch2D.QueueLine(new Vector2(0f, num3 + 0.0166666675f * num2), new Vector2(viewport.Width, num3 + 0.0166666675f * num2), 0f, Color.Green);
            }
            else
            {
                m_frameData = null;
            }
            m_primitivesRenderer.Flush();
        }
Beispiel #4
0
            public void RenderDrawItems()
            {
                Rectangle scissorRectangle = Display.ScissorRectangle;
                int       num = 0;

                foreach (DrawItem drawItem in m_drawItems)
                {
                    if (LayersLimit >= 0 && drawItem.Layer > LayersLimit)
                    {
                        break;
                    }
                    if (drawItem.Layer != num)
                    {
                        num = drawItem.Layer;
                        PrimitivesRenderer3D.Flush(Matrix.Identity);
                        PrimitivesRenderer2D.Flush();
                    }
                    if (drawItem.Widget != null)
                    {
                        if (drawItem.IsOverdraw)
                        {
                            drawItem.Widget.Overdraw(this);
                        }
                        else
                        {
                            drawItem.Widget.Draw(this);
                        }
                    }
                    else
                    {
                        Display.ScissorRectangle = Rectangle.Intersection(scissorRectangle, drawItem.ScissorRectangle.Value);
                    }
                }
                PrimitivesRenderer3D.Flush(Matrix.Identity);
                PrimitivesRenderer2D.Flush();
                Display.ScissorRectangle = scissorRectangle;
                CursorPrimitivesRenderer2D.Flush();
            }
 public static void Draw()
 {
     if (VrManager.IsVrStarted)
     {
         Point2 point = new Point2(Display.Viewport.Width, Display.Viewport.Height);
         if (MathUtils.Max(point.X, point.Y) == 0)
         {
             point = new Point2(1500, 1000);
         }
         while (MathUtils.Max(point.X, point.Y) < 1024)
         {
             point *= 2;
         }
         if (m_uiRenderTarget == null || m_uiRenderTarget.Width != point.X || m_uiRenderTarget.Height != point.Y)
         {
             Utilities.Dispose(ref m_uiRenderTarget);
             m_uiRenderTarget = new RenderTarget2D(point.X, point.Y, 1, ColorFormat.Rgba8888, DepthFormat.Depth24Stencil8);
         }
         RenderTarget2D renderTarget = Display.RenderTarget;
         try
         {
             Display.RenderTarget = m_uiRenderTarget;
             LayoutAndDrawWidgets();
             Display.RenderTarget = VrManager.VrRenderTarget;
             for (VrEye vrEye = VrEye.Left; vrEye <= VrEye.Right; vrEye++)
             {
                 Display.Clear(Color.Black, 1f, 0);
                 DrawVrBackground();
                 DrawVrQuad();
                 Matrix hmdMatrix        = VrManager.HmdMatrix;
                 Matrix m                = Matrix.Invert(VrManager.GetEyeToHeadTransform(vrEye));
                 Matrix m2               = Matrix.Invert(hmdMatrix);
                 Matrix projectionMatrix = VrManager.GetProjectionMatrix(vrEye, 0.1f, 1024f);
                 m_pr3.Flush(m2 * m * projectionMatrix);
                 VrManager.SubmitEyeTexture(vrEye, VrManager.VrRenderTarget);
             }
         }
         finally
         {
             Display.RenderTarget = renderTarget;
         }
         m_pr2.TexturedBatch(m_uiRenderTarget, useAlphaTest: false, 0, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.Opaque, SamplerState.PointClamp).QueueQuad(new Vector2(0f, 0f), new Vector2(m_uiRenderTarget.Width, m_uiRenderTarget.Height), 0f, new Vector2(0f, 0f), new Vector2(1f, 1f), Color.White);
         m_pr2.Flush();
     }
     else
     {
         Utilities.Dispose(ref m_uiRenderTarget);
         LayoutAndDrawWidgets();
     }
 }
 public void Update(float dt)
 {
     if (!DisableTextureAnimation && !m_subsystemTime.FixedTimeStep.HasValue)
     {
         float dt2 = (float)MathUtils.Min(m_subsystemTime.GameTime - m_lastAnimateGameTime, 1.0);
         m_lastAnimateGameTime = m_subsystemTime.GameTime;
         Texture2D blocksTexture = m_subsystemBlocksTexture.BlocksTexture;
         if (m_animatedBlocksTexture == null || m_animatedBlocksTexture.Width != blocksTexture.Width || m_animatedBlocksTexture.Height != blocksTexture.Height || m_animatedBlocksTexture.MipLevelsCount > 1 != SettingsManager.TerrainMipmapsEnabled)
         {
             Utilities.Dispose(ref m_animatedBlocksTexture);
             m_animatedBlocksTexture = new RenderTarget2D(blocksTexture.Width, blocksTexture.Height, (!SettingsManager.TerrainMipmapsEnabled) ? 1 : 4, ColorFormat.Rgba8888, DepthFormat.None);
         }
         Rectangle      scissorRectangle = Display.ScissorRectangle;
         RenderTarget2D renderTarget     = Display.RenderTarget;
         Display.RenderTarget = m_animatedBlocksTexture;
         try
         {
             Display.Clear(new Vector4(Color.Transparent));
             m_primitivesRenderer.TexturedBatch(blocksTexture, useAlphaTest: false, -1, DepthStencilState.None, RasterizerState.CullNone, BlendState.Opaque, SamplerState.PointClamp).QueueQuad(new Vector2(0f, 0f), new Vector2(m_animatedBlocksTexture.Width, m_animatedBlocksTexture.Height), 0f, Vector2.Zero, Vector2.One, Color.White);
             AnimateWaterBlocksTexture();
             AnimateMagmaBlocksTexture();
             m_primitivesRenderer.Flush();
             Display.ScissorRectangle = AnimateFireBlocksTexture(dt2);
             m_primitivesRenderer.Flush();
         }
         finally
         {
             Display.RenderTarget     = renderTarget;
             Display.ScissorRectangle = scissorRectangle;
         }
         if (SettingsManager.TerrainMipmapsEnabled && Time.FrameIndex % 2 == 0)
         {
             m_animatedBlocksTexture.GenerateMipMaps();
         }
     }
 }
        public void Draw(Camera camera, int drawOrder)
        {
            this.cam = camera;
            if (Point1.HasValue && Point2.HasValue && WorldEditMenu.IsChecked) // Выделение зоны между точками 1 и 2
            {
                int startX = Math.Min(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                int endX   = Math.Max(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                int startY = Math.Min(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                int endY   = Math.Max(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                int startZ = Math.Min(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);
                int endZ   = Math.Max(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);

                PrimitivesRenderer3D PrimitivesRenderer3D = new PrimitivesRenderer3D();
                Vector3     pointStart  = new Vector3(startX, startY, startZ);
                Vector3     pointEnd    = new Vector3(endX + 1, endY + 1, endZ + 1);
                BoundingBox boundingBox = new BoundingBox(pointStart, pointEnd);
                PrimitivesRenderer3D.FlatBatch(-1, DepthStencilState.None, (RasterizerState)null, (BlendState)null).QueueBoundingBox(boundingBox, Color.Green);
                PrimitivesRenderer3D.Flush(cam.ViewProjectionMatrix, true);
            }

            if (Point3.HasValue && WorldEditMenu.IsChecked) // Выделение зоны вставки
            {
                int startX = Math.Min(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                int endX   = Math.Max(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                int startY = Math.Min(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                int endY   = Math.Max(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                int startZ = Math.Min(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);
                int endZ   = Math.Max(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);

                startX += Point3.Value.CellFace.Point.X - Point1.Value.CellFace.Point.X;
                startY += Point3.Value.CellFace.Point.Y - Point1.Value.CellFace.Point.Y;
                startZ += Point3.Value.CellFace.Point.Z - Point1.Value.CellFace.Point.Z;
                endX   += Point3.Value.CellFace.Point.X - Point1.Value.CellFace.Point.X;
                endY   += Point3.Value.CellFace.Point.Y - Point1.Value.CellFace.Point.Y;
                endZ   += Point3.Value.CellFace.Point.Z - Point1.Value.CellFace.Point.Z;

                PrimitivesRenderer3D primitivesRenderer3D = new PrimitivesRenderer3D();
                Vector3     pointStart  = new Vector3(startX, startY, startZ);
                Vector3     pointEnd    = new Vector3(endX + 1, endY + 1, endZ + 1);
                BoundingBox boundingBox = new BoundingBox(pointStart, pointEnd);
                primitivesRenderer3D.FlatBatch(-1, DepthStencilState.None, (RasterizerState)null, (BlendState)null).QueueBoundingBox(boundingBox, Color.Red);
                primitivesRenderer3D.Flush(cam.ViewProjectionMatrix, true);
            }
            PrimitivesRenderer3D.Flush(camera.ViewProjectionMatrix, true, int.MaxValue);
            PrimitivesRenderer2D.Flush(true);
        }
Beispiel #8
0
 public void Draw(Camera camera, int drawOrder)
 {
     if (camera.GameWidget != m_componentPlayer.GameWidget)
     {
         return;
     }
     if (m_componentPlayer.ComponentHealth.Health > 0f && m_componentPlayer.ComponentGui.ControlsContainerWidget.IsVisible)
     {
         if (IsSightsVisible)
         {
             Texture2D       texture         = ContentManager.Get <Texture2D>("Textures/Gui/Sights");
             float           s               = (!camera.Eye.HasValue) ? 8f : 2.5f;
             Vector3         v               = m_sightsPosition + m_sightsDirection * 50f;
             Vector3         vector          = Vector3.Normalize(Vector3.Cross(m_sightsDirection, Vector3.UnitY));
             Vector3         v2              = Vector3.Normalize(Vector3.Cross(m_sightsDirection, vector));
             Vector3         p               = v + s * (-vector - v2);
             Vector3         p2              = v + s * (vector - v2);
             Vector3         p3              = v + s * (vector + v2);
             Vector3         p4              = v + s * (-vector + v2);
             TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(texture, useAlphaTest: false, 0, DepthStencilState.None);
             int             count           = texturedBatch3D.TriangleVertices.Count;
             texturedBatch3D.QueueQuad(p, p2, p3, p4, new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(1f, 1f), new Vector2(0f, 1f), Color.White);
             texturedBatch3D.TransformTriangles(camera.ViewMatrix, count);
         }
         if (!camera.Eye.HasValue && !camera.UsesMovementControls && !IsSightsVisible && (SettingsManager.LookControlMode == LookControlMode.SplitTouch || !m_componentPlayer.ComponentInput.IsControlledByTouch))
         {
             Subtexture      subtexture       = ContentManager.Get <Subtexture>("Textures/Atlas/Crosshair");
             float           s2               = 1.25f;
             Vector3         v3               = camera.ViewPosition + camera.ViewDirection * 50f;
             Vector3         vector2          = Vector3.Normalize(Vector3.Cross(camera.ViewDirection, Vector3.UnitY));
             Vector3         v4               = Vector3.Normalize(Vector3.Cross(camera.ViewDirection, vector2));
             Vector3         p5               = v3 + s2 * (-vector2 - v4);
             Vector3         p6               = v3 + s2 * (vector2 - v4);
             Vector3         p7               = v3 + s2 * (vector2 + v4);
             Vector3         p8               = v3 + s2 * (-vector2 + v4);
             TexturedBatch3D texturedBatch3D2 = m_primitivesRenderer3D.TexturedBatch(subtexture.Texture, useAlphaTest: false, 0, DepthStencilState.None);
             int             count2           = texturedBatch3D2.TriangleVertices.Count;
             texturedBatch3D2.QueueQuad(p5, p6, p7, p8, new Vector2(subtexture.TopLeft.X, subtexture.TopLeft.Y), new Vector2(subtexture.BottomRight.X, subtexture.TopLeft.Y), new Vector2(subtexture.BottomRight.X, subtexture.BottomRight.Y), new Vector2(subtexture.TopLeft.X, subtexture.BottomRight.Y), Color.White);
             texturedBatch3D2.TransformTriangles(camera.ViewMatrix, count2);
         }
     }
     m_primitivesRenderer2D.Flush();
     m_primitivesRenderer3D.Flush(camera.ProjectionMatrix);
 }
Beispiel #9
0
 public void Draw(Camera camera, int drawOrder)
 {
     if (drawOrder == m_drawOrders[0])
     {
         ViewUnderWaterDepth = 0f;
         ViewUnderMagmaDepth = 0f;
         Vector3    viewPosition = camera.ViewPosition;
         int        x            = Terrain.ToCell(viewPosition.X);
         int        y            = Terrain.ToCell(viewPosition.Y);
         int        z            = Terrain.ToCell(viewPosition.Z);
         FluidBlock surfaceFluidBlock;
         float?     surfaceHeight = m_subsystemFluidBlockBehavior.GetSurfaceHeight(x, y, z, out surfaceFluidBlock);
         if (surfaceHeight.HasValue)
         {
             if (surfaceFluidBlock is WaterBlock)
             {
                 ViewUnderWaterDepth = surfaceHeight.Value + 0.1f - viewPosition.Y;
             }
             else if (surfaceFluidBlock is MagmaBlock)
             {
                 ViewUnderMagmaDepth = surfaceHeight.Value + 1f - viewPosition.Y;
             }
         }
         if (ViewUnderWaterDepth > 0f)
         {
             int   seasonalHumidity = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
             int   temperature      = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y);
             Color c    = BlockColorsMap.WaterColorsMap.Lookup(temperature, seasonalHumidity);
             float num  = MathUtils.Lerp(1f, 0.5f, (float)seasonalHumidity / 15f);
             float num2 = MathUtils.Lerp(1f, 0.2f, MathUtils.Saturate(0.075f * (ViewUnderWaterDepth - 2f)));
             float num3 = MathUtils.Lerp(0.33f, 1f, SkyLightIntensity);
             m_viewFogRange.X           = 0f;
             m_viewFogRange.Y           = MathUtils.Lerp(4f, 10f, num * num2 * num3);
             m_viewFogColor             = Color.MultiplyColorOnly(c, 0.66f * num2 * num3);
             VisibilityRangeYMultiplier = 1f;
             m_viewIsSkyVisible         = false;
         }
         else if (ViewUnderMagmaDepth > 0f)
         {
             m_viewFogRange.X           = 0f;
             m_viewFogRange.Y           = 0.1f;
             m_viewFogColor             = new Color(255, 80, 0);
             VisibilityRangeYMultiplier = 1f;
             m_viewIsSkyVisible         = false;
         }
         else
         {
             float num4 = 1024f;
             float num5 = 128f;
             int   seasonalTemperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(Terrain.ToCell(viewPosition.X), Terrain.ToCell(viewPosition.Z));
             float num6 = MathUtils.Lerp(0.5f, 0f, m_subsystemWeather.GlobalPrecipitationIntensity);
             float num7 = MathUtils.Lerp(1f, 0.8f, m_subsystemWeather.GlobalPrecipitationIntensity);
             m_viewFogRange.X           = VisibilityRange * num6;
             m_viewFogRange.Y           = VisibilityRange * num7;
             m_viewFogColor             = CalculateSkyColor(new Vector3(camera.ViewDirection.X, 0f, camera.ViewDirection.Z), m_subsystemTimeOfDay.TimeOfDay, m_subsystemWeather.GlobalPrecipitationIntensity, seasonalTemperature);
             VisibilityRangeYMultiplier = MathUtils.Lerp(VisibilityRange / num4, VisibilityRange / num5, MathUtils.Pow(m_subsystemWeather.GlobalPrecipitationIntensity, 4f));
             m_viewIsSkyVisible         = true;
         }
         if (!FogEnabled)
         {
             m_viewFogRange = new Vector2(100000f, 100000f);
         }
         if (!DrawSkyEnabled || !m_viewIsSkyVisible || SettingsManager.SkyRenderingMode == SkyRenderingMode.Disabled)
         {
             FlatBatch2D flatBatch2D = m_primitivesRenderer2d.FlatBatch(-1, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.Opaque);
             int         count       = flatBatch2D.TriangleVertices.Count;
             flatBatch2D.QueueQuad(Vector2.Zero, camera.ViewportSize, 0f, m_viewFogColor);
             flatBatch2D.TransformTriangles(camera.ViewportMatrix, count);
             m_primitivesRenderer2d.Flush();
         }
     }
     else if (drawOrder == m_drawOrders[1])
     {
         if (DrawSkyEnabled && m_viewIsSkyVisible && SettingsManager.SkyRenderingMode != SkyRenderingMode.Disabled)
         {
             DrawSkydome(camera);
             DrawStars(camera);
             DrawSunAndMoon(camera);
             DrawClouds(camera);
             m_primitivesRenderer3d.Flush(camera.ViewProjectionMatrix);
         }
     }
     else
     {
         DrawLightning(camera);
         m_primitivesRenderer3d.Flush(camera.ViewProjectionMatrix);
     }
 }
Beispiel #10
0
        public void UpdateRenderTarget()
        {
            bool flag = false;

            foreach (GameWidget gameWidget in m_subsystemViews.GameWidgets)
            {
                bool flag2 = false;
                foreach (Vector3 lastUpdatePosition in m_lastUpdatePositions)
                {
                    if (Vector3.DistanceSquared(gameWidget.ActiveCamera.ViewPosition, lastUpdatePosition) < 4f)
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                return;
            }
            m_lastUpdatePositions.Clear();
            m_lastUpdatePositions.AddRange(m_subsystemViews.GameWidgets.Select((GameWidget v) => v.ActiveCamera.ViewPosition));
            m_nearTexts.Clear();
            foreach (TextData value in m_textsByPoint.Values)
            {
                Point3 point = value.Point;
                float  num   = m_subsystemViews.CalculateSquaredDistanceFromNearestView(new Vector3(point));
                if (num <= 400f)
                {
                    value.Distance = num;
                    m_nearTexts.Add(value);
                }
            }
            m_nearTexts.Sort((TextData d1, TextData d2) => Comparer <float> .Default.Compare(d1.Distance, d2.Distance));
            if (m_nearTexts.Count > 32)
            {
                m_nearTexts.RemoveRange(32, m_nearTexts.Count - 32);
            }
            foreach (TextData nearText in m_nearTexts)
            {
                nearText.ToBeRenderedFrame = Time.FrameIndex;
            }
            bool flag3 = false;

            for (int i = 0; i < MathUtils.Min(m_nearTexts.Count, 32); i++)
            {
                TextData textData = m_nearTexts[i];
                if (textData.TextureLocation.HasValue)
                {
                    continue;
                }
                int num2 = m_textureLocations.FirstIndex((TextData d) => d == null);
                if (num2 < 0)
                {
                    num2 = m_textureLocations.FirstIndex((TextData d) => d.ToBeRenderedFrame != Time.FrameIndex);
                }
                if (num2 >= 0)
                {
                    TextData textData2 = m_textureLocations[num2];
                    if (textData2 != null)
                    {
                        textData2.TextureLocation = null;
                        m_textureLocations[num2]  = null;
                    }
                    m_textureLocations[num2] = textData;
                    textData.TextureLocation = num2;
                    flag3 = true;
                }
            }
            if (flag3)
            {
                RenderTarget2D renderTarget = Display.RenderTarget;
                Display.RenderTarget = m_renderTarget;
                try
                {
                    Display.Clear(new Vector4(Color.Transparent));
                    FlatBatch2D flatBatch = m_primitivesRenderer2D.FlatBatch(0, DepthStencilState.None, null, BlendState.Opaque);

                    FontBatch2D fontBatch = m_primitivesRenderer2D.FontBatch(m_font, 1, DepthStencilState.None, null, BlendState.Opaque, SamplerState.PointClamp);
                    for (int j = 0; j < m_textureLocations.Length; j++)
                    {
                        TextData textData3 = m_textureLocations[j];
                        if (textData3 != null)
                        {
                            RenderText(fontBatch, flatBatch, textData3);
                        }
                    }
                    m_primitivesRenderer2D.Flush();
                }
                finally
                {
                    Display.RenderTarget = renderTarget;
                }
            }
        }
Beispiel #11
0
 public void UpdateRenderTargets()
 {
     if (m_skinTexture == null || m_componentPlayer.PlayerData.CharacterSkinName != m_skinTextureName)
     {
         m_skinTexture     = CharacterSkinsManager.LoadTexture(m_componentPlayer.PlayerData.CharacterSkinName);
         m_skinTextureName = m_componentPlayer.PlayerData.CharacterSkinName;
         Utilities.Dispose(ref m_innerClothedTexture);
         Utilities.Dispose(ref m_outerClothedTexture);
     }
     if (m_innerClothedTexture == null || m_innerClothedTexture.Width != m_skinTexture.Width || m_innerClothedTexture.Height != m_skinTexture.Height)
     {
         m_innerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentHumanModel.TextureOverride = m_innerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (m_outerClothedTexture == null || m_outerClothedTexture.Width != m_skinTexture.Width || m_outerClothedTexture.Height != m_skinTexture.Height)
     {
         m_outerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentOuterClothingModel.TextureOverride = m_outerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (DrawClothedTexture && !m_clothedTexturesValid)
     {
         m_clothedTexturesValid = true;
         Rectangle      scissorRectangle = Display.ScissorRectangle;
         RenderTarget2D renderTarget     = Display.RenderTarget;
         try
         {
             Display.RenderTarget = m_innerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             int             num             = 0;
             TexturedBatch2D texturedBatch2D = m_primitivesRenderer.TexturedBatch(m_skinTexture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
             texturedBatch2D.QueueQuad(Vector2.Zero, new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, Color.White);
             ClothingSlot[] innerSlotsOrder = m_innerSlotsOrder;
             foreach (ClothingSlot slot in innerSlotsOrder)
             {
                 foreach (int clothe in GetClothes(slot))
                 {
                     int          data         = Terrain.ExtractData(clothe);
                     MekClothData clothingData = MekClothingBlock.GetClothingData(data);
                     Color        fabricColor  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (!clothingData.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
             Display.RenderTarget = m_outerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             num             = 0;
             innerSlotsOrder = m_outerSlotsOrder;
             foreach (ClothingSlot slot2 in innerSlotsOrder)
             {
                 foreach (int clothe2 in GetClothes(slot2))
                 {
                     int          data2         = Terrain.ExtractData(clothe2);
                     ClothingData clothingData2 = ClothingBlock.GetClothingData(data2);
                     Color        fabricColor2  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data2));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData2.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (clothingData2.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_outerClothedTexture.Width, m_outerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor2);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
         }
         finally
         {
             Display.RenderTarget     = renderTarget;
             Display.ScissorRectangle = scissorRectangle;
         }
     }
 }
Beispiel #12
0
 public static void Capture(int width, int height, string filename)
 {
     if (GameManager.Project != null)
     {
         using (RenderTarget2D renderTarget2D = new RenderTarget2D(width, height, 1, ColorFormat.Rgba8888, DepthFormat.Depth24Stencil8))
         {
             RenderTarget2D renderTarget = Display.RenderTarget;
             Dictionary <ComponentGui, bool> dictionary = new Dictionary <ComponentGui, bool>();
             ResolutionMode resolutionMode = ResolutionMode.High;
             try
             {
                 if (!SettingsManager.ShowGuiInScreenshots)
                 {
                     foreach (ComponentPlayer componentPlayer in GameManager.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true).ComponentPlayers)
                     {
                         dictionary[componentPlayer.ComponentGui] = componentPlayer.ComponentGui.ControlsContainerWidget.IsVisible;
                         componentPlayer.ComponentGui.ControlsContainerWidget.IsVisible = false;
                     }
                 }
                 resolutionMode = SettingsManager.ResolutionMode;
                 SettingsManager.ResolutionMode = ResolutionMode.High;
                 Display.RenderTarget           = renderTarget2D;
                 ScreensManager.Draw();
                 if (SettingsManager.ShowLogoInScreenshots)
                 {
                     PrimitivesRenderer2D primitivesRenderer2D = new PrimitivesRenderer2D();
                     Texture2D            texture2D            = ContentManager.Get <Texture2D>("Textures/Gui/ScreenCaptureOverlay");
                     Vector2 vector = new Vector2((width - texture2D.Width) / 2, 0f);
                     Vector2 corner = vector + new Vector2(texture2D.Width, texture2D.Height);
                     primitivesRenderer2D.TexturedBatch(texture2D, useAlphaTest: false, 0, DepthStencilState.None).QueueQuad(vector, corner, 0f, new Vector2(0f, 0f), new Vector2(1f, 1f), Engine.Color.White);
                     primitivesRenderer2D.Flush();
                 }
             }
             finally
             {
                 Display.RenderTarget = renderTarget;
                 foreach (KeyValuePair <ComponentGui, bool> item in dictionary)
                 {
                     item.Key.ControlsContainerWidget.IsVisible = item.Value;
                 }
                 SettingsManager.ResolutionMode = resolutionMode;
             }
             if (!Storage.DirectoryExists(ModsManager.baseDir + "/ScreenCapture"))
             {
                 Storage.CreateDirectory(ModsManager.baseDir + "/ScreenCapture");
             }
             string path = Storage.CombinePaths(Storage.GetSystemPath(ModsManager.baseDir + "/ScreenCapture"), filename);
             using (FileStream stream = new FileStream(path, FileMode.Create))
             {
                 byte[] array = new byte[4 * renderTarget2D.Width * renderTarget2D.Height];
                 renderTarget2D.GetData(array, 0, new Rectangle(0, 0, renderTarget2D.Width, renderTarget2D.Height));
                 ByteBuffer src    = ByteBuffer.Wrap(array);
                 Bitmap     bitmap = Bitmap.CreateBitmap(renderTarget2D.Width, renderTarget2D.Height, Bitmap.Config.Argb8888);
                 bitmap.CopyPixelsFromBuffer(src);
                 bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
             }
             Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
             intent.SetData(Android.Net.Uri.FromFile(new Java.IO.File(path)));
             Window.Activity.SendBroadcast(intent);
         }
     }
 }
        public override void Draw(DrawContext dc)
        {
            if (Design == null)
            {
                return;
            }
            Matrix matrix;

            if (Mode == ViewMode.Perspective)
            {
                Viewport viewport = Display.Viewport;
                Vector3  vector   = new Vector3(0.5f, 0.5f, 0.5f);
                Matrix   m        = Matrix.CreateLookAt(2.65f * m_direction + vector, vector, Vector3.UnitY);
                Matrix   m2       = Matrix.CreatePerspectiveFieldOfView(1.2f, base.ActualSize.X / base.ActualSize.Y, 0.4f, 4f);
                Matrix   m3       = MatrixUtils.CreateScaleTranslation(base.ActualSize.X, 0f - base.ActualSize.Y, base.ActualSize.X / 2f, base.ActualSize.Y / 2f) * base.GlobalTransform * MatrixUtils.CreateScaleTranslation(2f / (float)viewport.Width, -2f / (float)viewport.Height, -1f, 1f);
                matrix = m * m2 * m3;
                FlatBatch3D flatBatch3D = m_primitivesRenderer3d.FlatBatch(1, DepthStencilState.DepthRead);
                for (int i = 0; i <= Design.Resolution; i++)
                {
                    float num   = (float)i / (float)Design.Resolution;
                    Color color = (i % 2 == 0) ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
                    color *= base.GlobalColorTransform;
                    flatBatch3D.QueueLine(new Vector3(num, 0f, 0f), new Vector3(num, 0f, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(1f, 0f, num), color);
                    flatBatch3D.QueueLine(new Vector3(0f, num, 0f), new Vector3(0f, num, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(0f, 1f, num), color);
                    flatBatch3D.QueueLine(new Vector3(0f, num, 1f), new Vector3(1f, num, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(num, 0f, 1f), new Vector3(num, 1f, 1f), color);
                }
                Color       color2      = new Color(64, 64, 64, 255) * base.GlobalColorTransform;
                FontBatch3D fontBatch3D = m_primitivesRenderer3d.FontBatch(ContentManager.Get <BitmapFont>("Fonts/Pericles"), 1);
                fontBatch3D.QueueText("Front", new Vector3(0.5f, 0f, 0f), 0.004f * new Vector3(-1f, 0f, 0f), 0.004f * new Vector3(0f, 0f, -1f), color2, TextAnchor.HorizontalCenter);
                fontBatch3D.QueueText("Side", new Vector3(1f, 0f, 0.5f), 0.004f * new Vector3(0f, 0f, -1f), 0.004f * new Vector3(1f, 0f, 0f), color2, TextAnchor.HorizontalCenter);
                if (DrawDebugFurniture)
                {
                    DebugDraw();
                }
            }
            else
            {
                Vector3 position;
                Vector3 up;
                if (Mode == ViewMode.Side)
                {
                    position = new Vector3(1f, 0f, 0f);
                    up       = new Vector3(0f, 1f, 0f);
                }
                else if (Mode != ViewMode.Top)
                {
                    position = new Vector3(0f, 0f, -1f);
                    up       = new Vector3(0f, 1f, 0f);
                }
                else
                {
                    position = new Vector3(0f, 1f, 0f);
                    up       = new Vector3(0f, 0f, 1f);
                }
                Viewport viewport2 = Display.Viewport;
                float    num2      = MathUtils.Min(base.ActualSize.X, base.ActualSize.Y);
                Matrix   m4        = Matrix.CreateLookAt(position, new Vector3(0f, 0f, 0f), up);
                Matrix   m5        = Matrix.CreateOrthographic(2f, 2f, -10f, 10f);
                Matrix   m6        = MatrixUtils.CreateScaleTranslation(num2, 0f - num2, base.ActualSize.X / 2f, base.ActualSize.Y / 2f) * base.GlobalTransform * MatrixUtils.CreateScaleTranslation(2f / (float)viewport2.Width, -2f / (float)viewport2.Height, -1f, 1f);
                matrix = Matrix.CreateTranslation(-0.5f, -0.5f, -0.5f) * m4 * m5 * m6;
                FlatBatch2D flatBatch2D = m_primitivesRenderer2d.FlatBatch();
                Matrix      m7          = base.GlobalTransform;
                for (int j = 1; j < Design.Resolution; j++)
                {
                    float   num3 = (float)j / (float)Design.Resolution;
                    Vector2 v    = new Vector2(base.ActualSize.X * num3, 0f);
                    Vector2 v2   = new Vector2(base.ActualSize.X * num3, base.ActualSize.Y);
                    Vector2 v3   = new Vector2(0f, base.ActualSize.Y * num3);
                    Vector2 v4   = new Vector2(base.ActualSize.X, base.ActualSize.Y * num3);
                    Vector2.Transform(ref v, ref m7, out v);
                    Vector2.Transform(ref v2, ref m7, out v2);
                    Vector2.Transform(ref v3, ref m7, out v3);
                    Vector2.Transform(ref v4, ref m7, out v4);
                    Color color3 = (j % 2 == 0) ? new Color(0, 0, 0, 56) : new Color(0, 0, 0, 28);
                    Color color4 = (j % 2 == 0) ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
                    color3 *= base.GlobalColorTransform;
                    color4 *= base.GlobalColorTransform;
                    flatBatch2D.QueueLine(v, v2, 0f, (j % 2 == 0) ? color3 : (color3 * 0.75f));
                    flatBatch2D.QueueLine(v + new Vector2(1f, 0f), v2 + new Vector2(1f, 0f), 0f, color4);
                    flatBatch2D.QueueLine(v3, v4, 0f, color3);
                    flatBatch2D.QueueLine(v3 + new Vector2(0f, 1f), v4 + new Vector2(0f, 1f), 0f, color4);
                }
            }
            Matrix            matrix2  = Matrix.Identity;
            FurnitureGeometry geometry = Design.Geometry;

            for (int k = 0; k < 6; k++)
            {
                Color globalColorTransform = base.GlobalColorTransform;
                if (Mode == ViewMode.Perspective)
                {
                    float num4 = LightingManager.LightIntensityByLightValueAndFace[15 + 16 * CellFace.OppositeFace(k)];
                    globalColorTransform *= new Color(num4, num4, num4);
                }
                if (geometry.SubsetOpaqueByFace[k] != null)
                {
                    BlocksManager.DrawMeshBlock(m_primitivesRenderer3d, geometry.SubsetOpaqueByFace[k], globalColorTransform, 1f, ref matrix2, null);
                }
                if (geometry.SubsetAlphaTestByFace[k] != null)
                {
                    BlocksManager.DrawMeshBlock(m_primitivesRenderer3d, geometry.SubsetAlphaTestByFace[k], globalColorTransform, 1f, ref matrix2, null);
                }
            }
            m_primitivesRenderer3d.Flush(matrix);
            m_primitivesRenderer2d.Flush();
        }