-
Notifications
You must be signed in to change notification settings - Fork 2
/
Simulation.h
82 lines (61 loc) · 1.96 KB
/
Simulation.h
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
74
75
76
77
78
79
80
81
82
#ifndef BOIDS_SIMULATION_H
#define BOIDS_SIMULATION_H
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include "SpatialHashGrid.h"
#include "Boid.h"
class Simulation {
private:
constexpr static int SCREEN_MARGIN = 200;
constexpr static int START_BOID_COUNT = 300;
constexpr static int MAX_BOID_COUNT = 600;
constexpr static int MIN_INIT_VELOCITY_XY = -400;
constexpr static int MAX_INIT_VELOCITY_XY = 400;
constexpr static int DEFAULT_BOID_HEIGHT = 7;
constexpr static int DEFAULT_BOID_WIDTH = 12;
constexpr static int MIN_BOID_HEIGHT = 7;
constexpr static int MAX_BOID_HEIGHT = 25;
// windows
constexpr static int WIN_WIDTH = 2880;
constexpr static int WIN_HEIGHT = 1800;
constexpr static int IMGUI_WIDTH = 450;
static const sf::Color DARK_BOID_COLOR;
static const sf::Color LIGHT_BOID_COLOR;
static const sf::Color PREDATOR_COLOR;
private:
// SFML stuff
sf::RenderWindow* window;
sf::VideoMode videoMode;
sf::Event ev{};
sf::Clock deltaClock;
sf::ContextSettings settings;
sf::Vector2f mousePosWindow;
// Boids
SpatialHashGrid m_grid;
std::vector<std::shared_ptr<Boid>> m_boids;
unsigned int m_margin;
int m_boidCount;
int m_mouseEffectDist;
int m_mouseModifier;
bool m_showTrail;
bool m_showNeighbors;
bool m_randomizeSize;
std::vector<std::shared_ptr<Boid>> m_currentBoidNeighbors;
void initWindow();
void initImGui();
void addBoids(int count, bool randomizeSize);
void updateBoidCount(int newCount, bool randomizeSize);
void updateBoids(UpdateBoidVelocityParams params, bool showTrail, sf::Time elapsed);
void updateMousePosition();
UpdateBoidVelocityParams updateImGui(sf::Time elapsed);
void renderBoids();
public:
Simulation();
virtual ~Simulation();
bool running() const;
void pollEvents();
void update();
void render();
};
#endif //BOIDS_SIMULATION_H