Thursday, October 26, 2006

Joyless Soul - meet Mr Big Fuck-off GUI

I wasn't in Madrid that long, was I?

I think I'm going to have to bite the bullet (or chew any other type of ammunition, though that may lead to the swallowing of poison darts) and write my own GUI system.

I've done one before. It didn't work very well, the code was a hideous mess and on some computers it slowed to a crawl. But none of that bothers me this time. First, things are object oriented now - this is good for GUI systems. Secondly, I've picked up a few tricks which I'm interested in trying out along the way.

And thirdly, fuck it. Every time I try a third party solution, it causes me as much hassle as it would be to write my own. There's nothing essentially wrong with these off the shelf GUI engines. For what they're designed to do, they do very well indeed - and they've been excellent to learn from. It's just that what I want to do, and the way I'd like to do it, is not really compatible. I wanted to build a system that would surround a GUI, providing me all the gadgets I need but without the headache inducing method of creating each and every screen through mind-numbing statements littered throughout the code. It needs to be skinnable - incredibly so. It's not enough to change colours, I want a modder to be able to redesign every screen in the game.

The last GUI I've been using was pretty good and I had a working system, but the fourth problem reared its head. Lack of transparency. Things were happening using this GUI that I didn't understand, and they were eating my frame rate - before I'd even so much as started processing any of the game stuff. At this point, that's the last thing I need. I need control, and I'm going to get it.

And the fifth thing? Well, that's the whole reason I started coding in the first place when I was about 10 years old. It's fun. It's fun to achieve things, it's fun to hack things, it's fun to just throw stuff at your computer and learn from the results. Back then I got a buzz from properly generating a random number and recreating Grandstand's Saturday afternoon vidiprinter. Over the last few months I've lost that buzz, and it's making me lose a lot more.

I'm going to have fun again. There will be a game at the end of all this. But if it was just a game I wanted, I'd be playing Football Manager.

Monday, October 09, 2006

Bars and Madrid

Despite the fact that I seem to never update anyway, I thought it wouldn't be a bad idea to let you six (or however many visit these days) know that there'll be no work done over the next four days, because some people who should really know better are sending me off to another country for reasons best known to themselves.

Still, I've almost completed an xml wrapper for the GUI system, and it's working well. It needs a good method of accessing the individual gadgets, and some way of getting the scrollbars to actually do something other than move up and down in a mesmerising but ultimately useless way. I'd kinda like certain things to scroll.

Oh, and properly skinned. I don't really want my game to look like Windows XP. Nobody does.

Tuesday, October 03, 2006

To simplify, treat middleware as your intestinal tract...

Owing to those recent problems that were doing my head in, I've spent the weekend doing my best (my lovely, lazy best) to come up with a viable solution.

Tonight I re-read a reply on the BlitzMax forums regarding the frame rate troubles I've been happen. At first, I had dismissed it as technical details that I wasn't willing to get into, especially when I simply don't have enough knowledge of how BlitzMax is actually working to dare get stuck into its guts and start changing variables.

Nevertheless, at a loss for a solution, I decided to give it a go.

The result was better than I could honestly have hoped.

Remember how the problem was this unwanted delay whilst trying to find out if a key or mouse button is being pressed? Well, tracing the path through the code from that simple KeyDown() function led me into the entrails that make up BlitzMax's innards, where I found the function PollSystem.

The offending function PollSystem.

What does it do? Well, allow me to put my whole heart into this biological analogy I've got going here.

Eating food is pretty simple, yeah? You chew, swallow, and it goes into your stomach, where your body does the rest. Your conscious job, unless you've just had a dodgy chip from the local eatery and are thus doomed to spend the next four hours renacting scenes from Platoon on the ceramic, is over.

Imagine, though, if that wasn't it. Imagine that every time your stomach wanted to do something with that disgustingly fatty yet absolutely deliciously greasy burger, it sent it back to your mouth. Asked you to chew again. And again. And again. Heck, never mind the burger, eating a fucking chip would take forever.

That is how PollSystem works. Or at least that's how it works to my admittedly incomplete knowledge. Every time I ask BlitzMax "is L being pressed?", it goes off and tries to read every single key again. This is just how it works.

On Windows, this is very, very fast. Negligible, in fact, unless you really wanted to make the absolute most of your time. We're talking... (I need a calculator for this) ..... one twenty-five-millionth. Is that a real number? 0.00000004 seconds. It's fucking fast.

On OS X, it's slower. I don't know if it's a bug with BlitzMax, a "quirk" (read fucking stupid flaw) of OS X, or anything, but it's one forty-thousandth in silly named numbers, or 0.0002496 if you want accuracy. That's 624 times slower.

So, what did I do? Well, I made BlitzMax chew its damn food before swallowing, that's what I did. By tweaking a single line, I stop it from calling PollSystem every time I check a key. The proviso is that I must do it myself, once per frame, to ensure that everything works. The result? OS X runs very fast indeed. My test came back telling me it ran six times faster than an untweaked Windows, but that's not a fair comparison for various technical reasons.

The thing eating away at the back of my mind, unfortunately, is that I'm no expert on BlitzMax and I'm not sure what the repercussions are of my tweaking. It does seem strange that the system would automatically be slower than is theoretically possible - however BlitzMax, being middleware, has been built with ease of use in mind every bit as much as power.

I'm hoping that this was simply a feature to keep the system more user friendly for new users. Hopefully someone in the know will clue me in. I'm feeling kind of lucky though, after seeing Watford throw away a 2-0 lead, but still steal an equaliser in the dying minutes to seal a 3-3 draw and win me £50.