]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
Cleaned up Objects handling
[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.hpp"
22
23 #include "Animation/Animation.hpp"
24 #include "Audio/openal_wrapper.hpp"
25 #include "Graphic/Texture.hpp"
26 #include "Menu/Menu.hpp"
27 #include "Utils/Folders.hpp"
28
29 extern float screenwidth, screenheight;
30 extern float viewdistance;
31 extern XYZ viewer;
32 extern float fadestart;
33 extern float texscale;
34 extern float gravity;
35 extern Light light;
36 extern Terrain terrain;
37 extern int kTextureSize;
38 extern float texdetail;
39 extern float realtexdetail;
40 extern float volume;
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 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         Account::active().endGame();
82         Game::endgame = 0;
83     }
84
85     Account::saveFile(Folders::getUserSavePath());
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     Account::loadFile(Folders::getUserSavePath());
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     Menu::Load();
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.hpp
654 void Game::LoadStuff()
655 {
656     static float temptexdetail;
657     static float viewdistdetail;
658     float megascale = 1;
659
660     LOGFUNC;
661
662     loadtime = 0;
663
664     stillloading = 1;
665
666     for (auto p:Person::players) {
667         p->skeleton.drawmodel.textureptr.destroy();
668     }
669
670     visibleloading = 0; //don't use loadscreentexture yet
671     loadscreentexture.load("Textures/Fire.jpg", 1);
672     visibleloading = 1;
673
674     temptexdetail = texdetail;
675     texdetail = 1;
676     text->LoadFontTexture("Textures/Font.png");
677     text->BuildFont();
678     texdetail = temptexdetail;
679
680     viewdistdetail = 2;
681     viewdistance = 50 * megascale * viewdistdetail;
682
683     if (detail == 2) {
684         texdetail = 1;
685         kTextureSize = 1024;
686     } else if (detail == 1) {
687         texdetail = 2;
688         kTextureSize = 512;
689     } else {
690         texdetail = 4;
691         kTextureSize = 256;
692     }
693
694     realtexdetail = texdetail;
695
696     LOG("Loading weapon data...");
697
698     Weapon::knifetextureptr.load("Textures/Knife.png", 0);
699     Weapon::bloodknifetextureptr.load("Textures/BloodKnife.png", 0);
700     Weapon::lightbloodknifetextureptr.load("Textures/BloodKnifeLight.png", 0);
701     Weapon::swordtextureptr.load("Textures/Sword.jpg", 1);
702     Weapon::bloodswordtextureptr.load("Textures/SwordBlood.jpg", 1);
703     Weapon::lightbloodswordtextureptr.load("Textures/SwordBloodLight.jpg", 1);
704     Weapon::stafftextureptr.load("Textures/Staff.jpg", 1);
705
706     Weapon::throwingknifemodel.load("Models/ThrowingKnife.solid", 1);
707     Weapon::throwingknifemodel.Scale(.001, .001, .001);
708     Weapon::throwingknifemodel.Rotate(90, 0, 0);
709     Weapon::throwingknifemodel.Rotate(0, 90, 0);
710     Weapon::throwingknifemodel.flat = 0;
711     Weapon::throwingknifemodel.CalculateNormals(1);
712
713     Weapon::swordmodel.load("Models/Sword.solid", 1);
714     Weapon::swordmodel.Scale(.001, .001, .001);
715     Weapon::swordmodel.Rotate(90, 0, 0);
716     Weapon::swordmodel.Rotate(0, 90, 0);
717     Weapon::swordmodel.Rotate(0, 0, 90);
718     Weapon::swordmodel.flat = 1;
719     Weapon::swordmodel.CalculateNormals(1);
720
721     Weapon::staffmodel.load("Models/Staff.solid", 1);
722     Weapon::staffmodel.Scale(.005, .005, .005);
723     Weapon::staffmodel.Rotate(90, 0, 0);
724     Weapon::staffmodel.Rotate(0, 90, 0);
725     Weapon::staffmodel.Rotate(0, 0, 90);
726     Weapon::staffmodel.flat = 1;
727     Weapon::staffmodel.CalculateNormals(1);
728
729     terrain.shadowtexture.load("Textures/Shadow.png", 0);
730     terrain.bloodtexture.load("Textures/Blood.png", 0);
731     terrain.breaktexture.load("Textures/Break.png", 0);
732     terrain.bloodtexture2.load("Textures/Blood.png", 0);
733
734
735     terrain.footprinttexture.load("Textures/Footprint.png", 0);
736     terrain.bodyprinttexture.load("Textures/Bodyprint.png", 0);
737     hawktexture.load("Textures/Hawk.png", 0);
738
739
740     Sprite::cloudtexture.load("Textures/Cloud.png", 1);
741     Sprite::cloudimpacttexture.load("Textures/CloudImpact.png", 1);
742     Sprite::bloodtexture.load("Textures/BloodParticle.png", 1);
743     Sprite::snowflaketexture.load("Textures/SnowFlake.png", 1);
744     Sprite::flametexture.load("Textures/Flame.png", 1);
745     Sprite::bloodflametexture.load("Textures/BloodFlame.png", 1);
746     Sprite::smoketexture.load("Textures/Smoke.png", 1);
747     Sprite::shinetexture.load("Textures/Shine.png", 1);
748     Sprite::splintertexture.load("Textures/Splinter.png", 1);
749     Sprite::leaftexture.load("Textures/Leaf.png", 1);
750     Sprite::toothtexture.load("Textures/Tooth.png", 1);
751
752     yaw = 0;
753     pitch = 0;
754     ReSizeGLScene(90, .01);
755
756     viewer = 0;
757
758     //Set up distant light
759     light.color[0] = .95;
760     light.color[1] = .95;
761     light.color[2] = 1;
762     light.ambient[0] = .2;
763     light.ambient[1] = .2;
764     light.ambient[2] = .24;
765     light.location.x = 1;
766     light.location.y = 1;
767     light.location.z = -.2;
768     Normalise(&light.location);
769
770     LoadingScreen();
771
772     SetUpLighting();
773
774
775     fadestart = .6;
776     gravity = -10;
777
778     texscale = .2 / megascale / viewdistdetail;
779     terrain.scale = 3 * megascale * viewdistdetail;
780
781     viewer.x = terrain.size / 2 * terrain.scale;
782     viewer.z = terrain.size / 2 * terrain.scale;
783
784     hawk.load("Models/Hawk.solid", 1);
785     hawk.Scale(.03, .03, .03);
786     hawk.Rotate(90, 1, 1);
787     hawk.CalculateNormals(0);
788     hawk.ScaleNormals(-1, -1, -1);
789     hawkcoords.x = terrain.size / 2 * terrain.scale - 5 - 7;
790     hawkcoords.z = terrain.size / 2 * terrain.scale - 5 - 7;
791     hawkcoords.y = terrain.getHeight(hawkcoords.x, hawkcoords.z) + 25;
792
793     eye.load("Models/Eye.solid", 1);
794     eye.Scale(.03, .03, .03);
795     eye.CalculateNormals(0);
796
797     cornea.load("Models/Cornea.solid", 1);
798     cornea.Scale(.03, .03, .03);
799     cornea.CalculateNormals(0);
800
801     iris.load("Models/Iris.solid", 1);
802     iris.Scale(.03, .03, .03);
803     iris.CalculateNormals(0);
804
805     LoadSave("Textures/BloodFur.png", 0, 1, &bloodText[0], 0);
806     LoadSave("Textures/WolfBloodFur.png", 0, 1, &wolfbloodText[0], 0);
807
808     oldenvironment = -4;
809
810     gameon = 1;
811     mainmenu = 0;
812
813     firstload = 0;
814
815     //Fix knife stab, too lazy to do it manually
816     XYZ moveamount;
817     moveamount = 0;
818     moveamount.z = 2;
819     // FIXME - Why this uses skeleton.joints.size() and not Animation::numjoints? (are they equal?)
820     // It seems skeleton.joints.size() is 0 at this point, so this is useless.
821     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
822         for (unsigned j = 0; j < Animation::animations[knifesneakattackanim].frames.size(); j++) {
823             Animation::animations[knifesneakattackanim].frames[j].joints[i].position += moveamount;
824         }
825     }
826
827     LoadingScreen();
828
829     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
830         for (unsigned j = 0; j < Animation::animations[knifesneakattackedanim].frames.size(); j++) {
831             Animation::animations[knifesneakattackedanim].frames[j].joints[i].position += moveamount;
832         }
833     }
834
835     LoadingScreen();
836
837     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
838         Animation::animations[dead1anim].frames[1].joints[i].position = Animation::animations[dead1anim].frames[0].joints[i].position;
839         Animation::animations[dead2anim].frames[1].joints[i].position = Animation::animations[dead2anim].frames[0].joints[i].position;
840         Animation::animations[dead3anim].frames[1].joints[i].position = Animation::animations[dead3anim].frames[0].joints[i].position;
841         Animation::animations[dead4anim].frames[1].joints[i].position = Animation::animations[dead4anim].frames[0].joints[i].position;
842     }
843     Animation::animations[dead1anim].frames[0].speed = 0.001;
844     Animation::animations[dead2anim].frames[0].speed = 0.001;
845     Animation::animations[dead3anim].frames[0].speed = 0.001;
846     Animation::animations[dead4anim].frames[0].speed = 0.001;
847
848     Animation::animations[dead1anim].frames[1].speed = 0.001;
849     Animation::animations[dead2anim].frames[1].speed = 0.001;
850     Animation::animations[dead3anim].frames[1].speed = 0.001;
851     Animation::animations[dead4anim].frames[1].speed = 0.001;
852
853     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
854         for (unsigned j = 0; j < Animation::animations[swordsneakattackanim].frames.size(); j++) {
855             Animation::animations[swordsneakattackanim].frames[j].joints[i].position += moveamount;
856         }
857     }
858     LoadingScreen();
859     for (unsigned j = 0; j < Animation::animations[swordsneakattackanim].frames.size(); j++) {
860         Animation::animations[swordsneakattackanim].frames[j].weapontarget += moveamount;
861     }
862
863     LoadingScreen();
864
865     for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
866         for (unsigned j = 0; j < Animation::animations[swordsneakattackedanim].frames.size(); j++) {
867             Animation::animations[swordsneakattackedanim].frames[j].joints[i].position += moveamount;
868         }
869     }
870
871     LoadingScreen();
872     temptexdetail = texdetail;
873     texdetail = 1;
874     texdetail = temptexdetail;
875
876     LoadingScreen();
877
878     if (!screentexture) {
879         LoadScreenTexture();
880     }
881
882     if (targetlevel != 7) {
883         emit_sound_at(fireendsound);
884     }
885
886     stillloading = 0;
887     loading = 0;
888     changedelay = 1;
889
890     visibleloading = 0;
891 }
892