Since creating track points is already working, the next thing to get done is loading from GPS data. Though before we can process the GPS data, we first have to get it. So the task at hand is to load in the GPS file.
I first had to download the correct file from my Google maps data. I just downloaded the XML version (KML file) of the route instead of the binary one. It seems easier to just parse a text file than first reading up on the data structure of a KMZ file. Though since the coordinates are not rounded values, I have to parse a floating point value. Which may turn out to be trickier than it seems. But we’ll see about that soon.
With the KML file downloaded and ready to go, I loaded it into the game. That was pretty easy. Next I wrote the parsing function. Luckily there is already some code for parsing text. So even that was not hard to do.
However I skipped the parsing of the coordinates themselves.
I just checked for the
Once found I would just use the old test points.
This way I would at least know if the parsing was working up to that point.
Which it luckily is! Now that I write about it I realise how easy it really was. Trying the same thing in C# would have probably taken me longer. Figuring out all the function calls or writing my own since some may be missing. My approach would probably be way different because you would read out the text per line first. Ugh, just thinking about it makes me hate it. This was way easier to grasp and make. And all the code has been written by myself.
So the parsing is working. Though I had to allocate some memory for those track points. This memory is only used to store the data from the file, so I dont want that data to stick around once the track has been generated. I have to make a temporary memory region to easily fix that issue. I think I can just use the transient memory area, as the tilemap is storen in the world memory area. However, I didn’t have enough time to test. It’s always fun when the train is way shorter and there is no spots left to sit and work. So testing it has to wait until the end of the day. Maybe I can have a go at the parsing of the actual coordinates data as well 🙂
On my way home I was able to get some more work in. Trying to correctly parse the coordinates. I won’t be parsing the actual float value for now. I just tried to get the complete string of the value. Then taking that first character and use that as a value instead. This seemed to be working for the first coordinate. But after the first line things went wrong and it took a bit of fiddling to get it right.
In these moments it’s not so smart to work on it in the train.
Just too much distraction and not enough concentration in general.
However it was now processing the file correctly.
Resulting in something like 242 points I think.
But then the
CreateTilemap function got stuck.
Not enough memory was available.
So I kept increasing it until I realised the loop was just stuck at coordinate 220.
I’ll have to figure out what is happening there and then I hope it will all be good (and run in a small memory footprint again haha)