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