Skip to navigation

Landscape: SmoothTileData

Name: SmoothTileData [Show more] Type: Subroutine Category: Landscape Summary: Smooth the entire landscape
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * GenerateLandscape calls SmoothTileData

Arguments: A Controls how we smooth the tile data: * Bit 6 clear = smooth each row/column of tile corners by working along the row/column and setting each tile corner's altitude to the average of its altitude with the three following tile corners, working along rows from left to right and along columns from front to back * Bit 6 set = smooth each row/column of tile corners by working along the row/column and setting the altitude of each outlier tile corner to that of its closest immediate neighbour in terms of altitude (i.e. smooth out single-point spikes or troughs in the row/column)
.SmoothTileData STA smoothingAction \ Store the action in smoothingAction so the calls to \ SmoothTileCorners can access it LDA #2 \ We perform the smoothing process twice, so set a loop STA loopCounter \ counter in loopCounter to count down from 2 .smoo1 \ We start by working our way through the landscape, \ smoothing the row of tile corners at the back (i.e. at \ tile z-coordinate 31), and then smoothing the next row \ forward, looping until we reach the front row LDA #31 \ Set zTile = 31 so we start iterating from the back row STA zTile \ (so zTile iterates from 31 to 0 in the following loop) .smoo2 LDA #00000000 \ Call SmoothTileCorners with bit 7 of A clear to smooth JSR SmoothTileCorners \ the row of tile corners at z-coordinate zTile DEC zTile \ Decrement the tile z-coordinate to move forward by one \ tile row BPL smoo2 \ Loop back until we have smoothed all 32 rows \ Next we work our way through the landscape from right \ to left, smoothing the column of tile corners on the \ right (i.e. the column of tile corners going into the \ screen at tile x-coordinate 31), and then smoothing \ the next column to the left, looping until we reach \ the column along the left edge of the landscape LDA #31 \ Set xTile = 31 so we start iterating from the right STA xTile \ column (so xTile iterates from 31 to 0 in the \ following loop) .smoo3 LDA #%10000000 \ Call SmoothTileCorners with bit 7 of A set to smooth JSR SmoothTileCorners \ the column of tile corners at x-coordinate xTile DEC xTile \ Decrement the tile x-coordinate to move left by one \ tile column BPL smoo3 \ Loop back until we have smoothed all 32 columns DEC loopCounter \ Decrement the loop counter BNE smoo1 \ Loop back until we have done the whole smoothing \ process twice RTS \ Return from the subroutine