-->

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)

Some more iPhone benchmarks and tests with everybody’s favorite difficult to pronounce 3d rendering framework!

Thumb mode and floating point:  Just don’t

iphone_irrlicht_md2_again

Ok, first, I was an idiot before and somehow was still compiling in thumb mode. I know not to do that!

Somehow the setting was removed but I guess the default is ON even with it missing or something.  After adding it by hand it the math-heavy md2 anim rendering test went from 31 fps to 60+ fps.

I think the mistake came from editing the build configuration by clicking on the project settings instead of the “build target” settings, so I’m going to check both from now on to be safe.

Irrlicht and Quake 3 style .bsp demo

Irrlicht's .bsp map demo on iPhone using pvrtc4 textures with collision

Irrlicht's .bsp map demo on iPhone using pvrtc4 textures with mipmaps and player collision enabled

I was expecting Irrlicht to do some kind of wicked optimizations when rendering a .bsp map.  Nope, it does nothing special.  You CAN load it into an octree but if OCTTREE_USE_HARDWARE is defined it renders the whole mesh anyway. (?!!?)   If that flag isn’t defined, it does render less primitives but without using VBO’s so it’s way slower anyway.

This forum thread may be of interest about that.

Collision detection would be a better candidate for a software octree but after playing with createOctTreeTriangleSelector with different settings I never saw even one fps of difference.  Strange, I would have expected it to noticeably help.

(this section was updated Dec 2nd after Tonic pointed out that you can use VBO’s with Octrees…)

Adding iPhone controls

As you can see in the screenshot above I’ve added a basic wolf3d control scheme to get around.

I use my own engine to handle the GUI overlay/handling (it draws after Irrlicht is done)  and just have it controlling Irrlicht’s FPSControlComponent.

I use camera->setTarget() to look up and down, and I fake UP/DOWN/LEFT/RIGHT key movement by sending pDevice->postEventFromUser() messages.  This works ok but bites because it’s not proportional or 360 degree so I’ll need to modify FPSControlComponent or just do my own movement stuff if I want to do it right.

Do using compressed textures help the FPS on the iPhone?

Short answer, a little.

I added CImageLoaderRTTEX to Irrlicht so it could load my own texture format.  It’s sort of a container that houses multiple formats including pvrct4, pvrct2, 4444 rgba, 565 rgb, etc.  It does extra stuff that normal .pvr’s don’t, like remember the original image size before padding or stretching.

I also modified the b3d and .bsp loader to look for textures with my .rttex file extension first.

Some rough numbers with the quake style .bsp map collision disabled:

  • Map test with raw 32 bit textures with mipmap chain: 26 fps
  • Map test with pvrtc4 format textures with mipmap chain: 28 fps

So yeah, tiny difference.

However, keep in mind there are also other good reasons to use pvrtc:

  • Fast loading even when zlib’ed.  Especially compared to decompressing a .jpg
  • Use a hell of a lot less texture memory

On the down side, the visual artifacts can look pretty bad so you still need some raw formats in your toolbox for specific images like GUI.

Do using mipmaps help speed on the iPhone?

I didn’t notice a difference.  Using mipmaps look better though, although I need to adjust the lod bias a bit so it doesn’t pop up so bad…

Tip: The iPhone requires a full mipmap chain to work, so don’t try to get tricky and only include a few of them.

irrlicht_broken_mipmaps

For your enjoyment here is what  happens when your texture processing utility has a bug in its mipmap generation.  (The festive blue, pink, and green colors shouldn’t be there…)

Putting it all together, our own level

I’ve got to say, the king of the 3dsmax exporters for Irrlicht is B3D Pipeline.

I know, you’re thinking “Uh… b3d, that Blitz3d format?  Why not use collada or .x or something?” All I can say is this is the exporter that actually worked right for me when trying to get the lightmaps working.

max_house_scene_render

So here is a low poly house in 3dsmax.  I’ve applied a light source and got it looking how I want.  Then I use max’s render to texture feature to make a single alpha lightmap.

The (old) iPhone has two texture units and this will be the second one, controlling where shadows appear, the same way the .bsp map example works.

After exporting it pops into the game engine fully lightmapped and ready to go with a single line of code.

iphone_irrlicht_shadowmapping

After adding a skybox and a simplified collision mesh it still gets nearly 60 fps, not bad.  Too bad a game needs more than one house.  Hmm, my fov looks a bit extreme.

So being between projects means I get to play around with random technology!

For some upcoming secret projects I’ve setup Flite TTS and Irrlicht as plugins in my iPhone engine to test out.

Flite

It’s a text to speech thingie that lets you make the iPhone talk.   It’s uh… well, I actually don’t really have a problem with it except I’m having a hard time controlling pitch and inflection.  Does anybody know of a better library?  Here’s a sample I made of Flite using the Kal 16kz voice. (Flite 1.3)

