Forum

[Server] numpr_globals

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

[Server] numpr_globals

Postby Spike » Fri Jul 30, 2010 9:04 pm

Not sure if anyone else has posted this...

To extend a progs to support 64k globals instead of a mere 32k is fairly easy.

step 1:
pr_comp.h
find dstatement_t.
change the 'short a, b, c;' line to 'unsigned short a, b, c;'

Well that the gist of it. However, we broke the jump instructions. Those ones need to remain signed.

step 2:
go into pr_exec.c, find the PR_ExecuteProgram function.
find the OP_IF, OP_IFNOT, and OP_GOTO instructions.
OP_GOTO contains the line 's += st->a - 1;' replace it with 's += (signed short)st->a - 1;'
Add a similar cast to the OP_IF and OP_IFNOT instructions as well.

You can now run mods that require 64k globals.

No other changes are required.
Last edited by Spike on Sat Jul 31, 2010 1:55 pm, edited 1 time in total.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby mh » Fri Jul 30, 2010 9:09 pm

:D

Nice one!
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby Baker » Sat Jul 31, 2010 1:07 pm

What an example of a situation where QC benefits from this?

/Weak in the QC department, especially when it comes to stuff like how the memory is used.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby Spike » Sat Jul 31, 2010 1:44 pm

large mods benefit from this.
numpr_globals is the hard limit on a prog's size. If you exceed it, things just break. The other limits are hard to exceed.

back with the original qcc, each operation generated a temp.
fred = foo + 5;
basically generates foo+5 in a temp, then stores that temp into fred.
that temp is a 'global', just a hidden one. Okay, the naming is not the best, as globals includes locals, but whatever.
So that basically gives you a limit of 32k maths... Which is pathetic. Truely pathetic.
However...
FrikQCC and FTEQCC both do a decent enough job at optimising away temps. Globals is still the hard limit, however.

One example mod that still suffers despite optimising QCCs is trinca's frogbots mod. It contains a whole lot of hard coded vector coords. Each one of them takes 3 globals.
FTEQCC has special inefficient reworking of vector arguments to avoid using globals/constants, but its not pretty.

More practically though, even with frikqcc, you'll not easily exceed the globals until you start using arrays. With this feature you can make slightly bigger arrays.
Either way its nice to document it.

Useless info:
Hexen2 actually split its gamecode into two separate progs in order to keep below the globals limit.
CustomTF switched to the kkqwsv server and created a new progs format to increase their limit from 32k to 2 billion.
Neither can be compiled without optimisations/workarounds.

So yeah, for large mods, use a better qcc, or use this. :)
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest