Example #1
0
        public void Decode1( int x, int y, MapBlock block )
        {
            if ( block == null ) {
                // We're not... draw black area.
                DrawBlack( x, y );
                return;
            }

            // do the actual drawing of this block
            ClearBuffer();
            Draw( block, x, y );
        }
Example #2
0
        public void Decode2( int x, int y, MapBlock block, MapBlock right )
        {
            ShiftShadowDown();

            if ( block == null ) {
                // We're not... draw black area.
                DrawBlack( x, y );
                return;
            }

            // Fill Shadowbuffer with info from the block right to this one
            if ( right != null ) PrepareRight( right );

            // do the actual drawing of this block
            Draw( block, x, y );
        }
Example #3
0
 public void WalkTree( MapBlock block, TreeWalkerMode mode )
 {
     OnBeforeWalk();
     switch ( mode ) {
         case TreeWalkerMode.Full:
             WalkTreeFull( block.Tree, 0, 0 ); break;
         case TreeWalkerMode.LeftOnly:
             WalkTreeLeft( block.Tree, 0, 0 ); break;
         case TreeWalkerMode.TopLeftOnly:
             WalkTreeTopLeft( block.Tree, 0, 0 ); break;
         case TreeWalkerMode.TopOnly:
             WalkTreeTop( block.Tree, 0, 0 ); break;
         default:
             throw new ArgumentOutOfRangeException();
     }
     OnAfterWalk();
 }
Example #4
0
        public void Decode4( int x, int y, MapBlock block, MapBlock right, MapBlock bottom, MapBlock bottomright )
        {
            if ( block == null ) {
                // We're not... draw black area.
                DrawBlack( x, y );
                return;
            }

            // Valid block, do more drawing
            if ( bottomright != null && bottom != null ) {
                // Fill Shadowbuffer with bottom and bottom-right info
                PrepareBottomRight( bottomright );
                PrepareBottom( bottom );
            }
            else {
                ClearBuffer();
            }

            // Fill Shadowbuffer with info from the block right to this one
            if ( right != null ) PrepareRight( right );

            // do the actual drawing of this block
            Draw( block, x, y );
        }
Example #5
0
 public void Erase( Rectangle area )
 {
     for ( int y=area.Top; y<area.Bottom; ++y ) {
         for ( int x=area.Left; y<area.Right; ++x ) {
             blocks[GetBlockIndex( NormalizeBlockX( x ), y )] = new MapBlock();
         }
     }
 }
Example #6
0
 public void Erase( int x, int y )
 {
     blocks[GetBlockIndex( x, y )] = new MapBlock();
 }
Example #7
0
 public void Erase( Point location )
 {
     blocks[GetBlockIndex(location)] = new MapBlock();
 }
Example #8
0
        public RawImage DecodeBlockImage( MapBlock block, Point location )
        {
            location = CoordMap.FitToGrid( location );
            RawImage image = new RawImage( zoom, new Rectangle( location, new Size( BlockSize, BlockSize ) ) );

            ImageDecoder decoder = new ImageDecoder( image );
            decoder.Decode1( 0, 0, block );

            return image;
        }
Example #9
0
 public virtual bool Equals( MapBlock other )
 {
     return this.ToString( true ) == other.ToString( true );
 }
Example #10
0
        public MapBlock Encode( int x, int y )
        {
            MapBlock result = new MapBlock( BuildTree( x, y, Lightmap.BlockFactor ) );

            return result;
        }
Example #11
0
 private void PrepareBottomRight( MapBlock block )
 {
     sx = 0; sy = 0;
     //block.WalkTree( MapBlock.WalkMode.TopLeftOnly, new MapBlock.Walker( BottomRightWalker ), 0, 0 );
     block.WalkTree( new DelegateWalker.VisitDelegate( BottomRightWalker ), TreeWalkerMode.TopLeftOnly );
 }
Example #12
0
 protected virtual void PrepareRight( MapBlock block )
 {
     sx = 0; sy = 0;
     block.WalkTree( new DelegateWalker.VisitDelegate( RightWalker ), TreeWalkerMode.LeftOnly );
 }
