-
Notifications
You must be signed in to change notification settings - Fork 0
/
Event.class.cpp
123 lines (110 loc) · 4.61 KB
/
Event.class.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// ************************************************************************** //
// //
// ::: :::::::: //
// Event.class.cpp :+: :+: :+: //
// +:+ +:+ +:+ //
// By: jmoiroux <jmoiroux@student.42.fr> +#+ +:+ +#+ //
// +#+#+#+#+#+ +#+ //
// Created: 2015/01/28 15:57:39 by jmoiroux #+# #+# //
// Updated: 2015/01/28 15:57:40 by jmoiroux ### ########.fr //
// //
// ************************************************************************** //
#include "Event.class.hpp"
#include "Map.class.hpp"
#include "Parseur.class.hpp"
#include "Scenar1.class.hpp"
#include "Scenar3.class.hpp"
#include "Scenar4.class.hpp"
#include "Scenar7.class.hpp"
#include "Scenar8.class.hpp"
int Event::initEvent( char ** av) {
if ( DEBUGG == true ) {
try {
d->debug.open("debugg.txt", std::fstream::app); // open debugg file
if (d->debug == NULL)
throw std::exception();
d->debug << "##############################################################" <<std::endl;
d->debug << "##############################################################" <<std::endl;
d->debug << "##############################################################" <<std::endl;
d->debug << std::endl;
d->debug << std::endl;
}
catch (std::exception & e) {
std::cerr << "Event::initEvent: Debugg file open error..." << std::endl;
throw std::exception();
}
}
this->d->Scenar = atoi(av[2]);
if ( 1 != this->d->Scenar && 3 != this->d->Scenar && 4 != this->d->Scenar
&& 7 != this->d->Scenar && 8 != this->d->Scenar ) {
std::cerr << "Event::initEvent: Scenar don't exist, try again..." << std::endl;
std::cerr << "\t1 -> MAIN Water up from all map" << std::endl;
std::cerr << "\t3 -> MAIN Double buffer - Water up from beach (better fonm OL)" << std::endl;
std::cerr << "\t8 -> MAIN MAIN --- it's raining" << std::endl;
std::cerr << "\t4 -> BONUS evaporation all map" << std::endl;
std::cerr << "\t7 -> BONUS simple buffer - Water up from beach" << std::endl;
throw std::exception();
}
this->d->map2d = ft42::allocMap2D();
this->d->originMAp = ft42::allocMap2D();
this->d->buffer1 = ft42::allocMap2D();
this->d->buffer2 = ft42::allocMap2D();
this->d->upZ = 0;
this->d->pause = true;
this->d->map = new Map();
this->d->scenar1 = new Scenar1();
this->d->scenar3 = new Scenar3();
this->d->scenar4 = new Scenar4();
this->d->scenar7 = new Scenar7();
this->d->scenar8 = new Scenar8();
this->d->parseur = new Parseur(av[1]);
if ( d->scenar1 == NULL || d->parseur == NULL || d->map == NULL || d == NULL
|| d->scenar1 == NULL || d->scenar3 == NULL || d->scenar4 == NULL
|| d->scenar7 == NULL || d->scenar8 == NULL) {
std::cerr << "Event::initEvent: Allocation Error !" << std::endl;
throw std::exception();
}
return 0;
}
void Event::initMap( void ) {
d->parseur->resizeValue(); // Scale map
d->parseur->sortByZ_minToMax(); // Sort by height
d->map->putRandomTo2dMap(); // put points to map2d array
d->map->doMapHill(); // generate Hill on map2d
}
void Event::initRender( int ac, char ** av ) {
glutInit(&ac, av); // init glut
glutInitDisplayMode(GLUT_RGB // set color to RGB
| GLUT_DOUBLE // set double buffered windows
| GLUT_DEPTH); // Bit mask to select a window with a depth buffer.
glutInitWindowSize(WINX, WINY); // Size of windows
glutInitWindowPosition(STARTX, STARTY); // where the windos in create on Xserver/Desktop
glutCreateWindow(TITLE); // Create windows with title in param char *
glClearColor(0.5f, 0.5f, 0.5f, 1); //purple //set background/void color
glEnable(GL_DEPTH_TEST);
glPointSize(3.0f);
glLineWidth(2.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
this->print_str("S to Start", 0, -0.050f);
this->print_str("SPACE = pause", -0.05f, -0.050);
this->print_str("Q ECHAP & others = exit", -0.1f, -0.050);
glFlush();
glutSwapBuffers();
glLoadIdentity();
}
void Event::renderScene(void ) {
glutKeyboardFunc(keyboard); // function for keyboard event
glutDisplayFunc(display);
glutTimerFunc(0, timer, 0);
glutMainLoop();
}
Event::Event() {
this->d = getData();
}
Event::Event( Event const & rSource ) {
*this = rSource;
}
Event & Event::operator=( Event const & rSource ) {
return *this;
}
Event::~Event() {}