"symbol X undefined" compiling cgame.qvm (new cvar)

Locked
JPL
Posts: 13
Joined: Sun Nov 11, 2007 1:17 am

"symbol X undefined" compiling cgame.qvm (new cvar)

Post by JPL »

Hi folks, I'm still learning the Q3 engine and C coding so sorry if this is a noob question.

I'm trying to add a new cvar called "g_airControl" that gives some, err, control over air control similar to how Unreal engine games do it. The code itself just makes pm_airaccelerate a percentage of pm_accelerate according to the cvar value, and that works fine. However I'm getting an error when I compile:

Code: Select all

Q3ASM build/release-linux-i386/baseq3/vm/cgame.qvm
error: symbol g_airControl undefined
I declare the cvar in g_main.c, and declare it extern in bg_local.h so that bg_pmove.c can access its value. Like I said the code that reads the value and changes the air acceleration works, it just gives an error that seems related to QVM compilation.

For what it's worth, I'm working off the ioquake3 base, and compiling as a normal C project rather than as a mod.
AnthonyJ
Posts: 130
Joined: Wed Nov 15, 2006 7:51 pm

Re: "symbol X undefined" compiling cgame.qvm (new cvar)

Post by AnthonyJ »

bg_*.c are used in both cgame and game projects. This means the code runs in two places - both on the client, and on the server.

Your code doesnt link because g_main.c doesnt exist in the cgame project - the equivilent place would be cg_main.c. However that wouldnt "work" (even though it'd compile), because both the client and the server would have a cvar, and they could be at different values (probably would be if changed from default).

One way to do what you want to put the data in somewhere that automatically gets synced between client and server, such as somewhere within the pm->ps struct. However given this is probably a value which never changes and is constant for all players, its probably more appropriate to use some form of server->client communication to keep a variable in sync on both client and server.
JPL
Posts: 13
Joined: Sun Nov 11, 2007 1:17 am

Re: "symbol X undefined" compiling cgame.qvm (new cvar)

Post by JPL »

Ah, thanks for the clarification. I'm starting to get all the nuances of what happens on the server VS the client.
JPL
Posts: 13
Joined: Sun Nov 11, 2007 1:17 am

Re: "symbol X undefined" compiling cgame.qvm (new cvar)

Post by JPL »

So my solution for this was to add a new var to the playerstate struct, and sync that with the cvar's value in ClientThink_real() in g_active.c (right next to the code that syncs ps.speed with g_speed). Then the code that runs in bg_pmove refers to the value in pm->ps.

This seems to work fine, although I haven't tested it with a dedicated server + client setup yet.

Is there anything sub-optimal about this solution, or am I on the right track? Either way thanks again for the advice.
AnthonyJ
Posts: 130
Joined: Wed Nov 15, 2006 7:51 pm

Re: "symbol X undefined" compiling cgame.qvm (new cvar)

Post by AnthonyJ »

Unless you're making engine changes too, you cant add extra things to the playerstate struct - they wont get transferred over the network unless you update qcommon\msg.c (see the comment). There is unused space there, but you probably want to save that for truely per-player values.

The way you described it before, it sounded like the value was a "set once" type cvar which is a server-wide value. IMO you'd be better sending it in a configstring or some other global server->client message.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: "symbol X undefined" compiling cgame.qvm (new cvar)

Post by ^misantropia^ »

JPL wrote:or am I on the right track?
Alas, no. Quoting from qcommon/q_shared.h:

Code: Select all

// you can't add anything to this without modifying the code in msg.c
Don't tamper with playerState_t or code in the engine will become very confused. You can however (ab)use the stats field; there's room for 16 integers there but only 8 of them are used (see the statIndex_t enum in game/bg_public.h).
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: "symbol X undefined" compiling cgame.qvm (new cvar)

Post by ^misantropia^ »

Meh, Anthony. Sneaking in a comment when I wasn't looking, eh?
JPL
Posts: 13
Joined: Sun Nov 11, 2007 1:17 am

Re: "symbol X undefined" compiling cgame.qvm (new cvar)

Post by JPL »

Yeah, I saw that comment about msg.c and added an entry for the thing I added to playerstate. Like I said it worked. I'm doing a standalone game not a mod, but it sounds like misantropia's solution is better in general. I'll try that.
Locked