Example #1
0
 /// <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
     {
     }
 }
Example #2
0
 /// <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
     {
     }
 }
Example #3
0
        /// <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
            {
            }
        }
Example #4
0
        /// <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());
            }
        }
Example #5
0
        /// <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
            {
            }
        }
Example #6
0
 /// <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);
 }