Monday 1 June 2015

Games Programming Languages

One thing that I've noticed with people who want to get started with games programming is that one of the first questions they ask is 'Which is the best programming language for writing games?'

Rather than give you opinions on each language, I'll go through each one I've used and explain what task I've used them for and why I chose them.
Not everyone else will make the same sort of games as I do for the same platforms so this is fairly subjective but I hope it will provide some useful information.
Afterwards I'm going to go through a number of games I've worked on and break them down into which languages we used and why.

C++

C++ is still the language I use the most for general purpose programming. This is mainly because I still seem to be writing games using in-house engines or using games engines which are programmed using C++. We've always felt that C++ provides the best compromise between performance and usability which is why we still use it for most of our games. Also having over 20 years experience with C++ influences the decision.

C#

A few years ago I'd never used C# for anything but since Unity has become popular I find myself using it more and more. Besides Unity, I've also used it for cross-platform utilities, build tools as well as a bit of server programming. I really like C# and hopefully one day I will use it for writing all my games.

Lua

Lua is my scripting language of choice and has been for a number of years. Since it is so easy to integrate into a C++ based games engine, I've used it as the scripting language for most C++ based games I've worked on for the last few years. I've used Lua in about 4 commercial titles for scripting high level game logic and UI. I've always found that Lua have great performance when used properly and that people find it easy to learn due to its simplicity.

Lua is also the programming language we use to set up our build system, Metabuilder.

Objective C

I've used Objective C for iOS titles and I've tried to use it as little as possible. This isn't because I don't like (actually I love it!) but mainly because it isn't really portable and I'm usually writing multi-platform games. Typically I'll use it to interface with the iOS API for such things as Game Centre integration, iCloud saving etc.

Javascript

I've used Javascript for various random bits and pieces. Mainly for HTML5 coding and a bit of NodeJS.

Java

I never really wanted to learn Java as I've only heard bad things about it from other programmers. But with Android development I've found myself learning it bit by bit as I've tried to get my games working with the Android OS. I've used Java with Android in a similar way to how I've used Objective C with iOS - mainly for interfacing with the OS for multi-platform games.

Language Breakdowns

I thought it might be a good idea to breakdown some of the titles I've worked on into which programming languages were used and what they were used for. I'll also try and explain our thinking in using the various languages.

Geometry Wars 3 - PS3, PS4,  PSVita, XBox360, XBoxOne, PC, iOS

C++ : Game engine, main game logic & user interface
Because of the specialised nature of geometry wars it was obvious from the start that our best option would be to write our own game engine. Our requirement was for a high performance, portable programming language. C++ was the obvious choice.
Lua: Individual level scripts
We wanted to give our level designers as much flexibility as possible when creating their levels. We'd used Lua before many times and knew from experience it would be the best choice.

PSPets: Puppy Parlour - iOS (Unity)

C#: Game logic
We developed the game using Unity and for us C# was the best choice of the scripting languages Unity has to offer in terms of features and performance.
Objective C: Native plugin to access PSN
We had to access various 3rd party libraries and network services. This had to be done through Objective C so we wrote a Unity plugin using Objective C.

Jacob Jones - iOS,Android, PSVita (Unreal 3)

UnrealScript: Game Logic
Most of the high level game logic was implemented using Unrealscript.
ActionScript: Puzzle Logic
The puzzles were developed in flash and then run in-game using Scaleform
C++: Engine customisations
C++ was used to make any changes to UE3 which were required to support the game.

2K Drive - iOS

C++: Game engine, vehicle simulation & physics.
We implemented a fairly typical driving simulation using C++ because we felt that it would give us the level of refinement required to develop the driving simulation we were aiming for. The driving simulation was very closely tied to the Bullet physics engine which we made several customisations to.
Lua: Event logic & in-game UI
Our game levels in 2K Drive were individually scripted driving challenges. We felt Lua would be the best language to script the challenges due to its simplicity and how easy it would be to integrate into our game engine.
Javascript: Magazine user interface
For the magazine part of 2K Drive we decided that we wanted it to look as much like a webpage as possible so we implemented using HTML5 using a web view in iOS.
Objective C: iOS integration, achievements, leaderboards
We only used Objective C where absolutely necessary to interact with iOS.
PHP: Server backend
There was a fairly significant server implementation required for 2K Drive. We decided to use PHP because it was popular, well documented and free. Part of our decision to use it was based on the availability of PHP programmers.
C#: Game database tool
We needed a database tool to set up our game data. We decided that it would be best to use C# to develop a cross-platform database tool that we could run both on PCs and Macs.

Travel Bug - PSVita

C++: Game engine & logic
Travel bug was an early Vita game so C++ was the only really choice of programming language. It was a pretty simple game and a fairly straightforward task to implement.

007 BloodStone - PS3, Xbox360, PC

