saving and loading grid co-ordinates at runtime
OK, I have a grid based game and what I want to do is save the co-ordinates of some cells in a list/array/ini/whatever, (think of it as a queue file). Then I want to start a loop which runs through the list, reads the grid coordinates and does an action.
Lets say for example i have a 10x10 grid, and I have a square brush 3x3 grid cells in size, covering the grid from cell 5,5 to 7,7. I want to save these cells into the queue list.
It should look something like this:
x pos,y pos
5,5
5,6
5,7
6,5
6,6
6,7
7,5
7,6
7,7
Once all grid coordinates have been added, a loop will start which reads the number of lines in the file and starts the loop that many times. In this case, the loop will start 9 times. On each loop, it will do some actions to the cells read from that line number.
Loop 1 - Do actions to cell 5,5
Loop 2 - Do actions to cell 5,6
etc
At the moment I am using the ini++ file with two groups named 'x' and 'y', and saving the position under each group, howver I know there is an easier way.
I am looking for the easiest and fastest method of doing this, as my grid is much larger than 10x10 cells and the values will be added/read/deleted many times per second.
Re: saving and loading grid co-ordinates at runtime
Quote:
Originally Posted by bigredron
OK, I have a grid based game and what I want to do is save the co-ordinates of some cells in a list/array/ini/whatever, (think of it as a queue file). Then I want to start a loop which runs through the list, reads the grid coordinates and does an action.
Lets say for example i have a 10x10 grid, and I have a square brush 3x3 grid cells in size, covering the grid from cell 5,5 to 7,7. I want to save these cells into the queue list.
It should look something like this:
x pos,y pos
5,5
5,6
5,7
6,5
6,6
6,7
7,5
7,6
7,7
Once all grid coordinates have been added, a loop will start which reads the number of lines in the file and starts the loop that many times. In this case, the loop will start 9 times. On each loop, it will do some actions to the cells read from that line number.
Loop 1 - Do actions to cell 5,5
Loop 2 - Do actions to cell 5,6
etc
At the moment I am using the ini++ file with two groups named 'x' and 'y', and saving the position under each group, howver I know there is an easier way.
I am looking for the easiest and fastest method of doing this, as my grid is much larger than 10x10 cells and the values will be added/read/deleted many times per second.
I would just use an array. It works in runtime without saving to a file (which I'm assuming that's what ini++ does, as I haven't used it, just the regular ini object which is purely for saving values to a file). Using one of the array object extensions for MMF2 would be far better as you can read/write from memory, not a file. But it also allows you the option of saving the array as a file if you wish, so you can retrieve these values from a file if needed.
Re: saving and loading grid co-ordinates at runtime
Shawn - The ini++ file doesnt save the file to disk unless u specify it too, just like the array file. It can store information in memory.
And I have thought about using an array file, however I already have a few other arrays storing important map information and I want to avoid using another one if possible. I am sure there is another method.
Re: saving and loading grid co-ordinates at runtime
Quote:
Originally Posted by bigredron
Shawn - The ini++ file doesnt save the file to disk unless u specify it too, just like the array file. It can store information in memory.
And I have thought about using an array file, however I already have a few other arrays storing important map information and I want to avoid using another one if possible. I am sure there is another method.
My bad then. I was only familiar with the regular ini object. I don't have an answer to this one. Hopefully someone else does.
Re: saving and loading grid co-ordinates at runtime
Its all good now. I used the MagicDeque object. This object is working absolutely beautifully and has helped me reducing the number of fastloops and actually works a lot faster than my previous method.
Thanks for your suggestion anyway.
Re: saving and loading grid co-ordinates at runtime
Quote:
Originally Posted by bigredron
Its all good now. I used the MagicDeque object. This object is working absolutely beautifully and has helped me reducing the number of fastloops and actually works a lot faster than my previous method.
Thanks for your suggestion anyway.
Thanks for posting your solution. I'll have to take a look at this object myself :)