All posts by Marc

SimCity – A(nother) tale of woe

Those who know me will wonder what I’m posting on this subject for. I’m not a big gamer so maybe I am missing something with the rollout of this game. I doubt it, though.

The tale starts with me pre-ordering the new SimCity game from EA – I’d played ealrier versions years ago and actually enjoyed playing. When the new version was released I thought I’d take time out to give it another try. Was it as good and enjoyable as I remembered? Was it going to be worth the 40-odd pounds it would cost? I was happy to wait and see.

And then the game had it’s UK release yesterday. I went online, downloaded the game I had pre-ordered and started it up.

Or at least, I tried to.

You see, it is by now well documented that EA massively underestimated the level of demand for this game, and the server infrastructure they put in place to deal with it crumbled under the load. Out of the dozen or so servers available, only one was listed as having any capacity. “Never mind”, I thought, “at least there is one server I can play on”. Well, that ambition was crushed pretty quickly as well. This is a screenshot I took while trying to connect.

20minutes

Yes, you’re reading that right – just short of 19 minutes until the game would even attempt to connect to the server again. Wow!

So, I wasted quite a while trying other servers, and attempting to reconnect. Every now and then I would be allowed to hit the “start” button, but each time I did I was greeted with a message saying all servers were busy. Not a great experience, EA. If I wait patiently for a place on a server, the least I’d expect is to be able to make use of that space when it is granted.

So, a few hours, a lot of waiting, and several choice swear-words later I finally manage to get in and start playing. (I realise that I am lucky and there are many, many others around the world who didn’t manage to get this far).

So, I went through the tutorial (I don’t see a way to skip it – am I missing something?) and all was well. Until the tutorial got to the point at which it had to connect to the servers again (for reasons I frankly don’t understand, or care about for that matter). This was a step too far for the fragile systems, and the game kicked me out. More swear-words.

Back to square one. I went through the whole thing again (hey, I’m nothing if not persistent) and this time actually managed to get through the tutorial and into actual game play. I spent a couple of hours building a city – not a very good city, but a city all the same. Got to a point where I was ready to call it a day, and exited the game through the menus, and turned in for the night.

This morning, I wanted to go play some more, so I booted my laptop, connected, was astonished to see that I was able to connect to a server within half an hour and went to look for my city.

Nothing.

The save had apparently failed. My “work” was gone, my city reduced to electrons and its citizens returned to being the stuff of memory.

So this brings me to a very important question. Actually, a series of important questions, but the one I want to focus on for now is this.

How did this game get released to the paying public in such a crippled and infuriating state? The answer, it seems, is in DRM.

I can understand that a games company such as EA loses millions each your to pirated software. I can understand that they would like to put something in place to prevent the wholesale theft of their intellectual property. I can’t, on the other hand, understand why they had to make the game so dependent on having an always-on connection to the ‘net. I mean, if I wanted to while away one of my regular 2-hour train journeys by playing a little SimCity, I would be out of luck. If my net connection were to disappear I wouldn’t be able to play. If the company massively underestimates demand and fails to provide enough server capacity to cope, I am similarly out of luck.

Why EA didn’t decide to give this game the ability to work offline with a periodic anti-piracy check by “phoning home” is beyond me. Isn’t it reasonable, even in the 21st century, for someone to want to play a game they paid for without being subject to this kind of heavy-handed security? “Of course you can play, but only if big brother is watching because we don’t trust our customers”.

Anti-piracy measures are not to be taken lightly. It’s a tightrope walk between protecting your IP and risking alienating your customer base. As an example of the completely opposite approach to IP protection, you only have to look at the Reaper audio production software. Rather than waste time and effort on implementing more and more obnoxious and intrusive anti-theft protection into their software, they didn’t bother adding it in the first place and charge a very reasonable fee for their product. Result? Consumers are happy that they know what they’re getting, and the company is happy because more people are willing and able to hand over the requested fees. Possibly not the best way to become millionaires, but a good, open and honest way to run a software company.

EA, on the other hand, have released a game that doesn’t work for most people right now, and to add insult to injury will not even entertain the idea of refunding anybody’s money. At all. The best they have managed to come up with so far is an offer of a free game from the EA catalogue. All very well for someone who plays a lot of games, or is happy to accept this as an acceptable alternative to getting the game they actually wanted. Personally, I’d be happy with a game that works as described in accordance with the Sale of Goods Act here in the UK. That, or a full refund after which I will walk away secure in the knowledge that I don’t have to have anything further to do with EA.

