General Ramblings comments edit

Dad's Car Accident
Dad’s Car Accident

My dad was headed to work yesterday and hit an icy patch in the road.  His car spun 180 degrees, went into the ditch, and hit a tree.

He’s okay, albeit on some serious pain killers and with some chipped vertebrae.  No one else was involved or injured and after some physical therapy and some time to rest up, he should be good as new.

Here are some pictures of what was left of his car.  Absolutely totaled.  He had to climb out the passenger window because the frame was so bent up neither door would open.

Of course, the thing he seems to be most concerned with is that, somewhere in the chaos, he lost his glasses.  Heh.

gists, aspnet, net comments edit

Let’s say you have some text on your web site that has an image inline.  Something like this:

Fields with a ! icon indicate failed validation.

You’ve seen that before.  You’ve probably done that before.  Now let’s say you’re using ASP.NET themes and skins to control your look and feel, and that icon is different based on your theme.  It might change to be:

Fields with a ! icon indicate failed validation.

You could have some ASPX code that handles that with the SkinID of the image, right?

Fields with a <asp:Image ID="icon" runat="server" SkinID="validationIcon" /> icon indicate failed validation.

Okay, that works acceptably, provided your skin defines an Image that has a SkinID “validationIcon.”  But you’re a savvy ASP.NET developer and you know better than to put literal strings like that right in your web application - you put your strings in resx files and look them up at runtime so your app can be localized.  Now what?

There are a few ideas you could try, but they don’t work (or not well):

  • String.Format - You could leave a {0} in the page text and try to String.Format the image into place.  That might work if you weren’t skinning, but you need to take advantage of ASP.NET skins… so that won’t work.
  • Client-side script - You could try some client-side script to render the image to a hidden place on the page and then place it into a <span /> or something in in the instructions, but that’s kind of painful.
  • Break the text up into separate controls - You could make the text three controls: the text before the image, the image, and the text after the image.  This could become hard to manage from a localization perspective (what if there isn’t any text after the image?) and it’s not terribly flexible.

The answer: ParseControl.

The System.Web.UI.Page class has a ParseControl method on it that it inherits from TemplateControl.  You can use this to your advantage - just put the markup inline into your resource string and use ParseControl method to create a control hierarchy on the fly.  Then just swap the parsed control hierarchy into your page where you want the text to display.  Put a Literal in your ASPX and do your string lookup…

<asp:Literal ID="pageText" runat="server" Text="<%$Resources: MyResources, PageText %>"/>

And in your resx file, put the entire text, including the image markup:

<data name="PageText" xml:space="preserve">
  <value>Fields with a &lt;asp:Image ID="icon" runat="server" SkinID="validationIcon" /&gt; indicate failed validation.</value>

See how that looks just like ASPX page markup?  Perfect.  Now in the codebehind of your page class, replace the Literal with the control hierarchy that gets parsed from the text in that very Literal:

public partial class MyPage : System.Web.UI.Page
  protected void Page_Load(object sender, EventArgs e)
    Control parsed = this.ParseControl(this.pageText.Text);
    Control parent = this.pageText.Parent;
    int index = parent.Controls.IndexOf(this.pageText);
    parent.Controls.AddAt(index, parsed);

In that example code, we:

  • Parse the text that got looked up from resources into a control hierarchy.  This lets us account for localization while still providing the inline themed icon we’re looking for.
  • Grab the parent of the original control.  This is important because you need to insert the parsed control hierarchy into the proper spot in the control tree.
  • Find the exact location of the original control in the parent’s control structure.  This tells us where to put the parsed control hierarchy.
  • Insert the parsed control hierarchy into the proper spot.
  • Remove the original control from the hierarchy - we’ve replaced it, so it’s no longer needed.

Pretty nifty, eh?  There are lots of other things you might want to consider if you do this, but I’ll leave them as “an exercise for the reader,” so to speak:

  • The example replaces the control with the parsed hierarchy; you might instead wish to add the parsed hierarchy as a child of the control you’re “replacing.”
  • If you use the same text twice in the same page, you may end up with control naming clashes; you might want to wrap the parsed control hierarchy in a naming container to avoid that.
  • You probably don’t want to repeat this code over and over in every page; you’d want to have a single service class that does this for you.

