10 C99 tricks

Here are ten interesting patterns and tricks I sometime use in my C code, some are well known, some not so much. I am sure all of them work with clang and gcc (after fixing the evetual typos). I didn’t try with MSVC, but except for no 1 and 5, I think it should also work. [edit]: Here is a link to the hacker news thread. [edit]: Maybe the title is a bit misleading, this is not strictly about C99....

2015 February 13

Procedural colors for video games

Recently I have been spending a lot of time thinking about how to use procedural colors in my -still unnamed- incoming video game. [edit]: The game is done now, it is called Blowfish Rescue, and you can play it for free on Android of iOS. This is a problem that I am sure many other indie game developers have been thinking about, and there are not so many resources about it online, so I though I would share my experience so far on the subject....

2014 October 6

Named parameters in C

C99 introduced the concept of designated initializers, that allows to initialize a structure using the name of the fields, like this: struct MyStruct {int x; float y;}; struct MyStruct a = { .x = 10, .y = 3.6, }; Here is a C macro that extends this syntax to function calls. I present it as a curiosity, and I really wouldn’t advise anybody to actually use it in a project (except maybe for very special cases, like for example emulating the interface of a language that accepts named arguments)....

2014 July 14

C++ patterns using plain C

So that’s it, you read this article, and this post, and this, and this, and you spent too many time trying to debug 8 pages long compilation error messages, and you also spent hours trying to follow your code path involving operator overloading, copy constructors, and virtual class methods called from constructors or whatnot. You have had enough of it. Yout think it’s time for you to stop using C++ altogether and return to simple, frank, easy to debug, plain, C....

2014 June 22

Automatic object factory in C++

Unlike other object oriented languages like java, C++ does not have much support for introspection. So for example it is not possible to request the list of subclasses of a given class. In this post I am going to talk about a little trick that I found very useful when dealing with a lot of subclasses of a single base class. This is typically what we see in video game, where we have a base Object class that represents any kind of object in the game, and then one subclass for each type of object, like the player, enemies, etc....

2014 June 15

How our ads based game makes more revenue than our paid version

For more than one year, our game voxel invaders was present on google play as both a free demo version and a full paid version. Recently we decided to remove the demo version and replace it with a free full version with ads. To make it simple, we just updated our demo package with a new package incorporating the admob SDK. In order to boost the new version, we also cooperated with app of the day (previously known as appturbo) to make a promotion of the game....

2014 June 2

How to deal with spaghetti legacy code

At least three times in my career as a programmer, I had to work on huge, complicated code written by other people. In one case I was specifically hired to replace the original maintainer who -as I later learned- left the company from a burnout caused by the frustration of having to maintain his own code. Inheriting legacy code is common, and few people enjoy it. Here I put down a few ideas that I think might help to deal with the situation....

2014 April 7

ARM assembly for iOS with XCode

This week-end I spent a lot of time trying to optimize the code of my incoming video game. The game engine features a fluid simulation algorithm based on this excellent paper by Jos Stam. The algorithm is CPU intensive, and so I tried my best to make the code as fast as possible, which eventually means having to write the code in assembly. Since I couldn’t find much information about how to write assembly code for iOS on XCode, here is a small tutorial I wrote about it....

2014 March 31

Procedural rendering test 1

For my incoming video game project I wrote a small procedural rendering engine. So now I can do all kind of creepy animations. Here is an example, compiled to javascript using emscripten.

2014 March 17

Vocabulary learning wallpaper with python and gnome

Here is a simple way to customize your gnome desktop to show random text taken from a file. I use it to learn Chinese, but it can be easily modified for any other kind of textual information. This is how I did it: Using inkscape, I made a template SVG file for the background. I started from the default gnome 3 wallpaper, and I added three text elements: one for the Chinese characters, one for the pinyin, and one for the English translation....

2014 March 9