[Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post tutorials on how to do certain tasks within game or engine code here.
Post Reply
Team Xlink
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

[Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by Team Xlink »

DP_SV_NODRAWTOCLIENT and DP_SV_DRAWONLYTOCLIENT are very useful, they have a wide array of possibilities, and implementing them is very easy.


[Tutorial]

Step 1.

Open up progs.h and add this under the edict_t/s struct.

Code: Select all

extern int eval_drawonlytoclient; //DP_SV_DRAWONLYTOCLIENT
extern int eval_nodrawtoclient; //DP_SV_NODRAWTOCLIENT
#define GETEDICTFIELDVALUE(ed, fieldoffset) (fieldoffset ? (eval_t*)((char*)&ed->v + fieldoffset) : NULL) //DP_SV_DRAWONLYTOCLIENT & DP_SV_NODRAWTOCLIENT
Step 2.

Open up pr_edict.c, after ED_FindFeild add this:

Code: Select all

int eval_nodrawtoclient; //DP_SV_NODRAWTOCLIENT
int eval_drawonlytoclient; //DP_SV_DRAWONLYTOCLIENT

//DP_SV_DRAWONLYTOCLIENT & DP_SV_NODRAWTOCLIENT Start
int FindFieldOffset(char *field)
{
	ddef_t *d;
	d = ED_FindField(field);
	if (!d)
		return 0;
	return d->ofs*4;
}

void FindEdictFieldOffsets()
{
	eval_nodrawtoclient		= FindFieldOffset("nodrawtoclient");
	eval_drawonlytoclient	= FindFieldOffset("drawonlytoclient");
};

//DP_SV_DRAWONLYTOCLIENT & DP_SV_NODRAWTOCLIENT End
Step 3.

Open up quakedef.h and at the end of the entity_state_t struct add this:

Code: Select all

	unsigned short nodrawtoclient; //DP_SV_NODRAWTOCLIENT
	unsigned short drawonlytoclient; //DP_SV_DRAWONLYTOCLIENT
Step 4.

Open up sv_main.c, add this at the end of the starting declarations in SV_WriteEntitiesToClient.

Code: Select all

	int clentnum; //DP_SV_DRAWONLYTOCLIENT & DP_SV_NODRAWTOCLIENT
	eval_t *val; //DP_SV_DRAWONLYTOCLIENT & DP_SV_NODRAWTOCLIENT
Step 5.

In SV_WriteEntitiesToClient after this:

Code: Select all

// find the client's PVS
	VectorAdd (clent->v.origin, clent->v.view_ofs, org);
	pvs = SV_FatPVS (org);
Add this:

Code: Select all

	clentnum = EDICT_TO_PROG(clent); // LordHavoc: for comparison purposes //DP_SV_DRAWONLYTOCLIENT & DP_SV_NODRAWTOCLIENT
Step 6.

In the same function after:

Code: Select all

// ignore ents without visible models
			if (!ent->v.modelindex || !pr_strings[ent->v.model])
				continue;
Add this:

Code: Select all

			//DP_SV_DRAWONLYTOCLIENT & DP_SV_NODRAWTOCLIENT Start
			if ((val = GETEDICTFIELDVALUE(ent, eval_drawonlytoclient)) && val->edict && val->edict != clentnum)
				continue;
				
			if ((val = GETEDICTFIELDVALUE(ent, eval_nodrawtoclient)) && val->edict == clentnum)
				continue;
			//DP_SV_DRAWONLYTOCLIENT & DP_SV_NODRAWTOCLIENT End
That should be all thats required.

**NOTICE**
This tutorial doesn't cover DPCHECKEXTENSIONS, I needed just these to DP_Extensions in my engine and didn't require the ability to check them, considering my engine is just for my own education ,experimentation and creation. It should be pretty straightforward on implementing it.

EDIT August 12th, 2010
I fixed some typos and formatting errors.

EDIT: September 20th, 2013
*Removed shameful self plugs
Last edited by Team Xlink on Sat Sep 21, 2013 1:19 am, edited 1 time in total.
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Post by qbism »

Tutorial worked well, used it to see OrionTF vwep support correctly.

If the engine already has dpextensions, just go to char *pr_extensions[] in pr_cmds.c and add "DP_SV_NODRAWTOCLIENT" and "DP_SV_DRAWONLYTOCLIENT"
Team Xlink
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

Post by Team Xlink »

Yeah it worked!

The lack of other confirmation had me worried that I missed something in the tutorial, because I attempted to implement it in an engine that wasn't standard and it worked, so I tutorialized it from the engine I implemented it in.
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: [Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by drm_wayne »

Sorry for bumping this but it seems not to work with Kurok engine...
I added everything and it compiled fine but i can still see all the stuff -.-

In Darkplaces everything works fine but not with your stuff...
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: [Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by Spike »

its the last part that contains the 'magic'.
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: [Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by drm_wayne »

Wrong, i even tested a Kurokbuild where HE added that stuff and Drawonlytoclient DOESNT work...
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: [Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by Spike »

Not wrong at all. step 6 IS the part that contains the logic that is the whole point of the two extensions.
If you actually stop to figure out what's actually happening, you might manage to see what's not happening.

Yes, it lacks a single instruction, literally. Yay for branches.
Without that instruction, its all dead code.
Have fun trying to find it.
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: [Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by drm_wayne »

i dont get it...

everybody wrote above YAY IT WORKED but its not working...
But well, i dont expect getting help here, PSP Quakers are not really welcome here...
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: [Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by drm_wayne »

To get this to work add this in pr_edict.c at the end of the
PR_LoadProgs function:

Code: Select all

FindEdictFieldOffsets (); // The stuff Team Xlink forget to add... Shame on you xD
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: [Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by qbism »

I didn't run into that, never knew why until now. This tutorial must be for a non-vanilla GetEdictFieldValue? Vanilla passes string, like GetEdictFieldValue(ent, "drawonlytoclient")) and the workaround isn't needed. Vanilla:

Code: Select all

eval_t *GetEdictFieldValue(edict_t *ed, char *field)
{
    ddef_t			*def = NULL;
    int				i;
    static int		rep = 0;

    for (i=0 ; i<GEFV_CACHESIZE ; i++)
    {
        if (!Q_strcmp(field, gefvCache[i].field))
        {
            def = gefvCache[i].pcache;
            goto Done;
        }
    }

    def = ED_FindField (field);

    if (Q_strlen(field) < MAX_FIELD_LEN)
    {
        gefvCache[rep].pcache = def;
        Q_strcpy (gefvCache[rep].field, field);
        rep ^= 1;
    }

Done:
    if (!def)
        return NULL;

    return (eval_t *)((char *)&ed->v + def->ofs*4);
}
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: [Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by drm_wayne »

Its for the PSP Kurok engine (and all other similar ones)...
I mainly needed it for 3rd person weapons and 1st person legs:

Image
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: [Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by qbism »

The legs are cool. Qfusion was the first time I saw that effect. It uses the lower body from md3 models.
leileilol
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Re: [Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by leileilol »

First time I saw first-person legs was Montezuma's Return!
Soon after we saw first-person breasts in Trespasser, rarely ever seen again, and they were vital for having a health meter TATOO
i should not be here
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: [Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post by ceriux »

i sucked at trespasser -.-
Post Reply