Asteroids tutorial problem

Started by Trudko, November 23, 2006, 08:34:20

Previous topic - Next topic

Trudko

Hi Iam just studying LWJGL Asteroids tutorial and I found out who problems in first lection.
1.
I don't under stand:
Quote
DisplayMode[] modes = Display.getAvailableDisplayModes();
DisplayMode mode = null;

for (int i=0;i<modes.length;i++) {
if ((modes.getBitsPerPixel() == bpp) || (mode == null)) {
if ((modes.getWidth() == width) && (modes.getHeight() == height)) {
mode = modes;
}
}
}

Why he is checking in condition mode == null ? Could this condition be like:
(modes.getWidth() == width) && (modes.getHeight() == height) && (modes.getBitsPerPixel() == bpp ) )... return modes
2.
In gameLoop he is using funkcion geTime() to check time to loop the function looks:
Quoteprivate static long getTime() {
      return (Sys.getTime() * 1000)/ Sys.getTimerResolution() ;
   }
In this I don't understatnd what is Sys.getTimerResoluton for, because I found out through System.Out.println... that the amount of it is 1000. Its make no sense to multiply it by 1000 and then divide it by 1000. But I think that I dont really understood the Sys.geTimer Resolution function.

Fool Running

QuoteWhy he is checking in condition mode == null ? Could this condition be like:
(modes[i].getWidth() == width) && (modes[i].getHeight() == height) && (modes[i].getBitsPerPixel() == bpp ) )... return modes[i]
Its saying that if we find a mode that has the same width and height and we don't have a mode yet, then use that mode no matter what the bpp is. This keeps us from saying we want 32bpp and its on linux and only shows up as 24bpp. (I think that's right) Also, if the machine doesn't support 32bpp, only 16bpp, then we still find a mode to change to (the 16bpp mode).
QuoteIn this I don't understatnd what is Sys.getTimerResoluton for, because I found out through System.Out.println... that the amount of it is 1000. Its make no sense to multiply it by 1000 and then divide it by 1000. But I think that I dont really understood the Sys.geTimer Resolution function.
The Sys.getTimerResolution() used to return values other than 1000, but I still don't know why its being multiplied by 1000 :lol:
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

kevglass

The time method wants to return the time in milliseconds.

Sys.getTime() returns the current time in "ticks"
Sys.getTimerResolution() returns the number of ticks per second.

So, Sys.getTime() / Sys.getTimerResolution() would give you the time in seconds. Multiplying by 1000 converts this to milliseconds. It's done before the division to prevent losing accuracy because of integer division.

Kev