I’ve done a huge refactoring of our game project, DVW, over the weekend. One reason was that I could not see the GUI code anymore. It was a mess! Most of the stuff was about four years old, and it looked like 40 years old or so. So I was spending the whole Friday night to rearrange things, move attributes and methods up to the parent class, remove some redundant stuff, and I even killed about 1000 lines of code by simply removing some GUI controls which were not used any longer and which were buggy as hell.
The main reason was that I am currently writing the main menu code which is completely controlled from a Lua script. I didn’t want it to be hardcoded, because I don’t want to be the one who needs to do all the fine tuning with all the visual effects we’re going to have. We have people who are much more talented with this detail work.
I wrote a state machine which supports multiple states at once, so that a single effect in the menu is represented by a state. For example, we have very short background videos playing between every menu dialog (a quick camera move which shows the Earth from different points in space, really cool), so this transistion is a state which shows the video, waits until it’s finished, and terminates, or triggers other states to start. In the meantime, another state is responsible to clean up the old GUI controls (i.e., they’re flying out of the screen, fading out, or whatever), while a third one moves the new controls in. And a fourth “randomizer” is responsible to create some effects from time to time (which are states, as well), e.g. some explosions on the Earth in the background, or some static (read: noise) in the background image, or a little falling star, and so on and so on. I’m sure it will become pretty cool if my poor programmers art is replaced with real artwork from our fantastic artists.
All this is done with our Lua API, a set of 100+ commands which interfere with the C++ part of the game logic. It isn’t just about GUI stuff; you can control roughly everything one could control with the mouse, and even more. You can move units, assign groups, move groups, evaluate influence maps, make factories produce a unit, search resources, play sound effects, crossfade music, select the next map to play, move the camera over the map, and so on and so on. Although the way I wrote the API isn’t the best one, I’m quite happy with the result.
Our lead tester is using it to tweak DVW to the maximum – he does things that I had never dreamed about! He has become our lead scripter in the meantime, and I am doing my best to support his efforts, as the outcome in turn is well worth my effort. So well, that’s it about my satisfying weekend.
Published on April 11, 2005