Created
October 10, 2012 14:26
-
-
Save mantognini/3865964 to your computer and use it in GitHub Desktop.
Compare SFML master VS PR #301
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <vector> | |
#include <SFML/Graphics.hpp> | |
#include "ResourcePath.hpp" | |
template <typename T> | |
std::string toString(T t) { | |
std::stringstream ss; | |
ss << t; | |
return ss.str(); | |
} | |
int random(int min, int max) { | |
static bool initialized = false; | |
if (!initialized) { | |
std::srand(std::time(0)); | |
initialized = true; | |
} | |
return rand() % (max - min + 1) + min; | |
} | |
sf::Vector2f randomPosition(sf::VideoMode mode) { | |
return { random(0, mode.width), random(0, mode.height) }; | |
} | |
int main (int argc, const char * argv[]) | |
{ | |
bool const DESKTOP = true; | |
// Create the main window | |
sf::VideoMode mode = DESKTOP ? sf::VideoMode::getDesktopMode() : sf::VideoMode(800, 600); | |
sf::RenderWindow window(mode, "SFML window", sf::Style::Fullscreen); | |
// Load some texture | |
std::size_t const TEXTURE_COUNT = 5; | |
sf::Texture textures[TEXTURE_COUNT]; | |
for (int i = 0; i < TEXTURE_COUNT; ++i) { | |
std::string file = "image" + toString(i + 1) + ".bmp"; | |
if (!textures[i].loadFromFile(resourcePath() + file)) { | |
std::cout << "Can't load " << file << std::endl; | |
return EXIT_FAILURE; | |
} | |
} | |
// Create some sprite | |
std::size_t const SPRITE_COUNT = 5000; | |
std::vector<sf::Sprite> sprites(SPRITE_COUNT); | |
for (std::size_t i = 0; i < SPRITE_COUNT; ++i) { | |
sf::Sprite& s = sprites[i]; | |
s.setTexture(textures[random(0, TEXTURE_COUNT)]); | |
s.setPosition(randomPosition(mode)); | |
s.setOrigin(s.getLocalBounds().width / 2.f, s.getLocalBounds().height / 2.f); | |
} | |
sf::Time const DURATION = sf::seconds(20); | |
sf::Clock clk; | |
std::size_t frameCount = 0; | |
// Start the game loop | |
while (clk.getElapsedTime() < DURATION) | |
{ | |
// Process events | |
sf::Event event; | |
while (window.pollEvent(event)) { } | |
// Clear screen | |
window.clear(); | |
float const angle = clk.getElapsedTime().asSeconds() * 100.f; | |
for (std::size_t i = 0; i < SPRITE_COUNT; ++i) { | |
sf::Sprite& s = sprites[i]; | |
s.setRotation(angle); | |
window.draw(s); | |
} | |
// Update the window | |
window.display(); | |
++frameCount; | |
} | |
std::cout | |
<< "REPORT : " | |
<< SPRITE_COUNT | |
<< " sprites rotating; " | |
<< frameCount | |
<< " frames in " | |
<< DURATION.asSeconds() | |
<< " seconds; ~" | |
<< frameCount / DURATION.asSeconds() | |
<< " FPS" | |
<< std::endl; | |
return EXIT_SUCCESS; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10/10/12 | |
### SFML 2.0 git master branch | |
> Desktop mode : | |
REPORT : 5000 sprites rotating; 354 frames in 20 seconds; ~17.7 FPS | |
> 800x600 mode : | |
REPORT : 5000 sprites rotating; 385 frames in 20 seconds; ~19.25 FPS | |
### SFML 2.0 git fullscreen branch | |
> Desktop mode : | |
REPORT : 5000 sprites rotating; 349 frames in 20 seconds; ~17.45 FPS | |
> 800x600 mode : | |
REPORT : 5000 sprites rotating; 392 frames in 20 seconds; ~19.6 FPS | |
### Conclusion : | |
- performance are the same | |
- 'master' version stretches the content is the mode has not the same ratio as the display | |
- 'fullscreen' version resizes all open windows |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment