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