2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
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.
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.
15 See the GNU General Public License for more details.
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.
23 #include "openal_wrapper.h"
24 #include "Animation.h"
26 extern float screenwidth,screenheight;
27 extern float viewdistance;
29 extern XYZ lightlocation;
30 extern float lightambient[3],lightbrightness[3];
31 extern float fadestart;
32 extern float texscale;
35 extern Skeleton testskeleton;
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;
45 extern Objects objects;
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;
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;
62 extern bool stillloading;
63 extern TGAImageRec texture;
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;
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;
95 extern float accountcampaignhighscore[10];
96 extern float accountcampaignfasttime[10];
97 extern float accountcampaignscore[10];
98 extern float accountcampaigntime[10];
100 extern int accountcampaignchoicesmade[10];
101 extern int accountcampaignchoices[10][5000];
103 extern OPENAL_STREAM * strm[20];
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);
108 void LOG(const std::string &fmt, ...)
110 // !!! FIXME: write me.
114 Game::TextureList Game::textures;
123 accountactive->endGame();
127 Account::saveFile(":Data:Users", accountactive);
129 TexIter it = textures.begin();
130 for (; it != textures.end(); ++it)
132 if (glIsTexture(it->second))
133 glDeleteTextures(1, &it->second);
137 LOG("Shutting down sound system...");
139 OPENAL_StopSound(OPENAL_ALL);
141 // this is causing problems on Linux, but we'll force an _exit() a little
142 // later in the shutdown process. --ryan.
144 #define streamcount 20
145 #define samplecount 100
147 for (i=0; i < samplecount; ++i)
149 OPENAL_Sample_Free(samp[i]);
152 for (i=0; i < streamcount; ++i)
154 OPENAL_Stream_Close(strm[i]);
167 void Game::LoadSounds()
171 LOG(std::string("Loading sounds..."));
173 OPENAL_3D_SetDopplerFactor(0);
175 OPENAL_SetSFXMasterVolume((int)(volume*255));
177 if(visibleloading){LoadingScreen(); loadscreencolor=5;}
181 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
187 LOG(std::string("Loading texture...") + fileName);
189 // Fix filename so that is os appropreate
190 char * fixedFN = ConvertFileName(fileName);
192 unsigned char fileNamep[256];
193 CopyCStringToPascal(fixedFN, fileNamep);
195 upload_image( fileNamep ,hasalpha);
197 // std::string fname(fileName);
198 // std::transform(fname.begin(), fname.end(), tolower);
199 // TexIter it = textures.find(fname);
203 //if(textures.end() == it)
206 if ( texture.bpp == 24 )
211 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
214 glGenTextures( 1, textureid );
215 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
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 );
223 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
227 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
235 LOG(std::string("Loading texture (S)...") + fileName);
238 unsigned char fileNamep[256];
239 CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
241 upload_image( fileNamep ,0);
242 //LoadTGA( fileName );
244 // std::string fname(fileName);
245 // std::transform(fname.begin(), fname.end(), tolower);
246 // TexIter it = textures.find(fname);
250 //if(textures.end() == it)
252 bytesPerPixel=texture.bpp/8;
255 if ( texture.bpp == 24 )
260 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
262 if(!*textureid)glGenTextures( 1, textureid );
263 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
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 );
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];
279 *skinsize=texture.sizeX;
281 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
283 // textures.insert(std::make_pair(fname, *textureid));
287 // *textureid = it->second;
291 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
298 LOG(std::string("Loading (S)...") + fileName);
301 float temptexdetail=texdetail;
303 //upload_image( fileName );
304 //LoadTGA( fileName );
306 // Converting file to something os specific
307 char * fixedFN = ConvertFileName(fileName);
310 unsigned char fileNamep[256];
311 CopyCStringToPascal(fixedFN, fileNamep);
313 upload_image( fileNamep ,0);
314 texdetail=temptexdetail;
318 bytesPerPixel=texture.bpp/8;
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];
330 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
337 //upload_image( fileName );
338 //LoadTGA( fileName );
340 unsigned char fileNamep[256];
341 CopyCStringToPascal(fileName,fileNamep);
344 opened=upload_image( fileNamep ,1);
357 bytesPerPixel=texture.bpp/8;
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];
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);
379 //***************> ResizeGLScene() <******/
380 GLvoid Game::ReSizeGLScene(float fov, float pnear)
387 glViewport(0,0,screenwidth,screenheight);
389 glMatrixMode(GL_PROJECTION);
392 gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
394 glMatrixMode(GL_MODELVIEW);
398 void Game::LoadingScreen()
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);
406 if (0 > deltaTime) // if negative microseconds
407 deltaTime /= -1000000.0;
408 else // else milliseconds
411 multiplier=deltaTime;
412 if(multiplier<.001)multiplier=.001;
413 if(multiplier>10)multiplier=10;
415 frametime = currTime; // reset for next time interval
420 glClearColor(0,0,0,1);
421 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
424 loadtime+=multiplier*4;
426 loadprogress=loadtime;
427 if(loadprogress>100)loadprogress=100;
429 //loadprogress=abs(Random()%100);
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);
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);
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);
462 //glScalef(.25,.25,.25);
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);
476 //glScalef(.25,.25,.25);
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);
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
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);
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);
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);
525 //glScalef(.25,.25,.25);
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);
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
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);
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);
564 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
566 //glScalef(.25,.25,.25);
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);
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
588 glEnable(GL_TEXTURE_2D);
589 static char string[256]="";
590 sprintf (string, "LOADING... %d%",(int)loadprogress);
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);
598 if(flashamount>1)flashamount=1;
599 if(flashdelay<=0)flashamount-=multiplier;
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);
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);
617 glColor4f(flashr,flashg,flashb,flashamount);
619 glVertex3f(0, 0, 0.0f);
620 glVertex3f(256, 0, 0.0f);
621 glVertex3f(256, 256, 0.0f);
622 glVertex3f(0, 256, 0.0f);
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);
639 void Game::FadeLoadingScreen(float howmuch)
641 static float loadprogress,minprogress,maxprogress;
646 glClearColor(0,0,0,1);
647 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
649 loadprogress=howmuch;
651 //loadprogress=abs(Random()%100);
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);
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);
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);
684 //glScalef(.25,.25,.25);
687 glVertex3f(-1, -1, 0.0f);
689 glVertex3f(1, -1, 0.0f);
691 glVertex3f(1, 1, 0.0f);
693 glVertex3f(-1, 1, 0.0f);
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
705 glEnable(GL_TEXTURE_2D);
706 static char string[256]="";
707 sprintf (string, "LOADING... %d%",(int)loadprogress);
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);
718 void Game::InitGame()
721 ProcessSerialNumber PSN;
722 ProcessInfoRec pinfo;
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);
735 vRefNum = pspec.vRefNum;
746 numchallengelevels=14;
748 accountactive=Account::loadFile(":Data:Users");
754 whichjointstartarray[0]=righthip;
755 whichjointendarray[0]=rightfoot;
757 whichjointstartarray[1]=righthip;
758 whichjointendarray[1]=rightankle;
760 whichjointstartarray[2]=righthip;
761 whichjointendarray[2]=rightknee;
763 whichjointstartarray[3]=rightknee;
764 whichjointendarray[3]=rightankle;
766 whichjointstartarray[4]=rightankle;
767 whichjointendarray[4]=rightfoot;
769 whichjointstartarray[5]=lefthip;
770 whichjointendarray[5]=leftfoot;
772 whichjointstartarray[6]=lefthip;
773 whichjointendarray[6]=leftankle;
775 whichjointstartarray[7]=lefthip;
776 whichjointendarray[7]=leftknee;
778 whichjointstartarray[8]=leftknee;
779 whichjointendarray[8]=leftankle;
781 whichjointstartarray[9]=leftankle;
782 whichjointendarray[9]=leftfoot;
784 whichjointstartarray[10]=abdomen;
785 whichjointendarray[10]=rightshoulder;
787 whichjointstartarray[11]=abdomen;
788 whichjointendarray[11]=rightelbow;
790 whichjointstartarray[12]=abdomen;
791 whichjointendarray[12]=rightwrist;
793 whichjointstartarray[13]=abdomen;
794 whichjointendarray[13]=righthand;
796 whichjointstartarray[14]=rightshoulder;
797 whichjointendarray[14]=rightelbow;
799 whichjointstartarray[15]=rightelbow;
800 whichjointendarray[15]=rightwrist;
802 whichjointstartarray[16]=rightwrist;
803 whichjointendarray[16]=righthand;
805 whichjointstartarray[17]=abdomen;
806 whichjointendarray[17]=leftshoulder;
808 whichjointstartarray[18]=abdomen;
809 whichjointendarray[18]=leftelbow;
811 whichjointstartarray[19]=abdomen;
812 whichjointendarray[19]=leftwrist;
814 whichjointstartarray[20]=abdomen;
815 whichjointendarray[20]=lefthand;
817 whichjointstartarray[21]=leftshoulder;
818 whichjointendarray[21]=leftelbow;
820 whichjointstartarray[22]=leftelbow;
821 whichjointendarray[22]=leftwrist;
823 whichjointstartarray[23]=leftwrist;
824 whichjointendarray[23]=lefthand;
826 whichjointstartarray[24]=abdomen;
827 whichjointendarray[24]=neck;
829 whichjointstartarray[25]=neck;
830 whichjointendarray[25]=head;
832 FadeLoadingScreen(0);
836 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
838 int temptexdetail=texdetail;
840 text.LoadFontTexture(":Data:Textures:Font.png");
842 texdetail=temptexdetail;
844 FadeLoadingScreen(10);
860 memset(channels, 0xff, sizeof(channels));
861 for (int it = 0; it < 20; ++it)
866 LOG("Initializing sound system...");
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;
879 OPENAL_SetOutput(output);
880 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
882 // if we tried ALSA and failed, fall back to OSS.
883 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
886 output = OPENAL_OUTPUT_OSS;
887 OPENAL_SetOutput(output);
888 rc = OPENAL_Init(44100, 32, 0);
895 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
896 OPENAL_SetOutput(output);
897 rc = OPENAL_Init(44100, 32, 0);
900 OPENAL_Init(44100, 32, 0);
903 OPENAL_SetSFXMasterVolume((int)(volume*255));
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);
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);
916 FadeLoadingScreen(20);
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);
923 FadeLoadingScreen(30);
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);
930 FadeLoadingScreen(40);
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);
936 FadeLoadingScreen(50);
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);
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);
947 FadeLoadingScreen(60);
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);
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);
961 FadeLoadingScreen(90);
964 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
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);
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;
984 FadeLoadingScreen(95);
995 newscreenwidth=screenwidth;
996 newscreenheight=screenheight;
1000 void Game::LoadStuff()
1002 static float temptexdetail;
1003 static float viewdistdetail;
1004 static int i,j,texsize;
1011 /*musicvolume[3]=512;
1012 PlaySoundEx( music4, samp[music4], NULL, true);
1013 OPENAL_SetPaused(channels[music4], false);
1014 OPENAL_SetVolume(channels[music4], 512);
1020 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
1022 for(i=0;i<maxplayers;i++)
1024 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
1026 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
1028 player[i].skeleton.drawmodel.textureptr=0;;
1031 //temptexdetail=texdetail;
1034 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
1035 //texdetail=temptexdetail;
1037 temptexdetail=texdetail;
1039 text.LoadFontTexture(":Data:Textures:Font.png");
1041 texdetail=temptexdetail;
1046 viewdistance=50*megascale*viewdistdetail;
1066 realtexdetail=texdetail;
1069 if(texdetail<1)texdetail=1;
1070 realtexdetail=texdetail*4;
1076 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
1078 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
1080 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1084 LOG("Loading weapon data...");
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);
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);
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);
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);
1123 //temptexdetail=texdetail;
1124 //if(texdetail>4)texdetail=4;
1125 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1127 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1129 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1131 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1134 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1136 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1138 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1140 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1142 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1144 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1146 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1148 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1149 //texdetail=temptexdetail;
1150 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1154 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1156 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1159 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
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);
1176 ReSizeGLScene(90,.01);
1183 if(detail)kTextureSize=1024;
1184 if(detail==1)kTextureSize=512;
1185 if(detail==0)kTextureSize=256;
1188 //drawmode=motionblurmode;
1190 //Set up distant light
1194 light.ambient[0]=.2;
1195 light.ambient[1]=.2;
1196 light.ambient[2]=.24;
1199 light.location.z=-.2;
1200 Normalise(&light.location);
1210 texscale=.2/megascale/viewdistdetail;
1211 terrain.scale=3*megascale*terraindetail*viewdistdetail;
1213 viewer.x=terrain.size/2*terrain.scale;
1214 viewer.z=terrain.size/2*terrain.scale;
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;
1226 eye.load((char *)":Data:Models:eye.solid",1);
1227 eye.Scale(.03,.03,.03);
1228 eye.CalculateNormals(0);
1230 cornea.load((char *)":Data:Models:cornea.solid",1);
1231 cornea.Scale(.03,.03,.03);
1232 cornea.CalculateNormals(0);
1234 iris.load((char *)":Data:Models:iris.solid",1);
1235 iris.Scale(.03,.03,.03);
1236 iris.CalculateNormals(0);
1238 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1239 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1247 //if(targetlevel!=7)
1248 Loadlevel(targetlevel);
1251 rabbitcoords=player[0].coords;
1252 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1254 loadAllAnimations();
1255 //Fix knife stab, too lazy to do it manually
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;
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;
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];
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;
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;
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;
1300 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1301 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
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;
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);
1321 temptexdetail=texdetail;
1323 texdetail=temptexdetail;
1330 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1332 glGenTextures( 1, &screentexture );
1333 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
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 );
1341 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1347 /*PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
1348 OPENAL_SetVolume(channels[consolesuccesssound], 256);
1349 OPENAL_SetPaused(channels[consolesuccesssound], false);
1352 float gLoc[3]={0,0,0};
1353 float vel[3]={0,0,0};
1354 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1355 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1356 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1357 OPENAL_SetVolume(channels[fireendsound], 256);
1358 OPENAL_SetPaused(channels[fireendsound], false);
1359 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);