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?
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.