Example #1
0
        private void Step(bool showProfile)
        {
            World.Step(_dt, 8, 3);
            FpsCounter.CountOne();

            if (showProfile)
            {
                //var p = World.Profile;

                //// Track maximum profile times
                //MaxProfile.Step = Math.Max(MaxProfile.Step, p.Step);
                //MaxProfile.Collide = Math.Max(MaxProfile.Collide, p.Collide);
                //MaxProfile.Solve = Math.Max(MaxProfile.Solve, p.Solve);
                //MaxProfile.SolveInit = Math.Max(MaxProfile.SolveInit, p.SolveInit);
                //MaxProfile.SolveVelocity = Math.Max(MaxProfile.SolveVelocity, p.SolveVelocity);
                //MaxProfile.SolvePosition = Math.Max(MaxProfile.SolvePosition, p.SolvePosition);
                //MaxProfile.SolveTOI = Math.Max(MaxProfile.SolveTOI, p.SolveTOI);
                //MaxProfile.Broadphase = Math.Max(MaxProfile.Broadphase, p.Broadphase);

                //TotalProfile.Step += p.Step;
                //TotalProfile.Collide += p.Collide;
                //TotalProfile.Solve += p.Solve;
                //TotalProfile.SolveInit += p.SolveInit;
                //TotalProfile.SolveVelocity += p.SolveVelocity;
                //TotalProfile.SolvePosition += p.SolvePosition;
                //TotalProfile.SolveTOI += p.SolveTOI;
                //TotalProfile.Broadphase += p.Broadphase;

                //var aveProfile = new Profile();
                //if (FixedUpdate.TickCount > 0)
                //{
                //    var scale = 1.0f / FixedUpdate.TickCount;
                //    aveProfile.Step = scale * TotalProfile.Step;
                //    aveProfile.Collide = scale * TotalProfile.Collide;
                //    aveProfile.Solve = scale * TotalProfile.Solve;
                //    aveProfile.SolveInit = scale * TotalProfile.SolveInit;
                //    aveProfile.SolveVelocity = scale * TotalProfile.SolveVelocity;
                //    aveProfile.SolvePosition = scale * TotalProfile.SolvePosition;
                //    aveProfile.SolveTOI = scale * TotalProfile.SolveTOI;
                //    aveProfile.Broadphase = scale * TotalProfile.Broadphase;
                //}

                //_sb.AppendLine($"FPS {FpsCounter.Fps}, ms {FpsCounter.Ms}");
                //_sb.AppendLine($"step [ave] (max) = {p.Step} [{aveProfile.Step}] ({MaxProfile.Step})");
                //_sb.AppendLine($"collide [ave] (max) = {p.Collide} [{aveProfile.Collide}] ({MaxProfile.Collide})");
                //_sb.AppendLine($"solve [ave] (max) = {p.Solve} [{aveProfile.Solve}] ({MaxProfile.Solve})");
                //_sb.AppendLine($"solve init [ave] (max) = {p.SolveInit} [{aveProfile.SolveInit}] ({MaxProfile.SolveInit})");
                //_sb.AppendLine($"solve velocity [ave] (max) = {p.SolveVelocity} [{aveProfile.SolveVelocity}] ({MaxProfile.SolveVelocity})");
                //_sb.AppendLine($"solve position [ave] (max) = {p.SolvePosition} [{aveProfile.SolvePosition}] ({MaxProfile.SolvePosition})");
                //_sb.AppendLine($"solveTOI [ave] (max) = {p.SolveTOI} [{aveProfile.SolveTOI}] ({MaxProfile.SolveTOI})");
                //_sb.AppendLine($"broad-phase [ave] (max) = {p.Broadphase} [{aveProfile.Broadphase}] ({MaxProfile.Broadphase})");

                //Console.SetCursorPosition(0, 0);
                //Console.Write(_sb.ToString());
                //_sb.Clear();
            }
        }
