I'll admit, I'm rather ashamed by how long it's been since the last time that I wrote a dev journal. The trouble is, I usually feel that what I'm working on is not interesting to end users (particularly the ones who aren't programmers). The stuff that I work on is usually not visible, unless it's a screen. It's usually something like data manipulation or i/o or something like that. I've been told I'm wrong, but I don't really expect many people to get as geeked as I do about generic xml parsers. Also, I know that I spend too much time trying to write a good article when I could be spending that time coding, doing the second level tech support, or going home on time instead of working late like the workaholic I am.
However, the last few weeks I've actually been working with graphics code: I've been re-writing the minimap. I had to deal with the minimap code in GalCiv1, and it was neither efficient nor that good looking and I was sick of trying to get the 2D drawing to look a little nicer. So I made one of the other coders do the minimap for GalCiv2, and he used GDI which, to be fair, looked nicer than the GalCiv1 minimap code. GDI has always been inefficient, but 2D used to have hardware acceleration support before 3D became the be-all, end-all of the game industry. (Note: I really like 3D and it makes a lot of things easier that would be horribly inefficient in 2D. But I'm not a fan of throwing out the baby with the bathwater.)
Anyway, in Windows Vista, GDI is horribly slow. So whenever the minimap was drawing, it was dragging down the framerate, particularly when scrolling because that causes the minimap to re-draw a lot. Not to mention that the code to draw the fog of war, ship ranges, and zone of control on the minimap was really inefficient. Basically, it was setting the color of each pixel in the minimap one at a time. The ship ranges code was even worse in that it was simulating alpha-blending by checking to see what the current color of the pixel was, multiplying it by 0.5, and then setting it again. I wasn't aware of just how bad this code was until I had to get in and start re-writing it, or I might have done this sooner. Also, it had seemed that the scrolling slowdown was an NVidia bug because ATI cards don't seem to have as much of a problem.
Last week, I put up a link to a test build where I replaced the calls to the GDI functions with the GalCiv1 drawing code. I tried this first because I was able to get it done fairly quickly, and it was code that I was already familiar with. I was hoping that since it used assembly code for copying the pixel colors that it would be some kind of improvement over GDI. Unfortunately, the people who tried it reported no change, so it was back to the drawing board. Our graphics gurus were working on other things that I didn't want to pull them off of, which meant that I was going to have to do it myself.
This time, I knew that I had to use Direct3D. For me, graphics code is not fun to write. I can do it, but since I don't do it that often, I have to look up a lot of stuff, usually several times. I wrote the code that displays the user inteface in GalCiv2, but that was fairly simple and only involved one kind of primitive: triangle strips. (For those of you who don't know what that means, it means that all of the graphics that make up the interface are displayed as triangles that are connected so that they form rectangles called quads. Just picture a square with a line drawn from the bottom left corner of the square to the top right corner of the square.) That was also quite awhile ago, because we used the code first for Political Machine which came out in 2004. Now I had to become familiar with the other primitive types so that I could learn how to draw things like circles.
I finally got the new code compiling and running without crashing yesterday late in the day, but it wasn't displaying correctly. I finally left an hour after I had been planning to leave and spent most of today debugging it. I now have it to the point where almost everything displays correctly. The starbases are practically invisible even on tiny galaxies, so I'll need to work on that. There's also this bug where the minimap shows up (before it's rotated) at the upper left hand corner of the screen briefly when the game first starts, instead of where it's supposed to be. Furthermore, there are a few more things I can do to make the minimap draw more efficiently. But it was good enough to try it out on my Vista test box, and I'm getting far better framerates than I was before. I'm also getting better framerates on XP. Yay! Next week, I'll also fix the line graphs to be more efficient.
The best thing about all of this is that we'll be able to re-use this new 2D drawing code for our next games, so my time was not entirely wasted.
Edit: I've added a link to an updated test build if any of you want to try it. But make sure that you back up your existing GC2DarkAvatar.exe and Lib3D.dll files. You should have the latest version off Stardock Central (1.59.078) installed before extracting the files in this zip.
Also, I made the text blue in the hopes that it would show up better on the galciv2 forums and journals page.
Link