Kenneth Gorking, on 31 December 2012 - 04:47 PM, said:
Keep in mind that casting a float to int, internally generates a call to ftol, which is quite slow. As for the VSync issue, I watched a Google I/O video yesterday that describes it pretty well, and why it helps:
thanks for the video, ill watch that as soon as i can ( got work atm) but about the casting a float to int, which is slow.
in the tutorial i followed they had 1 part where they zoomed into a image by a float deltax:
[size=3]Surface* img = [/size][size=3]new [/size][size=3]Surface( "assets/aagun.tga" );[/size]
float dx = 2.0f;
void Game::Tick( float a_DT )
{
Pixel* screen = m_Screen->GetBuffer(), *image = img->GetBuffer();
for ( int x = 0; x < SCRWIDTH; x++ )
for ( int y = 0; y < img->GetHeight(); y++ )
{
int readxpos = (int)(dx * x);
Pixel sample = image[readxpos + y * img->GetPitch()];
screen[x + y * m_Screen->GetPitch()] = sample;
}
dx *= 0.999f;
Sleep( 10 );
}
they later changed that into
Surface* img = new Surface( "assets/aagun.tga" );
int dx = (int)(2.0f * 1024.0f);
void Game::Tick( float a_DT )
{
Pixel* screen = m_Screen->GetBuffer(), *image = img->GetBuffer();
for ( int x = 0; x < SCRWIDTH; x++ )
for ( int y = 0; y < img->GetHeight(); y++ )
{
int readxpos = (dx * x) >> 10;
Pixel sample = image[readxpos + y * img->GetPitch()];
screen[x + y * m_Screen->GetPitch()] = sample;
}
dx = (dx * 999) >> 10;
Sleep( 10 );
}
and this was indeed quit a bit faster
was this what you meant and would you advise this?
(just to prevent explenation, i understand the concept of this bitshift, and i understand why it is faster, im just asking if it is worth it to change the code to get this, as im making this as an assignment to get into the NHTV "game architecture and design" study (the programming part), and this is the first actual game im making, so i want it to be good, and the second good point is that it would be best to not learn things wrong at the start, to prevent bad habbits













