Game Development

You are currently browsing the archive for the Game Development category.

Here I am again.
Almost 2 months and here it is a new version.
No new fancy features or big changes. Basically, I’ve just added support for loading WAV files encoded with ADPCM (IMA and Microsoft ADPCM supported).

I’ve been so quiet for a reason…
Last 2 months I’ve been looking for a new position in the games industry, and finally got one in Scotland-Dundee.

You can download the new version here :
Download lastest czPlayer demo

In my last contract, we used CEGUI for the User Interface. The String class provided and used by CEGUI uses an internal array as quick buffer for small strings, and reverts to the heap when the data doesn’t fit that quick buffer.
That approach increases performance if the quick buffer is big enough to hold most of your string operations.

However it lacks some features:

  • The quick buffer size is hard-coded in the class, instead of template-based.
  • When reverting to heap based, it doesn’t use any mechanisms to minimize allocations/ deallocations, like for example (Reference counting and Copy-On-Write)

Since I’m starting a new hobby project (my own small game engine), to test ideas and learn some new things, the first thing I’m coding is my own String class, which I’m also using as an exercise to test some more advanced templates stuff, instead of the classical “container of values of type T”.

So… about my String class.

Features:

  • Completely template based, using policies like described in the book Modern C++. This allows for a great deal of customization.
  • Using policies, it supports multiple types of string storage. Currently it support 2 storage types:
    • Heap based with reference counting and Copy-On-Write, to delay memory allocations/deallocations as much as possible.
    • Quick buffer based (like CEGUI), but with fallback to Heap based like described above when the data doesn’t fit the quick buffer. Also, the quick buffer size itself is a template parameter, so we set the size based on the use we have in mind.
  • We can mix strings declared with different policies (the ones provided), and internally it will still try to minimize memory allocations/deallocations, by using reference counting and Copy-On-Write when possible.
  • We can specify our own Allocator for heap based strings
  • Basic methods for manipulations. I need to implement a lot more.

Missing/Todo:

  • More methods for manipulations (make it more compatible with the std::string)
  • Unicode support. I’ve laid down the bases for that, but currently only works with char type

When coding it, I’ve used CppUnite2 for the tests. See this link for more information (Games from Within: CppUnitLite2 1.1).

I haven’t used this String class in a complex product yet, only in the tests during development, so I can’t talk about performance or bugs yet.

If you want to check it out, download it below:

NOTE: I’ve only tested it with Visual Studio 2005 (with sp1), so the provided project files are for that same compiler.

czString Download

I’ve been working hard on czPlayer, and here is the result. Version 0.2.0 released.
The API is mostly incompatible with the previous 0.1.1 version.
I’ve made a lot of changes to this version and added some new features, so I decided to jump the version number to 0.2.0.
All the internal refactoring I’ve made will hopefully allow me to add some new features I have in mind, like DSP effects (both internal and user provided) .
Needless to say, I’m not particularly confident about the stability of this version, with all the changes I’ve made. Some functions were not even tested yet. But like I said in earlier posts, there is always something to fix or improve, so I better release and work from there, than to keep fixing/improving stuff and never release.
I have so many crazy ideas for features! But most of them will not be implemented, because of the targeted platforms.
Codesize and performance have priority, not features… well… at least for czPlayer.
That leads me to another thing I’ve been thinking about…
Maybe I’ll eventually fork czPlayer into Mobile and Non-Mobile versions, so that I can go wild on all the things I want to implement. Hehe
Most of what I dislike in czPlayer (both internal, and in the external API), are a direct consequence of the compromises I had to make to support the targeted platforms, and have the same API for all of them.
Nuff said… You’ve got to ask yourself one question: “Do I feel lucky? Well, do you, punk ?

If so, go ahead, download the new version and give it a try:
Download lastest czPlayer demo.

