Пример #1
0
        private async Task <byte[]> GenerateBattlePreviewAsync()
        {
            int centerX           = 0;
            int centerY           = 0;
            int previewHalfHeight = 150;
            int previewHalfWidth  = 100;

            int chunkXFrom = (int)Math.Max(Math.Ceiling(((decimal)(centerX - previewHalfWidth)) / _battle.Settings.ChunkWidth), _battle.Settings.MinWidthIndex);
            int chunkYFrom = (int)Math.Max(Math.Ceiling(((decimal)(centerY - previewHalfHeight)) / _battle.Settings.ChunkHeight), _battle.Settings.MinHeightIndex);
            int chunkXTo   = (int)Math.Min(Math.Floor(((decimal)(centerX + previewHalfWidth)) / _battle.Settings.ChunkWidth), _battle.Settings.MaxWidthIndex);
            int chunkYTo   = (int)Math.Min(Math.Floor(((decimal)(centerY + previewHalfHeight)) / _battle.Settings.ChunkHeight), _battle.Settings.MaxHeightIndex);

            var chunks = new List <(int x, int y, byte[] image)>((chunkXTo - chunkXFrom) * (chunkYTo - chunkYFrom));

            for (int i = chunkXFrom; i <= chunkXTo; i++)
            {
                for (int j = chunkYFrom; j <= chunkYTo; j++)
                {
                    var chunkGrain = this.GrainFactory.GetGrain <IChunkGrain>(GuidExtensions.ToGuid(_battleId, i, j));
                    var chunkState = await chunkGrain.GetStateAsync();

                    chunks.Add((i, j, chunkState.Image));
                }
            }

            return(_imageProcessor.GenerateImageFromChunks(
                       chunks: chunks,
                       chunkHeight: _battle.Settings.ChunkHeight,
                       chunkWidth: _battle.Settings.ChunkWidth,
                       previewHeight: previewHalfHeight,
                       previewWidth: previewHalfWidth,
                       centerX: centerX,
                       centerY: centerY));
        }
Пример #2
0
        public void ImageProcessor_Can_GenerateImageFromChunks()
        {
            var image  = _imageProcessor.GetBytesFromPixels(_imageProcessor.GetDefaultImage(100, 100, 4278190080), 100, 100);
            var chunks = new List <(int x, int y, byte[] image)>
            {
                (0, 0, image),
                (1, 0, image),
                (2, 0, image)
            };
            var previewImage = _imageProcessor.GenerateImageFromChunks(chunks, 100, 100, 100, 150, 100, 50);

            Assert.Equal(45613623U, XXHash.Hash32(previewImage));
        }