mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-12-13 22:21:17 +00:00
12c84046f3
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.
140 lines
3.4 KiB
C
140 lines
3.4 KiB
C
/*
|
|
gl_warp.c
|
|
|
|
water polygons
|
|
|
|
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
|
|
|
|
#include "QF/cvar.h"
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/GL/defines.h"
|
|
#include "QF/GL/funcs.h"
|
|
#include "QF/GL/qf_rsurf.h"
|
|
|
|
#include "r_internal.h"
|
|
#include "vid_gl.h"
|
|
|
|
// speed up sin calculations - Ed
|
|
static float turbsin[] = {
|
|
# include "gl_warp_sin.h"
|
|
};
|
|
|
|
#define TURBSCALE (256.0 / (2 * M_PI))
|
|
#define TURBFRAC (32.0 / (2 * M_PI)) // an 8th of TURBSCALE
|
|
|
|
/*
|
|
GL_EmitWaterPolys
|
|
|
|
Does a water warp on the pre-fragmented glpoly_t chain
|
|
*/
|
|
void
|
|
GL_EmitWaterPolys (msurface_t *surf)
|
|
{
|
|
float os, ot, s, t, timetemp;
|
|
float *v;
|
|
int i;
|
|
glpoly_t *p;
|
|
|
|
timetemp = vr_data.realtime * TURBSCALE;
|
|
|
|
for (p = surf->polys; p; p = p->next) {
|
|
qfglBegin (GL_POLYGON);
|
|
for (i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE) {
|
|
os = turbsin[(int) (v[3] * TURBFRAC + timetemp) & 255];
|
|
ot = turbsin[(int) (v[4] * TURBFRAC + timetemp) & 255];
|
|
s = (v[3] + ot) * (1.0 / 64.0);
|
|
t = (v[4] + os) * (1.0 / 64.0);
|
|
qfglTexCoord2f (s, t);
|
|
|
|
if (r_waterripple != 0) {
|
|
vec3_t nv;
|
|
|
|
VectorCopy (v, nv);
|
|
nv[2] += r_waterripple * os * ot * (1.0 / 64.0);
|
|
qfglVertex3fv (nv);
|
|
} else
|
|
qfglVertex3fv (v);
|
|
}
|
|
qfglEnd ();
|
|
}
|
|
}
|
|
|
|
const float S = 0.15625;
|
|
const float F = 2.5;
|
|
const float A = 0.01;
|
|
|
|
static void
|
|
warp_uv (float *uv, float time)
|
|
{
|
|
float p1 = (time * S + F * uv[1]) * 2 * M_PI;
|
|
float p2 = (time * S + F * uv[0]) * 2 * M_PI;
|
|
uv[0] = uv[0] * (1 - 2 * A) + A * (1 + sin (p1));
|
|
uv[1] = uv[1] * (1 - 2 * A) + A * (1 + sin (p2));
|
|
}
|
|
|
|
void
|
|
gl_WarpScreen (framebuffer_t *fb)
|
|
{
|
|
gl_framebuffer_t *buffer = fb->buffer;
|
|
|
|
qfglMatrixMode (GL_PROJECTION);
|
|
qfglLoadIdentity ();
|
|
qfglOrtho (0, r_refdef.vrect.width, r_refdef.vrect.height, 0, -9999, 9999);
|
|
qfglMatrixMode (GL_MODELVIEW);
|
|
qfglLoadIdentity ();
|
|
qfglColor3ubv (color_white);
|
|
|
|
qfglDisable (GL_DEPTH_TEST);
|
|
qfglFrontFace (GL_CCW);
|
|
|
|
qfglBindTexture (GL_TEXTURE_2D, buffer->color);
|
|
|
|
int base_x = r_refdef.vrect.x;
|
|
int base_y = r_refdef.vrect.y;
|
|
int width = r_refdef.vrect.width;
|
|
int height = r_refdef.vrect.height;
|
|
|
|
float time = vr_data.realtime;
|
|
|
|
for (int y = 0; y < height; y += 40) {
|
|
qfglBegin (GL_QUAD_STRIP);
|
|
for (int x = 0; x <= width; x+= 40) {
|
|
int y2 = y + 40;
|
|
int xy1[] = { base_x + x, base_y + y };
|
|
int xy2[] = { base_x + x, base_y + y2};
|
|
float uv1[] = { (float) x / width, 1 - (float) y / height };
|
|
float uv2[] = { (float) x / width, 1 - (float) y2 / height };
|
|
warp_uv (uv1, time);
|
|
warp_uv (uv2, time);
|
|
qfglTexCoord2fv (uv2);
|
|
qfglVertex2iv (xy2);
|
|
qfglTexCoord2fv (uv1);
|
|
qfglVertex2iv (xy1);
|
|
}
|
|
qfglEnd ();
|
|
}
|
|
}
|