Engineering Windows 7 Blog

I have a kind of love-hate relationship with Windows Vista. I love it on some machines and hate it on others. This has a lot to do with the quality (or indeed existence) of device drivers, some manufacturers seem to have got away with sticking "Vista Capable" on things that were definitely not ready for showtime. More like "Vista Culpable".

You can't blame Microsoft for all these problems, but at the end of the day it is their name on the Vista tin and I hope they get tougher with hardware makers in the future. At the moment all eyes are on the upcoming "Windows 7", which is rather cleverly not pitching itself as the answer to all prayers, the wonder of wonders and the operating system to end all operating systems. Merely something that is better than XP and Vista.

As part of the efforts to keep everyone informed of how the development is going the senior managers of the Windows 7 team (and I do mean senior, these folks report directly to the top of Microsoft) have started an Engineering Windows 7 Blog. This is actually quite a worthwhile read. It gives you a nice insight into the way that enormous software products are created, and the conflicting pressures that the teams are exposed to. I also rather like the way that they are using the same blogging tool as I do, the venerable Windows Live Writer. (although I bet they get more hits than I do).

Casting?

I'm writing some new teaching material at the moment. It is going roughly half as fast as I expected, which is about right in my experience.

Anyhoo, I'm doing casting, where you tell the compiler to convert from one type to another by putting the type in front:

int i, j;

float factor = (float) i / j;

I have to cast i to floating point in the sum, otherwise I get an integer division and no fractional part.

In other words, in the above code if the value of i is 1 and the value of j is 2 I want the value of factor (1/2) to be 0.5 (floating point division) rather than 0 (integer division). I get this result by casting i to float in the sum. C# uses floating point division with floating point operands, and everything comes out OK.

This is a standard computing thing, most languages provide support for casting. And I started to wonder why it is called casting? Popular wisdom seems to be that it is related to casting things in a foundry, where you pour liquid metal into a mould of a particular shape. The shape of the mould determines the result of the cast. So by casting you can change one thing into another.

However, I've thought of another way to look at it. You can think of casting as making a movie. You take an actor (Christian Bale) and cast him as a character (Batman). For the duration of the film the character will behave in terms of the role they have been cast into. This even works when we consider stupid casts. In C# you can't do things like cast a string into an integer. In films you can't do things like cast Christian Bale as City Hall. I quite like this way of looking things, but one thing does worry me. Maybe this is the original meaning, and it has taken me years to figure it out.....

Final TechEd Sessions

Today I went to my final two sessions at TechEd 2008, which is rather sad. I really love these conferences. I only have to get a whiff of brand new nylon carpet (which they must use loads of) to be transported into a world of name badges, backpacks and session planning.

The first session I went to was by Jonathon Kagle who was doing something rather uncharacteristic for a Microsoft Product Manager. He was lifting the lid on the next version of his product, .NET Micro Framework 3.0, and even inviting comment and discussion. He has put a really good post onto the Micro Framework blog describing what is coming down the tracks, believe me it is good stuff.

One of the great things about the Micro Framework team is that they are staying true to their roots. Some products get kind of bloaty and feature creepy as they get older. Stuff gets added which might be useful in some contexts, but not all, and the whole thing gets larger and more complex as time goes by until it becomes less useful with each release. I'm a bit worried about C# 3.0 in this respect, stuff has been added which I don't really see the need for.

