Example #1
0
        /// <summary>
        ///     Initializes the usertracker and activates the kienct.
        ///     Dabei wird aus der Konfigurationsdatei die zuletzt verwendete
        ///     Auswahlgeste und Ersetzungstrategie verwendet.
        ///     <param name='filter'>
        ///         The gesture a user makes to register to the gesture control.
        ///     </param>
        ///     <param name='replace'>
        ///        The replacement strategy how bodys shall be replaced by another activation of the gesture control.
        ///     </param>
        ///     <returns>the initilized user tracker</returns>
        /// </summary>
        private static UserTracker InitializeUserTracker(GestureStrategy filter, ReplacementStrategy replace)
        {
            UserTracker userTracker = new UserTracker(filter, replace, true);

            userTracker.InitializeSensor();
            return(userTracker);
        }
Example #2
0
        /// <summary>
        ///   write-through / write-allocate approach.
        /// </summary>

        /**
         *  In the case of a cache hit, we must certainly modify the contents of the cache
         *  line, because subsequent reads to that line must return the most up-to-date information.
         *  Regarding deffering of write there are two options: 1)writeback and 2) write-through
         *
         *  write-through:  write both in the cache and in the next level of the hierarchy.
         *                  next level in hierarchy should be updated immediately after call write to cache.
         *                  With regard to whether write to cache in case of write miss there are two
         *                  options: 1) write-allocate and 2) write-around.
         *
         *
         *  write-allocate, in case of miss is to treat the write miss as a read miss followed by
         *                  a write hit. In contrary to write-around that is writes
         *                  ONLY in the next level of the memory hierarchy.
         */
        public override void WriteWord(Tag tag, Word word)
        {
            // for both hit and miss we read from lower level in memory hierarchy
            // because in any case we are going to save data in cache
            // for hit - in the same set as old word occupies (but the whole new line),
            // for miss - in any set returned by replacement algorithm

            storage_.WriteWord(tag, word.Buffer); // if can add new record then words is not empty

            List <Word> words = storage_.ReadLine(tag, cache_.CacheGeometry.WordsInLine);

            if (words.Count != 0)
            {
                int  setIndex      = 0;
                bool isFirstInLine = Util.ConvertToInt(tag) == words[0].Tag;
                bool invalidate    = !isFirstInLine;
                Word cachedWord    = cache_.ReadWord(tag, invalidate);
                if (isFirstInLine && !cachedWord.IsEmpty)
                {
                    // hit - rewrite old line in the same place
                    setIndex = cachedWord.SetIndex;
                }
                {
                    //miss or passed tag is not first in line and therefore tag maps not in old line
                    // ans replacement algorithm select new set index
                    setIndex = ReplacementStrategy.SelectVictim(tag);
                }
                cache_.SaveLine(setIndex, tag, words);
            }
        }
Example #3
0
        private Match FindMatch(ReplacementStrategy replacementStrategy, string filter = "", bool allowPartialMatch = true)
        {
            IEnumerable <Match> filteredMatches = GetMatches(filter, allowPartialMatch);

            if (filteredMatches == null)
            {
                return(null);
            }

            switch (replacementStrategy)
            {
            case ReplacementStrategy.First:
                return(filteredMatches.FirstOrDefault());

            case ReplacementStrategy.Last:
                return(filteredMatches.LastOrDefault());

            case ReplacementStrategy.Random:
                return(Utils.Choose(filteredMatches, WeightOfMatch, systemRandom));

            default:
                Debug.Log("Replacement strategy not supported. ");
                return(null);
            }
        }
    /// <summary>
    /// Inventory move in which the object was not previously in the inventory system (not in any ItemSlot)
    /// and now is.
    /// </summary>
    /// <param name="addedObject"></param>
    /// <param name="toSlot"></param>
    /// <param name="replacementStrategy">what to do if toSlot is already occupied</param>
    /// <returns></returns>
    public static InventoryMove Add(GameObject addedObject, ItemSlot toSlot, ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel)
    {
        var pu = addedObject.GetComponent <Pickupable>();

        if (pu == null)
        {
            Logger.LogErrorFormat("{0} has no pickupable, thus cannot be added to inventory", Category.Inventory, addedObject);
        }
        return(new InventoryMove(InventoryMoveType.Add, pu, null, toSlot, replacementStrategy: replacementStrategy));
    }