A tiny word of warning:  you probably don’t want to do this on every single string you localize. It’s not super expensive, but it isn’t necessarily “free,” either.  Here’s the timing from trace output - you can see the obvious difference in the amount of time the page Load event (where I’m doing this) takes vs. the other events.

Timings for parsing inline

It’s only ~0.01 seconds, but you wouldn’t want to, say, put this in the middle of a big databinding block.

General Ramblings comments edit

Woke up last night at 2:45a to the neighbors out in their yard arguing.  No physical violence, and it was mostly the guy yelling, but super loud.  I don’t even think I’d heard them before, except for their dog barking incessantly a year or so back.  Sigh.

Jenn ended up calling the cops who couldn’t actually find our house on a map.  She kept having to give a bunch of nearby cross-streets and directions.  That makes me feel really safe.  I imagine a time where there’s a psycho killer in my house trying to stab me and the 911 conversation goes like this:

Travis: Oh my God, help, there’s someone in my house trying to stab me!  Here’s my address - get here as soon as possible! Dispatcher: Hmmm… you don’t seem to be on the map. What’s your nearest cross-street? Travis: I think he’s coming up the stairs! Wait - cross-street? Uh… Foo Ave. Dispatcher: Yeeeaaaah, um, is that north or south of Bar St.? Travis: South.  Hurry! Dispatcher: Are you sure? Where are you in relation to Baz Pl.? Travis: -stabbed to death-

That’s the first time I’ve called the cops on someone.  When they finally arrived, it was in total force - like, two cars and another cop running up a side street.  I’m surprised the SWAT team wasn’t there.

Had a hell of a time getting back to sleep, though.  It took me forever to get to sleep the first time, then this.  I’m dead tired today.  Damn, anyway.

gaming, xbox comments edit

Okay, so for a while I thought it might be that I got a bum set of drums with my copy of Rock Band because I’m only able to get like 98% on Easy level.  I mean, I swear I’m hitting them right, but it’s just not registering.

To test, I went into practice mode and played a song segment that basically has no drums at all - so I wouldn’t get confused by notes being hit or missed.  I did a roll on each drum to see how it went and all of the hits were registered.  I also hit various combinations of two pads simultaneously and all of those hits were registered.  So I was/am encountering a combination of issues, all adding up to Bad News for Me:

  1. The timing on the drums is utterly unforgiving.  If you’re playing guitar, you get a little plus/minus room for strumming and hitting a note.  Sort of a “close enough” buffer.  With drums, you’re either ON or you’re NOT.  No fudge room.  A millisecond or two off, and it won’t count.
  2. The USB hub that comes with the game is pretty bad and seems to introduce a little latency.  Not a lot, but with timing having to be pretty precise, I notice a little better response when I plug the drums into the Xbox directly and everything else goes in the hub.
  3. Calibrating the game is hugely important.  Sometimes the presets work; I manually calibrated mine and things seemed to be a little better.
  4. I may just be a sucky drummer.  After checking out the responsiveness of the drums, calibrating everything, and plugging the drums right into the Xbox, I’m doing a little better but am still missing a couple of notes per song on Easy mode.  It’s usually during a spot where I have to hit two pads simultaneously and I think it’s that I’m hitting them close to correctly but actually hitting one pad slightly earlier than the other, so it doesn’t count.

I’m pretty good at Donkey Konga bongos.  I think playing drums with your hands and playing them with sticks might be two different beasts.  I’m OK with that - knowing that it means practice is one thing; doubting yourself without knowing if it’s the equipment or not is a whole other set of insecurities.

gaming, xbox comments edit

My copy of Rock Band arrived yesterday and it well and truly does rock.  The thing I was excited for was the drum kit; I’ve always fancied myself a drummer, and I finally get to test that out.

Turns out, I’m not all that bad.

A breakdown by instrument…

*Guitar **I’ve played my fair share of *Guitar Hero 2 and Guitar Hero 3, so I knew what to expect out of the guitar experience.  You can play lead or bass, your choice.  The actual playing experience with the guitar is roughly the same, so I won’t go too far into it.  That said, I did notice the difficulty level was significantly lower than GH3, and possibly slightly lower than GH2.  That’s not a bad thing - it just makes you feel cooler.

I can’t say much about the controller it ships with, though, because mine arrived broken (the directional pad on it is stuck so it constantly thinks the “down” arrow is being pushed - throws a wrench in the works, let me tell you).  Fortunately their support is really good and you can very quickly get an RMA and a replacement through their automated online system - no need for massive escalation or trouble.  Ordered my replacement this morning.

