Category: Game Programming

Master of None

2001 was the year I seriously decided to become a game developer.

I’d had aspirations of doing so for almost my entire life, but 2001 was the year my son David was born. That was when I had to face the fact that I probably wasn’t going to be able to support a family of four on game tester money.

Having a family made it simultaneously harder and easier to become a programmer. No, there would be no week-long eat/sleep/code stints for me. But at the same time the knowledge that I needed to do more for my family prompted me to work harder, learn what I needed to know and come out of my shell enough to get the job I wanted.

But I had read voraciously about programmers like John Carmack…prodigies who understood code in a way other people just can’t. I had long felt disheartened because I knew I’d never get to that level and it seemed (from my reading) that it was necessary to do so in order to succeed.

Actually getting a game development job disabused me of a lot of that notion, and subsequently I decided that while I couldn’t be a master at anything, I could at least get a little familiar with everything.

I wrote Inaria because I’d never written an RPG engine. I wrote Planitia because I’d never written a 3D RTS. While neither game makes me an expert, I can now be an asset to a team writing either type of game.

There’s a saying: “The jack of all trades is a master of none.” In that form, it seems to suggest that it’s better to master a single subject than be competent in several. But that’s actually a shortened form of the original saying, which was: “Jack of all trades, master of none, though ofttimes better than master of one.”

Because frankly, how often do you need a master of something?

Carmack sneered at the 3D engine Tim Sweeney wrote for Unreal, but it worked well enough, didn’t it? Well enough to create a multi-million selling series of games that made Epic (and Sweeney) a lot of money.

Indeed, Carmack’s mastery of 3D engine development isn’t standing him in much stead these days. He called his work on Doom 3 “pretty damn boring”. That’s why he’s writing Java games for phones now.

So it seemed to me that I made the right decision.

And now this article from Dilbert creator Scott Adams says the same thing! It gives external validation to something I believe internally, and thus, I like it!


A Note To All Budding Direct3D Programmers…

There will come a time when you will need to change a vertex buffer every frame, either to animate something or to do clipping.

You will think, “Well, I could create the vertex buffer at the maximum possible size and then just write data to it every frame, but that would waste memory. It’ll be so much better if I actually delete the old buffer, create a new buffer at the correct size, and then fill it with the new data every frame instead.”

Do not (repeat not) do this, because it causes some video cards to go “Oh, hey, what’r you – wait, I need that – no don’t – AGH I CAN’T TAKE IT ANY MORE!” and crash.

Instead, just create the vertex buffer once at the largest possible size, and then simply write new data to it every frame. Yes, you will waste a little memory, but everybody will be much happier.

I wasted two weeks on that bug. Sigh…

On a happier note, remember Cybermage? That awful, awful game from Origin that I used as a Name That Game! a few weeks back? Well, have I got a present for you.

See, you may ask yourself when you play old games, “Why does the voice acting suck so badly?” Well, it’s because the developers couldn’t hire professionals, so they had to make do with whoever they could find. And while the people they used may not have been impressive, the alternative was something like this.

And yes, I have been assured by an old friend at Origin that the guy giving that take wasn’t joking. He was dead serious. He really thought that performance might get him the part of Necrom. This friend told me that the guy was a bodybuilder and actually did a set of squats inside the recording studio to “get himself ready”.

Obviously he should have done one or two more.


Mighty Acorns

The screenshot I presented yesterday was a visual representation of the galaxy map of the original Elite. I generated it myself from the game data.

The Classic Elite Galaxy.

So why wasn’t such a map actually available inside the game itself? Surely providing such a map would have been very helpful to the player.

The answer is because in order to draw such a map and make it interactive, you would have to have the entire dataset for the galaxy in memory at once, and Elite couldn’t do that.

