Cross Compile Allegro 5 Programs in Linux for Windows

The Allegro game programming library has released v5 of their popular library and with it comes a whole mess of great changes. Thing is, since most of the applications you make with it are going to be games, your main audience lives in Windows. Since I am really upset with Microsofts offerings in this area I needed a way to capture this audience without having to drive myself insane.

What follows is how I am making Windows executables in Linux using Allegro. Please note that I live in Ubuntu (currently 10.10, Maverick Meerkat). You may have to make some slight changes to fit your distro but that should not be a big deal. These instructions assume a clean installation where no other copy of Allegro has been installed (not sure if that would be a problem or not as I have not tested).

  1. Install the required programs:
    sudo apt-get install cmake mingw32
  2. Retrieve and uncompress DirectX:
    Download and copy the DirectX headers and libraries to /usr/i586-mingw32msvc/. Note the file structure within the archive should compare to the mentioned directory. When prompted to overwrite any files do so but make sure you have a backup first in case something explodes.
  3. Retrieve and uncompress Allegro 5:
    Download allegro-5.x.x.tar.gz from their site. Uncompress some place easy to get to. I used my desktop as we can delete this when done.
  4. Compile from source:
    In a terminal type
    cd [path to uncompressed archive] && mkdir build && cd build && cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw.cmake .. && make && sudo make install
    This may take a little while depending on your hardware.

You should now have a functioning cross compiler setup for Allegro 5. Just replace gcc with i586-mingw32msvc-gcc or g++ with i586-mingw32msvc-g++ (for example, I compiled my first test with i586-mingw32msvc-g++ alleg.cpp -lallegro.dll -lallegro_image.dll -lallegro_font.dll -o alleg.exe). The DLLs you will need are in /usr/i586-mingw32msvc/bin/. You may now delete all of our working files on your desktop (or wherever you put them).

There are still one or two things I need to figure out. For one, dynamically linked programs are peachy on Linux; I am comfortable in my assumption that most people using Linux either already expect this or are willing to learn. Windows, not so much. I want to statically link for that platform but I have yet to experiment with that. Another thing is the fact that my current method has Windows opening up a console window in addition to the “main” window. I am sure this is also very simple but have not yet played with it.

Improving MySQL Index Performance on Bulk Insert

I have been working with a whole mess of data as of late in a series of MyISAM tables. The short of it is I have a 256GB XML file that I want in MySQL. A few tools already exist designed for this specific data. Problem is they import everything and I only want about 75% of the data and they were not as fast as I know they could be. So, being how I have so much free time, I decided to explore this a bit further and wrote my own PHP script to handle the job.

I came the conclusion that the indexes were what was killing me. The database ends up being ~3.5 billion records– yes, it is nearly that much– and indexes are kind of a very important thing. First I tried with the indexes enabled for the whole import. I do not know how long it would have taken because the larger the database grew the slower it got, kind of like how you can never quite reach the speed of light. After that I tried creating the tables without any indexing and using ALTER TABLE after. It looked good at first but when you have such huge tables it gets slower and slower with each added column (IE the first column indexed plenty fast but the second was half, the third half that, ect). The problem was, using ALTER TABLE, you have to add them one-by-one.

After further researching it seems to me that the best way to do this is to add the indexes while creating the table and then just disabling them. Before any of the data is inserted you do a ALTER TABLE table DISABLE KEYS and SET FOREIGN_KEY_CHECKS=0. After you have done your massive, massive import you just do SET FOREIGN_KEY_CHECKS=1 and ALTER TABLE table ENABLE KEYS to re-enable them. This way MySQL does all the work at once and virtually any time you let MySQL handle the work itself– versus multiple calls via external script– you end up with a big benefit.

A few notes:

  • The primary keys are still updated during insertion. I suppose you could use ALTER TABLE after to add those but I am pretty happy with the speed of this setup.
  • I also tried INSERT DELAYED (both alone and in combination with the above) and it resulted in a ~10% increase in time.

Edit 2011.10.30
I just found this article. It seems I was wrong about having to index one column at a time but there are a few caveats. The most notable one is that the order in which you specify the columns has a direct result on if it can be used or not. Any way, this is a huge topic and that is why there are DBAs. Good luck to us all…

Easily Install An Updated Ubuntu Kernel

I recently bought a new laptop. Since this laptop is so new and Ubuntu normally ships with kernel versions a few revisions back not all of my laptops features were supported. Bluetooth, for example, is detected but just refuses to turn on. The solution? A newer kernel with newer everything. Sure, I could just update the drivers but this is more fun.

Canonical offers pre-compiled kernels for Ubuntu. All you have to do is go over to http://kernel.ubuntu.com/~kernel-ppa/mainline/v2.6.39.1-oneiric/ and download which ever version you want. Just make sure you grab the headers (all), headers (architecture), and the image (architecture) packages. So if you wanted to upgrade to 2.6.39 you would download linux-headers-2.6.39-02063901_2.6.39-02063901.201106030905_all.deb, linux-headers-2.6.39-02063901-generic_2.6.39-02063901.201106030905_amd64.deb, and linux-image-2.6.39-02063901-generic_2.6.39-02063901.201106030905_amd64.deb. Just make sure you install them in that order and reboot.