Lately I have been refactoring czPlayer to add more features and make future maintenance easier.
Some parts of the code are almost 10 years old, when I first started playing with sound coding.
Needless to say, my code style and quality has improved a lot in 10 years, and it’s a funny thing to look at code this old. :)
As I was refactoring the code, I found a lot of ambiguities and redundancies caused by member variables added over time.
Let me explain….
I had a class responsible for MOD processing, and some of the member variables were:

class MODModule
{
// ...
bool m_loaded;
bool m_playing;
bool m_paused;
bool m_reachedEnd;
};

What’s the problem with this approach ?
Let’s see…
Suppose I want to call methods on the MOD object (e.g: Pause(), Resume(), etc)
I need to make some checks in each method.

To pause…

if (!m_loaded || m_playing || m_paused)
return SOME_ERROR;
m_pause = true;
// ... do pause stuff

Then to resume…

if (!m_loaded || !m_paused)
return SOME_ERROR;
m_paused = false;
// ... do resume stuff

When the MOD finishes playing, I needed something like this…

// ... some code that checks for end
m_reachedEnd = true;
//ups... How about m_playing, m_paused?
//We need to change their values, so we don't break code elsewhere
m_playing = false;
m_pause = false;

And similar things when playing, stopping, etc.
See the problems?

  • We need checks for multiples variables
  • We need to make sure the variables have valid values in relation to each other
  • What if we want to add an extra state? For example, “bool m_fading”. We would need to examine a lot of code to check how the other variables are used, and hardwire this new one somewhere. Every time you need to add an extra variable, you’ll need to check more and more code to make sure everything is ok.

Now look at the meaning of the variables. They are mostly mutually exclusive.

  • If it’s playing, it can’t be paused and hasn’t reached the end.
  • If it’s paused, it’s not playing, and hasn’t reached the end yet.
  • … and so on….

The more data members a class has, the harder it gets to keep the object in a valid state, so, the less data to manage, the better. Less maintenance and less bugs.

One technique I use a lot when trying to simplify code is to look at it with state diagrams whenever possible.
Here it is what happens (kind of) with instances of the MODModule class:

mod_states.png

I can easily translate it to code with enums.

enum MODState
{
MOD_STATE_NOT_LOADED,
MOD_STATE_STOPPED,
MOD_STATE_PLAYING,
MOD_STATE_PAUSED,
MOD_STATE_REACHED_END
};

class MODModule
{
// ...
MODState m_state; // Now we have only one variable
};

This approach is a lot easier to maintain, and less error prone.
Now the code in most functions become something like this:

To play…

if (m_state!=MOD_STATE_STOPPED)
return SOME_ERROR;
m_state = MOD_STATE_PLAYING;
// ... do play stuff

To pause…

if (m_state!=MOD_STATE_PLAYING)
return SOME_ERROR;
m_state = MOD_STATE_PAUSED;
// ... do pause stuff

To resume…

if (m_state!=MOD_STATE_PAUSED)
return SOME_ERROR;
m_state = MOD_STATE_PLAYING;
// ... do resume stuff

To stop…

// We cannot stop if it's not even loaded yet, or it's already stopped
if (m_state==MOD_STATE_NOT_LOADED || m_state==MOD_STATE_STOPPED)
return SOME_ERROR;
m_state = MOD_STATE_STOPPED;
// ... do stop stuff

The code may look similar, but it’s a lot less error prone, easier to follow and maintain.
Looking at the State Diagram, I could easily squeeze in a “Fading” state and understand the conditions to enter or leave that state.

As a bonus, using enums will enforce more rules and help you out with errors the compiler might catch. Always prefer compile-time errors over run-time errors. ;)

New release of czPlayer.
Just a few bug fixes in the internal mixer, and minor changes in the documentation.
Those bugs were particular hard to find and fix. They appeared mostly for short looped sounds, like those commonly used in chiptunes, causing some distortion or high pitch. I was making some wrong calculations for looped sounds, which caused 1 or 2 sound frames to be skipped for each sound. For big samples, you can’t hear the difference, but for very short samples, especially looped, just 1 or 2 wrong frames can mess up the final mix, since they represent a significant part of the affected samples.
I have a lot of changes planned, but  I’m waiting for a client to  finish  his game before I go wild on the code! hehe

