public bool Contains(MyTriggerComponent trigger) { m_updateLock = true; foreach (var tuple in m_removeCacheTrigger) { if (tuple.Item2 == trigger) { return(false); } } if (m_addCache.Contains(trigger)) { return(true); } foreach (var triggerList in m_triggers.Values) { if (triggerList.Contains(trigger)) { return(true); } } return(false); }
public void AddTrigger(MyTriggerComponent trigger) { Debug.Assert(trigger != null, "Horrible Assertion! Call a programmer! Hurry!"); MySandboxGame.AssertUpdateThread(); if (Contains(trigger)) { return; } using (m_dictionaryLock.AcquireExclusiveUsing()) { CachingHashSet triggerSet; if (m_triggers.TryGetValue((MyEntity)trigger.Entity, out triggerSet)) { triggerSet.Add(trigger); } else { m_triggers[(MyEntity)trigger.Entity] = new CachingHashSet { trigger }; } } }
/// <summary> /// Selects the closest trigger to provided position. /// </summary> /// <param name="position">Considered position.</param> public void SelectClosest(Vector3D position) { var minLength = double.MaxValue; // Change the debug draw color from previously selected to default color. if (SelectedTrigger != null) { SelectedTrigger.CustomDebugColor = Color.Red; } // Find the min length foreach (var trigger in m_currentQuery) { var length = (trigger.Center - position).LengthSquared(); if (length < minLength) { minLength = length; SelectedTrigger = trigger; } } if (Math.Abs(minLength - double.MaxValue) < double.Epsilon) { SelectedTrigger = null; } // Change the trigger debug draw color to selected. if (SelectedTrigger != null) { SelectedTrigger.CustomDebugColor = Color.Yellow; } }
public void RemoveTrigger(MyEntity entity, MyTriggerComponent trigger) { if (m_updateLock) { m_removeCacheTrigger.Add(new MyTuple <MyEntity, MyTriggerComponent>(entity, trigger)); } else { RemoveTriggerCached(entity, trigger); } }
public void AddTrigger(MyTriggerComponent trigger) { if (m_updateLock) { m_addCache.Add(trigger); } else { AddTriggerCached(trigger); } }
public void RemoveTrigger(MyEntity entity, MyTriggerComponent trigger) { using (m_dictionaryLock.AcquireExclusiveUsing()) { CachingHashSet triggerSet; if (m_triggers.TryGetValue(entity, out triggerSet)) { triggerSet.Remove(trigger); } } }
private void AddTriggerCached(MyTriggerComponent trigger) { if (!m_triggers.ContainsKey((MyEntity)trigger.Entity)) { m_triggers.Add((MyEntity)trigger.Entity, new List <MyTriggerComponent> { trigger }); } else { Debug.Assert(!m_triggers[(MyEntity)trigger.Entity].Contains(trigger)); m_triggers[(MyEntity)trigger.Entity].Add(trigger); } }
public bool Contains(MyTriggerComponent trigger) { using (m_dictionaryLock.AcquireSharedUsing()) { foreach (var triggerSet in m_triggers.Values) { if (triggerSet.Contains(trigger)) { return(true); } } } return(false); }
private void RemoveTriggerCached(MyEntity entity, MyTriggerComponent trigger) { if (m_triggers.ContainsKey(entity) && m_triggers[entity].Contains(trigger)) { if (m_triggers[entity].Count == 1) { m_triggers[entity].Clear(); m_triggers.Remove(entity); } else { m_triggers[entity].Remove(trigger); } } }
public MyEntity GetTriggersEntity(string triggerName, out MyTriggerComponent foundTrigger) { foundTrigger = null; foreach (var pair in m_triggers) { foreach (var component in pair.Value) { var areaTrigger = component as MyAreaTriggerComponent; if (areaTrigger != null && areaTrigger.Name == triggerName) { foundTrigger = component; return(pair.Key); } } } return(null); }
public MyEntity GetTriggerEntity(string entityName, out MyTriggerComponent foundTrigger) { foundTrigger = null; bool orig = m_updateLock; m_updateLock = true; foreach (var triggerList in m_triggers.Values) { foreach (var trigger in triggerList) { if (trigger is MyAreaTriggerComponent && ((MyAreaTriggerComponent)trigger).Name.Equals(entityName)) { foundTrigger = trigger; return((MyEntity)trigger.Entity); } } } m_updateLock = orig; return(null); }