Categories
Game Development

Documentation? Who needs it?

So here I am, doing what I usually do on my game. You get two guesses:
1. Adding features
2. Screwing around with compiler settings, trying to get third party libraries to work

If you guessed 1, you haven’t read any other posts on this blog.

So this time it’s Open AL. Back with version 1.0 I got it working quickly and with a minimum of hassle. I updated to 1.1 it’s like they purposely made it hard to compile. ONE API has FIVE projects, two of which are DLLs and 3 of which are static libraries. There’s no documentation on why there are 5 projects or what they do but who needs it when you have such descriptive names as “ALc”, “ALu”, and “ALut”?

After like an hour I got the damn thing compiling to a library, only to find out that it crashes every time I run it somewhere in assembly code. So I give up on libraries and just try to compile the source. Burn past about 100 warnings, get it compiling, and still crash in the same spot.

I’m still working on it. I’m just happy there is only one more third party library to deal with: Newton Physics. Hopefully that won’t be too bad. I wish more people took a lesson from the Irrlicht author and actually designed libraries in a meaningful robust fashion and include documentation.

Categories
Game Development

Irrlicht is well-written

Irrlicht is the first library I’ve ever used where
1. I feel all features are useful
2. I’m able to mod it without a headache
3. I can use the library directly, without feeling like I need to make my own wrappers.

With no other graphics library would I ever consider using their input library. Originally I was going to find something cross platform too. But for the heck of it I took a look at what Irrlicht does and it’s actually quite simple, sensible, yet does everything I need. It doesn’t force me to use strange design architecture and ties in well with their whole system of gui elements, cross platform capabilities, and event notification.

I was able to mod the file loader quite easily. Everything I needed was straightforward, in a single file. When I was looking at Torque before there were so many files that did so many things I got depressed just thinking about it.

Lastly, all the functions I’ve seen so far are powerful and simple. I remember when I used Ogre one of the first things I did out of the tutorial was to make a wrapper for the camera, since the camera was too low level, with many unnecessary functions that still somehow forced you to use a certain design paradigm. Sort of like MFC…

The author’s code is readable, clean, and well-documented. No Hungarian notation at all 🙂

Good job!

Categories
Game Development

State design

I’ve been thinking about a good state design system lately and how to address common problems in other games.

The problem in most other games is that states are designed to be modular, but don’t turn out to be, both in functions and in data.

Functionally, a game may have an options state, and a game state, and may later decide to show the options state while running the game state. If this is not defined in advance, the likely fix is just to call the render function of the options state from the game state. It works, but it’s poor design that can easily cause bugs. For example, the render function may rely on data setup by the enter function of the state. If not now, then maybe later when someone adds it and didn’t know about that dependency.

The same holds true for data in non-obvious ways. When I was working for nFusion we had to access game-specific data from the main menu screen, in order to determine if the continue button should show up or not.

You could just make the data global, or essentially global, such as putting it in the “Game” or “Application” class. However, this is bad design. You want to make data accessible to exactly the classes that need it, no more and no less. One solution is to put the data into a higher level shared class. For example, at my job we have an AI class and various controllers that interact with it. CONTROLLER SPECIFIC data sometimes needs to be shared between controllers that were designed to be independent. This generally goes in the AI class, which is bad design. We now have this huge AI class with a ton of data members, half of which serve some special purpose.

The solution I came up with is pretty simple but I think solves these problems with a minimum of complexity:

The application class contains a state manager
The state manager contains a stack of states, which are instantiated or deleted as needed.
States are unique in the state manager. No more than one instance of a particular state can run at the same time
States are independent and contain implementation functions and capability functions.
States refer to each other through enumerations, rather than pointers.
When a state manager gets an event (keypress, render, update), it goes to the state manager, which then processes it to each state in reverse order. For each of these, a state can trap an event so it does not progress to higher level states.
Data that is shared between states is held in a reference counted pointer.

How this works is easiest to show in an example:
Game states, calls state manager to create the main menu

The main menu does not already exist. It is created and put on top of the stack.

Query, update, and render calls to go the state manager, which sends the events to the main menu, which handles the events.

The user presses options. The main menu state tells the state manager to create the options state. As it does not already exist, it is created and put on top of the stack.

Since events are processed in reverse order, the main menu state renders and updates first. However, the main menu state queries the state manager and finds it is not at the top of the stack. Therefore, it renders a dimmed version of the background. All events are passed through to the options screen except the keypress “alt-z” which plays a main menu specific easter egg sound.

The options screen updates as usual.

Now the user presses esc. The options screen interprets this as “Remove myself from the state manager” and the user is back at the main menu.

The user presses “Start game” which tells the state manager to remove the main menu from the stack and create the game state.

In the game state, the user now brings up customize ship menu (which was also available from the main menu). The game continues to run in the background fully, but keypresses and mouse presses are not processed. The user then brings up the options screen while the customize ship menu is open.

The customize ship menu is not designed to run unless it has primary focus (top of stack). Therefore, the allow render and allow update calls return false. The options screen shows up over the game screen. The user presses esc, and as before the options screen is removed. Since the customize ship menu is next on the stack, it shows up again and none of the user’s changes were lost.

