]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
CLEANED UP WHITESPACE
[lugaru.git] / Source / GameInitDispose.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #include "Game.h"
23 #include "openal_wrapper.h"
24 #include "Animation.h"
25 #include "Texture.h"
26
27 extern float screenwidth, screenheight;
28 extern float viewdistance;
29 extern XYZ viewer;
30 extern XYZ lightlocation;
31 extern float fadestart;
32 extern float texscale;
33 extern float gravity;
34 extern Light light;
35 extern Skeleton testskeleton;
36 extern int numsounds;
37 extern Terrain terrain;
38 //extern Sprites sprites;
39 extern int kTextureSize;
40 extern float texdetail;
41 extern float realtexdetail;
42 extern float volume;
43 extern Objects objects;
44 extern int detail;
45 extern bool cellophane;
46 extern GLubyte bloodText[512 * 512 * 3];
47 extern GLubyte wolfbloodText[512 * 512 * 3];
48 extern bool ismotionblur;
49 extern bool trilinear;
50 extern bool osx;
51 extern bool musictoggle;
52 extern int environment;
53 extern bool ambientsound;
54 extern float multiplier;
55 extern int netdatanew;
56 extern float mapinfo;
57 extern bool stillloading;
58 extern TGAImageRec texture;
59 extern short vRefNum;
60 extern long dirID;
61 extern int mainmenu;
62 extern bool visibleloading;
63 extern float flashamount, flashr, flashg, flashb;
64 extern int flashdelay;
65 extern int whichjointstartarray[26];
66 extern int whichjointendarray[26];
67 extern int difficulty;
68 extern float tintr, tintg, tintb;
69 extern float slomospeed;
70 extern bool gamestarted;
71
72 extern int numdialogues;
73 extern int numdialogueboxes[20];
74 extern int dialoguetype[20];
75 extern int dialogueboxlocation[20][20];
76 extern float dialogueboxcolor[20][20][3];
77 extern int dialogueboxsound[20][20];
78 extern char dialoguetext[20][20][128];
79 extern char dialoguename[20][20][64];
80 extern XYZ dialoguecamera[20][20];
81 extern float dialoguecamerayaw[20][20];
82 extern float dialoguecamerapitch[20][20];
83 extern int indialogue;
84 extern int whichdialogue;
85 extern float dialoguetime;
86
87 extern float accountcampaignhighscore[10];
88 extern float accountcampaignfasttime[10];
89 extern float accountcampaignscore[10];
90 extern float accountcampaigntime[10];
91
92 extern int accountcampaignchoicesmade[10];
93 extern int accountcampaignchoices[10][5000];
94
95 void LOG(const std::string &fmt, ...)
96 {
97     // !!! FIXME: write me.
98 }
99
100 void Dispose()
101 {
102     LOGFUNC;
103
104     if (Game::endgame == 2) {
105         Game::accountactive->endGame();
106         Game::endgame = 0;
107     }
108
109     Account::saveFile(":Data:Users", Game::accountactive);
110
111     //textures.clear();
112
113     LOG("Shutting down sound system...");
114
115     OPENAL_StopSound(OPENAL_ALL);
116
117 // this is causing problems on Linux, but we'll force an _exit() a little
118 //  later in the shutdown process.  --ryan.
119 #if !PLATFORM_LINUX
120
121     for (int i = 0; i < sounds_count; ++i) {
122         OPENAL_Sample_Free(samp[i]);
123     }
124
125     OPENAL_Close();
126     if (texture.data) {
127         free(texture.data);
128     }
129     texture.data = 0;
130 #endif
131 }
132
133 void Game::newGame()
134 {
135     text = new Text();
136     skybox = new SkyBox();
137 }
138
139 void Game::deleteGame()
140 {
141     if (skybox)
142         delete skybox;
143     if (text)
144         delete text;
145     terraintexture.destroy();
146     terraintexture2.destroy();
147     cursortexture.destroy();
148     Maparrowtexture.destroy();
149     Mapboxtexture.destroy();
150     Mapcircletexture.destroy();
151     hawktexture.destroy();
152     loadscreentexture.destroy();
153
154     for (int i = 0; i < 10; i++)
155         Mainmenuitems[i].destroy();
156
157     glDeleteTextures(1, &screentexture);
158     glDeleteTextures(1, &screentexture2);
159
160     Dispose();
161 }
162
163
164
165 void LoadSave(const char *fileName, GLuint *textureid, bool mipmap, GLubyte *array, int *skinsize)
166 {
167     int i;
168     int bytesPerPixel;
169
170     LOGFUNC;
171
172     LOG(std::string("Loading (S)...") + fileName);
173
174     //Load Image
175     float temptexdetail = texdetail;
176     texdetail = 1;
177     //upload_image( fileName );
178     //LoadTGA( fileName );
179
180     // Converting file to something os specific
181     char * fixedFN = ConvertFileName(fileName);
182
183     //Load Image
184     unsigned char fileNamep[256];
185     CopyCStringToPascal(fixedFN, fileNamep);
186     //Load Image
187     upload_image( fileNamep , 0);
188     texdetail = temptexdetail;
189
190     //Is it valid?
191     if (1 == 1) {
192         bytesPerPixel = texture.bpp / 8;
193
194         int tempnum = 0;
195         for (i = 0; i < (int)(texture.sizeY * texture.sizeX * bytesPerPixel); i++) {
196             if ((i + 1) % 4 || bytesPerPixel == 3) {
197                 array[tempnum] = texture.data[i];
198                 tempnum++;
199             }
200         }
201     }
202 }
203
204
205
206 //***************> ResizeGLScene() <******/
207 GLvoid Game::ReSizeGLScene(float fov, float pnear)
208 {
209     if (screenheight == 0) {
210         screenheight = 1;
211     }
212
213     glViewport(0, 0, screenwidth, screenheight);
214
215     glMatrixMode(GL_PROJECTION);
216     glLoadIdentity();
217
218     gluPerspective(fov, (GLfloat)screenwidth / (GLfloat)screenheight, pnear, viewdistance);
219
220     glMatrixMode(GL_MODELVIEW);
221     glLoadIdentity();
222 }
223
224 void Game::LoadingScreen()
225 {
226     static float loadprogress;
227     static AbsoluteTime time = {0, 0};
228     static AbsoluteTime frametime = {0, 0};
229     AbsoluteTime currTime = UpTime ();
230     double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
231
232     if (0 > deltaTime) // if negative microseconds
233         deltaTime /= -1000000.0;
234     else // else milliseconds
235         deltaTime /= 1000.0;
236
237     multiplier = deltaTime;
238     if (multiplier < .001)
239         multiplier = .001;
240     if (multiplier > 10)
241         multiplier = 10;
242     if (multiplier > .05) {
243         frametime = currTime; // reset for next time interval
244
245         glLoadIdentity();
246         //Clear to black
247         glClearColor(0, 0, 0, 1);
248         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
249
250
251         loadtime += multiplier * 4;
252
253         loadprogress = loadtime;
254         if (loadprogress > 100)
255             loadprogress = 100;
256
257         //loadprogress=abs(Random()%100);
258
259         //Background
260
261         glEnable(GL_TEXTURE_2D);
262         loadscreentexture.bind();
263         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
264         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
265         glDisable(GL_DEPTH_TEST);
266         glDisable(GL_CULL_FACE);
267         glDisable(GL_LIGHTING);
268         glDepthMask(0);
269         glMatrixMode(GL_PROJECTION);
270         glPushMatrix();
271         glLoadIdentity();
272         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
273         glMatrixMode(GL_MODELVIEW);
274         glPushMatrix();
275         glLoadIdentity();
276         glTranslatef(screenwidth / 2, screenheight / 2, 0);
277         glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
278         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
279         glDisable(GL_BLEND);
280         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, 1);
281         glPushMatrix();
282         //glScalef(.25,.25,.25);
283         glBegin(GL_QUADS);
284         glTexCoord2f(.1 - loadprogress / 100, 0 + loadprogress / 100 + .3);
285         glVertex3f(-1, -1, 0.0f);
286         glTexCoord2f(.1 - loadprogress / 100, 0 + loadprogress / 100 + .3);
287         glVertex3f(1, -1, 0.0f);
288         glTexCoord2f(.1 - loadprogress / 100, 1 + loadprogress / 100 + .3);
289         glVertex3f(1, 1, 0.0f);
290         glTexCoord2f(.1 - loadprogress / 100, 1 + loadprogress / 100 + .3);
291         glVertex3f(-1, 1, 0.0f);
292         glEnd();
293         glPopMatrix();
294         glEnable(GL_BLEND);
295         glPushMatrix();
296         //glScalef(.25,.25,.25);
297         glBegin(GL_QUADS);
298         glTexCoord2f(.4 + loadprogress / 100, 0 + loadprogress / 100);
299         glVertex3f(-1, -1, 0.0f);
300         glTexCoord2f(.4 + loadprogress / 100, 0 + loadprogress / 100);
301         glVertex3f(1, -1, 0.0f);
302         glTexCoord2f(.4 + loadprogress / 100, 1 + loadprogress / 100);
303         glVertex3f(1, 1, 0.0f);
304         glTexCoord2f(.4 + loadprogress / 100, 1 + loadprogress / 100);
305         glVertex3f(-1, 1, 0.0f);
306         glEnd();
307         glPopMatrix();
308         glDisable(GL_TEXTURE_2D);
309         glMatrixMode(GL_PROJECTION);
310         glPopMatrix();
311         glMatrixMode(GL_MODELVIEW);
312         glPopMatrix();
313         glDisable(GL_BLEND);
314         glDepthMask(1);
315
316         glEnable(GL_TEXTURE_2D);
317         loadscreentexture.bind();
318         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
319         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
320         glDisable(GL_DEPTH_TEST);
321         glDisable(GL_CULL_FACE);
322         glDisable(GL_LIGHTING);
323         glDepthMask(0);
324         glMatrixMode(GL_PROJECTION);
325         glPushMatrix();
326         glLoadIdentity();
327         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
328         glMatrixMode(GL_MODELVIEW);
329         glPushMatrix();
330         glLoadIdentity();
331         glTranslatef(screenwidth / 2, screenheight / 2, 0);
332         glScalef((float)screenwidth / 2 * (1.5 - (loadprogress) / 200), (float)screenheight / 2 * (1.5 - (loadprogress) / 200), 1);
333         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
334         glEnable(GL_BLEND);
335         //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
336         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, 1);
337         glPushMatrix();
338         //glScalef(.25,.25,.25);
339         glBegin(GL_QUADS);
340         glTexCoord2f(0 + .5, 0 + .5);
341         glVertex3f(-1, -1, 0.0f);
342         glTexCoord2f(1 + .5, 0 + .5);
343         glVertex3f(1, -1, 0.0f);
344         glTexCoord2f(1 + .5, 1 + .5);
345         glVertex3f(1, 1, 0.0f);
346         glTexCoord2f(0 + .5, 1 + .5);
347         glVertex3f(-1, 1, 0.0f);
348         glEnd();
349         glPopMatrix();
350         glDisable(GL_TEXTURE_2D);
351         glMatrixMode(GL_PROJECTION);
352         glPopMatrix();
353         glMatrixMode(GL_MODELVIEW);
354         glPopMatrix();
355         glDisable(GL_BLEND);
356         glDepthMask(1);
357
358         glEnable(GL_TEXTURE_2D);
359         loadscreentexture.bind();
360         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
361         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
362         glDisable(GL_DEPTH_TEST);
363         glDisable(GL_CULL_FACE);
364         glDisable(GL_LIGHTING);
365         glDepthMask(0);
366         glMatrixMode(GL_PROJECTION);
367         glPushMatrix();
368         glLoadIdentity();
369         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
370         glMatrixMode(GL_MODELVIEW);
371         glPushMatrix();
372         glLoadIdentity();
373         glTranslatef(screenwidth / 2, screenheight / 2, 0);
374         glScalef((float)screenwidth / 2 * (100 + loadprogress) / 100, (float)screenheight / 2 * (100 + loadprogress) / 100, 1);
375         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
376         glEnable(GL_BLEND);
377         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, .4);
378         glPushMatrix();
379         //glScalef(.25,.25,.25);
380         glBegin(GL_QUADS);
381         glTexCoord2f(0 + .2, 0 + .8);
382         glVertex3f(-1, -1, 0.0f);
383         glTexCoord2f(1 + .2, 0 + .8);
384         glVertex3f(1, -1, 0.0f);
385         glTexCoord2f(1 + .2, 1 + .8);
386         glVertex3f(1, 1, 0.0f);
387         glTexCoord2f(0 + .2, 1 + .8);
388         glVertex3f(-1, 1, 0.0f);
389         glEnd();
390         glPopMatrix();
391         glDisable(GL_TEXTURE_2D);
392         glMatrixMode(GL_PROJECTION);
393         glPopMatrix();
394         glMatrixMode(GL_MODELVIEW);
395         glPopMatrix();
396         glDisable(GL_BLEND);
397         glDepthMask(1);
398
399         //Text
400
401         if (flashamount > 0) {
402             if (flashamount > 1)
403                 flashamount = 1;
404             if (flashdelay <= 0)
405                 flashamount -= multiplier;
406             flashdelay--;
407             if (flashamount < 0)
408                 flashamount = 0;
409             glDisable(GL_DEPTH_TEST);
410             glDisable(GL_CULL_FACE);
411             glDisable(GL_LIGHTING);
412             glDisable(GL_TEXTURE_2D);
413             glDepthMask(0);
414             glMatrixMode(GL_PROJECTION);
415             glPushMatrix();
416             glLoadIdentity();
417             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
418             glMatrixMode(GL_MODELVIEW);
419             glPushMatrix();
420             glLoadIdentity();
421             glScalef(screenwidth, screenheight, 1);
422             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
423             glEnable(GL_BLEND);
424             glColor4f(flashr, flashg, flashb, flashamount);
425             glBegin(GL_QUADS);
426             glVertex3f(0, 0, 0.0f);
427             glVertex3f(256, 0, 0.0f);
428             glVertex3f(256, 256, 0.0f);
429             glVertex3f(0, 256, 0.0f);
430             glEnd();
431             glMatrixMode(GL_PROJECTION);
432             glPopMatrix();
433             glMatrixMode(GL_MODELVIEW);
434             glPopMatrix();
435             glEnable(GL_DEPTH_TEST);
436             glEnable(GL_CULL_FACE);
437             glDisable(GL_BLEND);
438             glDepthMask(1);
439         }
440
441         swap_gl_buffers();
442     }
443 }
444
445 void FadeLoadingScreen(float howmuch)
446 {
447     static float loadprogress;
448
449     glLoadIdentity();
450     //Clear to black
451     glClearColor(0, 0, 0, 1);
452     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
453
454     loadprogress = howmuch;
455
456     //loadprogress=abs(Random()%100);
457
458     //Background
459
460     //glEnable(GL_TEXTURE_2D);
461     glDisable(GL_TEXTURE_2D);
462     //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
463     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
464     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
465     glDisable(GL_DEPTH_TEST);
466     glDisable(GL_CULL_FACE);
467     glDisable(GL_LIGHTING);
468     glDepthMask(0);
469     glMatrixMode(GL_PROJECTION);
470     glPushMatrix();
471     glLoadIdentity();
472     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
473     glMatrixMode(GL_MODELVIEW);
474     glPushMatrix();
475     glLoadIdentity();
476     glTranslatef(screenwidth / 2, screenheight / 2, 0);
477     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
478     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
479     glDisable(GL_BLEND);
480     glColor4f(loadprogress / 100, 0, 0, 1);
481     glPushMatrix();
482     //glScalef(.25,.25,.25);
483     glBegin(GL_QUADS);
484     glTexCoord2f(0, 0);
485     glVertex3f(-1, -1, 0.0f);
486     glTexCoord2f(1, 0);
487     glVertex3f(1, -1, 0.0f);
488     glTexCoord2f(1, 1);
489     glVertex3f(1, 1, 0.0f);
490     glTexCoord2f(0, 1);
491     glVertex3f(-1, 1, 0.0f);
492     glEnd();
493     glPopMatrix();
494     glDisable(GL_TEXTURE_2D);
495     glMatrixMode(GL_PROJECTION);
496     glPopMatrix();
497     glMatrixMode(GL_MODELVIEW);
498     glPopMatrix();
499     glDisable(GL_BLEND);
500     glDepthMask(1);
501     //Text
502     swap_gl_buffers();
503 }
504
505
506 extern bool cmdline(const char *cmd);
507
508 void Game::InitGame()
509 {
510 #if PLATFORM_MACOSX
511     ProcessSerialNumber PSN;
512     ProcessInfoRec pinfo;
513     FSSpec pspec;
514     OSStatus err;
515     /* set up process serial number */
516     PSN.highLongOfPSN = 0;
517     PSN.lowLongOfPSN = kCurrentProcess;
518     /* set up info block */
519     pinfo.processInfoLength = sizeof(pinfo);
520     pinfo.processName = NULL;
521     pinfo.processAppSpec = &pspec;
522     /* grab the vrefnum and directory */
523     err = GetProcessInformation(&PSN, &pinfo);
524     if (err == noErr) {
525         vRefNum = pspec.vRefNum;
526         dirID = pspec.parID;
527     }
528 #endif
529
530     LOGFUNC;
531
532     numchallengelevels = 14;
533
534     accountactive = Account::loadFile(":Data:Users");
535
536     tintr = 1;
537     tintg = 1;
538     tintb = 1;
539
540     whichjointstartarray[0] = righthip;
541     whichjointendarray[0] = rightfoot;
542
543     whichjointstartarray[1] = righthip;
544     whichjointendarray[1] = rightankle;
545
546     whichjointstartarray[2] = righthip;
547     whichjointendarray[2] = rightknee;
548
549     whichjointstartarray[3] = rightknee;
550     whichjointendarray[3] = rightankle;
551
552     whichjointstartarray[4] = rightankle;
553     whichjointendarray[4] = rightfoot;
554
555     whichjointstartarray[5] = lefthip;
556     whichjointendarray[5] = leftfoot;
557
558     whichjointstartarray[6] = lefthip;
559     whichjointendarray[6] = leftankle;
560
561     whichjointstartarray[7] = lefthip;
562     whichjointendarray[7] = leftknee;
563
564     whichjointstartarray[8] = leftknee;
565     whichjointendarray[8] = leftankle;
566
567     whichjointstartarray[9] = leftankle;
568     whichjointendarray[9] = leftfoot;
569
570     whichjointstartarray[10] = abdomen;
571     whichjointendarray[10] = rightshoulder;
572
573     whichjointstartarray[11] = abdomen;
574     whichjointendarray[11] = rightelbow;
575
576     whichjointstartarray[12] = abdomen;
577     whichjointendarray[12] = rightwrist;
578
579     whichjointstartarray[13] = abdomen;
580     whichjointendarray[13] = righthand;
581
582     whichjointstartarray[14] = rightshoulder;
583     whichjointendarray[14] = rightelbow;
584
585     whichjointstartarray[15] = rightelbow;
586     whichjointendarray[15] = rightwrist;
587
588     whichjointstartarray[16] = rightwrist;
589     whichjointendarray[16] = righthand;
590
591     whichjointstartarray[17] = abdomen;
592     whichjointendarray[17] = leftshoulder;
593
594     whichjointstartarray[18] = abdomen;
595     whichjointendarray[18] = leftelbow;
596
597     whichjointstartarray[19] = abdomen;
598     whichjointendarray[19] = leftwrist;
599
600     whichjointstartarray[20] = abdomen;
601     whichjointendarray[20] = lefthand;
602
603     whichjointstartarray[21] = leftshoulder;
604     whichjointendarray[21] = leftelbow;
605
606     whichjointstartarray[22] = leftelbow;
607     whichjointendarray[22] = leftwrist;
608
609     whichjointstartarray[23] = leftwrist;
610     whichjointendarray[23] = lefthand;
611
612     whichjointstartarray[24] = abdomen;
613     whichjointendarray[24] = neck;
614
615     whichjointstartarray[25] = neck;
616     whichjointendarray[25] = head;
617
618     FadeLoadingScreen(0);
619
620     stillloading = 1;
621
622     texture.data = ( GLubyte* )malloc( 1024 * 1024 * 4 );
623
624     int temptexdetail = texdetail;
625     texdetail = 1;
626     text->LoadFontTexture(":Data:Textures:Font.png");
627     text->BuildFont();
628     texdetail = temptexdetail;
629
630     FadeLoadingScreen(10);
631
632     if (detail == 2) {
633         texdetail = 1;
634     }
635     if (detail == 1) {
636         texdetail = 2;
637     }
638     if (detail == 0) {
639         texdetail = 4;
640     }
641
642     LOG("Initializing sound system...");
643
644 #if PLATFORM_LINUX
645     int output = -1;
646
647     unsigned char rc = 0;
648     output = OPENAL_OUTPUT_ALSA;  // Try alsa first...
649     if (cmdline("forceoss"))      //  ...but let user override that.
650         output = OPENAL_OUTPUT_OSS;
651     else if (cmdline("nosound"))
652         output = OPENAL_OUTPUT_NOSOUND;
653
654     OPENAL_SetOutput(output);
655     if ((rc = OPENAL_Init(44100, 32, 0)) == false) {
656         // if we tried ALSA and failed, fall back to OSS.
657         if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) ) {
658             OPENAL_Close();
659             output = OPENAL_OUTPUT_OSS;
660             OPENAL_SetOutput(output);
661             rc = OPENAL_Init(44100, 32, 0);
662         }
663     }
664
665     if (rc == false) {
666         OPENAL_Close();
667         output = OPENAL_OUTPUT_NOSOUND;  // we tried! just do silence.
668         OPENAL_SetOutput(output);
669         rc = OPENAL_Init(44100, 32, 0);
670     }
671 #else
672     OPENAL_Init(44100, 32, 0);
673 #endif
674
675     OPENAL_SetSFXMasterVolume((int)(volume * 255));
676     loadAllSounds();
677
678     if (musictoggle)
679         emit_stream_np(stream_menutheme);
680
681     cursortexture.load(":Data:Textures:Cursor.png", 0, 1);
682
683     Mapcircletexture.load(":Data:Textures:MapCircle.png", 0, 1);
684     Mapboxtexture.load(":Data:Textures:MapBox.png", 0, 1);
685     Maparrowtexture.load(":Data:Textures:MapArrow.png", 0, 1);
686
687     temptexdetail = texdetail;
688     if (texdetail > 2)
689         texdetail = 2;
690     Mainmenuitems[0].load(":Data:Textures:Lugaru.png", 0, 0);
691     Mainmenuitems[1].load(":Data:Textures:Newgame.png", 0, 0);
692     Mainmenuitems[2].load(":Data:Textures:Options.png", 0, 0);
693     Mainmenuitems[3].load(":Data:Textures:Quit.png", 0, 0);
694     Mainmenuitems[4].load(":Data:Textures:Eyelid.png", 0, 1);
695     Mainmenuitems[5].load(":Data:Textures:Resume.png", 0, 0);
696     Mainmenuitems[6].load(":Data:Textures:Endgame.png", 0, 0);
697
698     //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
699     //~ LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0); // LoadCampaign will take care of that
700     texdetail = temptexdetail;
701
702     FadeLoadingScreen(95);
703
704
705     gameon = 0;
706     mainmenu = 1;
707
708     stillloading = 0;
709     firstload = 0;
710
711     newdetail = detail;
712     newscreenwidth = screenwidth;
713     newscreenheight = screenheight;
714
715     LoadMenu();
716 }
717
718
719 void Game::LoadScreenTexture()
720 {
721     glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
722
723     if (!Game::screentexture)
724         glGenTextures( 1, &Game::screentexture );
725     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
726
727
728     glEnable(GL_TEXTURE_2D);
729     glBindTexture( GL_TEXTURE_2D, Game::screentexture);
730     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
731     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
732
733     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
734 }
735
736 //TODO: move LoadStuff() closer to GameTick.cpp to get rid of various vars shared in Game.h
737 void Game::LoadStuff()
738 {
739     static float temptexdetail;
740     static float viewdistdetail;
741     static int i, j;
742     float megascale = 1;
743
744     LOGFUNC;
745
746     loadtime = 0;
747
748     stillloading = 1;
749
750     for (i = 0; i < maxplayers; i++)
751         player[i].skeleton.drawmodel.textureptr.destroy();
752
753     i = abs(Random() % 4);
754     visibleloading = 0; //don't use loadscreentexture yet
755     loadscreentexture.load(":Data:Textures:fire.jpg", 1, 0);
756     visibleloading = 1;
757
758     temptexdetail = texdetail;
759     texdetail = 1;
760     text->LoadFontTexture(":Data:Textures:Font.png");
761     text->BuildFont();
762     texdetail = temptexdetail;
763
764     numsounds = 71;
765
766     viewdistdetail = 2;
767     viewdistance = 50 * megascale * viewdistdetail;
768
769     if (detail == 2) {
770         texdetail = 1;
771     }
772     if (detail == 1) {
773         texdetail = 2;
774     }
775     if (detail == 0) {
776         texdetail = 4;
777     }
778
779     realtexdetail = texdetail;
780
781     numplayers = 1;
782
783
784     LOG("Loading weapon data...");
785
786     Weapon::knifetextureptr.load(":Data:Textures:knife.png", 0, 1);
787     Weapon::bloodknifetextureptr.load(":Data:Textures:bloodknife.png", 0, 1);
788     Weapon::lightbloodknifetextureptr.load(":Data:Textures:lightbloodknife.png", 0, 1);
789     Weapon::swordtextureptr.load(":Data:Textures:sword.jpg", 1, 0);
790     Weapon::bloodswordtextureptr.load(":Data:Textures:Swordblood.jpg", 1, 0);
791     Weapon::lightbloodswordtextureptr.load(":Data:Textures:Swordbloodlight.jpg", 1, 0);
792     Weapon::stafftextureptr.load(":Data:Textures:Staff.jpg", 1, 0);
793
794     Weapon::throwingknifemodel.load((char *)":Data:Models:throwingknife.solid", 1);
795     Weapon::throwingknifemodel.Scale(.001, .001, .001);
796     //Weapon::throwingknifemodel.Rotate(0,0,-90);
797     Weapon::throwingknifemodel.Rotate(90, 0, 0);
798     Weapon::throwingknifemodel.Rotate(0, 90, 0);
799     Weapon::throwingknifemodel.flat = 0;
800     Weapon::throwingknifemodel.CalculateNormals(1);
801     //Weapon::throwingknifemodel.ScaleNormals(-1,-1,-1);
802
803     Weapon::swordmodel.load((char *)":Data:Models:sword.solid", 1);
804     Weapon::swordmodel.Scale(.001, .001, .001);
805     //Weapon::swordmodel.Rotate(0,0,-90);
806     Weapon::swordmodel.Rotate(90, 0, 0);
807     Weapon::swordmodel.Rotate(0, 90, 0);
808     Weapon::swordmodel.Rotate(0, 0, 90);
809     Weapon::swordmodel.flat = 1;
810     Weapon::swordmodel.CalculateNormals(1);
811     //Weapon::swordmodel.ScaleNormals(-1,-1,-1);
812
813     Weapon::staffmodel.load((char *)":Data:Models:staff.solid", 1);
814     Weapon::staffmodel.Scale(.005, .005, .005);
815     //Weapon::staffmodel.Rotate(0,0,-90);
816     Weapon::staffmodel.Rotate(90, 0, 0);
817     Weapon::staffmodel.Rotate(0, 90, 0);
818     Weapon::staffmodel.Rotate(0, 0, 90);
819     Weapon::staffmodel.flat = 1;
820     Weapon::staffmodel.CalculateNormals(1);
821     //Weapon::staffmodel.ScaleNormals(-1,-1,-1);
822
823     terrain.shadowtexture.load(":Data:Textures:shadow.png", 0, 1);
824     terrain.bloodtexture.load(":Data:Textures:blood.png", 0, 1);
825     terrain.breaktexture.load(":Data:Textures:break.png", 0, 1);
826     terrain.bloodtexture2.load(":Data:Textures:blood.png", 0, 1);
827
828
829     terrain.footprinttexture.load(":Data:Textures:footprint.png", 0, 1);
830     terrain.bodyprinttexture.load(":Data:Textures:bodyprint.png", 0, 1);
831     hawktexture.load(":Data:Textures:hawk.png", 0, 1);
832
833
834     Sprite::cloudtexture.load(":Data:Textures:cloud.png", 1, 1);
835     Sprite::cloudimpacttexture.load(":Data:Textures:cloudimpact.png", 1, 1);
836     Sprite::bloodtexture.load(":Data:Textures:bloodparticle.png", 1, 1);
837     Sprite::snowflaketexture.load(":Data:Textures:snowflake.png", 1, 1);
838     Sprite::flametexture.load(":Data:Textures:flame.png", 1, 1);
839     Sprite::bloodflametexture.load(":Data:Textures:bloodflame.png", 1, 1);
840     Sprite::smoketexture.load(":Data:Textures:smoke.png", 1, 1);
841     Sprite::shinetexture.load(":Data:Textures:shine.png", 1, 0);
842     Sprite::splintertexture.load(":Data:Textures:splinter.png", 1, 1);
843     Sprite::leaftexture.load(":Data:Textures:leaf.png", 1, 1);
844     Sprite::toothtexture.load(":Data:Textures:tooth.png", 1, 1);
845
846     yaw = 0;
847     pitch = 0;
848     ReSizeGLScene(90, .01);
849
850     viewer = 0;
851
852
853     if (detail)
854         kTextureSize = 1024;
855     if (detail == 1)
856         kTextureSize = 512;
857     if (detail == 0)
858         kTextureSize = 256;
859
860     //Set up distant light
861     light.color[0] = .95;
862     light.color[1] = .95;
863     light.color[2] = 1;
864     light.ambient[0] = .2;
865     light.ambient[1] = .2;
866     light.ambient[2] = .24;
867     light.location.x = 1;
868     light.location.y = 1;
869     light.location.z = -.2;
870     Normalise(&light.location);
871
872     LoadingScreen();
873
874     SetUpLighting();
875
876
877     fadestart = .6;
878     gravity = -10;
879
880     texscale = .2 / megascale / viewdistdetail;
881     terrain.scale = 3 * megascale * viewdistdetail;
882
883     viewer.x = terrain.size / 2 * terrain.scale;
884     viewer.z = terrain.size / 2 * terrain.scale;
885
886     hawk.load((char *)":Data:Models:hawk.solid", 1);
887     hawk.Scale(.03, .03, .03);
888     hawk.Rotate(90, 1, 1);
889     hawk.CalculateNormals(0);
890     hawk.ScaleNormals(-1, -1, -1);
891     hawkcoords.x = terrain.size / 2 * terrain.scale - 5 - 7;
892     hawkcoords.z = terrain.size / 2 * terrain.scale - 5 - 7;
893     hawkcoords.y = terrain.getHeight(hawkcoords.x, hawkcoords.z) + 25;
894
895     eye.load((char *)":Data:Models:eye.solid", 1);
896     eye.Scale(.03, .03, .03);
897     eye.CalculateNormals(0);
898
899     cornea.load((char *)":Data:Models:cornea.solid", 1);
900     cornea.Scale(.03, .03, .03);
901     cornea.CalculateNormals(0);
902
903     iris.load((char *)":Data:Models:iris.solid", 1);
904     iris.Scale(.03, .03, .03);
905     iris.CalculateNormals(0);
906
907     LoadSave(":Data:Textures:Bloodfur.png", 0, 1, &bloodText[0], 0);
908     LoadSave(":Data:Textures:Wolfbloodfur.png", 0, 1, &wolfbloodText[0], 0);
909
910     oldenvironment = -4;
911
912     gameon = 1;
913     mainmenu = 0;
914
915     firstload = 0;
916
917     loadAllAnimations();
918     //Fix knife stab, too lazy to do it manually
919     XYZ moveamount;
920     moveamount = 0;
921     moveamount.z = 2;
922     for (i = 0; i < player[0].skeleton.num_joints; i++) {
923         for (j = 0; j < animation[knifesneakattackanim].numframes; j++) {
924             animation[knifesneakattackanim].position[i][j] += moveamount;
925         }
926     }
927
928     LoadingScreen();
929
930     for (i = 0; i < player[0].skeleton.num_joints; i++) {
931         for (j = 0; j < animation[knifesneakattackedanim].numframes; j++) {
932             animation[knifesneakattackedanim].position[i][j] += moveamount;
933         }
934     }
935
936     LoadingScreen();
937
938     for (i = 0; i < player[0].skeleton.num_joints; i++) {
939         animation[dead1anim].position[i][1] = animation[dead1anim].position[i][0];
940         animation[dead2anim].position[i][1] = animation[dead2anim].position[i][0];
941         animation[dead3anim].position[i][1] = animation[dead3anim].position[i][0];
942         animation[dead4anim].position[i][1] = animation[dead4anim].position[i][0];
943     }
944     animation[dead1anim].speed[0] = 0.001;
945     animation[dead2anim].speed[0] = 0.001;
946     animation[dead3anim].speed[0] = 0.001;
947     animation[dead4anim].speed[0] = 0.001;
948
949     animation[dead1anim].speed[1] = 0.001;
950     animation[dead2anim].speed[1] = 0.001;
951     animation[dead3anim].speed[1] = 0.001;
952     animation[dead4anim].speed[1] = 0.001;
953
954     for (i = 0; i < player[0].skeleton.num_joints; i++) {
955         for (j = 0; j < animation[swordsneakattackanim].numframes; j++) {
956             animation[swordsneakattackanim].position[i][j] += moveamount;
957         }
958     }
959     LoadingScreen();
960     for (j = 0; j < animation[swordsneakattackanim].numframes; j++) {
961         animation[swordsneakattackanim].weapontarget[j] += moveamount;
962     }
963
964     LoadingScreen();
965
966     for (i = 0; i < player[0].skeleton.num_joints; i++) {
967         for (j = 0; j < animation[swordsneakattackedanim].numframes; j++) {
968             animation[swordsneakattackedanim].position[i][j] += moveamount;
969         }
970     }
971
972     LoadingScreen();
973     temptexdetail = texdetail;
974     texdetail = 1;
975     texdetail = temptexdetail;
976
977     LoadingScreen();
978
979     if (!screentexture) {
980         LoadScreenTexture();
981     }
982
983     if (targetlevel != 7) {
984         emit_sound_at(fireendsound);
985     }
986
987     stillloading = 0;
988     loading = 0;
989     changedelay = 1;
990
991     visibleloading = 0;
992 }
993