コード例 #1
0
 public ContextObserver(PhysicalContext <TEntityKey> observableContext)
 {
     LastObservedTick          = ObservationBeginTick = observableContext.Ticks;
     ObservableContext         = observableContext;
     IsActive                  = true;
     ObservableContext.OnTick += OnTick;
 }
コード例 #2
0
 /// <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;
 }
コード例 #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()
            ));
 }
コード例 #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));
        }
コード例 #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();
 }
コード例 #6
0
 internal LockedPhysicalContextException(PhysicalContext <TEntityKey> context)
     : base("Access to PhysicalContext.Tick() method are illegal while PhysicalContext.Tick() method is executed.")
 {
     Context = context;
 }
コード例 #7
0
 internal FilledPhysicalContextException(PhysicalContext <TEntityKey> context)
     : base($"Physical context is already filled. Can't add entities anymore.")
 {
     Context = context;
 }
コード例 #8
0
 internal UnexistingEntityException(PhysicalContext <TEntityKey> context, TEntityKey key)
     : base($"Physical context doesn't contain entity with key {key}.")
 {
     Context   = context;
     EntityKey = key;
 }
コード例 #9
0
 internal UninitializedPhysicalContextException(PhysicalContext <TEntityKey> context)
     : base($"Access to Tick() method is denied until context will be filled")
 {
     Context = context;
 }