Page 1 of 1

Passing playerstate info from game to cgame the proper way?

Posted: Sun Jun 07, 2009 2:29 am
by MDaveUK
Hi there, this has been causing me headaches for a while now.

I'm using a modified q3 engine that has some extra playerState members in the playerState struct. I've only added a few more to it like lockedTarget (int) and lockedPosition (vec3_t), which is needed for a special lock on mode for my fighting game mod. I've got it all working fine and everything, but I would like cgame to read the variables those members use for a special camera I'm working on in cg_view.c, but it seems it doesn't read them for some reason. Can anyone provide an example of how I'm supposed to do this? Sorry about this, I'm pretty new to q3 modding, and there dosn't seem to be an awful lot of info on how it all works :(

Cheers

Re: Passing playerstate info from game to cgame the proper way?

Posted: Sun Jun 07, 2009 8:49 am
by ^misantropia^
Any field you add to playerState_t needs to be reflected in the entityStateFields[] array in qcommon/msg.c. A member of said array looks like this:

Code: Select all

{ NETF(my_new_int_variable), 16 },
16 is the number of bits you want to transmit. If, for example, you know that your new variable will only contain values between 0 and 999, you only need to transmit 10 bits (because 1 << 10 == 1024 which is large enough to hold values between 0 and 999). When passing floats, just set it to zero:

Code: Select all

{ NETF(my_new_float_variable), 0 },
And the engine will determine the number of bits needed to transmit the variable without data loss (either 13 or 32, the code in msg.c contains a rather clever hack to calculate the required resolution).

Re: Passing playerstate info from game to cgame the proper way?

Posted: Mon Jun 08, 2009 2:27 pm
by MDaveUK
Ah that's it! That did the trick, thanks a ton :D I think I remember reading a comment about this in the source, but wasn't sure what exactly I had to do. Thanks :)

I will probably have more questions coming up soon :P Like why some events are constantly played sometimes (or not at all), but not when g_synchcronousClients is 1 it works fine. Or why some animations don't play sometimes, but they do properly with that cvar on too.

Re: Passing playerstate info from game to cgame the proper way?

Posted: Mon Jun 15, 2009 5:48 pm
by bitWISE
^misantropia^ wrote:And the engine will determine the number of bits needed to transmit the variable without data loss (either 13 or 32, the code in msg.c contains a rather clever hack to calculate the required resolution).
Tossing out an untested guess. XOR the sign bit, right-shift by 12, if result equal to zero then use 13bits, else use 32?

Re: Passing playerstate info from game to cgame the proper way?

Posted: Tue Jun 16, 2009 8:32 am
by ^misantropia^
Much simpler, really. =)

Code: Select all

if (f == (int)f && (int)f < 4096) {
    // use 13 bits
}

Re: Passing playerstate info from game to cgame the proper way?

Posted: Mon Jun 22, 2009 5:17 pm
by bitWISE
Wouldn't -4097 break that or is it just presumed that only unsigned values will be used?

Re: Passing playerstate info from game to cgame the proper way?

Posted: Tue Jun 23, 2009 8:07 am
by ^misantropia^
The latter. And to be fair, my code was rather a simplification of the real implementation.

Re: Passing playerstate info from game to cgame the proper way?

Posted: Tue Jun 30, 2009 1:16 am
by MDaveUK
Alright got a question! Is there a limit to how much I can put into the playerState struct? I've been adding more things into it, and it seems some stuff isn't working anymore. Does putting things into arrays help much, like for example "float baseStats[MAX_BASESTATS];" ? I've got added a few of those too. What's the best way of doing this? There's all sorts of information I need the player to have. :P

Re: Passing playerstate info from game to cgame the proper way?

Posted: Tue Jun 30, 2009 8:24 am
by ^misantropia^
You're going with modifying msg.c? In that case, there isn't any real upper limit. If it's not working properly, you are probably doing it wrong. ;-)

Re: Passing playerstate info from game to cgame the proper way?

Posted: Tue Jun 30, 2009 6:56 pm
by MDaveUK
Found out what the problem was, my enums were conflicting with other variables with the same names :P doh. Everything is well :)