Wednesday, June 21, 2006

The Art and Science of Wheel Invention

I am getting closer to revisiting my first post but until then here are thoughts on my latest task...
- A word of caution, todays post makes heavy use of italics, “quotes”, gratuitous use of the words invent and wheel, and other devices (like this) to denote tone; this is a very vocal post because there is collision in terms between concrete and abstract throughout. I apologize in advance that I couldn't recite it to you personally.

Reinventing the wheel is BAD! Bad I tell you!” (it's been pointed out since I first posted this that often someone telling you that is selling something)

Well, I won't tell you, but everyone else will. (neither will this guy)

I think the phrase "You shouldn't reinvent the wheel" (or something similar) is the real issue. To correctly apply the analogy of wheel production, I think what developers actually do is remake a wheel, not reinvent the whole of the concept of a wheel (design patterns are more like inventing wheels, implementing the pattern is more like making wheels)

And remaking a wheel is just fine.

For artists this idea doesn't apply very often. Why is that? Are they naturally less likely to reinvent? No, it's simply because they don't equate making a new character (or “art”) as reinventing characters (or “art”). They have the idea of character in mind already, they just need to make a specific character (or object or world). Rarely does an artist reinvent character, and if they really did that, I can't see that as bad, that seems like a really amazing, interesting achievement.

The problem is our game engine needs a decent glyph font overlay system. We've had overlays in different forms for a long time (items, speedometer, map, etc), but not an honest-to-goodness, any string, print to the screen, glyph-based text (great texture tool for this) display needed for game-to-player messages. This project at the game level has reached an impasse and a text overlay system must be added. (many developers may be thinking, "you didn't have text overlays done yet! why am I reading this guy's crap!" but the fact is the overlay system had done the job for many demos in the past and did the job for the existing game design. It's true however that for a reusable engine this is desirable but then each game often reimplements at least part of this to make it totally customized - barring the small growth of UI middleware, but I digress...)

And then there's that whole inventing of the wheels thing.

So I searched, hunted, downloaded, tested; if you are a developer on the 'net these days you know the drill. Fortunately for me I only spent a good day on this process, having repeated this so many times before for other needed components I've learned to give up quickly (yet another form of reinventing the wheel, the wheel of finding wheels). So you probably guessed it, I went ahead against all that is holy in the world of code and dogma, and...wait for it... REINVENTED the $%#%&@ wheel. (this is not technically correct as per my opening remarks because I know what I wanted/needed, a glyph font overlay system which is the idea of “wheel” - but I just will have to write it - remake A wheel)

As usual in my experience when given enough time to really imagine and think about the problem, I start to mentally construct the wheel using some of what I know I have, extending that, moving things around, and above all imagining the final product. While dreading this diversion from my other seemingly more important development duties, I stumble upon a particular effect (this is in my imagination, mind you) that is so interesting, so compelling, so FUN that it really begins to drive my motivation. And it reveals a solution path that in the end is far better than any other system I managed to examine earlier.

When the player is done reading the glyph font messages, I want them to fall out of the box/bubble/overlay container right onto my character's head. That's it. It's so simple to state and imagine.

Not so simple to code. Hmmmm, unless I use our particle system as the basis for the font system which is an obvious choice when you imagine a bunch of letters falling, which is exactly a particle system.

And that is exactly what I did.

Large image

This series of images shows the text in action. The first frames show the text typing out to the overlay area (which is the whole screen here) in 2D as expected. Then I trigger the conversion to 3D space (each letter is a 3D particle but in screen space to start, so for example, the Z coordinates are 0.0). The particles are unprojected out into 3D space (instantaneously, visually there is no change) which ultimately means they move, scale and start falling, and then interacting with the game. This effect is nearly as I want (the final version will have collision with the character so they can get annoyed but this behavior) and it could be called metagaming, like this.

So I have plenty of work still to do to get it really usable, and then even more to production level. On the way though, my particle system has had a bit of an overall with many improvements and more to come to support the text system. Incidentally, this isn't a all-equal size letter system like most. Because of that nice AngelCode tool that properly packs the letters AND gives you the character data needed to lay them out, the visual quality is quite good.

And I got to learn about kerning, which I'd never heard of and didn't know about, and gained me a bit more respect for people that work with fonts regularly. There is a secret complexity and elegance there hidden away that you experience directly but never really know about – very much like code often has.

And in some since I reinvented the wheel. I mean I really reinvented the wheel. I'm sure there are games that have this text effect, but I was not aware of them. So since I was forced (choose?) to remake the wheel and having not really known the invention well and in going through the process I ended up with something a little different, but what I wanted none-the-less. In fact, trying to get this effect with other systems was not possible.

So, it's true, we should try not to reinvent wheels.

Remaking them is just fine and often yields a better wheel.

And sometimes it really pays to remake a wheel because you just might reinvent it. (your mileage may vary)


Anonymous Anonymous said...

There is nothing wrong with remaking the wheel, as there isnt' anything wrong with reinventing it, because it might make you a milloinare (as Bridgestone tyres have found out ;))

Hehe, lovely blog, keep em coming.


9:15 AM  
Anonymous Anonymous said...

I'm happy to hear someone else disagree with the "reinventing the wheel" belief. I've visited too many development forums where developers criticize others for building something that has already been done. Understand that I fully agree with reuse and the "product line" philosphy of software design and development. But if you continue to use the same wheel and not try to improve it, then you will find yourself with a new and improve top of the line automobile with 1950 style tires. Just my two cents. jfelrod1960

2:43 PM  
Anonymous gdmike said...

Fonts as particles - now there's something I never would have thought of. And I agree with you on the wheel bit. Sometimes, the existing wheels just don't fit.

12:22 AM  
Blogger Shawn Kendall said...

Thanks for the comments everyone. I really appreciate the feedback!

6:36 AM  

Post a Comment

Links to this post:

Create a Link

<< Home