]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
Merge with p/lugaru
[lugaru.git] / Source / GameInitDispose.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #include "Game.h"
23 #include "openal_wrapper.h"
24 #include "Animation.h"
25
26 extern float screenwidth,screenheight;
27 extern float viewdistance;
28 extern XYZ viewer;
29 extern XYZ lightlocation;
30 extern float lightambient[3],lightbrightness[3];
31 extern float fadestart;
32 extern float texscale;
33 extern float gravity;
34 extern Light light;
35 extern Skeleton testskeleton;
36 extern int numsounds;
37 extern Terrain terrain;
38 //extern Sprites sprites;
39 extern int kTextureSize;
40 extern float texdetail;
41 extern float realtexdetail;
42 extern float volume;
43 extern Objects objects;
44 extern int detail;
45 extern bool cellophane;
46 extern GLubyte bloodText[512*512*3];
47 extern GLubyte wolfbloodText[512*512*3];
48 extern bool ismotionblur;
49 extern bool trilinear;
50 extern bool osx;
51 extern bool musictoggle;
52 extern int environment;
53 extern bool ambientsound;
54 extern float multiplier;
55 extern int netdatanew;
56 extern float mapinfo;
57 extern bool stillloading;
58 extern TGAImageRec texture;
59 extern short vRefNum;
60 extern long dirID;
61 extern int mainmenu;
62 extern int oldmainmenu;
63 extern bool visibleloading;
64 extern int loadscreencolor;
65 extern float flashamount,flashr,flashg,flashb;
66 extern int flashdelay;
67 extern int whichjointstartarray[26];
68 extern int whichjointendarray[26];
69 extern int difficulty;
70 extern float tintr,tintg,tintb;
71 extern float slomospeed;
72 extern bool gamestarted;
73
74 extern int numdialogues;
75 extern int numdialogueboxes[20];
76 extern int dialoguetype[20];
77 extern int dialogueboxlocation[20][20];
78 extern float dialogueboxcolor[20][20][3];
79 extern int dialogueboxsound[20][20];
80 extern char dialoguetext[20][20][128];
81 extern char dialoguename[20][20][64];
82 extern XYZ dialoguecamera[20][20];
83 extern float dialoguecamerarotation[20][20];
84 extern float dialoguecamerarotation2[20][20];
85 extern int indialogue;
86 extern int whichdialogue;
87 extern float dialoguetime;
88
89 extern float accountcampaignhighscore[10];
90 extern float accountcampaignfasttime[10];
91 extern float accountcampaignscore[10];
92 extern float accountcampaigntime[10];
93
94 extern int accountcampaignchoicesmade[10];
95 extern int accountcampaignchoices[10][5000];
96
97 void LOG(const std::string &fmt, ...)
98 {
99     // !!! FIXME: write me.
100 }
101
102
103 Game::TextureList Game::textures;
104
105 void Game::Dispose()
106 {
107         int i,j;
108
109         LOGFUNC;
110
111         if(endgame==2){
112                 accountactive->endGame();
113                 endgame=0;
114         }
115
116         Account::saveFile(":Data:Users", accountactive);
117
118         TexIter it = textures.begin();
119         for (; it != textures.end(); ++it)
120         {
121                 if (glIsTexture(it->second))
122                         glDeleteTextures(1, &it->second);
123         }
124         textures.clear();
125
126         LOG("Shutting down sound system...");
127
128         OPENAL_StopSound(OPENAL_ALL);
129
130 // this is causing problems on Linux, but we'll force an _exit() a little
131 //  later in the shutdown process.  --ryan.
132 #if !PLATFORM_LINUX
133
134         for (i=0; i < sounds_count; ++i)
135         {
136                 OPENAL_Sample_Free(samp[i]);
137         }
138
139         OPENAL_Close();
140         if (texture.data)
141         {
142                 free(texture.data);
143         }
144         texture.data = 0;
145 #endif
146 }
147
148
149 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
150 {
151         GLuint          type;
152
153         LOGFUNC;
154
155         LOG(std::string("Loading texture...") + fileName);
156
157         // Fix filename so that is os appropreate
158         char * fixedFN = ConvertFileName(fileName);
159
160         unsigned char fileNamep[256];
161         CopyCStringToPascal(fixedFN, fileNamep);
162         //Load Image
163         upload_image( fileNamep ,hasalpha);
164
165 //      std::string fname(fileName);
166 //      std::transform(fname.begin(), fname.end(), tolower);
167 //      TexIter it = textures.find(fname);
168
169         //Is it valid?
170         if(1==1)
171         //if(textures.end() == it)
172         {
173                 //Alpha channel?
174                 if ( texture.bpp == 24 )
175                         type = GL_RGB;
176                 else
177                         type = GL_RGBA;
178
179                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
180
181                 if(!*textureid)
182                         glGenTextures( 1, textureid );
183                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
184
185                 glBindTexture( GL_TEXTURE_2D, *textureid);
186                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
187                 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
188                 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
189                 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
190                 
191                 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
192         }
193 }
194
195 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
196 {
197         GLuint          type;
198         int i;
199         int bytesPerPixel;
200
201         LOGFUNC;
202
203         LOG(std::string("Loading texture (S)...") + fileName);
204
205         //Load Image
206         unsigned char fileNamep[256];
207         CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
208         //Load Image
209         upload_image( fileNamep ,0);
210         //LoadTGA( fileName );
211
212 //      std::string fname(fileName);
213 //      std::transform(fname.begin(), fname.end(), tolower);
214 //      TexIter it = textures.find(fname);
215
216         //Is it valid?
217         if(1==1)
218         //if(textures.end() == it)
219         {
220                 bytesPerPixel=texture.bpp/8;
221
222                 //Alpha channel?
223                 if ( texture.bpp == 24 )
224                         type = GL_RGB;
225                 else
226                         type = GL_RGBA;
227
228                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
229
230                 if(!*textureid)glGenTextures( 1, textureid );
231                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
232
233                 glBindTexture( GL_TEXTURE_2D, *textureid);
234                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
235                 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
236                 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
237                 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
238
239                 int tempnum=0;
240                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
241                         if((i+1)%4||type==GL_RGB){
242                                 array[tempnum]=texture.data[i];
243                                 tempnum++;
244                         }
245                 }
246
247                 *skinsize=texture.sizeX;
248
249                 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
250
251 //              textures.insert(std::make_pair(fname, *textureid));
252         }
253 //      else
254 //      {
255 //              *textureid = it->second;
256 //      }
257 }
258
259 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
260 {
261         int i;
262         int bytesPerPixel;
263
264         LOGFUNC;
265
266         LOG(std::string("Loading (S)...") + fileName);
267
268         //Load Image
269         float temptexdetail=texdetail;
270         texdetail=1;
271         //upload_image( fileName );
272         //LoadTGA( fileName );
273
274         // Converting file to something os specific
275         char * fixedFN = ConvertFileName(fileName);
276
277         //Load Image
278         unsigned char fileNamep[256];
279         CopyCStringToPascal(fixedFN, fileNamep);
280         //Load Image
281         upload_image( fileNamep ,0);
282         texdetail=temptexdetail;
283
284         //Is it valid?
285         if(1==1){
286                 bytesPerPixel=texture.bpp/8;
287
288                 int tempnum=0;
289                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
290                         if((i+1)%4||bytesPerPixel==3){
291                                 array[tempnum]=texture.data[i];
292                                 tempnum++;
293                         }
294                 }
295         }
296 }
297
298 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
299 {
300         int i;
301         int bytesPerPixel;
302
303         LOGFUNC;
304
305         //upload_image( fileName );
306         //LoadTGA( fileName );
307         //Load Image
308         unsigned char fileNamep[256];
309         CopyCStringToPascal(fileName,fileNamep);
310         //Load Image
311         bool opened;
312         opened=upload_image( fileNamep ,1);
313
314         float alphanum;
315         //Is it valid?
316         if(opened){
317                 if(tintr>1)tintr=1;
318                 if(tintg>1)tintg=1;
319                 if(tintb>1)tintb=1;
320
321                 if(tintr<0)tintr=0;
322                 if(tintg<0)tintg=0;
323                 if(tintb<0)tintb=0;
324
325                 bytesPerPixel=texture.bpp/8;
326
327                 int tempnum=0;
328                 alphanum=255;
329                 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
330                         if(bytesPerPixel==3)alphanum=255;
331                         else if((i+1)%4==0)alphanum=texture.data[i];
332                         //alphanum/=2;
333                         if((i+1)%4||bytesPerPixel==3){
334                                 if((i%4)==0)texture.data[i]*=tintr;
335                                 if((i%4)==1)texture.data[i]*=tintg;
336                                 if((i%4)==2)texture.data[i]*=tintb;
337                                 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
338                                 tempnum++;
339                         }
340                 }
341         }
342         else return 0;
343         return 1;
344 }
345
346
347 //***************> ResizeGLScene() <******/
348 GLvoid Game::ReSizeGLScene(float fov, float pnear)
349 {
350         if (screenheight==0)
351         {
352                 screenheight=1;
353         }
354
355         glViewport(0,0,screenwidth,screenheight);
356
357         glMatrixMode(GL_PROJECTION);
358         glLoadIdentity();
359
360         gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
361
362         glMatrixMode(GL_MODELVIEW);
363         glLoadIdentity();
364 }
365
366 void Game::LoadingScreen()
367 {
368         static float loadprogress,minprogress,maxprogress;
369         static AbsoluteTime time = {0,0};
370         static AbsoluteTime frametime = {0,0};
371         AbsoluteTime currTime = UpTime ();
372         double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
373
374         if (0 > deltaTime)      // if negative microseconds
375                 deltaTime /= -1000000.0;
376         else                            // else milliseconds
377                 deltaTime /= 1000.0;
378
379         multiplier=deltaTime;
380         if(multiplier<.001)multiplier=.001;
381         if(multiplier>10)multiplier=10;
382         if(multiplier>.05){
383                 frametime = currTime;   // reset for next time interval
384
385                 float size=1;
386                 glLoadIdentity();
387                 //Clear to black
388                 glClearColor(0,0,0,1);
389                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
390
391
392                 loadtime+=multiplier*4;
393
394                 loadprogress=loadtime;
395                 if(loadprogress>100)loadprogress=100;
396
397                 //loadprogress=abs(Random()%100);
398
399                 //Background
400
401                 glEnable(GL_TEXTURE_2D);
402                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
403                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
404                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
405                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
406                 glDisable(GL_CULL_FACE);
407                 glDisable(GL_LIGHTING);
408                 glDepthMask(0);
409                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
410                 glPushMatrix();                                                                         // Store The Projection Matrix
411                 glLoadIdentity();                                                                       // Reset The Projection Matrix
412                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
413                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
414                 glPushMatrix();                                                                         // Store The Modelview Matrix
415                 glLoadIdentity();                                                               // Reset The Modelview Matrix
416                 glTranslatef(screenwidth/2,screenheight/2,0);
417                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
418                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
419                 glDisable(GL_BLEND);
420                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
421                 //glColor4f(1,1,1,1);
422                 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
423                 if(loadscreencolor==1)glColor4f(1,0,0,1);
424                 if(loadscreencolor==2)glColor4f(0,1,0,1);
425                 if(loadscreencolor==3)glColor4f(0,0,1,1);
426                 if(loadscreencolor==4)glColor4f(1,1,0,1);
427                 if(loadscreencolor==5)glColor4f(1,0,1,1);
428                 */
429                 glPushMatrix();
430                 //glScalef(.25,.25,.25);
431                 glBegin(GL_QUADS);
432                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
433                 glVertex3f(-1,          -1,      0.0f);
434                 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
435                 glVertex3f(1,   -1,      0.0f);
436                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
437                 glVertex3f(1,   1, 0.0f);
438                 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
439                 glVertex3f(-1,  1, 0.0f);
440                 glEnd();
441                 glPopMatrix();
442                 glEnable(GL_BLEND);
443                 glPushMatrix();
444                 //glScalef(.25,.25,.25);
445                 glBegin(GL_QUADS);
446                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
447                 glVertex3f(-1,          -1,      0.0f);
448                 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
449                 glVertex3f(1,   -1,      0.0f);
450                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
451                 glVertex3f(1,   1, 0.0f);
452                 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
453                 glVertex3f(-1,  1, 0.0f);
454                 glEnd();
455                 glPopMatrix();
456                 glDisable(GL_TEXTURE_2D);
457                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
458                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
459                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
460                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
461                 glDisable(GL_BLEND);
462                 glDepthMask(1);
463
464                 glEnable(GL_TEXTURE_2D);
465                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
466                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
467                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
468                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
469                 glDisable(GL_CULL_FACE);
470                 glDisable(GL_LIGHTING);
471                 glDepthMask(0);
472                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
473                 glPushMatrix();                                                                         // Store The Projection Matrix
474                 glLoadIdentity();                                                                       // Reset The Projection Matrix
475                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
476                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
477                 glPushMatrix();                                                                         // Store The Modelview Matrix
478                 glLoadIdentity();                                                               // Reset The Modelview Matrix
479                 glTranslatef(screenwidth/2,screenheight/2,0);
480                 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
481                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
482                 glEnable(GL_BLEND);
483                 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
484                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
485                 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
486                 if(loadscreencolor==1)glColor4f(1,0,0,1);
487                 if(loadscreencolor==2)glColor4f(0,1,0,1);
488                 if(loadscreencolor==3)glColor4f(0,0,1,1);
489                 if(loadscreencolor==4)glColor4f(1,1,0,1);
490                 if(loadscreencolor==5)glColor4f(1,0,1,1);
491                 */
492                 glPushMatrix();
493                 //glScalef(.25,.25,.25);
494                 glBegin(GL_QUADS);
495                 glTexCoord2f(0+.5,0+.5);
496                 glVertex3f(-1,          -1,      0.0f);
497                 glTexCoord2f(1+.5,0+.5);
498                 glVertex3f(1,   -1,      0.0f);
499                 glTexCoord2f(1+.5,1+.5);
500                 glVertex3f(1,   1, 0.0f);
501                 glTexCoord2f(0+.5,1+.5);
502                 glVertex3f(-1,  1, 0.0f);
503                 glEnd();
504                 glPopMatrix();
505                 glDisable(GL_TEXTURE_2D);
506                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
507                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
508                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
509                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
510                 glDisable(GL_BLEND);
511                 glDepthMask(1);
512
513                 glEnable(GL_TEXTURE_2D);
514                 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
515                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
516                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
517                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
518                 glDisable(GL_CULL_FACE);
519                 glDisable(GL_LIGHTING);
520                 glDepthMask(0);
521                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
522                 glPushMatrix();                                                                         // Store The Projection Matrix
523                 glLoadIdentity();                                                                       // Reset The Projection Matrix
524                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
525                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
526                 glPushMatrix();                                                                         // Store The Modelview Matrix
527                 glLoadIdentity();                                                               // Reset The Modelview Matrix
528                 glTranslatef(screenwidth/2,screenheight/2,0);
529                 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
530                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
531                 glEnable(GL_BLEND);
532                 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
533                 glPushMatrix();
534                 //glScalef(.25,.25,.25);
535                 glBegin(GL_QUADS);
536                 glTexCoord2f(0+.2,0+.8);
537                 glVertex3f(-1,          -1,      0.0f);
538                 glTexCoord2f(1+.2,0+.8);
539                 glVertex3f(1,   -1,      0.0f);
540                 glTexCoord2f(1+.2,1+.8);
541                 glVertex3f(1,   1, 0.0f);
542                 glTexCoord2f(0+.2,1+.8);
543                 glVertex3f(-1,  1, 0.0f);
544                 glEnd();
545                 glPopMatrix();
546                 glDisable(GL_TEXTURE_2D);
547                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
548                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
549                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
550                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
551                 glDisable(GL_BLEND);
552                 glDepthMask(1);
553
554                 //Text
555                 /*
556                 glEnable(GL_TEXTURE_2D);
557                 static char string[256]="";
558                 sprintf (string, "LOADING... %d%",(int)loadprogress);
559                 glColor4f(1,1,1,.2);
560                 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
561                 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
562                 text.glPrint(280,125,string,1,1,640,480);
563                 */
564
565                 if(flashamount>0){
566                         if(flashamount>1)flashamount=1;
567                         if(flashdelay<=0)flashamount-=multiplier;
568                         flashdelay--;
569                         if(flashamount<0)flashamount=0;
570                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
571                         glDisable(GL_CULL_FACE);
572                         glDisable(GL_LIGHTING);
573                         glDisable(GL_TEXTURE_2D);
574                         glDepthMask(0);
575                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
576                         glPushMatrix();                                                                         // Store The Projection Matrix
577                         glLoadIdentity();                                                                       // Reset The Projection Matrix
578                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
579                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
580                         glPushMatrix();                                                                         // Store The Modelview Matrix
581                         glLoadIdentity();                                                               // Reset The Modelview Matrix
582                         glScalef(screenwidth,screenheight,1);
583                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
584                         glEnable(GL_BLEND);
585                         glColor4f(flashr,flashg,flashb,flashamount);
586                         glBegin(GL_QUADS);
587                         glVertex3f(0,           0,       0.0f);
588                         glVertex3f(256, 0,       0.0f);
589                         glVertex3f(256, 256, 0.0f);
590                         glVertex3f(0,   256, 0.0f);
591                         glEnd();
592                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
593                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
594                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
595                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
596                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
597                         glEnable(GL_CULL_FACE);
598                         glDisable(GL_BLEND);
599                         glDepthMask(1);
600                 }
601
602                 swap_gl_buffers();
603                 loadscreencolor=0;
604         }
605 }
606
607 void Game::FadeLoadingScreen(float howmuch)
608 {
609         static float loadprogress,minprogress,maxprogress;
610
611         float size=1;
612         glLoadIdentity();
613         //Clear to black
614         glClearColor(0,0,0,1);
615         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
616
617         loadprogress=howmuch;
618
619         //loadprogress=abs(Random()%100);
620
621         //Background
622
623         //glEnable(GL_TEXTURE_2D);
624         glDisable(GL_TEXTURE_2D);
625         //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
626         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
627         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
628         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
629         glDisable(GL_CULL_FACE);
630         glDisable(GL_LIGHTING);
631         glDepthMask(0);
632         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
633         glPushMatrix();                                                                         // Store The Projection Matrix
634         glLoadIdentity();                                                                       // Reset The Projection Matrix
635         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
636         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
637         glPushMatrix();                                                                         // Store The Modelview Matrix
638         glLoadIdentity();                                                               // Reset The Modelview Matrix
639         glTranslatef(screenwidth/2,screenheight/2,0);
640         glScalef((float)screenwidth/2,(float)screenheight/2,1);
641         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
642         glDisable(GL_BLEND);
643         glColor4f(loadprogress/100,0,0,1);
644         /*if(loadscreencolor==0)glColor4f(1,1,1,1);
645         if(loadscreencolor==1)glColor4f(1,0,0,1);
646         if(loadscreencolor==2)glColor4f(0,1,0,1);
647         if(loadscreencolor==3)glColor4f(0,0,1,1);
648         if(loadscreencolor==4)glColor4f(1,1,0,1);
649         if(loadscreencolor==5)glColor4f(1,0,1,1);
650         */
651         glPushMatrix();
652         //glScalef(.25,.25,.25);
653         glBegin(GL_QUADS);
654         glTexCoord2f(0,0);
655         glVertex3f(-1,          -1,      0.0f);
656         glTexCoord2f(1,0);
657         glVertex3f(1,   -1,      0.0f);
658         glTexCoord2f(1,1);
659         glVertex3f(1,   1, 0.0f);
660         glTexCoord2f(0,1);
661         glVertex3f(-1,  1, 0.0f);
662         glEnd();
663         glPopMatrix();
664         glDisable(GL_TEXTURE_2D);
665         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
666         glPopMatrix();                                                                          // Restore The Old Projection Matrix
667         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
668         glPopMatrix();                                                                          // Restore The Old Projection Matrix
669         glDisable(GL_BLEND);
670         glDepthMask(1);
671         //Text
672         /*
673         glEnable(GL_TEXTURE_2D);
674         static char string[256]="";
675         sprintf (string, "LOADING... %d%",(int)loadprogress);
676         glColor4f(1,1,1,.2);
677         text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
678         glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
679         text.glPrint(280,125,string,1,1,640,480);
680         */
681         swap_gl_buffers();
682         loadscreencolor=0;
683 }
684
685
686 void Game::InitGame()
687 {
688 #if PLATFORM_MACOSX
689         ProcessSerialNumber PSN;
690         ProcessInfoRec pinfo;
691         FSSpec pspec;
692         OSStatus err;
693         /* set up process serial number */
694         PSN.highLongOfPSN = 0;
695         PSN.lowLongOfPSN = kCurrentProcess;
696         /* set up info block */
697         pinfo.processInfoLength = sizeof(pinfo);
698         pinfo.processName = NULL;
699         pinfo.processAppSpec = &pspec;
700         /* grab the vrefnum and directory */
701         err = GetProcessInformation(&PSN, &pinfo);
702         if (err == noErr) {
703                 vRefNum = pspec.vRefNum;
704                 dirID = pspec.parID;
705         }
706 #endif
707
708         LOGFUNC;
709
710         autocam=0;
711
712         int i,j;
713
714         numchallengelevels=14;
715
716         accountactive=Account::loadFile(":Data:Users");
717
718         tintr=1;
719         tintg=1;
720         tintb=1;
721
722         whichjointstartarray[0]=righthip;
723         whichjointendarray[0]=rightfoot;
724
725         whichjointstartarray[1]=righthip;
726         whichjointendarray[1]=rightankle;
727
728         whichjointstartarray[2]=righthip;
729         whichjointendarray[2]=rightknee;
730
731         whichjointstartarray[3]=rightknee;
732         whichjointendarray[3]=rightankle;
733
734         whichjointstartarray[4]=rightankle;
735         whichjointendarray[4]=rightfoot;
736
737         whichjointstartarray[5]=lefthip;
738         whichjointendarray[5]=leftfoot;
739
740         whichjointstartarray[6]=lefthip;
741         whichjointendarray[6]=leftankle;
742
743         whichjointstartarray[7]=lefthip;
744         whichjointendarray[7]=leftknee;
745
746         whichjointstartarray[8]=leftknee;
747         whichjointendarray[8]=leftankle;
748
749         whichjointstartarray[9]=leftankle;
750         whichjointendarray[9]=leftfoot;
751
752         whichjointstartarray[10]=abdomen;
753         whichjointendarray[10]=rightshoulder;
754
755         whichjointstartarray[11]=abdomen;
756         whichjointendarray[11]=rightelbow;
757
758         whichjointstartarray[12]=abdomen;
759         whichjointendarray[12]=rightwrist;
760
761         whichjointstartarray[13]=abdomen;
762         whichjointendarray[13]=righthand;
763
764         whichjointstartarray[14]=rightshoulder;
765         whichjointendarray[14]=rightelbow;
766
767         whichjointstartarray[15]=rightelbow;
768         whichjointendarray[15]=rightwrist;
769
770         whichjointstartarray[16]=rightwrist;
771         whichjointendarray[16]=righthand;
772
773         whichjointstartarray[17]=abdomen;
774         whichjointendarray[17]=leftshoulder;
775
776         whichjointstartarray[18]=abdomen;
777         whichjointendarray[18]=leftelbow;
778
779         whichjointstartarray[19]=abdomen;
780         whichjointendarray[19]=leftwrist;
781
782         whichjointstartarray[20]=abdomen;
783         whichjointendarray[20]=lefthand;
784
785         whichjointstartarray[21]=leftshoulder;
786         whichjointendarray[21]=leftelbow;
787
788         whichjointstartarray[22]=leftelbow;
789         whichjointendarray[22]=leftwrist;
790
791         whichjointstartarray[23]=leftwrist;
792         whichjointendarray[23]=lefthand;
793
794         whichjointstartarray[24]=abdomen;
795         whichjointendarray[24]=neck;
796
797         whichjointstartarray[25]=neck;
798         whichjointendarray[25]=head;
799
800         FadeLoadingScreen(0);
801
802         stillloading=1;
803
804         texture.data = ( GLubyte* )malloc( 1024*1024*4 );
805
806         int temptexdetail=texdetail;
807         texdetail=1;
808         text.LoadFontTexture(":Data:Textures:Font.png");
809         text.BuildFont();
810         texdetail=temptexdetail;
811
812         FadeLoadingScreen(10);
813
814         if(detail==2){
815                 texdetail=1;
816         }
817         if(detail==1){
818                 texdetail=2;
819         }
820         if(detail==0){
821                 texdetail=4;
822         }
823
824         LOG("Initializing sound system...");
825
826     int output = -1;
827
828     #if PLATFORM_LINUX
829     extern bool cmdline(const char *cmd);
830     unsigned char rc = 0;
831     output = OPENAL_OUTPUT_ALSA;  // Try alsa first...
832     if (cmdline("forceoss"))      //  ...but let user override that.
833         output = OPENAL_OUTPUT_OSS;
834     else if (cmdline("nosound"))
835         output = OPENAL_OUTPUT_NOSOUND;
836
837     OPENAL_SetOutput(output);
838         if ((rc = OPENAL_Init(44100, 32, 0)) == false)
839     {
840         // if we tried ALSA and failed, fall back to OSS.
841         if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
842         {
843             OPENAL_Close();
844             output = OPENAL_OUTPUT_OSS;
845             OPENAL_SetOutput(output);
846                 rc = OPENAL_Init(44100, 32, 0);
847         }
848     }
849
850     if (rc == false)
851     {
852         OPENAL_Close();
853         output = OPENAL_OUTPUT_NOSOUND;  // we tried! just do silence.
854         OPENAL_SetOutput(output);
855             rc = OPENAL_Init(44100, 32, 0);
856     }
857     #else
858         OPENAL_Init(44100, 32, 0);
859     #endif
860
861         OPENAL_SetSFXMasterVolume((int)(volume*255));
862         loadAllSounds();
863
864         if(musictoggle)
865           emit_stream_np(stream_music3);
866
867         LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
868
869         LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
870         LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
871         LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
872
873         temptexdetail=texdetail;
874         if(texdetail>2)texdetail=2;
875         LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
876         LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
877         LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
878         LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
879         LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
880         LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
881         //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
882         texdetail=temptexdetail;
883
884         loaddistrib=0;
885         anim=0;
886
887         FadeLoadingScreen(95);
888
889
890         gameon=0;
891         mainmenu=1;
892
893         stillloading=0;
894         firstload=0;
895         oldmainmenu=0;
896
897         newdetail=detail;
898         newscreenwidth=screenwidth;
899         newscreenheight=screenheight;
900 }
901
902
903 void Game::LoadStuff()
904 {
905         static float temptexdetail;
906         static float viewdistdetail;
907         static int i,j,texsize;
908         float megascale =1;
909
910         LOGFUNC;
911
912         visibleloading=1;
913
914         loadtime=0;
915
916         stillloading=1;
917
918         //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
919
920         for(i=0;i<maxplayers;i++)
921         {
922                 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
923                 {
924                         glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
925                 }
926                 player[i].skeleton.drawmodel.textureptr=0;;
927         }
928
929         //temptexdetail=texdetail;
930         //texdetail=1;
931         i=abs(Random()%4);
932         LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
933         //texdetail=temptexdetail;
934
935         temptexdetail=texdetail;
936         texdetail=1;
937         text.LoadFontTexture(":Data:Textures:Font.png");
938         text.BuildFont();
939         texdetail=temptexdetail;
940
941         numsounds=71;
942
943         viewdistdetail=2;
944         viewdistance=50*megascale*viewdistdetail;
945
946         brightness=100;
947
948
949
950         if(detail==2){
951                 texdetail=1;
952         }
953         if(detail==1){
954                 texdetail=2;
955         }
956         if(detail==0){
957                 texdetail=4;
958         }
959
960         realtexdetail=texdetail;
961
962         /*texdetail/=4;
963         if(texdetail<1)texdetail=1;
964         realtexdetail=texdetail*4;
965         */
966         numplayers=1;
967
968
969
970         /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
971
972         LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
973
974         LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
975         */
976
977
978         LOG("Loading weapon data...");
979
980         LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
981         LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
982         LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
983         LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
984         LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
985         LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
986         LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
987
988         weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
989         weapons.throwingknifemodel.Scale(.001,.001,.001);
990         //weapons.throwingknifemodel.Rotate(0,0,-90);
991         weapons.throwingknifemodel.Rotate(90,0,0);
992         weapons.throwingknifemodel.Rotate(0,90,0);
993         weapons.throwingknifemodel.flat=0;
994         weapons.throwingknifemodel.CalculateNormals(1);
995         //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
996
997         weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
998         weapons.swordmodel.Scale(.001,.001,.001);
999         //weapons.swordmodel.Rotate(0,0,-90);
1000         weapons.swordmodel.Rotate(90,0,0);
1001         weapons.swordmodel.Rotate(0,90,0);
1002         weapons.swordmodel.Rotate(0,0,90);
1003         weapons.swordmodel.flat=1;
1004         weapons.swordmodel.CalculateNormals(1);
1005         //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1006
1007         weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1008         weapons.staffmodel.Scale(.005,.005,.005);
1009         //weapons.staffmodel.Rotate(0,0,-90);
1010         weapons.staffmodel.Rotate(90,0,0);
1011         weapons.staffmodel.Rotate(0,90,0);
1012         weapons.staffmodel.Rotate(0,0,90);
1013         weapons.staffmodel.flat=1;
1014         weapons.staffmodel.CalculateNormals(1);
1015         //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1016
1017         //temptexdetail=texdetail;
1018         //if(texdetail>4)texdetail=4;
1019         LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1020
1021         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1022
1023         LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1024
1025         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1026
1027
1028         LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1029
1030         LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1031
1032         /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1033
1034         LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1035
1036         LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1037
1038         LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1039
1040         LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1041
1042         LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1043         //texdetail=temptexdetail;
1044         LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1045
1046
1047
1048         LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1049
1050         LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1051
1052
1053         //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1054
1055
1056         LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1057         LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1058         LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1059         LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1060         LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1061         LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1062         LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1063         LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1064         LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1065         LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1066         LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1067
1068         rotation=0;
1069         rotation2=0;
1070         ReSizeGLScene(90,.01);
1071
1072         viewer=0;
1073
1074
1075
1076
1077         if(detail)kTextureSize=1024;
1078         if(detail==1)kTextureSize=512;
1079         if(detail==0)kTextureSize=256;
1080
1081
1082         //drawmode=motionblurmode;
1083
1084         //Set up distant light
1085         light.color[0]=.95;
1086         light.color[1]=.95;
1087         light.color[2]=1;
1088         light.ambient[0]=.2;
1089         light.ambient[1]=.2;
1090         light.ambient[2]=.24;
1091         light.location.x=1;
1092         light.location.y=1;
1093         light.location.z=-.2;
1094         Normalise(&light.location);
1095
1096         LoadingScreen();
1097
1098         SetUpLighting();
1099
1100
1101         fadestart=.6;
1102         gravity=-10;
1103
1104         texscale=.2/megascale/viewdistdetail;
1105         terrain.scale=3*megascale*viewdistdetail;
1106
1107         viewer.x=terrain.size/2*terrain.scale;
1108         viewer.z=terrain.size/2*terrain.scale;
1109
1110         hawk.load((char *)":Data:Models:hawk.solid",1);
1111         hawk.Scale(.03,.03,.03);
1112         hawk.Rotate(90,1,1);
1113         hawk.CalculateNormals(0);
1114         hawk.ScaleNormals(-1,-1,-1);
1115         hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1116         hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1117         hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1118
1119
1120         eye.load((char *)":Data:Models:eye.solid",1);
1121         eye.Scale(.03,.03,.03);
1122         eye.CalculateNormals(0);
1123
1124         cornea.load((char *)":Data:Models:cornea.solid",1);
1125         cornea.Scale(.03,.03,.03);
1126         cornea.CalculateNormals(0);
1127
1128         iris.load((char *)":Data:Models:iris.solid",1);
1129         iris.Scale(.03,.03,.03);
1130         iris.CalculateNormals(0);
1131
1132         LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1133         LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1134
1135         oldenvironment=-4;
1136
1137         gameon=1;
1138         mainmenu=0;
1139
1140         firstload=0;
1141         //if(targetlevel!=7)
1142                 Loadlevel(targetlevel);
1143
1144
1145         rabbitcoords=player[0].coords;
1146         rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1147
1148         loadAllAnimations();
1149         //Fix knife stab, too lazy to do it manually
1150         XYZ moveamount;
1151         moveamount=0;
1152         moveamount.z=2;
1153         for(i=0;i<player[0].skeleton.num_joints;i++){
1154                 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1155                         animation[knifesneakattackanim].position[i][j]+=moveamount;
1156                 }
1157         }
1158
1159         loadscreencolor=4;
1160         LoadingScreen();
1161
1162         for(i=0;i<player[0].skeleton.num_joints;i++){
1163                 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1164                         animation[knifesneakattackedanim].position[i][j]+=moveamount;
1165                 }
1166         }
1167
1168         loadscreencolor=4;
1169         LoadingScreen();
1170
1171         for(i=0;i<player[0].skeleton.num_joints;i++){
1172                 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1173                 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1174                 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1175                 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1176         }
1177         animation[dead1anim].speed[0]=0.001;
1178         animation[dead2anim].speed[0]=0.001;
1179         animation[dead3anim].speed[0]=0.001;
1180         animation[dead4anim].speed[0]=0.001;
1181
1182         animation[dead1anim].speed[1]=0.001;
1183         animation[dead2anim].speed[1]=0.001;
1184         animation[dead3anim].speed[1]=0.001;
1185         animation[dead4anim].speed[1]=0.001;
1186
1187         for(i=0;i<player[0].skeleton.num_joints;i++){
1188                 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1189                         animation[swordsneakattackanim].position[i][j]+=moveamount;
1190                 }
1191         }
1192         loadscreencolor=4;
1193         LoadingScreen();
1194         for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1195                 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1196         }
1197
1198         loadscreencolor=4;
1199         LoadingScreen();
1200
1201         for(i=0;i<player[0].skeleton.num_joints;i++){
1202                 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1203                         animation[swordsneakattackedanim].position[i][j]+=moveamount;
1204                 }
1205         }
1206         /*
1207         for(i=0;i<player[0].skeleton.num_joints;i++){
1208         for(j=0;j<animation[sleepanim].numframes;j++){
1209         animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1210         }
1211         }
1212         */
1213         loadscreencolor=4;
1214         LoadingScreen();
1215         temptexdetail=texdetail;
1216         texdetail=1;
1217         texdetail=temptexdetail;
1218
1219         loadscreencolor=4;
1220         LoadingScreen();
1221
1222         //if(ismotionblur){
1223         if(!screentexture){
1224                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1225
1226                 glGenTextures( 1, &screentexture );
1227                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1228
1229
1230                 glEnable(GL_TEXTURE_2D);
1231                 glBindTexture( GL_TEXTURE_2D, screentexture);
1232                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1233                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1234
1235                 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1236         }
1237
1238         if(targetlevel!=7){
1239                 emit_sound_at(fireendsound);
1240         }
1241
1242         stillloading=0;
1243         loading=0;
1244         changedelay=1;
1245
1246         visibleloading=0;
1247 }
1248