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