win32_gui: flicker mitigation

- do not invalidate window area if tile has not actually changed
   - do not erase backround when invalidating the tile
   - use NO_GLYPH for uninitialized map areas (as opposed to -1)
This commit is contained in:
Alex Kompel
2015-06-10 19:18:56 -07:00
parent 3b158eaa4a
commit ad654cdc61
+17 -13
View File
@@ -452,12 +452,15 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
switch (wParam) { switch (wParam) {
case MSNH_MSG_PRINT_GLYPH: { case MSNH_MSG_PRINT_GLYPH: {
PMSNHMsgPrintGlyph msg_data = (PMSNHMsgPrintGlyph) lParam; PMSNHMsgPrintGlyph msg_data = (PMSNHMsgPrintGlyph) lParam;
data->map[msg_data->x][msg_data->y] = msg_data->glyph; if((data->map[msg_data->x][msg_data->y] != msg_data->glyph)
data->bkmap[msg_data->x][msg_data->y] = msg_data->bkglyph; || (data->bkmap[msg_data->x][msg_data->y] != msg_data->bkglyph)) {
data->map[msg_data->x][msg_data->y] = msg_data->glyph;
data->bkmap[msg_data->x][msg_data->y] = msg_data->bkglyph;
/* invalidate the update area */ /* invalidate the update area */
nhcoord2display(data, msg_data->x, msg_data->y, &rt); nhcoord2display(data, msg_data->x, msg_data->y, &rt);
InvalidateRect(hWnd, &rt, TRUE); InvalidateRect(hWnd, &rt, FALSE);
}
} break; } break;
case MSNH_MSG_CLIPAROUND: { case MSNH_MSG_CLIPAROUND: {
@@ -508,7 +511,8 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
int i, j; int i, j;
for (i = 0; i < COLNO; i++) for (i = 0; i < COLNO; i++)
for (j = 0; j < ROWNO; j++) { for (j = 0; j < ROWNO; j++) {
data->map[i][j] = -1; data->map[i][j] = NO_GLYPH;
data->bkmap[i][j] = NO_GLYPH;
} }
InvalidateRect(hWnd, NULL, TRUE); InvalidateRect(hWnd, NULL, TRUE);
} break; } break;
@@ -556,7 +560,7 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
for (col = 0; col < COLNO; col++) { for (col = 0; col < COLNO; col++) {
if (index >= msg_data->max_size) if (index >= msg_data->max_size)
break; break;
if (data->map[col][row] == -1) { if (data->map[col][row] == NO_GLYPH) {
mgch = ' '; mgch = ' ';
} else { } else {
(void) mapglyph(data->map[col][row], &mgch, &color, (void) mapglyph(data->map[col][row], &mgch, &color,
@@ -593,8 +597,8 @@ onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
ZeroMemory(data, sizeof(NHMapWindow)); ZeroMemory(data, sizeof(NHMapWindow));
for (i = 0; i < COLNO; i++) for (i = 0; i < COLNO; i++)
for (j = 0; j < ROWNO; j++) { for (j = 0; j < ROWNO; j++) {
data->map[i][j] = -1; data->map[i][j] = NO_GLYPH;
data->bkmap[i][j] = -1; data->bkmap[i][j] = NO_GLYPH;
} }
data->bAsciiMode = FALSE; data->bAsciiMode = FALSE;
@@ -712,13 +716,13 @@ onPaint(HWND hWnd)
for (i = paint_rt.left; i < paint_rt.right; i++) for (i = paint_rt.left; i < paint_rt.right; i++)
for (j = paint_rt.top; j < paint_rt.bottom; j++) { for (j = paint_rt.top; j < paint_rt.bottom; j++) {
glyph = data->map[i][j]; glyph = data->map[i][j];
bkglyph = (glyph >= 0)? data->bkmap[i][j] : -1; bkglyph = (glyph != NO_GLYPH)? data->bkmap[i][j] : NO_GLYPH;
if (glyph == bkglyph) { if (glyph == bkglyph) {
glyph = -1; glyph = NO_GLYPH;
} }
if (bkglyph >= 0) { if (bkglyph != NO_GLYPH) {
ntile = glyph2tile[bkglyph]; ntile = glyph2tile[bkglyph];
t_x = TILEBMP_X(ntile); t_x = TILEBMP_X(ntile);
t_y = TILEBMP_Y(ntile); t_y = TILEBMP_Y(ntile);
@@ -730,7 +734,7 @@ onPaint(HWND hWnd)
GetNHApp()->mapTile_Y, SRCCOPY); GetNHApp()->mapTile_Y, SRCCOPY);
} }
if (glyph >= 0) { if (glyph != NO_GLYPH) {
ntile = glyph2tile[glyph]; ntile = glyph2tile[glyph];
t_x = TILEBMP_X(ntile); t_x = TILEBMP_X(ntile);
t_y = TILEBMP_Y(ntile); t_y = TILEBMP_Y(ntile);