Secrets of Xbox APIs

As part of the XNA initiative Microsoft have been sharing things that used to only be in the XDK and bringing them into the PC based SDK. I believe PIX was the first of these crossovers and in the October SDK we find 2 more - XACT and XInput.

For anyone who has written any DirectX applications you will know that its never as simple as calling a single line of code no matter how much that seems to be the sensible way. This is due to the level of integration with the hardware and the fact that game developers need to be able to set each and every flag differently to get the required performance for their games.

I spent yesterday and half of today working on a project which I will reveal more about on Tuesday. It needed some gamepad input and it was suggested to me that "it might be cool to use the XInput stuff". Well I'm always up for some beta madness so the laptop still has .Net beta 2, so that will work with the .Net 2.0 Managed DirectX beta assemblies that wrap the new (but released so there is some stability in the mix) XInput API. Of course XInput only reads from the all new Xbox360 controller for Windows (available to buy soon I am assured) which is a bit of a problem unless you attended Meltdown in which case they gave all attendees a controller. So beta controller, beta driver, beta API on an old  beta of the framework in a beta IDE. Sounds fun.

Well it turns out thats not the fun (or really the point of this blog entry). It turns out that while the rest of us have been struggling with DirectInput the XBox team have been able to write code like this: (I typed this from memory since the real code is on another machine - so it may not compile but its close enough)

State state=Controller.GetState(0);
if (state.AButton) doSomething();
if (state.BButton) doSomethingElse();
moveSprite(state.LeftThumbX, state.LeftThumbY);
Controller.SetVibration(0, new Vibration(state.LeftTrigger, state.YTrigger);

AND THAT'S IT.... no initialisation code, no disposing, no shutdown, no cooperative levels.....

No wonder they can write such great games on the XBox. Given this pattern I suspect the API is powerful enough to write code like this:

HaloGame game=new HaloGame(new Version(1.0));
game.play();

Which means the upgrade process is as simple as changing the constant! No wonder they don't let the XDK go public there would be riots in the streets.

Back to reality for a moment, unless you have a Xbox360 controller there isn't much you can do with XInput right now apart from read this. In fact unless you want to support only Xbox360 controllers you are still stuck with using DirectInput. Its probably for the best anyway given the state of the .Net 2.0 Managed DirectX assemblies. Rest assured I will be writing up an Ask The Zman column on this experience - and the smart folk among you might even be able to guess the publication date.

Published 13 October 2005 11:54 PM by zman

Comments

No Comments

Search

Go

This Blog

Syndication