Example #1
0
 public ContextObserver(PhysicalContext <TEntityKey> observableContext)
 {
     LastObservedTick          = ObservationBeginTick = observableContext.Ticks;
     ObservableContext         = observableContext;
     IsActive                  = true;
     ObservableContext.OnTick += OnTick;
 }
 /// <param name="newValueFunc">
 /// Function for evaluating new <see cref="Value"/> through new observable context state and old value.
 /// If result is <see langword="null"/> <see cref="Value"/> doesn't changes
 /// </param>
 public ContextDependentValue
 (
     TValue startValue,
     PhysicalContext <TEntityKey> observableContext,
     Func <PhysicalContext <TEntityKey>, TValue, TValue?> newValueFunc
 )
     : base(observableContext)
 {
     _newValueFunc       = newValueFunc;
     LastValueChangeTick = ObservationBeginTick;
     Value = startValue;
 }
Example #3
0
 public static ContextProgressTracker <TEntityKey> FromTime
 (
     PhysicalContext <TEntityKey> observableContext,
     double goalTime,
     params double[] checkPoints
 )
 {
     return(new ContextProgressTracker <TEntityKey>
            (
                observableContext,
                (ulong)Math.Round(goalTime / observableContext.TimePerTick),
                (from c in checkPoints select(ulong)(Math.Round(c / observableContext.TimePerTick))).ToArray()
            ));
 }
Example #4
0
        public ContextTracker
        (
            PhysicalContext <TEntityKey> observableContext,
            Func <PhysicalContext <TEntityKey>, TValue> valueFunc,
            ulong interval = 1
        )
            : base(observableContext)
        {
            if (interval == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(interval), "ContextTracker interval should be non-zero");
            }
            _func    = valueFunc;
            Interval = interval;
            _values  = new List <TValue>();

            _currTimer = 0;
            _values.Add(_func(ObservableContext));
        }
Example #5
0
 public ContextProgressTracker
 (
     PhysicalContext <TEntityKey> observableContext,
     ulong goalTick,
     params ulong[] checkPoints
 )
     : base(observableContext)
 {
     if (checkPoints.Any(point => observableContext.Ticks > point || point > goalTick))
     {
         throw new ArgumentOutOfRangeException
               (
                   $"Can't create ContextProgressTracker with checkpoints {CheckPoints}" +
                   $"because one or more of checkpoints are already less than observable" +
                   $"context current tick ({observableContext.Ticks}) or bigger than goal tick ({goalTick})"
               );
     }
     _checkPoints = checkPoints;
     Array.Sort(_checkPoints);
     _currentCheckPointIndex = 0;
     Goal = goalTick;
     Observe();
 }
Example #6
0
 internal LockedPhysicalContextException(PhysicalContext <TEntityKey> context)
     : base("Access to PhysicalContext.Tick() method are illegal while PhysicalContext.Tick() method is executed.")
 {
     Context = context;
 }
 internal FilledPhysicalContextException(PhysicalContext <TEntityKey> context)
     : base($"Physical context is already filled. Can't add entities anymore.")
 {
     Context = context;
 }
 internal UnexistingEntityException(PhysicalContext <TEntityKey> context, TEntityKey key)
     : base($"Physical context doesn't contain entity with key {key}.")
 {
     Context   = context;
     EntityKey = key;
 }
 internal UninitializedPhysicalContextException(PhysicalContext <TEntityKey> context)
     : base($"Access to Tick() method is denied until context will be filled")
 {
     Context = context;
 }