Showing posts with label software development. Show all posts
Showing posts with label software development. Show all posts

07 April 2016

Game Center With a Bad Network

I got a question about Game Center and network connectivity, and thought I’d share my thoughts publicly, since this was a major issue we had to deal with at Shenandoah Studio when we did multiplayer for Battle of the Bulge, Drive on Moscow, and Desert Fox.

Basically, the issue stems from loss of internet connection during a turn: at the end of a turn we save the state of the game board (locally, to PlayerPrefs), and use an End Turn method to communicate to Game Center that the turn is over.

If there’s no internet connection, the game state is saved but the end of turn message never gets sent (Android is awesome in the sense that end of turn messages are cached if the user has no internet connection, and sent when there is).

That is awesome, if it handles all network errors and not just lack of internet.

 So my question here is really, how do you gracefully handle a loss of internet connection? The only solution we have is to test for a connection prior to saving/ending the turn and present a pop-up advising the player to connect to the internet (otherwise, their turn is held in that state).

This one is enormously tricky with Game Center, because it has no guaranteed delivery.

First, I would not check for any specific error, because you can have anything at all go wrong during networking. (“No internet” might be worth a special test just because the player can deal with it by turning on WiFi or whatever, but it’s the least of your problems.)

Basically, you need to send the turn to Game Center and check for an error when your completion handler is called. If there’s failure, you need to do your own saving, and then send the update again later.

The problem is, you can get false negatives. Did you get a timeout because your network was so slow or noisy that the packet could not be delivered to Game Center? Or was the timeout because the “yes, turn received” acknowledgement from Game Center timed out? This is critical because the other player will have gotten the turn, and may have sent their own by the time you get to repost. So you also need some sort of logic to handle posting a stale turn.

To test your code, you’ll want to use the Network Link Conditioner (enable this in the Developer settings on the device). This lets you simulate a terrible network. Just be sure to disable it when you want to actually do anything (it’s all too easy to forget and wonder what’s wrong with your phone).

13 December 2010

Reviews: Debugging and Write Portable Code

Two books I bought recently were ones I expected to be easy going. They were, but I think they were still worthwhile.

Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems by David J Agans is about, well, debugging. Anything, not just software. It’s full of war stories from many domains (including cars, houses, and Sesame Street). The rules are how to logically approach problem solving, and make sure the problem is actually solved (rule 9). Most of it is common sense, but it doesn’t hurt to see it distilled. And based on the war stories, it’s easy to get wrong. Of potential use to non-developers: there’s a chapter on applying the 9 rules from the Help Desk, when you can't observe directly.

Interestingly, one of his war stories was kind of mentioned in...





Write Portable Code by Brian Hook. I’d had some dealings with Brian when I was at GameHouse, so I knew he knew his stuff. This book too was largely review (I’ve had to deal with getting code to run on different processors and compilers), but again it’s nice to have things spelled out sometimes. And I’d never heard of compile-time asserts or #pragma STDC before. Some of it’s a bit dated (version control in particular — and it must have been written right before the Mac Intel transition), but much of it is stuff you’d still have to deal with when moving between Mac and Windows — or even Mac and iOS. (Scalability is one aspect of portability.)

06 August 2010

Predecessor to DiceBook

I had a reason to open up my Newton, and realized that I had written a dice roller for that platform. No PDF viewing, but it provided simplicity and easy configuration. (I apologize for the poor photograph — I can’t remember how to take a screen capture from the device.)

I don’t remember if this was ever distributed — there certainly wasn’t an App Store in those days!

22 June 2010

Is the Future the Past?

One thing that struck me about John Siracusa’s interesting article on Apple’s language and API future: Apple did a high-level language once before. NewtonScript.

Whenever I see Python or Lua code, I think back to when I was coding in NewtonScript, which had a similar syntax and similar concepts. Here’s a bit of code from the original implementation of Jigami:


regTile := {_proto: pt_Tile, _parent: self, viewBounds: RelBounds(11, 112, 34, 34)};
regTile.edges := pt_Tile.possibleEdges[tileNum];
regTile:CalcEdges();
regTile.symbols := NIL;

