Tutorial *108*
Author		Tomas "Tomaz" Jakobsson

E-mail		[email protected]

Page		www.quakemods.net/tomaz

Oki... this little tutorial will show one of many ways to get the engine to read values from the qc code. I will show how to get alpha and scale for models. And alos how to make qc controled dynamic lights. The color part is only if u have colored dynamics lights. There are tutorials on how to get that to. First of we hawe to make the engine to be able to handle more then it currently can. Thanks LordHavoc for the code.
In CL_ParseUpdate in cl_parse.c
after


if (bits & U_MOREBITS)

{

	i = MSG_ReadByte ();

	bits |= (i<<8);

}

add


// Tomaz - QC Control Begin

if (bits & U_EXTEND1)

{

	bits |= MSG_ReadByte() << 16;

}

// Tomaz - QC Control End

In SV_WriteEntitiesToClient in sv_main.c
after


if (bits >= 256)

	bits |= U_MOREBITS;

add


// Tomaz - QC Control Begin

if (bits >= 65536)

	bits |= U_EXTEND1;

// Tomaz - QC Control End

and after


if (bits & U_MOREBITS)

	MSG_WriteByte (msg, bits>>8);

add


// Tomaz - QC Control Begin

if (bits & U_EXTEND1)

	MSG_WriteByte (msg, bits>>16);

// Tomaz - QC Control End

Thats it with the Control
Now we move on to get the other cool stuff.

In CL_RelinkEntities in cl_main.c
after


else if (ent->model->flags & EF_TRACER3)

	R_VoorTrail (oldorg, ent->origin);

add


// Tomaz - QC Glow Begin

else if (ent->glow_size)

{

	dl = CL_AllocDlight (i);

	VectorCopy (ent->origin, dl->origin);

	dl->radius = ent->glow_size;

	dl->die = cl.time + 0.001;

	dl->color[0] = ent->glow_red;

	dl->color[1] = ent->glow_green;

	dl->color[2] = ent->glow_blue;

}

// Tomaz - QC Glow End

This is the code that makes the dynamic light after it read the values from the QC. And if u dont have color then just remove those last 3 lines.

In CL_ParseUpdate in cl_parse.c
after


if (bits & U_ANGLE3)

	ent->msg_angles[0][2] = MSG_ReadAngle();

else

	ent->msg_angles[0][2] = ent->baseline.angles[2];

add


// Tomaz - QC Alpha Scale Glow Begin

if (bits & U_ALPHA)

	ent->alpha = MSG_ReadFloat();

else

	ent->alpha = 1.0;



if (bits & U_SCALE)

	ent->scale = MSG_ReadFloat();

else

	ent->scale = 1.0;



if (bits & U_GLOW_SIZE)

	ent->glow_size = MSG_ReadFloat();

else

	ent->glow_size = 0;



if (bits & U_GLOW_RED)

	ent->glow_red = MSG_ReadFloat();

else

	ent->glow_red = 0;



if (bits & U_GLOW_GREEN)

	ent->glow_green = MSG_ReadFloat();

else

	ent->glow_green = 0;



if (bits & U_GLOW_BLUE)

	ent->glow_blue = MSG_ReadFloat();

else

	ent->glow_blue = 0;

// Tomaz - QC Alpha Scale Glow End

This code gives the different models the values of the different alpha, scale and glow we set it to use.

In R_RotateForEntity in gl_rmain.c

at the bottom
add


glScalef  (e->scale, e->scale, e->scale);	// Tomaz - QC Scale

and the same thing in R_BlendedRotateForEntity if you have QER Interpolation.

This makes the models the size we set it to.
In GL_DrawALiasFrame in glrmain.c
change the


glColor3f

to


glColor4f

and at the end of it
add


, currententity->alpha

This makes the model to use the alpha we set it to.
same thing in GL_DrawAliasBlendedFrame if you have QER Interpolation
In R_DrawEntitiesFromList in gl_rmain.c before the switch loop
add


// Tomaz - QC Alpha Scale Begin

if ((!strncmp (currententity->model->name, "progs/bolt", 10)) ||

	(!strncmp (currententity->model->name, "progs/flame", 11)))

{

	currententity->alpha = 1;

	currententity->scale = 1;

}

// Tomaz - QC Alpha Scale End

This fixes a bug that makes the lightning bolt and all the wall torches to go invisible.

In R_DrawViewModel in gl_rmain.c <
after


currententity = &cl.viewent;

if (!currententity->model)

	return;

add


// Tomaz - QC Alpha Scale Begin

currententity->alpha = cl_entities[cl.viewentity].alpha;

currententity->scale = cl_entities[cl.viewentity].scale;

// Tomaz - QC Alpha Scale End

This fixes another bug that makes the weapons go invisible.

Now goto R_DrawAliasModel in gl_rmain.c
at top after all the variables
add


// Tomaz - QC Alpha Begin

