Skip to main content
added 61 characters in body
Source Link

Post Reopened by DMGregory
Cleanup
Source Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

Need advices for speeding Speeding up map rendering

Map loader uses for loops forMy map loading text based files then it stores them in list then for loop inand rendering takes data it parses them then sends them to opengl but itsprocess is slow when having maps thatusing very large any alternatives formaps, so I'm looking for loop in this method thanks

Map is file that stores game map contains list of object information

i firstly read the map

then parse them convert themways to arraymake it more efficient.

rendering use ifs in for loop check if first one contains pyramid then call pyramid object by taking other parametersMy 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 simply is simply slow rendering due this for loop in opengl render areamy OpenGL rendering code used for calling objects by checking values on arrays

but thats. It becomes slow with big objects need advices thanks

heres the code. 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

Language CSharp:

      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

    //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));
                
            }
    
        }

heres rendering

   

       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());
                       
                         
                        
                    }

input data looks like (x,y,z),material,blocktype (x,y,z),material,blocktype..
scale does not need stored on file due its not implemented 
```

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());        
}

Need advices for speeding up map rendering

Map loader uses for loops for loading text based files then it stores them in list then for loop in rendering takes data it parses them then sends them to opengl but its slow when having maps that very large any alternatives for for loop in this method thanks

Map is file that stores game map contains list of object information

i firstly read the map

then parse them convert them to array

rendering use ifs in for loop check if first one contains pyramid then call pyramid object by taking other parameters

issue simply is slow rendering due for loop in opengl render area used for calling objects by checking values on arrays

but thats slow with big objects need advices thanks

heres the code

different map loaders one for networking (receiving player object sending info) one for loading maps

Language CSharp

      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));
                
            }
    
        }

heres rendering

   

       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());
                       
                         
                        
                    }

input data looks like (x,y,z),material,blocktype (x,y,z),material,blocktype..
scale does not need stored on file due its not implemented 
```

Speeding up map rendering

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());        
}
added 44 characters in body; edited tags
Source Link
      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());
               
            }

        }
  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_();
            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));
            chunk_block.set_v1_material(Int32.Parse(map_[xj + 3]));//1
            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));
            
        }

    }

heres rendering

   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());
                   
                     
                    
                }

input data looks like (x,y,z),material,blocktype (x,y,z),material,blocktype.. scale does not need stored on file due its not implemented

     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));
                
            }
    
        }

heres rendering

   

       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());
                       
                         
                        
                    }

input data looks like (x,y,z),material,blocktype (x,y,z),material,blocktype..
scale does not need stored on file due its not implemented 
```
  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_();
            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));
            chunk_block.set_v1_material(Int32.Parse(map_[xj + 3]));//1
            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));
            
        }

    }

heres rendering

   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());
                   
                     
                    
                }

input data looks like (x,y,z),material,blocktype (x,y,z),material,blocktype.. scale does not need stored on file due its not implemented

      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));
                
            }
    
        }

heres rendering

   

       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());
                       
                         
                        
                    }

input data looks like (x,y,z),material,blocktype (x,y,z),material,blocktype..
scale does not need stored on file due its not implemented 
```
added language tag
Link
Pikalek
  • 13.4k
  • 5
  • 49
  • 54
Loading
deleted 2689 characters in body
Source Link
Loading
added 2589 characters in body
Source Link
Loading
added 4082 characters in body
Source Link
Loading
added 322 characters in body
Source Link
Loading
Post Closed as "Not suitable for this site" by DMGregory
Source Link
Loading