|
From: <qu...@ca...> - 2015-12-21 01:31:28
|
> Looks like you commented alot of stuff, so thats good.
If I dont, it is so freaking hard to figure out 3 months later - after I
had to leave the code for a bit...
Learned commenting the hard way.
> Whats the deal with crandom? Looks like you are saying the #ifdef means
> that if the mod used the crandom function, then use the alternate?
> Sorta
> lost on those #
> type references, thought they are just like the comment fields , ie:
> // ?
#{precompiler code} are all interpreted by the compiler, very similar to
various c languages.
I wrapped the function in "#ifndef opgrade". So if opgrade is defined
it uses the #define for crandom.
If opgrade is not defined it uses the old function.
#define crandom() 2*(random() - 0.5)
Is just like
float() crandom =
{
return 2*(random() - 0.5);
};
Except - the define is a macro that plugs in the code "2*(random() -
0.5)" for "crandom()".
So:
vel = normalize(dir + v_up*crandom() + v_right*crandom());
Compiles that way without opgrade defined.
With opgrade it compiles as
vel = normalize(dir + v_up*2*(random() - 0.5) + v_right*2*(random() -
0.5));
I did that just an experiment to find out if it works the same. Have
the test data somewhere.
It does save a global slot and a function slot - some of these
977 numfunctions (of 16384)
3474 numglobaldefs (of 32768)
3826 numpr_globals (of 65536)
At the expense of compiled code complexity.
Which could be important if you are approaching those limits.
What it does to the running c interpreter is hard to tell. It avoids a
function call, and runs the same math code,
so you would think it saves some ops here and there. Certainly saves
data on the stack.
Which means nothing on the hardware most of us have. Could have meaning
on the psp and other mobiles that run darkplaces.
fteqcc precompiler ops (these are in the fteqcc docs.)
#define opgrade
Gives opgrade a detectable existence for:
#ifdef opgrade
// opgrade defined
#else
// opgrade NOT defined
#endifdef
or
#ifndef opgrade
// opgrade NOT defined
#endifdef
#undef opgrade
Make opgrade undefined again. This is also useful for a substitute that
only gets used in one module.
#define crandom() 2*(random() - 0.5)
creates a substitue macro, where the text "crandom()" is replaced with
"2*(random() - 0.5)".
You dont need the ()
#define a__ aflag
These can have function parameters:
#define framer(sframe,eframe,t_on,t_to,t_time,excode) void() t_on {if
(self.think != t_on|| self.frame < sframe || self.frame >=
eframe){self.frame = sframe - 1; self.think = t_on;} self.frame =
self.frame + 1; self.nextthink = time + t_time; if (self.frame ==
eframe) {self.think = t_to;} excode;}
Also they can be very complex. The compiler currently has a 256 byte
limit on that - but unlimited substitutions.
So you can make a bunch of those and string them all together in a final
one.
In fact if you want to print a literal string, like "Hey there" from
that - you have to use multiple defines.
#include <incl/local_ent.qc>
Inlcudes the specified file.
#message -- version 1.07 qc++ quake-c -- compile
with fteqcc
Dumps a message out from the compile about what sequence just compiled.
No idea how that will look here - I have backspaces to overwrite the
"message:" tag that precedes it.
// turn off warnings for map spawn functions - most are normally only
called by the engine
#pragma warning off F300
These control compiler behavior. That stops it from complaining because
spawn functions dont get
referenced directly in the qc code. That seems like a very silly
complaint given how qc works.
These are awesome - I can now do things with quake-c without a bunch of
crap.
Like having to wrap all the warnings with some master variable, and then
delete every one of them when I want to
find out how and / or if the code runs without them.
And for purists I can leave in the practically useless iD debug and test
code.
(In fact, when I tried it, I found out some if it would not compile at
all, and other bits fail or do nothing. I fixed some of it...)
It also makes the code more portable. For darkplaces its easy to remove
the un-needed precache (since it has dynamic).
If you want to move to another engine, you can just turn it back on.
Between this and some of the darkplaces builtin its like a dream.
I can do stuff now that just were not possible with out a lot of if
thens, tons of literal strings, etc.
Code logic, that makes the old qc look like a dino!
I had been putting off learning the darkplaces extension (once I decided
my mod was dp only a couple years back)
to finish the Archon mod. Little did I realize it is the only way I'll
ever finish the mod.
Now I'm slamming along with the new stuff.
-6
|