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