Sunday, January 11, 2015

Reverse engineering my own game

I've long-since misplaced the source code to my Atari 800 game Dandy Dungeon. But thanks to the Atari800MacX emulator and the emulation scene, I've been able to play an emulated version of my original game. That's been helpful for remembering all the little details of gameplay.




For example, I was able to determine that the original game animated the arrows at 15 Hz and the players and monsters at 7.5 Hz.

FWIW I think the emulator may be slightly incorrect about the HBLANK processing emulation. I'm pretty sure that the color background for the 4th line of text should be a different color from the color background of the 3rd line of text.

The iOS version of the game is progressing -- the dual thumbstick virtual controls work well.

The next step (and it's a big one) is going to be multiplayer support. GameKit here I come.

Sunday, January 4, 2015

Fun with shaders

There are a total of 3 draw calls and 2 textures in this scene:


The whole tile map is rendered as a single draw call: a single 2-triangle tile that's instanced Row x Column times, using a 3D texture as a texture atlas. I originally used point sprites, but switched to instanced triangles because I wanted to use non-square tiles.

The virtual joystick is rendered as two coarse triangle strip rings, using a 1D radial texture. Note the anti aliasing. (I could have used quads, but wanted to minimize overdraw.)

So far Metal has been fairly straightforward to use, at least for someone like me coming from a DirectX 9 / Xbox 360 / Android OpenGL ES 2.0 background.

Friday, January 2, 2015

3*(N+1) Devices for N People

At my house we are trending towards having N+1 laptops for N people, because (a) I need to keep my work laptop separate from my home laptop, and (b) frequently everyone in the family wants to use their laptops at the same time.

The same goes for tablets, and when the kids are old enough to have phones I expect it will be the same for phones.

I tried using multi-user accounts on shared family tablets and laptops, but ended up assigning each kid their own devices. It was simpler from an account management point of view, and the kids like personalizing their devices with stickers and cases.

Having assigned devices also makes it easier to give different Internet and gaming privileges to different kids, depending on age and maturity.

A downside of assigned devices is that not all the devices have the same features. People complain about hand-me-down devices, as well as the perverse incentive created when an accidentally broken device is replaced by a brand new, better device.


Letting go of the Web and Embracing Mobile

When I started working on Android in 2007, I had never owned a mobile phone. When Andy Rubin heard this, he looked at me, grinned, and said "man, you're on the wrong project!"

But actually, being late to mobile worked out well. In the early days of Android the daily build was rough. Our Sooner and G1 prototypes often wouldn't work reliably as phones, and that drove the other Android developers crazy. But since I was not yet relying on a mobile phone, it didn't bother me much.

Seven years later, mobile's eaten the world. But I still haven't internalized what that means. I think I'm still too personal-computer-centric in my thinking and my planning.

Here's some recent changes that I'm still trying to come to grips with:

  • Android and iOS are the important client operating systems. The web is now a legacy system.
  • Containerized Linux is the important server operating system. Everything else is legacy.
  • OS X is the important programmer's desktop OS (because it's required for iOS development, and adequate for Android and containerized Linux development.)
  • The phone is the most important form factor, with tablet in second place.
  • Media has moved from local storage to streaming.
  • Programming cultural discussion has moved from blogs & mailing lists to Hacker News, Reddit & Twitter. (To be fair, these new forums mostly link back to blog posts for the actual content.)

In reaction, I've stopped working on the following projects:

  • Terminal Emulator for Android. When I started this project, all Android devices had hardware keyboards. But those days are long gone. And unfortunately for most people there isn't a compelling use case for an on-the-device terminal emulator. The compelling command-line use cases for mobile are SSH-ing from the mobile device to another machine, and adb-ing into the Android device from a desktop.
  • BitTorrent clients. My clients were written just for fun, to learn how to use the Golang and node.js networking libraries. With the fun/learning task accomplished, and with BitTorrent usage in decline, there isn't much point in working on these clients. (Plus I didn't like dealing with bug reports related to sketchy torrent sites.)
  • New languages. For the platforms I'm interested in, the practical languages are C/C++, Java, Objective C, and Swift. (And Golang for server-side work.)
    • I spent much of the past seven years experimenting with dynamic languages, but a year of using Python and JavaScript in production was discouraging. The brevity was great, but the loss of control was not.