Example #5
0
 public InventoryMove(InventoryMoveType inventoryMoveType, Pickupable movedObject, ItemSlot fromSlot, ItemSlot slot,
                      InventoryRemoveType?removeType          = null, BodyPartType?throwAim = null, Vector2?worldTargetVector = null, SpinMode?throwSpinMode = null,
                      ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel)
 {
     InventoryMoveType   = inventoryMoveType;
     MovedObject         = movedObject;
     FromSlot            = fromSlot;
     ToSlot              = slot;
     RemoveType          = removeType;
     ThrowAim            = throwAim;
     WorldTargetVector   = worldTargetVector;
     ThrowSpinMode       = throwSpinMode;
     ReplacementStrategy = replacementStrategy;
 }
        private void HandleOutgoing([NotNull] IEntity target, [NotNull] IEnumerable <IEntity> sources,
                                    [NotNull] IThreatModel model, IDiagram diagram, ReplacementStrategy strategy)
        {
            var outgoing = model.DataFlows.Where(x => sources.Any(y => y.Id == x.SourceId)).ToArray();

            if (outgoing.Any())
            {
                foreach (var flow in outgoing)
                {
                    var existing = model.GetDataFlow(target.Id, flow.TargetId);
                    HandleOutgoingDataFlow(target, model, diagram, strategy, flow, existing);
                }
            }
        }
Example #7
0
    /// <summary>
    /// Inventory move in which the object was not previously in the inventory system (not in any ItemSlot)
    /// and now is.
    /// </summary>
    /// <param name="addedObject"></param>
    /// <param name="toSlot"></param>
    /// <param name="replacementStrategy">what to do if toSlot is already occupied</param>
    /// <returns></returns>
    public static InventoryMove Add(GameObject addedObject, ItemSlot toSlot, ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel, bool IgnoreRestraints = false)
    {
        if (addedObject == null)
        {
            Logger.LogErrorFormat("Attempted to create inventory move to slot {0} for null object", Category.Inventory, toSlot);
            return(null);
        }
        var pu = addedObject.GetComponent <Pickupable>();

        if (pu == null)
        {
            Logger.LogErrorFormat("{0} has no pickupable, thus cannot be added to inventory", Category.Inventory, addedObject);
        }
        return(new InventoryMove(InventoryMoveType.Add, pu, null, toSlot, replacementStrategy: replacementStrategy, ignoreRestraints: IgnoreRestraints));
    }
        private bool Validate([NotNull] IEntity target, [NotNull] IEnumerable <IEntity> sources,
                              [NotNull] IThreatModel model, ReplacementStrategy strategy)
        {
            bool result = false;

            var cycles = model.DataFlows.Where(x => (sources.Any(y => y.Id == x.TargetId) || x.TargetId == target.Id) &&
                                               (sources.Any(y => y.Id == x.SourceId) || x.SourceId == target.Id));

            if (cycles.Any())
            {
                ShowWarning?.Invoke($"Unable to merge, because {cycles.Count()} Flows would create cycles, including '{cycles.First().Name}'");
            }
            else if (strategy == ReplacementStrategy.Stop)
            {
                var incoming   = model.DataFlows.Where(x => sources.Any(y => y.Id == x.TargetId));
                var inExisting = model.DataFlows.Where(x => x.TargetId == target.Id && incoming.Any(y => y.SourceId == x.SourceId));
                if (inExisting.Any())
                {
                    ShowWarning?.Invoke($"Unable to merge, because {inExisting.Count()} incoming Flows already exist, including '{inExisting.First().Name}'");
                }
                else
                {
                    var outgoing    = model.DataFlows.Where(x => sources.Any(y => y.Id == x.SourceId));
                    var outExisting = model.DataFlows.Where(x => x.SourceId == target.Id && outgoing.Any(y => y.TargetId == x.TargetId));
                    if (outExisting.Any())
                    {
                        ShowWarning?.Invoke($"Unable to merge, because {outExisting.Count()} outgoing Flows already exist, including '{outExisting.First().Name}'");
                    }
                    else
                    {
                        result = true;
                    }
                }
            }
            else
            {
                result = true;
            }

            return(result);
        }
        private Config(byte sizeBits, byte setBits, ReplacementStrategy strategy,
                       Action <ReplacementArgs <TValue, TKey> > replacementStrategyHr) : base()
        {
            if (sizeBits < MinCacheSizeBits || sizeBits > MaxCacheSizeBits)
            {
                throw new ArgumentOutOfRangeException($"sizeBits argument must have a value between {MinCacheSizeBits} and {MaxCacheSizeBits}");
            }
            if (setBits < 0)
            {
                throw new ArgumentOutOfRangeException(@"setBits cannot be less than 0");
            }
            if (setBits > sizeBits)
            {
                throw new ArgumentException(@"setBits argument value cannot be greater than value of sizeBits");
            }

            if (strategy == ReplacementStrategy.Custom && replacementStrategyHr == null)
            {
                throw new ArgumentNullException(@"replacementStrategyHr is reguired if custom replacement strategy is used,");
            }

            Size        = 2 << (sizeBits - 1);
            ItemsPerSet = (setBits <= 0) ? Size: 2 << (setBits - 1);
            if (setBits == 0) //one set. Fully associative
            {
                CacheType = CachingAlgorithm.FullyAssociative;
            }
            else if (setBits == sizeBits) //number of sets = cache size. Direct mapped
            {
                CacheType = CachingAlgorithm.DirectMapped;
            }
            else
            {
                CacheType = CachingAlgorithm.SetAssociative;
            }
            Strategy           = strategy;
            ReplacementHandler = replacementStrategyHr;
        }
