예제 #1
0
        private void AddEntity(GridAction action)
        {
            Debug.Assert(action.Entity.Map == null);

            GetGrid(action.Position).AddEntity(action);

            uint guid = entityCounter.Dequeue();

            entities.Add(guid, action.Entity);
            action.Entity.OnAddToMap(this, guid, action.Position);

            log.Trace($"Added entity {action.Entity.Guid} to map {Entry.Id}.");
        }
예제 #2
0
        public void RelocateEntity(GridAction action)
        {
            MapCell oldCell = GetCell(action.Entity.Position);
            MapCell newCell = GetCell(action.Position);

            // new position is in the same cell, no need to transfer entity to another cell
            if (newCell.Vector == oldCell.Vector)
            {
                return;
            }

            oldCell.RemoveEntity(action.Entity);
            newCell.AddEntity(action.Entity);
        }
예제 #3
0
        private void RelocateEntity(GridAction action)
        {
            Debug.Assert(action.Entity.Map != null);

            MapGrid newGrid = GetGrid(action.Position);
            MapGrid oldGrid = GetGrid(action.Entity.Position);

            if (newGrid.Vector != oldGrid.Vector)
            {
                oldGrid.RemoveEntity(action.Entity);
                newGrid.AddEntity(action);
            }
            else
            {
                oldGrid.RelocateEntity(action);
            }

            action.Entity.OnRelocate(action.Position);
        }
예제 #4
0
 public void AddEntity(GridAction action)
 {
     GetCell(action.Position).AddEntity(action.Entity);
 }