I have no less than a week’s worth of posts sitting in the queue, in much the same way that wet leaves might sit in your downspout, preventing efficient operation. All of them need that once-over in different places to weed out different places where I re-use words and the bad sentence structure in different places.
Next week I’m going to put up my long-delayed survival horror posts up for Halloween, so some of these posts will be stale by the time we reach them. Which do you prefer, unfinished, or irrelevant? No worries, I can do both!
I should have spent tonight (Thursday) on Friday’s noontime post, but instead I got caught up in a side project…
I’ve mentioned elsewhere that I build my comics using a homebrew program I came up with. It lets me throw down word bubbles and drag the tails around and generally do stuff that would be tedious and time consuming if done by hand.
But for months I’ve been irritated at how long it takes to update a bubble. When I type text into the dialog box, it takes a full second for the program to rebuild the bubble. This makes editing really annoying. At the heart of the problem are the Windows API calls I’m making. I draw the text into an off-screen Bitmap using common Windows text-drawing calls. The same ones used to draw the tooltips and menus in front of you right now if you’re on a Windows machine. But for whatever perverse reason, Windows takes preposterous amount of time to give me the data.
It goes like this:
Me: Hey Windows. You know that bitmap with all the words I just drew?
Windows: Oh yeah. Got it right here. You want me to save that to disk? Or maybe I should draw it on screen for you? Or maybe-
Me: Actually, could you just give it to me?
Windows: You… what? What do you want it for? I can save it or draw it. What else could you possibly…
Me: Please? Just hand over the raw data. I know what I’m doing. Just let me GetBitmapBits ().
Windows: Ok. Geeze. Hang tight. Give me some time to get all that together for you.
Me: But I just need access to data you’ve already got. You could just give me a pointer to…
Windows: Ngh. Huff huff huff. Oh this hurts.
Windows: Oh geeze. Here… it… comes…
Me: We’re talking about 256k of data here. That’s peanuts. This is ridiculous…
Windows: Gasp! Whew. That was a toughie. Here you go. Please don’t ask me to do that again.
Me: Actually, you took so long on that that the user has typed another letter by now. We’ve gotta do it all again.
Windows: Okay. Just give me a second to psyche myself up for this.
Me: Do you understand?!? YOU ARE OPERATING SLOWER THAN A HUMAN BEING CAN TYPE! This is NOT 1987! Pull yourself together!
Windows: Ngh. Huff huff huff. Oh this hurts.
I realized that I could do the job in under a millisecond (about 200 to 500 times faster, depending on the size of the bubble) if I dump the Windows crap and do all my font drawing in OpenGL. (Which is what I’m using to render the comics.) I can eliminate this entire mess by simply drawing into a texture map. The only cost is that I have to re-write all the font-drawing code myself.
This is a terrible time to do something like this, when I’m already behind on my webcomic and I have posts that need my attention. But inspiration (which in this case looks a lot like exasperation) is a capricious master and there’s no use in trying to write jokes when my mind wants to write code.
My program takes text and arranges it in an oval of variable size and aspect. (Never taller than it is wide.) The aesthetic arranging of words in a circular region is insanely complex. This is a job usually done by some sort of “artist” who uses a lot of “intuition”, which is just the sort of thing you want to avoid trying to turn into code.
The only two things I needed from windows is for it to tell me how big a word was (how big of a rectangle it occupies) and for it to draw that word. My program is experimenting with hundreds and hundreds of layouts before it finds just the right one, and then calculates how tight it needs to make the oval to contain the contents. It’s doing all of this complex stuff and then gags on blitting a medium-sized block of data, which should, in a sane world, be so fast I should have trouble measuring it with my millisecond-resolution timer.
I shudder to imagine what madness Windows must be working behind the scenes for it to spend that much time on it.
This is classic programmer behavior: To spend two hours writing code so that I can save a half-second per letter. Why, after 14,400 letters I’ll have saved enough time to justify the work I put into it! (It’s not so much the time that’s motivating me anyway. It’s the desire to Do It Right.)
And I realize I just blew even more time typing this up, but if you’re a programmer you’ll understand why I needed to do this.
The Biggest Game Ever
How did this niche racing game make a gameworld so massive, and why is that a big deal?
Crysis 2 has basically the same plot as Half-Life 2. So why is one a classic and the other simply obnoxious and tiresome?
The game was a dud, and I'm convinced a big part of that is due to the way the game leaned into its story. Its terrible, cringe-inducing story.
The No Politics Rule
Here are 6 reasons why I forbid political discussions on this site. #4 will amaze you. Or not.
I'm a very casual fan of the series, but I gave Civilization VI a look to see what was up with this nuclear war simulator.