]> git.jsancho.org Git - lugaru.git/blob - Source/GameInitDispose.cpp
Drop 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_Stream_Open(ConvertFileName(":Data:Sounds:music3.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=0;}
906 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music3], 4.0f, 1000.0f);
907         OPENAL_Stream_SetMode(strm[stream_music3], OPENAL_LOOP_NORMAL);
908
909         if(musictoggle){
910 //              PlaySoundEx( stream_music3, strm[stream_music3], NULL, true);
911                 PlayStreamEx(stream_music3, strm[stream_music3], 0, true);
912                 OPENAL_SetPaused(channels[stream_music3], false);
913                 OPENAL_SetVolume(channels[stream_music3], 256);
914         }
915
916         FadeLoadingScreen(20);
917
918         if(ambientsound){
919                 strm[stream_wind] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:wind.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
920 //              OPENAL_Sample_SetMinMaxDistance(strm[stream_wind], 4.0f, 1000.0f);
921                 OPENAL_Stream_SetMode(strm[stream_wind], OPENAL_LOOP_NORMAL);
922
923                 FadeLoadingScreen(30);
924
925                 strm[stream_desertambient] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:desertambient.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
926 //              OPENAL_Sample_SetMinMaxDistance(strm[stream_desertambient], 4.0f, 1000.0f);
927                 OPENAL_Stream_SetMode(strm[stream_desertambient], OPENAL_LOOP_NORMAL);
928         }
929
930         FadeLoadingScreen(40);
931
932         strm[stream_firesound] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:fire.ogg"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
933 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_firesound], 8.0f, 2000.0f);
934         OPENAL_Stream_SetMode(strm[stream_firesound], OPENAL_LOOP_NORMAL);
935
936         FadeLoadingScreen(50);
937
938         //if(musictoggle){
939         strm[stream_music1grass] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music1grass.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=1;}
940 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music1grass], 4.0f, 1000.0f);
941         OPENAL_Stream_SetMode(strm[stream_music1grass], OPENAL_LOOP_NORMAL);
942
943         strm[stream_music1snow] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music1snow.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=2;}
944 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music1snow], 4.0f, 1000.0f);
945         OPENAL_Stream_SetMode(strm[stream_music1snow], OPENAL_LOOP_NORMAL);
946
947         FadeLoadingScreen(60);
948
949         strm[stream_music1desert] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music1desert.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=3;}
950 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music1desert], 4.0f, 1000.0f);
951         OPENAL_Stream_SetMode(strm[stream_music1desert], OPENAL_LOOP_NORMAL);
952
953         FadeLoadingScreen(80);
954         strm[stream_music2] = OPENAL_Stream_Open(ConvertFileName(":Data:Sounds:music2.ogg"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=4;}
955 //      OPENAL_Sample_SetMinMaxDistance(strm[stream_music2], 4.0f, 1000.0f);
956         OPENAL_Stream_SetMode(strm[stream_music2], OPENAL_LOOP_NORMAL);
957
958         //}
959
960
961         FadeLoadingScreen(90);
962
963
964         LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
965
966         LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
967         LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
968         LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
969
970         temptexdetail=texdetail;
971         if(texdetail>2)texdetail=2;
972         LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
973         LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
974         LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
975         LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
976         LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
977         LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
978         //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
979         texdetail=temptexdetail;
980
981         loaddistrib=0;
982         anim=0;
983
984         FadeLoadingScreen(95);
985
986
987         gameon=0;
988         mainmenu=1;
989
990         stillloading=0;
991         firstload=0;
992         oldmainmenu=0;
993
994         newdetail=detail;
995         newscreenwidth=screenwidth;
996         newscreenheight=screenheight;
997 }
998
999
1000 void Game::LoadStuff()
1001 {
1002         static float temptexdetail;
1003         static float viewdistdetail;
1004         static int i,j,texsize;
1005         float megascale =1;
1006
1007         LOGFUNC;
1008
1009         visibleloading=1;
1010
1011         /*musicvolume[3]=512;
1012         PlaySoundEx( music4, samp[music4], NULL, true);
1013         OPENAL_SetPaused(channels[music4], false);
1014         OPENAL_SetVolume(channels[music4], 512);
1015         */
1016         loadtime=0;
1017
1018         stillloading=1;
1019
1020         //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
1021
1022         for(i=0;i<maxplayers;i++)
1023         {
1024                 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
1025                 {
1026                         glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
1027                 }
1028                 player[i].skeleton.drawmodel.textureptr=0;;
1029         }
1030
1031         //temptexdetail=texdetail;
1032         //texdetail=1;
1033         i=abs(Random()%4);
1034         LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
1035         //texdetail=temptexdetail;
1036
1037         temptexdetail=texdetail;
1038         texdetail=1;
1039         text.LoadFontTexture(":Data:Textures:Font.png");
1040         text.BuildFont();
1041         texdetail=temptexdetail;
1042
1043         numsounds=71;
1044
1045         viewdistdetail=2;
1046         viewdistance=50*megascale*viewdistdetail;
1047
1048         brightness=100;
1049
1050
1051
1052         if(detail==2){
1053                 texdetail=1;
1054                 terraindetail=1;
1055         }
1056         if(detail==1){
1057                 texdetail=2;
1058                 terraindetail=1;
1059         }
1060         if(detail==0){
1061                 texdetail=4;
1062                 terraindetail=1;
1063                 //terraindetail=2;
1064         }
1065
1066         realtexdetail=texdetail;
1067
1068         /*texdetail/=4;
1069         if(texdetail<1)texdetail=1;
1070         realtexdetail=texdetail*4;
1071         */
1072         numplayers=1;
1073
1074
1075
1076         /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
1077
1078         LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
1079
1080         LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1081         */
1082
1083
1084         LOG("Loading weapon data...");
1085
1086         LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
1087         LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
1088         LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
1089         LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
1090         LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
1091         LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
1092         LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
1093
1094         weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
1095         weapons.throwingknifemodel.Scale(.001,.001,.001);
1096         //weapons.throwingknifemodel.Rotate(0,0,-90);
1097         weapons.throwingknifemodel.Rotate(90,0,0);
1098         weapons.throwingknifemodel.Rotate(0,90,0);
1099         weapons.throwingknifemodel.flat=0;
1100         weapons.throwingknifemodel.CalculateNormals(1);
1101         //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1102
1103         weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1104         weapons.swordmodel.Scale(.001,.001,.001);
1105         //weapons.swordmodel.Rotate(0,0,-90);
1106         weapons.swordmodel.Rotate(90,0,0);
1107         weapons.swordmodel.Rotate(0,90,0);
1108         weapons.swordmodel.Rotate(0,0,90);
1109         weapons.swordmodel.flat=1;
1110         weapons.swordmodel.CalculateNormals(1);
1111         //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1112
1113         weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1114         weapons.staffmodel.Scale(.005,.005,.005);
1115         //weapons.staffmodel.Rotate(0,0,-90);
1116         weapons.staffmodel.Rotate(90,0,0);
1117         weapons.staffmodel.Rotate(0,90,0);
1118         weapons.staffmodel.Rotate(0,0,90);
1119         weapons.staffmodel.flat=1;
1120         weapons.staffmodel.CalculateNormals(1);
1121         //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1122
1123         //temptexdetail=texdetail;
1124         //if(texdetail>4)texdetail=4;
1125         LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1126
1127         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1128
1129         LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1130
1131         LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1132
1133
1134         LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1135
1136         LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1137
1138         /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1139
1140         LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1141
1142         LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1143
1144         LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1145
1146         LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1147
1148         LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1149         //texdetail=temptexdetail;
1150         LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1151
1152
1153
1154         LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1155
1156         LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1157
1158
1159         //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1160
1161
1162         LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1163         LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1164         LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1165         LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1166         LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1167         LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1168         LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1169         LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1170         LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1171         LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1172         LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1173
1174         rotation=0;
1175         rotation2=0;
1176         ReSizeGLScene(90,.01);
1177
1178         viewer=0;
1179
1180
1181
1182
1183         if(detail)kTextureSize=1024;
1184         if(detail==1)kTextureSize=512;
1185         if(detail==0)kTextureSize=256;
1186
1187
1188         //drawmode=motionblurmode;
1189
1190         //Set up distant light
1191         light.color[0]=.95;
1192         light.color[1]=.95;
1193         light.color[2]=1;
1194         light.ambient[0]=.2;
1195         light.ambient[1]=.2;
1196         light.ambient[2]=.24;
1197         light.location.x=1;
1198         light.location.y=1;
1199         light.location.z=-.2;
1200         Normalise(&light.location);
1201
1202         LoadingScreen();
1203
1204         SetUpLighting();
1205
1206
1207         fadestart=.6;
1208         gravity=-10;
1209
1210         texscale=.2/megascale/viewdistdetail;
1211         terrain.scale=3*megascale*terraindetail*viewdistdetail;
1212
1213         viewer.x=terrain.size/2*terrain.scale;
1214         viewer.z=terrain.size/2*terrain.scale;
1215
1216         hawk.load((char *)":Data:Models:hawk.solid",1);
1217         hawk.Scale(.03,.03,.03);
1218         hawk.Rotate(90,1,1);
1219         hawk.CalculateNormals(0);
1220         hawk.ScaleNormals(-1,-1,-1);
1221         hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1222         hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1223         hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1224
1225
1226         eye.load((char *)":Data:Models:eye.solid",1);
1227         eye.Scale(.03,.03,.03);
1228         eye.CalculateNormals(0);
1229
1230         cornea.load((char *)":Data:Models:cornea.solid",1);
1231         cornea.Scale(.03,.03,.03);
1232         cornea.CalculateNormals(0);
1233
1234         iris.load((char *)":Data:Models:iris.solid",1);
1235         iris.Scale(.03,.03,.03);
1236         iris.CalculateNormals(0);
1237
1238         LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1239         LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1240
1241         oldenvironment=-4;
1242
1243         gameon=1;
1244         mainmenu=0;
1245
1246         firstload=0;
1247         //if(targetlevel!=7)
1248                 Loadlevel(targetlevel);
1249
1250
1251         rabbitcoords=player[0].coords;
1252         rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1253
1254         loadAllAnimations();
1255         //Fix knife stab, too lazy to do it manually
1256         XYZ moveamount;
1257         moveamount=0;
1258         moveamount.z=2;
1259         for(i=0;i<player[0].skeleton.num_joints;i++){
1260                 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1261                         animation[knifesneakattackanim].position[i][j]+=moveamount;
1262                 }
1263         }
1264
1265         loadscreencolor=4;
1266         LoadingScreen();
1267
1268         for(i=0;i<player[0].skeleton.num_joints;i++){
1269                 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1270                         animation[knifesneakattackedanim].position[i][j]+=moveamount;
1271                 }
1272         }
1273
1274         loadscreencolor=4;
1275         LoadingScreen();
1276
1277         for(i=0;i<player[0].skeleton.num_joints;i++){
1278                 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1279                 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1280                 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1281                 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1282         }
1283         animation[dead1anim].speed[0]=0.001;
1284         animation[dead2anim].speed[0]=0.001;
1285         animation[dead3anim].speed[0]=0.001;
1286         animation[dead4anim].speed[0]=0.001;
1287
1288         animation[dead1anim].speed[1]=0.001;
1289         animation[dead2anim].speed[1]=0.001;
1290         animation[dead3anim].speed[1]=0.001;
1291         animation[dead4anim].speed[1]=0.001;
1292
1293         for(i=0;i<player[0].skeleton.num_joints;i++){
1294                 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1295                         animation[swordsneakattackanim].position[i][j]+=moveamount;
1296                 }
1297         }
1298         loadscreencolor=4;
1299         LoadingScreen();
1300         for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1301                 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1302         }
1303
1304         loadscreencolor=4;
1305         LoadingScreen();
1306
1307         for(i=0;i<player[0].skeleton.num_joints;i++){
1308                 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1309                         animation[swordsneakattackedanim].position[i][j]+=moveamount;
1310                 }
1311         }
1312         /*
1313         for(i=0;i<player[0].skeleton.num_joints;i++){
1314         for(j=0;j<animation[sleepanim].numframes;j++){
1315         animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1316         }
1317         }
1318         */
1319         loadscreencolor=4;
1320         LoadingScreen();
1321         temptexdetail=texdetail;
1322         texdetail=1;
1323         texdetail=temptexdetail;
1324
1325         loadscreencolor=4;
1326         LoadingScreen();
1327
1328         //if(ismotionblur){
1329         if(!screentexture){
1330                 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1331
1332                 glGenTextures( 1, &screentexture );
1333                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1334
1335
1336                 glEnable(GL_TEXTURE_2D);
1337                 glBindTexture( GL_TEXTURE_2D, screentexture);
1338                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1339                 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1340
1341                 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1342         }
1343         //}
1344
1345         LoadSounds();
1346
1347         /*PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
1348         OPENAL_SetVolume(channels[consolesuccesssound], 256);
1349         OPENAL_SetPaused(channels[consolesuccesssound], false);
1350         */
1351         if(targetlevel!=7){
1352                 float gLoc[3]={0,0,0};
1353                 float vel[3]={0,0,0};
1354                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1355                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1356                 OPENAL_SetVolume(channels[fireendsound], 256);
1357                 OPENAL_SetPaused(channels[fireendsound], false);
1358         }
1359
1360         stillloading=0;
1361         loading=0;
1362         changedelay=1;
1363
1364         visibleloading=0;
1365 }
1366