Monthly Archives: May 2004

Glop and PDL

As my third Glop example program I wrote a visualization of a quantum particle propagating in a crystal lattice1. I did it all in plain old Perl to start, and it was painfully slow: 1/2 a frame per second on a 32 x 24 lattice. Uh oh, this kind of speed simply won’t do for any serious game.

I rewrote my computation sub in C using the glory that is Inline::C, and it blazed along, even on a lattice four times the size (64 x 48). But then I noticed numerical stability problems. One particle sitting there without propagation would first be 100% likely to be there, then 150%, then 200%, then 300%… while I’d certainly like to measure it and find that it was three times more than always like to be there, I’m pretty sure the real world doesn’t do this (what happens when there is propagation and it’s 100% likely to be in two places at once).

I switched over to a Runge-Kutta integrator for the single particle case (which requires four computations of the derivative per frame), and that fixed the stability problems. But then propagation was still unstable, and in order to use RK on that you have to do it to the whole lattice four times—not just each position in the lattice four times.

So I scrapped all my C code; I wasn’t about to write that complex process in C, and it would have gotten unbearably slow yet again. I looked at PDL, since I had used it once for matrix computations during my Conjoint Analysis2 project. I studied up a bit, and implemented the RK method on the whole lattice: a computationally expensive process. PDL flew through it, giving me the same frame rates as the Euler integration gave for my C implementation. That’s amazing! I heard it was fast, but geez, that’s execellent.

I’m considering adding PDL to the Glop distribution, since numerical lattices are ubiquitous in games. I won’t if I don’t end up using it from the core, but I won’t hesitate to add it if I do want it in the core. Well, maybe I will. If it turns out that it’s easy to do something both in pure Perl and from PDL, I might provide a scan for PDL and use the pure Perl implementation if it’s not available.

1For the interested, the equation for zero-energy propagation on a one dimensional lattice is:

iħ ∂<x|ψ>/∂t = A <x|ψ> – 1/2 A <x-1|ψ> – 1/2 A <x+1|ψ>

Where <x|ψ> is the amplitude that the particle is at position x, ħ can be treated as an arbitrary constant when you’re doing a computational simulation, A is an arbitrary constant, and i is, of course, the square-root of -1. If you’re doing a multidimensional lattice, just add more of the negative terms, and change the 1/2 to 1/(the number of connected crystals).This is just a special case of a Hamiltonian integration. If you want to learn Quantum Mechanics, you must read Volume 3 of Feynman’s Lectures on Physics. It’s the absolute best.

2Adaptive Conjoint Analysis is a method that uses linear algebra to balance trade-offs between preferences. It’s a good way to figure out what consumers actually want, rather than what they think they want.

Class::Closure

I’ve released the first segment of Glop to the CPAN, and it’s called Class::Closure. It’s not directly related to games, but it is in a yak-shaving sort of way. Perl’s class syntax sucks, most Perl programmers agree on that. Both creating a basic class and referring to its members is a pain. So I wrote Class::Closure, which fixes that without using a source filter (if you want it with an ugly source filter, see my Perl6::Classes).

But another thing that games require more than anything else is speed. So I did some benchmarks on Class::Closure, and found that its dispatch was about 4 times slower than the generic object model. Acceptable, but not optimal. I did a few caching tests, and one of them proved promising. If I cached the methods in the class’s symbol table, it turned out to be faster than the traditional object model. So I switched over the whole module to create a new symbol table for each object instead of storing it in a hash, and it’s about twice as fast as the traditional model. As an added bonus, it cleaned up the inheritance scheme somewhat.

Roller-coaster letter

I got the deciding letter confirming or denying my acceptance to the University of Colorado today. The first paragraph is classic: an emotional roller-coaster ride. I’ll just paste it in for you:

I am pleased to acknowledge your interest in attending the University of Colorado at Boulder. After careful review of your application, we are unable to offer you admission to the College of Engineering and Applied Science [awww...]. However, in light of your past academic performance, I would like to offer you admission to the College of Arts and Sciences [wait—what? I'm.. wait.. what? Let me, um, I'm, um, accepted, er...?] I do hope that you will accept our offer of admission to this college and choose to attend CU-Boudler. [Er, okay, cool.]

So that makes me happy, if confused (you should have seen the other documents included; they’re even more ambiguous). I figure I can enter the A&S college and switch over to CS from there… If I want to.

My original plan was to major in computer science and fly through it, so I can get into CMU for grad school and learn something from the masters (no pun intended). But after my slackerly and bored performance in “Advanced” Java at front range, I’m not sure “flying though” would be the best option for me. I need something that interests me, at least a little. CS is a lot of work, and I’m not the type of person to put up with a lot of work when I’m bored.