[Source]

Some Tools Remain Unmodified for a Reason

I was out with friends last night and one of them brought his Kindle with him. He showed it to an inquisitive second friend. This second friend expressed an interest in owning one of his own. I, of course, had to step in.

Some animals have remained virtually unmodified for a long, long time. Why? Because there was no reason to change. They were already doing something that worked and, evidenced by the fact they are still here, had no immediate need for something new. This approach tends to give us everything we need in the long run without over complicating things. For example, paper-based books work great. They are light, easy to use, universally understood without any learning curve, and have remained virtually unchanged in most of human memory.

So why do I fear books moving into the future? Take Amazon for example. They have removed books from users Kindles without notice before. Unless someone enters my apartment or steals from me on the subway once I have the information it is mine; I own it and no one can take it away from me. This Big Brother thing Amazon has going on is not only wrong but only gives the illusion of control. Also while on the topic, what happens in a few years when Amazon has moved on and they no longer support their 10+-year-old tablet? If the service is gone so are "my" books.

The new e-ink displays are very neat. They only require power to display an image, which they only need to do once, and that power usage is impressively low. Still, though, why did I need to stick a battery in my perfectly functioning book in the first place? Sure, an electronic device may be able to stay in stand by for a month or more but my paper-based books can sit on a shelf forever and still work as intended.

Kindle-Man also felt it very important to tell me that he can carry some insane amount of e-books at once. The obvious response to this is that I am only in the habit of reading one book at a time. Perhaps if I am planning a long plane flight I may pack two books. Is this really so much of a benefit that I would drop so much money and risk the above “features?”

I love technology. I make my living on technology and do it in my free time as well. I, however, see the need to keep technology out of certain areas for at least these reasons. Also let us not forget the Battlestar Galactica, people!

College Bites, Your Hiring Practices Suck, Talent is Worth It

I have recently been on a lot of interviews. When I say “a lot” I mean something like 15 a week for a few weeks (after I weeded out the dregs via phone and I bet Verizon Wireless now wants to have my baby in appreciation). My marathon interview sessions are now over but they made me think of a few things.

  1. Small companies are much more fun than larger, established companies
    I have done a lot of work with New York City and financial companies. Not to imply that there are not cool people working at these places but the red tape and fear of management sends the message that no one can do things as they know they should be done. Instead employees often opt for “the old way” simply because it will make the fewest waves. If we do not innovate we will never have anything innovative. Perhaps the business of money does not change much from day to day but how we store data relating to money? Priceless.
  2. People love wacky projects
    I have written a few things about projects that I did for the sole enjoyment of it. Because of the fact that someone told me I could not, I set out to prove my theory that they were wrong, wrong, wrong. One such project was my crazy RAID array. As I admitted in the article, it serves no practical purpose. It helps no one (except teenage boys hiding their porn collections) but it was just cool. I enjoyed working on it and the people I have shown it to loved looking at it. They love them because it proves I am not just a pretty face– artistic license– but that I can create new, creative methods which they can use. Depending on the project the wow factor alone may be worth an idea man (read: manager of some kind).
  3. College is a waste of money
    Yes, yes, this is the dirty secret no one wants to admit after they wasted eight+ years of their lives. The fact of the matter is that years ago when my parents were getting ready for their live in the American work force college looked great on paper. It set them apart from their peers because not everyone had the chance to attend. Here we are in 2011 and the government has social programs up the whazoo. These programs sound great when you are deciding who to vote for until you realize, “hey… if everyone goes to college now I am getting deep into debt and spending years of my life just to break even?” It may not make me popular among parents but I say go for the experience with something to show for it right away (no, a degree is not proof of anything other than you can sit down and shut up so stop asking).
  4. New college graduates do not know anything
    To my last point, theory is great. Theory allows us to stand on the shoulders of giants, build on their work, and gives us a spring board to jump off of. Of course, what you can do with theory is just that. There is nothing you can not learn on your own with an Internet connection and a tiny amount of spare time here and there. I just came across a great article which explains my point very well and argues that the new college graduate that looks great on paper has not really done anything yet. They do not yet understand that the several kinds of sort algorithms they just learned do not matter nearly as much as the ability to write understandable code. Every problem is going to look like a nail to them since their lack of experience only gives them a hammer.
  5. Smart employers will fight over talent
    I do not mean to imply I am smarter than most. What I mean is that penny-wise equals pound-foolish. If you find someone you love but choose not to hire because they are $5,000 a year more then someone you just like you may be screwing yourself in the long run. This would need to be decided on a case-by-case basis but good talent pays for itself. Bad– or no– talent means unmanageable code that needs to be rewritten down the road. This also speaks to my experience point above: Some of us are more expensive because you get more employee for the price. If you are a small company who can not afford to hire specialised people that programmer with the strong storage background is going to come in handy when you need to upgrade your NAS array at the extra cost. Good people are called such for a reason.

For the record New York City had some of the best people I have ever worked with, bar none. They knew their stuff, they were down-to-Earth, and they were loyal and hard working. Anyone would be so lucky to have any of them.

Update 2011.05.27
Not to imply that I am the cause but I have been noticing a lot of this kind of commentary in the news as of late. [1] [2]