-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.cpp
235 lines (149 loc) · 3.46 KB
/
display.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include <GL/glut.h>
#include <sys/time.h>
#include <unistd.h>
#include <assert.h>
#include <iostream>
#include "display.h"
#include "Camera/Camera.h"
#include "WiiInterface/WiiInterface.h"
#include "AbstractScene/AbstractScene.h"
#include "MainMenu/MainMenu.h"
#include "FreeType/FreeType.h"
#include "CastleGame/CastleGame.h"
#include "config.h"
#include "TextPrinter/BitMapText.h"
#include "Audio/Audio.h"
struct SceneNode {
AbstractScene* scene;
SceneNode* next;
};
SceneNode* scenes = NULL;
SceneNode* currentScene = NULL;
/* Definition of function below */
void updateTime();
void InitDisplay()
{
updateTime();
/* Add all of the scenes here */
AddScene(new CastleGame());
/* Internal Intializers */
currentScene = scenes;
currentScene->scene->Init();
}
void displayScene()
{
currentScene->scene->Render();
}
void display()
{
/* Update the time for movement, and the like */
updateTime();
static float frameCounter = 0.0;
frameCounter += getTime();
static int intFrame = 0;
intFrame++;
if(frameCounter > 1.0)
{
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bfps:%i", intFrame);
fflush(stdout);
intFrame = 0;
frameCounter = 0;
}
/* Process Events from wiimotes */
if(useWiiMotes)
ProcessWiiEvents();
/* Generic OpenGL stuff */
glClearColor(0.8f, 0.8f, 0.8f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
/* Move Camera */
/*camera->positionCamera(); */
/* List everything to display to the screen here */
displayScene();
/* And now the normal OpenGL Cleanup stuff */
glPopMatrix();
glutSwapBuffers();
//usleep(10000);
}
void AddScene(AbstractScene* toAdd)
{
/* Add a scene to the list */
SceneNode* tmpNode = scenes;
if (tmpNode == NULL)
{
scenes = new SceneNode;
scenes->scene = toAdd;
scenes->next = NULL;
}
else
{
while (tmpNode != NULL)
{
tmpNode = tmpNode->next;
}
tmpNode->next = new SceneNode;
tmpNode->next->scene = toAdd;
tmpNode->next->next = NULL;
}
}
void NextScene()
{
assert(scenes);
assert(currentScene);
/* Tell the scene that it is done */
currentScene->scene->DeInit();
currentScene = currentScene->next;
/* Tell the new scene to get ready */
currentScene->scene->Init();
}
void PrevScene()
{
assert(scenes);
SceneNode* tmpScenes = scenes;
}
AbstractScene* GetDisplayed()
{
return currentScene->scene;
}
freetype::font_data* font = NULL;
freetype::font_data* GetFont()
{
if (font == NULL)
{
try
{
font = new freetype::font_data;
font->init("FreeType/Test.ttf", 16);
}
catch (std::exception &e)
{
printf ("%s\n", e.what());
}
}
return font;
}
double storeTime = 0, lastTime = 0;
double getTime() {
return storeTime - lastTime;
}
void updateTime() {
lastTime = storeTime;
timeval t;
gettimeofday(&t, 0);
//store seconds since epoch
storeTime = t.tv_sec;
//store micoseconds of that second, so divide by million
storeTime += ((double)t.tv_usec / 1000000);
}
void ShutDown()
{
printf("Shutting down\n");
fflush(stdout);
/* delete the scenes */
delete GetDisplayed();
delete font;
delete _audio;
WiiShutDown();
KillFont();
}