I'm using a mid-point displacement algorithm to generate a map, and the height values are then stored in an array.
The trouble I'm having is loading the numbers back out of the file and into the array when i press F7.
Here's my code for the reader/writer object:
It doesn't give me any Errors, but doesn't reload the map.public class Writer { final int DATA_SIZE = 257; FileWriter fw; Scanner sc; File filename = new File("savedmap.max"); public void write(MPDGenerator mpd) throws IOException{ fw = new FileWriter(filename); fw.write("version=1.0 seed="+mpd.RSEED+"\n"); for(int j=0;j<DATA_SIZE-1;j++){ for(int k=0;k<DATA_SIZE-1;k++){ fw.write((int)(mpd.data[j][k]+2000)); } } } public void read(MPDGenerator mpd) throws FileNotFoundException { sc = new Scanner(filename); sc.nextLine(); for(int j=0;j<DATA_SIZE-1;j++){ for(int k=0;k<DATA_SIZE-1;k++){ if (sc.hasNextInt()) { mpd.data[j][k] = (int) (sc.nextInt()-2000); } } } mpd.print(); } }
mpd.print(); is the method in the generator which converts the height values into a texture array for the renderer(which uses lwjgl)
the +2000 and *-2000 is so it looks neater in the file.