C++: Game engine & logic
Bloodstone was a fairly typical AAA in-house C++ engine developed game. We used a C++ game entity system for the game logic which meant all the game entities were coded using C++.
Lua: User interface
Our user interface system used Lua to script all the game screens and UI widgets.

The Club - PS3, XBox360, PC

C++: Game engine & logic
We developed our own multi-platform game engine for The Club using C++. All the core game logic and entities were written using C++.
Lua: Level scripting & UI
We integrated Lua and provided an interface to our game engine that the level designers could use to script the logic for their levels. We used Lua because it provided the level designers with a lot of flexibility and freedom to try ideas.

Treasure Planet - PS2

C++: Game engine and game logic
This was our first C++ game engine. We wrote a fully OO game entity system where entities could be placed and configured using our game editor. All the game entities were written as C++ objects.
VU Assembler
Parts of the graphics engine was written in VU assembler for the PS2's vector units. The only way of programming the vector units was by hand-coded assembler and this was vital to get maximum performance out of the PS2.

Treasure Planet - GBA

C: Game engine & logic
Since the GBA had limited resources we wrote the game engine in some very tightly write C. We chose C over C++ because it produced simpler code and didn't encourage elaborate implementation techniques (e.g. full OO based entities) that the GBA's 30MHz CPU would have difficulty coping with.
ARM assembler: Low-level interrupt handler, fast maths routines.
Some of the more optimal code had to be written in assembler, also some of the interrupt routines needed to be written in assembler due to their low-level nature.

Fur Fighters - Dreamcast, PC, PS2, iOS

C: Game engine & game logic
When we initially wrote Fur Fighters there was no C++ compiler available for the Dreamcast so we had to write all the game engine & logic in C. The game incorporated quite a few OO concepts so we had to work out ways of coding them in C rather than C++.
Objective C: iOS access to achievements & IAPs
When I ported the game to iOS (many years later!) I had to use objective C to interface with iOS for Game Centre integration.
SH4 Assembler: Inner graphics transform loop
The transform loop in the graphics engine was one of the most performance critical pieces of code in the game, it was originally written in C but we wrote an SH4 assembler version using some of the CPUs special features (SIMD & StoreQ) making it 3-4 times faster than the C version.

Formula 1 - PS1, PC

C: Graphics engine, game logic & UI.
Nearly all of the game engine and game logic was written in C. The PS1 was the first console whose primary programming language was C. This was a new and exciting time allowing us to write far more complicated games than we'd ever done before.
R3000 Assembler: Vehicle dynamics (PS1)
We still needed every ounce of performance possible to simulate a full grid of F1 cars so the vehicle dynamics were written in R3000 assembler, also the vehicle dynamics coder was a little crazy and he liked that sort of thing!

Thursday 15 January 2015

Quick Debugging Tip

If you have a minor bug that you just can't fix, step away from it. When you are relaxed and thinking of something else, the answer will pop into your head.

Sunday 11 January 2015

Recommended Programming Books

People often ask me what games programming books I would recommend. To be honest most of them aren't worth reading and are often written by people who have never shipped a game. After all being a game programmer is a more well paid and rewarding job than being an author so it's hardly surprising.

There are exceptions of course, usually when a seasoned game developer wants to give something back to the community. Here is my (albeit short) list:

Game Engine Architecture is written by a guy who worked at Naughty Dog and is very comprehensive.

Game Coding Complete is written by a guy who worked at the legendary Origin Systems and contains some great anecdotes about his time there.

Game Programming Patterns is a newish book and also a really good read, I especially like the introduction. There is a free online version here.

The Art of Game Design: A Book of Lenses is easily the best book on game design I have read, rather than tell you how to design games it teaches you how to evaluate you own game designs.

There are some good general programming books of course, especially Scott Meyers books on C++, I'll probably cover general technical books in a later article.

Friday 9 January 2015

Metabuilder

Before we started working on Geometry Wars 3 we realised that one of the biggest challenges we would face would be to maintain all the code projects for the platforms we were developing for.

Most of the team had worked on cross-platform games before and had used various build systems - cmake, jam as well as various proprietary build systems. We came to the conclusion that nothing we could find that was available to us would satisfy our requirements. We decided that we needed to develop our own build system.

One of our programmers wrote Metabuilder, it is essentially a Lua scriptable system for generating Visual Studio & XCode projects as well as makefiles. It was absolutely instrumental in getting GW3 delivered on time on all the platforms we were developing for.

We decided before starting work on it that we wanted it to be made publicly available and you can get it on GitHub from here.

New Year, New Blog

One of the things I decided to do this year is to try and share my knowledge and experience of game development in an attempt to help others who are trying to get started in this exciting and fun-packed world!

I've been developing games professionally for nearly 20 years. Initially I worked at Bizarre Creations and was a Lead Programmer there until it was closed down. After that I set up Lucid Games with a number of other ex-colleagues from Bizarre and my current role there is Programming Director.

This is the first blog I have written so it will be a bit of an experiment. Since I don't have a huge amount of time I will try and keep entries short and informative.