]> git.jsancho.org Git - lugaru.git/blob - Source/Game.cpp
cleanup, renamed rotations to yaw/pitch
[lugaru.git] / Source / Game.cpp
1 #include "Game.h"
2 #include "openal_wrapper.h"
3 #include "SDL_thread.h"
4
5 extern int mainmenu;
6
7 int numdialogues;
8 int numdialogueboxes[max_dialogues];
9 int dialoguetype[max_dialogues];
10 int dialogueboxlocation[max_dialogues][max_dialoguelength];
11 float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
12 int dialogueboxsound[max_dialogues][max_dialoguelength];
13 char dialoguetext[max_dialogues][max_dialoguelength][128];
14 char dialoguename[max_dialogues][max_dialoguelength][64];
15 XYZ dialoguecamera[max_dialogues][max_dialoguelength];
16 XYZ participantlocation[max_dialogues][10];
17 int participantfocus[max_dialogues][max_dialoguelength];
18 int participantaction[max_dialogues][max_dialoguelength];
19 float participantyaw[max_dialogues][10];
20 XYZ participantfacing[max_dialogues][max_dialoguelength][10];
21 float dialoguecamerayaw[max_dialogues][max_dialoguelength];
22 float dialoguecamerapitch[max_dialogues][max_dialoguelength];
23 int indialogue;
24 int whichdialogue;
25 int directing;
26 float dialoguetime;
27 int dialoguegonethrough[20];
28
29 namespace Game{
30     GLuint terraintexture = 0;
31     GLuint terraintexture2 = 0;
32     GLuint terraintexture3 = 0;
33     GLuint screentexture = 0;
34     GLuint screentexture2 = 0;
35     GLuint logotexture = 0;
36     GLuint loadscreentexture = 0;
37     GLuint Maparrowtexture = 0;
38     GLuint Mapboxtexture = 0;
39     GLuint Mapcircletexture = 0;
40     GLuint cursortexture = 0;
41     GLuint Mainmenuitems[10] = {};
42
43     int selected = 0;
44     int keyselect = 0;
45
46     int newdetail = 0;
47     int newscreenwidth = 0;
48     int newscreenheight = 0;
49
50     bool gameon = 0;
51     float deltah = 0;
52     float deltav = 0;
53     int mousecoordh = 0;
54     int mousecoordv = 0;
55     int oldmousecoordh = 0;
56     int oldmousecoordv = 0;
57     float yaw = 0;
58     float pitch = 0;
59     SkyBox *skybox = NULL;
60     bool cameramode = 0;
61     bool firstload = 0;
62
63         GLuint hawktexture = 0;
64         float hawkyaw = 0;
65         float hawkcalldelay = 0;
66     float leveltime = 0;
67     float loadtime = 0;
68
69     Model hawk;
70     XYZ hawkcoords;
71     XYZ realhawkcoords;
72
73     Model eye;
74     Model iris;
75     Model cornea;
76
77     bool stealthloading = 0;
78
79     int musictype = 0;
80
81     XYZ mapcenter;
82     float mapradius = 0;
83
84     Text *text = NULL;
85     float fps = 0;
86
87     bool editorenabled = 0;
88     int editortype = 0;
89     float editorsize = 0;
90     float editoryaw = 0;
91     float editorpitch = 0;
92
93     int tryquit = 0;
94
95     XYZ pathpoint[30];
96     int numpathpoints = 0;
97     int numpathpointconnect[30] = {};
98     int pathpointconnect[30][30] = {};
99     int pathpointselected = 0;
100
101     int endgame = 0;
102     bool scoreadded = 0;
103     int numchallengelevels = 0;
104
105     bool console = false;
106     char consoletext[15][256] = {};
107     int consolechars[15] = {};
108     bool chatting = 0;
109     char displaytext[15][256] = {};
110     int displaychars[15] = {};
111     float displaytime[15] = {};
112     float displayblinkdelay = 0;
113     bool displayblink = 0;
114     int displayselected = 0;
115     float consoleblinkdelay = 0;
116     bool consoleblink = 0;
117     int consoleselected = 0;
118
119     unsigned short crouchkey=0,jumpkey=0,forwardkey=0,chatkey=0,backkey=0,leftkey=0,rightkey=0,drawkey=0,throwkey=0,attackkey=0;
120     unsigned short consolekey=0;
121
122     int loading = 0;
123     
124     int oldenvironment = 0;
125     int targetlevel = 0;
126     float changedelay = 0;
127
128     bool waiting = false;
129     Account* accountactive = NULL;
130 }
131
132 void Game::fireSound(int sound) {
133         emit_sound_at(sound);
134 }
135
136 void Game::inputText(char* str, int* charselected, int* nb_chars) {
137         SDL_Event evenement;
138         
139         if(!waiting) {
140                 waiting=true;
141                 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
142                 SDL_EnableUNICODE(true);
143         }
144
145         while(SDL_PollEvent(&evenement)) {
146         
147                 switch(evenement.type) {
148                         case SDL_KEYDOWN:
149                                 if(evenement.key.keysym.sym == SDLK_ESCAPE) {
150                                         for(int i=0;i<255;i++)
151                                                 str[i]=0;
152                                         *nb_chars=0;
153                                         *charselected=0;
154                                         waiting=false;
155                                 } else if(evenement.key.keysym.sym==SDLK_BACKSPACE){
156                                         if((*charselected)!=0) {
157                                                 for(int i=(*charselected)-1;i<255;i++)
158                                                         str[i]=str[i+1];
159                                                 str[255]=0;
160                                                 (*charselected)--;
161                                                 (*nb_chars)--;
162                                         }
163                                 } else if(evenement.key.keysym.sym==SDLK_DELETE){
164                                         if((*charselected)<(*nb_chars)){
165                                                 for(int i=(*charselected);i<255;i++)
166                                                         str[i]=str[i+1];
167                                                 str[255]=0;
168                                                 (*nb_chars)--;
169                                         }
170                                 } else if(evenement.key.keysym.sym==SDLK_HOME){
171                                         (*charselected)=0;
172                                 } else if(evenement.key.keysym.sym==SDLK_END){
173                                         (*charselected)=(*nb_chars);
174                                 } else if(evenement.key.keysym.sym==SDLK_LEFT){
175                                         if((*charselected)!=0)
176                                                 (*charselected)--;
177                                 } else if(evenement.key.keysym.sym==SDLK_RIGHT){
178                                         if((*charselected)<(*nb_chars))
179                                                 (*charselected)++;
180                                 } else if(evenement.key.keysym.sym==SDLK_RETURN) {
181                                         waiting=false;
182                                 } else if(evenement.key.keysym.unicode>=32&&evenement.key.keysym.unicode<127&&(*nb_chars)<60){
183                                         for(int i=255;i>=(*charselected)+1;i--)
184                                                 str[i]=str[i-1];
185                                         str[*charselected]=evenement.key.keysym.unicode;
186                                         (*charselected)++;
187                                         (*nb_chars)++;
188                                 }
189                         break;
190                 }
191         }
192         
193         if(!waiting) {
194                 SDL_EnableKeyRepeat(0,0); // disable key repeat
195                 SDL_EnableUNICODE(false);
196         }
197 }
198
199 int setKeySelected_thread(void* data) {
200     using namespace Game;
201         int keycode=-1;
202         SDL_Event evenement;
203         while(keycode==-1) {
204                 SDL_WaitEvent(&evenement);
205                 switch(evenement.type) {
206                         case SDL_KEYDOWN:
207                                 keycode = evenement.key.keysym.sym;
208                         break;
209                         case SDL_MOUSEBUTTONDOWN:
210                                 keycode = SDLK_LAST+evenement.button.button;
211                         break;
212                         default:
213                         break;
214                 }
215         }
216         if(keycode != SDLK_ESCAPE) {
217                 fireSound();
218                 switch(keyselect) {
219                         case 0: forwardkey=keycode;
220                         break;
221                         case 1: backkey=keycode;
222                         break;
223                         case 2: leftkey=keycode;
224                         break;
225                         case 3: rightkey=keycode;
226                         break;
227                         case 4: crouchkey=keycode;
228                         break;
229                         case 5: jumpkey=keycode;
230                         break;
231                         case 6: drawkey=keycode;
232                         break;
233                         case 7: throwkey=keycode;
234                         break;
235                         case 8: attackkey=keycode;
236                         break;
237                         case 9: consolekey=keycode;
238                         break;
239                         default:
240                         break;
241                 }
242         }
243         keyselect=-1;
244         waiting=false;
245     LoadMenu();
246     return 0;
247 }
248
249 void Game::setKeySelected() {
250         waiting=true;
251     printf("launch thread\n");
252         SDL_Thread* thread = SDL_CreateThread(setKeySelected_thread,NULL);
253     if ( thread == NULL ) {
254         fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());
255                 waiting=false;
256         return;
257     }
258 }