Well, I've been working on this full-blast since I started it (about 66 hours ago... don't worry, I *did* sleep on occasion), and I FINALLY figured it out.
The algorithm has been tested with several layouts (from very simple, to as complex as the layout pictured below), and seems to be working just fine.
The idea is that I wanted the "void" between walls to be (more or less) invisible, while only using two tile types -- wall, and floor. Now, using blocks would have been simple, but quite boring IMO. Could also have gone the route of making graphics for all possible wall configurations, but that would require a lot of hassle (for map-building, AND graphics design, AND modifying graphics).
With this algorithm, the effect is accomplished. It basically starts at point 0*0 (in pixels), and "follows" the wall tiles in a counter-clockwise manner. It goes through each tile, incrementing the X/Y of a point, until a corner is found. When a corner is found, a point is plotted at the proper X/Y coordinate, and turns relatively either left (by default) or right (if there is a wall at the relative-right of the current tile being tested).
It was a pain in the butt getting this thing going, but, you know what? It's GOING.
Here's a basic rundown of the algorithm (in pseudocode):
Code:
Create a "temporary" point at 0/0
Create a tile tracker (simply stores X/Y of current tile)
Create a directional tracker (stores direction of travel)
Set initial direction to down (90 degrees)
Loop until done:
Get current point's offset (in case it is "inside" a tile)
If our next tile is a wall:
If there is a wall to our relative-right:
Go "inside" tile by 1/4
Plot point
Turn right
Reiterate this tile
OR: If there is NOT a wall to our relative-right:
Continue in current direction
Plot tile
OR: If our next tile is NOT a wall:
(Reiterate this tile after the following checks)
If the next tile in current heading is out of map bounds:
If there is a wall to our right:
Go "inside" tile by 1/4
Plot point
Turn Right
OR: If there is NOT a wall to our right:
Go to edge of map according to heading
Plot point
Turn Left
OR: If the next tile in current heading is within bounds:
If there is a wall to our right:
Go "inside" tile by 1/4
Plot point
Turn right
OR: If we are "hugging" the map bounds:
Go "inside" tile by 3/4
Plot point
Turn left
OR: No wall to right, not on edge of map
If we are on "outside" edge of tile:
Go ahead 3/4 tile
Plot point
Turn left
OR: We are "inside" tile:
Go ahead 1/2 tile
Plot point
If our last plotted point is at the same coordinate as the first, we're done!
End loop
It's still rough (I could probably move the check for relative-right tiles higher up in the hierarchy, since that check is required in all cases, and takes precedence over pretty much everything else), but I'm happy that I got it working!
To demonstrate the code in action, here is a "before-and-after" image, which shows the map as plain tiles, and with the tracing highlighted, and then with the "final" product:
