void UpdateTitleFps(float dt)
    {
        GamePlatform p = m.GetPlatform();

        fpscount++;
        longestframedt = MathCi.MaxFloat(longestframedt, dt);
        float elapsed = one * (p.TimeMillisecondsFromStart() - lasttitleupdateMilliseconds) / 1000;

        if (elapsed >= 1)
        {
            string fpstext1 = "";
            lasttitleupdateMilliseconds = p.TimeMillisecondsFromStart();
            fpstext1       = StringTools.StringAppend(p, fpstext1, p.StringFormat("FPS: {0}", p.IntToString(p.FloatToInt((one * fpscount) / elapsed))));
            fpstext1       = StringTools.StringAppend(p, fpstext1, p.StringFormat(" (min: {0})", p.IntToString(p.FloatToInt(one / longestframedt))));
            longestframedt = 0;
            fpscount       = 0;
            m.GetPerformanceInfo().Set("fps", fpstext1);

            string   s      = "";
            string[] l      = new string[64];
            int      lCount = 0;
            for (int i = 0; i < m.GetPerformanceInfo().count; i++)
            {
                if (m.GetPerformanceInfo().items[i] == null)
                {
                    continue;
                }
                l[lCount++] = m.GetPerformanceInfo().items[i].value;
            }

            int perline = 2;
            for (int i = 0; i < lCount; i++)
            {
                s = StringTools.StringAppend(p, s, l[i]);
                if ((i % perline == 0) && (i != lCount - 1))
                {
                    s = StringTools.StringAppend(p, s, ", ");
                }
                if (i % perline != 0)
                {
                    s = StringTools.StringAppend(p, s, "\n");
                }
            }
            fpstext = s;
        }
    }
Example #2
0
 public void AddPoint(float x, float y, float z)
 {
     //if is empty
     if (MinEdge == null || MaxEdge == null ||
         (MinEdge[0] == 0 && MinEdge[1] == 0 && MinEdge[2] == 0 &&
          MaxEdge[0] == 0 && MaxEdge[1] == 0 && MaxEdge[2] == 0))
     {
         MinEdge = Vec3.FromValues(x, y, z);
         MaxEdge = Vec3.FromValues(x, y, z);
     }
     MinEdge[0] = MathCi.MinFloat(MinEdge[0], x);
     MinEdge[1] = MathCi.MinFloat(MinEdge[1], y);
     MinEdge[2] = MathCi.MinFloat(MinEdge[2], z);
     MaxEdge[0] = MathCi.MaxFloat(MaxEdge[0], x);
     MaxEdge[1] = MathCi.MaxFloat(MaxEdge[1], y);
     MaxEdge[2] = MathCi.MaxFloat(MaxEdge[2], z);
 }
Example #3
0
    void UpdateStatisticsText(float dt)
    {
        GamePlatform p = m.GetPlatform();

        fpscount++;
        longestframedt = MathCi.MaxFloat(longestframedt, dt);
        float elapsed = one * (p.TimeMillisecondsFromStart() - lasttitleupdateMilliseconds) / 1000;

        if (elapsed >= 1)
        {
            lasttitleupdateMilliseconds = p.TimeMillisecondsFromStart();
            string fpstext1 = p.IntToString(p.FloatToInt((one * fpscount) / elapsed));
            fpstext1       = StringTools.StringAppend(p, fpstext1, p.StringFormat(" (min: {0})", p.IntToString(p.FloatToInt(one / longestframedt))));
            longestframedt = 0;
            fpscount       = 0;
            m.GetPerformanceInfo().Set("FPS", fpstext1);

            StatsLineCount = 0;
            for (int i = 0; i < m.GetPerformanceInfo().size; i++)
            {
                if (m.GetPerformanceInfo().items[i] == null)
                {
                    continue;
                }
                if (m.GetPerformanceInfo().items[i].key == "Chunk updates")
                {
                    UpdateChunkHistory(p.IntParse(m.GetPerformanceInfo().items[i].value));
                }
                if (m.GetPerformanceInfo().items[i].key == "Ping")
                {
                    UpdatePingHistory(p.IntParse(m.GetPerformanceInfo().items[i].value));
                }
                if (StatsLineCount >= StatsMaxLineCount)
                {
                    // Prevent running out of bounds
                    break;
                }
                StatsLines[StatsLineCount++] = p.StringFormat2("{0}: {1}", m.GetPerformanceInfo().items[i].key, m.GetPerformanceInfo().items[i].value);
            }
        }
    }
 static float Max3(float a, float b, float c)
 {
     return(MathCi.MaxFloat(MathCi.MaxFloat(a, b), c));
 }
Example #5
0
    /// <summary>
    /// Creates a bitmap from a given string
    /// </summary>
    /// <param name="t">The <see cref="Text_"/> object to create an image from</param>
    /// <returns>A <see cref="BitmapCi"/> containing the rendered text</returns>
    internal BitmapCi CreateTextTexture(Text_ t)
    {
        IntRef partsCount = new IntRef();

        TextPart[] parts = DecodeColors(t.text, t.color, partsCount);

        float totalwidth  = 0;
        float totalheight = 0;

        int[] sizesX = new int[partsCount.value];
        int[] sizesY = new int[partsCount.value];

        for (int i = 0; i < partsCount.value; i++)
        {
            IntRef outWidth  = new IntRef();
            IntRef outHeight = new IntRef();
            platform.TextSize(parts[i].text, t.font, outWidth, outHeight);

            sizesX[i] = outWidth.value;
            sizesY[i] = outHeight.value;

            totalwidth += outWidth.value;
            totalheight = MathCi.MaxFloat(totalheight, outHeight.value);
        }

        int      size2X = NextPowerOfTwo(platform.FloatToInt(totalwidth) + 1);
        int      size2Y = NextPowerOfTwo(platform.FloatToInt(totalheight) + 1);
        BitmapCi bmp2   = platform.BitmapCreate(size2X, size2Y);

        int[] bmp2Pixels = new int[size2X * size2Y];

        float currentwidth = 0;

        for (int i = 0; i < partsCount.value; i++)
        {
            int sizeiX = sizesX[i];
            int sizeiY = sizesY[i];
            if (sizeiX == 0 || sizeiY == 0)
            {
                continue;
            }

            Text_ partText = new Text_();
            partText.text  = parts[i].text;
            partText.color = parts[i].color;
            partText.font  = t.font;

            BitmapCi partBmp       = platform.CreateTextTexture(partText);
            int      partWidth     = platform.FloatToInt(platform.BitmapGetWidth(partBmp));
            int      partHeight    = platform.FloatToInt(platform.BitmapGetHeight(partBmp));
            int[]    partBmpPixels = new int[partWidth * partHeight];
            platform.BitmapGetPixelsArgb(partBmp, partBmpPixels);
            for (int x = 0; x < partWidth; x++)
            {
                for (int y = 0; y < partHeight; y++)
                {
                    if (x + currentwidth >= size2X)
                    {
                        continue;
                    }
                    if (y >= size2Y)
                    {
                        continue;
                    }
                    int c = partBmpPixels[MapUtilCi.Index2d(x, y, partWidth)];
                    if (Game.ColorA(c) > 0)
                    {
                        bmp2Pixels[MapUtilCi.Index2d(platform.FloatToInt(currentwidth) + x, y, size2X)] = c;
                    }
                }
            }
            currentwidth += sizeiX;
        }
        platform.BitmapSetPixelsArgb(bmp2, bmp2Pixels);
        return(bmp2);
    }