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

Author Topic: Questions and problems with sf::thread  (Read 8293 times)

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1841
  • Not doing gamedev/using SFML lately
    • View Profile
    • Email
Re: Questions and problems with sf::thread
« Reply #15 on: September 01, 2012, 10:38:33 pm »
Do you have only one huge texture for tileset? Maybe try making a class that takes window reference and then draws chunks of map(each chunk being class object containing small vertex array) that fall in view, it's substantially easier when there is only one texture.
I'm not using SFML nor doing any gamedev lately.

Brodal

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: Questions and problems with sf::thread
« Reply #16 on: September 01, 2012, 10:53:52 pm »
Nay, I draw  bunch of tiles to several larger textures, 1 texture is x = (1920/2), y = (1088/2) in size. So instead of calling draw for a couple of thousand tiles, I call draw 4 times. One for each of the larger textures containing tiles drawn onto them.

FRex

  • Hero Member
  • *****
  • Posts: 1841
  • Not doing gamedev/using SFML lately
    • View Profile
    • Email
Re: Questions and problems with sf::thread
« Reply #17 on: September 01, 2012, 10:57:48 pm »
I mean if the things you draw are all from one texture/no texture? And how many tiles do you draw per call?
I'm not using SFML nor doing any gamedev lately.

Brodal

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: Questions and problems with sf::thread
« Reply #18 on: September 01, 2012, 11:03:53 pm »
I don't fully understand what you mean so I will clarify how I do things. All tiles are their own objects, they do however use references to textures as not to waste memory. These tiles are then drawn onto larger textures. These larger textures are then drawn onto the screen. So the wast amount of small tiles are not iterated often and they do not take long time to draw onto the textures themselves, It's the creation of the textures that is taking to long. The reason that drawing onto the textures doesn't take long is because the tiles are grouped into different std::vectors depending on where on the screen they are, each large texture has a vector associated to it. The reason for this is so I dont waste alot of cpu time iterating through every tile on the screen, I just iterate through the relevent ones. So to the problem is creation of the textures, not the drawing onto them. I have checked this several times with timers and know for a fact that the RenderTexture.create() function is one of the things that is causing the slowdown.

FRex

  • Hero Member
  • *****
  • Posts: 1841
  • Not doing gamedev/using SFML lately
    • View Profile
    • Email
Re: Questions and problems with sf::thread
« Reply #19 on: September 01, 2012, 11:07:24 pm »
Would it be feasible to merge your tiles into vertex arrays of quads?
(ie : you don't ever move, rotate, scale them, they use one or very few sf::textures for their graphics)
I'm not using SFML nor doing any gamedev lately.

Brodal

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: Questions and problems with sf::thread
« Reply #20 on: September 01, 2012, 11:57:06 pm »
I have never before used vertex arrays, so it might be possible.  Do you know any site that explains how to use them?. I dont move rotate or scale these, they are static. I do however need to be able to remove and add new ones during runtime. But I'm guessing that wouldnt be a problem when using vertex arrays.

You gave me a very good idea with the usage of very few sf::textures. I can just hold a few textures and change which vector of tiles is associated to which of the textures depending on where the camera is, or something like that. Should take care of all the lag. Thanks alot for the idea! :)

FRex

  • Hero Member
  • *****
  • Posts: 1841
  • Not doing gamedev/using SFML lately
    • View Profile
    • Email
Re: Questions and problems with sf::thread
« Reply #21 on: September 02, 2012, 12:10:33 am »
I mean your tiles, the ones from which the graphics come, not rendertextures, textures, if there is one it's perfect to use vertex array there.
Vertex arrays hold vertices(a 'better point' that is point on texture and point in sfml space, optionally colored) and the form they are supposed to take(the interesting one for tiles is quads, it means that each 4(0-3,4-7,8-11,ect..) vertices will form a 4 sided shape). You have to pass texture pointer as state in the draw call if you want it textured.
The removal and adding(but mostly removal) with arrays might be problematic but class that'd take care of that could probably be written with a bit of trouble.
« Last Edit: September 02, 2012, 12:15:12 am by FRex »
I'm not using SFML nor doing any gamedev lately.

Brodal

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: Questions and problems with sf::thread
« Reply #22 on: September 02, 2012, 10:04:19 am »
I will definitely look into  vertex arrays, as of now I don't really need them i think as I'm running 3 million tiles at 2000 fps. But I will try to implement them anyway, just to learn ;D.

Lag issue fixed, using 1 rendertexture that I pass a pointer to when rendering my tiles. Works like a charm!

FRex

  • Hero Member
  • *****
  • Posts: 1841
  • Not doing gamedev/using SFML lately
    • View Profile
    • Email
Re: Questions and problems with sf::thread
« Reply #23 on: September 02, 2012, 12:32:51 pm »
That is quite a lot of tiles, arrays won't do probably.
I'm not using SFML nor doing any gamedev lately.

Brodal

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: Questions and problems with sf::thread
« Reply #24 on: September 02, 2012, 12:39:55 pm »
Vectors work just fine at the moment, as I'm splitting them into several vectors. Don't know how those vertex arrays work though.

FRex

  • Hero Member
  • *****
  • Posts: 1841
  • Not doing gamedev/using SFML lately
    • View Profile
    • Email
Re: Questions and problems with sf::thread
« Reply #25 on: September 02, 2012, 12:48:34 pm »
Almost everything is in documentation, what isn't is primitives explanation(but that can be googles/guessed) and how to texture them(by passing &texture as second parameter to draw).
I'm not using SFML nor doing any gamedev lately.