Page 1 of 1

[Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Posted: Mon Apr 26, 2010 11:23 pm
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

Posted: Sat Sep 11, 2010 12:12 am
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"

Posted: Mon Sep 13, 2010 11:00 pm
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.

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

Posted: Mon Dec 24, 2012 2:17 pm
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...

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

Posted: Mon Dec 24, 2012 3:17 pm
by Spike
its the last part that contains the 'magic'.

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

Posted: Mon Dec 24, 2012 3:26 pm
by drm_wayne
Wrong, i even tested a Kurokbuild where HE added that stuff and Drawonlytoclient DOESNT work...

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

Posted: Mon Dec 24, 2012 4:33 pm
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.

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

Posted: Mon Dec 24, 2012 5:39 pm
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...

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

Posted: Mon Mar 25, 2013 8:22 pm
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

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

Posted: Tue Mar 26, 2013 2:20 am
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);
}

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

Posted: Tue Mar 26, 2013 6:52 am
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

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

Posted: Wed Mar 27, 2013 12:09 am
by qbism
The legs are cool. Qfusion was the first time I saw that effect. It uses the lower body from md3 models.

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

Posted: Thu Apr 04, 2013 12:58 am
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

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

Posted: Thu Apr 04, 2013 4:57 am
by ceriux
i sucked at trespasser -.-