My map loading and rendering process is slow when using very large maps, so I'm looking for ways to make it more efficient.
My current solution works like this:
My map loader uses for loops for loading text based files and reading the map.
It parses the objects in the map and converts them to an array
The map is a text file that stores game map contents as a list of object information.
The input data looks like
(x,y,z),material,blocktype (x,y,z),material,blocktype...Scale does not need stored in the file because it's not implemented .
My rendering for loop traverses the array with a for loop
It checks if the entry in the array contains a pyramid
If so, then it calls the pyramid object's rendering method, taking other parameters
The issue is simply slow rendering due this for loop in my OpenGL rendering code used for calling objects by checking values on arrays. It becomes slow with big objects. How can I make this faster?
I use different map loaders one for networking (receiving player object sending info). Here's one for loading maps:
void MapLoad(string filelocation)
{
string[] map_;
string line = File.ReadAllText(filelocation);//
map_ = line.Split(new char[] { ',', ';', '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
for (int xj = 0; xj < map_.Length; xj += 5)
{
// Here xj is an index of a X coordinate, xj + 1 is an index of a Y coordinate, xj + 2 is an index of a Z coordinate
//object for storing the data
Block_ chunk_block = new Block_();
//coordinates set
chunk_block.set_v1(new Vector3(Int32.Parse(map_[xj]), Int32.Parse(map_[xj + 1]), Int32.Parse(map_[xj + 2])));
//material set
chunk_block.set_v1_material(Int32.Parse(map_[xj + 3]));//1
//block type set
chunk_block.set_v1_blocktype(Int32.Parse(map_[xj + 4]));
chunk_block.set_v1_scale(new Vector3(1, 1, 1));
stuff__.block_file.Add(chunk_block);
stuff__.collision.Add(chunk_block.get_v1());
}
}
//version for position
void MapLoad(string filelocation,Vector3 position)
{
string[] map_;
string line = File.ReadAllText(filelocation);//
map_ = line.Split(new char[] { ',', ';', '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
for (int xj = 0; xj < map_.Length; xj += 5)
{
// Here xj is an index of a X coordinate, xj + 1 is an index of a Y coordinate, xj + 2 is an index of a Z coordinate
Block_ chunk_block = new Block_();
//position
chunk_block.set_v1(new Vector3(Int32.Parse(map_[xj])+position.X, Int32.Parse(map_[xj + 1]) + position.Y, Int32.Parse(map_[xj + 2]) + position.Z));
//mat
chunk_block.set_v1_material(Int32.Parse(map_[xj + 3]));//1
//blocktype
chunk_block.set_v1_blocktype(Int32.Parse(map_[xj + 4]));
chunk_block.set_v1_scale(new Vector3(1, 1, 1));
stuff__.block_file.Add(chunk_block);
stuff__.collision.Add(new Vector3(chunk_block.get_v1().X, chunk_block.get_v1().Y+1, chunk_block.get_v1().Z));
}
}
And here is my rendering loop:
for (int i = 0; i < stuff__.block_file.Count; i++)
{
//block data given to block model object that takes material for textures etc but thats not about problem
block(new Vector3(stuff__.block_file[i].get_v1().X, stuff__.block_file[i].get_v1().Y-2 + walking__, stuff__.block_file[i].get_v1().Z), stuff__.block_file[i], BeginMode.Quads, stuff__.block_file[i].get_v1_scale());
}
