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