Ejemplo n.º 1
0
 public void SafeAdd(Type type, JObject jObject)
 {
     // we have a local lock here
     lock (_lock)
     {
         if (!_networkedComponentsInGameObject.ContainsKey(type))
         {
             var newComponent = gameObject.AddComponent(type);
             _networkedComponentsInGameObject.Add(type, new UpdateEvent());
             ComponentUpdater.UpdateObjectOfType((NetworkedComponent)newComponent, jObject);
         }
         else
         {
             _networkedComponentsInGameObject[type].AddNewestMessage(jObject);
         }
     }
 }
Ejemplo n.º 2
0
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem basequerySpecifier)
        {
            ITimeSpaceExchangeItem querySpecifier = basequerySpecifier as ITimeSpaceExchangeItem;

            if (querySpecifier == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            //------------------------------------------------------
            // Check if we need to update the output component

            // Time set of query must be defined and have at least 1 time
            if (querySpecifier.TimeSet == null ||
                querySpecifier.TimeSet.Times == null ||
                querySpecifier.TimeSet.Times.Count == 0)
            {
                throw new Exception("Invalid query specifier \"" + querySpecifier.Id +
                                    "\" for in GetValues() call to time decorater " + Id);
            }

            // Determine query time
            double queryTimeMjd = querySpecifier.TimeSet.Times[querySpecifier.TimeSet.Times.Count - 1].End().StampAsModifiedJulianDay;

            // Determine the times available in the buffer
            double        availableTimeMjd = Double.NegativeInfinity;
            IList <ITime> currentTimes     = TimeSet.Times;

            if (currentTimes.Count > 0)
            {
                availableTimeMjd = currentTimes[currentTimes.Count - 1].End().StampAsModifiedJulianDay;
            }

            // Check if we need to update
            // In case the output component is "busy", this may not actually update values
            // up to queryTimeMjd, in which case the _buffer.GetValues below will extrapolate.
            if (availableTimeMjd < queryTimeMjd)
            {
                if (ComponentUpdater == null)
                {
                    throw new Exception("Failed when trying to update time buffer (no updater is specified)");
                }
                ComponentUpdater.Update(querySpecifier);
            }

            //------------------------------------------------------
            // Retrieve values from the buffer

            // Return the values for the required time(s)
            IList <IList <double> > resultValues = new List <IList <double> >();

            if (querySpecifier.TimeSet != null && querySpecifier.TimeSet.Times != null)
            {
                for (int t = 0; t < querySpecifier.TimeSet.Times.Count; t++)
                {
                    ITime    queryTime         = querySpecifier.TimeSet.Times[t];
                    double[] valuesForTimeStep = _buffer.GetValues(queryTime);
                    resultValues.Add(valuesForTimeStep);
                }
            }
            ITime earliestConsumerTime = ExchangeItemHelper.GetEarliestConsumerTime(this);

            if (earliestConsumerTime != null)
            {
                _buffer.ClearBefore(earliestConsumerTime);
            }
            return(new TimeSpaceValueSet <double>(resultValues));
        }
Ejemplo n.º 3
0
 public void Update(NetworkedComponent component)
 {
     HasBeenUpdatedSinceLastGet = false;
     ComponentUpdater.UpdateObjectOfType(component, _mostRecentMessage);
 }