ImageTile manipulation

BlitzMax Forums/BlitzMax Beginners Area/ImageTile manipulation

I'm not exactly clear on the question either but it seems you might be thinking of using an array to store all the TImages?

Using an array you can implement a manually-controlled linked list system quite simply. All you need is a `Watermark` which is a variable to keep track of how many tiles are stored in the array (also acts as an index) and a variable to keep track of how much space the array actually has.

Let's say, you have a maximum of 50 tiles,

Local TileArray:TImage[50]
Local Watermark:Int=0
Local Space:Int=50

You load your images in and each time you add one to the TileArray[] you add it at the Watermark position (starts at 0), and increment the watermark by 1. Continue until all tiles are loaded, then Watermark should =50.

You can now use EachIn or similar to go through the array, where the last image to work on or use will be Watermark-1.

Then to remove images, you copy the highest-numbered tile in the array to the position of the tile you want to remove. Ie you overwrite the entry you want released with the highest entry, which is at Watermark-1, and decrease Watermark by 1. This auto-defragments the space in the array. Then you can again use EachIn to go through the array up to Watermark-1.

If you need to keep track of which tiles are which, if it's necessary for your engine, you might then want to maintain another array which acts as an index remapper. You give each tile a number and, at that numbered index in the ramap array (of int's) you store the number of what actual position in the Tile array it is stored at. If you don't need to know which images are representing what, you can ignore this part.

Maybe that helps, I dunno.

I am using these watermarked/auto-defragmenting arrays in my app a lot. When I need to add more items than there is space for in the array I just do array=array[..newsize] - it copies the handles to the objects to the new array, rather than copying all the object data.

You're basically maintaining a fixed space (array of 50 for example) which can be filled by different amounts of items; when you want to add an item you add it at the watermark and increase it by 1, and to remove you copy the item from watermark-1 to the item you want removed and decrease the watermark.