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 - yoyo

Pages: [1]
1
Graphics / Re: Sfml drawing faster algorithm slower
« on: December 18, 2019, 09:37:45 pm »
Well maybe I missunderstand something in vectors because I'm new in c++ but I got perfromance that I needed.

About 2 dimension VectorArray.

I need VectorArray of points (All of them make big square). I have to color every pixel.For example With RectangleShape[][] I could do something like that.

for(int i=0; i<1000; i++){
for(int j=0; j<1000; j++){
if(condition)
shape[i-1][j+1].setFillColor = Color::Red;
}
}

In vectors I have to add another field to iterate and for square of pixels it looks like that

int pom = 0;
        int j = 0;
        int i = 0;
        for (; i < 1000000; i = i + 1000) {
                for (j = 0; j < 1000; j++) {
if(condition)
vertex[pom-999].color = Color::Red;
pom++;

To make it easier for 1D VertexArray its much harder to make conditions of coloring than RectangleShape 2D array. Thats why I'm asking about it.

2
Graphics / Re: Sfml drawing faster algorithm slower
« on: December 18, 2019, 08:32:48 pm »
Well, im stupid. I used vectors for int and bool not a dynamic array. Now I got 800fps.

Still is there posibility to make 2 dimension vertex array without loosing efficiently on drawing? Its boring to make conditions for one dimension.

3
Graphics / Re: Sfml drawing faster algorithm slower
« on: December 18, 2019, 07:06:54 pm »
Ok my bad ^^

1. Every start of the program I make an VertexArray of primitve points. The code shows how I make it. I make 10k points, set color to green set position each of them that I got square of pixels (100x100). It's constructor.

2.In loop while(window.isOpen()) in other class I use the function that use this vertexArray (I declare this VertexArray once at the start of the game).

3.The function iterate through all elements of my VertexArray for(int i=0; i<VertexArray.size(); i++). So its 10k iterations.

4. In this function I check like 1-12 condition also I change like 1-8 colors. For example vert[i+1].color = Color::Red or vert[i-1].color = Color::Red.

5. Then I just turn off program. It looks like on youtube that I posted link.


The main problem is why this algorithm work faster on rectangle shapes? I dont have bigger loop or something.In two cases in my function I do the same things. Check some conditions and if they are true I increment some values(the same amount, expect one field) and change color of that poins/pixel/shape. And vertexArray its like 20x slower but drawing 20x faster. No idea why :/

I hope I make it clear :D

4
Graphics / Sfml drawing faster algorithm slower
« on: December 18, 2019, 03:42:06 pm »
Hi. (Sorry for grammar I don't use english everyday)

I have big problem. I wrote a lichen array function. The problem is with performance.

When I use 2 dimension array of rectangle shape (shape size 6x6). In my function I'm checking conditions and setting color of each rectangle. Then I draw it. So the time of draw is like 20ms and the time of iteriation 100x100 and setting colors/checking conditions  is under 1ms.

I have read that I should use VertexArray of points. So i did it. The draw time is under 0.1ms for 100x100 array and that is perfect but... iterating and swapping colors is over 25ms? No idea why I have the same amount of conditions etc. I just have one more field that I increment to 10000. So its O(1). Maybe the problem is with setting the array. For 100x100 I just set it like that in constructor. But I just do it once so I don't think so. (The Vertex is point and I add this point to VertexArray named vert, other two arrays are normal vectors)

int j = 0;
        int pom = 0;
        int pom2 = 0;
        for (int i = 0; i < 10000; i++) {
                odpornosc.push_back(0);
                flaga.push_back(true);
                if (i == 100) {
                        pom = i;
                        j++;
                        pom2 = 0;
                }
                if (pom + 100 == i) {
                        pom += 100;
                        j++;
                        pom2 = 0;
                }

                point.position = Vector2f(pom2, j);
                pom2++;
                point.color = Color::Green;
                vert.append(point);
        }
 

In my iteration function I use methods only like:

vert[pom].color = Color::Yellow;


Of course I use this function in loop while(window.isOpen())

It looks like that:

https://www.youtube.com/watch?v=XKkq8rPhtDk&feature=youtu.be


Maybe there is possibility to make 2 dimension vertex array and still draw efficiently?

Pages: [1]
anything