-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
73 lines (58 loc) · 1.73 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <SFML/Graphics.hpp>
#include "population.hpp"
using namespace std;
int main(int argc, char *argv[]) {
const sf::VideoMode screenSize = sf::VideoMode(800, 800, 24);
sf::RenderWindow window(screenSize, "SFML");
const float frameRate = 30.0;
window.setFramerateLimit(frameRate);
window.setActive(false);
window.requestFocus();
sf::Clock clock;
sf::Time timeSinceLastUpdate = sf::Time::Zero;
sf::Time timePerFrame = sf::seconds(1.f/frameRate);
Population pop = Population(800, 800);
bool startAgents = false;
// Main Loop here
while(window.isOpen())
{
sf::Time elapsedTime = clock.restart();
timeSinceLastUpdate += elapsedTime;
if(timeSinceLastUpdate < timePerFrame)
continue;
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
{
window.close();
break;
}
else if(event.type == sf::Event::KeyPressed)
{
const sf::Keyboard::Key keycode = event.key.code;
if(keycode == sf::Keyboard::Space)
{
startAgents = true;
}
}
}
window.clear();
if(startAgents)
{
// Perform agent calculation
for(Person p: pop.population){
if(p.getEmpty())
continue;
pop.move(p.getIndex());
}
}
// Draw population on screen
for(Person p : pop.population){
window.draw(p.getBox());
}
window.display();
timeSinceLastUpdate = sf::Time::Zero;
}
return 0;
}