There was also a visual design tool, Newton ToolKit (NTK). The combination of a dynamic language, no pointers, and a graphical editor was quite productive. And NewtonScript was good enough to use for all of the system apps. Yes, there was a little C++ code in parts, but a lot of it was probably premature optimization (there was nothing like Shark or Instruments for Newton).

I don’t know what direction Apple is moving, but at the very least it’s an interesting proof of concept for something that works well in a mobile device.

13 June 2010

WWDC Thoughts

Others have reported already, and everything except the keynote is covered by nondisclosure. But here are a few random thoughts on Apple’s Worldwide Developers Conference, held last week in San Francisco.

Apple made it very hard to plan — about 6 weeks notice. Luckily my employer, Rogue Amoeba, was waiting to pounce, because the event sold out in only 8 days.

I’ve been to the conference a number of times (I think my first was 1989), so I knew I’d be getting a t-shirt, and packed accordingly. Except this year they no longer handed out a t-shirt and a bag (sadly I didn’t go last year, when they handed out a slim laptop backpack). This year it was a lightweight jacket. This was actually pretty useful, given the temperature, but meant I had to get my own WWDC shirt so I didn’t stink on Friday.

Oddly, unwashed developer wasn’t something I noticed. I did however have to sit through a session next to someone with bad breath, someone smelling of alcohol (in a 09:00 session), and a smoker.

It was pretty obvious from the event list going in that it was going to be an iPhone-centric show. Apple doesn’t release all the event names until after the keynote, so I had some hopes that there would be a little more Macintosh content. Sadly, there wasn’t. On the other hand, I did manage to get to one session (the last one as it happened) that was directly helpful to my current work on Pulsar.

More surprising was the number of women. There are never a lot (you inevitably hear someone joking about the lines for the men’s toilet and the lack of line for the women’s), but this year seemed worse than I remember. Perhaps I was especially surprised because the very capable programmer I hired to do an iPhone game while at GameHouse was a woman.

Overall numbers seemed bigger than I recalled from 2 years ago as well. I remember lining up for the keynote, but I didn’t remember having to line up for other sessions — and some of these lines snaked around two corners.

I believe the conference cost significantly more this year ($1600), but the amenities seemed cut back. I already mentioned the reduction in attendee premium. There was also no reception, and no espresso bars inside Moscone. And the Beer Bash didn’t serve sushi.

We also got nothing at registration except the jacket and badge. Going paperless seemed reasonable though, because there was a custom application (apparently this was first available last year). It had some usability problems, and crashed relatively often. It was handy to have on both my iPhone and iPad despite that.

Speaking of iPad, this year I decided to try leaving my laptop home and using just an iPad (with Bluetooth keyboard) to take notes. This made it the first year I didn’t have to worry about keeping my battery charged (although several of the session rooms had electrical outlets attached to the seats, a great feature I made use of 2 years ago). I plan on discussing this more in a later post.

All in all, I found the week worthwhile, though I would have liked more on Macintosh.

14 February 2010

Coders at Work

I recently read Coders at Work by Peter Seibel. It’s a series of in-depth interviews with 15 noteworthy programmers, including Jamie Zawinski, Guy Steele, Ken Thompson, and Donald Knuth. Topics range from personal questions (“How did you begin programming?”) to occasionally esoteric discussion of computer science.

One thing I was continually struck by: that’s me! I don’t mean I’ve made a major impact on the world of computers, but so many of their attitudes and approaches were the same as mine. Perhaps that’s not surprising — a couple times it’s mentioned that perhaps 2% of the population are true programmers (who really understand and enjoy it), and I’m obviously in that group. And I’ve used some of the same computers (though one of them had a cutting-edge IBM 1620 in his high school, while our 1620 was obsolete and almost impossible to repair). But I don’t know what explains why we’re not fans of brainteaser interviews.

I’m not sure I use print statements to debug quite as often as most of them, though it is something I do often. I hadn’t realized how common it was!

Everyone (except Knuth) was asked whether they had read Knuth. I did read volumes 1 and 3 back in college, but haven’t referred to it more than once or twice since. That puts me about in the middle of the pack.

