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