/// <summary> /// Removes an object from the WorldGrid. /// </summary> /// <param name="obj">Object to remove.</param> public void Remove(WorldComponent obj) { try { obj.Cell.Remove(obj); } catch { } }
/// <summary> /// Trys to remove an object from this cell. /// </summary> /// <param name="obj">Object to remove.</param> public void Remove(WorldComponent obj) { try { ObjectsInCell.Remove(obj); } catch { } }
/// <summary> /// Adds an object to the WorldGrid. /// </summary> /// <param name="obj">Object to add.</param> public void Add(WorldComponent obj) { try { Tuple <int, int> cellIndex = GetCellFromPoint(obj.Position.ToPoint()); WorldCell cell = Cells[cellIndex.Item1][cellIndex.Item2]; cell.Add(obj); obj.Cell = cell; } catch { } }
/// <summary> /// Insert the component into the WorldGrid. /// </summary> /// <param name="id">Entity id.</param> /// <param name="component">WorldComponent.</param> public override void UnregisterComponent(int id) { WorldComponent component = (WorldComponent)Components[id]; base.UnregisterComponent(id); try { WorldGrid.Remove(component); } catch (Exception e) { Trace.WriteLine( "Exception in WorldSystem.UnregisterComponent:" ); Trace.WriteLine(e.ToString()); } }
/// <summary> /// Updates a given object within the world grid. Moving it to a new /// cell if required. /// </summary> /// <param name="obj">Object to update.</param> public void Update(WorldComponent obj) { try { Tuple <int, int> cellIndex = GetCellFromPoint(obj.Position.ToPoint()); WorldCell cell = Cells[cellIndex.Item1][cellIndex.Item2]; if (obj.Cell != cell) { obj.Cell.Remove(obj); cell.Add(obj); obj.Cell = cell; } } catch { } }
/// <summary> /// Adds an object to this cell. /// </summary> /// <param name="obj">Object to add.</param> public void Add(WorldComponent obj) { ObjectsInCell.Add(obj, obj.Entity); }