Personal Projects for 2015

First, I'm going to port my ancient game Dandy to mobile. It needs a lot of work to "work" on mobile, but it's a simple enough game that the port should be possible to do on a hobby time budget. I'm probably going to go closed-source on this project, but I may blog the progress, because the process of writing down my thoughts should be helpful.

After that, we'll see how it goes!

Game Programming Patterns Book

I've been reading Game Programming Patterns by Bob Nystrom.

It's available to read online for free, as well as for purchase in a variety of formats.

A good book for people who are writing a video game engine. I found myself agreeing with pretty much everything in this book.

Note - this book is about internal software design. It's not about game design, or graphics, physics, audio, input, monetization strategies, etc. So you won't be able to write a hit video game after reading this book. But if you happen to be writing an engine for a video game, this book will help you write a better one.

Edit -- and I've finished reading it. It was a quick read, but a good one. I consider myself an intermediate level game developer. I've written a few simple games and I've worked on several other games. (For example, I've ported Quake to many different computers over the years.)

For me the most educational chapters were Game Loop and Component, although Bytecode and Data Locality were also quite interesting.

I like that the chapters have links to relevant external documents for further research.

I felt smarter after reading this book.

What I was up to 2012-2014

It's been a while since my last post -- I've been posting inside the Google internal ecosystem, but haven't posted much publicly.

What have I been up to in the past 3 years?

Work

Prototyped a Dart runtime for Android. Amusingly enough, this involved almost no Dart code. It was 90% Python coding (wrangling Gyp build system scripts) and 10% C++ coding (calling the Dart VM).

Extended the Audio players for Google Play Music's Web client. I learned ActionScript, the Closure dialect of JavaScript, and HTML5 Audio APIs (Web Audio and EME.)

Started working on the Google Play Music iOS client.  I learned Objective C, Swift, iOS and Sqlite.

Personal Projects

Prototyped a Go language runtime for Android. Unpublished, but luckily the Go team is picking up the slack.

Finished working on Terminal Emulator for Android. I'm keeping it on life support, but no new features.

Personal Life

Started exercising again after a 10 year hiatus. It's good to get back into shape.

Switched to a low cholesterol diet. Google's cafes make this pretty easy to do.

Watched my kids grow!

Sunday, October 16, 2011

I translated Alexander Boswell's toy REYES renderer from C++ to Google's new Dart programming language.

Here's what the output looks like:



Try It Yourself

If your browser supports the canvas tag and JavaScript, you can see the sphere being rendered here:

Render a REYES bumpy sphere in your browser.

And the source is here: http://code.google.com/p/reyes-dart/

Translating C++ to Dart

It was pretty easy to translate the original code from C++ to Dart.
  • The original code made use of classes and overloaded operators, both of which are also in the Dart language.
  • The original code used the SDL library to display output. It was easy to switch to the HTML5 CANVAS tag.

I used an early version of the "Dart Editor" IDE. The Dart Editor IDE was helpful because of the compiler warnings and errors.

Debugging

I used a variety of techniques to debug the code:
  • print() Dart has a built-in print function that logs to the JavaScript console. This was good for logging small amounts of data.
  • write() This is a utility function I wrote that appended the argument text to the document body of my HTML document. This has several advantages over "print":
    • Easier to see output during development.
    • Much easier to search and copy/paste large amounts of text.
  • Dumping 3D geometry as text. At one point I wanted to check whether or not my geometry was correct. The easiest way to check it was to dump the geometry out as a 3D text file using "write()", and then copy-and-paste that code into a file and view it in the blender3d.org Blender app.
  • Using Chrome to step through the compiled app.js code. This was pretty painful, but was occasionally useful. The stack crawls for exceptions usually gave good hits as to what was going wrong.
Dart Limitations
  • The Dart "dom" library is not yet complete. Currently it can't write to canvas imageData. As a work-around I draw each pixel of output as a little filled rectangle.
Dart Editor Limitations

I wish the Dart Editor would support:
  • Formatting code.
  • Stripping whitespace from ends of lines on save.
  • Converting tabs to spaces on save.