It is my opinion that EA have failed massively. This game that I was looking forward to is crippled to the extent that I can’t play it. I am very unlikely indeed to entertain the idea of giving them any more of my money. Well done, EA. I hope you are able to use the money that you gained from this episode to good use. Maybe you’d like to invest in some market research to see why your failed product launch alienated so many people? That, or you could read your own forums.

WP7 Navigation Gotcha

This afternoon I discovered a bug in one of the apps I am working on. It happens because the keys we use for navigation are provided in a third-party feed, and one of those keys contains a plus sign (“+”).

This wasn’t immediately apparent as an issue, and we just navigated using

NavigationService.Navigate(new Uri("/Views/TargetView.xaml?key=" + myKeyValue, UriKind.Relative));

Unfortunately, this gets UrlDecoded on the receiving side as a sapce, so our key that started out being “text+text” was being resolved as “text text”. When looking that value up in our tables the key was obviosuly not found and a NullReferenceException was thrown.

The fix was pretty simple, though. We just had to UrlEncode the strong before we sent it, as follows.

NavigationService.Navigate(new Uri("/Views/TargetView.xaml?key=" + System.Net.HttpUtility.UrlEncode(myKeyValue), UriKind.Relative));

and all is good with the world again.

Silverlight Toolkit ExpanderView – Flat Objects

Before anyone posts, I know this is not the intended usage of the control. I did, however, have a requirement to show a list of simple objects and some of their properties in an expander view, so I’m going to explain one of many possible ways to do it.

My ViewModel contains an ObservableCollection<ServiceAddOn>, where my ServiceAddOn class looks like this.

public class ServiceAddOn : INotifyPropertyChanged
{
    string name;
    string cost;
    DateTime startDate;
    DateTime expiryDate;
    // encapsulation for public access to the 4 locals
    // INotifyPropertyChanged implementation
}

Don’t worry about the encapsulation or INotifyPropertyChanged implementation – they are as simple as it gets.

Now, I want to create an ListBox of ExpanderView controls that will display the information like this :


My Item Name
- Cost : £123.99
- Start Date : 1/1/2012
- Expiry Date : 1/1/2013
Second Item
ThirdItem

That is where the problems start. As far as I can tell (with admittedly limited research into the issue) there is no way to bind to properties of an object in both the HeaderTemplate and the ItemTemplate – something needed to be done to expose these properties as a collection. Since I was not able to change the inplementation of the ServiceAddOn class, I decided the best way would be to write a converter. Before starting that, though, I needed a class to hold each of myt exposed properties. It looks like this :

public class ExposedProperty
{
    public string Key { get; set; }
    public string Value { get; set; }
}

Again, it is about as simple as it gets. :)

Now, the converter:

public class ExposePropertyConverter : IValueConverter
{

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        ServiceAddOn obj = value as ServiceAddOn;
        if (null == obj) return null;
        ObservableCollection<ExposedProperty> values = new ObservableCollection<ExposedProperty>();
        values.Add(new ExposedProperty { Key = "Cost", Value = obj.Cost });
        values.Add(new ExposedProperty { Key = "Start Date", Value = obj.StartDate.Date.ToShortDateString() });
        values.Add(new ExposedProperty { Key = "Expiry Date", Value = obj.ExpiryDate.Date.ToShortDateString() });

        return values;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

So now, it is just a case of a bit of plumbing…

Add the namespace reference to the XAML, and declare a converter instance

<phone:PhoneApplicationPage 
    x:Class="MyExampleApp.MainPage"
    ...snip...
    xmlns:conv="clr-namespace:MyExampleApp.Converters"
    ...snip...
    >
    <phone:PhoneApplicationPage.Resources>
        <conv:ExposePropertyConverter x:Key="GetMyProperties" />
    </phone:PhoneApplicationPage.Resources>

and then wire up the Listbox / ExpanderView combo… (note tht my collection of ServiceAddOn objects is called “DisplayItems”)

<ListBox ItemsSource="{Binding DisplayItems}">
    ...snip standard plumbing...
    <ListBox.ItemTemplate>
        <DataTemplate>
             <toolkit:ExpanderView 
                 ItemsSource="{Binding Converter={StaticResource GetMyProperties}}"
                 Header="{Binding}"
                 NonExpandableHeader="{Binding}"
                 Expander="{Binding}">
                 <toolkit:ExpanderView.HeaderTemplate>
                     <DataTemplate>
                         <TextBlock Text="{Binding Name}" />
                     </DataTemplate>
                 </toolkit:ExpanderView.HeaderTemplate>
                 <toolkit:ExpanderView.ItemTemplate>
                     <DataTemplate>
                         <TextBlock>
                             <Run Text="{Binding Key}" />
                             <Run Text=" : " />
                             <Run Text="{Binding Value}" />
                         </TextBlock>
                     </DataTemplate>
                 </toolkit:ExpanderView.ItemTemplate>
             </toolkit:ExpanderView>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

The “magic” happens on line 6, where I bind the ItemsSource of the ExpanderView control to “{Binding Converter={StaticResource GetMyProperties}}”.

That’s it.

Next steps for this may be to make the Converter more generic, and possibly use reflection to get the properties instead of hard coding them, but for now this is good enough.

If you have any comments about a much simpler way to bind to flat, single-level objects in an ExpanderView control. I’d love to hear them.

Alter a Pivot controls header template the easy way (WP7)

If you want to alter the template for a Windows Phone 7 pivot control’s header, the simplest way is as follows…

