Opposite of If statement

Started by
9 comments, last by Darg 13 years ago

Me and Owl must of posted at the exact same time. I didn't even see it, but now I do. I think Owl's is best also
combining it like he did also saves some computing time. Since it just reads from memory and doesn't have to calculate.


What I posted is exactly what teutonicus proposed but I just made the calculations outside the function call for readability's sake. I don't think it's gonna be faster and if it is it'd be a despicable improvement, but I've learned to be willing to trade a few cycles for readability and code maintainability

You might want to explore what Brother Bob proposed: Implementing algebraic vectors into your code:

class vector3
{
public: // Make it right
int x;
int y;
int z;
};

// make a method in class world that combines blockGetAmount and blockExists
// the offset seem to be inside world so you don't even need to pass it as an argument.
bool World::BlockValidExists(vector3& v_pos, vector3& v_xof)
{
return (blockExists (v_pos, v_xof) && (blockGetAmount(v_pos, v_xof)!=-1));
}

// and then ...

vector3 xof_vector (world0->xOffset-location.x, world0->yOffset-location.y, world0->zOffset-location.z);
vector3 pos_vector (x-1, y, z);

if (world0->BlockValidExists(pos_vector, xof_vector))
{
[size="2"]I like the Walrus best.
Advertisement
I was just about to mention, before I saw Owls latest post that you're passing exactly the same variables through to World twice asking for two separate results. It would be far more readable if you simply introduced a third function in World that takes the variables once and does the two tests then passes back False if both of the values are true.

You'll learn as you go on, especially with larger projects that if you come back to that code in a couple of months you'll have to spend half an hour just deciphering what it was you were doing with it all. In my opinion readable code is more important even than super efficient code. I know a lot of people will say that when programming for realtime calculations like games efficiency is paramount but readable code will make development easier and quicker which should give you plenty of time at the end for efficiency changes if they're even needed at that point :)
Portfolio & Blog:http://scgamedev.tumblr.com/

This topic is closed to new replies.

Advertisement