First, I’m sorry about the content of the audio.   Second, there is a problem where raising the pitch for the (loosely) female voice causes clipping.  Maybe I shouldn’t be using “Kal” for that.

Irrlicht

This is a solid 3D engine that has been around forever but truly became appetizing after it went with the zlib license.

My tests on the iPhone have been a bit underwhelming, check these screenshots to see the FPS.

A single md2 model.  Disabling frame interpolation gave 45 fps.

Sydney.md2 from irrlicht media. Disabling frame interpolation gave 45 fps.

Skinned dwarf from the irrlicht media.  Bout the same speed as the md2!

Skinned dwarf from the irrlicht media. Bout the same speed as the md2!

Slightly tweaked version of the Irrlicht geomipmapping terrain demo.

Slightly tweaked version of the Irrlicht geomipmapping terrain demo with coldet. REALLY slow to load.

Two skinned squirrels exported with the Panda (.x format) from 3dsmax.  Slow!  One gets about 30 fps.

Two skinned squirrels exported with the Panda (.x format) from 3dsmax. (Akiko made these for Teenage Lawnmower back in the day) Slow! One gets about 30 fps.

Conclusion

So.. yeah, slow.

Is anybody getting better speed than this?  Am I doing something wrong?

If I export say, a squirrel as a solid mesh (no animation) I get 60 fps, so I guess the real bottleneck is in the animation math, not the triangles/texturing.

I have to say though, I really like how Irrlicht is laid out – it’s a great way to steal <ahem, borrow> a ton of easy to plug-in functionality.  It can load nearly everything! (Except animated Collada..)

Random thoughts

I can think of some ways to speed this up, for instance, one way would be to write an irrlicht program that converts skinned mesh anims to a morph/frame based one, then optimize the renderer for the iPhone,  should be way faster than even the .md2 renderer.  (So, mem/filespace exchanged for rendering speed.. could even avoid frame interpolation if you output the anim with enough frames maybe)

On the 3GS you could probably do a skinned mesh shader and just fly, not sure.  But I don’t even have a 3GS yet!  Meh!

Could probably drop the geomipmapping for the terrain and just dynamically create the render list based on terrain sectors in the players view and do a fog thing to hide the edges and see a big performance improvement for iPhone.

I’m happy to announce a major feature was just added to Mind Wall for iPhone (iTunes) to satiate the appetite of the master Mind Wallers – Gauntlet DX!

It’s a special mode where the shapes grow and mutate as you play.

While Gauntlet mode is about lightning fast shape recognition of a limited set, Gauntlet DX mode requires an agile brain that can process totally new shapes on the fly.

What’s new in V1.2:

  • NEW FEATURE: Gauntlet DX Mode – Can you master a constantly evolving shape?  New audio and visual effects, includes its own world-rankings
  • Showing solutions is now configurable
  • Performance improvements on 3GS

Special thanks to the beta test team for giving it a nice work-out.

In a perfect world…

I don’t know about you, but these days when I buy a game online I want the following to be true:

  • Q/P > 10 GDU.  (where Q = quality, P = price, and GDU is Good Deal Units of course)
  • Can use Paypal and have my order instantly processed so I can download in seconds
  • Can install it on all my computers without copy protection hassles
  • Can come back after a hard drive crash and instantly get my games again without muss nor fuss

Entering the 21st century… harder, better, faster,  stronger.

After writing a metric butt ton of PHP code and recompiling miles of old code I’m proud to say… my own company now passes my own test! About damn time.

RTsoft now automatically handles Paypal orders.  I was really getting ripped off by my old payment provider (cough, cough Regnow sucks) and have been wanting to go Paypal forever. It’s now feasible sell things for a buck and still get to keep most of it.

I’ve released new versions of Dungeon Scroll, Teenage Lawnmower, and Toolfish that are completely DRM free.

  • No annoying unlock codes to enter
  • No online authentication
  • You can backup the installer .exe file and know that it will always ‘just work’

What about existing customers?

Now, having bought boatloads of our software in the past you’re probably thinking “Great!  But I have an old version, how do I get the new one?!

No problem!  Just enter your email address on our Shiny New Support Page and it will automatically locate what you’ve bought and send you links to download the latest versions.

The future and beyond

The new kitt-like high-tech data-driven site lets me add new products easily and change prices at the drop of a hat.  Like, I could do that Radiohead “pay what you want” thing for a week if I feel like it or charge $1000 on Fridays.  I wonder how that would go over.

Dungeon Scroll for Windows goes on sale for $1.99

For now, I’m going to test it out by offering the PC version of Dungeon Scroll for same price as the iPhone version for a limited time!  Yep, $1.99.   I mean, they have exactly the same features.  Times are changing, kids.

If you notice any glitches, bad links, or general weirdness in the new site please let me know.

-