Exemple #1
0
        public void Update(Collision collision, long timestamp)
        {
            var parentB = collision.ParentB;
            var parentA = collision.ParentA;

            Id             = Helper.GetPairId(collision.BodyA, collision.BodyB);
            TimeUpdate     = timestamp;
            Collision      = collision;
            _inverseMass   = parentA.InverseMass + parentB.InverseMass;
            Friction       = Math.Min(parentA.Friction, parentB.Friction);
            FrictionStatic = Math.Max(parentA.FrictionStatic, parentB.FrictionStatic);
            Restitution    = Math.Max(parentA.Restitution, parentB.Restitution);
            Slop           = Math.Max(parentA.Slop, parentB.Slop);
            ActiveContacts.Clear();

            Trigger = collision.ParentA.Trigger || collision.ParentB.Trigger;

            if (collision.Collided)
            {
                foreach (var vertex in collision.Supports.Vertexes)
                {
                    var     contactId = vertex.GetId();
                    Contact contact;

                    if (Contacts.TryGetValue(contactId, out contact))
                    {
                        ActiveContacts.Add(contact);
                    }
                    else
                    {
                        var newContact = new Contact()
                        {
                            Id     = contactId,
                            Vertex = vertex
                        };
                        Contacts[contactId] = newContact;
                        ActiveContacts.Add(newContact);
                    }
                }

                _separation = collision.Depth;
                SetActive(true, timestamp);
            }
            else
            {
                if (Active)
                {
                    SetActive(false, timestamp);
                }
            }
        }
        private async Task <TimeSpan> LoadFromExternalDatabase()
        {
            ActiveContacts.Clear();

            var table = await _externalDb.FetchAllContacts();

            _logger.LogInfo("Found " + table.Count + " contacts in databse");
            foreach (var contact in table)
            {
                ActiveContacts.Add(contact);
            }

            ActiveContacts.Sort();

            //TimeScheduler.GetTimeScheduler().AddTask(DS_TASK_NAME, TimeSpan.FromSeconds(INITIAL_DELAY), () => OnTimedEvent());
            return(TimeScheduler.STOP_TIMER);                // This stops us being re-scheduled
        }