Category Archives : Tutorials

SDL 1.2 Game Development   Recently updated !

I finally decided to sit down and learn game development. From my research there is only one way to do it, and that is SDL. If it’s good enough for Valve and Steam, it’s good enough for me. As it turns out, it’s surprisingly easy to get up and running with SDL. There are plenty of tutorials about the basic SDL game setup, so I won’t repeat the ubiquitous info and go straight to some basic problems of making a game that no one really seems to discuss. There are two main problems when designing a game: How do I save and restore game state? How do I make my game configurable? C is a great language for speed and algorithms, but it is really shitty when you want to handle data. Games are both algorithm and data intensive. So for half the game development, C rocks. But for the other half, it’s a slog. Saving and restoring game state means populating a structure in your C code with values from a human editable, dynamically loaded file. Things like the x,y or even z coordinates of the player in game space, their health, equipped weapon, inventory items and so on. One solution for solving this problem is to use some kind of config file format like INI, or XML. INI is a good choice for very simple games, and it’s dead simple to write an INI parser in C. The other common option is XML, which means something like libXML, which means I’d rather have […]


ANTLR4: So awesome it makes Java look good

I have been trying to write my own programming language off and on for about 5 years now. That doesn’t mean I have spent 5 years on a single project. Only that I have been toying with the idea and educating myself for that amount of time. Writing your own language is kind of the Holy Grail of computer science. Well, writing a language that is actually useful. Over the years, my experience in Ruby, PHP, C/C++, Python and even LISP, has informed my idea of what a good language would look like. Note I didn’t say perfect language. There is no such thing. I have come to believe that all languages are good in some way or another, and bad in other ways. Emotionally I like Ruby, and I like C. The elegant syntax of Ruby makes you happy to program, while the Do-Anything attitude of C makes it the ultimate language. I have been looking at Java( due to it’s cross platform nature ) and have to say at first I hated it. Now I hate it less. The number one reason I hate it less is ANTLR. I love the code generated by ANTLR because it looks like code that a human being would actually write. It’s very dense, but it’s alive. It’s hackish and clever. I have been following along the book The Definitive ANTLR4 Reference. This is a first time for me. Normally I, quite wrongly, just jump in and get it done. This time I am going to RTFM. […]

HTML5 Canvas: Smooth, variable width lines with transparency. 2

When making a drawing app with HTML5 canvas, you might come up against the problem of making a smooth, variable width line. Eventually you might find that you can make several calls to ctx.quadraticCurveTo(x,y,xc,yc) and get some kind of effect. If you stroke every 2 or 3 points, then as long as the line width is very small, you won’t notice the jaggedness. Unfortunately, if you try to do this with semi-transparent lines, the effect is truly horrible. To solve this problem, instead of drawing lines, I simply draw very thin shapes, and fill them with a color. This allows for 1) variable thickness and 2) nice transparency. Variable transparency is a problem I haven’t quite figured out yet. It may require composing the shape from individual pixels, which is simply too slow, especially in IE. What I am writing is a drawing App that works with the Wacom Web Plugin, and therefore varies line thickness based on pressure. I would like to vary opacity too, but this seems problematic right now. A solution that may be possible is to fill the shape with a complex gradient, if it is possible to create semi-transparent stops. Here is an image of what the program does so far:   Each line is actually a full shape, with varying degrees of opacity. Thickness and thinness is accomplished with pen pressure from the Wacom Intuous5 tablet. As the line is drawn, a temporary line is shown to the user, when they lift the pen, that line disappears, and a […]


HTML5 Canvas, Pixel Compositing, Transparency, and why all the trivia!

One thing I really hate about new technology are all the early adopters who incessantly post the same trivial examples. They cross link them too. So you can go from one page to the next, and see essentially the same example, just with the bits renamed or moved around. At a certain point, I got it into my head that I wanted to make a quickie HTML5 App that works with my Intuous5 Wacom Pad. Wacom has a web plugin that let’s you get data about pen pressure and so on from the tablet. So I started to work on it, and found the said trivial examples and started mashing something up. Pretty soon it became apparent that if I wanted my lines to look good, I might have to anti-alias them, or so I am trying, I don’t know if it will work, because I just spent the better part of 2 hours looking for a solution to a simple problem. If you look for examples of pixel level manipulation for HTML5 Canvas, you will find the same trivial examples over and over again, which basically say: var id = context.createImageData(1,1); var d =; d[0] = r; // where r is 0…255 … context.putImageData(id,x,y); If you actually want a full trivial example, use google, they abound. The problem with the above is: it replaces the entire pixel, all the way to the background, erasing any colors beneath it. The alpha channel of the pixel doesn’t make it transparent to what was under the […]

Lexical Analysis: You should use FLEX…right?

It’s been a hobby of mine for that last few years to try to create my own programming language. Don’t ask why, I just want to. Over the years I have tried and failed multiple times. This is mainly due to the fact that I am a self taught programmer with no CS background, or Math background, or any real education. When you set out to learn how one makes a programming language you will receive a series of answers similar to this: Use flex to generate a lexical analyzer. Use Bison to generate a Parser Forget both of those and use ANTLR To understand what you need to do to create a programming language, you will need to understand that in general all programming languages have a set of modules that take turns with the users input (i.e. the script). The Lexer The Lexer, or Scanner is the first component of a programming language. It reads a stream of characters and groups them together into meaningful parts. The Lexer adds no semantic meaning to the stream. Lexers create “meaningful” tokens. They generally, but not always, do not create whitespace tokens, they “ignore” them in the sense that they do not lead to the emission of a token, but they “use” them to delineate tokens. Flex has a simple interface for creating a lexer, a simple Scanner will look like this: If we save that as test.y and run: flex test.y cc lex.yy.c -o example -lfl ./example We can then start entering in some text. […]

Qt C++: Threaded Communication with Artema Hybrid on Linux

Communicating with an Artema Hybrid CC Payment device is actually deceptively simple. I’ve written an application what uses a webkit widget exclusively for the UI display, and so I hook into the Javascript to provide some extra functionality to the app, in this case, reading and writing to/from the Artema Hybrid device. The documentation that I received was in German exclusively, so this took a bit of work to get going, but once you have it down it’s very easy. The device is connected via it’s POS connection Serial->RJ45 connection to a Serial->USB (FTDI chipset) converter that gets plugged into a usb port. You use the standard open, read, write and close functions. The Artema Hybrid constantly communicates with your system, so you’ll need to create a QThread to run in the background reading from the device once every second. The Artema Hybrid will send you an ENQ (0×05) and you need to respond with either an ACK (0×06) or an STX (0×02). With the way that I have it set up, the c++ code does the absolute minimum required which is it reads from the device and emits a dataRead() signal which is connected in Javascript. If I read ENQ, then I emit dataRead(“ENQ”). and in the Javascript function that is connected to the dataRead() signal, I see if the string passed up == ENQ. In the javascript, I have an array of data to write to the device, if that array is empty, I just write back to the Device ACK, otherwise, I […]

Rails will_paginate links to wrong page 4

Well, While setting up a website today I found a bit of retardation in will_paginate. Aside from poor and complicated documentation and an incredible amount of bloat for what amounts to a very simple kind of website component, I found that will_paginate was linking to /?page= on a page that showed in the url bar as /products, so the link should have been /products?page=. So I looked around for a quick fix, and this is the best I got: Revisited: roll your own pagination links with will_paginate and Rails 3 OH MY GAWD. You have to be shitting me. That is hands down the most retarded thing I have ever seen. So, like the little hack monster that I am, I did it faster and easier with less code. If you want to change the pagination links, you can do it with jQuery. $(‘div.pagination a’).each(function () { var url = $(this).attr(‘href’); url = url.replace(‘/’,”); $(this).attr(‘href’,url); }); Why? Because ideally, will_paginate shouldn’t give a shit about the url, that’s not its job, that’s my job, its job is to ADD get parameters, and manage what those parameters should be, anything else is retarded.

Rails 3 – PHP Style Global Variables, $_SESSION, $_GET, $_POST in the models, and everywhere.

PHP Globals in Rails 3 So, as part of my slow descent into hell for even showing this stuff, I thought I would make a quick and dirty post about getting PHP like globals into your models in Rails. I wrote a longer article about globals in the model in rails which you can check out for some other options. def some_before_filter $_SESSION = session $_GET = request.GET $_POST = request.POST $GLOBALS = {} end Yeah, that simple. When it comes to globals, the ruby and rails community is kind of like the child of a former Nazi sympathizer who got off the hook at Nuremburg. Yeah, they’re related, but they just don’t want to have anything to do with them, and if you remind them of the connection they get really angry.

Apache2/MySQL on Ubuntu Configuration

Once you’ve installed apache2 and mysql on your server, you might want to try these configuration changes to make it perform a bit better: In /etc/mysql/my.cnf key_buffer = 16K max_allowed_packet = 1M thread_stack = 64K table_cache = 4 sort_buffer = 64K net_buffer_length = 2K And in Apache2′s config, /etc/apache2/apache2.conf, find the section for MPM prefork if yo have it and: StartServers 1 MinSpareServers 3 MaxSpareServers 6 ServerLimit 24 MaxClients 24 MaxRequestsPerChild 3000 The above are just some things to try if you encounter a situation where apache is using too much memory, or the same for mysqld.