Example #10
0
 /// <summary>
 /// Inventory move in which the object was not previously in the inventory system (not in any ItemSlot)
 /// and now is.
 /// </summary>
 /// <param name="addedObject"></param>
 /// <param name="toSlot"></param>
 /// <param name="replacementStrategy">what to do if toSlot is already occupied</param>
 /// <returns>true if successful</returns>
 public static bool ServerAdd(GameObject addedObject, ItemSlot toSlot, ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel, bool IgnoreRestraints = false)
 {
     return(ServerPerform(InventoryMove.Add(addedObject, toSlot, replacementStrategy, IgnoreRestraints)));
 }
Example #11
0
    /// <summary>
    /// Instantiates prefab then add it to inventory
    /// </summary>
    /// <param name="addedObject"></param>
    /// <param name="toSlot"></param>
    /// <param name="replacementStrategy">what to do if toSlot is already occupied</param>
    /// <returns>true if successful</returns>
    public static bool ServerSpawnPrefab(GameObject addedObject, ItemSlot toSlot, ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel, bool IgnoreRestraints = false)
    {
        var spawn = Spawn.ServerPrefab(addedObject);

        return(ServerPerform(InventoryMove.Add(spawn.GameObject.GetComponent <Pickupable>(), toSlot, replacementStrategy, IgnoreRestraints)));
    }
Example #12
0
 /// <summary>
 /// Inventory move in which the object in one slot is transferred directly to another
 /// </summary>
 /// <param name="fromSlot"></param>
 /// <param name="toSlot"></param>
 /// <param name="replacementStrategy">what to do if toSlot is already occupied</param>
 /// <returns>true if successful</returns>
 public static bool ServerTransfer(ItemSlot fromSlot, ItemSlot toSlot, ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel, bool IgnoreRestraints = false)
 {
     return(ServerPerform(InventoryMove.Transfer(fromSlot, toSlot, replacementStrategy, IgnoreRestraints)));
 }
Example #13
0
 /// <summary>
 /// Inventory move in which the object in one slot is transferred directly to another
 /// </summary>
 /// <param name="fromSlot"></param>
 /// <param name="toSlot"></param>
 /// <param name="replacementStrategy">what to do if toSlot is already occupied</param>
 /// <returns>true if successful</returns>
 public static bool ServerTransfer(ItemSlot fromSlot, ItemSlot toSlot, ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel)
 {
     return(ServerPerform(InventoryMove.Transfer(fromSlot, toSlot, replacementStrategy)));
 }
