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