Example #1
0
        public void DrawFloatingMessage(Camera camera, string message, float factor)
        {
            BitmapFont font = ContentManager.Get <BitmapFont>("Fonts/Pericles");

            if (!camera.Eye.HasValue)
            {
                Vector2 position = camera.ViewportSize / 2f;
                position.X += 0.07f * camera.ViewportSize.X * (float)MathUtils.Sin(1.7300000190734863 * Time.FrameStartTime);
                position.Y += 0.07f * camera.ViewportSize.Y * (float)MathUtils.Cos(1.1200000047683716 * Time.FrameStartTime);
                FontBatch2D fontBatch2D = m_primitivesRenderer2D.FontBatch(font, 1, DepthStencilState.None, null, BlendState.AlphaBlend);
                int         count       = fontBatch2D.TriangleVertices.Count;
                fontBatch2D.QueueText(message, position, 0f, Color.White * factor, TextAnchor.HorizontalCenter | TextAnchor.VerticalCenter, Vector2.One * camera.GameWidget.GlobalScale, Vector2.Zero);
                fontBatch2D.TransformTriangles(camera.ViewportMatrix, count);
                fontBatch2D.Flush();
            }
            else
            {
                Vector3 position2 = -4f * Vector3.UnitZ;
                position2.X += 0.28f * (float)MathUtils.Sin(1.7300000190734863 * Time.FrameStartTime);
                position2.Y += 0.28f * (float)MathUtils.Cos(1.1200000047683716 * Time.FrameStartTime);
                FontBatch3D fontBatch3D = m_primitivesRenderer3D.FontBatch(font, 1, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.AlphaBlend);
                fontBatch3D.QueueText(message, position2, 0.008f * Vector3.UnitX, -0.008f * Vector3.UnitY, Color.White * factor, TextAnchor.HorizontalCenter | TextAnchor.VerticalCenter, Vector2.Zero);
                fontBatch3D.Flush(camera.ProjectionMatrix);
            }
        }
Example #2
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());
            }
        }
        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();
        }
Example #4
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;
                }
            }
        }
Example #5
0
 public override void Load(ValuesDictionary valuesDictionary)
 {
     fontBatch2D = primitivesRenderer.FontBatch(ContentManager.Get <BitmapFont>("Fonts/SignFont"));
     subsystemItemElectricBehavior = Project.FindSubsystem <SubsystemItemElectricBehavior>();
     base.Load(valuesDictionary);
 }