[renderer] Clean up a lot of recalc_refdef use

I think the widespread use of recalc_refdef (and force_fullscreen) was
the result of a rushed merge of the renderer and video code (I do seem
to remember sprinkling them around). This cleans the two out of the
client code.
This commit is contained in:
Bill Currie 2022-03-19 00:56:30 +09:00
parent a4479f4840
commit ee51d06aa3
12 changed files with 96 additions and 64 deletions

View file

@ -33,7 +33,6 @@ struct transform_s;
struct tex_s;
void SCR_Init (void);
void SCR_SetFOV (float fov);
void SCR_DrawRam (void);
void SCR_DrawTurtle (void);
@ -43,6 +42,9 @@ typedef void (*SCR_Func)(void);
// scr_funcs is a null terminated array
void SCR_UpdateScreen (struct transform_s *camera, double realtime,
SCR_Func *scr_funcs);
// control whether the 3d viewport is user-controlled or always fullscreen
void SCR_SetFullscreen (qboolean fullscreen);
void SCR_SetBottomMargin (int lines);
void SCR_DrawStringToSnap (const char *s, struct tex_s *tex, int x, int y);
struct tex_s *SCR_SnapScreen (unsigned width, unsigned height);

View file

@ -64,7 +64,6 @@ typedef struct viewstate_s {
cshift_t cshifts[NUM_CSHIFTS]; // Color shifts for damage, powerups
cshift_t prev_cshifts[NUM_CSHIFTS]; // and content types
quat_t cshift_color;
qboolean cshift_changed;
// pitch drifting vars
float idealpitch;

View file

@ -444,17 +444,17 @@ V_PrepBlend (viewstate_t *vs)
|| (vs->force_cshifts & INFO_CSHIFT_POWERUP))
V_CalcPowerupCshift (vs);
vs->cshift_changed = false;
qboolean cshift_changed = false;
for (i = 0; i < NUM_CSHIFTS; i++) {
if (vs->cshifts[i].percent != vs->prev_cshifts[i].percent) {
vs->cshift_changed = true;
cshift_changed = true;
vs->prev_cshifts[i].percent = vs->cshifts[i].percent;
}
for (j = 0; j < 3; j++) {
if (vs->cshifts[i].destcolor[j] != vs->prev_cshifts[i].destcolor[j])
{
vs->cshift_changed = true;
cshift_changed = true;
vs->prev_cshifts[i].destcolor[j] = vs->cshifts[i].destcolor[j];
}
}
@ -465,7 +465,7 @@ V_PrepBlend (viewstate_t *vs)
// drop the bonus value
V_DropCShift (&vs->cshifts[CSHIFT_BONUS], vs->time, 100);
if (!vs->cshift_changed && !r_data->vid->recalc_refdef)
if (!cshift_changed)
return;
V_CalcBlend (vs);

View file

@ -865,5 +865,4 @@ Menu_Leave ()
Con_SetState (con_inactive);
}
}
r_data->vid->recalc_refdef = true;
}

View file

@ -161,7 +161,14 @@ r_nearclip_f (cvar_t *var)
static void
scr_fov_f (cvar_t *var)
{
SCR_SetFOV (var->value);
// bound field of view
float fov = bound (0, var->value, 170);
if (fov != var->value) {
Cvar_SetValue (var, fov);
} else {
r_data->vid->recalc_refdef = 1;
}
}
static void

View file

