Thursday, July 04, 2013 Eric Richards
Personal things...

A while back I picked up Frank Luna's Introduction to 3D Game Programming with DirectX 11. I've been meaning to start going through it for some time, but some personal things have cut into my programming time significantly. I recently acquired a two year old Australian Cattle dog, and Dixie has kept me on the dead run for the weeks... It's very difficult to muster up the courage to dive into a programming project when you feel half zombified from getting up at 4:30 to let the dog out so she will stop her adorable yet frenzied licking attacks on your fiance.

But today, I'm going to start. I have not dealt with DirectX 11, nor 10 before; it's only in the last year or so that I built myself a modern desktop to replace my badly aging laptop from 2006. I do have some experience playing around with DirectX 9, so it will be interesting to see what has changed.

As I mentioned, I'll be going through Introduction to 3D Game Programming with DirectX 11 by Frank D. Luna. Atfirst glance, it seems very similar to his previous book, Introduction to 3D Game Programming with Direct X 9.0c: A Shader Approach , which I found to be very well-written, with easy to follow code examples. One wrinkle is that I'm going to be doing this in C#, with SlimDX, rather than in C++ and straight DirectX 11. At my job, I mostly write C#, and have developed a serious fondness for it. Additionally, I've found that attempting to port C++ code over to C# is a somewhat interesting exercise, and not a bad way to learn some of the darker and less-common corners of the C# standard libraries.

I plan on doing a post on each major example. So there may be a couple per chapter, and I don't know what kind of pace my schedule will allow me. If you're interested at looking at my code as I'm going along, you can clone my Git repository at https://github.com/ericrrichards/dx11.git. I'm not going to include the original book code (I couldn't find a license specifically for the code, and I'm struggling to parse the legalese on the inside cover of the book), but you can download it from the book's website at http://www.d3dcoder.net/d3d11.htm.


Tuesday, November 13, 2012 Eric Richards

Lately, I've been doing a lot of web applications, with C# on the server and ASP MVC/Razor/Javascript clients.  Javascript, especially with jQuery, is really wonderful for manipulating html, but there are a number of things that I've discovered that are unpleasant.  One of the most irritating to me, thus far, is the lack of syntactic sugar for defining default values for  parameters passed to functions.  In other languages that don't support default parameter values, you can often get around this through function overloading - by first defining a function with all the possible arguments, then defining functions with a subset of those arguments, and then calling the ur-function with the missing arguments substituted with default values.

This example is unnecessary in C#, since the language supports the following:

There are a couple of ways I've found to do this in Javascript, neither of which is particularly appealing:

Now, it may be possible to use the C# style syntax if one uses CoffeeScript or TypeScript; I haven't done enough research to know.  But it would be wonderful if javascript supported that syntax natively, just to reduce the amount of boiler-plate that you have to use.  Boilerplate is almost always bad; it introduces the possibility of simple mistakes.


Monday, February 27, 2012 Eric Richards

Lately, I've been working on a 2-D, hex-based strategy game, in the vein of the old classic, Civil War Generals 2 . Hex grids are a staple of wargames, like the old 5 Star SSI games (Panzer General and all of its descendants), although they've also turned up in some newer games, like Civilization 5 and Battle for Wesnoth.

Although they've been around forever, resources on coding hexmaps are somewhat scanty, in comparison to other things you might want to do with hobby game dev. A list of some canonical articles:

Naturally, a lot of the same algorithms you'd use with square grids are equally valid on hex grids. However, often times, those algorithms require some tweaking to work correctly with a hexagonal grid, and its not always easy to understand how they need to be tweaked without a good deal of iteration.

One thing that I found particularly difficult was understanding the correct way to compute distances in a hex grid. Amit's site has some valuable information, but, as much of it is really old, featuring archived newsgroup posts with ascii art and code written in nearly defunct languages, or worse, links that no longer exist, it is really more difficult to understand than it need be.

I'll start with a brief overview of hexagonal grids, and their typical representation.

Below, you'll see a hexagonal grid.