]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
Moved visibleloading check inside LoadingScreen
[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 &fmt, ...)
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     skybox = new SkyBox();
109 }
110
111 void Game::deleteGame()
112 {
113     if (skybox)
114         delete skybox;
115     if (text)
116         delete text;
117
118     glDeleteTextures(1, &screentexture);
119     glDeleteTextures(1, &screentexture2);
120
121     Dispose();
122 }
123
124
125
126 void LoadSave(const std::string& fileName, GLuint *textureid, bool mipmap, GLubyte *array, int *skinsize)
127 {
128     LOGFUNC;
129
130     LOG(std::string("Loading (S)...") + fileName);
131
132     //Load Image
133     float temptexdetail = texdetail;
134     texdetail = 1;
135
136     //Load Image
137     ImageRec texture;
138     if (!load_image(Folders::getResourcePath(fileName).c_str(), texture)) {
139         texdetail = temptexdetail;
140         return;
141     }
142     texdetail = temptexdetail;
143
144     int bytesPerPixel = texture.bpp / 8;
145
146     int tempnum = 0;
147     for (int i = 0; i < (int)(texture.sizeY * texture.sizeX * bytesPerPixel); i++) {
148         if ((i + 1) % 4 || bytesPerPixel == 3) {
149             array[tempnum] = texture.data[i];
150             tempnum++;
151         }
152     }
153 }
154
155
156
157 //***************> ResizeGLScene() <******/
158 GLvoid Game::ReSizeGLScene(float fov, float pnear)
159 {
160     if (screenheight == 0) {
161         screenheight = 1;
162     }
163
164     glViewport(0, 0, screenwidth, screenheight);
165
166     glMatrixMode(GL_PROJECTION);
167     glLoadIdentity();
168
169     gluPerspective(fov, (GLfloat)screenwidth / (GLfloat)screenheight, pnear, viewdistance);
170
171     glMatrixMode(GL_MODELVIEW);
172     glLoadIdentity();
173 }
174
175 void Game::LoadingScreen()
176 {
177     if (!visibleloading) {
178         return;
179     }
180
181     static float loadprogress;
182     static AbsoluteTime frametime = {0, 0};
183     AbsoluteTime currTime = UpTime ();
184     double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
185
186     if (0 > deltaTime) // if negative microseconds
187         deltaTime /= -1000000.0;
188     else // else milliseconds
189         deltaTime /= 1000.0;
190
191     multiplier = deltaTime;
192     if (multiplier < .001)
193         multiplier = .001;
194     if (multiplier > 10)
195         multiplier = 10;
196     if (multiplier > .05) {
197         frametime = currTime; // reset for next time interval
198
199         glLoadIdentity();
200         //Clear to black
201         glClearColor(0, 0, 0, 1);
202         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
203
204
205         loadtime += multiplier * 4;
206
207         loadprogress = loadtime;
208         if (loadprogress > 100)
209             loadprogress = 100;
210
211         //Background
212
213         glEnable(GL_TEXTURE_2D);
214         loadscreentexture.bind();
215         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
216         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
217         glDisable(GL_DEPTH_TEST);
218         glDisable(GL_CULL_FACE);
219         glDisable(GL_LIGHTING);
220         glDepthMask(0);
221         glMatrixMode(GL_PROJECTION);
222         glPushMatrix();
223         glLoadIdentity();
224         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
225         glMatrixMode(GL_MODELVIEW);
226         glPushMatrix();
227         glLoadIdentity();
228         glTranslatef(screenwidth / 2, screenheight / 2, 0);
229         glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
230         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
231         glDisable(GL_BLEND);
232         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, 1);
233         glPushMatrix();
234         glBegin(GL_QUADS);
235         glTexCoord2f(.1 - loadprogress / 100, 0 + loadprogress / 100 + .3);
236         glVertex3f(-1, -1, 0.0f);
237         glTexCoord2f(.1 - loadprogress / 100, 0 + loadprogress / 100 + .3);
238         glVertex3f(1, -1, 0.0f);
239         glTexCoord2f(.1 - loadprogress / 100, 1 + loadprogress / 100 + .3);
240         glVertex3f(1, 1, 0.0f);
241         glTexCoord2f(.1 - loadprogress / 100, 1 + loadprogress / 100 + .3);
242         glVertex3f(-1, 1, 0.0f);
243         glEnd();
244         glPopMatrix();
245         glEnable(GL_BLEND);
246         glPushMatrix();
247         glBegin(GL_QUADS);
248         glTexCoord2f(.4 + loadprogress / 100, 0 + loadprogress / 100);
249         glVertex3f(-1, -1, 0.0f);
250         glTexCoord2f(.4 + loadprogress / 100, 0 + loadprogress / 100);
251         glVertex3f(1, -1, 0.0f);
252         glTexCoord2f(.4 + loadprogress / 100, 1 + loadprogress / 100);
253         glVertex3f(1, 1, 0.0f);
254         glTexCoord2f(.4 + loadprogress / 100, 1 + loadprogress / 100);
255         glVertex3f(-1, 1, 0.0f);
256         glEnd();
257         glPopMatrix();
258         glDisable(GL_TEXTURE_2D);
259         glMatrixMode(GL_PROJECTION);
260         glPopMatrix();
261         glMatrixMode(GL_MODELVIEW);
262         glPopMatrix();
263         glDisable(GL_BLEND);
264         glDepthMask(1);
265
266         glEnable(GL_TEXTURE_2D);
267         loadscreentexture.bind();
268         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
269         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
270         glDisable(GL_DEPTH_TEST);
271         glDisable(GL_CULL_FACE);
272         glDisable(GL_LIGHTING);
273         glDepthMask(0);
274         glMatrixMode(GL_PROJECTION);
275         glPushMatrix();
276         glLoadIdentity();
277         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
278         glMatrixMode(GL_MODELVIEW);
279         glPushMatrix();
280         glLoadIdentity();
281         glTranslatef(screenwidth / 2, screenheight / 2, 0);
282         glScalef((float)screenwidth / 2 * (1.5 - (loadprogress) / 200), (float)screenheight / 2 * (1.5 - (loadprogress) / 200), 1);
283         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
284         glEnable(GL_BLEND);
285         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, 1);
286         glPushMatrix();
287         glBegin(GL_QUADS);
288         glTexCoord2f(0 + .5, 0 + .5);
289         glVertex3f(-1, -1, 0.0f);
290         glTexCoord2f(1 + .5, 0 + .5);
291         glVertex3f(1, -1, 0.0f);
292         glTexCoord2f(1 + .5, 1 + .5);
293         glVertex3f(1, 1, 0.0f);
294         glTexCoord2f(0 + .5, 1 + .5);
295         glVertex3f(-1, 1, 0.0f);
296         glEnd();
297         glPopMatrix();
298         glDisable(GL_TEXTURE_2D);
299         glMatrixMode(GL_PROJECTION);
300         glPopMatrix();
301         glMatrixMode(GL_MODELVIEW);
302         glPopMatrix();
303         glDisable(GL_BLEND);
304         glDepthMask(1);
305
306         glEnable(GL_TEXTURE_2D);
307         loadscreentexture.bind();
308         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
309         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
310         glDisable(GL_DEPTH_TEST);
311         glDisable(GL_CULL_FACE);
312         glDisable(GL_LIGHTING);
313         glDepthMask(0);
314         glMatrixMode(GL_PROJECTION);
315         glPushMatrix();
316         glLoadIdentity();
317         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
318         glMatrixMode(GL_MODELVIEW);
319         glPushMatrix();
320         glLoadIdentity();
321         glTranslatef(screenwidth / 2, screenheight / 2, 0);
322         glScalef((float)screenwidth / 2 * (100 + loadprogress) / 100, (float)screenheight / 2 * (100 + loadprogress) / 100, 1);
323         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
324         glEnable(GL_BLEND);
325         glColor4f(loadprogress / 100, loadprogress / 100, loadprogress / 100, .4);
326         glPushMatrix();
327         glBegin(GL_QUADS);
328         glTexCoord2f(0 + .2, 0 + .8);
329         glVertex3f(-1, -1, 0.0f);
330         glTexCoord2f(1 + .2, 0 + .8);
331         glVertex3f(1, -1, 0.0f);
332         glTexCoord2f(1 + .2, 1 + .8);
333         glVertex3f(1, 1, 0.0f);
334         glTexCoord2f(0 + .2, 1 + .8);
335         glVertex3f(-1, 1, 0.0f);
336         glEnd();
337         glPopMatrix();
338         glDisable(GL_TEXTURE_2D);
339         glMatrixMode(GL_PROJECTION);
340         glPopMatrix();
341         glMatrixMode(GL_MODELVIEW);
342         glPopMatrix();
343         glDisable(GL_BLEND);
344         glDepthMask(1);
345
346         //Text
347
348         if (flashamount > 0) {
349             if (flashamount > 1)
350                 flashamount = 1;
351             if (flashdelay <= 0)
352                 flashamount -= multiplier;
353             flashdelay--;
354             if (flashamount < 0)
355                 flashamount = 0;
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     texdetail = temptexdetail;
542
543     FadeLoadingScreen(10);
544
545     if (detail == 2) {
546         texdetail = 1;
547     }
548     if (detail == 1) {
549         texdetail = 2;
550     }
551     if (detail == 0) {
552         texdetail = 4;
553     }
554
555     LOG("Initializing sound system...");
556
557 #if PLATFORM_LINUX
558     unsigned char rc = 0;
559     int output = OPENAL_OUTPUT_ALSA;  // Try alsa first...
560     if (commandLineOptions[SOUND]) {
561         output = commandLineOptions[SOUND].last()->type(); //  ...but let user override that.
562     }
563
564     OPENAL_SetOutput(output);
565     if ((rc = OPENAL_Init(44100, 32, 0)) == false) {
566         // if we tried ALSA and failed, fall back to OSS.
567         if ( (output == OPENAL_OUTPUT_ALSA) && (commandLineOptions[SOUND].last()->type() != OPENAL_OUTPUT_ALSA) ) {
568             OPENAL_Close();
569             output = OPENAL_OUTPUT_OSS;
570             OPENAL_SetOutput(output);
571             rc = OPENAL_Init(44100, 32, 0);
572         }
573     }
574
575     if (rc == false) {
576         OPENAL_Close();
577         output = OPENAL_OUTPUT_NOSOUND;  // we tried! just do silence.
578         OPENAL_SetOutput(output);
579         rc = OPENAL_Init(44100, 32, 0);
580     }
581 #else
582     OPENAL_Init(44100, 32, 0);
583 #endif
584
585     OPENAL_SetSFXMasterVolume((int)(volume * 255));
586     loadAllSounds();
587
588     if (musictoggle)
589         emit_stream_np(stream_menutheme);
590
591     cursortexture.load("Textures/Cursor.png", 0);
592
593     Mapcircletexture.load("Textures/MapCircle.png", 0);
594     Mapboxtexture.load("Textures/MapBox.png", 0);
595     Maparrowtexture.load("Textures/MapArrow.png", 0);
596
597     temptexdetail = texdetail;
598     if (texdetail > 2)
599         texdetail = 2;
600     Mainmenuitems[0].load("Textures/Lugaru.png", 0);
601     Mainmenuitems[1].load("Textures/NewGame.png", 0);
602     Mainmenuitems[2].load("Textures/Options.png", 0);
603     Mainmenuitems[3].load("Textures/Quit.png", 0);
604     Mainmenuitems[4].load("Textures/Eyelid.png", 0);
605     Mainmenuitems[5].load("Textures/Resume.png", 0);
606     Mainmenuitems[6].load("Textures/EndGame.png", 0);
607
608     texdetail = temptexdetail;
609
610     FadeLoadingScreen(95);
611
612
613     gameon = 0;
614     mainmenu = 1;
615
616     stillloading = 0;
617     firstload = 0;
618
619     newdetail = detail;
620     newscreenwidth = screenwidth;
621     newscreenheight = screenheight;
622
623     Menu::Load();
624
625     Animation::loadAll();
626 }
627
628
629 void Game::LoadScreenTexture()
630 {
631     glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
632
633     if (!Game::screentexture)
634         glGenTextures( 1, &Game::screentexture );
635     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
636
637
638     glEnable(GL_TEXTURE_2D);
639     glBindTexture( GL_TEXTURE_2D, Game::screentexture);
640     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
641     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
642
643     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
644 }
645
646 //TODO: move LoadStuff() closer to GameTick.cpp to get rid of various vars shared in Game.hpp
647 void Game::LoadStuff()
648 {
649     static float temptexdetail;
650     static float viewdistdetail;
651     float megascale = 1;
652
653     LOGFUNC;
654
655     loadtime = 0;
656
657     stillloading = 1;
658
659     visibleloading = false; //don't use loadscreentexture yet
660     loadscreentexture.load("Textures/Fire.jpg", 1);
661     visibleloading = true;
662
663     temptexdetail = texdetail;
664     texdetail = 1;
665     text->LoadFontTexture("Textures/Font.png");
666     text->BuildFont();
667     texdetail = temptexdetail;
668
669     viewdistdetail = 2;
670     viewdistance = 50 * megascale * viewdistdetail;
671
672     if (detail == 2) {
673         texdetail = 1;
674         kTextureSize = 1024;
675     } else if (detail == 1) {
676         texdetail = 2;
677         kTextureSize = 512;
678     } else {
679         texdetail = 4;
680         kTextureSize = 256;
681     }
682
683     realtexdetail = texdetail;
684
685     LOG("Loading weapon data...");
686
687     Weapon::knifetextureptr.load("Textures/Knife.png", 0);
688     Weapon::bloodknifetextureptr.load("Textures/BloodKnife.png", 0);
689     Weapon::lightbloodknifetextureptr.load("Textures/BloodKnifeLight.png", 0);
690     Weapon::swordtextureptr.load("Textures/Sword.jpg", 1);
691     Weapon::bloodswordtextureptr.load("Textures/SwordBlood.jpg", 1);
692     Weapon::lightbloodswordtextureptr.load("Textures/SwordBloodLight.jpg", 1);
693     Weapon::stafftextureptr.load("Textures/Staff.jpg", 1);
694
695     Weapon::throwingknifemodel.load("Models/ThrowingKnife.solid", 1);
696     Weapon::throwingknifemodel.Scale(.001, .001, .001);
697     Weapon::throwingknifemodel.Rotate(90, 0, 0);
698     Weapon::throwingknifemodel.Rotate(0, 90, 0);
699     Weapon::throwingknifemodel.flat = 0;
700     Weapon::throwingknifemodel.CalculateNormals(1);
701
702     Weapon::swordmodel.load("Models/Sword.solid", 1);
703     Weapon::swordmodel.Scale(.001, .001, .001);
704     Weapon::swordmodel.Rotate(90, 0, 0);
705     Weapon::swordmodel.Rotate(0, 90, 0);
706     Weapon::swordmodel.Rotate(0, 0, 90);
707     Weapon::swordmodel.flat = 1;
708     Weapon::swordmodel.CalculateNormals(1);
709
710     Weapon::staffmodel.load("Models/Staff.solid", 1);
711     Weapon::staffmodel.Scale(.005, .005, .005);
712     Weapon::staffmodel.Rotate(90, 0, 0);
713     Weapon::staffmodel.Rotate(0, 90, 0);
714     Weapon::staffmodel.Rotate(0, 0, 90);
715     Weapon::staffmodel.flat = 1;
716     Weapon::staffmodel.CalculateNormals(1);
717
718     terrain.shadowtexture.load("Textures/Shadow.png", 0);
719     terrain.bloodtexture.load("Textures/Blood.png", 0);
720     terrain.breaktexture.load("Textures/Break.png", 0);
721     terrain.bloodtexture2.load("Textures/Blood.png", 0);
722
723
724     terrain.footprinttexture.load("Textures/Footprint.png", 0);
725     terrain.bodyprinttexture.load("Textures/Bodyprint.png", 0);
726     hawktexture.load("Textures/Hawk.png", 0);
727
728
729     Sprite::cloudtexture.load("Textures/Cloud.png", 1);
730     Sprite::cloudimpacttexture.load("Textures/CloudImpact.png", 1);
731     Sprite::bloodtexture.load("Textures/BloodParticle.png", 1);
732     Sprite::snowflaketexture.load("Textures/SnowFlake.png", 1);
733     Sprite::flametexture.load("Textures/Flame.png", 1);
734     Sprite::bloodflametexture.load("Textures/BloodFlame.png", 1);
735     Sprite::smoketexture.load("Textures/Smoke.png", 1);
736     Sprite::shinetexture.load("Textures/Shine.png", 1);
737     Sprite::splintertexture.load("Textures/Splinter.png", 1);
738     Sprite::leaftexture.load("Textures/Leaf.png", 1);
739     Sprite::toothtexture.load("Textures/Tooth.png", 1);
740
741     yaw = 0;
742     pitch = 0;
743     ReSizeGLScene(90, .01);
744
745     viewer = 0;
746
747     //Set up distant light
748     light.color[0] = .95;
749     light.color[1] = .95;
750     light.color[2] = 1;
751     light.ambient[0] = .2;
752     light.ambient[1] = .2;
753     light.ambient[2] = .24;
754     light.location.x = 1;
755     light.location.y = 1;
756     light.location.z = -.2;
757     Normalise(&light.location);
758
759     LoadingScreen();
760
761     SetUpLighting();
762
763
764     fadestart = .6;
765     gravity = -10;
766
767     texscale = .2 / megascale / viewdistdetail;
768     terrain.scale = 3 * megascale * viewdistdetail;
769
770     viewer.x = terrain.size / 2 * terrain.scale;
771     viewer.z = terrain.size / 2 * terrain.scale;
772
773     hawk.load("Models/Hawk.solid", 1);
774     hawk.Scale(.03, .03, .03);
775     hawk.Rotate(90, 1, 1);
776     hawk.CalculateNormals(0);
777     hawk.ScaleNormals(-1, -1, -1);
778     hawkcoords.x = terrain.size / 2 * terrain.scale - 5 - 7;
779     hawkcoords.z = terrain.size / 2 * terrain.scale - 5 - 7;
780     hawkcoords.y = terrain.getHeight(hawkcoords.x, hawkcoords.z) + 25;
781
782     eye.load("Models/Eye.solid", 1);
783     eye.Scale(.03, .03, .03);
784     eye.CalculateNormals(0);
785
786     cornea.load("Models/Cornea.solid", 1);
787     cornea.Scale(.03, .03, .03);
788     cornea.CalculateNormals(0);
789
790     iris.load("Models/Iris.solid", 1);
791     iris.Scale(.03, .03, .03);
792     iris.CalculateNormals(0);
793
794     LoadSave("Textures/BloodFur.png", 0, 1, &bloodText[0], 0);
795     LoadSave("Textures/WolfBloodFur.png", 0, 1, &wolfbloodText[0], 0);
796
797     oldenvironment = -4;
798
799     gameon = 1;
800     mainmenu = 0;
801
802     firstload = 0;
803
804     //Fix knife stab, too lazy to do it manually
805     XYZ moveamount;
806     moveamount = 0;
807     moveamount.z = 2;
808     // FIXME - Why this uses skeleton.joints.size() and not Animation::numjoints? (are they equal?)
809     // It seems skeleton.joints.size() is 0 at this point, so this is useless.
810     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
811         for (unsigned j = 0; j < Animation::animations[knifesneakattackanim].frames.size(); j++) {
812             Animation::animations[knifesneakattackanim].frames[j].joints[i].position += moveamount;
813         }
814     }
815
816     LoadingScreen();
817
818     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
819         for (unsigned j = 0; j < Animation::animations[knifesneakattackedanim].frames.size(); j++) {
820             Animation::animations[knifesneakattackedanim].frames[j].joints[i].position += moveamount;
821         }
822     }
823
824     LoadingScreen();
825
826     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
827         Animation::animations[dead1anim].frames[1].joints[i].position = Animation::animations[dead1anim].frames[0].joints[i].position;
828         Animation::animations[dead2anim].frames[1].joints[i].position = Animation::animations[dead2anim].frames[0].joints[i].position;
829         Animation::animations[dead3anim].frames[1].joints[i].position = Animation::animations[dead3anim].frames[0].joints[i].position;
830         Animation::animations[dead4anim].frames[1].joints[i].position = Animation::animations[dead4anim].frames[0].joints[i].position;
831     }
832     Animation::animations[dead1anim].frames[0].speed = 0.001;
833     Animation::animations[dead2anim].frames[0].speed = 0.001;
834     Animation::animations[dead3anim].frames[0].speed = 0.001;
835     Animation::animations[dead4anim].frames[0].speed = 0.001;
836
837     Animation::animations[dead1anim].frames[1].speed = 0.001;
838     Animation::animations[dead2anim].frames[1].speed = 0.001;
839     Animation::animations[dead3anim].frames[1].speed = 0.001;
840     Animation::animations[dead4anim].frames[1].speed = 0.001;
841
842     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
843         for (unsigned j = 0; j < Animation::animations[swordsneakattackanim].frames.size(); j++) {
844             Animation::animations[swordsneakattackanim].frames[j].joints[i].position += moveamount;
845         }
846     }
847     LoadingScreen();
848     for (unsigned j = 0; j < Animation::animations[swordsneakattackanim].frames.size(); j++) {
849         Animation::animations[swordsneakattackanim].frames[j].weapontarget += moveamount;
850     }
851
852     LoadingScreen();
853
854     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
855         for (unsigned j = 0; j < Animation::animations[swordsneakattackedanim].frames.size(); j++) {
856             Animation::animations[swordsneakattackedanim].frames[j].joints[i].position += moveamount;
857         }
858     }
859
860     LoadingScreen();
861     temptexdetail = texdetail;
862     texdetail = 1;
863     texdetail = temptexdetail;
864
865     LoadingScreen();
866
867     if (!screentexture) {
868         LoadScreenTexture();
869     }
870
871     if (targetlevel != 7) {
872         emit_sound_at(fireendsound);
873     }
874
875     stillloading = 0;
876     loading = 0;
877     changedelay = 1;
878
879     visibleloading = false;
880 }
881