yaft: optimize for paint == false case

This commit is contained in:
Stefan Seyfried
2018-01-27 20:29:48 +01:00
committed by Thilo Graf
parent bdb09c2a95
commit 2213cb1448

View File

@@ -124,6 +124,7 @@ bool YaFT_p::init()
* try to get a font size that fits about LINES x COLS into the terminal. * try to get a font size that fits about LINES x COLS into the terminal.
* NOTE: this is not guaranteed to work! Terminal might be smaller or bigger * NOTE: this is not guaranteed to work! Terminal might be smaller or bigger
*/ */
if (paint) {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
delete font; delete font;
delete fr; delete fr;
@@ -136,13 +137,18 @@ bool YaFT_p::init()
scalex = 64 * width / (fw * COLS) + 1; scalex = 64 * width / (fw * COLS) + 1;
scaley = 64 * height / (fh * LINES) + 1; scaley = 64 * height / (fh * LINES) + 1;
} }
} else {
/* dummy */
fh = height / LINES;
fw = width / COLS;
}
CELL_WIDTH = fw; CELL_WIDTH = fw;
CELL_HEIGHT = fh; CELL_HEIGHT = fh;
lines = height / CELL_HEIGHT; lines = height / CELL_HEIGHT;
cols = width / CELL_WIDTH; cols = width / CELL_WIDTH;
logging(NORMAL, "terminal cols:%d lines:%d\n", cols, lines); logging(NORMAL, "terminal cols:%d lines:%d paint:%d\n", cols, lines, paint);
/* allocate memory */ /* allocate memory */
line_dirty.reserve(lines); line_dirty.reserve(lines);
@@ -150,11 +156,12 @@ bool YaFT_p::init()
esc.buf.reserve(1024); esc.buf.reserve(1024);
cells.clear(); cells.clear();
if (paint) {
std::vector<cell_t> line; std::vector<cell_t> line;
line.resize(cols); line.resize(cols);
for (int i = 0; i < lines; i++) for (int i = 0; i < lines; i++)
cells.push_back(line); cells.push_back(line);
line.resize(0); }
/* initialize palette */ /* initialize palette */
for (int i = 0; i < COLORS; i++) for (int i = 0; i < COLORS; i++)
@@ -170,6 +177,8 @@ bool YaFT_p::init()
void YaFT_p::erase_cell(int y, int x) void YaFT_p::erase_cell(int y, int x)
{ {
struct cell_t *cellp; struct cell_t *cellp;
if (! paint)
return;
cellp = &cells[y][x]; cellp = &cells[y][x];
cellp->color_pair = color_pair; /* bce */ cellp->color_pair = color_pair; /* bce */
@@ -181,7 +190,8 @@ void YaFT_p::erase_cell(int y, int x)
void YaFT_p::copy_cell(int dst_y, int dst_x, int src_y, int src_x) void YaFT_p::copy_cell(int dst_y, int dst_x, int src_y, int src_x)
{ {
struct cell_t *dst, *src; struct cell_t *dst, *src;
if (! paint)
return;
dst = &cells[dst_y][dst_x]; dst = &cells[dst_y][dst_x];
src = &cells[src_y][src_x]; src = &cells[src_y][src_x];
*dst = *src; *dst = *src;
@@ -193,6 +203,9 @@ int YaFT_p::set_cell(int y, int x, std::string &utf8)
struct cell_t cell; struct cell_t cell;
uint8_t color_tmp; uint8_t color_tmp;
if (! paint)
return 1;
cell.utf8_str = utf8; cell.utf8_str = utf8;
cell.color_pair.fg = (attribute & attr_mask[ATTR_BOLD] && color_pair.fg <= 7) ? cell.color_pair.fg = (attribute & attr_mask[ATTR_BOLD] && color_pair.fg <= 7) ?
@@ -215,6 +228,10 @@ int YaFT_p::set_cell(int y, int x, std::string &utf8)
void YaFT_p::swap_lines(int i, int j) void YaFT_p::swap_lines(int i, int j)
{ {
/* only called from scroll(), which already checks for paint before
if (!paint)
return;
*/
std::swap(cells[i], cells[j]); std::swap(cells[i], cells[j]);
} }
@@ -222,7 +239,7 @@ void YaFT_p::scroll(int from, int to, int offset)
{ {
int abs_offset, scroll_lines; int abs_offset, scroll_lines;
if (offset == 0 || from >= to) if (offset == 0 || from >= to || paint == false)
return; return;
logging(DEBUG, "scroll from:%d to:%d offset:%d\n", from, to, offset); logging(DEBUG, "scroll from:%d to:%d offset:%d\n", from, to, offset);
@@ -254,6 +271,12 @@ void YaFT_p::move_cursor(int y_offset, int x_offset)
{ {
int x, y, top, bottom; int x, y, top, bottom;
if (y_offset > 0 && !nlseen)
txt.push("");
if (! paint)
return;
x = cursor.x + x_offset; x = cursor.x + x_offset;
y = cursor.y + y_offset; y = cursor.y + y_offset;
@@ -280,9 +303,6 @@ void YaFT_p::move_cursor(int y_offset, int x_offset)
scroll(top, bottom, y_offset); scroll(top, bottom, y_offset);
} }
cursor.y = y; cursor.y = y;
if (y_offset > 0 && !nlseen)
txt.push("");
} }
/* absolute movement: never scroll */ /* absolute movement: never scroll */