The user presses esc again, and goes back to the game.

Shared data will be in singletons that are referenced counted and delete themselves when they are no longer used. States will get a pointer to the singleton when they are created, and release the pointer on free.

Categories
Game Development

Next steps in technical investigation

I finally have 3D graphics appearing in both IE and Firefox. It takes some setup by the user. Once I pay the fee (IE) and provide an installer (Firefox) this should be easier.

Now that I have 3d graphics appearing in the webpage it’s time to test out other major, risky features:

Input
Sound
Level editor

I’ll look at these over the coming weeks but I don’t think any of them will be a serious problem.

Categories
Game Development

Some time wasted, some progress made

Last night, with a helpful download link from someone on the Games-L mailling list, I got a Mozilla plugin working in about an hour. I was pretty happy about that, because the same task with Active X took a week. I spent another hour trying to figure out how to get the data in the SRC tag into the C++ code but got nowhere. Thinking this should be something easy, I ask around in some online lists and go watch Battlestar Galactica.

This morning I check my email, expecting to find numerous relies about how stupid I am and pointing out some obvious answer. However, aside from spam there was nothing there. So I get back to work (it’s 8AM or so). My initial guess was that you were passed the file data in the startup code. This is not an unreasonable assumption in my opinion. I pursue this guess for about an hour but just can’t find the file data anywhere. I browse the web, find someone elses’ open source plugin, figure out how they downloaded the file, and painfully converted that to work with what I had. I set it up as a synchronous download, so I just get the whole file in one function call. It’s 11:00 AM now. As the final step, I decide to try out asynchronous download and add a progress bar. I change my download to asynch and suddenly I get two asynch reads rather than one. It turns out the original file was downloading asynch the whole time. Great…

I’m done dealing with the Mozilla plugin at this point. My next step is to get the custom LZMA pack that I wrote and convert it from file->file to memory->memory. This is harder than it sounds, because the LZMA author decided to implement his own version of cross-platform COM. So rather than the simple step of changing a few fopen lines, I now have to implement 2 custom COM classes as a memory stream class and painfully debug them. This was a risky stage in development due to the difficulty and reliance on 3rd party code. I was lucky that it worked without having to go too level because I would have given up and used Winzip instead rather than try to debug COM. Once again I’m thankful for open source libraries. This would have been impossible to accomplish otherwise.

Now that it works I have 3 different ways to launch the game. The Mozilla plugin downloads the data and starts a thread. ActiveX, for IE, gets the data from a resource and starts a thread. The EXE launcher just loads the regular data files from disk and runs in the default thread. They all run the same game code so in theory, though not very well in practice, I should be able to work from one launcher and have the other two automatically work.

Solution with firefox launcher

The next step is to finish up my resource manager, so fopen calls to Irrlicht go to that instead. If and when that is done I can finally see models in the browser.

Categories
Game Development

Developer roadmap

Stage 1: Technical investigation
2-3 weeks
I am going to implement a cross-section of the game, with all features, but basically implemented. This will let me know what kind of hoops I have to jump through and what is not possible.

Stage 2: Game design
2-4 days
I will fully flesh out each element of the game design into a full design doc.

Stage 3: Code design
1 day
Based on the game design, I will design classes, structures, and perhaps variables to represent this in an easy to use, extensible, and maintainable way.

Stage 4: Coding
3 months
I’m going to do the multiplayer part last. Normally this would be the wrong approach, but it works here because there is only one code author and it avoids a lot of overhead restarting and starting the server.

Stage 5: Assets + polish + design
2 months
This is the time to hire artists and sound designers. A lot of game design occurs at this point as well, since the initial rough values will need to be tweaked out with features added and dropped based on how well they work. If I can find someone affordable, I could hire an artist earlier during the programming stage.

Stage 6: Closed beta / bug finding
1 month
I might have to do the whole NDA deal. This will get all the major bugs out of the way so when open beta starts I’m not swamped beyond measure.

Stage 7: Larger beta
1 month
Here comes server load balancing, and a better opportunity to find exploits.

Stage 8: Open beta
3 months
More of the same, and bug fixing. Since I’m still early in development this is a great reminder not to make bugs to begin with!

Stage 9: Profit!
$$$

Categories
Game Development

Going on 10 hours setting up a project with Active X

If you asked me, or any other game programmer, to setup a game project with multiple static libraries divided by component it would take half an hour at at most.

If you had asked me, or any other game programmer that I know of, to do the same thing with ONE Active X / MFC project… well I just finished and it took 10 hours.

The MFC project is like a virus, or a tumor, in the body of the solution. Simply renaming a file can cause a link error. Then you change it back and get some other link error you’ve never seen before. At one point I was trying to change the output directory of the ocx, which somehow caused it to no longer link and the exe launcher to stop running due to some resource conflict. I had to create an entirely new Active X project, copy over all the relevant settings, remake some of the files, and import it into the solution. Although it was identical to the old project it now worked where the other one didn’t.

