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.
109 accountactive->endGame();
113 Account::saveFile(":Data:Users", accountactive);
117 LOG("Shutting down sound system...");
119 OPENAL_StopSound(OPENAL_ALL);
121 // this is causing problems on Linux, but we'll force an _exit() a little
122 // later in the shutdown process. --ryan.
125 for (i=0; i < sounds_count; ++i)
127 OPENAL_Sample_Free(samp[i]);
140 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha){
141 textures.push_back(TextureInfo(fileName,textureid,mipmap,hasalpha));
142 textures.back().load();
145 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize){
146 textures.push_back(TextureInfo(fileName,textureid,mipmap,array,skinsize));
147 textures.back().load();
150 void Game::LoadTextureData(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
156 LOG(std::string("Loading texture...") + fileName);
158 // Fix filename so that is os appropreate
159 char * fixedFN = ConvertFileName(fileName);
161 unsigned char fileNamep[256];
162 CopyCStringToPascal(fixedFN, fileNamep);
164 upload_image( fileNamep ,hasalpha);
166 // std::string fname(fileName);
167 // std::transform(fname.begin(), fname.end(), tolower);
168 // TexIter it = textures.find(fname);
172 //if(textures.end() == it)
175 if ( texture.bpp == 24 )
180 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
183 glGenTextures( 1, textureid );
184 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
186 glBindTexture( GL_TEXTURE_2D, *textureid);
187 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
188 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
189 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
190 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
192 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
196 void Game::LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload)
204 LOG(std::string("Loading texture (S)...") + fileName);
207 unsigned char fileNamep[256];
208 CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
210 upload_image( fileNamep ,0);
211 //LoadTGA( fileName );
213 // std::string fname(fileName);
214 // std::transform(fname.begin(), fname.end(), tolower);
215 // TexIter it = textures.find(fname);
219 //if(textures.end() == it)
221 bytesPerPixel=texture.bpp/8;
224 if ( texture.bpp == 24 )
229 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
231 if(!*textureid)glGenTextures( 1, textureid );
232 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
234 glBindTexture( GL_TEXTURE_2D, *textureid);
235 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
236 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
237 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
238 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
242 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++)
243 if((i+1)%4||type==GL_RGB){
244 array[tempnum]=texture.data[i];
248 *skinsize=texture.sizeX;
250 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
252 // textures.insert(std::make_pair(fname, *textureid));
256 // *textureid = it->second;
260 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
267 LOG(std::string("Loading (S)...") + fileName);
270 float temptexdetail=texdetail;
272 //upload_image( fileName );
273 //LoadTGA( fileName );
275 // Converting file to something os specific
276 char * fixedFN = ConvertFileName(fileName);
279 unsigned char fileNamep[256];
280 CopyCStringToPascal(fixedFN, fileNamep);
282 upload_image( fileNamep ,0);
283 texdetail=temptexdetail;
287 bytesPerPixel=texture.bpp/8;
290 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
291 if((i+1)%4||bytesPerPixel==3){
292 array[tempnum]=texture.data[i];
299 bool Game::AddClothes(const char *fileName, GLubyte *array)
306 //upload_image( fileName );
307 //LoadTGA( fileName );
309 unsigned char fileNamep[256];
310 CopyCStringToPascal(fileName,fileNamep);
313 opened=upload_image( fileNamep ,1);
326 bytesPerPixel=texture.bpp/8;
330 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
331 if(bytesPerPixel==3)alphanum=255;
332 else if((i+1)%4==0)alphanum=texture.data[i];
334 if((i+1)%4||bytesPerPixel==3){
335 if((i%4)==0)texture.data[i]*=tintr;
336 if((i%4)==1)texture.data[i]*=tintg;
337 if((i%4)==2)texture.data[i]*=tintb;
338 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
348 //***************> ResizeGLScene() <******/
349 GLvoid Game::ReSizeGLScene(float fov, float pnear)
356 glViewport(0,0,screenwidth,screenheight);
358 glMatrixMode(GL_PROJECTION);
361 gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
363 glMatrixMode(GL_MODELVIEW);
367 void Game::LoadingScreen()
369 static float loadprogress,minprogress,maxprogress;
370 static AbsoluteTime time = {0,0};
371 static AbsoluteTime frametime = {0,0};
372 AbsoluteTime currTime = UpTime ();
373 double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
375 if (0 > deltaTime) // if negative microseconds
376 deltaTime /= -1000000.0;
377 else // else milliseconds
380 multiplier=deltaTime;
381 if(multiplier<.001)multiplier=.001;
382 if(multiplier>10)multiplier=10;
384 frametime = currTime; // reset for next time interval
389 glClearColor(0,0,0,1);
390 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
393 loadtime+=multiplier*4;
395 loadprogress=loadtime;
396 if(loadprogress>100)loadprogress=100;
398 //loadprogress=abs(Random()%100);
402 glEnable(GL_TEXTURE_2D);
403 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
404 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
405 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
406 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
407 glDisable(GL_CULL_FACE);
408 glDisable(GL_LIGHTING);
410 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
411 glPushMatrix(); // Store The Projection Matrix
412 glLoadIdentity(); // Reset The Projection Matrix
413 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
414 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
415 glPushMatrix(); // Store The Modelview Matrix
416 glLoadIdentity(); // Reset The Modelview Matrix
417 glTranslatef(screenwidth/2,screenheight/2,0);
418 glScalef((float)screenwidth/2,(float)screenheight/2,1);
419 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
421 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
423 //glScalef(.25,.25,.25);
425 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
426 glVertex3f(-1, -1, 0.0f);
427 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
428 glVertex3f(1, -1, 0.0f);
429 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
430 glVertex3f(1, 1, 0.0f);
431 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
432 glVertex3f(-1, 1, 0.0f);
437 //glScalef(.25,.25,.25);
439 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
440 glVertex3f(-1, -1, 0.0f);
441 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
442 glVertex3f(1, -1, 0.0f);
443 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
444 glVertex3f(1, 1, 0.0f);
445 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
446 glVertex3f(-1, 1, 0.0f);
449 glDisable(GL_TEXTURE_2D);
450 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
451 glPopMatrix(); // Restore The Old Projection Matrix
452 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
453 glPopMatrix(); // Restore The Old Projection Matrix
457 glEnable(GL_TEXTURE_2D);
458 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
459 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
460 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
461 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
462 glDisable(GL_CULL_FACE);
463 glDisable(GL_LIGHTING);
465 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
466 glPushMatrix(); // Store The Projection Matrix
467 glLoadIdentity(); // Reset The Projection Matrix
468 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
469 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
470 glPushMatrix(); // Store The Modelview Matrix
471 glLoadIdentity(); // Reset The Modelview Matrix
472 glTranslatef(screenwidth/2,screenheight/2,0);
473 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
474 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
476 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
477 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
479 //glScalef(.25,.25,.25);
481 glTexCoord2f(0+.5,0+.5);
482 glVertex3f(-1, -1, 0.0f);
483 glTexCoord2f(1+.5,0+.5);
484 glVertex3f(1, -1, 0.0f);
485 glTexCoord2f(1+.5,1+.5);
486 glVertex3f(1, 1, 0.0f);
487 glTexCoord2f(0+.5,1+.5);
488 glVertex3f(-1, 1, 0.0f);
491 glDisable(GL_TEXTURE_2D);
492 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
493 glPopMatrix(); // Restore The Old Projection Matrix
494 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
495 glPopMatrix(); // Restore The Old Projection Matrix
499 glEnable(GL_TEXTURE_2D);
500 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
501 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
502 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
503 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
504 glDisable(GL_CULL_FACE);
505 glDisable(GL_LIGHTING);
507 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
508 glPushMatrix(); // Store The Projection Matrix
509 glLoadIdentity(); // Reset The Projection Matrix
510 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
511 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
512 glPushMatrix(); // Store The Modelview Matrix
513 glLoadIdentity(); // Reset The Modelview Matrix
514 glTranslatef(screenwidth/2,screenheight/2,0);
515 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
516 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
518 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
520 //glScalef(.25,.25,.25);
522 glTexCoord2f(0+.2,0+.8);
523 glVertex3f(-1, -1, 0.0f);
524 glTexCoord2f(1+.2,0+.8);
525 glVertex3f(1, -1, 0.0f);
526 glTexCoord2f(1+.2,1+.8);
527 glVertex3f(1, 1, 0.0f);
528 glTexCoord2f(0+.2,1+.8);
529 glVertex3f(-1, 1, 0.0f);
532 glDisable(GL_TEXTURE_2D);
533 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
534 glPopMatrix(); // Restore The Old Projection Matrix
535 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
536 glPopMatrix(); // Restore The Old Projection Matrix
542 glEnable(GL_TEXTURE_2D);
543 static char string[256]="";
544 sprintf (string, "LOADING... %d%",(int)loadprogress);
546 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
547 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
548 text.glPrint(280,125,string,1,1,640,480);
552 if(flashamount>1)flashamount=1;
553 if(flashdelay<=0)flashamount-=multiplier;
555 if(flashamount<0)flashamount=0;
556 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
557 glDisable(GL_CULL_FACE);
558 glDisable(GL_LIGHTING);
559 glDisable(GL_TEXTURE_2D);
561 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
562 glPushMatrix(); // Store The Projection Matrix
563 glLoadIdentity(); // Reset The Projection Matrix
564 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
565 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
566 glPushMatrix(); // Store The Modelview Matrix
567 glLoadIdentity(); // Reset The Modelview Matrix
568 glScalef(screenwidth,screenheight,1);
569 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
571 glColor4f(flashr,flashg,flashb,flashamount);
573 glVertex3f(0, 0, 0.0f);
574 glVertex3f(256, 0, 0.0f);
575 glVertex3f(256, 256, 0.0f);
576 glVertex3f(0, 256, 0.0f);
578 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
579 glPopMatrix(); // Restore The Old Projection Matrix
580 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
581 glPopMatrix(); // Restore The Old Projection Matrix
582 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
583 glEnable(GL_CULL_FACE);
592 void Game::FadeLoadingScreen(float howmuch)
594 static float loadprogress,minprogress,maxprogress;
599 glClearColor(0,0,0,1);
600 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
602 loadprogress=howmuch;
604 //loadprogress=abs(Random()%100);
608 //glEnable(GL_TEXTURE_2D);
609 glDisable(GL_TEXTURE_2D);
610 //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
611 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
612 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
613 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
614 glDisable(GL_CULL_FACE);
615 glDisable(GL_LIGHTING);
617 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
618 glPushMatrix(); // Store The Projection Matrix
619 glLoadIdentity(); // Reset The Projection Matrix
620 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
621 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
622 glPushMatrix(); // Store The Modelview Matrix
623 glLoadIdentity(); // Reset The Modelview Matrix
624 glTranslatef(screenwidth/2,screenheight/2,0);
625 glScalef((float)screenwidth/2,(float)screenheight/2,1);
626 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
628 glColor4f(loadprogress/100,0,0,1);
630 //glScalef(.25,.25,.25);
633 glVertex3f(-1, -1, 0.0f);
635 glVertex3f(1, -1, 0.0f);
637 glVertex3f(1, 1, 0.0f);
639 glVertex3f(-1, 1, 0.0f);
642 glDisable(GL_TEXTURE_2D);
643 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
644 glPopMatrix(); // Restore The Old Projection Matrix
645 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
646 glPopMatrix(); // Restore The Old Projection Matrix
651 glEnable(GL_TEXTURE_2D);
652 static char string[256]="";
653 sprintf (string, "LOADING... %d%",(int)loadprogress);
655 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
656 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
657 text.glPrint(280,125,string,1,1,640,480);
663 void Game::InitGame()
666 ProcessSerialNumber PSN;
667 ProcessInfoRec pinfo;
670 /* set up process serial number */
671 PSN.highLongOfPSN = 0;
672 PSN.lowLongOfPSN = kCurrentProcess;
673 /* set up info block */
674 pinfo.processInfoLength = sizeof(pinfo);
675 pinfo.processName = NULL;
676 pinfo.processAppSpec = &pspec;
677 /* grab the vrefnum and directory */
678 err = GetProcessInformation(&PSN, &pinfo);
680 vRefNum = pspec.vRefNum;
691 numchallengelevels=14;
693 accountactive=Account::loadFile(":Data:Users");
699 whichjointstartarray[0]=righthip;
700 whichjointendarray[0]=rightfoot;
702 whichjointstartarray[1]=righthip;
703 whichjointendarray[1]=rightankle;
705 whichjointstartarray[2]=righthip;
706 whichjointendarray[2]=rightknee;
708 whichjointstartarray[3]=rightknee;
709 whichjointendarray[3]=rightankle;
711 whichjointstartarray[4]=rightankle;
712 whichjointendarray[4]=rightfoot;
714 whichjointstartarray[5]=lefthip;
715 whichjointendarray[5]=leftfoot;
717 whichjointstartarray[6]=lefthip;
718 whichjointendarray[6]=leftankle;
720 whichjointstartarray[7]=lefthip;
721 whichjointendarray[7]=leftknee;
723 whichjointstartarray[8]=leftknee;
724 whichjointendarray[8]=leftankle;
726 whichjointstartarray[9]=leftankle;
727 whichjointendarray[9]=leftfoot;
729 whichjointstartarray[10]=abdomen;
730 whichjointendarray[10]=rightshoulder;
732 whichjointstartarray[11]=abdomen;
733 whichjointendarray[11]=rightelbow;
735 whichjointstartarray[12]=abdomen;
736 whichjointendarray[12]=rightwrist;
738 whichjointstartarray[13]=abdomen;
739 whichjointendarray[13]=righthand;
741 whichjointstartarray[14]=rightshoulder;
742 whichjointendarray[14]=rightelbow;
744 whichjointstartarray[15]=rightelbow;
745 whichjointendarray[15]=rightwrist;
747 whichjointstartarray[16]=rightwrist;
748 whichjointendarray[16]=righthand;
750 whichjointstartarray[17]=abdomen;
751 whichjointendarray[17]=leftshoulder;
753 whichjointstartarray[18]=abdomen;
754 whichjointendarray[18]=leftelbow;
756 whichjointstartarray[19]=abdomen;
757 whichjointendarray[19]=leftwrist;
759 whichjointstartarray[20]=abdomen;
760 whichjointendarray[20]=lefthand;
762 whichjointstartarray[21]=leftshoulder;
763 whichjointendarray[21]=leftelbow;
765 whichjointstartarray[22]=leftelbow;
766 whichjointendarray[22]=leftwrist;
768 whichjointstartarray[23]=leftwrist;
769 whichjointendarray[23]=lefthand;
771 whichjointstartarray[24]=abdomen;
772 whichjointendarray[24]=neck;
774 whichjointstartarray[25]=neck;
775 whichjointendarray[25]=head;
777 FadeLoadingScreen(0);
781 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
783 int temptexdetail=texdetail;
785 text.LoadFontTexture(":Data:Textures:Font.png");
787 texdetail=temptexdetail;
789 FadeLoadingScreen(10);
801 LOG("Initializing sound system...");
806 extern bool cmdline(const char *cmd);
807 unsigned char rc = 0;
808 output = OPENAL_OUTPUT_ALSA; // Try alsa first...
809 if (cmdline("forceoss")) // ...but let user override that.
810 output = OPENAL_OUTPUT_OSS;
811 else if (cmdline("nosound"))
812 output = OPENAL_OUTPUT_NOSOUND;
814 OPENAL_SetOutput(output);
815 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
817 // if we tried ALSA and failed, fall back to OSS.
818 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
821 output = OPENAL_OUTPUT_OSS;
822 OPENAL_SetOutput(output);
823 rc = OPENAL_Init(44100, 32, 0);
830 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
831 OPENAL_SetOutput(output);
832 rc = OPENAL_Init(44100, 32, 0);
835 OPENAL_Init(44100, 32, 0);
838 OPENAL_SetSFXMasterVolume((int)(volume*255));
842 emit_stream_np(stream_music3);
844 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
846 LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
847 LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
848 LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
850 temptexdetail=texdetail;
851 if(texdetail>2)texdetail=2;
852 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
853 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
854 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
855 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
856 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
857 LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
858 //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
859 texdetail=temptexdetail;
864 FadeLoadingScreen(95);
875 newscreenwidth=screenwidth;
876 newscreenheight=screenheight;
880 void Game::LoadScreenTexture(){
881 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
884 glGenTextures( 1, &screentexture );
885 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
888 glEnable(GL_TEXTURE_2D);
889 glBindTexture( GL_TEXTURE_2D, screentexture);
890 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
891 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
893 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
896 void Game::LoadStuff()
898 static float temptexdetail;
899 static float viewdistdetail;
900 static int i,j,texsize;
911 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
913 for(i=0;i<maxplayers;i++)
915 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
917 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
919 player[i].skeleton.drawmodel.textureptr=0;;
922 //temptexdetail=texdetail;
925 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
926 //texdetail=temptexdetail;
928 temptexdetail=texdetail;
930 text.LoadFontTexture(":Data:Textures:Font.png");
932 texdetail=temptexdetail;
937 viewdistance=50*megascale*viewdistdetail;
953 realtexdetail=texdetail;
956 if(texdetail<1)texdetail=1;
957 realtexdetail=texdetail*4;
963 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
965 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
967 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
971 LOG("Loading weapon data...");
973 LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
974 LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
975 LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
976 LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
977 LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
978 LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
979 LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
981 weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
982 weapons.throwingknifemodel.Scale(.001,.001,.001);
983 //weapons.throwingknifemodel.Rotate(0,0,-90);
984 weapons.throwingknifemodel.Rotate(90,0,0);
985 weapons.throwingknifemodel.Rotate(0,90,0);
986 weapons.throwingknifemodel.flat=0;
987 weapons.throwingknifemodel.CalculateNormals(1);
988 //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
990 weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
991 weapons.swordmodel.Scale(.001,.001,.001);
992 //weapons.swordmodel.Rotate(0,0,-90);
993 weapons.swordmodel.Rotate(90,0,0);
994 weapons.swordmodel.Rotate(0,90,0);
995 weapons.swordmodel.Rotate(0,0,90);
996 weapons.swordmodel.flat=1;
997 weapons.swordmodel.CalculateNormals(1);
998 //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1000 weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1001 weapons.staffmodel.Scale(.005,.005,.005);
1002 //weapons.staffmodel.Rotate(0,0,-90);
1003 weapons.staffmodel.Rotate(90,0,0);
1004 weapons.staffmodel.Rotate(0,90,0);
1005 weapons.staffmodel.Rotate(0,0,90);
1006 weapons.staffmodel.flat=1;
1007 weapons.staffmodel.CalculateNormals(1);
1008 //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1010 //temptexdetail=texdetail;
1011 //if(texdetail>4)texdetail=4;
1012 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1014 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1016 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1018 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1021 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1023 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1025 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1027 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1029 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1031 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1033 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1035 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1036 //texdetail=temptexdetail;
1037 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1041 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1043 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1046 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1049 LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1050 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1051 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1052 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1053 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1054 LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1055 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1056 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1057 LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1058 LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1059 LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1063 ReSizeGLScene(90,.01);
1070 if(detail)kTextureSize=1024;
1071 if(detail==1)kTextureSize=512;
1072 if(detail==0)kTextureSize=256;
1075 //drawmode=motionblurmode;
1077 //Set up distant light
1081 light.ambient[0]=.2;
1082 light.ambient[1]=.2;
1083 light.ambient[2]=.24;
1086 light.location.z=-.2;
1087 Normalise(&light.location);
1097 texscale=.2/megascale/viewdistdetail;
1098 terrain.scale=3*megascale*viewdistdetail;
1100 viewer.x=terrain.size/2*terrain.scale;
1101 viewer.z=terrain.size/2*terrain.scale;
1103 hawk.load((char *)":Data:Models:hawk.solid",1);
1104 hawk.Scale(.03,.03,.03);
1105 hawk.Rotate(90,1,1);
1106 hawk.CalculateNormals(0);
1107 hawk.ScaleNormals(-1,-1,-1);
1108 hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1109 hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1110 hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1113 eye.load((char *)":Data:Models:eye.solid",1);
1114 eye.Scale(.03,.03,.03);
1115 eye.CalculateNormals(0);
1117 cornea.load((char *)":Data:Models:cornea.solid",1);
1118 cornea.Scale(.03,.03,.03);
1119 cornea.CalculateNormals(0);
1121 iris.load((char *)":Data:Models:iris.solid",1);
1122 iris.Scale(.03,.03,.03);
1123 iris.CalculateNormals(0);
1125 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1126 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1134 //if(targetlevel!=7)
1135 Loadlevel(targetlevel);
1138 rabbitcoords=player[0].coords;
1139 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1141 loadAllAnimations();
1142 //Fix knife stab, too lazy to do it manually
1146 for(i=0;i<player[0].skeleton.num_joints;i++){
1147 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1148 animation[knifesneakattackanim].position[i][j]+=moveamount;
1154 for(i=0;i<player[0].skeleton.num_joints;i++){
1155 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1156 animation[knifesneakattackedanim].position[i][j]+=moveamount;
1162 for(i=0;i<player[0].skeleton.num_joints;i++){
1163 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1164 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1165 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1166 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1168 animation[dead1anim].speed[0]=0.001;
1169 animation[dead2anim].speed[0]=0.001;
1170 animation[dead3anim].speed[0]=0.001;
1171 animation[dead4anim].speed[0]=0.001;
1173 animation[dead1anim].speed[1]=0.001;
1174 animation[dead2anim].speed[1]=0.001;
1175 animation[dead3anim].speed[1]=0.001;
1176 animation[dead4anim].speed[1]=0.001;
1178 for(i=0;i<player[0].skeleton.num_joints;i++){
1179 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1180 animation[swordsneakattackanim].position[i][j]+=moveamount;
1184 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1185 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1190 for(i=0;i<player[0].skeleton.num_joints;i++){
1191 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1192 animation[swordsneakattackedanim].position[i][j]+=moveamount;
1196 for(i=0;i<player[0].skeleton.num_joints;i++){
1197 for(j=0;j<animation[sleepanim].numframes;j++){
1198 animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1203 temptexdetail=texdetail;
1205 texdetail=temptexdetail;
1211 LoadScreenTexture();
1215 emit_sound_at(fireendsound);