The designers of Elite, Ian Bell and David Braben, had a problem. The machines they were designing Elite for had at most 16k of RAM. One of the premises of Elite was that you were exploring a large section of the galaxy, one 256×256 units in area. This galactic sector had 256 star systems in it. Each star system would have data for its own unique name, tech level, economic level, government type, population level, productivity level, price for each trade good, and even a couple lines of text describing the most interesting aspects of the system. Each star system required four 16-bit values for this data. Thus, storing the entire galactic map would have required 2048 bytes of data – 2k, or 1/8 the amount of total space usable by the game. And when you’ve also got ship data to store and a 3D engine to run that’s just not good enough.

But Bell and Braben didn’t need access to the entire galactic data set at once. They typically only needed the data for the current star system the player was visiting.

Realizing this allowed them to solve the problem through the use of procedurally generated content. They started with three sixteen-bit numbers, which could range from 0 to 65535. These were called seed0, seed1, and seed2, and the values for the original Elite galaxy were 23114, 584 and 46931. These were not generated but were stored in code.

They then created a function called “tweakseed” that would create new numbers based on the existing ones. This function would also push the existing values “up”, getting rid of the oldest one and putting the new one into seed2. Here’s the C version of tweakseed from Bell’s Text Elite sources:

void tweakseed(seedtype *s)
{
    uint16 temp;
    temp = ((*s).w0)+((*s).w1)+((*s).w2); /* 2 byte aritmetic */
    (*s).w0 = (*s).w1;
    (*s).w1 = (*s).w2;
    (*s).w2 = temp;
}

Thus, before the first run of tweakseed, the seeds would have their initial values:

seed1 == 23114
seed2 == 584
seed3 == 46931

Running tweakseed once would generate a new seed, 5093, and the values would then look like this:

seed1 == 584
seed2 == 46931
seed3 == 5093

Since these values were generated by a function, they were predictable. They were random but in a controlled fashion. The game would use four seed values for each planetary system; thus, if the game needed the data for star system 113, it could just run tweakseed 448 times and then use the next four seeds as its data. The data would always be the same; thus, star systems would stay put. “Jumping” to a new star system was simply a matter of clearing out the data for the previous star system and replacing it with the generated data for the star system the player was jumping to.

Thus, these three numbers and this one small function represented an entire galaxy inside Elite. And as as if that weren’t enough, it didn’t just represent one galaxy. By changing the three starting seeds you change the entire galaxy. Since the three starting seeds could range from 0 to 65535 each, this formula could generate 281,474,976,710,656 galaxies. And initially Bell and Braben were going to allow the user to input their own seeds so that each player could play in his own private galaxy. They were overridden by the publisher, who felt that it was a bad idea to emphasize the fact that the galaxies were random. So Bell and Braben chose eight seed sets to represent the eight galaxies of the classic Elite Universe.

Procedurally generated content is all the rage nowadays, but it’s a very old concept. (As is sandbox gameplay, something Elite also pioneered decades before Grand Theft Auto III.) The interesting thing is that nowadays we are looking to generated content for exactly the opposite reason Bell and Braben did. Bell and Braben used generated content in Elite because they didn’t have the space to store their entire dataset at once. We are looking to generated content because we’ve got so much storage space that we can’t possibly hand-create enough content to fill it.


ODE is on its last legs…

I’ve no doubt that ODE can do what I want it to do.

I just can’t figure out how to make it do it, despite having stayed up until about 2 AM every night this week.

If I can’t get ODE integrated by April 1, I’m cutting it. If I cut it, I will try to replace it with some simple crappy physics of my own…but I can’t promise anything.

I’ve already cut (or severely scaled back) the world simulation that I thought the whole concept of this game was going to be built around…if I cut physics too, what’s left to make this game distinctive? I’ll basically be remaking Age of Mythology. Now, of course, this project was supposed to be a learning experience (and boy, it certainly has been)…but when I started I had a bit of a vision, and now it’s pretty much all gone.

Ah, well. It’s the Dark Time on the project. Every project has one. I’ll just have to push through it and see what comes out.


Planitia Update 9 – WITH DEMO!

My time of copping out is over.

Of course, that doesn’t mean that my time of writing good code has started yet.

In any event, I managed to get the demo together. Odd how it always seems to take one more week than I expect for me to get stuff done.