*Microphone (Vocals/Tambourine) **I haven’t played *SingStar but I gather the vocals portion here is the same as that.  It’s a little harder than I expected and it does require you to really know the words and the tune - including all the little fluctuations the singer makes while singing.  In some cases you can get by with volume over accuracy (which isn’t far from real life, right?) but generally you do need to know the song pretty well.

For example, I sing along to Bon Jovi’s “Wanted Dead or Alive” in the car, but it turns out I really only know about half the song… and thinking back, I do sort of hum my way through a lot in the car.  That said, I was able to get 100% (on Easy level) for The Clash song “Should I Stay Or Should I Go?”  So it’s not impossible, just sort of hard.

During musical solos, you can tap the mic in time with some “beats” that appear and play the tambourine.  This sort of reminds me of the clapping that you have to do in Donkey Konga.

Drums This is what I was waiting for.  It’s a heck of a setup and isn’t really small sitting in your living room, but it’s hella fun.  There are “notes” on the screen for hitting each of the four drum pads (just like Guitar Hero) and the kick drum is signified by a hard line that crosses all of the four note positions at once.  It takes a little getting used to, but once you figure it out, you’re in.  I’m working through Easy difficulty right now because I tried Medium and… well, there’s too much going on and I haven’t quite got drums down yet.

In some cases, though, I can’t figure out whether my drum controller is faulty or if I’m just a sucky drummer.  I swear I hit the right pad at the right time, it just says I didn’t.  Other times, everything’s fine.  I can get like 98% in some cases, I just miss a couple.  I would think if the controller was faulty it would be… more predictable.  Again, the 60 day warranty might be good here.  Drums are definitely less forgiving than the guitar - with the guitar, you can “pretty much” get the note and it’ll count it; with drums, you either get it dead on or you don’t get credit.  I think that’s more likely what I’m running into.

That said, I really hope someone comes out with some after-market drums for this game.  I like the drums, but I’d like some of it to be a little more adjustable.  I’m 6’2” and I feel sort of cramped by the kit due to the placement of the kick drum pedal.  Maybe I just need to try some different positioning.

*The Game **The game itself is pretty good.  Far better set list than *Guitar Hero 3 had.  I also really like the way the campaign is set up as a “world tour” where you start in small venues and gather money and fans - it feels more tangible than the arbitrary progression you get in Guitar Hero.  You also have a really nice character creation system that allows you to personalize your character including face, hair, clothes… very cool.  There were only three points of confusion I had:

Point of Confusion 1:  Bands are attached to an Xbox Live profile and to a Rock Band character.  When you create a band, the person who’s creating the band gets the band saved to their Xbox Live profile.  Further, as you select (or create) your character in the band, that specific character has to play in the band for the entire life of the band - they’re the band leader.  This is very important because…

Point of Confusion 2:  Characters can’t change instruments.  Once you create a character for a particular instrument (guitar/drums/mic), they can’t switch.  Jenn and I created a band where I was playing drums and she was playing guitar.  She wanted to try the drums out, so we tried to get it so her character was playing drums and mine was on guitar.  No dice - both of us were only allowed to create new characters.  And since my profile was the one with the band leader, and the band leader was playing drums, we either had to play under the other person’s profile or create a new band.  We created a new band.  (The third option, really, was to back out and do a “quick play” where you can form a band impromptu with anyone playing any instrument - no leader required.)

Point of Confusion 3: Once the instruments are attached to the Xbox 360, you can’t change their position.  So, say I attach the instruments and the drums are player 1, the guitar is player 2, and the mic is player 3.  By default, my console signs me in when it turns on, so I’m signed in as player 1 and I’m stuck on drums.  The easy way to fix this - connect all of the controllers to the Xbox, turn it on, and sign everyone out.  Everyone pick up the control they want to play with and sign in from there.  During the game if you want to change instruments, you can sign out and sign back in without exiting the game, so just do that - sign out on your current instrument and sign in on the one you want to switch to.  It sounds like a no-brainer when I say it here, but trust me, this was a huge problem for us to figure out.

Again, by-and-large, it’s an awesome game.  I’m also super happy [so far] with the ease of customer support.

Hey, since I’ve got the day off, I should probably go do a little rockin’ right now.