The book is marred by a few typos and formatting errors (e.g. an entire paragraph in bold), but is attractively set in Gill Sans.

I enjoyed it greatly. It was a nice mix of stories (such as what was going on at Netscape) and computer science (which as a practitioner I’ve gotten away from). Highly recommended to at least 2% of you.

03 January 2010

A Pun Generator

Back in the 1980s, my grandfather kept asking me when I was going to go for my PhD. I never did (and probably never will), but at the time I thought I might, and figured that my thesis would have something to do with puns. After all, lots of artificial intelligence research was involved with disambiguation. Why not turn that on its end, and revel in ambiguity!

It turns out that a team at the University of Aberdeen have created the Joking Computer. It basically creates puns: “Q: What kind of tree is nauseated? A: A sick-amore.”

So I’d probably need a new thesis…

29 November 2009

App Store Approval

The Jigami approval process went pretty smoothly. I submitted my final binary on Monday night, 16 November. The following Monday morning, 23 November, it was “In Review.” And on Wednesday afternoon, 25 November, it was “Ready for Sale.”

I didn’t want to release it right before Thanksgiving (and before I had my marketing ready), so I’d set the availability for 30 November. In parts of the world, it’s already on sale!

Obviously I’d prefer it if it didn’t take 8 business days to approve a board game, but Apple did live up to the “within 14 days,” and didn’t come up with a reason to reject it.

So for me, the approval process is not ideal, but is working.

16 November 2009

Jigami History

At long last, I wrapped up my first iPhone application, Jigami!

Looking at my notebook, the earliest record of it I can find is from 10 December 1991. I had apparently done a Mac prototype by February 1992, and continued to refine it (the next version I saved is from February 1993).

I took about 3 days to port it to NewtonScript in August 1993, and then Scott Shwarts and I polished it. As near as I can tell, we finished it in December 1993. Apple briefly published it as Jigsaw Strategy Game, but then decided they didn’t want to be in the game business, and we got the rights back and distributed it ourselves for a while.

The game was always intended for a handheld device, and in October 2008 I started an iPhone version. I got it working, but the UI wasn’t quite right. The original Newton version used a stylus, so you simply touched a piece and moved it directly. But doing the same thing with your finger meant you couldn’t see the piece you were moving. This is pretty important, since you need to see the shape and symbols. It took me a while to finally accept that the piece had to be moved out from under your finger. Suddenly the game became fun again.

I thought it would be cool to rotate with a gesture, and managed to get this working. But it nobody liked it, even though you could rotate by any amount (±270°). So I implemented a second tap. Everyone preferred this, even though rotating could now take up to 3 taps.

Autorotation was suggested by someone at the Casual Connect conference (sorry, I don’t remember who to credit).

The game was now better than the Newton version, but it still needed a lot more polish. I put in two more AI levels and a bunch of animation. Finally, I got Dalton Webb to do professional artwork. (You can see some of the art progress at the A Sharp Facebook page.)

The original game was available in English, French, German, and Japanese. Unfortunately, I couldn’t just use the original text, because minor things had changed. I didn’t get all of those in the first release, but Laurent Aillet gave me a French translation, and I hope to get more.

I actually submitted the game to the App Store last night, but one of my testers just sent me a crash log and I was able to figure out that it was not the crash I had fixed. Although it seemed to happen only on 2.2 devices (which are a definite minority), I thought it was worth getting right. So I rejected the binary, fixed the bug, and resubmitted it.

That puts me back at the end of the queue, but the silver lining is that I was able to submit French keywords (I had forgotten to get them localized). This is one piece of metadata that Apple doesn’t let you change at will.

Hopefully I’ll have the end of the story in a few days: release. Well, really it will be a new beginning, since I have a number of updates planned…

15 October 2009

Open Project in Xcode

One really nice feature (not sure if it’s new in 3.2 or if I hadn’t noticed it before) is how you can look at sample code.

API documentation has a link to sample code that uses the call. Click that link, and from the sample code page, click “Open Project in Xcode.” The project is downloaded and, well, opens in Xcode. Very nice integration.

14 October 2009