Screenshot:

Huh.  It looks slightly different.

And here’s the download link. It’s just over a meg.

Planitia Combat Demo One

Please play it! Please comment! Basically I’m looking get the feel of the camera control and the combat very natural – that’s all this is about. If you feel that anything works kind of clunky, please tell me. If something you thought should work didn’t, please tell me. If your machine crashes, please tell me so I can have you send me your log file.

The next update should have some god powers!

Edit: Thanks to whoever voted this entry up on Qatfish.com – this is my highest-ranking entry ever.

Note: If you get a message saying that you are missing “d3dx9_31.dll”, update your DirectX. Yes, even if you have 9.0c. See, there are different versions of 9.0c.

Note: I am aware that moving units off the map crashes the game, but the map is so big that this shouldn’t happen accidentally.

Version .11:

Removed two large unnecessary files from the download package, thus shrinking it from five megs to one meg.


Planitia Update 8

In which I admit to completely copping out.

I need to get the discrete event simulation working. I feel I understand the concept but it’s not something I’ve ever done before so I am having some trouble figuring out how to approach it.

So I did graphical stuff instead!

Huh.  It looks slightly different.

Made the hitpoint bars smaller and made them green instead of red. Changed the selection marker to a blue circle underneath the units. Went ahead and raised the resolution to 800×600, since that’s what the final game will run at.

Now, one thing that is kind of stopping me is that I need to figure out exactly how units act both when they have explicit orders from the player and when they don’t.

Here’s what I’m thinking. Comments welcome.

The current problem is that you can grab a group of units and give them an attack order and they will dutifully go and kill the unit you clicked on, but then they’ll just stand around even if his buddies are right there. And his buddies will stand around too. Obviously, units need to take the initiative and engage if they have no other orders. But units without explicit orders shouldn’t stray too far from where the player put them.

Thus, when you give units move orders, you are not only moving them, you are setting their anchor point. If units do not have orders, there should be a range within which they will move and engage enemies. Archers should never move, they should simply snipe at anything that comes into range, but warriors and barbarians should probably have a range of about three tiles…if an enemy moves into that range, the warrior or barbarian moves to intercept and attack. If the enemy moves out of that range, the warrior or barbarian breaks off contact and returns to their anchor point.

Now, three tiles is less than the range of archers (eight tiles). Thus, if a unit is attacked by the enemy (rather than simply has an enemy come into its range), it can go as far as it needs to in order to engage that enemy, but once that enemy is dead it returns to its anchor point.

These autonomous attacks happen only if the unit has no standing orders from the player. Thus, if you grab a group of units and tell them to move through a group of enemy units, they will not engage as they are attacked because your move order overrides that.

I think that should be close enough to how a “real” RTS feels. Please feel free to tell me how you think it should work.


Planitia Update 5

Flee! The barbarian hordes approach!

Run for your lives!

Still no band-selection yet, but otherwise the interface should feel quite familiar to anyone who has ever played a 3D RTS.

To be honest, I kind of psyched myself out with my last post about Planitia’s design, and I did it with two words: world simulation. Planitia will require at least a basic world simulation, but I’ll be darned if I know how to do one, and unfortunately my perusal of the Game Programming Gems books and AI Game Programming Wisdom books have been disappointing When all of these books discuss AI they discuss pathfinding, line-of-sight, group movement – unit-based AI. When they do talk about RTS AI, it’s about creating an AI opponent for the player to fight against (which, granted, may come in handy).

Of course, while I consider what I’m looking for to be “AI”, other game developers may not. What am I looking for?

A world simulation consists of a system composed of interacting subsystems with emergent properties. Oblivion’s world was made of a system like this. So was Ultima VII’s. So was Powermonger’s. Thus you can see that such a system doesn’t require heavy CPU horsepower. It does require one to know where to start coding such a system.

Once again, my friend Tom Mauer comes to my rescue. In college he heard about discrete event simulation, a form of computerized system simulation that is really big in manufacturing and scientific industries but hasn’t really been used for gaming. The basic concept seems simple enough; I’m going to try it out on Planitia. If I get it working I’ll probably write up an article on it.