        <controls:Pivot Title="Altered Styles">
            <controls:Pivot.HeaderTemplate>  
                <!-- This changes to look of the items headers -->
                <DataTemplate>
                    <TextBlock Text="{Binding}" Foreground="Black"/>
                </DataTemplate>
            </controls:Pivot.HeaderTemplate>
            <controls:Pivot.TitleTemplate>
                <!-- This changes to look of the pivot overall title -->
                <DataTemplate>
                    <TextBlock Text="{Binding}" Foreground="Black"/>
                </DataTemplate>
            </controls:Pivot.TitleTemplate>
            <controls:PivotItem Header="daily">
                <Grid/>
            </controls:PivotItem>
            <controls:PivotItem Header="hourly">
                <Grid/>
            </controls:PivotItem>
        </controls:Pivot>

Of course, all this example does is specifically set the colour used for the title and headers to black, but you can do (almost) whatever you like in those templates. Want to add an image as a bullet? Go for it.

<controls:Pivot.HeaderTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal">
            <Image Height="48" Width="48" Source="/MyBulletImage.png" />
            <TextBlock Text="{Binding}" Foreground="Black"/>
        </StackPanel>
    </DataTemplate>
</controls:Pivot.HeaderTemplate>

Alternating ListBox item background colours in WP7

I had a requirement today to implement alternating row colours in a Windows Phone 7 ListBox. After a bit of frustration with searching and only finding answers tht said “You can’t do it”, or that you need to add a property on the model to bind the background to, I eventually hit upon a nugget of common sense on this page.

Basically you need to create a converter class that will handle the alternation of backgrounds for you. It is ridiculously simple once you see it in action.

Step 1 : Create the converter.

public class AlternateRowColour : IValueConverter
{
bool isAlternate;
SolidColorBrush even = new SolidColorBrush(Colors.Transparent); // Set these two brushes to your alternating background colours.
SolidColorBrush odd = new SolidColorBrush(Color.FromArgb(255, 241, 241, 241));

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
isAlternate = !isAlternate;
return isAlternate ? even : odd ;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}

Step 2 : Add the converter to the page

<UserControl
 	...snip...
 	xmlns:conv="clr-namespace:MyApplication.Converters" 
 	...snip...
 	>
	<UserControl.Resources>
		<conv:AlternateRowColour x:Key="RowColour" />
	</UserControl.Resources>
	...snip...
</UserControl>

Step 3 : Bind to the ListBox

<ListBox ItemsSource="{Binding}">
  <ListBox.ItemTemplate>
    <DataTemplate>
      <Grid Background="{Binding Converter={StaticResource RowColour}}">
        <!-- layout XAML -->
      </Grid>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>				

And you’re done.

Using LINQ to randomise a list.

This afternoon I needed to select some random items from a collection, and my searching ran into this idea.

Random rnd = new Random();
var randomizedList = from item in list
                     orderby rnd.Next()
                     select item;

I modified it a little to do what I needed (Select 4 items at random from a list), and this is what I came up with…

Random rnd = new Random();
var MyCollection = (from icon in TheOriginalList orderby rnd.Next() select icon).Take(4));

Bandwidth Throttling – WP7

I have been chasing down a defect in a Windows Phone 7 app that I’m involved with, but it seems to be bandwidth related. I really need to find a way to limit the bandwidth that the phone emulator is able to use.

On suggestion from some respected colleagues I used Fiddler to try to limit the bandwidth. There are a few extra steps you need to take to enable the emulator’s use of Fiddler, but once it is up and running you can use the “Simulate Modem Speed” option under Rules » Performance to limit the rate of data transmission. Sadly, though, in my instance the way fiddler handles this is not eally sufficient for me.

The config file for the rule lists the following section :

var m_SimulateModem: boolean = false;

if (m_SimulateModem){
  // Delay sends by 300ms per KB uploaded.
  oSession["request-trickle-delay"] = "300";
  // Delay receives by 150ms per KB downloaded.
  oSession["response-trickle-delay"] = "150";
}

