-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllegroManager.cpp
69 lines (50 loc) · 1.76 KB
/
AllegroManager.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
//
// Created by louis on 06/04/2021.
//
#include "AllegroManager.h"
AllegroManager::AllegroManager(ALLEGRO_DISPLAY *windows, int screenWidth, int screenHeight) {
//Gestion des possible de alegros à l'inisialisation
if(!al_init()) {
this->crashOnError("failed to initialize allegro!");
}
if(!al_init_primitives_addon()) {
this->crashOnError("failed to initialize allegro primitives addon!");
}
al_set_new_display_flags(ALLEGRO_OPENGL_3_0);
//Création de la fenêtres
windows = al_create_display(screenWidth, screenHeight);
if(!windows) {
this->crashOnError("failed to initialize allegro display!");
}
if(!al_install_keyboard()) {
this->crashOnError("Failed to initialize allegro keyboard handling!");
}
if(!al_install_mouse()) {
this->crashOnError("Failed to initialize allegro mouse handling!");
}
}
void AllegroManager::mainLoop(ALLEGRO_KEYBOARD_STATE keyboardState, BoidsManager boidsManager) {
unsigned short currentStep = 0;
while (true) {
// Récupération des évenements clavier
al_get_keyboard_state(&keyboardState);
// Sortie si Esc.
if (al_key_down(&keyboardState, ALLEGRO_KEY_ESCAPE)) {
return;
}
// Comportement des boids
boidsManager.step(currentStep);
// On efface tout (dans le backbuffer)
al_clear_to_color(al_map_rgb(0, 0, 0));
// Dessin des boids (dans le backbuffer)
boidsManager.drawBoids();
// On affiche le backbuffer
al_flip_display();
std::this_thread::sleep_for(std::chrono::milliseconds(1));
currentStep++;
}
}
void AllegroManager::crashOnError(std::string message) {
cerr << message << endl;
exit(-1);
}