Game Performance: It’s the Hardware’s Fault
August 7, 2015
The outstanding To Do list for Sleuthhounds: The Cursed Cannon is shrinking daily. There’s light at the end of the tunnel but the game’s not quite there yet. With most of the key pieces put into place I’ve recently turned my attention to improving the performance of the game. However, before I could tackle the hard work of improving the software I first needed to make sure the hardware was in order.
One of the reasons I went with a traditional point-n-click adventure style for the Sleuthhounds games was so they would work well on these new-fangled tablets that people are sporting lately. After all, on a tablet you’re tapping different parts of the screen to interact with it and that’s a natural fit for a point-n-click interface.
For the most part I’ve been developing The Cursed Cannon on my nice, beefy desktop computer. It’s got horsepower to spare and so has never had a problem running the game. That’s great for general development but not so good for testing the actual performance of the game.
In addition to the desktop, I also have a tablet to test on. I got it a couple of years back a few months before Microsoft released their first wave of tablets. Mine’s an MSI WindPad 110W-050CA running Windows 7 (I took a look at Windows 8 and wasn’t too impressed and I’m waiting on the reviews for Windows 10).
In the time since I first got my tablet it’s amassed a fair number of Windows Updates. Enough so that the tablet started running out of space on its supplied 32 GB hard drive. Increasingly, this was causing problems with running the tablet in general.
When I came to test my game it was with the tablet in an already ailing state. I encountered three significant areas of concern with game:
- Load times in the game were terrible. Switching between rooms could take up to as much as ten seconds.
- Framerate was highly erratic. One of the rooms in the game is quite large, scrolls both horizontally and vertically, and has multiple characters and other sprites drawn in it. The framerate of this room varied from a slow 10 frames per second down to an abysmal 2 frames per second slideshow. The weird thing was that the speed would randomly change while within the room and while drawing all the same assets.
- The unresponsive square problem. Randomly while playing, the game would stop updating the display properly. No errors were generated, the game was seemingly still running, but it just wasn’t rendering the graphics correctly anymore. When the game got into this state, clicking on a part of the screen would update a small square around the mouse pointer to have the correct image. After about 15 to 20 seconds the game would start working properly again and refresh the screen. This was a weird one as I couldn’t think of anything in the game code that would cause this kind of problem.
In many respects, while the game ran well and worked properly on my desktop, on my tablet it was basically broken. Not so good considering my initial goal of having a game that would work on tablets.
The problem I had was that I wasn’t sure if the issues were from my game code or from the general instabilities that the tablet had become plagued with. In order to remove one variable from my analysis I decided to replace the tablet’s hard drive to see if that would fix anything at all.
I’d never “operated” on a tablet before, so that was a bit of a new experience. Here’s what I went through to change out the 32 GB drive for a 250 GB drive. It’s nice to have a record of these steps in case I need to do something like this again in the future. Fair warning, what follows is littered with TLAs (three letter acronyms) and does get a little technical in some places.
The first step was solving the problem of moving all the data from the original drive to the new one. I wasn’t keen on having to reinstall the OS and all the software I already had on the tablet so I was looking for a way to simply migrate the existing data from one drive to another. On a desktop computer this would have been easy. Plug in both drives at the same time and do a physical copy from one to the other. However, my tablet can only have one drive connected at a time. I could have bought an adapter that would allow me to plug a second drive into the USB port of the tablet, but that seemed like an expensive solution for something that I was only going to do once.
Fortunately, the tablet has an SD memory card reader and I had a 32 GB memory card. The easy solution then seemed to be to copy everything from the original drive to the SD card, replace the original drive with the new one, and copy everything back.
To do that there were two things that I needed:
- First, I needed a utility for doing a physical copy of one drive to another. A simple file copy is no good as that misses critical “hidden” data used for booting the computer, among other things.
- Second, once I removed the old drive, but before the new drive had the data copied to it, I needed a way to boot the computer so I could run the utility again to do the final copy.
After investigating a few options, I settled on making a regular 2 GB USB flash drive bootable with Ubuntu Linux. In addition to fitting on a smaller flash drive (Windows, I believe needs a 4 GB drive to install on) Ubuntu came with a couple of tools that would be perfect for copying the data. I downloaded the latest Ubuntu ISO and used Pen Drive Linux’s free application for properly copying the ISO to the USB drive so that I could boot my tablet with it.
At that point I started up the tablet and booted into Linux without problem. First hurdle crossed.
The next step was to make an exact clone of my original drive onto the SD card. Both drives were, in theory, 32 GB drives so I figured there would be no problem. Note that I said in theory.
It turns out that SD cards, which are typically used in digital cameras, essentially use a different numbering system from that used for hard drives for computers (I won’t bore you with the details but it gets into the differences in the base 10 numbering system that people are used to counting or their fingers and a base 2 numbering system that binary computers like to use). The result was that although the SD card said 32 GB on its label, the actual space, in computer terms, on the card was only about 30 GB.
Fortunately, I had about 3 GB free space left on the original hard drive. Using the Ubuntu tool GParted I was able to shrink the data partition on the original drive by about 2.5 GB so that it basically looked like a 29.5 GB drive instead of a 32 GB drive. Since the space was unused there was no risk of losing data when I shrunk the partition.
With the original drive reworked so it could fit on the SD card I then fired up Ubuntu’s Terminal “application” (basically a command-line window). First, I needed to identify the names of the original drive and the SD card. I did that with the following command:
sudo fdisk -l
That’s an “L” as in eLephant. That command identified the original drive’s name as “/dev/sda” and the SD card’s name as “/dev/mmcblk0”.
Next I kicked off the actual physical copy itself using the following command:
sudo dd if=/dev/sda of=/dev/mmcblk0
dd is used to do a copy of all the bytes of one drive/partition to another. The “if” identifies the source drive to copy from and the “of” identifies the destination drive to copy to. If you use this tool be absolutely sure to get these right. If you get them backwards then dd will be quite happy to copy the empty drive over the non-empty one and you’ll lose all your data. Just be cautious, is all I’m saying.
The dd command doesn’t report any progress so at this point I walked away from the tablet while it copied its 29.5 GB of data across. I’m not sure how long the copy took exactly, but it was at least three hours.
Once I had the data copied, I was ready to get into the fun work. Opening up the tablet and replacing the drive.
Opening the WindPad was fairly straightforward. On the bottom of the tablet are four small rubber feet that are held in place by friction. They pry out quite easily with a small kitchen knife. Possibly they could even be popped out with just a fingernail.
Beneath each foot is a small Number 1 Phillips screw. When I got the tablet open I found that the screws are backed by a thin foil paper meant to keep them from falling out accidentally. When I unscrewed the screws two of them came all the way out by themselves and the other two got caught on the foil. The two stuck ones didn’t matter as the screws were unscrewed enough to allow the tablet to open.
In addition to the four screws under the feet, there were two small screws set around the port for the tablet’s power connector. I unscrewed those as well.
With all the screws removed it was time to pop open the tablet. At either end of the lower edge of the tablet were small slots about an inch long. It was easy to slip the kitchen knife into one of the slots and start prying the tablet open. I followed the seam of the tablet clockwise around the case.
Small plastic tabs inside the case help to keep the back cover on. While I held the case open with my fingers I used the kitchen knife to press down on these tabs to disengage them from the back of the case. The back piece came off easily. The only thing I had to be careful about was the power button and the switch for locking the rotation of the screen. These two plastic pieces are secured to the case in any way. They stay in place while the case is closed but fall out quite easily when it’s open.
I finally had my chance to see the guts of the tablet. About a third of it was taken up by the battery, which was set in place to one side. Apart from that, other key components were easily in evidence including the hard drive, the DRAM card, the blue tooth receiver, and the GPS unit.
The hard drive was secured in place by the slot it plugged into and a single Phillips screw. With the screw removed the drive popped up a bit by itself making it easy to pull out. The hard drive was tucked inside a small foil wrapper, probably either to help with heat dissipation or cutting down signal noise from so many electrical components pressed so close together.
I removed the wrapper from the original drive and folded it about the new drive. The new drive slipped easily into place and the screw secured it down again.
Getting the cover back onto the tablet was a little tricky. What ultimately worked for me was to start at the upper edge of the tablet and hinge the cover down along both sides at the same time and finally having it click into place along the bottom. I then went around the whole edge of the tablet and pressed gently down to get all of those plastic tabs to click and reengage.
I did hit one snag putting the tablet back together. The power button had tumbled out when I first opened the tablet. I didn’t notice that two of the corners on the button were rounded and two were square until after I had screwed the tablet shut again. And of course – Murphy’s Law – I got the button in the wrong way.
Fortunately, because the button was upside down the case hadn’t quite closed properly around it. I was able to pry it open just enough to get the button out and turn it over. With it set the correct way the case nicely popped closed so you couldn’t tell it was ever open.
That just left putting the feet back in. I found that pushing the feet straight down into their holes didn’t really work. They bulged and worked their way back out doing that. What did work was to angle the feet so that they were pointed slightly towards their respective corners and to push them in that way. Somehow that caused them to pop down and fit snugly back into place.
With the tablet all sealed up, I fired up Ubuntu once more. Another quick check with the fdisk Terminal command showed the new drive was now called “/dev/sda”. At this point I used dd again but reversed the names, like so:
sudo dd if=/dev/mmcblk0 of=/dev/sda
Again I left the tablet while it did its copy. When it had finished, I ran Gparted to check the partitions of the new drive. Everything had copied properly and so I was left with 29.5 GB set up on the new 250 GB drive. I then used Gparted to extend the data partition out to fill the remaining size of the new drive.
It was finally, finally the moment of truth. I shut down the tablet and pulled out the Linux boot flash drive. I then restarted the tablet and watched and waited. Windows started up and decided to run a disk check, presumably because it noticed that the hard drive was now 250 GB instead of 32 GB. The check ran without problems, Windows rebooted the computer, and then everything started normally. Yay!
With hard drive space no longer a concern, I started The Cursed Cannon. You’ll recall that I had run into three performance problems with the game. Well, the results were encouraging:
- Load times. The load times were still pretty poor, which I had been expecting as that “felt” like it was probably a problem with my code, but they weren’t as bad as previously. That ten second load time went to about six seconds. Still not great, but better.
- Highly erratic framerate. The framerate for the game stabilized. The worst case room levelled out at about 12 seconds, instead of varying between 2 and 10. The slow rate is still not great, but I’m glad the randomness no longer seems to be present.
- The square problem. I’ve been playing the game on the tablet a fair bit since the hard drivectomy and I’ve yet to experience the square problem again. This was the biggest win as this was the only problem that I had no clue as to what could be causing issues.
Whew! That was a long post. After all that work the result is that the performance of the game on the tablet still needs some significant improvements. However, both the tablet and the game run rock steady now instead of having this weird variableness that was present before. By fixing up the hardware issues it will now be much easier to identify and correct the software issues. But I’ll go into that in more detail in two weeks.
Probably not as much detail as all of this though. ;-)