Looking at the comments, it implies that it will add a delay of 150ms to each KB of data returned. Sadly, the amount of data I’m working with is so small that the bandwidth limiting isn’t able to make any difference.

So, now I’m looking for alternate ways to achieve my goal, preferably to limit the data coming back on a byte-by-byte basis rather than per KB chunk. If you have any ideas, please either leave a comment here or get in touch through Twitter (@ZombieSheep)

Thanks a lot. :)

iPad 2 : First impressions…

(Do they still qualify as “first impressions” after owning the device for more than 24 hours?)

Yesterday I managed to get my hands on an iPad 2. Bear in mind that I had always thought of the original iPad as a good idea, but a bit of a waste of time and money – I mean, 400 quid for an overgrown iPhone that doesn’t let you call anyone? That, though, was before I saw the GarageBand demo. I saw one video on YouTube and it changed the game for me. As some of you know, I am often called on the be away from home, so having a very capable 8 track studio in my laptop bag is a big draw.

Anyway, I patiently waited my opportunity to pick up one of the new generation, albeit the bottom of the range 16GB wifi model. They first thing that struck me was how well it sits in my hands. That Mr. Ive is a talented designer, and his stuff always looks the part but I hadn’t realised how natural these devices feel in use.

The bundled apps on the device are pretty good too. Safari has always been a great browser and the iOS version is no exception. The mail client took seconds to configure with my main email account, and the app store experience is a joy after using the Windows Phone 7 marketplace for a few months.

So now came the big moment – installing GarageBand. I was expecting it to be more difficult than it actually was, for some reason. In the end, I just found the app in the app store, clicked on the buy button, and a couple of minutes later I was up and running with my new (almost) pocket sized studio. Having used the full version on my MacBook I was familiar with most if the functions, and it took me literally 10 minutes to get a half way decent recording down using just e out of the box instruments. Adding in the iRig guitar adapter that I bought, I was recording guitar parts that sounded like they had been recorded for a lot more money than I had just shelled out (apart from the dodgy playing, obviously).

So, all in all I’m extremely happy with the iPad 2. If you are a friend on Facebook you may well have noticed a few posts to that effect. ;)

Now, if you’ll excuse me, I have to go explore the app store some more to find a good Facebook client…

20110409-032846.jpg

Barenaked Ladies – Leeds (17/10/10)

OK, first thing’s first – I am not what you’d call a Barenaked Ladies fan. I have a copy of “Stunt“, and I know “One Week” (in fact, my band have been trying to work out how to adequately cover it for a while now), but that’s not the point…. I went to see them on Friday night in Leeds and was pretty much blown away by them.

Obligatory photo from a camera phone
Barenaked Ladies - Leeds 17/10/2010

I can hear you asking yourself now “If you’re not a fan, why did you go see them?” Well, that’s a fair question, and the answer is simple. One of my mates *is* a big fan, and won the chance to go meet the band at the pre-show meet-and-greet. Once again, though, the answer gets a little more complicated – I didn’t go along with her, because she’d already promised the second ticket to another of out mutual friends. I did, however, offer to drive to take them and pick them up after the show (hey, I’m a nice guy!). Anyway, the suggestion was made that I may as well get a ticket and join them, so I did. (Although quite why I dedicated a whole paragraph to that little story is beyond me)

Anyway – the gig. I could ramble on for a while about the support acts, who were great, but I’m not going to. I’m just going to focus on the main event.

As I’ve already said, I was aware of the band, and some of their work, but in all honesty a lot of the material was new to me. Did that matter? Not a bit! The songs I did recognise were performed exactly as I’d have wished to see them, and the ones I didn’t know were catchy enough for it not to matter that this was the first time I’d heard them. The standard of musicianship was excellent, as you’d expect from the headline act. What I really wasn’t expecting, though, was the level of engagement with the audience, and the level of humour with which the whole show was presented. Not “we’re trying to be funny” kind of humour, just a gentle background feeling that I was watching a bunch of guys who were having a whale of a time on stage. I was standing fairly near the back (right alongside the sound engineer, actually – the sound is always great there) but I felt drawn in to the show, felt a part of the good feeling in the room, and felt as if I was the one they were here to entertain. No mean feat, as anyone who’s been up on a stage will tell you.

So, what’s the point of this rambling and unfocussed post? Well, just to tell you that if you get a chance to go see these guys perform you should take it and get out and have a great night’s entertainment. Next time they’re around these parts, I’ll be going again. Maybe I’ll see you there too.

**EDIT** Seems my tweet about this post was re-tweeted by Tyler. Another example of the band’s accessibility, I guess. :)