Example #2
0
        private void Step(bool showProfile)
        {
            World.Step(_dt, 8, 3);
            FpsCounter.CountOne();
            if (_bodyCount < Count)
            {
                var bd = new BodyDef
                {
                    BodyType = BodyType.DynamicBody,
                    Position = new Vector2(0.0f, 10.0f)
                };
                var body = World.CreateBody(bd);

                var shape = new PolygonShape();
                shape.SetAsBox(0.125f, 0.125f);
                body.CreateFixture(shape, 1.0f);

                ++_bodyCount;
            }

            if (showProfile)
            {
                var p = World.Profile;

                // Track maximum profile times
                MaxProfile.Step          = Math.Max(MaxProfile.Step, p.Step);
                MaxProfile.Collide       = Math.Max(MaxProfile.Collide, p.Collide);
                MaxProfile.Solve         = Math.Max(MaxProfile.Solve, p.Solve);
                MaxProfile.SolveInit     = Math.Max(MaxProfile.SolveInit, p.SolveInit);
                MaxProfile.SolveVelocity = Math.Max(MaxProfile.SolveVelocity, p.SolveVelocity);
                MaxProfile.SolvePosition = Math.Max(MaxProfile.SolvePosition, p.SolvePosition);
                MaxProfile.SolveTOI      = Math.Max(MaxProfile.SolveTOI, p.SolveTOI);
                MaxProfile.Broadphase    = Math.Max(MaxProfile.Broadphase, p.Broadphase);

                TotalProfile.Step          += p.Step;
                TotalProfile.Collide       += p.Collide;
                TotalProfile.Solve         += p.Solve;
                TotalProfile.SolveInit     += p.SolveInit;
                TotalProfile.SolveVelocity += p.SolveVelocity;
                TotalProfile.SolvePosition += p.SolvePosition;
                TotalProfile.SolveTOI      += p.SolveTOI;
                TotalProfile.Broadphase    += p.Broadphase;

                var aveProfile = new Profile();
                if (FixedUpdate.TickCount > 0)
                {
                    var scale = 1.0f / FixedUpdate.TickCount;
                    aveProfile.Step          = scale * TotalProfile.Step;
                    aveProfile.Collide       = scale * TotalProfile.Collide;
                    aveProfile.Solve         = scale * TotalProfile.Solve;
                    aveProfile.SolveInit     = scale * TotalProfile.SolveInit;
                    aveProfile.SolveVelocity = scale * TotalProfile.SolveVelocity;
                    aveProfile.SolvePosition = scale * TotalProfile.SolvePosition;
                    aveProfile.SolveTOI      = scale * TotalProfile.SolveTOI;
                    aveProfile.Broadphase    = scale * TotalProfile.Broadphase;
                }

                _sb.AppendLine($"FPS {FpsCounter.Fps}, ms {FpsCounter.Ms}");
                _sb.AppendLine($"step [ave] (max) = {p.Step} [{aveProfile.Step}] ({MaxProfile.Step})");
                _sb.AppendLine($"collide [ave] (max) = {p.Collide} [{aveProfile.Collide}] ({MaxProfile.Collide})");
                _sb.AppendLine($"solve [ave] (max) = {p.Solve} [{aveProfile.Solve}] ({MaxProfile.Solve})");
                _sb.AppendLine($"solve init [ave] (max) = {p.SolveInit} [{aveProfile.SolveInit}] ({MaxProfile.SolveInit})");
                _sb.AppendLine($"solve velocity [ave] (max) = {p.SolveVelocity} [{aveProfile.SolveVelocity}] ({MaxProfile.SolveVelocity})");
                _sb.AppendLine($"solve position [ave] (max) = {p.SolvePosition} [{aveProfile.SolvePosition}] ({MaxProfile.SolvePosition})");
                _sb.AppendLine($"solveTOI [ave] (max) = {p.SolveTOI} [{aveProfile.SolveTOI}] ({MaxProfile.SolveTOI})");
                _sb.AppendLine($"broad-phase [ave] (max) = {p.Broadphase} [{aveProfile.Broadphase}] ({MaxProfile.Broadphase})");

                Console.SetCursorPosition(0, 0);
                Console.Write(_sb.ToString());
                _sb.Clear();
            }
        }