Download lastest czPlayer demo.

I’ve just released the first public version of czPlayer Sound System.

There are still things to improve and features to add, but a client is already using it as-is, so I chose to release it right after some documentation updates and small fixes/improvements. I have a huge list of things I want to improve, but I know myself. I’m a perfectionist, and as a result I’m never really happy with my code. So if I just kept on this cycle, I would never release it ! :)
Better release something and work from there, than to be stuck improving and never release it.

As some of you might know already. czPlayer it’s a multiplatform sound system for games. Right now it supports Windows, Windows Mobile (PocketPC/Smartphone), Symbian, and PalmOS (full ARM with prc-tools). The formats supported so far are MOD and IT for music, and WAV for sound. The next ones to come are probably ADPCM and Ogg Vorbis, but that depends on the needs of my clients, and the priority of others things left to do.

If you’re interested in a commercial license, or using it in freeware, check it out: czPlayer Sound System


In some previous posts I talked a little about UML, but I never talked about what tool I use.

I have already tried a few.

- BOUML

- UML Pad

- Rational Rose . Only used some years ago, and never liked it.

- Visual Paradigm for UML

So far, and by far… the one I like the most is Visual Paradigm for UML . The first time I looked at it, it scared me a little, with all the buttons, and functionality. But its quite a complete package. Great documentation, somewhat clutter free windows (considering the amount of functionality), and an amazing intuitive interface, that can get you going in no time.

For example, in a State Machine Diagram, just place the initial state, and you can do most stuff from there without ever leaving the design area, simply pulling the other states from that one. Mouse gestures really help with productivity. First time I discovered those, it reminded me of “Black and White”. Depending on the kind of diagram we are working on, we’ll have some specific gestures available. For example, in a Class Diagram, we have a gestures to create classes, packages, add operations, attributes, and so on.

Most gestures are easy to remember, but to make things even easier, we even have a fast lookup window:

visual-paradigm_1.png (521x339 pixels)

That menu option will show you the available mouse gestures for each diagram type, like this:

visual-paradigm_2.png (410x511 pixels)

Thumbs up for Visual Paradigm. Really intuitive interface, that can really boost productivity.

Of course it has a lot more features, but the productivity boost was the most interesting to me.

If you’re looking for a good UML tool, give it a try. Maybe you’ll like it too. You can always use the Community Edition for a while, which is free for non-commercial use.


czPlayer, the sound system I’ve been developing, it’s slowly growing. After a few days blind coding while porting to PalmOS, without having a device to test on, and not even an emulator (I’m compiling full-ARM code for PalmOS), today I was finally able to test it. Worked at the first try! I could only say… Man,that’s strange, I wasn’t expecting that!

That was one in a million, I think. hehe

There are still some things to improve, features to add, and more refactoring to do, but its already working on Windows, Windows Mobile, Symbian, and Palm, which are my targeted platforms at the moment, so things should be easier now.

If anyone is interested, I’ll be licensing czPlayer in a very near future.

The first day I was supposed to start working for gEasy, they tell me they cancelled the contract with their publisher.

That means I’m available for any other contracts, if anyone reads this. :)
Meanwhile, I’m working on my own projects, which should get me some income, particularly with BitRabbit.

Also, soon I’ll start posting some game development articles. I already have some topics planned to start with, like:

- Game states
- GUI
- Sound
- Networking (maybe)

