Tuesday, March 30, 2010

Annoyances with C#'s DirectoryInfo.Delete()

Taking a small break from writing up a game design doc for my iPhone game. It's interesting being the one actually writing a doc for a game, rather than reading one made by someone else. It does make me appreciate the amount of thought and work our designers put in.

Anyway, last week at work I was writing a new C# console utility to automate directory clean-up tasks on our build server. Things went pretty well until I hit a snag with DirectoryInfo.Delete(Boolean) not working properly and throwing a constant stream of exceptions. It ends up it was error'ing out because the directories I was trying to delete (which contain a good number of sub-directories of arbitrary depths, and several thousand files), contained a number of read-only files. After looking around a bit, it appears this is intended behavior, as it follows the idea of the pop-up notification users get when they try to manually delete directories.

To get around this, I ended up creating a simple method to iterate through all directories and files under a particular directory, and set all their Attributes to normal. Sorry for the formatting.

// Set attributes on all dirs and files in the passed in directory to 'Normal'
void SetDirectoryContentsToNormal ( DirectoryInfo Dir )
{
if ( Dir.Exists )
{
Dir.Attributes = FileAttributes.Normal;
DirectoryInfo[] SubDirs = Dir.GetDirectories("*", SearchOption.AllDirectories);

foreach ( DirectoryInfo SubDir in SubDirs )
{
SubDir.Attributes = FileAttributes.Normal;
}

FileInfo[] FilesInDir = Dir.GetFiles("*", SearchOption.AllDirectories);

foreach ( FileInfo file in FilesInDir )
{
file.Attributes = FileAttributes.Normal;
}
}
}

This does cause a little pause when running, however for our particular circumstance it's perfectly fine because the tool runs only once a day in the early morning.

Sunday, March 28, 2010

2010 Census

Finally got around to filling out my 2010 Census. If you received one make sure to fill it out as well. I will say I was surprised how short it was, I thought it would have a lot more questions. There are so many instructions and help hints and clarifications on the form I expected it to be more complex, I thought I did something wrong when I finished in about 10 minutes. Funnily enough, there was a note at the bottom of the form saying on average it would take about 10 minutes.

Thinking about it though, I can see why they had that much help embedded on the form. The Census is done by the Gov. to help determine the distribution of the population; and the results are used as the basis for policy decisions, budgetary allocations and government representation for the next decade. Making sure it's as clear and precise as possible is extremely important.

I do wonder how many iterations, focus tests, expert reviews and God knows what else was done to test the usability of the final Census form. Just the fact they had the 10 minute estimation means some of their testers had the same anxiety as I did...

Friday, March 26, 2010

Looking at website stuff

Finally decided I need to start learning more about web technologies. This area has been a big hole in my field of knowledge, and I figured I need to address that. First thing first has been figuring out WHAT web technology to learn, there are quite a few options out there and narrowing them down is a little daunting.

I'm leaning heavily toward ASP.NET, as I'm passingly familiar with the .NET framework now and feel comfortable working in that sandbox. There's also the huge benefit of being able to use Visual Web Developer IDE, which at first glance appears extremely powerful and well documented. My boss has worked on web stuff on and off for the past 10 years or so, and original came from a php background. He's been rebuilding his website with ASP.NET MVC, and he's enjoying it quite a bit. Personally too, I really don't feel like learning php/javascript all that much. I could learn them, but since I'm currently working on 2 other projects right now, I really don't have a ton of extra time to spare learning completely new languages. Being able to work in libraries and frameworks I'm already working in (.NET) is a pretty big draw.

The next step is actually finding a hosting plan...

Sunday, March 21, 2010

Annoying distractions

I was working on my iPhone game on Sunday, and wanted to load the latest build onto the device so I could test some stuff out. When the build came up on the screen, the main menu looked suspiciously like the old version of the game, and didn't contain the new test map I wanted to try out. I figured I did something wrong so I went back to XCode to 'Clean' and 'Build' my executable again...and received an Error in the output.

It ends up my iPhone developer certificate had just expired. In hindsight, I'm very glad this issue came up when it did. Since it was a Sunday I had the extra time to renew my iPhone dev certificate, and because the change I wanted to test was obviously not there, finding the underlying issues didn't take very long. It was an annoyance though. I ended up wasting about 20 minutes getting my stuff back in order and at the point I could build against my device again.

Oh well, at least I don't need to worry about this again until next year.

Thursday, March 4, 2010

Optimization fun with new project

I'm working on an iPhone project with a buddy, and the progress has been slow-ish going so far. Our biggest problem is committing to an idea; we have a good number of them, however we haven't found a gameplay combination we're fully ready to jump on. I feel like we're getting closer though, we've done a good job of bouncing new ideas around and trying to prototype stuff out.

While we're figuring out gameplay, I'm working on creating some generic utilities to assist us in development and iteration. One item that comes to mind is a search method I wrote several weeks ago. It provides a nice API method for finding a specific object by a name within a hierarchy of objects in the game scene. This method (call it FindGameObject) worked fairly well, however I found some limitations to it which I knew would cause a slowdown on the iPhone given the number unnecessary operations I was doing. Tonight I decided to trim this down to make it leaner and meaner with some ideas I came up with.

First thing I did was write a test script to provide profiling support and get a baseline of how much time it took to run 10 million searches using FindGameObject on a deep heirarchy (about 8 objects). I decided on 10 million somewhat randomly, however it was deliberately a large number to enhance the visible impact of small changes. Then I wrote the new version of my method (call it FindGameObject2) with my new changes and hooked it into the test script. The results were:

FindGameObject - Took: 6.948123 sec to run 1000000 lookups
FindGameObject2 - Took: 5.916583 sec to run 1000000 lookups

This is a rough average of about 5 runs, not a scientifically acceptable test set but good enough for our purposes. Comparing against the current functionality, you can see I gain ~1 second when doing 10 million lookups, which is about a 15% increase

Before I finish I must mention these tests were run on my PC dev machine, not the actual iPhone hardware. This makes it especially important to possess a test case I can reliably run on the iPhone hardware, so I can compare my changes against the original functionality on the target hardware. However I expect my optimizations to yield a comparable speed increase on the iPhone hardware.