Beispiel #1
0
        public static void Benchmark(IBroadphaseInterface broadphaseInterface)
        {
            IList<BroadphaseBenchmarkObject> objects = new List<BroadphaseBenchmarkObject>();
            Stopwatch wallclock = new Stopwatch();
            /* Begin			*/
            for (int iexp = 0; iexp < s_experiments.Length; ++iexp)
            {
                BroadphaseBenchmarkExperiment experiment = DbvtBroadphase.s_experiments[iexp];
                int object_count = experiment.object_count;
                int update_count = (object_count * experiment.update_count) / 100;
                int spawn_count = (object_count * experiment.spawn_count) / 100;
                float speed = experiment.speed;
                float amplitude = experiment.amplitude;
                if (BulletGlobals.g_streamWriter != null)
                {
                    BulletGlobals.g_streamWriter.WriteLine("Experiment #{0} '{1}':", iexp, experiment.name);
                    BulletGlobals.g_streamWriter.WriteLine("\tObjects: {0}", object_count);
                    BulletGlobals.g_streamWriter.WriteLine("\tUpdate: {0}", update_count);
                    BulletGlobals.g_streamWriter.WriteLine("\tSpawn: {0}", spawn_count);
                    BulletGlobals.g_streamWriter.WriteLine("\tSpeed: {0}", speed);
                    BulletGlobals.g_streamWriter.WriteLine("\tAmplitude: {0}", amplitude);
                }
                //srand(180673);
                /* Create objects	*/
                wallclock.Reset();
                //objects.Capacity = object_count;
                for (int i = 0; i < object_count; ++i)
                {
                    BroadphaseBenchmarkObject po = new BroadphaseBenchmarkObject();
                    po.center.X = BroadphaseBenchmark.UnitRand() * 50;
                    po.center.Y = BroadphaseBenchmark.UnitRand() * 50;
                    po.center.Z = BroadphaseBenchmark.UnitRand() * 50;
                    po.extents.X = BroadphaseBenchmark.UnitRand() * 2 + 2;
                    po.extents.Y = BroadphaseBenchmark.UnitRand() * 2 + 2;
                    po.extents.Z = BroadphaseBenchmark.UnitRand() * 2 + 2;
                    po.time = BroadphaseBenchmark.UnitRand() * 2000;
                    po.proxy = broadphaseInterface.CreateProxy(po.center - po.extents, po.center + po.extents, BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE, po, CollisionFilterGroups.BDefaultGroup, CollisionFilterGroups.BDefaultGroup, null, null);
                    objects.Add(po);

                }
                BroadphaseBenchmark.OutputTime("\tInitialization", wallclock, 1);
                /* First update		*/
                wallclock.Reset();
                for (int i = 0; i < objects.Count; ++i)
                {
                    objects[i].update(speed, amplitude, broadphaseInterface);
                }
                BroadphaseBenchmark.OutputTime("\tFirst update", wallclock, 1);
                /* Updates			*/
                wallclock.Reset();
                for (int i = 0; i < experiment.iterations; ++i)
                {
                    for (int j = 0; j < update_count; ++j)
                    {
                        objects[j].update(speed, amplitude, broadphaseInterface);
                    }
                    broadphaseInterface.CalculateOverlappingPairs(null);
                }
                BroadphaseBenchmark.OutputTime("\tUpdate", wallclock, (uint)experiment.iterations);
                /* Clean up			*/
                wallclock.Reset();
                for (int i = 0; i < objects.Count; ++i)
                {
                    broadphaseInterface.DestroyProxy(objects[i].proxy, null);
                    objects[i] = null;
                }
                objects.Clear();
                BroadphaseBenchmark.OutputTime("\tRelease", wallclock, 1);
            }
        }
Beispiel #2
0
        public static void Benchmark(IBroadphaseInterface broadphaseInterface)
        {
            IList <BroadphaseBenchmarkObject> objects = new List <BroadphaseBenchmarkObject>();
            Stopwatch wallclock = new Stopwatch();

            /* Begin			*/
            for (int iexp = 0; iexp < s_experiments.Length; ++iexp)
            {
                BroadphaseBenchmarkExperiment experiment = DbvtBroadphase.s_experiments[iexp];
                int   object_count = experiment.object_count;
                int   update_count = (object_count * experiment.update_count) / 100;
                int   spawn_count  = (object_count * experiment.spawn_count) / 100;
                float speed        = experiment.speed;
                float amplitude    = experiment.amplitude;
                if (BulletGlobals.g_streamWriter != null)
                {
                    BulletGlobals.g_streamWriter.WriteLine("Experiment #{0} '{1}':", iexp, experiment.name);
                    BulletGlobals.g_streamWriter.WriteLine("\tObjects: {0}", object_count);
                    BulletGlobals.g_streamWriter.WriteLine("\tUpdate: {0}", update_count);
                    BulletGlobals.g_streamWriter.WriteLine("\tSpawn: {0}", spawn_count);
                    BulletGlobals.g_streamWriter.WriteLine("\tSpeed: {0}", speed);
                    BulletGlobals.g_streamWriter.WriteLine("\tAmplitude: {0}", amplitude);
                }
                //srand(180673);
                /* Create objects	*/
                wallclock.Reset();
                //objects.Capacity = object_count;
                for (int i = 0; i < object_count; ++i)
                {
                    BroadphaseBenchmarkObject po = new BroadphaseBenchmarkObject();
                    po.center.X  = BroadphaseBenchmark.UnitRand() * 50;
                    po.center.Y  = BroadphaseBenchmark.UnitRand() * 50;
                    po.center.Z  = BroadphaseBenchmark.UnitRand() * 50;
                    po.extents.X = BroadphaseBenchmark.UnitRand() * 2 + 2;
                    po.extents.Y = BroadphaseBenchmark.UnitRand() * 2 + 2;
                    po.extents.Z = BroadphaseBenchmark.UnitRand() * 2 + 2;
                    po.time      = BroadphaseBenchmark.UnitRand() * 2000;
                    po.proxy     = broadphaseInterface.CreateProxy(po.center - po.extents, po.center + po.extents, BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE, po, CollisionFilterGroups.DefaultFilter, CollisionFilterGroups.DefaultFilter, null, null);
                    objects.Add(po);
                }
                BroadphaseBenchmark.OutputTime("\tInitialization", wallclock, 1);
                /* First update		*/
                wallclock.Reset();
                for (int i = 0; i < objects.Count; ++i)
                {
                    objects[i].update(speed, amplitude, broadphaseInterface);
                }
                BroadphaseBenchmark.OutputTime("\tFirst update", wallclock, 1);
                /* Updates			*/
                wallclock.Reset();
                for (int i = 0; i < experiment.iterations; ++i)
                {
                    for (int j = 0; j < update_count; ++j)
                    {
                        objects[j].update(speed, amplitude, broadphaseInterface);
                    }
                    broadphaseInterface.CalculateOverlappingPairs(null);
                }
                BroadphaseBenchmark.OutputTime("\tUpdate", wallclock, (uint)experiment.iterations);
                /* Clean up			*/
                wallclock.Reset();
                for (int i = 0; i < objects.Count; ++i)
                {
                    broadphaseInterface.DestroyProxy(objects[i].proxy, null);
                    objects[i] = null;
                }
                objects.Clear();
                BroadphaseBenchmark.OutputTime("\tRelease", wallclock, 1);
            }
        }