So perhaps I’ll go back to my plan B, which was the interesting as opposed to strategic one. I could major in mathematics with a minor in theory and composition. Or double major in those. Or do one of those and minor in linguistics. Considering all this, I’ll probably wait until my second year to declare my major/minor—there’s just too much damn stuff I’m interested in.

But yay, I was accepted. This was by no means expected, but not to say entirely unexpected.

Auf Wiedersehen, C(?:\+\+)?

I just got SDL_perl working. And you know what that means… C++: so long and good riddance. I shall now be doing my graphical programming in Perl.

I will, of course, still need to tolerate that vile language until the completion of Glop. After that, it will be used as a kind of “assembly”, which I’ll use to streamline the computationally intensive portions of my games when they start suffering, and for that purpose I don’t mind it one bit.

SDL_perl was a pain in the ass to get working on both Mac and Windows. For Mac, I ended up getting the full blown SDL+Perl framework distribution, which still didn’t compile. I had to fish through the source and change all occurances of #include <sdl.h> to #include <SDL/sdl.h>, and likewise with OpenGL. A semi-pain.

On Windows, I learned how to use ppm which comes with the ActiveState distro (my, how that works better than perl -MCPAN -eshell), and then hunted for a working SDL_Perl and OpenGL ppm. Worse yet, SDL::OpenGL doesn’t seem to work; I have to use the older and dirtier OpenGL.pm. And even worse, it doesn’t even break, it just decides not to export (or contain for that matter) any functions. What a pain.

One of Glop’s goals is to make it dead simple to install. I now see how ambitious a goal that is.

Oh, yes, and I’d love to have provided links to all these things, since they were kind of hard to find, but Comcrap’s DNS seems to be broken for the moment. I’ll scan through and fill them in when it comes back.

Glop progress

GLIP is now called Glop (Game Language Of Perl). Wait and see what next week’s name will be!

I’m pulling together the work force. I created a public mailing list so I can communicate to everyone I’ve tentatively “recruited” so far. These include the IPC crew, a guy from the GameDev group, and my friend Drew. If you’re not one of these people and you read my blog (I really have no idea how many people do, but I’ve recently been finding out that it’s more than I thought), consider helping out. There are a lot of areas that could use work.

The Perl ODE module is almost done, which was the first piece. Modules for SDL and OpenGL already exist, though I’m not sure if they compile on Windows. There’s a task for the interested already.

After I find/make a 2D collision detector, the fun part begins. Glop the language can start taking shape. We start finding abstractions that are ubiquitous in games and factor them out into generic modules under the Glop:: namespace. We create a model for interaction events1. Then we start creating simple games, and finding things in common that can be factored out in a generic way. And the process continues.

I’ve recently discovered PAR, which handily does the all the distribution stuff I was wanting.

The ideas are taking shape, lining up to get some code on the page. I’m excited.

1I’ve been thinking about using POE, but I don’t know anything about it—there’s another job!

Andy Dick

I’ve just made a Poker enemy. His name is Andy, and I first met him at his $50 buy-in tournament. He said that he doesn’t want to play with me anymore. This is usually a good sign for a Poker player.

He’s a gambler. He calls everything, supposing he has anything at all. He takes pride in his accurate-about-half-the-time reads. He’s very agressive psychologically: he rips me to shreds any time he gets the chance, and Namaste says he does the same to him, when I’m not around :-). It seems like he’s steaming before he even gets started.

It is my duty as a solid Poker player to take money from people like him. If it were online, or at a casino, I’d be more than happy to take his $70 (the amount he lost tonight) and send him home crying. But the point of my home game is not to make money. The point of my home game is to have a fun night with my friends, learn something about cards, and hopefully make a few bucks while I’m at it. So in that respect, I’m disappointed that Andy doesn’t want to play with me anymore.

I honestly don’t know what his problem with me is. We have disagreements about how the game should be played. He’s for a max buy-in about 25-50 times the big blind. I’m for no max buy in, or if so, at least 100 times the big blind. It seemed like every decision I made about how to play the game he disagreed with. And even things that are standard practice he took me up on. I think we just have a general clash of personality.

Anyway, he did make the game more stressful, and not very much fun, so it’s partially good that he’s not coming back. In other news, I don’t think we’ll be doing a ring game anymore: the losers lost waay too much, and it wasn’t as exciting (no heads up at the end, all-in draws for the whole pot, etc.). We’ll go back to a couple of tournaments per night next week.