Ejemplo n.º 1
0
        protected Demo(DemosGame game)
        {
            Game = game;
            parallelLooper = new ParallelLooper();
            //This section lets the engine know that it can make use of multithreaded systems
            //by adding threads to its thread pool.
            #if XBOX360
            parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 1 }); });
            parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 3 }); });
            parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 4 }); });
            parallelLooper.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 5 }); });

            #else
            if (Environment.ProcessorCount > 1)
            {
                for (int i = 0; i < Environment.ProcessorCount; i++)
                {
                    parallelLooper.AddThread();
                }
            }
            #endif

            Space = new Space(parallelLooper);

            game.Camera.LockedUp = Vector3.Up;
            game.Camera.ViewDirection = new Vector3(0, 0, -1);
        }
Ejemplo n.º 2
0
 public void BuildWorld()
 {
     MainThread = Thread.CurrentThread;
     MainThreadID = MainThread.ManagedThreadId;
     ParallelLooper pl = new ParallelLooper();
     for (int i = 0; i < Environment.ProcessorCount; i++)
     {
         pl.AddThread();
     }
     CollisionDetectionSettings.AllowedPenetration = 0.01f;
     PhysicsWorld = new Space(pl);
     PhysicsWorld.TimeStepSettings.MaximumTimeStepsPerFrame = 10;
     PhysicsWorld.ForceUpdater.Gravity = new Vector3(0, 0, -9.8f * 3f / 2f);
     PhysicsWorld.DuringForcesUpdateables.Add(new LiquidVolume(this));
     PhysicsWorld.TimeStepSettings.TimeStepDuration = 1f / TheServer.CVars.g_fps.ValueF;
     Collision = new CollisionUtil(PhysicsWorld);
     EntityConstructors.Add(EntityType.ITEM, new ItemEntityConstructor());
     EntityConstructors.Add(EntityType.BLOCK_ITEM, new BlockItemEntityConstructor());
     EntityConstructors.Add(EntityType.GLOWSTICK, new GlowstickEntityConstructor());
     EntityConstructors.Add(EntityType.MODEL, new ModelEntityConstructor());
     EntityConstructors.Add(EntityType.SMOKE_GRENADE, new SmokeGrenadeEntityConstructor());
     EntityConstructors.Add(EntityType.MUSIC_BLOCK, new MusicBlockEntityConstructor());
     ChunkManager = new ChunkDataManager();
     ChunkManager.Init(this);
     //LoadRegion(new Location(-MaxViewRadiusInChunks * 30), new Location(MaxViewRadiusInChunks * 30), true);
     //TheServer.Schedule.RunAllSyncTasks(0.016); // TODO: Separate per-region scheduler // Also don't freeze the entire server/region just because we're waiting on chunks >.>
     //SysConsole.Output(OutputType.INIT, "Finished building chunks! Now have " + LoadedChunks.Count + " chunks!");
 }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public MultithreadedScalingTestDemo(DemosGame game)
            : base(game)
        {
            simulationBuilders = new Func<Space, int>[]
                                     {
                                         BuildPileSimulation,
                                         BuildWallSimulation,
                                         BuildPlanetSimulation
                                     };

            #if WINDOWS
            int coreCountMax = Environment.ProcessorCount;

            testResults = new double[coreCountMax, simulationBuilders.Length];

            int reruns = 1;
            for (int i = 0; i < reruns; i++)
            {
                GC.Collect();
                var looper = new ParallelLooper();

                //Try different thread counts.
                for (int j = 0; j < coreCountMax; j++)
                {
                    looper.AddThread();
                    for (int k = 0; k < simulationBuilders.Length; k++)
                        testResults[j, k] = RunTest(looper, simulationBuilders[k]);
                    GC.Collect();

                }
            }
            #else
            testResults = new double[4, simulationBuilders.Length];
            int reruns = 10;
            for (int i = 0; i < reruns; i++)
            {
                GC.Collect();
                var threadManager = new SpecializedThreadManager();

                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 1 }); }, null);

                for (int k = 0; k < simulationBuilders.Length; k++)
                    testResults[0, k] += RunTest(threadManager, simulationBuilders[k]);
                GC.Collect();

                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 3 }); }, null);
                for (int k = 0; k < simulationBuilders.Length; k++)
                    testResults[1, k] += RunTest(threadManager, simulationBuilders[k]);
                GC.Collect();
                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 5 }); }, null);
                for (int k = 0; k < simulationBuilders.Length; k++)
                    testResults[2, k] += RunTest(threadManager, simulationBuilders[k]);
                GC.Collect();
                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 4 }); }, null);
                for (int k = 0; k < simulationBuilders.Length; k++)
                    testResults[3, k] += RunTest(threadManager, simulationBuilders[k]);
                GC.Collect();
            }
            #endif
        }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public BroadPhaseMultithreadingTestDemo(DemosGame game)
            : base(game)
        {
            Space.Solver.IterationLimit = 0;


#if WINDOWS
            int coreCountMax = Environment.ProcessorCount;
            int splitOffsetMax = 6;
            testResults = new double[coreCountMax, splitOffsetMax + 1];

            int reruns = 10;
            for (int i = 0; i < reruns; i++)
            {
                GC.Collect();
                var looper = new ParallelLooper();



                //Try different thread counts.
                for (int j = 0; j < coreCountMax; j++)
                {
                    looper.AddThread();
                    //Try different split levels.);
                    for (int k = 0; k <= splitOffsetMax; k++)
                    {
                        testResults[j, k] += RunTest(k, looper);
                        GC.Collect();
                    }
                }
            }

            for (int i = 0; i < testResults.GetLength(0); i++)
            {
                for (int j = 0; j < testResults.GetLength(1); j++)
                {
                    testResults[i, j] /= reruns;
                }
            }
#else
            int splitOffsetMax = 6;

            testResults = new double[4, splitOffsetMax + 1];

            int reruns = 10;
            for (int i = 0; i < reruns; i++)
            {
                var threadManager = new SpecializedThreadManager();
                GC.Collect();

                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 1 }); }, null);
                for (int j = 0; j <= splitOffsetMax; j++)
                {
                    testResults[0, j] += RunTest(j, threadManager);
                    GC.Collect();
                }
                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 3 }); }, null);
                for (int j = 0; j <= splitOffsetMax; j++)
                {
                    testResults[1, j] += RunTest(j, threadManager);
                    GC.Collect();
                }
                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 5 }); }, null);
                for (int j = 0; j <= splitOffsetMax; j++)
                {
                    testResults[2, j] += RunTest(j, threadManager);
                    GC.Collect();
                }
                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 4 }); }, null);
                for (int j = 0; j <= splitOffsetMax; j++)
                {
                    testResults[3, j] += RunTest(j, threadManager);
                    GC.Collect();
                }
            }

            for (int i = 0; i < testResults.GetLength(0); i++)
            {
                for (int j = 0; j < testResults.GetLength(1); j++)
                {
                    testResults[i,j] /= reruns;
                }
            }
