Grotesque: fun to say, fun to be.
Not a Member? - Login or Create an Account...MC Offline
Wednesday the 21st of March 2018 @ 07:02am
Front Page Projects Your Profile About

Filed Under: Journal - Development - Game Development

Speed & Selection

2003.06.25 09:24pm
So I had intended to do some interface code, and as it turns out I wasn't quite ready for it. At least not as ready as I had thought. Drawing stuff isn't really a problem any more, it turns out that actually interacting with things on the screen was a bit less trivial than I had expected. The way I figure, most of my interface with widgets will all be taking place in an orthographic projection, so the coordinate maps will be really easy to map. That is, the mouse is @ x,y in real screen resolution, and I can easily scale it to the orthographic coordinates that widgets exist on. It occured to me though that I had no way of selecting anything that wasn't rendered on the orthographic layer. So, I had to take a brief trip into OpenGL selection.

You know, I'm working witht he selection mode now and I can't help but feel like this isn't the way it's done in reality. I mean it works, but it seems more than a little cludgy to re-render the scene over again just to find out what the mouse has clicked on. But look as I may the only method that seems to be described over and over is using selection. Anyway. I took my orc model toy and set it up to do selections on it, and got the code in place and it DID work, but good lord was it slow. When I did the Md2 class I was basically just hacking to get it working. Not dirty, but not fast either. I set up three of my 'dancing' orcs and everything worked like a charm, but when the mouse was clicked it was rendering eight copies, four visually and four for the selection... and damn was it slow. The frame rate was diving to around 20-30 fps when the mouse button was down.

My little orc models aren't terribly complicated, so rendering eight of them shouldn't have been causing THAT kind of speed drop. So, even though I wasn't planning on doing any optimization until the end I was stuck messing with the Md2 class just to get it to work under TEST conditions. It was prety depressing. I hadn't expected any test scenario to run into speed problems, not on the hardware I'm running here, but herer I was with a simple scene, unlit even, and it was a dog.

I figured I should set up a baseline test, so I set up the camera and positions and disabled my checkboard floor and mouse cursor and got to work with some optimizations. Just to quickly start I did some pre-calculations for the verticies and texture maps and unrolled a loop, figuring I'd buy myself a couple extra fps and boy, was I ever suprised. When I started my baseline code was running at about 55.3 fps, after the optimizations it shot up to 425.7 fps. Not exactly a small gain. Not only did the speed increase, but I found a bug in my vertex transformations that was causing the z-axis to be a little fuddled. Something to do with reversing the axies before doing my translations.

So, yay! About an hour later, a bug fixed and a ~ 700% speed improvement everything was good to go. The only thing left is to disable the texture rendering when doing the selection, and maybe find a way to render a simplified model. Even without things are acceptable again, so I'm happy.

After my success with the md2 class I dug into my particle engine to see if I could buy some quick improvements in that code too. I probably shouldn't have, because I didn't have nearly the luck I did with the md2's. I moved some of the billboard calculations out of the render method and grouped my particles by texture but it didn't buy more than a 5-10 fps increase for 5000 particles. I'm not sure what to do about it now, exactly. I know I can get about 10,000 particles to run at ~30 fps if I lower the particle size, but it just doesn't look as good. *shrugs* Anyway, I doubt I'll get into any scenario's with Onyx that even require two thousand particles at once, let alone ten thousand, so maybe it won't be a big deal.

Just for the fun of it here's a screen shot of the fps test and selection code. The models clip into each other all over the place, but it gives the idea. Notice the nicely rendered hyperion font (anti-aliased, even) and the little orc-hand mouse cursor in the bottom right-ish corner of the image. Even casts a shadow... that's how bored I was. For even more fun I threw in a shot of the particle fountain running with 10,000 particles. Well, 9892 particles, with the target being ten thousand. It's been reduced to 800x600 from 1024x768. Nothing new or exciting about it, just makes the screen shot row two wide instead of one, which looks lonely.

Anyway, now that I have selection code working (which I'm not even going to use for the menus) and some more experience I think I'll try again on my widget code tonight. And I still need a stupid keyboard manager as well. I'm not super clear on how to move focus around, and how exactly to set up buttons and text boxes vs. their input controls... but hey, if I knew it wouldn't be any fun, right?

So... back to it.



Reader Comments

©2018 Aaron Cameron