예제 #1
0
        // ***********************

        public void Draw(BoundingArea.ReadOnly bounding_area, params IDrawableObject[] drawable_objects)
        {
            Utils.ThrowException(bounding_area == null ? new ArgumentNullException("bounding_area") : null);
            Utils.ThrowException(drawable_objects == null ? new ArgumentNullException("drawable_objects") : null);
            DateTime     start_time    = DateTime.Now;
            BoundingArea extended_area = bounding_area.GetWritableCopy();

            ExtendBoundingArea(extended_area, drawable_objects);
#if !NO_BB_SIMPLIFICATION
            extended_area.Optimize();
#endif
            TransformParams       tr = new TransformParams(0, 0, m_scale_factor);
            Set <IDrawableObject> outdated_objects = new Set <IDrawableObject>(drawable_objects);
            drawable_objects = m_drawable_object.GetObjectsIn(extended_area, tr);

            Rectangle enclosing_rect = GetEnclosingRect(extended_area.BoundingBox);

            BitmapInfo      render_layer = PrepareBitmap(RENDER_LAYER, enclosing_rect.Width, enclosing_rect.Height);
            TransformParams render_tr    = new TransformParams(-enclosing_rect.X, -enclosing_rect.Y, m_scale_factor);

            BoundingArea extended_area_tr = extended_area.Clone();
            extended_area_tr.Transform(new TransformParams(-enclosing_rect.X, -enclosing_rect.Y, 1));

            for (int i = drawable_objects.Length - 1; i >= 0; i--)
            {
                if (outdated_objects.Contains(drawable_objects[i]))
                {
                    drawable_objects[i].Draw(render_layer.Graphics, render_tr);
                }
                else
                {
                    drawable_objects[i].Draw(render_layer.Graphics, render_tr, extended_area_tr);
                }
            }
            BitmapInfo main_layer = m_bmp_cache[MAIN_LAYER];
            Graphics   canvas_gfx = Graphics.FromHwnd(picBoxCanvas.Handle);
            foreach (RectangleF rect in extended_area.Rectangles)
            {
                Rectangle view_area = GetEnclosingRect(rect);
                view_area.X -= enclosing_rect.X;
                view_area.Y -= enclosing_rect.Y;
                view_area.Intersect(new Rectangle(0, 0, enclosing_rect.Width, enclosing_rect.Height));
                EditableBitmap view = render_layer.EditableBitmap.CreateView(view_area);
                main_layer.Graphics.DrawImageUnscaled(view.Bitmap, view_area.X + enclosing_rect.X, view_area.Y + enclosing_rect.Y);
                // clipping to visible area?!?
                canvas_gfx.DrawImageUnscaled(view.Bitmap, view_area.X + enclosing_rect.X, view_area.Y + enclosing_rect.Y);
                //view_on_view.Dispose();
                view.Dispose();
            }
            canvas_gfx.Dispose();

            TimeSpan draw_time = DateTime.Now - start_time;
            m_draw_time += draw_time;
            m_draw_count++;

            FpsInfo.Text = string.Format("{0:0.00} ms / draw", (double)m_draw_time.TotalMilliseconds / (double)m_draw_count);
            m_draw_info.Add(draw_time.TotalMilliseconds);
            FpsInfo.Refresh();
        }
예제 #2
0
    void MakeTexture()
    {
        _FpsInfo.Clear();

        var GameResPath = Application.dataPath + "/../../GameRes/";

        if (!File.Exists(GameResPath + "fps.csv"))
        {
            return;
        }

        StreamReader streamReader = new StreamReader(GameResPath + "fps.csv");
        string       strLine      = streamReader.ReadLine();

        _Row    = int.Parse(strLine);
        strLine = streamReader.ReadLine();
        _Col    = int.Parse(strLine);
        strLine = streamReader.ReadLine();
        while (strLine != null)
        {
            var info = new FpsInfo(strLine);
            var fps  = info.fps;
            if (fps > _MaxFps)
            {
                _MaxFps = fps;
            }
            if (fps < _MinFps)
            {
                _MinFps = fps;
            }
            _FpsInfo.Add(info);
            strLine = streamReader.ReadLine();
        }
        _MinFps = 0;// _MinFps / _Weight;
        streamReader.Close();

        var col = _Col * _BlowUp - _BlowUp + 1;
        var row = _Row * _BlowUp - _BlowUp + 1;

        _TextureFps = new Texture2D(col, row);

        float[,] WeightColor = new float[col, row];
        //Debug.Log("Count : " + row * col);
        //Debug.Log("row : " + row + " col : " + col);
        //Debug.Log("_MaxFps : " + _MaxFps + " _MinFps : " + _MinFps);
        //Debug.Log("_FpsInfo Count : " + _FpsInfo.Count);
        //Debug.Log("_Weight : " + _Weight);
        for (int m = 0; m < _FpsInfo.Count; m++)
        {
            var info = _FpsInfo[m];
            var y    = info.y * _BlowUp;
            var x    = info.x * _BlowUp;
            for (int i = x - _Weight; i <= x + _Weight; i++)
            {
                if (i < 0 || i >= col)
                {
                    continue;
                }
                for (int j = y - _Weight; j <= y + _Weight; j++)
                {
                    if (j < 0 || j >= row)
                    {
                        continue;
                    }
                    var xDis = Mathf.Abs(x - i);
                    var yDis = Mathf.Abs(y - j);
                    if (xDis * xDis + yDis * yDis > _Weight * _Weight)
                    {
                        continue;
                    }
                    float dis = Vector2.Distance(new Vector2(xDis, yDis), new Vector2(0, 0));
                    WeightColor[i, j] += ((float)(_Weight - dis) / _Weight) * info.fps;
                }
            }
        }
        for (int i = 0; i < row; i++)
        {
            for (int j = 0; j < col; j++)
            {
                _TextureFps.SetPixel(j, i, GetFpsColor(WeightColor[j, i]));
            }
        }

        _TextureFps.Apply();
    }