optimise HUD widget erasing, avoid flicker when screen size is reduced (#1349)

This commit is contained in:
Roman Fomin 2023-12-23 16:43:55 +07:00 committed by GitHub
parent e4464862c5
commit b2c7b40641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 78 additions and 35 deletions

View File

@ -317,6 +317,7 @@ void D_Display (void)
if (borderdrawcount)
{
R_DrawViewBorder (); // erase old menu stuff
HU_Drawer ();
borderdrawcount--;
}
}

View File

@ -22,6 +22,8 @@
#include "m_swap.h"
#include "hu_lib.h"
#include "hu_stuff.h"
#include "r_draw.h"
#include "v_video.h"
// [FG] horizontal alignment
@ -121,13 +123,12 @@ boolean HUlib_add_key_to_line(hu_line_t *const l, unsigned char ch)
{
if (ch >= ' ' && ch <= '_')
add_char_to_line(l, (char) ch);
else
if (ch == KEY_BACKSPACE) // phares
del_char_from_line(l);
else
if (ch != KEY_ENTER) // phares
return false; // did not eat key
return true; // ate the key
else if (ch == KEY_BACKSPACE) // phares
del_char_from_line(l);
else if (ch != KEY_ENTER) // phares
return false; // did not eat key
return true; // ate the key
}
boolean HUlib_add_key_to_cur_line(hu_multiline_t *const m, unsigned char ch)
@ -503,6 +504,28 @@ void HUlib_init_multiline(hu_multiline_t *m,
m->built = false;
}
void HUlib_erase_widget (const hu_widget_t *const w)
{
const hu_multiline_t *const m = w->multiline;
const hu_font_t *const f = *m->font;
const int height = m->numlines * f->line_height;
const int y = vert_align_widget(w, m, f, w->h_align, w->v_align);
if (y < scaledviewy || y >= scaledviewy + scaledviewheight)
{
// erase entire line
R_VideoErase(0, y, video.unscaledw, height);
}
else
{
// erase left border
R_VideoErase(0, y, scaledviewx, height);
// erase right border
R_VideoErase(scaledviewx + scaledviewwidth, y, scaledviewx, height);
}
}
//----------------------------------------------------------------------------
//
// $Log: hu_lib.c,v $

View File

@ -137,6 +137,8 @@ void HUlib_init_multiline (hu_multiline_t *const m, int nl, hu_font_t **f, char
boolean HUlib_add_key_to_line (hu_line_t *const l, unsigned char ch);
boolean HUlib_add_key_to_cur_line (hu_multiline_t *const m, unsigned char ch);
void HUlib_erase_widget (const hu_widget_t *const w);
#endif
//----------------------------------------------------------------------------

View File

@ -24,6 +24,7 @@
#include "hu_stuff.h"
#include "hu_obituary.h"
#include "hu_lib.h"
#include "r_state.h"
#include "st_stuff.h" /* jff 2/16/98 need loc of status bar */
#include "w_wad.h"
#include "s_sound.h"
@ -1423,15 +1424,6 @@ void HU_Drawer(void)
HUlib_reset_align_offsets();
// jff 4/24/98 Erase current lines before drawing current
// needed when screen not fullsize
// killough 11/98: only do it when not fullsize
// moved here to properly update the w_sttime and w_monsec widgets
if (scaledviewheight < 200)
{
HU_Erase();
}
w = doom_widget;
while (w->multiline)
{
@ -1482,9 +1474,32 @@ void WI_DrawTimeWidget(void)
void HU_Erase(void)
{
// [FG] TODO optimize!
if (!automapactive && viewwindowx)
R_DrawViewBorder();
hu_widget_t *w;
if (automapactive || !scaledviewx)
return;
HUlib_reset_align_offsets();
w = doom_widget;
while (w->multiline)
{
if (*w->multiline->on)
{
HUlib_erase_widget(w);
}
w++;
}
w = boom_widget;
while (w->multiline)
{
if (w->multiline->built)
{
HUlib_erase_widget(w);
}
w++;
}
}
//

View File

@ -913,9 +913,12 @@ void R_FillBackScreen (void)
// Copy a screen buffer.
//
static void R_VideoErase(int x, int y, int w, int h)
void R_VideoErase(int x, int y, int w, int h)
{
V_CopyRect(x, y, background_buffer, w, h, x, y);
if (background_buffer == NULL)
return;
V_CopyRect(x, y, background_buffer, w, h, x, y);
}
//
@ -928,23 +931,23 @@ static void R_VideoErase(int x, int y, int w, int h)
// can scale to hires automatically in R_VideoErase().
//
void R_DrawViewBorder(void)
void R_DrawViewBorder(void)
{
int side;
int side;
if (scaledviewwidth == video.unscaledw || background_buffer == NULL)
return;
if (scaledviewwidth == video.unscaledw || background_buffer == NULL)
return;
// copy top
R_VideoErase(0, 0, video.unscaledw, scaledviewy);
// copy top
R_VideoErase(0, 0, video.unscaledw, scaledviewy);
// copy sides
side = scaledviewx;
R_VideoErase(0, scaledviewy, side, scaledviewheight);
R_VideoErase(video.unscaledw - side, scaledviewy, side, scaledviewheight);
// copy sides
side = scaledviewx;
R_VideoErase(0, scaledviewy, side, scaledviewheight);
R_VideoErase(video.unscaledw - side, scaledviewy, side, scaledviewheight);
// copy bottom
R_VideoErase(0, scaledviewy + scaledviewheight, video.unscaledw, scaledviewy);
// copy bottom
R_VideoErase(0, scaledviewy + scaledviewheight, video.unscaledw, scaledviewy);
}
//----------------------------------------------------------------------------

View File

@ -82,6 +82,7 @@ void R_InitBuffer(void);
void R_InitTranslationTables(void);
// Rendering function.
void R_VideoErase(int x, int y, int w, int h);
void R_FillBackScreen(void);
void R_DrawBorder(int x, int y, int w, int h);

View File

@ -558,8 +558,6 @@ void R_ExecuteSetViewSize (void)
}
}
//HU_disable_all_widgets();
// [crispy] forcefully initialize the status bar backing screen
ST_refreshBackground(true);