if(): howe much time consuming it is?
My first idea is probably a bad one as far as speed is concerned. I was looking for a way to not use "if", I forgot the problem was about speed.
It's possible what I read about using a pointer that way being faster was outdated. It's just something to consider. If you try it remember not to increment the original.
It's possible what I read about using a pointer that way being faster was outdated. It's just something to consider. If you try it remember not to increment the original.
Hmms allot of this stuff is a bit complex for my understanding, but since these are tiles i would employ a chess piece approach:
1-ignore tiles behind camera
2-ignore tiles beyond draw distance
3- in collision detect ignore tiles that are a distance > velocity of object*time tick
that way non interactive/ hidden tiles arent even refrence since all the distance calculations are adds rather than the tradtional distance formula
ie all your distances are in tile units so rendering 500 units of draw distance infront of the camera would call where each tile is 100 units
x= camera tile
[x]
[x+1]
[x+2]
[x+3]
[x+4]
[x+5]
1-ignore tiles behind camera
2-ignore tiles beyond draw distance
3- in collision detect ignore tiles that are a distance > velocity of object*time tick
that way non interactive/ hidden tiles arent even refrence since all the distance calculations are adds rather than the tradtional distance formula
ie all your distances are in tile units so rendering 500 units of draw distance infront of the camera would call where each tile is 100 units
x= camera tile
[x]
[x+1]
[x+2]
[x+3]
[x+4]
[x+5]
"Irrlicht is obese"
If you want modern rendering techniques learn how to make them or go to the engine next door =p
If you want modern rendering techniques learn how to make them or go to the engine next door =p
It is not so easy
normaly whole terrain with all tiles is a single mesh. By spliting terrain in to individual tiles you would efectively kill performance of your program.
I tried to split individual tiles in to mesh buffers = same result as spliting mesh.
So what I finaly did is to split terrain in to groups of tiles, each with its own mesh buffer. Number of mesh buffers is limited to 25. I test if mesh buffer is on screen each loop and let render only those which are. Works fine.
There would be possibility to test each tile and refill indice array each loop. I was not triing that so I don't know howe well it would work.
normaly whole terrain with all tiles is a single mesh. By spliting terrain in to individual tiles you would efectively kill performance of your program.
I tried to split individual tiles in to mesh buffers = same result as spliting mesh.
So what I finaly did is to split terrain in to groups of tiles, each with its own mesh buffer. Number of mesh buffers is limited to 25. I test if mesh buffer is on screen each loop and let render only those which are. Works fine.
There would be possibility to test each tile and refill indice array each loop. I was not triing that so I don't know howe well it would work.
Im not sure if this would easily be implemented in irrlicht but indexed vertexbuffers in ogl and dx could be used, each tile can be stored in the vertex ram(sent once) while the tile engine just sends its index to the gpu every cycle which would be one integer instead of (3 pos,2 texcoord*number of textures,4 color,3 normal)
"Irrlicht is obese"
If you want modern rendering techniques learn how to make them or go to the engine next door =p
If you want modern rendering techniques learn how to make them or go to the engine next door =p
-
- Posts: 279
- Joined: Fri Dec 24, 2004 6:37 pm
I am not in the current discussion as i hav a headache and not in quite the talkative mood, but i just did a bench mark just for fun and saw that a 1million ifs just cheking a bool without any if and doing nothing take <1ms using vc6 compiler! So i think i think you are safe using a lot of ifs!
BTW Heres the way i did the bench mark, it showed me 0ms so its less then 1ms:
BTW Heres the way i did the bench mark, it showed me 0ms so its less then 1ms:
Code: Select all
#include <iostream.h>
#include <time.h>
#include <windows.h>
#include <mmsystem.h>
#pragma comment( lib, "winmm.lib")
#define getHighPerformanceTime timeGetTime
#define BOOL_ARRAY_LENGTH 100000
int main()
{
bool temp[BOOL_ARRAY_LENGTH];
srand ( time(NULL) );
for (int i=0; i<BOOL_ARRAY_LENGTH; i++)
temp[i] = rand()%2;
long beforeIfTest = getHighPerformanceTime();
for (i=0; i<BOOL_ARRAY_LENGTH; i++)
{
if (temp[i] = true)
{
}
}
long afterIfTest = getHighPerformanceTime();
cout << BOOL_ARRAY_LENGTH << " number of ifs take " << (afterIfTest - beforeIfTest) << " ms" << endl;
return 0;
}
Code: Select all
for (i=0; i<BOOL_ARRAY_LENGTH; i++)
{
if (temp[i] = true)
{
}
}
Irrlicht Demos: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=6&t=45781
Lol, sio2’s right,
a lot of people make that mistake of measuring loops, etc that compiler wipes.
Compilers are pretty good now days, I pretty sure the compiler can even optimise stuff like:
to just add BOOL_ARRAY_LENGTH to n. (and i)
about this if stuff, to many people think about this low level stuff to early, when you can get the real speed ups from the high level design of the code, I mean why are you looping though 100 x 100 objects in the first place, in most cases you can avoid it (or at least not do the full loop in one update)
a lot of people make that mistake of measuring loops, etc that compiler wipes.
Compilers are pretty good now days, I pretty sure the compiler can even optimise stuff like:
Code: Select all
for (i=0; i<BOOL_ARRAY_LENGTH; i++)
{
n++;
}
about this if stuff, to many people think about this low level stuff to early, when you can get the real speed ups from the high level design of the code, I mean why are you looping though 100 x 100 objects in the first place, in most cases you can avoid it (or at least not do the full loop in one update)
omaremad >> well I do not intend to rebuild whole Irrlicht engine, I am not that good programer, nor I have enough time for that so I think I will stick with what is at hand But thanks anyway
RapchikProgrammer >> howe is your head hope you feel better thanks for testing, however I am also not sure is such a strayforward approach gives correct result as already mentioned. But your test gave me some idea: Ill try to run my loop with if() and then without ...of course making sure firsth that all pointers are vallid.
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.
RapchikProgrammer >> howe is your head hope you feel better thanks for testing, however I am also not sure is such a strayforward approach gives correct result as already mentioned. But your test gave me some idea: Ill try to run my loop with if() and then without ...of course making sure firsth that all pointers are vallid.
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.
-
- Posts: 279
- Joined: Fri Dec 24, 2004 6:37 pm
Firstly i have tried both with an n++ and without one and there was no difference in vc6 at least have no idea about other compilers that means vc6 doesnt ignore it! With or without n++ ait showed me 0ms that is <1ms!
And ya, my bad its 100,000! For a million it took me 11ms, but my pc is running a LOT of different programs rit now so it shud take about 10-11ms in my opinion! Even then i dont think its gonna hurt your performance a lot!
And ya, my bad its 100,000! For a million it took me 11ms, but my pc is running a LOT of different programs rit now so it shud take about 10-11ms in my opinion! Even then i dont think its gonna hurt your performance a lot!