@ -66,8 +66,8 @@ static qboolean scr_initialized;// ready to draw
static qpic_t *scr_ram;
static qpic_t *scr_turtle;
void
R_SetVrect (const vrect_t *vrectin, vrect_t *vrect, int lineadj)
static void
set_vrect (const vrect_t *vrectin, vrect_t *vrect, int lineadj)
{
float size;
int h;
@ -98,44 +98,43 @@ R_SetVrect (const vrect_t *vrectin, vrect_t *vrect, int lineadj)
vrect->y = (h - vrect->height) / 2;
}
static float __attribute__((pure))
CalcFov (float fov_x, float width, float height)
void//FIXME remove when sw warp is cleaned up
R_SetVrect (const vrect_t *vrectin, vrect_t *vrect, int lineadj)
{
double f = fov_x * M_PI / 360;
set_vrect (vrectin, vrect, lineadj);
}
static void
set_fov (float fov)
{
refdef_t *refdef = r_data->refdef;
double f = fov * M_PI / 360;
double c = cos(f);
double s = sin(f);
double w = refdef->vrect.width;
double h = refdef->vrect.height;
return 360 * atan2 (s * height, c * width) / M_PI;
refdef->fov_x = fov;
refdef->fov_y = 360 * atan2 (s * h, c * w) / M_PI;
}
static void
SCR_CalcRefdef (void)
{
vrect_t vrect;
refdef_t *refdef = r_data->refdef;
view_t *view = r_data->scr_view;
const vrect_t *rect = &r_data->refdef->vrect;
// force a background redraw
r_data->scr_fullupdate = 0;
r_data->vid->recalc_refdef = 0;
vrect.x = 0;
vrect.y = 0;
vrect.width = r_data->vid->width;
vrect.height = r_data->vid->height;
R_SetVrect (&vrect, &refdef->vrect, r_data->lineadj);
view_setgeometry (r_data->scr_view, refdef->vrect.x, refdef->vrect.y,
refdef->vrect.width, refdef->vrect.height);
// bound field of view
Cvar_SetValue (scr_fov, bound (0, scr_fov->value, 170));
refdef->fov_y = CalcFov (refdef->fov_x, refdef->vrect.width,
refdef->vrect.height);
view_setgeometry (view, rect->x, rect->y, rect->width, rect->height);
// notify the refresh of the change
r_funcs->R_ViewChanged ();
// force a background redraw
r_data->scr_fullupdate = 0;
}
/*
@ -216,12 +215,39 @@ SCR_UpdateScreen (transform_t *camera, double realtime, SCR_Func *scr_funcs)
r_funcs->end_frame ();
}
void
SCR_SetFOV (float fov)
static void
update_vrect (void)
{
refdef_t *refdef = r_data->refdef;
refdef->fov_x = fov;
r_data->vid->recalc_refdef = 1;
vrect_t vrect;
refdef_t *refdef = r_data->refdef;
vrect.x = 0;
vrect.y = 0;
vrect.width = r_data->vid->width;
vrect.height = r_data->vid->height;
set_vrect (&vrect, &refdef->vrect, r_data->lineadj);
set_fov (scr_fov->value);
}
void
SCR_SetFullscreen (qboolean fullscreen)
{
if (r_data->force_fullscreen == fullscreen) {
return;
}
r_data->force_fullscreen = fullscreen;
update_vrect ();
}
void
SCR_SetBottomMargin (int lines)
{
r_data->lineadj = lines;
update_vrect ();
}
static void
@ -465,6 +491,12 @@ SCR_SnapScreen (unsigned width, unsigned height)
return tex;
}
static void
viewsize_listener (void *data, const cvar_t *cvar)
{
update_vrect ();
}
void
SCR_Init (void)
{
@ -480,4 +512,7 @@ SCR_Init (void)
scr_initialized = true;
r_ent_queue = EntQueue_New (mod_num_types);
Cvar_AddListener (scr_viewsize, viewsize_listener, 0);
update_vrect ();
}

View file

@ -154,8 +154,7 @@ void
CL_ClearMemory (void)
{
VID_ClearMemory ();
if (r_data)
r_data->force_fullscreen = 0;
SCR_SetFullscreen (0);
}
void
@ -220,7 +219,7 @@ CL_ClearState (void)
cl.viewstate.chasestate = &cl.chasestate;
cl.chasestate.viewstate = &cl.viewstate;
cl.watervis = 1;
r_data->force_fullscreen = 0;
SCR_SetFullscreen (0);
r_data->lightstyle = cl.lightstyle;
SZ_Clear (&cls.message);

View file

@ -841,8 +841,6 @@ CL_ParseServerMessage (void)
}
Cbuf_Execute_Stack (host_cbuf);
CL_ParseServerInfo ();
// leave full screen intermission
r_data->vid->recalc_refdef = true;
break;
case svc_lightstyle:
@ -984,16 +982,14 @@ CL_ParseServerMessage (void)
case svc_intermission:
cl.intermission = 1;
r_data->force_fullscreen = 1;
SCR_SetFullscreen (1);
cl.completed_time = cl.time;
r_data->vid->recalc_refdef = true; // go to full screen
break;
case svc_finale:
cl.intermission = 2;
r_data->force_fullscreen = 1;
SCR_SetFullscreen (1);
cl.completed_time = cl.time;
r_data->vid->recalc_refdef = true; // go to full screen
str = MSG_ReadString (net_message);
if (strcmp (str, centerprint->str)) {
dstring_copystr (centerprint, str);
@ -1018,9 +1014,8 @@ CL_ParseServerMessage (void)
case svc_cutscene:
cl.intermission = 3;
r_data->force_fullscreen = 1;
SCR_SetFullscreen (1);
cl.completed_time = cl.time;
r_data->vid->recalc_refdef = true; // go to full screen
str = MSG_ReadString (net_message);
if (strcmp (str, centerprint->str)) {
dstring_copystr (centerprint, str);

View file

@ -206,10 +206,9 @@ calc_sb_lines (cvar_t *var)
static void
hud_sbar_f (cvar_t *var)
{
r_data->vid->recalc_refdef = true;
if (r_data->scr_viewsize)
calc_sb_lines (r_data->scr_viewsize);
r_data->lineadj = var->int_val ? sb_lines : 0;
SCR_SetBottomMargin (var->int_val ? sb_lines : 0);
if (var->int_val) {
view_remove (main_view, main_view->children[0]);
view_insert (main_view, sbar_view, 0);
@ -223,8 +222,9 @@ static void
viewsize_f (cvar_t *var)
{
calc_sb_lines (var);
if (hud_sbar)
r_data->lineadj = hud_sbar->int_val ? sb_lines : 0;
if (hud_sbar) {
SCR_SetBottomMargin (hud_sbar->int_val ? sb_lines : 0);
}
}

View file

@ -399,7 +399,7 @@ CL_ClearState (void)
memset (&cl, 0, sizeof (cl));
cl.viewstate.camera_transform = cam;
cl.players = calloc (MAX_CLIENTS, sizeof (player_info_t));
r_data->force_fullscreen = 0;
SCR_SetFullscreen (0);
cl.maxclients = MAX_CLIENTS;
cl.viewstate.voffs_enabled = 0;
@ -812,7 +812,7 @@ CL_Changing_f (void)
S_StopAllSounds ();
cl.intermission = 0;
cl.viewstate.intermission = 0;
r_data->force_fullscreen = 0;
SCR_SetFullscreen (0);
CL_SetState (ca_connected); // not active anymore, but not
// disconnected
Sys_Printf ("\nChanging map...\n");

View file

@ -1351,8 +1351,6 @@ CL_ParseServerMessage (void)
}
Cbuf_Execute_Stack (cl_stbuf);
CL_ParseServerData ();
// leave full screen intermission
r_data->vid->recalc_refdef = true;
break;
case svc_lightstyle:
@ -1455,9 +1453,8 @@ CL_ParseServerMessage (void)
Sys_MaskPrintf (SYS_dev, "svc_intermission\n");
cl.intermission = 1;
r_data->force_fullscreen = 1;
SCR_SetFullscreen (1);
cl.completed_time = realtime;
r_data->vid->recalc_refdef = true; // go to full screen
Sys_MaskPrintf (SYS_dev, "intermission simorg: ");
MSG_ReadCoordV (net_message, &cl.viewstate.player_origin[0]);//FIXME
cl.viewstate.player_origin[3] = 1;
@ -1479,9 +1476,8 @@ CL_ParseServerMessage (void)
case svc_finale:
cl.intermission = 2;
r_data->force_fullscreen = 1;
SCR_SetFullscreen (1);
cl.completed_time = realtime;
r_data->vid->recalc_refdef = true; // go to full screen
str = MSG_ReadString (net_message);
if (strcmp (str, centerprint->str)) {
dstring_copystr (centerprint, str);

View file

@ -194,10 +194,9 @@ calc_sb_lines (cvar_t *var)
static void
hud_sbar_f (cvar_t *var)
{
r_data->vid->recalc_refdef = true;
if (r_data->scr_viewsize)
calc_sb_lines (r_data->scr_viewsize);
r_data->lineadj = var->int_val ? sb_lines : 0;
SCR_SetBottomMargin (var->int_val ? sb_lines : 0);
if (var->int_val) {
view_remove (main_view, main_view->children[0]);
view_insert (main_view, sbar_view, 0);
@ -211,8 +210,9 @@ static void
viewsize_f (cvar_t *var)
{
calc_sb_lines (var);
if (hud_sbar)
r_data->lineadj = hud_sbar->int_val ? sb_lines : 0;
if (hud_sbar) {
SCR_SetBottomMargin (hud_sbar->int_val ? sb_lines : 0);
}
}