Friday, August 27, 2010

Undefined C programs and Game Loops

If you're in the habit of using C (and who isn't), you'll want to read this. It's a fantastic description of all sorts of way you can write programs with undefined behaviours in C. It also goes over the horrible and unintuitive things that can happen when you do.
http://blog.regehr.org/archives/213

I've also been looking at tweaking the game loop inside space smilies and found an excellent article on how to write game loops. If you've ever want to write a game, read this first!
http://dev.koonsolo.com/7/dewitters-gameloop/

Saturday, August 21, 2010

My Clock

One day I woke up and was surprised to see I had time traveled to the year 2108. Then I realized it was only the 21rst of August and went back to sleep much relieved.

Thursday, August 19, 2010

Scroll-wheel follows mouse

One of the few things I like about using the Gnome based system at work is that it scrolls the widget your mouse cursor is pointing it. It doesn't matter if the thing in question has the focus or not. It doesn't matter if it's in another window that doesn't have the focus it just scrolls whatever is under the mouse cursor. It's really nice.

Windows 7 doesn't do this. I miss this behavior.In Windows 7 you have to click on whatever you want to scroll to make sure it has the focus. Sometimes you don't want to click because it's hard to find something "safe" to click on. That is, something that won't screw up what you're doing. Using the window explorer/file manager is a good example. The way I use it, there's a pane on the left hand side that shows me the list of folders and where I am in the file hierarchy. Clicking just about anywhere in that pane changes the selected folder and moves you around in the hierarchy. If I want to scroll this pane I have trouble finding a place where I can give it focus while not getting myself lost in a sea of folders. Having the mouse cursor determine which scroll pane is scrolled, rather than the focus solves this problem nicely.

I've managed to find a utility that enables this behaviour. It's called WizMouse. Give WizMouse and the scroll-wheel follows mouse a try. In a little while you'll wonder how you lived with it any other way.

2012-11-08 - There are a few other products like this and I've tried a few of them. They all seem to have the problem of causing pauses/freezes. The pauses are so bad that even the mouse cursor will stutter its way across the screen. I've had to uninstall these utilities because the pausing has been more annoying than the default windows scrollwheel behaviour. Oh, and don't think I didn't notice that Chrome supports the gnome model.. at least within Chrome windows.

Saturday, August 14, 2010

Doodling


You know how it goes. Someone is talking about.. something.. Your mind starts to wander and you start to doodle in your notebook.

This one made me laugh so I thought I'd share it.







Saturday, August 7, 2010

History of the SSD

As some of you may know I'm a big SSD fan. For those who are worried about the negative reputation that SSDs have gotten you should check out an article pointed out to me by our chief architect.

History of the SSD courtesy of AnandTech:

http://www.anandtech.com/show/2738/1

Thursday, August 5, 2010

Light Text on a Mixed Background

Let's say you wake up one morning and find you're the guy responsible for deciding what colour the subtitle text should be. After overcoming the initial shock of having slept through a major career change, you'd come realize what a difficult problem this is. If you make the text white it'll show up fine on a dark background as you would find in a horror movie or Tim Burton film. On the other hand it will leave the audience puzzled at on a white background like the snowy battle of Hoth. If you give in to the star wars fans and make the text black the Tim Burton fans will grab their pitchforks and head up to your spooky castle during a midnight thunderstorm. Things get even more embarrassing if half the screen is white and half the screen is black. The audience will be able to read half the sentence and no doubt fill in the rest with whatever their dirty minds come up with. This, of course, will lead to many viewer complaints about how smutty modern films have become. What are you to do?

I've run into this problem a couple of times during my programming career. In my case it was adding text overlays to images to show additional image meta data... while fighting the Sith with Jonny Depp! It's actually surprisingly easy to get text to show up nicely on almost any background. All you need to do is have lightly coloured text with a shadow effect.

The simplest way to do this is to simply paint a copy of the text in question one pixel down and one to the right in black. For added readability add another copy one pixel to the right.

Here's some sample code:
g.setColor(Color.BLACK);
g.drawString(TEXT, 10 + 1, 10 + 1); //second shadow
g.drawString(TEXT, 10 + 1, 10); //first shadow

g.setColor(Color.WHITE);
g.drawString(TEXT, 10, 10);


Nice, large, translucent drop shadows can also increase the readability of text. In my case, though, I only want the shadow effect to increase the readability of the text. The simplicity and subtlety of the shadow effect above is a feature.

I've included a real time java demo of just how amazing this effect can be.

Shadowed text demo!

(Requires java. Open the file with the "java web start" application)

Source code is here!

