Showing posts with label Gaming. Show all posts
Showing posts with label Gaming. Show all posts

Friday, April 6, 2012

Long overdue update

I’ve had a lot going on in the past 18-months. Earthquakes in Christchurch for one, moving to the United Kingdom for another. Still, no real excuse not to be updating my blog, except maybe some programmers block.

While work sometimes sees me going weeks without writing much code, or even days without writing any, I try to keep myself busy with programming projects which I tend to pick up and put down again.

Learning new programming languages is an interest of mine, and one I’ve started using on a regular basis is D. It is a nice language to work in and feels to me to be most like a mix between C++ and C#, both languages I am quite familiar with. The D language seems to be quite mature, and the standard libraries are catching up, but the developer ecosystem isn’t anywhere near the more popular mainstream languages. Tools are a bit lacking right now too. This hasn’t stopped me on embarking on a few projects.

The first is Project Euler. The site contains a list of mathematical problems to solve, with the intention you write a program to do so. Going through these problems got me up to speed with D a lot quicker than just messing around with a tutorial. I haven’t been on in a while but I did get up to 63 problems solved.

The second project goes back to a long running interest of mine in ray tracers. Simply put a ray tracer renders a 3D scene by calculating a ray from a camera to a point on the screen (usually at least one per pixel), and determining what objects in the scene intersect with the ray. Then you perform some calculations based on the vectors at that intersection point to work out what colour it is. My first ray tracer was written about 6 years ago as part of a University assignment and I’ve been hooked ever since. Unfortunately I haven’t worked on a single program for 6 years, I’ve worked on several iterations of the same program over that time not really making much progress. My latest version is in D, and with a couple days of work taking the better C++ code I had and converting it to D I have yet another basic ray tracer. If I do more work on it more in the future it may become a topic for the blog.

More recently I have become interested in creating programming languages. It started with an idea on how you could turn a Reverse Polish Notation calculator into a language. The basic RPN interpreter is a typical student project. I know I made a couple during my study days. A bit of research on the idea lead me to Forth, which I ended up half (or a third) implementing in D. I then got a bit more ambitious and tried to come up with a more complex calculation only to get bogged down in details again. That design process is still on-going though so I might just make something of it yet.

With programming languages on my mind this put me in an appropriate mood to be receptive of the new project of Markus ‘Notch’ Persson, 0x10c. In summary it is an MMORPG set in the distant future in space. The most interesting part of this game is each player’s ship comes with a fully programmable computer, based on the fictional DCPU-16 chip. It is a very simple 16-bit processor and the spec is available so it isn’t surprising that emulators and assemblers are turning up everywhere. I’ve even written an emulator in D over a couple of nights and I’m planning an assembler next. It might even be interesting to implement a simple Pascal compiler for it.

Sunday, October 31, 2010

Playing with Minecraft levels

Minecraft is currently the only PC game I play these days. All my other games are on consoles. If you don’t know what Minecraft is, you can start here, but in a nutshell it is a freeform sandbox game set in a randomly generated world where you can mine and build.

Having spent some time playing I’ve built up a complicated network of structures and tunnels in search of those elusive diamonds (have not found them yet). It would be nice to have an alternative way of visualizing that world, so with that in mind I ignored the other mods and tools out there and set about writing my own.

The first tool is a NBT file to TXT converter. NBT stands for Named Binary Tags and is a format created by Notch for his Minecraft game. Following the documentation on the website I created a tool written in C# to read the compressed data files and turn them into a human readable format. The tool doesn’t understand what is in the files beyond the tags, which are essentially the metadata. The next step is to create something that understands the level format and is able to display the world in some way, such as a 2D map.

The tool is reasonably simple. It opens the target file into an uncompressing GZip stream and starts creating Tags. The Tag abstract class takes care of parsing basic data types and parsing the Tag Type to get the actual Tag derived object created. Each derived type parses its payload of data, which in the case of a List or a Compound will consist of other tags read recursively. Once that is done I write everything to another file by recursively calling the tree of Tags.

I should be doing some more Android programming but I have to admit little projects like this are more fun for me :).