Page 1 of 1

[Server] numpr_globals

Posted: Fri Jul 30, 2010 9:04 pm
by Spike
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.

Posted: Fri Jul 30, 2010 9:09 pm
by mh
:D

Nice one!

Posted: Sat Jul 31, 2010 1:07 pm
by Baker
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.

Posted: Sat Jul 31, 2010 1:44 pm
by Spike
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. :)