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 Terrain terrain;
38 //extern Sprites sprites;
39 extern int kTextureSize;
40 extern float texdetail;
41 extern float realtexdetail;
43 extern Objects objects;
45 extern bool cellophane;
46 extern GLubyte bloodText[512*512*3];
47 extern GLubyte wolfbloodText[512*512*3];
48 extern bool ismotionblur;
49 extern bool trilinear;
51 extern bool musictoggle;
52 extern int environment;
53 extern bool ambientsound;
54 extern float multiplier;
55 extern int netdatanew;
57 extern bool stillloading;
58 extern TGAImageRec texture;
62 extern int oldmainmenu;
63 extern bool visibleloading;
64 extern float flashamount,flashr,flashg,flashb;
65 extern int flashdelay;
66 extern int whichjointstartarray[26];
67 extern int whichjointendarray[26];
68 extern int difficulty;
69 extern float tintr,tintg,tintb;
70 extern float slomospeed;
71 extern bool gamestarted;
73 extern int numdialogues;
74 extern int numdialogueboxes[20];
75 extern int dialoguetype[20];
76 extern int dialogueboxlocation[20][20];
77 extern float dialogueboxcolor[20][20][3];
78 extern int dialogueboxsound[20][20];
79 extern char dialoguetext[20][20][128];
80 extern char dialoguename[20][20][64];
81 extern XYZ dialoguecamera[20][20];
82 extern float dialoguecamerarotation[20][20];
83 extern float dialoguecamerarotation2[20][20];
84 extern int indialogue;
85 extern int whichdialogue;
86 extern float dialoguetime;
88 extern float accountcampaignhighscore[10];
89 extern float accountcampaignfasttime[10];
90 extern float accountcampaignscore[10];
91 extern float accountcampaigntime[10];
93 extern int accountcampaignchoicesmade[10];
94 extern int accountcampaignchoices[10][5000];
96 void LOG(const std::string &fmt, ...)
98 // !!! FIXME: write me.
107 accountactive->endGame();
111 Account::saveFile(":Data:Users", accountactive);
115 LOG("Shutting down sound system...");
117 OPENAL_StopSound(OPENAL_ALL);
119 // this is causing problems on Linux, but we'll force an _exit() a little
120 // later in the shutdown process. --ryan.
123 for (int i=0; i < sounds_count; ++i)
125 OPENAL_Sample_Free(samp[i]);
138 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha){
139 textures.push_back(TextureInfo(fileName,textureid,mipmap,hasalpha));
140 textures.back().load();
143 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize){
144 textures.push_back(TextureInfo(fileName,textureid,mipmap,array,skinsize));
145 textures.back().load();
148 void Game::LoadTextureData(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
154 LOG(std::string("Loading texture...") + fileName);
156 // Fix filename so that is os appropreate
157 char * fixedFN = ConvertFileName(fileName);
159 unsigned char fileNamep[256];
160 CopyCStringToPascal(fixedFN, fileNamep);
162 upload_image( fileNamep ,hasalpha);
164 // std::string fname(fileName);
165 // std::transform(fname.begin(), fname.end(), tolower);
166 // TexIter it = textures.find(fname);
170 //if(textures.end() == it)
173 if ( texture.bpp == 24 )
178 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
181 glGenTextures( 1, textureid );
182 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
184 glBindTexture( GL_TEXTURE_2D, *textureid);
185 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
186 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
187 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
188 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
190 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
194 void Game::LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload)
202 LOG(std::string("Loading texture (S)...") + fileName);
205 unsigned char fileNamep[256];
206 CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
208 upload_image( fileNamep ,0);
209 //LoadTGA( fileName );
211 // std::string fname(fileName);
212 // std::transform(fname.begin(), fname.end(), tolower);
213 // TexIter it = textures.find(fname);
217 //if(textures.end() == it)
219 bytesPerPixel=texture.bpp/8;
222 if ( texture.bpp == 24 )
227 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
229 if(!*textureid)glGenTextures( 1, textureid );
230 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
232 glBindTexture( GL_TEXTURE_2D, *textureid);
233 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
234 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
235 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
236 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
240 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++)
241 if((i+1)%4||type==GL_RGB){
242 array[tempnum]=texture.data[i];
246 *skinsize=texture.sizeX;
248 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
250 // textures.insert(std::make_pair(fname, *textureid));
254 // *textureid = it->second;
258 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
265 LOG(std::string("Loading (S)...") + fileName);
268 float temptexdetail=texdetail;
270 //upload_image( fileName );
271 //LoadTGA( fileName );
273 // Converting file to something os specific
274 char * fixedFN = ConvertFileName(fileName);
277 unsigned char fileNamep[256];
278 CopyCStringToPascal(fixedFN, fileNamep);
280 upload_image( fileNamep ,0);
281 texdetail=temptexdetail;
285 bytesPerPixel=texture.bpp/8;
288 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
289 if((i+1)%4||bytesPerPixel==3){
290 array[tempnum]=texture.data[i];
297 bool Game::AddClothes(const char *fileName, GLubyte *array)
304 //upload_image( fileName );
305 //LoadTGA( fileName );
307 unsigned char fileNamep[256];
308 CopyCStringToPascal(fileName,fileNamep);
311 opened=upload_image( fileNamep ,1);
324 bytesPerPixel=texture.bpp/8;
328 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
329 if(bytesPerPixel==3)alphanum=255;
330 else if((i+1)%4==0)alphanum=texture.data[i];
332 if((i+1)%4||bytesPerPixel==3){
333 if((i%4)==0)texture.data[i]*=tintr;
334 if((i%4)==1)texture.data[i]*=tintg;
335 if((i%4)==2)texture.data[i]*=tintb;
336 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
346 //***************> ResizeGLScene() <******/
347 GLvoid Game::ReSizeGLScene(float fov, float pnear)
354 glViewport(0,0,screenwidth,screenheight);
356 glMatrixMode(GL_PROJECTION);
359 gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
361 glMatrixMode(GL_MODELVIEW);
365 void Game::LoadingScreen()
367 static float loadprogress;
368 static AbsoluteTime time = {0,0};
369 static AbsoluteTime frametime = {0,0};
370 AbsoluteTime currTime = UpTime ();
371 double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
373 if (0 > deltaTime) // if negative microseconds
374 deltaTime /= -1000000.0;
375 else // else milliseconds
378 multiplier=deltaTime;
379 if(multiplier<.001)multiplier=.001;
380 if(multiplier>10)multiplier=10;
382 frametime = currTime; // reset for next time interval
386 glClearColor(0,0,0,1);
387 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
390 loadtime+=multiplier*4;
392 loadprogress=loadtime;
393 if(loadprogress>100)loadprogress=100;
395 //loadprogress=abs(Random()%100);
399 glEnable(GL_TEXTURE_2D);
400 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
401 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
402 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
403 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
404 glDisable(GL_CULL_FACE);
405 glDisable(GL_LIGHTING);
407 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
408 glPushMatrix(); // Store The Projection Matrix
409 glLoadIdentity(); // Reset The Projection Matrix
410 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
411 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
412 glPushMatrix(); // Store The Modelview Matrix
413 glLoadIdentity(); // Reset The Modelview Matrix
414 glTranslatef(screenwidth/2,screenheight/2,0);
415 glScalef((float)screenwidth/2,(float)screenheight/2,1);
416 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
418 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
420 //glScalef(.25,.25,.25);
422 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
423 glVertex3f(-1, -1, 0.0f);
424 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
425 glVertex3f(1, -1, 0.0f);
426 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
427 glVertex3f(1, 1, 0.0f);
428 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
429 glVertex3f(-1, 1, 0.0f);
434 //glScalef(.25,.25,.25);
436 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
437 glVertex3f(-1, -1, 0.0f);
438 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
439 glVertex3f(1, -1, 0.0f);
440 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
441 glVertex3f(1, 1, 0.0f);
442 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
443 glVertex3f(-1, 1, 0.0f);
446 glDisable(GL_TEXTURE_2D);
447 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
448 glPopMatrix(); // Restore The Old Projection Matrix
449 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
450 glPopMatrix(); // Restore The Old Projection Matrix
454 glEnable(GL_TEXTURE_2D);
455 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
456 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
457 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
458 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
459 glDisable(GL_CULL_FACE);
460 glDisable(GL_LIGHTING);
462 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
463 glPushMatrix(); // Store The Projection Matrix
464 glLoadIdentity(); // Reset The Projection Matrix
465 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
466 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
467 glPushMatrix(); // Store The Modelview Matrix
468 glLoadIdentity(); // Reset The Modelview Matrix
469 glTranslatef(screenwidth/2,screenheight/2,0);
470 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
471 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
473 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
474 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
476 //glScalef(.25,.25,.25);
478 glTexCoord2f(0+.5,0+.5);
479 glVertex3f(-1, -1, 0.0f);
480 glTexCoord2f(1+.5,0+.5);
481 glVertex3f(1, -1, 0.0f);
482 glTexCoord2f(1+.5,1+.5);
483 glVertex3f(1, 1, 0.0f);
484 glTexCoord2f(0+.5,1+.5);
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*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
513 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
515 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
517 //glScalef(.25,.25,.25);
519 glTexCoord2f(0+.2,0+.8);
520 glVertex3f(-1, -1, 0.0f);
521 glTexCoord2f(1+.2,0+.8);
522 glVertex3f(1, -1, 0.0f);
523 glTexCoord2f(1+.2,1+.8);
524 glVertex3f(1, 1, 0.0f);
525 glTexCoord2f(0+.2,1+.8);
526 glVertex3f(-1, 1, 0.0f);
529 glDisable(GL_TEXTURE_2D);
530 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
531 glPopMatrix(); // Restore The Old Projection Matrix
532 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
533 glPopMatrix(); // Restore The Old Projection Matrix
540 if(flashamount>1)flashamount=1;
541 if(flashdelay<=0)flashamount-=multiplier;
543 if(flashamount<0)flashamount=0;
544 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
545 glDisable(GL_CULL_FACE);
546 glDisable(GL_LIGHTING);
547 glDisable(GL_TEXTURE_2D);
549 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
550 glPushMatrix(); // Store The Projection Matrix
551 glLoadIdentity(); // Reset The Projection Matrix
552 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
553 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
554 glPushMatrix(); // Store The Modelview Matrix
555 glLoadIdentity(); // Reset The Modelview Matrix
556 glScalef(screenwidth,screenheight,1);
557 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
559 glColor4f(flashr,flashg,flashb,flashamount);
561 glVertex3f(0, 0, 0.0f);
562 glVertex3f(256, 0, 0.0f);
563 glVertex3f(256, 256, 0.0f);
564 glVertex3f(0, 256, 0.0f);
566 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
567 glPopMatrix(); // Restore The Old Projection Matrix
568 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
569 glPopMatrix(); // Restore The Old Projection Matrix
570 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
571 glEnable(GL_CULL_FACE);
580 void Game::FadeLoadingScreen(float howmuch)
582 static float loadprogress;
586 glClearColor(0,0,0,1);
587 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
589 loadprogress=howmuch;
591 //loadprogress=abs(Random()%100);
595 //glEnable(GL_TEXTURE_2D);
596 glDisable(GL_TEXTURE_2D);
597 //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
598 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
599 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
600 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
601 glDisable(GL_CULL_FACE);
602 glDisable(GL_LIGHTING);
604 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
605 glPushMatrix(); // Store The Projection Matrix
606 glLoadIdentity(); // Reset The Projection Matrix
607 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
608 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
609 glPushMatrix(); // Store The Modelview Matrix
610 glLoadIdentity(); // Reset The Modelview Matrix
611 glTranslatef(screenwidth/2,screenheight/2,0);
612 glScalef((float)screenwidth/2,(float)screenheight/2,1);
613 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
615 glColor4f(loadprogress/100,0,0,1);
617 //glScalef(.25,.25,.25);
620 glVertex3f(-1, -1, 0.0f);
622 glVertex3f(1, -1, 0.0f);
624 glVertex3f(1, 1, 0.0f);
626 glVertex3f(-1, 1, 0.0f);
629 glDisable(GL_TEXTURE_2D);
630 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
631 glPopMatrix(); // Restore The Old Projection Matrix
632 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
633 glPopMatrix(); // Restore The Old Projection Matrix
641 void Game::InitGame()
644 ProcessSerialNumber PSN;
645 ProcessInfoRec pinfo;
648 /* set up process serial number */
649 PSN.highLongOfPSN = 0;
650 PSN.lowLongOfPSN = kCurrentProcess;
651 /* set up info block */
652 pinfo.processInfoLength = sizeof(pinfo);
653 pinfo.processName = NULL;
654 pinfo.processAppSpec = &pspec;
655 /* grab the vrefnum and directory */
656 err = GetProcessInformation(&PSN, &pinfo);
658 vRefNum = pspec.vRefNum;
667 numchallengelevels=14;
669 accountactive=Account::loadFile(":Data:Users");
675 whichjointstartarray[0]=righthip;
676 whichjointendarray[0]=rightfoot;
678 whichjointstartarray[1]=righthip;
679 whichjointendarray[1]=rightankle;
681 whichjointstartarray[2]=righthip;
682 whichjointendarray[2]=rightknee;
684 whichjointstartarray[3]=rightknee;
685 whichjointendarray[3]=rightankle;
687 whichjointstartarray[4]=rightankle;
688 whichjointendarray[4]=rightfoot;
690 whichjointstartarray[5]=lefthip;
691 whichjointendarray[5]=leftfoot;
693 whichjointstartarray[6]=lefthip;
694 whichjointendarray[6]=leftankle;
696 whichjointstartarray[7]=lefthip;
697 whichjointendarray[7]=leftknee;
699 whichjointstartarray[8]=leftknee;
700 whichjointendarray[8]=leftankle;
702 whichjointstartarray[9]=leftankle;
703 whichjointendarray[9]=leftfoot;
705 whichjointstartarray[10]=abdomen;
706 whichjointendarray[10]=rightshoulder;
708 whichjointstartarray[11]=abdomen;
709 whichjointendarray[11]=rightelbow;
711 whichjointstartarray[12]=abdomen;
712 whichjointendarray[12]=rightwrist;
714 whichjointstartarray[13]=abdomen;
715 whichjointendarray[13]=righthand;
717 whichjointstartarray[14]=rightshoulder;
718 whichjointendarray[14]=rightelbow;
720 whichjointstartarray[15]=rightelbow;
721 whichjointendarray[15]=rightwrist;
723 whichjointstartarray[16]=rightwrist;
724 whichjointendarray[16]=righthand;
726 whichjointstartarray[17]=abdomen;
727 whichjointendarray[17]=leftshoulder;
729 whichjointstartarray[18]=abdomen;
730 whichjointendarray[18]=leftelbow;
732 whichjointstartarray[19]=abdomen;
733 whichjointendarray[19]=leftwrist;
735 whichjointstartarray[20]=abdomen;
736 whichjointendarray[20]=lefthand;
738 whichjointstartarray[21]=leftshoulder;
739 whichjointendarray[21]=leftelbow;
741 whichjointstartarray[22]=leftelbow;
742 whichjointendarray[22]=leftwrist;
744 whichjointstartarray[23]=leftwrist;
745 whichjointendarray[23]=lefthand;
747 whichjointstartarray[24]=abdomen;
748 whichjointendarray[24]=neck;
750 whichjointstartarray[25]=neck;
751 whichjointendarray[25]=head;
753 FadeLoadingScreen(0);
757 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
759 int temptexdetail=texdetail;
761 text.LoadFontTexture(":Data:Textures:Font.png");
763 texdetail=temptexdetail;
765 FadeLoadingScreen(10);
777 LOG("Initializing sound system...");
782 extern bool cmdline(const char *cmd);
783 unsigned char rc = 0;
784 output = OPENAL_OUTPUT_ALSA; // Try alsa first...
785 if (cmdline("forceoss")) // ...but let user override that.
786 output = OPENAL_OUTPUT_OSS;
787 else if (cmdline("nosound"))
788 output = OPENAL_OUTPUT_NOSOUND;
790 OPENAL_SetOutput(output);
791 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
793 // if we tried ALSA and failed, fall back to OSS.
794 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
797 output = OPENAL_OUTPUT_OSS;
798 OPENAL_SetOutput(output);
799 rc = OPENAL_Init(44100, 32, 0);
806 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
807 OPENAL_SetOutput(output);
808 rc = OPENAL_Init(44100, 32, 0);
811 OPENAL_Init(44100, 32, 0);
814 OPENAL_SetSFXMasterVolume((int)(volume*255));
818 emit_stream_np(stream_menutheme);
820 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
822 LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
823 LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
824 LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
826 temptexdetail=texdetail;
827 if(texdetail>2)texdetail=2;
828 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
829 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
830 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
831 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
832 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
833 LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
834 //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
835 texdetail=temptexdetail;
837 FadeLoadingScreen(95);
848 newscreenwidth=screenwidth;
849 newscreenheight=screenheight;
853 void Game::LoadScreenTexture(){
854 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
857 glGenTextures( 1, &screentexture );
858 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
861 glEnable(GL_TEXTURE_2D);
862 glBindTexture( GL_TEXTURE_2D, screentexture);
863 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
864 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
866 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
869 void Game::LoadStuff()
871 static float temptexdetail;
872 static float viewdistdetail;
884 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
886 for(i=0;i<maxplayers;i++)
888 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
890 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
892 player[i].skeleton.drawmodel.textureptr=0;;
895 //temptexdetail=texdetail;
898 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
899 //texdetail=temptexdetail;
901 temptexdetail=texdetail;
903 text.LoadFontTexture(":Data:Textures:Font.png");
905 texdetail=temptexdetail;
910 viewdistance=50*megascale*viewdistdetail;
926 realtexdetail=texdetail;
929 if(texdetail<1)texdetail=1;
930 realtexdetail=texdetail*4;
936 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
938 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
940 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
944 LOG("Loading weapon data...");
946 LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
947 LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
948 LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
949 LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
950 LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
951 LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
952 LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
954 weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
955 weapons.throwingknifemodel.Scale(.001,.001,.001);
956 //weapons.throwingknifemodel.Rotate(0,0,-90);
957 weapons.throwingknifemodel.Rotate(90,0,0);
958 weapons.throwingknifemodel.Rotate(0,90,0);
959 weapons.throwingknifemodel.flat=0;
960 weapons.throwingknifemodel.CalculateNormals(1);
961 //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
963 weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
964 weapons.swordmodel.Scale(.001,.001,.001);
965 //weapons.swordmodel.Rotate(0,0,-90);
966 weapons.swordmodel.Rotate(90,0,0);
967 weapons.swordmodel.Rotate(0,90,0);
968 weapons.swordmodel.Rotate(0,0,90);
969 weapons.swordmodel.flat=1;
970 weapons.swordmodel.CalculateNormals(1);
971 //weapons.swordmodel.ScaleNormals(-1,-1,-1);
973 weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
974 weapons.staffmodel.Scale(.005,.005,.005);
975 //weapons.staffmodel.Rotate(0,0,-90);
976 weapons.staffmodel.Rotate(90,0,0);
977 weapons.staffmodel.Rotate(0,90,0);
978 weapons.staffmodel.Rotate(0,0,90);
979 weapons.staffmodel.flat=1;
980 weapons.staffmodel.CalculateNormals(1);
981 //weapons.staffmodel.ScaleNormals(-1,-1,-1);
983 //temptexdetail=texdetail;
984 //if(texdetail>4)texdetail=4;
985 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
987 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
989 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
991 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
994 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
996 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
998 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1000 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1002 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1004 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1006 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1008 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1009 //texdetail=temptexdetail;
1010 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1014 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1016 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1019 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1022 LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1023 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1024 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1025 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1026 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1027 LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1028 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1029 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1030 LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1031 LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1032 LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1036 ReSizeGLScene(90,.01);
1043 if(detail)kTextureSize=1024;
1044 if(detail==1)kTextureSize=512;
1045 if(detail==0)kTextureSize=256;
1048 //drawmode=motionblurmode;
1050 //Set up distant light
1054 light.ambient[0]=.2;
1055 light.ambient[1]=.2;
1056 light.ambient[2]=.24;
1059 light.location.z=-.2;
1060 Normalise(&light.location);
1070 texscale=.2/megascale/viewdistdetail;
1071 terrain.scale=3*megascale*viewdistdetail;
1073 viewer.x=terrain.size/2*terrain.scale;
1074 viewer.z=terrain.size/2*terrain.scale;
1076 hawk.load((char *)":Data:Models:hawk.solid",1);
1077 hawk.Scale(.03,.03,.03);
1078 hawk.Rotate(90,1,1);
1079 hawk.CalculateNormals(0);
1080 hawk.ScaleNormals(-1,-1,-1);
1081 hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1082 hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1083 hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1086 eye.load((char *)":Data:Models:eye.solid",1);
1087 eye.Scale(.03,.03,.03);
1088 eye.CalculateNormals(0);
1090 cornea.load((char *)":Data:Models:cornea.solid",1);
1091 cornea.Scale(.03,.03,.03);
1092 cornea.CalculateNormals(0);
1094 iris.load((char *)":Data:Models:iris.solid",1);
1095 iris.Scale(.03,.03,.03);
1096 iris.CalculateNormals(0);
1098 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1099 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1107 //if(targetlevel!=7)
1108 Loadlevel(targetlevel);
1111 rabbitcoords=player[0].coords;
1112 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1114 loadAllAnimations();
1115 //Fix knife stab, too lazy to do it manually
1119 for(i=0;i<player[0].skeleton.num_joints;i++){
1120 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1121 animation[knifesneakattackanim].position[i][j]+=moveamount;
1127 for(i=0;i<player[0].skeleton.num_joints;i++){
1128 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1129 animation[knifesneakattackedanim].position[i][j]+=moveamount;
1135 for(i=0;i<player[0].skeleton.num_joints;i++){
1136 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1137 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1138 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1139 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1141 animation[dead1anim].speed[0]=0.001;
1142 animation[dead2anim].speed[0]=0.001;
1143 animation[dead3anim].speed[0]=0.001;
1144 animation[dead4anim].speed[0]=0.001;
1146 animation[dead1anim].speed[1]=0.001;
1147 animation[dead2anim].speed[1]=0.001;
1148 animation[dead3anim].speed[1]=0.001;
1149 animation[dead4anim].speed[1]=0.001;
1151 for(i=0;i<player[0].skeleton.num_joints;i++){
1152 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1153 animation[swordsneakattackanim].position[i][j]+=moveamount;
1157 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1158 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1163 for(i=0;i<player[0].skeleton.num_joints;i++){
1164 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1165 animation[swordsneakattackedanim].position[i][j]+=moveamount;
1170 temptexdetail=texdetail;
1172 texdetail=temptexdetail;
1178 LoadScreenTexture();
1182 emit_sound_at(fireendsound);