Friday, October 29, 2010

Legend of the Guardians: The Owls of Ga'Hoole <= 15 Words

A brilliant film for kids featuring non anthropomorphized owls... and Snyder still manages spectacular action.

Thursday, October 28, 2010

What todo?

The return train ride after a visit to my parents' house is, if anything, more pleasant that the outward journey. This is not least, of course, because it ends in Edinburgh, rather than Doncaster*. Be that as it may, this is perhaps a good time to pick up the thought I left hanging at the end of my last entry, in which I talked a little about ways of keeping notes and writing down ideas. Having dealt with information, we now come to action. From stasis, to process. Less obliquely: what, exactly, are you going to do about those ideas?

For the longest time I never kept todo lists. I tried to keep my goals and the individual steps required to reach them inside my head. Sometimes this worked quite well; thoughts are things which are simple to rearrange and update as requirements change, after all. Other times, not so much. In short: I forgot things.

My first attempt at organising these things was quite simple. I wrote a todo list down in my lab book. Paper is always I good place to start for a lot of things. Simple is generally a good place to start, also. I'd say this worked almost flawlessly on the occasions when I finished every item on the todo list I wrote on a particular morning by the end of that day. The problem appears on the days when this doesn't happen. You don't always carry out the tasks in the order you wrote them down, because that doesn't always make sense, and there's no way to rearrange the order of the items short of rewriting the list (yeah, right). As result, you end up with a partially completed list to be carried over to the next day. Worse still, often times a single item will subdivide into numerous smaller tasks when you come to take a closer look at it. So now you have two lists on different pages of your book, with some miscellaneous notes (and quickly jotted down take-away orders) separating them.

Version 2 worked a lot better, and I still use it from time to time. Basically, you write each item down on a post-it note (the 2.5*7.5cm ones are ideal, though a little hard to find) and stick it on a flat surface close to where you work. You're then free to re-arrange them to you hearts content and, best of all, when you finish an item you get to take it down, screw it up into a little ball, and throw it in the bin. Very satisfying. Take that todo list! Obviously this isn't as mobile as version one, though you can pull the post-its down and stick them in a book to take with you. If you always work in the same place it's pretty great though. It's also fairly obvious, so apologies if I'm not telling you anything new here.

What version 2 doesn't do is allow you to easily add things wherever you are, share your todo lists, or integrate into your more everyday todo type scenarios. In particular, I do not recommend using this approach for shopping lists. That isn't going to work. As a result, I started looking at more computer based approaches (surprise, surprise). I gave Remember The Milk a try for a while, but the browser based approach doesn't work for me. I like applications to integrate with my desktop.

This was around the time that the brilliant OmniGroup announced OmniFocus. I already use (and love) OmniOutliner and OmniGraffle, so this looked like a pretty good bet. Plus they later announced that an iPhone version was coming as well. Perfect, or so I thought. As it turned out, I much prefer Cultured Code's Things, however. It is, quite frankly, the desktop todo manager of my dreams. It's Mac only though, which doesn't help me if I think of something at the office, or on the bus. Fortunately, there are also iPhone and iPad apps available, which are equally sweet. They like one crucial feature, though: web sync. Sure, I can sync them over wireless, but this is much less use to me. I have to actively do it, rather than just fire up the application and wait for the magic to happen. It's on the road map, but I'm still waiting. Side note: OmniGraffle does have web sync, but I don't like it as much, and it's a lot more expensive. It might be perfect for your needs, however.

Which brings me sort of full circle, to my shiny new Clockwork Aphid project. At this point I've mostly just been implementing things as the mood takes me, maybe planning a couple of steps ahead. I probably need a bit more structure than that. The post-it note and Things based approaches both have their benefits, but their are a couple other things to take into consideration. First of all, I'm using the fabulous BitBucket.org to host my source code, and that come with a handy issue tracker. Especially handy should anyone else join the project once it get a little bit more fleshed out. Another interesting possibility is the Mylyn plug-in for eclipse (my code editor of choice), which provides you with a "task based interface." In other words, it hides the clutter and shows you only the parts of your project you need to care about for the particular task you're working on. That's quite interesting, but works best when you link it up to a central issue tracker. Frustratingly, it doesn't work with the BitBucket issue tracker. It does work with Atlasian's Jira, however, and Atlasian recently acquired BitBucket, so hope is not lost.

These approaches are clearly better tailored to what I'm actually doing, but neither is as user friendly as either the post-its or Things, especially when it comes to adding new tasks, and that's the bit you need to do quickly, brain-dump style. The search continues...

I, of course, welcome any alternative todo list solutions you'd like you leave in the comments. <subliminal>Please comment on my blog.</subliminal>

* Know this: no written text, regardless of italicisation, can accurately reproduce the tone of my voice when I say the word "Doncaster."

 

Tuesday, October 26, 2010

The Journey Home

Authors note: This post was actually written on Sunday. As it turns out, writing it on the iPad was no problem at all, but actually posting it (with the picture and links) was a different matter entirely.

You know, the train journey from Edinburgh to Doncaster is really quite beautiful, for the most part. A reasonable amount of it happens within sight of the sea and most of the rest passes through open country. The Yorkshire dales is a landscape I find quite pleasing to look out over, unless I'm driving through it, in which case I find to to mostly feel endless. Some of the towns you pass through have more charm than others, of course. Newcastle isn't without its fans, and Berwick-Upon-Tweed is gorgeous, but I can't see anyone wanting to put Doncaster on a postcard any time soon.

Why the sudden reflection? I'm on the way down to visit my parents for a couple of days and for the first time in years I'm not taking a "real" computer with me. The implication here, of course, is that I'm taking something which is not a real computer, or at least something which some don't consider to be one. I picked up an iPad on my recent work trip down under (AU$ was doing quite well against USA$ at the time, which knocked a considerable amount of the price as far as I was concerned) and that's a gadget I have with me. Yes, I'm typing this on an iPad. I actually typed the majority of this post on it as well, using the on-screen keyboard, and it wasn't too bad at all. The biggest problem was that it reduced to effective screen area so much. Right now, though, I'm using a bluetooth keyboard for the typing. The iPad itself is resting on the crappy little shelf  attached to the seat in front (angled using one of these cases, which I highly recommend), while the keyboard is sitting on my knee, actually under the shelf. All in all, this setup is one hell of a lot more comfortable than a laptop would be in these circumstances. So that's definitely a win.

I didn't buy this thing to replace a laptop exactly, though. That would be silly. Nor did I intend to replace a smart phone with it. That makes no sense. What, then, is it actually for? This seems to be the number two reaction to seeing the thing in my experience. Number one being "cool!" and "it looks just like a giant iPhone!" being quite high up the list, as well. No, what I intended to replace with this gizmo is one of these:



As a general rule, I need to write thinks down more. I should probably make more notes of ideas and such which occur to me when I'm not in a position to do anything about them, and I find that todo lists are basically a necessity when it comes to keeping myself organised. Paper is pretty good for this, as a general rule. I'm pretty fond of my squared paper moleskin journal and when it comes to just scribbling things down I'd say it's pretty much unsurpassable. But, and there's usually a but, carrying it around at all times isn't exactly practical and it doesn't have an erase (or move) function, which isn't ideal when you suddenly realise that the diagram you've been working on for the last half an hour really needs to be about an inch to the left if you're actually going to fit the whole thing on the page.

If you're using Evernote for your notes, though, then jotting things down with a phone (which I do carry at all times) becomes an option. Throw in a couple of other applications and scribbling, brainstorming and generally playing with ideas does become a legitimate possibility. A possibility contained in something no larger than a Moleskin, which does have an erase, and indeed a shift-a-bit-to-the-left, function. Todo lists are a different matter, though, and I'm going to come back to those later.

As a final note here, it should probably be quite obvious that I'm not going to be doing any clockwork aphid related work in the next couple of days, as hacking is not currently a legitimate possibility on the iPad. Someone really needs to write an app which interfaces with Eclipse (or any other IDE) on your desktop and turns it into a context sensitive programmer's assistant keyboard type thing, though. Expect good things to show up towards the end of the week, however.

Friday, October 22, 2010

Fractal Errata

Some of the particularly sharp/anal ones amongst you might have noticed that while the technique for generating fractal lanscapes I previously described works (and works well), it's not 100% correct. Specifically, the fact that it uses the the same scaling factor for nodes created by the diamond and square steps isn't quite right.

Why is this? Because they generate nodes which adhere to different levels of detail, that's why. Lets go back to that last diagram for the post which described the algorithm:

[caption id="attachment_355" align="aligncenter" width="357" caption="Diamand step (left) and square step (right)."][/caption]

Now while you'll note that both steps add nodes that can be addressed using fractions with two as their denominator, the distance of the nodes created by the diamond step to their parents is greater than those created by the square step.

The nodes created by the square step are orthogonal to their parents, so the distance between them is proportional to a half, which as luck would have it has the same as the denominator as the fractions used to address the node. How convenient!

The nodes created by the diagonal step, on the other hand, are diagonal to their parents. This means that the distance to their parents is the pythagorean root of this same distance, so in this specific case:
sqrt(½*½+½*½) = sqrt(¼+¼) = sqrt(½) = something

Once again, the key fraction used to work this out has the same denominator as those used to address the node in the landscape. Thus, if d is equal to the denominator we're using to address a node, the basic scaling factor used to offset a new node from its parents would be the following:
if (diamond step) range = [-sqrt(1/d*1/d*2), sqrt(1/d*1/d*2)]

else range = [-1/d, 1/d]

As I said before, this won't make a lot of difference, but it will be more correct and that's important to some people. Myself included.

For comparison purposes this is the effect this change has on the example landscape I've been using:

[caption id="attachment_366" align="aligncenter" width="296" caption="The original scaling method."][/caption]

[caption id="attachment_388" align="aligncenter" width="296" caption="The updated scaling method."][/caption]

There's some difference visible, but not a huge amount. Mostly, it's just increased the range the data are occupying and expanded the bell curve accordingly. Hence, more high points and more low points, but the land is the same basic shape.

Now In Eye Popping 3D!

It took a little bit of fighting with bugs that weren't showing up in the 2D view, and a bit of time to figure out what was going on with the lighting system in JME, but I finally got the 3D display of the fractal landscapes working.

The first stage was just displaying each node as a discrete point so I could see that each was in about the right place. It looks a little bit like this:

 

[caption id="attachment_372" align="aligncenter" width="481" caption="Fractal landscape as points (click for bigger)."][/caption]

 

I did this by simply piping the spatial coordinates and colour information of each node into a pair of standard Java FloatBuffers, passing these to a JME Point class (which should really be called PointSet, in my opinion) and attaching this to the root display node of my JME application. The colouring scheme is the same as the one used for the 2D display. Some things don't look quite right, largely due to the fact that I've just drawn the "underwater" points as blue, rather than adding any actual "water." Don't fret, it's on the todo list.

That said, the landscape looks about right. All the points seem to be in their correct location. As a quick implementation note, I'm defining the (x, y, z) coordinates of the scene in the following way:
x = east

y = altitude

z = -north

With some scaling factors used to map the values from the [0,1] range used to address them to slightly more real world like dimensions.

The next stage was to display the landscape in wireframe to make sure the connections I'll be using create a more solid looking polygon based display are all working correctly. Why not just go directly to polygons? You can see the the detail better in the wireframe display, making debugging much easier. I'll definitely be using it again later.

This time, instead of piping each and every node into the vertex array, only the nodes at the highest level of detail are used. These are the nodes generated during the final "square stage" of the fractal algorithm, for those of you playing at home. Each draws a triangle (consisting of three separate lines) into the vertex buffer for each pair of parents it has in the landscape. The result looks something like this:

 

[caption id="attachment_374" align="aligncenter" width="493" caption="Fractal landscape as lines (click for bigger)."][/caption]

 

Everything seems to be in good order there, I think. One or two things don't look quite right, particularly the beaches, but the tessellation and coverage of the polygons looks right. Here's a closer in look at some of the polygons so you can see what the tessellation scheme actually produces:

 

[caption id="attachment_376" align="aligncenter" width="442" caption="Polygon tessellation (click for bigger)."][/caption]

 

You can (hopefully) see that each of the "active" nodes sits at the centre of a diamond formed from the shape of its parents, so it's the points with four lines branching from them (rather than eight) which are actually being used to draw the scene.

Next: polygons. Again, only the nodes at the highest level of detail are used. This time, each inserts itself into the vertex buffer, then adds its parents if they're not in there already. Each node remembers its postion in the vertex buffer, and these indices are then used to draw the actual polygons. These are declared by passing the indices in sets of three into a standard Java IntBuffer. The buffers are then passed to one of JME TriMesh geometry classes and displayed, like this:

 

[caption id="attachment_373" align="aligncenter" width="512" caption="Fractal landscape as polygons (click for bigger)."][/caption]

 

Again, the beaches don't look quite right, but otherwise I'm reasonably pleased. I still need to add the actual water and improve the form of the landscape itself (and about a million other things), but in terms of display this is looking pretty good. Except for one thing: I'm using far more detail than I need to. Let me illustrate this with a slightly more extreme example. The pictures I've posed so far were generated using seven iterations of the diamond square algorithm. Here's what happens when I use ten iterations (remember, the number of points increases exponentially):

 

[caption id="attachment_377" align="aligncenter" width="614" caption="MOAR POLYGONS! (click for bigger)"][/caption]

 

On the bright side the beaches look better, but that's a lot of polygons. Far more then we actually need to display. 1579008 polygons, in fact. We need to reduce that somewhat, if we're going to make things more complicated and maintain a reasonable frame rate (I'm getting about 60fps with this view at the moment). You can see the problem more clearly if I show you the same view using lines rather than polygons:

 

[caption id="attachment_378" align="aligncenter" width="614" caption="MOAR LINES! (click for bigger)"][/caption]

 

You can just about see the individual triangles up close, but further away the lines just mush together. I think we can afford to reduce the level of detail as we get further away, don't you?

Well, I'll get right on that, then...

Wednesday, October 20, 2010

Some Random Landscapes

I don't have any 3D views of the fractal landscapes I've been making to show you yet, as I'm still working through the different implementation options. I did get a little distracted with the 2D views of the landscape this morning, though, and play with the colouring scheme.

First of all, let's start again with the example landscape used in yesterday's post, only with slightly more sober colours and a bar on the right showing how the height values map to actual colours:

[caption id="attachment_363" align="aligncenter" width="296" caption="Fractal coastlines."][/caption]

Now that looks reasonably neat already, in a "my first atlas" kind of way, but clearly there's a lot of information missing. We can see this if I plot the height values in monochrome, giving the landscape a more "plasma cloud" appearence:

[caption id="attachment_364" align="aligncenter" width="296" caption="Plasma cloud landscape."][/caption]

Now we can see the extra information, but we've lost a lot of the sense that what we're looking at is a landscape. It looks more like a cloud. We can get some of that back by combining the two approaches and using different shades of blue and green:

[caption id="attachment_365" align="aligncenter" width="296" caption="Shaded landscape."][/caption]

Now this looks a lot better. I think the water looks quite reasonable using this scheme, but the landscape is a bit... homogenous. Is every part of the land covered in grass? How boring!

We can make things a bit more interesting by adding a thin band of "sand" around the coast, and some "mountainy" colours (and snow!) higher up, like so:

[caption id="attachment_366" align="aligncenter" width="296" caption="More in depth colouring scheme."][/caption]

Now this looks better, the sand in particular. The mountains look okay, but not quite right. Something's a little off. That's not what mountains actually look like. We also don't have any rivers or above sea level lakes. These are problems I'm going to look at later, after I get a reasonable 3D display system working. In the mean time, though, here are a couple more 2D landscapes for your viewing pleasure:

[caption id="attachment_367" align="aligncenter" width="296" caption="A bit more snow and an inland sea."][/caption]

[caption id="attachment_368" align="aligncenter" width="296" caption="Yet another coastal region."][/caption]

Tuesday, October 19, 2010

You're Speaking My Landscape, Baby.



No, that isn't a typo... but yes, it is a bad play on words. That's the bad news. The good news: finally! A Clockwork Aphid implementation post!

If you're building something which relates in some way to virtual worlds, then the first thing you're going to need is a virtual world. This gives you two options:

  1. Use a ready made one;

  2. Roll your own.


Option 1 is a possibility, and one that I'm going to come back to, but for now let's think about option 2. So then, when building a virtual world the first thing you need is the lanscape. Once again you have two options, and let me just cut this short and say that I'm taking the second one. I did used to be a bit of a CAD ninja in a previous job, but I'm not a 3D modeller and I have no desire to build the landscape by hand.

So I'm going to generate one procedurally. As to what that means exactly, if you don't already know... well I'm hoping that will become obvious as I go along.

Traditional Fractal Landscape Generation


There are several ways of generating a landscape. A pretty good one (and one I'm quite familiar with, thanks to a certain first year computer science assignment) is the fractal method. It goes something like this:

Start off with a square grid of floating point numbers, the length of whose sides are a power of two plus one. I'm going to use a 5*5 (2*2 + 1) grid for the purposes of this explanation.

Set the four corners to have the value 0.5 (the centre point of the range I'll be using), thus:

[caption id="" align="aligncenter" width="164" caption="Grid based starting point."]Fractal Landscape Step One[/caption]

Now, we're going to generate the landscape by repeatedly subdividing this and introducing fractal randomness (random fractility?) using the diamond square algorithm. First the diamond step, which in this iteration will the set the value of the central cell based on the value of the four corners:

[caption id="" align="aligncenter" width="163" caption="The first diamond step."][/caption]

To do this we take the average of the four corners (which I calculate to be 0.5 in this case, because I did maths at school) and adding a small randomly generated offset, which has been scaled according to the size of the subdivision we're making. How exactly you do this varies between implementations, but a good simple way of doing it is use a random number in the range [-0.25,0.25] at this stage and half this at each subsequent iteration. So, on this occasion let's say I roll the dice and come up with 0.23. This now leaves us with:

[caption id="" align="aligncenter" width="164" caption="Result of the first diamond step."][/caption]

Next, we have the square step, will set the cells in the centre of each of the sides. Once again we take the averages of other cells as starting point, this time in the following pattern:

[caption id="" align="aligncenter" width="163" caption="The first square step."][/caption]

Now we generate more random numbers in the same range and use them to offset the average values, giving us this:




[caption id="" align="aligncenter" width="164" caption="Result of the first square step."][/caption]

That completes an iteration of the algorithm. Next we half the size of the range to [-0.125,0.125] and start again with the diamond step:

[caption id="" align="aligncenter" width="163" caption="The second diamond step."][/caption]

...and so on until you've filled your grid. I think you get the general idea. I've left out one potentially important factor here and that's "roughness," which is an extra control you can use to adjust the appearance of the landscape. I'm going to come back to that in a later post, because (hopefully) I have a little more that I want to say about it. I need to play with it some more first, though.


Once you've finished here you can do a couple of different things if you want to actually look at your creation. The simplest is to pick a threshold value and call this "sea level," then draw the grid as an image with pixels set to blue below the threshold and green above it:

[caption id="" align="aligncenter" width="256" caption="Generated fractal landscape."][/caption]

This was obviously generated with a slightly larger grid (513*513), but as you can see it creates quite reasonable coastlines. You can do slightly fancier things with it, such as more in depth colouring schemes and 3D display. For 3D, the simplest method is to use each cell as a vertex in your 3D space and tessellate the grid into triangles like this:

[caption id="" align="aligncenter" width="136" caption="Simple grid based tessellation."][/caption]

You can then do a couple of fancy things to remove the triangles you don't need, either based on the amount of detail they actually add or their distance from the user (level of detail).

This system works quite well, but tends to produce quite regular landscapes, without of the variation we're used to or the things generated by rivers, differing geology, coastal erosion, glaciation and other forces which affect the landscape of the real world. Additionally, because the data is stored in a height map, there are some things it's just not capable of displaying, such as shear cliffs, overhangs, and cave systems. The grid structure is also very efficient, but quite inflexible.

How I'm Doing it


Needless to say that's not exactly how I'm doing it. Of course there's generally very little sense in reinventing the wheel, but sometimes it's fun to try.

I'm not doing too much differently with the actual algorithm, but I am using a slightly different data representation. Rather than a grid, I'm using discrete nodes. So you start off with something like this:

[caption id="" align="aligncenter" width="121" caption="Node based starting point."][/caption]




Which then is transformed like this to generate the actual landscape:

[caption id="" align="aligncenter" width="357" caption="Adding further nodes."][/caption]

..and so on.

What you you can't see from the diagrams is that I'm using fractions to address the individual nodes. So, for instance, the node in the centre is (1/2,1/2) and the node on the centre right is (1/1, 1/2). This means I don't need to worry about how many nodes I have in the landscape, and the adress of each never has to change. The next set of nodes will be addressed using fractions with 4 as the denominator, then 8, 16 and so on. Before looking up a node you first reduce its coordinates down to a lowest common denominator (which is a factor of 2) and then pull it out of the correct layer. I'm currently using maps as sparse arrays to store the data in a structure which looks like this:

Map<int, Map<int, Map<int, LandscapeNode>


If you're thinking that this isn't possible in Java, you're half right. I'm actually using one of these. The first int addresses the denominator, then the east numerator, then the north numerator. I've looked at another couple of strategies for hashing the three ints together to locate a unique node but this one seems to work the best in terms of speed and memory usage. I might look at other options later, but nor yet.

This is a much more flexible representation, which removes some of the limitations of the grid. I can keep adding more detail to my heart's content (up to a point) and I don't have do it in a regular fashion. i.e. the native level of detail doesn't have to be the same across the entire map. More remote areas can have less detail, for instance. By the same token, I can keep the entire "landscape" in memory, but flexibly pull individual nodes in or out depending on where the user actually is in the world, saving memory. This also potentially gives me the following:

  1. The possibility to decouple the geometry of the landscape from the topography of the representation;

  2. A "native" way of implementing different levels of detail;

  3. A natural tessellation strategy based on connecting a node to its parents (maybe you spotted it);

  4. Enough data to allow the landscape to be modified to produce more dramatic features across different levels of detail;

  5. The processes for the above should be very parallelisable.


There are still a couple of things I'm working on (3D display for a start), as I've been obsessing over how to organise the data structures I'm using. Hopefully I'll be back tomorrow with some 3D views.

If you're interested in the code you can find it here. If what you found at the end of that link didn't make any sense to you, then you're probably not a programmer (or you're still learning). If you still want a look drop me a comment and I'll see what I can do.

Disclaimer: As far as I'm aware I didn't steel this from anybody, but I don't claim it's completely original, either.


 

Despicable Me <= 15 Words

As much a toy advert as a film, not bad, though, just "meh." Also: Brand!

The Social Network <= 15 Words

No Rosebud, but still fascinating. The script's the star, but the camera gets its moment.

Sunday, October 17, 2010

Epic Googleyep and Other Stories

Update: Redirected video to one which hasn't been nuked.

I'm currently doing some tests on a couple of different data structure implementations for Clockwork Aphid, so while they're running I thought I'd a bit of time to write a music related post, since I haven't done one in a while.

Epic Googleyep


As you may or may not be aware, I spent a reasonable percentage of this year (about ten weeks) working in Australia. Some of that time was spent working offshore in this general area. I spent the latter offshore time on a boat called the Unlimited (fun fact: the company which owns this boat has two others: The No Limits; and The Limitless), a 24m catamaran, with for much of my trip had its full crew complement of twelve. For those of you counting at home, that's two metres each. It was... a little cramped. It did have a reasonable common area, however, with a great big flat screen TV. Outside the harbor, TV reception was less than good, and it was fairly common that the TV would be left on in an area of good reception, only to have us drift (or actively move) into a much crappier area.

Such was it that I wondered into the mess when a certain music video was trying to come through from the other side. At least 50% of it was static, but what I did hear I quite liked. Much of what I actually saw consisted of a slightly emo looking guy walking through a forest towards the camera, backed by two strikingly attractive and very similar looking ladies (at the time I thought it might have been the same girl twice) in evening dresses, one black and one white. I wanted to know more, but the signal gave out completely before the song finished.

I did not have a lot to go on, so the next time the internet was functional, I fired up Google and brazenly typed in "music video black dress white dress," and... win! I love it when that happens. Here's the video:







It's a little bit emo, but I like it. Good tune. Unless you're reading this in Australia you've probably never heard of Micheal Paynter, but likely have heard of the The Veronicas, the two ladies singing in the background. Now... Perhaps this is down to the alluring power of a well cut evening dress and a knowing smile, but... Damn. I've generally thought of them as "pretty" (and sometimes "annoying," musically) but they really are stunning in this video.

You Are Speaking My Language!


The title of my previous series of programming language related posts was, in case you hadn't guessed, a reference to this:







Now, I love Juliette & The Licks, but this really isn't their best song. In actual fact I find this entire album extremely disappointing (with the exception of "I never got to tell you what I wanted to"), where as the other two albums don't really have a bad song on them. The song title fit the posts quite well, however, so I didn't feel I could leave it out. I spent some time on YouTube trying to work out which other song of theirs I should post as well, and ended up coming to the conclusion that this was a safe bet:







It's a good song and I love the video. I've also seen plenty of girls walking through Edinburgh at 11am on a Saturday who looked like they might break into this at any moment.

As an additional note here: Juliette Lewis herself confuses the hell out of me. I don't find her attractive no matter how hard I try, but I do find her extremely sexy no matter how hard I try not to.

Gaga For Gaga


It's another Lady Gaga cover and I love it!







This is clearly still Lady Gaga's "Bad Romance," but with a rock opera feel on top, which I feel works very, very well. I can imagine this version of the song sounding amazing sung by Freddie Mercury, but then I suspect that might be the case for most Lady Gaga songs (not coincidentally).

Saturday, October 16, 2010

Language Post Mortem and Some Other Notes

A couple nuggets of knowledge came out of my "You're Speaking My Language, Baby" series of posts, so I though I'd just take a quick moment to talk about them.

The first two are perhaps the most obvious by far. Firstly: if you actually write blog posts, people are more likely to read your blog. Funny that, huh? While my post on installing Celtx on the Acer Aspire one is still my most popular by some margin (probably because it actually provides some utility), I actually had my highest numbers of hits per day during the last week. Secondly: I get less hits over the weekend. Lax working habits for the win!

What's also interesting is the relative popularity of the individual parts of the series. Most popular first, it goes like this:

  1. Introduction

  2. C++

  3. Conclusion

  4. Java

  5. Objective-C


Now, my number of hits still isn't exactly stellar, so this is a fairly small sample size, but it's still quite interesting. People seem to be far more interested in reading about C++ than any of the other languages. In general, readers tend to want to know what it is I'm actually talking about, and what conclusion I come to, but when it comes to specifics, C++ gets the most interest. Is this a recommendation of the language, or the oposite, though? People could be reading what I say about it because they think it's the sensible option... or because the folly of the language makes them seethe with rage. Hard to say. Perhaps I'll look for some metrics of programming language popularity online.

In one of those curious events the internet throws up, the writer of a blog I read on a regular basis also just started to work on a project of a potentially similar nature, and started off with some musings on which programming language to use. I'm talking about Shamus Young in his Twenty Sided blog (I should really add it to my blog roll). Interestingly, and slightly comically, he came came to an equal and oposite conclusion to my own. He didn't consider Objective-C (not out loud, anyway), but decided that Java was the language to use if he wanted to produce something with commercial viability, but C++ was the language to use if he wanted to do some prototyping.

I'm still scratching my head at this in some ways. I don't care how much experience you have in C++, you're still likely to program faster in almost any language other than C. But in other ways it makes perfect sense. He has about a decade's worth of experience with C++ (likewise I have about ten years worth of Java under my belt), but only limited exposure to Java. He's looking at building a complete game, so he's being influenced by games like Minecraft (which I will be talking about more later) which were successfully developed by an individual (in Java, as I understand it). If you're making something a bit niche and you don't have massive amounts of resources, then having a game which can be effortlessly ported to every major operating system is a good thing.  You want to expand you potential audience as much as possible. Also, if your target demographic slants towards the nerd side of the spectrum then you don't want count out Linux, nor OSX (which gets more nerd love than you might expect). Having your game be able to run out of a browser doesn't hurt, either.

I'm not (at this point) looking at building a complete game, but a piece of technology which could potentially be used by multiple games, though. Something of the order of a physics engine. Middleware is the term I seem to hear used. Thus Java (which I have more experience with) is my prototyping language, but C++ makes sense as an eventual target.

I've been holding back on what I'm actually doing, but I essentially outed myself when I said it was similar to what Shamus is. So: I'm doing something connected to procedural content generation. I'll explain more about what that means as I go along.

In other news I have two weeks off work. Seems I haven't used the vast majority of my holidays this year and taking the entire month of December off is not considered to be ideal. Thus: I have two weeks to do with as I please. So long as what I please doesn't cost too much or inconvenience my girlfriend. I may visit my parents or even some of my friends down south. I'll also spend quite a bit of time sitting in coffee shops with a book and a note pad. Coffee shops are good places to think, I find. Just the right amount of bussle. I'm also going to crack on with Clockwork Aphid. I'm tinkering with some implementation details at the moment, but I plan on writing about what I have so far as well. I'm also hoping to make the Heston Blumenthal chilli con carne I mentioned in a previous post, but there are complications. Firstly, he's quite specific about the types of chilli powder you should use and some only seem to be available from the good ol' USA. They're on order, so hopefully they'll arrive fairly soon. Secondly, there's clearly a mistake in the recipe, unless Heston want me to boil a pan of water and prepare a bowl of ice water for purely ornamental purposes. This isn't completely outside the bounds of reason.

More updates soon. Look to the skies!

Thursday, October 14, 2010

There Can be Only... Several...

As I've previously mentioned, this project (Clockwork Aphid) has been bubbling away in the  bearded cauldron that is my head for quite some time. As a result, I have quite a bit I want to say about it. I want to blog about the process of building it because I think it might be a good exercise to go through, and also because I think it might help me work the whole thing out. I'm going to talk more about what it actually is quite soon, partly because I want to start talking about implementation and partly because I've been prompted by someone else's project which I suspect might be quite similar. More about that later.

What to do when something like that happens? I think there are two reactions you can to a situation like that: you can feel threatened; or you can feel vindicated. Clearly the second is the more healthy approach, so I'll go with that one. This is probably for the best, since there are other parties who seem to be coming at the same problem as I am. I mentioned at the end of my post about World of Warcraft that I wasn't the only one frustrated by the static nature of its world, nor the only one attempting a solution of sorts. Specifically, I was talking about ArenaNet's upcoming Guild Wars 2. They'll probably explain it a little better than me, so I'll let them:

The video was supposed to be embedded here, but WordPress doesn't seem to want to let me. You can find it here.

Now... clearly they have more resources than I do, which could potentially make me feel a little bit like I was staring up at a shear rock face. A rock face covered in bees. Happily, though, they're going about it in a different way, though some of our goals are the same. Guess that means I'll just have to come up with some pretty creative solutions, huh?

It should be noted that what they've essentially done is polarise the world. Parts of it are shared, and these are the parts with the villages you can actually save (or fail to save), while other parts of it are instanced, which means you have your own copy. So if I kill the dragon in one of these parts, it stays dead... but only in my copy of the world. The dragon in your copy is still alive and kicking until you personally cut its head off / stab it up the bum / jam some opal fruits down its throat. They talk more about the shared, dynamic parts of the world in their blog here and here, and the instanced personal stories here. I encourage you to read just about all of that blog, in fact. I found much of it fascinating and quite insightful.

While, I'm talking about Guild Wars 2, though it is worth taking a moment to marvel over just how stunning those visuals are. The comparison I find myself making is that World of Warcraft looks like it was made out of clay:



While Guild Wars 2, on the other hand, looks as though it was made out of china:



Now before you cry foul and point out that GW2 is a much newer game, it's worth taking into account that this china like quality was also true of the original Guild Wars:



Obviously some of this has to do with the different graphics engines being used, but I think that actual quality of the design is definitely a factor as well. It's evident in the 2D promotional art, as well.

I'm also quite taken with the difference in the mythology of the two games, but perhaps I'll talk about that later. Mythology will be quite a relevant subject, later.

Wednesday, October 13, 2010

You're Speaking my Language, Baby. Part 5: Conclusion.

Author's note: As this post started out HUGE, it's been split into parts. You'll find the introduction here, my comments on Java here, my comments on C++ here, and my comments on Objective-C here.

So... what's the conclusion? It mostly comes back to the fact that I'm doing this mainly for fun (though you may have trouble believing it). That being the case I'm going to start working in Java. In fact I already have started working in Java, and I've already written the first bits of code. I'll talk about and make them available soon.

I just can't ignore the sheer applicability of C++, though, much as I may dislike it as a language. Most game developers are going to have the majority of their legacy code written in C++ and that creates a lot of momentum. Games are among the more demanding things most people do with their computers, so they generally try to squeeze every last drop of performance out of the system they're running on. C++ does have the potential to provide a performance advantage over Java (even if you might end up loosing that to your AI system when you starting having to use Lua to script behaviours). Another one of the reasons for this project was to create a bit of work which might act sort of like a portfolio piece. So, once the project has reached an early, but functional, stage of development I'm going to re-implement it in C++ and then see how I feel about the two different implementations before continuing. It's not impossible that I'll end up keeping both, but more than likely I'll kill one and just stick with the other.

By a process of elimination you might have realised that I'm now counting Objective-C out. This is true, but I have another side project I may end up using it on. One which lends itself quite well to being either an iPhone/iPad app or a website. Or all three. Objective-C is clearly quite applicable to the first two, and surprisingly applicable to the last, if you go the Objective-C -> MacRuby -> Ruby on Rails route.

That was the plan, at least, until I went ahead and did something silly. I have more than a passing interest in programming language design and so found myself reading about other programming languages. Stupidly, I found a couple which have enough merit that I really can't count them out.

The first of these is D, which is designed to fix a lot of the problems with C++ whilst maintaining its advantages. It seems to succeed at this quite well, so far as I can tell. It also seems to have direct access to a lot of things built directly for C/C++.

Then we have Scala and Fantom, which use the Java virtual machine as their runtime. Both seem capable of achieving the same level of performance as Java itself, but take away some of the legacy cruft which Java has been unable to shake, whilst adding extra useful features. Scala I'm only just starting to learn about, but people seem to like it a lot. Fantom, I think, might be perilously close to being the perfect programming language by many metrics, though. Don't take my word for it, have a read about it. I dare you not to be impressed (assuming, of course, that you are the sort of person who gets impressed with these sort of things). It adds some very cool extensions and has direct support for some very useful things, such as allowing both dynamic and static typing under the developer's control.

Both Scala and Fantom can transparently use libraries written in Java, though Fantom can also deploy to both .net and javascript (for web development).

All three of the these languages are interesting enough for me for to not count them out entirely, so I might also try a port to one or more of them.

As always, comments are welcome, so please feel free to try and convince me of the error of my ways. Keep it civil, though, I know how excited programming language discussions seem to make some people.

Tuesday, October 12, 2010

The Town <= 15 Words

He did it again. It feels gritty, real, and more than a little heart breaking.

You're Speaking my Language, Baby. Part 4: Objective-C.

Author's note: As this post started out HUGE, it's been split into parts. You'll find the introduction here, my comments on Java here, and my comments on C++ here.

The last language I'm considering is Objective-C. I know this language the least of three. To make matters worse, while Java and C++ share a similar syntax, Objective-C is completely different in places. That being said, it's semantically very similar to Java (more so than C++) and people who know it well speak very highly of it. i.e. it does not appear to be anywhere near as broken as C++. The language itself has some dynamic capability built in, but also has all of the additional dynamic options available to C++ (more on that later) and an excellent Ruby implementation which sits directly on top of the Objective-C runtime (MacRuby).

In general, Objective-C should be faster than Java, but not as fast as C++. It doesn't use a virtual machine, but it does have a minimal run time which is used to implement the more dynamic message passing paradigm it uses in place of standard message calls between objects. It also has optional garbage collection, allowing you to make a choice between stability and performance when you need to (i.e. you can get the code working and worry about the memory allocation later). It's also able to leverage all of the power of both the LLVM back end and the newer Clang front end, which C++ currently can't.

While there aren't a lot of directly relevant tools available for Objective-C itself, it is able to directly use any code or library written in either C or C++. No problems there, then.

It's the last metric which is the kick in the teeth fot Objective-C, though. In short: no one really uses it unless they're programming for an Apple platform. As a result, unless you're programming specifically for either OSX or iOS you'll loose out on a lot of frameworks. Objective-C is a first class language in the Gnu Compiler Collection (GCC), so it can be deployed easily enough under Linux (minus a lot of the good frameworks). This is not the case under windows, however, where there doesn't seem to be any good deployment options. I have no problem ignoring Windows, but directly precluding it would appear to be somewhat foolhardy when building a piece of technology related to computer games. It wouldn't be too much of a problem if I was only doing this as an academic exercise, but I actually have delusions of people using it.

That's the last of the languages I'm considering. Look for my conclusion (and possibly a bit of a twist) tomorrow (here).

Monday, October 11, 2010

You're Speaking my Language, Baby. Part 3: C++.



Author's note: As this post started out HUGE, it's been split into parts. You'll find the introduction here, and my comments on Java here.

The second language I'm considering is C++. This is the language that I use the most at my day job. It's also the language that's used to build the vast majority of computer games and one hell of a lot of commercial software. I'm not as familiar with it as I am with Java, but I know it well enough to be productive with it. I'm also familiar enough with it to know how horribly broken it is in many respects. One of the major design goals of Java (among other more modern programming languages) was to fix the problems with C++. It also has no dynamic capabilities what-so-ever, but it's possible to paper over this by using a minimal dynamic runtime such as Lua for scripting.

All things being equal, C++ is the fastest of the three languages. It is also the one you're most likely to write bad code in, though, so there's a bit of a trade off here.

As I mentioned, most games are programmed using C++. As a result, there is a veritable shit load of graphics engine options. I would probably tend towards using the open sourceOgre3D rendering engine (or something similar), but it's worth baring in mind that I could easily switch to using, say, the Quake 3 engine (open sourced by id) if I wanted to. I could also port the project to using a commercial graphics engine if I had the desire to do such a thing.

The measure of applicability to other parties is definitely a point in favour of C++. Code written in C++ would be the easiest of the three for deployment as part of a larger project, as that project is most likely to be written in C++. In terms of acting as a developer showcase C++ has the edge as well, as it's the language a lot of companies ask for code samples in.

Looks for my comments on the last language I'm considering tomorrow (here).

Sunday, October 10, 2010

You're Speaking my Language, Baby. Part 2: Java.

Author's note: As this post started out HUGE, it's been split into parts. You'll find the introduction here.

The first language I'm considering is Java. This is by far the language I'm most comfortable and proficient with. It was used for about 90% of my Bachelors degree, I wrote the entire codebase of my PhD using it, and it gets used here and there in my day job. I'm comfortable with Java, and find it to be quite a pleasant language to program in. Big tick on the question regarding my ability to use it, then. Java has some modest dynamic capabilities built in, but it also has a lot of small options for using higher level languages for the scripting, the cleanest of which is possibly Groovy.

Java has a bad reputation performance wise, but this largely isn't true any more. It does run using a virtual machine, but is compiled to native code at run time. It's a lot easier to write good code using Java than the other languages I'm considering, and that can help with performance a lot, but in general Java has the potential to be the slowest of the three, all things being equal.

Tools are actually not a problem. There are a lot of high quality graphics engines available for Java, with the Java Monkey Engine (JME) being my favourite. A physics add-on is available in the form of JMEPhysics, with the next version slated to have a physics engine baked in. Raw OpenGL is also an option with LWJGL, should I want it. Likewise, I suspect that the Red Dwarf Server is likely meet my communication needs.

The applicability of Java to other interested parties is an interesting question. A lot of software gets written in Java. A LOT. But the vast majority of it is not games. Largely, I think this is because it's perceived to be lacking in the performance department. It's also a little harder to protect you code when you're writing in Java, too. The previously mentioned JME has the support of a commercial games company, though, so clearly there is interest. Computers are getting faster at quite a rate, so performance has the potential to be less of a concern, especially if the project you're working on has the whiff of a server side application about it. When it comes to server side code, I think Java is definitely winning the race. Frankly, I have a bit of trouble calling this one either way.

One language down, two to go. Look for the next post tomorrow (here), should you be interested in such things.

Saturday, October 9, 2010

You're Speaking my Language, Baby. Part 1: Introduction.

Author's note: This post started out HUGE, so I've split it up. Look for the other parts over the next couple of days.

If you're about to start on a programming project of some sort (and I am), then the first choice you have to make is the main programming language you're going to use. Now, if you're carrying out this project on your employers time they probably have very specific views about that. I'm not doing this project on company time, though, so the world is my oyster, figuratively speaking. There are, at a rough guess, shit loads of programming languages out there. There's a reasonably good list to be found here, though it is missing a couple of the weird ones. While constructing the project using a language which uses LOL cat type speech for syntax, or takes its input in the form of abstract art would be an excellent mental challenge, I'm sure, that's just not what I'm looking for.

I'm also, right off the bat, going to eliminate a couple of other classes of language. First of all: no functional programming languages. I have no patience for learning a new programming paradigm, expecially one which up until now has shown limited application outside academia. No Haskell, no CAML and absolutely no Prolog.

I'm also not considering high level dynamically typed languages, so no Python and no Ruby. For that matter, no Groovy or Lua either. You can program very quickly in them, but I'm not prepared to take the performance hit which comes with them. Python might be very popular, but I think it actively encourages bad programming practice and I want no part of that. It's an excellent hobbyest language, but that isn't what I'm looking for.

Lastly: I'm not looking at anything based on Microsoft's .Net platform, and that includes Mono.

The questions I'm going to be asking of the languages I am considering are the following:

  • How well  can I use it?

  • Generally, speaking, how good is the performance?

  • What tools are available? Specifically, does it have access to the libraries I'll need to build the project. These are mostly ones relating to 3D graphics, inter-computer (client-server) communication and (possibly) physics. There are probably a couple of other things I haven't thought of yet.

  • How relevant is it to others? That is, if I write the project in this language will it be useful to other interested parties?


I considered three languages and I'll tackle them one at a time in future posts, starting here.

Friday, October 8, 2010

WoW oh WoW

Sooner or later, most people go looking for a bit of escapism every once in a while. There's definitely a spectrum of how far people like to escape. Some can't stand anything which steps outside the bounds of the possible, others practically require spaceships and dragons to co-exist with emotionally retarded vampires. Likewise, some people look to books for their diversions, some theatre, radio, television or cinema. Some people play computer games or one sort of another. No one is saying that everyone, or indeed anyone, has make a specific and binding choice, though. You can watch a movie about the emotion and theological struggle of gay monks one evening, read a couple of chapters of a book about an adolescent wizard immediately before bed, and take on the role of a greek god laying waste to, well... everything the next day.

The point of this project (Clockwork Aphid), when you get right down to it, has to do with my own frustrations with a certain kind of computer game. Specifically: the ones I'm going to lump together under the moniker "virtual worlds". There are a lot of them out there, and I can't claim to have tried them all, but I have had a play with a couple of the major ones and that's what I want to talk about today.

Where to start, though? I've gone backwards and forwards about this quite a bit and come to the conclusion that I should probably start at the top. The top in this case being the brute, the sprawling 500 lb gorilla that actually accounts for almost 10% of the revenues of the US gaming industry: World of Warcraft, or WoW, to give it its not exactly modest acronym. What we're talking about here is not just a virtual world, but a massively multi-player online role playing game, or MMORPG. Let's examine the meaning of this working backwards through the words:

Game - this is something you play, for fun.

Role playing - it contains some component of playing a role different to that of your everyday life. All games do this to a greater or lesser extent, but the difference here is that your character's own personality and skills have more relevance to the gameplay than your own.

Online - the game is played over the Internet.

Multi-player - the game is played simultaneously by multiple people.

Massively - the "multiple people" playing the game can number in the thousands.

WoW is set in an essentially Tolkenesque fantasy world populated by humans, dwarfs and elves, acting more or less as you'd expect them to had you read or seen the Lord of the Rings. There are other races: Orcs, trolls, undead, gnomes, undead, who are a little more stylised. There's quite a bit of steam punk and tribal culture in places. That's not the point though. The point, as in any game, is the question "what does the user do?" and the answer in this case is:

The user takes on the role of one of a member of one of these races, with a particular profession and proceeds to battle their way through the world, fighting hostile elements and performing quests in order to gain "experience" and improve their character. They can also join forces with other players to take on quests; in fact this is practically required in some cases.

I've spent a bit of time playing WoW and frankly it can be a lot of fun. The world is HUGE and exploring it can be very enjoyable. There's also a genuine sense of achievement to be gained from "levelling up" your character. Most of the time. Which brings me to the first frustration: the grind. A lot of the time you just find yourself killing monster, after monster, after monster. This is partly because a large number of the quests (which are handed out by non-player characters, or NPCs, with large yellow exclamation points above their heads) sound like this:

"Oh no! <insert description of peril>! Please help us!

Kill <insert number> of <insert name of monster responsible for this peril>"

Or even worse and with a more concrete example:

"Please bring me 10 giant spider legs."

The problem here being that against all conventional logic, you might only get a giant spider leg for every third giant spider you kill. As you may have gathered, they don't call it the grind because it's fun.

The next frustration is that you don't actually affect the world. You do the townsfolk a good turn by depleting the number of bandits besieging the town, but this changes nothing. Other players come along and do the exact same quest time after time after, because the bandits simply reappear a couple of minutes after you take them down. So, when you do the quest to take out the leader of the bandits, you arrive to find that a queue has formed. The first person kills him, the others wait for him to reappear and do the same. It sort of breaks the illusion of the game. More annoying still: you've been waiting patiently for your turn, but some git comes running in and kills him first. Most annoyingly, to my mind is... Well... Let me give you an anecdotal example:

I was playing as a rogue, which is a nice way of saying thief/assassin, and had been given a quest to recover a particular object from a beach. Needless to say, the beach turned out to be crawling with monsters. So I set about luring them away one by one, depleting their numbers so I could get my trophy without getting my ass handed to me (rogues can give it out, but they cannot take it). The problem being, that by the time I get the to point where I can start thinking about claiming the prize, the monsters I killed first have already started to resappear!

Here's the problem: this is not how the game wanted me to go about this task. It wanted me to find a group of other players and storm the beachhead, quickly despatching the monsters and grabbing the prize. I was playing as a damn rouge, though! That is not how an assassin does business! In the end I got lucky. A warrior stormed the beach as I was creeping up, and I snaffled the loot while the monsters were distracted. Amoral? I believe I did point out that I was playing as a rogue.

In a regular, non MMO, RPG, everything you kill stays dead for the most part. In this case the world doesn't have to be persistent (as in unchanging) because you're the only one playing it and it doesn't matter if no one else can do the quests. In an MMO, almost everyone needs to be able to do the quests, so the world generally performs a decent impression of Kirsten Dunst's hair in Interview with a Vampire. It is a workable solution to the problem, but it can make you feel as though you and your actions don't really matter, which isn't ideal given that you're supposed to be a hero.

I'm not the first person to have these sort of complaints, or to contemplate solutions, but that's a story for another day.

Thursday, October 7, 2010

What in the Name of all that's Holy is a Clockwork Aphid?

Clockwork Aphid is the name I'm giving to a side project I've had sitting at the back of head for a little while. I'm actually going to try and build it now. What it actually is is quite big and hard to explain, so I'm going to do it gradually, over time. This way I also get to maintain a little bit of mystery. Here's what I will say up front, though:

  • It's a programming project;

  • It's connected to computer games;

  • It's also connected to... another form of digital entertainment which is (arguably) related to computer games;

  • In the beginning at least, I'm going to make the code I write open source.


The actual name "Clockwork Aphid" comes from the name of the group I helped field to the "Dare to be Digital" computer game creation competition several years ago. We didn't get in, but we proposed a game called "Bad Penny" which I still think was a bloody good idea. Some of the elements of that project are contained in this one also, but the name Bad Penny was chosen for a good reason. It was very appropriate for the type of game we were proposing. This project is potentially bigger, though, and I don't want to limit the scope.

As for the Clockwork Aphid name itself? I just plain thought it sounded good then and I still think it sounds good now.