TMaps

BlitzMax Forums/BlitzMax Programming/TMaps

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I used something similar in a game where you had a 2D playing field that wasn't a fixed size but could potentially be something like 10,000 x 10,000. The contents of the map were created dynamically (like a trail) where the player had been. There wasn't any point using an array, but I did need the quick access to each map 'slot' that an array gave you. So I used a Tmap like data structure, and used a key that was calculated like this:
myKey$ = playerx+"_"+playery

Then it was simple to check if a map place/slot existed like this:
myMap.Contains(somex+"_"+somey)

and then check what it contained like this:
myMap.ValueForKey(somex+"_"+somey)

This system saved a lot of memory, as there were always very large areas of slots with nothing in them. But also had a lot of the structure, flexibility and usefulness of a real array.