Forum

Official Post Your Enging Coding Tips Thread

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

Postby Tomaz » Sun Aug 16, 2009 6:13 pm

reckless wrote:tbh im not sure

this is the one from fitz

#define CLAMP(min, x, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) //johnfitz

looks a bit more clean ill have to try it out and see if theres any difference.


Yeah that one makes the assumption that min is always smaller than max, the one i have handles the case where min might be bigger than max.
Tomaz
 
Posts: 67
Joined: Fri Nov 05, 2004 8:21 pm

Postby revelator » Sun Aug 16, 2009 11:29 pm

hmm interresting the bound value seems to assume that if the min value is greater or equal than the max value then min = max

#define bound(min, x, max) ((min) >= (max) ? (min) : (x) < (min) ? (min) : (x) > (max) ? (max) : (x)) //slight rewrite hopefully a bit more readable

if i pull first part of it where it checks if min >= max then the rest of the function is the same as fitz as to why i got no clue. safeguard maybe ?

if (min >= max)
{
min = max;
}

// macro splits here
if (x < min)
{
x = min;
}
else if (x > max)
{
X = max;
}
else
{
x = x;
}
return x;
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Postby mh » Mon Aug 17, 2009 10:11 am

I posted this one elsewhere:

Precalculating sizes and allocating in bulk is always good too. For example, you can figure out in advance how many glpoly_t structs (and the sizes of their vertexes) you need for non warp-surfaces, so why not just allocate a single big buffer at the end of Mod_LoadFaces and write the polys into that instead of doing a separate allocation for each poly?
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 Team Xlink » Fri Aug 21, 2009 3:48 pm

Another one:

Your code isn't just supposed to work.

It is supposed to work good.

Avoid hack-ish code if possible, try to make your code efficient.
Team Xlink
 
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

Postby revelator » Fri Aug 21, 2009 10:15 pm

indeed its better checking twice or more to make sure it actually runs, i had plenty of stuff that ran on my pc just to find out it didnt on anyone else pc "required msvc runtime missing or something so hacky only my own mess could run it xP"

thats why feedback is crucial we dont have all the hardware in the world to test releases against.

constructive feedback is probably the best resource in the world :)
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Postby Team Xlink » Mon Jan 25, 2010 8:39 pm

If your working on your own engine make sure you remove the #ifdef IDGODS code.

It is Id software's backdoor for servers. It lost its usability after the source code release because the majority of engines removed it and it was made public.
Team Xlink
 
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

Previous

Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest