Pages: [1]
  Print  
Author Topic: Is the game multi-process? Working on a mod and global variable seems duplicated  (Read 24546 times)
Maine
Nub


Cakes 0
Posts: 3


« on: May 07, 2008, 10:59:14 PM »

My friend and I are working on a neat project, where a gamer must pedal faster on an exercise bike to run faster in the game. We looked at several open source games and decided on Open Arena.

I'm doing the development on Linux, the hardware side of things is essentially done (I have a serial mouse which will function as a speedometer - already wrote the code to monitor mouse clicks over time and calculate the clicks per second which will become revolutions per minute when the stationary bicylce is setup - wheel will click the mouse button).


I have put the serial port mouse (aka cheap speedometer) monitoring code into a new function in renderer/tr_backend.c, and the thread is started in renderer/tr_cmds.c in the R_InitCommandBuffers method (I chose that location simply because I saw other threads started there). My plan was to store the speed (updated every three seconds or so) in a global float, so I made a header file with that variable's definition in it, and included it in tr_backend.c (and in my thread's function, it sets that variable). Fine, great....

Then, I modified game/bg_pmove.c, so that in the PM_WalkMove function it would multiply the wish velocity by whatever the speed multiplier was from that header file I made (and included in bg_pmove.c).

Code compiles fine, I've been moving the qvm files around appropriately, etc.

Here is the problem:
In bg_pmove.c, the value that the function reads from that global speed multiplier variable (remember, the serial port monitoring code was continually setting that variable) never changes. In the thread code, the variable is set just fine (determined this through print statements). So, after much wasted time I decided to print the address of that global speed multiplier variable in both code locations. Sure enough I get different addresses. Right about then I was thinking that the code must be forking a process somewhere, and the global speed multiplier was being copied. However, when I would bring up a terminal while the game was running, I could only find one process running that was associated with the game.

At this point I'm fairly frustrated and have no idea what to do. I feel like there's some basic thing I missing in this game, because I can't figure out why that global variable would be duplicated.

I'd really appreciate any insight into this problem. (Plus I'll try and post a simple write up of the "mod" if anyone can suggest an appropriate location for it...and if I ever get it to work.)

Let me know if you want any more detail about the problem or what I've tried out so far.

Thanks in advance!
~Maine
Logged
skankychicken
Lesser Nub


Cakes 1
Posts: 114


OpenArena 1.0.0 - /cg_roaminganimals 1 ; /cg_flipf


« Reply #1 on: May 07, 2008, 11:17:59 PM »

oh wow. I tried to get this kicked off but kind of fell apart when i requested a bag of nails as an entity to punctue enemy tires.



Good luck guys!
Logged
sago007
Posts a lot
*

Cakes 62
Posts: 1664


Open Arena Developer


WWW
« Reply #2 on: May 08, 2008, 04:48:55 AM »

QVMs run in a virtual machine that has no knowledge of the normal variables in the engine (for security reasons).

You can exchange data in two ways:

By using engine CVARs that can be accessed from within the game with trap_Cvar_VariableValue( "CVARNAME" ) and set by trap_Cvar_SetValue( "CVARNAME", VALUE );

Or using your own custom trap_function

I recommend the CVAR solution if you only need to read/write variables (and it sound likes that is the problem).

EDIT:
Actually it is possible to put the game and cgame out side the virtual machines if you use the dll/so/dynlib files. It is not usually a recommended way of solving the problem, but might work for standalone&&non-multiplayer projects. 

EDIT 2:
Also be aware that game and cgame are separated (server and client logic)
« Last Edit: May 08, 2008, 02:19:55 PM by sago007 » Logged

There are nothing offending in my posts.
iLeft.bye
Member


Cakes 1
Posts: 187



« Reply #3 on: May 08, 2008, 02:21:55 PM »

oh wow. I tried to get this kicked off but kind of fell apart when i requested a bag of nails as an entity to punctue enemy tires.



