Inside3D!
     

[Server] DP_QC_TRACEBOX

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials
View previous topic :: View next topic  
Author Message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sat Jul 31, 2010 10:03 am    Post subject: [Server] DP_QC_TRACEBOX Reply with quote

Just a quicky to show how simple some ommisions can be...

Tracebox, that awesome builtin that lets you trace a box through the world instead of a single tiny line.
Internally the engine already supports all this stuff for monster movement etc.

tracebox has this QC prototype:
void(vector start, vector min, vector max, vector end, float nomonsters, entity forent) tracebox = #90;

Open up pr_cmds.c
Find PF_traceline.
Add the following function below it.

Code:

void PF_tracebox (void)
{
   float   *v1, *v2, *mins, *maxs;
   trace_t   trace;
   int      nomonsters;
   edict_t   *ent;

   v1 = G_VECTOR(OFS_PARM0);
   mins = G_VECTOR(OFS_PARM1);
   maxs = G_VECTOR(OFS_PARM2);
   v2 = G_VECTOR(OFS_PARM3);
   nomonsters = G_FLOAT(OFS_PARM4);
   ent = G_EDICT(OFS_PARM5);

   trace = SV_Move (v1, mins, maxs, v2, nomonsters, ent);

   pr_global_struct->trace_allsolid = trace.allsolid;
   pr_global_struct->trace_startsolid = trace.startsolid;
   pr_global_struct->trace_fraction = trace.fraction;
   pr_global_struct->trace_inwater = trace.inwater;
   pr_global_struct->trace_inopen = trace.inopen;
   VectorCopy (trace.endpos, pr_global_struct->trace_endpos);
   VectorCopy (trace.plane.normal, pr_global_struct->trace_plane_normal);
   pr_global_struct->trace_plane_dist =  trace.plane.dist;   
   if (trace.ent)
      pr_global_struct->trace_ent = EDICT_TO_PROG(trace.ent);
   else
      pr_global_struct->trace_ent = EDICT_TO_PROG(sv.edicts);
}


There's our new builtin. Note that the only differences from the regular traceline is the extra two parameters (inserted between start/end), which are passed to the SV_Move function. There are no other changes.

Now we need to add it to the list, which is also easy.
Find the definition of pr_builtin below, pretty much right at the bottom, its the array.
At the end, you should see PF_setspawnparms as the last entry. This particular builtin is actually #78.
After that entry, we need to add some padding, so that entry #90 is our builtin. There's a special dummy builtin that can be used for his purpose, imaginitively called PF_Fixme.
So add 11 lines of PF_Fixme, followed by a single PF_tracebox line.

Mods using your engine can now use tracebox, although they can't query support for it.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Baker



Joined: 14 Mar 2006
Posts: 1538

PostPosted: Sat Jul 31, 2010 1:05 pm    Post subject: Reply with quote

Does this built-in let a QuakeC coder check for a space allocation?

For example, to see if at x, y, z there is enough space for a Shambler to be spawned there?
_________________
Tomorrow Never Dies. I feel this Tomorrow knocking on the door ...
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sat Jul 31, 2010 1:31 pm    Post subject: Reply with quote

if the mins/maxs match the shambler's size, yes.
traceboxing with the start and end points the same will work as a test to see if its empty. check the trace_startsolid as the return value in that case (fraction is generally 1 if startsolid is set, so meaningless).

alternatively droptofloor can permit you to test if its empty, if you want to avoid engine extensions.
as can walkmove, but note that walkmove touches triggers on success.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Sun Aug 01, 2010 3:03 am    Post subject: Reply with quote

Spike wrote:
...but note that walkmove touches triggers on success.


Noted! I should stop suggesting that to people then.
_________________
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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group