Heavy Updates

Aug 13, 2008

The official Team Fortress 2 blog has word of the upcoming update to the heavy class. There are tons of additions in the pipeline:

  • New game type (as yet unannounced) with five new maps
  • New payload map
  • New community made map
  • Three unlockable weapons
  • Thirty-five new achievements

An official heavy update site is revealing new information each day this week, as well as Monday and Tuesday of next week. So far, they've revealed the new community map (cp_steel), one of the new unlockable weapons (a pair of boxing gloves), and the list of achievements (though none of them have descriptions yet). As before, a free weekend will be held for folks new to the game. I'm looking forward to this update; it'll give me a reason to jump back into TF2.

One Bad Mutha

Aug 12, 2008

I was saddened to hear that music legend Isaac Hayes died on Sunday. He was an incredible composer and performer, and his additions to the music world will be greatly missed. Of his many works, my personal favorite (and, in my opinion, his best) is the soundtrack to the classic 1971 film Shaft. I highly recommend picking it up; it's top quality stuff, especially if you're a jazz and soul fan. While you're at it, pick up the film too; I consider it one of my top ten favorite movies.

Kayaking Fun

Aug 2, 2008

My dad and I took a 4-hour kayaking class this afternoon, from the folks at Frog Hollow Outdoors. The "intro to kayaking" class was incredibly thorough, and I learned a ton about how to kayak correctly. Topics covered included a number of various paddling strokes, wet exits (what to do when your kayak flips upside down with you in it), deep water rescues, and more. It's some of the best $68 I've ever spent. I had a blast, learned way more than I thought I would, and got excellent exercise (I'm so tired at the moment).

If you're in the Triangle area, and you're looking for a way to learn about kayaking (or canoeing for that matter), check out Frog Hollow. Our particular instructor, a guy by the name of Banks, was incredibly knowledgeable and very friendly. It was well worth the trip, and I'd do it again in a heart beat. My next goal: river kayaking fundamentals. I can't wait.

Fixing Pathfinding

Jul 29, 2008

I just finished reading an excellent article on how to fix pathfinding in games. The author presents a number of excellent examples of how today's pathfinding can break (with examples from legendary games like Oblivion and Half Life 2), and offers a great solution: use a navigation mesh instead of a waypoint graph. Genius.

I ran across another weird and subtle bug in Visual Studio 2005. If you've got a solution with many project in it, you can set one of those projects to be the default project at startup (i.e. when you open the solution file). But this setting apparently resides in the user options file (.suo), which is something we don't keep in our code repository (since it differs for every user). So how can you set a default startup project that affects anyone working with your code? Simple: hack the solution file.

Thankfully, the solution file is just plain text. Apparently, if there's no user options file for a given solution, Visual Studio 2005 simply selects the first project it comes across in the solution file. Here's a quick example of what a solution file looks like (wrapped lines marked with »):

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{3853E850-5CD7-11DD-AD8B-0800200C9A66}") = "ProjectA", »
"projecta.vcproj", "{D9BA97DE-0D09-4C35-99D6-CC4C30A6279C}"
EndProject
Project("{3853E850-5CD7-11DD-AD8B-0800200C9A66}") = "ProjectB", »
"projectb.vcproj", "{E1D73B44-57D9-4202-A92A-0296E3583AC4}"
EndProject
Global
{ ... a bunch of junk goes here ... }
EndGlobal

In this case, Project A will be the default startup project. To make Project B the default, simply move its associated lines above Project A in the file, like so:

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{3853E850-5CD7-11DD-AD8B-0800200C9A66}") = "ProjectB", »
"projectb.vcproj", "{E1D73B44-57D9-4202-A92A-0296E3583AC4}"
EndProject
Project("{3853E850-5CD7-11DD-AD8B-0800200C9A66}") = "ProjectA", »
"projecta.vcproj", "{D9BA97DE-0D09-4C35-99D6-CC4C30A6279C}"
EndProject
Global
{ ... a bunch of junk goes here ... }
EndGlobal

Don't forget to grab the end tags of each project (and any child content that may live between them).

Dustin and his wife recently uncovered an interesting limitation of my Monkey Album software: characters outside of the ISO-8859-1 (Latin 1) character set don't render properly. This comes as no surprise, seeing as I didn't design for Unicode. Being a rather egregious display error, I decided to set out and fix the problem. In the process, I learned quite a lot about Unicode, and how it affects web applications. This post will be the first of two detailing how to add Unicode support to a web application. I will only be exposing a tip of the Unicode iceberg in these posts. The ideas and practices behind Unicode support can (and do) fill the pages of many books. That said, let's jump in.

Brief Background

For the uninitiated, Unicode is a coded character set. That is, it maps a unique scalar value (a code point) to each character in a character set. ASCII is another example of a coded character set. Each character in a coded character set is intended to be encoded using a character encoding scheme. ISO-8859-1 is an example of a character encoding scheme.

It is important to note that ISO-8859-1 is the default encoding for documents on the web served via HTTP with a MIME type beginning with "text/". So, if you're not set up to specifically serve another encoding, your web pages are most likely using ISO-8859-1. This works just fine if you speak English or a subset of European languages. But because the ISO-8859-1 character encoding uses only 8 bits for its encoding scheme, it is limited to 256 possible characters. It turns out that 256 characters isn't enough for international text representation (the Chinese and Japanese languages come to mind). What can we do?

Thankfully, we have a solution in Unicode. A number of Unicode encoding schemes are available for us to use: UTF-7, UTF-8, UTF-16, and UTF-32. Each has its merits and detractors, but it turns out that UTF-8 is the preferred encoding of choice in the computing world (it's a nice trade off between space allocation and capability). As a bonus, UTF-8 works nicely with ASCII, which makes migrating English-based websites much easier.

Unfortunately, we have another major problem to deal with. All PHP releases (prior to the upcoming PHP 6) internally represent a character with 8-bits. That's right: PHP has no native support for international characters (yet)! This means that we have to be extra vigilant in our pursuit of internationalization support. So how do we do it?

Prepping Our PHP for Unicode

In order for our PHP application to properly display Unicode characters, we need to do some preparatory work. This involves setting the appropriate character encoding in a few places. We'll first set the encoding in the header:

header('Content-Type: text/html; charset=UTF-8');

Remember that the header() function must be called before we output any HTML, so it needs to appear early in the chain of events. Note also that the header call incorrectly labels the encoding as a 'charset,' making the naming conventions even more confusing.

We can also specify the encoding through the use of a meta tag (I recommend setting this even if you set the header):

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

If you take this route, make sure this tag is placed near the top of the <head> element in your HTML (before your <title> element, in fact). Otherwise, the browser may select an incorrect encoding.

To verify that that the appropriate encoding is being used, you can use the View Page Info feature in Firefox (just right click the page and you'll see it in the context menu). Here's an example:

Page Info Dialog in Firefox Showing UTF-8 Encoding
Displaying Unicode Text

One of the primary functions that PHP provides to convert characters into their HTML entity equivalents is the aptly named htmlentities() function. However, since we're converting our application to support UTF-8, we don't need to make use of this function. Why is this? First, HTML entities are generally only understood by web browsers. By converting special characters into HTML entity equivalents, it becomes much harder to move data between the web application and other data sources (RSS feeds, for example). Second, and most importantly, UTF-8 allows us to display extended characters directly. To quote Harry Fuecks [PDF], with UTF-8 "we don't need no stinkin' entities." Instead, we should only worry about the "special five":

  • Ampersand (&)
  • Double Quote (")
  • Single Quote (')
  • Less Than (<)
  • Greater Than (>)

Thankfully, PHP gives us the htmlspecialchars() function to handle these five special characters. One very important thing to note is that this function allows you to specify the character encoding to use when parsing the supplied text. For example:

htmlspecialchars($incomingString, ENT_QUOTES, "UTF-8");

Specifying the character encoding is very important when using this function! Otherwise, you open yourself up to to a rather nasty cross-site-scripting vulnerability, something that even Google was susceptible to a while back. In short, the character encoding specified in your htmlspecialchars() call should match the encoding being served by the page.

What Next?

In the next article, I'll cover the following topics:

  • Prepping MySQL databases for Unicode
  • Accepting Unicode characters from the user
  • Potential PHP pitfalls
  • Useful resources (loads of helpful links)

As always, if you have suggestions or questions, feel free to post them.

Recently at work, I spent a fair amount of time debugging some strange run-time errors in one of our test tools (after having ported it from Visual Studio 2003 to VS 2005). When starting up a debug build of the tool, I would get the following error message:

An application has made an attempt to load the C runtime library incorrectly. Please contact the application's support team for more information.

This error message turned out to be a red herring, though it pointed me in the direction of the actual culprit: a circular dependency chain of debug and release versions of various Microsoft DLLs. In trying to figure out what was going wrong, I ran across an incredibly helpful article on troubleshooting these kinds of issues. The author presents seven different scenarios that can arise with executables built in Visual Studio 2005, along with solutions for each one. It's a great resource to have if you run into these kinds of problems.

Upcoming Stuff

Jul 22, 2008

Apologies for the infrequent updates: my sister recently came back to the US for about a week (which was fun), then my grandmother came to visit (which I also enjoyed), and now I'm sick. So there you have it.

A two-part series on Unicode support for PHP web applications is coming, provided I can feel better and get rid of my writer's block.

Just yesterday, Microsoft released a 'critical update' for issue 951748, fixing a DNS security hole. It turns out that this fix completely hoses the Zone Alarm software firewall (which I happen to run). In essence, you completely lose your internet connection.

The folks that make the Zone Alarm firewall are aware of the problem. For now, they suggest two workarounds: either uninstall the MS fix or set the firewall security slider to medium (down from high). Hopefully, a true fix will be issued within the next few days.

Update: This problem has even made Slashdot.

As I surf through various news sites around the web, I often enjoy reading user comments. On many of the sites I frequent, the comments truly add to the discussion and are a good for a belly laugh or two (or three). The feedback left on nearly every story at Gizmodo is hilarious, and visitors to Slashdot are often quite funny as well, making those my favorite tech news sites. Other sites can be hit or miss. Take Digg.com for example. Occasionally, some classic comments can appear on a popular story, providing some insight into the story, or more often, supplying a funny, sarcastic remark about the story as a whole. Other times, the comments are mostly juvenile and unhelpful.

Unfortunately, the comments on some sites are painful to read. Take my favorite gaming news site, Blue's News. Nearly every comment on the site falls into one of these categories:

  • {Insert Game or Publisher Here} is Lame
  • {Insert Game 1 Here} is Better Than {Insert Game 2 Here}
  • Software Pirates Rule
  • Steam Sucks
  • OMG PONIES!
  • Yo momma!

The target demographic of the site is most likely males aged 13 to 21, but you'd think that someone would eventually have something good to say. Are there no civilized gaming websites in the world? This problem doesn't just affect gaming websites. Places like CNN.com or our local news station WRAL are nearly as bad. It's a shame that discussions vary so much. Do you read the comments at various news web sites? If so, what do you think?

I'm not exactly sure when Valve made them available, but player statistics are now publicly viewable on the web. You can keep tabs on my stats as I make progress on the various achievements recently added for the Medic and Pyro classes. If you click the "Return to jgbCodeMonkey's Steam ID" link, you can view stats for a few other games (though not all games report stats).

In other related news, Valve has recently put up an official Team Fortress 2 Blog. Lots of behind-the-scenes artwork is being shown, and some explanations for decisions they've made are presented. While the blog isn't the most active in the world, the nuggets of information they have provided so far are quite intriguing. Definitely a recommended read for fans of the game.

Diablo III Preview

Jun 30, 2008

On Saturday, Blizzard officially announced Diablo III, the next in the highly popular role-playing game series. Although the first Diablo was fun, it was Diablo II that put the series into the upper echelons of gaming. It has been over 7 years since the one and only expansion pack for Diablo II was released, enabling the game to run at 800x600 instead of a paltry 640x480 (those were the days).

I highly recommend the game play trailer on the official website (linked above). One of Blizzard's employees shows a number of new game mechanics (destructible environments that you can use to your advantage), as well as one of the new playable classes (the witch doctor, which looks super cool). I am super excited about this title, and I'll definitely be picking it up once it's released. Blizzard, like Valve, seldom disappoints with their releases, and this is one to definitely watch.

Death of the Newspaper

Jun 25, 2008

It's no surprise that the internet, along with 24-hour news channels, are killing off newspapers as a whole. But it seems as if the end of newsprint is nearer than expected. Earlier this month McClatchy Company, the group responsible for publishing our local Raleigh News & Observer, slashed over 10% of its workforce. This cut leads to the inevitable: less news in the newspaper.

When I read the newspaper, I mainly look at the local news section, the business section, and the comics (the most important part). The News & Observer will be merging the business section with the local news section, cutting coverage in both sections in the process. Happily, the comics section is (for now) being left alone. But these changes are leaving less for me to look forward to. I can only see this change as a snowball effect. Provide readers with less content and they'll leave. Have readers leave, and then cut back even more as a result, causing yet more readers to leave.

Do You Still Use CDs?

Jun 21, 2008

How do you purchase your music? Does anyone still buy CDs, or has everyone moved to digital music? And where do you purchase your music from?

Call me old school, but I still purchase CDs through my favorite retailer Amazon.com (I gave up buying music from brick and mortar stores long ago). Seeing as my musical tastes are outside of the mainstream, it's not surprising that many of the albums on my radar are difficult to find. For example, I recently picked up a few albums from 1970's progressive rock band Camel, and both were imports (and therefore more expensive than the domestic albums might be). But the imports were the only thing available. One other album I'm seeking is currently marked as shipping in '4 to 6 weeks' which, in Amazon speak, means that it's unlikely to ever be available again. This isn't an isolated case; I'm finding that it's increasingly difficult to find certain albums on CD.

As a result, I'm wondering whether it's worth buying CDs anymore. I primarily listen to CDs on my way to and from work, though I listen to my iPod exclusively at work and on the occasional trip somewhere. When I'm at home, I listen to my music through either iTunes or WinAmp. Having a CD gives me something tangible as well as a backup (in case the digital rip gets destroyed or corrupted). But CDs have their own problems. The jewel cases are bulky (they way a ton en mass), and they're always a bother to open up after purchasing them (what's with all those stickers and cellophane wrap?).

The Amazon MP3 Store seems very appealing, in that all the offered music is DRM free. But, not surprisingly, not every album is available. So what do you do?

The fine folks at Valve have updated Team Fortress 2 once again, bringing new achievements, unlockable weapons, and a core change to the Pyro class. Along with all of these changes come two new community maps: one control point map and one capture the flag map. If you're interested in checking out the new content for free, you can do so this weekend, from June 20 to June 22. As always, friend me up if you jump into a game; my nickname is jgbCodeMonkey.

I recently noted in Firefox 3.0 RC 2 that the sort order for autocompleting input fields is broken. In Firefox 2.x, items are sorted alphabetically (different from the insertion order scheme used in Firefox 1.x, if I recall correctly). Now, it appears that the items are sorted according to how they were inserted, with the most recent entries appearing on the bottom. This strange result unfortunately affects Googlebar Lite, beginning with Firefox 3 builds. I haven't received any complaints about this at the moment, but I'm guessing that most people haven't switched away from 2.x, so no one has caught it yet.

It's possible that this issue is a valid Firefox bug. I see that bug 418343 has been written against the search autocomplete results, though I'm guessing it applies to all autocompleting elements (with the exception of the AwesomeBar).

The autocomplete textbox inherits the sortDirection property from the base XUL element, but I have yet to try setting that manually to see if it has any effect. And I'm not sure whether to set it on the textbox itself, or on one of the child elements that lives inside.

Hopefully setting this property will fix the issue, though I'm only given three sort options: ascending, descending, and natural. I'm guessing that the natural option is what I'm seeing now in Firefox 3, with newest at the bottom. One of the largest feature requests that I get for Googlebar Lite is to sort search history items in the order they were inserted, with newest at the top. While I may not be able to easily sort things like people want, I might at least be able to return to the behavior seen in 2.x.

Mozilla Developer News reports that Firefox 3 will be officially launched next Tuesday, June 17. Make sure you download your copy that day, to help Mozilla break the world download record. I've been using Firefox 3 for a while now, and it's worlds better than Firefox 2 (which was already super awesome).

I have added a new section to the sidebar of this site, showing the most recent comments posted here. Hopefully, this will help foster further discussion on older topics (which occasionally get comments). This new feature comes via the aptly named Recent Comments WordPress plug-in. I'm quite impressed with the customization options available, and installation was a snap.

Does anyone have any recommendations for how the recent comments list should appear? Plenty of options are available, including an excerpt preview of each comment. I tried several options out, but I'm not sure what visitors would find most useful.

Your suggestions would be appreciated.

Are there any readers here who use Windows and don't make use of an anti-virus client? I've been thinking about ditching my anti-virus client altogether on my personal system, and after reading an interesting article on the subject, I'm wondering if anyone else out there has taken this route. In my experience, anti-virus solutions are slow, ineffective (I'm not sure they've ever flagged anything for me over the years), and are generally a bother to keep up with.

If you've ditched anti-virus, why'd you do it? And what have been your results?

It's official: I am switching to Firefox 3 RC1 as my primary web browser. All of the extensions I use are now compatible in some form or another (Firebug and Linkification are still in 'beta'), so that's no longer holding me back.

One interesting note about Firebug. The new version has removed the 'Disable / Enable' feature for individual sites. Or so I thought. This functionality has now been moved to the Network Monitor and Script Debugger sections of the extension. In other words, I can now explore the DOM tree for any site, without having to pay the performance hit from the network monitoring code. Woo-hoo!