First Person tricks

Hey folks, I’m working on a first person game. Right now, it’s nothing more than an environment of walls and sprites that you can wonder around in. However, I find I’m running into way more problems with framerate than I’d have expected. I was averaging 32, occasionally dipping down to 16, and this is way before I’ve tried ot put in any of the fancier graphics, AI, and colision tests(!). I implemented face culling, frustum culling, and sorting my walls, but found it to have a negligable improvement. Using a profiler, I found that if I just sort sprites, I’m spending 18% of my cpu on sorting lists and 30% on “WindowsOnscreenGLContext.swapBuffers.” When I start sorting walls, I essentially trade, to 28% on sorting lists and 18% on swappin’ buffers. I’m sorting using a bubble sort which stops once the list is sorted. I’m hardware accelerated and dubble buffered. I guess it could be an issue that I’m running at 1280 x 1024 resolution, but if at all possible I’d rather not mess with that.

Thanks,
Nick

[EDIT: It’s interesting to note, if I set the window size to just 800 x 600, it runs at a steady 64. BUT, if I take that 800x600 window, and enter fullscreen mode via device.setFullScreenWindow( this ), it still flickers to 32, and occasionally even 16 in narrow corridors. After a bit of tinkering, I’ve got a suspition that the size of the window before you enter fullscreen mode that way doesn’t matter. I know I’ve seen JoGL programs which make that distinctive click when it changes you’re resolution.]

It sounds to me like you need to draw less stuff. are you culling based on visibility?
For instance, if your character is in a small room without windows, there is no need to draw anything outside of the room that the character cannot possibly see. There are diverse methods to achieve this culling, none of which I can talk about with any authority, but they will be well documented somewhere on the net.

I’ve also just noticed that you’re using bubble sort. This is bad, doubly so on arrays/ArrayLists/Vectors. Bubble sort is essentially used in computer science courses as an introduction to sorting algorithms, and will be torn apart and humiliated as more advanced algorithms are taught. There are notable exceptions however - Bubble sort is quite quick with low numbers of elements, it only scales abominably.
Check out this page for graphical demos of a load of different sorting algorithms. Also note that there is a MergeSort already implemented for you in Java.

Of course, 95% of the time bubble sort is horrible. I’m only using it here, bucause I figured, from frame to frame, there are likely to be few changes in the order. Therefore, I thought a few bubblings would take much less time than a full sort of a list that’s pretty close to sorted.

[EDIT: That is to say, if I have one or two things, one or two slots out of place, it seems better to just bubble them right]

As to visibility culling, right now, I just have one big area, so it’d be very tricky to divide it into rooms. But possible if nessessary. I’d thought Frustum culling would make a bigger dent in the number of things drawn.

Looks like you need to disable vsync.?

Do you have any idea of the number of triangles you’re pushing?

This other thread might give you some performance hints:
http://www.java-gaming.org/forums/index.php?topic=14284.0

Apparently, the quickest way to slow down your application, is to have lots of small glBegin() - glEnd() blocks, in interactive mode.

que?