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