Sunday, October 30, 2005

Sunday 30th

Continued with the Test Map module, adding the fine-scroll code necessary to scroll the map smoothly; I took the liberty of peeking through my Citadel testbed code to see how I'd implemented the scroll routine, and it became apparent that I'd need a different approach for both the game and the Editor.

Essentially, I need a scrolling system which will automatically adapt itself around the player's position (or a given co-ordinate, in the case of the Editor). I also need an intelligent system which will allow the user to scroll the map by using the mouse, which will also call for a little intertia.

With this in mind, I spent a good while scouring the Blitz forums and Blitz Coder archives looking for suitable code to study. Most of the examples on offer all seem to work in a similar way, until I stumbled across a fantastic piece of example code which seemed to fit the bill - I'll be studying this code in detail over the next few days!

Saturday, October 29, 2005

Saturday 29th

Hit a stumbling block with today's assigned task (rotating the map 90 degrees clockwise and counter-clockwise), so my focus shifted to the Test Map module, which has been on my To-Do list from day one. Essentially, I want a system which allows the user to instantly 'preview' how their map will look, complete with smooth scrolling, parallax layers, animations, etc.

I started off by creating the basic window, canvas, and buttons (to control scrolling speed, parallax speed, and an Exit button to return to the Editor). As an afterthought, I also added visibility checkboxes similar to those already present in the Editor, to allow the user to toggle layers on and off as required.

Friday, October 28, 2005

Friday 28th

Finished the Tool Tips system by adding the rest of the labels and implementing the calls whenever a new tool is selected. Next, I gave the Fetch Tile routine a purpose in life, and linked it up to the Dropper mode (as an afterthought, I also expanded the functionality to allow Left and Right tiles to be grabbed).

Next came the creation of the Tile Inc and Tile Dec routines; these are based on some code I'd written to increment and decrement the current tile, and intelligently scroll the tile window up or down, depending on whether or not the cursor had moved out of sight. Sticking this code into separate routines allowed me to remove duplicate chunks of code - now all actions which increment or decrement the current tile (ie. the +/- keys, and the +/- buttons on the Anim and Grab panels) are consistent.

Fixed a minor bug in the MiniMap Meta window; variables were being set whenever the pull-down lists were activated, which meant that the Cancel button had no effect - this was naturally a simple tweak to fix. :)

Next up came Move Mode, which had been behaving a little quirky since the addition of a Move icon in the Toolbar. Now you can either click the Toolbar to engage Move Mode permanently (tapping M disengages this), or hold M to activate Mode Mode for as long as needed.

Next I tackled a bug in the Continuous Pen mode, which was causing rogue tiles to be printed when switching from the Tile selector to the main canvas. Far from being an irksome bug that took hours to track down, I managed to fix the problem by flushing the mouse buffer whenever canvases are switched. Simple but very effective!

Wednesday, October 19, 2005

Wednesday 19th

Tried without success to implement a snap-to-grid system, so my focus switched to the Tool Tips, which involved adding the panel and text labels, and implementing the tabber functionality. Threw in a couple of test labels, and the panel works beautifully - it now takes just a simple glance down at the panel to refresh your memory. :)

Tuesday, October 18, 2005

Tuesday 18th

Finished the Fetch Tile routine today, after banging my head on the desk repeatedly (in actual fact, it was just a process of working on each part of the routine in turn). Now the editor can intelligently display the cursor over the correct tile and adjust the scroll register so that the relevant tile is always in view.

Finished up by tweaking my menu code so that the keyboard shortcuts are justified properly (they used to be right-justified, now they're tabbed, for anyone remotely interested!).

Monday, October 17, 2005

Monday 17th

Fixed a minor bug in the MiniMap code which meant that the code had no default values to work from (and thus, was appearing completely black).

Decided to pluck some small tasks off my To-Do list, specifically the Tool Tips system which will provide prompts on using the various tools (after a suggestion by Muttley). At the moment, the program prints a line of text on the Status line, but this is usually lost whenever another action is performed (the Status area is used continually for prompts and messages).

Then I hit upon the idea of adding an extra panel to the Info / MiniMap area of the screen; whenever the user needs prompts, they simply click the tabber and follow the instructions. Full functionality will come later, but already the panel is fairly intuitive to use.

Addressed a small bug in the Grab Panel, which meant that thumbnail images were being generated in 32x32 tile mode, then started work on the Fetch Tile routine (which will hopefully move the tile selection cursors intelligently).

Thursday, October 13, 2005

Thursday 13th

Kicked off by tackling the MiniMap / Meta system as mentioned in the previous entry; managed to eventually track down the problem and celebrated by slapping my forehead repeatedly for being so dumb. Basically, I have a eight variables, each of which stores a Flag value - this value gets checked against the Meta data for each tile, and if they match, the tile is printed on the MiniMap in the relevant colour.

However, the values I was assigning to the variables were in the range of 1-16 (eg. 1, 2, 3, 4, 5...), instead of the corresponding bit values (1, 2, 4, 8, 16...). Once I'd slipped in some code to convert these values, the system was working like a dream.

In the process, I tracked down a small bug associated with the Meta Panel which meant that drawing tools wouldn't function properly when the Meta Panel was being displayed. Luckily, it was just a case of moving a little chunk of code into the right set of checks.

Finished up the MiniMap / Meta system by allowing the user to click on the corresponding colour values to change them. The system is now wonderfully flexible: basically, each tile has 16 Flags (Meta Data); the Meta system allows a Flag value to have an associated colour and thus, any tiles which have that particular Flag set will be displayed on the MiniMap in the relevant colour.

Finished up by adding the MiniMap threshold input system, which allows the user to specify a start and end tile - anything in that range is displayed on the MiniMap. Now that all of the functionality is finished, the MiniMap system offers three different ways for the user to customise the MiniMap view (using Mask data, Meta data, or the threshold input). Who says I never cater for all tastes? :)

