Exemple #1
0
        public void Remove(CollisionProperty property)
        {
            Debug.Assert(inCollisionDetection == 0);

            for (int i = 0; i < entityList.Count; ++i)
            {
                if (entityList[i].CollisionProperty == property)
                {
                    Remove(entityList[i]);
                    return;
                }
            }
        }
Exemple #2
0
        public bool ContainsCollisionEntity(CollisionProperty property)
        {
            Debug.Assert(inCollisionDetection == 0);
            for (int i = 0; i < entityList.Count; ++i)
            {
                if (entityList[i].CollisionProperty == property)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
 public CollisionEntity(
     Entity entity,
     CollisionProperty property,
     VolumeType volumeType,
     object[] volumes,
     bool needAllContacts
     )
 {
     this.entity            = entity;
     this.collisionProperty = property;
     this.volumeType        = volumeType;
     this.volumes           = volumes;
     this.needAllContacts   = needAllContacts;
 }
        //static int collisionCount = 0;

        public void Update(SimulationTime simTime)
        {
            Game.Instance.SimulationThread.Profiler.BeginSection("collision_update");

            //long t1 = System.DateTime.Now.Ticks;

            Game.Instance.SimulationThread.Profiler.BeginSection("collision_detection");

            testList.BeginCollisionDetection();

            //long t2 = System.DateTime.Now.Ticks;

            foreach (CollisionThread t in threads)
            {
                t.Start();
            }

            //long t3 = System.DateTime.Now.Ticks;

            foreach (CollisionThread t in threads)
            {
                t.Join();
            }

            //long t4 = System.DateTime.Now.Ticks;

            testList.EndCollisionDetection();

            Game.Instance.SimulationThread.Profiler.EndSection("collision_detection");

            //long t5 = System.DateTime.Now.Ticks;

            Game.Instance.SimulationThread.Profiler.BeginSection("collision_response");

            foreach (CollisionThread t in threads)
            {
                //System.Console.WriteLine("collisions: " + t.ContactCount);

                for (int i = 0; i < t.ContactCount; ++i)
                {
                    Contact contact = t.GetContact(i);

                    //System.Console.WriteLine(contact.Count);
                    //if (
                    //    entry.EntityA.entity.HasString(CommonNames.Kind) && entry.EntityB.entity.HasString(CommonNames.Kind) &&(
                    //        entry.EntityA.entity.GetString(CommonNames.Kind) == "pillar" ||
                    //        entry.EntityB.entity.GetString(CommonNames.Kind) == "pillar" ||
                    //        (entry.EntityA.entity.GetString(CommonNames.Kind) == "island" && entry.EntityB.entity.GetString(CommonNames.Kind) == "island")
                    //    ))
                    //if ((contact.EntityA.HasString(CommonNames.Kind) && contact.EntityA.GetString(CommonNames.Kind) == "cave") ||
                    //    (contact.EntityB.HasString(CommonNames.Kind) && contact.EntityB.GetString(CommonNames.Kind) == "cave"))
                    //{
                    //    System.Console.WriteLine("Collision {0,4}: between {1} and {2}!", collisionCount, contact.EntityA.Name, contact.EntityB.Name);
                    //    ++collisionCount;
                    //}

                    CollisionProperty propertyA = contact.EntityA.HasProperty("collision") ? contact.EntityA.GetProperty <CollisionProperty>("collision") : null;
                    CollisionProperty propertyB = contact.EntityB.HasProperty("collision") ? contact.EntityB.GetProperty <CollisionProperty>("collision") : null;

                    if (propertyA != null && propertyB != null)
                    {
                        propertyA.FireContact(simTime, contact);
                        contact.Reverse();
                        propertyB.FireContact(simTime, contact);
                    }
                    else
                    {
                        if (propertyA == null && propertyB == null)
                        {
                            throw new System.Exception(string.Format(
                                                           "someone has illegaly removed the collision property from entity {0} and {1}!",
                                                           contact.EntityA.Name, contact.EntityB.Name
                                                           ));
                        }
                        else
                        {
                            throw new System.Exception(string.Format(
                                                           "someone has illegaly removed the collision property from entity {0}!",
                                                           propertyA == null ? contact.EntityA.Name : contact.EntityB.Name
                                                           ));
                        }
                    }
                }
            }

            Game.Instance.SimulationThread.Profiler.EndSection("collision_response");

            //long t6 = System.DateTime.Now.Ticks;

            //long dt1 = t2 - t1;
            //long dt2 = t3 - t2;
            //long dt3 = t4 - t3;
            //long dt4 = t5 - t4;
            //long dt5 = t6 - t5;

            //double ddt1 = (double)dt1 / 10000.0;
            //double ddt2 = (double)dt2 / 10000.0;
            //double ddt3 = (double)dt3 / 10000.0;
            //double ddt4 = (double)dt4 / 10000.0;
            //double ddt5 = (double)dt5 / 10000.0;

            //System.Console.WriteLine("collision detection timing: ");
            //System.Console.WriteLine("  dt1: {0:G}", ddt1);
            //System.Console.WriteLine("  dt2: {0:G}", ddt2);
            //System.Console.WriteLine("  dt3: {0:G}", ddt3);
            //System.Console.WriteLine("  dt4: {0:G}", ddt4);
            //System.Console.WriteLine("  dt5: {0:G} {1}", ddt5, ddt5>10.0?"***************************************************":"");

            Game.Instance.SimulationThread.Profiler.EndSection("collision_update");
        }
 public void RemoveCollisionEntity(CollisionProperty property)
 {
     testList.Remove(property);
 }
 public bool ContainsCollisionEntity(CollisionProperty property)
 {
     return(testList.ContainsCollisionEntity(property));
 }
 public void AddSphereCollisionEntity(Entity entity, CollisionProperty property, object[] spheres, bool needAllContacts)
 {
     testList.Add(new CollisionEntity(entity, property, VolumeType.Sphere3, spheres, needAllContacts));
 }
 public void AddAlignedBox3TreeCollisionEntity(Entity entity, CollisionProperty property, object[] trees, bool needAllContacts)
 {
     testList.Add(new CollisionEntity(entity, property, VolumeType.AlignedBox3Tree, trees, needAllContacts));
 }
 public void AddCylinderCollisionEntity(Entity entity, CollisionProperty property, object[] cylinders, bool needAllContacts)
 {
     testList.Add(new CollisionEntity(entity, property, VolumeType.Cylinder3, cylinders, needAllContacts));
 }