Update to Opal

As I mentioned, I am using the new clang compiler and LLVM back end in the latest update (version 1.2.5) to my Opal outliner. I couldn’t really detect any differences in performance, but I’ll take the faster compiles!

The clang code analyzer did find a number of minor memory leaks, mostly in things that are less common, like printing or using the bookmark popup. So this release is cleaner than ever.

14 September 2009

NSUserDefaults Is Picky

If you’re not programming Mac or iPhone, you might want to skip this post…

I’m saving some state in an array, to be saved via NSUserDefaults. I know that NSArray can’t contain a nil value, but you can instead use [NSNull null]. BUT, property lists save only a limited number of classes, and NSNull is not one of them.

The confusing thing was that NSUserDefaults silently rejected an entire NSDictionary containing an NSArray containing an NSNull, while saving all the other changes I was making. So my testing showed that saving and restoring worked. And worked. And worked. Until the one case where there happened to be a nil. And then loading used the previous state.

So I had to come up with another way to save and restore a C array that can contain a nil. (In this case I was able to use a string.)

08 September 2009

The Real Difference Between Mac and Windows Programmers

It’s obviously the color of their tools. Leon Bambrick points out that Windows tools are orange. But mine are blue. (OK, you could argue Interface Builder has a little orange. At least there’s an X in Xcode, which I constantly have open…)

(Thanks to Raymond Chen for the link.)

07 September 2009

Clang Is Fast

As I’ve written, the developer tools in Snow Leopard are a great reason to upgrade.

Snow Leopard includes a new compiler, clang. Much of my work involves C++, which clang can’t handle. Which is a bummer, as the static analysis is so useful. But Opal is an Objective-C application, so I tried switching from GCC 4.2. I had to tweak a few things (clang doesn’t like the GCC -Wunreachable-code option), but mostly it gave a few different warnings.

And it’s about twice as fast. On my MacBook Air 2.13 GHz, it took GCC about 58 seconds to build Opal (with its plugins). Clang took about 32 seconds. (This isn’t all compile time — it also includes copying files into the bundle.) I built twice each time in case caching made a difference.

Opal isn’t very compute-bound, so I didn’t notice any speed differences from using the LLVM backend. As for code size, the bundle is 4,463,702 bytes, compared to 4,328,838 from GCC 4.2 and 4,349,342 from GCC 4.0. In many cases, bigger code runs slower, but Apple claims that LLVM generates better code. They pay a lot of attention to performance, so I’m going to believe them on this.

So I’m planning on using clang for the next Opal update.

05 September 2009

Snow Leopard Notes

I’ve been using Snow Leopard (Mac OS X 10.6) since official release. See John Siracusa for a very thorough and technical review. I just want to post a few random notes.

I forgot to be scientific about measuring the disk space savings, but I think I got 5 GB back (and I had never installed all the printer drivers). That’s a pretty valuable upgrade right there!

While people have noted it’s a plus that you can now show the date in the menu bar, in fact you don’t get to choose the date format, so it’s not very useful.

It’s pretty cool that Cisco VPN is now built in — the client from Cisco was pretty unreliable. Unfortunately, we use a shared secret that’s only distributed via a .pcf file, in encrypted form. Luckily, there’s a security hole and it’s possible to retrieve the plaintext password. Armed with this, I can use the Snow Leopard client.

I haven’t seen mention of a change in Time Machine: if you back up to a Time Capsule, you’re no longer saving to the top level of the volume but rather using your own account. (The screen shot shows the new approach above the old.) This should make things a little more secure, but it also means your old backup is ignored, and things start from scratch. (I couldn’t really verify Apple’s claims that the initial backup is a lot faster — it still seemed awfully slow over USB Ethernet.) On the other hand, I had to restart the initial backup since I didn’t have enough space for an entire new backup. Once I freed up space, the initial scan was pretty much instant.

So far, most of my software has been compatible (including those I wrote: Addressix and Opal). I was using an older version of Parallels Desktop, which for some reason was not moved to an “Incompatible” folder but won’t launch (with a message that it’s incompatible). I think I’ll be switching to VMWare Fusion.

