Sunday 24 January 2010

Building pygame on OSX Snow Leopard

The version of pygame available on the pygame site works for the python.org version of Python. I want one for the system Python (2.6.1 64-bit). I decided to revisit this after giving up (very easily) the first time.
  • First, get pygame source. I'm trying with 1.9.1 release. This sounds like recipe now.
  • Untar the source and python config.py reveals some dependencies are necessary. Config will show you which ones you have available.
  • The pygame dependencies are as follows. So we'll need collect these. Notes follow.
    • SDL.
    • SDL_ttf  (fonts).
    • SDL_image.
    • SDL_mixer.
    • smpeg.
    • PNG.
    • JPEG.
    • SCRAP  (cross-platform clipboard).
    • PortMIDI.
SDL
  • There is a Mac SDL 1.2 package on the downloads page.
  • I got SDL-1.2.14.dmg.
  • Version 1.2.14 has Snow Leopard support according to the ReadMe.txt and is the minimum requirement. See notes below from UniversalBinaryNotes file:
64-bit Universal Binary Notes:
SDL 1.2.14 is our first release with Snow Leopard on the market. In order to make SDL compile and run in 64-bit, we had to remove code that depended on deprecated Mac APIs and move over to more modern Mac APIs.
In addition, Apple has stopped shipping gcc 3.3 and the 10.3 SDK.
Because of all these combined factors, we have made the decision to make Mac OS X 10.4 the new minimum requirement for SDL.
Our official SDL.framework is compiled as a 3-way Universal Binary (64-bit Intel, 32-bit Intel, 32-bit PowerPC.)
Certain APIs that SDL relies on were not made 64-bit ready by Apple until 10.6. This means even though 10.5 had preliminary 64-bit support, SDL will not compile or run correctly in 64-bit mode on 10.5. So there are two fallout items from this.
First, you can only compile 64-bit code on Snow Leopard or greater (which removes the possibility of 64-bit PowerPC). 
Second, this presents a corner-case where if you have a 64-bit Intel executable in your Universal binary and try to run on 10.5 on an 64-bit Intel Mac, it will launch and crash. To force 10.5 to use the 32-bit version instead of the 64-bit, you should set the LaunchServices key, LSMinimumSystemVersionByArchitecture, in your application's Info.plist. Our SDL/Xcode templates for Snow Leopard already set this up for you.
One additional fallout item is we had to remove the SDL Custom Cocoa Xcode template project. It depended on NSQuickTimeView which was deprecated and removed from the SDL codebase. It may still be possible to recreate the behavior that this template demonstrated, but we would need a volunteer to investigate this.
In addition, the SDL satellite projects were affected by the 64-bit transition.
- SDL_mixer depended on legacy Quicktime for midi playback support. We had to disable midi. (Recall that we also disabled MP3 support awhile back because we never got SMPEG working during the Tiger/Intel transition.) To fix this, we would need a native Core Audio backend for SDL_mixer.
- Since we have changed the baseline to 10.4, we took this opportunity to switch SDL_image over to a new native ImageIO based backend. This makes the binary about 10x smaller, greatly simplifies our maintenance requirements and build process as we no longer have to maintain build systems for 3rd party dependencies, and gives us access to more image formats.
- The static library target for SDL_ttf no longer works because we no longer have access to a libfreetype.a. We have been relying on Apple's supplied libfreetype.a, but they stopped shipping a static version starting in 10.5 which means we have no static 64-bit version. But since 10.4 is our new baseline, all these systems should have libfreetype.dylib installed, so it shouldn't be much of a problem to use SDL_ttf as a dynamic library which dynamically links to libfreetype.
-Eric Wing 2009-09-23
  • To install SDL 1.2.14 we copy the SDL.framework to /Library/Frameworks:
    • sudo cp -r /Volumes/SDL/SDL.framework/ /Library/Frameworks/SDL.framework
SDL_ttf
  • There is a Mac OSX package on ttf project page.
  • I got version 2.0.9.
  • sudo cp -r /Volumes/SDL_ttf/SDL_ttf.framework/ /Library/Frameworks/SDL_ttf.framework
SDL_image
  • Get package from image project page.
  • I got version 1.2.10.
  • sudo cp -r /Volumes/SDL_image/SDL_image.framework/ /Library/Frameworks/SDL_image.framework
SDL_mixer
  • Get package from mixer project page.
  • I got version 1.2.11.
  • sudo cp -r /Volumes/SDL_mixer/SDL_mixer.framework/ /Library/Frameworks/SDL_mixer.framework
smpeg
  • From icculus page.
  • svn co svn://svn.icculus.org/smpeg/trunk smpeg
  • We'll skip this for, it's optional.
PNG
  • Get libPNG from the Sourceforge project download page. I got 1.2.42.
  • Don't run configure. Instead: cp scripts/makefile.darwin Makefile
  • make
  • sudo make install
JPEG
PortMIDI

  • Source is hosted on Sourceforge. 
  • I got version 2.00. Fairly new. 
  • Note: PortMIDI uses cmake to generate makefiles. So you'll need to have that installed. I have version 2.8.0. 
  • make -f pm_mac/Makefile.osx 
  • cd Release 
  • sudo make install 
SCRAP

I think this is support for the clipboard for pygame. We are missing sdl-config from our SDL framework install so we can't configure SCRAP to build it. We'll skip this.

Building pygame

So after all that palaver, you can now go to the pygame source and run the config.py.

One problem: Portmidi seems to have changed the name of its static library. It now has "_s" appended. config_darwin.py needs editing:
config_darwin.py:    Dependency('PORTMIDI', 'portmidi.h', 'libportmidi_s', ['portmidi']),
    Now:
    • python config.py
    • python setup.py build
    • sudo python setup.py install

    After testing... some of the examples work, but fonts don't. :(  This is something to do with SDL linking with a new dynamic library version of freetype which I think is in the /usr/X11/lib direcotory, but this isn't in the dlopen path... Grrr.


    Wednesday 20 January 2010

    Python Game Lab

    The Concept

    I started a new project on Google Code called pygamelab. Often, when you have some spare time and want to try out an idea it takes you most of the time to figure out which libraries to use, how to use them, debug them and develop your idea. Sometimes, your enthusiasm for the idea has evaporated by the time you finally have the tools to attack it.

    It would be nice to have a starting point that was:
    • Python: quick and fun to write.
    • Portable: Works on Windows, Mac and Linux.
    • Has lots of features to play with.
    • Has plenty of examples.
    • Has some useful tools.
    • Well documented libraries.

    One popular solution is pygame, but unfortunately Mac support isn't great. You need to install the python.org version of Python in order to install the version supplied off the site; I don't want to do this. I don't want the clutter and confusion. And if you do compile it natively, only other users that have done that can play your games.

    The Libraries

    So I looked around and found pyglet. This is a portable, Python OpenGL wrapper. It uses ctypes to access the necessary binary libraries for each platform. Pyglet also includes avbin, which gives access to multimedia functionality, like video streaming. Brilliant!

    Additionally, there is Cocos2d, a layer on top of Pyglet, which supplies things like game flow, sprite management and tiling. Then for physics, I've chosen pymunk. This uses Chipmunk, the C library, which I've used before. Again, this uses ctypes, but this time to a supplied binary. It works on Windows, Linux and I've supplied a Mac binary (that works with the system Python). There will be more libraries to come as new features get added. I'm currently experimenting with GUI libraries kytten and simplui.

    An important point to note is that the libraries are included in the repository. This means a user does not have to install extra Python packages and the versions will be compatible. It also means that I can fix bugs (which has happened) and modify the libraries. For example, they can be patched from the library repo with the latest features. For the package to be portable this means that care should be taken about any binaries that are included. Only two libraries contain binaries at present:
    • pyglet, with avbin. This looks to have good cross platform support, and uses ffmpeg, which again is well supported, portable and stable.
    • pymunk, which uses Chipmunk. This also looks to have good cross platform support (and 32/64bit support).
    Hosting and Version Control

    My previous projects have been on SourceForge. This is great site, but it is becoming a little slow and cluttered now. I thought I'd try Google Code, and so far it has been very good. Very fast, nice set of features and not complicated. Just the right level of functionality for managing a small project.

    For version control I decided on Mercurial. I'm relatively new to DVCS, but I've really started to like the idea of having a repository that you can clone and experiment with, and also that you don't have to be network attached to commit work. It makes working and experimentation a lot more flexible. It's nice to be able to clone a repo and experiment, commit to that depot, but then throw that work away if you want to. In non-DVCSs you'd have to obliterate the information somehow, and this sometimes has dire consequences.

    The other nice feature of Google Code projects is that users can clone a Mercurial repos for their own use. So if you want to collaborate with people, you don't have to give them access to the main repo. They can go away and experiment and do whatever you want, and you can choose whether you want to pull and merge. This is one of the ideas behind pygamelab, that you can clone a useful starting point and do your experiment quickly.

    The Future

    It's relatively early days, but I'm pretty happy with how it's going so far. I'm planning to supply a few simple default games from different genres that supply lots of different features. These will act as starting points and as sample code. And developing them in the first place is fun besides.

    So the idea is:
    • You clone pygamelab.
    • Mess around.
    • If you cloned the repo in the pygamelab project you push back any cool changes.
    • Everyone else can see your work and potentially pull it.
    • Any good features make it back permanently into the main repo.
    Assets

    Some of the default assets are from the Lost Garden site. There are some interesting articles on there and I get itching to try them out, but there is always that hurdle of getting started. So hopefully soon I'll be knocking out games or other apps. Just doing the research and getting things going has opened up a whole load of ideas.

    Sunday 17 January 2010

    Building PyQt4 on Snow Leopard

    Here are some notes on building PyQt4 on OSX 10.6 as I always seem to miss a step every time I do this! It should be very similar for all POSIX systems except for a few flags here and there.

    My set up: Intel MacBook Pro, OSX 10.6.2, Python 2.6.1 (Apple system python 64-bit, not python.org 32-bit Python).

    Get Qt LGPL package. Note, you want the Qt Cocoa libraries as PyQt4 expects 64 bit libraries. The default libraries in the Qt SDK are for Carbon (32-bit) for backwards compatibility. Snow Leopard gcc compiles 64-bit code by default.
    Get latest sip. Build and install:
    • python configure.py
    • Check configuration is what you want.
    • make
    • sudo make install
    Get QScintilla package from Riverbank.
    • cd Qt4
    • qmake -spec macx-g++ qscintilla.pro
    • make
    • sudo make install
    • make clean
    Now get Mac PyQt4 from Riverbank:
    • python configure.py
    • Accept the GPL license.
    • Check the configuration log doesn't contain anything silly.
    • make
    • Go and make a cup of tea. You have plenty of time.
    • sudo make install
    • Test to see if there: python -c 'import PyQt4; print PyQt4'
    If you get some error about PyQt4 being 64-bit and Qt is 32 bit, you've installed (or built) the default Carbon version of Qt. Build or install the 64 bit Cocoa version, as instructed above.

    Now, back to QScintilla package as we're going to build the Python bindings. This has to be done after PyQt has been built and installed.
    • cd Python
    • python configure.py
    • make
    • sudo make install
    • make clean
    Now the Qt Designer QScintilla plug-in:
    • cd designer-Qt4
    • qmake -spec macx-g++
    • make
    • sudo make install
    • make clean
    • Start Designer and make sure the QScintilla plug-in is there.

    Thursday 7 January 2010

    Microsoft Shopping Channel Slated

    Oh dear, can you smell the fear? Watch the video.

    It's like the Microsoft Shopping Channel. Has Ballmer really been reduced to this?

    Judging by the comments on the BBC site page I think many consumers have seen the light. Microsoft has failed to deliver. They missed the internet, tried to stifle competition, spent too long on luke warm Vista, and now they're worried about losing market share because they've missed the mobile market. People don't want a PC on a slate. They want something fast, responsive, easy. You don't want to "go into PC mode" when you pull your phone or slate out of your pocket.

    And I don't think it's even due to Bill Gates leaving. Microsoft just seem to be doing the same thing, but in a less savvy way now. Microsoft want to be everything to everybody, and you just can't do that. Microsoft have the desktop; it's a given, but Apple have exploited their niche very well, and quietly beavered away to create a great operating system which is part of a package that provides great software that is relevant to people today. For the average user, they hardly need to shell out for anything after buying a Mac. You get iPhoto, email manager, a proper web browser (HTML5?), Garageband, Xcode, and not forgetting Time Machine.

    Personally, I'm totally sold on the Mac at home at the moment. I didn't want anything Vista on it. It seemed like a sideways move. What does Vista do amazingly better than XP? Ultimately, the thing that sold me on OSX was Time Machine. I went from one shop looking at Sony laptops with Vista on and then into the Apple store. There was picture on the wall of Time Machine and I suddenly realised that Macs aren't more expensive, and even if they are, they are worth it. You save time and have a more enjoyable user experience. To have fully automated backups on a Mac, completely transparently all you need is an external hard drive.

    I'll probably be slagging off Apple one day when they become the complacent, greedy, corporate overlords that everyone hates, but for now I can't wait to see what the "iSlate" will offer. Microsoft are clearly rattled.

    Monday 4 January 2010

    Spaces and Command Key

    I've finally settled on a set up for switching spaces that I'm happy with on my MacBook. I started off using the command key + arrows to move from one space to another. But the problem with that is that it conflicts with editing any text, as command + arrow keys moves to the start end and end of things, which is a big thing to lose.


    I've tried control + arrows and option + arrows, but you always lose some functionality. It doesn't seem very well thought out. And why can't you use the "fn" key on a MacBook with the arrows?

    So I've given up on command + arrow keys and now I use command + number keys. This works well for the laptop, or for the keyboard I plug in for serious typing. You can't type properly on those new flat ones. Bah!

    It's very quick and comfortable once you're used to it, especially if you use command + tab for switching applications

    Saturday 2 January 2010

    Monkey Man

    This guy is amazing, completely fearless! I hope he gets his funding.

    Justin Lee Collins sucks

    Why is Justin Lee Collins on television? He just blathers on and on and has nothing interesting to say. He's just like some boring, conceited bloke you accidentally bump into in a pub who you can't get away from. Is this country really so short of talent that this is the best we have to offer? At least he's relegated to Channel 5 now. The slow decline.

    Excellent, there is a sack Justin Lee Collins petition. There are also other blogs detailing his crapness on his Star Wars programme. And a group on Facebook.

    Enough.