Exemple #1
0
    private void ScheduleTarget( HotSpotTarget target, double time )
    {
        bool noTargets = (0 == m_JobCollection.Count);

        //-- Schedule the new target; start by checking if there are any other targets scheduled at the same time
        LinkedList<HotSpotTarget> simultaneousTargets;
        bool found = m_JobCollection.TryGetValue( time, out simultaneousTargets );
        if( !found )
        {
            //-- No other targets were registered at that time slot, so let's register a
            //   new list of targets for that time
            simultaneousTargets = new LinkedList<HotSpotTarget>();
            m_JobCollection.Add( time, simultaneousTargets );
        }

        //-- Add our new target to the list for its time slot
        simultaneousTargets.AddLast( target );

        //-- If this is the first item to be queued, then we must schedule an
        //   update to affect it
        if( noTargets )
        {
            GameSystem.SendProcessJobMessage( GetID(), time );
        }
    }
Exemple #2
0
    /// <summary>
    /// The implementation of this method code assumes that this function does
    /// not get called twice for the same entity unless there is a 'HandleCollisionEnd'
    /// call for that entity in between.
    /// </summary>
    public override void HandleCollision( Entity collider )
    {
        if( (null == collider) || (collider.GetID() == InstanceID.Invalid_IID) )
        {
            //-- Don't accept null or invalid targets
            return;
        }

        if( !m_Active )
        {
            //-- Don't accept targets when inactive
            return;
        }
        
        if( IsAffectedTarget( collider ) )
        {
            int newTargetSlotIndex = -1;
            if( 0 < m_FreeSlots.Count )
            {
                //-- There's an expired target we can use
                int slotIndex = m_FreeSlots.Dequeue();

                //-- Re-initilize expired target with new data
                HotSpotTarget target = m_TargetPool[slotIndex];
                {
                    target.TargetEntityID = collider.GetID();
                    target.AffectationCount = 0;
                    target.Active = true;
                }

                newTargetSlotIndex = slotIndex;
            }
            else
            {
                //-- There was no more room in the pool, so grow it. Create a new
                //   target and append it to the target pool
                HotSpotTarget newTarget = new HotSpotTarget();
                newTarget.TargetEntityID = collider.GetID();
                newTarget.AffectationCount = 0;
                newTarget.Active = true;

                //-- Add new slot to target pool
                m_TargetPool.Add( newTarget );

                newTargetSlotIndex = m_TargetPool.Count - 1;
            }

            //-- Register the new target to our lookup dictionary
            m_TargetLookup[collider.GetID()] = newTargetSlotIndex;

            //-- Immediately schedule the target to be affected
            ScheduleTarget( newTargetSlotIndex, GameSystem.GetTime() + m_InitialDelay );
        }
    }
Exemple #3
0
    /// <summary>
    /// The implementation of this method code assumes that this function does
    /// not get called twice for the same entity unless there is a 'HandleCollisionEnd'
    /// call for that entity in between.
    /// </summary>
    public override void HandleCollision( Entity collider )
    {
        if( (null == collider) || (collider.GetID() == InstanceID.Invalid_IID) )
        {
            //-- Don't accept null or invalid targets
            return;
        }

        if( !m_Active )
        {
            //-- Don't accept targets when inactive
            return;
        }

        //-- Track the colliding entity
        m_CollidingEntities.Add( collider.GetID() );

        if( IsAffectedTarget( collider ) )
        {
            //-- Create a new target to schedule to be affected
            HotSpotTarget newTarget = new HotSpotTarget();
            newTarget.TargetEntityID = collider.GetID();
            newTarget.AffectationCount = 0;

            //-- Schedule the new target
            ScheduleTarget( newTarget, GameSystem.GetTime() + m_InitialDelay );
        }
    }