You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.4 KiB

#include <SFML/Window.hpp>
8 years ago
#include <SFML/Graphics.hpp>
#include <iostream>
#include <chrono>
#include <random>
const int WINDOW_X = 600;
const int WINDOW_Y = 800;
8 years ago
float elap_time(){
static std::chrono::time_point<std::chrono::system_clock> start;
static bool started = false;
8 years ago
if (!started){
start = std::chrono::system_clock::now();
started = true;
}
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_time = now - start;
return elapsed_time.count();
}
8 years ago
int main() {
elap_time();
std::mt19937 rng(time(NULL));
std::uniform_int_distribution<int> rgen(100, 400);
8 years ago
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
8 years ago
float step_size = 0.005f;
double frame_time = 0.0, elapsed_time = 0.0, delta_time = 0.0, accumulator_time = 0.0, current_time = 0.0;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
8 years ago
}
elapsed_time = elap_time();
delta_time = elapsed_time - current_time;
current_time = elapsed_time;
if (delta_time > 0.02f)
delta_time = 0.02f;
accumulator_time += delta_time;
while ((accumulator_time - step_size) >= step_size) {
accumulator_time -= step_size;
// Update(step_size);
}
window.clear(sf::Color::Black);
window.display();
}
return 0;
8 years ago
}