While there are some features that I appreciate (minimizing windows to the application icon instead of cluttering the Dock), for the most part it’s the same Mac, slightly improved.

Except as a development machine. The new version of Xcode offers some significant improvements for developers, ranging from better Subversion support to new compilers. I’m still in the process of using clang and the updated Instruments to track down subtle issues.

At the same time, one of the most annoying bugs is in the new developer tools: we can no longer use distcc to compile on 8 different machines simultaneously. Apple is aware of the problem.

As a user, it’s not a whizzy update, but I think still worth it. As a developer, I’m really happy to be using the new tools. I’m also hoping that this becomes the new baseline — it would be great to develop for 10.6+ rather than 10.4+.

17 August 2009

Dogfooding

Raymond Chen often writes about Microspeak — jargon that shows up at Microsoft.

I hadn’t realized that “dogfooding” was now a verb (though Wikipedia concurs), but the usage in the Office 2010 Engineering blog just seems wrong. “For those of you who are dogfooding the Technical Preview build, thanks for all of the great feedback you’ve sent us.” But, the phrase is actually “Eating one's own dog food!” It does not mean beta testing! The author of the blog may be dogfooding, but those in the blog’s audience presumably do not work in the Office 2010 group. I imagine they are actually users of the Technical Preview. They are not eating their own dogfood. They are eating the blog author’s dogfood. This may or may not need a colorful term, but it would need to be a different term.

When I use Opal, I am eating my own dogfood (because I’m the developer). But the people who help me test prerelease versions are not.

06 July 2009

The Intention-Behavior Gap

I remember telling my friend Al Tommervik I had a great idea for a game, and him replying that he didn’t want to hear it, otherwise I’d be less likely to complete it. (This was a long time ago, but I’m pretty sure the game was one I did end up completing perhaps 10 years later: King of Dragon Pass.)

I’ve always appreciated that advice, and it’s one reason I don’t talk a whole lot about software I have in development. I just learned that there’s research that shows that people who don’t announce their goals are more likely to achieve them. According to an abstract of four recent studies, “intentions that had been noticed by other people were translated into action less intensively than those that had been ignored.”

So unless something is imminent, I won’t be mentioning it here, as fun as it might be.

01 July 2009

iPhone App Store

Digging through some old notes, I found this link:

According to Anita Hamilton in Time, Apple’s upcoming App Store will be “anything but a bargain.”

She wrote that in July 2008, and since then the App Store has obviously turned out to be an amazing bargain. Seems like almost all apps are $0.99 or free, which is kind of a shame (since I’d like to sell apps). I’m still hoping Apple figures out a way that premium games can sell for a premium price. Right now there’s no differentiation in the App Store. I do see a few of the top 100 paid apps at $4.99 or higher, but most of those are associated with an existing brand (Sims 3, Tiger Woods, Tetris). Games that sell for $19.99 on Windows or Mac are just $0.99 on iPhone (Sally’s Salon).

As others have written, it’s because the easiest way to market on the App Store is to price yourself less than others. I’m not a marketer, but it seems like this is exactly the opposite of the way Apple operates. They sell better than average products for a price that reflects their value.

28 June 2009

Xcode comments

I knew that if you specified certain strings in comments, Xcode would put an entry in the function popup. But I just discovered there were some I didn't know about. Here’s the ones I now know of:

// TODO:


// FIXME:


// ???:


// !!!:

// MARK:



30 January 2009

Mac Box Set & Leopard

Just got my Mac Box Set (Mac OS X, iLife and iWork). At $149 (Amazon price as of 30 Jan), it’s the same price as iLife and iWork bought separately. I wanted both of those.

As it happened, I used the Mac OS X DVD to update a machine to 10.5.6, and tried to use that computer as part of my compile farm (using Xcode’s Distributed Build feature). It showed up as incompatible with the others. Apparently Mac Box Set includes 9G66, while the combo update installs 9G55. I didn’t realize Apple was distributing multiple builds of 10.5.6. Normally no one would really care, but distributed builds need perfect configuration matches.

So I probably won’t be able to use this machine in my compile farm until the next Mac OS X update.