Example #13
0
 protected virtual void PrepareBottom( MapBlock block )
 {
     sx = 0; sy = 0;
     //block.WalkTree( MapBlock.WalkMode.TopOnly, new MapBlock.Walker( BottomWalker ), 0, 0 );
     block.WalkTree( new DelegateWalker.VisitDelegate( BottomWalker ), TreeWalkerMode.TopOnly );
 }
Example #14
0
        public void Recompress( int[] indexes )
        {
            int x, y;
            for ( int i=0; i<indexes.Length; ++i ) {
                if ( indexes[i] < 0 || indexes[i] >= blocks.Length ) continue;

                if ( blocks[i].IsCompressed() ) blocks[indexes[i]] = new MapBlock( (CompressedBlock)blocks[indexes[i]], adjacent );
                x = (indexes[i] % SizeBlocks.Width) << BlockFactor;
                y = (indexes[i] / SizeBlocks.Width) << BlockFactor;
                blocks[indexes[i]] = ((MapBlock)blocks[indexes[i]]).Compress( x, y, zoom, provinces, adjacent, idmap );
            }
        }
Example #15
0
 protected virtual void Draw( MapBlock block, int x, int y )
 {
     sx = x; sy = y;
     block.WalkTree( new DelegateWalker.VisitDelegate( DrawWalker ) );
 }
Example #16
0
        public void Shrink( out Lightmap result1, out Lightmap result2 )
        {
            result1 = new Lightmap( zoom+1, provinces, adjacent, idmap );
            result2 = new Lightmap( zoom+2, provinces, adjacent, idmap );

            Size size = this.CoordMap.ActualToZoomedBlocks( Lightmap.BaseSize );
            //Size size1 = result1.CoordMap.ActualToZoomedBlocks( Lightmap.BaseSize );
            //Size size2 = result2.CoordMap.ActualToZoomedBlocks( Lightmap.BaseSize );
            int stride = CoordMap.ActualToZoomedBlocks( Lightmap.BaseWidth );
            MapBlock[,] matrix = new MapBlock[4,4];
            for ( int blockindex1 = 0, blockindex2 = 0, y=0; y<size.Height; y+=2 ) {
                for ( int x=0; x<size.Width; x+=2 ) {
                    // Get 4 blocks
                    int index = y*stride+x;

                    result1.blocks[blockindex1++] = MapBlock.Combine(
                        GetDecompressedBlock( index+stride+1 ),		// bottomright
                        GetDecompressedBlock( index+stride ),		// bottomleft
                        GetDecompressedBlock( index+1 ),			// topright
                        GetDecompressedBlock( index )   			// topleft
                        ).Compress( (x << BlockFactor) << zoom, (y << BlockFactor) << zoom, zoom+1, provinces, adjacent, idmap );

                    if ( (x % 4 == 0) && (y % 4 == 0) ) {
                        matrix[3,3] = GetDecompressedBlock( index+(stride*3)+3 );
                        matrix[2,3] = GetDecompressedBlock( index+(stride*3)+2 );
                        matrix[1,3] = GetDecompressedBlock( index+(stride*3)+1 );
                        matrix[0,3] = GetDecompressedBlock( index+(stride*3) );
                        matrix[3,2] = GetDecompressedBlock( index+(stride*2)+3 );
                        matrix[2,2] = GetDecompressedBlock( index+(stride*2)+2 );
                        matrix[1,2] = GetDecompressedBlock( index+(stride*2)+1 );
                        matrix[0,2] = GetDecompressedBlock( index+(stride*2) );
                        matrix[3,1] = GetDecompressedBlock( index+stride+3 );
                        matrix[2,1] = GetDecompressedBlock( index+stride+2 );
                        matrix[1,1] = GetDecompressedBlock( index+stride+1 );
                        matrix[0,1] = GetDecompressedBlock( index+stride );
                        matrix[3,0] = GetDecompressedBlock( index+3 );
                        matrix[2,0] = GetDecompressedBlock( index+2 );
                        matrix[1,0] = GetDecompressedBlock( index+1 );
                        matrix[0,0] = GetDecompressedBlock( index );

                        result2.blocks[blockindex2++] = MapBlock.Combine( matrix )
                            .Compress( (x << BlockFactor) << (zoom), (y << BlockFactor) << (zoom), zoom+2, provinces, adjacent, idmap );
                    }
                }
            }
        }
