{"id":464,"date":"2009-12-21T15:18:11","date_gmt":"2009-12-21T06:18:11","guid":{"rendered":"http:\/\/www.codedojo.com\/?p=464"},"modified":"2010-01-06T10:06:59","modified_gmt":"2010-01-06T01:06:59","slug":"development-diary-porting-dink-smallwood-to-iphone","status":"publish","type":"post","link":"https:\/\/www.codedojo.com\/?p=464","title":{"rendered":"Development Diary &#8211; Porting Dink Smallwood to iPhone"},"content":{"rendered":"<h2><strong>Can Dink be &#8220;done right&#8221; on iPhone?<\/strong><\/h2>\n<p>A few weeks ago I seriously looked into the possibility of putting our beloved RTsoft freeware RPG on the iPhone in style.<\/p>\n<p>I basically came to the same conclusion as previous times, it&#8217;s just Not Worth It.\u00a0 I might as well work on something new, I can&#8217;t use the GPL version with my gaming framework, etc.<\/p>\n<p>I mean, have you SEEN the original <a href=\"http:\/\/www.dinknetwork.com\/file\/dink_smallwood_1_08_source_code\/\">Dink source<\/a>?\u00a0 It&#8217;s hippopotamus butt.\u00a0 What was I thinking? \u00a0 I decided not to do it.<\/p>\n<p>But whatever. \u00a0 I had some free time while I was waiting on another project and figured I&#8217;d give it a test-run to see if I could solve the &#8220;millions of 8 bit textures on a GL device with power of 2 limitations&#8221; issue without any art retouching.<\/p>\n<p>Plus, there is something delicious about the challenge of refactoring 11 year old code.\u00a0 I can&#8217;t believe I just said that, but there it is.<\/p>\n<h2><strong>Step 1: Replacing DirectDraw<\/strong><\/h2>\n<div id=\"attachment_468\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_screwup.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-468\" class=\"size-medium wp-image-468\" title=\"dink_screwup\" src=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_screwup-300x234.jpg\" alt=\"dink_screwup\" width=\"300\" height=\"234\" srcset=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_screwup-300x234.jpg 300w, https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_screwup.jpg 646w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-468\" class=\"wp-caption-text\">Here is what happens when the background isn&#39;t blitted right.. Dink paint!<\/p><\/div>\n<p>First I wrote a skimpy software replacement for DirectDraw and dummied out the audio and text stuff.<\/p>\n<div id=\"attachment_467\" style=\"width: 330px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/texture_bug.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-467\" class=\"size-full wp-image-467\" title=\"texture_bug\" src=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/texture_bug.png\" alt=\"My DirectDraw software replacement had a bug... but it somehow made a cool sideways ANSI house pic!\" width=\"320\" height=\"480\" srcset=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/texture_bug.png 320w, https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/texture_bug-200x300.png 200w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><p id=\"caption-attachment-467\" class=\"wp-caption-text\">My DirectDraw software replacement had a bug... but it somehow made a cool sideways ANSI house pic!<\/p><\/div>\n<p>After it was working right,\u00a0 I put it on\u00a0 the iPhone and used glTexSubImage2D to put the final &#8220;fake&#8221; directdraw surface onto a GL texture every frame.<\/p>\n<div id=\"attachment_469\" style=\"width: 490px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_slow.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-469\" class=\"size-full wp-image-469 \" title=\"dink_slow\" src=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_slow.png\" alt=\"640X480 drawn to a 480X320 screen doesn't work that well.  Plus, slow as hell.\" width=\"480\" height=\"320\" srcset=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_slow.png 480w, https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_slow-300x200.png 300w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><p id=\"caption-attachment-469\" class=\"wp-caption-text\">It doesn&#39;t fit the screen and it&#39;s slow as hell.  But hey, it&#39;s running on an iPhone.<\/p><\/div>\n<p>Got 4 FPS.\u00a0 Not surprised.\u00a0 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.<\/p>\n<p>Just for fun I tried a technique where you draw a ton of GL_POINTS with color information instead.\u00a0 Slightly faster for the 640X480 I needed, but for smaller things it&#8217;s actually pretty zippy.\u00a0 I need to remember that if I ever want to do a low-res iPhone game where I need direct screen manipulation.<\/p>\n<h2><strong>Step 2: Mixing software and GL surfaces flexibly<\/strong><\/h2>\n<p>So, here comes the next logical step &#8211; let&#8217;s stop doing everything in software and get with the GL already.\u00a0 Fine.\u00a0 But Dink is a memory hog.\u00a0 Just for the background tile sheets it uses FORTY ONE 400X400 images.\u00a0 In GL terms, that means 512X512X4X41 bytes, or 41 MB just for some background tiles.\u00a0 (half that if we go with 16 bit surfaces)<\/p>\n<p>Considering we haven&#8217;t even got to the real sprites yet we can see this isn&#8217;t going to fly on the iPhone.<\/p>\n<p>Now, we could get funky and write a smart texture atlasing utility and such, but I think there is an easier way.\u00a0 Plus, I like the idea of using the original media formats, could help with DMOD support later.<\/p>\n<p>The solution?\u00a0 We&#8217;ll keep our fake software DirectDraw around but enable it to create and maintain &#8220;shadow GL&#8221; textures of themselves when actually blitting to the screen.\u00a0 We can give hints such as &#8220;don&#8217;t shadow GL any of the game tiles, just the final background that is built&#8221;.<\/p>\n<p>The result? Even after re-enabling text and audio through my Win\/iPhone framework I got 2400 FPS on Windows using OpenGL and &gt;50 FPS on the iPhone using GL ES.\u00a0 I&#8217;ve changed my mind, Dink is coming to iPhone!<\/p>\n<h2>\n<p><div id=\"attachment_470\" style=\"width: 490px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_killing.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-470\" class=\"size-full wp-image-470\" title=\"dink_killing\" src=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_killing.png\" alt=\"Real-time scaling to 480X320 looks pretty good.  FPS not bad either!  Temporary GUI, this will improve.\" width=\"480\" height=\"320\" srcset=\"https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_killing.png 480w, https:\/\/www.codedojo.com\/wp-content\/uploads\/2009\/12\/dink_killing-300x200.png 300w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><p id=\"caption-attachment-470\" class=\"wp-caption-text\">Real-time scaling to 480X320 looks pretty good.  FPS not bad either!  Temporary GUI, this will improve.<\/p><\/div><\/h2>\n<h2><strong><strong>Step 3: Get Justin on board<br \/>\n<\/strong><\/strong><\/h2>\n<p>Justin Martin, the original Dink artist has agreed to partner up and handle spiffing up the GUI &#8211; We&#8217;d both love to see an eloquent mobile version of Dink available.<\/p>\n<h2><strong>Step 4: The real work<\/strong><\/h2>\n<p>But to do this right, I still need to add some very important features.<\/p>\n<p>The challenging ones will be smooth and legal DMOD support on the iPhone and &#8220;save\/restore anywhere&#8221; functionality.<\/p>\n<p>I&#8217;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.<\/p>\n<p>Special thanks to Dan Walma (redink) and the Dink Network for letting me use the V1.08 version as a base to start from &#8211; it includes some improvements and bugfixes over 1.07.\u00a0 It&#8217;s still total ass though.\u00a0 (Not their fault, .. mine)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Can Dink be &#8220;done right&#8221; 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&#8217;s just Not Worth It.\u00a0 I might as well work on something new, I can&#8217;t use [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,12],"tags":[],"class_list":["post-464","post","type-post","status-publish","format-standard","hentry","category-development","category-dink"],"_links":{"self":[{"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/posts\/464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=464"}],"version-history":[{"count":11,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/posts\/464\/revisions"}],"predecessor-version":[{"id":513,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=\/wp\/v2\/posts\/464\/revisions\/513"}],"wp:attachment":[{"href":"https:\/\/www.codedojo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codedojo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}