GetWriteGenericDictionary(Type keyType, Type valueType) { WriteMapDelegate writeFn; var mapKey = new MapKey(keyType, valueType); if (CacheFns.TryGetValue(mapKey, out writeFn)) { return(writeFn.Invoke); } var genericType = typeof(ToStringDictionaryMethods <, ,>).MakeGenericType(keyType, valueType, typeof(TSerializer)); var mi = genericType.GetMethod("WriteIDictionary", BindingFlags.Static | BindingFlags.Public); writeFn = (WriteMapDelegate)Delegate.CreateDelegate(typeof(WriteMapDelegate), mi); Dictionary <MapKey, WriteMapDelegate> snapshot, newCache; do { snapshot = CacheFns; newCache = new Dictionary <MapKey, WriteMapDelegate>(CacheFns); newCache[mapKey] = writeFn; } while (!ReferenceEquals( Interlocked.CompareExchange(ref CacheFns, newCache, snapshot), snapshot)); return(writeFn.Invoke); }
public void SetTile(int x, int y, int tx, int ty) { MapKey mapKey = new MapKey(Mathf.FloorToInt(x / (float)mapSizeX), Mathf.FloorToInt(y / (float)mapSizeY)); if (worldMap == null) { worldMap = new MapDictionary(); } if (!worldMap.ContainsKey(mapKey)) { GameObject newmap = new GameObject(); newmap.transform.SetParent(transform, false); newmap.transform.localPosition = new Vector3(mapKey.x * mapSizeX, mapKey.y * mapSizeY, 0); newmap.hideFlags = HideFlags.HideInHierarchy; TileMap tmap = newmap.AddComponent <TileMap> (); tmap.tile_width = tileWidth; tmap.tile_height = tileHeight; tmap.GetComponent <MeshRenderer>().material = material; tmap.setTexture(texture); tmap.size_x = mapSizeX; tmap.size_y = mapSizeY; tmap.CreateMap(); worldMap.Add(mapKey, tmap); } worldMap [mapKey].setTile((x % mapSizeX + mapSizeX) % mapSizeX, (y % mapSizeY + mapSizeY) % mapSizeY, tx, ty); }
// Might avoid map store flushing public void WriteMapAt(IList <Expr> indices, Expr value) { TypeCheckIndices(indices); if (AreConcrete(indices)) { if (GetCurrentMode() == CurrentMode.SYMBOLIC_NON_ALIASING_STORE) { // Can't be in both modes simultaneously so flush any unflushed stores // left from StoresAtSymbolicNonAliasingIndices // FIXME: We could optimise to avoid doing this but we don't right now // because we could end up with a mix of concrete and symbolic indices // in the store and we might not flush them in the right order FlushUnflushedStores(); // Drop the stores they won't be valid anymore DropSymbolicNonAliasingStores(); Debug.Assert(GetCurrentMode() == CurrentMode.NONE); } // Don't create map store expressions, just store directly which can be retrieved by // ReadMapAt() var mapKey = new MapKey(indices); StoresAtConcreteIndices[mapKey] = value; UnflushedStores[mapKey] = value; Debug.Assert(GetCurrentMode() == CurrentMode.CONCRETE_STORE); return; } else if (AliasesZeroOrOneSymbolicNonAliasingIndices(indices)) { if (GetCurrentMode() == CurrentMode.CONCRETE_STORE) { // Can't be in both modes simultaneously so flush any unflushed stores // left from StoresAtConcreteIndices // FIXME: We could optimise to avoid doing this but we don't right now // because we could end up with a mix of concrete and symbolic indices // in the store and we might not flush them in the right order FlushUnflushedStores(); // Drop concrete stores, we can't have them around simultaneously DropConcreteStores(); } // Don't create map store expression, just store directly which can be retrieved // by ReadMapAt() var mapKey = new MapKey(indices); StoresAtSymbolicNonAliasingIndices[mapKey] = value; UnflushedStores[mapKey] = value; Debug.Assert(GetCurrentMode() == CurrentMode.SYMBOLIC_NON_ALIASING_STORE); return; } // Writing to a symbolic index. We need to flush all unflushed stores, drop the stores // and then store the new value FlushUnflushedStores(); DropConcreteStores(); // The stores are no longer valid so drop them DropSymbolicNonAliasingStores(); // The stores are no longer valid so drop them DirectWrite(indices, value); }
public IMap TryGetMap(MapKey mapKey) { if (MapCollection.ContainsKey(mapKey)) { return(MapCollection[mapKey]); } return(null); }
public object this[MapKey key] { get { return(base.InnerMap[key]); } set { base.InnerMap[key] = value; } }
public MapDetail GetDetail(MapKey key) { foreach (var mapKey in this.MapDetails.Keys) { if (mapKey.Equals(key)) { return(this.MapDetails[mapKey]); } } return(null); }
public IEnumerable <TValue> GetListValue <TValue>(MapKey key) { if (this.Map == null) { throw new ArgumentException(AmqpValue.Name); } var list = (List <object>) this.Map[key]; return(list.Cast <TValue>()); }
public bool Equals(MapKey other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.KeyType, KeyType) && Equals(other.ValueType, ValueType)); }
/// <summary> /// Finds a match to a game object property value. /// </summary> /// <param name="filter">The filter.</param> /// <returns></returns> private bool FindMatch(string filter) { return(Name?.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 || Pak.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 || MapKey?.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 || ParentTemplateId?.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 || DisplayNameHandle?.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 || DisplayName?.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 || DescriptionHandle?.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 || Description?.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 || Icon?.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 || Stats?.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0); }
public void Equals_SameString_ReturnsTrue() { var mapKey1 = new MapKey("testMap"); var mapKey2 = new MapKey("testMap"); mapKey1.Equals(mapKey2).Should().BeTrue(); (mapKey1 == mapKey2).Should().BeTrue(); mapKey1.GetHashCode().Should().Be(mapKey2.GetHashCode()); (mapKey1 != mapKey2).Should().BeFalse(); }
private MapKey KeyExtracter(RatingSystem.LSystemEvolution ratedLSystem) { MapKey key = new MapKey(); //Retreive average values from lsystem and insert into key //TODO: this is an example, figure out what features you want and how to get avg of levels generate for values //key.FeatureSpace["Pig"] = (int)Math.Round(ratedLSystem.xmls.Select(x => CountOccurencesOf(x, "Pig")).Average()); //key.FeatureSpace["TNT"] = (int)Math.Round(ratedLSystem.xmls.Select(x => CountOccurencesOf(x, "TNT")).Average()); foreach (string value in LSystem.block_names.Values.Distinct().Union(new string[] { "wood", "ice", "stone" })) { key.FeatureSpace[value] = (int)Math.Round(ratedLSystem.xmls.Select(x => CountOccurencesOf(x, value)).Average()); } return(key); }
public void DictionaryIndex() { var mapKey1 = new MapKey("testMap"); var mapKey2 = new MapKey("testMap"); var mapCoordinate1 = new MapCoordinate(mapKey1, 1, 1); var mapCoordinate2 = new MapCoordinate(mapKey2, 1, 1); var dictionary = new Dictionary <MapCoordinate, bool>(); dictionary.Add(mapCoordinate1, true); dictionary.ContainsKey(mapCoordinate2).Should().BeTrue(); dictionary[mapCoordinate2].Should().BeTrue(); }
public void Equals_SameCoordinate_ReturnsTrue() { var mapKey1 = new MapKey("testMap"); var mapKey2 = new MapKey("testMap"); var mapCoordinate1 = new MapCoordinate(mapKey1, 1, 1); var mapCoordinate2 = new MapCoordinate(mapKey2, 1, 1); mapCoordinate1.Equals(mapCoordinate2).Should().BeTrue(); (mapCoordinate1 == mapCoordinate2).Should().BeTrue(); mapCoordinate1.GetHashCode().Should().Be(mapCoordinate2.GetHashCode()); (mapCoordinate1 != mapCoordinate2).Should().BeFalse(); }
// returning list for better performance public List <TValue> GetListValue <TValue>(MapKey key) { if (Map == null) { throw new ArgumentException(AmqpValue.Name); } var list = (List <object>)Map[key]; // not optimized for empty lists due to the generic nature of this method var values = new List <TValue>(list.Count); // not using foreach for better performance for (var index = 0; index < list.Count; index++) { var item = list[index]; values.Add((TValue)item); } return(values); }
GetWriteGenericDictionary(Type keyType, Type valueType) { WriteMapDelegate writeFn; lock (CacheFns) { var mapKey = new MapKey(keyType, valueType); if (!CacheFns.TryGetValue(mapKey, out writeFn)) { var genericType = typeof(ToStringDictionaryMethods <, ,>) .MakeGenericType(keyType, valueType, typeof(TSerializer)); var mi = genericType.GetMethod("WriteIDictionary", BindingFlags.Static | BindingFlags.Public); writeFn = (WriteMapDelegate)Delegate.CreateDelegate(typeof(WriteMapDelegate), mi); CacheFns.Add(mapKey, writeFn); } } return(writeFn.Invoke); }
// Might avoid map store flushing public Expr ReadMapAt(IList <Expr> indices) { TypeCheckIndices(indices); if (AreConcrete(indices)) { Expr storedValue = null; var mapKey = new MapKey(indices); StoresAtConcreteIndices.TryGetValue(mapKey, out storedValue); if (storedValue != null) { // We have a hit! Return the stored value return(storedValue); } } else if (AreKnownSymbolicNonAliasingIndices(indices)) { // We have this symbolic location already stored var mapKey = new MapKey(indices); return(StoresAtSymbolicNonAliasingIndices[mapKey]); } // Reading from a location in the map we don't have stored // so we need to flush all stores and return the full expression. // Note we aren't doing a write so we can keep the stores in // StoresAtConcreteIndices and StoresAtSymbolicNonAliasingIndices // for future look up. // (by not calling DropConcreteStores() and DropSymbolicNonAliasingStores()) FlushUnflushedStores(); // Build map selects to access the location symbolically var groupedIndices = GroupIndices(indices); var result = ExpressionRepresentation; for (int index = 0; index < groupedIndices.Count; ++index) { result = Builder.MapSelect(result, groupedIndices[index].ToArray()); } return(result); }
public TValue GetValue <TValue>(MapKey key) { if (this.Map == null) { throw new ArgumentException(AmqpValue.Name); } var valueObject = this.Map[key]; if (valueObject == null) { throw new ArgumentException(key.ToString()); } if (!(valueObject is TValue)) { throw new ArgumentException(key.ToString()); } return((TValue)this.Map[key]); }
// maps from source name to target public string Map(string sourceLocalName, LocaleM targetLocale) { string defaultName = _localToDefaultNameMap[sourceLocalName]; MapKey mapKey = new MapKey(); Dictionary <MapKey, string> .KeyCollection mapKeys = _defaultNameToLocalMap.Keys; foreach (var key in mapKeys) { if (key.Key == defaultName && key.Locale == targetLocale) { mapKey = key; break; } } if (_defaultNameToLocalMap.ContainsKey(mapKey)) { string localName = _defaultNameToLocalMap[mapKey]; return(localName); } return(null); }
// maps from source name to target public string Map(string sourceLocalName, LocaleM targetLocale) { if (_localToDefaultNameMap != null && _localToDefaultNameMap.ContainsKey(sourceLocalName)) { string defaultName = _localToDefaultNameMap[sourceLocalName]; var mapKey = new MapKey(); foreach (var key in _defaultNameToLocalMap.Keys .Where(key => key.Key == defaultName && key.Locale == targetLocale)) { mapKey = key; break; } if (_defaultNameToLocalMap.ContainsKey(mapKey)) { var localName = _defaultNameToLocalMap[mapKey]; return(localName); } } return(null); }
public void modifyHeight(Vector2 center, float range, float value) { int rangeX = (int)range / mapSizeX + 1; int rangeY = (int)range / mapSizeY + 1; for (int i = -rangeX; i <= rangeX; i++) { for (int j = -rangeY; j <= rangeY; j++) { MapKey mapKey = new MapKey(Mathf.FloorToInt((int)center.x / (float)mapSizeX + i), Mathf.FloorToInt((int)center.y / (float)mapSizeY + j)); if (worldMap == null) { worldMap = new MapDictionary(); } if (!worldMap.ContainsKey(mapKey)) { GameObject newmap = new GameObject(); newmap.transform.SetParent(transform, false); newmap.transform.localPosition = new Vector3(mapKey.x * mapSizeX, mapKey.y * mapSizeY, 0); newmap.hideFlags = HideFlags.HideInHierarchy; TileMap tmap = newmap.AddComponent <TileMap>(); tmap.tile_width = tileWidth; tmap.tile_height = tileHeight; tmap.GetComponent <MeshRenderer>().material = material; tmap.setTexture(texture); tmap.size_x = mapSizeX; tmap.size_y = mapSizeY; tmap.CreateMap(); worldMap.Add(mapKey, tmap); } Vector2 mcenter = center - (Vector2)worldMap[mapKey].transform.localPosition; worldMap[mapKey].modifyHeight(mcenter, range, value); } } }
// override object.Equals public override bool Equals(object obj) { // // See the full list of guidelines at // http://go.microsoft.com/fwlink/?LinkID=85237 // and also the guidance for operator== at // http://go.microsoft.com/fwlink/?LinkId=85238 // if (obj == null || GetType() != obj.GetType()) { return(false); } MapKey other = obj as MapKey; if (other == null) { return(false); } var keys = FeatureSpace.Keys.Union(other.FeatureSpace.Keys); foreach (string key in keys) { if (!FeatureSpace.ContainsKey(key) || !other.FeatureSpace.ContainsKey(key)) { return(false); } if (FeatureSpace[key] != other.FeatureSpace[key]) { return(false); } } return(true); }
public void Tick() { CurrentTime++; ActiveMapKey = _playerSystem.Player.Get <Position>().MapCoordinate.Key; if (Entities != null) { var entitiesAtStartOfTick = new List <IEntity>(Entities); foreach (var entity in entitiesAtStartOfTick) { if (!entity.Removed) { RunTickUpdates(entity); if (entity.Get <Actor>().NextTick <= CurrentTime) { Act(entity); } } } } }
public bool TryGetValue <TValue>(MapKey key, out TValue value) { return(base.InnerMap.TryGetValue <TValue>(key, out value)); }
public bool Equals(MapKey <Input, Output> obj) { return(!ReferenceEquals(null, obj)); }
public IList <IEntity> EntitiesAt(MapKey mapKey, int x, int y, bool includeMapCells = true) { return(EntitiesAt(new MapCoordinate(mapKey, x, y), includeMapCells)); }
public ulong?NextId(ulong collectionId) { return(_nftClient.MakeCallWithReconnect(application => application.GetStorageObject <ulong?, MapKey <ulong> >(MapKey.Create(collectionId), Module, ItemListIndexStorage), _nftClient.Settings.MaxReconnectCount)); }
protected virtual void AddBranchPortals(ISystemContainer systemContainer, GeneratedBranch generatedBranch, Branch branch) { var engine = systemContainer.EntityEngine; var prototypeSystem = systemContainer.PrototypeSystem; var positionSystem = systemContainer.PositionSystem; var links = engine.GetAll <BranchLink>(); var relevantLinks = new Dictionary <BranchLinkEnd, BranchLinkEnd>(); foreach (var link in links) { if (link.From.Branch == branch.BranchName) { relevantLinks.Add(link.From, link.To); } if (link.To.Branch == branch.BranchName) { relevantLinks.Add(link.To, link.From); } } foreach (var link in relevantLinks) { var thisEnd = link.Key; var thatEnd = link.Value; var level = Random.Between(thisEnd.LevelFrom, thisEnd.LevelTo); var mapKey = new MapKey(branch.LevelName(level)); var potentialPortals = engine.EntitiesWith <Portal>() .Where(p => p.Get <Position>().MapCoordinate.Key == mapKey) .Where(p => string.IsNullOrEmpty(p.Get <Portal>().BranchLink)) .ToList(); if (!potentialPortals.Any()) { throw new Exception("No available portals to place branch link"); } var portalEntity = Random.PickOne(potentialPortals); var thisPortal = portalEntity.Get <Portal>(); thisPortal.BranchLink = thatEnd.Branch; var destinationBranch = prototypeSystem.Get(link.Value.Branch).Get <Branch>(); thisEnd.Location = portalEntity.Get <Position>().MapCoordinate; if (thatEnd.Location != null) { var thatPortal = positionSystem.EntitiesAt(thatEnd.Location) .Single(e => e.Has <Portal>()) .Get <Portal>(); thisPortal.Destination = thatEnd.Location; thatPortal.Destination = thisEnd.Location; } } }
/// <summary> /// Creates a MapContext Instance /// </summary> public MapEventContext(EventContext mapContext, MapKey key, int fieldNumber) { _mapContext = mapContext; _key = key; _fieldNumber = fieldNumber; }
public void Add(MapKey key, object value) { base.InnerMap.Add(key, value); }
public FileContents Get(FileName fileName, FileContents fileContents) { var key = new MapKey(fileContents); return(_map.GetOrAdd(key, fileContents)); }