Phil Hassey - game dev blog
Phil Hassey as Rambo
".. I've been there,
I know what it's like,
and I'll do it again if I have to."

Archive for the 'gamedev' Category

Prototyping in python

Friday, October 24th, 2008

So it’s about time to make something new here:

Instead of jumping right into the iPhone code on this one, I decided to prototype the game in python+pygame first. I’ve gotten a lot of UI glitches worked out, and I’m going to get at least one complete single player game working nicely in python before I port it over to C.

Galcon was “easy” to port to C because I had a very clear definition of what I was going to create before I created it.  Since this is a new game, I think if I define the game pretty well in python first it will save me loads of time tweaking stuff in C.

Watermelons for the iPhone / iPod Touch

Wednesday, September 10th, 2008

Watermelons is the ultimate fruit rescue mission game! The local watermelon tree has gone berserk and is producing fresh watermelons at an amazing rate.

You must move your trampoline at high speed in order to save the melons from splattering horribly on the ground. You get ten slip-ups before you lose your job as the Melon Master.

Includes high scores, realistic watermelon sound effects and authentic watermelon bouncing soundtrack.

Watermelons was first created in several hours using python+pygame.  I then ported it to haxe.  And then last of all, I ported it to the iPhone / iPod touch using C code.  I suppose the dev lesson learned is .. rapid prototyping stuff in python is really quick and easy.  So when I port a game from python to something else, I’ve got the whole game concept down, so it’s fairly straight forward to switch to a static language like C.  If say, the problem was not well defined, I suspect it would be harder to implement the games in C first.  (I think my statement here was particularly true for porting Galcon to the iPhone.)

Anyway, check out the flash version, and if you think it’s worth your 0.99, you can get it on the App Store now 🙂

Help Galcon – digg it :)

Thursday, September 4th, 2008

Hey, one of the Galcon-iPhone users is really doing his best to help me get the word out! He’s put up a digg article linking to an awesome youtube video he made demoing the gameplay on the iphone 🙂 Spread the word – and check out the sweet video!

Comparing python to C …

Wednesday, August 6th, 2008

Well, I’m about 1/2 done with adding multi-players to Galcon-iphone.  I figured I’d stop for five minutes and note down some things I noticed during my porting experience.  Obviously, C and python are different, but here are a few of the ways I’ve FELT the difference.

  • C doesn’t have garbage collection.  I’ve managed to avoid doing much manual GC by having everything in a single big struct that keeps the entire state.  The only place I use malloc/free is when I’m downloading web data.  So it hasn’t been a big deal for this project.
  • Speaking of web data, C doesn’t have a built in urllib.  I wrote my own awful HTTP 1.0 page fetcher.  On the plus side, I was able to make it work *exactly* how I wanted it.  No threads, non-blocking 🙂
  • Although not “built in” I found enet, which was a thin layer above UDP for networking.  I found this incredibly much easier to use than python sockets were.  (Yes, I could have used some other python lib, but I didn’t.)
  • C is really fast.  Thankfully, since I originally dev’d Galcon in python, I was “forced” to get my algorithms pretty good to keep the speed reasonable.  By porting everything to C, I’ve now got amazing speed.  I think I could host 100+ servers on a single CPU easily.
  • Managing strings in C is an ordeal.  It’s just not pretty, so I try to avoid doing much with them.
  • OpenGL seems pretty painless in C.  I haven’t done any notable OpenGL stuff in python, so I can’t really compare the two.
  • No exception handling makes me have to code things more carefully.  In python, I could parse an incoming networking packet, and just wrap it in a “try: (parse stuff) except: pass” block.  If something was bad about the packet, it would just move on.  In C, I have to check everything carefully so that I don’t create some kind of segfault by accident.
  • In my case, serializing data is easy in C.  I can just save a structure to a file (or send it in a net packet) and load it back later.  In python this is much more complicated.  (Especially since Galcon-shareware isn’t pure-python.)
  • By using C, I don’t have to deal with some awful FFI.  That is a HUGE time-saver.
  • I must admit, I LOVE python’s indents.  But I also must admit, now that I’m back into C coding, I don’t miss them as much as I thought I would.
  • I still dislike header files.  I wish C magically generated them or something instead of making me write them.
  • I learned about writing tests in python.  I’m doing that in C for my networking code.  I run the tests as part of my build process, and it saves loads of time by catching all the bugs for me 🙂
  • Automatic type checking is sort of nice.  Having the compiler tell me I didn’t do anything incredibly stupid is sort of nice.  (Although in some cases, it can get a bit annoying.)

Well, that’s about all I can think of for now.  Draw your own conclusions.

did someone say “galcon in the browser” ??

Saturday, April 5th, 2008

Hmn .. maybe someone did ..

ggconn.jpg

Yep, that’s python+pygame alright .. 🙂

Fun with the OLPC!

Wednesday, March 19th, 2008

Yesterday and today I worked with Mike Fletcher and had a great time porting a couple of my games to the OLPC 🙂

Watermelons

olpc-melons.jpg

Elephants (pic taken with an XO!)
blah.jpg

I had a great time working on this – though a couple of odd bugs in the dev. environment proved to be a bit bothersome, we were able to get through them. The main product of this effort was the creation of the “port your pygame game to the OLPC” tutorial.

On a side note, I also gave an impromptu talk on networking games to help an OLPC group get some good ideas on how to write an easy to use networking API for their games. A fair portion of it explained how I implemented networking in Galcon. The other portion explained how “I did it wrong – and you should do it some other way such as _____.” Richard Jones and Mike Fletcher also attended and chipped to help explain the bits that I glazed over.

Retro-remake of Joe Snow!

Wednesday, February 20th, 2008

I never thought I’d see the day where someone would do a retro-remake of one of my games! Indeed, someone has – Joe Snow Test Demo Released!! Check it out and leave some feedback 🙂

(My original is here for comparison. The remake is much better!)

tinypy 64k – nearing 1.0 – and it really does fit in 64k!

Tuesday, February 19th, 2008

Updates – I’ve got it all fitting in 64k*. It’s amazing how many functions that don’t do anything you can come across if you look around long enough. Not to mention how many little things you can trim out that don’t actually do anything. I have no idea where all this cruft comes from, but having a nice suite of tests sure is helpful for re-working stuff. I also cut out a bunch of stupid features nobody would ever use**. I was able to reduce the number of native types from 9 to 7.

One of the challenges I faced was trying to fix up the incremental garbage collection. My initial implementation was rather inefficient and caused some odd problems with how I wanted to code things. I was using a dict to store all the “white” items, which caused loads of dict hash lookups.

So in my mind I crafted a grand vision on how to accomplish this goal. I would adjust all objects (sans numbers) to contain a pointer to some data which would have some header data for the GC to do some bookkeeping in. Great! However, when I implemented this, I found that a number of problems presented themselves: I had to perform a malloc for each and every string that I used, which killed performance, actually making things 2-3x slower. I also noticed that the weird struct I defined was maybe a bit less standards compliant. This attempt was a wash.

So I re-crafted my grand vision. This time I would do the same thing. Brilliant aren’t I? Anyway, the results were basically the same. Who’d’ve thunk? It was slower again, this time I was quite confused by it, since I had worked around some of the string issues. I also found that the API for creating new strings wasn’t quite as “clean” as my original simple one. This caused some issues in the exception handling mechanism. I had to toss this try as well.

At this point, having re-mangled the code twice and having poor results, I suspected something else might be wrong. My brain was turning into mush. Each time I had completely edited my “tp.h” with all my struct changes in one go. I decided to make a final attempt at reworking tinypy, this time *one* data type at a time. After each data type I added I was able to see if my changes caused any performance issues. I found that my function data type was the culprit. My hashing function (borrowed from lua) wasn’t getting enough entropy and was generating massive collision cases! A few tweaks later, this was resolved. I was able to also craft the string interface to be backwards compatible with the original string interface while also working with the new garbage collection. This “step by step” approach got me to my goal. All said and done, with a bit more tweaking, I was able to *double* the speed of tinypy 🙂

Lesson learned – even if it’s only 64k, it’s better to do changes step by step instead of in one big go. valgrind and callgrind are your friends. (Although I found that tinypy doesn’t entirely agree with callgrind … ideas anyone?)

To wrap up this excessively long post about me trying to get code to work — this weekend I’m hosting a Ludum Dare warmup compo. I’m going to give tinypy a run in the “real world”. Here’s to hoping! Next week I plan on releasing the 1.0 version of tinypy.

I’m also thinking about renaming some of my files. And although pylang, dumbparse, and dump2vm have a certain rustic charm, I wonder if I’d do better with names like goat, gorilla, and sausage. Or maybe more descriptive names like tokenator, parsalizer, and bytecodatron.

svn://www.imitationpickles.org/tinypy/trunk for the brave. If you want a zip or an exe, check back in a week. I’ll have all those and more (a game!) Note that I’ve split the SDL dependency out of the main tinypy code. tinypy-sdl.c lets you run my julia.py example. The bootstrapping process also has a final step of compiling with -O3, which I think might not work for everyone. It gives pretty good speed gains on my system, so if it works for you, great!

*python mk64k.py will do a bit of search-n-replace to cut it down to size. I’ve resisted doing anything really ghastly, the code is still indented and readable. See README.txt for more disgusting details on how I cheat to pretend this is 64k.

**Okay, I’ve used some of those features. But hey, this is a 64k implementation, I’ve got to trim the fat.

tinypy 64k – now with built in garbage collection

Tuesday, February 12th, 2008

Yay – I got incremental garbage collection added into tinypy. It took a good deal of troubleshooting, but thanks to valgrind (and thanks to the people who pointed me to it) after some work I got all the memory leaks and crashes worked out. This is a nice step forward, since it enabled me to eliminate the libgc dependency.

tinypy is slightly larger than 64k, but I have vague hopes that will be remedied* at some point. In the meantime, I’m going to take a bit of a break from it. On Feb. 23rd, the Ludum Dare community is having a “warm-up” compo, and I shall give tinypy a real try at that point. After that I will probably put out the 1.0 release.

All that said, its been quite a learning experience for me. I learned how to tokenize, parse, generate byte code, build a virtual machine, and do garbage collection. I’m hoping this will make looking at the innards of other languages seem less intimidating in the future.

* if you’re a clever C / python coder and feel like taking a look at the tinypy code and give me ideas on how to compact the code a bit, I’d sure appreciate it. It’s 4k too big right now, and I’d really like to fix that. I’m cool with any suggestions though I won’t implement anything unless it leaves the code just as (if not more) readable. Please examine the README.txt to find out how I calculate the code size first.

svn://www.imitationpickles.org/tinypy/trunk or tinypy.zip for the brave. I’ve managed to compile it under mingw32 (Minimalist GCC for windows) as well as using GCC under MacOSX. Perhaps for the 1.0 release I’ll include binaries 🙂

64k tinypy – now with VM included

Thursday, January 10th, 2008

I’ve managed to build a simple VM into tinypy – modeled after the lua VM. It’s register based and “stackless” in the “it doesn’t use the C-stack” sense of the word. (Not in the, it does anything fancy like “stackless python” does sense.)

‘ve just reached the 64k mark, so that means anything I add into the code will require me to clean up other code to save space. I’ve already done a bit of that with good results. The one rule I follow in shortening code is that the code must retain readability, if not improve it.

Garbage collection is rather complicated, so I think I’ve decided to continue to leave that to libgc. I read some literature on the matter, and it sounds like I could write one, but it probably wouldn’t be very good. I’ve put it at the bottom of my TODO.txt list in the section labeled “Probably not going to happen”.

At present tinypy supports basic python code with functions and loops and lists and dicts and classes. At least, in some basic form. I’m looking towards adding in list comprehensions and *args **nargs to tinypy as those are two of my favorite python features. After that I’ve got a handful of functions I want to write and then some packaging work.

For the curious svn://www.imitationpickles.org/tinypy/trunk – ./run_julia_o3 to see it all happen. It depends on python to compile the bytecode (we’re not bootstrapped yet), libgc, and SDL.