Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Devast8or

Pages: [1]
1
Graphics / Re: Drawing Hextiles is slow
« on: March 07, 2016, 10:42:30 pm »
Thanks for your comments guys. I switched from debug-mode and it went down from 16 minutes to 2 minutes! Huge improvement but still long time for such a small map. I identified the delay to be located in drawing for loop for vector columns

 for (int c = 0; c < test.ReturnMap()[0].size(); c++)
      {         
         texture.draw(test.ReturnHex(r, c));     
      }

For some reason the test.ReturnMap()[0].size() call makes the whole loop sluggish.
When switching to a number (100) the time to draw 100 * 100 hexes went down to 1.9 seconds.
I still think it's slow if you go higher like 500 * 500 hexes, at 1000 * 1000 hexes it actually crashes and throws an exception.

texture.setRepeated( true ); improved the speed by 0.5 sec for 100*100 map.

If I use vertexArray do I get same functionality as with sf::ConvexShape?



2
Graphics / Drawing Hextiles is slow
« on: March 05, 2016, 11:37:16 pm »
Hi

I just recently started to experiment with SFML and the idea I have is to build a 2D top down game using hexagonals. I initially started with the idea to build a map editor before I proceed with the game itself. Everything has been working fine until I tried to generate maps larger than 20 * 20 hexes.

In the first test I tried to draw hexes on each screen refresh which resulted in low fps, then I thought well it's a map it will not change so it doesn't have to be redrawn on each frame so I drew it to a texture but it is still slow. To give you an idea a map consisting of 100 * 100 hexes takes approx 16 minutes to draw..

I designed two classes a hex class and a map class.
The hex class derives from sf::ConvexShape and contains a convex shape as one of the members, I'm using it to construct each and every hex.

The map class is built as following
class MAP {
private:
   int rows = 10;
   int columns = 10;
   std::vector<std::vector<HEXTILE>> combatmap;
   
Here I'm using a 2D vector to store each and every HEXTILE object. These are iterated, each hex is given proper x/y coordinates and itsĀ“corners are calculated and stored in a sf::Vector2f.
I'm then calling following method when iterating through the  array.

const sf::ConvexShape& ReturnHex(int r, int c) const { return combatmap[r][c]; }

When drawing I'm using following syntax.

for (int r = 0; r < test.ReturnMap().size(); r++)
   {
      
      size = test.ReturnMap().size();
      for (int c = 0; c < test.ReturnMap()[0].size(); c++)
      {         
         texture.draw(test.ReturnHex(r, c));      
      }
      
   }

I realize that I've probably selected wrong way to implement this but I'm kind of stuck. This is the first time I'm actually working with graphics so the whole concept of drawing/refreshing etc is fairly new to me.. Do I have to go with vertex arrays? I want each hex to be drawn with specific properties like X/Y coordinate, texture etc..

Since it's a map editor the user should be able to create a map with X*Y hexes then change textures in each hex by selecting a terrain type and then clicking on the hex.



Pages: [1]
anything