I’ve been intending to update the XNA 2.0 game engine we made for Take a Stand into something cleaner running under XNA 4.0. Code notes follow on setting up the project and porting the first bit of code over: error logging classes.
The name of our Visual Studio 2005 project, started in 2009, was “BaseSystem” out of no other reason than it was the base. I’ve named the new version BaseSystem2.
The strategy will be to port function from the old into the new, cleaning up along the way. There are some basic 2D graphic routines I want to port just so we can write text on the screen and support our console functions. Then, I would like to add some basic 2D GUI functions that make more sense than the old widgets. Toward the end of the project, we came up with better ways to organize 2D screen content on top of the 3D.
There is also a matter of just revisiting the game initialization and setting of XML-based runtime parameters. There’s plenty to do. I’ll document this step-by-step, and clean it up later.
Create the Project
I installed Visual Studio 2010 Professional, and then XNA Game Studio 4.0 Refresh on it. Created a new C# Windows Game solution called BaseSystem2. This created a few default program files:
I also opened BaseSystem under Visual Studio 2005, and did a side-by-side comparison of Program.cs. This is the stub program that contains the Main() entry point in the Program class. It’s a static entry point, and I think all C# programs start like this.
The only thing it really does is create a new Game instance, and then calls its Run() method. This is where all the XNA magic happens, so that should be far more interesting.
Comparing this to the BaseSystem (hereafter referred to OldBase), there’s some additional things we’ve crammed in here that I’d forgotten about. There is a global exception handler adopted from doogal.co.uk. This writes our error logs to disk for us. It’s part of our Utility classes. I think we can create a place for it in a Debugger namespace. I might as well move that code now.
Ooops, have to download the OldBase code, so I can copy it to NewBase. Ugh, I don’t like the way that VisualStudio named the various components…too many folder named BaseSystem2! I renamed the files and directories, then edited the .sln and .prj files to refer to the new directories after double-clicking the .sln file showed that there were reference errors. Double-clicking the solution file didn’t open Visual Studio 2010 the first time, though, after making this edit. Somehow the “default program” was set to use “Visual Studio 2010 Version Selector”, which didn’t do anything, as a result of that error. I just reset it to use VS2010.
Ok, now I can copy/paste some classes in! Creating “Debug.Logger” for these logger classes. I first tried to “add existing item”, but this didn’t create the folder hierarchy. I had to create the folder structure first, then add the files to that folder. I guess that’s OK…the folder hierarchy in the Solution view doesn’t have to match the disk layout. That’s probably more flexible.
I probably have to rewrite the namespace declarations for these files too. I’m also noting that TextFileLogger and LoggerImplementation can’t see the System.Windows.Forms package. VS2010 suggests I’m missing a reference. Let me see what references are here in the Solution Explorer:
It’ll be interesting to look through this later and see what’s in those references. A reference is how one links to a library, I guess, in Visual Studio 2010. I wonder how they are implemented or exist as files? Looking at the properties for the “System” reference:
- It’s an “Assembly”
- C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.0ProfileClientSystem.dll
A C# program maybe isn’t statically linked as in the old days. Perhaps this library is a hardcoded path and the system loads it on demand. Will have to read up on that. ANYWAY, let me see if there are difference references in OldBase:
So there are some differences. Three of these are game-specific (Farseer, Softimage, XSIXNA). The others might be new to Net 4.0 or renamed. I see I have to add System.Windows.Forms here. But how? Let me try right-clicking.
Add Reference -> .NET -> System.Windows.Forms…. that was easy. Let’s see if the errors have gone away in the loggers…yup.
At this point, we should be able to build…oops a few missing references. A function called HttpUtility.UrlEncode() doesn’t exist. Doing a google, I find it’s part of System.Web. I add that reference…but wait, System.Web isn’t listed. STUCK! A quick google, and apparently System.Web is part of the .NET 4 framework, but Visual Studio defaults to something called the .NET CLIENT PROFILE, which is a subset of the complete .NET framework. The idea is that it’s smaller, and therfore deploys smaller. Changing the “Target Framework” can be done by going to the project properties (Project Menu) and selecting the Application tab. I changed it from “.NET 4 Client Profile” to “NET Profile”. Now I see a lot more System.Web references available, including the one I want. Success!
The two remaining errors refer to missing stuff from OldBase. One is a reference to BaseGame, which is called Game1 in NewBase. I need to move this, actually, into my namespace hierarchy and clean it up:
- My ‘Engine’ solution has a classes folder, which might not be good practice. I probably should just let the folders live outside of this.
- However, there are other folders in this same level, the bin and obj folders. I’m going to rename them to _bin and _obj so they sort toward the top by modifying project’s Build properties…however, i don’t see a place to set the obj output. Hm. Google shows that you can add two properties to change this by editing the .csproj file. I did this, and it works.
- I’m just trying to make a clean directory here…sigh. I’ve made a directory manually called _src, and will try adding an existing item. Argh, this is annoying. The folder hierarchy in the solution explorer is what matters, apparently.
Oh well. I reverted all those changes and will live with “source” being in my namespace. It seems retarded…I must be missing something. I supposed I could manually rename all the namespaces as I create new files, but I would rather not.
I’ve added the stuff in, and commented it. I added a Singleton class based on Bretton’s original, except I added an “S” accessor variable in addition to the verbose “GetSingleton()” call. Also documented some of the interesting features he’s using with the Generic class.
So what do I have now? The beginnings of BaseSystem with a skeleton outline.