]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
Removed most of the commented out code
[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 frametime = {0, 0};
218     AbsoluteTime currTime = UpTime ();
219     double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
220
221     if (0 > deltaTime) // if negative microseconds
222         deltaTime /= -1000000.0;
223     else // else milliseconds
224         deltaTime /= 1000.0;
225
226     multiplier = deltaTime;
227     if (multiplier < .001)
228         multiplier = .001;
229     if (multiplier > 10)
230         multiplier = 10;
231     if (multiplier > .05) {
232         frametime = currTime; // reset for next time interval
233
234         glLoadIdentity();
235         //Clear to black
236         glClearColor(0, 0, 0, 1);
237         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
238
239
240         loadtime += multiplier * 4;
241
242         loadprogress = loadtime;
243         if (loadprogress > 100)
244             loadprogress = 100;
245
246         //Background
247
248         glEnable(GL_TEXTURE_2D);
249         loadscreentexture.bind();
250         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
251         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
252         glDisable(GL_DEPTH_TEST);
253         glDisable(GL_CULL_FACE);
254         glDisable(GL_LIGHTING);
255         glDepthMask(0);
256         glMatrixMode(GL_PROJECTION);
257         glPushMatrix();
258         glLoadIdentity();
259         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
260         glMatrixMode(GL_MODELVIEW);
261         glPushMatrix();
262         glLoadIdentity();
263         glTranslatef(screenwidth / 2, screenheight / 2, 0);
264         glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
265         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
266         glDisable(GL_BLEND);
267         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, 1);
268         glPushMatrix();
269         glBegin(GL_QUADS);
270         glTexCoord2f(.1 - loadprogress / 100, 0 + loadprogress / 100 + .3);
271         glVertex3f(-1, -1, 0.0f);
272         glTexCoord2f(.1 - loadprogress / 100, 0 + loadprogress / 100 + .3);
273         glVertex3f(1, -1, 0.0f);
274         glTexCoord2f(.1 - loadprogress / 100, 1 + loadprogress / 100 + .3);
275         glVertex3f(1, 1, 0.0f);
276         glTexCoord2f(.1 - loadprogress / 100, 1 + loadprogress / 100 + .3);
277         glVertex3f(-1, 1, 0.0f);
278         glEnd();
279         glPopMatrix();
280         glEnable(GL_BLEND);
281         glPushMatrix();
282         glBegin(GL_QUADS);
283         glTexCoord2f(.4 + loadprogress / 100, 0 + loadprogress / 100);
284         glVertex3f(-1, -1, 0.0f);
285         glTexCoord2f(.4 + loadprogress / 100, 0 + loadprogress / 100);
286         glVertex3f(1, -1, 0.0f);
287         glTexCoord2f(.4 + loadprogress / 100, 1 + loadprogress / 100);
288         glVertex3f(1, 1, 0.0f);
289         glTexCoord2f(.4 + loadprogress / 100, 1 + loadprogress / 100);
290         glVertex3f(-1, 1, 0.0f);
291         glEnd();
292         glPopMatrix();
293         glDisable(GL_TEXTURE_2D);
294         glMatrixMode(GL_PROJECTION);
295         glPopMatrix();
296         glMatrixMode(GL_MODELVIEW);
297         glPopMatrix();
298         glDisable(GL_BLEND);
299         glDepthMask(1);
300
301         glEnable(GL_TEXTURE_2D);
302         loadscreentexture.bind();
303         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
304         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
305         glDisable(GL_DEPTH_TEST);
306         glDisable(GL_CULL_FACE);
307         glDisable(GL_LIGHTING);
308         glDepthMask(0);
309         glMatrixMode(GL_PROJECTION);
310         glPushMatrix();
311         glLoadIdentity();
312         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
313         glMatrixMode(GL_MODELVIEW);
314         glPushMatrix();
315         glLoadIdentity();
316         glTranslatef(screenwidth / 2, screenheight / 2, 0);
317         glScalef((float)screenwidth / 2 * (1.5 - (loadprogress) / 200), (float)screenheight / 2 * (1.5 - (loadprogress) / 200), 1);
318         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
319         glEnable(GL_BLEND);
320         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, 1);
321         glPushMatrix();
322         glBegin(GL_QUADS);
323         glTexCoord2f(0 + .5, 0 + .5);
324         glVertex3f(-1, -1, 0.0f);
325         glTexCoord2f(1 + .5, 0 + .5);
326         glVertex3f(1, -1, 0.0f);
327         glTexCoord2f(1 + .5, 1 + .5);
328         glVertex3f(1, 1, 0.0f);
329         glTexCoord2f(0 + .5, 1 + .5);
330         glVertex3f(-1, 1, 0.0f);
331         glEnd();
332         glPopMatrix();
333         glDisable(GL_TEXTURE_2D);
334         glMatrixMode(GL_PROJECTION);
335         glPopMatrix();
336         glMatrixMode(GL_MODELVIEW);
337         glPopMatrix();
338         glDisable(GL_BLEND);
339         glDepthMask(1);
340
341         glEnable(GL_TEXTURE_2D);
342         loadscreentexture.bind();
343         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
344         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
345         glDisable(GL_DEPTH_TEST);
346         glDisable(GL_CULL_FACE);
347         glDisable(GL_LIGHTING);
348         glDepthMask(0);
349         glMatrixMode(GL_PROJECTION);
350         glPushMatrix();
351         glLoadIdentity();
352         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
353         glMatrixMode(GL_MODELVIEW);
354         glPushMatrix();
355         glLoadIdentity();
356         glTranslatef(screenwidth / 2, screenheight / 2, 0);
357         glScalef((float)screenwidth / 2 * (100 + loadprogress) / 100, (float)screenheight / 2 * (100 + loadprogress) / 100, 1);
358         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
359         glEnable(GL_BLEND);
360         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, .4);
361         glPushMatrix();
362         glBegin(GL_QUADS);
363         glTexCoord2f(0 + .2, 0 + .8);
364         glVertex3f(-1, -1, 0.0f);
365         glTexCoord2f(1 + .2, 0 + .8);
366         glVertex3f(1, -1, 0.0f);
367         glTexCoord2f(1 + .2, 1 + .8);
368         glVertex3f(1, 1, 0.0f);
369         glTexCoord2f(0 + .2, 1 + .8);
370         glVertex3f(-1, 1, 0.0f);
371         glEnd();
372         glPopMatrix();
373         glDisable(GL_TEXTURE_2D);
374         glMatrixMode(GL_PROJECTION);
375         glPopMatrix();
376         glMatrixMode(GL_MODELVIEW);
377         glPopMatrix();
378         glDisable(GL_BLEND);
379         glDepthMask(1);
380
381         //Text
382
383         if (flashamount > 0) {
384             if (flashamount > 1)
385                 flashamount = 1;
386             if (flashdelay <= 0)
387                 flashamount -= multiplier;
388             flashdelay--;
389             if (flashamount < 0)
390                 flashamount = 0;
391             glDisable(GL_DEPTH_TEST);
392             glDisable(GL_CULL_FACE);
393             glDisable(GL_LIGHTING);
394             glDisable(GL_TEXTURE_2D);
395             glDepthMask(0);
396             glMatrixMode(GL_PROJECTION);
397             glPushMatrix();
398             glLoadIdentity();
399             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
400             glMatrixMode(GL_MODELVIEW);
401             glPushMatrix();
402             glLoadIdentity();
403             glScalef(screenwidth, screenheight, 1);
404             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
405             glEnable(GL_BLEND);
406             glColor4f(flashr, flashg, flashb, flashamount);
407             glBegin(GL_QUADS);
408             glVertex3f(0, 0, 0.0f);
409             glVertex3f(256, 0, 0.0f);
410             glVertex3f(256, 256, 0.0f);
411             glVertex3f(0, 256, 0.0f);
412             glEnd();
413             glMatrixMode(GL_PROJECTION);
414             glPopMatrix();
415             glMatrixMode(GL_MODELVIEW);
416             glPopMatrix();
417             glEnable(GL_DEPTH_TEST);
418             glEnable(GL_CULL_FACE);
419             glDisable(GL_BLEND);
420             glDepthMask(1);
421         }
422
423         swap_gl_buffers();
424     }
425 }
426
427 void FadeLoadingScreen(float howmuch)
428 {
429     static float loadprogress;
430
431     glLoadIdentity();
432     //Clear to black
433     glClearColor(0, 0, 0, 1);
434     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
435
436     loadprogress = howmuch;
437
438     //Background
439
440     glDisable(GL_TEXTURE_2D);
441     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
442     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
443     glDisable(GL_DEPTH_TEST);
444     glDisable(GL_CULL_FACE);
445     glDisable(GL_LIGHTING);
446     glDepthMask(0);
447     glMatrixMode(GL_PROJECTION);
448     glPushMatrix();
449     glLoadIdentity();
450     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
451     glMatrixMode(GL_MODELVIEW);
452     glPushMatrix();
453     glLoadIdentity();
454     glTranslatef(screenwidth / 2, screenheight / 2, 0);
455     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
456     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
457     glDisable(GL_BLEND);
458     glColor4f(loadprogress / 100, 0, 0, 1);
459     glPushMatrix();
460     glBegin(GL_QUADS);
461     glTexCoord2f(0, 0);
462     glVertex3f(-1, -1, 0.0f);
463     glTexCoord2f(1, 0);
464     glVertex3f(1, -1, 0.0f);
465     glTexCoord2f(1, 1);
466     glVertex3f(1, 1, 0.0f);
467     glTexCoord2f(0, 1);
468     glVertex3f(-1, 1, 0.0f);
469     glEnd();
470     glPopMatrix();
471     glDisable(GL_TEXTURE_2D);
472     glMatrixMode(GL_PROJECTION);
473     glPopMatrix();
474     glMatrixMode(GL_MODELVIEW);
475     glPopMatrix();
476     glDisable(GL_BLEND);
477     glDepthMask(1);
478     //Text
479     swap_gl_buffers();
480 }
481
482
483 extern bool cmdline(const char *cmd);
484
485 void Game::InitGame()
486 {
487 #if PLATFORM_MACOSX
488     ProcessSerialNumber PSN;
489     ProcessInfoRec pinfo;
490     FSSpec pspec;
491     OSStatus err;
492     /* set up process serial number */
493     PSN.highLongOfPSN = 0;
494     PSN.lowLongOfPSN = kCurrentProcess;
495     /* set up info block */
496     pinfo.processInfoLength = sizeof(pinfo);
497     pinfo.processName = NULL;
498     pinfo.processAppSpec = &pspec;
499     /* grab the vrefnum and directory */
500     err = GetProcessInformation(&PSN, &pinfo);
501     if (err == noErr) {
502         vRefNum = pspec.vRefNum;
503         dirID = pspec.parID;
504     }
505 #endif
506
507     LOGFUNC;
508
509     numchallengelevels = 14;
510
511     accountactive = Account::loadFile(":Data:Users");
512
513     tintr = 1;
514     tintg = 1;
515     tintb = 1;
516
517     whichjointstartarray[0] = righthip;
518     whichjointendarray[0] = rightfoot;
519
520     whichjointstartarray[1] = righthip;
521     whichjointendarray[1] = rightankle;
522
523     whichjointstartarray[2] = righthip;
524     whichjointendarray[2] = rightknee;
525
526     whichjointstartarray[3] = rightknee;
527     whichjointendarray[3] = rightankle;
528
529     whichjointstartarray[4] = rightankle;
530     whichjointendarray[4] = rightfoot;
531
532     whichjointstartarray[5] = lefthip;
533     whichjointendarray[5] = leftfoot;
534
535     whichjointstartarray[6] = lefthip;
536     whichjointendarray[6] = leftankle;
537
538     whichjointstartarray[7] = lefthip;
539     whichjointendarray[7] = leftknee;
540
541     whichjointstartarray[8] = leftknee;
542     whichjointendarray[8] = leftankle;
543
544     whichjointstartarray[9] = leftankle;
545     whichjointendarray[9] = leftfoot;
546
547     whichjointstartarray[10] = abdomen;
548     whichjointendarray[10] = rightshoulder;
549
550     whichjointstartarray[11] = abdomen;
551     whichjointendarray[11] = rightelbow;
552
553     whichjointstartarray[12] = abdomen;
554     whichjointendarray[12] = rightwrist;
555
556     whichjointstartarray[13] = abdomen;
557     whichjointendarray[13] = righthand;
558
559     whichjointstartarray[14] = rightshoulder;
560     whichjointendarray[14] = rightelbow;
561
562     whichjointstartarray[15] = rightelbow;
563     whichjointendarray[15] = rightwrist;
564
565     whichjointstartarray[16] = rightwrist;
566     whichjointendarray[16] = righthand;
567
568     whichjointstartarray[17] = abdomen;
569     whichjointendarray[17] = leftshoulder;
570
571     whichjointstartarray[18] = abdomen;
572     whichjointendarray[18] = leftelbow;
573
574     whichjointstartarray[19] = abdomen;
575     whichjointendarray[19] = leftwrist;
576
577     whichjointstartarray[20] = abdomen;
578     whichjointendarray[20] = lefthand;
579
580     whichjointstartarray[21] = leftshoulder;
581     whichjointendarray[21] = leftelbow;
582
583     whichjointstartarray[22] = leftelbow;
584     whichjointendarray[22] = leftwrist;
585
586     whichjointstartarray[23] = leftwrist;
587     whichjointendarray[23] = lefthand;
588
589     whichjointstartarray[24] = abdomen;
590     whichjointendarray[24] = neck;
591
592     whichjointstartarray[25] = neck;
593     whichjointendarray[25] = head;
594
595     FadeLoadingScreen(0);
596
597     stillloading = 1;
598
599     texture.data = ( GLubyte* )malloc( 1024 * 1024 * 4 );
600
601     int temptexdetail = texdetail;
602     texdetail = 1;
603     text->LoadFontTexture(":Data:Textures:Font.png");
604     text->BuildFont();
605     texdetail = temptexdetail;
606
607     FadeLoadingScreen(10);
608
609     if (detail == 2) {
610         texdetail = 1;
611     }
612     if (detail == 1) {
613         texdetail = 2;
614     }
615     if (detail == 0) {
616         texdetail = 4;
617     }
618
619     LOG("Initializing sound system...");
620
621 #if PLATFORM_LINUX
622     unsigned char rc = 0;
623     int output = OPENAL_OUTPUT_ALSA;  // Try alsa first...
624     if (cmdline("forceoss"))      //  ...but let user override that.
625         output = OPENAL_OUTPUT_OSS;
626     else if (cmdline("nosound"))
627         output = OPENAL_OUTPUT_NOSOUND;
628
629     OPENAL_SetOutput(output);
630     if ((rc = OPENAL_Init(44100, 32, 0)) == false) {
631         // if we tried ALSA and failed, fall back to OSS.
632         if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) ) {
633             OPENAL_Close();
634             output = OPENAL_OUTPUT_OSS;
635             OPENAL_SetOutput(output);
636             rc = OPENAL_Init(44100, 32, 0);
637         }
638     }
639
640     if (rc == false) {
641         OPENAL_Close();
642         output = OPENAL_OUTPUT_NOSOUND;  // we tried! just do silence.
643         OPENAL_SetOutput(output);
644         rc = OPENAL_Init(44100, 32, 0);
645     }
646 #else
647     OPENAL_Init(44100, 32, 0);
648 #endif
649
650     OPENAL_SetSFXMasterVolume((int)(volume * 255));
651     loadAllSounds();
652
653     if (musictoggle)
654         emit_stream_np(stream_menutheme);
655
656     cursortexture.load(":Data:Textures:Cursor.png", 0, 1);
657
658     Mapcircletexture.load(":Data:Textures:MapCircle.png", 0, 1);
659     Mapboxtexture.load(":Data:Textures:MapBox.png", 0, 1);
660     Maparrowtexture.load(":Data:Textures:MapArrow.png", 0, 1);
661
662     temptexdetail = texdetail;
663     if (texdetail > 2)
664         texdetail = 2;
665     Mainmenuitems[0].load(":Data:Textures:Lugaru.png", 0, 0);
666     Mainmenuitems[1].load(":Data:Textures:Newgame.png", 0, 0);
667     Mainmenuitems[2].load(":Data:Textures:Options.png", 0, 0);
668     Mainmenuitems[3].load(":Data:Textures:Quit.png", 0, 0);
669     Mainmenuitems[4].load(":Data:Textures:Eyelid.png", 0, 1);
670     Mainmenuitems[5].load(":Data:Textures:Resume.png", 0, 0);
671     Mainmenuitems[6].load(":Data:Textures:Endgame.png", 0, 0);
672
673     //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
674     //~ LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0); // LoadCampaign will take care of that
675     texdetail = temptexdetail;
676
677     FadeLoadingScreen(95);
678
679
680     gameon = 0;
681     mainmenu = 1;
682
683     stillloading = 0;
684     firstload = 0;
685
686     newdetail = detail;
687     newscreenwidth = screenwidth;
688     newscreenheight = screenheight;
689
690     LoadMenu();
691 }
692
693
694 void Game::LoadScreenTexture()
695 {
696     glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
697
698     if (!Game::screentexture)
699         glGenTextures( 1, &Game::screentexture );
700     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
701
702
703     glEnable(GL_TEXTURE_2D);
704     glBindTexture( GL_TEXTURE_2D, Game::screentexture);
705     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
706     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
707
708     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
709 }
710
711 //TODO: move LoadStuff() closer to GameTick.cpp to get rid of various vars shared in Game.h
712 void Game::LoadStuff()
713 {
714     static float temptexdetail;
715     static float viewdistdetail;
716     static int i, j;
717     float megascale = 1;
718
719     LOGFUNC;
720
721     loadtime = 0;
722
723     stillloading = 1;
724
725     for (auto p:Person::players) {
726         p->skeleton.drawmodel.textureptr.destroy();
727     }
728
729     i = abs(Random() % 4);
730     visibleloading = 0; //don't use loadscreentexture yet
731     loadscreentexture.load(":Data:Textures:fire.jpg", 1, 0);
732     visibleloading = 1;
733
734     temptexdetail = texdetail;
735     texdetail = 1;
736     text->LoadFontTexture(":Data:Textures:Font.png");
737     text->BuildFont();
738     texdetail = temptexdetail;
739
740     numsounds = 71;
741
742     viewdistdetail = 2;
743     viewdistance = 50 * megascale * viewdistdetail;
744
745     if (detail == 2) {
746         texdetail = 1;
747     }
748     if (detail == 1) {
749         texdetail = 2;
750     }
751     if (detail == 0) {
752         texdetail = 4;
753     }
754
755     realtexdetail = texdetail;
756
757     LOG("Loading weapon data...");
758
759     Weapon::knifetextureptr.load(":Data:Textures:knife.png", 0, 1);
760     Weapon::bloodknifetextureptr.load(":Data:Textures:bloodknife.png", 0, 1);
761     Weapon::lightbloodknifetextureptr.load(":Data:Textures:lightbloodknife.png", 0, 1);
762     Weapon::swordtextureptr.load(":Data:Textures:sword.jpg", 1, 0);
763     Weapon::bloodswordtextureptr.load(":Data:Textures:Swordblood.jpg", 1, 0);
764     Weapon::lightbloodswordtextureptr.load(":Data:Textures:Swordbloodlight.jpg", 1, 0);
765     Weapon::stafftextureptr.load(":Data:Textures:Staff.jpg", 1, 0);
766
767     Weapon::throwingknifemodel.load((char *)":Data:Models:throwingknife.solid", 1);
768     Weapon::throwingknifemodel.Scale(.001, .001, .001);
769     //Weapon::throwingknifemodel.Rotate(0,0,-90);
770     Weapon::throwingknifemodel.Rotate(90, 0, 0);
771     Weapon::throwingknifemodel.Rotate(0, 90, 0);
772     Weapon::throwingknifemodel.flat = 0;
773     Weapon::throwingknifemodel.CalculateNormals(1);
774     //Weapon::throwingknifemodel.ScaleNormals(-1,-1,-1);
775
776     Weapon::swordmodel.load((char *)":Data:Models:sword.solid", 1);
777     Weapon::swordmodel.Scale(.001, .001, .001);
778     //Weapon::swordmodel.Rotate(0,0,-90);
779     Weapon::swordmodel.Rotate(90, 0, 0);
780     Weapon::swordmodel.Rotate(0, 90, 0);
781     Weapon::swordmodel.Rotate(0, 0, 90);
782     Weapon::swordmodel.flat = 1;
783     Weapon::swordmodel.CalculateNormals(1);
784     //Weapon::swordmodel.ScaleNormals(-1,-1,-1);
785
786     Weapon::staffmodel.load((char *)":Data:Models:staff.solid", 1);
787     Weapon::staffmodel.Scale(.005, .005, .005);
788     //Weapon::staffmodel.Rotate(0,0,-90);
789     Weapon::staffmodel.Rotate(90, 0, 0);
790     Weapon::staffmodel.Rotate(0, 90, 0);
791     Weapon::staffmodel.Rotate(0, 0, 90);
792     Weapon::staffmodel.flat = 1;
793     Weapon::staffmodel.CalculateNormals(1);
794     //Weapon::staffmodel.ScaleNormals(-1,-1,-1);
795
796     terrain.shadowtexture.load(":Data:Textures:shadow.png", 0, 1);
797     terrain.bloodtexture.load(":Data:Textures:blood.png", 0, 1);
798     terrain.breaktexture.load(":Data:Textures:break.png", 0, 1);
799     terrain.bloodtexture2.load(":Data:Textures:blood.png", 0, 1);
800
801
802     terrain.footprinttexture.load(":Data:Textures:footprint.png", 0, 1);
803     terrain.bodyprinttexture.load(":Data:Textures:bodyprint.png", 0, 1);
804     hawktexture.load(":Data:Textures:hawk.png", 0, 1);
805
806
807     Sprite::cloudtexture.load(":Data:Textures:cloud.png", 1, 1);
808     Sprite::cloudimpacttexture.load(":Data:Textures:cloudimpact.png", 1, 1);
809     Sprite::bloodtexture.load(":Data:Textures:bloodparticle.png", 1, 1);
810     Sprite::snowflaketexture.load(":Data:Textures:snowflake.png", 1, 1);
811     Sprite::flametexture.load(":Data:Textures:flame.png", 1, 1);
812     Sprite::bloodflametexture.load(":Data:Textures:bloodflame.png", 1, 1);
813     Sprite::smoketexture.load(":Data:Textures:smoke.png", 1, 1);
814     Sprite::shinetexture.load(":Data:Textures:shine.png", 1, 0);
815     Sprite::splintertexture.load(":Data:Textures:splinter.png", 1, 1);
816     Sprite::leaftexture.load(":Data:Textures:leaf.png", 1, 1);
817     Sprite::toothtexture.load(":Data:Textures:tooth.png", 1, 1);
818
819     yaw = 0;
820     pitch = 0;
821     ReSizeGLScene(90, .01);
822
823     viewer = 0;
824
825
826     if (detail)
827         kTextureSize = 1024;
828     if (detail == 1)
829         kTextureSize = 512;
830     if (detail == 0)
831         kTextureSize = 256;
832
833     //Set up distant light
834     light.color[0] = .95;
835     light.color[1] = .95;
836     light.color[2] = 1;
837     light.ambient[0] = .2;
838     light.ambient[1] = .2;
839     light.ambient[2] = .24;
840     light.location.x = 1;
841     light.location.y = 1;
842     light.location.z = -.2;
843     Normalise(&light.location);
844
845     LoadingScreen();
846
847     SetUpLighting();
848
849
850     fadestart = .6;
851     gravity = -10;
852
853     texscale = .2 / megascale / viewdistdetail;
854     terrain.scale = 3 * megascale * viewdistdetail;
855
856     viewer.x = terrain.size / 2 * terrain.scale;
857     viewer.z = terrain.size / 2 * terrain.scale;
858
859     hawk.load((char *)":Data:Models:hawk.solid", 1);
860     hawk.Scale(.03, .03, .03);
861     hawk.Rotate(90, 1, 1);
862     hawk.CalculateNormals(0);
863     hawk.ScaleNormals(-1, -1, -1);
864     hawkcoords.x = terrain.size / 2 * terrain.scale - 5 - 7;
865     hawkcoords.z = terrain.size / 2 * terrain.scale - 5 - 7;
866     hawkcoords.y = terrain.getHeight(hawkcoords.x, hawkcoords.z) + 25;
867
868     eye.load((char *)":Data:Models:eye.solid", 1);
869     eye.Scale(.03, .03, .03);
870     eye.CalculateNormals(0);
871
872     cornea.load((char *)":Data:Models:cornea.solid", 1);
873     cornea.Scale(.03, .03, .03);
874     cornea.CalculateNormals(0);
875
876     iris.load((char *)":Data:Models:iris.solid", 1);
877     iris.Scale(.03, .03, .03);
878     iris.CalculateNormals(0);
879
880     LoadSave(":Data:Textures:Bloodfur.png", 0, 1, &bloodText[0], 0);
881     LoadSave(":Data:Textures:Wolfbloodfur.png", 0, 1, &wolfbloodText[0], 0);
882
883     oldenvironment = -4;
884
885     gameon = 1;
886     mainmenu = 0;
887
888     firstload = 0;
889
890     loadAllAnimations();
891     //Fix knife stab, too lazy to do it manually
892     XYZ moveamount;
893     moveamount = 0;
894     moveamount.z = 2;
895     for (i = 0; i < Person::players[0]->skeleton.num_joints; i++) {
896         for (j = 0; j < animation[knifesneakattackanim].numframes; j++) {
897             animation[knifesneakattackanim].position[i][j] += moveamount;
898         }
899     }
900
901     LoadingScreen();
902
903     for (i = 0; i < Person::players[0]->skeleton.num_joints; i++) {
904         for (j = 0; j < animation[knifesneakattackedanim].numframes; j++) {
905             animation[knifesneakattackedanim].position[i][j] += moveamount;
906         }
907     }
908
909     LoadingScreen();
910
911     for (i = 0; i < Person::players[0]->skeleton.num_joints; i++) {
912         animation[dead1anim].position[i][1] = animation[dead1anim].position[i][0];
913         animation[dead2anim].position[i][1] = animation[dead2anim].position[i][0];
914         animation[dead3anim].position[i][1] = animation[dead3anim].position[i][0];
915         animation[dead4anim].position[i][1] = animation[dead4anim].position[i][0];
916     }
917     animation[dead1anim].speed[0] = 0.001;
918     animation[dead2anim].speed[0] = 0.001;
919     animation[dead3anim].speed[0] = 0.001;
920     animation[dead4anim].speed[0] = 0.001;
921
922     animation[dead1anim].speed[1] = 0.001;
923     animation[dead2anim].speed[1] = 0.001;
924     animation[dead3anim].speed[1] = 0.001;
925     animation[dead4anim].speed[1] = 0.001;
926
927     for (i = 0; i < Person::players[0]->skeleton.num_joints; i++) {
928         for (j = 0; j < animation[swordsneakattackanim].numframes; j++) {
929             animation[swordsneakattackanim].position[i][j] += moveamount;
930         }
931     }
932     LoadingScreen();
933     for (j = 0; j < animation[swordsneakattackanim].numframes; j++) {
934         animation[swordsneakattackanim].weapontarget[j] += moveamount;
935     }
936
937     LoadingScreen();
938
939     for (i = 0; i < Person::players[0]->skeleton.num_joints; i++) {
940         for (j = 0; j < animation[swordsneakattackedanim].numframes; j++) {
941             animation[swordsneakattackedanim].position[i][j] += moveamount;
942         }
943     }
944
945     LoadingScreen();
946     temptexdetail = texdetail;
947     texdetail = 1;
948     texdetail = temptexdetail;
949
950     LoadingScreen();
951
952     if (!screentexture) {
953         LoadScreenTexture();
954     }
955
956     if (targetlevel != 7) {
957         emit_sound_at(fireendsound);
958     }
959
960     stillloading = 0;
961     loading = 0;
962     changedelay = 1;
963
964     visibleloading = 0;
965 }
966