<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Eric Butler]]></title>
  <link href="http://www.ericbutler.net/atom.xml" rel="self"/>
  <link href="http://www.ericbutler.net/"/>
  <updated>2012-02-21T01:41:36+00:00</updated>
  <id>http://www.ericbutler.net/</id>
  <author>
    <name><![CDATA[Eric Butler]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Refraction Wins an Award!]]></title>
    <link href="http://www.ericbutler.net/blog/2011/10/28/refraction-wins-an-award/"/>
    <updated>2011-10-28T09:28:00+00:00</updated>
    <id>http://www.ericbutler.net/blog/2011/10/28/refraction-wins-an-award</id>
    <content type="html"><![CDATA[<p><a href="http://games.cs.washington.edu/refraction/">Refraction</a> is one of the major games
of my research lab, the <a href="http://games.cs.washington.edu/">Center for Game Science</a> at the University of Washington.
It&#8217;s a game that aims to help elementary school students learn about fractions,
and answer interesting research questions about how this learning occurs.
I&#8217;ve done a lot of work on the project, and it&#8217;s the primary platform for my current research.</p>

<p>The game recently won an award: The Minister of Education, Culture, Sports, Science and Technology Prize for the Best Work in the Primary School Category in the 38th NHK Japan Prize, 2011.
It&#8217;s pretty awesome. A lot of people did a lot of work to make this game happen, so it&#8217;s exciting when something like this happens.
You can check it out and play it on <a href="http://games.cs.washington.edu/refraction/">our website</a>, or go play it on <a href="http://www.kongregate.com/games/GameScience/refraction/">Kongregate</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[WP7 Tombstoning and Serialization]]></title>
    <link href="http://www.ericbutler.net/blog/2011/04/28/wp7-tombstoning-and-serialization/"/>
    <updated>2011-04-28T00:59:12+00:00</updated>
    <id>http://www.ericbutler.net/blog/2011/04/28/wp7-tombstoning-and-serialization</id>
    <content type="html"><![CDATA[<p>The most difficult engineering challenge in <em>Fireflies</em> was dealing with
<a href="http://create.msdn.com/en-US/education/catalog/article/tombstoning_wp7_games">tombstoning</a>. For those unfamiliar, <em>tombstoning</em> is Microsoft&#8217;s term for
what happens when your app is interrupted. An interruption might be, for
example, the user receiving a call, locking the screen, or hitting the home
button. As of the game&#8217;s publication, the phone did not have multitasking
support. Therefore, during an interruption, the app gets a notification that
it&#8217;s being tombstoned, then its process is terminated. This means that every
well-behaved app needs to expect these interruptions and be prepared to save
its state so it can resume the new process were the old left off.</p>

<p>To accomplish this, the game needs to be completely serializable no matter
which state it&#8217;s in. This turns out to be quite a daunting task to do
correctly. Many games in the Marketplace just punt entirely and only remember
basic things like your current level. Receive a phone call at the end of the
boss fight? I guess you get to start over! Just beat your old high score and
accidentally bumped the ad? Sucks for you!</p>

<p>This is, of course, unacceptable behavior. We were pedantic about making sure
the game can handle any interruption at any time, and the exact game state
will be saved, down to the positions of the little fireflies in the jar. As a
first step, we need to decide how to serialize the game state.</p>

<p>Some people roll their own serialization, typically with a custom interface,
perhaps something like <code>IBinarySerializable</code>. When performance is an issue,
this might be the necessary option, but it comes with several drawbacks.
Mainly, you spending time trying to debug why your objects are full of garbage
since your forgot to read in an int somewhere and screwed up the stream. If I
wanted to deal with that kind of crap I&#8217;d be writing in C. Thus, we chose to
avoid this on the grounds that I&#8217;d rather be making a game than figuring out
the best way to serialize reference cycles in my object graph. The good people
on the .NET team figured out all this hard stuff already.</p>

<p>For a small, simple game, the built-in methods are perfectly fine. The two
main options are <code>XmlSerializer</code> and <code>DataContractSerializer</code>. The differences
didn&#8217;t really matter for our simple case, but we went with
<code>DataContractSerializer</code>, since which members are serialized are opt-in rather
than opt-out. We didn&#8217;t want to accidentally serialize a <code>RenderTarget2D</code> or
other ephemeral resource.</p>

<p>Not that the built-in serializer doesn&#8217;t have its own drawbacks. In order to
serialize private and read-only members, the serializer must use unsafe code.
Only you can&#8217;t use unsafe code on the phone. So no private or read-only
members, I guess. Well, good thing we already wrote the game code. At least I
won&#8217;t have to cringe looking at it.</p>

<p><img class="right" src="http://www.ericbutler.net/media/images/fireflies/question_firefly.png"></p>

<p>Of course it&#8217;s not enough to just write your entire program state to disk. An
important part in making serialization work smoothly is keeping the
<em>persistent</em> data (stuff you need to serialize) separate from the <em>ephemeral</em>
data (stuff you can re-create next time). For example, all of our assets such
as textures are loaded into one object, and no game state objects hold onto
any references to any assets. The asset-holding object is passed to every
update or render function that needs them. Now we don&#8217;t need to worry about
fixing up game state objects after deserializing them, since they don&#8217;t have
any references to ephemeral resources. This kind of separation is a good idea
anyway, but it&#8217;s absolutely crucial if you want to be able to quickly and
easily save the persistent data.</p>

<p>There&#8217;s also many special situations to consider. What happens if the user is
entering their name for a highscore in XNA&#8217;s built-in keyboard input control
when they hit the home button? Turns out the control returns the empty string
before the process exits, which left a blank name in the highscore list.
Therefore, the game has to check on startup if the name field for the most
recent score is empty and, if so, bring up the dialog again. What happens if
the game is tombstoned during first initialization? The game saves out an
uninitialized game state, then happily loads in said state next time and
crashes. So the game has to be careful to only save after initialization is
complete.</p>

<p>So, even with the built-in serialization, it still took over a week to get
saving and loading fully working. Solving corner cases took a lot of time, but
I&#8217;m really proud that our game handles them. Even when multitasking support
arrives, it&#8217;s still nice for the user to be able to back out of your app and
return later to find the app exactly as it was. So make sure to take care of
your users. They&#8217;ll be much happier for it.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Well that was fast. Fireflies internationalization fail.]]></title>
    <link href="http://www.ericbutler.net/blog/2011/04/12/well-that-was-fast-fireflies-internationalization-fail/"/>
    <updated>2011-04-12T16:18:29+00:00</updated>
    <id>http://www.ericbutler.net/blog/2011/04/12/well-that-was-fast-fireflies-internationalization-fail</id>
    <content type="html"><![CDATA[<p><a href="http://www.ericbutler.net/games/fireflies/">Fireflies</a> has been out for less than a day and we&#8217;ve already submitted an
updated version. Turns out the game crashed on international versions (or,
more specifically, versions with a non-English locale). And the title on the
phone was wrong, which had not been caught in testing but we caught after
submission.</p>

<p>I discovered the issue this morning by looking at comments from the European
WP7 Marketplaces. No one could get past the loading screen. The bug was caused
by my completely erroneous and ignorant assumption that the XNA SpriteFont
used to display an in-game timer would only need numerals, &#8216;:&#8217;, and &#8216;.&#8217;
characters. I had forgotten about the comma character used in many European
languages.</p>

<p>Lessons learned:</p>

<ul>
<li>Always uncheck &#8220;Automatically publish to marketplace after passing testing.&#8221; You will invariably find a bug in your submission, and the App Hub currently does not allow you to cancel submissions. Your bug will be sitting on the marketplace for all to see until you can get another version through verification.</li>
<li>Don&#8217;t make assumptions about strings and languages. I attempted to &#8220;optimize&#8221; my game by removing &#8220;unnecessary&#8221; characters from the SpriteFont used for numbers. So I traded a few KB of size in exchange for breaking all international versions on release, which may irrecoverably damage my game&#8217;s reputation in those markets.</li>
<li>With XNA, always use the SpriteFont&#8217;s default character feature just in case. That way, if you try to render a character not in the SpriteFont, it&#8217;ll display the default character rather than throwing an exception. I had the foresight to do this for the strings used in the highscore table, but not the ones used in the UI. There&#8217;s no reason not to set a default character for the final release version; that would have turned my crashing bug into a minor font-rendering bug.</li>
<li>Test your application with other locales, which is easily accomplished with the WP7 emulator. This hadn&#8217;t even crossed my mind. I thought, <em>These are unicode strings, I made sure to watch out for strings given by the user, nothing could possibly be wrong</em>. Silly me.</li>
</ul>


<p>Any one of these would have prevented the crash. Hopefully the updated version
will get through testing within the week, before all of Europe thinks I suck
at writing code.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Fireflies: My First Phone Game Released!]]></title>
    <link href="http://www.ericbutler.net/blog/2011/04/12/fireflies-my-first-phone-game-released/"/>
    <updated>2011-04-12T00:55:28+00:00</updated>
    <id>http://www.ericbutler.net/blog/2011/04/12/fireflies-my-first-phone-game-released</id>
    <content type="html"><![CDATA[<p><a href="http://www.ericbutler.net/games/fireflies/">Check it out!</a></p>

<p>Kristin and I just published our first phone game to the Windows Phone 7
Marketplace! I&#8217;ll let you read the description on the game&#8217;s page.</p>

<p>I&#8217;ll post some dev-diary-like posts when I have time in the upcoming week,
talking about my experiences with the development process. The game took about
a month of calendar time to make from conception to publication. We hope to
keep up the pace with another one!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Hello world!]]></title>
    <link href="http://www.ericbutler.net/blog/2011/04/09/hello-world/"/>
    <updated>2011-04-09T10:05:23+00:00</updated>
    <id>http://www.ericbutler.net/blog/2011/04/09/hello-world</id>
    <content type="html"><![CDATA[<p>Hello! I&#8217;m Eric Butler. Welcome to my site! This is where I&#8217;ll put information
about all the games I make, as well as posts about game development, games I
play, and parts of computer science that interest me.</p>

<p>In the meanwhile, you can <a href="http://www.ericbutler.net/games">check out all the games</a> I&#8217;ve made in the past
several years.</p>
]]></content>
  </entry>
  
</feed>

