Gaming, Hacking, Programming

Animating build progress on a Minecraft server

My Minecraft server is seeing some use again, and I decided to build a life size model of the Philadelphia Museum of Art. I also thought it would be cool to have an animated gif of the build progress as things go.

2014-10-15

Configuring Overviewer

We use Minecraft Overviewer to generate Google-maps style views of our world for the web. I created a config file limiting the render area to the coordinates around the building

worlds["Main"] = "/minecraft/Minecraft/world"

renders["normalrender"] = {
        "world": "Main",
        "title": "Overworld",
        "dimension": "overworld",
        "crop" : (200, -90, 420, 70),
}
outputdir="/minecraft/renders/museum"

Compositing the tiles
I found a script for making composites from google map data, originally written for use with Overviewer, but it was pretty far out of date and written for a different version of python than what I’ve got installed. I used it as a jumping off point for writing my own composite script.

#!/usr/bin/env python

import Image, ImageChops

import os, fnmatch
import os.path
import re

import sys

CHUNK_SIZE = 384

def trim(im):
    bg = Image.new(im.mode, im.size, im.getpixel((0,0)))
    diff = ImageChops.difference(im, bg)
    diff = ImageChops.add(diff, diff, 2.0, -100)
    bbox = diff.getbbox()
    if bbox:
        return im.crop(bbox)

def find_files(directory, pattern):
    regex = re.compile(pattern)
    for root, dirs, files in os.walk(directory):
        for basename in files:
            if regex.match(basename):
                filename = os.path.join(root, basename)
                yield filename

def getAllFiles(srcdir):
  return find_files(srcdir,  "[0-9]+.png")

def getCoordinates(f):
  return map(lambda x: int(x), re.findall(r'[0-9-]+', f))

def getX(c):
  return {
    0: 0,
    1: 1,
    2: 0,
    3: 1,
  }[c]

def getY(c):
  return {
    0:0,
    1:0,
    2:1,
    3:1,
  }[c]

if len(sys.argv) != 4:
  print "Usage:", sys.argv[0], "<source directory (Dir)> <output file> <zoom level>"
  sys.exit(1)

sourceDirectory = sys.argv[1]
zoomLevel = int(sys.argv[3])
outputName = sys.argv[2]

width = (2**zoomLevel)  * CHUNK_SIZE
height = (2**zoomLevel)  * CHUNK_SIZE
print "Width:", width, "Height:", height

output = Image.new("RGBA", (width, height))

for f in getAllFiles(sourceDirectory):
  coords = getCoordinates(f)
  if len(coords) == zoomLevel:
    chunk = Image.open(os.path.join(sourceDirectory, f))
    #print chunk
    xbin = ""
    ybin = ""
    for c in coords:
      xbin = xbin + str(getX(c))
      ybin = ybin + str(getY(c))
    y = int(ybin,2)
    x = int(xbin,2)
    output.paste(chunk, (x*CHUNK_SIZE, y*CHUNK_SIZE))

print "Map merged, saving..."

output = trim(output)

if outputName[-3:] == "jpg" or outputName[-4:] == "jpeg":
  output.save(outputName, quality=100)
else:
  try:
    output.save(outputName, quality=85, progressive=True, optimize=True)
  except:
    print "Error saving with progressive=True and optimize=True, trying normally..."
    output.save(outputName, quality=85)

print "Done!"

This generates a daily snapshot and puts it in a web-accessible folder. I can then make a gif of all the images in that folder with ImageMagick’s convert utility
convert -delay 80 -loop 0 *jpg animated.gif

Checking for modifications
Originally I ran the script once daily on a cron, but later decided to run the world generator every half hour and only generate an image if there’s something new to see.

#!/bin/bash

rendersecs=$(expr `date +%s` - `stat -c %Y /minecraft/renders/museum/normalrender/3/`)
snapsecs=$(expr `date +%s` - `stat -c %Y /minecraft/renders/museum/last-snapshot`)
if [ "$rendersecs" -lt "$snapsecs" ]; then
  echo "Render was modified $rendersecs secs ago. Last snapshot $snapsecs secondds ago. Updating snapshot."
  /minecraft/renders/merge.py /minecraft/renders/museum /var/www/html/museum/$(date +\%Y-\%m-\%d-\%H\%M).jpg 3
  touch -m /minecraft/renders/museum/last-snapshot
  convert -delay 40 -loop 0 /var/www/html/museum/*jpg /var/www/html/museum/animated.gif
fi

Setting up cron tasks
I put two new jobs in my crontab file: one to generate the terrain and one to run my shell script. I give Overviewer a bit of a head start in case it has a lot of work to do.

*/30 *  * * *  overviewer.py --conifg=/minecraft/overviewer-museum.conf
10,40 *  * * *  /minecraft/update-museum.sh
Gaming

