if(): howe much time consuming it is?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

I though the statement was the part that the if looks at? Statements can be true or false. If is a function, it does something,it has an input and an output.

It even has its own opcode, with the statement being the input and the output being changing the state and redirecting code excution.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

It seems this thread is newer going to die :lol:
surprises myself howe lively it is :)

OK here are my two cents:
As much as I know even operators like + - = * / re functions in fact. I think I have it from Bruce Eckel if I remember right ...and if I am correct. Not that I feel like some authority here :wink:
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

I agree since just look at the definition of a function from wikipedia
an abstract entity that associates an input to a corresponding output according to some rule
Im sure the guys that chose the naming conventions for thing in programming languages followed the alrady exsisting definition.

well you could think of an if statement as the if funtion with the expression inside?
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Luke
Admin
Posts: 449
Joined: Fri Jul 14, 2006 7:55 am
Location: Australia
Contact:

Post by Luke »

I am updating each tile from data array everytime camera change position more than one tile. Sure I can awoid it if I would shift tiles instead of mooving them.

You could draw the tiles based on there x and y position + (or -) the camera position.

And only loop though the tiles that will be on the screen.

Eg:

Code: Select all


//This is not real code....

Tiles[100][100];

TileSize=30? ;

TilesInScreen=15 ;

CamX, CamY;

for (s32 x=CamX/TileSize -1;x<CamX/TileSize +TilesInScreen;++x) 
for (s32 y=CamY/TileSize -1;y<CamY/TileSize +TilesInScreen;++y)
{
	//(you should check the x and y values are safe)

	DrawTile(Tiles[x][y], x*TileSize +CamX, y*TileSize +CamY);
	
}
Frodenius
Posts: 64
Joined: Sun Aug 29, 2004 11:24 am
Location: Germany/Frankfurt
Contact:

Post by Frodenius »

btw: sorry if i missed that, but what do you want to use instead of the if-statement ?
i think its a, no its THE fundemental thing in programming to decide wether to go on with the current string of ops or jump to another. well and how do you do it if not by testing a condition? (e.g. assembler has jnz and its.. well i dont know 1 cycle or so...)
worst programming style ever seen...
Warchief
Posts: 204
Joined: Tue Nov 22, 2005 10:58 am

Post by Warchief »

Frodenius wrote:btw: sorry if i missed that, but what do you want to use instead of the if-statement ?
You can avoid using the if statement using a container without null pointers. It's not the if itself, but looping for a bunch of elements that will never meet the condition.
Warchief's Warboard 3D Now hotseat release
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Not that I am against if() I just want to know what can it's extensive use cause.

Luke >> unfortunately it is not applycable for my problem. Its easier and fasther to update all tiles once, than to check and update vissible tiles every time camera change angle or position.
Luke
Admin
Posts: 449
Joined: Fri Jul 14, 2006 7:55 am
Location: Australia
Contact:

Post by Luke »

unfortunately it is not applycable for my problem. Its easier and fasther to update all tiles once, than to check and update vissible tiles every time camera change angle or position.
So it's not a loop to draw the tiles? It's a loop to update the tiles?

Why are you updating the tiles?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

By drawing tiles one by one I would force most of the computers to standstill. I am drawing tiles in groups.

I am updating them when I change position of terrain. You may look at demo if you wan to understand why.
messen
Posts: 25
Joined: Tue Aug 29, 2006 2:51 pm
Location: Agalon
Contact:

Post by messen »

Hi,

Code: Select all

cmp eax, 1
It is fast indeed.
Luke
Admin
Posts: 449
Joined: Fri Jul 14, 2006 7:55 am
Location: Australia
Contact:

Post by Luke »

By drawing tiles one by one I would force most of the computers to standstill. I am drawing tiles in groups.

I am updating them when I change position of terrain. You may look at demo if you wan to understand why.
Wait, so this is 3D tiles/terrain your talking about, sorry I though it was 2d tiles.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Yes
Post Reply