Hello,
I am working on a random project where i need to have a code as efficient as possible so i tried to check if the way I draw is efficient enough but it isn't.
I saw people how draw millions of points whie still having a decent amount of FPS but I can't draw more than around 200000 points.
I tried with circles, recangles, convexs, rectangles with the size of a pixel but it never gets better.
If you have a solution I would be happy to here it.
Here is the code :
while(window.isOpen()){
window.clear();
while(window.pollEvent(event)){
if((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Enter) && (!fullscreen)) {
fullscreen = true;
window.create(VideoMode(1920, 1080), nameProject, (fullscreen ? Style::Fullscreen : Style::Resize|Style::Close));
}
else if((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Escape) && (fullscreen)) {
fullscreen = false;
window.create(VideoMode(1920, 1080), nameProject, (fullscreen ? Style::Fullscreen : Style::Resize|Style::Close));
}
if((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Space) && (fullscreen)) {
pause = !pause;
}
if(event.type == Event::Closed){
window.close();
}
}
float dt = gameClock.getElapsedTime().asSeconds();
gameClock.restart();
for(int i=0; i<player.size(); i++){
if(fullscreen && !pause){
player[i].x+=player[i].vx*dt;
player[i].y+=player[i].vy*dt;
if(player[i].x < player[i].r){
player[i].x += 2*(player[i].r-player[i].x);
player[i].vx *= -1;
}
else if(player[i].x > window.getSize().x-player[i].r){
player[i].x += 2*(window.getSize().x-player[i].r-player[i].x);
player[i].vx *= -1;
}
if(player[i].y < player[i].r){
player[i].y += 2*(player[i].r-player[i].y);
player[i].vy *= -1;
}
else if(player[i].y > window.getSize().y-player[i].r){
player[i].y += 2*(window.getSize().y-player[i].r-player[i].y);
player[i].vy *= -1;
}
}
if(fullscreen){
player[i].body.setPosition(player[i].x-player[i].r, player[i].y-player[i].r);
window.draw(player[i].body);
}
}
window.display();
Sleep(1);
}