Terrain Saving and Loading

Its been a really long time since I have been here, so, hi again. Anyways, I have a question of how to implement terrain tiles in my game. Right now I create a random height map and have the game loop through the map once to load all the terrain tiles into a arraylist. The game gets rid of the height map and now all the tiles that are in the arraylist have x and y coordinates, an ID of where it fits into the original arraylist index, and some other stuff like a boolean for saying the tile is walkable or not. I didn’t like how much memory the game was using and decided to kind of load the terrain as chunks, but even loading a chunk size of just the tiles on the screen takes a couple secs even on my fast computer.

This is a little sloppy and very early so please be gentle ////. Its not doing exactly what I want it to do right now but this loads all the tiles to fill up the screen when the player moves one space. I’m going to trim it down to only load an area ahead of the player and save n drop the tiles that wont be visible anymore. I’m sure after that the save and load times of only a few tiles would be better but I feel this could be quite a problem when I actually start adding all kinds of objects and stuff to the game. Is having the terrain tiles as objects in arraylist just a bad idea all together? If I change it to just an array of integers or something that represent the tiles for rendering only, I’d lose alot of functionality. Actually… Thinking about it how it is now, the process of creating a new map with all the procedural generation components is actually quicker than loading the chunk that is the size of the screen… Any ideas. Btw the size of the map is adjustable and is set at 500 x 500 for now and looking to make it bigger with additional content.


public EntityManager loadChunk()
    {	
	String file = "src/saves/";
	int i = (((World.getPlayer().getX() - Game.halfWidthInTiles)) + (((World.getPlayer().getY() - Game.halfHeightInTiles)) * Terrain.mapSize)); 
	int j = (((World.getPlayer().getX() + Game.halfWidthInTiles)) + (((World.getPlayer().getY() + Game.halfHeightInTiles)) * Terrain.mapSize));

	EntityManager entityManager = new EntityManager();
	EntityManager tempEntityManager = null;
	
	try{  
	   
	    FileInputStream saveFile = new FileInputStream(file + "map" + ".sav");
	    ObjectInputStream save = new ObjectInputStream(saveFile);
	    tempEntityManager = (EntityManager) save.readObject();
	    
	    	for(int k = i; k < j; k++)
	    	{
	    	    entityManager.getEntities().add(tempEntityManager.getEntities().get(k));
	    	}
	    	
	    save.close(); 
	}
	catch(Exception exc){
	    exc.printStackTrace(); 
	}

	return entityManager;

    }