Anniversary Mario Playthrough

9582_10101820976400499_1408507493_nRevolvingDork and I celebrated our two year anniversary, and kept up our quest to play each Super Mario Brothers sidescroller straight through, in order.

This year’s game was Super Mario Brothers 2 (SMB2), which came out for the NES in 1988. We played it on the Wii’s virtual console as we sadly don’t have the original cartridge.

Our rules are pretty simple: we hotseat lives / levels, and if we get a game over we’re allowed to warp back to the world we were on, but no warping past that.

This game is probably one of the most challenging. It is also one of the weirdest Mario games, because it wasn’t actually written as a mario game. It’s actually a reskin of the Japanese game Doki Doki Panic, as the Japanese Mario 21 was deemed too challenging for American audiences.

Aside from the somewhat punishing levels, SMB2 is challenging because 1-ups are few and far between. You get two continues before you are unceremoniously booted to the start screen, losing all your progress. Your only real chance to rack up some lives is to voraciously collect coins2 and then participate in the bonus round slot game at the end of the level. With some practice I was able to consistently get extra lives, but even then our maximum life count was a measly 25.

The other factor that made it a challenge was the layout of the warp zones. You can warp from world 1 to world 4, 3 to 5,  4 to 6, and 5 to 7. So when we died in the last stage of world 3 we had to start all over from the beginning. It took a while, and there was a lot of cursing.

We did finally vanquish the game – on our last life with only one heart remaining. If this was an XBOX game, I would have demanded an Achievement for that.

  1. Later released in the US as Super Mario: The Lost Levels []
  2. Coins are counted and displayed in hexadecimal. You can collect up to B coins per level, which is 11 in decimal []
Gaming

My PAX East packing list

We’re heading up to Boston for PAX East and every I manage to forget some Very Important Things so this year I am making a list. Maybe this year I won’t have to make any emergency trips to Best Buy on the way up!

There are a number of PAX packing lists, including an “official” one on the forums but they’re really just the same “so you’re going on a trip” list you find everywhere. And there are some very specific items I wouldn’t attend PAX without.

So here’s my list:

  • Clothes for 3 days. I have gone on enough trips I no longer feel the need to break this out.
  • Toiletries for 3 days. See above.
  • A swimsuit I will not actually use but bring every year “just in case.”
  • Exercise clothes. If I’m going to eat conference garbage for 3 days I ought to at least keep up with my workout routine.
  • Exercise shoes. The exercise clothes are less useful without them. Ask me how I know this.
  • A niceish outfit in case we want to go to a niceish restaurant. This really just means an outfit that does not include a nerdy t-shirt.
  • Shoes to go with that niceish outfit if it is a dress.
  • A Nintendo 3DS. Mario Kart and Tetris are the universal language of PAX.
  • A 3DS charger. Mercifully there are a bunch of these you can usually borrow from folks, but it’s a lot handier to have your own.
  • My cell phone.
  • My cell phone charger. This is the #1 item I purchase at out of town Best Buy stores.
  • My laptop (mostly just in case something comes up with work)
  • My laptop charger. This is the #2 item no prescription online pharmacy I purchase at Best Buy stores.
  • A deck of Magic: the Gathering cards. The little starter packs they give out always makes me long for my own deck, which incidentally I only ever play during the month after I attend PAX.
  • An empty tote bag, useful for anything you might buy or pick up on the expo floor. I hate walking around all day with a backpack, tote bags fold nice and small
Gaming, Software

Getting XBMC to work with our Xbox 360 Wireless Controller

This is part two of our home theater PC adventure. If you’ve just arrived you may want to start with part 1, Hello Xbox 360 Wireless Gaming Receiver.

