Terrain maximum age

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Terrain maximum age

Post by imtrobin »

Hi

I'm finding that when I collide with the terrain, the Space.entities coutn goes up by quite a lot. so I trying to set them to have a shorter time span. I changed the values to

terrain_.maximumAge = 0;
terrain_.deletionInterval = 0.01f;

But it seems to take 3 second before it is removed. So what does the value range like 0.01 mean.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Terrain maximum age

Post by imtrobin »

Actually is there a way to prevent it from add to the entities list. I'm using the large terrain where a lot of units are shooting and fighting, and the performance is really horrible because when they hit the terrain which is generating thousands of entities. I'm using kinematic missile to test collide with the terrain, so I don't really need it to be added to the list, until I turn units to dynamic.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain maximum age

Post by Norbo »

The maximumAge is how many intervals pass before it is deleted. If one passes and the maximumAge is 0, then it will be removed- if there isn't something there actively refreshing it. Chances are this is what you're seeing; the entity that needed the triangles there in the first place is still nearby, keeping them around.

The Terrain (and StaticTriangleGroup) both have their own collisionRules property. If the relationship between an entity and the Terrain is 'noPair,' no triangles will be created.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Terrain maximum age

Post by imtrobin »

That isn't quite what I'm seeing. I fire a kinematic entity to hit the terrain, which I remove it almost immidiately (in next frame). The entitie count increases by say 10, drops one due to by removed one, it takes about 3 seconds to return back to normal to remove the 10.

I need to kinematic to collide with terrain, so I cannot use nopair, but I use noresponse. I don't need it to add triangles to the list because it's only the kinematic that's colliding. It can go up to few thousand entities and its killing the performance big time.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain maximum age

Post by Norbo »

I am unable to replicate the problem using those settings; a simple reproduction case (perhaps a modification of one of the demos) would help me track it down.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain maximum age

Post by Norbo »

By any chance is your terrain's maximumNumberOfTrianglesToDelete a very low number relative to the number of triangles being spawned? This would take some time to slowly get back to normal.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Terrain maximum age

Post by imtrobin »

I did not change it so I think it is 200 but don't think so it is the case.
The values are consistent then jump back eg.

11 - initial before collision
19
19
19
and goes on for a few seconds
11
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Terrain maximum age

Post by imtrobin »

I use my own sample, not the demos. I can send you if you need but it's large. This is my setup

The sphere is a kinematic which I can control with keyboard. Once it passes the terrain, the space.entities goes up

Code: Select all


            space_ = new Space (new BEPUphysics.BroadPhases.DynamicBinaryHierarchy ()); //Create the world 

#if XBOX360
            //Note that not all four available hardware threads are used.
            //Currently, BEPUphysics will allocate an equal amount of work to each thread.
            //If two threads are put on one core, it will bottleneck the engine and run significantly slower than using 3 hardware threads.
            space_.threadManager.add(delegate(object information) { Thread.CurrentThread.SetProcessorAffinity(new int[] { 1 }); }, null);
            space_.threadManager.add(delegate(object information) { Thread.CurrentThread.SetProcessorAffinity(new int[] { 3 }); }, null);
            space_.threadManager.add(delegate(object information) { Thread.CurrentThread.SetProcessorAffinity(new int[] { 5 }); }, null); 

            space.useMultithreadedUpdate = true;
#else
            if (Environment.ProcessorCount > 1)
            {
                for (int i = 0; i < Environment.ProcessorCount; i++)
                {
                    space_.threadManager.add ();
                }

                space_.useMultithreadedUpdate = true;
            }
#endif
            space_.simulationSettings.motionUpdate.gravity = new Vector3 (0, -9.81f, 0f); //If left unset, the default value is (0,0,0).

            space_.simulationSettings.timeStep.timeScale = 1f; //If left unset, the default value is 1.
            space_.simulationSettings.collisionResponse.iterations = 15; //If left unset, the default value is 15.
            //Fiddling with margins and position correction is one way to tune the engine for the specific game/simulation.
            space_.simulationSettings.collisionDetection.defaultMargin = .04f;//Defaults to .04f
            space_.simulationSettings.collisionDetection.defaultAllowedPenetration = .005f;//Defaults to .005f

            CollisionGroup collisionGroup1 = new CollisionGroup ()
                          ,collisionGroup2 = new CollisionGroup ();

            space_.simulationSettings.collisionDetection.collisionGroupRules.Add (new CollisionGroupPair (collisionGroup1, collisionGroup2), CollisionRule.noResponse);

            {
                sphere_ = new Sphere (new Vector3 (400, 800, 400), 3.5f, 2);
                sphere_.becomeKinematic ();

                sphere_.tag = ship_;

                sphere_.eventManager.addEventHook (new EventHandlerEntityUpdated (EventEntityUpdated));

                sphere_.collisionRules.group = collisionGroup1;

                space_.add (sphere_);
            }

            {
                physicsTerrain_ = new Terrain (Vector3.Zero);

                IndexBuffer indexBuffer = graphicsTerrain_.Models [0].Meshes [0].IndexBuffer;

                if (indexBuffer.IndexElementSize == IndexElementSize.SixteenBits)
                {
                    short[] indexData = new short [indexBuffer.SizeInBytes / 2];
                    indexBuffer.GetData (indexData);
                }
                else
                {
                    int[] indexData = new int [indexBuffer.SizeInBytes / 4];
                    indexBuffer.GetData (indexData);

                    float[,] heights = new float [graphicsTerrain_.Width, graphicsTerrain_.Height];

                    for (int x = 0; x < graphicsTerrain_.Width; ++x)
                    {
                        for (int z = 0; z < graphicsTerrain_.Height; ++z)
                        {
                            heights[x, z] = graphicsTerrain_.GetHeightMapData(x, z) * graphicsTerrain_.WorldBounds.Max.Y;
                        }
                    }

                    physicsTerrain_.setData(heights, QuadFormats.lowerLeftUpperRight, graphicsTerrain_.WorldBounds.Max.X / (graphicsTerrain_.Height - 1), graphicsTerrain_.WorldBounds.Max.Z / (graphicsTerrain_.Width - 1));


                    physicsTerrain_.collisionRules.group = collisionGroup2;
                    //physicsTerrain_.collisionFilter = 1;

                    physicsTerrain_.maximumAge = 0;
                    physicsTerrain_.deletionInterval = 0.01f;

                    space_.add (physicsTerrain_);
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain maximum age

Post by Norbo »

I wasn't able to replicate the issue using that setup either. I'll probably need a runnable reproduction case; the less code the better. Smaller demos make it easier to isolate the problem.
Post Reply