<commit_before>/*
* Box2D.XNA port of Box2D:
* Copyright (c) 2009 <NAME>, <NAME>
*
* Original source Box2D:
* Copyright (c) 2006-2009 <NAME> http://www.gphysics.com 
* 
* This software is provided 'as-is', without any express or implied 
* warranty.  In no event will the authors be held liable for any damages 
* arising from the use of this software. 
* Permission is granted to anyone to use this software for any purpose, 
* including commercial applications, and to alter it and redistribute it 
* freely, subject to the following restrictions: 
* 1. The origin of this software must not be misrepresented; you must not 
* claim that you wrote the original software. If you use this software 
* in a product, an acknowledgment in the product documentation would be 
* appreciated but is not required. 
* 2. Altered source versions must be plainly marked as such, and must not be 
* misrepresented as being the original software. 
* 3. This notice may not be removed or altered from any source distribution. 
*/

using System;
using FarseerPhysics.Collision;
using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Common;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using FarseerPhysics.Dynamics.Joints;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace FarseerPhysics.TestBed.Framework
{
    public static class Rand
    {
        public static Random Random = new Random(0x2eed2eed);

        /// Random number in range [-1,1]
        public static float RandomFloat()
        {
            return (float) (Random.NextDouble() * 2.0 - 1.0);
        }

        /// Random floating point number in range [lo, hi]
        public static float RandomFloat(float lo, float hi)
        {
            float r = (float) Random.NextDouble();
            r = (hi - lo) * r + lo;
            return r;
        }
    }

    public class GameSettings
    {
        public uint DrawAABBs;
        public uint DrawCOMs;
        public uint DrawContactForces;
        public uint DrawContactNormals;
        public uint DrawContactPoints;
        public uint DrawFrictionForces;
        public uint DrawJoints;
        public uint DrawPairs;
        public uint DrawPolygonPoints;
        public uint DrawShapes;
        public uint DrawStats;
        public float Hz;
        public bool Pause;
        public bool SingleStep;

        public GameSettings()
        {
            Hz = 60.0f;
            DrawShapes = 1;
            DrawJoints = 1;
            //DrawAABBs = 1;
            //DrawStats = 1;
            //DrawCOMs = 1;
            DrawPolygonPoints = 1;
        }
    }

    public struct TestEntry
    {
        public Func<Test> CreateFcn;
        public string Name;
    }

    public struct ContactPoint
    {
        public Fixture FixtureA;
        public Fixture FixtureB;
        public Vector2 Normal;
        public Vector2 Position;
        public PointState State;
    }

    public class Test
    {
        private const int k_MaxContactPoints = 2048;
        internal DebugViewXNA.DebugViewXNA DebugView;
        internal int PointCount;
        internal ContactPoint[] Points = new ContactPoint[k_MaxContactPoints];
        internal int StepCount;
        internal int TextLine;
        internal World World;
        private FixedMouseJoint _fixedMouseJoint;

        protected Test()
        {
            World = new World(new Vector2(0.0f, -10.0f));

            TextLine = 30;

            World.JointRemoved += JointRemoved;
            World.ContactManager.PreSolve += PreSolve;
            World.ContactManager.PostSolve += PostSolve;
            World.ContactManager.BeginContact += BeginContact;
            World.ContactManager.EndContact += EndContact;

            StepCount = 0;
        }

        public Game1 GameInstance { protected get; set; }

        public virtual void Initialize()
        {
            if (GameInstance.DebugViewEnabled)
                DebugView = new DebugViewXNA.DebugViewXNA(World);
        }

        private void JointRemoved(Joint joint)
        {
            if (_fixedMouseJoint == joint)
            {
                _fixedMouseJoint = null;
            }
        }

        public void SetTextLine(int line)
        {
            TextLine = line;
        }

        public void DrawTitle(int x, int y, string title)
        {
            DebugView.DrawString(x, y, title);
        }

        public virtual void Update(GameSettings settings, GameTime gameTime)
        {
            //float timeStep = settings.Hz > 0.0f ? 1.0f / settings.Hz : 0.0f;

            // added
            float timeStep = Math.Min((float) gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f, (1f / 30f));

            if (settings.Pause)
            {
                if (settings.SingleStep)
                {
                    settings.SingleStep = false;
                }
                else
                {
                    timeStep = 0.0f;
                }

                DebugView.DrawString(50, TextLine, "****PAUSED****");
                TextLine += 15;
            }

            if (GameInstance.DebugViewEnabled)
            {
                uint flags = 0;
                flags += settings.DrawShapes * (uint) DebugViewFlags.Shape;
                flags += settings.DrawJoints * (uint) DebugViewFlags.Joint;
                flags += settings.DrawAABBs * (uint) DebugViewFlags.AABB;
                flags += settings.DrawPairs * (uint) DebugViewFlags.Pair;
                flags += settings.DrawCOMs * (uint) DebugViewFlags.CenterOfMass;
                DebugView.Flags = (DebugViewFlags) flags;
            }

            PointCount = 0;

            World.Step(timeStep);

            if (timeStep > 0.0f)
            {
                ++StepCount;
            }

            if (GameInstance.DebugViewEnabled)
            {
                DebugView.DrawDebugData();

                if (settings.DrawStats > 0)
                {
                    DebugView.DrawString(50, TextLine, "bodies/contacts/joints/proxies = {0:n}/{1:n}/{2:n}/{3:n}",
                                         World.BodyCount, World.ContactManager.ContactCount, World.JointCount,
                                         World.ProxyCount);
                    TextLine += 15;
                }

                if (_fixedMouseJoint != null)
                {
                    Vector2 p1 = _fixedMouseJoint.WorldAnchorB;
                    Vector2 p2 = _fixedMouseJoint.Target;

                    DebugView.DrawPoint(p1, 0.5f, new Color(0.0f, 1.0f, 0.0f));
                    DebugView.DrawPoint(p1, 0.5f, new Color(0.0f, 1.0f, 0.0f));<commit_msg>Changed Test.cs to use DebugView.AppendFlags() instead of bitwise operations.<commit_after>/*
* Box2D.XNA port of Box2D:
* Copyright (c) 2009 <NAME>, <NAME>
*
* Original source Box2D:
* Copyright (c) 2006-2009 <NAME> http://www.gphysics.com 
* 
* This software is provided 'as-is', without any express or implied 
* warranty.  In no event will the authors be held liable for any damages 
* arising from the use of this software. 
* Permission is granted to anyone to use this software for any purpose, 
* including commercial applications, and to alter it and redistribute it 
* freely, subject to the following restrictions: 
* 1. The origin of this software must not be misrepresented; you must not 
* claim that you wrote the original software. If you use this software 
* in a product, an acknowledgment in the product documentation would be 
* appreciated but is not required. 
* 2. Altered source versions must be plainly marked as such, and must not be 
* misrepresented as being the original software. 
* 3. This notice may not be removed or altered from any source distribution. 
*/

using System;
using FarseerPhysics.Collision;
using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Common;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using FarseerPhysics.Dynamics.Joints;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace FarseerPhysics.TestBed.Framework
{
    public static class Rand
    {
        public static Random Random = new Random(0x2eed2eed);

        /// Random number in range [-1,1]
        public static float RandomFloat()
        {
            return (float) (Random.NextDouble() * 2.0 - 1.0);
        }

        /// Random floating point number in range [lo, hi]
        public static float RandomFloat(float lo, float hi)
        {
            float r = (float) Random.NextDouble();
            r = (hi - lo) * r + lo;
            return r;
        }
    }

    public class GameSettings
    {
        public uint DrawAABBs;
        public uint DrawCOMs;
        public uint DrawContactForces;
        public uint DrawContactNormals;
        public uint DrawContactPoints;
        public uint DrawFrictionForces;
        public uint DrawJoints;
        public uint DrawPairs;
        public uint DrawPolygonPoints;
        public uint DrawShapes;
        public uint DrawStats;
        public float Hz;
        public bool Pause;
        public bool SingleStep;

        public GameSettings()
        {
            Hz = 60.0f;
            DrawShapes = 1;
            DrawJoints = 1;
            //DrawAABBs = 1;
            //DrawStats = 1;
            //DrawCOMs = 1;
            DrawPolygonPoints = 1;
        }
    }

    public struct TestEntry
    {
        public Func<Test> CreateFcn;
        public string Name;
    }

    public struct ContactPoint
    {
        public Fixture FixtureA;
        public Fixture FixtureB;
        public Vector2 Normal;
        public Vector2 Position;
        public PointState State;
    }

    public class Test
    {
        private const int k_MaxContactPoints = 2048;
        internal DebugViewXNA.DebugViewXNA DebugView;
        internal int PointCount;
        internal ContactPoint[] Points = new ContactPoint[k_MaxContactPoints];
        internal int StepCount;
        internal int TextLine;
        internal World World;
        private FixedMouseJoint _fixedMouseJoint;

        protected Test()
        {
            World = new World(new Vector2(0.0f, -10.0f));

            TextLine = 30;

            World.JointRemoved += JointRemoved;
            World.ContactManager.PreSolve += PreSolve;
            World.ContactManager.PostSolve += PostSolve;
            World.ContactManager.BeginContact += BeginContact;
            World.ContactManager.EndContact += EndContact;

            StepCount = 0;
        }

        public Game1 GameInstance { protected get; set; }

        public virtual void Initialize()
        {
            if (GameInstance.DebugViewEnabled)
                DebugView = new DebugViewXNA.DebugViewXNA(World);
        }

        private void JointRemoved(Joint joint)
        {
            if (_fixedMouseJoint == joint)
            {
                _fixedMouseJoint = null;
            }
        }

        public void SetTextLine(int line)
        {
            TextLine = line;
        }

        public void DrawTitle(int x, int y, string title)
        {
            DebugView.DrawString(x, y, title);
        }

        public virtual void Update(GameSettings settings, GameTime gameTime)
        {
            //float timeStep = settings.Hz > 0.0f ? 1.0f / settings.Hz : 0.0f;

            // added
            float timeStep = Math.Min((float) gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f, (1f / 30f));

            if (settings.Pause)
            {
                if (settings.SingleStep)
                {
                    settings.SingleStep = false;
                }
                else
                {
                    timeStep = 0.0f;
                }

                DebugView.DrawString(50, TextLine, "****PAUSED****");
                TextLine += 15;
            }

            if (GameInstance.DebugViewEnabled)
            {
                DebugView.AppendFlags(DebugViewFlags.Shape);
                DebugView.AppendFlags(DebugViewFlags.Joint);
            }

            PointCount = 0;

            World.Step(timeStep);

            if (timeStep > 0.0f)
            {
                ++StepCount;
            }

            if (GameInstance.DebugViewEnabled)
            {
                DebugView.DrawDebugData();

                if (settings.DrawStats > 0)
                {
                    DebugView.DrawString(50, TextLine, "bodies/contacts/joints/proxies = {0:n}/{1:n}/{2:n}/{3:n}",
                                         World.BodyCount, World.ContactManager.ContactCount, World.JointCount,
                                         World.ProxyCount);
                    TextLine += 15;
                }

                if (_fixedMouseJoint != null)
                {
                    Vector2 p1 = _fixedMouseJoint.WorldAnchorB;
                    Vector2 p2 = _fixedMouseJoint.Target;

                    DebugView.DrawPoint(p1, 0.5f, new Color(0.0f, 1.0f, 0.0f));
                    DebugView.DrawPoint(p1, 0.5f, new Color(0.0f, 1.0f, 0.0f));
{'fraction_non_alphanumeric': 0.07964669154039443, 'fraction_numerical': 0.016066397624305187, 'mean_word_length': 1.726593315341499, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7305932', 'n_tokens_mistral': 3740, 'n_tokens_neox': 3436, 'n_words': 1005}