Hooray, Windows can finally see the controller. We fire up the control panel tool for gaming devices and confirm that all buttons and axes work. We’re just about there! XBMC even helpfully includes keymappings for the xbox controller by default! We should be pretty much plug-and-play from here! I open up XBMC and…. nothing. The controller does nothing. I smash all the buttons, and still nothing.

The first step in debugging is to open up the log file and see what’s going on. The log file starts fresh every time you boot XBMC, and if you’re lucky you’ll see a line like this shoved in there:

19:00:17 T:2904 M:876916736 NOTICE: Enabled Joystick: Controller (XBOX 360 For Windows)

This means that XBMC can see the controller. It also tells us that it thinks the controller is named “Controller (XBOX 360 For Windows)” and depending on your OS and a few other seemingly random factors, it may be named something different.

This name is critically important, because it’s how XBMC knows which keymapping profile to pick up. When I went into the XBMC system/keymappings folder and looked at the existing 360 controller profiles, none of them was an exact name match. So I copied one of them and pasted it into the user keymappings folder.

The next step is to go into our copy and replace with or whatever your system thinks it’s called. That node pops up a bunch so you’ll probably want to use find+replace rather than manually copying and pasting all the time.

I’m not sure exactly what happened, at some point while I was messing around with all of this I managed to un-pair the controller from the PC without realizing it. After much cursing and whining, “why doesn’t it woooooork,” I realized what had happened and rebooted things.
Once I had renamed the joystick and it was actually communicating with the PC, I fired up XBMC and something magical happened: both the A and B buttons were functioning as Select and Back, respectively. Hooray! And the right analog stick was working as a volume control (though the axis was inverted). Not much else seemed to do anything, but IT WAS WORKING. Hooray!

The next task was getting the D-pad to work for navigating menus. Let me take this time to say that like most people who grew up with Nintendo controllers, the d-pad on the Xbox 360 controller is a source of scorn and hatred. But I wasn’t quite ready to tackle the analog stick, so the d-pad would have to do.

At this point I turned on debugging in XBMC and then proceeded to methodically press every button on the controller (and swivel each stick axis) exactly once. This worked great for the buttons but none of the axis data showed up in the debugger at all. Great. The keymap xml file I copied incorrectly identified the d-pad as “buttons” when it is in fact a “hat” according to Windows, so once I replaced the “button” nodes with “hat” nodes I was able to map the directions on the d-pad to Up/Down/Left/Right commands.

I should mention that I spent a lot of time googling about my problem, and mostly found forum threads where one person said “my xbox controller doesn’t work” and another person said “use xpadder,” or someone says “the d-pad doesn’t seem to work” and again the reply is “use xpadder.” After reading that response in about 20 threads, I was really starting to think the whole system was just too bugged to be viable. But in reality, people on the xbmc forums just aren’t willing to get their hands dirty.

Only in the process of writing up this post did I find someone who had actually taken the time to map out which buttons, hats, and axes where which. I wish I had found that post last night, it would have saved me about two hours.

I’m still deciding what the analog sticks should do, and trying to figure out how to get the controller to turn off when I’m done, but we got things to the point where it was good enough to navigate around to Dexter, and that was enough for one night. And I will say, navigating with the Xbox controller feels nice, much nicer than breaking out the clunky keyboard.

Gaming

Writing Reviews Isn't All Fun and Games

Actually, it is all games, but it’s not all fun. I’ve been playing and reviewing games for Sparkle Gamer for about a week and a half now. There are 5 full reviews up now, and I’ve even been lucky enough to have a publisher send me some promo copies of new games. If there’s one thing I’ve gained working on this project it’s a new respect for professional reviewers.

Being a professional video game reviewer sounds like a pretty great job, you get paid to play games and write about them. And I still think it’s a great job. But for every review copy you get of a game like Child of Eden, you get a Bratz: Forever Diamondz. I’m playing through Rabbids Travel in Time now, which is pretty good, but after the Petz Fantasy 3D review I needed a palate cleanser. If you play too many similar games they all start running together. If you play too many bad games, you start to feel your standards slipping. And suddenly you understand why so many horrible, horrible games have so many positive reviews on Amazon: because it can get so much worse.

