Spaceinvaders 104

All working fine here:

Range of 56 to 87 frames per second - JOGL and LWJGL

System: Win XP SP2, Geforce 2MX 64MB, Java 1.4.2_04

Tutorial text is here:

http://www.cokeandcode.com/info/tut2d-4.html

typos/corrections appreciated.

Kev

I find the huge fluctuation in framerates odd, considering that frame-to-frame it’s drawing the same stuff over and over.

Cas :slight_smile:

Yep, same here. Specially as on most systems we’re seeing exactly 100 fps or vsync limited.

I keep wondering if its something to do with Gage Timer on hyperthreading machines. I tried to contact jbanes but the email address I had seems to be bouncing. I might give LWJGL timer a try, just to see if its sorts it out.

Kev

Just so you know: I do not have a hyper threaded machine: it is a 1Ghz PIII. the fluctuations appears when taking input from the keyboard.

Could you guys try this one out for me:

http://www.cokeandcode.com/spaceinvaders104/si104-timer.jnlp

Kev

PS. Uh, you’ve got a hyperthreaded P3? Do they exist?

[quote]Uh, you’ve got a hyperthreaded P3? Do they exist?
[/quote]

LWJGL: 82 - 86 fps
JOGL: 81 - 86 fps
Java 2D: 96 - 100 fps (although, it didn’t look as smooth)

Ah ha! Thanks for that Abuse.

What graphics card is that on, its more likely just an issue there if you’re seeing problems on all renderers.

Kev

Still weird. Fast, slow, fast, slow, etc. under LWJGL. But I think it’s actually because it’s incapable of running at a smooth 100fps - the most it can manage is 70fps or so. Set the time down to 60 and it’s smooth as glass.

Cas :slight_smile:

It runs perfectly well in all modes on my machine.

Java2d: 100fps
JoGL: 75fps (vsync / 100 without)
LWJGL: 75fps (vsync / 100 without)

Specs: K7 500, gf2mx, win98se, 1.4.2_03, 32.82deto

But I think it’s actually because it’s incapable of running at a smooth 100fps

Can’t be. Just look at my shitty machine with is able to do that.

Eventually QPC is to blame?


#include <windows.h>
#include <stdio.h>

int main() {

   LARGE_INTEGER liFrequency;
   LARGE_INTEGER liCurrent;
   LARGE_INTEGER liLast;
   LARGE_INTEGER liRecent[10];
   DWORD dwCurrent;
   DWORD dwLast;
   DWORD dwPerfElapsed;
   DWORD dwTickElapsed;
   int i = 0;
   int j;

   // Save the performance counter frequency for later use.
   if (!QueryPerformanceFrequency(&liFrequency))
      printf("QPF() failed with error %d\n", GetLastError());

   // Query the performance counter value and tick count.
   dwCurrent = GetTickCount();
   if (!QueryPerformanceCounter(&liCurrent))
      printf("QPC() failed with error %d\n", GetLastError());

   liLast = liCurrent;
   dwLast = dwCurrent;

   while (TRUE) {

      // Query the performance counter value and tick count.
      if (!QueryPerformanceCounter(&liCurrent))
         printf("QPC() failed with error %d\n", GetLastError());
      dwCurrent = GetTickCount();

      // Store the performance counter value in the list of recent values.
      liRecent[i].QuadPart = liCurrent.QuadPart;
      i = (i+1) % 10;

      // Convert difference in performance counter values to milliseconds.
      dwPerfElapsed = (DWORD) (((liCurrent.QuadPart - liLast.QuadPart)
            * 1000) / liFrequency.QuadPart);

      dwTickElapsed = dwCurrent - dwLast;

      // Check for a discrepancy greater than 500 milliseconds.
      if (abs(dwPerfElapsed - dwTickElapsed) > 500) {

         // Print the previous 9 performance-counter values.
         for (j=9; j>0; j--) {
            printf("      Previous %d:  %I64X\n", j, liRecent[i].QuadPart);
            i = (i+1) % 10;
         }

         // Print the leap value.
         printf( "LEAP: Current:     %I64X  delta = %I64X\n",
               liCurrent.QuadPart, liCurrent.QuadPart - liLast.QuadPart);

         // Retrieve and print the next 9 performance-counter values.
         for (j=1; j<=9; j++) {

            QueryPerformanceCounter(&liCurrent);
            printf("      Next     %d:  %I64X\n", j, liCurrent.QuadPart);

            liRecent[i].QuadPart = liCurrent.QuadPart;
            i = (i+1) % 10;
         }

         printf("\n");
      }

      liLast = liCurrent;
      dwLast = dwCurrent;
   }

   return 0;
}

That’s a test programm from MS. If it ever prints out some text your machine has a dodgy timer.

The latest nVidia drivers appear a little odd for me, a windowed LWJGL app runs significantly slower (somewhere in the region of about 40fps) than the exact same one running fullscreen (which constantly hits its target of 60fps). Dunno whether this is skewing the fps for this…

Graphics Card: Geforce 2 MX 64MB - not the best, but its should be easliy able to handle at least a magnitude more computations per second.

[quote]Eventually QPC is to blame?

That’s a test programm from MS. If it ever prints out some text your machine has a dodgy timer.
[/quote]
QueryPerformanceCounter is known not to work properly on multi-processor systems. A workaround is to make sure you only call it on a single processor by setting the processor affinity.

Fiddling with the affinity didn’t help.

And besides, all of my stuff works perfectly well on this machine and doesn’t suffer from the strange fast/slow/fast/slow effect.

I’m beginning to suspect that Nvidia have done something funny with the immediate mode glBegin/End implementation.

Cas :slight_smile:

I’m beginning to suspect that Nvidia have done something
funny with the immediate mode glBegin/End implementation.

Hmm… eventually flushing helps? (*)

(* guess work)

Some more mac feedback:

LWJGL: -
JOGL: 99 - 100 (only in the first 5 seconds does the frame rate drop to 99)
Java2D: 43 - 58 (starts off at 43, but as enemies are killed the fps slowly increases).

Sys: Mac OS X (10.3.4), Java 1.4.2_03, Radeon 9700 128MB

[quote]Yep, same here. Specially as on most systems we’re seeing exactly 100 fps or vsync limited.

I keep wondering if its something to do with Gage Timer on hyperthreading machines. I tried to contact jbanes but the email address I had seems to be bouncing. I might give LWJGL timer a try, just to see if its sorts it out.

Kev
[/quote]
Hi Kev,

Just got done with some pretty stressful writing work. Were you emailing to jbanes@techie.com? That address should work. I suppose it’s possible that my mail provider doesn’t like your email host. You can always try emailing to jbanes@gmail.com. Just got it, and I’m loving it. ;D

As for HyperThreading, it seems to be a problem on Java overall, and can produce some pretty weird results. For example, I’ve got at least one report against DataDino that it uses a constant 50% CPU on HyperThreaded machines. Considering that the program doesn’t do anything when it’s idling, the report is very strange indeed. Definitely something to keep an eye on.

I get a cokeandcode.com not found error when I try to browse there. Did the net hiccup or is something down for a bit?

Regards,
Aaron R>

I do apologise, the newdawnsoftware and cokeandcode domains are currently offline due to machine outage. No predicted time of recovery as yet either.

This also means I’m not answering or sending mails :frowning:

Kev