#endif


        }
Ejemplo n.º 5
0
 /// <summary>
 /// Builds the physics world.
 /// </summary>
 public void BuildWorld()
 {
     ParallelLooper pl = new ParallelLooper();
     for (int i = 0; i < Environment.ProcessorCount; i++)
     {
         pl.AddThread();
     }
     CollisionDetectionSettings.AllowedPenetration = 0.01f;
     PhysicsWorld = new Space(pl);
     PhysicsWorld.TimeStepSettings.MaximumTimeStepsPerFrame = 10;
     // Set the world's general default gravity
     PhysicsWorld.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, 0, -9.8f * 3f / 2f);
     PhysicsWorld.DuringForcesUpdateables.Add(new LiquidVolume(this));
     // Load a CollisionUtil instance
     Collision = new CollisionUtil(PhysicsWorld);
 }
Ejemplo n.º 6
0
        public static void Test()
        {
            float leafMinSize = 1;
            float leafMaxSize = 100;
            float leafSizePower = 10;
            int queryCount = 1000000;
            int selfTestCount = 1;
            int refitCount = 1;
            int frameCount = 2048;
            float dt = 1 / 60f;

            VelocityDescription velocityDescription = new VelocityDescription
            {
                MinVelocity = 0,
                MaxVelocity = 10,
                VelocityDistributionPower = 10,
                PortionOfMovingLeaves = 1
            };

            Vector3 querySize = new Vector3(20);
            int queryLocationCount = 16384; //<-- POWER OF TWO!!! REMEMBER!

            ParallelLooper looper = new ParallelLooper();
            for (int i = 0; i < Environment.ProcessorCount; ++i)
            {
                looper.AddThread();
            }


#if RANDOMLEAVES
            BoundingBox randomLeafBounds = new BoundingBox { Min = new Vector3(0, 0, 0), Max = new Vector3(629.96f) };
            BoundingBox queryBounds = randomLeafBounds;
            int randomLeafCount = 65536;

#else
            int leafCountX = 64;
            int leafCountY = 64;
            int leafCountZ = 64;
            float leafGap = 10;
            BoundingBox queryBounds = new BoundingBox { Min = new Vector3(0), Max = new Vector3(leafCountX, leafCountY, leafCountZ) * (new Vector3(leafSize) + new Vector3(leafGap)) };
#endif

            {

                var queries = GetQueryLocations(queryLocationCount, queryBounds, querySize);

#if RANDOMLEAVES
                var leaves = GetRandomLeaves(randomLeafCount, randomLeafBounds, new Vector3(leafMinSize), new Vector3(leafMaxSize), leafSizePower, velocityDescription);
#else
                var leaves = GetLeaves(leafCountX, leafCountY, leafCountZ, leafSize, leafGap);
#endif
                GC.Collect();
                //TestVectorized(leaves, queries, queryCount, selfTestCount, refitCount);
#if RANDOMLEAVES
                leaves = GetRandomLeaves(randomLeafCount, randomLeafBounds, new Vector3(leafMinSize), new Vector3(leafMaxSize), leafSizePower, velocityDescription);
#else
                leaves = GetLeaves(leafCountX, leafCountY, leafCountZ, leafSize, leafGap);
#endif
                GC.Collect();
                //TestBaseline(leaves, queries, queryCount, selfTestCount, refitCount);
#if RANDOMLEAVES
                leaves = GetRandomLeaves(randomLeafCount, randomLeafBounds, new Vector3(leafMinSize), new Vector3(leafMaxSize), leafSizePower, velocityDescription);
#else
                leaves = GetLeaves(leafCountX, leafCountY, leafCountZ, leafSize, leafGap);
#endif
                GC.Collect();
                var results = TestSingleArray(leaves, queries, randomLeafBounds, queryCount, selfTestCount, refitCount, frameCount, dt, looper);

                using (var stream = File.Open("newTreeResults.txt", FileMode.Create))
                {
                    using (var textWriter = new StreamWriter(stream))
                    {
                        results.Save(textWriter);
                    }
                }
            }

            {

#if RANDOMLEAVES
                var leaves = GetRandomLeavesBEPU(randomLeafCount, randomLeafBounds, new Vector3(leafMinSize), new Vector3(leafMaxSize), leafSizePower, velocityDescription);
#else
                var leaves = GetLeavesBEPU(leafCountX, leafCountY, leafCountZ, leafSize, leafGap);
#endif
                var queries = GetBEPUQueryLocations(queryLocationCount, queryBounds, querySize);

                GC.Collect();
                //TestBEPU(leaves, queries, queryCount, selfTestCount, refitCount);
                var results = TestDH(leaves, queries, ref randomLeafBounds, queryCount, selfTestCount, refitCount, frameCount, dt, looper);
                using (var stream = File.Open("oldDHResults.txt", FileMode.Create))
                {
                    using (var textWriter = new StreamWriter(stream))
                    {
                        results.Save(textWriter);
                    }
                }
            }

        }