Its just some ideas I want to start with. Graphics is out of that list for a while.
I will most probably concentrate on mundane tasks I encountered and learned during the time I worked on Galactic Melee. Those things we don’t think about when we first start a game, but eventually we’ll get to it, like how to manage game states (menu, gameplay, credits, etc), or how to plan the code for a UI screen, which is in fact easy, but for a non-trivial UI screen, you’ll find yourself complicating the code a lot whenever you want to add more functionality.For that, planning with state-diagrams and implementing it with that approach too, made things a lot easier for me.

Anyway, as soon as I start posting those articles, if they are of any interest to you, you can buy me a coffee (read __donation__). You should see a link on the sidebar for that.

While porting my sound engine to other platforms I came across several platform limitations.
The easier one, turned out to be Win32 and Windows Mobile, of course. Good development tools, debugger, etc, and Symbian and Palm the harder ones.
What I’ve learned so far is that when coding multiplatform code, its really hard to keep the design as we want. We often need to hack stuff to defeat platform limitations.
With the limitations I knew about, I started refactoring and changing the design of the library. When I had all set, to avoid Symbian limitations, and started the Palm port, more problems!
The lack of documentation on some platforms doesn’t help either.
It’s really frustrating this kind of situation when we have scarce documentation, follow the rules, and it still fails. A lot of trial and error, where along the way we find small platform quirks which are not documented, or deeply buried in the documentation.
I’ve done a lot of refactoring, to account for the limitations I already knew about while at the same time keeping a reasonably clean design, but then I found more limitations on Palm.
It’s time for more refactoring to overcome more limitations!
I usually like to say…
“If it can be done, I can do it.â€?… But it may take a while! :)

Finally I resumed work in some of my own projects. I’ve been working on my Sound System (czPlayer), which I intend to license to BitRabbit.

About czPlayer Sound System:
Platforms supported:
- Win32
- Pocket PC
- Symbian
- Palm
Features:
- Sound.. of course. :P
- MOD and IT support
- More to come.

czPlayer codebase started around 1998, when I created a music disk (See http://en.wikipedia.org/wiki/Music_disk ) with some friends. I’ve done all the code, and two friends of mine the gfx and sfx. We we’re still using MS-DOS at that time.
Everything was coded in Watcom C++ compiler which was the best DOS compiler at the time, and the PMODE/W dos extender.

I think we’ve done everything in our summer vacations, in 2-3 months
At that time, czPlayer was called Jupiter Sound System or something like that. It had nice features for a DOS sound library, supporting SB mono to SB 16, Gravis Ultrasound with both hardware and software mixing to overcome some limitations. See (http://en.wikipedia.org/wiki/Gravis_Ultrasound)

Maybe I’ll post here a video or the music disk itself later.

Anyway, most of the code was refactored by now, and doesn’t look like the old code.

It’s nice to be back to my projects.

Alpha testers needed.

http://www.galacticmelee.com/

Go on and dogfight… ;)

From the site…

Galactic Melee is a physics based massively multiplayer space combat action game. You are a single fighter pilot among hundreds, carving a path through the chaos of fighter to fighter battle. Become the top ranked dueler in tournament mode. Kill in 90 seconds or die yourself in wave-based survivor mode. Or mine asteroids to buy carriers, launching waves of your fighters at the enemy starbase in Armada.

Skill decides battles, not equipment, or level, or time spent grinding. As a Trainee in your first battle, with minimal equipment, you can challenge the most advanced fighters in the universe. Can you make a name for yourself among thousands?

For some of the programming tasks I’ve been doing, I found myself planning things with UML State Diagrams. I really helped to understand some details, find problems, and follow the specifications. Since I haven’t been using UML for some time, I took out of the dust a book I downloaded and printed back in 2001 (I think) from Ariadne Training . Since I always liked that book, I noticed they already have the second edition available.
That book is actually a course manual, but I always found the first edition quite good even without attending the course. Not sure about this second edition, but I’ve already printed it anyway.
Here goes the link to the PDF:
http://www.ariadnetraining.co.uk/ariadnetraining.co.uk/downloads.htm
Have fun!