-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
156 lines (108 loc) · 3.29 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* File: main.cpp
* Author: gg
*
* Created on 2 de outubro de 2019, 19:26
*/
#include <cstdlib>
#include <GL/freeglut_std.h>
#include "filepath.h"
#include "settings.h"
#include "xmlutils.h"
#include "simplesvg.h"
#include "stopwatch.h"
#include "thirdpersonfollower.h"
#include "game.h"
using namespace std;
app_settings* loadSettings(char* configFile) {
file_path path(configFile);
path.append("config.xml");
printf("Trying to open %s\n", path.toString());
return new app_settings(path.toString());
}
Game* sGame = NULL;
void display();
void mouseDragged(int x, int y);
void mouseMoved(int x, int y);
void mouseButtonEvent(int button, int state, int x, int y);
void mousePressed(int button, int x, int y);
void mouseReleased(int button, int x, int y);
void reshape(int width, int height);
void idle();
void keyPressed(unsigned char key, int x, int y);
void keyReleased(unsigned char key, int x, int y);
/*
*
*/
int main(int argc, char** argv) {
printf("TODO Create embedded presentation\n");
glutInit(&argc, argv);
try {
if (argc < 2) {
printf("syntax: %s <config folder>\n", argv[0]);
return EXIT_SUCCESS;
}
app_settings* settings = loadSettings(argv[1]);
// TODO create game context (objects, GLUT, etc)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
std::string title("TF - Guilherme, Ricardo");
glutCreateWindow(title.c_str());
sGame = new Game(settings);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc(keyPressed);
glutKeyboardUpFunc(keyReleased);
glutPassiveMotionFunc(mouseMoved);
glutMotionFunc(mouseDragged);
glutMouseFunc(mouseButtonEvent);
glutIdleFunc(idle);
// As stated in the spec, the initial frame size is 500x500
const int initialWidth = 500;
const int initialHeight = 700;
glutInitWindowSize(initialWidth, initialHeight);
glutReshapeWindow(initialWidth, initialHeight);
// glutInitWindowPosition(100, 20);
printf("Game context created\n");
delete settings;
glutMainLoop();
delete sGame;
} catch (IOException& ex) {
printf("[error] An exception: %s\n", ex.what());
} catch (MissingElementException& ex) {
printf("[error] An exception: %s\n", ex.what());
} catch (AttributeException& ex) {
printf("[error] An exception: %s\n", ex.what());
}
return EXIT_SUCCESS;
}
// wrappers for GLUT to Game
void display() {
sGame->display();
}
void mouseDragged(int x, int y) {
sGame->mouseDragged(x, y);
}
void mouseMoved(int x, int y) {
sGame->mouseMoved(x, y);
}
void mouseButtonEvent(int button, int state, int x, int y) {
sGame->mouseButtonEvent(button, state, x, y);
}
void mousePressed(int button, int x, int y) {
sGame->mousePressed(button, x, y);
}
void mouseReleased(int button, int x, int y) {
sGame->mouseReleased(button, x, y);
}
void reshape(int width, int height) {
sGame->reshape(width, height);
}
void idle() {
sGame->idle();
}
void keyPressed(unsigned char key, int x, int y) {
sGame->keyPressed(key, x, y);
}
void keyReleased(unsigned char key, int x, int y) {
sGame->keyReleased(key, x, y);
}