/// <summary> /// Registers entity with given ID. Do not call this directly, it is called automatically /// when EntityID is first time assigned. /// </summary> /// <param name="entity"></param> public static void AddEntityWithId(IMyEntity entity) { Debug.Assert(entity != null, "Adding null entity. This can't happen."); Debug.Assert(!m_entityList.ContainsKey(entity.EntityId), "Entity with this key (" + entity.EntityId + ") already exists in entity list! This can't happen."); Debug.Assert(!m_entityList.ContainsValue(entity), "Entity is already registered by different ID. This can't happen."); m_entityList.Add(entity.EntityId, entity); }
public static void AddOrUpdate <T>(this MyConcurrentDictionary <T, float> dic, T key, float value) { if (dic.ContainsKey(key)) { dic[key] += value; } else { dic[key] = value; } }
/// <summary> /// Removes replicable, children should be already removed /// </summary> public void Remove(IMyReplicable replicable) { IMyReplicable parent; if (m_childToParent.TryGetValue(replicable, out parent)) // Replicable is child { RemoveChild(replicable, parent); } Debug.Assert(!m_parentToChildren.ContainsKey(replicable), "Removing parent before children are removed"); m_roots.Remove(replicable); m_updateQueue.Remove(replicable); }
public void UpdateBlacklist() { var blacklist = MyScriptCompiler.Static.Whitelist.OpenIngameBlacklistBatch(); var types = new MyConcurrentHashSet <Type>(); var memberDict = new MyConcurrentDictionary <Type, List <string> >(); Parallel.ForEach(PluginSettings.Instance.BlacklistItems, item => { if (string.IsNullOrEmpty(item.Type)) { return; } var targetType = FindTypeInAllAssemblies(item.Type); if (targetType == null) { return; } if (string.IsNullOrEmpty(item.Member)) { lock (types) types.Add(targetType); } var members = targetType.GetMember(item.Member); if (members.Length != 0) { if (!memberDict.ContainsKey(targetType)) { memberDict.Add(targetType, new List <string>()); } memberDict[targetType].Add(item.Member); } }); if (types.Count > 0) { blacklist.AddTypes(types.ToArray()); foreach (var type in types) { Essentials.Log.Info($"Added type {type.Name} to PB blacklist."); } } foreach (var entry in memberDict) { blacklist.AddMembers(entry.Key, entry.Value.ToArray()); foreach (var name in entry.Value) { Essentials.Log.Info($"Added {entry.Key.Name}.{name} to PB blacklist."); } } }
/// <summary> /// Removes replicable, children should be already removed /// </summary> virtual protected void Remove(IMyReplicable replicable) { IMyReplicable parent; if (m_childToParent.TryGetValue(replicable, out parent)) // Replicable is child { RemoveChild(replicable, parent); } Debug.Assert(!m_parentToChildren.ContainsKey(replicable), "Removing parent before children are removed"); if (ContainsRoot(replicable)) { RemoveRoot(replicable); } }
public void PrefetchShapeOnRay(ref LineD ray) { Vector3I minCorner, maxCorner; MyVoxelCoordSystems.WorldPositionToVoxelCoord(PositionLeftBottomCorner, ref ray.From, out minCorner); MyVoxelCoordSystems.WorldPositionToVoxelCoord(PositionLeftBottomCorner, ref ray.To, out maxCorner); minCorner /= PHYSICS_SECTOR_SIZE_METERS; maxCorner /= PHYSICS_SECTOR_SIZE_METERS; for (var it = new Vector3I_RangeIterator(ref minCorner, ref maxCorner); it.IsValid(); it.MoveNext()) { if (m_physicsShapes.ContainsKey(it.Current)) { m_physicsShapes[it.Current].PrefetchShapeOnRay(ref ray); } } }
public void RegisterFromAssembly(Assembly assembly) { #if XB1 // XB1_ALLINONEASSEMBLY System.Diagnostics.Debug.Assert(m_registered == false); if (m_registered == true) { return; } m_registered = true; foreach (var type in MyAssembly.GetTypes().Where(t => typeof(MyExternalReplicable).IsAssignableFrom(t) && !t.IsAbstract)) #else // !XB1 foreach (var type in assembly.GetTypes().Where(t => typeof(MyExternalReplicable).IsAssignableFrom(t) && !t.IsAbstract)) #endif // !XB1 { var objType = type.FindGenericBaseTypeArgument(typeof(MyExternalReplicable <>)); if (objType != null && !m_objTypeToExternalReplicableType.ContainsKey(objType)) { Debug.Assert(type.HasDefaultConstructor(), string.Format("Type '{0}' should have public constructor", type.Name)); m_objTypeToExternalReplicableType.TryAdd(objType, type); } } }
public void AddTrigger(MyUpdateTriggerComponent trigger) { Debug.Assert(!m_triggers.ContainsKey((MyEntity)trigger.Entity)); m_triggers[(MyEntity)trigger.Entity] = trigger; }