glDisable(GL_ALPHA_TEST);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glEnable(GL_BLEND);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

// Tomaz - QC Alpha End

then at the bottom of the function
add


// Tomaz - QC Alpha Begin

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glDisable(GL_BLEND);

glDisable(GL_ALPHA_TEST);

// Tomaz - QC Alpha End

In protocol.h
after


#define	U_LONGENTITY	(1<<14)

add


// Tomaz - QC Alpha Scale Glow Control Begin

#define	U_EXTEND1	(1<<15)

#define	U_SCALE		(1<<16)

#define	U_ALPHA		(1<<17)

#define	U_GLOW_SIZE	(1<<18)

#define	U_GLOW_RED	(1<<19)

#define	U_GLOW_GREEN	(1<<20)

#define	U_GLOW_BLUE	(1<<21)

// Tomaz - QC Alpha Scale Glow Control End

In typedef struct entity_s in render.h
at bottom
add


// Tomaz - QC Alpha Scale Glow Begin

float		alpha;

float		scale;

float		glow_size;

float		glow_red;

float		glow_green;

float		glow_blue;

// Tomaz - QC Alpha Scale Glow End

In SV_WriteEntitiesToClient
at top with all the other variables
add


// Tomaz - QC Alpha Scale Glow Begin

float	alpha;

float	scale;

float	glow_size;

float	glow_red;

float	glow_green;

float	glow_blue;

// Tomaz - QC Alpha Scale Glow End

after


		if (ent->baseline.modelindex != ent->v.modelindex)

			bits |= U_MODEL;

add


// Tomaz - QC Alpha Scale Glow Begin

{

	eval_t  *val;



	alpha=1;

	scale=1;



	if (val = GetEdictFieldValue(ent, "alpha"))

	{

		alpha = val->_float;

	}

	else

		alpha = 1;



	if (val = GetEdictFieldValue(ent, "scale"))

	{

		scale = val->_float;

	}

	else

		scale = 1;



	if (scale > 4)

		glow_size = 4;



	if (val = GetEdictFieldValue(ent, "glow_size"))

	{

		glow_size = val->_float;

	}

	else

		glow_size = 0;



	if (glow_size > 250)

		glow_size = 250;



	if (val = GetEdictFieldValue(ent, "glow_red"))

	{

		glow_red = val->_float;

	}

	else

		glow_red = 0;



	if (val = GetEdictFieldValue(ent, "glow_green"))

	{

		glow_green = val->_float;

	}

	else

		glow_green = 0;



	if (val = GetEdictFieldValue(ent, "glow_blue"))

	{

		glow_blue = val->_float;

	}

	else

		glow_blue = 0;



	if ((alpha <= 1) && (alpha > 0))

		bits |= U_ALPHA;



	if ((scale <= 4) && (scale > 0))

		bits |= U_SCALE;



	if (glow_size >= 0)

	{

		bits |= U_GLOW_SIZE;

		bits |= U_GLOW_RED;

		bits |= U_GLOW_GREEN;

		bits |= U_GLOW_BLUE;

	}

}

// Tomaz - QC Alpha Scale Glow End

This code is the one that actually does the reading from the Qc code.
after


if (bits & U_ANGLE3)

	MSG_WriteAngle(msg, ent->v.angles[2]);

add


// Tomaz - QC Alpha Scale Glow Begin

if (bits & U_ALPHA)

	MSG_WriteFloat(msg, alpha);



if (bits & U_SCALE)

	MSG_WriteFloat(msg, scale);



if (bits & U_GLOW_SIZE)

	MSG_WriteFloat(msg, glow_size);



if (bits & U_GLOW_RED)

	MSG_WriteFloat(msg, glow_red);



if (bits & U_GLOW_GREEN)

	MSG_WriteFloat(msg, glow_green);



if (bits & U_GLOW_BLUE)

	MSG_WriteFloat(msg, glow_blue);

// Tomaz - QC Alpha Scale Glow End

And this last piece of code gives the values we got to the other code we did in CL_ParseUpdate.
All code is also done so that if it cant find any value it sets the alpha ans scale to 1, and sets the glow_size to 0 so it wont make any light if we dont want it to.

Next thing is the code we need in the Qc.
In defs.qc at the bottm
add


.float	alpha;

.float	scale;

.float	glow_size;

.float	glow_red;

.float	glow_green;

.float	glow_blue;

now all u have to do is to give models the values.
like


self.alpha = 0.5;

self.scale = 2;

self.glow_size = 200;

self.red = 1;

self.blue = 1;

would make the model to be 50% transparent, double the size and have a big nice purple glow.
all values is from 0-1. Except the scale that goes from 0-4.. i dont think anyone want a model that is more then 4 times as big as it used to.
If anything is unclear then just let me know and im sure we can sort it out.


 
Not logged in
Sign up
Login:
Passwd: