Egad, two updates in as many days?!

September 30th, 2009

Yep, that’s right, I’m writing blog posts on consecutive days now. Whatever next; Twitter?

Anyway, I’ve tapped on my keyboard a bit more and have now gotten rid of those pesky Piece and Debris classes once and for all, and fixed up some bugs that have crept in during my purging. Pieces are now defined by their behaviour components, which take their parameters from good old objects.xml. To show off how fantabulous this is, I went and added raise pieces in the shapes of crosses, lines and blocks, and had them hooked into the game in probably under a minute.

Eye candy is always nice, so here’s a screenshot of the CITS after a couple of minutes of play:

Busy island

No more buildings any more

September 28th, 2009

I’ve done a wee bit more work; the Person class is now completely gone and replaced by GameObjects with PersonBehaviourComponents. Also Building, and its subclasses SmallHouse, LargeHouse and RaisableHouse are gone, replaced by GameObjects with NormalBuildingBehaviourComponents and RaisableBuildingBehaviourComponents. What this means to me is squeaky clean code and the right to lord it up over other programmers, and what it means for you is that I can now edit my objects.xml file to have a “Lighthouse”, “Observatory”, “Sheep Factory” and so on without having to go through lots of copying and pasting (and subsequent maintaining) of lots of C++ code. Hurrah!

I actually removed Person a little while ago, but I didn’t think you’d be particularly interested. Not that removing Building and friends is any more interesting to you but it was quite significant to me! That, and Rich told me to write another post. Is this satisfactory, o great blog critic? :)

Isn’t XML clever?

August 9th, 2009

One of the things I’ve been doing recently is transitioning from an inheritance-based to a component-based game object system. I started the project with full knowledge that component-based game object systems are better, but intentionally didn’t implement one since I thought it would be unnecessary for such a small game. It turns out that I was wrong, and since it’s something I’m very interested in and have thought about a lot, and since something similar was going on at work, I thought I’d give it a go.

Originally I had specific classes (Building, SmallHouse, Person) that handle everything about themselves (like graphics, physics, game logic) and do all their processing in a big ‘update’ method. I’ve factored out and moved around this code through several stages, keeping it building and running along the way, as it’s dangerous to just rip it out and start again. Now I’m at a stage where these classes have been replaced by a GameObject class, which owns a collection of Components, whose subclasses like PhysicsComponent and GraphicsComponent are registered with and updated by PhysicsSystem and GraphicsSystem respectively. GameObjects can be created by name from a GameObjectFactory, and object types can be created and registered at runtime, or from an XML file. So I now have an ‘objects.xml’ file that looks a bit like this:

<objects>
 <object name="SmallHouseDebris">
  <component type="Graphics">
   <property name="meshName" type="string">
    smallHouse.mesh
   </property>
   <property name="translationOffset" type="Vector3">
    0 0 0
   </property>
   <property name="scale" type="Vector3">
    1 1 1
   </property>
   <property name="rotationOffset" type="Quaternion">
    1 0 0 0
   </property>
  </component>
  <component type="Physics">
   <property name="size" type="Vector3">
    3.8 3.8 3.8
   </property>
   <property name="translationOffset" type="Vector3">
    0 2 0
   </property>
   <property name="contactGroup" type="unsigned int">
    2
   </property>
  </component>
  <component type="DestroyAfterTimeBehaviour">
   <property name="timeUntilDestruction" type="float">
    10.0
   </property>
  </component>
 </object>
</objects>

What a difference! If you aren’t impressed by that, you’re either not a programmer, or you’re a programmer in a field a bit less backwards than video games.

Now, I told a bit of a fib; actually the only class I’ve completely removed is ‘Debris’, since changing everything at once would have involved a lot of copying and pasting, as a lot of the intermediate steps were actually quite ugly and verbose. But now that I’ve proven the system works for Debris, I can get rid of all the other ‘game object’ classes. Then the only C++ code I write for game objects will be for their game logic, if that can’t be reused from existing components.

As such, the visible results you can expect from this are a variety of interesting new buildings some time soonish!

Why CITS got git

June 23rd, 2009

Subversion is good, don’t get me wrong, git is just better! In a nutshell, git is a fast distributed version control system, which supports a much more flexible style of development than Subversion. The two features that prompted me to switch were its distributed nature and its support for branching.

The distributed part is interesting; instead of checking out “the latest version” then checking in your changes, you make a complete clone of the repository (including history), do whatever you want with it, then merge your changes to wherever, you want, however you want. The main reason this is interesting to me (and the main thing that prompted me to use git) is that it means I can work completely ‘offline’, in that I can view full history, make commits, branch and so on without having access to the server. My server is actually an ordinary desktop PC that dual boots into Windows, so sometimes it’s not available, and being able to still work properly when it’s not on is brilliant. Using Subversion, I would end up building up large changelists whilst waiting to be able to commit, which is a bad thing. Additionally I wouldn’t be able to view history or revert anything to a previous version, which are two things that are needed more often than you’d think.

Git’s branching is also very useful to me. It supports fast and local branching and merging; branching is a lightweight operation, you can have branches that are local to only one repository, and merging is pretty brilliant.

I tend to flit between tasks depending on how I feel when I sit down to do some work. Sometimes I’ll want to do some refactoring, sometimes I want to work on a new feature, sometimes I feel like making some new art. Under Subversion, one way to do this would be to work on all of these in the same working directory and selectively commit parts of that when they are ready. That’s dangerous because it’s then impossible to test changes in isolation – I may end up checking in something that depends on something I’m not checking in. It also becomes a pain when changes overlap, as you then can’t selectively commit anyway.

You could also save changelists and apply them when you want to do some more work, or commit, but then you’re losing many of the benefits of source control, in that each of these features is effectively now one version, and they’re not backed up on a server.

Another way to do it would be to create branches and work within those, but Subversion doesn’t do branches very nicely. Branches are basically just a dumb copy of the whole working directory to another directory, and as such are checked in to the main repository visible to everyone. With git, you can quite easily create and switch to a new branch, do some fiddling, switch to another branch, fiddle some more, merge the two branches and commit the result. This is perfect for me, and is exactly what I do, except with several days between each step! You can commit several times to each branch, you can store work in progress (via git-stash) so you don’t have ugly half-finished commits, and the ‘main’ repository (the central server visible by everyone) needn’t know about any of this. You just push to it once a series of commits that make up some number of features is deemed ‘done’.

Of course there are plenty of other niceties that come with using git, but these were the two most important things to me.

I’ll go into exactly how I use git in my next git post. Stay tuned :)

Migrating from Subversion to git

May 17th, 2009

One of the things I’ve been busy with is migrating Cities in the Sky’s source control from Subversion to git. I’ll go over the reasons in full in a later post, but in a nutshell, git supports my workflow better than Subversion since it is distributed and supports fast branching and merging.

Now, there are some good guides dotted around the net which deal with migrating from Subversion to git, and with setting up a git server in a secure and maintainable manner, but I found them lacking a little in friendliness and details. There are also a lot of blog posts that more or less copy those guides and add in nothing of their own, sometimes to cheaply draw visitors to their sites, sometimes “in case I forget where the original is”, and sometimes just for the hell of it. Rather than add that little bit more redundancy to the Internet, I thought I’d write up a friendly explanation about just what these guides are doing, along with some extra advice I discovered to be useful.

Installing git and git-svn

So let’s get started! The first step is creating a git repository from your Subversion repository, which is made pretty easy through the use of git-svn, which is a tool for using git locally with a remote Subversion repository. I’m going to go ahead and assume you’re using some flavour of Linux – I’m using Ubuntu. I believe git-svn is supposed to be installed as part of git, but for whatever reason it isn’t on Ubuntu, so to install git and git-svn I had to do this:

sudo apt-get install git-core git-svn

Converting your repository from Subversion to git

Once you have installed git and git-svn, follow this guide on Simplistic Complexity and you’ll have a local git repository containing the full history of your Subversion repository with all the Subversion users mapped to git users. This bit is pretty easy, so the only piece of advice I have for this step is that in the users file you can add entries even for those ‘no author’ commits – just use the exact string Subversion reports as the author of the commit. For example, my users file looked like this:

Ben = Ben Hymers &lt;my.email@host.com&gt;
ben = Ben Hymers &lt;my.email@host.com&gt;
(no author) = Ben Hymers &lt;my.email@host.com&gt;
root = Ben Hymers &lt;my.email@host.com&gt;

There will often be odd users like these near the beginning of a project’s history, from the initial import or just before proper authentication was set up. Including these lines ‘fixes’ the history for the git repository.

Securely serving your git repository

The next step is to set up your server to serve your new git repository securely, since at the moment it is just on the local filesystem and will only be available to users that have permission to access the directory. Read through the excellent directions in this article on scie.nti.st. If you understood them perfectly then go ahead and use them, if not then read on!

Some background knowledge

It’s probably helpful to mention that a git repository is basically just a directory, which contains metadata and a big load of compressed bits and bobs which comprise the data of your project over its history, and optionally a working copy. If it has a working copy, which is typically the case when you’re a developer doing some work on the repository, the git data will be stored in ‘.git/’ in the root of your project, whilst the working copy will be present as normal. If it doesn’t have a working copy, it is what’s called a ‘bare’ repository, which is typically what a server will use as it has no need to modify anything, and the git data will just be stored straight in the directory. A ‘git server’ then is some process that makes this directory available to others via something other than just the filesystem.

The way we’re going to serve up the git repository is via SSH. Once it’s set up, commands you issue to git that require the address of the repository (clone, push and so on) will cause git to SSH into the server machine, to the directory that is the git repository, to perform their monkey business.

I hadn’t really used SSH before this so it was all quite alien to me, but there are plenty of articles on SSH and public key authentication on the web; I suggest you read one of those to understand why we’re creating keys, how they’re used, and what they mean.

We set up a user called ‘git’ who will own all the repositories. We do this so we can keep the permissions as specific as possible (if a user is compromised, damage is limited) and to avoid having to set up a user on the server and grant them permissions to the appropriate git repositories every time a new external user wants access. Instead, all access to the git repositories will be done via the git user – external users will SSH into the server as user ‘git’.

It’s also handy to know that git repositories are commonly named with the suffix ‘.git’, to show that the directory is a git repository. It’s like a file extension for directories.

Finally, the git documentation says that addresses of the form “[user@]host.xz:path/to/repo.git” are equivalent to addresses of the form “ssh://[user@]host.xz/~/path/to/repo.git”.

So, with those nuggets of knowledge in hand it becomes a bit clearer what lines like ”

git clone git@my_server:my_repository.git

” mean. ‘

git clone

‘ is the command to clone a repository given as the argument. The strange-looking address can actually be reinterpreted as “ssh://git@my_server/~/my_repository.git”. Breaking that apart, we see that we are connecting using the SSH protocol as user ‘git’ to ‘my_server’, in the directory ‘~/my_repository.git’. ‘~’ is unix shorthand for the home directory, and since we are connecting as user ‘git’ this will be git’s home, which is where the repository resides. Isn’t that clever?

Setting up gitosis

Now, what’s this gitosis stuff all about, and how does it help you create and maintain git repositories? Well, you could create the git user, and log in as git to add users’ keys and to create repositories in your home directory yourself, but that would get a bit tedious, and quite tricky when you have multiple repositories that each have different permissions. Gitosis automates all that, and hosts the configuration via git in a clever recursive manner.

Follow the commands in the first section of the article linked above and you’ll have checked out (via git) the gitosis config, ready to create repositories and authenticate users. Note that initially there will only be one user able to access the configuration – the user whose public key you initially gave to gitosis – which is nice and safe. It doesn’t have to be someone local to the server. Configuration is pretty simple – there is a directory for public keys, into which you place keys you collect from users’ machines. Then there is a configuration file, in which you list groups, which consist of users that are members, and permissions to repositories. Repositories are created implicitly – list one as writeable by some group, and after you commit the config changes it will exist and you can start pushing to it.

So, to add a user, get them to generate a public key and give it to you. You then name the key appropriately (e.g. “ben@windowsmachine.pub”) and place it in keydir/. Find or create a group that has the permissions you want the user to have, and add the name of the public key file (without the .pub extension) to the ‘users’ section of that group.

If you want to allow more people access to the configuration, do the same and add them to the default ‘gitosis-admin’ group, which has write access to the gitosis-admin repository, the one you are editing. You won’t want to go doing this too much for security purposes, but I did it to grant myself access from my other machines. Commit your changes and gitosis will update its configuration automagically.

The only advice I need to give on setting up gitosis is to follow the directions exactly, to the letter. A little knowledge is a dangerous thing, and since I have a little knowledge I ended up skipping out some commands or doing them my way since I thought I knew what I was doing, and as a result ended up undoing and redoing most of those steps several times until I realised I’d broken the whole thing and had to start from the very beginning.

Tying it all together

To tie these two steps together – converting your repository from Subersion to git, and hosting it via gitosis – you just need to push your new git repository to one you have listed in your gitosis config. You can either do this by giving the address of the repository to the push command, like so:

git push git@my_server:my_repository.git

Or you can add a ‘remote’ to your git config so push has a ‘default’ place to push to, like so:

git remote rm origin
git remote add origin git@my_server:my_repository.git
git push

We remove the remote ‘origin’ first since it’ll likely already be set to the location of the git-svn repository you cloned from, and there’s little point pushing back to that one! ‘origin’ is as it sounds – where the repository was cloned from – and is the default remote to push to. There are plenty of other rules that determine what ‘default’ means but none will apply unless you’ve done anything other than what’s listed here! Consult the git-remote and git-push documentation for more details.

From then on it’s business as usual, and you can use whatever git workflow you fancy. Since you’ve just converted from Subversion you’re probably used to the checkout -> edit -> update/merge -> commit workflow, in which case you’ll probably want to mimic that until you get used to git and want to try out anything crazy. I found the Git – SVN Crash Course useful for this.

There you have it then; hopefully with the combination of the articles I have linked and the extra explanation of what they are doing I have given, you will be able to migrate from Subversion to git in a secure and maintainable way with ease. Good luck!

Random bits and bobs

May 13th, 2009

Just a small update this time; I noticed the lighting was a bit odd in that the surface of the island seemed to be shaded uniformly and the underside was a bit too light, so I tweaked that.

Also I noticed looking at the past few screenshots that the island is the same each time, when it’s meant to be random! That’s a shame since I spent quite a while making a nice island generator. So I reinstated that code and now it’s generating random islands again every time.

Lighting tweaks and random island

You may also have noticed that I’m now using Flickr to host screenshots (well done you). I chose Flickr because Picasa seems to reduce the quality of its thumbnails massively, which is really annoying and makes CITS look even worse than it should do. Also Flickr’s image previews happen to be exactly the same width as the text on this page which pleases me :)

Still, one tiny update in over a month? I’d be a bit miffed if I were you. Trust me though, I’ve been doing all sorts of other interesting things (that don’t deserve screenshots) which I’ll post about very soon!

Happy little chaps and demolition

April 6th, 2009

As I said in my last post, the next thing I wanted to get done was to fix up the physics on the raisable buildings by rejiggling the code for the Building class. I’ve now added ‘Debris’ which is spawned by each ‘Building’ when it decides it’s time to fall off the island. Currently all the buildings just spawn a piece of debris that looks exactly like the building itself, though in the raisable building’s case this means one piece per floor.Broken buildings and little people Since the physics can be a tad unstable at times, this can result in interesting-looking explosions such as that pictured in this screenshot!

You may also notice there are some bright orange buildings there. If you don’t notice them you’re not looking very hard. They’re just replacements I made for the ‘tudor house’ mesh that I borrowed from Ogre right at the start of this project – it was unnecessarily highly detailed, a bit ugly, and not mine. These new buildings have only one of those problems.

I also replaced the graphics of the people – they’re now little chaps made out of several cuboids (what an evolutionary leap!). They’re even textured! You can’t see it from the screenshot, but they each have a smiley happy face. They’re blissfully unaware that if ‘trippedOver’ ever returns true, they’ll be launched upwards with ‘10′ force, which although unitless is definitely quite deadly, and comical.

Next I’m going to do a bit more rejiggling (’refactoring’ is a term many programmers use inappropriately, so it’s sort of lost its meaning. ‘Rejiggling’ is a good replacement I think), since there are a few bits of code that are being duplicated every time I add a new type of object. After that I’ll be adding some ’special’ buildings and updating the game logic a bit, which will be fun :) That will probably have to wait until after Easter though, since I’m off to France with my girlfriend for a bit first!

Skyscrapers

March 30th, 2009

Tonight I added those raisable buildings I was talking about. This involved a lot more work than you’d think! Mostly this was because it’s quite a radical change from the way things are done currently. Each building is made up of several meshes now – a ground floor, a roof, and several middle floors, whereas before there was the assumption that there was a 1:1:1 mapping between building, physics object and mesh.

You may also notice that I’ve thrown some random rotations of buildings into the mix. This pretty much came for free when I was adding in all the other stuff, so I’m happy since it makes things look a whole load more interesting! Similarly, it’ll now be easy for me to add things like stilts/foundations to make sure buildings don’t hover like they can now, or to add scaffolding temporarily just after construction, or to change the appearance of buildings entirely (make them more futuristic as the game progresses or the buildings are developed enough). All graphical niceties that I’ll get to in time!