Good luck guys!
10 fps :?
Logged
fromhell
Administrator
GET A LIFE!
**********

Cakes 35
Posts: 14520



WWW
« Reply #4 on: May 08, 2008, 02:24:58 PM »

i have no idea where all these players get their crappy video cards from, come on a voodoo2 can do better
Logged

asking when OA3 will be done won't get OA3 done.
Progress of OA3 currently occurs behind closed doors alone

I do not provide technical support either.

new code development on github
skankychicken
Lesser Nub


Cakes 1
Posts: 114


OpenArena 1.0.0 - /cg_roaminganimals 1 ; /cg_flipf


« Reply #5 on: May 08, 2008, 06:29:50 PM »

Quote
10 fps :?

It's a screenshot. It was from ages ago and I recognise the timescale messages from a demo player. I would normally have the screen a little smaller and push it up to 14 fps. If you are new to the game then I guess it might look odd but when using timescale that number means nothing. I think the config used was for brodcasting live streams to the www via a media server. I seem to remember the CPU of the game was at 99% and I was displaying it in a browser which was transcoding at the same time.

edit:  Nice idea Maine, hope it works out - it sounds a little crazy, so I'm sure it will be alot of fun and educational.  Keep us up-updated. Have you considered a uni-cycle? Cheesy
« Last Edit: May 08, 2008, 06:33:29 PM by skankychicken » Logged
Maine
Nub


Cakes 0
Posts: 3


« Reply #6 on: May 11, 2008, 11:02:20 PM »

Thanks for the encouragement and tips about the cvars. I'm still struggling with it though. If I try to set the cvar inside my thread (whose function is defined in tr_backend.c), I always get an undefined reference (I am including  ui/ui_local.h). 

