Development Diary – Porting Dink Smallwood to iPhone

Can Dink be “done right” on iPhone?

A few weeks ago I seriously looked into the possibility of putting our beloved RTsoft freeware RPG on the iPhone in style.

I basically came to the same conclusion as previous times, it’s just Not Worth It.  I might as well work on something new, I can’t use the GPL version with my gaming framework, etc.

I mean, have you SEEN the original Dink source?  It’s hippopotamus butt.  What was I thinking?   I decided not to do it.

But whatever.   I had some free time while I was waiting on another project and figured I’d give it a test-run to see if I could solve the “millions of 8 bit textures on a GL device with power of 2 limitations” issue without any art retouching.

Plus, there is something delicious about the challenge of refactoring 11 year old code.  I can’t believe I just said that, but there it is.

Step 1: Replacing DirectDraw

dink_screwup

Here is what happens when the background isn't blitted right.. Dink paint!

First I wrote a skimpy software replacement for DirectDraw and dummied out the audio and text stuff.

My DirectDraw software replacement had a bug... but it somehow made a cool sideways ANSI house pic!

My DirectDraw software replacement had a bug... but it somehow made a cool sideways ANSI house pic!

After it was working right,  I put it on  the iPhone and used glTexSubImage2D to put the final “fake” directdraw surface onto a GL texture every frame.

640X480 drawn to a 480X320 screen doesn't work that well.  Plus, slow as hell.

It doesn't fit the screen and it's slow as hell. But hey, it's running on an iPhone.

Got 4 FPS.  Not surprised.  Even updating a tiny GL texture piece seems to be horrible slow, I guess on the iPhone 3G it actually updates the whole surface or something.

Just for fun I tried a technique where you draw a ton of GL_POINTS with color information instead.  Slightly faster for the 640X480 I needed, but for smaller things it’s actually pretty zippy.  I need to remember that if I ever want to do a low-res iPhone game where I need direct screen manipulation.

Step 2: Mixing software and GL surfaces flexibly

So, here comes the next logical step – let’s stop doing everything in software and get with the GL already.  Fine.  But Dink is a memory hog.  Just for the background tile sheets it uses FORTY ONE 400X400 images.  In GL terms, that means 512X512X4X41 bytes, or 41 MB just for some background tiles.  (half that if we go with 16 bit surfaces)

Considering we haven’t even got to the real sprites yet we can see this isn’t going to fly on the iPhone.

Now, we could get funky and write a smart texture atlasing utility and such, but I think there is an easier way.  Plus, I like the idea of using the original media formats, could help with DMOD support later.

The solution?  We’ll keep our fake software DirectDraw around but enable it to create and maintain “shadow GL” textures of themselves when actually blitting to the screen.  We can give hints such as “don’t shadow GL any of the game tiles, just the final background that is built”.

The result? Even after re-enabling text and audio through my Win/iPhone framework I got 2400 FPS on Windows using OpenGL and >50 FPS on the iPhone using GL ES.  I’ve changed my mind, Dink is coming to iPhone!

Real-time scaling to 480X320 looks pretty good.  FPS not bad either!  Temporary GUI, this will improve.

Real-time scaling to 480X320 looks pretty good. FPS not bad either! Temporary GUI, this will improve.

Step 3: Get Justin on board

Justin Martin, the original Dink artist has agreed to partner up and handle spiffing up the GUI – We’d both love to see an eloquent mobile version of Dink available.

Step 4: The real work

But to do this right, I still need to add some very important features.

The challenging ones will be smooth and legal DMOD support on the iPhone and “save/restore anywhere” functionality.

I’ll also take this opportunity to fix/change a few things that have been bugging me about the original Dink, improve the audio, some balance issues, etc.

Special thanks to Dan Walma (redink) and the Dink Network for letting me use the V1.08 version as a base to start from – it includes some improvements and bugfixes over 1.07.  It’s still total ass though.  (Not their fault, .. mine)

12 thoughts on “Development Diary – Porting Dink Smallwood to iPhone

  1. tonic

    AFAIK whenever you upload/modify a texture, it’s going to be swizzled which in turn ends up doing a malloc, so that’s an inherent source of some slowness. It still doesn’t completely rule out doing some per-frame-updates…

    I didn’t exactly understand the details fully about how you jumped from 4 to 50 fps though. You said you’re creating a texture version of all the graphics but without actually using an atlas… but not for the background? For what you describe, it sounds like you’re constructing the fullscreen background on the fly as a software 480×320 buffer and then make a texture it each frame, which is what I thought would exactly make everything dog slow. Can you elaborate just a little bit on that? :)

  2. Seth Post author

    Hmmm, that swizzling thing would explain the slow down even on small pieces.

    You have the right idea about how it’s building the background – but here’s the thing, Dink is like, say, NES Zelda. It has a static non-scrolling background which works well for this.

    So the actual background is only updated when the character pushes against the bounds of the screen and the game pages to the neighboring screen – an acceptable 300 MS delay.

    Actually a bit more because I glRead the screen into another texture before loading the new one so I can do a smooth sliding transition between them.

  3. DaVince

    Nice. But I’m wondering, wouldn’t it have been easier to start from FreeDink, considering how it already relies on cross-platform libraries, and its code is cleaned up?

  4. Seth Post author

    DaVince – it probably would be, but FreeDink’s GPL license is incompatible with my iPhone framework and places strict limits on how I can use the source later.

    By using my original source base I keep things free and clear of red tape.

  5. DaVince

    Oh, I see… That’s too bad. Now that I think about it, I do believe I’ve read once that GPL’ed code can’t be submitted to the iPhone store or something like that.

    So your original code wasn’t released as GPL at some point? Hmm…

  6. Billy Hyde

    I was thinking the same thing about Beuc’s FreeDink until I realised that Seth probably wants to sell this. Whereas if the iPhone source was GPL’d someone could easily compile it and run it on their jailbroken iPhone without paying a cent.
    RTSoft most likely still retain the rights to the original source. It was released under no specific license. Beuc did mention something about a bzip license though.

  7. Swordfish Guy

    I’d love to see Dink on the iPhone. Whether you could get full d-mod support is an interesting question. If it couldn’t be done, would you consider cherry picking a selection of the better d-mods to be included with the game (Prophecy of the Ancients etc), or just stick with the original adventure?

  8. WhiteKitteh

    This makes me happy. :D!

    But to be perfectly honest, I’ll probably buy an iPod touch + DinkMobile, But never play it. It’ll be like a nerdy conversation starter!

    “I’ve got Dink Smallwood on my iPod!”
    “Really?, That’s awesome!, Where are you up to?”
    “uhh.. The nut tree..”

    Hmm.. Wait, Will it even be available on the iPod? I don’t have ether, So I’m sort of assuming that they use the same service. Guess I’ll have one soon, then?
    And out of curiosity, Is Justin just doing a new interface, or will other things be overhauled?

  9. levent

    As a suggestion;
    Since Justin is on board, do you plan to revise up some of the gfx and animations? A clear case that needs a revamp is the NPC walking animation. Those were *good* in ’97, but I think giving them an update of 8-way animation like Dink himself would well worth your time. So far the progress is well done. I might consider getting an ipod for this (though I’m playing original on my PSP now)

Leave a Reply

Your email address will not be published. Required fields are marked *