programming

LuaJIT 2.0 with devkitARM (Nintendo DS)

tung's picture

I just compiled LuaJIT with devkitARM, a toolchain for making homebrew Nintendo DS ROMs. The steps are:

  1. Have devkitARM set up.
  2. Get the LuaJIT source code.
  3. Tweak src/Makefile.
  4. Build LuaJIT.
  5. Copy over the LuaJIT headers and library.
  6. Use LuaJIT.

The following notes are really hacky; follow them at your own risk.

Read more »

C++, Threads and Linux Audio: A Brief Retrospective

tung's picture

I just spent the last few days trawling through someone else's multi-threaded C++ Linux audio code, so I thought I'd share a few of my experiences.

First: The commit.

That code converts direct audio hardware access via ALSA into newer plugin-based output. It also fixes a race condition that occurs at the seam of the two subsystems involved: the client code provided a mixer callback that used a buffer that is initialised immediately after the server spawns the thread that needs it. It's a mistake made by the code's author, but to be fair I wouldn't have spotted it either if the code hadn't segfaulted on me.

If you ever find yourself in this situation, here are some tips:

  • Print statements really work. Yes, even with threads. Especially with C++, where control flow isn't obvious.

  • In threaded code, if you just insert print statements and behaviour changes, that's almost certainly a sign of a race condition.

  • C++ is harder to grep through than C, but it still works, if less effectively. C++ adds a lot of context that makes individual identifiers less useful on the isolated lines printed by grep.

  • Persistence pays. Even if the best programmers in the world say that threaded debugging is difficult, it can still be done.

  • If you're in college/university and going the computer/software route, take the Operating Systems course(s). Threads and concurrency get a lot of good exposure in them.

Read more »

Building Thatcher Ulrich's luaSDL for Lua 5.1 on Windows with MinGW

tung's picture

luaSDL is a library that can be loaded by Lua to make use of SDL. To get a fresh new luaSDL.dll that Lua 5.1 can load, read on!

Ingredients

Read on to get a fresh new luaSDL.dll for you to load and use!

Read more »

Installing Git on Windows, as of June 2010

tung's picture

As of June 2010, there's no one-click installer of Git for Windows. Following this blog entry will get you:

  • msysgit, without its shell integration
  • TortoiseGit shell integration instead

msysgit's shell integration is nasty to uninstall, and if you do it wrong it'll pop up a dialog every 10 seconds.

Here's how you do it...

Read more »

How do I autoconf?

tung's picture

I was working on a project when general upgrade instability caused it to stop working on my development machine (read: starting OpenGL kills X for some reason). Off of Arch and onto Ubuntu 9.04, and I find that my Linux-based project won't build under Linux.

Autoconf is a set of tools that smooths over differences in build environments, like different file system conventions, library names, search paths, tool chains, and so on.

The following is based on a series of long articles over at the Free Software Magazine: the only tutorial/guide that didn't attempt to shove 20 years of history down my throat from the get-go. It's my personal reference and I'll update it as I learn.

Read more »

libpng's man page makes a crap tutorial

tung's picture

If there were a competition for world's worst man page, libpng's would be right up there. Instead of individual man pages for each function and struct, it rolls everything into the one huge document. That would be acceptable if it gave descriptions for each of the functions, but it doesn't, instead providing an nigh-impenetrable wall of text which is borderline useless as a guide or a reference.

Misgivings aside, I've managed to extract the useful information for the simple loading of a PNG image and put it in the code sample below:

Read more »

Max-heap in Go

tung's picture

I was helping somebody on a forum a few days ago with a C++ max-heap implementation. I thought it might be fun to try it out in Go.

package main
 
import (
    "container/vector";
    "flag";
    "rand";
    "time";
)
 
var num = flag.Int("n", 10, "number of elements to heap sort")
 
func main() {
    flag.Parse();
    rand.Seed(time.Nanoseconds());
    v := vector.NewIntVector(*num);
    for i := 1; i <= *num; i++ {
        v.Set(i - 1, rand.Int() % 100)
    }
    heapSort(v);
    printHeap(v, 0, 0);
}
 
func left(i int) int {
    return i * 2 + 1
}
 
func right(i int) int {
    return i * 2 + 2
}
 
func parent(i int) int {
    return (i - 1) / 2
}
 
// Swap vec[i] with its parent if its larger. Stop at the top.
func maxHeapify(vec *vector.IntVector, i int) {
    if i <= 0 {
        return
    }
    p := parent(i);
    if vec.At(p) < vec.At(i) {
        temp := vec.At(p);
        vec.Set(p, vec.At(i));
        vec.Set(i, temp);
        maxHeapify(vec, p);
    }
}
 
// Given a list of numbers in any order, max heap sort it.
func heapSort(vec *vector.IntVector) {
    for i := 0; i < vec.Len(); i++ {
        maxHeapify(vec, i)
    }
}
 
func printHeap(vec *vector.IntVector, i int, nest int) {
    if i >= vec.Len() {
        return
    }
    for n := 0; n < nest; n++ {
        print("    ")
    }
    print(vec.At(i));
    print("\n");
    printHeap(vec, left(i), nest + 1);
    printHeap(vec, right(i), nest + 1);
}
Read more »

goblog: A proof-of-concept blog in Go

tung's picture

As if I wasn't bored enough, I've written a proof-of-concept blog using Go, that new language out of Google. I blogged about this language before, but I wanted to give it a real test drive, so I came up with this.

goblog on github

Pointers ahoy

The first thing I noticed when I got started was pointer trouble on my part. Go still has pointers like in C, but some of the syntax smooths over the differences.

Read more »

Impressions of Go: From the guy who learned it in 2 days

tung's picture

Go is that new-fangled language out of Google, and though I won't describe it (been done much better by somebody else), I will give a few opinions from the point of view of somebody who's written some code in it.

C-like syntax

It looks like C. Braces, parens and semi-colons all make yet another cameo in a programming language.

Read more »

Tea: Simple 2D Ruby game dev

tung's picture

For simpler games from a simpler age.

Tea is a simple 2D game development library for Ruby. It’s designed with these things in mind:

  • 0 is better than 1, and 1 is better than 2.
  • Simplicity beats speed.
  • Value and convenience can sometimes beat simplicity.
  • Procedural beats object-oriented in a dead-heat.

The aim of Tea is to bring back some of the grass roots game development that things like QBASIC fostered. By staying unobtrusive and out of the way, Tea lets you focus on your game or demo, and not the pointy bits that are part of many game engines and APIs.

Read more »
Syndicate content