Archive, XNA

Multithreading for the Xbox 360

Jason / January 27, 2007

When multithreading on the Xbox 360, here are a few things to keep in mind.

Affinity
In multithreaded programming, programmers often lack the ability to specify the Processor Affinity of a thread. Even when API calls are available to specify a processor, it is usually ignored. The reason for this is that modern operating systems have many processes running, each with many threads. The operating system zealously manages processor affinity in order to maximum some metric. read more

Archive

Halo 3 Beta

Jason / January 24, 2007

I have been chosen for the Halo 3 beta… this is awesome!

I received the email yesterday, but it went to my hotmail account (which I rarely check). This is perhaps the best email I have ever received.
I think they have just given me a reason to check my hotmail account more often:
"Keep an eye on your inbox, we will be sending more information about this opportunity soon." read more

.NET, Archive, C#

Throwing More Than Just Exceptions

Jason / January 23, 2007

It is a little known fact (and probably for the best) that the CLR can throw and catch more than just System.Exception and its children. In fact, the CLR can use any type as if it was an Exception.

.assembly ExceptionTestAssembly {}

.class public ExceptionTest { //custom class
//note that ExceptionTest does NOT extend System.Exception
.method public void .ctor(){
.maxstack 1
ret
}

.method static void main() il managed{
.entrypoint //program entry point...
.try {
newobj instance void ExceptionTest::.ctor()
throw //throw a random object

} catch ExceptionTest { //catch the random object
pop
ldstr "Random object caught"
call void [mscorlib]System.Console::WriteLine(string)
leave.s OUT

}
OUT: ret
}
}
read more

Archive, C#, XNA

Embedding Assets Into Your XNA Game

Jason / January 21, 2007

Currently I am a working on a small XNA project whose solution is composed of 4 projects, a DLL, a Windows Game, a Xbox 360 game, and a level editor. Each projects needs access to my assets (currently just 2d sprites), and has raised the interesting question of how to easily share them between each project.

What I had been doing was adding the assets to the Windows game as pipeline content. After compiling it I would then copy the compiled assets from the bin directory, to the bin directories of the level editor and the Xbox 360 game. While this worked, it was error prone and time consuming.

Instead I found that I can add my assets to the DLL as embedded content, and then load them at runtime. Normally you would have probably loaded content by calling the "Load" method of "ContentManager", like:

            _content.Load<Texture2D>("mySprite");

As stated above, the problem with this solution is that "mySprite" would have had to been compiled into the content pipeline. When your assets are added as embedded content, the above method does not work. Instead, you can load your content like this:

Assembly asm = Assembly.GetExecutingAssembly();
Texture2D.FromFile(_graphicsDevice, asm.GetManifestResourceStream("SampleProject.Textures.mySprite.png"));
read more

Archive

Lisp interpreter for XNA

Jason / January 20, 2007

I just found a Lisp interpreter for use with XNA. It was created by Jon Watte in C#, and is compatible with both Windows and the Xbox 360.

For those who are unfamiliar with Lisp, it is a high-level functional language created by John McCarthy in 1958. Lisp is commonly used by artificial intelligence researchers, and could come in handy for adding in-game AI to your next XNA project. read more

.NET, Archive, ASP.NET, C#

Cookie Renaming in ASP.NET

Jason / January 20, 2007

In ASP.NET you can seamlessly rename cookies on the fly with the help the PreSendRequestHeaders and BeginRequest events of the HttpApplication class.

Both events call EventArgs delegates, with the sender object as a HttpApplication instance.

///

/// Called when a cookie is about to be sent to the browser. /// private void CookieOut(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; HttpCookie cookie = app.Response.Cookies["ASP.NET_SessionId"]; if (cookie != null) { app.Response.Cookies.Remove("ASP.NET_SessionId"); cookie.Name = "fooBar"; app.Response.Cookies.Add(cookie); } } read more