Wednesday, October 12, 2005

Wednesday 12th

Not much time spent coding today, but managed to get the Grab Panel functions finished with the completion of the Strip From Buffer command; in a similar vein to the Strip All function I wrote yesterday, this function strips tiles in a continuous strip starting with the Grab Buffer's current location. This is especially handy if you're grabbing tiles that aren't aligned with the tile 'grid'.

The final function I want to add after Beta will be the facility to grab tiles from the Static image using a similar system to the Brush grabbing function (this may sneak in before Beta, however, depending on how hard it is to code!).

Rounded off the night by investigating my MiniMap code to find out why it fails to read the Meta data properly; the user can have the MiniMap draw tiles only with specific Meta values - currently, however, the code has more bugs than, well, than it should. :)

Tuesday, October 11, 2005

Tuesday 11th

More thumbnail code on the agenda, specifically the tile rotate and flip functions, although fingers crossed this should be the last bit of thumbnail code I need to write. Subsequently realised I'd spoken too soon, as I needed to implement the Strip commands from the Grab panel (both of which require thumbnail code). D'oh!

The Strip All function will basically start stripping tiles from the Static picture and copy them into the tileset at a given point. With the potential to completely fill the existing tileset, I needed a way to regenerate the entire tileset as a thumbnail image (this causes a slight delay, but the status bar at the bottom of the screen now displays a "Regenerating thumbnails" message to keep the user informed.

Monday, October 10, 2005

Monday 10th

Not much time for code today, but managed to get a few tasks knocked off the agenda. First up was the Tile Save routine, which I'd neglected to finish properly; as discussed in the last entry, the 128x128 tilesets are actually two rows of 128 tiles (as opposed to one continuous strip). As my Tile Save code was based around continuous strips, a minor tweak was required.

The final tasks involved adding thumbnail code to the copy/paste tile/range routines, which was fairly straightforward - however, the sheer number of thumbnail additions is making me wonder if a modular routine might be quicker. Hmmm!

Friday, October 7, 2005

Friday 7th

First on today's agenda was the tweakage of the Grab functions I've been writing over the last couple of days. It suddenly dawned on me last night that all of the functions are based around a 32x32 Tileset; due to the fact that thumbnail images are used when the Tileset differs from 32x32, I needed to adapt my code so that the Grab buffers are the correct size and that appropriate actions will not only update the current Tileset, but also the thumbnail Tileset.

This was a fairly lengthy process, but relatively straightforward once I knew which areas of the code to change, and after about an hour of changes, checks, and tweaks, everything was working as intended (one of those situations where, after a hard slog changing the code, the program performs exactly as it did before!).

Next came the addition of the I/O routines for saving and loading Buffers and Buffer Sets (the former saves and loads the current Grab buffer, the latter saves and loads all 8 Grab buffers). As this involved tinkering with the Grab Menu, I also took the liberty of tying in some of the menu options with the existing code.

Next I tackled a small bug in my Copy/Paste Range function; essentially, all of the Tilesets are arranged in a long, continuous bitmap file which is one tile high and 256 tiles long. However, the 128x128 Tileset is only 128 tiles long and 2 tiles high, due to the fact that its width would otherwise exceed Windows limitations. As my Copy/Paste code potentially allows the entire Tileset to be copied and pasted, I needed to limit this so that the image size is not exceeded.

After tinkering with the Tile functions, it became apparent that the Tile menu was just too damn big; out came the scissors, and within minutes I'd chopped out the Meta commands and Mask commends and housed them in their own menus. This actually makes a little more sense, as each Panel now has a corresponding Menu.

While writing the I/O routines earlier, the thought occurred to me that the facility to Import and Export a range of tiles would be a nice function (after all, once the range is copied to the buffer it's a single command to save this to disk). Within minutes I'd managed to get the code up and running, though it's apparent that my Menus will need a little bit of tidying up (basically, I'll have to renumber all of the menu commands and their corresponding checks - something of a dog's job but the code will be much more organised as a result).

Thursday, October 6, 2005

Thursday 6th

Kicked off by removing the New and Delete buttons from the Anim panel. After careful thought, rather than allow the user to have as many animations as they want (which is where the buttons in question come into use), I'd have 256 animations already in memory at startup, one for each tile. Should the animation contain more than one frame, it is processed by the animation routine.

The main reason for this approach is partly due to time (I can't waste time perfecting an ideal animation system just for the Editor), and partly due to the fact that deleting and reordering a vast sequence of Types has huge potential for bugs and suchlike. The New and Delete buttons are now Copy and Paste respectively, which is much more useful in my opinion. :)

I also removed the 'Destination' selector from the Anim panel. Essentially, the User would have been able to generate up to 256 animation sequences; the Destination indicator was used to decide which tile on the map would trigger that sequence. While this is ultimately more flexible, again the time factor and bug potential far outweighs the usability; with the new system, the data will be much more regimented and easier for other programmers to strip out what they need.

Next came the addition of the Grab menu, which will compliment the Grab panel (along with the addition of extra commands to Save and Load Buffers and Buffer sets). In order to save memory (and effort!), the various Grab panel functions will be bundled into their own separate routines which my button checks and menu checks will call.

Though making your code portable and modular is something of a prerequisite, more often than not, I tend not to make certain pieces of code modular mainly because it takes so long to set up and call a function, whereas running the code directly within an If...Endif loop is much faster.

The final task of the day involved creating the Copy Range / Paste Range functions for the Tile menu. This was a fairly straightforward task, largely due to the amount of tile copying and manipulation code I've written recently, and once in place turned out to be a rather handy little function.

Wednesday, October 5, 2005

Wednesday 5th

Tweaked the Nudge controls I'd added yesterday, as the nudging was one pixel out at the edges - not a big deal to you or I, but you know how stroppy graphic artists can be! :)

Next came a couple of adjustments to the Tile Grab Mode I'd added yesterday; though it's fairly simple to grab a tile from the Static image, and nudge it into position if necessary, I thought it'd also be nice if the user could have a pixel-perfect cursor mode (as opposed to being fixed to an invisible grid). Thankfully it wasn't too awkward to squeeze into the existing code, and the whole system is becoming a joy to use.

Rounded off the day's session by going through the remainder of the menus and so forth in order to work out precisely what tasks are left; in the process, I also decided to make a number of changes to the Animation system, which will be explained as and when they are tackled.

Tuesday, October 4, 2005

Tuesday 4th

After a brief discussion yesterday with Muttley, one of my test pilots and all-round good egg, we concluded that the SaveImage problem was indeed a problem with Blitz, so today saw me writing a routine that creates a new image, copies across all of the tiles from the AnimImage, then saves out the image file. Phew!

Next came a chunk of code I hadn't particularly been looking forward to; the facility to grab tiles from a Static image. The logic behind the routine was fairly simple, however, and within minutes it was in and working - the user can now jab 'T' to enter Tile Grab Mode. After a couple of tweaks to the code, to check that the cursor wasn't going over the edge of the image, the bulk of the routine was done.

I took the opportunity to limit the number of buffers to 8 - now the user can happily grab tiles to any of these 8 buffers. I finished up by adding the facility to copy from the buffer to the current tile, and vice versa, and then added a Nudge facility so that the buffer contents can be moved in 1-pixel increments for extra precision.

Monday, October 3, 2005

Monday 3rd

Continued with the various tasks required to bring the Grab Panel to life; the good thing about these tasks is that they're all fairly self-contained, allowing me to dip in and code for as little or as long as I want to.

First up came the routine to rotate the tile 90 degrees clockwise - I had planned on using the code from the Brush Rotate function, but this proved problematic due to the way I'd written that particular routine (ie. with no care for anyone else who might want to use it!). Luckily, I managed to shoehorn the code into the existing For...Next loop I'd set up for the Tile Flipping, and after that it was a simple task to add the counter-clockwise code, too.

Next came the Tile Scroll functions, which again were relatively straightforward to add to the existing loop - this means that all of my Tile manipulation gubbins is now contained within a single routine, making it much easier to tweak.

Flushed with the progress I was making, I decided to tackle a few odd tweaks and bugs that had been hanging around (by sliding a bug onto my schedule whenever things are going well I can feed off my enthusiasm and get things done!). First up came the cursor display for the Anim Panel, which required a teensy tweak so that it always displays properly regardless of the Tile size.

Next, I needed to take my Tile thumbnail code - which currently takes any 64x64 Tileset and scales it down to 32x32 for the Anim and Grab Panels - and turn it into a generic routine so that any Tileset being loaded or refreshed has a thumbnail image to accompany it.

Finally came the Tile Save routine, which had been hanging around the To Do list for far too long; now that the Grab Panel is taking shape, however, it seems logical to implement Tile Saving so that any changes made to the Tileset can actually be saved, too. The logic was fairly easy to poach from another routine, but I hit a snag when saving the Tileset - for some reason, the SaveImage command will only save the first Tile in the Tileset. Hmmm. I sense a posting to the Blitz forums coming on!