Official Post Your Enging Coding Tips Thread
Moderator: InsideQC Admins
51 posts
• Page 4 of 4 • 1, 2, 3, 4
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
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;
#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;
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
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
We knew the words, we knew the score, we knew what we were fighting for
-

mh - Posts: 2292
- Joined: Sat Jan 12, 2008 1:38 am
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.
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
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
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
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
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.
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
51 posts
• Page 4 of 4 • 1, 2, 3, 4
Who is online
Users browsing this forum: No registered users and 1 guest