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.
102 Game::TextureList Game::textures;
111 accountactive->endGame();
115 Account::saveFile(":Data:Users", accountactive);
117 TexIter it = textures.begin();
118 for (; it != textures.end(); ++it)
120 if (glIsTexture(it->second))
121 glDeleteTextures(1, &it->second);
125 LOG("Shutting down sound system...");
127 OPENAL_StopSound(OPENAL_ALL);
129 // this is causing problems on Linux, but we'll force an _exit() a little
130 // later in the shutdown process. --ryan.
133 for (i=0; i < sounds_count; ++i)
135 OPENAL_Sample_Free(samp[i]);
148 void Game::LoadTexture(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::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
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 );
239 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
240 if((i+1)%4||type==GL_RGB){
241 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, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
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,minprogress,maxprogress;
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
387 glClearColor(0,0,0,1);
388 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
391 loadtime+=multiplier*4;
393 loadprogress=loadtime;
394 if(loadprogress>100)loadprogress=100;
396 //loadprogress=abs(Random()%100);
400 glEnable(GL_TEXTURE_2D);
401 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
402 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
403 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
404 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
405 glDisable(GL_CULL_FACE);
406 glDisable(GL_LIGHTING);
408 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
409 glPushMatrix(); // Store The Projection Matrix
410 glLoadIdentity(); // Reset The Projection Matrix
411 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
412 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
413 glPushMatrix(); // Store The Modelview Matrix
414 glLoadIdentity(); // Reset The Modelview Matrix
415 glTranslatef(screenwidth/2,screenheight/2,0);
416 glScalef((float)screenwidth/2,(float)screenheight/2,1);
417 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
419 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
421 //glScalef(.25,.25,.25);
423 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
424 glVertex3f(-1, -1, 0.0f);
425 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
426 glVertex3f(1, -1, 0.0f);
427 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
428 glVertex3f(1, 1, 0.0f);
429 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
430 glVertex3f(-1, 1, 0.0f);
435 //glScalef(.25,.25,.25);
437 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
438 glVertex3f(-1, -1, 0.0f);
439 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
440 glVertex3f(1, -1, 0.0f);
441 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
442 glVertex3f(1, 1, 0.0f);
443 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
444 glVertex3f(-1, 1, 0.0f);
447 glDisable(GL_TEXTURE_2D);
448 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
449 glPopMatrix(); // Restore The Old Projection Matrix
450 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
451 glPopMatrix(); // Restore The Old Projection Matrix
455 glEnable(GL_TEXTURE_2D);
456 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
457 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
458 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
459 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
460 glDisable(GL_CULL_FACE);
461 glDisable(GL_LIGHTING);
463 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
464 glPushMatrix(); // Store The Projection Matrix
465 glLoadIdentity(); // Reset The Projection Matrix
466 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
467 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
468 glPushMatrix(); // Store The Modelview Matrix
469 glLoadIdentity(); // Reset The Modelview Matrix
470 glTranslatef(screenwidth/2,screenheight/2,0);
471 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
472 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
474 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
475 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
477 //glScalef(.25,.25,.25);
479 glTexCoord2f(0+.5,0+.5);
480 glVertex3f(-1, -1, 0.0f);
481 glTexCoord2f(1+.5,0+.5);
482 glVertex3f(1, -1, 0.0f);
483 glTexCoord2f(1+.5,1+.5);
484 glVertex3f(1, 1, 0.0f);
485 glTexCoord2f(0+.5,1+.5);
486 glVertex3f(-1, 1, 0.0f);
489 glDisable(GL_TEXTURE_2D);
490 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
491 glPopMatrix(); // Restore The Old Projection Matrix
492 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
493 glPopMatrix(); // Restore The Old Projection Matrix
497 glEnable(GL_TEXTURE_2D);
498 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
499 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
500 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
501 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
502 glDisable(GL_CULL_FACE);
503 glDisable(GL_LIGHTING);
505 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
506 glPushMatrix(); // Store The Projection Matrix
507 glLoadIdentity(); // Reset The Projection Matrix
508 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
509 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
510 glPushMatrix(); // Store The Modelview Matrix
511 glLoadIdentity(); // Reset The Modelview Matrix
512 glTranslatef(screenwidth/2,screenheight/2,0);
513 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
514 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
516 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
518 //glScalef(.25,.25,.25);
520 glTexCoord2f(0+.2,0+.8);
521 glVertex3f(-1, -1, 0.0f);
522 glTexCoord2f(1+.2,0+.8);
523 glVertex3f(1, -1, 0.0f);
524 glTexCoord2f(1+.2,1+.8);
525 glVertex3f(1, 1, 0.0f);
526 glTexCoord2f(0+.2,1+.8);
527 glVertex3f(-1, 1, 0.0f);
530 glDisable(GL_TEXTURE_2D);
531 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
532 glPopMatrix(); // Restore The Old Projection Matrix
533 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
534 glPopMatrix(); // Restore The Old Projection Matrix
540 glEnable(GL_TEXTURE_2D);
541 static char string[256]="";
542 sprintf (string, "LOADING... %d%",(int)loadprogress);
544 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
545 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
546 text.glPrint(280,125,string,1,1,640,480);
550 if(flashamount>1)flashamount=1;
551 if(flashdelay<=0)flashamount-=multiplier;
553 if(flashamount<0)flashamount=0;
554 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
555 glDisable(GL_CULL_FACE);
556 glDisable(GL_LIGHTING);
557 glDisable(GL_TEXTURE_2D);
559 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
560 glPushMatrix(); // Store The Projection Matrix
561 glLoadIdentity(); // Reset The Projection Matrix
562 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
563 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
564 glPushMatrix(); // Store The Modelview Matrix
565 glLoadIdentity(); // Reset The Modelview Matrix
566 glScalef(screenwidth,screenheight,1);
567 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
569 glColor4f(flashr,flashg,flashb,flashamount);
571 glVertex3f(0, 0, 0.0f);
572 glVertex3f(256, 0, 0.0f);
573 glVertex3f(256, 256, 0.0f);
574 glVertex3f(0, 256, 0.0f);
576 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
577 glPopMatrix(); // Restore The Old Projection Matrix
578 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
579 glPopMatrix(); // Restore The Old Projection Matrix
580 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
581 glEnable(GL_CULL_FACE);
590 void Game::FadeLoadingScreen(float howmuch)
592 static float loadprogress,minprogress,maxprogress;
597 glClearColor(0,0,0,1);
598 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
600 loadprogress=howmuch;
602 //loadprogress=abs(Random()%100);
606 //glEnable(GL_TEXTURE_2D);
607 glDisable(GL_TEXTURE_2D);
608 //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
609 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
610 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
611 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
612 glDisable(GL_CULL_FACE);
613 glDisable(GL_LIGHTING);
615 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
616 glPushMatrix(); // Store The Projection Matrix
617 glLoadIdentity(); // Reset The Projection Matrix
618 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
619 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
620 glPushMatrix(); // Store The Modelview Matrix
621 glLoadIdentity(); // Reset The Modelview Matrix
622 glTranslatef(screenwidth/2,screenheight/2,0);
623 glScalef((float)screenwidth/2,(float)screenheight/2,1);
624 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
626 glColor4f(loadprogress/100,0,0,1);
628 //glScalef(.25,.25,.25);
631 glVertex3f(-1, -1, 0.0f);
633 glVertex3f(1, -1, 0.0f);
635 glVertex3f(1, 1, 0.0f);
637 glVertex3f(-1, 1, 0.0f);
640 glDisable(GL_TEXTURE_2D);
641 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
642 glPopMatrix(); // Restore The Old Projection Matrix
643 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
644 glPopMatrix(); // Restore The Old Projection Matrix
649 glEnable(GL_TEXTURE_2D);
650 static char string[256]="";
651 sprintf (string, "LOADING... %d%",(int)loadprogress);
653 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
654 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
655 text.glPrint(280,125,string,1,1,640,480);
661 void Game::InitGame()
664 ProcessSerialNumber PSN;
665 ProcessInfoRec pinfo;
668 /* set up process serial number */
669 PSN.highLongOfPSN = 0;
670 PSN.lowLongOfPSN = kCurrentProcess;
671 /* set up info block */
672 pinfo.processInfoLength = sizeof(pinfo);
673 pinfo.processName = NULL;
674 pinfo.processAppSpec = &pspec;
675 /* grab the vrefnum and directory */
676 err = GetProcessInformation(&PSN, &pinfo);
678 vRefNum = pspec.vRefNum;
689 numchallengelevels=14;
691 accountactive=Account::loadFile(":Data:Users");
697 whichjointstartarray[0]=righthip;
698 whichjointendarray[0]=rightfoot;
700 whichjointstartarray[1]=righthip;
701 whichjointendarray[1]=rightankle;
703 whichjointstartarray[2]=righthip;
704 whichjointendarray[2]=rightknee;
706 whichjointstartarray[3]=rightknee;
707 whichjointendarray[3]=rightankle;
709 whichjointstartarray[4]=rightankle;
710 whichjointendarray[4]=rightfoot;
712 whichjointstartarray[5]=lefthip;
713 whichjointendarray[5]=leftfoot;
715 whichjointstartarray[6]=lefthip;
716 whichjointendarray[6]=leftankle;
718 whichjointstartarray[7]=lefthip;
719 whichjointendarray[7]=leftknee;
721 whichjointstartarray[8]=leftknee;
722 whichjointendarray[8]=leftankle;
724 whichjointstartarray[9]=leftankle;
725 whichjointendarray[9]=leftfoot;
727 whichjointstartarray[10]=abdomen;
728 whichjointendarray[10]=rightshoulder;
730 whichjointstartarray[11]=abdomen;
731 whichjointendarray[11]=rightelbow;
733 whichjointstartarray[12]=abdomen;
734 whichjointendarray[12]=rightwrist;
736 whichjointstartarray[13]=abdomen;
737 whichjointendarray[13]=righthand;
739 whichjointstartarray[14]=rightshoulder;
740 whichjointendarray[14]=rightelbow;
742 whichjointstartarray[15]=rightelbow;
743 whichjointendarray[15]=rightwrist;
745 whichjointstartarray[16]=rightwrist;
746 whichjointendarray[16]=righthand;
748 whichjointstartarray[17]=abdomen;
749 whichjointendarray[17]=leftshoulder;
751 whichjointstartarray[18]=abdomen;
752 whichjointendarray[18]=leftelbow;
754 whichjointstartarray[19]=abdomen;
755 whichjointendarray[19]=leftwrist;
757 whichjointstartarray[20]=abdomen;
758 whichjointendarray[20]=lefthand;
760 whichjointstartarray[21]=leftshoulder;
761 whichjointendarray[21]=leftelbow;
763 whichjointstartarray[22]=leftelbow;
764 whichjointendarray[22]=leftwrist;
766 whichjointstartarray[23]=leftwrist;
767 whichjointendarray[23]=lefthand;
769 whichjointstartarray[24]=abdomen;
770 whichjointendarray[24]=neck;
772 whichjointstartarray[25]=neck;
773 whichjointendarray[25]=head;
775 FadeLoadingScreen(0);
779 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
781 int temptexdetail=texdetail;
783 text.LoadFontTexture(":Data:Textures:Font.png");
785 texdetail=temptexdetail;
787 FadeLoadingScreen(10);
799 LOG("Initializing sound system...");
804 extern bool cmdline(const char *cmd);
805 unsigned char rc = 0;
806 output = OPENAL_OUTPUT_ALSA; // Try alsa first...
807 if (cmdline("forceoss")) // ...but let user override that.
808 output = OPENAL_OUTPUT_OSS;
809 else if (cmdline("nosound"))
810 output = OPENAL_OUTPUT_NOSOUND;
812 OPENAL_SetOutput(output);
813 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
815 // if we tried ALSA and failed, fall back to OSS.
816 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
819 output = OPENAL_OUTPUT_OSS;
820 OPENAL_SetOutput(output);
821 rc = OPENAL_Init(44100, 32, 0);
828 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
829 OPENAL_SetOutput(output);
830 rc = OPENAL_Init(44100, 32, 0);
833 OPENAL_Init(44100, 32, 0);
836 OPENAL_SetSFXMasterVolume((int)(volume*255));
840 emit_stream_np(stream_music3);
842 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
844 LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
845 LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
846 LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
848 temptexdetail=texdetail;
849 if(texdetail>2)texdetail=2;
850 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
851 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
852 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
853 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
854 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
855 LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
856 //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
857 texdetail=temptexdetail;
862 FadeLoadingScreen(95);
873 newscreenwidth=screenwidth;
874 newscreenheight=screenheight;
878 void Game::LoadStuff()
880 static float temptexdetail;
881 static float viewdistdetail;
882 static int i,j,texsize;
893 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
895 for(i=0;i<maxplayers;i++)
897 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
899 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
901 player[i].skeleton.drawmodel.textureptr=0;;
904 //temptexdetail=texdetail;
907 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
908 //texdetail=temptexdetail;
910 temptexdetail=texdetail;
912 text.LoadFontTexture(":Data:Textures:Font.png");
914 texdetail=temptexdetail;
919 viewdistance=50*megascale*viewdistdetail;
935 realtexdetail=texdetail;
938 if(texdetail<1)texdetail=1;
939 realtexdetail=texdetail*4;
945 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
947 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
949 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
953 LOG("Loading weapon data...");
955 LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
956 LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
957 LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
958 LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
959 LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
960 LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
961 LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
963 weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
964 weapons.throwingknifemodel.Scale(.001,.001,.001);
965 //weapons.throwingknifemodel.Rotate(0,0,-90);
966 weapons.throwingknifemodel.Rotate(90,0,0);
967 weapons.throwingknifemodel.Rotate(0,90,0);
968 weapons.throwingknifemodel.flat=0;
969 weapons.throwingknifemodel.CalculateNormals(1);
970 //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
972 weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
973 weapons.swordmodel.Scale(.001,.001,.001);
974 //weapons.swordmodel.Rotate(0,0,-90);
975 weapons.swordmodel.Rotate(90,0,0);
976 weapons.swordmodel.Rotate(0,90,0);
977 weapons.swordmodel.Rotate(0,0,90);
978 weapons.swordmodel.flat=1;
979 weapons.swordmodel.CalculateNormals(1);
980 //weapons.swordmodel.ScaleNormals(-1,-1,-1);
982 weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
983 weapons.staffmodel.Scale(.005,.005,.005);
984 //weapons.staffmodel.Rotate(0,0,-90);
985 weapons.staffmodel.Rotate(90,0,0);
986 weapons.staffmodel.Rotate(0,90,0);
987 weapons.staffmodel.Rotate(0,0,90);
988 weapons.staffmodel.flat=1;
989 weapons.staffmodel.CalculateNormals(1);
990 //weapons.staffmodel.ScaleNormals(-1,-1,-1);
992 //temptexdetail=texdetail;
993 //if(texdetail>4)texdetail=4;
994 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
996 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
998 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1000 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1003 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1005 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1007 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1009 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1011 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1013 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1015 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1017 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1018 //texdetail=temptexdetail;
1019 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1023 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1025 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1028 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1031 LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1032 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1033 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1034 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1035 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1036 LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1037 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1038 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1039 LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1040 LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1041 LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1045 ReSizeGLScene(90,.01);
1052 if(detail)kTextureSize=1024;
1053 if(detail==1)kTextureSize=512;
1054 if(detail==0)kTextureSize=256;
1057 //drawmode=motionblurmode;
1059 //Set up distant light
1063 light.ambient[0]=.2;
1064 light.ambient[1]=.2;
1065 light.ambient[2]=.24;
1068 light.location.z=-.2;
1069 Normalise(&light.location);
1079 texscale=.2/megascale/viewdistdetail;
1080 terrain.scale=3*megascale*viewdistdetail;
1082 viewer.x=terrain.size/2*terrain.scale;
1083 viewer.z=terrain.size/2*terrain.scale;
1085 hawk.load((char *)":Data:Models:hawk.solid",1);
1086 hawk.Scale(.03,.03,.03);
1087 hawk.Rotate(90,1,1);
1088 hawk.CalculateNormals(0);
1089 hawk.ScaleNormals(-1,-1,-1);
1090 hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1091 hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1092 hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1095 eye.load((char *)":Data:Models:eye.solid",1);
1096 eye.Scale(.03,.03,.03);
1097 eye.CalculateNormals(0);
1099 cornea.load((char *)":Data:Models:cornea.solid",1);
1100 cornea.Scale(.03,.03,.03);
1101 cornea.CalculateNormals(0);
1103 iris.load((char *)":Data:Models:iris.solid",1);
1104 iris.Scale(.03,.03,.03);
1105 iris.CalculateNormals(0);
1107 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1108 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1116 //if(targetlevel!=7)
1117 Loadlevel(targetlevel);
1120 rabbitcoords=player[0].coords;
1121 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1123 loadAllAnimations();
1124 //Fix knife stab, too lazy to do it manually
1128 for(i=0;i<player[0].skeleton.num_joints;i++){
1129 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1130 animation[knifesneakattackanim].position[i][j]+=moveamount;
1136 for(i=0;i<player[0].skeleton.num_joints;i++){
1137 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1138 animation[knifesneakattackedanim].position[i][j]+=moveamount;
1144 for(i=0;i<player[0].skeleton.num_joints;i++){
1145 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1146 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1147 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1148 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1150 animation[dead1anim].speed[0]=0.001;
1151 animation[dead2anim].speed[0]=0.001;
1152 animation[dead3anim].speed[0]=0.001;
1153 animation[dead4anim].speed[0]=0.001;
1155 animation[dead1anim].speed[1]=0.001;
1156 animation[dead2anim].speed[1]=0.001;
1157 animation[dead3anim].speed[1]=0.001;
1158 animation[dead4anim].speed[1]=0.001;
1160 for(i=0;i<player[0].skeleton.num_joints;i++){
1161 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1162 animation[swordsneakattackanim].position[i][j]+=moveamount;
1166 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1167 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1172 for(i=0;i<player[0].skeleton.num_joints;i++){
1173 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1174 animation[swordsneakattackedanim].position[i][j]+=moveamount;
1178 for(i=0;i<player[0].skeleton.num_joints;i++){
1179 for(j=0;j<animation[sleepanim].numframes;j++){
1180 animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1185 temptexdetail=texdetail;
1187 texdetail=temptexdetail;
1193 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1195 glGenTextures( 1, &screentexture );
1196 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1199 glEnable(GL_TEXTURE_2D);
1200 glBindTexture( GL_TEXTURE_2D, screentexture);
1201 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1202 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1204 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1208 emit_sound_at(fireendsound);