Saving Waypoints to a File

BlitzMax Forums/BlitzMax Programming/Saving Waypoints to a File

mothmanbr(Posted 2007) [#1]
Hi,

I wrote a function that will navigate my game map and create waypoints. The waypoint is an object with X and Y positions, and a list of pointers to the adjacent points. Since this function takes some time and the maps won't ever change, I decided to only do this once and save the waypoints to a file.

But there is a problem... If I save only the location of the waypoints, then the pointers to the adjacent points will be lost. If I also save the adjacent points, I'll go into an infinite loop saving the same points again and again. So I could just mark what points were already saved. But then I'll have a problem whenever I load the points...

How can I save this without losing the adjacent points? I thought about giving an integer ID to each point, so I only save to the file the ID to the adjacent points and after loading all of them, I only move through each point changing from the ID to a pointer, but I have a feeling this is not the best way to do things...

I'll also take suggestions of an alternate way to keep track of the possible paths. The maps only have 2 areas, passable and impassable. The impassable areas get no waypoints. Whenever an entity spawns, it takes the closest point and follows the adjacent points to reach its goal.

Thanks in advance :)

Edit: Another solution I thought of is keeping a Map-like type that keeps track of the waypoints that were already loaded or saved. When I give it the coordinates, it'll look for a waypoint with those coordinates in a list. If found, it'll return that point. If not found, it'll create and then return the point.