Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

passing a vec3_t to the qc vm

| Inside3d Forums Forum Index -> Engine Programming

View previous topic :: View next topic
Author | Message
--- | ---
sp4x0r Joined: 21 Jul 2008 Posts: 6 |

Posted: Mon Jul 21, 2008 12:24 pm Post subject: passing a vec3_t to the qc vm |

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?

Back to top |

Spike Joined: 05 Nov 2004 Posts: 944 Location: UK |

Posted: Mon Jul 21, 2008 8:20 pm Post subject: |

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.
_________________
What's a signature?

Back to top |

sp4x0r Joined: 21 Jul 2008 Posts: 6 |

Posted: Tue Jul 22, 2008 9:36 am Post subject: |

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:
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:
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:
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:
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:
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:
{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.

Back to top |

Display posts from previous:

| Inside3d Forums Forum Index -> Engine Programming | 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