For those without java this is what the incredibly light pink text looks like on a pure white background:


(The application isn't this blurry when you run it :-) )

Google makes use of a subtle and more fancy shadow effects if you select a background for you Google homepage. You can use any photo for the background. In this image I've selected a plain, white background:

(The Google homepage slightly cropped.)

Sunday, August 1, 2010

Booting XP with the new motherboard

You may remember how I recently got a new motherboard.. and then I changed the CPU. I thought I'd get my motherboard to boot Windows XP.

When I upgraded to Windows 7 from Windows XP I installed Windows 7 on a brand-new solid state drive (remember when I got one of those?). This left me with the original installation of Windows XP on the existing hard drive. This is a sweet arrangement as it meant I could boot up with Windows XP if I discovered of applications that can't run in Windows 7. It's also useful to have your old Windows XP around if you want to look up some setting or bookmark or something that won't transfer over to Windows 7.

When I changed the motherboard I could no longer boot into Windows XP. I'm not entirely sure why that happened. My suspicion, at the time, was the drive numbers changed around. Windows XP keeps track of which drive number it's booted from in the boot.ini file. I went into the boot any file and tried changing the numbers to my best guess as to what what they should be but for some reason it wasn't working. I'm still not sure why it didn't work, actually. I think it may have had something to do with me screwing up the file format a little. I thought the '#' symbol was used to denote comments when in reality it's the ';'. Oh dear.. a little too much Linux shell scripting.

In any case, it wasn't working so I tried to use the utility EasyBCD to re-create the Windows XP boot option. This failed as well. I'm not sure why this failed either. I'm not sure what EasyBCD was trying to do but my booting arrangement is a bit unusual in that my old Windows XP drive contains the boot loader which then boots Windows 7 on my new solid-state drive. I think EasyBCD was a bit confused by this. When I would launch Easy BCD, it couldn't find the BCD file, for instance. I think it was setting everything up thinking the boot loader was being run from the solid-state drive. In any case, it I was left pretty much where I started except that now I kept getting messages about NTDETECT failing.

I noticed that EasyBCD had messed with files that Windows XP uses to boot. I tried to repair the Windows XP installation by running a few commands off the Windows XP repair CD. Many of the Windows XP commands were throwing errors and clearly had no idea what Windows 7 and easy BCD had done to the installation.

(The BIOS bone's connected to the MBR record. The MBR's connected to the PBR. The PBR points the BCD file.. but not on my system 'cause it's b0rked. yeah!)

I tried rebooting and was surprised to find I couldn't even boot Windows 7 now. After much swearing I used the Windows 7 repair CD to try and repair the installation. The Windows 7 installation CD had no idea what I'd done. I had no idea what I'd done. Things were going from bad to worse. I knew that the Windows 7 repair CD (or at very least the Windows 7 installation itself) would have the tools I needed to repair the Windows 7 installation. Theoretically, all I would need to do is generate a new BCD file that would point to the already installed Windows 7 installation. The thing was, I didn't know what the damn commands were that did that.

I tried to use EasyBCD but that didn't work as it needed the full Windows 7 to run; the repair CD didn't cut it. I couldn't even run the command line versions of EasyBCD. After a further sampling of four letter expletives, I started up the old Dell netbook and poked around the Internet looking for a solution. It turns out that, in the Windows\System32 directory, you can find two commands that will allow you to manipulate the BCD file. "bcdboot.exe" allows you to build a new BCD file and "bcdedit.exe" allows you to edit said file to add additional boot options. Sweet.

To make a long story short I used bcdboot.exe to make a new BCD file on the solid-state drive. I then switched the solid-state drive to my primary boot drive in the BIOS. With that I could boot into Window 7. yay! I then added the Windows XP installation as an option with EasyBCD. I now had a choice between the two operating systems when I booted. This all went so well that I also took a stab at repairing the BCD file on the Windows XP installation just in case my solid-state drive (containing the all important BCD file and Windows 7 installation) died. If the solid-state drive died I could boot directly to Windows XP on my other hard drive. I haven't actually tested it yet. I think it might boot Windows 7 but I don't hold out much hope that it's going to actually boot Windows XP. To do that I would need to use that BCD file to boot into Windows 7 and then used it two commands to add a second entry for Windows XP. This is precisely what I couldn't figure out how to do the first time. Oh well, maybe I'll try it again.. A bit later...

Now that Windows XP is booting all I need to do is install the drivers and get ACHI working again. Weeeeeeeeeeeeeeeeeeeeee......

IM IN UR BOXEN MESIN WIF UR BOOT DRIV