Saturday, June 23, 2012

Outside the Box, Just a Little

There seems to be no end to refactoring, but every step now makes something easier later.  Also, it's made some things easier now, and I've been up to a few new things today.  Rooms now have basic random monster and loot tables, and support is in for different room shapes:

The new ones are just made out of two overlapping rectangles.  I need to fix up the door attachments a bit so they don't do the diagonal thing you see here.

Had to update the display code for these new rooms, since it's no longer possible to just draw a rectangle.  Did a bit of research, skimmed the marching squares article on Wikipedia, and got to work.  To my great pleasure, it worked perfectly the first time.  Nice when that happens.  This algorithm should work fine for other room shapes I want to do later; I'll have to adapt it, though, for rooms with "holes" in them.

Up next, implementing a couple more layout types to get a bit of variety and further explore what works (and looks, and plays) best with the engine's current capabilities.  Then I think I'll get the AI working again (it's been broken since I converted the level indexing from unsigned to signed, quite a while ago).

Thursday, June 21, 2012


Progress rumbles beneath the surface.  I'm reworking things to make it possible to set up different room types while establishing level structure.  Getting some nice healthy refactoring into my programming diet.  Treasure chests are in, though loot tables need to get a lot more interesting.

Also, there's this:

The magenta network is a debug view of the level graph, meant to help me visualize what's going on when generation fails.  It's not quite finished for that purpose (I need to fix some stuff I broke), but it's interesting to see.

Monday, June 11, 2012

More Eye Candy

Today's been a grab bag including graphical tweaks, a new graph type generator, and a lot of rework that's helping me try new things in areas of level gen that had previously been inflexible.  That's a constant battle, but I'm starting to work my way into some new avenues.

The results are sure pretty:

I think once I can get these kind of results a bit more reliably at this size, I ought to be satisfied for a while -- this is definitely enough room structure to play with for now.  Later I'll crack the divide-and-conquer nut and really go hog wild with some big levels that aren't all stretched to annoyance.

There's any number of small tricks that can perhaps be applied at this point, too.  For example, long hallways that twist around only to dead-end at a single room are fairly common; it wouldn't be hard to move those dead-end rooms closer to the source.  I'm also looking into directly adjusting the force pairs between rooms.  This could be used to introduce extra repulsion between "problem" rooms that wind up too close to one another.

I'm putting in some basic treasure chests now, and planning on some more debug visualization stuff because it's just so darn helpful.  I saw a great talk online recently about the value of immediacy in design tools, and it's so true.  Looking directly at what's going on gives me much greater insight about what I'm doing, and extends my grasp.  After that I'm planning some infrastructure related to boss monsters, loot tables, and similar stuff that will pertain to quest design.

Sunday, June 10, 2012

A New Look

Today's screenshot speaks for itself:

I did a bunch of optimization work last night, primarily reworking the way location and feature data are structured and indexed.  Once the major gains had been made there, the remaining slowness was all related to the way I was doing tile graphics.  Since I'd been interested in taking more of a vector-based graphical approach anyway, I decided this would be a good time to take some steps in that direction.  The results are above.

Things may get even more neon from here on out.  The game runs quite a bit faster now too, which bodes well for my further efforts.

Friday, June 8, 2012


Hooray!  I'm back at it after what turned into a couple months' worth of hiatus.  The programming break did give me time to step back and think through some solutions, and now that I'm coding again the progress is coming quickly.

For a start, I fixed what I feel was the root problem with hallway routing by changing my algorithm to go from room center to room center and figure out the doors afterwards.  It's still necessary to avoid all the other rooms, so it's not quite as simple as routing the hallways and then thinking about rooms, but the application of a few elementary set operations proved sufficient for this approach.

Things didn't go perfectly smoothly at first (pretty good though, really), so I wound up finishing work on the level generation visualizer.  Being able to see what was going on proved both fascinating and helpful, and I'm making extensive use of it now.  A* is fun to watch in action.

With the aid of the visualizer, I have been able to significantly improve the capability of the level generation engine.  It's definitely still a work in progress; I need to work quite a bit more on getting the rooms closer together, particularly in the case of larger levels where things can really go wild at the moment.  I haven't got it all robustified yet, so ugly cases still cause some crashes and endless loops, but I've seen it do enough that I'm convinced it can be made to produce an acceptable variety of levels.  Eventually I'll get into things like divide-and-conquer to tackle more ambitious layouts, so the horizon still has plenty to offer.

Okay, enough talk, time to give up the goods.  Here are a few fairly attractive levels from the latest engine:

Hub-and-spoke layout with locks & keys

3x3 grid

Chain of locks and keys.  These can get plenty long.

These are by no means the most complex levels possible now, but things do get a bit spread out looking as we go bigger:

Longer chain of locks and keys, getting a bit spacey.

This will obviously need a bit more work, and I've a number of ideas yet to try, so we'll see what comes of that.

I'll also be spending some time with a profiler to try and optimize out some slowness that's making my debug runs drag.  It's mostly in the graphics layer (ironically), and I upgraded to a new version of the graphics library (SFML 2.0 RC), which helped some, but really it's got no excuse to be this slow and I'm going to have to hammer it into shape.  There should be some good low-hanging fruit, though, so I'm not concerned; at any rate, it runs plenty fast in release mode.

I'm not sure how much longer I'll spend on level generation after that.  Once it's running fast enough, can make larger levels that aren't way too spaced out, and I've got a decent library of structures ready to generate, I think it'll be time to proceed on to other things.  I need to make the monster pathfinding work again and maybe start some other AI inroads, and then I'd like to change gears completely and start focusing on procedural narrative, to breathe life into these generated environments.

Thanks to everyone for staying interested!  There's still plenty more to come.