Forum

[Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

[Tutorial PSP/PC] - DP_SV_NODRAWTOCLIENT & DP_SV_DRAWONL

Postby Team Xlink » Mon Apr 26, 2010 11:23 pm

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.
Team Xlink
 
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

Postby qbism » Sat Sep 11, 2010 12:12 am

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"
User avatar
qbism
 
Posts: 1235
Joined: Thu Nov 04, 2004 5:51 am

Postby Team Xlink » Mon Sep 13, 2010 11:00 pm

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.
Team Xlink
 
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

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

Postby drm_wayne » Mon Dec 24, 2012 2:17 pm

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...
User avatar
drm_wayne
 
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

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

Postby Spike » Mon Dec 24, 2012 3:17 pm

its the last part that contains the 'magic'.
Spike
 
Posts: 2874
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

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

Postby drm_wayne » Mon Dec 24, 2012 3:26 pm

Wrong, i even tested a Kurokbuild where HE added that stuff and Drawonlytoclient DOESNT work...
User avatar
drm_wayne
 
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

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

Postby Spike » Mon Dec 24, 2012 4:33 pm

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.
Spike
 
Posts: 2874
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

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

Postby drm_wayne » Mon Dec 24, 2012 5:39 pm

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...
User avatar
drm_wayne
 
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

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

Postby drm_wayne » Mon Mar 25, 2013 8:22 pm

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
User avatar
drm_wayne
 
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

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

Postby qbism » Tue Mar 26, 2013 2:20 am

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);
}
User avatar
qbism
 
Posts: 1235
Joined: Thu Nov 04, 2004 5:51 am

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

Postby drm_wayne » Tue Mar 26, 2013 6:52 am

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

Image
User avatar
drm_wayne
 
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

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

Postby qbism » Wed Mar 27, 2013 12:09 am

The legs are cool. Qfusion was the first time I saw that effect. It uses the lower body from md3 models.
User avatar
qbism
 
Posts: 1235
Joined: Thu Nov 04, 2004 5:51 am

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

Postby leileilol » Thu Apr 04, 2013 12:58 am

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
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

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

Postby ceriux » Thu Apr 04, 2013 4:57 am

i sucked at trespasser -.-
User avatar
ceriux
 
Posts: 2220
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest