2002-12-11 17:34:48 +00:00
|
|
|
/*
|
|
|
|
screen.c
|
|
|
|
|
|
|
|
master for refresh, status bar, console, chat, notify, etc
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2002-12-11 17:34:48 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/draw.h"
|
2022-03-07 05:39:47 +00:00
|
|
|
#include "QF/dstring.h"
|
2003-09-04 18:59:39 +00:00
|
|
|
#include "QF/image.h"
|
2022-03-07 05:39:47 +00:00
|
|
|
#include "QF/png.h"
|
2002-12-11 17:34:48 +00:00
|
|
|
#include "QF/pcx.h"
|
2022-03-07 05:39:47 +00:00
|
|
|
#include "QF/quakefs.h"
|
2002-12-11 17:34:48 +00:00
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/screen.h"
|
|
|
|
#include "QF/sys.h"
|
2022-03-07 05:39:47 +00:00
|
|
|
#include "QF/va.h"
|
2002-12-11 17:34:48 +00:00
|
|
|
|
2022-03-17 03:00:43 +00:00
|
|
|
#include "QF/scene/entity.h"
|
2022-05-05 05:41:46 +00:00
|
|
|
#include "QF/scene/scene.h"
|
2022-02-28 07:59:38 +00:00
|
|
|
#include "QF/scene/transform.h"
|
2021-07-10 09:04:34 +00:00
|
|
|
#include "QF/ui/view.h"
|
|
|
|
|
2002-12-11 17:34:48 +00:00
|
|
|
#include "compat.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2002-12-11 17:34:48 +00:00
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
// only the refresh window will be updated unless these variables are flagged
|
2002-12-11 17:34:48 +00:00
|
|
|
int scr_copytop;
|
2022-03-06 04:47:41 +00:00
|
|
|
byte *draw_chars; // 8*8 graphic characters FIXME location
|
2021-01-12 07:14:46 +00:00
|
|
|
qboolean r_cache_thrash; // set if surface cache is thrashing
|
2022-05-22 02:18:32 +00:00
|
|
|
int *r_node_visframes; //FIXME per renderer
|
2022-05-22 05:43:07 +00:00
|
|
|
int *r_leaf_visframes; //FIXME per renderer
|
2022-05-22 07:31:24 +00:00
|
|
|
int *r_face_visframes; //FIXME per renderer
|
2021-01-12 07:14:46 +00:00
|
|
|
|
2002-12-11 17:34:48 +00:00
|
|
|
qboolean scr_skipupdate;
|
2022-03-06 04:47:41 +00:00
|
|
|
static qboolean scr_initialized;// ready to draw
|
2002-12-11 17:34:48 +00:00
|
|
|
|
2022-03-24 06:45:01 +00:00
|
|
|
static framebuffer_t *fisheye_cube_map;
|
2022-03-24 03:22:27 +00:00
|
|
|
static framebuffer_t *warp_buffer;
|
2022-03-24 06:45:01 +00:00
|
|
|
|
2022-03-30 05:55:32 +00:00
|
|
|
static float fov_x, fov_y;
|
|
|
|
static float tan_fov_x, tan_fov_y;
|
2022-05-05 05:41:46 +00:00
|
|
|
static scene_t *scr_scene;//FIXME don't want this here
|
2022-03-30 05:55:32 +00:00
|
|
|
|
2022-03-24 06:45:01 +00:00
|
|
|
static mat4f_t box_rotations[] = {
|
|
|
|
[BOX_FRONT] = {
|
2022-04-23 01:56:56 +00:00
|
|
|
{ 1, 0, 0, 0},
|
2022-03-24 06:45:01 +00:00
|
|
|
{ 0, 1, 0, 0},
|
|
|
|
{ 0, 0, 1, 0},
|
|
|
|
{ 0, 0, 0, 1}
|
|
|
|
},
|
|
|
|
[BOX_RIGHT] = {
|
2022-04-23 01:56:56 +00:00
|
|
|
{ 0,-1, 0, 0},
|
2022-03-24 06:45:01 +00:00
|
|
|
{ 1, 0, 0, 0},
|
|
|
|
{ 0, 0, 1, 0},
|
|
|
|
{ 0, 0, 0, 1}
|
|
|
|
},
|
|
|
|
[BOX_BEHIND] = {
|
2022-04-23 01:56:56 +00:00
|
|
|
{-1, 0, 0, 0},
|
2022-03-24 06:45:01 +00:00
|
|
|
{ 0,-1, 0, 0},
|
|
|
|
{ 0, 0, 1, 0},
|
|
|
|
{ 0, 0, 0, 1}
|
|
|
|
},
|
|
|
|
[BOX_LEFT] = {
|
2022-04-23 01:56:56 +00:00
|
|
|
{ 0, 1, 0, 0},
|
2022-03-24 06:45:01 +00:00
|
|
|
{-1, 0, 0, 0},
|
|
|
|
{ 0, 0, 1, 0},
|
|
|
|
{ 0, 0, 0, 1}
|
|
|
|
},
|
|
|
|
[BOX_TOP] = {
|
2022-04-23 01:56:56 +00:00
|
|
|
{ 0, 0, 1, 0},
|
2022-03-24 06:45:01 +00:00
|
|
|
{ 0, 1, 0, 0},
|
|
|
|
{-1, 0, 0, 0},
|
|
|
|
{ 0, 0, 0, 1}
|
|
|
|
},
|
|
|
|
[BOX_BOTTOM] = {
|
2022-04-23 01:56:56 +00:00
|
|
|
{ 0, 0,-1, 0},
|
2022-03-24 06:45:01 +00:00
|
|
|
{ 0, 1, 0, 0},
|
|
|
|
{ 1, 0, 0, 0},
|
|
|
|
{ 0, 0, 0, 1}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-03-18 15:56:30 +00:00
|
|
|
static void
|
|
|
|
set_vrect (const vrect_t *vrectin, vrect_t *vrect, int lineadj)
|
2004-02-08 00:37:11 +00:00
|
|
|
{
|
|
|
|
float size;
|
|
|
|
int h;
|
|
|
|
|
2013-01-13 07:53:22 +00:00
|
|
|
size = min (r_viewsize, 100);
|
2021-01-12 07:14:46 +00:00
|
|
|
if (r_data->force_fullscreen) {
|
2022-03-07 14:32:44 +00:00
|
|
|
// intermission is always full screen
|
2004-02-08 00:37:11 +00:00
|
|
|
size = 100.0;
|
|
|
|
lineadj = 0;
|
|
|
|
}
|
|
|
|
size /= 100.0;
|
|
|
|
|
2013-01-13 07:07:11 +00:00
|
|
|
h = vrectin->height - lineadj;
|
2004-02-08 00:37:11 +00:00
|
|
|
|
2013-01-13 07:07:11 +00:00
|
|
|
vrect->width = vrectin->width * size + 0.5;
|
|
|
|
if (vrect->width < 96) {
|
|
|
|
size = 96.0 / vrectin->width;
|
|
|
|
vrect->width = 96; // min for icons
|
2004-02-08 00:37:11 +00:00
|
|
|
}
|
2013-01-13 07:07:11 +00:00
|
|
|
vrect->width &= ~7;
|
2004-02-08 00:37:11 +00:00
|
|
|
|
2013-01-13 07:07:11 +00:00
|
|
|
vrect->height = vrectin->height * size + 0.5;
|
|
|
|
if (vrect->height > h)
|
|
|
|
vrect->height = h;
|
|
|
|
vrect->height &= ~1;
|
2004-02-08 00:37:11 +00:00
|
|
|
|
2013-01-13 07:07:11 +00:00
|
|
|
vrect->x = (vrectin->width - vrect->width) / 2;
|
|
|
|
vrect->y = (h - vrect->height) / 2;
|
2004-02-08 00:37:11 +00:00
|
|
|
}
|
|
|
|
|
2022-03-18 15:56:30 +00:00
|
|
|
void//FIXME remove when sw warp is cleaned up
|
|
|
|
R_SetVrect (const vrect_t *vrectin, vrect_t *vrect, int lineadj)
|
|
|
|
{
|
|
|
|
set_vrect (vrectin, vrect, lineadj);
|
|
|
|
}
|
|
|
|
|
2022-03-30 05:55:32 +00:00
|
|
|
void
|
|
|
|
SCR_SetFOV (float fov)
|
2021-04-01 10:40:25 +00:00
|
|
|
{
|
2022-03-18 15:56:30 +00:00
|
|
|
|
|
|
|
refdef_t *refdef = r_data->refdef;
|
|
|
|
|
|
|
|
double f = fov * M_PI / 360;
|
2022-03-18 02:03:37 +00:00
|
|
|
double c = cos(f);
|
|
|
|
double s = sin(f);
|
2022-03-18 15:56:30 +00:00
|
|
|
double w = refdef->vrect.width;
|
|
|
|
double h = refdef->vrect.height;
|
2021-04-01 10:40:25 +00:00
|
|
|
|
2022-03-30 05:55:32 +00:00
|
|
|
fov_x = fov;
|
|
|
|
fov_y = 360 * atan2 (s * h, c * w) / M_PI;
|
|
|
|
tan_fov_x = s / c;
|
|
|
|
tan_fov_y = (s * h) / (c * w);
|
|
|
|
r_funcs->set_fov (tan_fov_x, tan_fov_y);
|
2021-04-01 10:40:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-05 05:35:56 +00:00
|
|
|
static void
|
2004-02-08 00:37:11 +00:00
|
|
|
SCR_CalcRefdef (void)
|
|
|
|
{
|
2021-01-12 07:14:46 +00:00
|
|
|
r_data->vid->recalc_refdef = 0;
|
2004-02-08 00:37:11 +00:00
|
|
|
|
2022-03-18 15:56:30 +00:00
|
|
|
// force a background redraw
|
|
|
|
r_data->scr_fullupdate = 0;
|
2022-09-21 16:11:56 +00:00
|
|
|
r_funcs->bind_framebuffer (0);
|
2004-02-08 00:37:11 +00:00
|
|
|
}
|
2002-12-11 17:34:48 +00:00
|
|
|
|
2022-03-24 06:45:01 +00:00
|
|
|
static void
|
|
|
|
render_scene (void)
|
|
|
|
{
|
|
|
|
r_framecount++;
|
|
|
|
EntQueue_Clear (r_ent_queue);
|
|
|
|
r_funcs->render_view ();
|
|
|
|
r_funcs->draw_particles (&r_psystem);
|
|
|
|
r_funcs->draw_transparent ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
render_side (int side)
|
|
|
|
{
|
|
|
|
mat4f_t camera;
|
|
|
|
mat4f_t camera_inverse;
|
|
|
|
mat4f_t rotinv;
|
|
|
|
|
|
|
|
memcpy (camera, r_refdef.camera, sizeof (camera));
|
|
|
|
memcpy (camera_inverse, r_refdef.camera_inverse, sizeof (camera_inverse));
|
|
|
|
mmulf (r_refdef.camera, camera, box_rotations[side]);
|
|
|
|
mat4ftranspose (rotinv, box_rotations[side]);
|
|
|
|
mmulf (r_refdef.camera_inverse, rotinv, camera_inverse);
|
|
|
|
|
|
|
|
//FIXME see fixme in r_screen.c
|
|
|
|
r_refdef.frame.mat[0] = -r_refdef.camera[1];
|
|
|
|
r_refdef.frame.mat[1] = r_refdef.camera[0];
|
|
|
|
r_refdef.frame.mat[2] = r_refdef.camera[2];
|
|
|
|
r_refdef.frame.mat[3] = r_refdef.camera[3];
|
|
|
|
|
2022-03-25 03:22:16 +00:00
|
|
|
refdef_t *refdef = r_data->refdef;
|
2022-03-30 05:55:32 +00:00
|
|
|
R_SetFrustum (refdef->frustum, &refdef->frame, 90, 90);
|
2022-03-25 03:22:16 +00:00
|
|
|
|
2022-03-24 06:45:01 +00:00
|
|
|
r_funcs->bind_framebuffer (&fisheye_cube_map[side]);
|
|
|
|
render_scene ();
|
|
|
|
|
|
|
|
memcpy (r_refdef.camera, camera, sizeof (camera));
|
|
|
|
memcpy (r_refdef.camera_inverse, camera_inverse, sizeof (camera_inverse));
|
|
|
|
}
|
|
|
|
|
2021-01-11 07:57:31 +00:00
|
|
|
void
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
SCR_UpdateScreen (transform_t camera, double realtime, SCR_Func *scr_funcs)
|
2021-01-11 07:57:31 +00:00
|
|
|
{
|
|
|
|
if (scr_skipupdate || !scr_initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (r_timegraph || r_speeds || r_dspeeds) {
|
2022-03-17 08:50:38 +00:00
|
|
|
r_time1 = Sys_DoubleTime ();
|
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (scr_fisheye && !fisheye_cube_map) {
|
2022-03-24 06:45:01 +00:00
|
|
|
fisheye_cube_map = r_funcs->create_cube_map (r_data->vid->height);
|
|
|
|
}
|
|
|
|
|
2022-03-17 03:00:43 +00:00
|
|
|
refdef_t *refdef = r_data->refdef;
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
if (Transform_Valid (camera)) {
|
2022-03-17 03:00:43 +00:00
|
|
|
Transform_GetWorldMatrix (camera, refdef->camera);
|
|
|
|
Transform_GetWorldInverse (camera, refdef->camera_inverse);
|
2022-02-28 07:59:38 +00:00
|
|
|
} else {
|
2022-03-17 03:00:43 +00:00
|
|
|
mat4fidentity (refdef->camera);
|
|
|
|
mat4fidentity (refdef->camera_inverse);
|
2022-02-28 07:59:38 +00:00
|
|
|
}
|
2022-03-17 03:00:43 +00:00
|
|
|
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
// FIXME pre-rotate the camera 90 degrees about the z axis such that the
|
|
|
|
// camera forward vector (camera Y) points along the world +X axis and the
|
|
|
|
// camera right vector (camera X) points along the world -Y axis. This
|
|
|
|
// should not be necessary here but is due to AngleVectors (and thus
|
|
|
|
// AngleQuat for compatibility) treating X as forward and Y as left (or -Y
|
|
|
|
// as right). Fixing this would take an audit of the usage of both, but is
|
|
|
|
// probably worthwhile in the long run.
|
2022-03-17 03:00:43 +00:00
|
|
|
refdef->frame.mat[0] = -refdef->camera[1];
|
|
|
|
refdef->frame.mat[1] = refdef->camera[0];
|
|
|
|
refdef->frame.mat[2] = refdef->camera[2];
|
|
|
|
refdef->frame.mat[3] = refdef->camera[3];
|
2022-03-30 05:55:32 +00:00
|
|
|
R_SetFrustum (refdef->frustum, &refdef->frame, fov_x, fov_y);
|
2022-03-17 03:00:43 +00:00
|
|
|
|
2021-01-12 07:14:46 +00:00
|
|
|
r_data->realtime = realtime;
|
|
|
|
scr_copytop = r_data->scr_copyeverything = 0;
|
2021-01-11 07:57:31 +00:00
|
|
|
|
2021-01-12 07:14:46 +00:00
|
|
|
if (r_data->vid->recalc_refdef) {
|
2021-01-11 07:57:31 +00:00
|
|
|
SCR_CalcRefdef ();
|
|
|
|
}
|
|
|
|
|
2022-03-17 08:50:38 +00:00
|
|
|
R_RunParticles (r_data->frametime);
|
2022-03-17 03:00:43 +00:00
|
|
|
R_AnimateLight ();
|
2022-05-05 05:58:47 +00:00
|
|
|
if (scr_scene && scr_scene->worldmodel) {
|
|
|
|
scr_scene->viewleaf = 0;
|
2022-03-17 03:00:43 +00:00
|
|
|
vec4f_t position = refdef->frame.position;
|
2022-05-22 02:18:32 +00:00
|
|
|
scr_scene->viewleaf = Mod_PointInLeaf (position, scr_scene->worldmodel);
|
2022-03-24 03:22:27 +00:00
|
|
|
r_dowarpold = r_dowarp;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (r_waterwarp) {
|
2022-05-05 05:58:47 +00:00
|
|
|
r_dowarp = scr_scene->viewleaf->contents <= CONTENTS_WATER;
|
2022-03-24 03:22:27 +00:00
|
|
|
}
|
|
|
|
if (r_dowarp && !warp_buffer) {
|
2022-03-24 06:45:01 +00:00
|
|
|
warp_buffer = r_funcs->create_frame_buffer (r_data->vid->width,
|
|
|
|
r_data->vid->height);
|
2022-03-24 03:22:27 +00:00
|
|
|
}
|
2022-05-22 07:31:24 +00:00
|
|
|
R_MarkLeaves (scr_scene->viewleaf, r_node_visframes, r_leaf_visframes,
|
|
|
|
r_face_visframes);
|
2022-03-17 03:00:43 +00:00
|
|
|
}
|
2022-03-17 08:50:38 +00:00
|
|
|
R_PushDlights (vec3_origin);
|
2022-03-17 03:00:43 +00:00
|
|
|
|
2022-03-07 14:32:44 +00:00
|
|
|
r_funcs->begin_frame ();
|
2022-03-24 03:22:27 +00:00
|
|
|
if (r_dowarp) {
|
|
|
|
r_funcs->bind_framebuffer (warp_buffer);
|
|
|
|
}
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (scr_fisheye && fisheye_cube_map) {
|
2022-03-26 00:41:58 +00:00
|
|
|
int side = fisheye_cube_map->width;
|
|
|
|
vrect_t feye = { 0, 0, side, side };
|
|
|
|
r_funcs->set_viewport (&feye);
|
2022-03-30 05:55:32 +00:00
|
|
|
r_funcs->set_fov (1, 1); //FIXME shouldn't be every frame (2d stuff)
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
switch (scr_fviews) {
|
2022-03-24 06:45:01 +00:00
|
|
|
case 6: render_side (BOX_BEHIND);
|
|
|
|
case 5: render_side (BOX_BOTTOM);
|
|
|
|
case 4: render_side (BOX_TOP);
|
|
|
|
case 3: render_side (BOX_LEFT);
|
|
|
|
case 2: render_side (BOX_RIGHT);
|
|
|
|
default:render_side (BOX_FRONT);
|
|
|
|
}
|
|
|
|
r_funcs->bind_framebuffer (0);
|
2022-03-25 15:29:34 +00:00
|
|
|
r_funcs->set_viewport (&r_refdef.vrect);
|
2022-03-24 06:45:01 +00:00
|
|
|
r_funcs->post_process (fisheye_cube_map);
|
|
|
|
} else {
|
2022-03-26 00:41:58 +00:00
|
|
|
r_funcs->set_viewport (&r_refdef.vrect);
|
2022-03-24 06:45:01 +00:00
|
|
|
render_scene ();
|
2022-03-25 15:29:34 +00:00
|
|
|
if (r_dowarp) {
|
|
|
|
r_funcs->bind_framebuffer (0);
|
|
|
|
r_funcs->post_process (warp_buffer);
|
|
|
|
}
|
2022-03-24 06:45:01 +00:00
|
|
|
}
|
2022-03-15 06:42:43 +00:00
|
|
|
r_funcs->set_2d (0);
|
2022-10-31 15:40:52 +00:00
|
|
|
//view_draw (r_data->scr_view);
|
2022-03-15 06:42:43 +00:00
|
|
|
r_funcs->set_2d (1);
|
2022-03-07 14:32:44 +00:00
|
|
|
while (*scr_funcs) {
|
2022-03-15 06:42:43 +00:00
|
|
|
(*scr_funcs) ();
|
2022-03-07 14:32:44 +00:00
|
|
|
scr_funcs++;
|
|
|
|
}
|
|
|
|
r_funcs->end_frame ();
|
2004-02-08 00:37:11 +00:00
|
|
|
}
|
2002-12-11 17:34:48 +00:00
|
|
|
|
2022-03-18 15:56:30 +00:00
|
|
|
static void
|
|
|
|
update_vrect (void)
|
2013-01-30 12:09:11 +00:00
|
|
|
{
|
2021-03-25 13:01:31 +00:00
|
|
|
r_data->vid->recalc_refdef = 1;
|
2022-03-18 15:56:30 +00:00
|
|
|
|
|
|
|
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);
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
SCR_SetFOV (scr_fov);
|
2022-03-18 15:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 ();
|
2013-01-30 12:09:11 +00:00
|
|
|
}
|
|
|
|
|
2022-03-31 10:07:15 +00:00
|
|
|
typedef struct scr_capture_s {
|
|
|
|
dstring_t *name;
|
|
|
|
QFile *file;
|
|
|
|
} scr_capture_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
scr_write_caputre (tex_t *tex, void *data)
|
|
|
|
{
|
|
|
|
scr_capture_t *cap = data;
|
|
|
|
|
|
|
|
if (tex) {
|
2022-03-31 11:00:13 +00:00
|
|
|
WritePNG (cap->file, tex);
|
2022-03-31 10:07:15 +00:00
|
|
|
free (tex);
|
|
|
|
Sys_Printf ("Wrote %s/%s\n", qfs_userpath, cap->name->str);
|
|
|
|
} else {
|
|
|
|
Sys_Printf ("Capture failed\n");
|
|
|
|
}
|
|
|
|
Qclose (cap->file);
|
|
|
|
dstring_delete (cap->name);
|
|
|
|
free (cap);
|
|
|
|
}
|
|
|
|
|
2012-04-11 13:45:23 +00:00
|
|
|
static void
|
|
|
|
ScreenShot_f (void)
|
|
|
|
{
|
2022-03-07 05:39:47 +00:00
|
|
|
dstring_t *name = dstring_new ();
|
2022-03-31 08:27:04 +00:00
|
|
|
QFile *file;
|
2022-03-07 05:39:47 +00:00
|
|
|
|
|
|
|
// find a file name to save it to
|
2022-03-31 08:27:04 +00:00
|
|
|
if (!(file = QFS_NextFile (name, va (0, "%s/qf", qfs_gamedir->dir.shots),
|
|
|
|
".png"))) {
|
2022-03-31 07:40:27 +00:00
|
|
|
Sys_Printf ("SCR_ScreenShot_f: Couldn't create a PNG file: %s\n",
|
|
|
|
name->str);
|
2022-03-31 10:07:15 +00:00
|
|
|
dstring_delete (name);
|
2022-03-07 05:39:47 +00:00
|
|
|
} else {
|
2022-03-31 10:07:15 +00:00
|
|
|
scr_capture_t *cap = malloc (sizeof (scr_capture_t));
|
|
|
|
cap->file = file;
|
|
|
|
cap->name = name;
|
|
|
|
r_funcs->capture_screen (scr_write_caputre, cap);
|
2022-03-07 05:39:47 +00:00
|
|
|
}
|
2012-04-11 13:45:23 +00:00
|
|
|
}
|
|
|
|
|
2002-12-11 17:34:48 +00:00
|
|
|
/*
|
|
|
|
SCR_SizeUp_f
|
|
|
|
|
|
|
|
Keybinding command
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-12-11 17:34:48 +00:00
|
|
|
SCR_SizeUp_f (void)
|
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (scr_viewsize < 120) {
|
|
|
|
scr_viewsize = scr_viewsize + 10;
|
2021-01-12 07:14:46 +00:00
|
|
|
r_data->vid->recalc_refdef = 1;
|
2002-12-11 17:34:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SCR_SizeDown_f
|
|
|
|
|
|
|
|
Keybinding command
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-12-11 17:34:48 +00:00
|
|
|
SCR_SizeDown_f (void)
|
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
scr_viewsize = scr_viewsize - 10;
|
2021-01-12 07:14:46 +00:00
|
|
|
r_data->vid->recalc_refdef = 1;
|
2002-12-11 17:34:48 +00:00
|
|
|
}
|
|
|
|
|
2022-03-18 15:56:30 +00:00
|
|
|
static void
|
|
|
|
viewsize_listener (void *data, const cvar_t *cvar)
|
|
|
|
{
|
|
|
|
update_vrect ();
|
|
|
|
}
|
|
|
|
|
2022-09-21 16:11:56 +00:00
|
|
|
static void
|
|
|
|
vidsize_listener (void *data, const viddef_t *vdef)
|
|
|
|
{
|
|
|
|
update_vrect ();
|
|
|
|
if (fisheye_cube_map) {
|
|
|
|
r_funcs->destroy_frame_buffer (fisheye_cube_map);
|
|
|
|
fisheye_cube_map = 0;
|
|
|
|
}
|
|
|
|
if (warp_buffer) {
|
|
|
|
r_funcs->destroy_frame_buffer (warp_buffer);
|
|
|
|
warp_buffer = 0;
|
|
|
|
}
|
|
|
|
r_funcs->set_fov (tan_fov_x, tan_fov_y);
|
|
|
|
}
|
|
|
|
|
2002-12-11 17:34:48 +00:00
|
|
|
void
|
|
|
|
SCR_Init (void)
|
|
|
|
{
|
2022-10-31 15:40:52 +00:00
|
|
|
//r_data->scr_view->xlen = r_data->vid->width;
|
|
|
|
//r_data->scr_view->ylen = r_data->vid->height;
|
2022-09-21 08:31:18 +00:00
|
|
|
|
2002-12-11 17:34:48 +00:00
|
|
|
// register our commands
|
2012-04-11 13:45:23 +00:00
|
|
|
Cmd_AddCommand ("screenshot", ScreenShot_f, "Take a screenshot, "
|
2022-03-07 05:39:47 +00:00
|
|
|
"saves as qfxxxx.png in the QF directory");
|
2002-12-11 17:34:48 +00:00
|
|
|
Cmd_AddCommand ("sizeup", SCR_SizeUp_f, "Increases the screen size");
|
|
|
|
Cmd_AddCommand ("sizedown", SCR_SizeDown_f, "Decreases the screen size");
|
|
|
|
|
|
|
|
scr_initialized = true;
|
2022-03-17 08:50:38 +00:00
|
|
|
|
|
|
|
r_ent_queue = EntQueue_New (mod_num_types);
|
2022-03-18 15:56:30 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
cvar_t *var = Cvar_FindVar ("viewsize");
|
|
|
|
Cvar_AddListener (var, viewsize_listener, 0);
|
2022-09-21 16:11:56 +00:00
|
|
|
VID_OnVidResize_AddListener (vidsize_listener, 0);
|
2022-03-18 15:56:30 +00:00
|
|
|
update_vrect ();
|
2002-12-11 17:34:48 +00:00
|
|
|
}
|
2022-05-05 05:41:46 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SCR_NewScene (scene_t *scene)
|
|
|
|
{
|
2022-11-17 12:57:53 +00:00
|
|
|
if (scr_scene) {
|
|
|
|
ECS_RemoveEntities (scr_scene->reg, scene_visibility);
|
2022-11-17 13:10:04 +00:00
|
|
|
R_ClearEfrags ();
|
2022-11-17 12:57:53 +00:00
|
|
|
}
|
2022-05-05 05:41:46 +00:00
|
|
|
scr_scene = scene;
|
|
|
|
if (scene) {
|
2022-05-22 02:18:32 +00:00
|
|
|
mod_brush_t *brush = &scr_scene->worldmodel->brush;
|
2022-05-22 07:31:24 +00:00
|
|
|
int count = brush->numnodes + brush->modleafs
|
|
|
|
+ brush->numsurfaces;
|
|
|
|
int size = count * sizeof (int);
|
2022-05-22 02:18:32 +00:00
|
|
|
r_node_visframes = Hunk_AllocName (0, size, "visframes");
|
2022-05-22 05:43:07 +00:00
|
|
|
r_leaf_visframes = r_node_visframes + brush->numnodes;
|
2022-05-22 07:31:24 +00:00
|
|
|
r_face_visframes = r_leaf_visframes + brush->modleafs;
|
2022-05-05 05:41:46 +00:00
|
|
|
r_funcs->set_fov (tan_fov_x, tan_fov_y);
|
|
|
|
r_funcs->R_NewScene (scene);
|
|
|
|
} else {
|
|
|
|
r_funcs->R_ClearState ();
|
|
|
|
}
|
|
|
|
}
|