Forum

passing a vec3_t to the qc vm

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

passing a vec3_t to the qc vm

Postby sp4x0r » Mon Jul 21, 2008 12:24 pm

I'm fiddling in the darkplaces engine to do a few things with input that I can't do in QC, and while I've miraculously come a long way there are a number of simple things I don't understand.

What I'd like to do is create a vec3_t in the engine, assign the values in the C code, and then be able to use it as a vector in QC. Most of the variables that get passed to QC that I've looked at are confusing me. I'm pretty sure the vector I want to record is only going to be used by the client, I don't think the server needs to keep track of it.

Is there a simple way to do this?
User avatar
sp4x0r
 
Posts: 16
Joined: Mon Jul 21, 2008 11:48 am

Postby Spike » Mon Jul 21, 2008 8:20 pm

vectors are just three consecutive floats, hence how vec_x vec_y vec_z work.
if you want to pass it in to a qc function as a parameter, write to offset OFS_PARM0+0, OFS_PARM0+1, OFS_PARM0+2 for the first parameter.
in the released sourcecode there was some function called GetEdictFieldOfs or something like that which can get a named field. it returns a union. The vector part is an array. Can't remember the proper way to do globals. mneh.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby sp4x0r » Tue Jul 22, 2008 9:36 am

Thanks, that got me started.

I copied how some of the prydon_cursor stuff works. I have no idea if this is a bad way to do things.

In the event any n00bs like me want to know what I did (the order of these steps probably hinders the explanation):

- in client.h I set up a vec3_t in the usercmd_s struct
- in progsvm.h I put in an entry under prvm_prog_fieldoffsets_s (these are all declared as ints and I have no idea if this step is necessary in the first place. Seems to be used for csqc and ssqc, which I don't think I'm actually using anway)
- in prvm_edict.c I put a line like this into PRVM_FindOffsets():
Code: Select all
prog->fieldoffsets.my_vector = PRVM_ED_FindFieldOffset("my_vector");

- I put some code in my stuff that sets the coordinates of the vector
e.g.
Code: Select all
cl.cmd.my_vector[0] = x_value;
cl.cmd.my_vector[1] = y_value;
cl.cmd.my_vector[2] = z_value;

- I sent the values to the server in cl_input.c toward the end of CL_SendMove():
Code: Select all
MSG_WriteFloat (&buf, cmd->my_vector[0]);
MSG_WriteFloat (&buf, cmd->my_vector[1]);
MSG_WriteFloat (&buf, cmd->my_vector[2]);

(just after the prydon_cursor stuff)

- in sv_user.c I grab the values after the prydon_cursor stuff toward the end of SV_ReadClientMove:
Code: Select all
move->my_vector[0] = MSG_ReadFloat();
move->my_vector[1] = MSG_ReadFloat();
move->my_vector[2] = MSG_ReadFloat();

- still in sv_user.c I put this at the end of SV_ApplyClientMove():
Code: Select all
if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.my_vector))) VectorCopy(move->my_vector, val->vector);

- in sv_main.c I put a line in at the end of prvm_required_field_t reqfields[] =:
Code: Select all
{ev_vector, "my_vector"},


After compiling I can use it in QC by declaring .my_vector and then using self.my_vector.

I only have a vague idea how this works (but it works) because I'm useless at programming, so if there's a smarter way I'd love to know. Some of these steps may be completely unnecessary.
User avatar
sp4x0r
 
Posts: 16
Joined: Mon Jul 21, 2008 11:48 am


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest