Category Archives : C/C++ Programming

SDL 1.2 Game Development

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 […]


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 […]

Deploy Ruby on Rails to the Desktop (Ubuntu), as a Debian Package 1

Introduction to deploying Rails Applications to the Desktop Some things you’ll learn in this series of articles: How to distribute a Rails App to an Ubuntu Desktop How to Compile a custom Ruby installation to avoid conflicting with an existing Ruby install Get automatic updates to all users for free by virtue of being a Debian Package How to organize a build environment to make and distribute all Debian packages with a single command. How to build your own custom dumb browser in QT C++ (QT Creator now includes the ability to generate an HTML5 App, it didn’t when I started building Salor…) This is not a step by step tutorial, it’s a broad discussion, though I plan to make an example video with a hello world style app at a later date. Deploying Rails applications to the desktop, specifically unbuntu, though I plan to figure out how to do it with windows very soon, turns out to be much easier than I ever thought. While deploying Rails apps can kind of suck in comparison to other types of web-applications, it’s hardly any more difficult than any other kind of executable deployment. The reasons for using Rails for a desktop application are pretty obvious, ease of development, ease of maintenance, and Ruby can pretty much do anything you need it to do. For instance, in our application we use ruby to connect to a receipt printer and print out receipts, reports, labels and barcodes and more. Before you deploy a Rails app, you might give […]

salor point of salor

Qt C++ Screen Capture using BitBlt 2

So I got to thinking I wanted to be able to take abitrary screen captures based on some startx/starty -> endx/endy input. I found various sites showing how to do this, but most of them were pretty confusing. I thought I would post the final working code here. void RSystem::snap(int startx, int starty,int endx,int endy) { HDC hdcScreen,hdcMemDC = NULL; HBITMAP hbmScreen = NULL; BITMAP bmpScreen; HWND hDesktopWnd = NULL; hDesktopWnd = GetDesktopWindow(); hdcScreen = GetDC(hDesktopWnd); hdcMemDC = CreateCompatibleDC(hdcScreen); if (!hdcScreen) { qDebug()