Ejemplo n.º 1
0
Archivo: R0.cs Proyecto: Mechami/router
        /** \brief Routes a message of the specified event to all subscribers outside the specified radius. */
        /// \returns Enqueues all returned data from subscribers of this event type in the specified queue.\n
        /// \returns Enqueues nothing if the message cannot be sent.
        public static void RouteMessageAreaInverse(AreaMessage MessageParameters /**< Struct containing parameters for the area message. */, Queue <R> OutputQueue /**< Queue to output returned values into. */)
        {
            CleanDeadRoutes(MessageParameters.EventType);

            if (TablesExist && EventIsPopulated(MessageParameters.EventType))
            {
                decimal           RadiusD = new Decimal(MessageParameters.Radius);
                List <Route <R> > RT      = RouteTable[MessageParameters.EventType].FindAll(x => (new Decimal(Vector3.Distance(MessageParameters.Origin, x.Subscriber.transform.position)) > RadiusD));
                RT.ForEach(x => OutputQueue.Enqueue(x.Address()));
            }
        }
Ejemplo n.º 2
0
        /** \brief Routes a message of the specified event to all subscribers inside the specified radius. */
        /** If UseInverse is true then a message will be routed to all subscribers outside the specified radius. */
        /// \note Only works for subscribed GameObjects.
        public void RouteMessageArea(AreaMessage Parameters /**< Struct containing parameters for the area message. */, bool DoRayCheck = false /**< Send messages only to entities that pass a Line-Of-Sight check. */)
        {
            CleanDeadRoutes(Parameters.EventType);

            if (TableExists && EventIsPopulated(Parameters.EventType))
            {
                Action <Route> Mailman = DoRayCheck?
                                         new Action <Route>(x => SendAreaChecked(x, Parameters)) :
                                         new Action <Route>(x => SendArea(x, Parameters));

                RouteTable[Parameters.EventType].ForEach(Mailman);
            }
        }
Ejemplo n.º 3
0
        private void SendArea(Route RT, AreaMessage AM)
        {
            decimal Distance = new Decimal(
                Vector3.Distance(AM.Origin, RT.Subscriber.transform.position));
            decimal Radius = new Decimal(AM.Radius);

            if (AM.UseInverse && (Distance >= Radius))
            {
                RT.Address();
            }

            if (!AM.UseInverse && (Distance < Radius))
            {
                RT.Address();
            }
        }
Ejemplo n.º 4
0
        private void SendAreaChecked(Route RT, AreaMessage AM)
        {
            Vector3 Position = RT.Subscriber.transform.position;
            decimal Distance = new Decimal(
                Vector3.Distance(AM.Origin, Position));
            decimal Radius = new Decimal(AM.Radius);

            if (AM.UseInverse &&
                (Distance >= Radius) && !Physics.Linecast(AM.Origin, Position))
            {
                RT.Address();
            }

            if (!AM.UseInverse &&
                (Distance < Radius) && !Physics.Linecast(AM.Origin, Position))
            {
                RT.Address();
            }
        }
Ejemplo n.º 5
0
Archivo: R0.cs Proyecto: Mechami/router
        /** \brief Routes a message of the specified event to all subscribers outside the specified radius. */
        /// \returns Adds all returned data from subscribers of this event type to the specified list.\n
        /// \returns Assigns null to OutputList if the message cannot be sent.
        public static void RouteMessageAreaInverse(AreaMessage MessageParameters /**< Struct containing parameters for the area message. */, out List <R> OutputList /**< List to output returned values into. */)
        {
            CleanDeadRoutes(MessageParameters.EventType);
            OutputList = null;

            if (TablesExist && EventIsPopulated(MessageParameters.EventType))
            {
                decimal           RadiusD = new Decimal(MessageParameters.Radius);
                List <Route <R> > RT      = RouteTable[MessageParameters.EventType].FindAll(x => (new Decimal(Vector3.Distance(MessageParameters.Origin, x.Subscriber.transform.position)) > RadiusD));
                OutputList = new List <R>(RT.Count);

                for (int i = 0; i < RT.Count; i++)
                {
                    OutputList.Add(RT[i].Address());
                }

                OutputList.TrimExcess();
            }
        }
Ejemplo n.º 6
0
Archivo: R0.cs Proyecto: Mechami/router
        /** \brief Routes a message of the specified event to all subscribers in a radius. */
        /// \returns Returns a List<R> containing all returned data from subscribers of this event type.\n
        /// \returns Otherwise returns null if the message cannot be sent.
        /// \note Only works for subscribed GameObjects.
        /// \bug Seems to call some routes twice; Possibly present in other methods as-well.
        /// \todo Regression testing for double-routing bug.
        public static List <R> RouteMessageArea(AreaMessage MessageParameters /**< Struct containing parameters for the area message. */)
        {
            CleanDeadRoutes(MessageParameters.EventType);

            List <R> Results = null;

            if (TablesExist && EventIsPopulated(MessageParameters.EventType))
            {
                decimal           RadiusD = new Decimal(MessageParameters.Radius);
                List <Route <R> > RT      = RouteTable[MessageParameters.EventType].FindAll(x => (new Decimal(Vector3.Distance(MessageParameters.Origin, x.Subscriber.transform.position)) <= RadiusD));
                Results = new List <R>(RT.Count);

                for (int i = 0; i < RT.Count; i++)
                {
                    Results.Add(RT[i].Address());
                }

                Results.TrimExcess();
            }

            return(Results);
        }