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