Passing playerstate info from game to cgame the proper way?

Locked
MDaveUK
Posts: 11
Joined: Fri May 01, 2009 2:01 pm

Passing playerstate info from game to cgame the proper way?

Post 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
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

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

Post 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).
MDaveUK
Posts: 11
Joined: Fri May 01, 2009 2:01 pm

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

Post 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.
bitWISE
Posts: 10704
Joined: Wed Dec 08, 1999 8:00 am

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

Post 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?
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

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

Post by ^misantropia^ »

Much simpler, really. =)

Code: Select all

if (f == (int)f && (int)f < 4096) {
    // use 13 bits
}
bitWISE
Posts: 10704
Joined: Wed Dec 08, 1999 8:00 am

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

Post by bitWISE »

Wouldn't -4097 break that or is it just presumed that only unsigned values will be used?
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

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

Post by ^misantropia^ »

The latter. And to be fair, my code was rather a simplification of the real implementation.
MDaveUK
Posts: 11
Joined: Fri May 01, 2009 2:01 pm

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

Post 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
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

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

Post 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. ;-)
MDaveUK
Posts: 11
Joined: Fri May 01, 2009 2:01 pm

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

Post by MDaveUK »

Found out what the problem was, my enums were conflicting with other variables with the same names :P doh. Everything is well :)
Locked