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