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

Author Topic: [SOLVED] VertexArray & Vertex's tilemap nightmare  (Read 19033 times)

0 Members and 1 Guest are viewing this topic.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
AW: Re: VertexArray & Vertex's tilemap nightmare
« Reply #15 on: January 29, 2013, 12:15:44 pm »
However, I'm worried about perfomance with huge maps (8000x2000~ tiles)
Once you run into performance issues, there are many possible optimization. One of the most common one is the divide the screen space into multiple vertex arrays and thrn only draw the ones that are actually visible.

but what I don't get at all is the process of "moving" the right vertexs to the left top corner of the screen in order to start drawing the tiles.
I've no idea what you're talking about here... ;)

Trying to figure out which Vertex are inside the View rect isn't good Idea either because some points of the 4 that compose the vertex will not been draw, thus, showing just three, two or one of them
In the logic part for culling you don't 'think' about points but about quads - you don't see 4 individual points, but a package of 4 points.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
Re: AW: Re: VertexArray & Vertex's tilemap nightmare
« Reply #16 on: January 29, 2013, 10:15:39 pm »
but what I don't get at all is the process of "moving" the right vertexs to the left top corner of the screen in order to start drawing the tiles.
I've no idea what you're talking about here... ;)
never mind xd

Trying to figure out which Vertex are inside the View rect isn't good Idea either because some points of the 4 that compose the vertex will not been draw, thus, showing just three, two or one of them
In the logic part for culling you don't 'think' about points but about quads - you don't see 4 individual points, but a package of 4 points.

Hmm, yes, indeed that approach makes more sense! :)

EDIT:

I'm doing some progress but without testing it...
So, I'm thinking on packages of 4 points as eXpl0it3r told me, and I must say that this is really easy than I thought before. Consider the following image:



The trick here is to calculate correctly the coordinates for the first vertex (Vertex1 or v1), and then, use the position or tex_coords of the first Vertex to calculate the other 3 vertex of a Quad:

# We calculate the first vertex
v1 = sfml.Vertex(tex_coods=sfml.Vector2(
        float(x), float(y)))

# Then use v1.tex_coords to calculate the others
v2 = sfml.Vertex(tex_coords=sfml.Vector2(
        v1.tex_coords.x + tilewidth,
        v1.tex_coords.y))
v3 = sfml.Vertex(tex_coords=sfml.Vector2(
        v1.tex_coords.x + tilewidth,
        v1.tex_coords.y + tileheight))
v4 = sfml.Vertex(tex_coords=sfml.Vector2(
        v1.tex_coords.x,
        v1.tex_coords.y + tileheight))

# store the quad somewhere
tileimg = (v1, v2, v3, v4,)
 

very easy, right?
This should (yes, I didn't run any test yet) work also for positioning the quads on screen. Orthographic or Isometric maps, that no matters, just calculate the first vertex position correctly and everything else should flow naturally! 
« Last Edit: January 31, 2013, 03:11:16 am by shackra »

GNU User
Python programmer
Blog

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
Re: VertexArray & Vertex's tilemap nightmare
« Reply #17 on: January 31, 2013, 08:58:11 pm »


almost there!!...

GNU User
Python programmer
Blog

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
Re: VertexArray & Vertex's tilemap nightmare
« Reply #18 on: February 01, 2013, 12:54:53 am »
There is!!



All tiles are drawn on screen, I need to implement that stuff drawing just those tiles that are visible!

GNU User
Python programmer
Blog

 

anything