This past week(ish) has seen some important code improvements going on, with a lot of work being done to fix up the scene management system. I stress ‘fix up’ in a positive sense. It worked, but needed to be made better, and extended to support the more demanding needs of the growing code base.
As a consequence, I have now also lobotomised the Autopilot (almost literally). It had become somewhat of a ‘mare to deal with, and after some consideration I realised it was doing too much that it didn’t really need to. Consider the Autopilot in a plain. Quite simply, it maintains altitude, heading, and speed. Nothing else. (Ok, these days this is becoming increasingly ‘less true’ but bear with me…)
My Autopilot was considerably different. It plotted courses between star systems, in 3D space with no defined ‘up’, and has to avoid stars, planets, stations and all manner of moving obstacles – such as ships. It also provides a docking/undocking facility.
And there was the rub – that’s a lot to take on. Especially when it has to deal with the multiple scene hierarchy being used to portray an entire galactic cluster in one go. After considering this, it became obvious there are two clearly defined roles at play.
1) The Autopilot
Taking the ‘dumb-stoopid’ ethos, it should just maintain a velocity, and do as little else as possible. Almost like Cruise Control on a car. If the player speeds up or slows down, the Autopilot remains on and will correct these changes over time. If the player adjusts the speed the Autopilot is set to, it will then maintain that speed. However, if the player alters course, then the Autopilot can do one of two things; turn itself off, or correct the course once the player stops mucking with it. The only other chore is to avoid ramming into dynamic objects (other vessels, asteroids, etc.)
2) The Navigator
This handles all the complex stuff, such as plotting courses based on the current drive system, chosen destination, current location, obstacles and so on. That’s all it does. Nothing else.
Now these two systems will interact with each other quite closely. The Autopilot will be given a Navigator, who will plot the course. The Autopilot will then aim to follow the course as closely as possible, unless interrupted. If it is taken off course too much, the Navigator must re-plot the course to the original destination from the current location. And so on, so forth.
In Software Engineering terms – the above is called the ‘Single Responsibility Principle’ – ie. Do one thing, but do it well. This makes changing things, debugging and improving it a lot, lot, lot easier.
So in short, now I can give the Navigator all manner of complex things to do – say plotting a course through an asteroid field and the Autopilot won’t care. It will just ask the Navigator ‘Hey, bud, where do I point this thing at?’
Comments are closed.