Setup screen, part deux
Thursday, April 27th, 2006I got my first spam comment on the blog. As Strong Bad would say: “DELETED!”
Lately I’ve been working on the setup screen I mentioned in my previous post. That screen poses some interesting implementation challenges, for an RTS game. In single-player games, it’s pretty simple. The user tweaks a bunch of game parameters, hits Start, and boom! off you go. But in multi-player mode, it is really a different beast. The setup dialog essentially becomes a networked, cooperative dialog. Each remote user is responsible for filling in his own race, team, etc. in his player slot. Then the local user, the guy who created the game, fills in all the general parameters. So you’ve got this one “virtual” dialog, where different users fill in different parts. Eventually everybody marks their player as “ready”, the local user hits Start and the game begins.
There are a bunch of interesting aspects to this. For one, everybody has to connect to the game server *before* the game actually starts. Otherwise they couldn’t cooperatively interact with the setup screen. For another, every user (client) has his own local copy of the setup screen, in-memory on his own machine. But the “master” setup data is kept only on the server. When a client connects to the server, the server has to dump all the master data out to the client, so his setup GUI can be up-to-date. Then, as the client tweaks his parameters, his local setup GUI has to sends those changes back to the server. The server then broadcasts the changes out to all the other clients, so they can see what the first client is doing. There are also security issues, such as validating that a particular client is authorized to change a particular parameter. The multi-player aspect of the setup screen even impacts how the game caches the setup parameters to disk (i.e., to be used as defaults the next time you play the game). Should single-player and multi-player modes share the same cache? Or should the multi-player mode parameters be cached at all? Or maybe multi-player mode should cache only the game’s general parameters, and not anything from the player slots?
I find it somewhat amusing that, in my impementation, it looks like there’ll end up being four(!!!) copies of the setup data sitting around in memory. Yes, four! And this for a single-player game. Why such redundancy? Well, single-player mode will have the same architecture as multi-player mode, so there’ll be both a client and server. And with that architecture, (1) all the GUI controls contain the setup data, so that’s one copy; (2) I need a client-side cache to detect when the user changes GUI controls, so that’s two copies; (3) the server needs its “authoritative” master copy of the data, so that’s three copies; (4) finally, Torque has a standard set of variables used for caching setup parameters out to disk (the “prefs.cs” file), and these variables’ values should really be human-readable whereas the master data is not, so these variables make yet another, fourth copy. LOL! Four copies, for some reason I find that funny.
In implementing this setup dialog, I also ran into some limitations with Torque’s GUI controls that I didn’t know about before. So Torque has this nice GUI system which is cross-platform and all, right? It has buttons, checkboxes, combo boxes (or pop-up menus depending on your terminology), etc. Unfortunately, Torque’s controls are missing some nice features. For one, I don’t see any way to get callbacks when the value of a control changes. I need this feature for the setup dialog, because like I said earlier, clients need to tell the server when a user changes a parameter. So I have to know *when* a user changes a parameter! (That’s the reason for the existence of the client-side data cache, to compare against current values of UI controls in order to detect changes.) Second, I don’t think Torque’s GUI controls can be disabled. But I need to be able to disable controls in the setup dialog, so that users can only mess with the controls that they’re supposed to mess with. A remote player should not be able to edit other players’ race, team, etc.! I think I’ll try to add this disabl-ing feature natively to the Torque engine, and if I do I’ll see about publishing it as a resource on Garage Games’ forums (the publishers of Torque). Seems like other people would find it useful too.








