2 #include "openal_wrapper.h"
3 #include "SDL_thread.h"
6 extern OPENAL_SAMPLE *samp[100];
7 extern int channels[100];
8 extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
20 loadscreentexture = 0;
26 memset(Mainmenuitems, 0, sizeof(Mainmenuitems));
30 memset(startx, 0, sizeof(startx));
31 memset(starty, 0, sizeof(starty));
32 memset(endx, 0, sizeof(endx));
33 memset(endy, 0, sizeof(endy));
35 memset(selectedlong, 0, sizeof(selectedlong));
36 memset(offsetx, 0, sizeof(offsetx));
37 memset(offsety, 0, sizeof(offsety));
38 memset(movex, 0, sizeof(movex));
39 memset(movey, 0, sizeof(movey));
40 memset(endy, 0, sizeof(endy));
53 memset(menustring, 0, sizeof(menustring));
54 memset(registrationname, 0, sizeof(registrationname));
55 registrationnumber = 0;
62 deltah = 0,deltav = 0;
63 mousecoordh = 0,mousecoordv = 0;
64 oldmousecoordh = 0,oldmousecoordv = 0;
65 rotation = 0,rotation2 = 0;
70 cameratogglekeydown = 0;
71 chattogglekeydown = 0;
74 drawmodetogglekeydown = 0;
75 explodetogglekeydown = 0;
76 detailtogglekeydown = 0;
86 // XYZ realhawkcoords;
98 campaignnumlevels = 0;
100 memset(campaignmapname, 0, sizeof(campaignmapname));
101 memset(campaigndescription, 0, sizeof(campaigndescription));
102 memset(campaignchoosenext, 0, sizeof(campaignchoosenext));
103 memset(campaignnumnext, 0, sizeof(campaignnumnext));
104 memset(campaignnextlevel, 0, sizeof(campaignnextlevel));
105 int campaignchoicesmade;
106 memset(campaignchoices, 0, sizeof(campaignchoices));
107 memset(campaignlocationx, 0, sizeof(campaignlocationx));
108 memset(campaignlocationy, 0, sizeof(campaignlocationy));
109 memset(campaignlocationy, 0, sizeof(campaignlocationy));
111 campaignchoicenum = 0;
113 memset(campaignchoicewhich, 0, sizeof(campaignchoicewhich));
119 memset(levelorder, 0, sizeof(levelorder));
120 memset(levelvisible, 0, sizeof(levelvisible));
121 memset(levelhighlight, 0, sizeof(levelhighlight));
125 musictype = 0,oldmusictype = 0,oldoldmusictype = 0;
140 envtogglekeydown = 0;
141 slomotogglekeydown = 0;
142 texturesizetogglekeydown = 0;
143 freezetogglekeydown = 0;
157 // XYZ pathpoint[30];
159 memset(numpathpointconnect, 0, sizeof(numpathpointconnect));
160 memset(pathpointconnect, 0, sizeof(pathpointconnect));
161 pathpointselected = 0;
165 numchallengelevels = 0;
170 memset(consoletext, 0, sizeof(consoletext));
171 memset(consolechars, 0, sizeof(consolechars));
173 memset(displaytext, 0, sizeof(displaytext));
174 memset(displaychars, 0, sizeof(displaychars));
175 memset(displaytime, 0, sizeof(displaytime));
176 displayblinkdelay = 0;
180 consoletogglekeydown = 0;
181 consoleblinkdelay = 0;
184 memset(togglekey, 0, sizeof(togglekey));
185 memset(togglekeydelay, 0, sizeof(togglekeydelay));
189 crouchkey = 0,jumpkey = 0,forwardkey = 0,chatkey = 0,backkey = 0,leftkey = 0,rightkey = 0,drawkey = 0,throwkey = 0,attackkey = 0;
196 // XYZ boundary[360];
203 memset(musicvolume, 0, sizeof(musicvolume));
204 memset(oldmusicvolume, 0, sizeof(oldmusicvolume));
213 accountactive = NULL;
218 void (Game::*method)();
221 void Game::fireSound(int sound) {
222 float gLoc[3]={0,0,0};
223 float vel[3]={0,0,0};
224 OPENAL_Sample_SetMinMaxDistance(samp[sound], 9999.0f, 99999.0f);
225 PlaySoundEx( sound, samp[sound], NULL, true);
226 OPENAL_3D_SetAttributes(channels[sound], gLoc, vel);
227 OPENAL_SetVolume(channels[sound], 256);
228 OPENAL_SetPaused(channels[sound], false);
229 OPENAL_Sample_SetMinMaxDistance(samp[sound], 8.0f, 2000.0f);
232 void Game::inputText() {
234 params_thread* data = new params_thread;
236 data->method = &Game::inputText_thread;
237 SDL_Thread* thread = SDL_CreateThread(Game::thread, data);
238 if ( thread == NULL ) {
239 fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());
245 void Game::inputText_thread() {
247 SDL_EnableKeyRepeat(400, 40);
248 SDL_EnableUNICODE(true);
252 SDL_WaitEvent(&evenement);
254 switch(evenement.type) {
256 if(evenement.key.keysym.sym == SDLK_ESCAPE) {
258 displaytext[0][i]=' ';
262 mainmenutogglekeydown=1;
264 } else if(evenement.key.keysym.sym==SDLK_BACKSPACE&&displayselected!=0){
265 for(i=displayselected-1;i<255;i++){
266 displaytext[0][i]=displaytext[0][i+1];
268 displaytext[0][255]=' ';
271 } else if(evenement.key.keysym.sym==SDLK_DELETE&&displayselected!=0){
272 for(i=displayselected;i<255;i++){
273 displaytext[0][i]=displaytext[0][i+1];
275 displaytext[0][255]=' ';
277 } else if(evenement.key.keysym.sym==SDLK_LEFT&&displayselected!=0){
279 } else if(evenement.key.keysym.sym==SDLK_RIGHT&&displayselected<displaychars[0]){
281 } else if(evenement.key.keysym.sym==SDLK_RETURN) {
283 accountactive = Account::add(string(displaytext[0]));
289 fireSound(firestartsound);
292 displaytext[0][i]=' ';
299 } else if(evenement.key.keysym.unicode&&displaychars[0]<60) {
300 for(i=255;i>=displayselected+1;i--){
301 displaytext[0][i]=displaytext[0][i-1];
303 displaytext[0][displayselected]=evenement.key.keysym.unicode;
306 printf("%c\n",evenement.key.keysym.unicode);
312 SDL_EnableKeyRepeat(0,0); // disable key repeat
313 SDL_EnableUNICODE(false);
316 void Game::setKeySelected() {
318 params_thread* data = new params_thread;
320 data->method = &Game::setKeySelected_thread;
321 printf("launch thread\n");
322 SDL_Thread* thread = SDL_CreateThread(Game::thread, data);
323 if ( thread == NULL ) {
324 fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());
330 void Game::setKeySelected_thread() {
334 SDL_WaitEvent(&evenement);
335 switch(evenement.type) {
337 keycode = evenement.key.keysym.sym;
339 case SDL_MOUSEBUTTONDOWN:
340 keycode = SDLK_LAST+evenement.button.button;
346 if(keycode != SDLK_ESCAPE) {
349 case 0:forwardkey=keycode;
351 case 1:backkey=keycode;
353 case 2:leftkey=keycode;
355 case 3:rightkey=keycode;
357 case 4:crouchkey=keycode;
359 case 5:jumpkey=keycode;
361 case 6:drawkey=keycode;
363 case 7:throwkey=keycode;
365 case 8:attackkey=keycode;
375 int Game::thread(void *data) {
376 params_thread* pt = (params_thread*)data;
378 (pt->game->*(pt->method))();