This is not happening with the Micro Framework. Version 2.5 actually has a smaller memory footprint than 2.0, as the team have got better at squeezing quarts into pint pots. At one point Jonathon said that they had actually figured out how to add generics (a very useful but by no means essential part of C# 2.0) to the framework but that this would have added around 17K to the memory footprint of the platform, with no easy way to disable it.

That amazed me for two reasons. The first is that someone managed to get generic support into the runtime in 17K of code, the second is that 17K is a tiny amount of memory. Less than a full stop in this text is taking up on the screen. However, in the context of a platform that needs to be able to fit into 400K or so, it is big deal, at around a 5% increase. So they left it out. The Micro Framework will now fit onto a single chip microprocessor (a single 9mm square chip). Amazing.This platform just gets better and better.

The next session I went to was about Linq, which is also amazing. The reason you go to TechEd is to find out things that you'd never get hold of any other way. Like PasteXmlasLinq. You can find it in amongst the samples provided with Visual Studio 2008. For me it was  C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033\CSharpSamples.zip\LinqSamples\PasteXmlAsLinq.

This does exactly what it says on the tin. it converts a file of XML into the Linq code to produce that XML output. it provides a magical way of taking an existing lump of XML and getting code that will write it. So rather than having to mess around with writing elements and building up the structure the hard way, I can just paste the XML source into Visual Studio had have the code written for me. You have to play with it to believe it. If you have any interest in the use of Xml you should know about Linq. In fact, if you work with data in any way (even if you are not even using a database, just objects) you should know about Linq. Dan Fergus, the MVP who gave the talk did a first rate job of showing the power of Linq, and how you can use it to good effect on a mobile device.

Growing your own game content

There are two ways you can get content into games. You can hand craft and design your entire environment, painstakingly the drawing trees, rocks, grass and sky. Or you can get a program to create all this for you. In the first approach you get exactly what you want, but it takes a while and you have to do all the work yourself. In the second you use carefully managed randomness to get something which "grew" by itself.

First thing this morning we were at a talk by the developers of FarCry 2, which is due for release later this year. They've gone for the programmatic approach to making their jungle. Their trees really grow, based on parameters and design settings from the graphics designers creating the game world world. They don't actually create the scenery when the game runs, instead they use a whole bunch of programs to make it before it is fed into the game. The end result was really impressive, with very realistic trees which wave in the breeze, and even come to bits when the weather hits storm force.

I expect that in the future more games will work this way, as the power of the consoles increases and the increasing amount of detail in the game environments makes it harder to make this stuff by hand.

Fraught Software

Some software is what I call "Fraught". By this I mean that it is somewhat unstable, but just useful enough to make it worth living with the problems it causes. Early versions of PowerPoint were like this. They let you create great slides, but they also had a habit of crashing when you thought about saving your deck. At one point I suspected that they might have some form of mind reading ability.

Anyhoo, PowerPoint is now solid, and very good at recovering if anything bad does happen. Photoshop Elements is however fraught. It does what I want, it has a very sensible and useful range of features and it didn't cost me too much. And every now and then it tips over, the most recent one giving me the blood curdling message "Can't open the catalogue". As the catalogue is the file that ties everything else together, this could well be a bad thing as it would have meant re-importing and categorising everything. Fortunately, after a reboot and a fifteen minute repair session we are now back on the rails again, but I'll always be slightly on edge when I use the program. I hope at some point Adobe can get around to un-fraughting the code.

In One Ear

Since my early experiments with speech recognition I had been looking out for a decent head set. I was really pleased when I discovered some Logitech headphones at a knockdown price in our local Staples store.  I took them home and plugged them in and started talking.  And they didn't work very well. 

The sound was indistinct and the recognition was very poor.  I spent a while fiddling with the settings and re-training but it was nowhere near as good as it used to be.  At this point I decided that I might have bought a duff device so I did a little investigating.

Rather surprisingly, results seemed to be equally bad with the headset microphone switched off or even unplugged.  After some investigation I discovered the speech recognition software was still using the microphone inside the computer.  It seems that it doesn't always automatically select the headset microphone.

However, now I've managed to make the switch must handle the speech recognition works an awful lot better.

A tip, you can disable and enable sound devices by going to Control Panel -> Hardware and Sound and clicking Manage audio devices.  This opens up the Sound dialogue. When you disable a device it rather annoyingly vanishes from the list of devices. You can get a device back again, so you can re-enable it, by right clicking in the device window and selecting show disabled devices from the context menu that appears.

Adobe Photoshop Elements 6

Microsoft have stopped making my favourite image manipulation tool. The 2006 version of Digital Image Suite was the last, which is rather sad as I always quite liked the program. Unfortunately, the code is showing its age a bit now, and it doesn't handle raw camera images very well, and so I've had to look around for a new image processing program. Paint .NET is great for a freebie, but doesn't do much with raw images and I also wanted some image cataloguing tools.

So last week I downloaded a 30 day evaluation copy of Photoshop Elements from Adobe, and this week I bought a book which tells me how to use the program (essential in this case because even a seasoned computer user like me finds some of the ways the program works to be quite opaque). Next week (or perhaps the week after) I might even buy the software itself.

I've always had a kind of "dis-affection" for Adobe software. It never seems to quite work properly for me. Their PDF reader is a huge, unwieldy beast for something which is essentially a file viewer, and it really upsets me when such a lowly program insists on rebooting my machine when it has updated itself. It used to annoy me even more when it hid the update confirmation window behind everything else, and brought my machine to a standstill waiting for a response. Having said that, the latest reader does have some rather nice tools that you can use to annotate PDFs which are rather cute, although I guess they contribute to the "bloatiness" of the program and make it much slower to load when all I want to do is look at a document.

Anyhoo, I digress. The Elements installation went smoothly, and I quickly had a picture open for edit. And I got that sinking feeling again. All I wanted to do was darken one part of the image, to hide some of the background. An adjustment layer might have hit the spot, if I could have figured out how to mask it over the bits that I need. A darkening brush might have been nice too if I could figure out how to use it. There's usually a scene in most action movies where the hero gets into the pilot's seat in a helicopter, spaceship, ocean liner or some such and is confronted by a huge, complicated array of controls. You then get a close up of their baffled face as they scan the buttons, dials and levers in front of them. I get that face whenever I use Elements. Stuff I never want to do ("Conte Crayon" anyone?) is right in front of me and stuff I always want to do ("make this bit darker")  is nowhere to be seen. In the end I gave up and resolved to buy a book.

I then had a go with the photo catalogue software. Now, granted, bringing 50 gigs of images into the index in one go might be pushing it a bit, but I was hoping for something a bit more useful then a terse "import failed" message after thirty minutes of hard disk rattling.  I imported the pictures in a directory at a time and this time it worked OK. Then Elements started nagging me to do a backup of my catalogue so eventually I said yes, hooked up an external drive and pointed the program at it. At which point it put 24 thousand images into the root directory of the disk. Most backup programs that I've used create a directory to put their files in. Not Elements. Actually, kudos to Vista here, in that I managed to select all the files and put them into a more sensible place without the file explorer window tipping over.

However, the program is growing on me bit by bit. I've been reading the book I bought to find out what it can do, and it really is a powerful beast. And perhaps I've been a bit harsh in expecting it to just work. We shall see.

Deathmatch Bot Fun

I took some time off from the glossary to have a go in our Deathmatch challenge today. We've run these before and they are always great fun. We write C# programs that control bots in Unreal Tournament and pit them against each other. I'd not had much time to write any code so I quickly knocked up a "happy camper" who grabbed a gun and then took pot shots at anyone who wandered past. If you want to run your own challenge you can find out more here. The going was tough.

2108791890
A tense moment

2108017765
Darren's Ripper Santa does the business (note my best score)

2108016941
Zoe takes first prize from Darren

Why Software Sucks...

There are some books that anyone working with computers should just read. Code Complete by Steve McConnell is one of them. And now I've found another one.

Why Software Sucks... (and what you can do about it)  is by David Platt is a book you really should get. It is not hugely technical. It is not hard to read. It will make you laugh (and if you are a developer promptly feel guilty). It is a text which takes as its starting point the fact that we are not really very good at writing software.

It ties in rather neatly with a lot of things that I tell our students when they are writing programs for other people to use, but it also touches on security and a whole host of other issues, always with humour and always grounded in real life experience.

Even (or especially) if you are not a programmer you must read this book. Excellent stuff.

Live Writer Goes Live

It looks like Live Writer (the thing that I'm using to write this blog) has finally gone, er, live. It was in beta for ages, and the "Help About" screen in my version still says Beta, but now it looks much more like a finished product. All the nice features are still there, along with the plugin structure (which seems to have sprouted a bunch of extra plugins - but nothing as nice as my Flickr Inkifier of course).

If you write blogs and want a lovely place to work, you should take a look here:

http://get.live.com/writer/overview

Get Paint .NET

I've been messing around with images and for some time I've been using a free program called "The Gimp" which can do useful things like layers and transparency. It can probably do lots of other tasks too, but it is such a pain to figure out how it works that I will never know.

For some time I've been looking for a decent free graphics editor which doesn't make me tear my hair out, and luckily I seem to have found one. Paint .NET started life as student project and now is a very well specified graphics editor which is great to use. It has a bunch of artistic effects as well as those features that I need to create images for the XNA games.

If you are after a good program to work with images, take a look here.

The Silliness Starts Here

I've put my first XNA file on VerySillyGames. It is just a silly screen display. The source code will be provided when the book is released. It is a nice example of how you can get really good graphical effects almost by mistake. You can find a runnable version of the program for the PC at www.verysillygames.com. It is optimised for 1280 x 1024 displays on a PC with the XNA framework installed. An Xbox version will be available later.

1580731593
I've added rotation to the original program, let me know what you think

If you are lucky enough to be a student at Hull you can join the VerySillyGames.com development effort, where we are going to take some of the silly game ideas and try to make them real. This time next year we'll all be millionaires. Oh yes.

Excel Prize Competition

I don't use spreadsheets very much, but every year we have to produce a demonstrators timetable, and Excel is how we do it. I've got a very clever spreadsheet that lets you enter things and automatically highlights cells for the demonstrators, counts their loading and all sorts. I'm quite proud of it.

It uses a named range, called Times, which has all the timeslots in it. This year we have added modules and moved things around, and now the named range does not reflect the part of the spreadsheet that I want it to.

And nothing in Excel 97 would seem to let me change this.

The help, like always, tells me in mind numbing detail how to do things which are either too simple for words or too complex for me to ever want to use. I have that sinking feeling in the pit of my stomach that there is a very easy way to do this (in fact I even remember doing it once many years ago) but I don't know what it is.

Very frustrating.

So, I turn to you, dear reader. You have already shown that you are highly intelligent just by the kind of blogs you read (i.e. this one). So prove this by letting me know how to do this "simple" thing. First answer that works wins a Mars Bar.

XNA Bits and Bobs, and the power of XACT

I've added a new section to the XNA Book part. This is where I put all the little things that I've found out about XNA development. I've discovered a couple of things about using XACT which you might find useful. They are here.

On the subject of XACT (the program that you use to create audio content for XNA games) I've gone from mild loathing to strong affection. Sort of a love affair, but with wavebanks. It lets you do really nice things with your samples, so that you can create complex sound stages with only a few wave files. It will change playback settings each time it plays the same waveform, to make a single sample sound like hundreds of different ones. It will randomly select a sample from a range, so that you get a nice variation in sounds. It will even let you bind variables in your program to settings used for playback, so that the sound can get louder on the left when the spaceship moves to the left.

So far I've only really scratched the surface of the tool (which is all I'll have time to do in the book) but if you want a nice way to add sound to games you should take a look. It is free, supplied as part of the XNA 2.0 developers kit.

Accidental Art

1377990827

I've been playing with XNA for the new book (book news coming soon, along with another chapter). As part of this I investigated the use of layers and transparency and what happens if you draw lots of coloured things on top of each other. I ended up with this rather attractive arty looking display which I've made into a clock.

Having decided that the output looked nice, I then reckoned that from a software point of view the code could be a lot better organised. So I went in and tidied things up, re-factored classes, improved the scaling and made the movement of the layers more realistic. And of course the "proper" version looked rubbish.

I'll be making the clock available on verysillygames.com later on. And you can actually see the clock in action here. It is a bit jerky, but it gives you an idea of how it works.


Video: XNA Groovy Clock

Raw Power

My biggish camera can take pictures in RAW format. This means that rather than compressing and processing the image data when it takes a picture, the camera simply dumps the output of the photo sensor into a file. It results in rather large files (around 14Mb in my case) for each picture but it does represent the epitome of quality, as you get all the data from the picture. It also means that you can do things like white balance compensation (making sure that things don't look yellow, or blue or whatever) after taking the picture, rather than at the time.

I was taking pictures of Seoul at night, and unsure about the white balance, so I took a few RAW pictures as well. The bad news was that when I got home, I now had to convert them into proper images. Fuji, who made my camera, supply a truly horrid set of programs to do this. They don't work very well on Vista, and I've lost the disks, so I thought I was stuffed. Until I found this.

These folks have written an image decoder for Finepix cameras that does everything I want. It is free and it works. If you want to play with RAW images and get the maximum quality from your camera, you should download the program and have a play.

1114663591
Raw Seoul

Jetlagged Software

I'm trying a new trick to deal with jetlag. The name of the game is "get enough sleep to stay sane". This means that if I find myself wide awake at, say 2:00 am in the morning, the trick is to go with the flow, work on something for a little while and then go back to bed.

Snag is, this means that I need something to do in the time. So I've decided to start writing silly software in this situation. I've written a daft little application that I'm now using in Korea on the wonderful Smartphone (which gives me another advantage for the device - if I find something I need to make it do, I can just write a program).

You can find out more here.

Note: I nearly bought "jetlaggedsoftware.com" to go with the product but in the end I backed off. Perhaps I'm (gulp) growing up....