pioneerspacesim/pioneer — pull request #833 by robn (2011-12-01 11:12:36+00:00)
Title: Space, Game and load/save refactor

This refactors much of the codebase to provde discrete `Game` and `Space` classes/objects and all the changes around the place to support that.

`Space` is roughly equivalent to the old `Space` namespace and its global storage. Its a container for all the physics objects and takes care of getting them safely added and removed from the space and making sure they're updated sanely.

`Game` is somewhat larger in scope. In includes much of the game setup/teardown and control code (notably timeaccel) that used to live in the `Pi`, as well as some stuff from `Serializer` and a few other bits and pieces. The idea is that a single `Game` object represents the entire game state at any given time.

`Game` owns the `Player` and the `Space`, and is responsible for transitioning the `Player` between `Space`s as they are created and destroyed. The current `Space` is destroyed when the player hyperspaces, and a new one is created to represent hyperspace (which is just a `Space` with only the player in it). At the end of hyperspace, the `Space` is destroyed and a new one created for the destination starsystem.

I've tried to clean up a good change of the load/save stuff, mostly by moving the dialog out to its own class that can handle all of the work of turning a filename into a `Reader` or `Writer`. Game save is done through the `Game` object. Load is done via a specific constructor and produces a whole new `Game` object.

The main menu and setup/teardown has been given some love. Apart from the "Exit" option, each start option simply has to produce a valid `Game`.

There's some stuff that still isn't done. The two things that do belong in the `Game` are the `LuaManager` and the various `View`s that make up the UI. `LuaManager` is another big job that I don't have the mental space for right now, and the UI is an even larger job because the views assume that they can poke around inside each other and the game state as they please. That's all got to be fixed anyway when Rocket comes along, so there's not a lot of point doing it now. I have made some attempt to let `Game` control the setup and teardown of the `View`s, but there's a few tricky bits it has to work around. All commented with trust `XXX` comments.

Another thing that needs to happen is for `Pi::game` to go away. I'd much prefer everything that needs it (or the `Space` or whatever) to declare that fact in its constructor (dependency injection).

Still another thing that needs to happen is for `Player` to be split into a piece with game-wide state (player attributes, cash, missions, etc) and the physics stuff (a glorified `Ship`). That way the `Space` can retain full control of the player body, avoiding the mess in `Game::~Game()`.

I've tested by doing a lot of hyperspace jumps and testing that flight, autopilot, docking, ship interactions, etc. Loads and saves have been tested throughout this. Everything seems to be working, though I haven't really stressed anything. It should be fine as pretty much all of the old logic code is unchanged, just moved around.