1
0
Fork 0
forked from fte/fteqw

change crosshairimage/crosshair/crosshaircolor to use callbacks

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2206 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
TimeServ 2006-04-14 04:31:29 +00:00
parent ad0c14548a
commit 363223186e
7 changed files with 117 additions and 78 deletions

View file

@ -74,13 +74,13 @@ cvar_t v_ipitch_level = SCVAR("v_ipitch_level", "0.3");
cvar_t v_idlescale = SCVAR("v_idlescale", "0");
cvar_t crosshair = SCVARF("crosshair", "0", CVAR_ARCHIVE);
cvar_t crosshaircolor = SCVARF("crosshaircolor", "79", CVAR_ARCHIVE);
cvar_t crosshaircolor = SCVARF("crosshaircolor", "79", CVAR_ARCHIVE | CVAR_RENDERERCALLBACK);
cvar_t crosshairsize = SCVARF("crosshairsize", "8", CVAR_ARCHIVE);
cvar_t cl_crossx = SCVARF("cl_crossx", "0", CVAR_ARCHIVE);
cvar_t cl_crossy = SCVARF("cl_crossy", "0", CVAR_ARCHIVE);
cvar_t crosshaircorrect = SCVARF("crosshaircorrect", "0", CVAR_SEMICHEAT);
cvar_t crosshairimage = SCVAR("crosshairimage", "");
cvar_t crosshairimage = SCVARF("crosshairimage", "", CVAR_RENDERERCALLBACK);
cvar_t crosshairalpha = SCVAR("crosshairalpha", "1");
cvar_t gl_cshiftpercent = SCVAR("gl_cshiftpercent", "100");

View file

