]> granicus.if.org Git - nethack/commitdiff
win32_gui: flicker mitigation
authorAlex Kompel <barbos+nethack@gmail.com>
Thu, 11 Jun 2015 02:18:56 +0000 (19:18 -0700)
committerAlex Kompel <barbos+nethack@gmail.com>
Thu, 11 Jun 2015 02:18:56 +0000 (19:18 -0700)
   - 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)

win/win32/mhmap.c

index ec5f5c5f72f0460109414776fcf338edf77f3347..1b491f00c6ba8c8574433e463b5d3a18807501bc 100644 (file)
@@ -452,12 +452,15 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
     switch (wParam) {
     case MSNH_MSG_PRINT_GLYPH: {
         PMSNHMsgPrintGlyph msg_data = (PMSNHMsgPrintGlyph) lParam;
-        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 */
-        nhcoord2display(data, msg_data->x, msg_data->y, &rt);
-        InvalidateRect(hWnd, &rt, TRUE);
+        if((data->map[msg_data->x][msg_data->y] != msg_data->glyph)
+            || (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 */
+            nhcoord2display(data, msg_data->x, msg_data->y, &rt);
+            InvalidateRect(hWnd, &rt, FALSE);
+        }
     } break;
 
     case MSNH_MSG_CLIPAROUND: {
@@ -508,7 +511,8 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
         int i, j;
         for (i = 0; i < COLNO; i++)
             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);
     } break;
@@ -556,7 +560,7 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
             for (col = 0; col < COLNO; col++) {
                 if (index >= msg_data->max_size)
                     break;
-                if (data->map[col][row] == -1) {
+                if (data->map[col][row] == NO_GLYPH) {
                     mgch = ' ';
                 } else {
                     (void) mapglyph(data->map[col][row], &mgch, &color,
@@ -593,8 +597,8 @@ onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
     ZeroMemory(data, sizeof(NHMapWindow));
     for (i = 0; i < COLNO; i++)
         for (j = 0; j < ROWNO; j++) {
-            data->map[i][j] = -1;
-            data->bkmap[i][j] = -1;
+            data->map[i][j] = NO_GLYPH;
+            data->bkmap[i][j] = NO_GLYPH;
         }
 
     data->bAsciiMode = FALSE;
@@ -712,13 +716,13 @@ onPaint(HWND hWnd)
             for (i = paint_rt.left; i < paint_rt.right; i++)
                 for (j = paint_rt.top; j < paint_rt.bottom; 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) {
-                        glyph = -1;
+                        glyph = NO_GLYPH;
                     }
 
-                    if (bkglyph >= 0) {
+                    if (bkglyph != NO_GLYPH) {
                         ntile = glyph2tile[bkglyph];
                         t_x = TILEBMP_X(ntile);
                         t_y = TILEBMP_Y(ntile);
@@ -730,7 +734,7 @@ onPaint(HWND hWnd)
                                    GetNHApp()->mapTile_Y, SRCCOPY);
                     }
 
-                    if (glyph >= 0) {
+                    if (glyph != NO_GLYPH) {
                         ntile = glyph2tile[glyph];
                         t_x = TILEBMP_X(ntile);
                         t_y = TILEBMP_Y(ntile);