Friday, September 17, 2004

Friday 17th

A welcome return to the land of code saw the start of a major overhaul to the way the Editor stores and manipulates maps. I'd been giving this a lot of thought recently (even when I'm not updating the Blog or programming, I'm still musing over ideas!), and concluded that using Data Banks is the easiest way of storing and manipulating the data.

Why? Well, as previously discussed, it's very difficult to store an array of arrays - every array has to be the same size, and if you redefine one array (for instance, if the user resized the map), you'd lose ALL of the data. However, arrays are useful because they allow you to refer to something - be it a map or list of data - using an offset, making it extremely easy to code routines which work with data chunks of variable size.

However, the system is a nightmare to rewrite for a few reasons; you have a routine which defines the map, one that prints it to the screen, and then the tool routines which allow you to draw to the map. An error in any one of those routines would spell trouble - but how would you know if your line drawing code was at fault, or the routine that displayed the data?

After diving in at the deep end and tweaking several routines, I decided to step through methodically and try them one at a time. Firstly, I adapted the Load routine so I could import an existing map; this allowed me to tweak the map display routine to get it working (after all, I knew what the loaded map was supposed to look like - any errors would therefore be down to the display routine).

Once this was working, I tweaked the control and map initialisation routines, as there was a nasty bug associated with Bank sizes (in fact, precisely the same problem I had on Friday 3rd September - perhaps I should start reading my own Blog!). After about an hour's intense coding, I finally had everything working properly, and set about tweaking the various drawing tools.

Pen Mode was straightforward enough, but Line Mode caused a couple of panic attacks; the numbers used by the routine are floating point, whereas the Data Bank deals with integers - and plotting Floats into an Integer bank causes somewhat unexpected results. After delving into the docs, I found a command that converts Float to Int which worked beautifully.

Although the session started with more than a little dread, I was quite pleased with how things progressed. I also developed my knowledge of Data Banks a little more, and in the process devised a neat way of implementing an Undo feature. Splendid.