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