Example #17
0
        public MapBlock this[int index]
        {
            get {
                if ( index < 0 || index >= blocks.Length ) return null;
                if ( blocks[index] == null ) return null;

                // Decompress first if necessary
                //Console.WriteLine( "block {0} - {1}", index, blocks[index].IsCompressed() );
                if ( blocks[index].IsCompressed() ) {
                    if ( volatiledecompression )
                        return new MapBlock( (CompressedBlock)blocks[index], adjacent );
                    else {
                        CompressedBlock compressed = (CompressedBlock)blocks[index];
                        blocks[index] = new MapBlock( compressed, adjacent );
                    }
                }

                return (MapBlock)blocks[index];
            }
            set {
                if ( index < 0 || index >= blocks.Length ) return;
                blocks[index] = value;
            }
        }
Example #18
0
        public static MapBlock Combine( MapBlock[,] matrix )
        {
            Node root = new Node( false );

            // Create 4 children
            root.BottomRightChild = new Node( false );
            root.BottomLeftChild = new Node( false );
            root.TopRightChild = new Node( false );
            root.TopLeftChild  = new Node( false );

            // Add items to children
            root.BottomRightChild.BottomRightChild = matrix[3,3].Tree.Clone();
            root.BottomRightChild.BottomLeftChild = matrix[2,3].Tree.Clone();
            root.BottomRightChild.TopRightChild = matrix[3,2].Tree.Clone();
            root.BottomRightChild.TopLeftChild = matrix[2,2].Tree.Clone();

            root.BottomLeftChild.BottomRightChild = matrix[1,3].Tree.Clone();
            root.BottomLeftChild.BottomLeftChild = matrix[0,3].Tree.Clone();
            root.BottomLeftChild.TopRightChild = matrix[1,2].Tree.Clone();
            root.BottomLeftChild.TopLeftChild = matrix[0,2].Tree.Clone();

            root.TopRightChild.BottomRightChild = matrix[3,1].Tree.Clone();
            root.TopRightChild.BottomLeftChild = matrix[2,1].Tree.Clone();
            root.TopRightChild.TopRightChild = matrix[3,0].Tree.Clone();
            root.TopRightChild.TopLeftChild = matrix[2,0].Tree.Clone();

            root.TopLeftChild.BottomRightChild = matrix[1,1].Tree.Clone();
            root.TopLeftChild.BottomLeftChild = matrix[0,1].Tree.Clone();
            root.TopLeftChild.TopRightChild = matrix[1,0].Tree.Clone();
            root.TopLeftChild.TopLeftChild = matrix[0,0].Tree.Clone();

            root.Level = matrix[3,3].Tree.Level+2;

            // Use for new block
            MapBlock result = new MapBlock( root );

            // Clip the tree
            result.WalkTree( new MapBlockHandling.TreeClipperDeep( ) );
            result.tree.Level = 5;

            // Optimise the tee
            result.WalkTree( new MapBlockHandling.TreeOptimiser( true ) );

            return result;
        }
Example #19
0
        public static Lightmap CreateEmpty( int zoom )
        {
            Lightmap result = new Lightmap( zoom, null, null, null );

            CompressedBlock block = new MapBlock().Compress( 0, 0, zoom, null, null, null );
            for ( int i=0; i<result.blocks.Length; ++i ) result.blocks[i] = block;
            return result;
        }
Example #20
0
        public static MapBlock Combine( MapBlock bottomright, MapBlock bottomleft, MapBlock topright, MapBlock topleft )
        {
            // Merge 4 trees
            Node root = new Node( false, bottomright.Tree.Level+1 );
            root.BottomRightChild = bottomright.Tree.Clone();
            root.BottomLeftChild = bottomleft.Tree.Clone();
            root.TopRightChild = topright.Tree.Clone();
            root.TopLeftChild = topleft.Tree.Clone();

            // Use for new block
            MapBlock result = new MapBlock( root );

            // Clip the tree
            result.WalkTree( new MapBlockHandling.TreeClipper() );
            result.tree.Level = 5;

            // Optimise the tee
            result.WalkTree( new MapBlockHandling.TreeOptimiser( true ) );

            return result;
        }
Example #21
0
 public void WalkTree( MapBlock block )
 {
     WalkTree( block, defaultWalkmode );
 }