Exemplo n.º 1
0
        private void HandleDirtyEvent(IconSmoothDirtyEvent ev)
        {
            // Yes, we updates ALL smoothing entities surrounding us even if they would never smooth with us.
            // This is simpler to implement. If you want to optimize it be my guest.
            var senderEnt = ev.Sender;

            if (senderEnt.IsValid() &&
                senderEnt.TryGetComponent(out IconSmoothComponent iconSmooth) &&
                iconSmooth.Running)
            {
                var snapGrid = senderEnt.GetComponent <SnapGridComponent>();

                _dirtyEntities.Enqueue(senderEnt);
                AddValidEntities(snapGrid.GetInDir(Direction.North));
                AddValidEntities(snapGrid.GetInDir(Direction.South));
                AddValidEntities(snapGrid.GetInDir(Direction.East));
                AddValidEntities(snapGrid.GetInDir(Direction.West));
                if (ev.Mode == IconSmoothingMode.Corners)
                {
                    AddValidEntities(snapGrid.GetInDir(Direction.NorthEast));
                    AddValidEntities(snapGrid.GetInDir(Direction.SouthEast));
                    AddValidEntities(snapGrid.GetInDir(Direction.SouthWest));
                    AddValidEntities(snapGrid.GetInDir(Direction.NorthWest));
                }
            }

            if (ev.LastPosition.HasValue)
            {
                // Entity is no longer valid, update around the last position it was at.
                var grid = _mapManager.GetGrid(ev.LastPosition.Value.grid);
                var pos  = ev.LastPosition.Value.pos;

                AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(1, 0), ev.Offset));
                AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(-1, 0), ev.Offset));
                AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(0, 1), ev.Offset));
                AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(0, -1), ev.Offset));
                if (ev.Mode == IconSmoothingMode.Corners)
                {
                    AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(1, 1), ev.Offset));
                    AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(-1, -1), ev.Offset));
                    AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(-1, 1), ev.Offset));
                    AddValidEntities(grid.GetSnapGridCell(pos + new MapIndices(1, -1), ev.Offset));
                }
            }
        }
Exemplo n.º 2
0
        private void HandleDirtyEvent(object sender, IconSmoothDirtyEvent ev)
        {
            // Yes, we updates ALL smoothing entities surrounding us even if they would never smooth with us.
            // This is simpler to implement. If you want to optimize it be my guest.
            if (sender is IEntity senderEnt && senderEnt.IsValid() &&
                senderEnt.HasComponent <IconSmoothComponent>())
            {
                var snapGrid = senderEnt.GetComponent <SnapGridComponent>();

                _dirtyEntities.Enqueue(senderEnt);
                AddValidEntities(snapGrid.GetInDir(Direction.North));
                AddValidEntities(snapGrid.GetInDir(Direction.South));
                AddValidEntities(snapGrid.GetInDir(Direction.East));
                AddValidEntities(snapGrid.GetInDir(Direction.West));
                if (ev.Mode == IconSmoothingMode.Corners)
                {
                    AddValidEntities(snapGrid.GetInDir(Direction.NorthEast));
                    AddValidEntities(snapGrid.GetInDir(Direction.SouthEast));
                    AddValidEntities(snapGrid.GetInDir(Direction.SouthWest));
                    AddValidEntities(snapGrid.GetInDir(Direction.NorthWest));
                }
            }