I’ve gotten into the habit after EVERY change, no matter how meaningless (such as adding a ‘d’ to the end of the output filename in debug), to recompile everything in both debug and release and run it to make sure nothing broke. Sound pointless? I didn’t do it the first 8 hours and I did do it the last 2. That’s the only reason it only wound up taking 10 hours instead of 20 or 30. Of course the few times everything actually runs I also zip it up and keep a backup so I can revert the entire solution, which I had to do several times.

There are so many little annoyances and time wasters. For example, if you make a temporary project, build it, and delete it your registry now has junk in it. The Active X Control Test container has an unregister button but it only works if you still have the same project on your harddrive using the same GUID. It asks you if you want to wipe out the registry keys, but that never works. So every so often I have to manually edit and clean out the registry just because I’m creating test projects in Active X.

Active X Registry Cleaning

Anyway, it seems like I finally got things running:

First working solution

Perforce is being a pain in the ass but I can’t blame it since few people have to delete, create, move, and rename projects as much as I have in the last 10 hours. So I’m just going to wipe the database and upload what I have.

Categories
Game Development

MFC = Garbage ++

MFC is an IMMENSELY buggy and bloated piece of crap. I spent the entire weekend just setting up the damn project for Christ’s sake.

1. Kept getting a crash when quitting an Active X control – it’s a known bug in the compiler and I’m a novice user that encountered it 10 minutes in.
2. Couldn’t compile due to various library conflicts
3. DirectX 8 kept loading some stupid library that was removed for 5 years now. Had to upgrade to DirectX 9
4. Overriding the Run function flat out doesn’t work.
5. The registration utility crashes and fails to consistently remove dead projects.

I’m having these tremendous, undocumented show stoppers time and time again. If you search for the same linker errors they are ALL OVER THE NET.

Of course what I’m doing is very advanced so you can’t blame them for missing a few bugs. In one case you have to:
1. Create a default project
2. Run it

Another is even more complicated:
1. Create a default project
2. Add one line of code that doesn’t do anything
3. Run it.

Assert

Was this even tested? Why does anyone use it?

Categories
Game Development

The value of open source software

When I originally started programming my view of open source was it meant there was more code I had to look at and learn in order to be productive. The implication was that with closed source libraries the author was responsible for creating true black boxes – input goes in, output comes out, and since you had no knowledge of the workings the author should carefully document each function and system. The other half was that open source library authors could be lazy – you were expected to look at the code if you had a problem.

Ironically, I started out using the worst documented and packaged API I’ve ever seen – Panard Vision. This was back in version 4.0 or so, but I checked on the website recently and saw something like “Version 7.0 just released, documentation coming soon.” I was more tolerant and less able back then than I was now, so I spent a good week just trying to get it to compile. You can imagine my rightfully felt wrath, considering I just spent several hundred dollars registering. I wrote a scathing review on the gaming site I was running back then. That was ridiculous since the gaming site had nothing to do with programming libraries. I just wanted a place to attack and vent. Considering how unpopular his library still is, even after all these years, it seems like others agree documentation is important.

Programmers document or not depending on their own conscientiousness and it has nothing to do what they should do. Open source simply lets you see inside the black box if you want to, which you will when you run into bugs. Recent experiences have driven that lesson home.

Closed source libraries protect the author at the cost of the user’s time. Since my time is valuable to me, I’m immediately rejecting libraries that are closed source from this point forward.

Categories
Game Development

How to make an appealing graphics engine

With all the engines I’ve been looking at I thought it would be fun to write down what appeals to me.

In order of importance:
1. Easy to use
2. Encompassing set of tools
3. Doesn’t use script, or if it does the role of script is limited and optional.
4. Feature set

Easy to use
Ease of use is important to me because, like most people, a graphics engine is a means to an end and not an end in itself. I want to get the engine installed as fast as possible, spending as little time as possible learning, and getting the engine to do what I want with a minimum of fuss. This is one thing good about the Wild Tangent engine… once you get past the installation 🙂

Toolset
For much the same reason as ease of use, my goal is not to spend a lot of time writing exporters for custom tools and getting those into my game. My goal is to get the artwork into my game as fast as possible with as little effort as possible. If I have to read 20 pages of text and follow 5 different links to get a model into my game it just isn’t going to happen. Ogre 3D could stand improvement here especially, since the only level format it reads requires a license from ID Software to build. Like I said, it’s not going to happen.

Doesn’t use script
We have a common theme going here. If an engine uses script, that means I have to learn what they did to write it. I don’t want to learn what they did. I don’t care what they did. The last thing I want is to spend a week figuring out an arbitrary language just to see if I like the engine. As I said in the previous blog, script should be for level designers. When it comes to designing my levels AFTER I know I like the engine, fantastic.

Feature set
This is the least important to me. Why? If I wanted a huge feature set then I’d be making a huge game. If I was making a huge game I’d be using a huge engine and would have a huge amount of money to buy said engine. I wouldn’t be using a free engine. I’d use an engine where I know I can get support, where the engine will be updated over time, and where I know it’s been used in successful games before.