Add extension: DP_SV_MODELFLAGS_AS_EFFECTS

Post tutorials on how to do certain tasks within game or engine code here.
Post Reply
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Add extension: DP_SV_MODELFLAGS_AS_EFFECTS

Post by qbism »

About- The DP_SV_MODELFLAGS_AS_EFFECTS extension provides a way to override model flags within qc. Model flags are baked-in the mdl, and vanilla Quake does not expose the flags to qc. For more info, search DP source code for "modelflags"

Disclaimer- The cut-and-paste code shown here may need to be adapted to your particular engine, which will already be heavily modded. This tutorial only applies to engines that already have the extensions system built-in, AND a network protocol that can write extended effects up to 32 bits.

Background- Pick-up item models are compiled with a flag set called EF_ROTATE to automatically make them spin around slowly. But vanilla Quake does not provide a way to bestow this rotation on any arbitrary entity from qc. An example would be a vwep model that doubles as a pick-up model. This was my original need, but the idea can be expanded to all model flags with DP_SV_MODELFLAGS_AS_EFFECTS.

Let's get messy- First back up your code!

Crack open the header file where entity effects are defined, typically server.h, and add:

Code: Select all

#define EF_NOMODELFLAGS			8388608		// indicates the model's .effects should be ignored (allows overriding them)
#define EF_ROCKET				16777216	// leave a trail
#define EF_GRENADE				33554432	// leave a trail
#define EF_GIB					67108864	// leave a trail
#define EF_ROTATE				134217728	// rotate (bonus items)
#define EF_TRACER				268435456	// green split trail
#define EF_ZOMGIB				536870912	// small blood trail
#define EF_TRACER2				1073741824	// orange split trail + rotate
#define EF_TRACER3				0x80000000	// purple trail
Rename defines starting with EF_ in model.h to MF_

Code: Select all

 #define	MF_ROCKET	1			// leave a trail
#define	MF_GRENADE	2			// leave a trail
#define	MF_GIB		4			// leave a trail
#define	MF_ROTATE	8			// rotate (bonus items)
#define	MF_TRACER	16			// green split trail
#define	MF_ZOMGIB	32			// small blood trail
#define	MF_TRACER2	64			// orange split trail + rotate
#define	MF_TRACER3	128			// purple trail
In render.h in typedef stuct entity_s add

Code: Select all

int						modelflags;
In model.c change

Code: Select all

mod->flags = LittleLong (pinmodel->flags);
to this

Code: Select all

	i = LittleLong (pinmodel->flags);
	mod->flags = ((i & 255) << 24) | (i & 0x00FFFF00);
Just before the section of cl_main.c that processes model flag effects like EF_ROTATE add

Code: Select all

		if (!(ent->effects & 0xFF800000))  //qbism based on DP model flags
			ent->effects |= ent->model->flags;
and replace occurrences of ent->model->flags with ent->effects.
This conditional is using model flag overrides if they exist in ent->effects. Otherwise it uses the flags as read from the mdl.

Open sv_main.c and be careful where you stick the following, engines vary greatly here. Also maybe this could be written more concisely. Just prior to comparison of entity effects to baseline add

Code: Select all

		if ((val = GetEdictFieldValue(ent, "modelflags")))
		{
			i= (unsigned int)ent->v.effects;
			i |= ((unsigned int)val->_float & 0xff) << 24;
			ent->v.effects = i;
		}
Head to pr_cmds.c, add this extension to the list:

Code: Select all

char *pr_extensions[] =
{
// add the extension names here, syntax: "extensionname",
	"DP_SV_MODELFLAGS_AS_EFFECTS  ",
That's the gist of it, engine side.

qc source changes- In defs.qc in field definitions, add

Code: Select all

.float 		modelflags;
Scroll further down to built-in functions and add

Code: Select all

float(string ext) dp_checkextension = #99;
It may already be somwhere as frik_checkextension.

Tack this to the effect definitions in defs.qc

Code: Select all

float EF_NOMODELFLAGS = 8388608; // ignore any effects in a model file and substitute your own
float MF_ROCKET  =   1; // leave a trail
float MF_GRENADE =   2; // leave a trail
float MF_GIB     =   4; // leave a trail
float MF_ROTATE  =   8; // rotate (bonus items)
float MF_TRACER  =  16; // green split trail
float MF_ZOMGIB  =  32; // small blood trail
float MF_TRACER2 =  64; // orange split trail
float MF_TRACER3 = 128; // purple trail
Example to set a flag-

Code: Select all

self.modelflags = MF_ROTATE;
Last edited by qbism on Sun Sep 12, 2010 6:21 pm, edited 12 times in total.
Sajt
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Post by Sajt »

What you were looking for is probably DP_SV_MODELFLAGS_AS_EFFECTS. It adds a field, .modelflags, which uses the same flag values as mdl flags. There is only one .effects flag added, EF_NOMODELFLAGS, which cancels the original .mdl flags.
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Post by qbism »

That would be a more flexible way to go, and I'm going to try it. Does any other engine but DP have it?

Searching DP for "modelflags" brings out the starting points.
Post Reply