Unfortunately I’ve broken the physics on those buildings since they can no longer just take their position and orientation from their physics component (otherwise the whole building would be at ground floor level), but I haven’t bothered to fix this since that’s next on my list of things to revamp. I’ll make buildings spawn ‘building chunk’ objects when they collapse, which will improve things in many ways – the Building class will then have one responsibility rather than two (it currently has states for ‘free’ and ‘attached’, the ‘controlled’ state being lost when I factored that out into the ‘Piece’ class), there will be the possibility for multiple building chunks with different graphics to that of the building they came from (proper bits of rubble!), and the Building object will need physics only for collision detection and not to physically attach it to the island.

Still bringing home the bacon

March 20th, 2009

Well, if you didn’t know already you’ll know after reading this or this – Rare announced last month that it would be doing some ‘restructuring’, which is a friendly term for sacking a bunch of people. The whole process has been farcical at best, and has demoralised everyone thoroughly, but the powers that be have now let some people go. Thankfully I’m not one of them (which is fortunate since my redundancy payout would be pennies, and the Midlands isn’t exactly bursting with game development studios that would welcome me with open arms), but it’s been difficult seeing some of the people I work with depart, especially those that weren’t planning on walking out anyway. I hope they land on their feet, and something better finds them.

So there you go, a brief ‘behind the scenes’ glimpse at the sham of a mockery of a sham that is the games industry.

Surprise!

March 8th, 2009

Hah, I bet you didn’t think I’d wait this long before posting those interesting things, did you? Did you?

What I’ve done is had a good ol’ rethink of the way the gameplay is going to work. Up until now, the idea has been that individual buildings fall from the sky and get attached to the island when they hit it. If you build on top of an old building, you destroy both the old and the new. Your score was going to be decided on a measure of each building’s quality (depending on where on the island it was placed, and which other buildings were around and so on), multiplied by the number of people, to get a rough measure of the total ‘happiness’ of your population.

The problem with this is that you’d quickly run out of space and end up being forced to destroy all your old buildings. There would come a time when your island is full, and your task would change from building a nice city to coaxing the physics system into not wrecking everything each time you place a building. Development would be linear, and capped, and I don’t think that would be very fun.

I went through a few more ideas after this, and after some discussions with the guys at work (that means you Rich!) and an old university chum (that means you Mike!), I’ve come up with something that plays well in my head, which I intend to try out. It’s just a few changes to the old idea, but I think they add up to something quite fun.

Instead of dropping actual buildings, you now drop pieces which can create buildings, or perform some other function. The main pieces will be ‘raise’ pieces, which will raise whichever buildings they hit (or create them if not present. These buildings will be your ordinary houses, and the idea will be to just have as many of these as high as you can make them. Of course the higher they are the less stable they are. The other main types of pieces will be the special pieces, which build buildings like docks, windmills, farms, mines and so on. These will generally have some criteria for where they can be built – docks at the edge, windmills up high, farms on flat ground – and will sometimes have gameplay effects other than their physical presence – mines will mine out a cavity inside the island gradually which will act as a negative weight, docks will attract merchants which will serve as other physics objects to get in the way.

Scoring remains cumulative over time, but instead of the previous sum of building scores times population, it will be a general ‘development’ score (which I see being a sum of ordinary buildings and their heights), affected by several multipliers relating to the special pieces. These multipliers will be things like ‘have 3 docks’, ‘have 3 windmills’, ‘have a really tall ordinary building’, and will be shown as greyed out icons next to the score when inactive, and lit up when active, probably with some crazy effects when several of them are acting together.

I’ve made a start, in that I’ve re-jiggled things to no longer drop buildings but to drop pieces, and I’ve added multi-part pieces (just an ‘L’ shaped raise piece at the moment), and added the base functionality for the raising mechanic (Note that you can also see the temporary Flash-based replacement for the in-game GUI in this screenshot!). In doing all this I’ve learnt some 3D modelling with Blender, which was different. Just today I figured out how to do UV editing and texturing, and exporting that information from Blender into a format that OGRE can use. All that must have appealed to my previously undiscovered inner artiste, since I then spent a few days learning to use my graphics tablet to do a spot of ‘digital painting’, but that’s a story for another day!