@ -763,22 +763,6 @@ void Cvar_ForceCheatVars(qboolean semicheats, qboolean absolutecheats)
}
}
void Cvar_ApplyCallbacks(int callbackflag)
{
cvar_group_t *grp;
cvar_t *var;
for (grp=cvar_groups ; grp ; grp=grp->next)
for (var=grp->cvars ; var ; var=var->next)
{
if (var->flags & callbackflag)
{
if (var->callback)
var->callback(var, var->string);
}
}
}
void Cvar_ApplyLatches(int latchflag)
{
cvar_group_t *grp;
@ -1127,6 +1111,32 @@ void Cvar_WriteVariables (vfsfile_t *f, qboolean all)
}
}
void Cvar_Hook(cvar_t *cvar, void (*callback) (struct cvar_s *var, char *oldvalue))
{
cvar->callback = callback;
}
void Cvar_Unhook(cvar_t *cvar)
{
cvar->callback = NULL;
}
void Cvar_ApplyCallbacks(int callbackflag)
{
cvar_group_t *grp;
cvar_t *var;
for (grp=cvar_groups ; grp ; grp=grp->next)
for (var=grp->cvars ; var ; var=var->next)
{
if (var->flags & callbackflag)
{
if (var->callback)
var->callback(var, var->string);
}
}
}
void Cvar_Shutdown(void)
{
cvar_t *var;

View file

@ -131,6 +131,12 @@ void Cvar_SetValue (cvar_t *var, float value);
void Cvar_ApplyLatches(int latchflag);
//sets vars to thier latched values
void Cvar_Hook(cvar_t *cvar, void (*callback) (struct cvar_s *var, char *oldvalue));
//hook a cvar with a given callback function at runtime
void Cvar_Unhook(cvar_t *cvar);
//unhook a cvar
void Cvar_ApplyCallbacks(int callbackflag);
//forces callbacks to be ran for given flags

View file

@ -90,6 +90,7 @@ float custom_char_instep, default_char_instep; //to avoid blending issues
float char_instep;
static unsigned cs_data[16*16];
static int externalhair;
typedef struct
{
@ -1347,20 +1348,66 @@ void GLDraw_Alt_String (int x, int y, const qbyte *str)
vec3_t chcolor;
int chmodified;
void GLCrosshairimage_Callback(struct cvar_s *var, char *oldvalue)
{
if (*(var->string))
externalhair = Mod_LoadHiResTexture (var->string, "crosshairs", false, true, true);
}
void GLCrosshair_Callback(struct cvar_s *var, char *oldvalue)
{
unsigned int c, c2;
if (!var->value)
return;
c = (unsigned int)(chcolor[0] * 255) | // red
((unsigned int)(chcolor[1] * 255) << 8) | // green
((unsigned int)(chcolor[2] * 255) << 16) | // blue
0xff000000; // alpha
c2 = c;
#define Pix(x,y,c) { \
if (y+8<0)c=0; \
if (y+8>=16)c=0; \
if (x+8<0)c=0; \
if (x+8>=16)c=0; \
\
cs_data[(y+8)*16+(x+8)] = c; \
}
memset(cs_data, 0, sizeof(cs_data));
switch((int)var->value)
{
default:
#include "crosshairs.dat"
}
#undef Pix
GL_Bind (cs_texture);
GL_Upload32(NULL, cs_data, 16, 16, 0, true);
}
void GLCrosshaircolor_Callback(struct cvar_s *var, char *oldvalue)
{
SCR_StringToRGB(var->string, chcolor, 255);
chcolor[0] = bound(0, chcolor[0], 1);
chcolor[1] = bound(0, chcolor[1], 1);
chcolor[2] = bound(0, chcolor[2], 1);
GLCrosshair_Callback(&crosshair, "");
}
void GLDraw_Crosshair(void)
{
int x, y;
int sc;
static int externalhair;
float x1, x2, y1, y2;
float size, chc;
int c2, c, usecolor;
int chrebuild;
usecolor = 0;
c2 = c = 0; // shut up msvc
int usecolor = 0;
if (crosshair.value == 1 && !*crosshairimage.string)
{
@ -1373,36 +1420,9 @@ void GLDraw_Crosshair(void)
}
GL_TexEnv(GL_MODULATE);
chrebuild = chmodified != crosshaircolor.modified ||
crosshair.modified ||
(*crosshairimage.string && crosshairimage.modified) ||
crosshair.value >= FIRSTANIMATEDCROSHAIR;
if (chrebuild)
{
SCR_StringToRGB(crosshaircolor.string, chcolor, 255);
chcolor[0] = bound(0, chcolor[0], 1);
chcolor[1] = bound(0, chcolor[1], 1);
chcolor[2] = bound(0, chcolor[2], 1);
c = (int)(chcolor[0] * 255) | // red
((int)(chcolor[1] * 255) << 8) | // green
((int)(chcolor[2] * 255) << 16) | // blue
0xff000000; // alpha
c2 = c;
chmodified = crosshaircolor.modified;
}
if (*crosshairimage.string)
{
usecolor = 1;
if (crosshairimage.modified)
{
crosshairimage.modified = false;
externalhair = Mod_LoadHiResTexture (crosshairimage.string, "crosshairs", false, true, true);
}
GL_Bind (externalhair);
chc = 0;
@ -1414,28 +1434,10 @@ void GLDraw_Crosshair(void)
GL_Bind (cs_texture);
chc = 1/16.0;
if (chrebuild)
{
crosshair.modified = false;
// force crosshair refresh with animated crosshairs
if (crosshair.value >= FIRSTANIMATEDCROSHAIR)
GLCrosshair_Callback(&crosshair, "");
#define Pix(x,y,c) { \
if (y+8<0)c=0; \
if (y+8>=16)c=0; \
if (x+8<0)c=0; \
if (x+8>=16)c=0; \
\
cs_data[(y+8)*16+(x+8)] = c; \
}
memset(cs_data, 0, sizeof(cs_data));
switch((int)crosshair.value)
{
default:
#include "crosshairs.dat"
}
GL_Upload32(NULL, cs_data, 16, 16, 0, true);
#undef Pix
}
if (crosshairsize.value <= 16)
{
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

View file

@ -657,6 +657,12 @@ void GLR_TimeRefresh_f (void);
extern cvar_t gl_bump;
extern cvar_t r_stains, r_stainfadetime, r_stainfadeammount;
// callback defines
extern cvar_t crosshair, crosshairimage, crosshaircolor;
void GLCrosshairimage_Callback(struct cvar_s *var, char *oldvalue);
void GLCrosshair_Callback(struct cvar_s *var, char *oldvalue);
void GLCrosshaircolor_Callback(struct cvar_s *var, char *oldvalue);
void GLR_DeInit (void)
{
Cmd_RemoveCommand ("timerefresh");
@ -665,6 +671,10 @@ void GLR_DeInit (void)
Cmd_RemoveCommand ("makewad");
Cvar_Unhook(&crosshair);
Cvar_Unhook(&crosshairimage);
Cvar_Unhook(&crosshaircolor);
GLDraw_DeInit();
GLSurf_DeInit();
@ -677,6 +687,10 @@ void GLR_Init (void)
// Cmd_AddRemCommand ("makewad", R_MakeTexWad_f);
Cvar_Hook(&crosshair, GLCrosshair_Callback);
Cvar_Hook(&crosshairimage, GLCrosshairimage_Callback);
Cvar_Hook(&crosshaircolor, GLCrosshaircolor_Callback);
R_InitBubble();
GLR_ReInit();

View file

@ -203,11 +203,17 @@ void SWR_InitTextures (void)
}
}*/
// callback declares
extern cvar_t crosshaircolor;
void SWCrosshaircolor_Callback(struct cvar_s *var, char *oldvalue);
void SWR_DeInit (void)
{
Cmd_RemoveCommand ("timerefresh");
Cmd_RemoveCommand ("pointfile");
Cvar_Unhook(&crosshaircolor);
SWDraw_Shutdown();
D_Shutdown();
}
@ -228,6 +234,8 @@ void SWR_Init (void)
Cmd_AddRemCommand ("timerefresh", SWR_TimeRefresh_f);
Cvar_Hook(&crosshaircolor, SWCrosshaircolor_Callback);
if (!r_maxedges.value)
Cvar_SetValue (&r_maxedges, (float)NUMSTACKEDGES);
if (!r_maxsurfs.value)

View file

@ -909,6 +909,11 @@ void SWDraw_Pixel(int x, int y, qbyte color)
}
}
void SWCrosshaircolor_Callback(struct cvar_s *var, char *oldvalue)
{
sw_crosshaircolor = SCR_StringToPalIndex(var->string, 255);
}
#include "crosshairs.dat"
qbyte *COM_LoadFile (char *path, int usehunk);
void SWDraw_Crosshair(void)
@ -919,12 +924,6 @@ void SWDraw_Crosshair(void)
qbyte c, c2;
int sc;
if (crosshaircolor.modified)
{ // redo color every modification to crosshaircolor
sw_crosshaircolor = SCR_StringToPalIndex(crosshaircolor.string, 255);
crosshaircolor.modified = false;
}
c2 = c = sw_crosshaircolor;
for (sc = 0; sc < cl.splitclients; sc++)