I’ve been playing a lot more Starcraft II since I started order levitra Sparkle Gamer, as well as Box Life on the DS. Because all of the titles I’ve reviewed so far have been DS games, I’ve been able to play them while commuting to/from the office. I judge a title by how much slower or faster it makes my commute go.

You’re supposed to play each game all the way through, which I do when I can tolerate it. The worst thing about most of the girl game titles is that they’re incredibly repetitive; most of them have nothing new to offer after the first hour or so of playing. And I do mean nothing: many of them don’t even bother ratcheting up the difficulty level of the minigames.

So I have a new respect for people who do this for a living.  Sure, it beats a lot of other things, but it’s still hard work.

Gaming

Sparkle Gamer: Reviewing Games for Girls

I need another project like I need a hole in the head, but this one was just too ridiculous to pass up.

I’ve started a review site for games for girls. Specifically I mean games marketed towards girls.

It’s a little tough to explain why I’m doing this. It kills me a little that there even are “games for girls,” because I believe a good game is for everybody. You can get the full spiel at “Why Review Games for Girls”, but it came up in a conversation with Chris the other day that most of the games marketed to young girls aren’t reviewed by the major review sites, if anyone at all.

Parents who buy these games, most of which are junk, don’t really have anything to go on but the Amazon reviews. Unfortunately the Amazon reviews skew heavily towards “my daughter liked this because she loves [insert character here].” So for the discerning parent who’s concerned about the quality and content of the games their daughter plays, there aren’t a lot of resources.

Personally I’d love it if parents would drop the pink-is-for-girls thing and just buy games that were good, regardless of gender marketing. But some girls get the princess bug despite the protests of their parents.
I hope to arm parents with information so they can buy high quality games for their kids, navigating the murky world of games for girls and highlighting some gender neutral games which might appeal to even the biggest Disney princess fan.

Check out Sparkle Gamer, and if you’d like to review some games, let me know!

Gaming

City of Epic Promo Video

In an effort to better explain what City of Epic is, we’ve put together this informative commercial. You could even call it an infomercial!

Development continues behind the scenes. It’s been quiet on the blog because we’ve been hard at work! There’s not a ton to see on the site yet, but here’s a sneak peek at some of the artwork to tide you over.

That’s right, our game will have zombies.

Gaming

No Starcraft Until Midnight

As is often the case when one pre-orders games, I got my hands on Starcraft a little early.

Unfortunately, Blizzard would have none of it:

blizzard hate

On the plus side, at midnight when the game does go live, I’ll be playing Starcraft II instead of waiting in line at Gamestop.
Curiously, SCII comes with two “guest passes” for the game. Interested to find out the logistics of how those work.

Edit: or, I could just read the back of the card, duh. The “Guest Pass” is valid for 7 hours or 14 days, whichever comes first. This seems less useful than the “spawn” installations available with SCI, but since everyone I know has a copy of SCI, we never needed it anyway.

Gaming, Software

DSx86

Every now and then I come across something that I can’t believe someone has taken the time to write.

In this case, it’s a DOS emulator for the Nintendo DS, the DSx86.

As if there weren’t enough options for extending the DS (homebrew, NES emulation), one man has taken it upon himself to write a DOS emulator for the DS. It will run most games that run on a 286/386, with some caveats. Not all the opcodes have been written in yet, and sound blaster support requires a little bit of finesse. But it’s under active development, which is exciting.

You load a game the same way you did back in the day… from the command line. Since the DS doesn’t have a keyboard, DSx86 includes one for you on the touch screen. It’s hilariously adorable.

Once the game is loaded you can either continue to use the “keyboard” or swap screens so that your game is shown in the touchscreen and you can use the stylus as a mouse. Holding down left/right on the d-pad to click took a bit of getting used to. There’s also a tap-to-click mode, but I found it difficult to use for gaming. It was a good illustration of how programs not designed for a touchscreen can be infuriating to use on one. Because most DOS games run at a slightly larger resolution than the DS, you have the option of either panning or resizing the screen. I found panning to be the most useful, and all it really cut off was the title/menu bar at the top.

Seeing the old Sierra logo along with the MIDI-tastic intro music on the DS was ridiculous and awesome. I’m just about finished my 20th or so lifetime play through of The Island of Dr. Brain. If you’re dying to take some of your old DOS games with you (you did save them all, right?) , check the compatibility list and give DSx86 a try.