public static World CreateWorld(float worldSideLength = 2000, float metersPerBody = 50, BodyStructureType bodyType = BodyStructureType.TwelveFixtureStructure)
        {
            var world = new World();

            // enable multithreading
            world.ContactManager.VelocityConstraintsMultithreadThreshold = 256;
            world.ContactManager.PositionConstraintsMultithreadThreshold = 256;
            world.ContactManager.CollideMultithreadThreshold             = 256;

            // no grav
            world.Gravity = Vector2.Zero;

            WorldPerformanceTestSetup.CreateBounds(world, worldSideLength);

            WorldPerformanceTestSetup.CreateBodies(world, worldSideLength, metersPerBody, bodyType);

            world.HibernationEnabled = true;

            return(world);
        }
        private static void CreateBodies(World world, float worldSideLength, float metersPerBody, BodyStructureType bodyType)
        {
            // load the game world
            var tempWorld = new World();

            RubeLoader.Load("data/testbodies.json", tempWorld);

            // settings
            const float MAX_LINEAR_VELOCITY  = 20.0f;
            const float MAX_ANGULAR_VELOCITY = 1.5F;

            // add the specific body
            //const int COMPLEX_BODY_INDEX = 2;
            //const int C_BODY_INDEX = 1;
            //const int BOX_BODY_INDEX = 0;
            var worldRadius       = worldSideLength / 2f;
            var selectedBodyIndex = (int)bodyType; //BOX_BODY_INDEX;

            for (var x = metersPerBody; x <= worldSideLength - metersPerBody; x += metersPerBody)
            {
                for (var y = metersPerBody; y <= worldSideLength - metersPerBody; y += metersPerBody)
                {
                    var bodyDef = tempWorld.BodyList[selectedBodyIndex];
                    var body    = bodyDef.DeepClone(world);

                    body.Position        = new Vector2(x - worldRadius, y - worldRadius);
                    body.LinearVelocity  = RandomGenerator.Vector2(MAX_LINEAR_VELOCITY);
                    body.AngularVelocity = RandomGenerator.Float(-MAX_ANGULAR_VELOCITY, MAX_ANGULAR_VELOCITY);
                }
            }
        }
        public override void Keyboard(KeyboardManager keyboardManager)
        {
            base.Keyboard(keyboardManager);

            var cMgr = World.ContactManager;

            if (keyboardManager.IsNewKeyPress(Keys.D1))
            {
                cMgr.VelocityConstraintsMultithreadThreshold = 0;
            }
            if (keyboardManager.IsNewKeyPress(Keys.D2))
            {
                cMgr.VelocityConstraintsMultithreadThreshold = 256;
            }
            if (keyboardManager.IsNewKeyPress(Keys.D3))
            {
                cMgr.VelocityConstraintsMultithreadThreshold = int.MaxValue;
            }

            if (keyboardManager.IsNewKeyPress(Keys.D4))
            {
                cMgr.PositionConstraintsMultithreadThreshold = 0;
            }
            if (keyboardManager.IsNewKeyPress(Keys.D5))
            {
                cMgr.PositionConstraintsMultithreadThreshold = 256;
            }
            if (keyboardManager.IsNewKeyPress(Keys.D6))
            {
                cMgr.PositionConstraintsMultithreadThreshold = int.MaxValue;
            }

            if (keyboardManager.IsNewKeyPress(Keys.D7))
            {
                cMgr.CollideMultithreadThreshold = 0;
            }
            if (keyboardManager.IsNewKeyPress(Keys.D8))
            {
                cMgr.CollideMultithreadThreshold = 256;
            }
            if (keyboardManager.IsNewKeyPress(Keys.D9))
            {
                cMgr.CollideMultithreadThreshold = int.MaxValue;
            }

            if (keyboardManager.IsNewKeyPress(Keys.Space))
            {
                if (cMgr.VelocityConstraintsMultithreadThreshold == int.MaxValue)
                {
                    cMgr.VelocityConstraintsMultithreadThreshold = 0;
                }
                else
                {
                    cMgr.VelocityConstraintsMultithreadThreshold = int.MaxValue;
                }
                cMgr.PositionConstraintsMultithreadThreshold = cMgr.VelocityConstraintsMultithreadThreshold;
                cMgr.CollideMultithreadThreshold             = cMgr.VelocityConstraintsMultithreadThreshold;
            }

            // World side size.
            foreach (var key in this.WorldSideSizeOptions.Keys)
            {
                if (keyboardManager.IsNewKeyPress(key))
                {
                    var pressedSize = this.WorldSideSizeOptions[key];
                    if (pressedSize != this.WorldSideSize)
                    {
                        this.WorldSideSize = pressedSize;
                        this.Initialize();
                    }
                    break;
                }
            }

            // Meters per body.
            foreach (var key in this.MetersPerBodyOptions.Keys)
            {
                if (keyboardManager.IsNewKeyPress(key))
                {
                    var newMetersPerBody = this.MetersPerBodyOptions[key];
                    if (newMetersPerBody != this.MetersPerBody)
                    {
                        this.MetersPerBody = newMetersPerBody;
                        this.Initialize();
                    }
                    break;
                }
            }

            // Body structure type.
            foreach (var key in this.BodyStructureTypeOptions.Keys)
            {
                if (keyboardManager.IsNewKeyPress(key))
                {
                    var newBodyStructureType = this.BodyStructureTypeOptions[key];
                    if (newBodyStructureType != this.BodyStructureType)
                    {
                        this.BodyStructureType = newBodyStructureType;
                        this.Initialize();
                    }
                    break;
                }
            }

            if (keyboardManager.IsNewKeyPress(Keys.LeftAlt))
            {
                this.EnableCoordinateRendering = !this.EnableCoordinateRendering;
            }

            if (keyboardManager.IsNewKeyPress(Keys.RightControl))
            {
                this.DebugView.ToggleFlag(DebugViewFlags.HibernatedBodyAABBs);
            }

            if (keyboardManager.IsNewKeyPress(Keys.LeftControl))
            {
                this.DebugView.Enabled = !this.DebugView.Enabled;
            }

            if (keyboardManager.IsNewKeyPress(Keys.OemTilde))
            {
                this.IsControlPanelRenderEnabled = !this.IsControlPanelRenderEnabled;
            }
        }