]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
e84f10ebb61f29d28eb7cc33c8570092de12d9b3
[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 // this is causing problems on Linux, but we'll force an _exit() a little
92 //  later in the shutdown process.  --ryan.
93 #if !PLATFORM_LINUX
94
95     for (int i = 0; i < sounds_count; ++i) {
96         OPENAL_Sample_Free(samp[i]);
97     }
98
99     OPENAL_Close();
100 #endif
101 }
102
103 void Game::newGame()
104 {
105     text = new Text();
106     textmono = new Text();
107     skybox = new SkyBox();
108 }
109
110 void Game::deleteGame()
111 {
112     delete skybox;
113     delete text;
114     delete textmono;
115
116     glDeleteTextures(1, &screentexture);
117     glDeleteTextures(1, &screentexture2);
118
119     Dispose();
120 }
121
122 void LoadSave(const std::string& fileName, GLubyte* array)
123 {
124     LOGFUNC;
125
126     LOG(std::string("Loading (S)...") + fileName);
127
128     //Load Image
129     float temptexdetail = texdetail;
130     texdetail = 1;
131
132     //Load Image
133     ImageRec texture;
134     if (!load_image(Folders::getResourcePath(fileName).c_str(), texture)) {
135         texdetail = temptexdetail;
136         return;
137     }
138     texdetail = temptexdetail;
139
140     int bytesPerPixel = texture.bpp / 8;
141
142     int tempnum = 0;
143     for (int i = 0; i < (int)(texture.sizeY * texture.sizeX * bytesPerPixel); i++) {
144         if ((i + 1) % 4 || bytesPerPixel == 3) {
145             array[tempnum] = texture.data[i];
146             tempnum++;
147         }
148     }
149 }
150
151 //***************> ResizeGLScene() <******/
152 GLvoid Game::ReSizeGLScene(float fov, float pnear)
153 {
154     if (screenheight == 0) {
155         screenheight = 1;
156     }
157
158     glViewport(0, 0, screenwidth, screenheight);
159
160     glMatrixMode(GL_PROJECTION);
161     glLoadIdentity();
162
163     gluPerspective(fov, (GLfloat)screenwidth / (GLfloat)screenheight, pnear, viewdistance);
164
165     glMatrixMode(GL_MODELVIEW);
166     glLoadIdentity();
167 }
168
169 void Game::LoadingScreen()
170 {
171     if (!visibleloading) {
172         return;
173     }
174
175     static float loadprogress;
176     static AbsoluteTime frametime = { 0, 0 };
177     AbsoluteTime currTime = UpTime();
178     double deltaTime = (float)AbsoluteDeltaToDuration(currTime, frametime);
179
180     if (0 > deltaTime) { // if negative microseconds
181         deltaTime /= -1000000.0;
182     } else { // else milliseconds
183         deltaTime /= 1000.0;
184     }
185
186     multiplier = deltaTime;
187     if (multiplier < .001) {
188         multiplier = .001;
189     }
190     if (multiplier > 10) {
191         multiplier = 10;
192     }
193     if (multiplier > .05) {
194         frametime = currTime; // reset for next time interval
195
196         glLoadIdentity();
197         //Clear to black
198         glClearColor(0, 0, 0, 1);
199         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
200
201         loadtime += multiplier * 4;
202
203         loadprogress = loadtime;
204         if (loadprogress > 100) {
205             loadprogress = 100;
206         }
207
208         //Background
209
210         glEnable(GL_TEXTURE_2D);
211         loadscreentexture.bind();
212         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
213         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
214         glDisable(GL_DEPTH_TEST);
215         glDisable(GL_CULL_FACE);
216         glDisable(GL_LIGHTING);
217         glDepthMask(0);
218         glMatrixMode(GL_PROJECTION);
219         glPushMatrix();
220         glLoadIdentity();
221         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
222         glMatrixMode(GL_MODELVIEW);
223         glPushMatrix();
224         glLoadIdentity();
225         glTranslatef(screenwidth / 2, screenheight / 2, 0);
226         glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
227         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
228         glDisable(GL_BLEND);
229         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, 1);
230         glPushMatrix();
231         glBegin(GL_QUADS);
232         glTexCoord2f(.1 - loadprogress / 100, 0 + loadprogress / 100 + .3);
233         glVertex3f(-1, -1, 0.0f);
234         glTexCoord2f(.1 - loadprogress / 100, 0 + loadprogress / 100 + .3);
235         glVertex3f(1, -1, 0.0f);
236         glTexCoord2f(.1 - loadprogress / 100, 1 + 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         glEnd();
241         glPopMatrix();
242         glEnable(GL_BLEND);
243         glPushMatrix();
244         glBegin(GL_QUADS);
245         glTexCoord2f(.4 + loadprogress / 100, 0 + loadprogress / 100);
246         glVertex3f(-1, -1, 0.0f);
247         glTexCoord2f(.4 + loadprogress / 100, 0 + loadprogress / 100);
248         glVertex3f(1, -1, 0.0f);
249         glTexCoord2f(.4 + loadprogress / 100, 1 + loadprogress / 100);
250         glVertex3f(1, 1, 0.0f);
251         glTexCoord2f(.4 + loadprogress / 100, 1 + loadprogress / 100);
252         glVertex3f(-1, 1, 0.0f);
253         glEnd();
254         glPopMatrix();
255         glDisable(GL_TEXTURE_2D);
256         glMatrixMode(GL_PROJECTION);
257         glPopMatrix();
258         glMatrixMode(GL_MODELVIEW);
259         glPopMatrix();
260         glDisable(GL_BLEND);
261         glDepthMask(1);
262
263         glEnable(GL_TEXTURE_2D);
264         loadscreentexture.bind();
265         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
266         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
267         glDisable(GL_DEPTH_TEST);
268         glDisable(GL_CULL_FACE);
269         glDisable(GL_LIGHTING);
270         glDepthMask(0);
271         glMatrixMode(GL_PROJECTION);
272         glPushMatrix();
273         glLoadIdentity();
274         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
275         glMatrixMode(GL_MODELVIEW);
276         glPushMatrix();
277         glLoadIdentity();
278         glTranslatef(screenwidth / 2, screenheight / 2, 0);
279         glScalef((float)screenwidth / 2 * (1.5 - (loadprogress) / 200), (float)screenheight / 2 * (1.5 - (loadprogress) / 200), 1);
280         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
281         glEnable(GL_BLEND);
282         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, 1);
283         glPushMatrix();
284         glBegin(GL_QUADS);
285         glTexCoord2f(0 + .5, 0 + .5);
286         glVertex3f(-1, -1, 0.0f);
287         glTexCoord2f(1 + .5, 0 + .5);
288         glVertex3f(1, -1, 0.0f);
289         glTexCoord2f(1 + .5, 1 + .5);
290         glVertex3f(1, 1, 0.0f);
291         glTexCoord2f(0 + .5, 1 + .5);
292         glVertex3f(-1, 1, 0.0f);
293         glEnd();
294         glPopMatrix();
295         glDisable(GL_TEXTURE_2D);
296         glMatrixMode(GL_PROJECTION);
297         glPopMatrix();
298         glMatrixMode(GL_MODELVIEW);
299         glPopMatrix();
300         glDisable(GL_BLEND);
301         glDepthMask(1);
302
303         glEnable(GL_TEXTURE_2D);
304         loadscreentexture.bind();
305         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
306         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
307         glDisable(GL_DEPTH_TEST);
308         glDisable(GL_CULL_FACE);
309         glDisable(GL_LIGHTING);
310         glDepthMask(0);
311         glMatrixMode(GL_PROJECTION);
312         glPushMatrix();
313         glLoadIdentity();
314         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
315         glMatrixMode(GL_MODELVIEW);
316         glPushMatrix();
317         glLoadIdentity();
318         glTranslatef(screenwidth / 2, screenheight / 2, 0);
319         glScalef((float)screenwidth / 2 * (100 + loadprogress) / 100, (float)screenheight / 2 * (100 + loadprogress) / 100, 1);
320         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
321         glEnable(GL_BLEND);
322         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, .4);
323         glPushMatrix();
324         glBegin(GL_QUADS);
325         glTexCoord2f(0 + .2, 0 + .8);
326         glVertex3f(-1, -1, 0.0f);
327         glTexCoord2f(1 + .2, 0 + .8);
328         glVertex3f(1, -1, 0.0f);
329         glTexCoord2f(1 + .2, 1 + .8);
330         glVertex3f(1, 1, 0.0f);
331         glTexCoord2f(0 + .2, 1 + .8);
332         glVertex3f(-1, 1, 0.0f);
333         glEnd();
334         glPopMatrix();
335         glDisable(GL_TEXTURE_2D);
336         glMatrixMode(GL_PROJECTION);
337         glPopMatrix();
338         glMatrixMode(GL_MODELVIEW);
339         glPopMatrix();
340         glDisable(GL_BLEND);
341         glDepthMask(1);
342
343         //Text
344
345         if (flashamount > 0) {
346             if (flashamount > 1) {
347                 flashamount = 1;
348             }
349             if (flashdelay <= 0) {
350                 flashamount -= multiplier;
351             }
352             flashdelay--;
353             if (flashamount < 0) {
354                 flashamount = 0;
355             }
356             glDisable(GL_DEPTH_TEST);
357             glDisable(GL_CULL_FACE);
358             glDisable(GL_LIGHTING);
359             glDisable(GL_TEXTURE_2D);
360             glDepthMask(0);
361             glMatrixMode(GL_PROJECTION);
362             glPushMatrix();
363             glLoadIdentity();
364             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
365             glMatrixMode(GL_MODELVIEW);
366             glPushMatrix();
367             glLoadIdentity();
368             glScalef(screenwidth, screenheight, 1);
369             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
370             glEnable(GL_BLEND);
371             glColor4f(flashr, flashg, flashb, flashamount);
372             glBegin(GL_QUADS);
373             glVertex3f(0, 0, 0.0f);
374             glVertex3f(256, 0, 0.0f);
375             glVertex3f(256, 256, 0.0f);
376             glVertex3f(0, 256, 0.0f);
377             glEnd();
378             glMatrixMode(GL_PROJECTION);
379             glPopMatrix();
380             glMatrixMode(GL_MODELVIEW);
381             glPopMatrix();
382             glEnable(GL_DEPTH_TEST);
383             glEnable(GL_CULL_FACE);
384             glDisable(GL_BLEND);
385             glDepthMask(1);
386         }
387
388         swap_gl_buffers();
389     }
390 }
391
392 void FadeLoadingScreen(float howmuch)
393 {
394     static float loadprogress;
395
396     glLoadIdentity();
397     //Clear to black
398     glClearColor(0, 0, 0, 1);
399     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
400
401     loadprogress = howmuch;
402
403     //Background
404
405     glDisable(GL_TEXTURE_2D);
406     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
407     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
408     glDisable(GL_DEPTH_TEST);
409     glDisable(GL_CULL_FACE);
410     glDisable(GL_LIGHTING);
411     glDepthMask(0);
412     glMatrixMode(GL_PROJECTION);
413     glPushMatrix();
414     glLoadIdentity();
415     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
416     glMatrixMode(GL_MODELVIEW);
417     glPushMatrix();
418     glLoadIdentity();
419     glTranslatef(screenwidth / 2, screenheight / 2, 0);
420     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
421     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
422     glDisable(GL_BLEND);
423     glColor4f(loadprogress / 100, 0, 0, 1);
424     glPushMatrix();
425     glBegin(GL_QUADS);
426     glTexCoord2f(0, 0);
427     glVertex3f(-1, -1, 0.0f);
428     glTexCoord2f(1, 0);
429     glVertex3f(1, -1, 0.0f);
430     glTexCoord2f(1, 1);
431     glVertex3f(1, 1, 0.0f);
432     glTexCoord2f(0, 1);
433     glVertex3f(-1, 1, 0.0f);
434     glEnd();
435     glPopMatrix();
436     glDisable(GL_TEXTURE_2D);
437     glMatrixMode(GL_PROJECTION);
438     glPopMatrix();
439     glMatrixMode(GL_MODELVIEW);
440     glPopMatrix();
441     glDisable(GL_BLEND);
442     glDepthMask(1);
443     //Text
444     swap_gl_buffers();
445 }
446
447 void Game::InitGame()
448 {
449     LOGFUNC;
450
451     numchallengelevels = 14;
452
453     Account::loadFile(Folders::getUserSavePath());
454
455     whichjointstartarray[0] = righthip;
456     whichjointendarray[0] = rightfoot;
457
458     whichjointstartarray[1] = righthip;
459     whichjointendarray[1] = rightankle;
460
461     whichjointstartarray[2] = righthip;
462     whichjointendarray[2] = rightknee;
463
464     whichjointstartarray[3] = rightknee;
465     whichjointendarray[3] = rightankle;
466
467     whichjointstartarray[4] = rightankle;
468     whichjointendarray[4] = rightfoot;
469
470     whichjointstartarray[5] = lefthip;
471     whichjointendarray[5] = leftfoot;
472
473     whichjointstartarray[6] = lefthip;
474     whichjointendarray[6] = leftankle;
475
476     whichjointstartarray[7] = lefthip;
477     whichjointendarray[7] = leftknee;
478
479     whichjointstartarray[8] = leftknee;
480     whichjointendarray[8] = leftankle;
481
482     whichjointstartarray[9] = leftankle;
483     whichjointendarray[9] = leftfoot;
484
485     whichjointstartarray[10] = abdomen;
486     whichjointendarray[10] = rightshoulder;
487
488     whichjointstartarray[11] = abdomen;
489     whichjointendarray[11] = rightelbow;
490
491     whichjointstartarray[12] = abdomen;
492     whichjointendarray[12] = rightwrist;
493
494     whichjointstartarray[13] = abdomen;
495     whichjointendarray[13] = righthand;
496
497     whichjointstartarray[14] = rightshoulder;
498     whichjointendarray[14] = rightelbow;
499
500     whichjointstartarray[15] = rightelbow;
501     whichjointendarray[15] = rightwrist;
502
503     whichjointstartarray[16] = rightwrist;
504     whichjointendarray[16] = righthand;
505
506     whichjointstartarray[17] = abdomen;
507     whichjointendarray[17] = leftshoulder;
508
509     whichjointstartarray[18] = abdomen;
510     whichjointendarray[18] = leftelbow;
511
512     whichjointstartarray[19] = abdomen;
513     whichjointendarray[19] = leftwrist;
514
515     whichjointstartarray[20] = abdomen;
516     whichjointendarray[20] = lefthand;
517
518     whichjointstartarray[21] = leftshoulder;
519     whichjointendarray[21] = leftelbow;
520
521     whichjointstartarray[22] = leftelbow;
522     whichjointendarray[22] = leftwrist;
523
524     whichjointstartarray[23] = leftwrist;
525     whichjointendarray[23] = lefthand;
526
527     whichjointstartarray[24] = abdomen;
528     whichjointendarray[24] = neck;
529
530     whichjointstartarray[25] = neck;
531     whichjointendarray[25] = head;
532
533     FadeLoadingScreen(0);
534
535     stillloading = 1;
536
537     int temptexdetail = texdetail;
538     texdetail = 1;
539     text->LoadFontTexture("Textures/Font.png");
540     text->BuildFont();
541     textmono->LoadFontTexture("Textures/FontMono.png");
542     textmono->BuildFont();
543     texdetail = temptexdetail;
544
545     FadeLoadingScreen(10);
546
547     if (detail == 2) {
548         texdetail = 1;
549     }
550     if (detail == 1) {
551         texdetail = 2;
552     }
553     if (detail == 0) {
554         texdetail = 4;
555     }
556
557     LOG("Initializing sound system...");
558
559     OPENAL_Init(44100, 32, 0);
560
561     OPENAL_SetSFXMasterVolume((int)(volume * 255));
562     loadAllSounds();
563
564     if (musictoggle) {
565         emit_stream_np(stream_menutheme);
566     }
567
568     cursortexture.load("Textures/Cursor.png", 0);
569
570     Mapcircletexture.load("Textures/MapCircle.png", 0);
571     Mapboxtexture.load("Textures/MapBox.png", 0);
572     Maparrowtexture.load("Textures/MapArrow.png", 0);
573
574     temptexdetail = texdetail;
575     if (texdetail > 2) {
576         texdetail = 2;
577     }
578     Mainmenuitems[0].load("Textures/Lugaru.png", 0);
579     Mainmenuitems[1].load("Textures/NewGame.png", 0);
580     Mainmenuitems[2].load("Textures/Options.png", 0);
581     Mainmenuitems[3].load("Textures/Quit.png", 0);
582     Mainmenuitems[4].load("Textures/Eyelid.png", 0);
583     Mainmenuitems[5].load("Textures/Resume.png", 0);
584     Mainmenuitems[6].load("Textures/EndGame.png", 0);
585
586     texdetail = temptexdetail;
587
588     FadeLoadingScreen(95);
589
590     gameon = 0;
591     mainmenu = 1;
592
593     stillloading = 0;
594     firstLoadDone = false;
595
596     newdetail = detail;
597     newscreenwidth = screenwidth;
598     newscreenheight = screenheight;
599
600     Menu::Load();
601
602     Animation::loadAll();
603
604     PersonType::Load();
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/WolfBloodFur.png", &PersonType::types[wolftype].bloodText[0]);
742     LoadSave("Textures/BloodFur.png", &PersonType::types[rabbittype].bloodText[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 }