optimize rendering even more.

This commit is contained in:
Christopher Jeffrey 2013-06-06 05:19:52 -05:00
parent d0473749c9
commit ac10c408e3

View File

@ -197,10 +197,16 @@ Screen.prototype.alloc = function() {
this.lines[y] = [];
for (x = 0; x < this.cols; x++) {
this.lines[y][x] = [this.dattr, ' '];
//this.lines[y][x].dirty = true;
}
this.lines[y].dirty = true;
}
this.olines = [];
for (y = 0; y < this.rows; y++) {
this.olines[y] = [];
for (x = 0; x < this.cols; x++) {
this.olines[y][x] = [];
}
}
};
Screen.prototype.render = function() {
@ -222,11 +228,18 @@ Screen.prototype.draw = function(start, end) {
, bgColor
, flags;
var lx = -1
, ly = -1
, o;
this.program.saveCursor();
//this.program.write('\x1b[1;1H');
for (y = start; y <= end; y++) {
line = this.lines[y];
o = this.olines[y];
// TODO: Possibly get rid of .dirty altogether.
if (!line.dirty) continue;
line.dirty = false;
@ -237,6 +250,21 @@ Screen.prototype.draw = function(start, end) {
data = line[x][0];
ch = line[x][1];
if (data === o[x][0] && ch === o[x][1]) {
if (lx === -1) {
lx = x;
ly = y;
}
continue;
} else if (lx !== -1) {
out += y === ly
? '\x1b[' + (x - lx) + 'C'
: '\x1b[' + (y + 1) + ';' + (x + 1) + 'H';
lx = -1, ly = -1;
}
o[x][0] = data;
o[x][1] = ch;
if (data !== attr) {
if (attr !== this.dattr) {
out += '\x1b[m';
@ -315,7 +343,8 @@ Screen.prototype.draw = function(start, end) {
//this.program.move(y + 1, 1);
//this.program.write(out);
this.program.write('\x1b[' + (y + 1) + ';1H' + out);
if (out) this.program.write('\x1b[' + (y + 1) + ';1H' + out);
//if (out) this.program.write(lx !== -1 ? out : '\x1b[' + (y + 1) + ';1H' + out);
}
this.program.restoreCursor();
@ -651,7 +680,6 @@ Box.prototype.render = function() {
// lines[yi][xi][0] = attr;
// lines[yi][xi][1] = ch;
// lines[yi].dirty = true;
// //lines[yi][xi].dirty = true;
// }
// }
//}
@ -660,7 +688,6 @@ Box.prototype.render = function() {
lines[yi][xi][0] = attr;
lines[yi][xi][1] = ch;
lines[yi].dirty = true;
//lines[yi][xi].dirty = true;
}
}
}
@ -764,7 +791,6 @@ Text.prototype.render = function() {
// lines[yi][xi][0] = attr;
// lines[yi][xi][1] = ch;
// lines[yi].dirty = true;
// //lines[yi][xi].dirty = true;
// }
// }
//}
@ -773,7 +799,6 @@ Text.prototype.render = function() {
lines[yi][xi][0] = attr;
lines[yi][xi][1] = ch;
lines[yi].dirty = true;
//lines[yi][xi].dirty = true;
}
}
}
@ -1086,7 +1111,6 @@ ProgressBar.prototype.render = function() {
lines[y][x][0] = attr;
lines[y][x][1] = ch;
lines[y].dirty = true;
//lines[y][x].dirty = true;
}
}
}