Exemplo n.º 1
0
        /// ----------------------------------------------
        /// FUNCTION:		Insert
        ///
        /// DATE:			March 11, 2019
        ///
        /// REVISIONS:		(none)
        ///
        /// DESIGNER:	    Daniel Shin, Cameron Roberts
        ///
        /// PROGRAMMER:		Daniel Shin, Cameron Roberts
        ///
        /// INTERFACE:      public void Insert (CollisionItem toAdd)
        ///
        /// RETURNS:        void
        ///
        /// NOTES:		    The function inserts a CollisionItem to the circular buffer if the
        ///					item does not already exist in the buffer and the buffer is not full.
        /// ----------------------------------------------
        public void Insert(CollisionItem toAdd)
        {
            lock (padlock) {
                if (!IsFull())
                {
                    CollisionItem cur = ContainsBufferItem(toAdd);
                    if (ContainsBufferItem(toAdd) == null)
                    {
                        Log.V("Adding collision item to the queue");
                        buffer[headPtr++] = toAdd;
                        currentBufferSize++;
                        cur = toAdd;
                        Log.V("Added collision head " + headPtr + ", tail " + tailPtr);
                    }
                    else
                    {
                        Log.V("Incrementing validity of existing collision item. Validity " + cur.validity);
                    }
                    if (++cur.validity == requiredValidity && !cur.isSignalSent)
                    {
                        SignalCollision(cur);
                    }
                }
                else
                {
                    throw new OutOfMemoryException("Not enough space in circular buffer to insert a new element.");
                }

                headPtr = headPtr % buffer.Length;
            }
        }
Exemplo n.º 2
0
        /// ----------------------------------------------
        /// FUNCTION:		ContainsBufferItem
        ///
        /// DATE:			March 11, 2019
        ///
        /// REVISIONS:		(none)
        ///
        /// DESIGNER:	    Daniel Shin
        ///
        /// PROGRAMMER:		Daniel Shin, Cameron Roberts
        ///
        /// INTERFACE:      private CollisionItem ContainsBufferItem (CollisionItem toAdd)
        ///
        /// RETURNS:        CollisionItem; returns the CollisionItem in the buffer we are looking for,
        ///					null if it does not exist.
        ///
        /// NOTES:		    The function searches for a CollisionItem in the buffer and returns it if it exists
        ///					and returns null if it does not.
        /// ----------------------------------------------
        private CollisionItem ContainsBufferItem(CollisionItem toAdd)
        {
            for (int i = tailPtr; i % MaxBufferSize != headPtr % MaxBufferSize; i++)
            {
                if (!buffer[i].Equals(toAdd))
                {
                    continue;
                }
                return(buffer[i]);
            }

            return(null);
        }
Exemplo n.º 3
0
        /// ----------------------------------------------
        /// FUNCTION:		Equals
        ///
        /// DATE:			March 11, 2019
        ///
        /// REVISIONS:		(none)
        ///
        /// DESIGNER:	    Daniel Shin
        ///
        /// PROGRAMMER:		Daniel Shin, Cameron Roberts
        ///
        /// INTERFACE:      public override bool Equals (object obj)
        ///
        /// RETURNS:        bool; returns true if two CollisionItem is the same, false otherwise.
        ///
        /// NOTES:		    A overridden Equals method for CollisionItem.
        /// ----------------------------------------------
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (obj.GetType() != typeof(CollisionItem))
            {
                return(false);
            }
            CollisionItem other = (CollisionItem)obj;

            Log.V(other.collisionId + " = " + collisionId);

            return(abilityId == other.abilityId && actorHitId == other.actorHitId && actorCastId == other.actorCastId && collisionId == other.collisionId);
        }
Exemplo n.º 4
0
 private void SignalCollision(CollisionItem toSignal)
 {
     Log.V("Signal collision " + toSignal.abilityId + ", " + toSignal.actorHitId + ", " + toSignal.actorCastId);
     toSignal.isSignalSent = true;
     gameState.TriggerAbility(toSignal.abilityId, toSignal.actorHitId, toSignal.actorCastId);
 }