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