Example #14
0
 /// <summary>
 /// Inventory move in which the object was not previously in the inventory system (not in any ItemSlot)
 /// and now is.
 /// </summary>
 /// <param name="addedObject"></param>
 /// <param name="toSlot"></param>
 /// <param name="replacementStrategy">what to do if toSlot is already occupied</param>
 /// <returns>true if successful</returns>
 public static bool ServerAdd(GameObject addedObject, ItemSlot toSlot, ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel)
 {
     return(ServerPerform(InventoryMove.Add(addedObject, toSlot, replacementStrategy)));
 }
Example #15
0
        private void HandleOutgoingDataFlow(IEntity target, IThreatModel model, IDiagram diagram, ReplacementStrategy strategy, IDataFlow flow, IDataFlow existing)
        {
            if (existing != null)
            {
                switch (strategy)
                {
                case ReplacementStrategy.Stop:
                    // This should not happen!
                    throw new InvalidOperationException("Replacement Strategy is Stop.");

                case ReplacementStrategy.Replace:
                    model.RemoveDataFlow(existing.Id);
                    MoveOutgoingDataFlow(target, model, diagram, flow);
                    break;

                case ReplacementStrategy.Skip:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(strategy), strategy, null);
                }
            }
            else
            {
                MoveOutgoingDataFlow(target, model, diagram, flow);
            }
        }
Example #16
0
 /// <summary>
 /// Inventory move in which the object was not previously in the inventory system (not in any ItemSlot)
 /// and now is.
 /// </summary>
 /// <param name="addedObject"></param>
 /// <param name="toSlot"></param>
 /// <param name="replacementStrategy">what to do if toSlot is already occupied</param>
 /// <returns></returns>
 public static InventoryMove Add(Pickupable addedObject, ItemSlot toSlot, ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel)
 {
     return(new InventoryMove(InventoryMoveType.Add, addedObject, null, toSlot, replacementStrategy: replacementStrategy));
 }
Example #17
0
 /// <summary>
 /// Inventory move in which the object in one slot is transferred directly to another
 /// </summary>
 /// <param name="fromSlot"></param>
 /// <param name="toSlot"></param>
 /// <param name="replacementStrategy">what to do if toSlot is already occupied</param>
 /// <returns></returns>
 public static InventoryMove Transfer(ItemSlot fromSlot, ItemSlot toSlot, ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel)
 {
     return(new InventoryMove(InventoryMoveType.Transfer, fromSlot.Item, fromSlot, toSlot, replacementStrategy: replacementStrategy));
 }
Example #18
0
 /// <summary>
 /// Inventory move in which the object in one slot is transferred directly to another
 /// </summary>
 /// <param name="fromSlot"></param>
 /// <param name="toSlot"></param>
 /// <param name="replacementStrategy">what to do if toSlot is already occupied</param>
 /// <returns></returns>
 public static InventoryMove Transfer(ItemSlot fromSlot, ItemSlot toSlot, ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel, bool ignoreRestraints = false)
 {
     return(new InventoryMove(InventoryMoveType.Transfer, fromSlot.Item, fromSlot, toSlot, replacementStrategy: replacementStrategy, ignoreRestraints: ignoreRestraints));
 }
Example #19
0
 /// <summary>
 /// Inventory move in which the object was not previously in the inventory system (not in any ItemSlot)
 /// and now is.
 /// </summary>
 /// <param name="addedObject"></param>
 /// <param name="toSlot"></param>
 /// <param name="replacementStrategy">what to do if toSlot is already occupied</param>
 /// <returns></returns>
 public static InventoryMove Add(Pickupable addedObject, ItemSlot toSlot, ReplacementStrategy replacementStrategy = ReplacementStrategy.Cancel, bool IgnoreRestraints = false)
 {
     return(new InventoryMove(InventoryMoveType.Add, addedObject, null, toSlot, replacementStrategy: replacementStrategy, ignoreRestraints: IgnoreRestraints));
 }