Friday, February 22, 2013

Randomness Leaves Town, Randomness Comes to Town, IN SPACE

As I've mentioned earlier, I've got several chunks of code that I want to work on over the next week. Almost all of them have a few properties:

  • Supporting another piece of the code - if I change this bit, that other piece is going to need to change. Part of this is sloppy coding, which I admit to, and know I can do better. But most of it is just tight coupling of what the systems do - if I change the way that ships move, that changes the way that planets need to be laid out. And those connections are usually two-way links; the "birthday cake" diagrams I drew in class about abstraction layers aren't helping me here. Or, you know, maybe they would, if I thought through the problem better. But there's no time for thinking!
  • Perched on a refactoring cliff - the work that I need to do involves taking working code and putting it into a state of not-working before getting it to work again. I should really set up a local Git repository to take some of the risk out of changes like this (also, to lessen my exposure to catastrophic machine failure). I usually like to have lots of incremental work that can go in without destabilizing the game. These changes aren't that.
  • Not well-suited to screenshots - working on economic systems is important, but how do you take a picture of them? I could have a dashboard, demonstrating that the systems are working, but that's not what the user would see. Maybe I should do it, anyway, to prove that it's working to myself. I'm sure to have printf-debugging log file output, perhaps that's sufficient.
  • Self-directed - this isn't a big deal, but some of the stuff on my TODO list has come about from external feedback. Some are requests for features that I've wanted to do anyway, some are other people's ideas of how they'd like to play the game. I need to remind myself that these are all good, and I need to consider them all, and decide what gets in and what doesn't. February 28th is coming up fast, so not everything I want will get in, and not everything that friends suggested will, either. But I'm happy when I get to tell a buddy that his feature is in and working. Most of the big stuff I'm working on is on my personal must-have list, so there's nobody to brag to but myself.
So, that's the knot that I'm going to try to unravel over the next weekend.

I'm happy to say that I put in a little bit of time into the BigWorld procedural universe generation refactoring task, and it's going well. I've moved the planets (aside: I'd like to call these things "systems", as that feels more astrophysically plausible, but it's also more awkward, and the code says "planets") into a new class called Sector. I also have a SectorMgr which provides Sectors to the rest of the game. Is it a factory? A cache? I think that's getting underneath the abstraction - it serves up Sectors based on sector coordinates, and the illusion to the player is that the universe is huge and unchanging (at least, on the level of what planet systems are where). Carve away a little bit at it, and the Sectors are coming in and out of memory, but they'll be there when you need them.

So, right now, the SectorMgr is serving up a single Sector, and that Sector is procedurally (ish) generated from a seeded random number generator. Which is just about indistinguishable from the way the game had been working up until now.

The bit that is noticeable is that I keep reusing the same seed ([0,0]), so restarting the game no longer gives you a new layout of systems. You get a random layout, but it's always the same random layout each time.

One of the next things to do is to allow the player to fly off the edge of a sector and give them a new sector to fly onto. This isn't hard, just a little bit of changing some of the references high up.

Once this gets working, players may notice that they've seen all 1570+ of the hardcoded planet names I've accumulated. This will bring me to another procedural exercise: generating system names. A pretty simple Markov chain generator should get me most of the way. I have some ideas of ways to make it better, including working from both ends; names have interesting suffixes that I want my name generator to produce. We'll see if I'm still that ambitious as I write the code.

Once all that's up and running, the next huge system is the dynamic economic model.

No comments:

Post a Comment