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