Planitia Update 4

Woo freakin’ hoo!

This opens up a whole bunch of options for me. Yes, Planitia is now a serious go, but I could also use the same system to re-create my combat prototype in 3D now. Or make a Final Fantasy Tactics-sytle 3D turn-based combat strategy game. Or make my 3D RPG.

I’m so happy!


Planitia Update 3

Unit Drop.

I’m using a better grass texture (although it still looks weird since that’s the only texture) and I’m now using a plasma I generated for my heightfield data. And I finally have units.

The unit is a simple billboarded quad. He moves autonomously across the terrain and his height is being constantly adjusted to match that of the terrain below him. I can’t pick him yet, but I can drop as many of them on the heightfield as I want…and now that I think about it, a horde of them would have made a much better-looking screenshot. Ah, well.

Next up, unit and terrain picking. Oooh, that’s going to be a pain. You may say, “Just grab some existing code!” and yeah, that would work, but the whole point of this is to understand all this stuff.

Once I get picking, I will probably go ahead and implement a very simple, fairly standard RTS using the classic three types (barbarian, warrior and archer) just so I can get the interface right.

Or I might just put in a god power or two. Picking a unit would make it possible to zap said unit with the lightning of Zeus! Which would be fun.


There’s a Hole in my Soul…

I guess it’s time for me to stop messing around and admit to myself what I really want.

So what is it I really want? Well, let’s see. Exactly what projects have I undertaken since I started this blog back up two years ago?

I wrote an rpg.

I wrote an rpg team-based combat prototype.

I wrote a little arcade game.

I tried to write an RPG in one page. (That’s on permanent hiatus by the way; RPGs are just too information-dense to do in one page of source. I might try to write one in two pages later, we’ll see.)

And now I’m writing a 3D engine with a fixed 3/4 perspective.

Let’s face it; I want to write a 3D RPG.

Specifically, I want to write this 3D RPG:

The Real Ultima IX.

There’s a hole in my soul, and it’s Ultima IX-shaped. This Wikipedia article goes over the basic facts that lead up to the train wreck that Ultima IX became.

The version of Ultima IX I am referring to is the second design mentioned in the Wikipedia article, the one Mike McShaffry was working on. The one before the entire team got pulled off to finish Ultima Online and before that team subsequently quit and before EA execs started saying things like “It will be our Tomb Raider 2” and before the game was redesigned five times by people who knew nothing about Ultima.

(calmblueoceanscalmblueoceanscalmblueoceans)

But back when I was still working at Origin and the game was still in development, the mantras going around were “The plot is going to be a remake of Ultima IV” and “The engine is going to be Ultima VII in 3D”. The early screenshots certainly seemed to bear that out, and my anticipation was palpable. It led me to my doom at Origin, when I decided I wanted to test Ultima IX instead of Ultima Online.

There were four aspects of the original design of Ultima IX that I felt were vital to the game’s appeal.

* The game was fully 3D.

* The game utilized a fixed isometric perspective.

* The game had a streaming world.

* The game was party-based rather than a single-character game.

I don’t think I’ve ever seen another game with all four features. The closest I’ve ever seen was Dungeon Siege, which was much closer to Diablo than Ultima.

So I guess if I want to play such a game, I’ll have to make it myself. The problem, of course, is that such a game is way to big for me to make myself. And yet, looking back over the work I’ve actually done over the last year, it’s obvious that I’ve been subconsciously making sure that everything I did somehow contributed to the overall goal of making a 3D RPG. So I may as well just come out and admit it.

Now, this does not mean that I won’t finish Planitia. Quite the opposite; I intend to make all my newbie 3D mistakes on Planitia instead of on my 3D RPG. But after that…well, there’s no sense putting it off any more. It may not be a big 3D RPG; it may not be a very full-featured 3D RPG; but for cryin’ out loud, I need to write this 3D RPG if only to get it out of my system.