[ Content | Sidebar ]

Archives for February, 2010

Some thoughts on trees

February 27th, 2010

I’ve been wondering for a while now what is the best way to add trees to Train Game. Trees seem fairly important for a train game seeing as trains mostly travel through the countryside where there are trees. (Except for my daily commute to work through Slough where there are no green things.)

Anyway my first attempt was to use flat quads with an alpha-blended tree textured onto them. These are commonly called “billboards” if you didn’t know. The quads are then oriented to always point at the camera, hopefully giving the illusion of a fully 3D tree. While the maths to calculate the billboard orientation is a bit tricky, these trees are incredibly cheap at runtime. Blodgett was kind enough to use its artistic talents to produce some tree pictures for me:

While these trees look quite good from a distance, when you get up close and especially when look from above the rotation and obvious flatness is a bit disconcerting.

So next I tried a completely different approach to tree rendering. Inspired by examples of procedural plant generation e.g. here and here I implemented an L-system tree generator – albeit a much simpler one than in those examples. Here’s a screenshot showing some examples of trunks and branches:

I think these look rather good. Unfortunately there are two problems: rendering them is incredibly slow, and I found it very difficult to generate decent looking leaves. Since trees are only scenery and I’d like to have a lot of them on the screen at once, it’s not really acceptable to have them use more of the render-cycle budget than the train itself. Simplifying the branch structure and using square leaves, plus some OpenGL performance tricks, gets them running at a reasonable speed, although they don’t look nearly as good:

Incidentally, these screenshots are showing the new map editor which ditches FLTK and replaces it with my own home-made XML GUI toolkit. I’m rather pleased with it design-wise and it plays much nicer with the rest of the game (it renders directly onto an OpenGL texture).

Anyway, back to trees and my conclusion from the L-system experiment is that I didn’t like them that much, they were expensive to render, and perhaps most importantly, they didn’t fit in with the rest of the artwork in the game (in the “childishly cartoonish” style). So I abandoned the code in a git branch and went for the simplest option: make some models of trees.

Thus far I’ve made two tree models – a pine tree and an apple tree – both around 80 polygons. They are very cheap to render – cheaper in fact than the billboard trees since I have an optimised VBO-based mesh renderer.

I really do like these trees! I think they’re cute but I’m a little worried other people will think they’re daft. Anyway, I’m sticking with them for the time being.

In a month or so I will tidy up the code in git and release another demo/preview version. Hopefully there will be some useful features by then ;). In the meantime you could look at my gitweb if you’re curious or clone http://www.nickg.me.uk/~nick/git/traingame.git.

Thank you muchly to blodgett for assisting with tree evaluation!

Samsung Q320 Fn-keys in Linux 2.6.32

February 20th, 2010

If you’ve been following my attempts to get the brightness up/down and other fn-keys on my Samsung Q320 laptop to work in Linux, you might like to know the saga has reached a happy conclusion. Previously I published a hack to the atkbd kernel driver to get these problematic keys to send key release events. My attempt to get this included in the kernel failed, but I was told the 2.6.32 kernel would contain a new mechanism for fixing this from userspace.

Well, 2.6.32 is here so how can we fix the fn-key release problem? Documentation for the new sysfs attribute is a bit scanty as it’s intended to be used only by udev/HAL/DeviceKit, but you can set it yourself quite easily. The relevant file is /sys/devices/platform/i8042/serio0/force_release – this lets you manipulate a bitmap in atkbd.c indicating which scancodes don’t send key release events.

echo 130-132,134,136,137,179,247,249 \
    > /sys/devices/platform/i8042/serio0/force_release

The bitmap editing syntax is quite nice – done in lib/bitmap.c rather than the atkbd driver itself. I got those scancodes from the array atkbd_samsung_forced_release_keys in atkbd.c. They were originally intended for the NC20 but the Q320 keyboard seems to be the same. It works for me anyway.

You still need to map the brightness up/down keys to the correct X11 codes, which you can do like this:

setkeycodes e008 225 e009 224

Job’s a good’un.

All my Samsung Q320 coverage is here.

A sad day

February 20th, 2010

It is with sadness that I have to report the death of my mini dragon tree plant.

Mini dragon tree plant was born about two and half years ago and died sometime in the last few weeks. It graced the top of my bookshelf, and before that my desk. Unfortunately in it’s new location in my flat it doesn’t seem to have got enough light so it’s leaves turned yellow and fell off. Let’s all take a moment to remember the too brief life of mini dragon tree plant.

While this death was tragic, important lessons have been learned so hopefully it’s successor – mini dragon tree plant II – will fare better.

Filed in musings - Comments closed

Valentine’s day

February 14th, 2010

Today is Valentine’s day. Valentine’s day is all about love, and the internationally recognised symbol of love is the stylised heart. I love sed. This is probably why I spent this evening alone writing a filter to format text as ASCII hearts:

nick@pickle:~$ sed --posix -n -f hearts.sed < poem
     Shall        I comp
   are thee t   o a summer
 's day? Thou  art more love
ly and more temperate. Rough 
winds do shake the darling bu
ds of May, And summer's lease
  hath all too short a date.
    Sometime too hot the e
     ye of heaven shines
       , And often is 
         his gold co
           mplexio
             n d
              i
     mmed;        And ev
   ery fair f   rom fair s
 ometime decli nes, By chanc
e, or nature's changing cours
e untrimmed. But thy eternal 
summer shall not fade Nor los
 e possession of that fair t
   hou ow'st; Nor shall de
     ath brag thou wand'
       rest in his sha
         de, When in
            eterna
             l l
              i
     nes to        time 
   thou grow'   st, So lon
 g as men can  breathe or ey
es can see, So long lives thi
s, and this gives life to the
e............................
 ...........................
   .......................
     ...................
       ...............
         ...........
           .......
             ...
              .

You can download the script here: hearts.sed.

As far as I can tell, girls are mad keen on standards compliance. So I went out of my way to make this script POSIX compliant.

I’ve reproduced this labour of love below. As you can see, it demonstrates the elegance and practicality of sed as general purpose programming language:

: gather
/^[[:space:]]*$/d
s/[[:space:]]\{1,\}/ /g
/.\{251\}/{
  s/^\(.\{6\}\)\(.\{6\}\)/     \1       \2\n1/;P
  s/^.*\n1\(.\{10\}\)\(.\{10\}\)/   \1   \2\n2/;P
  s/^.*\n2\(.\{13\}\)\(.\{13\}\)/ \1 \2\n3/;P
  s/^.*\n3\(.\{29\}\)/\1\n4/;P
  s/^.*\n4\(.\{29\}\)/\1\n5/;P
  s/^.*\n5\(.\{29\}\)/\1\n6/;P
  s/^.*\n6\(.\{27\}\)/ \1\n7/;P
  s/^.*\n7\(.\{23\}\)/   \1\n8/;P
  s/^.*\n8\(.\{19\}\)/     \1\n9/;P
  s/^.*\n9\(.\{15\}\)/       \1\nA/;P
  s/^.*\nA\(.\{11\}\)/         \1\nB/;P
  s/^.*\nB\(.\{7\}\)/           \1\nC/;P
  s/^.*\nC\(.\{3\}\)/             \1\nD/;P
  s/^.*\nD\(.\)/              \1\n/;P
  $ { d; q }
  D
}
$ { s/$/\./; b gather }
N
s/\n\n*/ /g
b gather

Breakfast biscuits give you vim

February 13th, 2010

I was wandering around Reading museum this afternoon. Not only does it have a surprisingly large and diverse collection – including a full replica of the Bayeux tapestry – it has a rather confusing and maze-like layout. Walk down what looks like a service corridor or fire exit and you discover a whole new collection of galleries. Anyway, it was one of these jaunts down a nondescript passage that led to my discovery near closing time of the BISCUIT WING! This is an exhibition on the once great biscuit industry of Reading. Among the items on display was a 99 year old biscuit!

At the end of the biscuit exhibit I noticed this rather alarming marketing poster for vim:

Apparently if you eat biscuits for breakfast you’ll be a hardened vim user by lunch. This also seems to imply that using vim “makes you fit and keeps you slim” which is clearly not borne out by reality. Better contact the advertising standards authority…

Filed in musings - Comments closed

Advances in mash technology

February 13th, 2010

Here’s an experimental new method for overcoming some weaknesses in my current mashed potato process:

While the potatoes are bubbling and the sausages are sizzling take a small saucepan and make a small fire under it. Add a large quantity of butter, small amount of milk, some salt, some pepper, and a tiny amount of English mustard. If you’re feeling risqué and want to live life on the edge, add a little bit of nutmeg. Now, stir this mixture until it goopifies but don’t let it get too hot! While you are mashing, slowly add the butter sauce and the mash will be made!

Advantages to this technique: it makes the mashing stage significantly faster; it makes effective use of the idle time when waiting for things to fry/boil; it eliminates the cooling effect of adding cold milk and butter from the fridge; it gives a more uniform mash.

Disadvantages: it creates extra washing up; it can go a bit weird if it gets too hot; it is difficult to judge the right quantity of ingredients to add.

I’ve tried this technique twice now and have been quite pleased with the result. Experimentation continues.

Filed in musings - Comments closed

Storefjell

February 1st, 2010

You might have noticed the lack of posts in the last week or so. This is because I was 1km up a mountain in Norway. Possibly not the best time of year to be visiting, as it was incredibly cold with temperatures as low as -20°C during the day. The reason I was there was a corporate conference/holiday thing. I quite enjoyed it, especially as it was free!

To get there we went on a three hour coach journey through the frozen countryside which can be loosely described as “epic”: frozen lakes, huge forests, wild deer, tog, … This was perhaps the best bit of the whole trip.

Food was good: I consumed moose, ostrich, reindeer, and a variety of other more common animals. There was also copious quantities of free alcohol, which our Norwegian colleagues took full advantage of.

I made a brief attempt at participating in some outdoor activities: these being tobogganing which I summarise as “dangerous”, and cross-country skiing which is best described as “daft” and more thoroughly as long periods of tedious and tiring uphill skiing followed by terrifying uncontrollable sliding downhill. Not something I’ll be trying again.

The light that far north is strange. The sun takes ages to get up and go to bed, and even once it’s up it sits barely above the horizon. It was rather weird and atmospheric and makes for some excellent sunrises and sunsets which I attempted to capture here:

I took some photos. They’re all variants on the same theme: snow and mountains. They are also a bit hit and miss due to me not quite mastering the white-balance thingy. Also, I have become rather attached to the 16:9 aspect ratio. Anyway: