Challenges for iPhone CocoaGlk
First off, a screenshot. It might not look like much (or anything), but this is actually a bit of a milestone: that’s a glk window in CocoaGlk running under aspen:

The reason this is interesting is that it was actually several days worth of work before CocoaGlk could achieve the same feat. I’ve been able to take across even some of the UI code from the ‘full’ OS X version of CocoaGlk, so things are progressing quite fast.
There are still a few things that I need to make some decisions on, though. Read on for the details.
Development so far has actually been quite quick as I’ve been focusing on the things that are the same on the iPhone as on desktop OS X. Eventually, I’m going to need to address the differences, though.
Technical
No sub-processes
OS X CocoaGlk runs its interpreters in a separate process. This seems to be something discouraged by Apple on the iPhone, so they’ll run in their own thread instead.
This is not quite ideal. Most IF interpreters aren’t designed to be shut down and started up again, so this means that once you finish playing a game you’ll have to be returned to the home screen and not a game selection screen. Reworking interpreters so that they shut down cleanly is likely to be tough, error-prone work, and mistakes that lead to memory leaks are going to be more obvious on the iPhone. It’s annoying, but I think the best thing to do is to force the user to return to the home screen before starting a new game.
Another consequence of this is that each application will only be able to interpret one form of IF. Trying to stuff multiple interpreters into the same executable is going to lead to namespace collisions - farming them off to a separate process nicely solves this. This is going to be annoying when it comes to configuration as well: Apple’s restriction on applications not looking at data belonging to other apps means that each interpreter is going to need its own independent settings. Which is annoying.
There’s an upside, though: inter-thread communication is slightly faster than inter-process communication, so the display should run slightly faster.
Synchronisation
Something I would really like to implement is the ability to synchronise with Zoom running on a Mac, so when you plug your iPhone in, all your latest saved games are copied between the two applications, and any story files that you’ve selected get copied onto the phone. Unfortunately, I haven’t come across anything in the SDK documentation about synchronising yet, so I’m wondering whether or not Apple intends this to be possible.
Synchronising over wifi is possible, I suppose, but it would be nicer to have iTunes do it for you when you plug your phone in.
Obtaining games
I haven’t decided on the methods for obtaining stories yet. I think that this should be reasonably easy: provide an interface to the IFDB that works when the phone has a wifi connection. Synchronisation would be nice, but it can’t be the only way that stories are put onto the phone, because PC users would be left out in the cold.
Auto-save
Interpreters running on the iPhone are really going to need this. I doubt users would appreciate a ‘are you sure’ dialog when you hit the home button and losing game state just because a phone call has arrived is really poor form.
Zoom supports this, so this should be easy for Z-Code. glulx doesn’t, though: I’ll have a look at hacking this into the interpreter, but it really needs to be a part of the specification for any IF interpreter (even on the desktop)
Licensing
CocoaGlk is currently licensed under the LGPL and distributed as a framework. This isn’t appropriate for the iPhone, as there’s no such thing as a framework and the LGPL requires things that are statically linked to be under the LGPL as well. That means almost no interpreters as many are under incompatible licenses.
The solution is to change the license to one that is less restrictive: probably the MIT or modified BSD license.
A more serious issue is that Apple’s SDK license prohibits downloading code to interpret: this means that it would be impossible to load any games that were not bundled with the interpreter. I think this is probably a fatal problem: it seems doubtful that many IF authors will be willing to pay the $99 required to get their work onto the iPhone - plus it would mean no Zork, ever.
User Interface
I haven’t really decided on how the UI should work. The basic functionality should be pretty simple, but there are a few issues new to running on a small display:
Complex graphics
Games like moments out of time use a complex window layout that won’t work too well if we use a large enough font to be legible when everything is on screen. So, it would seem sensible to have a Safari-like ability to zoom in and out.
However, games with a more traditional layout won’t really benefit from this, so we’re going to need to be clever and detect when we need to have a zooming display and when a simple, more legible, display is useful - some experimentation is required! The initial version will go for the ‘big but simple’ approach, which should work with the majority of IF games that are out there, but I’m not going to be satisfied until games like City of Secrets and Moments Out of Time run and look good.
Text entry
This is pretty crucial to get right. The iPhone keyboard isn’t ideal for typing lots of stuff in, so CocoaGlk is going to need to help out. Luckily, I can borrow ideas liberally from the Palm interpreters that already exist:
- Tapping on a word in a text window should insert it as input (with an animation + a quick way of undoing accidental taps)
- Tap + hold on the center of the display should pop up a compass rose. Dragging in a direction will enter that direction as a command.
- If possible, I’d like any words the game prints that don’t exist in the autocompletion dictionary to be added, at least for as long as CocoaGlk is running: that should make typing those made up magic words a lot easier.
- There also needs to be a way of getting a list of common verbs. I’m thinking that if a tap+hold on the center brings up a compass, one on the right side of the screen should bring up the verb list - drag to select a verb (the verb under where the user taps would be blank to avoid accidental input)
- Possibly the tap+hold gestures should be duplicated in a toolbar along the bottom of the screen (or only done that way if it works better)
There’s a tap+hold gesture on the left hand side that’s not being used in this scheme, so if someone thinks of some other useful shortcut, that could go there. The reason for using a tap+hold to bring up shortcuts is that dragging is more sensibly used to scroll around the game output.
That’s it for now.. I’ll try to get something more exciting for the next screenshot. Honest.