tr_backend.c:(.text+0x169): undefined reference to `trap_Cvar_SetValue'

If I try to include trap_Cvar_VariableValue or Cvar_Get in bg_pmove.c (where I'd be reading the value in order to multiply the user's speed)

error: symbol trap_Cvar_VariableValue undefined

It seems I'm continually blocked by the compiling/linking errors. Is there some way to use these functions in the areas of code I'm attempting to modify? Is there something else I'm missing?





Logged
sago007
Posts a lot
*

Cakes 62
Posts: 1664


Open Arena Developer


WWW
« Reply #7 on: May 12, 2008, 04:13:39 AM »

You should only use trap_ functions to access CVARs in game and cgame code. If you are in the same module as the one you have defined the CVAR in you can access it by CVARNAME.value or CVARNAME.integer (it is assumed that the engine should never access CVARs in the game code)

I don't know where the CVARs are defined in the engine. Try searching for cvar
Logged

There are nothing offending in my posts.
kick52
Member


Cakes -1
Posts: 229


« Reply #8 on: May 12, 2008, 09:58:06 AM »

A guy at my school named Oscar appeared in the newspapers for testing one of these things..
Logged
Maine
Nub


Cakes 0
Posts: 3


« Reply #9 on: May 18, 2008, 10:50:35 PM »

You should only use trap_ functions to access CVARs in game and cgame code. If you are in the same module as the one you have defined the CVAR in you can access it by CVARNAME.value or CVARNAME.integer (it is assumed that the engine should never access CVARs in the game code)

I don't know where the CVARs are defined in the engine. Try searching for cvar

I am using the trap functions in game and cgame code. I've removed the function calls from any other areas, and if I try to use a function like trap_Cvar_VariableIntegerValue in game/bg_pmove.c (which is used in game/g_main.c which includes g_local.h the same as I've done in game/bg_pmove.c), I receive hate mail from the compiler:

Q3LCC code/qcommon/q_shared.c
Q3ASM build/release-linux-i386/baseq3/vm/cgame.qvm
error: symbol trap_Cvar_VariableIntegerValue undefined
make[2]: *** [build/release-linux-i386/baseq3/vm/cgame.qvm] Error 1

and if I comment the invocation of trap_Cvar_VariableIntegerValue out in bg_pmove.c, everything compiles fine.

As far as where cvars are declared (I'm assuming you mean cvar_t pointers), I see them declared in lots of spots, but none in the game or cgame folders.

Logged
sago007
Posts a lot
*

Cakes 62
Posts: 1664


Open Arena Developer


WWW
« Reply #10 on: May 20, 2008, 12:49:19 PM »

bg_* might be a problem as they are compiled in both the game and cgame code. I'm not sure if it has anything to do with your compile problem but the trap function might be missing in cgame.

Cvars defined in the Virtual machine is called vmCvar_t and is a struct. I don't think it should do any difference if you use trap_fucntions to access it. I have used trap_functions to access variables that the user defined through the console.

I have never defined CVARs outside the vm but I think it is the right place to define them in your case.
Logged

There are nothing offending in my posts.
Mr. Oho
Half-Nub


Cakes 0
Posts: 55

I will press the button!


« Reply #11 on: May 20, 2008, 01:17:41 PM »

Interesting project Tongue

I cant realy help with the engine side of things but game/cgame cvar declarations should be in g_main.c/g_local.h and cg_main.c/cg_local.h (long lists you can hardly miss them). Also from looking over cg_syscalls.c the only traps for for reading cvars in cgame are:

Code:
void trap_Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize ) {
syscall( CG_CVAR_VARIABLESTRINGBUFFER, var_name, buffer, bufsize );
}

void trap_Cvar_LatchedVariableStringBuffer( const char *var_name, char *buffer, int bufsize ) {
syscall( CG_CVAR_LATCHEDVARIABLESTRINGBUFFER, var_name, buffer, bufsize );
}

but im not sure if you realy need this as defining the cvar name in cvarTable with no default value seems to automaticaly get it for you.

Code:
cvarTable_t gameCvarTable[] = {
// don't override the cheat state set by the system
{ &g_cheats, "sv_cheats", "", 0, qfalse },

This is from the ET SDK but id be realy suprised if it would be different in Q3. Hope this helps a bit and good luck Tongue

Edit:

Thinking a bit about it it might not be the best approach to use cvars in the bg_*code because if its not a local server like cgame and game running in the same process the server wouldnt have a clue about the value on the client anyways. Youd have to send it to the server somehow (you have 3 more or less shitty posibilities to do this) then store it into some variable that has the same name in game and cgame to make bg_* happy.

Your posibilities to send your value to the server are like this:

1)

Code:
{ &cg_uinfo, "cg_uinfo", "0", CVAR_ROM | CVAR_USERINFO },

CVAR_USERINFO signals that the cvar is to be send to the server everytime it changes and you can fetch it in g_client.c ClientUserinfoChanged but i dont think its designed for stuff that changes alot.

2)

Code:
trap_SendClientCommand(va("sgstats %d", i));

You can get it in g_cmd.c ClientCommand. That might be the most practical solution but im not sure how quake will like it if you send it every frame. Possibly needs a rate limit or something.

3)

Stuff it in usercmd_t. This would possibly be the ultimate solution as it is designed to be send every frame and from the little digging i did it seems to be set in the engine and is readily available in bg_pmove.c. Downside is unless you find some unused space in usercmd_t youll have to change netcode. No idea who much work this would be but it would surley render your engine incompatible with every other quake3 engine out there.

If anyone has better ideas id like to here them Tongue
« Last Edit: May 20, 2008, 03:47:54 PM by Mr. Oho » Logged
fufinha
stop making alt accounts and self-termination
Member


Cakes 7
Posts: 584


retired


« Reply #12 on: May 23, 2008, 07:51:58 PM »

If a cvar changes in the game, but is not specified in config. How do I  use the server to put that entry into the clients config.

for eg. cvars that maybe user preference like...

cg_pmove_accurate 1
cg_pmove_fixed 0
Logged
Mr. Oho
Half-Nub


Cakes 0
Posts: 55

I will press the button!


« Reply #13 on: May 24, 2008, 03:24:03 AM »

Hmm to be honest im not realy sure what you want to do. Do want the server to force client cvars to a specific value or do want to send values to the server so the player has control over stuff thats only server side now or am i maybe guessing in a completly wrong direction? Tongue In short: Could you please clarify it a bit? Wink
Logged
fufinha
stop making alt accounts and self-termination
Member


Cakes 7
Posts: 584


retired


« Reply #14 on: May 24, 2008, 06:45:29 AM »

ok

pmove_fixed

.. server option Cheesy

it used to be the same command on the client. But i think it got changed somewhere along the lines to... cg_pmove_fixed

So pmove_fixed  in a clients config is kinda useless, since its replaced by cg_

But I only have these options in my cfg if i do..

/seta cg_pmove_fixed whaeva

Logged
Mr. Oho
Half-Nub


Cakes 0
Posts: 55

I will press the button!


« Reply #15 on: May 24, 2008, 07:29:51 AM »

Ahh now i get it Tongue Well i fear you wont get around a client mod to do this :/ But in cgame its fairly simple. Just do something like this in CG_Init:

Code:
trap_Cvar_VariableStringBuffer("pmove_fixed",mybuffer,sizeof(mybuffer));
if(*mybuffer){ // cvar isnt empty
     trap_Cvar_Set("cg_pmove_fixed",mybuffer);
}

Btw: Î looked around a bit and (at least in the vanilla oa client) there seem to be no pmove related cvars. Maybe they were just removed as the client uses the servers settings anyways?

Edit: I fear we are way offtopic :S

Edit2: Hooray for sleep deprived copy/paste. Its ofcourse trap_Cvar_VariableStringBuffer not trap_Cvar_LatchedVariableStringBuffer... sry if i cost you debugging time :[
« Last Edit: May 24, 2008, 09:52:32 AM by Mr. Oho » Logged
fufinha
stop making alt accounts and self-termination
Member


Cakes 7
Posts: 584


retired


« Reply #16 on: May 24, 2008, 02:09:47 PM »

ooooh.. thats way over my head Cheesy

yea.. the pmove has changed alright. But far superior is cg_pmove_accurate. That is in the code which is non fps dependant. So people might not be aware of this.
Logged
CFQ
---
Member


Cakes 0
Posts: 173


---


« Reply #17 on: June 18, 2008, 02:50:56 PM »

----
« Last Edit: August 13, 2008, 08:26:56 PM by CFQ » Logged

I blanked my posts because I don't like this forum anymore! BAWWWWW
fufinha
stop making alt accounts and self-termination
Member


Cakes 7
Posts: 584


retired


« Reply #18 on: June 18, 2008, 06:43:18 PM »

OMG! That is the post I was referring to in my last one!! spooooky

I havent even read the response. Cheesy
Logged
CFQ
---
Member


Cakes 0
Posts: 173


---


« Reply #19 on: June 18, 2008, 08:10:50 PM »

----
« Last Edit: August 13, 2008, 08:27:13 PM by CFQ » Logged

I blanked my posts because I don't like this forum anymore! BAWWWWW
fufinha
stop making alt accounts and self-termination
Member


Cakes 7
Posts: 584


retired


« Reply #20 on: June 18, 2008, 08:27:05 PM »

Well I think pmove_fixed still needs to be on the server, as with pmove_accurate.

But cg_pmove_accurate will work doing a seta. pmove_accurate wont
« Last Edit: June 18, 2008, 08:37:50 PM by missbehaving » Logged
fufinha
stop making alt accounts and self-termination
Member


Cakes 7
Posts: 584


retired


« Reply #21 on: June 18, 2008, 08:36:02 PM »

And thank you for your assistance, and also MrOho.. Smiley
Logged
Pages: [1]
  Print  
 
Jump to: