Archive for code

More Google Summer of Code!

Posted in awkward, CrystalSpace with tags , , , , , , , , , , , , , , , , , on August 28, 2011 by tayron

Well,Β  GSoC came to an end and I thought I’d post an update. πŸ™‚

As a quick refresher, my project involved adding video decode support to the open source engine CrystalSpace. Everything turned out ok, so I’m gonna talk a bit about it.

I added video decode support through Theora, and open source video compression format. The basic idea behind my implementation was to have the main thread to render the scene, and another thread to decode video frames and convert data from theΒ  YCbCr colorspace to RGB. Then, in the main thread, data would be written to one of the buffers, and the buffers would be swapped. I used double buffering.

If I had to give a few tips on video decoding, here’s what I’d say:

1. Threads

If you can, avoid them. Threads introduce concurrency and code that ran perfectly before, will probably run slower and you won’t know why. If you can get just the right amount of processing transferred over to another thread, you’ll get a speed boost, but you’ll have to experiment quite a bit. In my project, I used threads, because you can’t just use up the main thread (which renders and updates the scene) to do your dirty work. It worked well in the end, but it was a bit of a pain in the ass. Here’s a nice article on threads.

2. Conversion

Depending on the colorspace supported by the surface you render the video frames to, you will have to do conversion. I did it on the CPU using Look-up Tables, and it worked well, but just for the 4:2:0 pixel format. 4:2:2 and 4:4:4 were too slow to be useable. My advice, if you’re doing conversion on the CPU, is to use MMX. I ran some tests on MMX during my project, and it turned out about 2 times faster. Implementing conversion in MMX using LUTs isn’t really a hard thing, but you’ll have to watch out for different compilers. asm tags are usually different for each one. Unfortunately, I din’t have time to move conversion to MMX. In any case, here’s a paper about optimizing YUV->RGB conversion. Alternatively, you can do conversion on the GPU, using a shader. Again, I didn’t have time to implement this, but here’s a reference.

3. OpenGL

The main problem I ran into during this project is that openGL doesn’t support multi threading (as far as I know, oGL 3 and up do support it). This is a big problem. You can’t access an openGL context from outside the thread it was created in. This is annoying because, if you’re processing an openGL resource on another thread, you need to place a callback in the main thread to apply the changes, which slows you down. Admittedly, the slow down isn’t that big, but you’ll see a huge difference between single threaded implementations and multi threaded ones. For example, w/o multi threading, converting th 4:4:4 pixel format (the one used for 720p vids) was pretty fast. As soon as I moved conversion to another thread, due to the synchronization induced by this, it was now too slow to be practical.


In any case, the project turned out OK, and I’m happy with it. Learned a lot of things this summer. It was a really nice experience. πŸ™‚

This also means I can get back to game dev πŸ˜€ Gonna post a prototype as soon as I have one πŸ˜€


Robots nicked my stuff!

Posted in 7-day games, aw-games, awkward with tags , , , , , , , , , , , , , , , , , , , , , , , on May 2, 2011 by tayron

I’ve always wanted to make an arcade game. And Ludum Dare #20 gave me this opportunity. The theme was “It’s Dangerous to go Alone! Take this!”. I quite liked it, so I decided to join. 33 hours later, I finished my entry, and I’m kinda proud of it πŸ˜€ Hope you people will like it too.

Robots nicked my stuff!

33-hour game for Ludum Dare #20.


Attention! If the games runs slow, you can try turning off the background by pressing U in-game. I strongly suggest you run it on a PC that’s 2.2 Ghz or higher.

Game: (4.8mb)

Source: (5.7mb)


The strange thing in the center is a portal, and will drop items from time to time
These items are either weapons or helpers
You shoot weapons
Helpers need to be placed or used with the right mouse button
If a dropped item is not picked up, no more items will spawn until it is
If you loose all your life, you will respawn, but the portal will loose life
The portal also looses life when robots hit it
Its life is displayed at the bottom
Your life and your current weapon and helper will be displayed top-left
When the portal dies, you die


Left click-fire
Right click-use helper


If you have problems getting the game to run I’d suggest installing the newest XNA 3.1 redistributable and making sure you have .net framework 3.5 installed.


Game design, code & gfx made by Alin Baciu (bc_alin{[@]}yahoo{[dot]}co{[dot]}uk)

Music: morgantj – 8-bit kung fu

Sfx were done using sfxr.

Inspiration source: Ludum Dare.

The game itself is under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 license.

Source code

The source code can be found in the “” archive in the download section. In order to compile it, you need Visual C# 2008 and XNA framework 3.1.
The code is under the LGPL license.

Want feedback!
Peace! :)

Also, here’s a timelapse of how I did it!