Skip to content

Commit

Permalink
Faster scrolly-tile rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Daft-Freak committed Aug 11, 2021
1 parent e7ee5ca commit 0e88007
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions examples/scrolly-tile/scrolly-tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void for_each_tile(tile_callback callback, void *args) {
for(auto x = 0; x < TILES_X; x++) {
uint16_t index = (y * TILES_X) + x;
tiles[index] = callback(tiles[index], x, y, args);
}
}
}
}

Expand Down Expand Up @@ -186,17 +186,27 @@ uint8_t render_tile(uint8_t tile, uint8_t x, uint8_t y, void *args) {
// Draw tiles without anti-aliasing to save code bloat
// Uses the rounded corner flags to miss a pixel for a
// basic rounded corner effect.
for(auto py = 0; py < TILE_H; py++){
for(auto px = 0; px < TILE_W; px++){
// Skip drawing the pixels for each rounded corner
if(round_tl && px == 0 && py == 0) continue;
if(round_tr && px == TILE_W - 1 && py == 0) continue;
if(round_bl && px == 0 && py == TILE_H - 1) continue;
if(round_br && px == TILE_H - 1 && py == TILE_H - 1) continue;
screen.pen = color_base;
screen.pixel(Point(tile_x + px, tile_y + py));
}
}

screen.pen = color_base;

// top row
int start_x = 0, w = TILE_W;

if(round_tl) start_x++;
if(round_tr) w--;
screen.h_span(Point(tile_x + start_x, tile_y), w - start_x);

// bottom row
start_x = 0;
w = TILE_W;

if(round_bl) start_x++;
if(round_br) w--;
screen.h_span(Point(tile_x + start_x, tile_y + TILE_H - 1), w - start_x);

// rest of the tile
screen.rectangle(Rect(tile_x, tile_y + 1, TILE_W, TILE_H - 2));

} else {
if(feature_map & TILE_ABOVE) {
// Draw the top left/right rounded inside corners
Expand Down Expand Up @@ -287,7 +297,7 @@ uint16_t generate_new_row_mask() {
new_row_mask |= (0x8000 >> passages[i]);

int8_t direction = (passages[i] < target_p_x) ? 1 : -1;

while(passages[i] != target_p_x) {
passages[i] += direction;
new_row_mask |= (0x8000 >> passages[i]);
Expand Down

0 comments on commit 0e88007

Please sign in to comment.